2008-10-12 13:29:20 +08:00
|
|
|
//===--- RewriteTest.cpp - Rewriter playground ----------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2008-10-12 13:29:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is a testbed.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2012-09-01 13:09:24 +08:00
|
|
|
#include "clang/Rewrite/Core/TokenRewriter.h"
|
2016-07-19 03:02:11 +08:00
|
|
|
#include "clang/Rewrite/Frontend/Rewriters.h"
|
2009-05-19 09:02:07 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-10-12 13:29:20 +08:00
|
|
|
|
2016-07-19 03:02:11 +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
|
|
|
}
|