Objective-C header parsing

I need to parse some Objective-C headers.

  • I tried using Doxygen and parsing the XML output, but it does not fully support Objective-C headers without comment (it chokes on macros defined in properties, checks Doxygen for incorrectly recognizing properties )
  • I also tried using appledoc , but the XML output is not large enough (for example, there is no inheritance information for classes) and it has the same problem with property macros.
  • I also tried otool metadata output of the Objective-C library (using otool ), but noticed that metadata does not store types in methods (so you get method:(id)param:(id) )

Does anyone know a good tool to do what I want? I suspect clang will help me, but for now, -ast-dump and similar parameters are just trying to generate an AST for a source that I don't have (headers only).

+6
source share
2 answers

You might be able to use libclang. libclang is a programming interface designed to implement tools such as syntax highlighting and code completion.

clang -ast-dump works for me. (Note that the -ast-dump driver is not supported by the driver, so you need to do extra work to pass the flags that the driver normally processes. You can use clang -### ... to see what the driver does. )

 % clang -cc1 -ast-dump -fblocks -x objective-c /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h [...] |-ObjCInterfaceDecl 0x1023727c0 <line:50:1, line:96:2> NSObject | |-ObjCProtocol 0x102371350 'NSObject' [...] 
+15
source

I think using clang sounds too complicated. I would just use RegEx.

Instead, I would write a simple script wrapper around Doxygen that comments on the problematic syntax.

This should be pretty easy to change:

 @property(nonatomic, retain) BOOL myProperty NS_AVAILABLE_IOS(3_2); 

To:

 @property(nonatomic, retain) BOOL myProperty /*NS_AVAILABLE_IOS(3_2)*/; 

You can even convert things like NS_DEPRECATED() to @deprecated comment.

-5
source

Source: https://habr.com/ru/post/949171/


All Articles