示例#1
0
        public override void Compare(CompilationUnit compilationUnit, StreamReader reader)
        {
            IList <Diagnostic>   diagnostics = compilationUnit.AllDiagnostics();
            ProgramClassDocument pcd         = compilationUnit.ProgramClassDocumentSnapshot;

            Compare(pcd.Root.Programs, pcd.Root.Classes, diagnostics, reader);
        }
示例#2
0
        public override void Compare(CompilationUnit result, StreamReader reader)
        {
            ProgramClassDocument pcd = result.ProgramClassDocumentSnapshot;
            var symbolTables         = new List <SymbolTable>();

            symbolTables.Add(pcd.Root.SymbolTable);

            Compare(symbolTables, reader);
        }
示例#3
0
        /// <summary>
        /// Creates a new snapshot of the document viewed as complete Cobol Program or Class.
        /// (if the code elements lines changed since the last time this method was called)
        /// Thread-safe : this method can be called from any thread.
        /// </summary>
        public void RefreshProgramClassDocumentSnapshot()
        {
            // Make sure two threads don't try to update this snapshot at the same time
            bool snapshotWasUpdated = false;

            lock (lockObjectForProgramClassDocumentSnapshot)
            {
                // Capture previous snapshot at one point in time
                CodeElementsDocument codeElementsDocument = CodeElementsDocumentSnapshot;

                // Check if an update is necessary and compute changes to apply since last version
                if ((CodeElementsDocumentSnapshot != null) && (ProgramClassDocumentSnapshot == null || ProgramClassDocumentSnapshot.PreviousStepSnapshot.CurrentVersion != codeElementsDocument.CurrentVersion))
                {
                    // Start perf measurement
                    var perfStatsForParserInvocation = PerfStatsForProgramClassParser.OnStartRefreshParsingStep();

                    // Program and Class parsing is not incremental : the objects are rebuilt each time this method is called
                    SourceFile root;
                    IList <ParserDiagnostic>       newDiagnostics;
                    Dictionary <CodeElement, Node> nodeCodeElementLinkers = new Dictionary <CodeElement, Node>();
                    //TODO cast to ImmutableList<CodeElementsLine> sometimes fails here
                    ProgramClassParserStep.ParseProgramOrClass(TextSourceInfo, ((ImmutableList <CodeElementsLine>)codeElementsDocument.Lines), CompilerOptions, CustomSymbols, perfStatsForParserInvocation, out root, out newDiagnostics, out nodeCodeElementLinkers);

                    // Capture the result of the parse in a new snapshot
                    ProgramClassDocumentSnapshot = new ProgramClassDocument(
                        codeElementsDocument, ProgramClassDocumentSnapshot == null ? 0 : ProgramClassDocumentSnapshot.CurrentVersion + 1,
                        root, newDiagnostics, nodeCodeElementLinkers);
                    snapshotWasUpdated = true;

                    // Stop perf measurement
                    PerfStatsForProgramClassParser.OnStopRefreshParsingStep();
                }
            }

            // Send events to all listeners
            EventHandler <ProgramClassEvent> programClassChanged    = ProgramClassChanged; // avoid race condition
            EventHandler <ProgramClassEvent> programClassNotChanged = ProgramClassNotChanged;

            if (snapshotWasUpdated && programClassChanged != null)
            {
                programClassChanged(this, new ProgramClassEvent()
                {
                    Version = ProgramClassDocumentSnapshot.CurrentVersion
                });
            }
            else if (!snapshotWasUpdated && programClassNotChanged != null)
            {
                programClassNotChanged(this, new ProgramClassEvent()
                {
                    Version = ProgramClassDocumentSnapshot.CurrentVersion
                });
            }
        }
示例#4
0
        /// <summary>
        /// Creates a new snapshot of the document viewed as complete Cobol Program or Class.
        /// Thread-safe : this method can be called from any thread.
        /// </summary>
        public void RefreshProgramClassDocumentSnapshot()
        {
            // Make sure two threads don't try to update this snapshot at the same time
            bool snapshotWasUpdated = false;

            lock (lockObjectForProgramClassDocumentSnapshot)
            {
                // Capture previous snapshot at one point in time
                TemporarySemanticDocument temporarySnapshot = TemporaryProgramClassDocumentSnapshot;

                // Check if an update is necessary and compute changes to apply since last version
                if ((TemporaryProgramClassDocumentSnapshot != null) && (ProgramClassDocumentSnapshot == null || ProgramClassDocumentSnapshot.PreviousStepSnapshot.CurrentVersion != temporarySnapshot.CurrentVersion))
                {
                    PerfStatsForProgramCrossCheck.OnStartRefreshParsingStep();

                    // Program and Class parsing is not incremental : the objects are rebuilt each time this method is called
                    SourceFile        root        = temporarySnapshot.Root;
                    List <Diagnostic> diagnostics = new List <Diagnostic>();
                    Dictionary <CodeElement, Node> nodeCodeElementLinkers = temporarySnapshot.NodeCodeElementLinkers ?? new Dictionary <CodeElement, Node>();
                    ProgramClassParserStep.CrossCheckPrograms(root);

                    // Capture the result of the parse in a new snapshot
                    ProgramClassDocumentSnapshot = new ProgramClassDocument(
                        temporarySnapshot, ProgramClassDocumentSnapshot?.CurrentVersion + 1 ?? 0,
                        root, diagnostics, nodeCodeElementLinkers);
                    snapshotWasUpdated = true;;

                    PerfStatsForProgramCrossCheck.OnStopRefreshParsingStep();
                }
            }

            // Send events to all listeners
            EventHandler <ProgramClassEvent> programClassChanged    = ProgramClassChanged; // avoid race condition
            EventHandler <ProgramClassEvent> programClassNotChanged = ProgramClassNotChanged;

            if (snapshotWasUpdated && programClassChanged != null)
            {
                programClassChanged(this, new ProgramClassEvent()
                {
                    Version = ProgramClassDocumentSnapshot.CurrentVersion
                });
            }
            else if (!snapshotWasUpdated && programClassNotChanged != null)
            {
                programClassNotChanged(this, new ProgramClassEvent()
                {
                    Version = ProgramClassDocumentSnapshot.CurrentVersion
                });
            }
        }
示例#5
0
        public override void Compare(CompilationUnit compilationUnit, StreamReader reader)
        {
            ProgramClassDocument pcd         = compilationUnit.ProgramClassDocumentSnapshot;
            IList <Diagnostic>   diagnostics = compilationUnit.AllDiagnostics();

            StringBuilder sb = new StringBuilder();

            foreach (var diagnostic in diagnostics)
            {
                sb.AppendLine(diagnostic.ToString());
            }

            sb.AppendLine("--- Nodes ---");
            sb.Append(pcd.Root);

            string result = sb.ToString();

            if (debug)
            {
                Console.WriteLine("\"" + paths.SamplePath + "\" result:\n" + result);
            }
            ParserUtils.CheckWithResultReader(paths.SamplePath, result, reader);
        }
示例#6
0
        public override void Compare(CompilationUnit result, StreamReader reader)
        {
            ProgramClassDocument pcd = result.ProgramClassDocumentSnapshot;

            Compare(pcd.Program.SymbolTable, reader);
        }