diff options
Diffstat (limited to 'clang/Driver')
| -rw-r--r-- | clang/Driver/RewriteTest.cpp | 41 | ||||
| -rw-r--r-- | clang/Driver/clang.cpp | 8 | ||||
| -rw-r--r-- | clang/Driver/clang.h | 4 |
3 files changed, 53 insertions, 0 deletions
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp new file mode 100644 index 00000000000..446ae1a4fb6 --- /dev/null +++ b/clang/Driver/RewriteTest.cpp @@ -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); + } + + +}
\ No newline at end of file diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 91d521246ab..ae7ec879dda 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -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) { diff --git a/clang/Driver/clang.h b/clang/Driver/clang.h index ddb5dcb11d8..829467546d0 100644 --- a/clang/Driver/clang.h +++ b/clang/Driver/clang.h @@ -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. |

