mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 19:22:40 +01:00
CGrammar: Fix struct member declarations, pluralize "pointers to" when applicable
This commit is contained in:
parent
c40fd81bb0
commit
77f1005e03
@ -13,8 +13,8 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 647,
|
||||
BUILD_DATE => "2014-06-16",
|
||||
BUILD_REVISION => 648,
|
||||
BUILD_DATE => "2014-06-17",
|
||||
};
|
||||
|
||||
1;
|
||||
|
@ -626,7 +626,7 @@ declaration:
|
||||
if(@init_list > 1) {
|
||||
my $last = pop @init_list;
|
||||
$init_declaration_list = join(', ', @init_list) . ' and ' . $last;
|
||||
push $last, @init_list;
|
||||
push @init_list, $last;
|
||||
} else {
|
||||
$init_declaration_list = $init_list[0];
|
||||
}
|
||||
@ -635,8 +635,10 @@ declaration:
|
||||
|
||||
push @defined_types, @init_list;
|
||||
} else {
|
||||
my $inits = 0;
|
||||
while(@init_list) {
|
||||
$return .= "Let ";
|
||||
$inits++;
|
||||
$return .= "Let " unless $arg{context} eq 'struct member';
|
||||
|
||||
my $first_object = shift @init_list;
|
||||
my @args = split /\|/, $first_object, 3;
|
||||
@ -704,6 +706,38 @@ declaration:
|
||||
splice @init_list, $i--, 1;
|
||||
}
|
||||
|
||||
if($arg{context} eq 'struct member') {
|
||||
if($inits > 1 and not @init_list) {
|
||||
$return .= ' and ';
|
||||
} elsif($inits > 1) {
|
||||
$return .= ', ';
|
||||
}
|
||||
|
||||
if($first_qualifier) {
|
||||
if(@identifiers == 1 and $first_qualifier !~ /^(a|an)\s+/) {
|
||||
$return .= $first_qualifier =~ m/^[aeiouy]/ ? 'an ' : 'a ';
|
||||
} else {
|
||||
$first_qualifier =~ s/pointer/pointers/;
|
||||
}
|
||||
$return .= "$first_qualifier $item{declaration_specifiers} ";
|
||||
} else {
|
||||
if(@identifiers == 1 and $item{declaration_specifiers} !~ /^(a|an)\s+/) {
|
||||
$return .= $item{declaration_specifiers} =~ m/^[aeiouy]/ ? 'an ' : 'a ';
|
||||
}
|
||||
$return .= "$item{declaration_specifiers} ";
|
||||
}
|
||||
|
||||
my $and = @identifiers > 1 ? ' and ' : '';
|
||||
my $comma = '';
|
||||
for(my $i = 0; $i < @identifiers; $i++) {
|
||||
if($i == @identifiers - 1) {
|
||||
$return .= "$and$identifiers[$i]";
|
||||
} else {
|
||||
$return .= "$comma$identifiers[$i]";
|
||||
$comma = ', ';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
my $and = @identifiers > 1 ? ' and ' : '';
|
||||
my $comma = '';
|
||||
for(my $i = 0; $i < @identifiers; $i++) {
|
||||
@ -720,6 +754,8 @@ declaration:
|
||||
if($first_qualifier) {
|
||||
if(@identifiers == 1 and $first_qualifier !~ /^(a|an)\s+/) {
|
||||
$return .= $first_qualifier =~ m/^[aeiouy]/ ? 'an ' : 'a ';
|
||||
} else {
|
||||
$first_qualifier =~ s/pointer/pointers/;
|
||||
}
|
||||
$return .= "$first_qualifier $item{declaration_specifiers}";
|
||||
} else {
|
||||
@ -761,6 +797,7 @@ declaration:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init_declarator_list:
|
||||
<leftop: init_declarator ',' init_declarator>
|
||||
@ -1272,10 +1309,30 @@ struct_declaration_list:
|
||||
}
|
||||
}
|
||||
|
||||
bitfield_identifier:
|
||||
identifier ':' constant
|
||||
{ $return = [$item{identifier}, $item{constant}]; }
|
||||
|
||||
struct_declaration:
|
||||
specifier_qualifier_list ';'
|
||||
| comment(?) specifier_qualifier_list struct_declarator_list ';'
|
||||
{ $return = join('', @{$item{'comment(?)'}}) . $item{specifier_qualifier_list} . ' ' . $item{struct_declarator_list}; }
|
||||
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?)
|
||||
{ $return = join('', @{$item[1]}) . $item{declaration} . join('', @{$item[-1]}); }
|
||||
|
||||
type_name:
|
||||
specifier_qualifier_list abstract_declarator(?)
|
||||
@ -1288,16 +1345,6 @@ specifier_qualifier_list:
|
||||
$return .= ' ' . join('', @{$item{'specifier_qualifier_list(?)'}}) if @{$item{'specifier_qualifier_list(?)'}};
|
||||
}
|
||||
|
||||
struct_declarator_list:
|
||||
struct_declarator
|
||||
| struct_declarator ',' struct_declarator_list
|
||||
{ $return = $item{struct_declarator} . join('',@{$item{struct_declarator_list}}); }
|
||||
|
||||
struct_declarator:
|
||||
declarator
|
||||
| declarator(?) ':' constant_expression
|
||||
{ $return = join('',@{$item{'declarator(?)'}}) . " a bit field $item{constant_expression}"; }
|
||||
|
||||
struct_or_union:
|
||||
comment(?) ('struct'
|
||||
{ $return = 'a structure'; }
|
||||
|
Loading…
Reference in New Issue
Block a user