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

[ffigen] Support more MACROS #1066

Open
dcharkes opened this issue Apr 2, 2024 · 1 comment
Open

[ffigen] Support more MACROS #1066

dcharkes opened this issue Apr 2, 2024 · 1 comment

Comments

@dcharkes
Copy link
Collaborator

dcharkes commented Apr 2, 2024

We have support for macros that are direct constants:

But maybe we can do better and try to support more expressions and macros referring to macros.

// minwindef.h

#define MAKEWORD(a, b)      ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
#define MAKELONG(a, b)      ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
#define LOWORD(l)           ((WORD)(((DWORD_PTR)(l)) & 0xffff))
#define HIWORD(l)           ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
#define LOBYTE(w)           ((BYTE)(((DWORD_PTR)(w)) & 0xff))
#define HIBYTE(w)           ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))

Maybe @mannprerak2 can give some insight on what would or would not be possible.

We're happy to receive contributions if anyone wants to take a stab at this. Relevant code:

  • pkgs/ffigen/lib/src/header_parser/sub_parsers/macro_parser.dart
@mannprerak2
Copy link
Contributor

mannprerak2 commented Apr 2, 2024

I think we are already able to parse all non functional macros. Since we create a new cpp file and create variables for each macro and let libclang handle parsing and simply fetch that variable's value.

Any functional macros would require us to parse the underlying tokens directly.

Edit: I assume we're talking about parsing functional macros as helper functions in dart, anything constant at compile time should probably already work (unless there's an issue with include headers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants