コード例 #1
0
        public bool ReportErrors(IEnumerable <DiagnosticInfo> diagnostics, TextWriter consoleOutput, ErrorLogger2 errorLoggerOpt)
        {
            bool hasErrors = false;

            if (diagnostics != null && diagnostics.Any())
            {
                foreach (var diagnostic in diagnostics)
                {
                    if (diagnostic.GetFieldOrProperty <DiagnosticSeverity>("Severity") == DiagnosticSeverity.Hidden)
                    {
                        // Not reported from the command-line compiler.
                        continue;
                    }

                    PrintError(diagnostic, consoleOutput);
                    errorLoggerOpt?.InvokeAction("LogDiagnostic", typeof(Diagnostic).InvokeFunction("Create", diagnostic));

                    if (diagnostic.GetFieldOrProperty <DiagnosticSeverity>("Severity") == DiagnosticSeverity.Error)
                    {
                        hasErrors = true;
                    }
                }
            }

            return(hasErrors);
        }
コード例 #2
0
        public bool ReportErrors(IEnumerable <Diagnostic> diagnostics, TextWriter consoleOutput, ErrorLogger2 errorLoggerOpt)
        {
            bool hasErrors = false;

            foreach (var diag in diagnostics)
            {
                if (_reportedDiagnostics.Contains(diag))
                {
                    // TODO: This invariant fails (at least) in the case where we see a member declaration "x = 1;".
                    // First we attempt to parse a member declaration starting at "x".  When we see the "=", we
                    // create an IncompleteMemberSyntax with return type "x" and an error at the location of the "x".
                    // Then we parse a member declaration starting at "=".  This is an invalid member declaration start
                    // so we attach an error to the "=" and attach it (plus following tokens) to the IncompleteMemberSyntax
                    // we previously created.
                    //this assert isn't valid if we change the design to not bail out after each phase.
                    //System.Diagnostics.Debug.Assert(diag.Severity != DiagnosticSeverity.Error);
                    continue;
                }
                else if (diag.Severity == DiagnosticSeverity.Hidden)
                {
                    // Not reported from the command-line compiler.
                    continue;
                }

                // We want to report diagnostics with source suppression in the error log file.
                // However, these diagnostics should not be reported on the console output.
                errorLoggerOpt?.InvokeAction("LogDiagnostic", diag);
                if (diag.IsSuppressed)
                {
                    continue;
                }

                consoleOutput.WriteLine(DiagnosticFormatter.Format(diag));

                if (diag.Severity == DiagnosticSeverity.Error)
                {
                    hasErrors = true;
                }

                _reportedDiagnostics.Add(diag);
            }

            return(hasErrors);
        }