[cfe-commits] r120873 - in /cfe/trunk: include/clang/Checker/BugReporter/BugReporter.h lib/Checker/BugReporter.cpp lib/Checker/CFRefCount.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Dec 3 17:12:15 PST 2010


Author: akirtzidis
Date: Fri Dec  3 19:12:15 2010
New Revision: 120873

URL: http://llvm.org/viewvc/llvm-project?rev=120873&view=rev
Log:
Minor refactoring; have BugReport::getRanges return a pair of iterator, no functionality change.

Modified:
    cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h
    cfe/trunk/lib/Checker/BugReporter.cpp
    cfe/trunk/lib/Checker/CFRefCount.cpp

Modified: cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h?rev=120873&r1=120872&r2=120873&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h (original)
+++ cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h Fri Dec  3 19:12:15 2010
@@ -62,7 +62,7 @@
   std::string ShortDescription;
   std::string Description;
   const ExplodedNode *ErrorNode;
-  SourceRange R;
+  mutable SourceRange R;
 
 protected:
   friend class BugReporter;
@@ -126,8 +126,10 @@
   ///  This location is used by clients rendering diagnostics.
   virtual SourceLocation getLocation() const;
 
+  typedef const SourceRange *ranges_iterator;
+
   /// getRanges - Returns the source ranges associated with this bug.
-  virtual void getRanges(const SourceRange*& beg, const SourceRange*& end);
+  virtual std::pair<ranges_iterator, ranges_iterator> getRanges() const;
 
   virtual PathDiagnosticPiece* VisitNode(const ExplodedNode* N,
                                          const ExplodedNode* PrevN,
@@ -192,7 +194,7 @@
 
 // FIXME: Collapse this with the default BugReport class.
 class RangedBugReport : public BugReport {
-  std::vector<SourceRange> Ranges;
+  llvm::SmallVector<SourceRange, 4> Ranges;
 public:
   RangedBugReport(BugType& D, llvm::StringRef description,
                   ExplodedNode *errornode)
@@ -210,17 +212,8 @@
     Ranges.push_back(R);
   }
 
-  // FIXME: Move this out of line.
-  void getRanges(const SourceRange*& beg, const SourceRange*& end) {
-
-    if (Ranges.empty()) {
-      beg = NULL;
-      end = NULL;
-    }
-    else {
-      beg = &Ranges[0];
-      end = beg + Ranges.size();
-    }
+  virtual std::pair<ranges_iterator, ranges_iterator> getRanges() const {
+    return std::make_pair(Ranges.begin(), Ranges.end());
   }
 };
 

Modified: cfe/trunk/lib/Checker/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/BugReporter.cpp?rev=120873&r1=120872&r2=120873&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/BugReporter.cpp (original)
+++ cfe/trunk/lib/Checker/BugReporter.cpp Fri Dec  3 19:12:15 2010
@@ -1239,8 +1239,8 @@
   if (!S)
     return NULL;
 
-  const SourceRange *Beg, *End;
-  getRanges(Beg, End);
+  BugReport::ranges_iterator Beg, End;
+  llvm::tie(Beg, End) = getRanges();
   PathDiagnosticLocation L(S, BRC.getSourceManager());
 
   // Only add the statement itself as a range if we didn't specify any
@@ -1254,15 +1254,15 @@
   return P;
 }
 
-void BugReport::getRanges(const SourceRange*& beg, const SourceRange*& end) {
+std::pair<BugReport::ranges_iterator, BugReport::ranges_iterator>
+BugReport::getRanges() const {
   if (const Expr* E = dyn_cast_or_null<Expr>(getStmt())) {
     R = E->getSourceRange();
     assert(R.isValid());
-    beg = &R;
-    end = beg+1;
+    return std::make_pair(&R, &R+1);
   }
   else
-    beg = end = 0;
+    return std::make_pair(ranges_iterator(), ranges_iterator());
 }
 
 SourceLocation BugReport::getLocation() const {
@@ -1828,8 +1828,8 @@
     D->addMeta(*s);
 
   // Emit a summary diagnostic to the regular Diagnostics engine.
-  const SourceRange *Beg = 0, *End = 0;
-  exampleReport->getRanges(Beg, End);
+  BugReport::ranges_iterator Beg, End;
+  llvm::tie(Beg, End) = exampleReport->getRanges();
   Diagnostic &Diag = getDiagnostic();
   FullSourceLoc L(exampleReport->getLocation(), getSourceManager());
   
@@ -1852,7 +1852,7 @@
 
   {
     DiagnosticBuilder diagBuilder = Diag.Report(L, ErrorDiag);
-    for (const SourceRange *I = Beg; I != End; ++I)
+    for (BugReport::ranges_iterator I = Beg; I != End; ++I)
       diagBuilder << *I;
   }
 

Modified: cfe/trunk/lib/Checker/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/CFRefCount.cpp?rev=120873&r1=120872&r2=120873&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Checker/CFRefCount.cpp Fri Dec  3 19:12:15 2010
@@ -1941,15 +1941,15 @@
 
     virtual ~CFRefReport() {}
 
-    CFRefBug& getBugType() {
+    CFRefBug& getBugType() const {
       return (CFRefBug&) RangedBugReport::getBugType();
     }
 
-    virtual void getRanges(const SourceRange*& beg, const SourceRange*& end) {
+    virtual std::pair<ranges_iterator, ranges_iterator> getRanges() const {
       if (!getBugType().isLeak())
-        RangedBugReport::getRanges(beg, end);
+        return RangedBugReport::getRanges();
       else
-        beg = end = 0;
+        return std::make_pair(ranges_iterator(), ranges_iterator());
     }
 
     SymbolRef getSymbol() const { return Sym; }





More information about the cfe-commits mailing list