Exemplo n.º 1
0
        /// <summary>
        /// LoadCopies method.
        /// </summary>
        /// <param name="writer">AbstractErrorWriter</param>
        /// <param name="paths">List<string></param>
        /// <param name="copyDocumentFormat">DocumentFormat</param>
        /// <returns>SymbolTable</returns>
        private static SymbolTable LoadCopies(AbstractErrorWriter writer, List <string> paths, DocumentFormat copyDocumentFormat)
        {
            var parser = new Parser();
            var table  = new SymbolTable(null, SymbolTable.Scope.Intrinsic);

            var copies = new List <string>();

            foreach (string path in paths)
            {
                copies.AddRange(Tools.FileSystem.GetFiles(path, parser.Extensions, false));
            }

            foreach (string path in copies)
            {
                try {
                    parser.Init(path, new TypeCobolOptions {
                        ExecToStep = ExecutionStep.SemanticCheck
                    }, copyDocumentFormat);
                    parser.Parse(path);

                    foreach (var diagnostic in parser.Results.AllDiagnostics())
                    {
                        Server.AddError(writer, MessageCode.IntrinsicLoading,
                                        diagnostic.ColumnStart, diagnostic.ColumnEnd, diagnostic.Line,
                                        "Error during parsing of " + path + ": " + diagnostic, path);
                    }
                    if (parser.Results.ProgramClassDocumentSnapshot.Program == null)
                    {
                        Server.AddError(writer, MessageCode.IntrinsicLoading, "Error: Your Intrisic types/functions are not included into a program.", path);
                        continue;
                    }

                    var symbols = parser.Results.ProgramClassDocumentSnapshot.Program.SymbolTable;
                    foreach (var types in symbols.Types)
                    {
                        foreach (var type in types.Value)
                        {
                            table.AddType(type);
                        }
                    }
                    foreach (var functions in symbols.Functions)
                    {
                        foreach (var function in functions.Value)
                        {
                            table.AddFunction(function);
                        }
                    }
                    //TODO check if types or functions are already there
                }
                catch (Exception e) {
                    Server.AddError(writer, MessageCode.IntrinsicLoading, e.Message + "\n" + e.StackTrace, path);
                }
            }
            return(table);
        }
Exemplo n.º 2
0
        private static SymbolTable LoadCopies(AbstractErrorWriter writer, List<string> paths, DocumentFormat copyDocumentFormat)
        {
            var parser = new Parser();
            var table = new SymbolTable(null, SymbolTable.Scope.Intrinsic);

            var copies = new List<string>();
            foreach(string path in paths) copies.AddRange(Tools.FileSystem.GetFiles(path, parser.Extensions, false));

            foreach(string path in copies) {
                try {
                    parser.Init(path, copyDocumentFormat);
                    parser.Parse(path);

                    foreach (var diagnostic in parser.Results.CodeElementsDocumentSnapshot.ParserDiagnostics) {
                        AddError(writer, "Syntax error during parsing of " + path + ": " + diagnostic, path, "intrinsicLoading");
                    }

                    if (parser.Results.ProgramClassDocumentSnapshot == null) continue;
                    foreach (var diagnostic in parser.Results.ProgramClassDocumentSnapshot.Diagnostics) {
                        AddError(writer, "Semantic error during parsing of " + path + ": " + diagnostic, path, "intrinsicLoading");
                    }

                    if (parser.Results.ProgramClassDocumentSnapshot.Program == null) {
                        AddError(writer, "Error: Your Intrisic types/functions are not included into a program.", path,
                            "intrinsicLoading");
                        continue;
                    }
                    var symbols = parser.Results.ProgramClassDocumentSnapshot.Program.SymbolTable;
                    foreach (var types in symbols.Types)
                        foreach (var type in types.Value)
                            table.AddType((Compiler.Nodes.TypeDefinition) type);
                    foreach (var functions in symbols.Functions)
                        foreach (var function in functions.Value)
                            table.AddFunction((Compiler.Nodes.FunctionDeclaration) function);
                    //TODO check if types or functions are already there
                } catch (Exception e) {
                    AddError(writer, e.Message, path, "intrinsicLoading");
                }
            }
            return table;
        }