tests: check typed mid-rule actions

* tests/input.at (_AT_UNUSED_VALUES_DECLARATIONS): Check
typed mid-rule actions.
* tests/report.at (Reports): Check that types of typed mid-rule
actions are reported.
* tests/actions.at (Typed mid-rule actions): Check that
the values of typed mid-rule actions are correct.
This commit is contained in:
Akim Demaille
2018-08-05 08:51:19 +02:00
parent b79b889de5
commit 11548b8e68
3 changed files with 88 additions and 6 deletions

View File

@@ -64,6 +64,55 @@ AT_PARSER_CHECK([./input], 0,
AT_CLEANUP
## ------------------------ ##
## Typed mid-rule actions. ##
## ------------------------ ##
AT_SETUP([Typed mid-rule actions])
AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([[input.y]],
[[%define parse.error verbose
%debug
%code {
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
%union {
int ival;
}
%type <ival> exp
%%
exp: <ival>{ $$ = 0; }
'1' <ival>{ $$ = 1; }
'2' <ival>{ $$ = 2; }
'3' <ival>{ $$ = 3; }
'4' <ival>{ $$ = 4; }
'5' <ival>{ $$ = 5; }
'6' <ival>{ $$ = 6; }
'7' <ival>{ $$ = 7; }
'8' <ival>{ $$ = 8; }
'9' <ival>{ $$ = 9; } <ival>{ $$ = 10; } <ival>{ $$ = 11; }
{
$$ = $1 + $3 + $5 + $7 + $9 + $11 + $13 + $15 + $17 + $19 + $20 + $21;
printf ("%d\n", $$);
}
;
%%
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["123456789"])[
]AT_MAIN_DEFINE[
]])
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-d -v -o input.c input.y])
AT_COMPILE([input])
AT_PARSER_CHECK([./input], 0,
[[66
]])
AT_CLEANUP
## ----------------------- ##
## Implicitly empty rule. ##
## ----------------------- ##

View File

@@ -168,7 +168,7 @@ AT_CLEANUP
# declarations for the unused values tests.
m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
[[[%token <integer> INT;
%type <integer> a b c d e f g h i j k l;
%type <integer> a b c d e f g h i j k l m n o;
%destructor { destroy ($$); } <integer>;]]])
@@ -189,7 +189,7 @@ start:
'a' a { $][2; } | 'b' b { $][2; } | 'c' c { $][2; } | 'd' d { $][2; }
| 'e' e { $][2; } | 'f' f { $][2; } | 'g' g { $][2; } | 'h' h { $][2; }
| 'i' i { $][2; } | 'j' j { $][2; } | 'k' k { $][2; } | 'l' l { $][2; }
| 'm' m { $][2; } | 'n' n { $][2; } | 'o' o { $][2; }
;
a: INT | INT { } INT { } INT { };
@@ -204,6 +204,9 @@ i: INT | INT INT { } { $][$ = $][1 + $][2; };
j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };
m: INT | INT <integer>{ $][$ = $][1; } INT <integer>{ $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; };
n: INT | INT <integer>{ } INT <integer>{ } INT { };
o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
]]m4_ifval($1, [
_AT_UNUSED_VALUES_DECLARATIONS])
)
@@ -309,7 +312,37 @@ input.y:22.14-16: warning: unused value: $][2 [-Wother]
]]m4_ifval($2, [[[input.y:22.35-64: warning: unused value: $][4 [-Wmidrule-values]
k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
]]]))
]]])[[input.y:25.23-25: warning: unset value: $][$ [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^
input.y:25.40-42: warning: unset value: $][$ [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^
input.y:25.10-50: warning: unset value: $][$ [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
input.y:25.10-12: warning: unused value: $][1 [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^
input.y:25.23-25: warning: unused value: $][2 [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^
input.y:25.27-29: warning: unused value: $][3 [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^
input.y:25.40-42: warning: unused value: $][4 [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^
input.y:25.44-46: warning: unused value: $][5 [-Wother]
n: INT | INT <integer>{ } INT <integer>{ } INT { };
^^^
input.y:26.23-25: warning: unset value: $][$ [-Wother]
o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
^^^
input.y:26.40-42: warning: unset value: $][$ [-Wother]
o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
^^^
]])
])
## --------------- ##

View File

@@ -53,7 +53,7 @@ id:
"identifier";
exp:
"incr" exp { $<int>$ = 1; } { $<int>$ = 10; } exp { $$ = $2 + $<int>3 + $<int>4 + $5; }
"incr" exp <int>{ $$ = 1; } <int>{ $$ = 10; } exp { $$ = $2 + $3 + $4 + $5; }
| "(" exp ")" { std::swap ($$, $2); }
| "identifier" { $$ = driver.variables[$1]; }
| "number" { std::swap ($$, $1); };
@@ -113,9 +113,9 @@ id <std::string> (13)
on left: 5, on right: 4
exp <int> (14)
on left: 8 9 10 11, on right: 1 4 8 9
@1 (15)
@1 <int> (15)
on left: 6, on right: 8
@2 (16)
@2 <int> (16)
on left: 7, on right: 8