#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallVector.h"
namespace clang {
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;
}
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) {
// 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();