[cfe-commits] r58652 - in /cfe/trunk: Driver/Analyses.def Driver/AnalysisConsumer.cpp Driver/AnalysisConsumer.h Driver/clang.cpp include/clang/Driver/PathDiagnosticClients.h lib/Driver/PlistDiagnostics.cpp

Ted Kremenek kremenek at apple.com
Mon Nov 3 15:18:07 PST 2008


Author: kremenek
Date: Mon Nov  3 17:18:07 2008
New Revision: 58652

URL: http://llvm.org/viewvc/llvm-project?rev=58652&view=rev
Log:
Hook up the Plist diagnostic client to the driver.
Fix Plist output.

Modified:
    cfe/trunk/Driver/Analyses.def
    cfe/trunk/Driver/AnalysisConsumer.cpp
    cfe/trunk/Driver/AnalysisConsumer.h
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Driver/PathDiagnosticClients.h
    cfe/trunk/lib/Driver/PlistDiagnostics.cpp

Modified: cfe/trunk/Driver/Analyses.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Analyses.def?rev=58652&r1=58651&r2=58652&view=diff

==============================================================================
--- cfe/trunk/Driver/Analyses.def (original)
+++ cfe/trunk/Driver/Analyses.def Mon Nov  3 17:18:07 2008
@@ -15,10 +15,6 @@
 #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)
 #endif
 
-#ifndef ANALYSIS_STORE
-#define ANALYSIS_STORE(NAME, CMDFLAG, DESC)
-#endif
-
 ANALYSIS(CFGDump, "cfg-dump",
          "Display Control-Flow Graphs", Code)
 
@@ -52,8 +48,22 @@
          "Run the [Core] Foundation reference count checker", Code)
 
 
+#ifndef ANALYSIS_STORE
+#define ANALYSIS_STORE(NAME, CMDFLAG, DESC)
+#endif
+
 ANALYSIS_STORE(BasicStore, "basic", "Use basic analyzer store")
 ANALYSIS_STORE(RegionStore, "region", "Use region-based analyzer store")
 
+#ifndef ANALYSIS_DIAGNOSTICS
+#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)
+#endif
+
+ANALYSIS_DIAGNOSTICS(HTML,  "html",  "Output analysis results using HTML",   CreateHTMLDiagnosticClient)
+ANALYSIS_DIAGNOSTICS(PLIST, "plist", "Output analysis results using Plists", CreatePlistDiagnosticClient)
+
 #undef ANALYSIS
 #undef ANALYSIS_STORE
+#undef ANALYSIS_DIAGNOSTICS
+
+

Modified: cfe/trunk/Driver/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.cpp?rev=58652&r1=58651&r2=58652&view=diff

==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.cpp (original)
+++ cfe/trunk/Driver/AnalysisConsumer.cpp Mon Nov  3 17:18:07 2008
@@ -75,20 +75,21 @@
     llvm::OwningPtr<PathDiagnosticClient> PD;
     bool AnalyzeAll;  
     AnalysisStores SM;
+    AnalysisDiagClients DC;
 
     AnalysisConsumer(Diagnostic &diags, Preprocessor* pp,
                      PreprocessorFactory* ppf,
                      const LangOptions& lopts,
                      const std::string& fname,
                      const std::string& htmldir,
-                     AnalysisStores sm,
+                     AnalysisStores sm, AnalysisDiagClients dc,
                      bool visgraphviz, bool visubi, bool trim, bool analyzeAll) 
       : VisGraphviz(visgraphviz), VisUbigraph(visubi), TrimGraph(trim),
         LOpts(lopts), Diags(diags),
         Ctx(0), PP(pp), PPF(ppf),
         HTMLDir(htmldir),
         FName(fname),
-        AnalyzeAll(analyzeAll), SM(sm) {}
+        AnalyzeAll(analyzeAll), SM(sm), DC(dc) {}
     
     void addCodeAction(CodeAction action) {
       FunctionActions.push_back(action);
@@ -165,9 +166,14 @@
     }
     
     virtual PathDiagnosticClient* getPathDiagnosticClient() {
-      if (C.PD.get() == 0 && !C.HTMLDir.empty())
-        C.PD.reset(CreateHTMLDiagnosticClient(C.HTMLDir, C.PP, C.PPF));
-      
+      if (C.PD.get() == 0 && !C.HTMLDir.empty()) {
+        switch (C.DC) {
+          default:
+#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN)\
+case PD_##NAME: C.PD.reset(CREATEFN(C.HTMLDir, C.PP, C.PPF)); break;
+#include "Analyses.def"
+        }
+      }
       return C.PD.get();      
     }
       
@@ -449,6 +455,7 @@
 
 ASTConsumer* clang::CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
                                            AnalysisStores SM,
+                                           AnalysisDiagClients DC,
                                            Diagnostic &diags, Preprocessor* pp,
                                            PreprocessorFactory* ppf,
                                            const LangOptions& lopts,
