From: Ted Kremenek Date: Fri, 18 Apr 2008 05:34:33 +0000 (+0000) Subject: Provide a version of html::HighlightMacros that takes a Preprocessor&. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb58609c5b3f0d665ea58e37ef39eb7ea74758a4;p=clang Provide a version of html::HighlightMacros that takes a Preprocessor&. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49896 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Rewrite/HTMLRewrite.h b/include/clang/Rewrite/HTMLRewrite.h index 8c708400ac..a47d569eb2 100644 --- a/include/clang/Rewrite/HTMLRewrite.h +++ b/include/clang/Rewrite/HTMLRewrite.h @@ -75,9 +75,15 @@ namespace html { /// 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 HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor &PP); + + void HighlightMacros(Rewriter &R, unsigned FileID, PreprocessorFactory &PPF); + + + } // end html namespace } // end clang namespace diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index d0d1ff0b93..c854965c4f 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -393,28 +393,24 @@ 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, - PreprocessorFactory &PPF) { - - llvm::OwningPtr PP(PPF.CreatePreprocessor()); - +void html::HighlightMacros(Rewriter &R, unsigned FileID, Preprocessor& PP) { 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; } @@ -424,7 +420,7 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, SourceMgr.getDecomposedFileLoc(LLoc); if (LLocInfo.first != FileID) { - PP->Lex(Tok); + PP.Lex(Tok); continue; } @@ -442,11 +438,11 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, strlen("")); RB.InsertTextBefore(TokOffs+TokLen, "", strlen("")); - 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 @@ -461,9 +457,9 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, LineLen -= Expansion.size(); // Escape any special characters in the token text. - Expansion += ' ' + EscapeText(PP->getSpelling(Tok)); + Expansion += ' ' + EscapeText(PP.getSpelling(Tok)); LineLen += Expansion.size(); - PP->Lex(Tok); + PP.Lex(Tok); } // Insert the information about the expansion inside the macro span. @@ -472,4 +468,9 @@ void html::HighlightMacros(Rewriter &R, unsigned FileID, } } - +void html::HighlightMacros(Rewriter &R, unsigned FileID, + PreprocessorFactory &PPF) { + + llvm::OwningPtr PP(PPF.CreatePreprocessor()); + HighlightMacros(R, FileID, *PP); +}