зеркало из https://github.com/microsoft/clang-1.git
Add a new -rewrite-test option, which is basically a
playground to experiment with some new rewriter approaches. For now it is probably the most complex version of 'cat' ever invented. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57406 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
c106c106c6
Коммит
b13c5eef36
|
@ -0,0 +1,41 @@
|
|||
//===--- 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -66,6 +66,7 @@ enum ProgActions {
|
|||
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.
|
||||
|
@ -119,6 +120,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
|
|||
"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",
|
||||
|
@ -1173,6 +1176,11 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
|
|||
RewriteMacrosInInput(PP, InFile, OutputFile);
|
||||
ClearSourceMgr = true;
|
||||
break;
|
||||
|
||||
case RewriteTest:
|
||||
DoRewriteTest(PP, InFile, OutputFile);
|
||||
ClearSourceMgr = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Consumer) {
|
||||
|
|
|
@ -32,6 +32,10 @@ void DoPrintPreprocessedInput(Preprocessor &PP, const std::string& OutFile);
|
|||
/// 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.
|
||||
|
|
|
@ -122,6 +122,7 @@
|
|||
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 */; };
|
||||
|
@ -443,6 +444,8 @@
|
|||
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>"; };
|
||||
|
@ -883,6 +886,7 @@
|
|||
9030C1090E807A9300941490 /* RewriteBlocks.cpp */,
|
||||
DEA0EBD90DD2D3C8007A02A9 /* RewriteMacros.cpp */,
|
||||
035611E10DB40C8100D2EF2A /* RewriteObjC.cpp */,
|
||||
DE4DC79D0EA1C09E00069E5A /* RewriteTest.cpp */,
|
||||
352981080CC58344008B5E84 /* SerializationTest.cpp */,
|
||||
);
|
||||
name = Driver;
|
||||
|
@ -1057,6 +1061,7 @@
|
|||
35F2BE7B0DAC2963006E7668 /* HTMLRewrite.h */,
|
||||
DEF7D9F60C9C8B1A0001F598 /* Rewriter.h */,
|
||||
DE53370B0CE2D96F00D9A028 /* RewriteRope.h */,
|
||||
DE4DC7980EA1BE4400069E5A /* TokenRewriter.h */,
|
||||
);
|
||||
name = Rewrite;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1253,6 +1258,7 @@
|
|||
355106860E9A8507006A4E44 /* MemRegion.cpp in Sources */,
|
||||
3551068C0E9A8546006A4E44 /* ParsePragma.cpp in Sources */,
|
||||
3551068D0E9A8546006A4E44 /* ParseTentative.cpp in Sources */,
|
||||
DE4DC79E0EA1C09E00069E5A /* RewriteTest.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче