Fronted/CC_LOG_DIAGNOSTICS: Output main file name, and add support for

outputting dwarf-debug-flags.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129094 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2011-04-07 18:51:54 +00:00
Родитель 5dccf575ad
Коммит 28f14933ed
2 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -12,6 +12,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallVector.h"
namespace clang {
@ -49,11 +50,18 @@ class LogDiagnosticPrinter : public DiagnosticClient {
llvm::SmallVector<DiagEntry, 8> Entries;
std::string MainFilename;
std::string DwarfDebugFlags;
public:
LogDiagnosticPrinter(llvm::raw_ostream &OS, const DiagnosticOptions &Diags,
bool OwnsOutputStream = false);
virtual ~LogDiagnosticPrinter();
void setDwarfDebugFlags(llvm::StringRef Value) {
DwarfDebugFlags = Value;
}
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) {
LangOpts = &LO;
}

Просмотреть файл

@ -53,8 +53,14 @@ void LogDiagnosticPrinter::EndSourceFile() {
llvm::raw_svector_ostream OS(Msg);
OS << "<dict>\n";
// FIXME: Output main translation unit file name.
// FIXME: Include the invocation, if dwarf-debug-flags is available.
if (!MainFilename.empty()) {
OS << " <key>main-file</key>\n"
<< " <string>" << MainFilename << "</string>\n";
}
if (!DwarfDebugFlags.empty()) {
OS << " <key>dwarf-debug-flags</key>\n"
<< " <string>" << DwarfDebugFlags << "</string>\n";
}
OS << " <key>diagnostics</key>\n";
OS << " <array>\n";
for (unsigned i = 0, e = Entries.size(); i != e; ++i) {
@ -92,6 +98,17 @@ void LogDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
// Default implementation (Warnings/errors count).
DiagnosticClient::HandleDiagnostic(Level, Info);
// Initialize the main file name, if we haven't already fetched it.
if (MainFilename.empty()) {
const SourceManager &SM = Info.getSourceManager();
FileID FID = SM.getMainFileID();
if (!FID.isInvalid()) {
const FileEntry *FE = SM.getFileEntryForID(FID);
if (FE && FE->getName())
MainFilename = FE->getName();
}
}
// Create the diag entry.
DiagEntry DE;
DE.DiagnosticID = Info.getID();