diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Index')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Index/CallGraph.cpp | 2 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Index/Entity.cpp | 77 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Index/EntityImpl.h | 1 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Index/Indexer.cpp | 21 | ||||
-rw-r--r-- | contrib/llvm/tools/clang/lib/Index/Makefile | 12 |
5 files changed, 85 insertions, 28 deletions
diff --git a/contrib/llvm/tools/clang/lib/Index/CallGraph.cpp b/contrib/llvm/tools/clang/lib/Index/CallGraph.cpp index 6403319..dedcc0e 100644 --- a/contrib/llvm/tools/clang/lib/Index/CallGraph.cpp +++ b/contrib/llvm/tools/clang/lib/Index/CallGraph.cpp @@ -55,7 +55,7 @@ void CGBuilder::VisitCallExpr(CallExpr *CE) { } } -CallGraph::CallGraph() : Root(0) { +CallGraph::CallGraph(Program &P) : Prog(P), Root(0) { ExternalCallingNode = getOrInsertFunction(Entity()); } diff --git a/contrib/llvm/tools/clang/lib/Index/Entity.cpp b/contrib/llvm/tools/clang/lib/Index/Entity.cpp index cd9d277..7a24719 100644 --- a/contrib/llvm/tools/clang/lib/Index/Entity.cpp +++ b/contrib/llvm/tools/clang/lib/Index/Entity.cpp @@ -42,14 +42,48 @@ public: EntityGetter(Program &prog, ProgramImpl &progImpl) : Prog(prog), ProgImpl(progImpl) { } + // Get an Entity. + Entity getEntity(Entity Parent, DeclarationName Name, + unsigned IdNS, bool isObjCInstanceMethod); + + // Get an Entity associated with the name in the global namespace. + Entity getGlobalEntity(llvm::StringRef Name); + Entity VisitNamedDecl(NamedDecl *D); Entity VisitVarDecl(VarDecl *D); + Entity VisitFieldDecl(FieldDecl *D); Entity VisitFunctionDecl(FunctionDecl *D); + Entity VisitTypeDecl(TypeDecl *D); }; } } +Entity EntityGetter::getEntity(Entity Parent, DeclarationName Name, + unsigned IdNS, bool isObjCInstanceMethod) { + llvm::FoldingSetNodeID ID; + EntityImpl::Profile(ID, Parent, Name, IdNS, isObjCInstanceMethod); + + ProgramImpl::EntitySetTy &Entities = ProgImpl.getEntities(); + void *InsertPos = 0; + if (EntityImpl *Ent = Entities.FindNodeOrInsertPos(ID, InsertPos)) + return Entity(Ent); + + void *Buf = ProgImpl.Allocate(sizeof(EntityImpl)); + EntityImpl *New = + new (Buf) EntityImpl(Parent, Name, IdNS, isObjCInstanceMethod); + Entities.InsertNode(New, InsertPos); + + return Entity(New); +} + +Entity EntityGetter::getGlobalEntity(llvm::StringRef Name) { + IdentifierInfo *II = &ProgImpl.getIdents().get(Name); + DeclarationName GlobName(II); + unsigned IdNS = Decl::IDNS_Ordinary; + return getEntity(Entity(), GlobName, IdNS, false); +} + Entity EntityGetter::VisitNamedDecl(NamedDecl *D) { Entity Parent; if (!D->getDeclContext()->isTranslationUnit()) { @@ -91,24 +125,14 @@ Entity EntityGetter::VisitNamedDecl(NamedDecl *D) { ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D); bool isObjCInstanceMethod = MD && MD->isInstanceMethod(); - - llvm::FoldingSetNodeID ID; - EntityImpl::Profile(ID, Parent, GlobName, IdNS, isObjCInstanceMethod); - - ProgramImpl::EntitySetTy &Entities = ProgImpl.getEntities(); - void *InsertPos = 0; - if (EntityImpl *Ent = Entities.FindNodeOrInsertPos(ID, InsertPos)) - return Entity(Ent); - - void *Buf = ProgImpl.Allocate(sizeof(EntityImpl)); - EntityImpl *New = - new (Buf) EntityImpl(Parent, GlobName, IdNS, isObjCInstanceMethod); - Entities.InsertNode(New, InsertPos); - - return Entity(New); + return getEntity(Parent, GlobName, IdNS, isObjCInstanceMethod); } Entity EntityGetter::VisitVarDecl(VarDecl *D) { + // Local variables have no linkage, make invalid Entities. + if (D->hasLocalStorage()) + return Entity(); + // If it's static it cannot be referred to by another translation unit. if (D->getStorageClass() == VarDecl::Static) return Entity(D); @@ -124,6 +148,18 @@ Entity EntityGetter::VisitFunctionDecl(FunctionDecl *D) { return VisitNamedDecl(D); } +Entity EntityGetter::VisitFieldDecl(FieldDecl *D) { + // Make FieldDecl an invalid Entity since it has no linkage. + return Entity(); +} + +Entity EntityGetter::VisitTypeDecl(TypeDecl *D) { + // Although in C++ class name has external linkage, usually the definition of + // the class is available in the same translation unit when it's needed. So we + // make all of them invalid Entity. + return Entity(); +} + //===----------------------------------------------------------------------===// // EntityImpl Implementation //===----------------------------------------------------------------------===// @@ -172,6 +208,12 @@ Entity EntityImpl::get(Decl *D, Program &Prog, ProgramImpl &ProgImpl) { return EntityGetter(Prog, ProgImpl).Visit(D); } +/// \brief Get an Entity associated with a global name. +Entity EntityImpl::get(llvm::StringRef Name, Program &Prog, + ProgramImpl &ProgImpl) { + return EntityGetter(Prog, ProgImpl).getGlobalEntity(Name); +} + std::string EntityImpl::getPrintableName() { return Name.getAsString(); } @@ -217,6 +259,11 @@ Entity Entity::get(Decl *D, Program &Prog) { return EntityImpl::get(D, Prog, ProgImpl); } +Entity Entity::get(llvm::StringRef Name, Program &Prog) { + ProgramImpl &ProgImpl = *static_cast<ProgramImpl*>(Prog.Impl); + return EntityImpl::get(Name, Prog, ProgImpl); +} + unsigned llvm::DenseMapInfo<Entity>::getHashValue(Entity E) { return DenseMapInfo<void*>::getHashValue(E.getAsOpaquePtr()); diff --git a/contrib/llvm/tools/clang/lib/Index/EntityImpl.h b/contrib/llvm/tools/clang/lib/Index/EntityImpl.h index cbce934..da52ccf 100644 --- a/contrib/llvm/tools/clang/lib/Index/EntityImpl.h +++ b/contrib/llvm/tools/clang/lib/Index/EntityImpl.h @@ -47,6 +47,7 @@ public: /// \brief Get an Entity associated with the given Decl. /// \returns Null if an Entity cannot refer to this Decl. static Entity get(Decl *D, Program &Prog, ProgramImpl &ProgImpl); + static Entity get(llvm::StringRef Name, Program &Prog, ProgramImpl &ProgImpl); std::string getPrintableName(); diff --git a/contrib/llvm/tools/clang/lib/Index/Indexer.cpp b/contrib/llvm/tools/clang/lib/Index/Indexer.cpp index 57bfc5b..7f21c4f 100644 --- a/contrib/llvm/tools/clang/lib/Index/Indexer.cpp +++ b/contrib/llvm/tools/clang/lib/Index/Indexer.cpp @@ -25,14 +25,22 @@ namespace { class EntityIndexer : public EntityHandler { TranslationUnit *TU; Indexer::MapTy ⤅ + Indexer::DefMapTy &DefMap; public: - EntityIndexer(TranslationUnit *tu, Indexer::MapTy &map) : TU(tu), Map(map) { } + EntityIndexer(TranslationUnit *tu, Indexer::MapTy &map, + Indexer::DefMapTy &defmap) + : TU(tu), Map(map), DefMap(defmap) { } virtual void Handle(Entity Ent) { if (Ent.isInternalToTU()) return; Map[Ent].insert(TU); + + Decl *D = Ent.getDecl(TU->getASTContext()); + if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) + if (FD->isThisDeclarationADefinition()) + DefMap[Ent] = std::make_pair(FD, TU); } }; @@ -62,7 +70,7 @@ void Indexer::IndexAST(TranslationUnit *TU) { assert(TU && "Passed null TranslationUnit"); ASTContext &Ctx = TU->getASTContext(); CtxTUMap[&Ctx] = TU; - EntityIndexer Idx(TU, Map); + EntityIndexer Idx(TU, Map, DefMap); Prog.FindEntities(Ctx, Idx); SelectorIndexer SelIdx(Prog, TU, SelMap); @@ -102,3 +110,12 @@ void Indexer::GetTranslationUnitsFor(GlobalSelector Sel, for (TUSetTy::iterator I = Set.begin(), E = Set.end(); I != E; ++I) Handler.Handle(*I); } + +std::pair<FunctionDecl *, TranslationUnit *> +Indexer::getDefinitionFor(Entity Ent) { + DefMapTy::iterator I = DefMap.find(Ent); + if (I == DefMap.end()) + return std::make_pair((FunctionDecl *)0, (TranslationUnit *)0); + else + return I->second; +} diff --git a/contrib/llvm/tools/clang/lib/Index/Makefile b/contrib/llvm/tools/clang/lib/Index/Makefile index 4d86713..e87e638 100644 --- a/contrib/llvm/tools/clang/lib/Index/Makefile +++ b/contrib/llvm/tools/clang/lib/Index/Makefile @@ -11,17 +11,9 @@ # ##===----------------------------------------------------------------------===## -LEVEL = ../../../.. -include $(LEVEL)/Makefile.config - +CLANG_LEVEL := ../.. LIBRARYNAME := clangIndex BUILD_ARCHIVE = 1 -ifeq ($(ARCH),PowerPC) -CXX.Flags += -maltivec -endif - -CPP.Flags += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include - -include $(LEVEL)/Makefile.common +include $(CLANG_LEVEL)/Makefile |