diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-05 22:22:19 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-05 22:22:19 +0000 |
commit | 9eec4ed6ca0dcf098580da9146b97e0841556d12 (patch) | |
tree | 990b7278fb0983249a24c985f00fc4ff361a7d42 /lib/Index/IndexProvider.cpp | |
parent | 2c2ba3e258961dd98cacffe3a2167bb6d958fd53 (diff) |
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
Diffstat (limited to 'lib/Index/IndexProvider.cpp')
-rw-r--r-- | lib/Index/IndexProvider.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/Index/IndexProvider.cpp b/lib/Index/IndexProvider.cpp new file mode 100644 index 0000000000..45719bb8e1 --- /dev/null +++ b/lib/Index/IndexProvider.cpp @@ -0,0 +1,68 @@ +//===--- IndexProvider.h - Map of entities to translation units -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSaE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Maps Entities to TranslationUnits +// +//===----------------------------------------------------------------------===// + +#include "clang/Index/IndexProvider.h" +#include "clang/Index/Program.h" +#include "clang/Index/EntityHandler.h" +#include "clang/Index/TranslationUnit.h" +using namespace clang; +using namespace idx; + +class IndexProvider::Indexer : public EntityHandler { + TranslationUnit *TU; + MapTy ⤅ + +public: + Indexer(TranslationUnit *tu, MapTy &map) : TU(tu), Map(map) { } + + virtual void HandleEntity(Entity *Ent) { + MapTy::iterator I = Map.find(Ent); + if (I != Map.end()) { + I->second.insert(TU); + return; + } + + Map[Ent].insert(TU); + } +}; + +void IndexProvider::IndexAST(TranslationUnit *TU) { + Indexer Idx(TU, Map); + Prog.FindEntities(TU->getASTContext(), &Idx); +} + +IndexProvider::translation_unit_iterator +IndexProvider::translation_units_begin(Entity *Ent) const { + MapTy::iterator I = Map.find(Ent); + if (I == Map.end()) + return translation_unit_iterator(0); + + return I->second.begin(); +} + +IndexProvider::translation_unit_iterator +IndexProvider::translation_units_end(Entity *Ent) const { + MapTy::iterator I = Map.find(Ent); + if (I == Map.end()) + return translation_unit_iterator(0); + + return I->second.end(); +} + +bool IndexProvider::translation_units_empty(Entity *Ent) const { + MapTy::iterator I = Map.find(Ent); + if (I == Map.end()) + return true; + + return I->second.begin() == I->second.end(); +} |