From 307645b7b7a21453fb8a777ddb7b0bf76df84dfd Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 25 Oct 2020 09:53:18 -0400 Subject: [PATCH] Narrow the interface between Flex and the skeleton file... ...and reduce C preprocessor entanglement in the C99 skeleton. --- src/c99-flex.skl | 4 ++-- src/cpp-flex.skl | 4 ++-- src/flexdef.h | 1 - src/main.c | 4 ++-- src/misc.c | 5 ----- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/c99-flex.skl b/src/c99-flex.skl index b011a0a79..8fcffb0cc 100644 --- a/src/c99-flex.skl +++ b/src/c99-flex.skl @@ -42,11 +42,11 @@ m4_define([[M4_HOOK_EOF_STATE_CASE_ARM]], [[ case YY_STATE_EOF($1):]]) m4_define([[M4_HOOK_EOF_STATE_CASE_FALLTHROUGH]], [[ /* FALLTHROUGH */]]) m4_define([[M4_HOOK_EOF_STATE_CASE_TERMINATE]], [[ yyterminate(); ]]) -m4_define([[M4_HOOK_CONST_DEFINE]], [[#define $1 $2 +m4_define([[M4_HOOK_CONST_DEFINE]], [[const int $1 = $2; ]]) m4_define([[M4_HOOK_SET_YY_DECL]], [[#define YY_DECL $1 ]]) -m4_define([[M4_HOOK_SET_YYLMAX]], [[#define YYLMAX $1 +m4_define([[M4_HOOK_SET_OFFSET_TYPE]], [[#define YY_OFFSET_TYPE $1 ]]) m4_define([[M4_HOOK_SET_USERINIT]], [[#define YY_USER_INIT $1 ]]) diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index 6c0920aef..caf5fe163 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -46,9 +46,9 @@ m4_define([[M4_HOOK_EOF_STATE_CASE_TERMINATE]], [[ yyterminate(); ]]) m4_define([[M4_HOOK_CONST_DEFINE]], [[#define $1 $2 ]]) -m4_define([[M4_HOOK_SET_YY_DECL]], [[#define YY_DECL $1 +m4_define([[M4_HOOK_SET_OFFSET_TYPE]], [[#define YY_OFFSET_TYPE $1 ]]) -m4_define([[M4_HOOK_SET_YYLMAX]], [[#define YYLMAX $1 +m4_define([[M4_HOOK_SET_YY_DECL]], [[#define YY_DECL $1 ]]) m4_define([[M4_HOOK_SET_USERINIT]], [[#define YY_USER_INIT $1 ]]) diff --git a/src/flexdef.h b/src/flexdef.h index 8c909335e..098f72da8 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -929,7 +929,6 @@ extern void out_dec(const char *, int); extern void out_dec2(const char *, int, int); extern void out_hex(const char *, unsigned int); extern void out_str(const char *, const char *); -extern void out_str3(const char *, const char *, const char *, const char *); extern void out_str_dec(const char *, const char *, int); extern void outc(int); extern void outn(const char *); diff --git a/src/main.c b/src/main.c index e358027f3..735cf807f 100644 --- a/src/main.c +++ b/src/main.c @@ -205,7 +205,7 @@ int flex_main (int argc, char *argv[]) /* Need to define the transet type as a size large * enough to hold the biggest offset. */ - out_str3 ("M4_HOOK_CONST_DEFINE(%s, %s)", "YY_OFFSET_TYPE", optimize_pack(tblend + numecs + 1)->name, ""); + out_str ("M4_HOOK_SET_OFFSET_TYPE(%s)", optimize_pack(tblend + numecs + 1)->name); comment("END of Flex-generated definitions\n"); skelout (true); /* %% [2.0] - tables get dumped here */ @@ -1307,7 +1307,7 @@ void readin (void) } if (ctrl.yylmax != 0) { - out_dec ("M4_HOOK_SET_YYLMAX(%d)\n", ctrl.yylmax); + out_dec ("M4_CONST_DEFINE(YYLMAX, %d)\n", ctrl.yylmax); } /* Dump the user defined preproc directives. */ diff --git a/src/misc.c b/src/misc.c index 5c1664eac..9b434c8c8 100644 --- a/src/misc.c +++ b/src/misc.c @@ -503,11 +503,6 @@ void out_str (const char *fmt, const char str[]) fprintf (stdout,fmt, str); } -void out_str3 (const char *fmt, const char s1[], const char s2[], const char s3[]) -{ - fprintf (stdout,fmt, s1, s2, s3); -} - void out_str_dec (const char *fmt, const char str[], int n) { fprintf (stdout,fmt, str, n);