2008-10-12 13:29:20 +08:00
|
|
|
//===--- RewriteTest.cpp - Rewriter playground ----------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is a testbed.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-06-16 01:48:49 +08:00
|
|
|
#include "clang/Rewrite/Rewriters.h"
|
2008-10-12 13:29:20 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2008-10-12 14:09:52 +08:00
|
|
|
#include "clang/Rewrite/TokenRewriter.h"
|
2009-05-19 09:02:07 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-10-12 13:29:20 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void clang::DoRewriteTest(Preprocessor &PP, raw_ostream* OS) {
|
2008-10-12 13:29:20 +08:00
|
|
|
SourceManager &SM = PP.getSourceManager();
|
2012-03-11 15:00:24 +08:00
|
|
|
const LangOptions &LangOpts = PP.getLangOpts();
|
2008-10-12 13:29:20 +08:00
|
|
|
|
2008-10-12 13:44:03 +08:00
|
|
|
TokenRewriter Rewriter(SM.getMainFileID(), SM, LangOpts);
|
2008-10-12 14:09:52 +08:00
|
|
|
|
|
|
|
// 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>");
|
2008-10-12 13:29:20 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
|
2008-10-12 14:09:52 +08:00
|
|
|
// Print out the output.
|
2008-10-12 13:44:03 +08:00
|
|
|
for (TokenRewriter::token_iterator I = Rewriter.token_begin(),
|
|
|
|
E = Rewriter.token_end(); I != E; ++I)
|
2009-05-19 09:02:07 +08:00
|
|
|
*OS << PP.getSpelling(*I);
|
2008-10-20 16:12:48 +08:00
|
|
|
}
|