diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 264a84035db8..9267bde14a6e 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -479,16 +479,21 @@ public: /// } /// class ObjCIvarDecl : public FieldDecl { - ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW) - : FieldDecl(ObjCIvar, L, Id, T, BW) {} public: - static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L, - IdentifierInfo *Id, QualType T, Expr *BW = NULL); - enum AccessControl { None, Private, Protected, Public, Package }; +private: + ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, + AccessControl ac, Expr *BW) + : FieldDecl(ObjCIvar, L, Id, T, BW) {} + +public: + static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L, + IdentifierInfo *Id, QualType T, + AccessControl ac, Expr *BW = NULL); + void setAccessControl(AccessControl ac) { DeclAccess = ac; } AccessControl getAccessControl() const { return AccessControl(DeclAccess); } diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 4b798474f626..9ba6e86cf097 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -87,9 +87,10 @@ void ObjCInterfaceDecl::Destroy(ASTContext& C) { ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, - IdentifierInfo *Id, QualType T, Expr *BW) { + IdentifierInfo *Id, QualType T, + AccessControl ac, Expr *BW) { void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCIvarDecl(L, Id, T, BW); + return new (Mem) ObjCIvarDecl(L, Id, T, ac, BW); } ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 7753a757961d..25d4ad5751b4 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1947,16 +1947,21 @@ Sema::DeclTy *Sema::ActOnIvar(Scope *S, InvalidDecl = true; } - ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T, + // Get the visibility (access control) for this ivar. + ObjCIvarDecl::AccessControl ac = + Visibility != tok::objc_not_keyword ? TranslateIvarVisibility(Visibility) + : ObjCIvarDecl::None; + + // Construct the decl. + ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T, ac, (Expr *)BitfieldWidth); + // Process attributes attached to the ivar. ProcessDeclAttributes(NewID, D); if (D.getInvalidType() || InvalidDecl) NewID->setInvalidDecl(); - // If we have visibility info, make sure the AST is set accordingly. - if (Visibility != tok::objc_not_keyword) - NewID->setAccessControl(TranslateIvarVisibility(Visibility)); + return NewID; }