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/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();