]> granicus.if.org Git - clang/commitdiff
Fix --html-diags in driver by delaying the construction of an HTMLDiagnosticClient...
authorTed Kremenek <kremenek@apple.com>
Thu, 7 Aug 2008 17:49:57 +0000 (17:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 7 Aug 2008 17:49:57 +0000 (17:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54472 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/clang.cpp
include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp

index 1aa7651aa6f65e3711bf3c5d9dd776d677dd9df7..7721e83affc9693e81187aefbfddadec07e36ddb 100644 (file)
@@ -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();      
       
index 617702c7f9eba3625e881fb731b8a6332d7ed41e..f2140912727bd46bb33790a50353d3452ce82e33 100644 (file)
@@ -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.
index 35d665d1a5c1cdc321779b8d3a0ff54fe2d2bbd3..16bdd4a6c22574dc59870e62030cec6352e57860 100644 (file)
@@ -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;
 }