jacob-carlborg / dstep

A tool for converting C and Objective-C headers to D modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#define with double cast not translated correctly

Robert-M-Muench opened this issue · comments

#define FORWARD_WM_POWER(hwnd, code, fn) \
    (void)(fn)((hwnd), WM_POWER, (WPARAM)(int)(code), 0L)

is translated to:

extern (D) auto FORWARD_WM_POWER(T0, T1, T2)(auto ref T0 hwnd, auto ref T1 code, auto ref T2 fn)
{
    return cast(void) fn(hwnd, WM_POWER, WPARAM(int)(code), 0L);
}

which errors out as:

..\..\winsdk\windowsx.d(211,52): Error: found ) when expecting . following int
..\..\winsdk\windowsx.d(211,53): Error: found ( when expecting identifier following int.
..\..\winsdk\windowsx.d(211,54): Error: found code when expecting ,

Could you provide the context of this code? It looks like WPARAM is not recognized as a type and the expression is parsed as the function call.

For example this code is translated properly (as long as cast() is right associative, of what I'm not sure):

#define FORWARD_WM_POWER(hwnd, code, fn) \
    (void)(fn)((hwnd), WM_POWER, (float)(int)(code), 0L)
extern (C):

extern (D) auto FORWARD_WM_POWER(T0, T1, T2)(auto ref T0 hwnd, auto ref T1 code, auto ref T2 fn)
{
    return cast(void) fn(hwnd, WM_POWER, cast(float) cast(int) code, 0L);
}

Yeah most likely not a bug:

#define WPARAM int

#define FORWARD_WM_POWER(hwnd, code, fn) \
    (void)(fn)((hwnd), WM_POWER, (WPARAM)(int)(code), 0L)
extern (C):

alias WPARAM = int;

extern (D) auto FORWARD_WM_POWER(T0, T1, T2)(auto ref T0 hwnd, auto ref T1 code, auto ref T2 fn)
{
    return cast(void) fn(hwnd, WM_POWER, cast(WPARAM) cast(int) code, 0L);
}

Ev. we could add some cmd line switches to define standard windows macros...

Thx. I just needed the windowsx.h header, so no special context.

The thing with windowsx.h is, that when pre-processed on its own the WPARAM define is missing/not included.

How about providing something like a config-file with a list of standard windows macros? Not only via command line. Such a config file could be included in the dstep package.

@Robert-M-Muench I think this is an acceptable solution as Windowsx.h is quite commonly used header. @jacob-carlborg what do you think?

There's the -include flag to add additional headers that should be processed first. Would that help?

Yes, so, now we only need to create and include some "platform includes" where such things are collected. So I would use: -include dstep-windows-sdk.h where all the missing/necessary macros are included.

Am I right, that the include would be in C format? Or would it be possible to provide a D format include too?

Am I right, that the include would be in C format?

Yes, it should be a C header file.

Or would it be possible to provide a D format include too?

No. This is not a DStep specific feature. The flag is passed straight through to Clang. DStep accepts all flags that Clang accepts. In this case you need to pass all the DStep specific flags, then -- -include ....

Ideally you would add the file we’re the missing symbols are declared.