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