mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-14 23:03:04 +00:00
parse.lac: implement exploratory stack reallocations.
* data/yacc.c: Rename %define variable parse.lac.es-capacity to parse.lac.es-capacity-initial. Accept parse.lac.memory-trace with values of "failures" (default) or "full". (b4_declare_parser_state_variables): Add yyesa, yyes, and yyes_capacity variables. (YYSTACK_USE_ALLOCA): Ignore it if LAC requested. (YYSTACK_ALLOC, YYSTACK_FREE, YYSTACK_ALLOC_MAXIMUM): Define if LAC requested. (YYCOPY_NEEDED): New cpp macro. (YYCOPY): Define if LAC requested. (yy_lac_stack_realloc): New function implementing stack reallocations. Use YYMAXDEPTH for maximum stack size given that the stack should never need to grow larger than the main state stack needs to grow without LAC. (YY_LAC_ESTABLISH): Update yy_lac invocation. (yy_lac): Add arguments for exploratory stack memory data recorded in the main parser. Invoke yy_lac_stack_realloc when reallocation is necessary. (yysyntax_error): Add the same new arguments and pass them to yy_lac. (yypstate_delete): Free yyes if necessary. (yyesa, yyes, yyes_capacity): #define these to yypstate members in the case of push parsing. (yyparse, yypush_parse): Initialize yyes and yyes_capacity. Update yysyntax_error invocations. At yyreturn, free yyes if necessary. * src/parse-gram.y: %define parse.lac full. * tests/input.at (LAC: errors for %define): Extend for parse.lac-memory-trace. * tests/regression.at (LAC: Exploratory stack): Extend to check that stack reallocs happen when expected. (LAC: Memory exhaustion): Update to use YYMAXDEPTH and parse.lac.es-capacity-initial.
This commit is contained in:
@@ -1306,5 +1306,9 @@ AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
|
||||
[[1]], [],
|
||||
[[<command line>:2: %define variable `parse.lac.es-capacity-initial' is not used
|
||||
]])
|
||||
AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
|
||||
[[1]], [],
|
||||
[[<command line>:2: %define variable `parse.lac.memory-trace' is not used
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -1498,6 +1498,8 @@ AT_DATA_GRAMMAR([input.y],
|
||||
// default reductions in inconsistent states
|
||||
// v v v v v v v v v v v v v v
|
||||
S: A B A A B A A A A B A A A A A A A B C C A A A A A A A A A A A A B ;
|
||||
// ^ ^ ^
|
||||
// LAC reallocs
|
||||
|
||||
A: 'a' | /*empty*/ { printf ("inconsistent default reduction\n"); } ;
|
||||
B: 'b' ;
|
||||
@@ -1527,9 +1529,8 @@ main (void)
|
||||
}
|
||||
]])
|
||||
|
||||
# Give exactly the right amount of memory to be sure there's no
|
||||
# off-by-one error, for example.
|
||||
AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity=12 \
|
||||
AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
|
||||
-Dparse.lac.memory-trace=full \
|
||||
-t -o input.c input.y]], [[0]], [],
|
||||
[[input.y: conflicts: 21 shift/reduce
|
||||
]])
|
||||
@@ -1552,6 +1553,11 @@ AT_CHECK([[perl -0777 -ne 'print s/inconsistent default reduction//g;' \
|
||||
AT_CHECK([[perl -0777 -ne 'print s/\bconsistent default reduction//g;' \
|
||||
< stdout.txt || exit 77]], [[0]], [[2]])
|
||||
|
||||
# Check number of reallocs to be sure reallocated memory isn't somehow
|
||||
# lost between LAC invocations.
|
||||
AT_CHECK([[perl -0777 -ne 'print s/\(realloc//g;' < stderr.txt \
|
||||
|| exit 77]], [[0]], [[3]])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
])
|
||||
|
||||
@@ -1579,6 +1585,7 @@ AT_DATA_GRAMMAR([input.y],
|
||||
#include <stdio.h>
|
||||
void yyerror (char const *);
|
||||
int yylex (void);
|
||||
#define YYMAXDEPTH 8
|
||||
}
|
||||
|
||||
%error-verbose
|
||||
@@ -1611,7 +1618,7 @@ main (void)
|
||||
}
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity=8 \
|
||||
AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
|
||||
-t -o input.c input.y]], [[0]], [],
|
||||
[[input.y: conflicts: 8 shift/reduce
|
||||
]])
|
||||
@@ -1626,7 +1633,7 @@ AT_PARSER_CHECK([[./input]], [[2]], [[]],
|
||||
Entering state 0
|
||||
Reading a token: Now at end of input.
|
||||
LAC: initial context established for $end
|
||||
LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max stack size exceeded)
|
||||
LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
|
||||
memory exhausted
|
||||
Cleanup: discarding lookahead token $end ()
|
||||
Stack now 0
|
||||
@@ -1642,7 +1649,7 @@ Reading a token: Next token is token $undefined ()
|
||||
LAC: initial context established for $undefined
|
||||
LAC: checking lookahead $undefined: Always Err
|
||||
Constructing syntax error message
|
||||
LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max stack size exceeded)
|
||||
LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
|
||||
syntax error
|
||||
memory exhausted
|
||||
Cleanup: discarding lookahead token $undefined ()
|
||||
|
||||
Reference in New Issue
Block a user