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

Doxide fails to parse bit-fields #79

Open
Corristo opened this issue Mar 9, 2025 · 2 comments
Open

Doxide fails to parse bit-fields #79

Corristo opened this issue Mar 9, 2025 · 2 comments

Comments

@Corristo
Copy link

Corristo commented Mar 9, 2025

For example, this definition

struct Foo {
   unsigned char low : 4 {};
   unsigned char high : 4 {};
};

will cause doxide to print the warning

warning: parse error at ': 4', but will continue

for both bit-fields.

@lawmurray
Copy link
Owner

Thanks for the report @Corristo. It looks like using a brace-initializer with a bitfield, rather than just the bitfield alone, gives a parse error from from tree-sitter-cpp, so this seems to be an upstream issue.

Checking the tree-sitter parse on their playground, your example fails to parse:

struct Foo {
   unsigned char low : 4 {};
   unsigned char high : 4 {};
};
translation_unit [0, 0] - [4, 0]
  struct_specifier [0, 0] - [3, 1]
    name: type_identifier [0, 7] - [0, 10]
    body: field_declaration_list [0, 11] - [3, 1]
      field_declaration [1, 3] - [1, 28]
        type: sized_type_specifier [1, 3] - [1, 16]
          type: primitive_type [1, 12] - [1, 16]
        declarator: field_identifier [1, 17] - [1, 20]
        ERROR [1, 21] - [1, 24]
          bitfield_clause [1, 21] - [1, 24]
            number_literal [1, 23] - [1, 24]
        default_value: initializer_list [1, 25] - [1, 27]
      field_declaration [2, 3] - [2, 29]
        type: sized_type_specifier [2, 3] - [2, 16]
          type: primitive_type [2, 12] - [2, 16]
        declarator: field_identifier [2, 17] - [2, 21]
        ERROR [2, 22] - [2, 25]
          bitfield_clause [2, 22] - [2, 25]
            number_literal [2, 24] - [2, 25]
        default_value: initializer_list [2, 26] - [2, 28]

whereas removing the brace-initializers seems to work:

struct Foo {
   unsigned char low : 4;
   unsigned char high : 4;
};
translation_unit [0, 0] - [4, 0]
  struct_specifier [0, 0] - [3, 1]
    name: type_identifier [0, 7] - [0, 10]
    body: field_declaration_list [0, 11] - [3, 1]
      field_declaration [1, 3] - [1, 25]
        type: sized_type_specifier [1, 3] - [1, 16]
          type: primitive_type [1, 12] - [1, 16]
        declarator: field_identifier [1, 17] - [1, 20]
        bitfield_clause [1, 21] - [1, 24]
          number_literal [1, 23] - [1, 24]
      field_declaration [2, 3] - [2, 26]
        type: sized_type_specifier [2, 3] - [2, 16]
          type: primitive_type [2, 12] - [2, 16]
        declarator: field_identifier [2, 17] - [2, 21]
        bitfield_clause [2, 22] - [2, 25]
          number_literal [2, 24] - [2, 25]

Is the documentation appearing correctly for you despite the warning messages?

@Corristo
Copy link
Author

The documentation appears to be correct.

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