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

Can`t parse attributes defined by macro #51

Open
NarutoUA opened this issue Sep 2, 2021 · 2 comments
Open

Can`t parse attributes defined by macro #51

NarutoUA opened this issue Sep 2, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@NarutoUA
Copy link

NarutoUA commented Sep 2, 2021

I try to parse DirectX headers and parser doesn't handle uuid attribute if it is defined by macro:

MIDL_INTERFACE("9d06dffa-d1e5-4d07-83a8-1bb123f2f841")
ID3D11Device2 : public ID3D11Device1

As a workaround, replacing MIDL_INTERFACE by regex works and parser returns correct attributes

struct __declspec(uuid("9d06dffa-d1e5-4d07-83a8-1bb123f2f841")) __declspec(novtable)
ID3D11Device2 : public ID3D11Device1

Both ParseAttributes and ParseMacros are set to true

You can reproduce it if you replace input text in TestStructAttributes and enable macros parsing.

@"
#ifndef DECLSPEC_NOVTABLE
#if (_MSC_VER >= 1100) && defined(__cplusplus)
#define DECLSPEC_NOVTABLE __declspec(novtable)
#else
#define DECLSPEC_NOVTABLE
#endif
#endif

#ifndef DECLSPEC_UUID
#if (_MSC_VER >= 1100) && defined(__cplusplus)
#define DECLSPEC_UUID(x) __declspec(uuid(x))
#else
#define DECLSPEC_UUID(x)
#endif
#endif

#define MIDL_INTERFACE(x)   struct DECLSPEC_UUID(x) DECLSPEC_NOVTABLE

MIDL_INTERFACE(""9d06dffa-d1e5-4d07-83a8-1bb123f2f841"") Test{
    int a;
    int b;
};"
@xoofx
Copy link
Owner

xoofx commented Sep 26, 2021

Yes, unfortunately, I'm not sure if we have any workaround for this. The problem is that libclamg-C does not parse or give access to these attributes correctly, so we need to parse them ourselves... but then we parse from the original source, not the postprocessed sources, hence why attribute parsing doesn't work when using macros.

@xoofx xoofx added the bug Something isn't working label Sep 26, 2021
@ninloot
Copy link

ninloot commented Apr 19, 2022

This issue is causing us issues as well. I was wondering if during VisitMember(), when the CursorKind is CXCursorKind.CXCurser_MacroExpansion if we could expand the macro and create the elements that the macro expands into. That would expose the attributes or anything else in the macro at the point where it's supposed to be expanded. I've been looking at the code to see if doing something like this is possible.
Another more specific option would be in ParseAttributes() where in addition to the check for a keyword, check if the token is a macro and if it is parse that macro. For our specific case we don't need a full macro parser, just a single expansion to get the macros content which will always be the [[attribute]] type.

ninloot pushed a commit to CognexVisionSoftware/CppAst.NET that referenced this issue Apr 22, 2022
Only basic parsing is performed by this PR but it does allow for
a macro to hold an scoped attribute with arguments.
ninloot pushed a commit to CognexVisionSoftware/CppAst.NET that referenced this issue Apr 22, 2022
Only basic parsing is performed by this PR but it does allow for
a macro to hold an scoped attribute with arguments.
harsszegi pushed a commit to CognexVisionSoftware/CppAst.NET that referenced this issue Dec 11, 2023
Only basic parsing is performed by this PR but it does allow for
a macro to hold an scoped attribute with arguments.
harsszegi pushed a commit to CognexVisionSoftware/CppAst.NET that referenced this issue Dec 11, 2023
Only basic parsing is performed by this PR but it does allow for
a macro to hold an scoped attribute with arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants