Skip to content

Commit

Permalink
adds support for unnamed bit fields (#41)
Browse files Browse the repository at this point in the history
I am not sure in which standard it got into language but looks like
that it is in it for a long time.
  • Loading branch information
ivg authored May 17, 2021
1 parent f9196a7 commit d53127c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions ctoxml/test.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3866,7 +3866,7 @@
</fundec>
</file>

$ echo 'struct foo {int x;};' | dune exec ctoxml
$ echo 'struct foo {int x;};' | ctoxml
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<file>
<struct id="struct:foo">
Expand All @@ -3889,7 +3889,7 @@
</fundec>
</file>

$ echo 'const volatile int n;' | dune exec ctoxml
$ echo 'const volatile int n;' | ctoxml
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<file>
<var id="n" store="auto">
Expand Down Expand Up @@ -5448,7 +5448,7 @@
</fundef>
</file>

$ echo 'void fn(char xs[const static volatile]) {}' | dune exec ctoxml --
$ echo 'void fn(char xs[const static volatile]) {}' | ctoxml --
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<file>
<fundef id="fn" store="auto">
Expand All @@ -5472,7 +5472,7 @@
</body>
</fundef>
</file>
$ echo 'void fn(char xs[const static volatile 10]) {}' | dune exec ctoxml --
$ echo 'void fn(char xs[const static volatile 10]) {}' | ctoxml
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<file>
<fundef id="fn" store="auto">
Expand All @@ -5496,3 +5496,15 @@
</body>
</fundef>
</file>

$ echo 'struct s {int : 32;};' | ctoxml
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<file>
<struct id="struct:s">
<field name="">
<bits>
<int>32</int>
</bits>
</field>
</struct>
</file>
4 changes: 2 additions & 2 deletions frontc/cparser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ field_dec:
{(fst $2, set_type (PROTO (NO_TYPE, fst $5, snd $5)) (snd $2))}
| LPAREN field_dec RPAREN
{$2}
| IDENT COLON expression
{($1, BITFIELD (NO_SIGN, $3))}
| IDENT? COLON expression
{((match $1 with None -> "" | Some x -> x), BITFIELD (NO_SIGN, $3))}
;


Expand Down

0 comments on commit d53127c

Please sign in to comment.