本文整理汇总了C#中CompilerContext类的典型用法代码示例。如果您正苦于以下问题:C# CompilerContext类的具体用法?C# CompilerContext怎么用?C# CompilerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilerContext类属于命名空间,在下文中一共展示了CompilerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContent
public void GetContent(CompilerContext context, ParseTreeNode parseNode)
{
if (parseNode.HasChildNodes())
{
ParallelTasks = Convert.ToUInt32(parseNode.ChildNodes[1].Token.Value);
}
}
示例2: BeginFiltering
public override IEnumerable<Token> BeginFiltering(CompilerContext context, IEnumerable<Token> tokens)
{
foreach (Token token in tokens) {
if (!token.Terminal.IsSet(TermOptions.IsBrace)) {
yield return token;
continue;
}
//open brace symbol
if (token.Terminal.IsSet(TermOptions.IsOpenBrace)) {
_braces.Push(token);
yield return token;
continue;
}
//We have closing brace
if (_braces.Count == 0) {
yield return context.CreateErrorTokenAndReportError( token.Location, token.Text, "Unmatched closing brace '{0}'", token.Text);
continue;
}
//check match
Token last = _braces.Pop();
if (last.AsSymbol.IsPairFor != token.AsSymbol) {
yield return context.CreateErrorTokenAndReportError(token.Location, token.Text,
"Unmatched closing brace '{0}' - expected '{1}'", last.AsSymbol.IsPairFor.Name);
continue;
}
//everything is ok, there's matching brace on top of the stack
Token.LinkMatchingBraces(last, token);
context.CurrentParseTree.OpenBraces.Add(last);
yield return token; //return this token
}//foreach token
yield break;
}
示例3: Execute
public ScriptResult Execute(string code, string[] scriptArgs, AssemblyReferences references, IEnumerable<string> namespaces,
ScriptPackSession scriptPackSession)
{
Guard.AgainstNullArgument("references", references);
Guard.AgainstNullArgument("scriptPackSession", scriptPackSession);
references.PathReferences.UnionWith(scriptPackSession.References);
SessionState<Evaluator> sessionState;
if (!scriptPackSession.State.ContainsKey(SessionKey))
{
Logger.Debug("Creating session");
var context = new CompilerContext(new CompilerSettings
{
AssemblyReferences = references.PathReferences.ToList()
}, new ConsoleReportPrinter());
var evaluator = new Evaluator(context);
var allNamespaces = namespaces.Union(scriptPackSession.Namespaces).Distinct();
var host = _scriptHostFactory.CreateScriptHost(new ScriptPackManager(scriptPackSession.Contexts), scriptArgs);
MonoHost.SetHost((ScriptHost)host);
evaluator.ReferenceAssembly(typeof(MonoHost).Assembly);
evaluator.InteractiveBaseClass = typeof(MonoHost);
sessionState = new SessionState<Evaluator>
{
References = new AssemblyReferences(references.PathReferences, references.Assemblies),
Namespaces = new HashSet<string>(),
Session = evaluator
};
ImportNamespaces(allNamespaces, sessionState);
scriptPackSession.State[SessionKey] = sessionState;
}
else
{
Logger.Debug("Reusing existing session");
sessionState = (SessionState<Evaluator>)scriptPackSession.State[SessionKey];
var newReferences = sessionState.References == null ? references : references.Except(sessionState.References);
foreach (var reference in newReferences.PathReferences)
{
Logger.DebugFormat("Adding reference to {0}", reference);
sessionState.Session.LoadAssembly(reference);
}
sessionState.References = new AssemblyReferences(references.PathReferences, references.Assemblies);
var newNamespaces = sessionState.Namespaces == null ? namespaces : namespaces.Except(sessionState.Namespaces);
ImportNamespaces(newNamespaces, sessionState);
}
Logger.Debug("Starting execution");
var result = Execute(code, sessionState.Session);
Logger.Debug("Finished execution");
return result;
}
示例4: GetContent
public override void GetContent(CompilerContext context, ParseTreeNode parseNode)
{
#region Get the optional type list
if (parseNode.ChildNodes[1].HasChildNodes())
{
_TypesToDump = ((parseNode.ChildNodes[1].ChildNodes[1].AstNode as TypeListNode).Types).Select(tlnode => tlnode.TypeName).ToList();
}
#endregion
_DumpType = (parseNode.ChildNodes[2].AstNode as DumpTypeNode).DumpType;
_DumpFormat = (parseNode.ChildNodes[3].AstNode as DumpFormatNode).DumpFormat;
_DumpableGrammar = context.Compiler.Language.Grammar as IDumpable;
if (_DumpableGrammar == null)
{
throw new GraphDBException(new Error_NotADumpableGrammar(context.Compiler.Language.Grammar.GetType().ToString()));
}
if (parseNode.ChildNodes[4].HasChildNodes())
{
_DumpDestination = parseNode.ChildNodes[4].ChildNodes[1].Token.ValueString;
}
}
示例5: GetContent
public override void GetContent(CompilerContext context, ParseTreeNode parseNode)
{
if (parseNode.HasChildNodes())
{
//get type
if (parseNode.ChildNodes[1] != null && parseNode.ChildNodes[1].AstNode != null)
{
_Type = ((ATypeNode)(parseNode.ChildNodes[1].AstNode)).ReferenceAndType.TypeName;
}
else
{
throw new GraphDBException(new Error_NotImplemented(new System.Diagnostics.StackTrace(true)));
}
if (parseNode.ChildNodes[3] != null && parseNode.ChildNodes[3].HasChildNodes())
{
_AttributeAssignList = new List<AAttributeAssignOrUpdate>((parseNode.ChildNodes[3].AstNode as AttrUpdateOrAssignListNode).ListOfUpdate.Select(e => e as AAttributeAssignOrUpdate));
}
if (parseNode.ChildNodes[4] != null && ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition != null)
{
_WhereExpression = ((WhereExpressionNode)parseNode.ChildNodes[4].AstNode).BinaryExpressionDefinition;
}
}
}
示例6: GetContent
/// <summary>
/// This handles the Where Expression Node with all the
/// </summary>
/// <param name="context"></param>
/// <param name="parseNode"></param>
/// <param name="typeManager"></param>
public void GetContent(CompilerContext context, ParseTreeNode parseNode)
{
if (parseNode.HasChildNodes())
{
BinExprNode = (BinaryExpressionNode)parseNode.ChildNodes[1].AstNode;
}
}
示例7: GetContent
public void GetContent(CompilerContext context, ParseTreeNode parseNode)
{
var content = parseNode.FirstChild.AstNode as RemoveFromListAttrUpdateNode;
AttributeRemoveList = content.AttributeRemoveList;
base.ParsingResult.PushIExceptional(content.ParsingResult);
}
示例8: RuntimeScriptCode
public RuntimeScriptCode(CompilerContext/*!*/ context, MSAst.Expression<Func<object>>/*!*/ expression, PythonAst/*!*/ ast, CodeContext/*!*/ codeContext)
: base(context.SourceUnit) {
_code = expression;
_ast = ast;
_context = context;
_optimizedContext = codeContext;
}
示例9: TotemAst
public TotemAst(bool isModule, ModuleOptions languageFeatures, bool printExpressions, CompilerContext context)
{
_isModule = isModule;
_printExpressions = printExpressions;
_languageFeatures = languageFeatures;
_mode = ((TotemCompilerOptions)context.Options).CompilationMode ?? GetCompilationMode(context);
_compilerContext = context;
FuncCodeExpr = _functionCode;
TotemCompilerOptions tco = context.Options as TotemCompilerOptions;
Debug.Assert(tco != null);
string name;
if (!context.SourceUnit.HasPath || (tco.Module & ModuleOptions.ExecOrEvalCode) != 0)
{
name = "<module>";
}
else
{
name = context.SourceUnit.Path;
}
_name = name;
Debug.Assert(_name != null);
TotemOptions to = ((TotemContext)context.SourceUnit.LanguageContext).TotemOptions;
_document = context.SourceUnit.Document ?? Expression.SymbolDocument(name, TotemContext.LanguageGuid, TotemContext.VendorGuid);
}
示例10: GetRequiredFiles
public static IEnumerable<RequiredFile> GetRequiredFiles(CompilerContext context, string script)
{
var matches = Regex.Matches(script, RequireMatchPattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
var result = new List<RequiredFile>();
foreach (Match match in matches)
{
var location = match.Groups["requiredFile"].Value.Trim();
var protocolString = match.Groups["protocol"].Value ?? string.Empty;
var isEmbedded = location.EndsWith("`") && location.StartsWith("`");
location = isEmbedded ? location.Substring(1, location.Length - 2) : location;
var file = new RequiredFile
{
IsEmbedded = isEmbedded,
Location = location,
Protocol = FileProtocol.LocalFile,
RegexMatch = match,
Context = context
};
if (!string.IsNullOrEmpty(protocolString)) {
FileProtocol protocol;
Enum.TryParse<FileProtocol>(protocolString.Replace("://", string.Empty), true, out protocol);
file.Protocol = protocol;
}
if (file.Protocol == FileProtocol.LocalFile)
if (!new FileInfo(file.Location).Exists)
file.Location = Path.Combine(context.WorkingDirectory, file.Location);
result.Add(file);
}
return result;
}
示例11: BindAst
internal static void BindAst(TotemAst ast, CompilerContext context)
{
Assert.NotNull(ast, context);
TotemNameBinder binder = new TotemNameBinder(context);
binder.Bind(ast);
}
示例12: Initialize
public virtual void Initialize(CompilerContext context)
{
_context = context;
_codeBuilder = new EnvironmentProvision<BooCodeBuilder>();
_typeSystemServices = new EnvironmentProvision<TypeSystemServices>();
_nameResolutionService = new EnvironmentProvision<NameResolutionService>();
}
示例13: GetContent
public void GetContent(CompilerContext context, ParseTreeNode parseNode)
{
var idChain = ((IDNode)parseNode.ChildNodes[0].AstNode).IDChainDefinition;
var AttrName = parseNode.ChildNodes[0].FirstChild.FirstChild.Token.ValueString;
var tupleDefinition = ((TupleNode)parseNode.ChildNodes[2].AstNode).TupleDefinition;
AttributeRemoveList = new Managers.Structures.AttributeRemoveList(idChain, AttrName, tupleDefinition);
}
示例14: GetContent
public void GetContent(CompilerContext context, ParseTreeNode parseNode)
{
_Settings = new Dictionary<String, String>();
foreach (var _ParseTreeNode1 in parseNode.ChildNodes)
{
if (_ParseTreeNode1.HasChildNodes())
{
switch (_ParseTreeNode1.ChildNodes[0].Token.Text.ToUpper())
{
case "GET":
_OperationType = TypesOfSettingOperation.GET;
break;
case "SET":
_OperationType = TypesOfSettingOperation.SET;
break;
case "REMOVE":
_OperationType = TypesOfSettingOperation.REMOVE;
break;
}
foreach (var _ParseTreeNode2 in _ParseTreeNode1.ChildNodes[1].ChildNodes)
{
if (_ParseTreeNode2 != null)
{
if (_ParseTreeNode2.HasChildNodes())
{
if (_ParseTreeNode2.ChildNodes[0] != null)
{
if (_ParseTreeNode2.ChildNodes[2] != null)
{
if (_ParseTreeNode2.ChildNodes[0].Token != null && _ParseTreeNode2.ChildNodes[2].Token != null)
{
var Temp = _ParseTreeNode2.ChildNodes[2].Token.Text.ToUpper();
if (Temp.Contains("DEFAULT"))
_Settings.Add(_ParseTreeNode2.ChildNodes[0].Token.ValueString.ToUpper(), Temp);
else
_Settings.Add(_ParseTreeNode2.ChildNodes[0].Token.ValueString.ToUpper(), _ParseTreeNode2.ChildNodes[2].Token.ValueString.ToUpper());
}
}
}
}
else
{
if (_ParseTreeNode2.Token != null)
_Settings.Add(_ParseTreeNode2.Token.ValueString, "");
}
}
}
}
}
}
示例15: CreateParserWorker
private static Parser CreateParserWorker(CompilerContext context, PythonOptions options, bool verbatim) {
ContractUtils.RequiresNotNull(context, "context");
ContractUtils.RequiresNotNull(options, "options");
PythonCompilerOptions compilerOptions = context.Options as PythonCompilerOptions;
if (options == null) {
throw new ArgumentException(Resources.PythonContextRequired);
}
SourceCodeReader reader;
try {
reader = context.SourceUnit.GetReader();
if (compilerOptions.SkipFirstLine) {
reader.ReadLine();
}
} catch (IOException e) {
context.Errors.Add(context.SourceUnit, e.Message, SourceSpan.Invalid, 0, Severity.Error);
throw;
}
Tokenizer tokenizer = new Tokenizer(context.Errors, compilerOptions, verbatim);
tokenizer.Initialize(null, reader, context.SourceUnit, SourceLocation.MinValue);
tokenizer.IndentationInconsistencySeverity = options.IndentationInconsistencySeverity;
Parser result = new Parser(tokenizer, context.Errors, context.ParserSink, compilerOptions.LanguageFeatures);
result._sourceReader = reader;
return result;
}