diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-04-17 22:31:54 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-04-17 22:31:54 +0000 |
commit | 339b9c27759d7b6a53e2370f83f66e78b3254595 (patch) | |
tree | 15e66daac43c681523a05a5df269e2a6d9f19c8d /lib/Rewrite/HTMLRewrite.cpp | |
parent | 1ee8d6ffabdec9288dbc87773913fde5e2938772 (diff) |
class Preprocessor: Now owns the "predefines" char*; it deletes [] it in its dstor.
clang.cpp: InitializePreprocessor now makes a copy of the contents of PredefinesBuffer and
passes it to the preprocessor object.
clang.cpp: DriverPreprocessorFactory now calls "InitializePreprocessor" instead of this being done in main().
html::HighlightMacros() now takes a PreprocessorFactory, allowing it to conjure up a new
Preprocessor to highlight macros.
class HTMLDiagnostics now takes a PreprocessorFactory* that it can use for html::HighlightMacros().
Updated clients of HTMLDiagnostics to use this new interface.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r-- | lib/Rewrite/HTMLRewrite.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index fd671821f6..ced8e5e938 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -12,11 +12,13 @@ // //===----------------------------------------------------------------------===// +#include "clang/Lex/Preprocessor.h" #include "clang/Rewrite/Rewriter.h" #include "clang/Rewrite/HTMLRewrite.h" #include "clang/Lex/Preprocessor.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/MemoryBuffer.h" #include <sstream> using namespace clang; @@ -382,23 +384,28 @@ void html::SyntaxHighlight(Rewriter &R, unsigned FileID, Preprocessor &PP) { /// file, to reexpand macros and insert (into the HTML) information about the /// macro expansions. This won't be perfectly perfect, but it will be /// reasonably close. -void html::HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP) { +void html::HighlightMacros(Rewriter &R, unsigned FileID, + PreprocessorFactory &PPF) { + + llvm::OwningPtr<Preprocessor> PP(PPF.CreatePreprocessor()); + + RewriteBuffer &RB = R.getEditBuffer(FileID); // Inform the preprocessor that we don't want comments. - PP.SetCommentRetentionState(false, false); + PP->SetCommentRetentionState(false, false); // Start parsing the specified input file. - PP.EnterMainSourceFile(); + PP->EnterMainSourceFile(); // Lex all the tokens. - const SourceManager &SourceMgr = PP.getSourceManager(); + const SourceManager &SourceMgr = PP->getSourceManager(); Token Tok; - PP.Lex(Tok); + PP->Lex(Tok); while (Tok.isNot(tok::eof)) { // Ignore non-macro tokens. if (!Tok.getLocation().isMacroID()) { - PP.Lex(Tok); + PP->Lex(Tok); continue; } @@ -408,7 +415,7 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP) { SourceMgr.getDecomposedFileLoc(LLoc); if (LLocInfo.first != FileID) { - PP.Lex(Tok); + PP->Lex(Tok); continue; } @@ -426,11 +433,11 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP) { strlen("<span class='macro'>")); RB.InsertTextBefore(TokOffs+TokLen, "</span>", strlen("</span>")); - std::string Expansion = PP.getSpelling(Tok); + std::string Expansion = PP->getSpelling(Tok); unsigned LineLen = Expansion.size(); // Okay, eat this token, getting the next one. - PP.Lex(Tok); + PP->Lex(Tok); // Skip all the rest of the tokens that are part of this macro // instantiation. It would be really nice to pop up a window with all the @@ -444,9 +451,9 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP) { } LineLen -= Expansion.size(); - Expansion += ' ' + PP.getSpelling(Tok); + Expansion += ' ' + PP->getSpelling(Tok); LineLen += Expansion.size(); - PP.Lex(Tok); + PP->Lex(Tok); } // Insert the information about the expansion inside the macro span. |