aboutsummaryrefslogtreecommitdiff
path: root/tools/clang-cc/RewriteTest.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-24 03:00:12 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-24 03:00:12 +0000
commit073777f3ab6f829d6f16105e0d9513b7691b4a4d (patch)
treeb609d540bdaacaf817b0a0eb24bc6171d36d8440 /tools/clang-cc/RewriteTest.cpp
parentcbcd98bdb9e8eb09203ff212bf496734c3249e33 (diff)
Move <root>/Driver into <root>/tools/clang-cc.
Again, I tried to update cmake but it is untested. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67605 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-cc/RewriteTest.cpp')
-rw-r--r--tools/clang-cc/RewriteTest.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/clang-cc/RewriteTest.cpp b/tools/clang-cc/RewriteTest.cpp
new file mode 100644
index 0000000000..1d0c6f9e9c
--- /dev/null
+++ b/tools/clang-cc/RewriteTest.cpp
@@ -0,0 +1,40 @@
+//===--- 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"
+#include "clang/Rewrite/TokenRewriter.h"
+#include <iostream>
+
+void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
+ const std::string &OutFileName) {
+ SourceManager &SM = PP.getSourceManager();
+ const LangOptions &LangOpts = PP.getLangOptions();
+
+ TokenRewriter Rewriter(SM.getMainFileID(), SM, LangOpts);
+
+ // 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>");
+ }
+
+
+ // Print out the output.
+ for (TokenRewriter::token_iterator I = Rewriter.token_begin(),
+ E = Rewriter.token_end(); I != E; ++I)
+ std::cout << PP.getSpelling(*I);
+}