October 04, 2013 Re: C++ -> D converter mentioned in AMA | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | "Jacob Carlborg" <doob@me.com> wrote in message news:l2lqik$1vdt$1@digitalmars.com... > 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. | |||
October 04, 2013 Re: C++ -> D converter mentioned in AMA | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | On 2013-10-04 12:21, Daniel Murphy wrote: > 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. Then you need to A) build your own preprocessor or B) limiting yourself to non-generic code, as you have done in this case. This was my original point, having it work on generic code. -- /Jacob Carlborg | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply