[cfe-dev] introspection objective-c

Adrian Tofan tofan.adrian at gmail.com
Wed Jun 22 01:28:01 PDT 2011


On 22 juin 2011, at 09:37, David Chisnall wrote:

> Hi Adrian,
> 
> I think you're massively underestimating the amount of introspection information already present at runtime.  You can already get the types of all method arguments at run time - the runtime even provides an API for telling you the type of each argument and the number of arguments.  
> 

What is really missing is argument type. As I remember there is a runtime method method_getArgumentType which is supposed to do that. The problem is that it returns the string 'id' for object arguments.

For -(id) initWithString:(NSString*) str;   it will return 'id' as argument type. What I need is NSString. 

I guess that this is  linked to the dynamic nature of objective-c. The runtime doesn't care what kind of object is there. 


> In the EtoileFoundation framework, we provide a complete implementation of class mirrors that uses this information for reflection.
> 
> It would help if you could suggest exactly what information you are looking for that is not present for runtime introspection already.  For example, the following are all trivial to access:
> 
> - List of all classes
> - All methods of a class, including names and types (return type and argument types)
> - All instance variable names, offsets, and types

it is true that for ivars the runtime keeps type information. For example runtime method ivar_getTypeEncoding returns an Objective-C type encoding. 

What I did not mentioned in the original post is that I  also need to support some kind of source code annotation which becomes available at runtime 

> About the only things that are not available for introspection are categories and C functions.  With libclang, you can already get the Objective-C type encoding of C functions trivially, so I'm not sure what else you need.
> 

As I mentioned in the original post, my solution involves a rather complicated process:

- code analysis to extract missing reflexion information
- code generation
- add generated code to project
- compile original code
- compile generated code

I wanted to see if there is no simple solution to do all that in one single step "compile original code" without modifying clang ;-)  Or at least hoping that I can simplify part of the process. 

> 
> P.S. I'm assuming that you mean @implementation when you say @protocol - otherwise your code is not Objective-C.

right :-)




More information about the cfe-dev mailing list