[cfe-dev] Relationship between ObjCPropertyRefExpr and ObjCIvarDecl

Hendrik vP variadic.template at googlemail.com
Wed Mar 16 09:08:07 PDT 2011


The items-property gets synthesized within the implementation. But i just
realized
that i missed two details within my example, those are
1. Foo implements a protocol with a method, call it bar
2. the access to the items happen inside the implementation of bar
Is it possible that clang doesn't resolve the ObjCIvar as it isn't a method
that got
declared within the interface or something like that?

I'll take a look into Sema::ActOnPropertyImplDecl - thank you so far.

2011/3/16 Fariborz Jahanian <fjahanian at apple.com>

> It only sets it for synthesized ivars. Look at Sema::ActOnPropertyImplDecl
> for details. You can follow
> the same logic for looking up the ivar;  starting at if (Synthesize) {...}
>
> - Fariborz
>
> On Mar 16, 2011, at 8:49 AM, Hendrik vP wrote:
>
> > I'm experimenting with clang to do some analyzes and inspections on
> > Objective-C-code, or, to be more precise, iPhone-Code.
> > Currently, I'm trying to 'guess' the inner-types of enumeratable types,
> especially for
> > NSArrays. For this, I set up a RecursiveASTVisitor and collect all of the
> variables
> > that I am interested in (ObjCIVar, VarDecl, ParmVarDecl). Also, I'm
> looking into
> > statements and declarations where those variables get used. I already got
> it to
> > guess some inner-types by inspecting ObjCForCollection-statments, which
> is
> > fine.
> > Now, I'm doing some specializations for NSMutableArray inside my visitor
> to get
> > some hints from statements like
> > [<NSMutableArray> addObject:<variable X>]
> > so i can build a relationship between the type of variable X and the
> inner-type of
> > the array. This already works for local declared arrays, but not for
> ObjCIvars.
> > For the moment, I'm stuck with an expression that looks like
> > [self.items addObject:item]
> > where items is declared as
> >
> >
> > @interface Foo : NSObject {
> > @private
> >   NSMutableArray *items;
> > }
> > @property(retain) NSMutableArray *items;
> > @end
> >
> > @implementation Foo
> > @synthesize items;
> > @end
> >
> >
> > So, I'm diving into the ObjCMessageExpression and try to get the
> ObjCIvarDecl.
> > For this, I'm catching the instance-receiver, which is a
> ImplicitCastExpr, get it's
> > subExpr and cast it to the ObjCPropertyRefExpr that it is. On this, I'm
> calling
> > getExplicitProperty() and receiving the ObjCPropertyDecl.
> >
> > And here's the point that confuses me: when I try to get the ObjCIvarDecl
> by
> > calling getPropertyIvarDecl on the ObjCPropertyDecl, I'm receiving a
> nullpointer.
> >
> > The header of Foo is included and also my compilerinstance reports no
> errors,
> > so i think the configuration of the project itself should be correct. Am
> I
> > misunderstanding the concept/functionality of the methods I'm using - or
> is it
> > maybe a bug inside clang, that it doesn't set the ObjCIvarDecl properly
> for
> > every ObjCProperetyDecl?
> > svn log says that I am using r127573.
> >
> > Thanks,
> > Hendrik
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110316/dd7d3a55/attachment.html>


More information about the cfe-dev mailing list