summaryrefslogtreecommitdiff
path: root/src/c99-flex.skl
diff options
context:
space:
mode:
Diffstat (limited to 'src/c99-flex.skl')
-rw-r--r--src/c99-flex.skl80
1 files changed, 66 insertions, 14 deletions
diff --git a/src/c99-flex.skl b/src/c99-flex.skl
index 1e04afe..317c038 100644
--- a/src/c99-flex.skl
+++ b/src/c99-flex.skl
@@ -268,9 +268,11 @@ typedef struct yyguts_t *yyscan_t;
/* Action number for EOF rule of a given start state. */
m4_define([[YY_STATE_EOF]], [[YY_END_OF_BUFFER + $1 + 1]])
-/* The state buf must be large enough to hold one state per character in the main buffer.
+/* The state buf must be large enough to hold one state per character in the main buffer,
+ * plus the start state, plus the two end-of-buffer byte states.
*/
-m4_define([[YY_STATE_BUF_SIZE]], [[((YY_BUF_SIZE + 2) * sizeof(yy_state_type))]])
+m4_define([[YY_STATE_BUF_EXTRA_SPACE]], [[3]])
+m4_define([[YY_STATE_BUF_SIZE]], [[(YY_BUF_SIZE + YY_STATE_BUF_EXTRA_SPACE)]])
const bool FLEX_DEBUG = m4_ifdef([[M4_MODE_DEBUG]], [[true]], [[false]]);
@@ -516,6 +518,7 @@ struct yyguts_t {
m4_ifdef( [[M4_MODE_USES_REJECT]], [[
yy_state_type *yy_state_buf;
yy_state_type *yy_state_ptr;
+ size_t yy_state_buf_max;
char *yy_full_match;
int yy_lp;
@@ -847,6 +850,8 @@ void yypop_buffer_state (yyscan_t yyscanner)
*/
void yyrestart(FILE * input_file, yyscan_t yyscanner)
{
+ size_t new_size = 0;
+ yy_state_type *new_state_buf = 0;
if ( yy_current_buffer(yyscanner) == NULL ) {
yyensure_buffer_stack (yyscanner);
@@ -856,6 +861,30 @@ void yyrestart(FILE * input_file, yyscan_t yyscanner)
yy_init_buffer( yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top], input_file, yyscanner);
yy_load_buffer_state( yyscanner );
+
+m4_ifdef( [[M4_MODE_USES_REJECT]], [[
+ /* Ensure the reject state buffer is large enough.
+ */
+ if ( yyscanner->yy_state_buf_max < (yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) ) {
+ new_size = yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE;
+ new_state_buf = (yy_state_type*) yyrealloc( yyscanner->yy_state_buf, (new_size * sizeof(yy_state_type)), yyscanner );
+
+ if ( new_state_buf == NULL ) {
+ yypanic( "out of dynamic memory in yylex()", yyscanner );
+ }
+ else {
+ yyscanner->yy_state_buf = new_state_buf;
+ yyscanner->yy_state_buf_max = new_size;
+ }
+ }
+]] )
+
+ /* We don't actually know whether we did this switch during
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yyscanner->yy_did_buffer_switch_on_eof = true;
}
static void yybumpline( yyscan_t yyscanner) {
@@ -1567,7 +1596,9 @@ bool yyatbol(yyscan_t yyscanner) {
*/
void yy_switch_to_buffer(yybuffer new_buffer, yyscan_t yyscanner)
{
-
+ size_t new_size = 0;
+ yy_state_type *new_state_buf = 0;
+
/* TODO. We should be able to replace this entire function body
* with
* yypop_buffer_state();
@@ -1587,6 +1618,23 @@ void yy_switch_to_buffer(yybuffer new_buffer, yyscan_t yyscanner)
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] = new_buffer;
yy_load_buffer_state( yyscanner );
+m4_ifdef( [[M4_MODE_USES_REJECT]], [[
+ /* Ensure the reject state buffer is large enough.
+ */
+ if ( yyscanner->yy_state_buf_max < (yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) ) {
+ new_size = yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE;
+ new_state_buf = (yy_state_type *)yyrealloc( yyscanner->yy_state_buf, (new_size * sizeof(yy_state_type)), yyscanner );
+
+ if ( new_state_buf == NULL ) {
+ yypanic( "out of dynamic memory in yylex()", yyscanner );
+ }
+ else {
+ yyscanner->yy_state_buf = new_state_buf;
+ yyscanner->yy_state_buf_max = new_size;
+ }
+ }
+]] )
+
/* We don't actually know whether we did this switch during
* EOF (yywrap()) processing, but the only time this flag
* is looked at is after yywrap() is called, so it's safe
@@ -1972,17 +2020,6 @@ m4_ifdef( [[<M4_YY_BISON_LLOC>]],
m4_ifdef([[YY_USER_INIT]], [[YY_USER_INIT]])
-m4_ifdef( [[M4_MODE_USES_REJECT]],
-[[
- /* Create the reject buffer large enough to save one state per allowed character. */
- if ( yyscanner->yy_state_buf == NULL ) {
- yyscanner->yy_state_buf = (yy_state_type *)yyalloc(YY_STATE_BUF_SIZE, yyscanner);
- }
- if ( yyscanner->yy_state_buf == NULL) {
- yypanic( "out of dynamic memory in yylex()", yyscanner);
- }
-]])
-
if ( yyscanner->yy_start == 0 ) {
yyscanner->yy_start = 1; /* first start state */
}
@@ -1997,6 +2034,20 @@ m4_ifdef( [[M4_MODE_USES_REJECT]],
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] =
yy_create_buffer( yyscanner->yyin_r, YY_BUF_SIZE, yyscanner);
}
+
+m4_ifdef( [[M4_MODE_USES_REJECT]],
+[[
+ /* Create the reject buffer large enough to save one state per allowed character.
+ * If the reject buffer already exists, keep using it.
+ */
+ if ( yyscanner->yy_state_buf == NULL ) {
+ yyscanner->yy_state_buf = (yy_state_type *)yyalloc(((yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yy_state_type)), yyscanner);
+ if ( yyscanner->yy_state_buf == NULL ) {
+ yypanic( "out of dynamic memory in yylex()", yyscanner );
+ }
+ yyscanner->yy_state_buf_max = (yy_current_buffer(yyscanner)->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE);
+ }
+]])
yy_load_buffer_state( yyscanner );
}
@@ -2355,6 +2406,7 @@ m4_ifdef( [[M4_MODE_USES_REJECT]],
[[
yyscanner->yy_state_buf = 0;
yyscanner->yy_state_ptr = 0;
+ yyscanner->yy_state_buf_max = 0;
yyscanner->yy_full_match = 0;
yyscanner->yy_lp = 0;
]])