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
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index 6709860..5af4d0e 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 @@
   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);