aboutsummaryrefslogtreecommitdiff
path: root/lib/Index/Indexer.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-29 23:41:18 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-29 23:41:18 +0000
commitd88284b4386169bb165d70796953ef802f2e90a5 (patch)
treeee6ffe1e2c029cb06a1129f17631e422d3b2cfc1 /lib/Index/Indexer.cpp
parent0f3984809f998cdfcdef9880fcdade12c9f9b5f6 (diff)
Index the selectors and provide the translation units that contain them
through the IndexProvider. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77543 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Index/Indexer.cpp')
-rw-r--r--lib/Index/Indexer.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/lib/Index/Indexer.cpp b/lib/Index/Indexer.cpp
index ddc22f7fbc..75dfbd584c 100644
--- a/lib/Index/Indexer.cpp
+++ b/lib/Index/Indexer.cpp
@@ -13,9 +13,9 @@
#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"
+#include "ASTVisitor.h"
#include "clang/AST/DeclBase.h"
using namespace clang;
using namespace idx;
@@ -36,13 +36,37 @@ public:
}
};
+class SelectorIndexer : public ASTVisitor<SelectorIndexer> {
+ Program &Prog;
+ TranslationUnit *TU;
+ Indexer::SelMapTy &Map;
+
+public:
+ SelectorIndexer(Program &prog, TranslationUnit *tu, Indexer::SelMapTy &map)
+ : Prog(prog), TU(tu), Map(map) { }
+
+ void VisitObjCMethodDecl(ObjCMethodDecl *D) {
+ Map[GlobalSelector::get(D->getSelector(), Prog)].insert(TU);
+ Base::VisitObjCMethodDecl(D);
+ }
+
+ void VisitObjCMessageExpr(ObjCMessageExpr *Node) {
+ Map[GlobalSelector::get(Node->getSelector(), Prog)].insert(TU);
+ Base::VisitObjCMessageExpr(Node);
+ }
+};
+
} // anonymous namespace
void Indexer::IndexAST(TranslationUnit *TU) {
assert(TU && "Passed null TranslationUnit");
- CtxTUMap[&TU->getASTContext()] = TU;
+ ASTContext &Ctx = TU->getASTContext();
+ CtxTUMap[&Ctx] = TU;
EntityIndexer Idx(TU, Map);
- Prog.FindEntities(TU->getASTContext(), Idx);
+ Prog.FindEntities(Ctx, Idx);
+
+ SelectorIndexer SelIdx(Prog, TU, SelMap);
+ SelIdx.Visit(Ctx.getTranslationUnitDecl());
}
void Indexer::GetTranslationUnitsFor(Entity Ent,
@@ -65,3 +89,16 @@ void Indexer::GetTranslationUnitsFor(Entity Ent,
for (TUSetTy::iterator I = Set.begin(), E = Set.end(); I != E; ++I)
Handler.Handle(*I);
}
+
+void Indexer::GetTranslationUnitsFor(GlobalSelector Sel,
+ TranslationUnitHandler &Handler) {
+ assert(Sel.isValid() && "Expected valid GlobalSelector");
+
+ SelMapTy::iterator I = SelMap.find(Sel);
+ if (I == SelMap.end())
+ return;
+
+ TUSetTy &Set = I->second;
+ for (TUSetTy::iterator I = Set.begin(), E = Set.end(); I != E; ++I)
+ Handler.Handle(*I);
+}