[cfe-dev] introspection objective-c
Jacob Carlborg
doob at me.com
Wed Jun 22 01:12:32 PDT 2011
On 2011-06-22 08:17, Adrian Tofan wrote:
> 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
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Have you looked at the "method_" related functions in the Objective-C
runtime, for example "method_getTypeEncoding"? From the documentation:
"Returns a string describing a method's parameter and return types."
A assume this will just indicate that an argument is just an object and
not what kind of object, don't know if this is enough for your needs.
--
/Jacob Carlborg
More information about the cfe-dev
mailing list