[cfe-dev] Getting "wrong" ObjCMethodDecl-reference from ObjCMessageExpr
rjmccall at apple.com
Sat May 5 12:06:12 PDT 2012
On May 5, 2012, at 10:17 AM, Hendrik vP wrote:
> while playing around with libClang and trying to extract some
> statistics of objective-c-code, I encountered some strange behavior on
> ObjCMessageExpr-instances have a getMethodDecl-method, which I'm
> expecting to return the _exact_ ObjCMethodDecl-instance if clang is
> able to deduce it - or null, if clang has not the ability to do so.
The compiler never has the ability to deduce the exact method that a
message send goes to, because it's supported behavior to do things
like replace methods at runtime or patch the class pointer or whatever.
ObjCMessageExpr points to the method that the message send was
type-checked against. The specified behavior in the case of a message
send to 'id' is to type-check against the first method with that selector
that was declared in the file. Finding a method to type-check against
is important because many, many methods do not return a type
compatible with 'id'. Using the first method is also important because
(IIRC) Cocoa manages to declare two methods with incompatible
return types using the 'length' selector, and it's critical that we silently
pick the one from NSString.
More information about the cfe-dev