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

Support __attribute__ within struct declaration #75

Open
nxmaintainer opened this issue May 1, 2023 · 1 comment
Open

Support __attribute__ within struct declaration #75

nxmaintainer opened this issue May 1, 2023 · 1 comment

Comments

@nxmaintainer
Copy link

nxmaintainer commented May 1, 2023

    typedef struct {
        __attribute__((__deprecated__)) int test1;
    } test2;

fails with plyparser.ParseError: :3:9: before: __attribute__

PLY: PARSE DEBUG START
State  : 0
Stack  : . LexToken(TYPEDEF,'typedef',2,5)
Action : Shift and goto state 65
State  : 65
Stack  : TYPEDEF . LexToken(STRUCT,'struct',2,13)
Action : Reduce rule [storage_class_specifier -> TYPEDEF] with ['typedef'] and goto state 22
Result : <str @ 0x7f027d5ccab0> ('typedef')
State  : 22
Stack  : storage_class_specifier . LexToken(STRUCT,'struct',2,13)
Action : Reduce rule [empty -> <empty>] with [] and goto state 121
Result : <NoneType @ 0x7f02812c6280> (None)
State  : 121
Stack  : storage_class_specifier empty . LexToken(STRUCT,'struct',2,13)
Action : Reduce rule [declaration_specifiers_no_type_opt -> empty] with [None] and goto state 124
Result : <NoneType @ 0x7f02812c6280> (None)
State  : 124
Stack  : storage_class_specifier declaration_specifiers_no_type_opt . LexToken(STRUCT,'struct',2,13)
Action : Reduce rule [declaration_specifiers_no_type -> storage_class_specifier declaration_specifiers_no_type_opt] with ['typedef',None] and goto state 26
Result : <dict @ 0x7f027d837500> ({'qual': [], 'storage': ['typedef'], 'ty ...)
State  : 26
Stack  : declaration_specifiers_no_type . LexToken(STRUCT,'struct',2,13)
Action : Shift and goto state 73
State  : 73
Stack  : declaration_specifiers_no_type STRUCT . LexToken(LBRACE,'{',2,20)
Action : Reduce rule [struct_or_union -> STRUCT] with ['struct'] and goto state 39
Result : <str @ 0x7f027d5cd7d0> ('struct')
State  : 39
Stack  : declaration_specifiers_no_type struct_or_union . LexToken(LBRACE,'{',2,20)
Action : Shift and goto state 145
State  : 145
Stack  : declaration_specifiers_no_type struct_or_union LBRACE . LexToken(__ATTRIBUTE__,'__attribute__',3,30)
Action : Reduce rule [brace_open -> LBRACE] with ['{'] and goto state 148
Result : <str @ 0x7f02813fc070> ('{')
State  : 148
Stack  : declaration_specifiers_no_type struct_or_union brace_open . LexToken(__ATTRIBUTE__,'__attribute__',3,30)
ERROR: Error  : declaration_specifiers_no_type struct_or_union brace_open . LexToken(__ATTRIBUTE__,'__attribute__',3,30)

I'm trying to fix, but don't understand why function_specifier doesn't hit here, @inducer if you'd have a moment to take a quick look and point me into a right direction, I'd provide a PR asap.

@nxmaintainer
Copy link
Author

nxmaintainer commented May 1, 2023

Ok, I don't think the problem is related to struct at all, my bad.

typedef struct 
{
  int test1 __attribute__((__deprecated__));
} test2;

works correctly (both CParser and CGenerator), which means the problem related only to prefixing with __attribute__ and it seems reasonable due to xxx_declarator : direct_xxx_declarator asm_label_opt attributes_opt rule, where attributes_opt can be defined only after. Ok, I approximately understand how to fix, will try.

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

1 participant