]> granicus.if.org Git - flex/commitdiff
Made yy_flex_debug non-global in reentrant scanner.
authorJohn Millaway <john43@users.sourceforge.net>
Tue, 9 Jul 2002 16:37:04 +0000 (16:37 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Tue, 9 Jul 2002 16:37:04 +0000 (16:37 +0000)
Created get/set functions for yy_flex_debug.
Defined prefixes for new yy_flex_debug symbols.
Added tests/ for yy_flex_debug.

14 files changed:
configure.in
flex.skl
gen.c
main.c
scan.l
tests/Makefile.am
tests/test-debug-nr/.cvsignore [new file with mode: 0644]
tests/test-debug-nr/Makefile.am [new file with mode: 0644]
tests/test-debug-nr/scanner.l [new file with mode: 0644]
tests/test-debug-nr/test.input [new file with mode: 0644]
tests/test-debug-r/.cvsignore [new file with mode: 0644]
tests/test-debug-r/Makefile.am [new file with mode: 0644]
tests/test-debug-r/scanner.l [new file with mode: 0644]
tests/test-debug-r/test.input [new file with mode: 0644]

index 442f189e0d3e1a6d4635e7ab9880ad7c0623160f..467024da4867008f64ae0975f172ce135d2b34a7 100644 (file)
@@ -73,4 +73,6 @@ tests/test-string-r/Makefile
 tests/test-yyextra/Makefile
 tests/test-lineno-nr/Makefile
 tests/test-lineno-r/Makefile
+tests/test-debug-r/Makefile
+tests/test-debug-nr/Makefile
 )
index 0ba0880d5ffd25c7bc004795bf01541174da223e..ca6d15d9122e4d22130c8ecd51a5a044c32a43b3 100644 (file)
--- a/flex.skl
+++ b/flex.skl
@@ -1,4 +1,4 @@
-/* -*-C-*- */
+%# -*-C-*- vi: set ft=c:
 /* A lexical scanner generated by flex */
 
 %# Lines in this skeleton starting with a '%' character are "control lines"
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <stdbool.h>
 /* end standard C headers. */
 %+
 /* begin standard C++ headers. */
@@ -115,6 +116,7 @@ typedef void* yyscan_t;
 #define yyleng YY_G(yyleng_r)
 #define yytext YY_G(yytext_r)
 #define yylineno YY_G(yylineno_r)
+#define yy_flex_debug YY_G(yy_flex_debug_r)
 
 int yylex_init YY_PROTO((yyscan_t* scanner));
 int yylex_destroy YY_PROTO((yyscan_t scanner));
@@ -432,6 +434,7 @@ struct yy_globals_t
     char* yy_last_accepting_cpos;
 
     int yylineno_r;
+    bool yy_flex_debug_r;
 
 #ifdef YY_TEXT_IS_ARRAY
     char yytext_r[YYLMAX];
@@ -1900,6 +1903,33 @@ void yyset_out( out_str YY_LAST_ARG )
 }
 #endif /* !YY_NO_SET_OUT */
 
+
+#ifndef YY_NO_GET_DEBUG
+#ifdef YY_USE_PROTOS
+bool  yyget_debug( YY_ONLY_ARG )
+#else
+bool yyget_debug( YY_ONLY_ARG )
+    YY_DECL_LAST_ARG
+#endif
+{
+    return yy_flex_debug;
+}
+#endif /* !YY_NO_GET_DEBUG */
+
+#ifndef YY_NO_SET_DEBUG
+#ifdef YY_USE_PROTOS
+void yyset_debug(bool bdebug YY_LAST_ARG )
+#else
+void yyset_debug( bdebug YY_LAST_ARG )
+    bool bdebug;
+    YY_DECL_LAST_ARG
+#endif
+{
+    yy_flex_debug = bdebug ;
+}
+#endif /* !YY_NO_SET_DEBUG */
+
+
 /* Accessor methods for yylval and yylloc */
 
 #ifdef YY_REENTRANT_BISON_PURE
