Exemple #1
1
 public override void Render(SymbolTable symbols, TextWriter tw, object item)
 {
     foreach (var child in Children)
     {
         child.Render(symbols, tw, item);
     }
 }
        public static void ParseProgramOrClass(TextSourceInfo textSourceInfo, ISearchableReadOnlyList<CodeElementsLine> codeElementsLines, TypeCobolOptions compilerOptions, SymbolTable customSymbols, out Program newProgram, out Class newClass, out IList<ParserDiagnostic> diagnostics)
        {
            // Create an Antlr compatible token source on top a the token iterator
            CodeElementsLinesTokenSource tokenSource = new CodeElementsLinesTokenSource(
                textSourceInfo.Name,
                codeElementsLines);

            // Init parser
            ITokenStream tokenStream = new TokensLinesTokenStream(tokenSource, Token.CHANNEL_SourceTokens);
            ProgramClassParser cobolParser = new ProgramClassParser(tokenStream);
            // -> activate full ambiguities detection
            //parser.Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection;

            // Register all parse errors in a list in memory
            DiagnosticSyntaxErrorListener errorListener = new DiagnosticSyntaxErrorListener();
            cobolParser.RemoveErrorListeners();
            cobolParser.AddErrorListener(errorListener);

            // Try to parse a Cobol program or class
            ProgramClassParser.CobolCompilationUnitContext codeElementParseTree = cobolParser.cobolCompilationUnit();

            // Visit the parse tree to build a first class object representing a Cobol program or class
            ParseTreeWalker walker = new ParseTreeWalker();
            CobolNodeBuilder programClassBuilder = new CobolNodeBuilder();
            programClassBuilder.CustomSymbols = customSymbols;
            programClassBuilder.Dispatcher = new NodeDispatcher();
            programClassBuilder.Dispatcher.CreateListeners();
            walker.Walk(programClassBuilder, codeElementParseTree);

            // Register compiler results
            newProgram = programClassBuilder.Program;
            newClass = programClassBuilder.Class;
            diagnostics = errorListener.Diagnostics;
        }
        public void AddValue_Correct_Test()
        {
            symbolTable = new SymbolTable();
            symbolTable.AddValue(id, new Bool(false));

            Assert.IsNotNull(symbolTable.GetValue(id));
        }
Exemple #4
0
		internal LoadLocalAddress(SymbolTable symbols, MethodDefinition method, Instruction untyped, int index) : base(untyped, index)
		{			
			switch (untyped.OpCode.Code)
			{
				case Code.Ldloca_S:
				case Code.Ldloca:
					VariableDefinition param = untyped.Operand as VariableDefinition;
					if (param != null)
					{
						Variable = param.Index;
						Type = param.VariableType;
					}
					else
					{
						Variable = (int) untyped.Operand;
						Type = method.Body.Variables[Variable].VariableType;
					}
					Name = symbols.LocalName(method, untyped, Variable);
					break;
										
				default:
					DBC.Fail(untyped.OpCode.Code + " is not a valid LoadLocalAddress");
					break;
			}
			
			RealName = symbols.HaveLocalNames(method);
		}
Exemple #5
0
        private bool ProcessExpression(SymbolTable symbolTable)
        {
            // TODO: If there are performance problems, we could find a faster way to detect expressions than doing a full parse
            var tokenSequence = new TokenSequence(XValue);

            if (tokenSequence.RequiresProcessing)
            {
                if (tokenSequence.RequiresTemplateArguments)
                {
                    var templateInstance = TemplateInstance;
                    if (templateInstance == null || templateInstance.Template == null)
                    {
                        return false;
                    }

                    XValue = tokenSequence.Process(symbolTable, templateInstance.ArgumentDictionary);
                }
                else
                {
                    XValue = tokenSequence.Process(symbolTable, null);
                }
            }

            return true;
        }
Exemple #6
0
 /// <summary>
 /// Constructs an empty rule builder.
 /// </summary>
 public RuleBuilder()
 {
     var rootScope = new SymbolTable();
     _dependencyBuilder = new DependencyGroupBuilder(rootScope);
     _groupBuilder = new GroupBuilder(rootScope, GroupType.And);
     _actionGroupBuilder = new ActionGroupBuilder(rootScope);
 }
        public void Insert_Lookup_WriteTable_SymbolTableTest()
        {
            var count = 0;
            var symTable = new SymbolTable();
            symTable.Printer = (val) => { count++; };

            symTable.Insert(Token.CreateToken("x", 0), 0);
            symTable.Insert(Token.CreateToken("y", 0), 0);
            symTable.Insert(Token.CreateToken("z", 0), 0);

            symTable.Lookup("x").Content = CreateVariableContent();
            symTable.Lookup("y").Content = CreateVariableContent();
            symTable.Lookup("z").Content = CreateVariableContent();

            symTable.Insert(Token.CreateToken("a", 0), 1);
            symTable.Insert(Token.CreateToken("x", 0), 1);
            symTable.Insert(Token.CreateToken("y", 0), 1);
            symTable.Insert(Token.CreateToken("z", 0), 1);

            symTable.Lookup("a").Content = CreateVariableContent();
            symTable.Lookup("x").Content = CreateVariableContent();
            symTable.Lookup("y").Content = CreateVariableContent();
            symTable.Lookup("z").Content = CreateVariableContent();

            symTable.WriteTable(0);
            Assert.AreEqual(3, count);

            count = 0;
            symTable.WriteTable(1);
            Assert.AreEqual(4, count);

            count = 0;
            symTable.WriteTable(2);
            Assert.AreEqual(0, count);
        }
 public NameExpression(
     IExpression identifier,
     SymbolTable<string, IValue> symbolTable)
 {
     _identifier = identifier;
     _symbolTable = symbolTable;
 }
