summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FlexLexer.h1
-rw-r--r--[-rwxr-xr-x]src/Makefile.am1
-rw-r--r--src/c99-flex.skl80
-rw-r--r--src/cpp-flex.skl80
-rw-r--r--src/go-flex.skl81
5 files changed, 202 insertions, 41 deletions
diff --git a/src/FlexLexer.h b/src/FlexLexer.h
index ccd9eeb..9b54949 100644
--- a/src/FlexLexer.h
+++ b/src/FlexLexer.h
@@ -202,6 +202,7 @@ protected:
yy_state_type* yy_state_buf;
yy_state_type* yy_state_ptr;
+ size_t yy_state_buf_max;
char* yy_full_match;
int* yy_full_state;
diff --git a/src/Makefile.am b/src/Makefile.am
index fada4a7..ce21a4d 100755..100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -130,6 +130,7 @@ endif
dist-hook: scan.l flex$(EXEEXT)
chmod u+w $(distdir) && \
+ chmod u+w $(distdir)/scan.c && \
./flex$(EXEEXT) -o scan.c $< && \
mv -f scan.c $(distdir)
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;
]])
diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl
index 1c62e3d..0941d4d 100644
--- a/src/cpp-flex.skl
+++ b/src/cpp-flex.skl
@@ -422,9 +422,11 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]],
m4_ifdef( [[M4_YY_NOT_IN_HEADER]],
[[
-/* 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.
*/
-#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+#define YY_STATE_BUF_EXTRA_SPACE 3
+#define YY_STATE_BUF_SIZE (YY_BUF_SIZE + YY_STATE_BUF_EXTRA_SPACE)
]])
@@ -1074,6 +1076,7 @@ m4_ifdef( [[M4_YY_NOT_REENTRANT]], [[
m4_ifdef( [[M4_MODE_C_ONLY]], [[
/* Declare state buffer variables. */
static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;
+static size_t yy_state_buf_max=0;
static char *yy_full_match;
static int yy_lp;
m4_ifdef( [[M4_MODE_VARIABLE_TRAILING_CONTEXT_RULES]], [[
@@ -1226,6 +1229,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;
@@ -1876,17 +1880,6 @@ m4_ifdef( [[<M4_YY_BISON_LLOC>]],
YY_USER_INIT;
#endif
-m4_ifdef( [[M4_MODE_USES_REJECT]],
-[[
- /* Create the reject buffer large enough to save one state per allowed character. */
- if ( ! YY_G(yy_state_buf) ) {
- YY_G(yy_state_buf) = (yy_state_type *)yyalloc(YY_STATE_BUF_SIZE M4_YY_CALL_LAST_ARG);
- }
- if ( ! YY_G(yy_state_buf) ) {
- YY_FATAL_ERROR( "out of dynamic memory in yylex()" );
- }
-]])
-
if ( ! YY_G(yy_start) ) {
YY_G(yy_start) = 1; /* first start state */
}
@@ -1911,6 +1904,20 @@ m4_ifdef([[M4_MODE_CXX_ONLY]], [[
YY_CURRENT_BUFFER_LVALUE =
yy_create_buffer( yyin, YY_BUF_SIZE M4_YY_CALL_LAST_ARG);
}
+
+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 ( ! YY_G(yy_state_buf) ) {
+ YY_G(yy_state_buf) = (yy_state_type *)yyalloc( ((YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yy_state_type)) M4_YY_CALL_LAST_ARG);
+ if ( ! YY_G(yy_state_buf) ) {
+ YY_FATAL_ERROR( "out of dynamic memory in yylex()" );
+ }
+ YY_G(yy_state_buf_max) = (YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE);
+ }
+]])
yy_load_buffer_state( M4_YY_CALL_ONLY_ARG );
}
@@ -2323,6 +2330,7 @@ void yyFlexLexer::ctor_common() {
m4_ifdef( [[M4_MODE_USES_REJECT]],
[[
yy_state_buf = new yy_state_type[YY_STATE_BUF_SIZE];
+ yy_state_buf_max = YY_STATE_BUF_SIZE;
]],
[[
yy_state_buf = 0;
@@ -2824,6 +2832,8 @@ void yyFlexLexer::yyrestart( std::istream& input_file )
]])
{
M4_YY_DECL_GUTS_VAR();
+ size_t new_size = 0;
+ yy_state_type *new_state_buf = 0;
if ( yy_current_buffer() == NULL ) {
yyensure_buffer_stack (M4_YY_CALL_ONLY_ARG);
@@ -2833,6 +2843,30 @@ void yyFlexLexer::yyrestart( std::istream& input_file )
yy_init_buffer( YY_CURRENT_BUFFER_LVALUE, input_file M4_YY_CALL_LAST_ARG);
yy_load_buffer_state( M4_YY_CALL_ONLY_ARG );
+
+m4_ifdef( [[M4_MODE_USES_REJECT]], [[
+ /* Ensure the reject state buffer is large enough.
+ */
+ if ( YY_G(yy_state_buf_max) < (yy_current_buffer()->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) ) {
+ new_size = yy_current_buffer()->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE;
+ new_state_buf = (yy_state_type *)yyrealloc( YY_G(yy_state_buf), (new_size * sizeof(yy_state_type)) M4_YY_CALL_LAST_ARG );
+
+ if ( new_state_buf == NULL ) {
+ YY_FATAL_ERROR( "out of dynamic memory in yylex()" );
+ }
+ else {
+ YY_G(yy_state_buf) = new_state_buf;
+ YY_G(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.
+ */
+ YY_G(yy_did_buffer_switch_on_eof) = 1;
}
m4_ifdef([[M4_MODE_CXX_ONLY]], [[
@@ -2862,6 +2896,8 @@ void yyFlexLexer::yy_switch_to_buffer( yybuffer new_buffer )
]])
{
M4_YY_DECL_GUTS_VAR();
+ size_t new_size = 0;
+ yy_state_type *new_state_buf = 0;
/* TODO. We should be able to replace this entire function body
* with
@@ -2881,6 +2917,23 @@ void yyFlexLexer::yy_switch_to_buffer( yybuffer new_buffer )
YY_CURRENT_BUFFER_LVALUE = new_buffer;
yy_load_buffer_state( M4_YY_CALL_ONLY_ARG );
+
+m4_ifdef( [[M4_MODE_USES_REJECT]], [[
+ /* Ensure the reject state buffer is large enough.
+ */
+ if ( YY_G(yy_state_buf_max) < (YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE) ) {
+ new_size = YY_CURRENT_BUFFER_LVALUE->yy_buf_size + YY_STATE_BUF_EXTRA_SPACE;
+ new_state_buf = (yy_state_type *)yyrealloc( YY_G(yy_state_buf), (new_size * sizeof(yy_state_type)) M4_YY_CALL_LAST_ARG );
+
+ if ( new_state_buf == NULL ) {
+ YY_FATAL_ERROR( "out of dynamic memory in yylex()" );
+ }
+ else {
+ YY_G(yy_state_buf) = new_state_buf;
+ YY_G(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
@@ -3714,6 +3767,7 @@ m4_ifdef( [[M4_MODE_USES_REJECT]],
[[
YY_G(yy_state_buf) = 0;
YY_G(yy_state_ptr) = 0;
+ YY_G(yy_state_buf_max) = 0;
YY_G(yy_full_match) = 0;
YY_G(yy_lp) = 0;
]])
diff --git a/src/go-flex.skl b/src/go-flex.skl
index f2807dd..53f0b90 100644
--- a/src/go-flex.skl
+++ b/src/go-flex.skl
@@ -194,9 +194,11 @@ m4_define([[YY_SC_TO_UI]], [[((YY_CHAR)($1))]])
/* 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]], [[((flexInputBufferSize + 2) * sizeof(yyStateType))]])
+m4_define([[YY_STATE_BUF_EXTRA_SPACE]], [[3]])
+m4_define([[YY_STATE_BUF_SIZE]], [[(flexInputBufferSize + YY_STATE_BUF_EXTRA_SPACE)]])
const bool FLEX_DEBUG = m4_ifdef([[M4_MODE_DEBUG]], [[true]], [[false]]);
@@ -447,6 +449,7 @@ m4_ifdef([[M4_MODE_YYTEXT_IS_ARRAY]], [[
m4_ifdef([[M4_MODE_USES_REJECT]], [[
yyStateType *yyStateBuf;
yyStateType *yyStatePtr;
+ size_t yyStateBufMax;
char *yyFullMatch;
int yyLp;
m4_ifdef([[M4_MODE_VARIABLE_TRAILING_CONTEXT_RULES]], [[m4_dnl
@@ -756,7 +759,10 @@ void yypop_buffer_state (FlexLexer *yyscanner)
*/
void yyrestart(FILE * input_file, FlexLexer *yyscanner)
{
-
+
+ size_t newSize = 0;
+ yyStateType *newStateBuf = 0;
+
if (yy_current_buffer(yyscanner) == NULL) {
yyensure_buffer_stack (yyscanner);
yyscanner->yyBufferStack[yyscanner->yyBufferStackTop] =
@@ -765,6 +771,30 @@ void yyrestart(FILE * input_file, FlexLexer *yyscanner)
yy_init_buffer(yyscanner->yyBufferStack[yyscanner->yyBufferStackTop], input_file, yyscanner);
yy_load_buffer_state(yyscanner);
+
+m4_ifdef( [[M4_MODE_USES_REJECT]], [[
+ /* Ensure the reject state buffer is large enough.
+ */
+ if ( yyscanner->yyStateBufMax < (yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE) ) {
+ newSize = yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE;
+ newStateBuf = (yyStateType *)yyrealloc( yyscanner->yyStateBuf, (newSize * sizeof(yyStateType)), yyscanner );
+
+ if ( newStateBuf == NULL ) {
+ yypanic( "out of dynamic memory in yylex()", yyscanner );
+ }
+ else {
+ yyscanner->yyStateBuf = newStateBuf;
+ yyscanner->yyStateBufMax = newSize;
+ }
+ }
+]] )
+
+ /* 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->yyDidBufferSwitchOnEof = true;
}
static void yybumpline(FlexLexer *yyscanner) {
@@ -1417,6 +1447,8 @@ bool yyatbol(FlexLexer *yyscanner) {
*/
void yy_switch_to_buffer(yybuffer newBuffer, FlexLexer *yyscanner)
{
+ size_t newSize = 0;
+ yyStateType *newStateBuf = 0;
/* TODO. We should be able to replace this entire function body
* with
@@ -1436,6 +1468,23 @@ void yy_switch_to_buffer(yybuffer newBuffer, FlexLexer *yyscanner)
yyscanner->yyBufferStack[yyscanner->yyBufferStackTop] = newBuffer;
yy_load_buffer_state(yyscanner);
+
+m4_ifdef( [[M4_MODE_USES_REJECT]], [[
+ /* Ensure the reject state buffer is large enough.
+ */
+ if ( yyscanner->yyStateBufMax < (yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE) ) {
+ newSize = yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE;
+ newStateBuf = (yyStateType *)yyrealloc( yyscanner->yyStateBuf, (newSize * sizeof(yyStateType)), yyscanner );
+
+ if ( newStateBuf == NULL ) {
+ yypanic( "out of dynamic memory in yylex()", yyscanner );
+ }
+ else {
+ yyscanner->yyStateBuf = newStateBuf;
+ yyscanner->yyStateBufMax = newSize;
+ }
+ }
+]] )
/* We don't actually know whether we did this switch during
* EOF (yywrap()) processing, but the only time this flag
@@ -1822,17 +1871,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->yyStateBuf == NULL) {
- yyscanner->yyStateBuf = (yyStateType *)yyalloc(YY_STATE_BUF_SIZE, yyscanner);
- }
- if (yyscanner->yyStateBuf == NULL) {
- yypanic("out of dynamic memory in yylex()", yyscanner);
- }
-]])
-
if (yyscanner->yyStart == 0) {
yyscanner->yyStart = 1; /* first start state */
}
@@ -1848,6 +1886,20 @@ m4_ifdef([[M4_MODE_USES_REJECT]],
yy_create_buffer(yyscanner->yyin, flexInputBufferSize, 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->yyStateBuf == NULL) {
+ yyscanner->yyStateBuf = (yyStateType *)yyalloc((yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE) * sizeof(yyStateType), yyscanner);
+ if ( yyscanner->yyStateBuf == NULL ) {
+ yypanic( "out of dynamic memory in yylex()", yyscanner );
+ }
+ yyscanner->yyStateBufMax = (yy_current_buffer(yyscanner)->yyInputBufSize + YY_STATE_BUF_EXTRA_SPACE);
+ }
+]])
+
yy_load_buffer_state(yyscanner);
}
@@ -2204,6 +2256,7 @@ m4_ifdef([[M4_MODE_USES_REJECT]],
[[
yyscanner->yyStateBuf = NULL;
yyscanner->yyStatePtr = NULL;
+ yyscanner->yyStateBufMax = 0;
yyscanner->yyFullMatch = NULL;
yyscanner->yyLp = 0;
]])