2009-07-13 06:33:12 +08:00
|
|
|
//===--- Program.cpp - Entity originator and misc -------------------------===//
|
2009-07-06 06:22:19 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Storage for Entities and utility functions
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Index/Program.h"
|
|
|
|
#include "ProgramImpl.h"
|
2009-07-30 07:38:21 +08:00
|
|
|
#include "clang/Index/Handlers.h"
|
2009-07-06 06:22:19 +08:00
|
|
|
#include "clang/Index/TranslationUnit.h"
|
|
|
|
#include "clang/AST/DeclBase.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace clang;
|
|
|
|
using namespace idx;
|
|
|
|
|
|
|
|
// Out-of-line to give the virtual tables a home.
|
|
|
|
TranslationUnit::~TranslationUnit() { }
|
|
|
|
|
|
|
|
Program::Program() : Impl(new ProgramImpl()) { }
|
|
|
|
|
|
|
|
Program::~Program() {
|
|
|
|
delete static_cast<ProgramImpl *>(Impl);
|
|
|
|
}
|
|
|
|
|
2009-07-30 07:38:45 +08:00
|
|
|
static void FindEntitiesInDC(DeclContext *DC, Program &Prog,
|
|
|
|
EntityHandler &Handler) {
|
2009-07-06 06:22:19 +08:00
|
|
|
for (DeclContext::decl_iterator
|
|
|
|
I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) {
|
2009-07-21 08:07:06 +08:00
|
|
|
if (I->getLocation().isInvalid())
|
|
|
|
continue;
|
|
|
|
Entity Ent = Entity::get(*I, Prog);
|
|
|
|
if (Ent.isValid())
|
2009-07-30 07:38:45 +08:00
|
|
|
Handler.Handle(Ent);
|
2009-07-06 06:22:19 +08:00
|
|
|
if (DeclContext *SubDC = dyn_cast<DeclContext>(*I))
|
|
|
|
FindEntitiesInDC(SubDC, Prog, Handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Traverses the AST and passes all the entities to the Handler.
|
2009-07-30 07:38:45 +08:00
|
|
|
void Program::FindEntities(ASTContext &Ctx, EntityHandler &Handler) {
|
2009-07-06 06:22:19 +08:00
|
|
|
FindEntitiesInDC(Ctx.getTranslationUnitDecl(), *this, Handler);
|
|
|
|
}
|