Skip to content

Commit

Permalink
Support C99 array declarator syntax involving static and *
Browse files Browse the repository at this point in the history
E.g. `int x[static 10]` or `int x [*]`.
Treated like `int x[10]` and `int x[]` respectively.

Fixes: #531
  • Loading branch information
xavierleroy committed Nov 29, 2024
1 parent 5e445cd commit 51bfa1b
Show file tree
Hide file tree
Showing 3 changed files with 860 additions and 775 deletions.
19 changes: 17 additions & 2 deletions cparser/Parser.vy
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,23 @@ direct_declarator:
| decl = direct_declarator LBRACK RBRACK
{ let 'Cabs.Name name typ attr loc := decl in
Cabs.Name name (Cabs.ARRAY typ [] None) attr loc }
(*| direct_declarator LBRACK ... STATIC ... RBRACK
| direct_declarator LBRACK STAR RBRACK*)
| decl = direct_declarator LBRACK STATIC quallst = type_qualifier_list
expr = assignment_expression RBRACK
{ let 'Cabs.Name name typ attr loc := decl in
Cabs.Name name (Cabs.ARRAY typ (rev' quallst) (Some (fst expr))) attr loc }
| decl = direct_declarator LBRACK STATIC expr = assignment_expression RBRACK
{ let 'Cabs.Name name typ attr loc := decl in
Cabs.Name name (Cabs.ARRAY typ [] (Some (fst expr))) attr loc }
| decl = direct_declarator LBRACK quallst = type_qualifier_list STATIC
expr = assignment_expression RBRACK
{ let 'Cabs.Name name typ attr loc := decl in
Cabs.Name name (Cabs.ARRAY typ (rev' quallst) (Some (fst expr))) attr loc }
| decl = direct_declarator LBRACK quallst = type_qualifier_list STAR RBRACK
{ let 'Cabs.Name name typ attr loc := decl in
Cabs.Name name (Cabs.ARRAY typ (rev' quallst) None) attr loc }
| decl = direct_declarator LBRACK STAR RBRACK
{ let 'Cabs.Name name typ attr loc := decl in
Cabs.Name name (Cabs.ARRAY typ [] None) attr loc }
| decl = direct_declarator LPAREN params = parameter_type_list RPAREN
{ let 'Cabs.Name name typ attr loc := decl in
Cabs.Name name (Cabs.PROTO typ params) attr loc }
Expand Down
Loading

0 comments on commit 51bfa1b

Please sign in to comment.