@@ -459,7 +466,7 @@
                                            bool analyzeAll) {
   
   llvm::OwningPtr<AnalysisConsumer>
-  C(new AnalysisConsumer(diags, pp, ppf, lopts, fname, htmldir, SM,
+  C(new AnalysisConsumer(diags, pp, ppf, lopts, fname, htmldir, SM, DC,
                          VisGraphviz, VisUbi, trim, analyzeAll));
   
   for ( ; Beg != End ; ++Beg)

Modified: cfe/trunk/Driver/AnalysisConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.h?rev=58652&r1=58651&r2=58652&view=diff

==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.h (original)
+++ cfe/trunk/Driver/AnalysisConsumer.h Mon Nov  3 17:18:07 2008
@@ -27,9 +27,15 @@
 #include "Analyses.def"
 NumStores
 };
+  
+enum AnalysisDiagClients {
+#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME,
+#include "Analyses.def"
+NUM_ANALYSIS_DIAG_CLIENTS
+};
 
 ASTConsumer* CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
-                                    AnalysisStores SM,
+                                    AnalysisStores SM, AnalysisDiagClients DC,
                                     Diagnostic &diags, Preprocessor* pp,
                                     PreprocessorFactory* ppf,
                                     const LangOptions& lopts,

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=58652&r1=58651&r2=58652&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Mon Nov  3 17:18:07 2008
@@ -220,6 +220,15 @@
 #include "Analyses.def"
 clEnumValEnd));
 
+static llvm::cl::opt<AnalysisDiagClients>
+AnalysisDiagOpt(llvm::cl::desc("SCA Output Options:"),
+                llvm::cl::init(PD_HTML),
+                llvm::cl::values(
+#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN)\
+clEnumValN(PD_##NAME, "analyzer-output-" CMDFLAG, DESC),
+#include "Analyses.def"
+clEnumValEnd));                                
+
 //===----------------------------------------------------------------------===//
 // Language Options
 //===----------------------------------------------------------------------===//
@@ -1224,7 +1233,7 @@
       assert (!AnalysisList.empty());
       return CreateAnalysisConsumer(&AnalysisList[0],
                                     &AnalysisList[0]+AnalysisList.size(),
-                                    AnalysisStoreOpt,
+                                    AnalysisStoreOpt, AnalysisDiagOpt,
                                     Diag, PP, PPF, LangOpts,
                                     AnalyzeSpecificFunction,
                                     OutputFile, VisualizeEGDot, VisualizeEGUbi,

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

==============================================================================
--- cfe/trunk/include/clang/Driver/PathDiagnosticClients.h (original)
+++ cfe/trunk/include/clang/Driver/PathDiagnosticClients.h Mon Nov  3 17:18:07 2008
@@ -26,7 +26,9 @@
                                                  Preprocessor* PP,
                                                  PreprocessorFactory* PPF);
   
-PathDiagnosticClient* CreatePlistDiagnosticClient(const std::string& prefix);
+PathDiagnosticClient* CreatePlistDiagnosticClient(const std::string& prefix,
+                                                  Preprocessor* PP,
+                                                  PreprocessorFactory* PPF);
 }
 
 #endif

Modified: cfe/trunk/lib/Driver/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/PlistDiagnostics.cpp?rev=58652&r1=58651&r2=58652&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/Driver/PlistDiagnostics.cpp Mon Nov  3 17:18:07 2008
@@ -24,6 +24,11 @@
 using namespace clang;
 typedef llvm::DenseMap<unsigned,unsigned> FIDMap;
 
+namespace clang {
+  class Preprocessor;
+  class PreprocessorFactory;
+}
+
 namespace {
   class VISIBILITY_HIDDEN PlistDiagnostics : public PathDiagnosticClient {
     llvm::sys::Path Directory, FilePrefix;
@@ -40,7 +45,9 @@
   FilePrefix.appendComponent("report"); // All Plist files begin with "report" 
 }
 
-PathDiagnosticClient* clang::CreatePlistDiagnosticClient(const std::string& s) {
+PathDiagnosticClient*
+clang::CreatePlistDiagnosticClient(const std::string& s,
+                                   Preprocessor*, PreprocessorFactory*) {
   return new PlistDiagnostics(s);
 }
 
@@ -118,7 +125,7 @@
   
   // Output the text.
   Indent(o, indent) << "<key>message</key>\n";
-  Indent(o, indent) << "<string>" << P.getString() << "</string>";
+  Indent(o, indent) << "<string>" << P.getString() << "</string>\n";
   
   // Output the hint.
   Indent(o, indent) << "<key>displayhint</key>\n";
@@ -222,9 +229,9 @@
   o << " </array>\n";
     
   // Output the bug type and bug category.  
-  o << " <key>description</key><string>" << D->getDescription() << "</string>\n"
-       " <key>category</key><string>" << D->getCategory() << "</string>\n";
+  o << " <key>description</key>\n <string>" << D->getDescription() << "</string>\n"
+       " <key>category</key>\n <string>" << D->getCategory() << "</string>\n";
 
   // Finish.
-  o << "</dict>\n";
+  o << "</dict>\n</plist>";
 }





More information about the cfe-commits mailing list