diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-08-07 17:49:57 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-08-07 17:49:57 +0000 |
commit | b4398aa27da4d6919c3ae448d1ae66ba6cafc048 (patch) | |
tree | 6f34a5c54a19240c6517e50fd6d51524ce7009fe | |
parent | 45e52e137702abbfa44852979a5717dfdc09c9bc (diff) |
Fix --html-diags in driver by delaying the construction of an HTMLDiagnosticClient until after we have created the Preprocessor object.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54472 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Driver/clang.cpp | 64 | ||||
-rw-r--r-- | include/clang/Basic/Diagnostic.h | 11 | ||||
-rw-r--r-- | lib/Basic/Diagnostic.cpp | 10 |
3 files changed, 44 insertions, 41 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 1aa7651aa6..7721e83aff 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -1389,38 +1389,26 @@ int main(int argc, char **argv) { // Create the diagnostic client for reporting errors or for // implementing -verify. - std::auto_ptr<DiagnosticClient> DiagClient; - TextDiagnostics* TextDiagClient = NULL; + TextDiagnostics* TextDiagClient = 0; - if (!HTMLDiag.empty()) { - - // FIXME: The HTMLDiagnosticClient uses the Preprocessor for - // (optional) syntax highlighting, but we don't have a preprocessor yet. - // Fix this dependency later. - DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, 0, 0)); - } - else { // Use Text diagnostics. - if (!VerifyDiagnostics) { - // Print diagnostics to stderr by default. - TextDiagClient = new TextDiagnosticPrinter(!NoShowColumn, - !NoCaretDiagnostics); - } else { - // When checking diagnostics, just buffer them up. - TextDiagClient = new TextDiagnosticBuffer(); - - if (InputFilenames.size() != 1) { - fprintf(stderr, - "-verify only works on single input files for now.\n"); - return 1; - } + if (!VerifyDiagnostics) { + // Print diagnostics to stderr by default. + TextDiagClient = new TextDiagnosticPrinter(!NoShowColumn, + !NoCaretDiagnostics); + } else { + // When checking diagnostics, just buffer them up. + TextDiagClient = new TextDiagnosticBuffer(); + + if (InputFilenames.size() != 1) { + fprintf(stderr, + "-verify only works on single input files for now.\n"); + return 1; } - - assert (TextDiagClient); - DiagClient.reset(TextDiagClient); } - + // Configure our handling of diagnostics. - Diagnostic Diags(*DiagClient); + llvm::OwningPtr<DiagnosticClient> DiagClient(TextDiagClient); + Diagnostic Diags(DiagClient.get()); InitializeDiagnostics(Diags); // -I- is a deprecated GCC feature, scan for it and reject it. @@ -1445,15 +1433,16 @@ int main(int argc, char **argv) { // Are we invoking one or more source analyses? if (!AnalysisList.empty() && ProgAction == ParseSyntaxOnly) ProgAction = RunAnalysis; - - + llvm::OwningPtr<SourceManager> SourceMgr; for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { const std::string &InFile = InputFilenames[i]; - if (isSerializedFile(InFile)) + if (isSerializedFile(InFile)) { + Diags.setClient(TextDiagClient); ProcessSerializedFile(InFile,Diags,FileMgr); + } else { /// Create a SourceManager object. This tracks and owns all the file /// buffers allocated to a translation unit. @@ -1489,7 +1478,20 @@ int main(int argc, char **argv) { if (!PP) continue; + + // Create the HTMLDiagnosticsClient if we are using one. Otherwise, + // always reset to using TextDiagClient. + llvm::OwningPtr<DiagnosticClient> TmpClient; + if (!HTMLDiag.empty()) { + TmpClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, PP.get(), + &PPFactory)); + Diags.setClient(TmpClient.get()); + } + else + Diags.setClient(TextDiagClient); + + // Process the source file. ProcessInputFile(*PP, PPFactory, InFile); HeaderInfo.ClearFileInfo(); diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 617702c7f9..f214091272 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -61,7 +61,7 @@ private: bool WarningsAsErrors; // Treat warnings like errors: bool WarnOnExtensions; // Enables warnings for gcc extensions: -pedantic. bool ErrorOnExtensions; // Error on extensions: -pedantic-errors. - DiagnosticClient &Client; + DiagnosticClient *Client; /// DiagMappings - Mapping information for diagnostics. Mapping info is /// packed into two bits per diagnostic. @@ -77,16 +77,17 @@ private: /// CustomDiagInfo - Information for uniquing and looking up custom diags. diag::CustomDiagInfo *CustomDiagInfo; public: - explicit Diagnostic(DiagnosticClient &client); + explicit Diagnostic(DiagnosticClient *client); ~Diagnostic(); //===--------------------------------------------------------------------===// // Diagnostic characterization methods, used by a client to customize how // - DiagnosticClient &getClient() { return Client; }; - - const DiagnosticClient &getClient() const { return Client; }; + DiagnosticClient &getClient() { return *Client; }; + const DiagnosticClient &getClient() const { return *Client; }; + + void setClient(DiagnosticClient* client) { Client = client; } /// setIgnoreAllWarnings - When set to true, any unmapped warnings are /// ignored. If this and WarningsAsErrors are both set, then this one wins. diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 35d665d1a5..16bdd4a6c2 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -108,7 +108,7 @@ namespace clang { // Common Diagnostic implementation //===----------------------------------------------------------------------===// -Diagnostic::Diagnostic(DiagnosticClient &client) : Client(client) { +Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) { IgnoreAllWarnings = false; WarningsAsErrors = false; WarnOnExtensions = false; @@ -219,7 +219,7 @@ void Diagnostic::Report(DiagnosticClient* C, return; // Set the diagnostic client if it isn't set already. - if (!C) C = &Client; + if (!C) C = Client; // If this is not an error and we are in a system header, ignore it. We have // to check on the original class here, because we also want to ignore @@ -227,13 +227,13 @@ void Diagnostic::Report(DiagnosticClient* C, // warnings/extensions to errors. if (DiagID < diag::NUM_BUILTIN_DIAGNOSTICS && getBuiltinDiagClass(DiagID) != ERROR && - Client.isInSystemHeader(Pos)) + Client->isInSystemHeader(Pos)) return; if (DiagLevel >= Diagnostic::Error) { ErrorOccurred = true; - if (C == &Client) + if (C == Client) ++NumErrors; } @@ -242,7 +242,7 @@ void Diagnostic::Report(DiagnosticClient* C, C->HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID, Strs, NumStrs, Ranges, NumRanges); - if (C == &Client) + if (C == Client) ++NumDiagnostics; } |