Douglas Gregor | f78cc43 | 2010-05-07 15:41:56 +0000 | [diff] [blame] | 1 | //===-- BoostConAction.cpp - BoostCon Workshop Action -----------*- C++ -*-===// |
| 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 | #include "clang/Frontend/FrontendActions.h" |
| 10 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | d30bf2e | 2010-05-07 22:11:34 +0000 | [diff] [blame] | 11 | #include "clang/AST/RecursiveASTVisitor.h" |
Douglas Gregor | ffb507a | 2010-05-07 15:59:09 +0000 | [diff] [blame] | 12 | #include <cstdio> |
Douglas Gregor | b4eeaff | 2010-05-07 23:12:07 +0000 | [diff] [blame] | 13 | #include <iostream> |
Douglas Gregor | f78cc43 | 2010-05-07 15:41:56 +0000 | [diff] [blame] | 14 | using namespace clang; |
| 15 | |
| 16 | namespace { |
Chandler Carruth | dfc35e3 | 2010-06-09 08:17:30 +0000 | [diff] [blame] | 17 | class BoostConASTConsumer : public ASTConsumer, |
Douglas Gregor | d30bf2e | 2010-05-07 22:11:34 +0000 | [diff] [blame] | 18 | public RecursiveASTVisitor<BoostConASTConsumer> { |
Douglas Gregor | f78cc43 | 2010-05-07 15:41:56 +0000 | [diff] [blame] | 19 | public: |
| 20 | /// HandleTranslationUnit - This method is called when the ASTs for entire |
| 21 | /// translation unit have been parsed. |
| 22 | virtual void HandleTranslationUnit(ASTContext &Ctx); |
Chandler Carruth | dfc35e3 | 2010-06-09 08:17:30 +0000 | [diff] [blame] | 23 | |
Douglas Gregor | b4eeaff | 2010-05-07 23:12:07 +0000 | [diff] [blame] | 24 | bool VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 25 | std::cout << D->getNameAsString() << std::endl; |
Chandler Carruth | e3e210c | 2010-06-10 10:31:57 +0000 | [diff] [blame] | 26 | return true; |
Chandler Carruth | dfc35e3 | 2010-06-09 08:17:30 +0000 | [diff] [blame] | 27 | } |
Douglas Gregor | f78cc43 | 2010-05-07 15:41:56 +0000 | [diff] [blame] | 28 | }; |
| 29 | } |
| 30 | |
| 31 | ASTConsumer *BoostConAction::CreateASTConsumer(CompilerInstance &CI, |
| 32 | llvm::StringRef InFile) { |
| 33 | return new BoostConASTConsumer(); |
| 34 | } |
| 35 | |
| 36 | void BoostConASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { |
| 37 | fprintf(stderr, "Welcome to BoostCon!\n"); |
Chandler Carruth | dfc35e3 | 2010-06-09 08:17:30 +0000 | [diff] [blame] | 38 | TraverseDecl(Ctx.getTranslationUnitDecl()); |
Douglas Gregor | f78cc43 | 2010-05-07 15:41:56 +0000 | [diff] [blame] | 39 | } |