3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-01 17:16:39 +02:00

CGrammar: Add C11 use of type-qualifiers and static in array declarators in function parameter lists

This commit is contained in:
Pragmatic Software 2014-07-02 20:55:50 +00:00
parent d320d5e04a
commit df5fcbeaaa
2 changed files with 83 additions and 28 deletions

View File

@ -13,7 +13,7 @@ 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 => 697, BUILD_REVISION => 698,
BUILD_DATE => "2014-07-02", BUILD_DATE => "2014-07-02",
}; };

View File

@ -1217,46 +1217,74 @@ direct_declarator:
| identifier[context => 'direct_declarator'] array_declarator(s?) | identifier[context => 'direct_declarator'] array_declarator(s?)
{ {
if (@{$item{'array_declarator(s?)'}}) { if (@{$item{'array_declarator(s?)'}}) {
$return = [$item{identifier}, join('', @{$item{'array_declarator(s?)'}})]; $return = [$item{identifier}, join(' ', @{$item{'array_declarator(s?)'}})];
} else { } else {
$return = $item{identifier}; $return = $item{identifier};
} }
} }
| '(' declarator ')' array_declarator(s) | '(' declarator ')' array_declarator(s)
{ {
push @{$item{declarator}}, join('', @{$item{'array_declarator(s)'}}); push @{$item{declarator}}, join(' ', @{$item{'array_declarator(s)'}});
$return = $item{declarator}; $return = $item{declarator};
} }
| '(' parameter_type_list ')' | '(' parameter_type_list ')'
{ $return = "function taking $item{parameter_type_list} and returning"; } { $return = "function taking $item{parameter_type_list} and returning"; }
| '(' declarator array_declarator(s) ')' | '(' declarator array_declarator(s) ')'
{ $return = $item{'declarator'} . join('', @{$item{'array_declarator(s)'}}) } { $return = $item{'declarator'} . join(' ', @{$item{'array_declarator(s)'}}) }
| '(' declarator ')' | '(' declarator ')'
{ $return = $item{declarator}; } { $return = $item{declarator}; }
array_qualifiers:
type_qualifier_list array_qualifiers(?)
{
$return = $item{'type_qualifier_list'};
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
$return .= " $qualifiers" if $qualifiers;
}
| 'static' array_qualifiers(?)
{
$return = $item[1];
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
$return .= " $qualifiers" if $qualifiers;
}
array_declarator: array_declarator:
( '[' assignment_expression(?) ']' '[' array_qualifiers(?) assignment_expression(?) ']'
{ {
if (@{$item{'assignment_expression(?)'}}) { my $size;
my $size = join('', @{$item{'assignment_expression(?)'}}); if (@{$item{'assignment_expression(?)'}}) {
$size = join('', @{$item{'assignment_expression(?)'}});
if ($size =~ /^(unsigned|long)*\s*1$/) { if ($size =~ /^(unsigned|long)*\s*1$/) {
$return = "$size element "; $size = "$size element";
} else { } else {
$return = "$size elements "; $size = "$size elements";
} }
} else {
$return = 'unspecified length ';
}
}
)(s?)
{
my @array = @{$item[-1]};
if (@array) {
$return .= 'an array of ' . join('of an array of ' , @array) . 'of';
} else { } else {
undef; $size = 'unspecified length';
}
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
if ($qualifiers) {
if($qualifiers =~ s/static//g) {
$qualifiers =~ s/^\s+//;
$qualifiers =~ s/\s+$//;
$qualifiers =~ s/\s+/ /g;
if($qualifiers) {
$return = "a $qualifiers array ";
} else {
$return = "an array ";
}
$return .= "with optimization hint to provide access to the first element of $size of";
} else {
$return = "an $qualifiers array of $size of";
}
} else {
$return = "an array of $size of";
} }
} }
| '[' '*' ']'
{ $return = 'an array of variable length of unspecified size of'; }
identifier_list: identifier_list:
(identifier ',')(s?) identifier (identifier ',')(s?) identifier
@ -1332,18 +1360,45 @@ direct_abstract_declarator:
'(' abstract_declarator ')' '(' abstract_declarator ')'
{ $return = $item{abstract_declarator}; } { $return = $item{abstract_declarator}; }
| '[' ']' | '[' ']'
{ $return = "array of unspecified length of"; } { $return = 'array of unspecified length of'; }
| '[' constant_expression ']' | '[' '*' ']'
{ { $return = 'array of variable length of unspecified size of'; }
my $size = $item{constant_expression}; | '[' array_qualifiers(?) assignment_expression(?) ']'
if ($size =~ /^(unsigned|long)*\s*1$/) { {
$return = "array of $size element of"; my $size;
if (@{$item{'assignment_expression(?)'}}) {
$size = join('', @{$item{'assignment_expression(?)'}});
if ($size =~ /^(unsigned|long)*\s*1$/) {
$size = "$size element";
} else {
$size = "$size elements";
}
} else { } else {
$return = "array of $size elements of"; $size = 'unspecified length';
}
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
if ($qualifiers) {
if($qualifiers =~ s/static//g) {
$qualifiers =~ s/^\s+//;
$qualifiers =~ s/\s+$//;
$qualifiers =~ s/\s+/ /g;
if($qualifiers) {
$return = "a $qualifiers array ";
} else {
$return = "an array ";
}
$return .= "with optimization hint to provide access to the first element of $size of";
} else {
$return = "an $qualifiers array of $size of";
}
} else {
$return = "an array of $size of";
} }
} }
| DAD '[' ']' | DAD '[' ']'
| DAD '[' constant_expression ']' | DAD '[' array_qualifiers(?) assignment_expression(?) ']'
| '(' ')' | '(' ')'
{ $return = 'function taking unspecified parameters and returning'; } { $return = 'function taking unspecified parameters and returning'; }
| '(' parameter_type_list ')' | '(' parameter_type_list ')'
@ -1354,7 +1409,7 @@ direct_abstract_declarator:
DAD: # macro for direct_abstract_declarator DAD: # macro for direct_abstract_declarator
( '(' abstract_declarator ')' )(s?) ( '(' abstract_declarator ')' )(s?)
( '[' ']' )(s?) ( '[' ']' )(s?)
( '[' constant_expression ']' )(s?) ( '[' assignment_expression ']' )(s?)
( '(' ')' )(s?) ( '(' ')' )(s?)
( '(' parameter_type_list ')' )(s?) ( '(' parameter_type_list ')' )(s?)