Exemple #9
0
        public bool Init(ErrorHandling errorContext, SymbolTable symtable)
        {
            _runtimeBinderSymbolTable = symtable;
            Debug.Assert(_pBSymmgr != null);

#if !CSEE
            Debug.Assert(_predefSyms == null);
#else // CSEE
            Debug.Assert(predefSyms == null || aidMsCorLib != KAID.kaidNil);
#endif // CSEE

            if (_aidMsCorLib == KAID.kaidNil)
            {
                // If we haven't found mscorlib yet, first look for System.Object. Then use its assembly as
                // the location for all other pre-defined types.
                AggregateSymbol aggObj = FindPredefinedType(errorContext, PredefinedTypeFacts.GetName(PredefinedType.PT_OBJECT), KAID.kaidGlobal, AggKindEnum.Class, 0, true);
                if (aggObj == null)
                    return false;
                _aidMsCorLib = aggObj.GetAssemblyID();
            }

            _predefSyms = new AggregateSymbol[(int)PredefinedType.PT_COUNT];
            Debug.Assert(_predefSyms != null);

            return true;
        }
Exemple #10
0
        static void Main(string[] args)
        {
            while(true)
            {
                Console.Write("WinLisp>> ");
                string input = Console.ReadLine();

                // Scan input
                var tokens = Scanner.scan_input(input);

                if (tokens.left == null) { Console.WriteLine(tokens.right.ToString()); continue; }

                foreach (var token in tokens.left) Console.WriteLine(token.ToString());

                // Parse Input
                var funcalls = Parser.parse_tokens(tokens.left);

                if (funcalls.left == null) foreach (var error in funcalls.right) { Console.WriteLine(error.ToString()); continue; }

                foreach (var funcall in funcalls.left) Console.WriteLine(funcall.ToString());

                // Evaluate Input
                foreach (var call in funcalls.left)
                {
                    var result = Evaluator.evaluate_FunCall(table, call);

                    if (result?.left == null) { Console.WriteLine(result.right.ToString()); continue; }

                    Console.WriteLine(result.left.Item2.ToString());
                    table = result.left.Item1;

                }
            }
        } // End of Main
Exemple #11
0
 public NestedProgram(Program containingProgram)
 {
     IsNested = true;
     ContainingProgram = containingProgram;
     SymbolTable = new SymbolTable(containingProgram.SymbolTable);
     SyntaxTree.Root.SymbolTable = SymbolTable;
 }
        public void Instantiate(SymbolTable symbolTable, UnboundReferences unboundReferences)
        {
            var parentEtl = ParentItem as AstEtlRootNode;
            var transformationTemplate = Template as AstTransformationTemplateNode;
            var clonedMapping = new Dictionary<IFrameworkItem, IFrameworkItem>();
            if (transformationTemplate != null && parentEtl != null)
            {
                var clonedTransformations = new List<AstTransformationNode>();
                foreach (var transformation in transformationTemplate.Transformations)
                {
                    clonedTransformations.Add((AstTransformationNode)transformation.Clone(parentEtl, clonedMapping));
                }

                parentEtl.Transformations.Replace(this, clonedTransformations);
            }

            foreach (var bindingItem in transformationTemplate.UnboundReferences)
            {
                var clonedBindingItem = new BindingItem(
                    bindingItem.BoundProperty,
                    bindingItem.XObject,
                    bindingItem.XValue,
                    clonedMapping[bindingItem.ParentItem],
                    bindingItem.BimlFile,
                    this);
                unboundReferences.Add(clonedBindingItem);
            }
        }
Exemple #13
0
        public Pascal(String operation, String filePath, String flags)
        {
            try{
                bool intermediate = flags.IndexOf('i') > 1;
                bool xref = flags.IndexOf('x') > 1;
                source = new Source(new StreamReader(filePath));
                source.AddMessageListener(new SourceMessageListener());

                parser = FrontEndFactory.CreateParser("pascal","top-down",source);
                parser.AddMessageListener(new ParserMessageListener());

                backend = BackendFactory.CreateBackend("compile");
                backend.AddMessageListener(new BackendMessageListener());

                parser.Parse();
                source.close();

                intermediateCode = parser.IntermediateCode;
                symbolTable = Parser.SymbolTable;

                backend.Process(intermediateCode,symbolTable);
            }
            catch(Exception ex){
                Console.WriteLine ("Internal translation error");
                Console.WriteLine (ex.StackTrace);
            }
        }
 public TypeCheckerVisitor(ErrorHandler errors, StmtList statements)
 {
     Errors = errors;
     SymbolTable = new SymbolTable();
     Checker = new TypeChecker(errors);
     RootStmtList = statements;
 }
Exemple #15
0
        /// <summary>
        /// Creates a new object code file object.
        /// </summary>
        /// <param name="StartAddress">The load address of the object file.</param>
        /// <param name="Filename">The name of the object file.</param>
        /// <param name="Architecture">The targeted architecture of the object file.</param>
        /// <param name="Sections">The sections of the object file.</param>
        /// <param name="SymbolTable">The symbol table of the object file.</param>
        /// <param name="Code">The source code of the object file.</param>
        public ObjectCodeFile(long StartAddress, String Filename, String Architecture,
            Section[] Sections, SymbolTable SymbolTable, CodeUnit[] Code)
        {
            this.loadAddress  = StartAddress;
            this.Filepath     = Filename;
            this.Architecture = Architecture;
            this.Sections     = Sections;
            this.SymbolTable  = SymbolTable;
            this.Code         = Code;

            this.RequestedLoadAddress = StartAddress;

            // Sum loaded sections' sizes
            if (this.Sections != null)
            this.Size = this.Sections.Sum(
                sec => sec.Flags.HasFlag(SectionFlags.Load) ? (long)sec.Size : 0);

            // Get unique source file paths
            var tmpFiles = new HashSet<string>();

            foreach (CodeUnit unit in this.Code) {
                tmpFiles.Add(unit.SourceFilepath.Trim());
            }
            this.SourceFiles = tmpFiles.ToArray();
        }
        public void Instantiate(SymbolTable symbolTable, UnboundReferences unboundReferences)
        {
            var rootNode = ParentItem as AstRootNode;
            var tableTemplate = Template as AstTableTemplateNode;
            var clonedMapping = new Dictionary<IFrameworkItem, IFrameworkItem>();
            if (tableTemplate != null && rootNode != null)
            {
                var clonedTable = (AstTableNode)tableTemplate.Table.Clone(rootNode, clonedMapping);
                clonedTable.Emit = this.Emit;

                // TODO: Some of the ViewModel stuff might not fully support Replace - so simulating with Remove and Insert
                int index = rootNode.Tables.IndexOf(this);
                rootNode.Tables.Remove(this);
                rootNode.Tables.Insert(index, clonedTable);
            }

            foreach (var bindingItem in tableTemplate.UnboundReferences)
            {
                var clonedBindingItem = new BindingItem(
                    bindingItem.BoundProperty,
                    bindingItem.XObject,
                    bindingItem.XValue,
                    clonedMapping[bindingItem.ParentItem],
                    bindingItem.BimlFile,
                    this);
                unboundReferences.Add(clonedBindingItem);
            }
        }
