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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2008-10-12 14:09:52 +08:00
|
|
|
#include "clang/Rewrite/TokenRewriter.h"
|
2008-10-12 13:29:20 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
|
|
|
|
const std::string &OutFileName) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
std::cout << PP.getSpelling(*I);
|
2008-10-20 16:12:48 +08:00
|
|
|
}
|