blob: 446ae1a4fb65db30fb6cf9b6596adac038f29b79 [file] [log] [blame]
Chris Lattnerb13c5ee2008-10-12 05:29:20 +00001//===--- RewriteTest.cpp - Rewriter playground ----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is a testbed.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Rewrite/TokenRewriter.h"
15#include "clang.h"
16#include "clang/Lex/Preprocessor.h"
17#include <iostream>
18
19void clang::DoRewriteTest(Preprocessor &PP, const std::string &InFileName,
20 const std::string &OutFileName) {
21 SourceManager &SM = PP.getSourceManager();
22 const LangOptions &LangOpts = PP.getLangOptions();
23
24 std::pair<const char*,const char*> File =SM.getBufferData(SM.getMainFileID());
25
26 // Create a lexer to lex all the tokens of the main file in raw mode. Even
27 // though it is in raw mode, it will not return comments.
28 Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
29 LangOpts, File.first, File.second);
30
31 RawLex.SetKeepWhitespaceMode(true);
32
33 Token RawTok;
34 RawLex.LexFromRawLexer(RawTok);
35 while (RawTok.isNot(tok::eof)) {
36 std::cout << PP.getSpelling(RawTok);
37 RawLex.LexFromRawLexer(RawTok);
38 }
39
40
41}