]> granicus.if.org Git - clang/commitdiff
Hook up the Plist diagnostic client to the driver.
authorTed Kremenek <kremenek@apple.com>
Mon, 3 Nov 2008 23:18:07 +0000 (23:18 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 3 Nov 2008 23:18:07 +0000 (23:18 +0000)
Fix Plist output.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58652 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/Analyses.def
Driver/AnalysisConsumer.cpp
Driver/AnalysisConsumer.h
Driver/clang.cpp
include/clang/Driver/PathDiagnosticClients.h
lib/Driver/PlistDiagnostics.cpp

index 0661a4e9463d2d91f99fd3cfd3ae9b8f9eb0bdb6..1f702cc0e9c252064f8dd2a4926f1c8a1ebffe01 100644 (file)
 #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 @@ ANALYSIS(CheckerCFRef, "checker-cfref",
          "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
+
+
index aa78337ae00135cd364db0dd97f716784d8ee370..5f338c8af53dd8cd2704c998d62e5c6505dc37b4 100644 (file)
@@ -75,20 +75,21 @@ namespace {
     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 @@ case NAME##Model: return Create##NAME##Manager;
     }
     
     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 @@ static void ActionWarnObjCMethSigs(AnalysisManager& mgr) {
 
 ASTConsumer* clang::CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
                                            AnalysisStores SM,
+                                           AnalysisDiagClients DC,
                                            Diagnostic &diags, Preprocessor* pp,
                                            PreprocessorFactory* ppf,
                                            const LangOptions& lopts,
@@ -459,7 +466,7 @@ ASTConsumer* clang::CreateAnalysisConsumer(Analyses* Beg, Analyses* End,
                                            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)
index 420714fd60bfa9d6ed8d143d62768d996d18ba2c..27c8e6e07ab05f3c076e4675d31027ac8298f9ca 100644 (file)
@@ -27,9 +27,15 @@ enum AnalysisStores {
 #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,
index 4d5e6bef313aae3cd58427e2b1410c45c95e8d5d..5fc86a775996134e4eb54c0f2295eb64d7758a6b 100644 (file)
@@ -220,6 +220,15 @@ clEnumValN(NAME##Model, "analyzer-store-" CMDFLAG, DESC),
 #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 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
       assert (!AnalysisList.empty());
       return CreateAnalysisConsumer(&AnalysisList[0],
                                     &AnalysisList[0]+AnalysisList.size(),
-                                    AnalysisStoreOpt,
+                                    AnalysisStoreOpt, AnalysisDiagOpt,
                                     Diag, PP, PPF, LangOpts,
                                     AnalyzeSpecificFunction,
                                     OutputFile, VisualizeEGDot, VisualizeEGUbi,
index 78457bd76d2111e70632eb72bdecf43e6ac1a7b0..b227bbb03a2a9a570257e727dd22aa57f7784fb7 100644 (file)
@@ -26,7 +26,9 @@ PathDiagnosticClient* CreateHTMLDiagnosticClient(const std::string& prefix,
                                                  Preprocessor* PP,
                                                  PreprocessorFactory* PPF);
   
-PathDiagnosticClient* CreatePlistDiagnosticClient(const std::string& prefix);
+PathDiagnosticClient* CreatePlistDiagnosticClient(const std::string& prefix,
+                                                  Preprocessor* PP,
+                                                  PreprocessorFactory* PPF);
 }
 
 #endif
index fe8022c7c17227efc6cc24077395e69d90f5f602..500524157e57ec0698c74ee07206b91356a3406a 100644 (file)
 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 @@ PlistDiagnostics::PlistDiagnostics(const std::string& prefix)
   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 @@ static void ReportDiag(llvm::raw_ostream& o, const PathDiagnosticPiece& P,
   
   // 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 @@ void PlistDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) {
   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>";
 }