Use PlistSupport in a few more places
Switch over LogDiagnosticPrinter and introduce an integer helper. llvm-svn: 212384
This commit is contained in:
parent
2582895832
commit
525fdfc11e
|
@ -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, SmallVectorImpl<FileID> &V,
|
|||
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 raw_ostream &EmitInteger(raw_ostream &o, int64_t value) {
|
||||
o << "<integer>";
|
||||
o << value;
|
||||
o << "</integer>";
|
||||
return o;
|
||||
}
|
||||
|
||||
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 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_ostream &o, StringRef s) {
|
|||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,10 @@ class LogDiagnosticPrinter : public DiagnosticConsumer {
|
|||
/// 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;
|
||||
|
|
|
@ -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(DiagnosticsEngine::Level Level) {
|
|||
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";
|
||||
|
||||
|
|
|
@ -173,8 +173,8 @@ static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P,
|
|||
}
|
||||
|
||||
// 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());
|
||||
|
|
Loading…
Reference in New Issue