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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-05-19 12:14:29 +08:00
|
|
|
#include "clang/Frontend/Utils.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
|
|
|
|
2009-05-19 09:02:07 +08:00
|
|
|
void clang::DoRewriteTest(Preprocessor &PP, llvm::raw_ostream* OS) {
|
2008-10-12 13:29:20 +08:00
|
|
|
SourceManager &SM = PP.getSourceManager();
|
|
|
|
const LangOptions &LangOpts = PP.getLangOptions();
|
|
|
|
|
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
|
|
|
}
|