From 9eec4ed6ca0dcf098580da9146b97e0841556d12 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sun, 5 Jul 2009 22:22:19 +0000 Subject: Introduce the 'Index' library. Its purpose is to provide the basic infrastructure for cross-translation-unit analysis like indexing, refactoring, etc. Currently it is very "primitive" and with no type-names support. It can provide functionality like "show me all references of this function from these translation units". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74802 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/Program.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/Index/Program.cpp (limited to 'lib/Index/Program.cpp') diff --git a/lib/Index/Program.cpp b/lib/Index/Program.cpp new file mode 100644 index 0000000000..22fad9f964 --- /dev/null +++ b/lib/Index/Program.cpp @@ -0,0 +1,48 @@ +//===--- Program.h - Entity originator and misc -----------------*- C++ -*-===// +// +// 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" +#include "clang/Index/EntityHandler.h" +#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. +EntityHandler::~EntityHandler() { } +TranslationUnit::~TranslationUnit() { } + +Program::Program() : Impl(new ProgramImpl()) { } + +Program::~Program() { + delete static_cast(Impl); +} + +static void FindEntitiesInDC(DeclContext *DC, Program &Prog, EntityHandler *Handler) { + for (DeclContext::decl_iterator + I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) { + Entity *Ent = Entity::get(*I, Prog); + if (Ent) + Handler->HandleEntity(Ent); + if (DeclContext *SubDC = dyn_cast(*I)) + FindEntitiesInDC(SubDC, Prog, Handler); + } +} + +/// \brief Traverses the AST and passes all the entities to the Handler. +void Program::FindEntities(ASTContext &Ctx, EntityHandler *Handler) { + FindEntitiesInDC(Ctx.getTranslationUnitDecl(), *this, Handler); +} -- cgit v1.2.3-18-g5258