diff options
author | Chris Lattner <sabre@nondot.org> | 2008-10-12 06:09:52 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-10-12 06:09:52 +0000 |
commit | f6a3bda65e423955f6b6de235bcba3602e32fff0 (patch) | |
tree | 0e2c2b5fc1c6c8d82eff1b5ca34572edc2763bf2 /clang/Driver/RewriteTest.cpp | |
parent | 198966dbef6ba7de92e0145e76153f416111e97a (diff) | |
download | bcm5719-llvm-f6a3bda65e423955f6b6de235bcba3602e32fff0.tar.gz bcm5719-llvm-f6a3bda65e423955f6b6de235bcba3602e32fff0.zip |
make the -rewrite-test a bit more interesting: it now
wraps comments in <i> tags. Extend rewrite tokens to support
this minimal functionality.
llvm-svn: 57409
Diffstat (limited to 'clang/Driver/RewriteTest.cpp')
-rw-r--r-- | clang/Driver/RewriteTest.cpp | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp index 6709860272b..5af4d0e3958 100644 --- a/clang/Driver/RewriteTest.cpp +++ b/clang/Driver/RewriteTest.cpp @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// -#include "clang/Rewrite/TokenRewriter.h" #include "clang.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/TokenRewriter.h" #include <iostream> void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName, @@ -22,27 +22,18 @@ void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName, const LangOptions &LangOpts = PP.getLangOptions(); TokenRewriter Rewriter(SM.getMainFileID(), SM, LangOpts); - - - - - - std::pair<const char*,const char*> File =SM.getBufferData(SM.getMainFileID()); - - // Create a lexer to lex all the tokens of the main file in raw mode. Even - // though it is in raw mode, it will not return comments. - Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0), - LangOpts, File.first, File.second); - - RawLex.SetKeepWhitespaceMode(true); - - Token RawTok; - RawLex.LexFromRawLexer(RawTok); - while (RawTok.isNot(tok::eof)) { - std::cout << PP.getSpelling(RawTok); - RawLex.LexFromRawLexer(RawTok); + + // Throw <i> </i> tags around comments. + for (TokenRewriter::token_iterator I = Rewriter.token_begin(), + E = Rewriter.token_end(); I != E; ++I) { + if (I->isNot(tok::comment)) continue; + + Rewriter.AddTokenBefore(I, "<i>"); + Rewriter.AddTokenAfter(I, "</i>"); } + + // Print out the output. for (TokenRewriter::token_iterator I = Rewriter.token_begin(), E = Rewriter.token_end(); I != E; ++I) std::cout << PP.getSpelling(*I); |