[cfe-commits] r77543 - in /cfe/trunk: include/clang/Index/IndexProvider.h include/clang/Index/Indexer.h lib/Index/Indexer.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Wed Jul 29 16:41:18 PDT 2009


Author: akirtzidis
Date: Wed Jul 29 18:41:18 2009
New Revision: 77543

URL: http://llvm.org/viewvc/llvm-project?rev=77543&view=rev
Log:
Index the selectors and provide the translation units that contain them
through the IndexProvider.

Modified:
    cfe/trunk/include/clang/Index/IndexProvider.h
    cfe/trunk/include/clang/Index/Indexer.h
    cfe/trunk/lib/Index/Indexer.cpp

Modified: cfe/trunk/include/clang/Index/IndexProvider.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexProvider.h?rev=77543&r1=77542&r2=77543&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/IndexProvider.h (original)
+++ cfe/trunk/include/clang/Index/IndexProvider.h Wed Jul 29 18:41:18 2009
@@ -19,6 +19,7 @@
 namespace idx {
   class Entity;
   class TranslationUnitHandler;
+  class GlobalSelector;
 
 /// \brief Maps information to TranslationUnits.
 class IndexProvider {
@@ -26,6 +27,8 @@
   virtual ~IndexProvider();
   virtual void GetTranslationUnitsFor(Entity Ent,
                                       TranslationUnitHandler &Handler) = 0;
+  virtual void GetTranslationUnitsFor(GlobalSelector Sel,
+                                      TranslationUnitHandler &Handler) = 0;
 };
 
 } // namespace idx

Modified: cfe/trunk/include/clang/Index/Indexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/Indexer.h?rev=77543&r1=77542&r2=77543&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/Indexer.h (original)
+++ cfe/trunk/include/clang/Index/Indexer.h Wed Jul 29 18:41:18 2009
@@ -15,6 +15,8 @@
 #define LLVM_CLANG_INDEX_INDEXER_H
 
 #include "clang/Index/IndexProvider.h"
+#include "clang/Index/Entity.h"
+#include "clang/Index/GlobalSelector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/DenseMap.h"
 #include <map>
@@ -32,6 +34,7 @@
   typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy;
   typedef llvm::DenseMap<ASTContext *, TranslationUnit *> CtxTUMapTy;
   typedef std::map<Entity, TUSetTy> MapTy;
+  typedef std::map<GlobalSelector, TUSetTy> SelMapTy;
 
   explicit Indexer(Program &prog) : Prog(prog) { }
 
@@ -42,11 +45,14 @@
 
   virtual void GetTranslationUnitsFor(Entity Ent,
                                       TranslationUnitHandler &Handler);
+  virtual void GetTranslationUnitsFor(GlobalSelector Sel,
+                                      TranslationUnitHandler &Handler);
 
 private:
   Program &Prog;
   MapTy Map;
   CtxTUMapTy CtxTUMap;
+  SelMapTy SelMap;
 };
 
 } // namespace idx

Modified: cfe/trunk/lib/Index/Indexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/Indexer.cpp?rev=77543&r1=77542&r2=77543&view=diff

==============================================================================
--- cfe/trunk/lib/Index/Indexer.cpp (original)
+++ cfe/trunk/lib/Index/Indexer.cpp Wed Jul 29 18:41:18 2009
@@ -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 @@
   }
 };
 
+class SelectorIndexer : public ASTVisitor<SelectorIndexer> {
+  Program &Prog;
+  TranslationUnit *TU;
+  Indexer::SelMapTy ⤅
+
+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 @@
   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);
+}





More information about the cfe-commits mailing list