]> granicus.if.org Git - clang/commitdiff
PlistSupport: Eliminate duplicated EmitLocation() and EmitRange() functions
authorAlp Toker <alp@nuanti.com>
Sat, 25 Jan 2014 14:38:41 +0000 (14:38 +0000)
committerAlp Toker <alp@nuanti.com>
Sat, 25 Jan 2014 14:38:41 +0000 (14:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200077 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/PlistSupport.h
lib/ARCMigrate/PlistReporter.cpp
lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

index e410aa3b372fe1787d9e669357a0ad9a17b339d8..e636ce2a10a711a639619df6d2b3a7de8e35d658 100644 (file)
@@ -7,13 +7,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLVM_CLANG_PLISTSUPPORT_H
+#define LLVM_CLANG_PLISTSUPPORT_H
+
 #include "llvm/Support/raw_ostream.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
 
 namespace clang {
-
+namespace markup {
 typedef llvm::DenseMap<FileID, unsigned> FIDMap;
 
 static const char *PlistHeader =
@@ -24,7 +27,6 @@ static const char *PlistHeader =
 
 static void AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
                    const SourceManager &SM, SourceLocation L) {
-
   FileID FID = SM.getFileID(SM.getExpansionLoc(L));
   FIDMap::iterator I = FIDs.find(FID);
   if (I != FIDs.end())
@@ -51,7 +53,6 @@ static void EmitLocation(raw_ostream &o, const SourceManager &SM,
                          const LangOptions &LangOpts, SourceLocation L,
                          const FIDMap &FM, unsigned indent,
                          bool extend = false) {
-
   FullSourceLoc Loc(SM.getExpansionLoc(L), const_cast<SourceManager &>(SM));
 
   // Add in the length of the token, so that we cover multi-char tokens.
@@ -107,3 +108,6 @@ static raw_ostream &EmitString(raw_ostream &o, StringRef s) {
   return o;
 }
 }
+}
+
+#endif
index 433f41c517a12549c8dde70aa8a44d2e49c8b233..d88392df3065334e376314e798e4aa63b965fcba 100644 (file)
@@ -14,6 +14,7 @@
 #include "clang/Lex/Lexer.h"
 using namespace clang;
 using namespace arcmt;
+using namespace markup;
 
 void arcmt::writeARCDiagsToPlist(const std::string &outPath,
                                  ArrayRef<StoredDiagnostic> diags,
index 1a40f5e58272ecf4a5af3acbfb42a95352db97ed..f10ce2038235be87bd8f44b0995a7d210ef5edfe 100644 (file)
@@ -24,6 +24,7 @@
 #include "llvm/Support/Casting.h"
 using namespace clang;
 using namespace ento;
+using namespace markup;
 
 namespace {
   class PlistDiagnostics : public PathDiagnosticConsumer {
@@ -77,23 +78,6 @@ void ento::createPlistMultiFileDiagnosticConsumer(AnalyzerOptions &AnalyzerOpts,
                                    PP.getLangOpts(), true));
 }
 
-static void EmitLocation(raw_ostream &o, const SourceManager &SM,
-                         const LangOptions &LangOpts,
-                         const PathDiagnosticLocation &L, const FIDMap& FM,
-                         unsigned indent, bool extend = false) {
-  EmitLocation(o, SM, LangOpts, L.asLocation(), FM, indent, extend);
-}
-
-static void EmitRange(raw_ostream &o, const SourceManager &SM,
-                      const LangOptions &LangOpts,
-                      PathDiagnosticRange R, const FIDMap &FM,
-                      unsigned indent) {
-  Indent(o, indent) << "<array>\n";
-  EmitLocation(o, SM, LangOpts, R.getBegin(), FM, indent+1);
-  EmitLocation(o, SM, LangOpts, R.getEnd(), FM, indent+1, !R.isPoint);
-  Indent(o, indent) << "</array>\n";
-}
-
 static void ReportControlFlow(raw_ostream &o,
                               const PathDiagnosticControlFlowPiece& P,
                               const FIDMap& FM,
@@ -121,11 +105,13 @@ static void ReportControlFlow(raw_ostream &o,
     // logic for clients.
     Indent(o, indent) << "<key>start</key>\n";
     SourceLocation StartEdge = I->getStart().asRange().getBegin();
-    EmitRange(o, SM, LangOpts, SourceRange(StartEdge, StartEdge), FM, indent+1);
+    EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(StartEdge), FM,
+              indent + 1);
 
     Indent(o, indent) << "<key>end</key>\n";
     SourceLocation EndEdge = I->getEnd().asRange().getBegin();
-    EmitRange(o, SM, LangOpts, SourceRange(EndEdge, EndEdge), FM, indent+1);
+    EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(EndEdge), FM,
+              indent + 1);
 
     --indent;
     Indent(o, indent) << "</dict>\n";
@@ -177,7 +163,8 @@ static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P,
     ++indent;
     for (ArrayRef<SourceRange>::iterator I = Ranges.begin(), E = Ranges.end();
          I != E; ++I) {
-      EmitRange(o, SM, LangOpts, *I, FM, indent+1);
+      EmitRange(o, SM, LangOpts, CharSourceRange::getTokenRange(*I), FM,
+                indent + 1);
     }
     --indent;
     Indent(o, indent) << "</array>\n";
@@ -468,7 +455,7 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
 
     // Output the location of the bug.
     o << "  <key>location</key>\n";
-    EmitLocation(o, *SM, LangOpts, D->getLocation(), FM, 2);
+    EmitLocation(o, *SM, LangOpts, D->getLocation().asLocation(), FM, 2);
 
     // Output the diagnostic to the sub-diagnostic client, if any.
     if (!filesMade->empty()) {