atilaneves / dpp

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

Quite verbose d files generated #263

Closed andre2007 closed 1 year ago

andre2007 commented 4 years ago

For this dockerfile

FROM dlang2/ldc-ubuntu:1.20.0 as ldc

RUN apt-get update && apt-get upgrade -y \
    && apt-get install -y curl clang-9 libclang-9-dev

RUN curl -fskSL https://github.com/open62541/open62541/releases/download/v1.1-rc1/open62541-linux64.tar.gz | tar -xzf - --strip-components=1 open62541-linux64 -C /usr/
RUN ln -s /usr/bin/clang-9 /usr/bin/clang
RUN DFLAGS="-L=-L/usr/lib/llvm-9/lib/" dub build dpp

ADD open62541h.dpp /tmp/
RUN DFLAGS="-L=-L/usr/lib/llvm-9/lib/" dub run dpp -- /tmp/open62541h.dpp \
    --include-path /include/open62541/ \
    --preprocess-only

and the file open62541h.dpp

#include <open62541/client.h>
#include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>

A 6MB file /tmp/open62541h.d is generated with ~ 142.000 lines. The first 6000 lines looks as expected. After that there are lines with these pattern:

    static if(!is(typeof(UA_NS0ID_OPCUA_BINARYSCHEMA_ROLEPERMISSIONTYPE_DICTIONARYFRAGMENT))) {
        private enum enumMixinStr_UA_NS0ID_OPCUA_BINARYSCHEMA_ROLEPERMISSIONTYPE_DICTIONARYFRAGMENT = `enum UA_NS0ID_OPCUA_BINARYSCHEMA_ROLEPERMISSIONTYPE_DICTIONARYFRAGMENT = 16133;`;
        static if(is(typeof({ mixin(enumMixinStr_UA_NS0ID_OPCUA_BINARYSCHEMA_ROLEPERMISSIONTYPE_DICTIONARYFRAGMENT); }))) {
            mixin(enumMixinStr_UA_NS0ID_OPCUA_BINARYSCHEMA_ROLEPERMISSIONTYPE_DICTIONARYFRAGMENT);
        }
    }

    static if(!is(typeof(UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTROLEPERMISSIONS))) {
        private enum enumMixinStr_UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTROLEPERMISSIONS = `enum UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTROLEPERMISSIONS = 16134;`;
        static if(is(typeof({ mixin(enumMixinStr_UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTROLEPERMISSIONS); }))) {
            mixin(enumMixinStr_UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTROLEPERMISSIONS);
        }
    }

    static if(!is(typeof(UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTUSERROLEPERMISSIONS))) {
        private enum enumMixinStr_UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTUSERROLEPERMISSIONS = `enum UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTUSERROLEPERMISSIONS = 16135;`;
        static if(is(typeof({ mixin(enumMixinStr_UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTUSERROLEPERMISSIONS); }))) {
            mixin(enumMixinStr_UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTUSERROLEPERMISSIONS);
        }
    }

Are the static if / string mixin really needed, or could just instead the line

enum UA_NS0ID_OPCUANAMESPACEMETADATA_DEFAULTROLEPERMISSIONS = 16134;

be added?

atilaneves commented 4 years ago

If there was a way to detect that a macro is an integer or string constant, then I'd be all for the change, but I can't think of any.

If you don't care about macros, you can use --ignore-macros, and that code won't get generated.

andre2007 commented 4 years ago

I just saw pr https://github.com/atilaneves/dpp/pull/262 and now think about wheter an argument --accept-macros=foo,bar would solve the issue better.

There is a small list of macros which I need. Beeing able to specify them would be great .