[cfe-commits] r69379 - in /cfe/trunk: include/clang/Analysis/PathDiagnostic.h include/clang/Frontend/PathDiagnosticClients.h lib/Frontend/HTMLDiagnostics.cpp tools/clang-cc/clang-cc.cpp

Chris Lattner sabre at nondot.org
Fri Apr 17 13:40:01 PDT 2009


Author: lattner
Date: Fri Apr 17 15:40:01 2009
New Revision: 69379

URL: http://llvm.org/viewvc/llvm-project?rev=69379&view=rev
Log:
refactor htmldiags to be created up front like the other diag clients.

Modified:
    cfe/trunk/include/clang/Analysis/PathDiagnostic.h
    cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h
    cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Analysis/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathDiagnostic.h?rev=69379&r1=69378&r2=69379&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/Analysis/PathDiagnostic.h Fri Apr 17 15:40:01 2009
@@ -32,12 +32,15 @@
 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);
   

Modified: cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h?rev=69379&r1=69378&r2=69379&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h (original)
+++ cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h Fri Apr 17 15:40:01 2009
@@ -23,8 +23,8 @@
 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,

Modified: cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp?rev=69379&r1=69378&r2=69379&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp Fri Apr 17 15:40:01 2009
@@ -39,14 +39,14 @@
   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 @@
   
 } // 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 @@
 
 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 @@
 }
 
 HTMLDiagnostics::~HTMLDiagnostics() {
-  
   while (!BatchedDiags.empty()) {
     const PathDiagnostic* D = BatchedDiags.back();
     BatchedDiags.pop_back();
@@ -109,9 +106,7 @@
 }
 
 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 @@
   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.
   

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=69379&r1=69378&r2=69379&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Fri Apr 17 15:40:01 2009
@@ -2229,29 +2229,31 @@
   
   // 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 @@
     const std::string &InFile = InputFilenames[i];
     
     if (isSerializedFile(InFile)) {
-      Diags.setClient(TextDiagClient);
       ProcessSerializedFile(InFile,Diags,FileMgr);
       continue;
     }
@@ -2301,7 +2302,7 @@
     
     // 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 @@
         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)





More information about the cfe-commits mailing list