Hook up HTMLDiagnostics to use Chris's new syntax highlighting. --html-diags
currently doesn't pass in the Preprocessor from the driver, so we don't get
syntax highlighting when we create HTMLDiagnostics in that way.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49796 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/HTMLDiagnostics.cpp b/Driver/HTMLDiagnostics.cpp
index 327a77f..b49586f 100644
--- a/Driver/HTMLDiagnostics.cpp
+++ b/Driver/HTMLDiagnostics.cpp
@@ -37,8 +37,9 @@
class VISIBILITY_HIDDEN HTMLDiagnostics : public PathDiagnosticClient {
llvm::sys::Path Directory, FilePrefix;
bool createdDir, noDir;
+ Preprocessor* PP;
public:
- HTMLDiagnostics(const std::string& prefix);
+ HTMLDiagnostics(const std::string& prefix, Preprocessor* pp = NULL);
virtual ~HTMLDiagnostics() {}
@@ -52,17 +53,18 @@
} // end anonymous namespace
-HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix)
- : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false) {
+HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp)
+ : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false),
+ PP(pp) {
// All html files begin with "report"
FilePrefix.appendComponent("report");
}
PathDiagnosticClient*
-clang::CreateHTMLDiagnosticClient(const std::string& prefix) {
+clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP) {
- return new HTMLDiagnostics(prefix);
+ return new HTMLDiagnostics(prefix, PP);
}
//===----------------------------------------------------------------------===//
@@ -116,6 +118,15 @@
html::EscapeText(R, FileID);
html::AddLineNumbers(R, FileID);
+ // If we have a preprocessor, relex the file and syntax highlight.
+ // We might not have a preprocessor if we come from a deserialized AST file,
+ // for example.
+
+ if (PP) {
+ html::SyntaxHighlight(R, FileID, *PP);
+ html::HighlightMacros(R, FileID, *PP);
+ }
+
// Get the full directory name of the analyzed file.
const FileEntry* Entry = SMgr.getFileEntryForID(FileID);