Exemple #17
0
        public override object Execute(SymbolTable table)
        {
            base.Execute(table);
            StatementList.Execute(table);

            return null;
        }
Exemple #18
0
 public ReplWindow()
 {
     this.Width = 450;
     this.Height = 350;
     this.Title = "YACQ Console";
     this.Content = this.textBox;
     this.textBox.AcceptsReturn = true;
     this.textBox.BorderThickness = new Thickness(0);
     this.textBox.FontFamily = new FontFamily("Consolas");
     this.textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
     this.textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
     this.textBox.TextWrapping = TextWrapping.Wrap;
     this.textBox.Text = string.Format("YACQ {0} on Krile {1}\r\n", YacqServices.Version, typeof(App).Assembly.GetName().Version);
     this.textBox.Select(this.textBox.Text.Length, 0);
     this.textBox.PreviewKeyDown += this.textBox_PreviewKeyDown;
     this.symbolTable = new SymbolTable(typeof(Symbols))
     {
         {"*textbox*", YacqExpression.Constant(textBox)},
     };
     var rcPath = Path.Combine(
         Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
         "yacq_lib\\rc.yacq"
     );
     if(File.Exists(rcPath))
     {
         YacqServices.ParseAll(this.symbolTable, File.ReadAllText(rcPath))
             .ForEach(e => YacqExpression.Lambda(e).Compile().DynamicInvoke());
         this.textBox.AppendText("rc.yacq was loaded.\r\n");
     }
     this.textBox.AppendText(">>> ");
 }
        public void Instantiate(SymbolTable symbolTable, UnboundReferences unboundReferences)
        {
            var parentContainer = ParentItem as AstContainerTaskBaseNode;
            var taskTemplate = Template as AstTaskTemplateNode;
            var clonedMapping = new Dictionary<IFrameworkItem, IFrameworkItem>();
            if (taskTemplate != null && parentContainer != null)
            {
                var clonedTasks = new List<AstTaskNode>();
                foreach (var task in taskTemplate.Tasks)
                {
                    clonedTasks.Add((AstTaskNode)task.Clone(parentContainer, clonedMapping));
                }

                parentContainer.Tasks.Replace(this, clonedTasks);
            }

            foreach (var bindingItem in taskTemplate.UnboundReferences)
            {
                var clonedBindingItem = new BindingItem(
                    bindingItem.BoundProperty,
                    bindingItem.XObject,
                    bindingItem.XValue,
                    clonedMapping[bindingItem.ParentItem],
                    bindingItem.BimlFile,
                    this);
                unboundReferences.Add(clonedBindingItem);
            }
        }
        public override void GenerateCode(FileManager fileManager, SymbolTable symbolTable, CodeGeneratorHelper codeGeneratorHelper)
        {
            AppendNodeComment(fileManager);

            // Check condition
            this._children[0].GenerateCode(fileManager, symbolTable, codeGeneratorHelper);

            // If the condition is false, jump to the else-statement (exit label if else-statement is null)
            string elseLabel = codeGeneratorHelper.GenerateNextLabel();
            fileManager.Output.Append(Macro.JumpOnFalse(elseLabel));

            // Then-statement
            this._children[1].GenerateCode(fileManager, symbolTable, codeGeneratorHelper);

            // On existing else-statement jump over it
            string outLabel = null;
            if (this._children[2] != null)
            {
                outLabel = codeGeneratorHelper.GenerateNextLabel();
                fileManager.Output.Append(Macro.Jump(outLabel));
            }

            // Generate else label
            fileManager.Output.Append(Macro.Label(elseLabel));

            // Else-statement and exit label
            if (this._children[2] != null)
            {
                this._children[2].GenerateCode(fileManager, symbolTable, codeGeneratorHelper);
                fileManager.Output.Append(Macro.Label(outLabel));
            }
        }
        public override void GenerateCode(FileManager fileManager, SymbolTable symbolTable, CodeGeneratorHelper codeGeneratorHelper)
        {
            AppendNodeComment(fileManager);

            // Initialization assignment
            this._children[0].GenerateCode(fileManager, symbolTable, codeGeneratorHelper);

            // Generate loop start label
            string startLabel = codeGeneratorHelper.GenerateNextLabel();
            fileManager.Output.Append(Macro.Label(startLabel));

            // Check condition and jump out if false
            this._children[1].GenerateCode(fileManager, symbolTable, codeGeneratorHelper);
            string outLabel = codeGeneratorHelper.GenerateNextLabel();
            fileManager.Output.Append(Macro.JumpOnFalse(outLabel));

            // Loop body
            this._children[3].GenerateCode(fileManager, symbolTable, codeGeneratorHelper);

            // Altering assignment
            this._children[2].GenerateCode(fileManager, symbolTable, codeGeneratorHelper);

            // Jump back to condition check
            fileManager.Output.Append(Macro.Jump(startLabel));

            // Generate loop end label
            fileManager.Output.Append(Macro.Label(outLabel));
        }
Exemple #22
0
        public static EvalResult evaluate_System_Function(SymbolTable symbols, FunCall fun_call)
        {
            var fun_name = fun_call.value.value;
            EvalFunc f = (s,func) => new EvalResult(new Error(fun_call.value.line_num, "Could not match system function!"));

            switch (fun_name)
            {
                case "define": f = add_definition;  break;
                case "+": f = addition;             break;
                case "-": f = subtraction;          break;
                case "*": f = multiplication;       break;
                case "/": f = division;             break;
                case "%": f = mod;                  break;
                case "head": f = head;              break;
                case "tail": f = tail;              break;
                case "++": f = cons;                break;
                case "==": f = equality_test;       break;
                case "not": f = not;                break;
                case "&&": f = logical_and;         break;
                case "||": f = logical_or;          break;
                case "<": f = less_than;            break;
                case ">": f = greater_than;         break;
            }

            return f(symbols, fun_call);
        }
