diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-06-05 18:16:35 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-06-05 18:16:35 +0000 |
commit | 496b5a894c5ec5425de53909f5aac3fb4771a2ec (patch) | |
tree | 72853dce38a871d04763325c89e8a6acd3dcb879 /lib/Sema/SemaDecl.cpp | |
parent | f5dba388e7d4a725b7ac9a7000bfdf0c2da9a36a (diff) |
Use of DeclContext for objc's ivars. No functionality
change. More to follow.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72951 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 51b5449d9f..c67af295c1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3914,6 +3914,7 @@ TranslateIvarVisibility(tok::ObjCKeywordKind ivarVisibility) { /// in order to create an IvarDecl object for it. Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, SourceLocation DeclStart, + DeclPtrTy IntfDecl, Declarator &D, ExprTy *BitfieldWidth, tok::ObjCKeywordKind Visibility) { @@ -3952,14 +3953,28 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S, ObjCIvarDecl::AccessControl ac = Visibility != tok::objc_not_keyword ? TranslateIvarVisibility(Visibility) : ObjCIvarDecl::None; - + // Must set ivar's DeclContext to its enclosing interface. + Decl *EnclosingDecl = IntfDecl.getAs<Decl>(); + DeclContext *EnclosingContext; + if (ObjCImplementationDecl *IMPDecl = + dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) { + // Case of ivar declared in an implementation. Context is that of its class. + ObjCInterfaceDecl* IDecl = IMPDecl->getClassInterface(); + assert(IDecl && "No class- ActOnIvar"); + EnclosingContext = cast_or_null<DeclContext>(IDecl); + } + else + EnclosingContext = dyn_cast<DeclContext>(EnclosingDecl); + assert(EnclosingContext && "null DeclContext for ivar - ActOnIvar"); + // Construct the decl. - ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, CurContext, Loc, II, T,ac, + ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, + EnclosingContext, Loc, II, T,ac, (Expr *)BitfieldWidth); if (II) { NamedDecl *PrevDecl = LookupName(S, II, LookupMemberName, true); - if (PrevDecl && isDeclInScope(PrevDecl, CurContext, S) + if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S) && !isa<TagDecl>(PrevDecl)) { Diag(Loc, diag::err_duplicate_member) << II; Diag(PrevDecl->getLocation(), diag::note_previous_declaration); @@ -4100,7 +4115,11 @@ void Sema::ActOnFields(Scope* S, if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) { ID->setIVarList(ClsFields, RecFields.size(), Context); ID->setLocEnd(RBrac); - + // Add ivar's to class's DeclContext. + for (unsigned i = 0, e = RecFields.size(); i != e; ++i) { + ClsFields[i]->setLexicalDeclContext(ID); + ID->addDecl(Context, ClsFields[i]); + } // Must enforce the rule that ivars in the base classes may not be // duplicates. if (ID->getSuperClass()) { @@ -4121,12 +4140,10 @@ void Sema::ActOnFields(Scope* S, } else if (ObjCImplementationDecl *IMPDecl = dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) { assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl"); - for (unsigned I = 0, N = RecFields.size(); I != N; ++I) { - // FIXME: Set the DeclContext correctly when we build the - // declarations. + for (unsigned I = 0, N = RecFields.size(); I != N; ++I) + // Ivar declared in @implementation never belongs to the implementation. + // Only it is in implementation's lexical context. ClsFields[I]->setLexicalDeclContext(IMPDecl); - IMPDecl->addDecl(Context, ClsFields[I]); - } CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac); } } |