--- /dev/null
+//===--- 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/Rewrite/TokenRewriter.h"
+#include "clang.h"
+#include "clang/Lex/Preprocessor.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();
+
+ std::pair<const char*,const char*> File =SM.getBufferData(SM.getMainFileID());
+
+ // Create a lexer to lex all the tokens of the main file in raw mode. Even
+ // though it is in raw mode, it will not return comments.
+ Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
+ LangOpts, File.first, File.second);
+
+ RawLex.SetKeepWhitespaceMode(true);
+
+ Token RawTok;
+ RawLex.LexFromRawLexer(RawTok);
+ while (RawTok.isNot(tok::eof)) {
+ std::cout << PP.getSpelling(RawTok);
+ RawLex.LexFromRawLexer(RawTok);
+ }
+
+
+}
\ No newline at end of file
RewriteObjC, // ObjC->C Rewriter.
RewriteBlocks, // ObjC->C Rewriter for Blocks.
RewriteMacros, // Expand macros but not #includes.
+ RewriteTest, // Rewriter playground
HTMLTest, // HTML displayer testing stuff.
EmitLLVM, // Emit a .ll file.
EmitBC, // Emit a .bc file.
"Build ASTs then convert to LLVM, emit .bc file"),
clEnumValN(SerializeAST, "serialize",
"Build ASTs and emit .ast file"),
+ clEnumValN(RewriteTest, "rewrite-test",
+ "Rewriter playground"),
clEnumValN(RewriteObjC, "rewrite-objc",
"Rewrite ObjC into C (code rewriter example)"),
clEnumValN(RewriteMacros, "rewrite-macros",
RewriteMacrosInInput(PP, InFile, OutputFile);
ClearSourceMgr = true;
break;
+
+ case RewriteTest:
+ DoRewriteTest(PP, InFile, OutputFile);
+ ClearSourceMgr = true;
+ break;
}
if (Consumer) {
/// RewriteMacrosInInput - Implement -rewrite-macros mode.
void RewriteMacrosInInput(Preprocessor &PP, const std::string &InFileName,
const std::string& OutFile);
+
+void DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
+ const std::string &OutFileName);
+
/// CreatePrintParserActionsAction - Return the actions implementation that
/// implements the -parse-print-callbacks option.
DE4772FA0C10EAE5002239E8 /* CGStmt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4772F90C10EAE5002239E8 /* CGStmt.cpp */; };
DE4772FC0C10EAEC002239E8 /* CGExpr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */; };
DE47999C0D2EBE1A00706D2D /* SemaExprObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE47999B0D2EBE1A00706D2D /* SemaExprObjC.cpp */; };
+ DE4DC79E0EA1C09E00069E5A /* RewriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */; };
DE5932D10AD60FF400BC794C /* clang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CD0AD60FF400BC794C /* clang.cpp */; };
DE5932D20AD60FF400BC794C /* clang.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE5932CE0AD60FF400BC794C /* clang.h */; };
DE5932D30AD60FF400BC794C /* PrintParserCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE5932CF0AD60FF400BC794C /* PrintParserCallbacks.cpp */; };
DE4772F90C10EAE5002239E8 /* CGStmt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGStmt.cpp; path = lib/CodeGen/CGStmt.cpp; sourceTree = "<group>"; tabWidth = 2; };
DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGExpr.cpp; path = lib/CodeGen/CGExpr.cpp; sourceTree = "<group>"; tabWidth = 2; };
DE47999B0D2EBE1A00706D2D /* SemaExprObjC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaExprObjC.cpp; path = lib/Sema/SemaExprObjC.cpp; sourceTree = "<group>"; tabWidth = 2; };
+ DE4DC7980EA1BE4400069E5A /* TokenRewriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TokenRewriter.h; path = clang/Rewrite/TokenRewriter.h; sourceTree = "<group>"; };
+ DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RewriteTest.cpp; path = Driver/RewriteTest.cpp; sourceTree = "<group>"; };
DE53370B0CE2D96F00D9A028 /* RewriteRope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RewriteRope.h; path = clang/Rewrite/RewriteRope.h; sourceTree = "<group>"; };
DE5932CD0AD60FF400BC794C /* clang.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = clang.cpp; path = Driver/clang.cpp; sourceTree = "<group>"; };
DE5932CE0AD60FF400BC794C /* clang.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = clang.h; path = Driver/clang.h; sourceTree = "<group>"; };
9030C1090E807A9300941490 /* RewriteBlocks.cpp */,
DEA0EBD90DD2D3C8007A02A9 /* RewriteMacros.cpp */,
035611E10DB40C8100D2EF2A /* RewriteObjC.cpp */,
+ DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */,
352981080CC58344008B5E84 /* SerializationTest.cpp */,
);
name = Driver;
35F2BE7B0DAC2963006E7668 /* HTMLRewrite.h */,
DEF7D9F60C9C8B1A0001F598 /* Rewriter.h */,
DE53370B0CE2D96F00D9A028 /* RewriteRope.h */,
+ DE4DC7980EA1BE4400069E5A /* TokenRewriter.h */,
);
name = Rewrite;
sourceTree = "<group>";
355106860E9A8507006A4E44 /* MemRegion.cpp in Sources */,
3551068C0E9A8546006A4E44 /* ParsePragma.cpp in Sources */,
3551068D0E9A8546006A4E44 /* ParseTentative.cpp in Sources */,
+ DE4DC79E0EA1C09E00069E5A /* RewriteTest.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};