summaryrefslogtreecommitdiffstats
path: root/clang/lib/Index/Entity.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2010-07-06 05:55:13 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2010-07-06 05:55:13 +0000
commitb525bce698882e9387dcfd53295717d366ada364 (patch)
tree4fe56c93850256f111612e150bcf7123545ae625 /clang/lib/Index/Entity.cpp
parent8f06b4a294cdf22ee9e2623c1a6919ebd6fc309a (diff)
downloadbcm5719-llvm-b525bce698882e9387dcfd53295717d366ada364.tar.gz
bcm5719-llvm-b525bce698882e9387dcfd53295717d366ada364.zip
Collect function definitions in the Indexer when indexing through the ASTs.
Add an API to get an Entity associated with a name in the global namespace. llvm-svn: 107642
Diffstat (limited to 'clang/lib/Index/Entity.cpp')
-rw-r--r--clang/lib/Index/Entity.cpp59
1 files changed, 44 insertions, 15 deletions
diff --git a/clang/lib/Index/Entity.cpp b/clang/lib/Index/Entity.cpp
index b6fb17fc2b1..7a247191bee 100644
--- a/clang/lib/Index/Entity.cpp
+++ b/clang/lib/Index/Entity.cpp
@@ -42,6 +42,13 @@ 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);
@@ -52,6 +59,31 @@ public:
}
}
+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()) {
@@ -93,21 +125,7 @@ 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) {
@@ -190,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();
}
@@ -235,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());
OpenPOWER on IntegriCloud