3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

CGrammar: Fix some abstract declarators in parameter lists; remove some minor extra whitespace

This commit is contained in:
Pragmatic Software 2014-06-22 02:28:28 +00:00
parent a388994d54
commit d4cda2bbc6
2 changed files with 31 additions and 13 deletions

View File

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

View File

@ -567,7 +567,6 @@ declaration_list:
declaration: declaration:
declaration_specifiers init_declarator_list(?) ';' declaration_specifiers init_declarator_list(?) ';'
{ {
print STDERR "wtf2\n", ::Dumper \%item;
my @init_list = defined $item{'init_declarator_list(?)'}->[0] ? @{$item{'init_declarator_list(?)'}->[0]} : (''); my @init_list = defined $item{'init_declarator_list(?)'}->[0] ? @{$item{'init_declarator_list(?)'}->[0]} : ('');
my $init_declaration_list; my $init_declaration_list;
@ -1117,12 +1116,20 @@ parameter_list:
if(@list == 0) { if(@list == 0) {
$return = "no parameters"; $return = "no parameters";
} elsif (@list == 1) { } elsif (@list == 1) {
$return .= $list[0]; if($list[0] eq 'void') {
$return = "no parameters";
} else {
$return .= $list[0];
}
} else { } else {
push @list, shift @list; push @list, shift @list;
my $identifier = shift @list; if($list[0] =~ /^`.*`$/) {
$return .= "$identifier as "; my $identifier = shift @list;
$return .= join(' ', @list); $return .= "$identifier as ";
$return .= join(' ', @list);
} else {
$return .= join(' ', @list);
}
} }
} else { } else {
$return .= $parameter_list[$i]; $return .= $parameter_list[$i];
@ -1142,22 +1149,34 @@ parameter_declaration:
| '...' | '...'
{ $return = "variadic parameters"; } { $return = "variadic parameters"; }
| declaration_specifiers abstract_declarator(?) | declaration_specifiers abstract_declarator(?)
{ $return = [$item{declaration_specifiers}, $item{'abstract_declarator(?)'}]; }
| '' | ''
{ $return = "unspecified parameters"; } { $return = "unspecified parameters"; }
abstract_declarator: abstract_declarator:
pointer pointer
| pointer(?) direct_abstract_declarator | pointer(?) direct_abstract_declarator(s)
{ $return = join('',@{$item{'pointer(?)'}}) . $item{direct_abstract_declarator}; } { $return = join(' ',@{$item{'pointer(?)'}}) . join(' ', @{$item{'direct_abstract_declarator(s)'}}); }
direct_abstract_declarator: direct_abstract_declarator:
'(' abstract_declarator ')' '(' abstract_declarator ')'
{ $return = $item{abstract_declarator}; }
| '[' ']' | '[' ']'
{ $return = "array of unspecified length of"; }
| '[' constant_expression ']' | '[' constant_expression ']'
{
my $size = $item{constant_expression};
if($size =~ /^(unsigned|long)*\s*1$/) {
$return = "array of $size element of";
} else {
$return = "array of $size elements of";
}
}
| DAD '[' ']' | DAD '[' ']'
| DAD '[' constant_expression ']' | DAD '[' constant_expression ']'
| '(' ')' | '(' ')'
| '(' parameter_type_list ')' | '(' parameter_type_list ')'
{ $return = "function taking $item{parameter_type_list} and returning"; }
| DAD '(' ')' | DAD '(' ')'
| DAD '(' parameter_type_list ')' | DAD '(' parameter_type_list ')'
@ -1175,12 +1194,12 @@ pointer:
'*' type_qualifier_list(s) pointer(?) '*' type_qualifier_list(s) pointer(?)
{ {
$return = join('', @{$item{'pointer(?)'}}) if @{$item{'pointer(?)'}}; $return = join('', @{$item{'pointer(?)'}}) if @{$item{'pointer(?)'}};
$return .= ' ' . join('', @{$item{'type_qualifier_list(s)'}}) . ' pointer to '; $return .= ' ' . join('', @{$item{'type_qualifier_list(s)'}}) . ' pointer to';
} }
| '*' pointer(?) | '*' pointer(?)
{ {
$return = join('', @{$item{'pointer(?)'}}); $return = join('', @{$item{'pointer(?)'}});
$return .= ' pointer to '; $return .= 'pointer to';
} }
type_qualifier_list: type_qualifier_list:
@ -1199,7 +1218,6 @@ declaration_specifiers:
} }
| comment(?) type_specifier declaration_specifiers(?) | comment(?) type_specifier declaration_specifiers(?)
{ {
print STDERR "wtf1\n", ::Dumper \%item;
my $decl_spec = join(' ', @{$item{'declaration_specifiers(?)'}}); my $decl_spec = join(' ', @{$item{'declaration_specifiers(?)'}});
$return = join('',@{$item{'comment(?)'}}); $return = join('',@{$item{'comment(?)'}});
$return .= "$decl_spec " if $decl_spec; $return .= "$decl_spec " if $decl_spec;