1*0a6a1f1dSLionel Sambuc //===--- RewriteTest.cpp - Rewriter playground ----------------------------===// 2*0a6a1f1dSLionel Sambuc // 3*0a6a1f1dSLionel Sambuc // The LLVM Compiler Infrastructure 4*0a6a1f1dSLionel Sambuc // 5*0a6a1f1dSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6*0a6a1f1dSLionel Sambuc // License. See LICENSE.TXT for details. 7*0a6a1f1dSLionel Sambuc // 8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===// 9*0a6a1f1dSLionel Sambuc // 10*0a6a1f1dSLionel Sambuc // This is a testbed. 11*0a6a1f1dSLionel Sambuc // 12*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===// 13*0a6a1f1dSLionel Sambuc 14*0a6a1f1dSLionel Sambuc #include "clang/Rewrite/Frontend/Rewriters.h" 15*0a6a1f1dSLionel Sambuc #include "clang/Lex/Preprocessor.h" 16*0a6a1f1dSLionel Sambuc #include "clang/Rewrite/Core/TokenRewriter.h" 17*0a6a1f1dSLionel Sambuc #include "llvm/Support/raw_ostream.h" 18*0a6a1f1dSLionel Sambuc DoRewriteTest(Preprocessor & PP,raw_ostream * OS)19*0a6a1f1dSLionel Sambucvoid clang::DoRewriteTest(Preprocessor &PP, raw_ostream* OS) { 20*0a6a1f1dSLionel Sambuc SourceManager &SM = PP.getSourceManager(); 21*0a6a1f1dSLionel Sambuc const LangOptions &LangOpts = PP.getLangOpts(); 22*0a6a1f1dSLionel Sambuc 23*0a6a1f1dSLionel Sambuc TokenRewriter Rewriter(SM.getMainFileID(), SM, LangOpts); 24*0a6a1f1dSLionel Sambuc 25*0a6a1f1dSLionel Sambuc // Throw <i> </i> tags around comments. 26*0a6a1f1dSLionel Sambuc for (TokenRewriter::token_iterator I = Rewriter.token_begin(), 27*0a6a1f1dSLionel Sambuc E = Rewriter.token_end(); I != E; ++I) { 28*0a6a1f1dSLionel Sambuc if (I->isNot(tok::comment)) continue; 29*0a6a1f1dSLionel Sambuc 30*0a6a1f1dSLionel Sambuc Rewriter.AddTokenBefore(I, "<i>"); 31*0a6a1f1dSLionel Sambuc Rewriter.AddTokenAfter(I, "</i>"); 32*0a6a1f1dSLionel Sambuc } 33*0a6a1f1dSLionel Sambuc 34*0a6a1f1dSLionel Sambuc 35*0a6a1f1dSLionel Sambuc // Print out the output. 36*0a6a1f1dSLionel Sambuc for (TokenRewriter::token_iterator I = Rewriter.token_begin(), 37*0a6a1f1dSLionel Sambuc E = Rewriter.token_end(); I != E; ++I) 38*0a6a1f1dSLionel Sambuc *OS << PP.getSpelling(*I); 39*0a6a1f1dSLionel Sambuc } 40