aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-29 23:39:52 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-29 23:39:52 +0000
commit52f1d4793588af6c5c09ab096818ff942bae3af6 (patch)
tree6b96038d9e89db1e8c40afb752aea9f16a4b430c
parente380c51d6f56a2cc32fa0f5723584224214c5b9f (diff)
Modify the Indexer class so that it can return the TranslationUnit that internal
decls originated from. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77534 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Index/Indexer.h3
-rw-r--r--lib/Index/Entity.cpp3
-rw-r--r--lib/Index/Indexer.cpp12
3 files changed, 15 insertions, 3 deletions
diff --git a/include/clang/Index/Indexer.h b/include/clang/Index/Indexer.h
index 3597dbff73..4fa3616064 100644
--- a/include/clang/Index/Indexer.h
+++ b/include/clang/Index/Indexer.h
@@ -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 @@ namespace idx {
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) { }
diff --git a/lib/Index/Entity.cpp b/lib/Index/Entity.cpp
index 85b4f2e196..d33110074f 100644
--- a/lib/Index/Entity.cpp
+++ b/lib/Index/Entity.cpp
@@ -59,11 +59,12 @@ Entity EntityGetter::VisitNamedDecl(NamedDecl *D) {
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)
diff --git a/lib/Index/Indexer.cpp b/lib/Index/Indexer.cpp
index 08e367a279..ddc22f7fbc 100644
--- a/lib/Index/Indexer.cpp
+++ b/lib/Index/Indexer.cpp
@@ -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 @@ public:
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::IndexAST(TranslationUnit *TU) {
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())