]> granicus.if.org Git - flex/commitdiff
Introduce %option extra-type="your_type *" (resolves bug #1744505).
authorAaron Stone <sodabrew@users.sourceforge.net>
Mon, 10 Sep 2007 06:16:33 +0000 (06:16 +0000)
committerAaron Stone <sodabrew@users.sourceforge.net>
Mon, 10 Sep 2007 06:16:33 +0000 (06:16 +0000)
NEWS
doc/flex.texi
flex.skl
flexdef.h
main.c
parse.y
scan.l

diff --git a/NEWS b/NEWS
index 9b07c58c10a11bb6876d9f127d9b09a782bd5adc..712b28e3791bedb10f7317e84360a17bdec1fa4c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ See the file COPYING for copying conditions.
 
 ** introduce yylex_init_extra; see the manual for details
 
+** introduce %option extra-type="your_type *" (resolves bug #1744505)
+
 ** The flex program now parses multiple short concatenated options (resolves bug
   #1619820). Thanks to Petr Machata of Red Hat on this issue.
 
index e4a2f3d71170f0774cf3c8e89bd5dd345678ef43..f9a9e9ec9f0a5d96b201d050fdafc997dbb0a718 100644 (file)
@@ -4215,6 +4215,7 @@ after @code{yylex}, respectively.
 @example
 @verbatim
     int yylex_init ( yyscan_t * ptr_yy_globals ) ;
+    int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t * ptr_yy_globals ) ;
     int yylex ( yyscan_t yyscanner ) ;
     int yylex_destroy ( yyscan_t yyscanner ) ;
 @end verbatim
@@ -4359,10 +4360,8 @@ be accessed from within the very first yyalloc, used to allocate
 the scanner itself.
 
 By default, @code{YY_EXTRA_TYPE} is defined as type @code{void *}.  You
-will have to cast @code{yyextra} and the return value from
-@code{yyget_extra} to the appropriate value each time you access the
-extra data.  To avoid casting, you may override the default type by
-defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
+may redefine this type using @code{%option extra-type="your_type"} in 
+the scanner:
 
 @cindex YY_EXTRA_TYPE, defining your own type
 @example
@@ -4371,9 +4370,9 @@ defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
     %{
     #include <sys/stat.h>
     #include <unistd.h>
-    #define YY_EXTRA_TYPE  struct stat*
     %}
     %option reentrant
+    %option extra-type="struct stat *"
     %%
 
     __filesize__     printf( "%ld", yyextra->st_size  );
index b935c0a05b35e8d28eefd942f9a0505f3fdafaf7..fabb270c97d74094be9ae234586d209543523b29 100644 (file)
--- a/flex.skl
+++ b/flex.skl
@@ -332,7 +332,6 @@ m4_define( [[M4_YY_INCR_LINENO]],
     }while(0)
 ]])
 
-int yylex_init M4_YY_PARAMS(yyscan_t* scanner);
 %endif
 
 
@@ -780,9 +779,16 @@ m4_ifdef( [[M4_YY_NO_UNISTD_H]],,
 #endif
 ]])
 
+m4_ifdef( [[M4_EXTRA_TYPE_DEFS]],
+[[
+#define YY_EXTRA_TYPE M4_EXTRA_TYPE_DEFS
+]],
+[[
 #ifndef YY_EXTRA_TYPE
 #define YY_EXTRA_TYPE void *
 #endif
+]]
+)
 
 %if-c-only Reentrant structure and macros (non-C++).
 %if-reentrant
@@ -882,6 +888,10 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]],
     ]])
 ]])
 
+int yylex_init M4_YY_PARAMS(yyscan_t* scanner);
+
+int yylex_init_extra M4_YY_PARAMS( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
+
 %endif
 
 /* Accessor methods to globals.
index 29062c3bbcab48f778b475914b3a37269ca9b740..d038952d44ea422f9d400f564bda6d3464a5e8ee 100644 (file)
--- a/flexdef.h
+++ b/flexdef.h
@@ -448,7 +448,7 @@ extern const char *skel[];
 extern int skel_ind;
 extern char *infilename, *outfilename, *headerfilename;
 extern int did_outfilename;
-extern char *prefix, *yyclass;
+extern char *prefix, *yyclass, *extra_type;
 extern int do_stdinit, use_stdout;
 extern char **input_files;
 extern int num_input_files;
diff --git a/main.c b/main.c
index 90fcc022677a8d765846b5bf3336e8d370bd03ef..cec2d77d3ab639a6f30bdcb1e79ee14cd34ce9f4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -65,7 +65,7 @@ int     action_size, defs1_offset, prolog_offset, action_offset,
        action_index;
 char   *infilename = NULL, *outfilename = NULL, *headerfilename = NULL;
 int     did_outfilename;
-char   *prefix, *yyclass;
+char   *prefix, *yyclass, *extra_type = NULL;
 int     do_stdinit, use_stdout;
 int     onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
 int     onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
@@ -334,6 +334,9 @@ void check_options ()
     if (!ansi_func_protos)
         buf_m4_define( &m4defs_buf, "M4_YY_NO_ANSI_FUNC_PROTOS", NULL);
 
+    if (extra_type)
+        buf_m4_define( &m4defs_buf, "M4_EXTRA_TYPE_DEFS", extra_type);
+
        if (!use_stdout) {
                FILE   *prev_stdout;
 
diff --git a/parse.y b/parse.y
index 40debce0600b0767969e25a71c5d91e6a2746a8e..22d5933cf4a463d2a89ab33bb6f3c68a5675989f 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -1,7 +1,7 @@
 /* parse.y - parser for flex input */
 
 %token CHAR NUMBER SECTEND SCDECL XSCDECL NAME PREVCCL EOF_OP
-%token OPTION_OP OPT_OUTFILE OPT_PREFIX OPT_YYCLASS OPT_HEADER
+%token OPTION_OP OPT_OUTFILE OPT_PREFIX OPT_YYCLASS OPT_HEADER OPT_EXTRA_TYPE
 %token OPT_TABLES
 
 %token CCE_ALNUM CCE_ALPHA CCE_BLANK CCE_CNTRL CCE_DIGIT CCE_GRAPH
@@ -196,6 +196,8 @@ option              :  OPT_OUTFILE '=' NAME
                        outfilename = copy_string( nmstr );
                        did_outfilename = 1;
                        }
+               |  OPT_EXTRA_TYPE '=' NAME
+                       { extra_type = copy_string( nmstr ); }
                |  OPT_PREFIX '=' NAME
                        { prefix = copy_string( nmstr ); }
                |  OPT_YYCLASS '=' NAME
diff --git a/scan.l b/scan.l
index e06279fc6c9a60fc5a0a362fd572dbb14244e403..23158764112f69c20cc295f193ef07081be377ed 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -420,6 +420,7 @@ M4QEND      "]]"
     yyget_lloc      ACTION_M4_IFDEF("M4""_YY_NO_GET_LLOC", ! option_sense);
     yyset_lloc      ACTION_M4_IFDEF("M4""_YY_NO_SET_LLOC", ! option_sense);
 
+       extra-type      return OPT_EXTRA_TYPE;
        outfile         return OPT_OUTFILE;
        prefix          return OPT_PREFIX;
        yyclass         return OPT_YYCLASS;