CGrammar: Add _Generic; fix issue with compound-literals

This commit is contained in:
Pragmatic Software 2014-07-21 07:11:11 +00:00
parent fd89a4d0f4
commit de375e63a1
3 changed files with 38 additions and 13 deletions

View File

@ -13,8 +13,8 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 740,
BUILD_DATE => "2014-07-17",
BUILD_REVISION => 741,
BUILD_DATE => "2014-07-21",
};
1;

View File

@ -623,7 +623,11 @@ logical_OR_AND_expression:
{
if (defined $arg{context} and $arg{context} eq 'for conditional') { print STDERR "hmm2\n"; }
my $expression = join('', @{$item[1]});
if($arg{context} =~ /initializer expression$/ and $expression =~ / / and $expression !~ /^the .*? number \S+$/i and $expression !~ /^the result of the/) {
if($arg{context} =~ /initializer expression$/
and $expression =~ / /
and $expression !~ /^the .*? number \S+$/i
and $expression !~ /the size of/i
and $expression !~ /^the result of the/) {
$return = 'the result of the expression ^L';
}
$return .= $expression;
@ -1213,7 +1217,13 @@ postfix_productions:
| {""}
postfix_expression:
primary_expression postfix_productions[primary_expression => $item[1], context => $arg{context}]
'(' type_name ')' '{' initializer_list '}' postfix_productions[context => "$arg{context}|compound literal"](?)
{
my $postfix = $item[-1]->[0];
$return = "A compound-literal of type $item{type_name} initialized to { $item{initializer_list} }";
$return = "$postfix $return" if $postfix;
}
| primary_expression postfix_productions[primary_expression => $item[1], context => $arg{context}]
{
my $postfix_productions = $item{'postfix_productions'};
@ -1227,12 +1237,6 @@ postfix_expression:
$return = undef;
}
}
| '(' type_name ')' '{' initializer_list '}' postfix_productions[context => "$arg{context}|compound literal"](?)
{
my $postfix = $item[-1]->[0];
$return = "A compound-literal of type $item{type_name} initialized to { $item{initializer_list} }";
$return = "$postfix $return" if $postfix;
}
postfix_suffix:
'[' expression ']'
@ -1286,8 +1290,30 @@ primary_expression:
| constant
| string
| identifier
| generic_selection
| {} # nothing
generic_selection:
'_Generic' '(' assignment_expression ',' generic_assoc_list ')'
{ $return = "a generic-selection on $item{assignment_expression} yielding $item{generic_assoc_list}"; }
generic_assoc_list:
<leftop: generic_association ',' generic_association>
{
if (@{$item[-1]} == 1) {
$return = $item[-1]->[0];
} else {
my $last = pop @{$item[-1]};
$return = join(', ', @{$item[-1]}) . " and $last";
}
}
generic_association:
type_name ':' assignment_expression
{ $return = "$item{assignment_expression} in the case that it has type $item{type_name}"; }
| 'default' ':' assignment_expression
{ $return = "$item{assignment_expression} in the default case"; }
Alignas:
'_Alignas'
| 'alignas'

View File

@ -19,9 +19,6 @@ if ($opt_T ) {
$::RD_HINT = 1;
$Parse::RecDescent::skip = '\s*';
# This may be necessary..
# $::RD_AUTOACTION = q { [@item] };
my $parser;
if($opt_P or !eval { require PCGrammar }) {
@ -76,6 +73,8 @@ foreach my $arg (@ARGV) {
$output =~ s/by evaluate the/by the/g;
$output =~ s/the a /the /g;
$output =~ s/Then if it has the value/If it has the value/g;
$output =~ s/result of the expression a generic-selection/result of a generic-selection/g;
$output =~ s/the function a generic-selection/the function resulting from a generic-selection/g;
$output =~ s/\.\s+Then exit switch block/ and then exit switch block/g;
foreach my $quote (@quotes) {