diff options
author | Chris Lattner <sabre@nondot.org> | 2008-10-12 05:29:20 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-10-12 05:29:20 +0000 |
commit | 1782da2f84eb78cccb495a3251366b3bd42149ab (patch) | |
tree | 88be88f56880b622d2dc3bfc466c397eb4e50840 /clang/Driver/RewriteTest.cpp | |
parent | fc7d4a3bd24301362a7cc88f1bfcabff9e6d40ba (diff) | |
download | bcm5719-llvm-1782da2f84eb78cccb495a3251366b3bd42149ab.tar.gz bcm5719-llvm-1782da2f84eb78cccb495a3251366b3bd42149ab.zip |
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.
llvm-svn: 57406
Diffstat (limited to 'clang/Driver/RewriteTest.cpp')
-rw-r--r-- | clang/Driver/RewriteTest.cpp | 41 |
1 files changed, 41 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 |