"Jacob Carlborg" <[email protected]> wrote in message news:[email protected]... > On 2013-10-04 08:37, Szymon Gatner wrote: > >> Well, that is nothing Clang can't handle. The subset is what I was >> asking for - there has to be something that tool handles correctly, >> right? > > Of course Clang will be able to lex and parse it. But how should it be > translated? > > void foo (int a > #if BAR > , > int b > #endif > ) > { ... } > > You cannot do the exact same thing in D: > > void foo (int a > version (BAR) > { > , > int b > } > ) > { ... } > > Doing these crazy things are only possible with a preprocessor. > > Then you need to duplicate the function, use a string mixin or something > else that's ugly. > > We can take a simpler example: > > #if _WIN32 > void foo (int); > #elif __APPLE__ > void foo (long long); > #elif linux > void foo (long long); > #endif > > Translating this manually it would look like this: > > version (Windows) > void foo (int); > else version (OSX) > void foo (long); > else version (linux) > void foo (long); > > But how could this be translated automatically? In this case you would > want to have all the above preprocessor macros enabled, at the same time. > Or somehow run it multiple times with different macros enabled and merge > them. > > I don't know how the preprocessor API looks like in Clang. If you could > search for hard coded identifiers or something similar. > > -- > /Jacob Carlborg
I deal with this by not running a preprocessor. The #if directives are parsed as if they're real C++ constructs, and this means everything inside (and around) them must be valid C++ code. With this constraint, translating them to static if/version and doing all versions simultaneously becomes possible.
