]> granicus.if.org Git - clang/commitdiff
Static Analyzer Diagnostics: Allow checkers to add ExtraDescriptiveText, now renamed...
authorAnna Zaks <ganna@apple.com>
Mon, 22 Aug 2011 20:31:28 +0000 (20:31 +0000)
committerAnna Zaks <ganna@apple.com>
Mon, 22 Aug 2011 20:31:28 +0000 (20:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138272 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
lib/StaticAnalyzer/Core/BugReporter.cpp
lib/StaticAnalyzer/Core/CFRefCount.cpp

index cfe7048a77611500c1f53fd13d14ea4d397181dd..95b27e7861ce0d994e7106e7d2517b733858ba29 100644 (file)
@@ -62,6 +62,7 @@ public:
 
   typedef const SourceRange *ranges_iterator;
   typedef llvm::ImmutableList<BugReporterVisitor*>::iterator visitor_iterator;
+  typedef SmallVector<StringRef, 2> ExtraTextList;
 
 protected:
   friend class BugReporter;
@@ -73,6 +74,7 @@ protected:
   FullSourceLoc Location;
   const ExplodedNode *ErrorNode;
   SmallVector<SourceRange, 4> Ranges;
+  ExtraTextList ExtraText;
 
   // Not the most efficient data structure, but we use an ImmutableList for the
   // Callbacks because it is safe to make additions to list during iteration.
@@ -115,8 +117,12 @@ public:
   /// \brief This allows for addition of meta data to the diagnostic.
   ///
   /// Currently, only the HTMLDiagnosticClient knows how to display it. 
-  virtual std::pair<const char**,const char**> getExtraDescriptiveText() {
-    return std::make_pair((const char**)0,(const char**)0);
+  void addExtraText(StringRef S) {
+    ExtraText.push_back(S);
+  }
+
+  virtual const ExtraTextList &getExtraText() {
+    return ExtraText;
   }
 
   /// \brief Return the "definitive" location of the reported bug.
index 31786dd002ab6fce4348ed9cc82b248e1b4ec788..fc28c587d212f394cbca38fafa5d818503ce35ac 100644 (file)
@@ -1860,10 +1860,12 @@ void BugReporter::FlushReport(BugReportEquivClass& EQ) {
     return;
   
   // Get the meta data.
-  std::pair<const char**, const char**> Meta =
-    exampleReport->getExtraDescriptiveText();
-  for (const char** s = Meta.first; s != Meta.second; ++s)
-    D->addMeta(*s);
+  const BugReport::ExtraTextList &Meta =
+                                  exampleReport->getExtraText();
+  for (BugReport::ExtraTextList::const_iterator i = Meta.begin(),
+                                                e = Meta.end(); i != e; ++i) {
+    D->addMeta(*i);
+  }
 
   // Emit a summary diagnostic to the regular Diagnostics engine.
   BugReport::ranges_iterator Beg, End;
index 4ade451ba57609bf85d69a920f7f30f0964a34c0..e1cf34c2db49963b805e39cba2bb4fc3326036b6 100644 (file)
@@ -1797,9 +1797,9 @@ void CFRefCount::BindingsPrinter::Print(raw_ostream &Out,
 //===----------------------------------------------------------------------===//
 // Error reporting.
 //===----------------------------------------------------------------------===//
+static void addExtraTextToCFReport(BugReport &R);
 
 namespace {
-
   //===-------------===//
   // Bug Descriptions. //
   //===-------------===//
@@ -1951,12 +1951,14 @@ namespace {
       : BugReport(D, D.getDescription(), n) {
       if (registerVisitor)
         addVisitor(new CFRefReportVisitor(sym, tf));
+      addExtraTextToCFReport(*this);
     }
 
     CFRefReport(CFRefBug& D, const CFRefCount &tf,
                 ExplodedNode *n, SymbolRef sym, StringRef endText)
       : BugReport(D, D.getDescription(), endText, n) {
       addVisitor(new CFRefReportVisitor(sym, tf));
+      addExtraTextToCFReport(*this);
     }
 
     virtual ~CFRefReport() {}
@@ -1968,8 +1970,6 @@ namespace {
       else
         return std::make_pair(ranges_iterator(), ranges_iterator());
     }
-
-    std::pair<const char**,const char**> getExtraDescriptiveText();
   };
 
   class CFRefLeakReport : public CFRefReport {
@@ -1985,8 +1985,6 @@ namespace {
   };
 } // end anonymous namespace
 
-
-
 static const char* Msgs[] = {
   // GC only
   "Code is compiled to only use garbage collection",
@@ -2000,26 +1998,33 @@ static const char* Msgs[] = {
   " (non-GC).  The bug occurs in non-GC mode"
 };
 
-std::pair<const char**,const char**> CFRefReport::getExtraDescriptiveText() {
-  CFRefCount& TF = static_cast<CFRefBug&>(getBugType()).getTF();
+// Add the metadata text.
+static void addExtraTextToCFReport(BugReport &R) {
+  CFRefCount& TF = static_cast<CFRefBug&>(R.getBugType()).getTF();
 
   switch (TF.getLangOptions().getGCMode()) {
-    default:
-      assert(false);
+  default:
+    assert(false);
 
-    case LangOptions::GCOnly:
-      assert (TF.isGCEnabled());
-      return std::make_pair(&Msgs[0], &Msgs[0]+1);
+  case LangOptions::GCOnly:
+    assert (TF.isGCEnabled());
+    R.addExtraText(Msgs[0]);
+    return;
 
-    case LangOptions::NonGC:
-      assert (!TF.isGCEnabled());
-      return std::make_pair(&Msgs[1], &Msgs[1]+1);
+  case LangOptions::NonGC:
+    assert (!TF.isGCEnabled());
+    R.addExtraText(Msgs[1]);
+    return;
 
-    case LangOptions::HybridGC:
-      if (TF.isGCEnabled())
-        return std::make_pair(&Msgs[2], &Msgs[2]+1);
-      else
-        return std::make_pair(&Msgs[3], &Msgs[3]+1);
+  case LangOptions::HybridGC:
+    if (TF.isGCEnabled()) {
+      R.addExtraText(Msgs[2]);
+      return;
+    }
+    else {
+      R.addExtraText(Msgs[3]);
+      return;
+    }
   }
 }