Change ObjCInterfaceDecl to inherit from NamedDecl (not TypeDecl). While ObjCInterfaceDecl is arguably a TypeDecl, it isn't a ScopedDecl. Since TypeDecl's are scoped, it makes sense to simply treat them as NamedDecl's. I could have fiddled a bit more with the hierarchy (in terms of creating a non-scoped TypeDecl), however this probably isn't worth the effort.
I also finished unifying access to scope decl change by converting Sema::getObjCInterfaceDecl() to use Sema::LookupDecl(). This is much cleaner now:-)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49107 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index e98d9b5..d2ad5c5 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -94,7 +94,14 @@
/// with @protocol keyword, so that we can emit errors on duplicates and
/// find the declarations when needed.
llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
-
+
+ /// ObjCInterfaceDecls - Keep track of all class declarations declared
+ /// with @interface, so that we can emit errors on duplicates and
+ /// find the declarations when needed.
+ typedef llvm::DenseMap<const IdentifierInfo*,
+ ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
+ ObjCInterfaceDeclsTy ObjCInterfaceDecls;
+
/// ObjCAliasDecls - Keep track of all class declarations declared
/// with @compatibility_alias, so that we can emit errors on duplicates and
/// find the declarations when needed. This construct is ancient and will
@@ -102,7 +109,7 @@
typedef llvm::DenseMap<const IdentifierInfo*,
ObjCCompatibleAliasDecl*> ObjCAliasTy;
ObjCAliasTy ObjCAliasDecls;
-
+
// Enum values used by KnownFunctionIDs (see below).
enum {
id_printf,
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index c5901f0..c9ea54f 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -86,19 +86,11 @@
/// getObjCInterfaceDecl - Look up a for a class declaration in the scope.
/// return 0 if one not found.
-/// FIXME: removed this when ObjCInterfaceDecl's aren't ScopedDecl's.
ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *Id) {
- ScopedDecl *IDecl;
- // Scan up the scope chain looking for a decl that matches this identifier
- // that is in the appropriate namespace.
- for (IDecl = Id->getFETokenInfo<ScopedDecl>(); IDecl;
- IDecl = IDecl->getNext())
- if (IDecl->getIdentifierNamespace() == Decl::IDNS_Ordinary)
- break;
+ // The third "scope" argument is 0 since we aren't enabling lazy built-in
+ // creation from this context.
+ Decl *IDecl = LookupDecl(Id, Decl::IDNS_Ordinary, 0, false);
- if (ObjCCompatibleAliasDecl *ADecl =
- dyn_cast_or_null<ObjCCompatibleAliasDecl>(IDecl))
- return ADecl->getClassInterface();
return dyn_cast_or_null<ObjCInterfaceDecl>(IDecl);
}
@@ -130,6 +122,9 @@
// Unlike typedef's, they can only be introduced at file-scope (and are
// therefore not scoped decls). They can, however, be shadowed by
// other names in IDNS_Ordinary.
+ ObjCInterfaceDeclsTy::iterator IDI = ObjCInterfaceDecls.find(II);
+ if (IDI != ObjCInterfaceDecls.end())
+ return IDI->second;
ObjCAliasTy::iterator I = ObjCAliasDecls.find(II);
if (I != ObjCAliasDecls.end())
return I->second->getClassInterface();
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 62e7c8a..69a1022 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -101,10 +101,7 @@
IDecl = ObjCInterfaceDecl::Create(Context, AtInterfaceLoc, NumProtocols,
ClassName);
- // Chain & install the interface decl into the identifier.
- IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
- ClassName->setFETokenInfo(IDecl);
-
+ ObjCInterfaceDecls[ClassName] = IDecl;
// Remember that this needs to be removed when the scope is popped.
TUScope->AddDecl(IDecl);
}
@@ -388,8 +385,7 @@
// Build, chain & install the interface decl into the identifier.
IDecl = ObjCInterfaceDecl::Create(Context, AtClassImplLoc, 0, ClassName,
false, true);
- IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
- ClassName->setFETokenInfo(IDecl);
+ ObjCInterfaceDecls[ClassName] = IDecl;
IDecl->setSuperClass(SDecl);
IDecl->setLocEnd(ClassLoc);
@@ -597,9 +593,7 @@
if (!IDecl) { // Not already seen? Make a forward decl.
IDecl = ObjCInterfaceDecl::Create(Context, AtClassLoc, 0, IdentList[i],
true);
- // Chain & install the interface decl into the identifier.
- IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
- IdentList[i]->setFETokenInfo(IDecl);
+ ObjCInterfaceDecls[IdentList[i]] = IDecl;
// Remember that this needs to be removed when the scope is popped.
TUScope->AddDecl(IDecl);