From b09f6e15c59b89d5820db8ef40598eb1d1323c1f Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Tue, 19 May 2009 04:14:29 +0000 Subject: Move clang-cc.h to lib/Frontend/Utils.h, and move the associated .cpp files to lib/Frontend. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72099 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/RewriteTest.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/Frontend/RewriteTest.cpp (limited to 'lib/Frontend/RewriteTest.cpp') diff --git a/lib/Frontend/RewriteTest.cpp b/lib/Frontend/RewriteTest.cpp new file mode 100644 index 0000000000..f9eb58f867 --- /dev/null +++ b/lib/Frontend/RewriteTest.cpp @@ -0,0 +1,39 @@ +//===--- 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/Frontend/Utils.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Rewrite/TokenRewriter.h" +#include "llvm/Support/raw_ostream.h" + +void clang::DoRewriteTest(Preprocessor &PP, llvm::raw_ostream* OS) { + SourceManager &SM = PP.getSourceManager(); + const LangOptions &LangOpts = PP.getLangOptions(); + + TokenRewriter Rewriter(SM.getMainFileID(), SM, LangOpts); + + // Throw 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, ""); + Rewriter.AddTokenAfter(I, ""); + } + + + // Print out the output. + for (TokenRewriter::token_iterator I = Rewriter.token_begin(), + E = Rewriter.token_end(); I != E; ++I) + *OS << PP.getSpelling(*I); +} -- cgit v1.2.3-18-g5258