[cfe-dev] introspection objective-c

Adrian Tofan tofan.adrian at gmail.com
Tue Jun 21 23:17:12 PDT 2011


Hello,

I am investigating the possibility of building a tool that adds introspection capabilities to Objective-C classes. I want to use this tool to build a dependency injection library for objective-c.   It is true that the Objective-C runtime already provides some informations, but many important aspects are missing, most notably method arguments types.

From my perspective it would work like this  :

- STEP1 - the tool will extract all required informations from source code (ex: method names, method arguments with types etc.) . This tool may be libclang based, invoked before compilation of each file
- STEP2 - somehow it will make all extracted information available at runtime. An easy solution would be to generate for each input class the implementation of a protocol which provides missing introspection information. For example: 
@protocol SomeClass(Introspection)
+(NSArray) methodArguments:(NSString*)methodName{
    // generated code
}
@end
As far as I can see this can be generated in an external file and compiled in to the project.  

I would like to ask your advice about this solution. My most important concerns are :

1. This tool does the same thing as a compiler plus some extra steps. This means slower build times, because the compiler is invoked twice, once to compile and second time to extract introspection information. Is there a simple way to integrate in to clang so compilation and extraction of introspection information is done in one step ? I have played with PrintFunctionNames plugin example, but as far as I understand, the plugin cannot be executed as an extra compile step. 

2. I have already experimented with code generation in a similar context, except that in the first step I was invoking Doxygen, afterward parsing it's xml output to generate the introspection protocol implementations for each class and finally include the generated file in to the project to compile it. It involved the coordination between several external scripts with xcode and I cannot say that it was easy to set up or fast. I wonder if there is a better/simpler way to compile generated code and include it in the final build.

I can tell you that I have more an objective-c/c background than c++ and that I am a beginner with clang.

Thank you,

Adrian Tofan 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110622/2fbd642e/attachment.html>


More information about the cfe-dev mailing list