summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2020-11-19 18:26:48 -0500
committerEric S. Raymond <esr@thyrsus.com>2020-11-19 18:26:48 -0500
commit5a9a913893c2c8309fb0f9ea9ab8e2331e5ba9dc (patch)
treedac3a397e3604ddefb329e7416d4fc078f1795f1
parent75da1e1d8a8dc0b89803495b951627e76e821822 (diff)
downloadflex-git-5a9a913893c2c8309fb0f9ea9ab8e2331e5ba9dc.tar.gz
Eliminate forwards in the C99 back end.
-rw-r--r--src/c99-flex.skl67
-rw-r--r--tests/alloc_extra_c99.l2
-rw-r--r--tests/mem_c99.l21
3 files changed, 43 insertions, 47 deletions
diff --git a/src/c99-flex.skl b/src/c99-flex.skl
index a72ccee..478a9d2 100644
--- a/src/c99-flex.skl
+++ b/src/c99-flex.skl
@@ -339,14 +339,36 @@ struct yy_buffer_state {
int yy_buffer_status;
};
-/* These forwards can simply deleted when poerting to a target language
- * with two-pass name resoltion.
- */
-void *yyalloc ( yy_size_t, yyscan_t yyscanner );
-void *yyrealloc ( void *, yy_size_t, yyscan_t yyscanner );
-void yyfree ( void *, yyscan_t yyscanner );
+m4_ifdef( [[M4_YY_NO_FLEX_ALLOC]],,
+[[
+void *yyalloc(yy_size_t size, yyscan_t yyscanner) {
+ (void)yyscanner; /* forestall unused-argument warning */
+ return malloc(size);
+}
+]])
-/* Begin user sect3 */
+m4_ifdef( [[M4_YY_NO_FLEX_REALLOC]],,
+[[
+void *yyrealloc(void * ptr, yy_size_t size, yyscan_t yyscanner) {
+ (void)yyscanner; /* forestall unused-argument warning */
+ return realloc(ptr, size);
+}
+]])
+
+m4_ifdef( [[M4_YY_NO_FLEX_FREE]],,
+[[
+void yyfree(void * ptr, yyscan_t yyscanner) {
+ (void)yyscanner; /* forestall unused-argument warning */
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ free( (char *) ptr );
+}
+]])
m4_ifdef( [[M4_MODE_NO_YYWRAP]], [[
int M4_MODE_PREFIX[[wrap]](yyscan_t yyscanner) {
@@ -2444,37 +2466,6 @@ m4_ifdef( [[M4_MODE_USES_REJECT]],
return 0;
}
-m4_ifdef( [[M4_YY_NO_FLEX_ALLOC]],,
-[[
-void *yyalloc(yy_size_t size, yyscan_t yyscanner) {
- (void)yyscanner; /* forestall unused-argument warning */
- return malloc(size);
-}
-]])
-
-m4_ifdef( [[M4_YY_NO_FLEX_REALLOC]],,
-[[
-void *yyrealloc(void * ptr, yy_size_t size, yyscan_t yyscanner) {
- (void)yyscanner; /* forestall unused-argument warning */
- return realloc(ptr, size);
-}
-]])
-
-m4_ifdef( [[M4_YY_NO_FLEX_FREE]],,
-[[
-void yyfree(void * ptr, yyscan_t yyscanner) {
- (void)yyscanner; /* forestall unused-argument warning */
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- free( (char *) ptr );
-}
-]])
-
m4_ifdef([[M4_YY_MAIN]], [[
int main () {
yyscan_t lexer;
diff --git a/tests/alloc_extra_c99.l b/tests/alloc_extra_c99.l
index 67c3526..d99a4ca 100644
--- a/tests/alloc_extra_c99.l
+++ b/tests/alloc_extra_c99.l
@@ -40,6 +40,8 @@ struct Check {
char qux;
};
+void *yyalloc(size_t, yyscan_t);
+
/* Save char into junk array at next position. */
static void check_extra ( yyscan_t scanner );
diff --git a/tests/mem_c99.l b/tests/mem_c99.l
index fefe67b..1d206b5 100644
--- a/tests/mem_c99.l
+++ b/tests/mem_c99.l
@@ -37,10 +37,13 @@
#endif
#define YY_BUF_SIZE 8
+void * yyalloc(yy_size_t, yyscan_t);
+void *yyrealloc ( void *, yy_size_t, yyscan_t yyscanner );
+void yyfree ( void *, yyscan_t yyscanner );
%}
%option emit="c99" bufsize=8
-%option 8bit prefix="test"
+%option 8bit
%option nounput nomain noyywrap noinput noyy_top_state
%option warn stack nodefault
%option noyyalloc noyyrealloc noyyfree
@@ -86,7 +89,7 @@ static void dump_mem(FILE* fp){
fprintf(fp,"}\n");
}
-void * testalloc(yy_size_t n , yyscan_t yyscanner)
+void * yyalloc(yy_size_t n , yyscan_t yyscanner)
{
(void)yyscanner;
@@ -117,7 +120,7 @@ void * testalloc(yy_size_t n , yyscan_t yyscanner)
return p;
}
-void * testrealloc(void* p, yy_size_t n , yyscan_t yyscanner)
+void * yyrealloc(void* p, yy_size_t n , yyscan_t yyscanner)
{
(void)yyscanner;
@@ -140,7 +143,7 @@ void * testrealloc(void* p, yy_size_t n , yyscan_t yyscanner)
exit(1);
}
-void testfree(void* p , yyscan_t yyscanner)
+void yyfree(void* p , yyscan_t yyscanner)
{
(void)yyscanner;
@@ -172,11 +175,11 @@ main (void)
ptrs = calloc(1, sizeof(struct memsz));
nptrs = 0;
- testlex_init(&scanner);
- testset_in(stdin,scanner);
- testset_out(stdout,scanner);
- testlex(scanner);
- testlex_destroy(scanner);
+ yylex_init(&scanner);
+ yyset_in(stdin,scanner);
+ yyset_out(stdout,scanner);
+ yylex(scanner);
+ yylex_destroy(scanner);
free(ptrs);
if ( nptrs > 0 || total_mem > 0){