atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
230 stars 31 forks source link

preprocessor macros should not be applied to module and import D statements #229

Closed Laeeth closed 4 years ago

Laeeth commented 4 years ago

Example.

module symmetry.linux.libnl.

included linux header defines linux to be ' 1' somehow.  

module symmetry. 1 .libnl

will try to flesh out a little shortly.

workaround but with obvious potentially dangerous side-effects if other macros should refer to the symbol.

#undef linux
atilaneves commented 4 years ago

I scratched my head as to why this was happening since dpp no longer translates literal macros as actual macros but as D enums. The reason is that linux is one of the built-in macros in clang on Linux and so is never seen by dpp. Even if it were, there's no way to stop the preprocessor from then replacing the enum's name when it runs.

atilaneves commented 4 years ago

preprocessor macros should not be applied to module and import D statements

This isn't possible. dpp doesn't (and can't) know anything about module or import statements. Or any D statements at all. The preprocessor can't either, all it seens are tokens.

obvious potentially dangerous side-effects if other macros should refer to the symbol.

That would be extremely unlikely. The most likely case for linux showing up anywhere would be in an ifdef or ifndef, by which point everything has been properly preprocessed.

I think the workaround is good enough, and that without it, the behaviour is consistent with what it would be in C++ (i.e. trying to name a C++20 module linux would fail as well), which is the goal of dpp.