Exemple #23
0
        public void CreateProgram(string moduleName)
        {
            AssemblyName name = new AssemblyName(Path.GetFileNameWithoutExtension(moduleName));
            var asmb = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Save);

            ModuleBuilder modb = asmb.DefineDynamicModule(moduleName);

            var type = modb.DefineType("$program");

            var symbolTable = new SymbolTable(type);

            symbolTable.AddFunctionHeader("$main", MethodAttributes.Static, null, new FunctionDefinition.Argument[] { },"$program");

            var il = symbolTable.functionTable["$main"].GetILGenerator();

            Program.GenerateIL(il, symbolTable);

            il.Emit(OpCodes.Ret);

            modb.CreateGlobalFunctions();
            asmb.SetEntryPoint(symbolTable.functionTable["$main"].methodDefinition);

            symbolTable.typeTable.types[0].typeBuilder.CreateType();

            asmb.Save(moduleName);
        }
Exemple #24
0
        public static void ProcessIsNullPatcherTransformations(SymbolTable symbolTable)
        {
            var snapshotSymbolTable = new List<IReferenceableItem>(symbolTable);
            foreach (var astNamedNode in snapshotSymbolTable)
            {
                var nullPatcherNode = astNamedNode as AstIsNullPatcherNode;
                if (nullPatcherNode != null && astNamedNode.FirstThisOrParent<ITemplate>() == null)
                {
                    var astDerivedColumnListNode = new AstDerivedColumnListNode(nullPatcherNode.ParentItem)
                                                       {
                                                           Name = nullPatcherNode.Name,
                                                           ValidateExternalMetadata = nullPatcherNode.ValidateExternalMetadata
                                                       };

                    foreach (AstIsNullPatcherColumnNode patchColumn in nullPatcherNode.Columns)
                    {
                        var column = new AstDerivedColumnNode(astDerivedColumnListNode)
                                         {
                                             Name = patchColumn.Name,
                                             ReplaceExisting = true,
                                             Expression = String.Format(CultureInfo.InvariantCulture, "ISNULL({0}) ? {1} : {0}", patchColumn.Name, patchColumn.DefaultValue),
                                             DerivedColumnType = VulcanEngine.IR.Ast.ColumnType.Object
                                         };
                        astDerivedColumnListNode.Columns.Add(column);
                    }

                    Utility.Replace(nullPatcherNode, new List<AstTransformationNode> { astDerivedColumnListNode });
                }
            }
        }
 private void Check(CodeElement e, SymbolTable table, FunctionCall call, FunctionDeclaration definition)
 {
     var parameters = definition.Profile.Parameters;
     if (call.InputParameters.Count > parameters.Count) {
     var m = System.String.Format("Function {0} only takes {1} parameters", definition.Name, parameters.Count);
     DiagnosticUtils.AddError(e, m);
     }
     for (int c = 0; c < parameters.Count; c++) {
     var expected = parameters[c];
     if (c < call.InputParameters.Count) {
         var actual = call.InputParameters[c];
         if (actual.IsLiteral) continue;
         var found = table.GetVariable(new URI(actual.Value));
         if (found.Count < 1) DiagnosticUtils.AddError(e, "Parameter "+actual.Value+" is not referenced");
         if (found.Count > 1) DiagnosticUtils.AddError(e, "Ambiguous reference to parameter "+actual.Value);
         if (found.Count!= 1) continue;
         var type = found[0] as Typed;
         // type check. please note:
         // 1- if only one of [actual|expected] types is null, overriden DataType.!= operator will detect it
         // 2- if both are null, we WANT it to break: in TypeCobol EVERYTHING should be typed,
         //    and things we cannot know their type as typed as DataType.Unknown (which is a non-null valid type).
         if (type == null || type.DataType != expected.DataType) {
             var m = System.String.Format("Function {0} expected parameter {1} of type {2} (actual: {3})", definition.Name, c+1, expected.DataType, type.DataType);
             DiagnosticUtils.AddError(e, m);
         }
         if (type != null && type.Length > expected.Length) {
             var m = System.String.Format("Function {0} expected parameter {1} of max length {2} (actual: {3})", definition.Name, c+1, expected.Length, type.Length);
             DiagnosticUtils.AddError(e, m);
         }
     } else {
         var m = System.String.Format("Function {0} is missing parameter {1} of type {2}", definition.Name, c+1, expected.DataType);
         DiagnosticUtils.AddError(e, m);
     }
     }
 }
 public override void GenerateIL(ILGenerator il, SymbolTable st)
 {
     LocalSymbolTable = new SymbolTable(st);
     foreach(var statement in Block)
     {
         statement.GenerateIL(il, LocalSymbolTable);
     }
 }
        public override void GenerateCode(FileManager fileManager, SymbolTable symbolTable, CodeGeneratorHelper labelHelper)
        {
            AppendNodeComment(fileManager);

            SyntaxTreeDeclarationNode declNode = symbolTable.GetDeclarationNodeLinkToSymbol(this.Identifier) as SyntaxTreeDeclarationNode;

            fileManager.Output.Append(Macro.LoadAccu(declNode.GetMemoryAddress()));
        }
Exemple #28
0
 public Context()
 {
     SourceCode = String.Empty;
     GlobalVarList = null;
     execFlagList = null;
     symbolTable = null;
     exprExecutionFlags = new Dictionary<int, bool>();
 }
        public void Is_In_Table_Test()
        {
            symbolTable = new SymbolTable();

            AddValue_Correct_Test();

            Assert.IsTrue(symbolTable.IsInTable(id));
        }
 public virtual void GenerateCode(FileManager fileManager, SymbolTable symbolTable, CodeGeneratorHelper labelHelper)
 {
     foreach (var node in this._children)
     {
         if (node != null)
             node.GenerateCode(fileManager, symbolTable, labelHelper);
     }
 }
Exemple #31
0
 public override TreeNode GetAstCodeGenerator(SymbolTable t)
 {
     MIPSCodeGenerator.Loop w = new MIPSCodeGenerator.Loop((MIPSCodeGenerator.Expression)condition.GetAstCodeGenerator(t), (MIPSCodeGenerator.Expression)body.GetAstCodeGenerator(t));
     SetGeneratorType(w);
     return(w);
 }
Exemple #32
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return(LeftNode.Evaluate(table) % RightNode.Evaluate(table));
 }
Exemple #33
0
        /// <summary>
        /// Adds a label (an integer value) to the symbol table and to the graph element.
        /// </summary>
        /// <param name="table"> the symbol table </param>
        /// <param name="code"> a label code </param>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addLabel(org.maltparser.core.symbol.SymbolTable table, int code) throws org.maltparser.core.exception.MaltChainedException
        public void addLabel(SymbolTable table, int code)
        {
            addLabel(table, table.getSymbolCodeToString(code));
        }
Exemple #34
0
 public ProgNodeContext()
 {
     this.SymTable = new SymbolTable();
 }
Exemple #35
0
 public void Start(SymbolTable t)
 {
 }
Exemple #36
0
        private IFrontEndController CreateControllerWithDebugger(PathTable pathTable, SymbolTable symbolTable)
        {
            var confPort                  = Configuration.FrontEnd.DebuggerPort();
            var debugServerPort           = confPort != 0 ? confPort : DebugServer.DefaultDebugPort;
            var pathTranslator            = GetPathTranslator(Configuration.Logging, pathTable);
            var debugServer               = new DebugServer(LoggingContext, pathTable, pathTranslator, debugServerPort);
            Task <IDebugger> debuggerTask = debugServer.StartAsync();
            var evaluationDecorator       = new LazyDecorator(debuggerTask, Configuration.FrontEnd.DebuggerBreakOnExit());
            var frontEndFactory           = new FrontEndFactory();

            frontEndFactory.AddPhaseStartHook(EnginePhases.Evaluate, () =>
            {
                if (!debuggerTask.IsCompleted)
                {
                    Logger.Log.WaitingForClientDebuggerToConnect(LoggingContext, debugServer.Port);
                }

                debuggerTask.Result?.Session.WaitSessionInitialized();
            });

            frontEndFactory.AddPhaseEndHook(EnginePhases.Evaluate, () =>
            {
                // make sure the debugger is shut down at the end (unnecessary in most cases, as the debugger will shut itself down after completion)
                debugServer.ShutDown();
                debuggerTask.Result?.ShutDown();
            });

            return(TryCreateFrontEndController(
                       frontEndFactory,
                       evaluationDecorator,
                       Configuration,
                       symbolTable,
                       LoggingContext,
                       Collector,
                       collectMemoryAsSoonAsPossible: CollectMemoryAsSoonAsPossible,
                       statistics: m_statistics));
        }
Exemple #37
0
        private IFrontEndController CreateControllerWithProfiler(PathTable pathTable, SymbolTable symbolTable)
        {
            var frontEndFactory   = new FrontEndFactory();
            var profilerDecorator = new ProfilerDecorator();

            // When evaluation is done we materialize the result of the profiler
            frontEndFactory.AddPhaseEndHook(EnginePhases.Evaluate, () =>
            {
                var entries           = profilerDecorator.GetProfiledEntries();
                var materializer      = new ProfilerMaterializer(pathTable);
                var reportDestination = Configuration.FrontEnd.ProfileReportDestination(pathTable);

                Logger.Log.MaterializingProfilerReport(LoggingContext, reportDestination.ToString(pathTable));

                try
                {
                    materializer.Materialize(entries, reportDestination);
                }
                catch (BuildXLException ex)
                {
                    Logger.Log.ErrorMaterializingProfilerReport(LoggingContext, ex.LogEventErrorCode, ex.LogEventMessage);
                }
            });

            return(TryCreateFrontEndController(
                       frontEndFactory,
                       profilerDecorator,
                       Configuration,
                       symbolTable,
                       LoggingContext,
                       Collector,
                       collectMemoryAsSoonAsPossible: CollectMemoryAsSoonAsPossible,
                       statistics: m_statistics));
        }
 public static bool TryFormat(this Guid value, Span <byte> buffer, out int bytesWritten, ParsedFormat format = default, SymbolTable symbolTable = null)
 => CustomFormatter.TryFormat(value, buffer, out bytesWritten, format, symbolTable);
Exemple #39
0
 internal DependencyGroupBuilder(SymbolTable scope)
     : base(scope)
 {
 }
        public bool TryFormat(Span <byte> buffer, out int bytesWritten, ParsedFormat format, SymbolTable symbolTable)
        {
            if (!PrimitiveFormatter.TryFormat(_age, buffer, out bytesWritten, format, symbolTable))
            {
                return(false);
            }

            char symbol = _inMonths ? 'm' : 'y';

            if (!symbolTable.TryEncode((byte)symbol, buffer.Slice(bytesWritten), out int written))
            {
                return(false);
            }

            bytesWritten += written;
            return(true);
        }
 internal void SetSymbolTable(SymbolTable symbolTable)
 {
     RuntimeBinderSymbolTable = symbolTable;
 }
Exemple #42
0
 static void Validate <T>(long value, StandardFormat format, SymbolTable symbolTable)
 {
     Validate <T>(unchecked ((ulong)value), format, symbolTable);
 }
Exemple #43
0
        public void SetUp()
        {
            IBlacklistManager blacklistManager = new IDbCommandBlacklistManagerStub();

            _symbolTable = new SymbolTable(blacklistManager);
        }
Exemple #44
0
 public PipelineTextOutput(PipeWriter writer, SymbolTable symbolTable)
 {
     _writer     = writer;
     SymbolTable = symbolTable;
 }
 public StylesheetTask(string stylesheetText, SymbolTable symbolTable)
 {
     StylesheetText = stylesheetText;
     QLSymbolTable  = symbolTable;
 }
Exemple #46
0
 public abstract object Eval(SymbolTable vartable);
Exemple #47
0
 public void EscapeScope(SymbolTable t)
 {
 }
Exemple #48
0
 public void EscapeScope(SymbolTable t)
 {
     IntermediateCode.CurrentIO.EmitBlock("}");
 }
Exemple #49
0
        public void ProcessDeclaration(Decl declaration, IPlatform platform, TypeLibraryDeserializer tldser, SymbolTable symbolTable)
        {
            var types        = symbolTable.AddDeclaration(declaration);
            var type         = types[0];
            int?vectorOffset = GetVectorOffset(declaration);

            if (vectorOffset.HasValue)
            {
                var ntde = new NamedDataTypeExtractor(platform, declaration.decl_specs, symbolTable);
                foreach (var declarator in declaration.init_declarator_list)
                {
                    var nt   = ntde.GetNameAndType(declarator.Declarator);
                    var ssig = (SerializedSignature)nt.DataType;
                    if (ssig.ReturnValue != null)
                    {
                        ssig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes(
                            "returns", declaration.attribute_list);
                    }
                    var sser = new ProcedureSerializer(platform, tldser, platform.DefaultCallingConvention);
                    var sig  = sser.Deserialize(ssig, platform.Architecture.CreateFrame());
                    SystemServices.Add(
                        vectorOffset.Value,
                        new SystemService
                    {
                        Name        = nt.Name,
                        SyscallInfo = new SyscallInfo
                        {
                            Vector = vectorOffset.Value,
                        },
                        Signature = sig,
                    });
                }
            }
        }
Exemple #50
0
 public ExpNameDiscovery(SymbolTable syms)
 {
     this.syms = syms;
 }
 public TemplateContext()
 {
     _globalSymbolTable = new SymbolTable();
     _symbolTablestack.Push(_globalSymbolTable);
     _astGeneratorFunc = (snippet, errorfn) => new CachingLiquidASTGenerator(new LiquidASTGenerator()).Generate(snippet, errorfn);
 }
        public static void CupParseProgramOrClass(TextSourceInfo textSourceInfo, ISearchableReadOnlyList <CodeElementsLine> codeElementsLines, TypeCobolOptions compilerOptions, SymbolTable customSymbols, PerfStatsForParserInvocation perfStatsForParserInvocation, out SourceFile root, out List <Diagnostic> diagnostics, out Dictionary <CodeElement, Node> nodeCodeElementLinkers)
        {
            PrepareCupParser();
#if DEBUG_ANTRL_CUP_TIME
            var t1 = DateTime.UtcNow;
#endif
            CodeElementTokenizer             scanner = new CodeElementTokenizer(codeElementsLines);
            CupParser.TypeCobolProgramParser parser  = new CupParser.TypeCobolProgramParser(scanner);
            CupParserTypeCobolProgramDiagnosticErrorReporter diagReporter = new CupParserTypeCobolProgramDiagnosticErrorReporter();
            parser.ErrorReporter = diagReporter;
            ProgramClassBuilder builder = new ProgramClassBuilder();
            parser.Builder = builder;
            ParserDiagnostic programClassBuilderError = null;

            builder.SyntaxTree    = new SyntaxTree <CodeElement>(); //Initializie SyntaxTree for the current source file
            builder.CustomSymbols = customSymbols;
            builder.Dispatcher    = new NodeDispatcher <CodeElement>();
            builder.Dispatcher.CreateListeners();

            // Try to parse a Cobol program or class, with cup w are also building the The Syntax Tree Node
            perfStatsForParserInvocation.OnStartParsing();
            try
            {
                TUVienna.CS_CUP.Runtime.Symbol symbol = parser.parse();
            }
            catch (Exception ex)
            {
                var code = Diagnostics.MessageCode.ImplementationError;
                programClassBuilderError = new ParserDiagnostic(ex.ToString(), null, null, code, ex);
            }
            perfStatsForParserInvocation.OnStopParsing(0, 0);

#if DEBUG_ANTRL_CUP_TIME
            var t2 = DateTime.UtcNow;
            var t  = t2 - t1;
            System.Diagnostics.Debug.WriteLine("Time[" + textSourceInfo.Name + "];" + t.Milliseconds);
#endif
            root = builder.SyntaxTree.Root; //Set output root node

            perfStatsForParserInvocation.OnStartTreeBuilding();

            //Create link between data definition an Types, will be stored in SymbolTable
            root.AcceptASTVisitor(new TypeCobolLinker());

            //Stop measuring tree building performance
            perfStatsForParserInvocation.OnStopTreeBuilding();

            // Register compiler results
            diagnostics            = diagReporter.Diagnostics ?? new List <Diagnostic>();
            nodeCodeElementLinkers = builder.NodeCodeElementLinkers;

            if (programClassBuilderError != null)
            {
                diagnostics.Add(programClassBuilderError);
            }
        }
Exemple #53
0
 public FhirPathCompiler(SymbolTable symbols)
 {
     Symbols = symbols;
 }
Exemple #54
0
        public static bool TryParseUInt16(ReadOnlySpan <byte> text, out ushort value, out int bytesConsumed, StandardFormat format = default, SymbolTable symbolTable = null)
        {
            symbolTable = symbolTable ?? SymbolTable.InvariantUtf8;

            if (!format.IsDefault && format.HasPrecision)
            {
                throw new NotImplementedException("Format with precision not supported.");
            }

            if (symbolTable == SymbolTable.InvariantUtf8)
            {
                if (Parsers.IsHexFormat(format))
                {
                    return(Utf8Parser.TryParse(text, out value, out bytesConsumed, 'X'));
                }
                else
                {
                    return(Utf8Parser.TryParse(text, out value, out bytesConsumed));
                }
            }
            else if (symbolTable == SymbolTable.InvariantUtf16)
            {
                ReadOnlySpan <char> utf16Text = text.NonPortableCast <byte, char>();
                int  charactersConsumed;
                bool result;
                if (Parsers.IsHexFormat(format))
                {
                    result = Utf16Parser.Hex.TryParseUInt16(utf16Text, out value, out charactersConsumed);
                }
                else
                {
                    result = Utf16Parser.TryParseUInt16(utf16Text, out value, out charactersConsumed);
                }
                bytesConsumed = charactersConsumed * sizeof(char);
                return(result);
            }

            if (Parsers.IsHexFormat(format))
            {
                throw new NotImplementedException("The only supported encodings for hexadecimal parsing are InvariantUtf8 and InvariantUtf16.");
            }

            if (!(format.IsDefault || format.Symbol == 'G' || format.Symbol == 'g'))
            {
                throw new NotImplementedException(String.Format("Format '{0}' not supported.", format.Symbol));
            }
            if (!symbolTable.TryParse(text, out SymbolTable.Symbol nextSymbol, out int thisSymbolConsumed))
            {
                value         = default;
                bytesConsumed = 0;
                return(false);
            }

            if (nextSymbol > SymbolTable.Symbol.D9)
            {
                value         = default;
                bytesConsumed = 0;
                return(false);
            }

            uint parsedValue = (uint)nextSymbol;
            int  index       = thisSymbolConsumed;

            while (index < text.Length)
            {
                bool success = symbolTable.TryParse(text.Slice(index), out nextSymbol, out thisSymbolConsumed);
                if (!success || nextSymbol > SymbolTable.Symbol.D9)
                {
                    bytesConsumed = index;
                    value         = (ushort)parsedValue;
                    return(true);
                }

                // If parsedValue > (ushort.MaxValue / 10), any more appended digits will cause overflow.
                // if parsedValue == (ushort.MaxValue / 10), any nextDigit greater than 5 implies overflow.
                if (parsedValue > ushort.MaxValue / 10 || (parsedValue == ushort.MaxValue / 10 && nextSymbol > SymbolTable.Symbol.D5))
                {
                    bytesConsumed = 0;
                    value         = default;
                    return(false);
                }

                index      += thisSymbolConsumed;
                parsedValue = parsedValue * 10 + (uint)nextSymbol;
            }

            bytesConsumed = text.Length;
            value         = (ushort)parsedValue;
            return(true);
        }
Exemple #55
0
 /// <summary>
 /// Initializes dictionary and sets the SymbolTable instance to use
 /// </summary>
 /// <param name="symbolTable">Used to convert between strings and FullSymbols</param>
 /// <param name="concurrencyLevel">This setting affects the number of locks that the dictionary is using; default value is 32</param>
 /// <param name="initialCapacity">Initial capacity of the collection; default value is 31</param>
 public FullSymbolConcurrentDictionary(SymbolTable symbolTable, int concurrencyLevel = 32, int initialCapacity = 31)
 {
     m_fullSymbolsToValues = new ConcurrentDictionary <FullSymbol, TValue>(concurrencyLevel, initialCapacity);
     m_symbolTable         = symbolTable;
 }
        static void Run(CodeGeneratorOptions options, DirectoryAssemblyResolver resolver)
        {
            string assemblyQN              = options.AssemblyQualifiedName;
            string api_level               = options.ApiLevel;
            int    product_version         = options.ProductVersion;
            bool   preserve_enums          = options.PreserveEnums;
            string csdir                   = options.ManagedCallableWrapperSourceOutputDirectory ?? "cs";
            string javadir                 = "java";
            string enumdir                 = options.EnumOutputDirectory ?? "enum";
            string enum_metadata           = options.EnumMetadataOutputFile ?? "enummetadata";
            var    references              = options.AssemblyReferences;
            string enum_fields_map         = options.EnumFieldsMapFile;
            string enum_flags              = options.EnumFlagsFile;
            string enum_methods_map        = options.EnumMethodsMapFile;
            var    fixups                  = options.FixupFiles;
            string api_versions_xml        = options.ApiVersionsXmlFile;
            var    annotations_zips        = options.AnnotationsZipFiles;
            string filename                = options.ApiDescriptionFile;
            string mapping_file            = options.MappingReportFile;
            bool   only_xml_adjuster       = options.OnlyRunApiXmlAdjuster;
            string api_xml_adjuster_output = options.ApiXmlAdjusterOutput;
            var    apiSource               = "";
            var    opt = new CodeGenerationOptions()
            {
                CodeGenerationTarget = options.CodeGenerationTarget,
                UseGlobal            = options.GlobalTypeNames,
                IgnoreNonPublicType  = true,
                UseShortFileNames    = options.UseShortFileNames,
                ProductVersion       = options.ProductVersion
            };

            // Load reference libraries

            foreach (var lib in options.LibraryPaths)
            {
                resolver.SearchDirectories.Add(lib);
            }
            foreach (var reference in references)
            {
                resolver.SearchDirectories.Add(Path.GetDirectoryName(reference));
            }
            foreach (var reference in references)
            {
                try {
                    Report.Verbose(0, "resolving assembly {0}.", reference);
                    var assembly = resolver.Load(reference);
                    foreach (var md in assembly.Modules)
                    {
                        foreach (var td in md.Types)
                        {
                            // FIXME: at some stage we want to import generic types.
                            // For now generator fails to load generic types that have conflicting type e.g.
                            // AdapterView`1 and AdapterView cannot co-exist.
                            // It is mostly because generator primarily targets jar (no real generics land).
                            if (td.HasGenericParameters &&
                                md.GetType(td.FullName.Substring(0, td.FullName.IndexOf('`'))) != null)
                            {
                                continue;
                            }
                            ProcessReferencedType(td, opt);
                        }
                    }
                } catch (Exception ex) {
                    Report.Warning(0, Report.WarningCodeGenerator + 0, ex, "failed to parse assembly {0}: {1}", reference, ex.Message);
                }
            }

            // For class-parse API description, transform it to jar2xml style.
            string apiXmlFile = filename;

            string apiSourceAttr = null;

            using (var xr = XmlReader.Create(filename)) {
                xr.MoveToContent();
                apiSourceAttr = xr.GetAttribute("api-source");
            }
            if (apiSourceAttr == "class-parse")
            {
                apiXmlFile = api_xml_adjuster_output ?? Path.Combine(Path.GetDirectoryName(filename), Path.GetFileName(filename) + ".adjusted");
                new Adjuster().Process(filename, SymbolTable.AllRegisteredSymbols().OfType <GenBase> ().ToArray(), apiXmlFile);
            }
            if (only_xml_adjuster)
            {
                return;
            }

            // load XML API definition with fixups.

            Dictionary <string, EnumMappings.EnumDescription> enums = null;

            EnumMappings enummap = null;

            if (enum_fields_map != null || enum_methods_map != null)
            {
                enummap = new EnumMappings(enumdir, enum_metadata, api_level, preserve_enums);
                enums   = enummap.Process(enum_fields_map, enum_flags, enum_methods_map);
                fixups.Add(enum_metadata);
            }

            Parser         p    = new Parser();
            List <GenBase> gens = p.Parse(apiXmlFile, fixups, api_level, product_version);

            if (gens == null)
            {
                return;
            }
            apiSource = p.ApiSource;
            opt.Gens  = gens;

            // disable interface default methods here, especially before validation.
            foreach (var gen in gens)
            {
                gen.StripNonBindables();
            }

            Validate(gens, opt);

            if (api_versions_xml != null)
            {
                ApiVersionsSupport.AssignApiLevels(gens, api_versions_xml, api_level);
            }

            foreach (GenBase gen in gens)
            {
                gen.FillProperties();
            }

            foreach (var gen in gens)
            {
                gen.UpdateEnums(opt);
            }

            foreach (GenBase gen in gens)
            {
                gen.FixupMethodOverrides();
            }

            foreach (GenBase gen in gens)
            {
                gen.FixupExplicitImplementation();
            }

            GenerateAnnotationAttributes(gens, annotations_zips);

            //SymbolTable.Dump ();

            GenerationInfo gen_info = new GenerationInfo(csdir, javadir, assemblyQN);

            opt.AssemblyName = gen_info.Assembly;

            if (mapping_file != null)
            {
                GenerateMappingReportFile(gens, mapping_file);
            }

            new NamespaceMapping(gens).Generate(opt, gen_info);

            foreach (IGeneratable gen in gens)
            {
                if (gen.IsGeneratable)
                {
                    gen.Generate(opt, gen_info);
                }
            }

            ClassGen.GenerateTypeRegistrations(opt, gen_info);
            ClassGen.GenerateEnumList(gen_info);

            // Create the .cs files for the enums
            var enumFiles = enums == null
                                ? null
                                : enummap.WriteEnumerations(enumdir, enums, FlattenNestedTypes(gens).ToArray(), opt.UseShortFileNames);

            gen_info.GenerateLibraryProjectFile(options, enumFiles);
        }
