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
[ addObject:]
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