[cfe-commits] r98280 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Sema/SemaDeclObjC.cpp
Daniel Dunbar
daniel at zuster.org
Fri Mar 12 00:17:15 PST 2010
On Thu, Mar 11, 2010 at 11:44 AM, Ted Kremenek <kremenek at apple.com> wrote:
> Author: kremenek
> Date: Thu Mar 11 13:44:54 2010
> New Revision: 98280
>
> URL: http://llvm.org/viewvc/llvm-project?rev=98280&view=rev
> Log:
> For ivars created using @synthesize, set their DeclContext to be
> the @implementation (instead of the @interface) and actually add
> the ivar to the DeclContext (which we weren't doing before).
>
> This allows us to simplify ASTContext::CollectNonClassIvars() by
> removing ASTContext::CollectProtocolSynthesizedIvars(). Now all
> ivars can be found by either inspecting the ObjCInterfaceDecl and
> its companion ObjCImplementationDecl.
Nice!
- Daniel
>
> Modified:
> cfe/trunk/include/clang/AST/ASTContext.h
> cfe/trunk/lib/AST/ASTContext.cpp
> cfe/trunk/lib/Sema/SemaDeclObjC.cpp
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=98280&r1=98279&r2=98280&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Thu Mar 11 13:44:54 2010
> @@ -950,8 +950,6 @@
> llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
> void CollectNonClassIvars(const ObjCInterfaceDecl *OI,
> llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
> - void CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
> - llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
> unsigned CountSynthesizedIvars(const ObjCInterfaceDecl *OI);
> unsigned CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD);
> void CollectInheritedProtocols(const Decl *CDecl,
>
> Modified: cfe/trunk/lib/AST/ASTContext.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=98280&r1=98279&r2=98280&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
> +++ cfe/trunk/lib/AST/ASTContext.cpp Thu Mar 11 13:44:54 2010
> @@ -971,22 +971,10 @@
> CollectNonClassIvars(OI, Ivars);
> }
>
> -void ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD,
> - llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
> - for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(),
> - E = PD->prop_end(); I != E; ++I)
> - if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
> - Ivars.push_back(Ivar);
> -
> - // Also look into nested protocols.
> - for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(),
> - E = PD->protocol_end(); P != E; ++P)
> - CollectProtocolSynthesizedIvars(*P, Ivars);
> -}
> -
> /// CollectNonClassIvars -
> /// This routine collects all other ivars which are not declared in the class.
> -/// This includes synthesized ivars and those in class's implementation.
> +/// This includes synthesized ivars (via @synthesize) and those in
> +// class's @implementation.
> ///
> void ASTContext::CollectNonClassIvars(const ObjCInterfaceDecl *OI,
> llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
> @@ -997,21 +985,9 @@
> Ivars.push_back(*I);
> }
> }
> -
> - for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(),
> - E = OI->prop_end(); I != E; ++I) {
> - if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
> - Ivars.push_back(Ivar);
> - }
> - // Also look into interface's protocol list for properties declared
> - // in the protocol and whose ivars are synthesized.
> - for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(),
> - PE = OI->protocol_end(); P != PE; ++P) {
> - ObjCProtocolDecl *PD = (*P);
> - CollectProtocolSynthesizedIvars(PD, Ivars);
> - }
>
> - // Also add any ivar defined in this class's implementation
> + // Also add any ivar defined in this class's implementation. This
> + // includes synthesized ivars.
> if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) {
> for (ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
> E = ImplDecl->ivar_end(); I != E; ++I)
>
> Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=98280&r1=98279&r2=98280&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Mar 11 13:44:54 2010
> @@ -2492,15 +2492,17 @@
> ObjCInterfaceDecl *ClassDeclared;
> Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared);
> if (!Ivar) {
> - DeclContext *EnclosingContext = cast_or_null<DeclContext>(IDecl);
> + DeclContext *EnclosingContext = cast_or_null<DeclContext>(ClassImpDecl);
> assert(EnclosingContext &&
> "null DeclContext for synthesized ivar - ActOnPropertyImplDecl");
> Ivar = ObjCIvarDecl::Create(Context, EnclosingContext, PropertyLoc,
> PropertyIvar, PropType, /*Dinfo=*/0,
> ObjCIvarDecl::Public,
> (Expr *)0);
> + EnclosingContext->addDecl(Ivar);
> IDecl->makeDeclVisibleInContext(Ivar, false);
> property->setPropertyIvarDecl(Ivar);
> +
> if (!getLangOptions().ObjCNonFragileABI)
> Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
> // Note! I deliberately want it to fall thru so, we have a
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list