Chris Lattner | 77cd2a0 | 2007-10-11 00:43:27 +0000 | [diff] [blame^] | 1 | //===--- RewriteTest.cpp - Playground for the code rewriter ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Hacks and fun related to the code rewriter. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ASTConsumers.h" |
| 15 | #include "clang/AST/AST.h" |
| 16 | #include "clang/AST/ASTConsumer.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | |
| 21 | namespace { |
| 22 | class ASTViewer : public ASTConsumer { |
| 23 | SourceManager *SM; |
| 24 | public: |
| 25 | void Initialize(ASTContext &Context, unsigned MainFileID) { |
| 26 | SM = &Context.SourceMgr; |
| 27 | } |
| 28 | |
| 29 | virtual void HandleTopLevelDecl(Decl *D); |
| 30 | }; |
| 31 | } |
| 32 | |
| 33 | ASTConsumer *clang::CreateCodeRewriterTest() { return new ASTViewer(); } |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | void ASTViewer::HandleTopLevelDecl(Decl *D) { |
| 39 | if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
| 40 | if (ND->getName()) |
| 41 | printf("%s\n", ND->getName()); |
| 42 | |
| 43 | } |