Chris Lattner | c3a6540 | 2009-07-12 22:33:12 +0000 | [diff] [blame] | 1 | //===--- Program.cpp - Entity originator and misc -------------------------===// |
Argyrios Kyrtzidis | 9eec4ed | 2009-07-05 22:22:19 +0000 | [diff] [blame] | 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 | // Storage for Entities and utility functions |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Index/Program.h" |
| 15 | #include "ProgramImpl.h" |
| 16 | #include "clang/Index/EntityHandler.h" |
| 17 | #include "clang/Index/TranslationUnit.h" |
| 18 | #include "clang/AST/DeclBase.h" |
| 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | using namespace clang; |
| 22 | using namespace idx; |
| 23 | |
| 24 | // Out-of-line to give the virtual tables a home. |
| 25 | EntityHandler::~EntityHandler() { } |
| 26 | TranslationUnit::~TranslationUnit() { } |
| 27 | |
Argyrios Kyrtzidis | f7cf15c | 2009-07-21 00:07:06 +0000 | [diff] [blame] | 28 | void EntityHandler::HandleEntity(Entity Ent) { } |
| 29 | |
Argyrios Kyrtzidis | 9eec4ed | 2009-07-05 22:22:19 +0000 | [diff] [blame] | 30 | Program::Program() : Impl(new ProgramImpl()) { } |
| 31 | |
| 32 | Program::~Program() { |
| 33 | delete static_cast<ProgramImpl *>(Impl); |
| 34 | } |
| 35 | |
| 36 | static void FindEntitiesInDC(DeclContext *DC, Program &Prog, EntityHandler *Handler) { |
| 37 | for (DeclContext::decl_iterator |
| 38 | I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { |
Argyrios Kyrtzidis | f7cf15c | 2009-07-21 00:07:06 +0000 | [diff] [blame] | 39 | if (I->getLocation().isInvalid()) |
| 40 | continue; |
| 41 | Entity Ent = Entity::get(*I, Prog); |
| 42 | if (Ent.isValid()) |
Argyrios Kyrtzidis | 9eec4ed | 2009-07-05 22:22:19 +0000 | [diff] [blame] | 43 | Handler->HandleEntity(Ent); |
| 44 | if (DeclContext *SubDC = dyn_cast<DeclContext>(*I)) |
| 45 | FindEntitiesInDC(SubDC, Prog, Handler); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /// \brief Traverses the AST and passes all the entities to the Handler. |
| 50 | void Program::FindEntities(ASTContext &Ctx, EntityHandler *Handler) { |
| 51 | FindEntitiesInDC(Ctx.getTranslationUnitDecl(), *this, Handler); |
| 52 | } |