xoofx / xoofx/CppAst.NET

Can`t parse attributes defined by macro

Open
#51 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
620
Forks
79
Avg merge
14h 27m
Merged PRs (30d)
1

Description

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;
};"

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open src/CppAst.Tests/TestAttributes.cs at TestStructAttributes and run it with ParseAttributes and ParseMacros enabled using the supplied MIDL_INTERFACE input. Trace how ParseMacros and ParseAttributes handle the macro-expanded uuid; done when the test parses the struct and returns the expected uuid attribute as it does after the regex workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.