blob: 9a49496d74af43bbb5a198d2f149df78dd084e5e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 Handle(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();
}
|