Dear all,
I need some help/advice regarding Clang. My requirement is to do source-to-source transformation. I have to parse Objective C code and build AST and then modify AST (insert, delete or modify AST nodes) and generate finally output custom code having different semantics and syntax (not Objective C). I do not require to generate IR or binary code. Can someone please confirm following understandings,
-
I can parse ObjC code using Clang and then write my Visitor class by extending ASTConsumer to transform the AST and finally I will implement a CustomRewriter to generate the output in my custom format.
-
I have need to parse ObjC code on Windows operating system and I don’t have Mac OS X header files. So if I use “SetSuppressIncludeNotFoundError(true);” option on “clang::Preprocessor” instance then I can ignore the missing header files and generate AST for available ObjC code only. Please confirm if it is possible and AST will be generated.
-
If point-2 mentioned above is not possible then can I generate pre-compiled headers (pch file) on Max OS X and then generate proper AST tree on windows by providing pch file?
Any other suggestion or help will be highly appreciated.
Thanks,
–Tayyab
You may take a look at objective rewriter source code in: lib/Rewriter/RewriteObjC.cpp
- Fariborz
Thanks Fariborz,
I am already looking at RewriteObjc and its really helpful. I just need to get opinion that I am on write track, and it is doable. Can you please confirm regarding PCH files? Is it possible that I generate PCH file of ObjC code on Mac OS X and then use Clang parser on Windows to parse ObjC code using that PCH file. Because I don’t have Mac headers on windows so can I resolve these headers using pch file?
Thanks,
–Tayyab
Thanks Fariborz,
I am already looking at RewriteObjc and its really helpful. I just need to get opinion that I am on write track, and it is doable. Can you please confirm regarding PCH files? Is it possible that I generate PCH file of ObjC code on Mac OS X and then use Clang parser on Windows to parse ObjC code using that PCH file. Because I don’t have Mac headers on windows so can I resolve these headers using pch file?
On the surface, you should be able to do this. But, in practice, I am not sure if clang on Windows will accept it. For example, it is generated with different set of command line options than
when it is consumed. But there may be more substantive reasons than that.
Thanks Fariborz,
I am already looking at RewriteObjc and its really helpful. I just need to get opinion that I am on write track, and it is doable. Can you please confirm regarding PCH files? Is it possible that I generate PCH file of ObjC code on Mac OS X and then use Clang parser on Windows to parse ObjC code using that PCH file. Because I don’t have Mac headers on windows so can I resolve these headers using pch file?
No, this won’t work. PCH is an optimization only, which assumes that the headers are still available.
Thanks Douglas,
So nice of you.
Regards,
–Tayyab