From: Alexander Kornienko Date: Thu, 6 Mar 2014 13:23:30 +0000 (+0000) Subject: Added an inserter for ArrayRef. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11318087d1f201bef5ace1ab1190b2624eaa6158;p=clang Added an inserter for ArrayRef. Summary: Added an inserter for ArrayRef, 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203117 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 5e3fd015a5..e2dfd8182c 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -1015,7 +1015,8 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, int I) { 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,19 +1053,26 @@ operator<<(const DiagnosticBuilder &DB, T *DC) { DiagnosticsEngine::ak_declcontext); return DB; } - + inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, const SourceRange &R) { DB.AddSourceRange(CharSourceRange::getTokenRange(R)); return DB; } +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + ArrayRef 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<<(const DiagnosticBuilder &DB, } inline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc, - unsigned DiagID){ + unsigned DiagID) { assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!"); CurDiagLoc = Loc; CurDiagID = DiagID; diff --git a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index 119760e74f..d8feac31b0 100644 --- a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -103,14 +103,6 @@ public: IncludePath = true; } - const DiagnosticBuilder &addRanges(const DiagnosticBuilder &DB, - ArrayRef Ranges) { - for (ArrayRef::iterator I = Ranges.begin(), E = Ranges.end(); - I != E; ++I) - DB << *I; - return DB; - } - void FlushDiagnosticsImpl(std::vector &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(); } } }