Path: blob/main/contrib/llvm-project/clang/lib/Frontend/Rewrite/RewriteTest.cpp
35266 views
//===--- RewriteTest.cpp - Rewriter playground ----------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This is a testbed.9//10//===----------------------------------------------------------------------===//1112#include "clang/Lex/Preprocessor.h"13#include "clang/Rewrite/Core/TokenRewriter.h"14#include "clang/Rewrite/Frontend/Rewriters.h"15#include "llvm/Support/raw_ostream.h"1617void clang::DoRewriteTest(Preprocessor &PP, raw_ostream *OS) {18SourceManager &SM = PP.getSourceManager();19const LangOptions &LangOpts = PP.getLangOpts();2021TokenRewriter Rewriter(SM.getMainFileID(), SM, LangOpts);2223// Throw <i> </i> tags around comments.24for (TokenRewriter::token_iterator I = Rewriter.token_begin(),25E = Rewriter.token_end(); I != E; ++I) {26if (I->isNot(tok::comment)) continue;2728Rewriter.AddTokenBefore(I, "<i>");29Rewriter.AddTokenAfter(I, "</i>");30}313233// Print out the output.34for (TokenRewriter::token_iterator I = Rewriter.token_begin(),35E = Rewriter.token_end(); I != E; ++I)36*OS << PP.getSpelling(*I);37}383940