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