[cfe-dev] Handling platform specific code

fdart via cfe-dev cfe-dev at lists.llvm.org
Mon May 6 13:57:12 PDT 2019


Hi,

I am writing a code generator to generate language bindings in C# for an
existing C++ API using clang libtooling.

Our C++ interface has platform specific code.  In order to handle this in
the code generation, I see two possible approaches.

   1. Do a build such that all platforms are defined such that all possible
   code is included in the build
   2. Run clang libtooling on each platform, and merge the resulting code.

In either case, clang::PPCallbacks looks great for getting preprocessor
information.
#if defined (WIN_32)
...
#endif

I have two questions

   1. It would be a lot easier to run the code generation on one platform,
   using approach #1 above, while enabling all the platform specific code.
   The blocker to this issue is that one platform's specific definitions won't
   be available on another platform.  Is there a way to invoke clang such that
   it continues, without error, if it encounters types that it does not
   recognize?
   2. While using the PPCallbacks interface, we are notified when a #if,
   #elif, #else, #endif is present and provided a sourceRange.  Is the correct
   way to determine what was inside these preprocessor definitions to compare
   the source ranges from the end of the #if to the start of the #endif?


Thanks,
Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190506/16905412/attachment.html>


More information about the cfe-dev mailing list