blob: 22fad9f96446f1d5bd0f0ab6c99a0cff04639bff [file] [log] [blame]
Argyrios Kyrtzidis9eec4ed2009-07-05 22:22:19 +00001//===--- Program.h - Entity originator and misc -----------------*- 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//
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"
21using namespace clang;
22using namespace idx;
23
24// Out-of-line to give the virtual tables a home.
25EntityHandler::~EntityHandler() { }
26TranslationUnit::~TranslationUnit() { }
27
28Program::Program() : Impl(new ProgramImpl()) { }
29
30Program::~Program() {
31 delete static_cast<ProgramImpl *>(Impl);
32}
33
34static void FindEntitiesInDC(DeclContext *DC, Program &Prog, EntityHandler *Handler) {
35 for (DeclContext::decl_iterator
36 I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) {
37 Entity *Ent = Entity::get(*I, Prog);
38 if (Ent)
39 Handler->HandleEntity(Ent);
40 if (DeclContext *SubDC = dyn_cast<DeclContext>(*I))
41 FindEntitiesInDC(SubDC, Prog, Handler);
42 }
43}
44
45/// \brief Traverses the AST and passes all the entities to the Handler.
46void Program::FindEntities(ASTContext &Ctx, EntityHandler *Handler) {
47 FindEntitiesInDC(Ctx.getTranslationUnitDecl(), *this, Handler);
48}