aboutsummaryrefslogtreecommitdiff
path: root/Driver/RewriteTest.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-10-12 06:09:52 +0000
committerChris Lattner <sabre@nondot.org>2008-10-12 06:09:52 +0000
commit99bd46c018ece10d6541a4b6bf0dbe97ad162477 (patch)
treeef850dfd6e2cca38fea0a10b8a7f16b17f5484e1 /Driver/RewriteTest.cpp
parentcff9cc95de367a3aea885a7f8fee304fe2707b92 (diff)
make the -rewrite-test a bit more interesting: it now
wraps comments in <i> tags. Extend rewrite tokens to support this minimal functionality. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57409 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/RewriteTest.cpp')
-rw-r--r--Driver/RewriteTest.cpp31
1 files changed, 11 insertions, 20 deletions
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index 6709860272..5af4d0e395 100644
--- a/Driver/RewriteTest.cpp
+++ b/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);