r212384 - Use PlistSupport in a few more places
Alp Toker
alp at nuanti.com
Sat Jul 5 21:26:52 PDT 2014
Author: alp
Date: Sat Jul 5 23:26:52 2014
New Revision: 212384
URL: http://llvm.org/viewvc/llvm-project?rev=212384&view=rev
Log:
Use PlistSupport in a few more places
Switch over LogDiagnosticPrinter and introduce an integer helper.
Modified:
cfe/trunk/include/clang/Basic/PlistSupport.h
cfe/trunk/include/clang/Frontend/LogDiagnosticPrinter.h
cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
Modified: cfe/trunk/include/clang/Basic/PlistSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/PlistSupport.h?rev=212384&r1=212383&r2=212384&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/PlistSupport.h (original)
+++ cfe/trunk/include/clang/Basic/PlistSupport.h Sat Jul 5 23:26:52 2014
@@ -25,8 +25,8 @@ static const char *PlistHeader =
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
"<plist version=\"1.0\">\n";
-static void AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
- const SourceManager &SM, SourceLocation L) {
+static inline 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())
@@ -35,51 +35,28 @@ static void AddFID(FIDMap &FIDs, SmallVe
V.push_back(FID);
}
-static unsigned GetFID(const FIDMap &FIDs, const SourceManager &SM,
- SourceLocation L) {
+static inline unsigned GetFID(const FIDMap &FIDs, const SourceManager &SM,
+ SourceLocation L) {
FileID FID = SM.getFileID(SM.getExpansionLoc(L));
FIDMap::const_iterator I = FIDs.find(FID);
assert(I != FIDs.end());
return I->second;
}
-static raw_ostream &Indent(raw_ostream &o, const unsigned indent) {
+static inline raw_ostream &Indent(raw_ostream &o, const unsigned indent) {
for (unsigned i = 0; i < indent; ++i)
o << ' ';
return o;
}
-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.
- unsigned offset =
- extend ? Lexer::MeasureTokenLength(Loc, SM, LangOpts) - 1 : 0;
-
- Indent(o, indent) << "<dict>\n";
- Indent(o, indent) << " <key>line</key><integer>"
- << Loc.getExpansionLineNumber() << "</integer>\n";
- Indent(o, indent) << " <key>col</key><integer>"
- << Loc.getExpansionColumnNumber() + offset
- << "</integer>\n";
- Indent(o, indent) << " <key>file</key><integer>" << GetFID(FM, SM, Loc)
- << "</integer>\n";
- Indent(o, indent) << "</dict>\n";
-}
-
-static inline void EmitRange(raw_ostream &o, const SourceManager &SM,
- const LangOptions &LangOpts, CharSourceRange 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.isTokenRange());
- Indent(o, indent) << "</array>\n";
+static inline raw_ostream &EmitInteger(raw_ostream &o, int64_t value) {
+ o << "<integer>";
+ o << value;
+ o << "</integer>";
+ return o;
}
-static raw_ostream &EmitString(raw_ostream &o, StringRef s) {
+static inline raw_ostream &EmitString(raw_ostream &o, StringRef s) {
o << "<string>";
for (StringRef::const_iterator I = s.begin(), E = s.end(); I != E; ++I) {
char c = *I;
@@ -107,6 +84,35 @@ static raw_ostream &EmitString(raw_ostre
o << "</string>";
return o;
}
+
+static inline 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.
+ unsigned offset =
+ extend ? Lexer::MeasureTokenLength(Loc, SM, LangOpts) - 1 : 0;
+
+ Indent(o, indent) << "<dict>\n";
+ Indent(o, indent) << " <key>line</key>";
+ EmitInteger(o, Loc.getExpansionLineNumber()) << '\n';
+ Indent(o, indent) << " <key>col</key>";
+ EmitInteger(o, Loc.getExpansionColumnNumber() + offset) << '\n';
+ Indent(o, indent) << " <key>file</key>";
+ EmitInteger(o, GetFID(FM, SM, Loc)) << '\n';
+ Indent(o, indent) << "</dict>\n";
+}
+
+static inline void EmitRange(raw_ostream &o, const SourceManager &SM,
+ const LangOptions &LangOpts, CharSourceRange 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.isTokenRange());
+ Indent(o, indent) << "</array>\n";
+}
}
}
Modified: cfe/trunk/include/clang/Frontend/LogDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LogDiagnosticPrinter.h?rev=212384&r1=212383&r2=212384&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/LogDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/LogDiagnosticPrinter.h Sat Jul 5 23:26:52 2014
@@ -39,7 +39,10 @@ class LogDiagnosticPrinter : public Diag
/// The level of the diagnostic.
DiagnosticsEngine::Level DiagnosticLevel;
};
-
+
+ void EmitDiagEntry(llvm::raw_ostream &OS,
+ const LogDiagnosticPrinter::DiagEntry &DE);
+
raw_ostream &OS;
const LangOptions *LangOpts;
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
Modified: cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp?rev=212384&r1=212383&r2=212384&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/LogDiagnosticPrinter.cpp Sat Jul 5 23:26:52 2014
@@ -10,11 +10,13 @@
#include "clang/Frontend/LogDiagnosticPrinter.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/PlistSupport.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
+using namespace markup;
LogDiagnosticPrinter::LogDiagnosticPrinter(raw_ostream &os,
DiagnosticOptions *diags,
@@ -40,19 +42,34 @@ static StringRef getLevelName(Diagnostic
llvm_unreachable("Invalid DiagnosticsEngine level!");
}
-// Escape XML characters inside the raw string.
-static void emitString(llvm::raw_svector_ostream &OS, const StringRef Raw) {
- for (StringRef::iterator I = Raw.begin(), E = Raw.end(); I != E; ++I) {
- char c = *I;
- switch (c) {
- default: OS << c; break;
- case '&': OS << "&"; break;
- case '<': OS << "<"; break;
- case '>': OS << ">"; break;
- case '\'': OS << "'"; break;
- case '\"': OS << """; break;
- }
+void
+LogDiagnosticPrinter::EmitDiagEntry(llvm::raw_ostream &OS,
+ const LogDiagnosticPrinter::DiagEntry &DE) {
+ OS << " <dict>\n";
+ OS << " <key>level</key>\n"
+ << " ";
+ EmitString(OS, getLevelName(DE.DiagnosticLevel)) << '\n';
+ if (!DE.Filename.empty()) {
+ OS << " <key>filename</key>\n"
+ << " ";
+ EmitString(OS, DE.Filename) << '\n';
}
+ if (DE.Line != 0) {
+ OS << " <key>line</key>\n"
+ << " ";
+ EmitInteger(OS, DE.Line) << '\n';
+ }
+ if (DE.Column != 0) {
+ OS << " <key>column</key>\n"
+ << " ";
+ EmitInteger(OS, DE.Column) << '\n';
+ }
+ if (!DE.Message.empty()) {
+ OS << " <key>message</key>\n"
+ << " ";
+ EmitString(OS, DE.Message) << '\n';
+ }
+ OS << " </dict>\n";
}
void LogDiagnosticPrinter::EndSourceFile() {
@@ -72,48 +89,18 @@ void LogDiagnosticPrinter::EndSourceFile
OS << "<dict>\n";
if (!MainFilename.empty()) {
OS << " <key>main-file</key>\n"
- << " <string>";
- emitString(OS, MainFilename);
- OS << "</string>\n";
+ << " ";
+ EmitString(OS, MainFilename) << '\n';
}
if (!DwarfDebugFlags.empty()) {
OS << " <key>dwarf-debug-flags</key>\n"
- << " <string>";
- emitString(OS, DwarfDebugFlags);
- OS << "</string>\n";
+ << " ";
+ EmitString(OS, DwarfDebugFlags) << '\n';
}
OS << " <key>diagnostics</key>\n";
OS << " <array>\n";
- for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
- DiagEntry &DE = Entries[i];
-
- OS << " <dict>\n";
- OS << " <key>level</key>\n"
- << " <string>";
- emitString(OS, getLevelName(DE.DiagnosticLevel));
- OS << "</string>\n";
- if (!DE.Filename.empty()) {
- OS << " <key>filename</key>\n"
- << " <string>";
- emitString(OS, DE.Filename);
- OS << "</string>\n";
- }
- if (DE.Line != 0) {
- OS << " <key>line</key>\n"
- << " <integer>" << DE.Line << "</integer>\n";
- }
- if (DE.Column != 0) {
- OS << " <key>column</key>\n"
- << " <integer>" << DE.Column << "</integer>\n";
- }
- if (!DE.Message.empty()) {
- OS << " <key>message</key>\n"
- << " <string>";
- emitString(OS, DE.Message);
- OS << "</string>\n";
- }
- OS << " </dict>\n";
- }
+ for (auto &DE : Entries)
+ EmitDiagEntry(OS, DE);
OS << " </array>\n";
OS << "</dict>\n";
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp?rev=212384&r1=212383&r2=212384&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp Sat Jul 5 23:26:52 2014
@@ -173,8 +173,8 @@ static void ReportEvent(raw_ostream &o,
}
// Output the call depth.
- Indent(o, indent) << "<key>depth</key>"
- << "<integer>" << depth << "</integer>\n";
+ Indent(o, indent) << "<key>depth</key>";
+ EmitInteger(o, depth) << '\n';
// Output the text.
assert(!P.getString().empty());
More information about the cfe-commits
mailing list