Argyrios Kyrtzidis | 9eec4ed | 2009-07-05 22:22:19 +0000 | [diff] [blame] | 1 | //===--- IndexProvider.h - Map of entities to translation units -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSaE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Maps Entities to TranslationUnits |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Index/IndexProvider.h" |
| 15 | #include "clang/Index/Program.h" |
| 16 | #include "clang/Index/EntityHandler.h" |
| 17 | #include "clang/Index/TranslationUnit.h" |
| 18 | using namespace clang; |
| 19 | using namespace idx; |
| 20 | |
| 21 | class IndexProvider::Indexer : public EntityHandler { |
| 22 | TranslationUnit *TU; |
| 23 | MapTy ⤅ |
| 24 | |
| 25 | public: |
| 26 | Indexer(TranslationUnit *tu, MapTy &map) : TU(tu), Map(map) { } |
| 27 | |
| 28 | virtual void HandleEntity(Entity *Ent) { |
| 29 | MapTy::iterator I = Map.find(Ent); |
| 30 | if (I != Map.end()) { |
| 31 | I->second.insert(TU); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | Map[Ent].insert(TU); |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | void IndexProvider::IndexAST(TranslationUnit *TU) { |
| 40 | Indexer Idx(TU, Map); |
| 41 | Prog.FindEntities(TU->getASTContext(), &Idx); |
| 42 | } |
| 43 | |
| 44 | IndexProvider::translation_unit_iterator |
| 45 | IndexProvider::translation_units_begin(Entity *Ent) const { |
| 46 | MapTy::iterator I = Map.find(Ent); |
| 47 | if (I == Map.end()) |
| 48 | return translation_unit_iterator(0); |
| 49 | |
| 50 | return I->second.begin(); |
| 51 | } |
| 52 | |
| 53 | IndexProvider::translation_unit_iterator |
| 54 | IndexProvider::translation_units_end(Entity *Ent) const { |
| 55 | MapTy::iterator I = Map.find(Ent); |
| 56 | if (I == Map.end()) |
| 57 | return translation_unit_iterator(0); |
| 58 | |
| 59 | return I->second.end(); |
| 60 | } |
| 61 | |
| 62 | bool IndexProvider::translation_units_empty(Entity *Ent) const { |
| 63 | MapTy::iterator I = Map.find(Ent); |
| 64 | if (I == Map.end()) |
| 65 | return true; |
| 66 | |
| 67 | return I->second.begin() == I->second.end(); |
| 68 | } |