Exemple #57
0
        private static IFrontEndController TryCreateFrontEndController(
            FrontEndFactory frontEndFactory,
            IDecorator <EvaluationResult> decorator,
            ICommandLineConfiguration configuration,
            SymbolTable symbolTable,
            LoggingContext loggingContext,
            PerformanceCollector collector,
            bool collectMemoryAsSoonAsPossible,
            IFrontEndStatistics statistics)
        {
            Contract.Requires(frontEndFactory != null && !frontEndFactory.IsSealed);

            var workspaceResolverFactory = new DScriptWorkspaceResolverFactory();

            // Statistic should be global for all front-ends, not per an instance.
            var frontEndStatistics = statistics ?? new FrontEndStatistics();

            var sharedModuleRegistry = new ModuleRegistry(symbolTable);

            // Note, that the following code is absolutely critical for detecting that front-end related objects
            // are freed successfully after evaluation.
            // ModuleRegistry was picked intentionally because it holds vast amount of front-end data.
            FrontEndControllerMemoryObserver.CaptureFrontEndReference(sharedModuleRegistry);

            frontEndFactory.SetConfigurationProcessor(
                new ConfigurationProcessor(
                    new FrontEndStatistics(), // Configuration processing is so lightweight that it won't affect overall perf statistics
                    logger: null));

            var msBuildFrontEnd = new MsBuildFrontEnd();

            var ninjaFrontEnd = new NinjaFrontEnd();

            var cmakeFrontEnd = new CMakeFrontEnd();

            // TODO: Workspace resolvers and frontends are registered in separate factories. Consider
            // adding a main coordinator/registry
            RegisterKnownWorkspaceResolvers(
                symbolTable.StringTable,
                workspaceResolverFactory,
                frontEndStatistics);

            frontEndFactory.AddFrontEnd(new DScriptFrontEnd(
                                            frontEndStatistics,
                                            evaluationDecorator: decorator));

            frontEndFactory.AddFrontEnd(new NugetFrontEnd(
                                            frontEndStatistics,
                                            evaluationDecorator: decorator));

            frontEndFactory.AddFrontEnd(new DownloadFrontEnd());

            frontEndFactory.AddFrontEnd(msBuildFrontEnd);
            frontEndFactory.AddFrontEnd(ninjaFrontEnd);
            frontEndFactory.AddFrontEnd(cmakeFrontEnd);

            if (!frontEndFactory.TrySeal(loggingContext))
            {
                return(null);
            }

            return(new FrontEndHostController(
                       frontEndFactory,
                       workspaceResolverFactory,
                       evaluationScheduler: EvaluationScheduler.Default,
                       moduleRegistry: sharedModuleRegistry,
                       frontEndStatistics: frontEndStatistics,
                       logger: BuildXL.FrontEnd.Core.Tracing.Logger.CreateLogger(),
                       collector: collector,
                       collectMemoryAsSoonAsPossible: collectMemoryAsSoonAsPossible));
        }
Exemple #58
0
 public override IFrameworkItem Clone(IFrameworkItem parentItem, Dictionary <IFrameworkItem, IFrameworkItem> cloneMapping)
 {
     SymbolTable.GetSourceToCloneDefinitionMappings(this, parentItem, cloneMapping);
     CloneInto(cloneMapping[this], cloneMapping);
     return(cloneMapping[this]);
 }
Exemple #59
0
 public ClassValidationVisitor(MessageLog log, SymbolTable symbols)
 {
     Log     = log;
     Symbols = symbols;
     Success = true;
 }
 public void PopulateSymbolTableWithName(Type callingType, ArgumentObject[] arguments)
 => SymbolTable.PopulateSymbolTableWithName(SpecialNames.Indexer, null, arguments[0].Type);