2014-06-08 08:34:55 +02:00
|
|
|
# C-to-English Grammar
|
2014-06-23 13:17:23 +02:00
|
|
|
# Pragmatic Software
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2017-03-05 22:33:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2014-06-07 15:00:07 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my ($rule_name, @macros, @typedefs, @identifiers);
|
2014-06-07 15:00:07 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
startrule:
|
|
|
|
translation_unit
|
|
|
|
{
|
2014-06-07 15:00:07 +02:00
|
|
|
my $output = $item[-1];
|
2014-06-20 09:43:06 +02:00
|
|
|
$output =~ s/\^L(\s*.?)/\L$1/g; # lowercase specified characters
|
|
|
|
$output =~ s/\^U(\s*.?)/\U$1/g; # uppercase specified characters
|
2014-06-22 08:08:01 +02:00
|
|
|
push @$return, $output;
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
startrule(?)
|
2014-06-22 08:08:01 +02:00
|
|
|
{ push @$return, $item[-1]; }
|
2018-04-24 23:22:05 +02:00
|
|
|
|
2014-06-10 08:05:14 +02:00
|
|
|
translation_unit:
|
2014-06-17 20:20:13 +02:00
|
|
|
comment
|
2014-06-23 13:17:23 +02:00
|
|
|
| external_declaration
|
2014-06-08 08:34:55 +02:00
|
|
|
| function_definition
|
2014-06-10 23:12:09 +02:00
|
|
|
| preproc[matchrule => 'translation_unit']
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
preproc:
|
|
|
|
'#' (definition
|
|
|
|
| undefinition
|
|
|
|
| inclusion
|
|
|
|
| line
|
2014-06-15 03:09:06 +02:00
|
|
|
| error
|
2018-04-24 23:22:05 +02:00
|
|
|
| pragma
|
2014-06-15 03:09:06 +02:00
|
|
|
| preproc_conditional[matchrule => $arg{matchrule}])
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
definition:
|
2014-06-10 08:05:14 +02:00
|
|
|
macro_definition
|
2014-06-15 03:09:06 +02:00
|
|
|
| 'define' identifier token_sequence(?) <skip: '[ \t]*'> "\n"
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
|
|
|
my $token_sequence = join('',@{$item{'token_sequence(?)'}});
|
2014-06-10 08:05:14 +02:00
|
|
|
$return = "Define the macro $item{identifier}";
|
2014-06-08 08:34:55 +02:00
|
|
|
$return .= " to mean $token_sequence" if $token_sequence;
|
|
|
|
$return .= ".\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_definition:
|
2014-06-15 03:09:06 +02:00
|
|
|
'define' identifier '(' <leftop: identifier ',' identifier> ')' token_sequence <skip: '[ \t]*'> "\n"
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my @symbols = @{$item[-5]};
|
|
|
|
my $last;
|
|
|
|
push @macros, $item{identifier};
|
|
|
|
$return = "Define the macro $item{identifier} ";
|
|
|
|
if ($#symbols > 0) {
|
|
|
|
$last = pop @symbols;
|
|
|
|
$return .= "with the symbols " . join(", ",@symbols) . " and $last ";
|
|
|
|
} else {
|
|
|
|
$return .= "with the symbol $symbols[0] ";
|
|
|
|
}
|
|
|
|
$return .= "to use the token sequence `$item{token_sequence}`.\n";
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
undefinition:
|
2014-06-15 03:09:06 +02:00
|
|
|
'undef' identifier <skip: '[ \t]*'> "\n"
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-06-10 08:05:14 +02:00
|
|
|
@macros = grep { $_ ne $item{identifier} } @macros;
|
|
|
|
$return = "\nAnnul the definition of $item{identifier}.\n";
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
inclusion:
|
2014-06-15 03:09:06 +02:00
|
|
|
'include' '<' filename '>' <skip: '[ \t]*'> "\n"
|
2014-07-05 01:41:54 +02:00
|
|
|
{ $return = "\nInclude the header $item{filename}.\n"; }
|
2014-06-15 03:09:06 +02:00
|
|
|
| 'include' '"' filename '"' <skip: '[ \t]*'> "\n"
|
2014-07-05 01:41:54 +02:00
|
|
|
{ $return = "\nInclude the source file $item{filename}.\n"; }
|
2014-06-15 03:09:06 +02:00
|
|
|
| 'include' token
|
2018-04-24 23:22:05 +02:00
|
|
|
{ $return = "\nImport code noted by the token $item{token}.\n"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
filename:
|
|
|
|
/[_\.\-\w\/]+/
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
line:
|
2014-06-15 03:09:06 +02:00
|
|
|
'line' constant ('"' filename '"'
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = "and filename $item{filename}"; }
|
2014-06-10 08:05:14 +02:00
|
|
|
)(?) <skip: '[ \t]*'> "\n"
|
|
|
|
{ $return = "\nThis is line number $item{constant} " . join('', @{$item[-3]}) . ".\n"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
error:
|
2014-06-15 03:09:06 +02:00
|
|
|
'error' token_sequence(?) <skip: '[ \t]*'> "\n"
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = "Stop compilation with error \"" . join('', @{$item{'token_sequence(?)'}}) . "\".\n"; }
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
pragma:
|
2014-06-15 03:09:06 +02:00
|
|
|
'pragma' token_sequence(?) <skip: '[ \t]*'> "\n"
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $pragma = join('',@{$item{'token_sequence(?)'}});
|
2014-06-10 19:01:43 +02:00
|
|
|
if ($pragma) { $pragma = ' "$pragma"'; }
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "Process a compiler-dependent pragma$pragma.\n";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
preproc_conditional:
|
|
|
|
if_line[matchrule => $arg{matchrule}]
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $rule_name = $arg{matchrule}; }
|
2014-06-10 08:05:14 +02:00
|
|
|
<matchrule: $rule_name>(s?)
|
|
|
|
{ $return = $item{if_line} . join('',@{$item[-1]}); }
|
|
|
|
(elif_parts[matchrule => $rule_name])(?)
|
|
|
|
(else_parts[matchrule => $rule_name])(?)
|
|
|
|
{ $return .= join('',@{$item[-2]}) . join('',@{$item[-1]}); }
|
2018-04-24 23:22:05 +02:00
|
|
|
'#' 'endif'
|
2014-06-10 08:05:14 +02:00
|
|
|
{ $return .= "End preprocessor conditional.\n"; }
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
if_line:
|
2014-06-15 03:09:06 +02:00
|
|
|
'ifdef' identifier <skip: '[ \t]*'> "\n"
|
2014-06-10 19:01:43 +02:00
|
|
|
{ $return .= "If the macro $item{identifier} is defined, then ^L"; }
|
2014-06-15 03:09:06 +02:00
|
|
|
| 'ifndef' identifier <skip: '[ \t]*'> "\n"
|
2014-06-10 19:01:43 +02:00
|
|
|
{ $return .= "If the macro $item{identifier} is not defined, then ^L"; }
|
2014-06-15 03:09:06 +02:00
|
|
|
| 'if' constant_expression <skip: '[ \t]*'> "\n"
|
2014-06-10 19:01:43 +02:00
|
|
|
{ $return .= "If the preprocessor condition^L $item{constant_expression} is true, then ^L"; }
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
elif_parts:
|
2018-04-24 23:22:05 +02:00
|
|
|
('#' 'elif' constant_expression
|
2014-06-10 23:12:09 +02:00
|
|
|
{ $return .= "Otherwise, if the preprocessor condition $item{constant_expression} is true, then ^L"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
(<matchrule: $rule_name> )[matchrule => $arg{matchrule}](s?)
|
|
|
|
{ $return .= join('',@{$item[-1]}); }
|
2018-04-24 23:22:05 +02:00
|
|
|
)(s)
|
2014-06-10 23:12:09 +02:00
|
|
|
{ $return = join('', @{$item[-1]}); }
|
2018-04-24 23:22:05 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
else_parts:
|
2018-04-24 23:22:05 +02:00
|
|
|
'#' 'else'
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $rule_name = $arg{matchrule}; }
|
|
|
|
(<matchrule: $rule_name>)[matchrule => $arg{matchrule}](s?)
|
2014-06-10 19:01:43 +02:00
|
|
|
{ $return = "Otherwise, ^L" . join('',@{$item[-1]}); }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
token_sequence:
|
|
|
|
token(s)
|
|
|
|
{ $return = join(' ', @{$item[1]}); }
|
|
|
|
|
|
|
|
token:
|
2018-04-24 23:22:05 +02:00
|
|
|
<skip: '[ \t]*'> /\S+/
|
2014-06-10 19:01:43 +02:00
|
|
|
{ $return = $item[-1]; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
external_declaration:
|
2018-04-24 23:22:05 +02:00
|
|
|
declaration[context => 'external declaration']
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
function_definition:
|
2014-06-23 13:10:40 +02:00
|
|
|
declaration_specifiers[context => 'function definition'](?) declarator[context => 'function definition'] compound_statement[context => 'function definition statement'](?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $declaration_specifiers = join('', @{$item{'declaration_specifiers(?)'}});
|
2014-06-20 09:43:06 +02:00
|
|
|
my $name = $item{declarator}->[0];
|
|
|
|
my $parameter_list = $item{declarator}->[1];
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-06-20 09:43:06 +02:00
|
|
|
my $return_type;
|
2014-07-01 18:21:52 +02:00
|
|
|
if (@{$item{declarator}} > 2) {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return_type = "$item{declarator}->[2] $declaration_specifiers";
|
2014-06-10 08:05:14 +02:00
|
|
|
} else {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return_type = $declaration_specifiers;
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($return_type =~ s/( with.*)$//) {
|
2014-07-04 13:09:58 +02:00
|
|
|
my $specifier = $1;
|
|
|
|
$parameter_list =~ s/function/function$specifier/;
|
2014-06-23 10:29:08 +02:00
|
|
|
}
|
|
|
|
|
2014-07-04 13:09:58 +02:00
|
|
|
if ($return_type =~ s/inline//g) {
|
|
|
|
$return_type = join(' ', split(' ', $return_type));
|
|
|
|
my $and = $parameter_list =~ s/function with/function/ ? ' and' : '';
|
|
|
|
$parameter_list =~ s/function/function with suggestion to be as fast as possible$and/;
|
|
|
|
}
|
|
|
|
|
2014-07-04 14:18:59 +02:00
|
|
|
if ($return_type =~ s/_Noreturn//g) {
|
|
|
|
$return_type = join(' ', split(' ', $return_type));
|
2014-07-04 13:09:58 +02:00
|
|
|
$parameter_list =~ s/ returning$//;
|
2014-07-04 14:18:59 +02:00
|
|
|
if ($return_type eq 'void') {
|
|
|
|
$return_type = "which doesn't return to its caller";
|
|
|
|
} else {
|
|
|
|
$return_type = "which shouldn't return to its caller yet does mysteriously return $return_type";
|
|
|
|
}
|
2014-07-04 13:09:58 +02:00
|
|
|
}
|
2015-09-08 07:20:52 +02:00
|
|
|
|
|
|
|
if (ref $name eq 'ARRAY') {
|
|
|
|
my @a = @$name;
|
|
|
|
$name = shift @a;
|
|
|
|
$parameter_list = join(' ', @a) . " $parameter_list";
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
|
2014-07-04 14:18:59 +02:00
|
|
|
$return = "\nLet $name be a $parameter_list $return_type.\n";
|
2018-04-24 23:22:05 +02:00
|
|
|
|
2014-07-04 14:18:59 +02:00
|
|
|
my $statements = join('', @{$item{'compound_statement(?)'}});
|
|
|
|
$return .= "When called, the function will ^L$statements";
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-02 19:54:21 +02:00
|
|
|
block_item_list:
|
|
|
|
block_item(s)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-04 14:18:59 +02:00
|
|
|
if (@{$item{'block_item(s)'}} == 1) {
|
|
|
|
$return = $item{'block_item(s)'}->[0];
|
|
|
|
} elsif (@{$item{'block_item(s)'}} == 2) {
|
|
|
|
my $first = $item{'block_item(s)'}->[0];
|
|
|
|
my $second = $item{'block_item(s)'}->[1];
|
|
|
|
$first =~ s/\.?\s*$//;
|
|
|
|
$return = "$first and then ^L$second";
|
|
|
|
} else {
|
|
|
|
my $last = pop @{$item{'block_item(s)'}};
|
|
|
|
$return = join('Then ^L', @{$item{'block_item(s)'}}) . "Finally, ^L$last";
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 19:54:21 +02:00
|
|
|
|
|
|
|
block_item:
|
|
|
|
declaration
|
2014-07-18 05:52:16 +02:00
|
|
|
| statement[context => "$arg{context}|block item"]
|
2014-07-02 20:04:22 +02:00
|
|
|
| preproc
|
|
|
|
| comment
|
2014-07-02 19:54:21 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
compound_statement:
|
2018-04-24 23:22:05 +02:00
|
|
|
'{' block_item_list(s?) '}'
|
|
|
|
{
|
2014-07-02 19:54:21 +02:00
|
|
|
my $block_items = join('', @{$item{'block_item_list(s?)'}});
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-18 05:52:16 +02:00
|
|
|
if ($arg{context} =~ /block item/
|
|
|
|
and $arg{context} !~ /do loop$/
|
|
|
|
and $arg{context} !~ /if statement$/
|
|
|
|
and $arg{context} !~ /switch$/
|
|
|
|
and $arg{context} !~ /else block$/) {
|
|
|
|
$return = "Begin new block.\n";
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($block_items) {
|
2014-07-02 19:54:21 +02:00
|
|
|
$return .= $block_items;
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return .= "Do nothing.\n";
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-18 05:52:16 +02:00
|
|
|
if ($arg{context} =~ /block item/
|
|
|
|
and $arg{context} !~ /do loop$/
|
|
|
|
and $arg{context} !~ /if statement$/
|
|
|
|
and $arg{context} !~ /switch$/
|
|
|
|
and $arg{context} !~ /else block$/) {
|
|
|
|
$return .= "End block.\n";
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($arg{context}
|
2014-07-18 05:52:16 +02:00
|
|
|
and $arg{context} !~ /do loop$/
|
|
|
|
and $arg{context} !~ /if statement$/
|
|
|
|
and $arg{context} !~ /else block$/
|
|
|
|
and $arg{context} !~ /case$/
|
2018-04-24 23:22:05 +02:00
|
|
|
and $arg{context} !~ /function definition statement$/
|
|
|
|
and $arg{context} !~ /function definition$/) {
|
2014-07-18 05:52:16 +02:00
|
|
|
my @contexts = split /\|/, $arg{context};
|
|
|
|
my $context = pop @contexts;
|
|
|
|
$return .= "End $context.\n" unless $context eq 'block item';
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
1;
|
|
|
|
}
|
|
|
|
|
|
|
|
statement_list:
|
2014-06-20 09:43:06 +02:00
|
|
|
comment(?) preproc[matchrule => 'statement'](?) statement[context => undef]
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $preproc = join('',@{$item{'preproc(?)'}});
|
|
|
|
my $comment = join('',@{$item{'comment(?)'}});
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
$return = $item{statement};
|
2018-04-24 23:22:05 +02:00
|
|
|
|
|
|
|
if ($comment) { $return = $comment . $return; }
|
|
|
|
if ($preproc) { $return = $preproc . $return; }
|
|
|
|
}
|
2014-06-20 09:43:06 +02:00
|
|
|
statement_list(?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return .= join('',@{$item{'statement_list(?)'}}); }
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
statement:
|
2014-06-08 08:34:55 +02:00
|
|
|
jump_statement
|
2014-06-20 09:43:06 +02:00
|
|
|
| compound_statement
|
2014-06-08 08:34:55 +02:00
|
|
|
| iteration_statement
|
|
|
|
| selection_statement
|
|
|
|
| labeled_statement
|
|
|
|
| expression_statement
|
|
|
|
|
|
|
|
iteration_statement:
|
2018-04-24 23:22:05 +02:00
|
|
|
'for' '(' <commit> for_initialization(?) for_expression(?) for_increment(?) ')'
|
2014-06-10 10:50:19 +02:00
|
|
|
statement[context => 'for loop']
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
my $initialization = join('', @{$item{'for_initialization(?)'}});
|
|
|
|
my $expression = join('',@{$item{'for_expression(?)'}});
|
|
|
|
my $increment = join('',@{$item{'for_increment(?)'}});
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($initialization) {
|
|
|
|
$return .= "Prepare a loop by ^L$initialization, then ^L";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if (length $expression) {
|
2014-07-10 15:11:13 +02:00
|
|
|
if ($expression =~ /^(\d+)$/) {
|
|
|
|
if($expression == 0) {
|
2014-07-10 15:13:57 +02:00
|
|
|
$return .= "Never repeatedly ^L";
|
2014-07-10 15:11:13 +02:00
|
|
|
} else {
|
|
|
|
$return .= "Repeatedly ^L";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
my $expression = ::istrue $expression;
|
2018-04-24 23:22:05 +02:00
|
|
|
$return .= "For as long as ^L$expression, ^L";
|
2014-07-10 15:11:13 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
|
|
|
$return .= "Repeatedly ^L";
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-10 15:11:13 +02:00
|
|
|
$return .= $item{statement};
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($increment) {
|
2014-06-12 14:23:16 +02:00
|
|
|
$return =~ s/End for loop.$//;
|
2018-04-24 23:22:05 +02:00
|
|
|
$return .= "After each iteration, ^L$increment.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| 'while' '(' <commit> expression[context => 'while conditional'] ')' statement[context => 'while loop']
|
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{expression} =~ /(^\d+$)/) {
|
|
|
|
if ($1 == 0) {
|
2014-07-10 15:13:57 +02:00
|
|
|
$return = "Never repeatedly ^L";
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
2014-06-11 10:29:58 +02:00
|
|
|
$return = "Repeatedly ^L";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-11 10:29:58 +02:00
|
|
|
} else {
|
2014-06-24 07:34:54 +02:00
|
|
|
my $expression = ::istrue $item{expression};
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "While ^L$expression, ^L";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{statement}) {
|
2014-07-17 20:36:09 +02:00
|
|
|
$return .= $item{statement} . "\n";
|
2014-06-11 10:29:58 +02:00
|
|
|
} else {
|
|
|
|
$return .= "do nothing.\n";
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
|
|
|
| 'do' statement[context => 'do loop'] 'while' '(' expression[context => 'do while conditional'] ')' ';'
|
2014-06-23 10:29:08 +02:00
|
|
|
{
|
|
|
|
$item{statement} =~ s/^do nothing/nothing/i;
|
|
|
|
$return = "Do the following:^L $item{statement}";
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{expression} =~ /(^\d+$)/) {
|
|
|
|
if ($1 == 0) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return .= "Do this once.\n";
|
|
|
|
} else {
|
|
|
|
$return .= "Do this repeatedly.\n";
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-24 07:34:54 +02:00
|
|
|
my $expression = ::istrue $item{expression};
|
|
|
|
$return .= "Do this as long as ^L$expression.\n";
|
2014-06-23 10:29:08 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
for_initialization:
|
2014-06-29 23:13:18 +02:00
|
|
|
declaration[context => 'for init']
|
|
|
|
| expression_statement[context => 'for init']
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
for_expression:
|
2014-06-29 23:13:18 +02:00
|
|
|
expression_statement[context => 'for conditional']
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
for_increment:
|
2018-04-24 23:22:05 +02:00
|
|
|
expression[context => 'for increment statement']
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
selection_statement:
|
2014-07-17 20:51:29 +02:00
|
|
|
'if' <commit> '(' expression[context => 'if conditional'] ')' statement[context => "$arg{context}|if statement"]
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{expression} =~ /^(\d+)$/) {
|
|
|
|
if ($1 == 0) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = "Never ";
|
2014-06-12 14:23:16 +02:00
|
|
|
} else {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = "Always ";
|
2014-06-12 14:23:16 +02:00
|
|
|
}
|
2014-06-23 10:29:08 +02:00
|
|
|
} else {
|
2014-06-24 07:34:54 +02:00
|
|
|
my $expression = ::istrue $item{expression};
|
|
|
|
$return = "If ^L$expression then ";
|
2014-06-12 14:23:16 +02:00
|
|
|
}
|
2014-06-23 10:29:08 +02:00
|
|
|
$return .= "^L$item{statement}";
|
2014-06-12 14:23:16 +02:00
|
|
|
}
|
2014-07-17 20:51:29 +02:00
|
|
|
('else' statement[context => "$arg{context}|else block"]
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = "Otherwise, ^L$item{statement}"; }
|
|
|
|
)(?)
|
|
|
|
{ $return .= join('',@{$item[-1]}); }
|
2018-04-24 23:22:05 +02:00
|
|
|
| 'switch' '(' expression[context => 'switch conditional'] ')' statement[context => "$arg{context}|switch"]
|
|
|
|
{
|
2014-07-18 05:52:16 +02:00
|
|
|
$return = "When given the expression ^L$item{expression}, ^L$item{statement}";
|
2014-06-23 10:29:08 +02:00
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
jump_statement:
|
|
|
|
'break' ';'
|
|
|
|
{
|
2014-07-17 20:51:29 +02:00
|
|
|
if ($arg{context} =~ /switch/ or $arg{context} =~ /case/) {
|
2014-07-17 20:36:09 +02:00
|
|
|
$return = "Exit switch block.\n";
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif (length $arg{context}) {
|
2014-07-17 21:04:09 +02:00
|
|
|
my ($context) = $arg{context} =~ /([^|]+)/;
|
|
|
|
$return = "Break from the $context.\n";
|
2014-06-14 20:41:55 +02:00
|
|
|
} else {
|
|
|
|
$return = "Break from the current block.\n";
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
| 'continue' ';'
|
2018-04-24 23:22:05 +02:00
|
|
|
{ $return = "Return to the top of the current loop.\n"; }
|
|
|
|
| 'return' <commit> expression[context => "$arg{context}|return expression"](?) ';'
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-06-24 07:34:54 +02:00
|
|
|
my $expression = join('', @{$item{'expression(?)'}});
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if (length $expression) {
|
2014-06-24 07:34:54 +02:00
|
|
|
$return = "Return ^L$expression.\n";
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
|
|
|
$return = "Return no value.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
| 'goto' <commit> identifier ';' comment(?)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-06-08 08:34:55 +02:00
|
|
|
$return = "Go to the label named $item{identifier}.\n";
|
2014-06-14 21:13:53 +02:00
|
|
|
$return .= join('', @{$item{'comment(?)'}});
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
expression_statement:
|
2014-07-01 18:16:40 +02:00
|
|
|
expression[context => "$arg{context}|statement"](?) ';'
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
my $expression = join('',@{$item[1]});
|
2014-07-10 15:11:13 +02:00
|
|
|
if (not length $expression) {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} eq 'label'
|
2014-06-29 23:13:18 +02:00
|
|
|
or $arg{context} eq 'for init'
|
|
|
|
or $arg{context} eq 'for conditional') {
|
|
|
|
$return = "";
|
2014-06-14 21:13:53 +02:00
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "Do nothing.\n";
|
2014-06-14 21:13:53 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
} else {
|
2014-06-29 23:13:18 +02:00
|
|
|
$return = $expression;
|
2014-07-17 21:04:09 +02:00
|
|
|
$return .= ".\n" unless $arg{context} =~ /for (init|conditional)$/;
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
labeled_statement:
|
2014-06-14 21:13:53 +02:00
|
|
|
identifier ':' statement[context => 'label'] (';')(?)
|
2014-06-14 20:41:55 +02:00
|
|
|
{ $return = "Let there be a label $item{identifier}.\n$item{statement}"; }
|
2018-04-24 23:22:05 +02:00
|
|
|
| ('case' constant_expression
|
|
|
|
{ $return = $item{constant_expression}; }
|
2014-07-17 20:36:09 +02:00
|
|
|
':')(s)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-17 20:36:09 +02:00
|
|
|
my @items = @{$item[1]};
|
|
|
|
if (@items <= 2) {
|
|
|
|
$return = join(' or ', @{$item[1]});
|
|
|
|
} else {
|
|
|
|
my $last = pop @items;
|
|
|
|
$return = join(', ', @items) . " or $last";
|
|
|
|
}
|
|
|
|
}
|
2014-07-18 05:52:16 +02:00
|
|
|
(statement[context => "$arg{context}|case"])(s)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-17 20:36:09 +02:00
|
|
|
my $last = pop @{$item[-1]};
|
|
|
|
my $statements = join('', @{$item[-1]});
|
2014-07-17 20:51:29 +02:00
|
|
|
if (length $statements and $statements !~ /Exit switch block\.\s*$/) {
|
2014-07-17 20:36:09 +02:00
|
|
|
$statements .= "Fall through to the next case.\n";
|
2014-07-18 02:39:06 +02:00
|
|
|
} elsif (not length $statements and not $last) {
|
|
|
|
$statements = "Do nothing.\n";
|
2014-07-17 20:36:09 +02:00
|
|
|
}
|
|
|
|
$return = "If it has the value $item[-2], ^L$statements$last";
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| 'default' ':' statement
|
|
|
|
{ $return = "In the default case, ^L$item{statement}"; }
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
expression:
|
2014-06-26 09:35:11 +02:00
|
|
|
<leftop: assignment_expression ',' assignment_expression>
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} eq 'for increment statement'
|
2014-06-29 23:13:18 +02:00
|
|
|
or $arg{context} eq 'for init') {
|
2014-06-26 09:35:11 +02:00
|
|
|
$return = join(', then ', @{$item[-1]});
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ( $arg{context} =~ /conditional/) {
|
2014-06-28 12:18:28 +02:00
|
|
|
$return = join(' and the result discarded and ', @{$item[-1]});
|
2014-06-26 09:35:11 +02:00
|
|
|
} else {
|
2014-06-28 12:18:28 +02:00
|
|
|
$return .= "Evaluate " if @{$item[-1]} > 1;
|
2018-04-24 23:22:05 +02:00
|
|
|
$return .= join(" and discard the result and then evaluate ^L", @{$item[-1]});
|
2014-06-26 09:35:11 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assignment_expression:
|
2018-04-24 23:22:05 +02:00
|
|
|
unary_expression[context => 'assignment expression']
|
2014-06-26 09:35:11 +02:00
|
|
|
assignment_operator
|
2018-04-24 23:22:05 +02:00
|
|
|
assignment_expression[context => 'assignment expression']
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $assignment_expression = $item{assignment_expression};
|
2014-06-08 08:34:55 +02:00
|
|
|
my $assignment_operator = $item{assignment_operator};
|
|
|
|
|
2014-07-01 18:16:40 +02:00
|
|
|
if (ref $assignment_operator eq 'ARRAY') {
|
2014-06-12 14:23:16 +02:00
|
|
|
$return .= "${$item{assignment_operator}}[0] $item{unary_expression} ";
|
2014-07-21 23:27:22 +02:00
|
|
|
${$item{assignment_operator}}[1] =~ s/the value/the result of the expression/ if $assignment_expression =~ / /;
|
2014-06-12 14:23:16 +02:00
|
|
|
$return .= "${$item{assignment_operator}}[1] " if $assignment_expression !~ /the result of/;
|
|
|
|
$return .= $assignment_expression;
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "$item{unary_expression} $assignment_operator $assignment_expression";
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 09:35:11 +02:00
|
|
|
| conditional_expression
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
conditional_expression:
|
2014-06-26 09:35:11 +02:00
|
|
|
logical_OR_AND_expression conditional_ternary_expression
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{conditional_ternary_expression}) {
|
2014-06-18 03:08:19 +02:00
|
|
|
my $op1 = $item{conditional_ternary_expression}->[0];
|
|
|
|
my $op2 = $item{conditional_ternary_expression}->[1];
|
2014-06-24 07:34:54 +02:00
|
|
|
my $expression = ::istrue $item{logical_OR_AND_expression};
|
2014-07-01 18:16:40 +02:00
|
|
|
|
2014-07-18 05:52:16 +02:00
|
|
|
if ($arg{context} =~ /initializer expression$/) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "$op1 if $expression otherwise to $op2";
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($arg{context} =~ /assignment expression$/) {
|
2014-07-03 23:33:20 +02:00
|
|
|
$return = "$op1 if $expression otherwise the value $op2";
|
2014-07-01 18:16:40 +02:00
|
|
|
} else {
|
|
|
|
$return = "$op1 if $expression otherwise $op2";
|
|
|
|
}
|
2014-06-15 02:46:49 +02:00
|
|
|
} else {
|
|
|
|
$return = $item{logical_OR_AND_expression};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
conditional_ternary_expression:
|
|
|
|
'?' expression ':' conditional_expression
|
2018-04-24 23:22:05 +02:00
|
|
|
{ $return = [$item{expression}, $item{conditional_expression}]; }
|
2014-06-16 04:31:13 +02:00
|
|
|
| {""}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
assignment_operator:
|
2018-04-24 23:22:05 +02:00
|
|
|
'='
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-07-01 19:03:07 +02:00
|
|
|
if ($arg{context} =~ /for init/) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = ['assigning to^L', 'the value^L' ];
|
2018-04-24 23:22:05 +02:00
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Assign to^L', 'the value^L' ];
|
|
|
|
} else {
|
|
|
|
$return = 'which is assigned to be^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| '+='
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($arg{context} =~ /for init/) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = ['incrementing^L','by^L'];
|
2018-04-24 23:22:05 +02:00
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
2014-07-01 19:03:07 +02:00
|
|
|
$return = ['Increment^L','by^L'];
|
2018-04-24 23:22:05 +02:00
|
|
|
} else {
|
|
|
|
$return = 'which is incremented by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '-='
|
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['decrementing^L' , 'by^L'];
|
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Decrement^L', 'by^L'];
|
|
|
|
} else {
|
|
|
|
$return = 'which is decremented by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '*='
|
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($arg{context} =~ /for init/) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = ['multiplying^L' , 'by^L'];
|
2018-04-24 23:22:05 +02:00
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Multiply^L' , 'by^L'];
|
|
|
|
} else {
|
|
|
|
$return = 'which is multiplied by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '/='
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['dividing^L' , 'by^L' ];
|
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Divide^L' , 'by^L' ];
|
|
|
|
} else {
|
|
|
|
$return = 'which is divided by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| '%='
|
|
|
|
{
|
|
|
|
if ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['reducing^L', 'to modulo ^L'] ;
|
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Reduce^L', 'to modulo ^L'] ;
|
|
|
|
} else {
|
|
|
|
$return = 'which is reduced to modulo^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '<<='
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['bit-shifting^L', 'left by^L'];
|
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Bit-shift^L', 'left by^L'];
|
|
|
|
} else {
|
|
|
|
$return = 'which is bit-shifted left by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '>>='
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['bit-shifting^L', 'right by^L'];
|
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Bit-shift^L', 'right by^L'];
|
|
|
|
} else {
|
|
|
|
$return = 'which is bit-shifted right by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '&='
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['bitwise-ANDing^L', 'by^L' ];
|
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Bitwise-AND^L', 'by^L' ];
|
|
|
|
} else {
|
|
|
|
$return = 'which is bitwise-ANDed by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '^='
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /for init/) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = ['exclusive-ORing^L','by^L'];
|
2018-04-24 23:22:05 +02:00
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
2014-07-01 19:03:07 +02:00
|
|
|
$return = ['Exclusive-OR^L','by^L'];
|
2018-04-24 23:22:05 +02:00
|
|
|
} else {
|
|
|
|
$return = 'which is exclusive-ORed by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '|='
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['bitwise-ORing^L', 'by^L'];
|
|
|
|
} elsif ($arg{context} =~ /statement$/) {
|
|
|
|
$return = ['Bitwise-OR^L', 'by^L'];
|
|
|
|
} else {
|
|
|
|
$return = 'which is bitwise-ORed by^L';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
constant_expression:
|
|
|
|
conditional_expression
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
logical_OR_AND_expression:
|
|
|
|
<leftop:
|
2014-06-26 09:35:11 +02:00
|
|
|
rel_add_mul_shift_expression
|
2014-06-08 08:34:55 +02:00
|
|
|
log_OR_AND_bit_or_and_eq
|
2014-06-15 02:46:49 +02:00
|
|
|
rel_add_mul_shift_expression[context => 'logical_OR_AND_expression']>
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-07-13 08:36:55 +02:00
|
|
|
my $expression = join('', @{$item[1]});
|
2014-07-21 09:11:11 +02:00
|
|
|
if($arg{context} =~ /initializer expression$/
|
|
|
|
and $expression =~ / /
|
2015-09-08 07:20:52 +02:00
|
|
|
and $expression !~ /^the .*? constant \S+$/i
|
2014-07-21 09:11:11 +02:00
|
|
|
and $expression !~ /the size of/i
|
2014-08-10 07:03:37 +02:00
|
|
|
and $expression !~ /the offset/i
|
2014-09-09 09:20:42 +02:00
|
|
|
and $expression !~ /the address of/i
|
2014-07-21 09:11:11 +02:00
|
|
|
and $expression !~ /^the result of the/) {
|
2014-07-13 08:36:55 +02:00
|
|
|
$return = 'the result of the expression ^L';
|
|
|
|
}
|
|
|
|
$return .= $expression;
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
log_OR_AND_bit_or_and_eq:
|
2014-06-23 10:29:08 +02:00
|
|
|
'||' { $return = ' or ^L'; }
|
|
|
|
| '&&' { $return = ' and ^L'; }
|
|
|
|
| '|' { $return = ' bitwise-ORed by ^L'; }
|
|
|
|
| '&' { $return = ' bitwise-ANDed by ^L'; }
|
|
|
|
| '^' { $return = ' bitwise-XORed by ^L';}
|
|
|
|
| '==' { $return = ' is equal to ^L'; }
|
2018-04-24 23:22:05 +02:00
|
|
|
| '!=' { $return = ' is not equal to ^L'; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
rel_mul_add_ex_op:
|
2014-06-23 10:29:08 +02:00
|
|
|
'+' { $return = ' plus ^L'; }
|
|
|
|
| '-' { $return = ' minus ^L'; }
|
|
|
|
| '*' { $return = ' times ^L'; }
|
|
|
|
| '/' { $return = ' divided by ^L'; }
|
|
|
|
| '%' { $return = ' modulo ^L'; }
|
|
|
|
| '<<' { $return = ' shifted left by ^L'; }
|
|
|
|
| '>>' { $return = ' shifted right by ^L'; }
|
|
|
|
| '>=' { $return = ' is greater than or equal to ^L'; }
|
|
|
|
| "<=" { $return = ' is less than or equal to ^L'; }
|
|
|
|
| '>' { $return = ' is greater than ^L'; }
|
|
|
|
| '<' { $return = ' is less than ^L'; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
unary_operator:
|
2014-06-24 10:47:29 +02:00
|
|
|
'&' { $return = 'the address of ^L'; }
|
|
|
|
| '*' { $return = 'the dereference of ^L'; }
|
2014-06-12 15:13:45 +02:00
|
|
|
| '+' { $return = ''; }
|
2014-06-24 10:47:29 +02:00
|
|
|
| '-' ...identifier { $return = 'negative ^L'; }
|
|
|
|
| '-' { $return = 'minus ^L'; }
|
|
|
|
| '~' { $return = "the one's complement of ^L"; }
|
|
|
|
| '!' '!' { $return = 'the normalized boolean value of ^L'; }
|
2018-04-24 23:22:05 +02:00
|
|
|
| '!'
|
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} =~ /conditional/) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = ['', ' is false'];
|
|
|
|
} else {
|
2014-06-24 10:47:29 +02:00
|
|
|
$return = 'the logical negation of ^L';
|
2014-06-23 10:29:08 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
rel_add_mul_shift_expression:
|
2014-06-23 10:29:08 +02:00
|
|
|
cast_expression ...';'
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = $item{cast_expression}; }
|
2014-06-23 10:29:08 +02:00
|
|
|
| <leftop: cast_expression rel_mul_add_ex_op cast_expression>
|
2014-07-13 08:36:55 +02:00
|
|
|
{ $return = join('', @{$item[1]}); }
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
closure:
|
|
|
|
',' | ';' | ')'
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
cast_expression:
|
|
|
|
'(' type_name ')' cast_expression[context => 'recast']
|
2014-07-13 08:36:55 +02:00
|
|
|
{ $return = "$item{cast_expression} converted to $item{type_name}"; }
|
2018-04-24 23:22:05 +02:00
|
|
|
| unary_expression
|
|
|
|
{ $return = $item{unary_expression}; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-07 10:27:10 +02:00
|
|
|
Static_assert:
|
|
|
|
'_Static_assert'
|
|
|
|
| 'static_assert'
|
|
|
|
|
|
|
|
static_assert_declaration:
|
2014-09-19 06:17:37 +02:00
|
|
|
Static_assert '(' constant_expression[context => 'static assert'] ',' string ')' ';'
|
2014-07-07 10:27:10 +02:00
|
|
|
{
|
2014-09-19 06:17:37 +02:00
|
|
|
my $expression = ::istrue $item{constant_expression};
|
|
|
|
$return = "Halt compilation and produce the diagnostic $item{string} unless $expression.\n";
|
2014-07-07 10:27:10 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
declaration_list:
|
|
|
|
preproc[context => 'statement'](?) declaration(s)
|
2014-06-10 08:05:14 +02:00
|
|
|
{ $return = join('', @{$item{'preproc(?)'}}) . join('', @{$item{'declaration(s)'}}); }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
declaration:
|
2014-06-20 09:43:06 +02:00
|
|
|
declaration_specifiers init_declarator_list(?) ';'
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-06-08 15:51:29 +02:00
|
|
|
my @init_list = defined $item{'init_declarator_list(?)'}->[0] ? @{$item{'init_declarator_list(?)'}->[0]} : ('');
|
2014-06-25 12:15:12 +02:00
|
|
|
my $typedef = $item{declaration_specifiers} =~ s/^type definition of //;
|
2014-07-04 13:09:58 +02:00
|
|
|
my $noreturn = $item{declaration_specifiers} =~ s/_Noreturn//g;
|
|
|
|
$item{declaration_specifiers} = join(' ', split(' ', $item{declaration_specifiers}));
|
|
|
|
|
|
|
|
if ($noreturn) {
|
2014-07-04 14:18:59 +02:00
|
|
|
if($item{declaration_specifiers} eq 'void') {
|
|
|
|
$item{declaration_specifiers} = "which doesn't return to its caller";
|
|
|
|
} else {
|
|
|
|
$item{declaration_specifiers} = "which shouldn't return to its caller yet does mysteriously return $item{declaration_specifiers}";
|
|
|
|
}
|
2014-07-04 13:09:58 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-06-25 12:15:12 +02:00
|
|
|
my $inits = 0;
|
2014-07-01 18:21:52 +02:00
|
|
|
while (@init_list) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$inits++;
|
2014-07-01 18:21:52 +02:00
|
|
|
if (not $arg{context} eq 'struct member') {
|
|
|
|
if ($arg{context} eq 'for init') {
|
2014-07-04 14:18:59 +02:00
|
|
|
$return .= "declaring ";
|
2014-06-29 23:13:18 +02:00
|
|
|
} else {
|
2014-07-04 14:18:59 +02:00
|
|
|
$return .= "Declare ";
|
2014-06-29 23:13:18 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-25 12:15:12 +02:00
|
|
|
|
|
|
|
my @args = ::flatten shift @init_list;
|
|
|
|
|
|
|
|
my ($first_qualifier, $first_initializer);
|
|
|
|
my $first_identifier = shift @args;
|
|
|
|
|
2014-07-05 01:41:54 +02:00
|
|
|
my @identifiers = ($first_identifier) unless not length $first_identifier;
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-07-08 02:33:50 +02:00
|
|
|
foreach my $arg (@args) {
|
|
|
|
if ($arg =~ /initialized/) {
|
2014-07-08 05:28:51 +02:00
|
|
|
$first_initializer .= (length $first_initializer ? ' ' : '') . $arg;
|
2014-07-08 02:33:50 +02:00
|
|
|
} else {
|
2014-07-08 05:28:51 +02:00
|
|
|
$first_qualifier .= (length $first_qualifier ? ' ' : '') . $arg;
|
2014-07-08 02:33:50 +02:00
|
|
|
}
|
2014-06-25 12:15:12 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-06-25 12:15:12 +02:00
|
|
|
my @initializers;
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($first_initializer) {
|
2014-06-25 12:15:12 +02:00
|
|
|
push @initializers, [ $first_identifier, $first_initializer ];
|
|
|
|
}
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
for (my $i = 0; $i < @init_list; $i++) {
|
2014-06-25 12:15:12 +02:00
|
|
|
@args = ::flatten $init_list[$i];
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-25 12:15:12 +02:00
|
|
|
my ($qualifier, $initializer);
|
|
|
|
my $identifier = shift @args;
|
2014-06-10 19:01:43 +02:00
|
|
|
|
2014-07-08 02:33:50 +02:00
|
|
|
foreach my $arg (@args) {
|
|
|
|
if ($arg =~ /initialized/) {
|
2014-07-08 05:28:51 +02:00
|
|
|
$initializer .= (length $initializer ? ' ' : '') . $arg;
|
2014-07-08 02:33:50 +02:00
|
|
|
} else {
|
2014-07-08 05:28:51 +02:00
|
|
|
$qualifier .= (length $qualifier ? ' ' : '') . $arg;
|
2014-07-08 02:33:50 +02:00
|
|
|
}
|
2014-06-08 15:51:29 +02:00
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-25 12:15:12 +02:00
|
|
|
next unless $qualifier eq $first_qualifier;
|
2014-06-14 19:54:20 +02:00
|
|
|
|
2014-06-25 12:15:12 +02:00
|
|
|
push @identifiers, $identifier;
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($initializer) {
|
2014-06-25 12:15:12 +02:00
|
|
|
push @initializers, [ $identifier, $initializer ];
|
2014-06-10 19:01:43 +02:00
|
|
|
}
|
|
|
|
|
2014-06-25 12:15:12 +02:00
|
|
|
splice @init_list, $i--, 1;
|
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} eq 'struct member') {
|
|
|
|
if ($inits > 1 and not @init_list) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$return .= ' and ';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($inits > 1) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$return .= ', ';
|
2014-06-10 19:01:43 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-03 23:33:20 +02:00
|
|
|
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 = ', ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-05 01:41:54 +02:00
|
|
|
$return .= ' as ' unless not @identifiers;
|
2014-07-03 23:33:20 +02:00
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($first_qualifier) {
|
|
|
|
if ($first_qualifier =~ /bit\-field/) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$first_qualifier = "$item{declaration_specifiers} $first_qualifier";
|
|
|
|
$item{declaration_specifiers} = '';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-10 19:01:43 +02:00
|
|
|
|
2014-08-10 07:31:29 +02:00
|
|
|
if (@identifiers == 1 and $first_qualifier !~ /^(an|a)\s+/) {
|
2014-07-08 07:24:21 +02:00
|
|
|
$return .= $first_qualifier =~ m/^[aeiou]/ ? 'an ' : 'a ';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif (@identifiers > 1 and not $typedef) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$first_qualifier =~ s/pointer/pointers/;
|
2014-06-25 14:01:06 +02:00
|
|
|
$first_qualifier =~ s/an array/arrays/;
|
2014-06-10 19:01:43 +02:00
|
|
|
}
|
2014-07-05 01:41:54 +02:00
|
|
|
$return .= "$first_qualifier";
|
2014-07-05 07:11:07 +02:00
|
|
|
$return .= " $item{declaration_specifiers}" if $item{declaration_specifiers};
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
2014-08-10 07:31:29 +02:00
|
|
|
if (@identifiers == 1 and $item{declaration_specifiers} !~ /^(an|a)\s+/) {
|
2014-07-08 07:24:21 +02:00
|
|
|
$return .= $item{declaration_specifiers} =~ m/^[aeiou]/ ? 'an ' : 'a ';
|
2014-06-10 19:01:43 +02:00
|
|
|
}
|
2014-07-03 23:33:20 +02:00
|
|
|
$return .= $item{declaration_specifiers};
|
2014-06-25 12:15:12 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
my $and = @identifiers > 1 ? ' and ' : '';
|
|
|
|
my $comma = '';
|
2014-07-01 18:21:52 +02:00
|
|
|
for (my $i = 0; $i < @identifiers; $i++) {
|
|
|
|
if ($i == @identifiers - 1) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$return .= "$and$identifiers[$i]";
|
|
|
|
} else {
|
|
|
|
$return .= "$comma$identifiers[$i]";
|
|
|
|
$comma = ', ';
|
|
|
|
}
|
|
|
|
}
|
2014-06-17 20:20:13 +02:00
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($typedef) {
|
2014-06-25 14:01:06 +02:00
|
|
|
$return .= ' each' if @identifiers > 1;
|
2014-07-04 14:18:59 +02:00
|
|
|
$return .= ' as another name for ';
|
2014-06-25 12:15:12 +02:00
|
|
|
push @typedefs, @identifiers;
|
2014-06-25 14:01:06 +02:00
|
|
|
} else {
|
2014-07-05 01:41:54 +02:00
|
|
|
$return .= ' as ' unless not @identifiers;
|
2014-06-25 12:15:12 +02:00
|
|
|
}
|
2014-06-17 20:20:13 +02:00
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($first_qualifier) {
|
2014-07-04 13:09:58 +02:00
|
|
|
if ($noreturn) {
|
|
|
|
$first_qualifier =~ s/ returning$//;
|
|
|
|
}
|
|
|
|
|
2014-08-10 07:31:29 +02:00
|
|
|
if (@identifiers == 1 and $first_qualifier !~ /^(an|a)\s+/) {
|
2014-07-08 07:24:21 +02:00
|
|
|
$return .= $first_qualifier =~ m/^[aeiou]/ ? 'an ' : 'a ';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif (@identifiers > 1 and not $typedef) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$first_qualifier =~ s/pointer/pointers/;
|
2014-06-25 14:01:06 +02:00
|
|
|
$first_qualifier =~ s/an array/arrays/;
|
2014-06-25 12:15:12 +02:00
|
|
|
}
|
|
|
|
$return .= "$first_qualifier ";
|
|
|
|
$return .= $item{declaration_specifiers};
|
|
|
|
} else {
|
2014-08-10 07:31:29 +02:00
|
|
|
if (@identifiers == 1 and $item{declaration_specifiers} !~ /^(an|a)\s+/) {
|
2014-07-08 07:24:21 +02:00
|
|
|
$return .= $item{declaration_specifiers} =~ m/^[aeiou]/ ? 'an ' : 'a ';
|
2014-06-25 12:15:12 +02:00
|
|
|
}
|
|
|
|
$return .= $item{declaration_specifiers};
|
|
|
|
}
|
2014-06-17 20:20:13 +02:00
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if (@initializers) {
|
|
|
|
if (@identifiers > 1) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$return .= ".\nInitialize ";
|
|
|
|
|
|
|
|
@initializers = sort { $a->[1] cmp $b->[1] } @initializers;
|
|
|
|
my ($and, $comma);
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
for (my $i = 0; $i < @initializers; $i++) {
|
2014-06-25 12:15:12 +02:00
|
|
|
my ($identifier, $initializer) = @{$initializers[$i]};
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($i < @initializers - 1 and $initializer eq $initializers[$i + 1]->[1]) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$return .= "$comma$identifier";
|
|
|
|
$comma = ', ';
|
|
|
|
$and = ' and ';
|
|
|
|
} else {
|
2014-07-08 05:28:51 +02:00
|
|
|
$initializer =~ s/^initialized to \^L//;
|
2014-06-25 12:15:12 +02:00
|
|
|
$return .= "$and$identifier to $initializer";
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($i < @initializers - 2) {
|
2014-06-25 12:15:12 +02:00
|
|
|
$and = $comma = ', ';
|
2014-06-17 20:20:13 +02:00
|
|
|
} else {
|
2014-06-25 12:15:12 +02:00
|
|
|
$and = ' and ';
|
2014-06-10 19:01:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-25 12:15:12 +02:00
|
|
|
} else {
|
|
|
|
$return .= " $initializers[0]->[1]";
|
2014-06-10 19:01:43 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-04 04:58:55 +02:00
|
|
|
$return =~ s/,$//;
|
2014-06-29 23:13:18 +02:00
|
|
|
$return .= ".\n" unless $arg{context} eq 'for init';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-07 10:27:10 +02:00
|
|
|
| static_assert_declaration
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
init_declarator_list:
|
2018-04-24 23:22:05 +02:00
|
|
|
<leftop: init_declarator ',' init_declarator>
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
init_declarator:
|
2014-07-05 07:11:07 +02:00
|
|
|
declarator[context => "$arg{context}|init_declarator"]
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
|
|
|
$return = $item{declarator};
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
('=' initializer)(?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $init = join('',@{$item[-1]});
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
if (length $init) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = [$item{declarator}, "initialized to ^L$init"];
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initializer:
|
2014-07-02 03:32:13 +02:00
|
|
|
designation initializer
|
|
|
|
{ $return = "$item[1] $item[2]"; }
|
2014-07-09 11:19:49 +02:00
|
|
|
| comment(?) assignment_expression[context => "$arg{context}|initializer expression"] comment(?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = $item[2];
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if (join('',@{$item[1]})) {
|
|
|
|
$return = '['.join('',@{$item[1]}).']' . $return;
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if (join('',@{$item[1]})) {
|
|
|
|
$return .= join('',@{$item[-1]});
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
| '{' comment(?) initializer_list (',' )(?) '}'
|
2018-04-24 23:22:05 +02:00
|
|
|
{ $return = '{' . $item{'initializer_list'} . '}'; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
initializer_list:
|
2018-04-24 23:22:05 +02:00
|
|
|
<leftop: initializer ',' initializer >
|
2014-07-08 02:33:50 +02:00
|
|
|
{ $return = join(', ', @{$item[1]}); }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-02 03:32:13 +02:00
|
|
|
designation:
|
|
|
|
designator_list '='
|
2014-07-03 23:33:20 +02:00
|
|
|
{ $return = $item{designator_list}; }
|
2014-07-02 03:32:13 +02:00
|
|
|
|
|
|
|
designator_list:
|
|
|
|
designator(s)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-03 23:33:20 +02:00
|
|
|
$return = join(' of ', reverse @{$item{'designator(s)'}});
|
|
|
|
$return .= ' set to';
|
2014-07-02 03:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
designator:
|
|
|
|
'[' constant_expression ']'
|
|
|
|
{
|
|
|
|
my $expression = $item{constant_expression};
|
|
|
|
if ($expression =~ /^\d+$/) {
|
|
|
|
$expression++;
|
|
|
|
my ($last_digit) = $expression =~ /(\d)$/;
|
|
|
|
if ($last_digit == 1) {
|
|
|
|
if ($expression =~ /11$/) {
|
|
|
|
$expression .= 'th';
|
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
$expression .= 'st';
|
2014-07-02 03:32:13 +02:00
|
|
|
}
|
|
|
|
} elsif ($last_digit == 2) {
|
|
|
|
$expression .= 'nd';
|
|
|
|
} elsif ($last_digit == 3) {
|
|
|
|
$expression .= 'rd';
|
|
|
|
} else {
|
|
|
|
$expression .= 'th';
|
|
|
|
}
|
|
|
|
$expression = "the $expression element";
|
|
|
|
} else {
|
2014-09-09 09:20:42 +02:00
|
|
|
$expression = "the element at location ^L$expression^L";
|
2014-07-02 03:32:13 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 23:33:20 +02:00
|
|
|
$return = $expression;
|
2014-07-02 03:32:13 +02:00
|
|
|
}
|
|
|
|
| '.' identifier
|
2014-07-03 23:33:20 +02:00
|
|
|
{ $return = "the member $item{identifier}"; }
|
2014-07-02 03:32:13 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
unary_expression:
|
2014-06-26 09:35:11 +02:00
|
|
|
postfix_expression
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = $item{postfix_expression}; }
|
|
|
|
| '++' unary_expression
|
|
|
|
{
|
2014-07-01 19:03:07 +02:00
|
|
|
if ($arg{context} =~ /for init/) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "pre-incrementing $item{unary_expression}";
|
|
|
|
} elsif ($arg{context} =~ /(conditional|expression)/) {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{unary_expression} =~ s/^the member//) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "the pre-incremented member $item{unary_expression}";
|
2014-07-03 23:33:20 +02:00
|
|
|
} elsif ($item{unary_expression} =~ s/^the element//) {
|
|
|
|
$return = "the pre-incremented element $item{unary_expression}";
|
|
|
|
}else {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "pre-incremented $item{unary_expression}";
|
|
|
|
}
|
2014-07-01 19:03:07 +02:00
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "pre-increment $item{unary_expression}";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| '--' unary_expression
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-07-01 19:03:07 +02:00
|
|
|
if ($arg{context} =~ /for init/) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "pre-decrementing $item{unary_expression}";
|
|
|
|
} elsif ($arg{context} =~ /(conditional|expression)/) {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{unary_expression} =~ s/^the member//) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "the pre-decremented member $item{unary_expression}";
|
2014-07-03 23:33:20 +02:00
|
|
|
} elsif ($item{unary_expression} =~ s/^the element//) {
|
|
|
|
$return = "the pre-decremented element $item{unary_expression}";
|
2014-07-01 18:16:40 +02:00
|
|
|
} else {
|
|
|
|
$return = "pre-decremented $item{unary_expression}";
|
|
|
|
}
|
2014-07-01 19:03:07 +02:00
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "Pre-decrement $item{unary_expression}";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-26 09:35:11 +02:00
|
|
|
| unary_operator cast_expression
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if (ref $item{unary_operator} eq 'ARRAY') {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = $item{unary_operator}->[0] . $item{cast_expression} . $item{unary_operator}->[1];
|
|
|
|
} else {
|
|
|
|
$return = $item{unary_operator} . $item{cast_expression};
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| 'sizeof' unary_expression[context => 'sizeof']
|
2014-07-08 02:33:50 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /statement$/) {
|
|
|
|
$return = "Evaluate and discard the size of ^L$item{unary_expression}";
|
|
|
|
} else {
|
|
|
|
$return = "the size of ^L$item{unary_expression}";
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| 'sizeof' '(' type_name[context => 'sizeof'] ')'
|
2014-07-08 02:33:50 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /statement$/) {
|
|
|
|
$return = "Evaluate and discard the size of the type $item{type_name}";
|
|
|
|
} else {
|
|
|
|
$return = "the size of the type $item{type_name}";
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| 'sizeof' '(' assignment_expression[context => 'sizeof'] ')'
|
2014-07-08 02:33:50 +02:00
|
|
|
{
|
|
|
|
if ($arg{context} =~ /statement$/) {
|
|
|
|
$return = "Evaluate and discard the size of the type of the expression (^L$item{assignment_expression})";
|
|
|
|
} else {
|
|
|
|
$return = "the size of the type of the expression (^L$item{assignment_expression})";
|
|
|
|
}
|
|
|
|
}
|
2014-07-07 08:45:50 +02:00
|
|
|
| Alignof '(' type_name ')'
|
|
|
|
{ $return = "the alignment of the type $item{type_name}"; }
|
2014-08-10 07:03:37 +02:00
|
|
|
| 'offsetof' '(' type_name[context => 'offsetof'] ',' identifier ')'
|
|
|
|
{
|
|
|
|
$return = "the offset, in bytes, of member $item{identifier} from the beginning of $item{type_name}";
|
|
|
|
}
|
2014-07-07 08:45:50 +02:00
|
|
|
|
|
|
|
Alignof:
|
|
|
|
'_Alignof'
|
|
|
|
| 'alignof'
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-06-16 04:31:13 +02:00
|
|
|
postfix_productions:
|
|
|
|
'(' argument_expression_list(?) ')' postfix_productions[context => 'function call'](?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-06-16 04:31:13 +02:00
|
|
|
my $postfix = $item[-1]->[0];
|
|
|
|
|
2014-06-29 23:13:18 +02:00
|
|
|
$arg{primary_expression} =~ s/^Evaluate the expression/resulting from the expression/;
|
|
|
|
|
2014-07-13 08:36:55 +02:00
|
|
|
if($arg{context} =~ /statement$/) {
|
2014-07-03 23:33:20 +02:00
|
|
|
$return = "Call the function $arg{primary_expression}";
|
2014-06-10 10:50:19 +02:00
|
|
|
} else {
|
2014-07-03 23:33:20 +02:00
|
|
|
$return = "the result of the function $arg{primary_expression}";
|
2014-06-10 10:50:19 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
# To discriminate between macros and functions.
|
|
|
|
foreach (@macros) {
|
|
|
|
if ($arg{primary_expression} eq $_) {
|
2014-06-10 10:50:19 +02:00
|
|
|
$return =~ s/Call/Insert/;
|
2018-04-24 23:22:05 +02:00
|
|
|
$return =~ s/function/macro/;
|
2014-06-10 10:50:19 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
my $arg_exp_list = join('',@{$item{'argument_expression_list(?)'}});
|
|
|
|
if (length $arg_exp_list) {
|
2014-06-10 10:50:19 +02:00
|
|
|
$return .= " with argument$arg_exp_list";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-15 05:57:27 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($postfix) {
|
2014-06-16 23:13:30 +02:00
|
|
|
$return =~ s/^(Call|Insert)/the result of/;
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "$postfix $return";
|
2014-06-15 05:57:27 +02:00
|
|
|
}
|
2014-06-16 04:31:13 +02:00
|
|
|
1;
|
2014-06-15 05:57:27 +02:00
|
|
|
}
|
2014-07-08 07:24:21 +02:00
|
|
|
| '[' expression[context => 'array address'] ']' postfix_productions[context => "$arg{context}|array address"](?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-07-08 07:24:21 +02:00
|
|
|
my $expression = $item[2];
|
2014-06-16 04:31:13 +02:00
|
|
|
my $postfix = $item[-1]->[0];
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if (length $expression) {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($expression =~ /^\d+$/) {
|
2014-06-24 07:34:54 +02:00
|
|
|
$expression++;
|
|
|
|
my ($last_digit) = $expression =~ /(\d)$/;
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($last_digit == 1) {
|
|
|
|
if ($expression =~ /11$/) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$expression .= 'th';
|
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
$expression .= 'st';
|
2014-07-01 18:16:40 +02:00
|
|
|
}
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($last_digit == 2) {
|
2014-06-24 07:34:54 +02:00
|
|
|
$expression .= 'nd';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($last_digit == 3) {
|
2014-06-24 07:34:54 +02:00
|
|
|
$expression .= 'rd';
|
2014-06-12 15:13:45 +02:00
|
|
|
} else {
|
2014-06-24 07:34:54 +02:00
|
|
|
$expression .= 'th';
|
2014-06-12 15:13:45 +02:00
|
|
|
}
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} eq 'function call') {
|
2014-06-24 10:44:28 +02:00
|
|
|
$return = "the $expression element of^L";
|
2014-06-16 04:31:13 +02:00
|
|
|
} else {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "the $expression element of^L";
|
|
|
|
$return .= " $arg{primary_expression}" if $arg{primary_expression};
|
2014-06-16 04:31:13 +02:00
|
|
|
}
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($expression =~ /^-\s*\d+$/) {
|
2014-06-24 07:34:54 +02:00
|
|
|
$expression *= -1;
|
|
|
|
my $plural = $expression == 1 ? '' : 's';
|
2015-09-08 07:20:52 +02:00
|
|
|
$return = "the element $expression element$plural backwards from where ^L$arg{primary_expression} points^L";
|
2014-06-12 15:13:45 +02:00
|
|
|
} else {
|
2014-09-09 09:20:42 +02:00
|
|
|
$return = "the element at location ^L$expression of^L";
|
2014-07-08 07:24:21 +02:00
|
|
|
$return .= " $arg{primary_expression}" if $arg{primary_expression};
|
2014-06-12 15:13:45 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($postfix) {
|
2014-06-16 04:31:13 +02:00
|
|
|
$return = "$postfix $return";
|
2014-07-03 23:33:20 +02:00
|
|
|
$return =~ s/the post-([^ ]+) the/the post-$1/g;
|
2014-06-16 04:31:13 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-01 18:16:40 +02:00
|
|
|
| '.' identifier postfix_productions[context => "$arg{context}|struct access"](?)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
my $identifier = $item[-2];
|
2014-06-16 04:31:13 +02:00
|
|
|
my $postfix = $item[-1]->[0];
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($postfix) {
|
|
|
|
if (ref $postfix eq 'ARRAY') {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "$postfix->[0] the member $identifier $postfix->[1] of";
|
|
|
|
} else {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "$postfix member $identifier of";
|
2014-07-03 23:33:20 +02:00
|
|
|
$return .= " the" unless $arg{context} =~ /array address/;
|
2014-07-01 18:16:40 +02:00
|
|
|
} else {
|
|
|
|
$postfix =~ s/ the(\^L)?$/$1/;
|
|
|
|
$return = "$postfix the member $identifier of";
|
2014-07-03 23:33:20 +02:00
|
|
|
$return .= " the" unless $arg{context} =~ /array address/;
|
2014-07-01 18:16:40 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($arg{primary_expression}) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return =~ s/ the(\^L)?$/$1/;
|
|
|
|
$return .= " ^L$arg{primary_expression}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-07-03 23:33:20 +02:00
|
|
|
if ($arg{context} =~ /array address/) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "the member $identifier of^L";
|
2014-06-24 10:44:28 +02:00
|
|
|
} else {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "the member $identifier of the^L";
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{primary_expression}) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return =~ s/ the(\^L)?$/$1/;
|
|
|
|
$return .= " $arg{primary_expression}";
|
|
|
|
}
|
2014-06-24 10:44:28 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-07-01 18:16:40 +02:00
|
|
|
1;
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
|
|
|
| '->' identifier postfix_productions[context => "$arg{context}|struct access"](?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $identifier = $item[-2];
|
2014-06-16 04:31:13 +02:00
|
|
|
my $postfix = $item[-1]->[0];
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($postfix) {
|
|
|
|
if (ref $postfix eq 'ARRAY') {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "$postfix->[0] the member $identifier $postfix->[1] of the structure pointed to by^L";
|
2014-06-24 10:44:28 +02:00
|
|
|
} else {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "$postfix member $identifier of the structure pointed to by the^L";
|
|
|
|
} else {
|
|
|
|
$postfix =~ s/ the(\^L)?$/$1/;
|
|
|
|
$return = "$postfix the member $identifier of the structure pointed to by the^L";
|
|
|
|
}
|
2014-06-24 10:44:28 +02:00
|
|
|
}
|
2014-07-01 18:16:40 +02:00
|
|
|
} else {
|
|
|
|
$return = "the member $identifier of the structure pointed to by the^L";
|
2014-06-16 04:31:13 +02:00
|
|
|
}
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{primary_expression}) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return =~ s/ the(\^L)?$/$1/;
|
|
|
|
$return .= " $arg{primary_expression}";
|
|
|
|
}
|
|
|
|
1;
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-16 04:31:13 +02:00
|
|
|
| ('++')(s)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $increment = join('',@{$item[-1]});
|
2014-06-08 08:34:55 +02:00
|
|
|
if ($increment) {
|
2014-07-03 23:33:20 +02:00
|
|
|
if ($arg{context} =~ /(struct access|array address)/) {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "the post-incremented";
|
|
|
|
} else {
|
|
|
|
$return = "post-increment";
|
|
|
|
}
|
2014-07-01 19:03:07 +02:00
|
|
|
} elsif ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['incrementing', 'by one'];
|
|
|
|
} elsif ($arg{context} =~ /(conditional|expression)/) {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return = "post-incremented $arg{primary_expression}";
|
2014-07-01 19:03:07 +02:00
|
|
|
} else {
|
|
|
|
$return = ['increment', 'by one'];
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-16 04:31:13 +02:00
|
|
|
| ('--')(s)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $increment = join('',@{$item[-1]});
|
2014-06-08 08:34:55 +02:00
|
|
|
if ($increment) {
|
2014-07-03 23:33:20 +02:00
|
|
|
if ($arg{context} =~ /(struct access|array address)/) {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
|
2014-07-01 18:16:40 +02:00
|
|
|
$return = "the post-decremented";
|
|
|
|
} else {
|
|
|
|
$return = "post-decrement";
|
|
|
|
}
|
2014-07-01 19:03:07 +02:00
|
|
|
} elsif ($arg{context} =~ /for init/) {
|
|
|
|
$return = ['decrementing', 'by one'];
|
|
|
|
} elsif ($arg{context} =~ /(conditional|expression)/) {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return = "post-decremented $arg{primary_expression}";
|
2014-07-01 19:03:07 +02:00
|
|
|
} else {
|
|
|
|
$return = ['decrement', 'by one'];
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-16 04:31:13 +02:00
|
|
|
| {""}
|
|
|
|
|
|
|
|
postfix_expression:
|
2014-07-21 09:11:11 +02:00
|
|
|
'(' type_name ')' '{' initializer_list '}' postfix_productions[context => "$arg{context}|compound literal"](?)
|
|
|
|
{
|
|
|
|
my $postfix = $item[-1]->[0];
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "A compound-literal of type $item{type_name} initialized to {$item{initializer_list}}";
|
2014-07-21 09:11:11 +02:00
|
|
|
$return = "$postfix $return" if $postfix;
|
|
|
|
}
|
|
|
|
| primary_expression postfix_productions[primary_expression => $item[1], context => $arg{context}]
|
2014-06-16 04:31:13 +02:00
|
|
|
{
|
|
|
|
my $postfix_productions = $item{'postfix_productions'};
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if (ref $postfix_productions eq 'ARRAY') {
|
2014-06-26 09:35:11 +02:00
|
|
|
$return = "$postfix_productions->[0] $item{primary_expression} $postfix_productions->[1]";
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif (length $postfix_productions) {
|
2014-06-16 04:31:13 +02:00
|
|
|
$return = $postfix_productions;
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif (length $item{primary_expression}) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = $item{primary_expression};
|
2014-06-16 04:31:13 +02:00
|
|
|
} else {
|
|
|
|
$return = undef;
|
|
|
|
}
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
postfix_suffix:
|
2014-06-25 10:19:56 +02:00
|
|
|
'[' expression ']'
|
|
|
|
| '.' identifier
|
|
|
|
| '->' identifier
|
|
|
|
| '++'
|
|
|
|
| '--'
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
argument_expression_list:
|
2014-06-16 04:31:13 +02:00
|
|
|
<leftop: assignment_expression[context => 'function argument'] ',' assignment_expression[context => 'function argument']>
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my @arg_exp_list = @{$item[1]};
|
|
|
|
my $last = '';
|
2014-06-15 05:57:27 +02:00
|
|
|
if (@arg_exp_list > 2) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$last = pop @arg_exp_list;
|
2016-02-21 10:41:47 +01:00
|
|
|
$return = 's ' . join(', ^L', @arg_exp_list) . " and ^L$last";
|
2018-04-24 23:22:05 +02:00
|
|
|
} elsif (@arg_exp_list == 2 ) {
|
|
|
|
$return = "s ^L$arg_exp_list[0] and ^L$arg_exp_list[1]";
|
2014-06-15 05:57:27 +02:00
|
|
|
} else {
|
2014-07-10 14:35:33 +02:00
|
|
|
if (length $arg_exp_list[0]) {
|
2014-07-10 14:24:29 +02:00
|
|
|
$return = " ^L$arg_exp_list[0]";
|
2014-06-15 05:57:27 +02:00
|
|
|
} else {
|
|
|
|
$return = '';
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-15 05:57:27 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
narrow_closure:
|
2014-06-15 05:57:27 +02:00
|
|
|
';' | ',' | '->'
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
primary_expression:
|
2014-07-01 19:03:07 +02:00
|
|
|
'(' expression[context => "$arg{context}|expression"] ')' (...narrow_closure)(?)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
my $expression = $item{expression} ;
|
|
|
|
my $repeats = 1;
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($expression =~ /^The expression (\(+)/) {
|
|
|
|
$repeats = (length $1) + 1;
|
2014-06-23 10:29:08 +02:00
|
|
|
$expression =~ s/^The expression \(+//;
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-06-15 02:46:49 +02:00
|
|
|
|
|
|
|
$expression .= ')';
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} =~ /statement$/) {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = "Evaluate the expression ";
|
|
|
|
} else {
|
2014-09-09 09:20:42 +02:00
|
|
|
#$return = "The result of the expression ";
|
2014-06-23 10:29:08 +02:00
|
|
|
}
|
2014-06-15 02:46:49 +02:00
|
|
|
$return .= '(' x $repeats;
|
2014-06-26 09:35:11 +02:00
|
|
|
$return .= "^L$expression";
|
2014-06-15 02:46:49 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
| constant
|
2018-04-24 23:22:05 +02:00
|
|
|
| string
|
2014-06-08 08:34:55 +02:00
|
|
|
| identifier
|
2014-07-21 09:11:11 +02:00
|
|
|
| generic_selection
|
2014-06-16 04:31:13 +02:00
|
|
|
| {} # nothing
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2014-07-21 09:11:11 +02:00
|
|
|
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>
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-21 09:11:11 +02:00
|
|
|
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"; }
|
|
|
|
|
2014-07-06 06:47:07 +02:00
|
|
|
Alignas:
|
|
|
|
'_Alignas'
|
|
|
|
| 'alignas'
|
|
|
|
|
|
|
|
alignment_specifier:
|
|
|
|
Alignas '(' type_name ')'
|
|
|
|
{
|
|
|
|
$return = "with alignment of the type $item{type_name}";
|
|
|
|
}
|
|
|
|
| Alignas '(' constant_expression ')'
|
|
|
|
{
|
|
|
|
my $plural = $item{constant_expression} != 1 ? 's' : '';
|
|
|
|
$return = "with alignment of $item{constant_expression} byte$plural between objects";
|
|
|
|
}
|
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
declarator:
|
2014-06-20 09:43:06 +02:00
|
|
|
direct_declarator(s)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-06-20 09:43:06 +02:00
|
|
|
my @direct_declarator = @{$item{'direct_declarator(s)'}};
|
2014-07-01 18:21:52 +02:00
|
|
|
if (@direct_declarator == 1) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = $direct_declarator[0];
|
2014-06-20 09:43:06 +02:00
|
|
|
} else {
|
2015-09-08 07:20:52 +02:00
|
|
|
$return = $item{'direct_declarator(s)'};
|
2014-06-20 09:43:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| pointer direct_declarator(s)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-06-20 09:43:06 +02:00
|
|
|
push @{$item{'direct_declarator(s)'}}, $item{pointer};
|
|
|
|
$return = $item{'direct_declarator(s)'};
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
direct_declarator:
|
2014-06-18 01:33:34 +02:00
|
|
|
identifier ':' constant
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-06-18 01:33:34 +02:00
|
|
|
my $bits = $item{constant} == 1 ? "$item{constant} bit" : "$item{constant} bits";
|
2014-06-22 06:50:21 +02:00
|
|
|
$return = [$item{identifier}, "bit-field of $bits"];
|
2014-06-18 01:33:34 +02:00
|
|
|
}
|
|
|
|
| identifier[context => 'direct_declarator'] array_declarator(s?)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if (@{$item{'array_declarator(s?)'}}) {
|
2014-07-02 22:55:50 +02:00
|
|
|
$return = [$item{identifier}, join(' ', @{$item{'array_declarator(s?)'}})];
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return = $item{identifier};
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
| '(' declarator ')' array_declarator(s)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-02 22:55:50 +02:00
|
|
|
push @{$item{declarator}}, join(' ', @{$item{'array_declarator(s)'}});
|
2014-06-20 09:43:06 +02:00
|
|
|
$return = $item{declarator};
|
|
|
|
}
|
|
|
|
| '(' parameter_type_list ')'
|
|
|
|
{ $return = "function taking $item{parameter_type_list} and returning"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
| '(' declarator array_declarator(s) ')'
|
2014-07-02 22:55:50 +02:00
|
|
|
{ $return = $item{'declarator'} . join(' ', @{$item{'array_declarator(s)'}}) }
|
2018-04-24 23:22:05 +02:00
|
|
|
| '(' declarator ')'
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = $item{declarator}; }
|
|
|
|
|
2014-07-02 22:55:50 +02:00
|
|
|
array_qualifiers:
|
|
|
|
type_qualifier_list array_qualifiers(?)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-02 22:55:50 +02:00
|
|
|
$return = $item{'type_qualifier_list'};
|
|
|
|
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
|
|
|
|
$return .= " $qualifiers" if $qualifiers;
|
|
|
|
}
|
|
|
|
| 'static' array_qualifiers(?)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-07-02 22:55:50 +02:00
|
|
|
$return = $item[1];
|
|
|
|
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
|
|
|
|
$return .= " $qualifiers" if $qualifiers;
|
|
|
|
}
|
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
array_declarator:
|
2014-07-02 22:55:50 +02:00
|
|
|
'[' array_qualifiers(?) assignment_expression(?) ']'
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-07-02 22:55:50 +02:00
|
|
|
my $size;
|
|
|
|
if (@{$item{'assignment_expression(?)'}}) {
|
|
|
|
$size = join('', @{$item{'assignment_expression(?)'}});
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($size =~ /^(unsigned|long)*\s*1$/) {
|
2014-07-02 22:55:50 +02:00
|
|
|
$size = "$size element";
|
2014-06-18 01:12:02 +02:00
|
|
|
} else {
|
2014-07-02 22:55:50 +02:00
|
|
|
$size = "$size elements";
|
2014-06-18 01:12:02 +02:00
|
|
|
}
|
2014-07-02 22:55:50 +02:00
|
|
|
} else {
|
2014-07-05 07:11:07 +02:00
|
|
|
if ($arg{context} =~ /struct member/) {
|
|
|
|
$size = 'flexible length';
|
|
|
|
} else {
|
|
|
|
$size = 'unspecified length';
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-07-02 22:55:50 +02:00
|
|
|
|
|
|
|
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
|
|
|
|
|
|
|
|
if ($qualifiers) {
|
|
|
|
if($qualifiers =~ s/static//g) {
|
2014-07-04 13:09:58 +02:00
|
|
|
$qualifiers = join(' ', split(' ', $qualifiers));
|
2014-07-02 22:55:50 +02:00
|
|
|
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";
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
2014-07-02 22:55:50 +02:00
|
|
|
$return = "an array of $size of";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-02 22:55:50 +02:00
|
|
|
| '[' '*' ']'
|
|
|
|
{ $return = 'an array of variable length of unspecified size of'; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
identifier_list:
|
|
|
|
(identifier ',')(s?) identifier
|
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my @identifier_list = @{$item[1]};
|
2014-06-08 08:34:55 +02:00
|
|
|
if ($#identifier_list > 1) {
|
2016-02-21 10:41:47 +01:00
|
|
|
$return = join(', ', @identifier_list) . ' and ' . $item{identifier};
|
2018-04-24 23:22:05 +02:00
|
|
|
} elsif ($#identifier_list == 1) {
|
|
|
|
$return = $identifier_list[1] . ' and ' . $item{identifier};
|
|
|
|
} else {
|
|
|
|
$return = $item{identifier};
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parameter_type_list:
|
2014-06-20 09:43:06 +02:00
|
|
|
parameter_list
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
parameter_list:
|
|
|
|
<leftop: parameter_declaration ',' parameter_declaration>
|
|
|
|
{
|
2014-06-20 09:43:06 +02:00
|
|
|
my @parameter_list = @{$item[1]};
|
|
|
|
my $comma = '';
|
2014-07-01 18:21:52 +02:00
|
|
|
for (my $i = 0; $i < @parameter_list; $i++) {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return .= $comma;
|
2014-07-01 18:21:52 +02:00
|
|
|
if (ref $parameter_list[$i] eq 'ARRAY') {
|
2014-06-21 01:16:04 +02:00
|
|
|
my @list = ::flatten @{$parameter_list[$i]};
|
2014-07-01 18:21:52 +02:00
|
|
|
if (@list == 0) {
|
2014-07-04 10:20:01 +02:00
|
|
|
$return = "no arguments";
|
2014-06-20 09:43:06 +02:00
|
|
|
} elsif (@list == 1) {
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($list[0] eq 'void') {
|
2014-07-04 10:20:01 +02:00
|
|
|
$return = "no arguments";
|
2014-06-22 04:28:28 +02:00
|
|
|
} else {
|
|
|
|
$return .= $list[0];
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
} else {
|
2014-06-21 03:40:55 +02:00
|
|
|
push @list, shift @list;
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($list[0] =~ /^`.*`$/) {
|
2014-06-22 04:28:28 +02:00
|
|
|
my $identifier = shift @list;
|
|
|
|
$return .= "$identifier as ";
|
|
|
|
$return .= join(' ', @list);
|
|
|
|
} else {
|
|
|
|
$return .= join(' ', @list);
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-06-20 09:43:06 +02:00
|
|
|
$return .= $parameter_list[$i];
|
|
|
|
}
|
2014-06-21 01:16:04 +02:00
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($i == $#parameter_list - 1) {
|
2014-06-20 09:43:06 +02:00
|
|
|
$comma = ' and ';
|
|
|
|
} else {
|
|
|
|
$comma = ', ';
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parameter_declaration:
|
2018-04-24 23:22:05 +02:00
|
|
|
declaration_specifiers declarator
|
2014-06-20 09:43:06 +02:00
|
|
|
{ $return = [$item{declaration_specifiers}, $item{declarator}]; }
|
|
|
|
| '...'
|
2014-07-04 10:20:01 +02:00
|
|
|
{ $return = "variadic arguments"; }
|
2018-04-24 23:22:05 +02:00
|
|
|
| declaration_specifiers abstract_declarator(?)
|
2014-06-22 04:28:28 +02:00
|
|
|
{ $return = [$item{declaration_specifiers}, $item{'abstract_declarator(?)'}]; }
|
2014-06-08 08:34:55 +02:00
|
|
|
| ''
|
2014-07-04 10:20:01 +02:00
|
|
|
{ $return = "unspecified arguments"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
abstract_declarator:
|
|
|
|
pointer(?) direct_abstract_declarator(s)
|
|
|
|
{
|
2014-07-05 07:11:07 +02:00
|
|
|
my $pointer = join(' ', @{$item{'pointer(?)'}});
|
|
|
|
$return = "$pointer " if $pointer;
|
|
|
|
$return .= join(' ', @{$item{'direct_abstract_declarator(s)'}});
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| pointer
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
direct_abstract_declarator:
|
|
|
|
'(' abstract_declarator ')'
|
2014-06-22 04:28:28 +02:00
|
|
|
{ $return = $item{abstract_declarator}; }
|
2014-06-08 08:34:55 +02:00
|
|
|
| '[' ']'
|
2014-07-02 22:55:50 +02:00
|
|
|
{ $return = 'array of unspecified length of'; }
|
|
|
|
| '[' '*' ']'
|
|
|
|
{ $return = 'array of variable length of unspecified size of'; }
|
|
|
|
| '[' array_qualifiers(?) assignment_expression(?) ']'
|
|
|
|
{
|
|
|
|
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 {
|
|
|
|
$size = 'unspecified length';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $qualifiers = join('', @{$item{'array_qualifiers(?)'}});
|
|
|
|
|
|
|
|
if ($qualifiers) {
|
|
|
|
if($qualifiers =~ s/static//g) {
|
2014-07-04 13:09:58 +02:00
|
|
|
$qualifiers = join(' ', split(' ', $qualifiers));
|
2014-07-02 22:55:50 +02:00
|
|
|
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";
|
|
|
|
}
|
2014-06-22 04:28:28 +02:00
|
|
|
} else {
|
2014-07-02 22:55:50 +02:00
|
|
|
$return = "an array of $size of";
|
2014-06-22 04:28:28 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
| DAD '[' ']'
|
2014-07-02 22:55:50 +02:00
|
|
|
| DAD '[' array_qualifiers(?) assignment_expression(?) ']'
|
2014-06-08 08:34:55 +02:00
|
|
|
| '(' ')'
|
2014-07-04 10:20:01 +02:00
|
|
|
{ $return = 'function taking unspecified arguments and returning'; }
|
2014-06-08 08:34:55 +02:00
|
|
|
| '(' parameter_type_list ')'
|
2014-06-22 04:28:28 +02:00
|
|
|
{ $return = "function taking $item{parameter_type_list} and returning"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
| DAD '(' ')'
|
|
|
|
| DAD '(' parameter_type_list ')'
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
DAD: # macro for direct_abstract_declarator
|
2014-06-08 08:34:55 +02:00
|
|
|
( '(' abstract_declarator ')' )(s?)
|
|
|
|
( '[' ']' )(s?)
|
2014-07-02 22:55:50 +02:00
|
|
|
( '[' assignment_expression ']' )(s?)
|
2014-06-08 08:34:55 +02:00
|
|
|
( '(' ')' )(s?)
|
|
|
|
( '(' parameter_type_list ')' )(s?)
|
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
identifier:
|
2014-06-08 08:34:55 +02:00
|
|
|
...!reserved identifier_word
|
2014-06-25 10:19:56 +02:00
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if (not grep { $_ eq $item{identifier_word} } @identifiers) {
|
2014-06-25 10:19:56 +02:00
|
|
|
push @identifiers, $item{identifier_word};
|
|
|
|
}
|
|
|
|
$return = $item{identifier_word};
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
pointer:
|
2018-04-24 23:22:05 +02:00
|
|
|
'*' type_qualifier_list(s) pointer(?)
|
|
|
|
{
|
2014-06-18 02:14:16 +02:00
|
|
|
$return = join('', @{$item{'pointer(?)'}}) if @{$item{'pointer(?)'}};
|
2014-06-22 04:28:28 +02:00
|
|
|
$return .= ' ' . join('', @{$item{'type_qualifier_list(s)'}}) . ' pointer to';
|
2014-06-07 15:00:07 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| '*' pointer(?)
|
|
|
|
{
|
2014-06-23 10:29:08 +02:00
|
|
|
my $pointers = join('', @{$item{'pointer(?)'}});
|
|
|
|
$return .= "$pointers " if $pointers;
|
2018-04-24 23:22:05 +02:00
|
|
|
$return .= 'pointer to';
|
|
|
|
}
|
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
type_qualifier_list:
|
2018-04-24 23:22:05 +02:00
|
|
|
type_qualifier(s)
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = join(' ', @{$item{'type_qualifier(s)'}}); }
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-07-04 13:09:58 +02:00
|
|
|
function_specifier:
|
|
|
|
'inline'
|
|
|
|
| '_Noreturn'
|
|
|
|
| 'noreturn'
|
|
|
|
{ $return = '_Noreturn'; }
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
declaration_specifiers:
|
2014-07-06 06:47:07 +02:00
|
|
|
comment[context => 'declaration_specifiers'] declaration_specifiers(s)
|
|
|
|
{ $return = "$item{comment} " . join(' ', @{$item{'declaration_specifiers(s)'}}); }
|
|
|
|
| type_specifier ...identifier
|
|
|
|
{ $return = $item{type_specifier}; }
|
2018-04-24 23:22:05 +02:00
|
|
|
| storage_class_specifier declaration_specifiers(?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
|
|
|
my $decl_spec = join(' ', @{$item{'declaration_specifiers(?)'}});
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($item{storage_class_specifier} =~ m/^with/) {
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($decl_spec) { $return .= "$decl_spec "; }
|
2014-06-23 10:29:08 +02:00
|
|
|
$return .= $item{storage_class_specifier};
|
|
|
|
} else {
|
|
|
|
$return .= $item{storage_class_specifier};
|
|
|
|
if ($decl_spec) { $return .= " $decl_spec"; }
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| type_specifier(s) declaration_specifiers(?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
|
|
|
my $decl_spec = join(' ', @{$item{'declaration_specifiers(?)'}});
|
2014-07-06 06:47:07 +02:00
|
|
|
if ($decl_spec =~ s/\s*(with.*)$//) {
|
|
|
|
push @{$item{'type_specifier(s)'}}, $1;
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-19 00:31:56 +02:00
|
|
|
$return .= "$decl_spec " if $decl_spec;
|
2014-06-27 13:38:54 +02:00
|
|
|
$return .= join(' ', @{$item{'type_specifier(s)'}});
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| type_qualifier declaration_specifiers(?)
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2014-06-19 00:31:56 +02:00
|
|
|
my $decl_spec = join(' ',@{$item{'declaration_specifiers(?)'}});
|
2014-07-06 06:47:07 +02:00
|
|
|
$return = $item{type_qualifier};
|
2014-06-19 00:31:56 +02:00
|
|
|
$return .= " $decl_spec" if $decl_spec;
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2014-07-06 06:47:07 +02:00
|
|
|
| function_specifier declaration_specifiers(?)
|
2014-07-04 13:09:58 +02:00
|
|
|
{
|
|
|
|
my $decl_spec = join(' ',@{$item{'declaration_specifiers(?)'}});
|
2014-07-06 06:47:07 +02:00
|
|
|
$return = $item{function_specifier};
|
2014-07-04 13:09:58 +02:00
|
|
|
$return .= " $decl_spec" if $decl_spec;
|
|
|
|
}
|
2014-07-06 06:47:07 +02:00
|
|
|
| alignment_specifier(s) declaration_specifiers(?)
|
|
|
|
{
|
|
|
|
my $decl_spec = join(' ',@{$item{'declaration_specifiers(?)'}});
|
|
|
|
if ($decl_spec) {
|
|
|
|
$return = "$decl_spec ";
|
|
|
|
$return .= 'or ' if $decl_spec =~ /with alignment/;
|
|
|
|
}
|
|
|
|
$return .= join(' or ', @{$item{'alignment_specifier(s)'}});
|
|
|
|
$return .= ', whichever is more strict' if $return =~ /or with alignment/;
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
storage_class_specifier:
|
|
|
|
'auto'
|
2014-06-23 10:29:08 +02:00
|
|
|
{ $return = "with automatic storage-duration"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
| 'extern'
|
2014-06-23 10:29:08 +02:00
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} eq 'function definition') {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = "with external linkage";
|
|
|
|
} else {
|
|
|
|
$return = "with external linkage, possibly defined elsewhere";
|
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| 'static'
|
|
|
|
{
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($arg{context} eq 'function definition') {
|
2014-06-23 10:29:08 +02:00
|
|
|
$return = "with internal linkage";
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($arg{context} eq 'function definition statement') {
|
2014-06-23 13:10:40 +02:00
|
|
|
$return = "with life-time duration";
|
2014-06-23 10:29:08 +02:00
|
|
|
} else {
|
|
|
|
$return = "with internal linkage and life-time duration";
|
|
|
|
}
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
| 'register'
|
2014-06-23 10:29:08 +02:00
|
|
|
{ $return = "with a suggestion to be as fast as possible"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
| 'typedef'
|
|
|
|
{ $return = 'type definition of'; }
|
|
|
|
|
|
|
|
type_qualifier:
|
|
|
|
'const'
|
2018-04-24 23:22:05 +02:00
|
|
|
| 'volatile'
|
2014-07-07 11:15:46 +02:00
|
|
|
| 'restrict'
|
|
|
|
| '_Atomic'
|
|
|
|
{ $return = 'atomic'; }
|
|
|
|
|
|
|
|
atomic_type_specifier:
|
|
|
|
'_Atomic' '(' type_name ')'
|
|
|
|
{ $return = "atomic $item{type_name}"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
type_specifier:
|
2014-07-08 05:28:51 +02:00
|
|
|
<skip:''> /\s*/
|
2015-05-26 02:25:00 +02:00
|
|
|
('void'
|
2014-07-08 05:28:51 +02:00
|
|
|
| 'signed' | 'unsigned'
|
|
|
|
| 'FILE' | 'fpos_t'
|
|
|
|
| 'bool' | '_Bool'
|
|
|
|
| '_Complex' | '_Imaginary'
|
|
|
|
| 'int_fast8_t' | 'int_fast16_t' | 'int_fast24_t' | 'int_fast32_t' | 'int_fast64_t' | 'int_fast128_t'
|
|
|
|
| 'uint_fast8_t' | 'uint_fast16_t' | 'uint_fast24_t' | 'uint_fast32_t' | 'uint_fast64_t' | 'uint_fast128_t'
|
|
|
|
| 'int_least8_t' | 'int_least16_t' | 'int_least24_t' | 'int_least32_t' | 'int_least64_t' | 'int_least128_t'
|
|
|
|
| 'uint_least8_t' | 'uint_least16_t' | 'uint_least24_t' | 'uint_least32_t' | 'uint_least64_t' | 'uint_least128_t'
|
|
|
|
| 'int8_t' | 'int16_t' | 'int24_t' | 'int32_t' | 'int64_t' | 'int128_t'
|
|
|
|
| 'uint8_t' | 'uint16_t' | 'uint24_t' | 'uint32_t' | 'uint64_t' | 'uint128_t'
|
|
|
|
| 'intmax_t' | 'uintmax_t'
|
|
|
|
| 'intptr_t' | 'uintptr_t' | 'ptrdiff_t'
|
|
|
|
| 'sig_atomic_t'
|
|
|
|
| 'wint_t' | 'wchar_t'
|
|
|
|
| 'size_t' | 'rsize_t' | 'max_align_t'
|
|
|
|
| 'mbstate_t' | 'char16_t' | 'char32_t'
|
|
|
|
| 'fenv_t' | 'fexcept_t'
|
|
|
|
| 'div_t' | 'ldiv_t' | 'lldiv_t' | 'imaxdiv_t'
|
|
|
|
| 'cnd_t' | 'thrd_t' | 'tss_t' | 'mtx_t' | 'tss_dtor_t' | 'thrd_start_t' | 'once_flag'
|
|
|
|
| 'clock_t' | 'time_t'
|
|
|
|
| <skip:'[\s]*'> struct_or_union_specifier
|
|
|
|
| <skip:'[\s]*'> enum_specifier
|
2015-05-26 02:25:00 +02:00
|
|
|
| <skip:'[\s]*'> atomic_type_specifier | typedef_name
|
|
|
|
| 'double' | 'float' | 'char' | 'short' | 'int' | 'long'
|
2014-07-08 05:28:51 +02:00
|
|
|
) .../\W/
|
2014-07-02 18:36:22 +02:00
|
|
|
{ $return = $item[3]; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
typedef_name:
|
|
|
|
identifier
|
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
my $answer = 0;
|
|
|
|
foreach (@typedefs) {
|
2014-06-08 08:34:55 +02:00
|
|
|
if ($item{identifier} eq $_) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$answer = 1;
|
2014-07-08 07:24:21 +02:00
|
|
|
$return = ($item{identifier} =~ m/^`[aeiou]/ ? 'an ' : 'a ') . $item{identifier};
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
if (!$answer) { undef $answer; }
|
|
|
|
$answer;
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct_or_union_specifier:
|
2018-04-24 23:22:05 +02:00
|
|
|
comment(?) struct_or_union identifier(?) '{' struct_declaration_list '}'
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
|
|
|
my $identifier = join('',@{$item{'identifier(?)'}});
|
2014-06-08 15:51:29 +02:00
|
|
|
$return = join('',@{$item{'comment(?)'}}) . $item{struct_or_union};
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($identifier) { $return .= " tagged $identifier"; }
|
2014-07-08 03:15:51 +02:00
|
|
|
my $plural = $item{struct_declaration_list} =~ / and (?!returning)/ ? 's' : '';
|
2014-07-04 04:58:55 +02:00
|
|
|
$return .= ", with member$plural $item{struct_declaration_list},";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
| struct_or_union identifier
|
|
|
|
{
|
2014-08-10 07:31:29 +02:00
|
|
|
$item{struct_or_union} =~ s/^(an|a)\s+//;
|
2014-07-08 07:24:21 +02:00
|
|
|
$return = $item{identifier} =~ m/^`[aeiou]/ ? 'an' : 'a';
|
2014-06-16 23:13:30 +02:00
|
|
|
$return .= " $item{identifier} $item{struct_or_union}";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct_declaration_list:
|
|
|
|
struct_declaration(s)
|
|
|
|
{
|
|
|
|
my $finaldec;
|
2018-04-24 23:22:05 +02:00
|
|
|
my @declarations = @{$item{'struct_declaration(s)'}};
|
|
|
|
if ($#declarations > 1) {
|
|
|
|
$finaldec = pop @declarations;
|
2016-02-21 10:41:47 +01:00
|
|
|
$return = join(', ', @declarations ) . ' and ' . $finaldec;
|
2018-04-24 23:22:05 +02:00
|
|
|
} elsif ($#declarations == 1) {
|
2014-06-08 08:34:55 +02:00
|
|
|
$return = join(' and ', @declarations);
|
2018-04-24 23:22:05 +02:00
|
|
|
} else {
|
|
|
|
$return = $declarations[0];
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
struct_declaration:
|
2014-06-18 01:33:34 +02:00
|
|
|
comment(s?) declaration[context => 'struct member'] comment(s?)
|
2014-06-17 20:20:13 +02:00
|
|
|
{ $return = join('', @{$item[1]}) . $item{declaration} . join('', @{$item[-1]}); }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
type_name:
|
2014-06-23 10:29:08 +02:00
|
|
|
specifier_qualifier_list abstract_declarator(?)
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
2014-06-23 10:29:08 +02:00
|
|
|
my $abstract_declarator = join('',@{$item{'abstract_declarator(?)'}});
|
|
|
|
$return = "$abstract_declarator " if $abstract_declarator;
|
|
|
|
$return .= $item{specifier_qualifier_list};
|
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
specifier_qualifier_list:
|
2018-04-24 23:22:05 +02:00
|
|
|
type_specifier specifier_qualifier_list(?)
|
|
|
|
{
|
2014-06-12 14:23:16 +02:00
|
|
|
$return = $item{type_specifier};
|
|
|
|
$return .= ' ' . join('', @{$item{'specifier_qualifier_list(?)'}}) if @{$item{'specifier_qualifier_list(?)'}};
|
2018-01-18 02:15:05 +01:00
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
| type_qualifier specifier_qualifier_list(?)
|
|
|
|
{
|
2018-01-18 02:15:05 +01:00
|
|
|
$return = $item{type_qualifier};
|
|
|
|
$return .= ' ' . join('', @{$item{'specifier_qualifier_list(?)'}}) if @{$item{'specifier_qualifier_list(?)'}};
|
2014-06-12 14:23:16 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
struct_or_union:
|
2018-04-24 23:22:05 +02:00
|
|
|
comment(?) ('struct'
|
2014-06-08 08:34:55 +02:00
|
|
|
{ $return = 'a structure'; }
|
2014-06-08 15:51:29 +02:00
|
|
|
| 'union'
|
|
|
|
{ $return = 'an union'; }
|
2018-04-24 23:22:05 +02:00
|
|
|
) comment(?)
|
|
|
|
{
|
|
|
|
shift @item;
|
|
|
|
foreach (@item) {
|
|
|
|
if (ref($_)) {
|
|
|
|
$return .= join('',@{$_});
|
|
|
|
} else {
|
|
|
|
$return .= $_;
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum_specifier:
|
2018-04-24 23:22:05 +02:00
|
|
|
'enum' identifier(?) '{' enumerator_list '}'
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
$return .= 'an enumeration';
|
2014-06-08 08:34:55 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
if (@{$item{'identifier(?)'}}){
|
2014-06-09 12:18:26 +02:00
|
|
|
$return .= ' of ' . join('',@{$item{'identifier(?)'}});
|
|
|
|
}
|
|
|
|
|
2014-06-09 12:00:13 +02:00
|
|
|
my @enumerator_list = @{$item{enumerator_list}};
|
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if (@enumerator_list == 1) {
|
2014-06-09 12:18:26 +02:00
|
|
|
$return .= " comprising $enumerator_list[0]";
|
2014-06-09 12:00:13 +02:00
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
my $last = pop @enumerator_list;
|
2016-02-21 10:41:47 +01:00
|
|
|
$return .= ' comprising ' . join(', ', @enumerator_list) . " and $last";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-06-09 12:00:13 +02:00
|
|
|
| 'enum' identifier
|
2014-06-09 12:18:26 +02:00
|
|
|
{ $return = "an enumeration of type $item{identifier}"; }
|
2014-06-09 12:00:13 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
enumerator_list:
|
2014-06-09 12:00:13 +02:00
|
|
|
<leftop:enumerator ',' enumerator>
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
enumerator:
|
|
|
|
identifier ( '=' constant_expression )(?)
|
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = $item[1];
|
|
|
|
if (@{$item[-1]}) {
|
|
|
|
$return .= ' marking ^L' . join('', @{$item[-1]});
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
comment:
|
2018-04-24 23:22:05 +02:00
|
|
|
comment_c
|
2014-06-08 08:34:55 +02:00
|
|
|
| comment_cxx
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
comment_c:
|
2014-06-11 10:29:58 +02:00
|
|
|
m{/\*[^*]*\*+([^/*][^*]*\*+)*/}s
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
|
|
|
$return = $item[1];
|
|
|
|
$return =~ s|^/\*+\s*||;
|
|
|
|
$return =~ s|\s*\*+/$||;
|
|
|
|
$return =~ s/"/\\"/g;
|
2014-07-06 06:47:07 +02:00
|
|
|
if ($arg{context} =~ /statement/) {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "\nA comment: \"$return\".\n";
|
2014-07-06 06:47:07 +02:00
|
|
|
} else {
|
2018-04-24 23:22:05 +02:00
|
|
|
$return = "(a comment: \"$return\")";
|
2014-07-06 06:47:07 +02:00
|
|
|
}
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
comment_cxx:
|
|
|
|
m{//(.*?)\n}
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
$return = $item[1];
|
2014-06-08 08:34:55 +02:00
|
|
|
$return =~ s|^//\s*||;
|
|
|
|
$return =~ s/\n*$//;
|
2014-06-11 10:54:12 +02:00
|
|
|
$return =~ s/"/\\"/g;
|
2014-07-21 23:27:22 +02:00
|
|
|
$return = "\nA quick comment: \"$return\".\n";
|
2014-06-08 08:34:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
constant:
|
2014-06-16 23:13:30 +02:00
|
|
|
/-?[0-9]*\.[0-9]*[lf]{0,2}/i
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
if ($item[1] =~ s/f$//i) {
|
2015-09-08 07:20:52 +02:00
|
|
|
$return = "the floating point constant $item[1]";
|
2014-06-16 23:13:30 +02:00
|
|
|
} elsif ($item[1] =~ s/l$//i) {
|
|
|
|
$return = "long double $item[1]";
|
|
|
|
} else {
|
2014-06-07 15:00:07 +02:00
|
|
|
$return = $item[1];
|
|
|
|
}
|
2014-06-20 11:12:56 +02:00
|
|
|
$return .= '0' if $return =~ /\.$/;
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-20 11:12:56 +02:00
|
|
|
| /0x[0-9a-f]+[lu]{0,3}/i
|
2018-04-24 23:22:05 +02:00
|
|
|
{
|
|
|
|
$return .= 'unsigned ' if $item[1] =~ s/[Uu]//;
|
|
|
|
$return .= 'long ' while $item[1] =~ s/[Ll]//;
|
2015-09-08 07:20:52 +02:00
|
|
|
$return = "the $return" . "hexadecimal constant $item[1]";
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2014-06-20 11:12:56 +02:00
|
|
|
| /0\d+[lu]{0,3}/i
|
2014-06-16 23:13:30 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
$return .= 'unsigned ' if $item[1] =~ s/[Uu]//;
|
|
|
|
$return .= 'long ' while $item[1] =~ s/[Ll]//;
|
2015-09-08 07:20:52 +02:00
|
|
|
$return = "the $return" . "octal constant $item[1]";
|
2014-06-16 23:13:30 +02:00
|
|
|
}
|
2014-06-20 11:12:56 +02:00
|
|
|
| /-?[0-9]+[lu]{0,3}/i # integer constant
|
2014-06-08 08:34:55 +02:00
|
|
|
{
|
2018-04-24 23:22:05 +02:00
|
|
|
$return .= "unsigned " if $item[-1] =~ s/[Uu]//;
|
|
|
|
$return .= "long " while $item[-1] =~ s/[Ll]//;
|
2014-06-20 11:12:56 +02:00
|
|
|
$return .= $item[-1];
|
2018-04-24 23:22:05 +02:00
|
|
|
}
|
2015-02-14 06:34:02 +01:00
|
|
|
| /[LuU]?(?:\'(?:\\\'|(?!\').)*\')/ # character constant
|
2014-06-10 10:50:19 +02:00
|
|
|
{
|
|
|
|
my $constant = $item[1];
|
2015-02-14 06:34:02 +01:00
|
|
|
my $modifier = "";
|
|
|
|
|
|
|
|
$modifier = 'wide character ' if $constant =~ s/^L//;
|
|
|
|
$modifier = '16-bit character ' if $constant =~ s/^u//;
|
|
|
|
$modifier = '32-bit character ' if $constant =~ s/^U//;
|
2014-06-10 10:50:19 +02:00
|
|
|
|
2014-07-01 18:21:52 +02:00
|
|
|
if ($constant eq q('\n')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'newline';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($constant eq q('\f')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'form-feed character';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($constant eq q('\t')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'tab';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($constant eq q('\v')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'vertical tab';
|
2016-02-21 10:41:47 +01:00
|
|
|
} elsif ($constant eq q('\a')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = 'an alert character' if not length $modifier;
|
|
|
|
$return = "a $modifier" . 'alert character' if length $modifier;
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($constant eq q('\r')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'carriage-return';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($constant eq q('\b')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'backspace character';
|
2014-07-01 18:21:52 +02:00
|
|
|
} elsif ($constant eq q('\'')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'single-quote';
|
2014-07-16 15:36:40 +02:00
|
|
|
} elsif ($constant eq q(' ')) {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = "a $modifier" . 'space';
|
2014-06-10 10:50:19 +02:00
|
|
|
} else {
|
2015-02-14 06:34:02 +01:00
|
|
|
$return = $constant if not length $modifier;
|
|
|
|
$return = "a $modifier$constant" if length $modifier;
|
2014-06-10 10:50:19 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-24 23:22:05 +02:00
|
|
|
|
2014-06-08 08:34:55 +02:00
|
|
|
identifier_word:
|
|
|
|
/[a-z_\$][a-z0-9_]*/i
|
2014-06-08 15:51:29 +02:00
|
|
|
{ $return = "`$item[-1]`"; }
|
2014-06-08 08:34:55 +02:00
|
|
|
|
|
|
|
string:
|
2015-02-14 06:34:02 +01:00
|
|
|
(/(u8|u|U|L)?(?:\"(?:\\\"|(?!\").)*\")/)(s)
|
2014-07-11 13:30:05 +02:00
|
|
|
{
|
2015-02-14 06:34:02 +01:00
|
|
|
my $final_string = "";
|
|
|
|
foreach my $string (@{$item[-1]}) {
|
2015-02-23 08:58:03 +01:00
|
|
|
my $modifier = "";
|
|
|
|
$modifier = 'an UTF-8 string ' if $string =~ s/^u8//;
|
|
|
|
$modifier = 'a wide character string ' if $string =~ s/^L//;
|
|
|
|
$modifier = 'a 16-bit character string ' if $string =~ s/^u//;
|
|
|
|
$modifier = 'a 32-bit character string ' if $string =~ s/^U//;
|
|
|
|
|
2015-02-14 06:34:02 +01:00
|
|
|
if (not length $final_string) {
|
|
|
|
$final_string = $modifier;
|
|
|
|
$final_string .= '"';
|
2014-07-11 13:30:05 +02:00
|
|
|
}
|
2015-02-14 06:34:02 +01:00
|
|
|
|
|
|
|
$string =~ s/^"//;
|
|
|
|
$string =~ s/"$//;
|
|
|
|
$final_string .= $string;
|
2014-07-11 13:30:05 +02:00
|
|
|
}
|
2015-02-14 06:34:02 +01:00
|
|
|
$final_string .= '"';
|
|
|
|
$return = $final_string;
|
2014-07-11 13:30:05 +02:00
|
|
|
}
|
2014-06-07 15:00:07 +02:00
|
|
|
|
2018-04-24 23:22:05 +02:00
|
|
|
reserved:
|
2014-06-21 08:40:03 +02:00
|
|
|
/(auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto
|
2014-06-29 23:13:18 +02:00
|
|
|
|if|inline|int|long|register|restrict|return|short|signed|sizeof|static|struct|switch|typedef
|
2014-07-07 08:45:50 +02:00
|
|
|
|union|unsigned|void|volatile|while|_Alignas|alignas|_Alignof|alignof|_Atomic|_Bool|_Complex|_Generic
|
2014-08-10 07:03:37 +02:00
|
|
|
|_Imaginary|_Noreturn|noreturn|_Static_assert|static_assert|_Thread_local|offsetof)\b/x
|
2014-06-07 15:00:07 +02:00
|
|
|
|