From 01f4aaddd993c77ed4e7cd9213c082f95909f380 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 22 Sep 2020 06:41:54 -0400 Subject: gen_next_state(true) becomes m4 code. As with patch #20 in this series, the changes in generated code fall in the classes: 1. Addition of comments. I elected to copy the comments from the generator functions into their corresponding m4 macros in hopes of making the generated code less nasty to read. 2. Lines like "if ( yy_current_state >= 12 )" changing so the numeric literal is replaced by YY_JAMSTATE + 1. This was a consequence of the change in #15 to simplify the C code generators so they could be translated into static nacros. 3. "YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : YY_NUL_EC);: being replaced by "YY_CHAR yy_c = (*yy_cp ? *(yy_ec+YY_SC_TO_UI(*yy_cp)) : YY_NUL_EC);" The strange way of indexing yy_ec avoids a syntactic collision with the use of [] as m4 quotes. The gen_next_state(false) case was translated to m4 at patch #20 #22 in the retargeting patch series --- src/cpp-flex.skl | 27 ++++++++++++++++++++++ src/flexdef.h | 3 --- src/gen.c | 70 -------------------------------------------------------- 3 files changed, 27 insertions(+), 73 deletions(-) diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index 25b7612..83339ac 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -1997,6 +1997,33 @@ M4_GEN_START_STATE for ( yy_cp = YY_G(yytext_ptr) + YY_MORE_ADJ; yy_cp < YY_G(yy_c_buf_p); ++yy_cp ) { %% [16.0] code to find the next state goes here + /* Generate the code to find the next state. */ + m4_ifdef([[M4_MODE_NO_NULTRANS]], [[m4_define([[CHAR_MAP_3]], [[(*yy_cp ? M4_EC(YY_SC_TO_UI(*yy_cp)) : YY_NUL_EC)]])]]) + m4_ifdef([[M4_MODE_NULTRANS]], [[m4_define([[CHAR_MAP_3]], [[M4_EC(YY_SC_TO_UI(*yy_cp))]])]]) + + m4_ifdef([[M4_MODE_NULTRANS]], [[ + /* Compressed tables back up *before* they match. */ + m4_ifdef([[M4_MODE_NO_FULLSPD_OR_FULLTBL]], [[M4_GEN_BACKING_UP]]) + if ( *yy_cp ) { + ]]) + + m4_ifdef([[M4_MODE_FULLTBL]], [[ + m4_ifdef([[M4_MODE_GENTABLES]], [[yy_current_state = yy_nxt[yy_current_state][CHAR_MAP_3];]]) + m4_ifdef([[M4_MODE_NO_GENTABLES]], [[yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + CHAR_MAP_3];]]) + ]]) + + m4_ifdef([[M4_MODE_FULLSPD]], [[yy_current_state += yy_current_state[CHAR_MAP_3].yy_nxt;]]) + m4_ifdef([[M4_MODE_NO_FULLSPD_OR_FULLTBL]], [[M4_GEN_NEXT_COMPRESSED_STATE(CHAR_MAP_3)]]) + + m4_ifdef([[M4_MODE_NULTRANS]], [[ + } else { + yy_current_state = yy_NUL_trans[yy_current_state]; + } + ]]) + + m4_ifdef([[M4_MODE_FULLTBL]], [[M4_GEN_BACKING_UP]]) + m4_ifdef([[M4_MODE_FULLSPD]], [[M4_GEN_BACKING_UP]]) + m4_ifdef([[M4_MODE_USES_REJECT]], [[*YY_G(yy_state_ptr)++ = yy_current_state;]]) } return yy_current_state; diff --git a/src/flexdef.h b/src/flexdef.h index 7ee87eb..c68cbb8 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -786,9 +786,6 @@ extern void genftbl(void); /* generate full transition table */ /* Generate the code to find the next compressed-table state. */ extern void gen_next_compressed_state(char *); -/* Generate the code to find the next state. */ -extern void gen_next_state(int); - /* Generate the code to make a NUL transition. */ extern void gen_NUL_trans(void); diff --git a/src/gen.c b/src/gen.c index c0740bc..60d9a7c 100644 --- a/src/gen.c +++ b/src/gen.c @@ -513,72 +513,6 @@ void gen_next_compressed_state (char *char_map) } -/* Generate the code to find the next state. */ - -void gen_next_state (int worry_about_NULs) -{ /* NOTE - changes in here should be reflected in gen_next_match() */ - char *char_map; - - if (worry_about_NULs && !nultrans) { - if (useecs) - char_map = "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : YY_NUL_EC)"; - else - char_map = "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : YY_NUL_EC)"; - } - - else - char_map = useecs ? - "yy_ec[YY_SC_TO_UI(*yy_cp)] " : - "YY_SC_TO_UI(*yy_cp)"; - - if (worry_about_NULs && nultrans) { - if (!fulltbl && !fullspd) - /* Compressed tables back up *before* they match. */ - outn ("M4_GEN_BACKING_UP"); - - indent_puts ("if ( *yy_cp )"); - ++indent_level; - indent_puts ("{"); - } - - if (fulltbl) { - if (gentables) - indent_put2s - ("yy_current_state = yy_nxt[yy_current_state][%s];", - char_map); - else - indent_put2s - ("yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + %s];", - char_map); - } - - else if (fullspd) - indent_put2s - ("yy_current_state += yy_current_state[%s].yy_nxt;", - char_map); - - else - gen_next_compressed_state (char_map); - - if (worry_about_NULs && nultrans) { - - indent_puts ("}"); - --indent_level; - indent_puts ("else"); - ++indent_level; - indent_puts - ("yy_current_state = yy_NUL_trans[yy_current_state];"); - --indent_level; - } - - if (fullspd || fulltbl) - outn ("M4_GEN_BACKING_UP"); - - if (reject) - indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;"); -} - - /* Generate the code to make a NUL transition. */ void gen_NUL_trans (void) @@ -1624,12 +1558,8 @@ void make_tables (void) /* Generate code for yy_get_previous_state(). */ - set_indent (1); skelout (); /* %% [15.0] - break point in skel */ - - set_indent (2); skelout (); /* %% [16.0] - break point in skel */ - gen_next_state (true); set_indent (1); skelout (); /* %% [17.0] - break point in skel */ -- cgit v1.2.1