clang API Documentation
00001 //===--- Program.cpp - Entity originator and misc -------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Storage for Entities and utility functions 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "clang/Index/Program.h" 00015 #include "ProgramImpl.h" 00016 #include "clang/Index/Handlers.h" 00017 #include "clang/Index/TranslationUnit.h" 00018 #include "clang/AST/DeclBase.h" 00019 #include "clang/AST/ASTContext.h" 00020 #include "llvm/Support/raw_ostream.h" 00021 using namespace clang; 00022 using namespace idx; 00023 00024 // Out-of-line to give the virtual tables a home. 00025 TranslationUnit::~TranslationUnit() { } 00026 00027 Program::Program() : Impl(new ProgramImpl()) { } 00028 00029 Program::~Program() { 00030 delete static_cast<ProgramImpl *>(Impl); 00031 } 00032 00033 static void FindEntitiesInDC(DeclContext *DC, Program &Prog, 00034 EntityHandler &Handler) { 00035 for (DeclContext::decl_iterator 00036 I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { 00037 if (I->getLocation().isInvalid()) 00038 continue; 00039 Entity Ent = Entity::get(*I, Prog); 00040 if (Ent.isValid()) 00041 Handler.Handle(Ent); 00042 if (DeclContext *SubDC = dyn_cast<DeclContext>(*I)) 00043 FindEntitiesInDC(SubDC, Prog, Handler); 00044 } 00045 } 00046 00047 /// \brief Traverses the AST and passes all the entities to the Handler. 00048 void Program::FindEntities(ASTContext &Ctx, EntityHandler &Handler) { 00049 FindEntitiesInDC(Ctx.getTranslationUnitDecl(), *this, Handler); 00050 }