diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:38:21 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:38:21 +0000 |
commit | b17dc46c795d5eceeceb1424b96d63739d12a522 (patch) | |
tree | d41ccd8f87a22fa6ff2efea2375c96c088b1a640 /lib | |
parent | 8e9e9ef5348bce1a8f0741a5684fac3de9701c28 (diff) |
-Make IndexProvider an abstract interface for getting indexing information.
-Introduce Indexer as an IndexProvider implementation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77524 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Index/Handlers.cpp | 21 | ||||
-rw-r--r-- | lib/Index/IndexProvider.cpp | 64 | ||||
-rw-r--r-- | lib/Index/Indexer.cpp | 86 | ||||
-rw-r--r-- | lib/Index/Program.cpp | 5 |
4 files changed, 113 insertions, 63 deletions
diff --git a/lib/Index/Handlers.cpp b/lib/Index/Handlers.cpp new file mode 100644 index 0000000000..c94314b295 --- /dev/null +++ b/lib/Index/Handlers.cpp @@ -0,0 +1,21 @@ +//===--- Handlers.cpp - Interfaces for receiving information ----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Abstract interfaces for receiving information. +// +//===----------------------------------------------------------------------===// + +#include "clang/Index/Handlers.h" +#include "clang/Index/Entity.h" +using namespace clang; +using namespace idx; + +// Out-of-line to give the virtual tables a home. +EntityHandler::~EntityHandler() { } +TranslationUnitHandler::~TranslationUnitHandler() { } diff --git a/lib/Index/IndexProvider.cpp b/lib/Index/IndexProvider.cpp index 38317eb9c2..eea0988757 100644 --- a/lib/Index/IndexProvider.cpp +++ b/lib/Index/IndexProvider.cpp @@ -1,74 +1,20 @@ -//===--- IndexProvider.cpp - Map of entities to translation units ---------===// +//===- IndexProvider.cpp - Maps information 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. +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // -// Maps Entities to TranslationUnits +// Maps information to TranslationUnits. // //===----------------------------------------------------------------------===// #include "clang/Index/IndexProvider.h" -#include "clang/Index/Program.h" #include "clang/Index/Entity.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) { - if (Ent.isInternalToTU()) - return; - - 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); -} - -static IndexProvider::TUSetTy EmptySet; - -IndexProvider::translation_unit_iterator -IndexProvider::translation_units_begin(Entity Ent) const { - MapTy::iterator I = Map.find(Ent); - if (I == Map.end()) - return EmptySet.begin(); - - 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 EmptySet.end(); - - 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(); -} +// Out-of-line to give the virtual table a home. +IndexProvider::~IndexProvider() { } diff --git a/lib/Index/Indexer.cpp b/lib/Index/Indexer.cpp new file mode 100644 index 0000000000..58787d1485 --- /dev/null +++ b/lib/Index/Indexer.cpp @@ -0,0 +1,86 @@ +//===--- Indexer.cpp - IndexProvider implementation -------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// IndexProvider implementation. +// +//===----------------------------------------------------------------------===// + +#include "clang/Index/Indexer.h" +#include "clang/Index/Program.h" +#include "clang/Index/Entity.h" +#include "clang/Index/Handlers.h" +#include "clang/Index/TranslationUnit.h" +using namespace clang; +using namespace idx; + +namespace { + +class EntityIndexer : public EntityHandler { + TranslationUnit *TU; + Indexer::MapTy ⤅ + +public: + EntityIndexer(TranslationUnit *tu, Indexer::MapTy &map) : TU(tu), Map(map) { } + + virtual void HandleEntity(Entity Ent) { + if (Ent.isInternalToTU()) + return; + Map[Ent].insert(TU); + } +}; + +} // anonymous namespace + +void Indexer::IndexAST(TranslationUnit *TU) { + EntityIndexer Idx(TU, Map); + Prog.FindEntities(TU->getASTContext(), &Idx); +} + +void Indexer::GetTranslationUnitsFor(Entity Ent, + TranslationUnitHandler *Handler) { + assert(Ent.isValid() && "Expected valid Entity"); + assert(!Ent.isInternalToTU() && + "Expected an Entity visible outside of its translation unit"); + + MapTy::iterator I = Map.find(Ent); + if (I == Map.end()) + return; + + TUSetTy &Set = I->second; + for (TUSetTy::iterator I = Set.begin(), E = Set.end(); I != E; ++I) + Handler->Handle(*I); +} + +static Indexer::TUSetTy EmptySet; + +Indexer::translation_unit_iterator +Indexer::translation_units_begin(Entity Ent) const { + MapTy::iterator I = Map.find(Ent); + if (I == Map.end()) + return EmptySet.begin(); + + return I->second.begin(); +} + +Indexer::translation_unit_iterator +Indexer::translation_units_end(Entity Ent) const { + MapTy::iterator I = Map.find(Ent); + if (I == Map.end()) + return EmptySet.end(); + + return I->second.end(); +} + +bool Indexer::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(); +} diff --git a/lib/Index/Program.cpp b/lib/Index/Program.cpp index 73759dc95c..48c85f8472 100644 --- a/lib/Index/Program.cpp +++ b/lib/Index/Program.cpp @@ -13,7 +13,7 @@ #include "clang/Index/Program.h" #include "ProgramImpl.h" -#include "clang/Index/EntityHandler.h" +#include "clang/Index/Handlers.h" #include "clang/Index/TranslationUnit.h" #include "clang/AST/DeclBase.h" #include "clang/AST/ASTContext.h" @@ -22,11 +22,8 @@ using namespace clang; using namespace idx; // Out-of-line to give the virtual tables a home. -EntityHandler::~EntityHandler() { } TranslationUnit::~TranslationUnit() { } -void EntityHandler::HandleEntity(Entity Ent) { } - Program::Program() : Impl(new ProgramImpl()) { } Program::~Program() { |