diff --git a/gen.c b/gen.c
index 2394f581c1e2a221bbd49a092314a2b818d89c89..509724f637e61a13e215b6d370d7253627bcd4e7 100644 (file)
--- a/gen.c
+++ b/gen.c
@@ -1191,7 +1191,7 @@ void make_tables()
 
        if ( ddebug )
                { /* Spit out table mapping rules to line numbers. */
-               if ( ! C_plus_plus )
+               if ( ! C_plus_plus && ! reentrant )
                        {
                        indent_puts( "extern int yy_flex_debug;" );
                        indent_puts( "int yy_flex_debug = 1;\n" );
diff --git a/main.c b/main.c
index 6cc6930e7bd2c39fe5659e78db60a9f66df3f804..79aa64bda2797329fefbe57a16625c752b9e4d1b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -355,13 +355,13 @@ void check_options()
                 GEN_PREFIX( "leng" );
                 GEN_PREFIX( "in" );
                 GEN_PREFIX( "out" );
+                GEN_PREFIX( "_flex_debug" );
             outn( "#endif" );
                        GEN_PREFIX( "_create_buffer" );
                        GEN_PREFIX( "_delete_buffer" );
                        GEN_PREFIX( "_scan_buffer" );
                        GEN_PREFIX( "_scan_string" );
                        GEN_PREFIX( "_scan_bytes" );
-                       GEN_PREFIX( "_flex_debug" );
                        GEN_PREFIX( "_init_buffer" );
                        GEN_PREFIX( "_flush_buffer" );
                        GEN_PREFIX( "_load_buffer_state" );
@@ -370,6 +370,8 @@ void check_options()
                        GEN_PREFIX( "restart" );
             GEN_PREFIX( "lex_init" );
             GEN_PREFIX( "lex_destroy" );
+            GEN_PREFIX( "get_debug" );
+            GEN_PREFIX( "set_debug" );
             GEN_PREFIX( "get_extra" );
             GEN_PREFIX( "set_extra" );
             GEN_PREFIX( "get_in" );
@@ -580,6 +582,7 @@ int exit_status;
             fprintf(header_out,"#undef YY_MORE_ADJ\n");
             fprintf(header_out,"#undef YY_NEED_STRLEN\n");
             fprintf(header_out,"#undef YY_NEW_FILE\n");
+            fprintf(header_out,"#undef YY_NO_GET_DEBUG\n");
             fprintf(header_out,"#undef YY_NO_GET_EXTRA\n");
             fprintf(header_out,"#undef YY_NO_GET_IN\n");
             fprintf(header_out,"#undef YY_NO_GET_LENG\n");
@@ -594,6 +597,7 @@ int exit_status;
             fprintf(header_out,"#undef YY_NO_SCAN_BUFFER\n");
             fprintf(header_out,"#undef YY_NO_SCAN_BYTES\n");
             fprintf(header_out,"#undef YY_NO_SCAN_STRING\n");
+            fprintf(header_out,"#undef YY_NO_SET_DEBUG\n");
             fprintf(header_out,"#undef YY_NO_SET_EXTRA\n");
             fprintf(header_out,"#undef YY_NO_SET_IN\n");
             fprintf(header_out,"#undef YY_NO_SET_LINENO\n");
diff --git a/scan.l b/scan.l
index 723704c40825e85c159a9a6943636c0fc0bb72e8..3c341a209353ad45ad32cb686fc1de30b4bb561f 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -286,6 +286,8 @@ LEXOPT              [aceknopr]
        yy_scan_bytes   ACTION_IFDEF("YY_NO_SCAN_BYTES", ! option_sense);
        yy_scan_string  ACTION_IFDEF("YY_NO_SCAN_STRING", ! option_sense);
 
+    yyget_debug     ACTION_IFDEF("YY_NO_GET_DEBUG", ! option_sense);
+    yyset_debug     ACTION_IFDEF("YY_NO_SET_DEBUG", ! option_sense);
     yyget_extra     ACTION_IFDEF("YY_NO_GET_EXTRA", ! option_sense);
     yyset_extra     ACTION_IFDEF("YY_NO_SET_EXTRA", ! option_sense);
     yyget_leng      ACTION_IFDEF("YY_NO_GET_LENG", ! option_sense);
index 895dd72b864b51718a4ee88efc7e33c3f40a299f..4a32c2440f892b422bc5b41a7b26921ce1ecadcb 100644 (file)
@@ -26,6 +26,8 @@ noinst_SCRIPTS = \
        create-test
 
 SUBDIRS = \
+       test-debug-nr \
+       test-debug-r \
        test-lineno-r \
        test-lineno-nr \
        TEMPLATE \
diff --git a/tests/test-debug-nr/.cvsignore b/tests/test-debug-nr/.cvsignore
new file mode 100644 (file)
index 0000000..689066f
--- /dev/null
@@ -0,0 +1,9 @@
+Makefile
+Makefile.in
+parser.c
+parser.h
+scanner.c
+TEMPLATE
+OUTPUT
+.deps
+test-debug-nr
diff --git a/tests/test-debug-nr/Makefile.am b/tests/test-debug-nr/Makefile.am
new file mode 100644 (file)
index 0000000..4096694
--- /dev/null
@@ -0,0 +1,44 @@
+# This file is part of flex.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+
+# Neither the name of the University nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE.
+
+BISON = @BISON@
+FLEX = $(top_builddir)/flex
+
+EXTRA_DIST = scanner.l test.input
+CLEANFILES = scanner.c scanner.h test-debug-nr OUTPUT $(OBJS)
+OBJS = scanner.o
+
+INCLUDES = -I $(srcdir) -I $(top_srcdir) -I $(top_builddir) -I .
+#LDFLAGS = $(top_srcdir)/libfl.a 
+
+testname = test-debug-nr
+
+scanner.c: $(srcdir)/scanner.l
+       $(FLEX) $(LFLAGS) $<
+
+$(testname)$(EXEEXT): $(OBJS)
+       $(CC) -o $@ $(OBJS) $(LDFLAGS)
+
+test: $(testname)$(EXEEXT)
+       ./$(testname)$(EXEEXT) < $(srcdir)/test.input
+
+.c.o:
+       $(CC) -c -o $@ $(INCLUDES) $<
diff --git a/tests/test-debug-nr/scanner.l b/tests/test-debug-nr/scanner.l
new file mode 100644 (file)
index 0000000..4a4a26f
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * This file is part of flex.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+%{
+/* A template scanner file to build "scanner.c". */
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+
+%}
+
+%option 8bit outfile="scanner.c" prefix="test"
+%option nounput nomain noyywrap 
+%option warn debug
+
+%%
+.+   { }
+\n   { }
+%%
+
+int
+main ( int argc, char** argv )
+{
+    yyin = stdin;
+    yyout = stdout;
+    yy_flex_debug = 1;
+    yylex();
+    printf("TEST RETURNING OK.\n");
+    return 0;
+}
diff --git a/tests/test-debug-nr/test.input b/tests/test-debug-nr/test.input
new file mode 100644 (file)
index 0000000..8d6476c
--- /dev/null
@@ -0,0 +1,2 @@
+Any input will do for this test.
+We are only testing if it actually runs in debug mode.
diff --git a/tests/test-debug-r/.cvsignore b/tests/test-debug-r/.cvsignore
new file mode 100644 (file)
index 0000000..d2b0c7c
--- /dev/null
@@ -0,0 +1,9 @@
+Makefile
+Makefile.in
+parser.c
+parser.h
+scanner.c
+TEMPLATE
+OUTPUT
+.deps
+test-debug-r
diff --git a/tests/test-debug-r/Makefile.am b/tests/test-debug-r/Makefile.am
new file mode 100644 (file)
index 0000000..76595cd
--- /dev/null
@@ -0,0 +1,44 @@
+# This file is part of flex.
+
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+
+# Neither the name of the University nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE.
+
+BISON = @BISON@
+FLEX = $(top_builddir)/flex
+
+EXTRA_DIST = scanner.l test.input
+CLEANFILES = scanner.c test-debug-r OUTPUT $(OBJS)
+OBJS = scanner.o 
+
+INCLUDES = -I $(srcdir) -I $(top_srcdir) -I $(top_builddir) -I .
+#LDFLAGS = $(top_srcdir)/libfl.a 
+
+testname = test-debug-r
+
+scanner.c: $(srcdir)/scanner.l
+       $(FLEX) $(LFLAGS) $<
+
+$(testname)$(EXEEXT): $(OBJS)
+       $(CC) -o $@ $(OBJS) $(LDFLAGS)
+
+test: $(testname)$(EXEEXT)
+       ./$(testname)$(EXEEXT) < $(srcdir)/test.input
+
+.c.o:
+       $(CC) -c -o $@ $(INCLUDES) $<
diff --git a/tests/test-debug-r/scanner.l b/tests/test-debug-r/scanner.l
new file mode 100644 (file)
index 0000000..af85722
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * This file is part of flex.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+%{
+/* A template scanner file to build "scanner.c". */
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+
+%}
+
+%option 8bit outfile="scanner.c" prefix="test"
+%option nounput nomain noyywrap 
+%option warn debug reentrant
+
+%%
+.+   { }
+\n   { }
+%%
+
+int main (int argc, char** argv )
+{
+    yyscan_t  lexer;
+    yylex_init( &lexer );
+    yyset_out ( stdout,lexer);
+    yyset_in  ( stdin, lexer);
+    
+    /* Just see if the next line compiles. */
+    testset_debug (testget_debug(lexer), lexer);
+    
+    while( yylex(lexer) )
+    {
+    }
+    yylex_destroy( lexer );
+    printf("TEST RETURNING OK.\n");
+    return 0;
+}
diff --git a/tests/test-debug-r/test.input b/tests/test-debug-r/test.input
new file mode 100644 (file)
index 0000000..8d6476c
--- /dev/null
@@ -0,0 +1,2 @@
+Any input will do for this test.
+We are only testing if it actually runs in debug mode.