public void GetContent(CompilerContext context, ParseTreeNode parseNode) { if (parseNode.HasChildNodes()) { ParallelTasks = Convert.ToUInt32(parseNode.ChildNodes[1].Token.Value); } }
public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast, Dictionary<int, bool> handlerLocations, Dictionary<int, Dictionary<int, bool>> loopAndFinallyLocations) { // create the CodeContext PythonGlobal[] globalArray = new PythonGlobal[_globals.Count]; // now fill in the dictionary and create the array foreach (var global in _globals) { globalArray[global.Value.Index] = _globalVals[global.Key]; } _array.Array = globalArray; // finally build the funcion that's closed over the array and string name = ((PythonCompilerOptions)context.Options).ModuleName ?? "<unnamed>"; var func = Ast.Lambda<Func<FunctionCode, object>>( Ast.Block( new[] { _globalArray, _globalContext }, Ast.Assign(_globalArray, Ast.Constant(globalArray)), Ast.Assign(_globalContext, Ast.Constant(_context)), Utils.Convert(body, typeof(object)) ), name, new [] { AstGenerator._functionCode } ); return new RuntimeScriptCode(context, func, ast, _context); }
public void GetContent(CompilerContext context, ParseTreeNode parseNode) { var aSelectNode = (SelectNode)parseNode.ChildNodes[0].AstNode; SelectDefinition = new Managers.Structures.SelectDefinition(aSelectNode.TypeList, aSelectNode.SelectedElements, aSelectNode.WhereExpressionDefinition, aSelectNode.GroupByIDs, aSelectNode.Having, aSelectNode.Limit, aSelectNode.Offset, aSelectNode.OrderByDefinition, aSelectNode.ResolutionDepth); }
/// <summary> /// Gets the content of an UpdateStatement. /// </summary> /// <param name="context">CompilerContext of Irony.</param> /// <param name="parseNode">The current ParseNode.</param> /// <param name="typeManager">The TypeManager of the GraphDB.</param> public override void GetContent(CompilerContext myCompilerContext, ParseTreeNode myParseTreeNode) { #region get Type _TypeName = (myParseTreeNode.ChildNodes[1].AstNode as ATypeNode).ReferenceAndType.TypeName; #endregion #region get myAttributes if (myParseTreeNode.ChildNodes[3].HasChildNodes()) { var AttrUpdateOrAssign = (AttrUpdateOrAssignListNode)myParseTreeNode.ChildNodes[3].AstNode; _listOfUpdates = AttrUpdateOrAssign.ListOfUpdate; base.ParsingResult.PushIExceptional(AttrUpdateOrAssign.ParsingResult); } #endregion #region whereClauseOpt if (myParseTreeNode.ChildNodes[4].HasChildNodes()) { var tempWhereNode = (WhereExpressionNode) myParseTreeNode.ChildNodes[4].AstNode; _WhereExpression = tempWhereNode.BinaryExpressionDefinition; } #endregion }
public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) { MSAst.Expression finalBody = Ast.Block( new[] { _globalCtx }, Ast.Assign( _globalCtx, Ast.Call(typeof(PythonOps).GetMethod("CreateTopLevelCodeContext"), _globalScope, _language ) ), body ); PythonCompilerOptions pco = ((PythonCompilerOptions)context.Options); string name = pco.ModuleName ?? "<unnamed>"; var lambda = Ast.Lambda<Func<Scope, LanguageContext, object>>( finalBody, name, new[] { _globalScope, _language } ); Func<Scope, LanguageContext, object> func; // TODO: adaptive compilation should be eanbled /*PythonContext pc = (PythonContext)context.SourceUnit.LanguageContext; if (pc.ShouldInterpret(pco, context.SourceUnit)) { func = CompilerHelpers.LightCompile(lambda); } else*/ { func = lambda.Compile(context.SourceUnit.EmitDebugSymbols); } return new PythonScriptCode(func, context.SourceUnit); }
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, ""); } } } } } }
public RuntimeScriptCode(CompilerContext/*!*/ context, MSAst.Expression<Func<object>>/*!*/ expression, PythonAst/*!*/ ast, CodeContext/*!*/ codeContext) : base(context.SourceUnit) { _code = expression; _ast = ast; _context = context; _optimizedContext = codeContext; }
public void GetContent(CompilerContext context, ParseTreeNode parseNode) { var content = parseNode.FirstChild.AstNode as RemoveFromListAttrUpdateNode; AttributeRemoveList = content.AttributeRemoveList; base.ParsingResult.PushIExceptional(content.ParsingResult); }
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; }
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); }
internal static void BindAst(TotemAst ast, CompilerContext context) { Assert.NotNull(ast, context); TotemNameBinder binder = new TotemNameBinder(context); binder.Bind(ast); }
public virtual void Initialize(CompilerContext context) { _context = context; _codeBuilder = new EnvironmentProvision<BooCodeBuilder>(); _typeSystemServices = new EnvironmentProvision<TypeSystemServices>(); _nameResolutionService = new EnvironmentProvision<NameResolutionService>(); }
internal AstGenerator(CompilerContext/*!*/ context, SourceSpan span, string name, bool generator, bool print) : this(name, generator, print) { Assert.NotNull(context); _context = context; _binderState = new BinderState(Binder); _document = _context.SourceUnit.Document; }
public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ lambda, CompilerContext/*!*/ compilerContext, PythonAst/*!*/ ast) { PythonContext context = (PythonContext)compilerContext.SourceUnit.LanguageContext; Type t = _typeGen.FinishType(); #if SILVERLIGHT _finalType.Value = t; #endif // create the CodeContext for this optimized module InitOptimizedCodeContext(t); t.GetField("__global_context").SetValue(null, _context); // publish the cached constants foreach (var ci in _constants) { FieldInfo fi = t.GetField(ci.Value.Field.Name); fi.SetValue(null, ci.Key); } // publish all of the call site instances foreach (SiteInfo si in _sites) { FieldInfo fi = t.GetField(si.Field.Name); fi.SetValue(null, CallSite.Create(si.DelegateType, si.Binder)); } // initialize all of the cached symbol IDs. ScriptingRuntimeHelpers.InitializeSymbols(t); string name = ((PythonCompilerOptions)compilerContext.Options).ModuleName ?? "<unnamed>"; var func = Ast.Lambda<Func<object>>(lambda, name, new MSAst.ParameterExpression[0]); return new RuntimeScriptCode(compilerContext, func, ast, _context); }
public void GetContent(CompilerContext context, ParseTreeNode parseNode) { _DropIndexList = new Dictionary<String, String>(); if (parseNode.ChildNodes[1].ChildNodes.Count == 2 && parseNode.ChildNodes[1].ChildNodes.TrueForAll(item => !item.HasChildNodes())) { var idxName = parseNode.ChildNodes[1].ChildNodes[0].Token.Text; var idxEdition = ((EditionOptNode)parseNode.ChildNodes[1].ChildNodes[1].AstNode).IndexEdition; if (!_DropIndexList.ContainsKey(idxName)) { _DropIndexList.Add(idxName, idxEdition); } } else { foreach (var nodes in parseNode.ChildNodes[1].ChildNodes) { var idxName = nodes.ChildNodes[0].Token.Text; var idxEdition = ((EditionOptNode)nodes.ChildNodes[1].AstNode).IndexEdition; if (!_DropIndexList.ContainsKey(idxName)) { _DropIndexList.Add(idxName, idxEdition); } } } }
public void GetContent(CompilerContext myCompilerContext, ParseTreeNode myParseTreeNode) { if (myParseTreeNode.ChildNodes[0].HasChildNodes()) { if (myParseTreeNode.ChildNodes[0].ChildNodes[0].ChildNodes.Count > 1) { _IndexType = ((ATypeNode)myParseTreeNode.ChildNodes[0].ChildNodes[0].ChildNodes[0].AstNode).ReferenceAndType.TypeName; _IndexAttribute = ((IDNode)myParseTreeNode.ChildNodes[0].ChildNodes[0].ChildNodes[2].AstNode).IDChainDefinition; } else { //_IndexAttribute = myParseTreeNode.ChildNodes[0].ChildNodes[0].Token.ValueString; _IndexAttribute = new IDChainDefinition(); _IndexAttribute.AddPart(new ChainPartTypeOrAttributeDefinition(myParseTreeNode.ChildNodes[0].ChildNodes[0].Token.ValueString)); } } if (myParseTreeNode.ChildNodes.Count > 1 && myParseTreeNode.ChildNodes[1].HasChildNodes()) { _OrderDirection = myParseTreeNode.ChildNodes[1].FirstChild.Token.ValueString; } else { _OrderDirection = String.Empty; } IndexAttributeDefinition = new IndexAttributeDefinition(_IndexAttribute, _IndexType, _OrderDirection); }
public void GetContent(CompilerContext context, ParseTreeNode parseNode) { TypesSettingScope? settingType; if (parseNode.HasChildNodes() && (parseNode.ChildNodes.Count >= 2)) { switch (parseNode.ChildNodes[1].Token.Text.ToUpper()) { case "TYPE": settingType = TypesSettingScope.TYPE; _DescribeSettingDefinition = new DescribeSettingDefinition(settingType, myTypeName: (parseNode.ChildNodes[2].ChildNodes[0].AstNode as ATypeNode).ReferenceAndType.TypeName); break; case "ATTRIBUTE": settingType = TypesSettingScope.ATTRIBUTE; _DescribeSettingDefinition = new DescribeSettingDefinition(settingType, myIDChain: (parseNode.ChildNodes[2].ChildNodes[2].AstNode as IDNode).IDChainDefinition); break; case "DB": settingType = TypesSettingScope.DB; _DescribeSettingDefinition = new DescribeSettingDefinition(settingType); break; case "SESSION": settingType = TypesSettingScope.SESSION; _DescribeSettingDefinition = new DescribeSettingDefinition(settingType); break; default: settingType = null; _DescribeSettingDefinition = new DescribeSettingDefinition(settingType); break; } } }
public ParseTree Parse(CompilerContext context, string sourceText, string fileName) { int start = Environment.TickCount; Parser.Parse(context, sourceText, fileName); context.CurrentParseTree.ParseTime = Environment.TickCount - start; return context.CurrentParseTree; }
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; }
public void GetContent(CompilerContext context, ParseTreeNode parseNode) { if (parseNode.HasChildNodes()) { _DescrAggrDefinition = new DescribeAggregateDefinition(parseNode.ChildNodes[1].Token.ValueString.ToUpper()); } }
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; } }
public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) { MSAst.ParameterExpression scope = Ast.Parameter(typeof(Scope), "$scope"); MSAst.ParameterExpression language = Ast.Parameter(typeof(LanguageContext), "$language "); // finally build the funcion that's closed over the array and var func = Ast.Lambda<Func<Scope, LanguageContext, object>>( Ast.Block( new[] { GlobalArray }, Ast.Assign( GlobalArray, Ast.Call( null, typeof(PythonOps).GetMethod("GetGlobalArray"), scope ) ), Utils.Convert(body, typeof(object)) ), ((PythonCompilerOptions)context.Options).ModuleName, new MSAst.ParameterExpression[] { scope, language } ); PythonCompilerOptions pco = context.Options as PythonCompilerOptions; return new SavableScriptCode(func, context.SourceUnit, GetNames(), pco.ModuleName); }
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; }
public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) { // create the CodeContext PythonGlobal[] globalArray = new PythonGlobal[_globals.Count]; // now fill in the dictionary and create the array foreach (var global in _globals) { SymbolId globalName = SymbolTable.StringToId(global.Key); globalArray[global.Value.Index] = _globalVals[globalName]; } _array.Array = globalArray; // finally build the funcion that's closed over the array and string name = ((PythonCompilerOptions)context.Options).ModuleName ?? "<unnamed>"; var func = Ast.Lambda<Func<object>>( Ast.Block( new[] { _globalArray, _globalContext }, Ast.Assign(_globalArray, Ast.Constant(globalArray)), Ast.Assign(_globalContext, Ast.Constant(_context)), body ), name, new MSAst.ParameterExpression[0] ); return new RuntimeScriptCode(context, func, ast, _context); }
/// <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; } }
public PythonAst(Statement body, bool isModule, ModuleOptions languageFeatures, bool printExpressions, CompilerContext context) { ContractUtils.RequiresNotNull(body, "body"); _body = body; _isModule = isModule; _printExpressions = printExpressions; _languageFeatures = languageFeatures; _mode = ((PythonCompilerOptions)context.Options).CompilationMode ?? GetCompilationMode(context); _compilerContext = context; FuncCodeExpr = _functionCode; PythonCompilerOptions pco = context.Options as PythonCompilerOptions; Debug.Assert(pco != null); string name; if (!context.SourceUnit.HasPath || (pco.Module & ModuleOptions.ExecOrEvalCode) != 0) { name = "<module>"; } else { name = context.SourceUnit.Path; } _name = name; Debug.Assert(_name != null); PythonOptions po = ((PythonContext)context.SourceUnit.LanguageContext).PythonOptions; if (po.EnableProfiler && _mode != CompilationMode.ToDisk) { _profiler = Profiler.GetProfiler(PyContext); } _document = context.SourceUnit.Document ?? Ast.SymbolDocument(name, PyContext.LanguageGuid, PyContext.VendorGuid); }
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; } } }
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; }
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); }
internal AstGenerator(AstGenerator/*!*/ parent, string name, bool generator, bool print) : this(name, generator, false) { Assert.NotNull(parent); _context = parent.Context; _binderState = parent.BinderState; _document = _context.SourceUnit.Document; }
internal static List <object> GetInterpolationItems(ITextSource input, Interval valueInterval, CompilerContext context, Module module) { var intItems = new List <object>(); var i = ValueIsMissingQuote(input, '"', valueInterval) ? 0 : -1; var value = input.GetText(valueInterval.Begin.Index + 1, valueInterval.End.Index + i); var matches = Regex.Matches(value, //Escape characters @"(\\(?:[""\\\/bfnrt]|u[a-fA-F0-9]{0,4}|" + //Alias or parameter with brackets @"(?:\$|!%)\([ \t]*(?:(?:_|[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD])" + @"(?:[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" + @"-|\.|[0-9]|\xB7|[\u0300-\u036F]|[\u203F-\u2040])*)[ \t]*\)?|" + //Alias or parameter without brackets @"(?:\$|!%)(?:(?:_|[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD])" + @"(?:[A-Z]|[a-z]|[\xC0-\xD6]|[\xD8-\xF6]|[\xF8-\u02FF]|[\u0370-\u037D]|[\u037F-\u1FFF]|[\u200C-\u200D]|[\u2070-\u218F]|[\u2C00-\u2FEF]|[\u3001-\uD7FF]|[\uF900-\uFDCF]|[\uFDF0-\uFFFD]|" + @"-|\.|[0-9]|\xB7|[\u0300-\u036F]|[\u203F-\u2040])*)" + //Incorrect escape, indent, new line, other characters @"|.?))|(\r?\n[ \t]*)|([^\\\0-\x1F\x7F]+)", RegexOptions.Singleline); var line = valueInterval.Begin.Line; var column = valueInterval.Begin.Column; foreach (var match in matches) { if (((Match)match).Value.StartsWith(@"\$")) { intItems.Add(GetAliasInterpolationItem((Match)match, line, column + 1, context, module)); } else if (((Match)match).Value.StartsWith(@"\!%")) { intItems.Add(GetParameterInterpolationItem((Match)match, line, column + 1, context, module)); } else if (((Match)match).Value.StartsWith(@"\")) { intItems.Add(GetEscapeInterpolationItem((Match)match, line, column + 1, context, module)); } else if (((Match)match).Value.StartsWith("\n") || ((Match)match).Value.StartsWith("\r")) { intItems.Add(GetEolEscapeInterpolationItem((Match)match)); } else { intItems.Add(((Match)match).Value); } if (((Match)match).Value.StartsWith("\n")) { line++; column = ((Match)match).Value.Length; } else if (((Match)match).Value.StartsWith("\r")) { line++; column = ((Match)match).Value.Length + 1; } else { column += ((Match)match).Value.Length; } } return(intItems); }
internal static Tuple <string, List <object> > GetValue(ITextSource input, AssignmentEnum assignment, int valueQuotesType, Interval valueInterval, int valueIndent, CompilerContext context, Module module) { if (valueInterval == null) { if (assignment == AssignmentEnum.E || assignment == AssignmentEnum.EE) { return(new Tuple <string, List <object> >(string.Empty, null)); } return(new Tuple <string, List <object> >(null, null)); } if (valueInterval.Begin.Index == -1) { return(new Tuple <string, List <object> >(string.Empty, null)); } if (valueQuotesType == '\'') { if (!ValueIsMissingQuote(input, valueQuotesType, valueInterval)) { return(new Tuple <string, List <object> >(GetValueFromValueInterval(input, assignment, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index - 1, valueIndent), null)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval(input, assignment, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index, valueIndent), null)); } if (valueQuotesType == '"') { var ii = GetInterpolationItems(input, valueInterval, context, module); string value = (string)(ii.Count == 1 && ii[0] is string?ii[0] : string.Empty); return(new Tuple <string, List <object> >(value, ii)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval(input, assignment, valueQuotesType, valueInterval.Begin.Index, valueInterval.End.Index, valueIndent), null)); }
public override void Initialize(CompilerContext context) { base.Initialize(context); _astAttributeInterface = TypeSystemServices.Map(typeof(IAstAttribute)); }
public void Initialize(CompilerContext context) { }
public CustomDynamicDriver(CompilerContext ctx) { this.ctx = ctx; }
/// <summary> /// Creates instance of the class. /// </summary> /// <param name="context"><see cref="CompilerContext"/> that will be used to report errors.</param> /// <param name="fileName">Source code file name that will be used to report error location.</param> public ErrorListener(CompilerContext context, string fileName) { _context = context; _fileName = fileName; }
void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom) { ctx.EmitBasicWrite("WriteDouble", valueFrom); }
protected override void EmitWrite(CompilerContext ctx, Local valueFrom) { ctx.LoadAddress(valueFrom, this.ExpectedType); ctx.LoadValue(this.property); ctx.WriteNullCheckedTail(this.property.PropertyType, this.Tail, null); }
/// <inheritdoc /> public void Dispose() { _context = null; }
public string Compile(CompilerContext ctx) { return($"\"{Value}\""); }
internal CompilerService(CompilerContext outerContext) { _currentContext = new ModuleCompilerContext(outerContext); }
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom) { ProtoTypeCode typeCode = this.GetTypeCode(); if (this.map == null) { ctx.EmitBasicRead("ReadInt32", ctx.MapType(typeof(int))); ctx.ConvertFromInt32(typeCode, false); } else { int[] keys = new int[this.map.Length]; object[] values = new object[this.map.Length]; for (int i = 0; i < this.map.Length; i++) { keys[i] = this.map[i].WireValue; values[i] = this.map[i].RawValue; } using (Local local = new Local(ctx, this.ExpectedType)) { using (Local local2 = new Local(ctx, ctx.MapType(typeof(int)))) { ctx.EmitBasicRead("ReadInt32", ctx.MapType(typeof(int))); ctx.StoreValue(local2); CodeLabel label = ctx.DefineLabel(); BasicList.NodeEnumerator enumerator = BasicList.GetContiguousGroups(keys, values).GetEnumerator(); while (enumerator.MoveNext()) { BasicList.Group current = (BasicList.Group)enumerator.Current; CodeLabel label2 = ctx.DefineLabel(); int count = current.Items.Count; if (count == 1) { ctx.LoadValue(local2); ctx.LoadValue(current.First); CodeLabel label3 = ctx.DefineLabel(); ctx.BranchIfEqual(label3, true); ctx.Branch(label2, false); WriteEnumValue(ctx, typeCode, label3, label, current.Items[0], local); } else { ctx.LoadValue(local2); ctx.LoadValue(current.First); ctx.Subtract(); CodeLabel[] jumpTable = new CodeLabel[count]; for (int j = 0; j < count; j++) { jumpTable[j] = ctx.DefineLabel(); } ctx.Switch(jumpTable); ctx.Branch(label2, false); for (int k = 0; k < count; k++) { WriteEnumValue(ctx, typeCode, jumpTable[k], label, current.Items[k], local); } } ctx.MarkLabel(label2); } ctx.LoadReaderWriter(); ctx.LoadValue(this.ExpectedType); ctx.LoadValue(local2); ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("ThrowEnumException")); ctx.MarkLabel(label); ctx.LoadValue(local); } } } }
/// <summary> /// Creates instance of <see cref="PairFactoryForXml"/>. /// </summary> /// <param name="context"><see cref="CompilerContext"/> used to report errors.</param> /// <param name="module">Current module.</param> public PairFactoryForXml(CompilerContext context, Module module) { _context = context; _module = module; }
public void EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType) { ctx.G.ThrowNotSupportedException(); }
public virtual void Dispose() { _context = null; }
void IProtoSerializer.EmitRead(CompilerContext ctx, Local valueFrom) { ctx.EmitBasicRead("ReadDouble", this.ExpectedType); }
public ParseSourceFile(CompilerContext context, ParseUnit parseUnit) : base(context, parseUnit) { }
/* * private static List<string> _firsts = new List<string>() { "'", "\"", "@" }; */ #endregion #region Init public override TokenAst TryMatch(CompilerContext context, ISourceStream source) { bool isVerbatim = false; int start = source.Position; if (source.CurrentChar == '@') { isVerbatim = true; source.Position++; start++; } if (IsCurrentQuote(source)) { source.Position++; start++; } else { return(null); } while (!source.EOF()) { if (!isVerbatim) { if (source.CurrentChar == '\\') { //TODO: Escape processing source.Position += 2; continue; } if (LRParser.LineTerminators.IndexOf(source.CurrentChar) >= 0) { return(null); } } if (IsCurrentQuote(source)) { break; } source.Position++; } if (IsCurrentQuote(source)) { source.Position++; } else { return(null); } string lexeme = source.GetLexeme(); string body = source.Text.Substring(start, source.Position - start - 1); //TODO: handle this in escape processing if (!isVerbatim) { body = body.Replace("\\'", "'").Replace("\\\"", "\"").Replace("\\\\", "\\"); } TokenAst token = TokenAst.Create(this, context, source.TokenStart, lexeme, body); return(token); //return Grammar.CreateSyntaxErrorToken(context, source.TokenStart, "Failed to convert the value"); }
public override void Initialize(CompilerContext context) { base.Initialize(context); this.OptimizeNullComparisons = false; }
public void EmitCreateInstance(CompilerContext ctx) { ctx.G.ThrowNotSupportedException(); }
public GenericsServices(CompilerContext context) { Initialize(context); }
public PythonAst(Statement body, bool isModule, ModuleOptions languageFeatures, bool printExpressions, CompilerContext context, int[] lineLocations) : this(isModule, languageFeatures, printExpressions, context) { ContractUtils.RequiresNotNull(body, "body"); _body = body; _lineLocations = lineLocations; }
public static TiledTile TileGetTileObject(this uint tile, List <TiledTilesetDefinition> tilesets, CompilerContext context) { TiledTilesetDefinition tileset = tilesets.GetTilesetByGlobalTileId(tile); if (tileset == null) { context.ExitError("could not find tileset of tile {0}", tile); } TiledTile foundTile = tileset.RealTileset.Tiles.FirstOrDefault(t => t.Id == tile - tileset.FirstGlobalId); if (foundTile == null) { context.ExitError("could not find tile object for tile {0}", tile); } return(foundTile); }
private PythonNameBinder(CompilerContext context) { _define = new DefineBinder(this); _delete = new DeleteBinder(this); Context = context; }
/// <inheritdoc /> public void Initialize(CompilerContext context) { _context = context; context.Properties.Add("NamespaceResolver", new NamespaceResolver(context)); }
/// <summary> /// Creates a new PythonAst without a body. ParsingFinished should be called afterwards to set /// the body. /// </summary> public PythonAst(bool isModule, ModuleOptions languageFeatures, bool printExpressions, CompilerContext context) { _isModule = isModule; _printExpressions = printExpressions; _languageFeatures = languageFeatures; _mode = ((PythonCompilerOptions)context.Options).CompilationMode ?? GetCompilationMode(context); _compilerContext = context; FuncCodeExpr = _functionCode; PythonCompilerOptions pco = context.Options as PythonCompilerOptions; Debug.Assert(pco != null); string name; if (!context.SourceUnit.HasPath || (pco.Module & ModuleOptions.ExecOrEvalCode) != 0) { name = "<module>"; } else { name = context.SourceUnit.Path; } _name = name; Debug.Assert(_name != null); PythonOptions po = ((PythonContext)context.SourceUnit.LanguageContext).PythonOptions; if (po.EnableProfiler #if FEATURE_REFEMIT && _mode != CompilationMode.ToDisk #endif ) { _profiler = Profiler.GetProfiler(PyContext); } _document = context.SourceUnit.Document ?? Ast.SymbolDocument(name, PyContext.LanguageGuid, PyContext.VendorGuid); }
protected override void EmitMatchLogic <TDelegate>(CompilerContext <TDelegate> context, Label success) { context.MatchCharacterClass(charClass, success); }
public TypeSystemServices(CompilerContext context) { if (null == context) { throw new ArgumentNullException("context"); } _context = context; _anonymousCallablesManager = new AnonymousCallablesManager(this); _findImplicitConversionOperator = new MemoizedFunction <IType, IType, IMethod>((fromType, toType) => FindConversionOperator("op_Implicit", fromType, toType)); _findExplicitConversionOperator = new MemoizedFunction <IType, IType, IMethod>((fromType, toType) => FindConversionOperator("op_Explicit", fromType, toType)); My <CurrentScope> .Instance.Changed += (sender, args) => ClearScopeDependentMemoizedFunctions(); _canBeReachedByPromotion = new MemoizedFunction <IType, IType, bool>(CanBeReachedByPromotionImpl); DuckType = Map(typeof(Builtins.duck)); IQuackFuType = Map(typeof(IQuackFu)); VoidType = Map(Types.Void); ObjectType = Map(Types.Object); RegexType = Map(Types.Regex); ValueTypeType = Map(typeof(ValueType)); EnumType = Map(typeof(Enum)); ArrayType = Map(Types.Array); TypeType = Map(Types.Type); StringType = Map(Types.String); BoolType = Map(Types.Bool); SByteType = Map(Types.SByte); CharType = Map(Types.Char); ShortType = Map(Types.Short); IntType = Map(Types.Int); LongType = Map(Types.Long); ByteType = Map(Types.Byte); UShortType = Map(Types.UShort); UIntType = Map(Types.UInt); ULongType = Map(Types.ULong); SingleType = Map(Types.Single); DoubleType = Map(Types.Double); DecimalType = Map(Types.Decimal); TimeSpanType = Map(Types.TimeSpan); DateTimeType = Map(Types.DateTime); RuntimeServicesType = Map(Types.RuntimeServices); BuiltinsType = Map(Types.Builtins); ListType = Map(Types.List); HashType = Map(Types.Hash); ICallableType = Map(Types.ICallable); IEnumerableType = Map(Types.IEnumerable); IEnumeratorType = Map(typeof(IEnumerator)); ICollectionType = Map(Types.ICollection); IDisposableType = Map(typeof(IDisposable)); IntPtrType = Map(Types.IntPtr); UIntPtrType = Map(Types.UIntPtr); MulticastDelegateType = Map(Types.MulticastDelegate); DelegateType = Map(Types.Delegate); SystemAttribute = Map(typeof(Attribute)); ConditionalAttribute = Map(typeof(ConditionalAttribute)); IEnumerableGenericType = Map(Types.IEnumerableGeneric); IEnumeratorGenericType = Map(typeof(IEnumerator <>)); ICollectionGenericType = Map(typeof(ICollection <>)); IListGenericType = Map(typeof(IList <>)); IListType = Map(typeof(IList)); NullableGenericType = Map(Types.Nullable); IAstMacroType = Map(typeof(IAstMacro)); IAstGeneratorMacroType = Map(typeof(IAstGeneratorMacro)); TaskType = Map(typeof(System.Threading.Tasks.Task)); GenericTaskType = Map(typeof(System.Threading.Tasks.Task <>)); AsyncGenericTaskMethodBuilderType = Map(typeof(System.Runtime.CompilerServices.AsyncTaskMethodBuilder <>)); AsyncTaskMethodBuilderType = Map(typeof(System.Runtime.CompilerServices.AsyncTaskMethodBuilder)); AsyncVoidMethodBuilderType = Map(typeof(System.Runtime.CompilerServices.AsyncVoidMethodBuilder)); IAsyncStateMachineType = Map(typeof(System.Runtime.CompilerServices.IAsyncStateMachine)); GenericFuncType = Map(typeof(System.Func <>)); ObjectArrayType = ObjectType.MakeArrayType(1); PreparePrimitives(); PrepareBuiltinFunctions(); }
private void Build(DFor node, Hints hints, CompilerContext ctx) { ctx = new(ctx) { BlockSkip = cw.DefineLabel(), BlockExit = cw.DefineLabel(), BlockBreakExit = cw.DefineLabel() }; if (TryOptimizeFor(node, hints, ctx)) { return; } StartScope(ScopeKind.Loop, node.Location); hints = hints.Remove(Last); var inc = false; if (node.Pattern.NodeType == NodeType.NamePattern && !char.IsUpper(((DNamePattern)node.Pattern).Name[0] !)) { inc = true; } var sys = AddVariable(); var initSkip = cw.DefineLabel(); Build(node.Target, hints.Append(Push), ctx); cw.Briter(initSkip); cw.GetMember(Builtins.Iterate); cw.CallNullaryFunction(); cw.MarkLabel(initSkip); cw.GetIter(); cw.PopVar(sys); var iter = cw.DefineLabel(); cw.MarkLabel(iter); cw.PushVar(new ScopeVar(sys)); cw.CallNullaryFunction(); cw.Brterm(ctx.BlockExit); if (inc) { var ai = AddVariable(((DNamePattern)node.Pattern).Name !, node.Pattern.Location, VarFlags.None); cw.PopVar(ai); } else { BuildPattern(node.Pattern, hints, ctx); cw.Brfalse(ctx.BlockSkip); } if (node.Guard != null) { Build(node.Guard, hints.Append(Push), ctx); cw.Brfalse(ctx.BlockSkip); } var nh = hints.Remove(Push); Build(node.Body, nh, ctx); cw.MarkLabel(ctx.BlockSkip); cw.Br(iter); cw.MarkLabel(ctx.BlockExit); cw.Pop(); cw.PushNil(); AddLinePragma(node); cw.MarkLabel(ctx.BlockBreakExit); PopIf(hints); cw.Nop(); EndScope(); }
public static T TileGetProperty <T>(this uint tile, List <TiledTilesetDefinition> tilesets, CompilerContext context, string propertyName, Func <string, T> converter, bool errorOnNotFound = true, T defaultValue = default(T)) { TiledTilesetDefinition tileset = tilesets.GetTilesetByGlobalTileId(tile); uint relativeTile = tile.TileGetRelativeId(tilesets, context); TiledTile chosenTile = tileset.RealTileset.Tiles.FirstOrDefault(t => t.Id == relativeTile); if (chosenTile == null) { if (errorOnNotFound) { context.ExitError("could not find {0} on tile {1}", propertyName, tile); } context.PushWarning("tile {0} does not have a {1}, assuming {2}", tile, propertyName, defaultValue); return(defaultValue); } if (chosenTile.Properties.PropertyList == null) { if (errorOnNotFound) { context.ExitError("could not find {0} on tile {1}", propertyName, tile); } context.PushWarning("tile {0} does not have a {1}, assuming {2}", tile, propertyName, defaultValue); return(defaultValue); } if (!chosenTile.Properties.PropertyList.Exists(prop => prop.Name == propertyName)) { if (errorOnNotFound) { context.ExitError("could not find {0} on tile {1}", propertyName, tile); } context.PushWarning("tile {0} does not have a {1}, assuming {2}", tile, propertyName, defaultValue); return(defaultValue); } return(chosenTile.Properties.RetrieveProperty(propertyName, context, chosenTile, converter, errorOnNotFound, defaultValue)); }