Skip to content

Commit 051aaf0

Browse files
committed
Move setting has_consumed_input flag into lx's advance hook.
This avoids cluttering libfsm's print output with `has_consumed_input`, which is specific to lx.
1 parent f25e8b7 commit 051aaf0

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/libfsm/print/c.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -484,17 +484,6 @@ fsm_print_c_body(FILE *f, const struct ir *ir,
484484
}
485485
}
486486

487-
/* This flag indicates whether the any of the input stream was
488-
* consumed before getting EOF and skipping over the state and
489-
* character logic expanded here.
490-
*
491-
* lx needs to track this for proper EOF handling. It previously
492-
* generated the state enum itself, so that it could include an
493-
* additional 'NONE' state. Inside the input loop, the default
494-
* state of NONE would be updated to the start state, but if the
495-
* input loop was skipped it would still be NONE. */
496-
fprintf(f, "\tint has_consumed_input = 0;\n");
497-
498487
/* enum of states */
499488
print_stateenum(f, ir->n);
500489
fprintf(f, "\n");
@@ -506,17 +495,14 @@ fsm_print_c_body(FILE *f, const struct ir *ir,
506495
switch (opt->io) {
507496
case FSM_IO_GETC:
508497
fprintf(f, "\twhile (c = fsm_getc(getc_opaque), c != EOF) {\n");
509-
fprintf(f, "\t\thas_consumed_input = 1;\n");
510498
break;
511499

512500
case FSM_IO_STR:
513501
fprintf(f, "\tfor (p = s; *p != '\\0'; p++) {\n");
514-
fprintf(f, "\t\thas_consumed_input = 1;\n");
515502
break;
516503

517504
case FSM_IO_PAIR:
518505
fprintf(f, "\tfor (p = b; p != e; p++) {\n");
519-
fprintf(f, "\t\thas_consumed_input = 1;\n");
520506
break;
521507
}
522508

@@ -533,10 +519,6 @@ fsm_print_c_body(FILE *f, const struct ir *ir,
533519
fprintf(f, "\t}\n");
534520
fprintf(f, "\n");
535521

536-
/* Suppress unused variable warning -- this is mainly for lx. */
537-
fprintf(f, "\t(void)has_consumed_input;\n");
538-
fprintf(f, "\n");
539-
540522
/* end states */
541523
if (-1 == print_endstates(f, opt, hooks, ir)) {
542524
return -1;

src/lx/print/c.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ advance_c(FILE *f, const struct fsm_options *opt, const char *cur_char_var, void
302302
{
303303
(void)hook_opaque;
304304

305+
fprintf(f, "\t\thas_consumed_input = 1;\n");
306+
305307
switch (opt->io) {
306308
case FSM_IO_GETC:
307309
break;
@@ -783,6 +785,17 @@ print_zone(FILE *f, const struct ast *ast, const struct ast_zone *z,
783785
fprintf(f, "z%u(struct %slx *lx)\n", zindexof(ast, z), prefix.lx);
784786
fprintf(f, "{\n");
785787

788+
/* This flag indicates whether the any of the input stream was
789+
* consumed before getting EOF and skipping over the state and
790+
* character logic expanded here.
791+
*
792+
* lx needs to track this for proper EOF handling. It previously
793+
* generated the state enum itself, so that it could include an
794+
* additional 'NONE' state. Inside the input loop, the default
795+
* state of NONE would be updated to the start state, but if the
796+
* input loop was skipped it would still be NONE. */
797+
fprintf(f, "\tint has_consumed_input = 0;\n");
798+
786799
switch (opt->io) {
787800
case FSM_IO_GETC:
788801
fprintf(f, "\tint c;\n");

0 commit comments

Comments
 (0)