3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

CGrammar: Move bit-field to declarator so they can be declared in lists like int a[5], b:5

This commit is contained in:
Pragmatic Software 2014-06-17 23:33:34 +00:00
parent b2a0963abb
commit dfb7ca0abd
2 changed files with 13 additions and 24 deletions

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 649,
BUILD_REVISION => 650,
BUILD_DATE => "2014-06-17",
};

View File

@ -714,6 +714,11 @@ declaration:
}
if($first_qualifier) {
if($first_qualifier =~ /bit\-field/) {
$first_qualifier = "$item{declaration_specifiers} $first_qualifier";
$item{declaration_specifiers} = '';
}
if(@identifiers == 1 and $first_qualifier !~ /^(a|an)\s+/) {
$return .= $first_qualifier =~ m/^[aeiouy]/ ? 'an ' : 'a ';
} elsif(@identifiers > 1) {
@ -1081,7 +1086,12 @@ declarator:
{ $return = "$item{direct_declarator}|$item{pointer}"; }
direct_declarator:
identifier[context => 'direct_declarator'] array_declarator(s?)
identifier ':' constant
{
my $bits = $item{constant} == 1 ? "$item{constant} bit" : "$item{constant} bits";
$return = "$item{identifier}|bit-field of $bits";
}
| identifier[context => 'direct_declarator'] array_declarator(s?)
{
if(@{$item{'array_declarator(s?)'}}) {
$return = "$item{identifier}|" . join('', @{$item{'array_declarator(s?)'}});
@ -1314,29 +1324,8 @@ struct_declaration_list:
}
}
bitfield_identifier:
identifier ':' constant
{ $return = [$item{identifier}, $item{constant}]; }
struct_declaration:
declaration_specifiers <leftop: bitfield_identifier ',' bitfield_identifier> ';'
{
$return = "$item{declaration_specifiers} ";
my @bitfields = @{$item[-2]};
my $sep = '';
for(my $i = 0; $i < @bitfields; $i++) {
my $plural = $bitfields[$i]->[1] == 1 ? '' : 's';
$return .= "$sep" . "bit-field of $bitfields[$i]->[1] bit$plural $bitfields[$i]->[0]";
if($i == $#bitfields - 1) {
$sep = ' and ';
} else {
$sep = ', ';
}
}
}
| comment(s?) declaration[context => 'struct member'] comment(s?)
comment(s?) declaration[context => 'struct member'] comment(s?)
{ $return = join('', @{$item[1]}) . $item{declaration} . join('', @{$item[-1]}); }
type_name: