Beispiel #1
0
 public abstract Compilation CreateCompilation(TextWriter consoleOutput, ErrorLogger errorLoggerOpt);
Beispiel #2
0
        private int RunCore(TextWriter consoleOutput, ErrorLogger errorLogger, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (Arguments.DisplayVersion)
            {
                PrintVersion(consoleOutput);
                return(Succeeded);
            }

            if (Arguments.DisplayLangVersions)
            {
                PrintLangVersions(consoleOutput);
                return(Succeeded);
            }

            if (Arguments.DisplayLogo)
            {
                PrintLogo(consoleOutput);
            }

            if (Arguments.DisplayHelp)
            {
                PrintHelp(consoleOutput);
                return(Succeeded);
            }

            if (ReportErrors(Arguments.Errors, consoleOutput, errorLogger))
            {
                return(Failed);
            }

            Compilation compilation = CreateCompilation(consoleOutput, errorLogger);

            if (compilation == null)
            {
                return(Failed);
            }

            var diagnosticInfos     = new List <DiagnosticInfo>();
            var additionalTextFiles = ResolveAdditionalFilesFromArguments(diagnosticInfos, MessageProvider);

            if (ReportErrors(diagnosticInfos, consoleOutput, errorLogger))
            {
                return(Failed);
            }

            var diagnostics = DiagnosticBag.GetInstance();

            CompileAndEmit(
                ref compilation,
                additionalTextFiles,
                diagnostics,
                cancellationToken);

            var exitCode = ReportErrors(diagnostics, consoleOutput, errorLogger)
                                ? Failed
                                : Succeeded;

            // The act of reporting errors can cause more errors to appear in
            // additional files due to forcing all additional files to fetch text
            foreach (var additionalFile in additionalTextFiles)
            {
                if (ReportErrors(additionalFile.Diagnostics, consoleOutput, errorLogger))
                {
                    exitCode = Failed;
                }
            }

            diagnostics.Free();

            return(exitCode);
        }
Beispiel #3
0
 public bool ReportErrors(IEnumerable <DiagnosticInfo> diagnostics, TextWriter consoleOutput, ErrorLogger errorLoggerOpt) =>
 ReportErrors(diagnostics.Select(info => Diagnostic.Create(info)), consoleOutput, errorLoggerOpt);
Beispiel #4
0
 private bool ReportErrors(DiagnosticBag diagnostics, TextWriter consoleOutput, ErrorLogger errorLoggerOpt)
 => ReportErrors(diagnostics.ToReadOnly(), consoleOutput, errorLoggerOpt);
Beispiel #5
0
        public bool ReportErrors(IEnumerable <Diagnostic> diagnostics, TextWriter consoleOutput, ErrorLogger 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?.LogDiagnostic(diag);
                if (diag.IsSuppressed)
                {
                    continue;
                }

                // Diagnostics that aren't suppressed will be reported to the console output and, if they are errors,
                // they should fail the run
                if (diag.Severity == DiagnosticSeverity.Error)
                {
                    hasErrors = true;
                }

                PrintError(diag, consoleOutput);

                _reportedDiagnostics.Add(diag);
            }

            return(hasErrors);
        }
Beispiel #6
0
 public override Compilation CreateCompilation(TextWriter consoleOutput, ErrorLogger errorLoggerOpt)
 {
     throw new NotImplementedException();
 }