From: Steve Naroff Date: Fri, 14 Sep 2007 23:09:53 +0000 (+0000) Subject: Rename Action::ParseRecordBody() to ProcessFieldDecls(), and add a visibility argument. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f13271f8402b4434f978b64143f236db0a99c13a;p=clang Rename Action::ParseRecordBody() to ProcessFieldDecls(), and add a visibility argument. Remove Action::ObjcAddVisibilityToIvars(). No need for an extra API when it is trivial to add this info to the previous hook. In general, I want to start migrating away from having Actions prefixed with "Parse" (which is confusing, since the Action API doesn't do any parsing, per se). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41973 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Parse/ParseDecl.cpp b/Parse/ParseDecl.cpp index be3711106b..9dd0d95d79 100644 --- a/Parse/ParseDecl.cpp +++ b/Parse/ParseDecl.cpp @@ -757,7 +757,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc, MatchRHSPunctuation(tok::r_brace, LBraceLoc); - Actions.ParseRecordBody(RecordLoc, TagDecl, &FieldDecls[0],FieldDecls.size()); + Actions.ProcessFieldDecls(RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size()); AttributeList *AttrList = 0; // If attributes exist after struct contents, parse them. diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 29f8001c13..791057b627 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -659,10 +659,9 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) { } } if (AllIvarDecls.size()) { // Check for {} - no ivars in braces - Actions.ObjcAddVisibilityToIvars(interfaceDecl, - &AllIvarDecls[0], AllIvarDecls.size(), &AllVisibilities[0]); - Actions.ParseRecordBody(LBraceLoc, interfaceDecl, - &AllIvarDecls[0], AllIvarDecls.size()); + Actions.ProcessFieldDecls(LBraceLoc, interfaceDecl, + &AllIvarDecls[0], AllIvarDecls.size(), + &AllVisibilities[0]); } MatchRHSPunctuation(tok::r_brace, LBraceLoc); return; diff --git a/Sema/Sema.h b/Sema/Sema.h index 2b50f5e354..a9e33f423a 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -155,8 +155,11 @@ private: SourceLocation NameLoc, AttributeList *Attr); virtual DeclTy *ParseField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart, Declarator &D, ExprTy *BitfieldWidth); - virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl, - DeclTy **Fields, unsigned NumFields); + + // This is used for both record definitions and ObjC interface declarations. + virtual void ProcessFieldDecls(SourceLocation RecLoc, DeclTy *TagDecl, + DeclTy **Fields, unsigned NumFields, + tok::ObjCKeywordKind *visibility = 0); virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl, DeclTy *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, @@ -368,10 +371,6 @@ public: virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc, tok::TokenKind MethodType, TypeTy *ReturnType, IdentifierInfo *SelectorName, AttributeList *AttrList); - - virtual void ObjcAddVisibilityToIvars(DeclTy *ClassDec, DeclTy **Ivar, - unsigned numIvars, - tok::ObjCKeywordKind *visibility); private: // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts // functions and arrays to their respective pointers (C99 6.3.2.1). diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 260a450dd4..b0a3a1266a 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -877,40 +877,6 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(SourceLocation AtInterfaceLoc, return IDecl; } -void Sema::ObjcAddVisibilityToIvars(DeclTy *ClassDecl, DeclTy **Ivar, - unsigned numIvars, - tok::ObjCKeywordKind *visibility) { - assert((ClassDecl && numIvars) && "missing class or instance variable"); - ObjcInterfaceDecl *OInterface = dyn_cast( - static_cast(ClassDecl)); - assert (OInterface && "mistyped class"); - for (unsigned i = 0; i != numIvars; ++i) { - ObjcIvarDecl *OIvar = dyn_cast(static_cast(Ivar[i])); - tok::ObjCKeywordKind ivarVisibility = visibility[i]; - - assert(OIvar && "mistyped instance variable"); - - switch (ivarVisibility) { - case tok::objc_private: - OIvar->setAccessControl(ObjcIvarDecl::Private); - break; - case tok::objc_public: - OIvar->setAccessControl(ObjcIvarDecl::Public); - break; - case tok::objc_protected: - OIvar->setAccessControl(ObjcIvarDecl::Protected); - break; - case tok::objc_package: - OIvar->setAccessControl(ObjcIvarDecl::Package); - break; - default: - OIvar->setAccessControl(ObjcIvarDecl::None); - break; - } - } - // FIXME: add to the class... -} - /// ObjcClassDeclaration - /// Scope will always be top level file scope. Action::DeclTy * @@ -1092,10 +1058,31 @@ Sema::DeclTy *Sema::ParseField(Scope *S, DeclTy *TagDecl, return NewFD; } -// FIXME: Change ParseRecordBody name to something more generic as -// it also used for ivar semantics check. -void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl, - DeclTy **Fields, unsigned NumFields) { +static void ObjcSetIvarVisibility(ObjcIvarDecl *OIvar, + tok::ObjCKeywordKind ivarVisibility) { + assert(OIvar && "missing instance variable"); + switch (ivarVisibility) { + case tok::objc_private: + OIvar->setAccessControl(ObjcIvarDecl::Private); + break; + case tok::objc_public: + OIvar->setAccessControl(ObjcIvarDecl::Public); + break; + case tok::objc_protected: + OIvar->setAccessControl(ObjcIvarDecl::Protected); + break; + case tok::objc_package: + OIvar->setAccessControl(ObjcIvarDecl::Package); + break; + default: + OIvar->setAccessControl(ObjcIvarDecl::None); + break; + } +} + +void Sema::ProcessFieldDecls(SourceLocation RecLoc, DeclTy *RecDecl, + DeclTy **Fields, unsigned NumFields, + tok::ObjCKeywordKind *visibility) { Decl *EnclosingDecl = static_cast(RecDecl); assert(EnclosingDecl && "missing record or interface decl"); RecordDecl *Record = dyn_cast(EnclosingDecl); @@ -1127,6 +1114,10 @@ void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl, // Get the type for the field. Type *FDTy = FD->getType().getTypePtr(); + // If we have visibility info, make sure the AST is set accordingly. + if (visibility) + ObjcSetIvarVisibility(dyn_cast(FD), visibility[i]); + // C99 6.7.2.1p2 - A field may not be a function type. if (FDTy->isFunctionType()) { Diag(FD->getLocation(), diag::err_field_declared_as_function, diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 770187a930..141261b7cd 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -180,9 +180,9 @@ public: Declarator &D, ExprTy *BitfieldWidth) { return 0; } - virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl, - DeclTy **Fields, unsigned NumFields) {} - + virtual void ProcessFieldDecls(SourceLocation RecLoc, DeclTy *TagDecl, + DeclTy **Fields, unsigned NumFields, + tok::ObjCKeywordKind *visibility = 0) {} virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl, DeclTy *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, @@ -449,11 +449,6 @@ public: AttributeList *AttrList) { return 0; } - virtual void ObjcAddVisibilityToIvars(DeclTy *ClassDec, DeclTy **Ivars, - unsigned numIvars, - tok::ObjCKeywordKind *visibility) { - return; - } virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl, DeclTy **allMethods, unsigned allNum) { return;