r203117 - Added an inserter for ArrayRef<SourceRange>.

Alexander Kornienko alexfh at google.com
Thu Mar 6 05:23:31 PST 2014


Author: alexfh
Date: Thu Mar  6 07:23:30 2014
New Revision: 203117

URL: http://llvm.org/viewvc/llvm-project?rev=203117&view=rev
Log:
Added an inserter for ArrayRef<SourceRange>.

Summary:
Added an inserter for ArrayRef<SourceRange>, as it is already needed in at least
two places (static analyzer and clang-tidy).

Reviewers: jordan_rose

CC: cfe-commits, gribozavr

Differential Revision: http://llvm-reviews.chandlerc.com/D2984

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=203117&r1=203116&r2=203117&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Mar  6 07:23:30 2014
@@ -1015,7 +1015,8 @@ inline const DiagnosticBuilder &operator
   return DB;
 }
 
-inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,bool I) {
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+                                           bool I) {
   DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
   return DB;
 }
@@ -1052,7 +1053,7 @@ operator<<(const DiagnosticBuilder &DB,
                   DiagnosticsEngine::ak_declcontext);
   return DB;
 }
-  
+
 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                            const SourceRange &R) {
   DB.AddSourceRange(CharSourceRange::getTokenRange(R));
@@ -1060,11 +1061,18 @@ inline const DiagnosticBuilder &operator
 }
 
 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+                                           ArrayRef<SourceRange> Ranges) {
+  for (const SourceRange &R: Ranges)
+    DB.AddSourceRange(CharSourceRange::getTokenRange(R));
+  return DB;
+}
+
+inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                            const CharSourceRange &R) {
   DB.AddSourceRange(R);
   return DB;
 }
-  
+
 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
                                            const FixItHint &Hint) {
   if (!Hint.isNull())
@@ -1073,7 +1081,7 @@ inline const DiagnosticBuilder &operator
 }
 
 inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
-                                            unsigned DiagID){
+                                                   unsigned DiagID) {
   assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
   CurDiagLoc = Loc;
   CurDiagID = DiagID;

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=203117&r1=203116&r2=203117&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Thu Mar  6 07:23:30 2014
@@ -103,14 +103,6 @@ public:
     IncludePath = true;
   }
 
-  const DiagnosticBuilder &addRanges(const DiagnosticBuilder &DB,
-                                     ArrayRef<SourceRange> Ranges) {
-    for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
-         I != E; ++I)
-      DB << *I;
-    return DB;
-  }
-
   void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
                             FilesMade *filesMade) {
     unsigned WarnID = Diag.getCustomDiagID(DiagnosticsEngine::Warning, "%0");
@@ -120,8 +112,8 @@ public:
          E = Diags.end(); I != E; ++I) {
       const PathDiagnostic *PD = *I;
       SourceLocation WarnLoc = PD->getLocation().asLocation();
-      addRanges(Diag.Report(WarnLoc, WarnID) << PD->getShortDescription(),
-                PD->path.back()->getRanges());
+      Diag.Report(WarnLoc, WarnID) << PD->getShortDescription()
+                                   << PD->path.back()->getRanges();
 
       if (!IncludePath)
         continue;
@@ -131,8 +123,8 @@ public:
                                       PE = FlatPath.end();
            PI != PE; ++PI) {
         SourceLocation NoteLoc = (*PI)->getLocation().asLocation();
-        addRanges(Diag.Report(NoteLoc, NoteID) << (*PI)->getString(),
-                  (*PI)->getRanges());
+        Diag.Report(NoteLoc, NoteID) << (*PI)->getString()
+                                     << (*PI)->getRanges();
       }
     }
   }





More information about the cfe-commits mailing list