<div>I haven't had a very deep look into the Sema-code, as my knowledge of the internals</div><div>of clang at this level isn't that good that i could benefit from it.</div><div>Instead, i tried to get the ObjCIvarDecl with the methods I know and I'm used too - and</div>
<div>finally i got it. </div><div>I get to the ObjCInterfaceDecl through the ValueDecl that lies in the deeps of the base of</div><div>the ObjCPropertyRefExpr. Through this, I can get to the ObjCImplementationDecl, to</div>
<div>the ObjCPropertyImplDecl and to the ObjCIvarDecl. By comparing the getter-name within</div><div>the ObjCPropertyRefExpr, i finally can find the right ObjCPropertyImplDecl and the </div><div>ObjCIvarDecl. The method itseld can be found at</div>
<div><a href="http://pastebin.com/VEVACTvP">http://pastebin.com/VEVACTvP</a><br></div><div>I still have no clue if clang misses something in Sema to set the ObjCIvar-reference on</div><div>the ObjCPropertyDecl, or if I'm misinterpreting some methods or maybe if it is totally </div>
<div>wrong what I'm doing - but for now, it seems to work and I'm going to grant now my</div><div>braincells some cooldown ;)</div><br><div class="gmail_quote">2011/3/16 Hendrik vP <span dir="ltr"><<a href="mailto:variadic.template@googlemail.com">variadic.template@googlemail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>The items-property gets synthesized within the implementation. But i just realized<br></div><div>that i missed two details within my example, those are</div>
<div>1. Foo implements a protocol with a method, call it bar</div>
<div>2. the access to the items happen inside the implementation of bar</div><div>Is it possible that clang doesn't resolve the ObjCIvar as it isn't a method that got</div><div>declared within the interface or something like that?</div>

<div><br></div><div>I'll take a look into Sema::ActOnPropertyImplDecl - thank you so far.</div><div><div class="h5"><br><div class="gmail_quote">2011/3/16 Fariborz Jahanian <span dir="ltr"><<a href="mailto:fjahanian@apple.com" target="_blank">fjahanian@apple.com</a>></span><br>

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