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

Argiris Kirtzidis akyrtzi at gmail.com
Wed Jul 29 16:39:52 PDT 2009


Author: akirtzidis
Date: Wed Jul 29 18:39:52 2009
New Revision: 77534

URL: http://llvm.org/viewvc/llvm-project?rev=77534&view=rev
Log:
Modify the Indexer class so that it can return the TranslationUnit that internal
decls originated from.

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

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

==============================================================================
--- cfe/trunk/include/clang/Index/Indexer.h (original)
+++ cfe/trunk/include/clang/Index/Indexer.h Wed Jul 29 18:39:52 2009
@@ -16,9 +16,11 @@
 
 #include "clang/Index/IndexProvider.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/DenseMap.h"
 #include <map>
 
 namespace clang {
+  class ASTContext;
 
 namespace idx {
   class Program;
@@ -28,6 +30,7 @@
 class Indexer : public IndexProvider {
 public:
   typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy;
+  typedef llvm::DenseMap<ASTContext *, TranslationUnit *> CtxTUMapTy;
   typedef std::map<Entity, TUSetTy> MapTy;
 
   explicit Indexer(Program &prog) : Prog(prog) { }

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

==============================================================================
--- cfe/trunk/lib/Index/Entity.cpp (original)
+++ cfe/trunk/lib/Index/Entity.cpp Wed Jul 29 18:39:52 2009
@@ -59,11 +59,12 @@
     return Entity(D);
 
   // FIXME: Only works for DeclarationNames that are identifiers.
+  // Treats other DeclarationNames as internal Decls for now..
 
   DeclarationName Name = D->getDeclName();
 
   if (!Name.isIdentifier())
-    return Entity();
+    return Entity(D);
 
   IdentifierInfo *II = Name.getAsIdentifierInfo();
   if (!II)

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

==============================================================================
--- cfe/trunk/lib/Index/Indexer.cpp (original)
+++ cfe/trunk/lib/Index/Indexer.cpp Wed Jul 29 18:39:52 2009
@@ -16,6 +16,7 @@
 #include "clang/Index/Entity.h"
 #include "clang/Index/Handlers.h"
 #include "clang/Index/TranslationUnit.h"
+#include "clang/AST/DeclBase.h"
 using namespace clang;
 using namespace idx;
 
@@ -39,6 +40,7 @@
 
 void Indexer::IndexAST(TranslationUnit *TU) {
   assert(TU && "Passed null TranslationUnit");
+  CtxTUMap[&TU->getASTContext()] = TU;
   EntityIndexer Idx(TU, Map);
   Prog.FindEntities(TU->getASTContext(), Idx);
 }
@@ -46,8 +48,14 @@
 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");
+
+  if (Ent.isInternalToTU()) {
+    Decl *D = Ent.getInternalDecl();
+    CtxTUMapTy::iterator I = CtxTUMap.find(&D->getASTContext());
+    if (I != CtxTUMap.end())
+      Handler.Handle(I->second);
+    return;
+  }
 
   MapTy::iterator I = Map.find(Ent);
   if (I == Map.end())





More information about the cfe-commits mailing list