]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/lib/Index/Program.cpp
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / lib / Index / Program.cpp
1 //===--- Program.cpp - Entity originator and misc -------------------------===//
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/Handlers.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 TranslationUnit::~TranslationUnit() { }
26
27 Program::Program() : Impl(new ProgramImpl()) { }
28
29 Program::~Program() {
30   delete static_cast<ProgramImpl *>(Impl);
31 }
32
33 static void FindEntitiesInDC(DeclContext *DC, Program &Prog,
34                              EntityHandler &Handler) {
35   for (DeclContext::decl_iterator
36          I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) {
37     if (I->getLocation().isInvalid())
38       continue;
39     Entity Ent = Entity::get(*I, Prog);
40     if (Ent.isValid())
41       Handler.Handle(Ent);
42     if (DeclContext *SubDC = dyn_cast<DeclContext>(*I))
43       FindEntitiesInDC(SubDC, Prog, Handler);
44   }
45 }
46
47 /// \brief Traverses the AST and passes all the entities to the Handler.
48 void Program::FindEntities(ASTContext &Ctx, EntityHandler &Handler) {
49   FindEntitiesInDC(Ctx.getTranslationUnitDecl(), *this, Handler);
50 }