diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2020-09-21 17:03:17 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2020-09-21 17:11:29 -0400 |
commit | f858b63e23ce8e4d45926d1baa28d0fd1c67b339 (patch) | |
tree | 9450feac6f709f784770b1d695b01c052a462d8b | |
parent | 5f41ac5a99f49cb2780115adf167f95b3d43690d (diff) | |
download | flex-git-f858b63e23ce8e4d45926d1baa28d0fd1c67b339.tar.gz |
Turn gen_start_state() into an M4 macro.
This is the first patch in the retargeting series to substantively
modify the skeleton file. (The only previous one to touch it just
renamed a mode switch.)
Adds some comments and whitespace to the generated code in the tests,
but produces no logic changes.
#14 in the retargeting patch series
-rw-r--r-- | src/cpp-flex.skl | 19 | ||||
-rw-r--r-- | src/flexdef.h | 3 | ||||
-rw-r--r-- | src/gen.c | 37 |
3 files changed, 21 insertions, 38 deletions
diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index b4fd247..dc9b711 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -1184,6 +1184,25 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], %% [6.0] YY_RULE_SETUP definition goes here ]]) +%# Code snippets used in various cases of code generation in the main scanner. + +m4_define([[M4_GEN_START_STATE]], [[ + /* Generate the code to find the start state. */ +m4_ifdef([[M4_MODE_FULLSPD]], [[ +m4_ifdef([[M4_MODE_BOL_NEEDED]], [[yy_current_state", "yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];]]) +m4_ifdef([[M4_MODE_NO_BOL_NEEDED]], [[yy_current_state = yy_start_state_list[YY_G(yy_start)];]]) +]]) +m4_ifdef([[M4_MODE_NO_FULLSPD]], [[ + yy_current_state = YY_G(yy_start); +m4_ifdef([[M4_MODE_BOL_NEEDED]], [[yy_current_state += YY_AT_BOL();]]) + /* Set up for storing up states. */ + m4_ifdef( [[M4_MODE_USES_REJECT]], [[ + YY_G(yy_state_ptr) = YY_G(yy_state_buf); + *YY_G(yy_state_ptr)++ = yy_current_state; +]]) +]]) +]]) + %not-for-header /** The main scanner function which does all the work. */ diff --git a/src/flexdef.h b/src/flexdef.h index 781fe25..a5ee509 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -801,9 +801,6 @@ extern void gen_next_state(int); /* Generate the code to make a NUL transition. */ extern void gen_NUL_trans(void); -/* Generate the code to find the start state. */ -extern void gen_start_state(void); - /* Generate data statements for the transition tables. */ extern void gentabs(void); @@ -823,39 +823,6 @@ void gen_NUL_trans (void) } -/* Generate the code to find the start state. */ - -void gen_start_state (void) -{ - if (fullspd) { - if (bol_needed) { - indent_puts - ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];"); - } - else - indent_puts - ("yy_current_state = yy_start_state_list[YY_G(yy_start)];"); - } - - else { - indent_puts ("yy_current_state = YY_G(yy_start);"); - - if (bol_needed) - indent_puts ("yy_current_state += YY_AT_BOL();"); - - if (reject) { - /* Set up for storing up states. */ - outn ("m4_ifdef( [[M4_MODE_USES_REJECT]],\n[["); - indent_puts - ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);"); - indent_puts - ("*YY_G(yy_state_ptr)++ = yy_current_state;"); - outn ("]])"); - } - } -} - - /* gentabs - generate data statements for the transition tables */ void gentabs (void) @@ -1732,7 +1699,7 @@ void make_tables (void) skelout (); /* %% [9.0] - break point in skel */ - gen_start_state (); + outn ("M4_GEN_START_STATE"); /* Note, don't use any indentation. */ outn ("yy_match:"); @@ -1898,7 +1865,7 @@ void make_tables (void) set_indent (1); skelout (); /* %% [15.0] - break point in skel */ - gen_start_state (); + outn ("M4_GEN_START_STATE"); set_indent (2); skelout (); /* %% [16.0] - break point in skel */ |