Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On enums and scope #140

Closed
russel opened this issue Jun 3, 2017 · 3 comments
Closed

On enums and scope #140

russel opened this issue Jun 3, 2017 · 3 comments

Comments

@russel
Copy link
Contributor

russel commented Jun 3, 2017

With the libdvbv5 C header file transform, a lot of named enums are created. This is fine per se. So for example:

typedef enum fe_delivery_system {
	SYS_UNDEFINED,
	SYS_DVBC_ANNEX_A,
	SYS_DVBC_ANNEX_B,
	SYS_DVBT,
	SYS_DSS,
	SYS_DVBS,
	SYS_DVBS2,
	SYS_DVBH,
	SYS_ISDBT,
	SYS_ISDBS,
	SYS_ISDBC,
	SYS_ATSC,
	SYS_ATSCMH,
	SYS_DTMB,
	SYS_CMMB,
	SYS_DAB,
	SYS_DVBT2,
	SYS_TURBO,
	SYS_DVBC_ANNEX_C,
} fe_delivery_system_t;

is transformed to:

enum fe_delivery_system
{
    SYS_UNDEFINED = 0,
    SYS_DVBC_ANNEX_A = 1,
    SYS_DVBC_ANNEX_B = 2,
    SYS_DVBT = 3,
    SYS_DSS = 4,
    SYS_DVBS = 5,
    SYS_DVBS2 = 6,
    SYS_DVBH = 7,
    SYS_ISDBT = 8,
    SYS_ISDBS = 9,
    SYS_ISDBC = 10,
    SYS_ATSC = 11,
    SYS_ATSCMH = 12,
    SYS_DTMB = 13,
    SYS_CMMB = 14,
    SYS_DAB = 15,
    SYS_DVBT2 = 16,
    SYS_TURBO = 17,
    SYS_DVBC_ANNEX_C = 18
}

alias fe_delivery_system_t = fe_delivery_system;

However, the line:

#define SYS_DVBC_ANNEX_AC	SYS_DVBC_ANNEX_A

gets transformed into:

enum SYS_DVBC_ANNEX_AC = SYS_DVBC_ANNEX_A;

where it needs to be transformed to:

enum SYS_DVBC_ANNEX_AC = fe_delivery_system.SYS_DVBC_ANNEX_A;
@jacob-carlborg
Copy link
Owner

I'm not sure if this is possible. When the compiler is analyzing #define SYS_DVBC_ANNEX_AC SYS_DVBC_ANNEX_A, I'm pretty sure it has no idea that SYS_DVBC_ANNEX_A is the same as the one defined in fe_delivery_system. The only way I can see this working is if DStep added aliases for all enum members to expose them outside the enum.

@russel
Copy link
Contributor Author

russel commented Jun 3, 2017

Hummm… C enum symbols are global and must be named appropriately to avoid clashes. D scopes the symbols and is better for that.

I guess the only way is to keep a temporary look up table of all enum symbols and then do a look up to impose the scope. This may be more effort that it is worth.

@jacob-carlborg
Copy link
Owner

Hummm… C enum symbols are global and must be named appropriately to avoid clashes. D scopes the symbols and is better for that.

I think it would be reasonable to have a flag to add aliases for all enum members. That would allow to generate bindings with a closer API to the C API.

I guess the only way is to keep a temporary look up table of all enum symbols and then do a look up to impose the scope. This may be more effort that it is worth.

Perhaps that could work.

ciechowoj added a commit to ciechowoj/dstep that referenced this issue Jun 4, 2017
ciechowoj added a commit to ciechowoj/dstep that referenced this issue Jun 4, 2017
jacob-carlborg added a commit that referenced this issue Jun 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants