atilaneves / dpp

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

Module "linux" will be " 1 " #258

Closed ShigekiKarita closed 4 years ago

ShigekiKarita commented 4 years ago

input file: test.dpp

module foo.linux.bar;

preprocess result: d++ --preprocess-only test.dpp

module foo. 1 .bar;

        import core.stdc.config;
        import core.stdc.stdarg: va_list;
        static import core.simd;
        static import std.conv;

        struct Int128 { long lower; long upper; }
        struct UInt128 { ulong lower; ulong upper; }

        struct __locale_data { int dummy; }

alias _Bool = bool;
struct dpp {
    static struct Opaque(int N) {
        void[N] bytes;
    }

    static bool isEmpty(T)() {
        return T.tupleof.length == 0;
    }
    static struct Move(T) {
        T* ptr;
    }

    static auto move(T)(ref T value) {
        return Move!T(&value);
    }
    mixin template EnumD(string name, T, string prefix) if(is(T == enum)) {
        private static string _memberMixinStr(string member) {
            import std.conv: text;
            import std.array: replace;
            return text(` `, member.replace(prefix, ""), ` = `, T.stringof, `.`, member, `,`);
        }
        private static string _enumMixinStr() {
            import std.array: join;
            string[] ret;
            ret ~= "enum " ~ name ~ "{";
            static foreach(member; __traits(allMembers, T)) {
                ret ~= _memberMixinStr(member);
            }
            ret ~= "}";
            return ret.join("\n");
        }
        mixin(_enumMixinStr());
    }
}

extern(C)
{
}
atilaneves commented 4 years ago

Unfortunately that's what happens when the preprocessor is involved. dpp can't control what predefined macros clang brings to the table.

The only way around it is to have an option to not run the C preprocessor. Or, of course, rename the module.

ShigekiKarita commented 4 years ago

Thanks for suggestions. I will rename that.

2020年5月11日(月) 21:24 Atila Neves notifications@github.com:

Unfortunately that's what happens when the preprocessor is involved. dpp can't control what predefined macros clang brings to the table.

The only way around it is to have an option to not run the C preprocessor. Or, of course, rename the module.

—in You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/atilaneves/dpp/issues/258#issuecomment-626668996, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTOZ3TXQ5GAERXFNGWMQJDRQ7U7LANCNFSM4M43EGBA .

atilaneves commented 4 years ago

There's also #259

ShigekiKarita commented 4 years ago

Nice!