]> granicus.if.org Git - clang/commitdiff
refactor htmldiags to be created up front like the other diag clients.
authorChris Lattner <sabre@nondot.org>
Fri, 17 Apr 2009 20:40:01 +0000 (20:40 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 17 Apr 2009 20:40:01 +0000 (20:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69379 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathDiagnostic.h
include/clang/Frontend/PathDiagnosticClients.h
lib/Frontend/HTMLDiagnostics.cpp
tools/clang-cc/clang-cc.cpp

index 8d53cdb67996c406e22688d6187320aa6b27525b..0e0b85eb109de4dc3f5c6e676ed86d3f5d074388 100644 (file)
@@ -32,12 +32,15 @@ namespace clang {
 class PathDiagnostic;
 class Stmt;
 class Decl;
+class Preprocessor;
 
 class PathDiagnosticClient : public DiagnosticClient  {
 public:
   PathDiagnosticClient() {}
   virtual ~PathDiagnosticClient() {}
   
+  virtual void SetPreprocessor(Preprocessor *PP) {}
+  
   virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
                                 const DiagnosticInfo &Info);
   
index 5380de79c6cd2be8683a529591f58c52349e8e11..028cd8549272dc0e8f8cc980696398449e7f73b0 100644 (file)
@@ -23,8 +23,8 @@ class Preprocessor;
 class PreprocessorFactory;
 
 PathDiagnosticClient* CreateHTMLDiagnosticClient(const std::string& prefix,
-                                                 Preprocessor* PP,
-                                                 PreprocessorFactory* PPF);
+                                                 Preprocessor* PP = 0,
+                                                 PreprocessorFactory* PPF = 0);
   
 PathDiagnosticClient* CreatePlistDiagnosticClient(const std::string& prefix,
                                                   Preprocessor* PP,
index 752d41fb4c1649f664819ec0e460ae67095802c0..9cfe0b2a6124b21bc02fa320e6a5102456d25e49 100644 (file)
@@ -39,14 +39,14 @@ class VISIBILITY_HIDDEN HTMLDiagnostics : public PathDiagnosticClient {
   llvm::sys::Path Directory, FilePrefix;
   bool createdDir, noDir;
   Preprocessor* PP;
-  PreprocessorFactory* PPF;
   std::vector<const PathDiagnostic*> BatchedDiags;  
 public:
-  HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
-                  PreprocessorFactory* ppf);
+  HTMLDiagnostics(const std::string& prefix, Preprocessor* pp);
 
   virtual ~HTMLDiagnostics();
   
+  virtual void SetPreprocessor(Preprocessor *pp) { PP = pp; }
+  
   virtual void HandlePathDiagnostic(const PathDiagnostic* D);
   
   unsigned ProcessMacroPiece(llvm::raw_ostream& os,
@@ -65,10 +65,9 @@ public:
   
 } // end anonymous namespace
 
-HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
-                                 PreprocessorFactory* ppf)
+HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp)
   : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false),
-    PP(pp), PPF(ppf) {
+    PP(pp) {
   
   // All html files begin with "report" 
   FilePrefix.appendComponent("report");
@@ -76,9 +75,8 @@ HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
 
 PathDiagnosticClient*
 clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP,
-                                  PreprocessorFactory* PPF) {
-  
-  return new HTMLDiagnostics(prefix, PP, PPF);
+                                  PreprocessorFactory*) {
+  return new HTMLDiagnostics(prefix, PP);
 }
 
 //===----------------------------------------------------------------------===//
@@ -99,7 +97,6 @@ void HTMLDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) {
 }
 
 HTMLDiagnostics::~HTMLDiagnostics() {
-  
   while (!BatchedDiags.empty()) {
     const PathDiagnostic* D = BatchedDiags.back();
     BatchedDiags.pop_back();
@@ -109,9 +106,7 @@ HTMLDiagnostics::~HTMLDiagnostics() {
 }
 
 void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
-  
   // Create the HTML directory if it is missing.
-  
   if (!createdDir) {
     createdDir = true;
     std::string ErrorMsg;
@@ -170,10 +165,8 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
   unsigned max = n;
   
   for (PathDiagnostic::const_reverse_iterator I=D.rbegin(), E=D.rend();
-        I!=E; ++I, --n) {
-    
+        I!=E; ++I, --n)
     HandlePiece(R, FID, *I, n, max);
-  }
   
   // Add line numbers, header, footer, etc.
   
index 81d1e397904b4ec5a3b0e58b8f212f8aeb37b271..ba4d77795f951d211354332d880d77f960230810 100644 (file)
@@ -2229,29 +2229,31 @@ int main(int argc, char **argv) {
   
   // Create the diagnostic client for reporting errors or for
   // implementing -verify.
-  DiagnosticClient* TextDiagClient = 0;
-  
-  if (!VerifyDiagnostics) {
+  llvm::OwningPtr<DiagnosticClient> DiagClient;
+  if (VerifyDiagnostics) {
+    // When checking diagnostics, just buffer them up.
+    DiagClient.reset(new TextDiagnosticBuffer());
+    if (InputFilenames.size() != 1) {
+      fprintf(stderr, "-verify only works on single input files for now.\n");
+      return 1;
+    }
+    if (!HTMLDiag.empty()) {
+      fprintf(stderr, "-verify and -html-diags don't work together\n");
+      return 1;
+    }
+  } else if (HTMLDiag.empty()) {
     // Print diagnostics to stderr by default.
-    TextDiagClient = new TextDiagnosticPrinter(llvm::errs(),
+    DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(),
                                                !NoShowColumn,
                                                !NoCaretDiagnostics,
                                                !NoShowLocation,
                                                PrintSourceRangeInfo,
-                                               PrintDiagnosticOption);
+                                               PrintDiagnosticOption));
   } 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;
-    }
+    DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag));
   }
 
   // Configure our handling of diagnostics.
-  llvm::OwningPtr<DiagnosticClient> DiagClient(TextDiagClient);
   Diagnostic Diags(DiagClient.get());
   if (ProcessWarningOptions(Diags))
     return 1;
@@ -2287,7 +2289,6 @@ int main(int argc, char **argv) {
     const std::string &InFile = InputFilenames[i];
     
     if (isSerializedFile(InFile)) {
-      Diags.setClient(TextDiagClient);
       ProcessSerializedFile(InFile,Diags,FileMgr);
       continue;
     }
@@ -2301,7 +2302,7 @@ int main(int argc, char **argv) {
     
     // Initialize language options, inferring file types from input filenames.
     LangOptions LangInfo;
-    TextDiagClient->setLangOptions(&LangInfo);
+    DiagClient->setLangOptions(&LangInfo);
     
     InitializeBaseLanguage();
     LangKind LK = GetLanguage(InFile);
@@ -2327,23 +2328,14 @@ int main(int argc, char **argv) {
         InitializeSourceManager(*PP.get(), InFile))
       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);
+    if (!HTMLDiag.empty())
+      ((PathDiagnosticClient*)DiagClient.get())->SetPreprocessor(PP.get());
 
     // Process the source file.
     ProcessInputFile(*PP, PPFactory, InFile, ProgAction);
     
     HeaderInfo.ClearFileInfo();
-    TextDiagClient->setLangOptions(0);
+    DiagClient->setLangOptions(0);
   }
 
   if (Verbose)