summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flex.skl84
-rw-r--r--misc.c57
2 files changed, 73 insertions, 68 deletions
diff --git a/flex.skl b/flex.skl
index 7fe6791..ac7eeff 100644
--- a/flex.skl
+++ b/flex.skl
@@ -12,12 +12,15 @@
%# %c++-only - The following lines are printed for C++ scanners ONLY.
%# %c-only - The following lines are NOT printed for C++ scanners.
%# %c-or-c++ - The following lines are printed in BOTH C and C++ scanners.
+%# %if-reentrant - Print for reentrant scanners.(push)
+%# %if-not-reentrant - Print for non-reentrant scanners. (push)
+%# %endif - Same as pop.
%# %% - A stop-point, where code is inserted by flex.
%# Each stop-point is numbered here and also in the code generator.
%# (See gen.c, etc. for details.)
%# %not-for-header - Begin code that should NOT appear in a ".h" file.
%# %ok-for-header - %c and %e are used for building a header file.
-%# %tables-serialization-code-begin
+%# %if-tables-serialization
%#
%# All control-lines EXCEPT comment lines ("%#") will be inserted into
%# the generated scanner as a C-style comment. This is to aid those who
@@ -39,10 +42,9 @@
#include <stdint.h>
%pop
-%push
-%tables-serialization-code-begin
+%if-tables-serialization
#include <netinet/in.h>
-%pop
+%endif
/* end standard C headers. */
%push
@@ -111,7 +113,7 @@
*/
#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-#ifdef YY_REENTRANT
+%if-reentrant
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -151,8 +153,9 @@ typedef void* yyscan_t;
#define yy_flex_debug YY_G(yy_flex_debug_r)
int yylex_init YY_PARAMS((yyscan_t* scanner));
+%endif
-#else /* not YY_REENTRANT */
+%if-not-reentrant
/* Define these macros to be no-ops. */
#define YY_G(var) (var)
@@ -168,7 +171,7 @@ int yylex_init YY_PARAMS((yyscan_t* scanner));
#define YY_CALL_LAST_ARG
#define YY_CALL_ONLY_ARG
-#endif
+%endif
/* For compilers that need traditional function definitions.
@@ -231,15 +234,15 @@ int yylex_init YY_PARAMS((yyscan_t* scanner));
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
-#ifndef YY_REENTRANT
+%if-not-reentrant
extern size_t yyleng;
-#endif
+%endif
%push
%c-only
-#ifndef YY_REENTRANT
+%if-not-reentrant
extern FILE *yyin, *yyout;
-#endif
+%endif
%pop
#define EOB_ACT_CONTINUE_SCAN 0
@@ -377,9 +380,9 @@ struct yy_buffer_state
%push
%c-only Standard (non-C++) definition
%not-for-header
-#ifndef YY_REENTRANT
+%if-not-reentrant
static YY_BUFFER_STATE yy_current_buffer = 0;
-#endif
+%endif
%ok-for-header
%pop
@@ -392,7 +395,7 @@ static YY_BUFFER_STATE yy_current_buffer = 0;
%push
%c-only Standard (non-C++) definition
-#ifndef YY_REENTRANT
+%if-not-reentrant
%not-for-header
/* yy_hold_char holds the character lost when yytext is formed. */
static char yy_hold_char;
@@ -412,7 +415,7 @@ static int yy_start = 0; /* start state number */
*/
static int yy_did_buffer_switch_on_eof;
%ok-for-header
-#endif /* end !YY_REENTRANT */
+%endif
void yyrestart YY_PARAMS(( FILE *input_file YY_PROTO_LAST_ARG ));
@@ -507,7 +510,7 @@ static void yy_fatal_error YY_PARAMS(( yyconst char msg[] YY_PROTO_LAST_ARG ));
%push
%c-only Reentrant structure and macros (non-C++).
-#ifdef YY_REENTRANT
+%if-reentrant
%not-for-header
/* Holds the entire state of the reentrant scanner. */
@@ -571,17 +574,18 @@ static int yy_init_globals YY_PARAMS(( YY_PROTO_ONLY_ARG ));
%not-for-header These go in the .c file only.
/* This must go here because YYSTYPE and YYLSTYPE are included
* from bison output in section 1.*/
-#ifdef YY_REENTRANT
+%if-reentrant
#ifdef YY_BISON_BRIDGE
# define yylval YY_G(yylval_r)
# ifdef YYLTYPE
# define yylloc YY_G(yylloc_r)
# endif
#endif /* YY_BISON_BRIDGE */
-#endif /* YY_REENTRANT */
+%endif
+
%ok-for-header
-#endif /* end if YY_REENTRANT */
+%endif
/* Accessor methods to globals.
These are made visible to non-reentrant scanners for convenience. */
@@ -695,13 +699,14 @@ static int input YY_PARAMS(( YY_PROTO_ONLY_ARG ));
#if YY_STACK_USED
-#ifndef YY_REENTRANT
+%if-not-reentrant
%not-for-header
static int yy_start_stack_ptr = 0;
static int yy_start_stack_depth = 0;
static int *yy_start_stack = 0;
%ok-for-header
-#endif
+%endif
+
#ifndef YY_NO_PUSH_STATE
static void yy_push_state YY_PARAMS(( int new_state YY_PROTO_LAST_ARG));
#endif
@@ -774,8 +779,7 @@ static int yy_top_state YY_PARAMS(( YY_PROTO_ONLY_ARG ));
%pop
#endif
-%push
-%tables-serialization-code-begin structures and prototypes
+%if-tables-serialization structures and prototypes
m4_include(`tables_shared.h')
/* Load the DFA tables from the given stream. */
@@ -808,7 +812,7 @@ struct yytbl_reader {
uint32_t bread; /**< bytes read since beginning of current tableset */
};
-%pop
+%endif
/* end tables serialization structures and prototypes */
%ok-for-header
@@ -867,12 +871,12 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#ifdef YY_BISON_BRIDGE
-# ifndef YY_REENTRANT
+%if-not-reentrant
YYSTYPE * yylval;
# ifdef YYLTYPE
YYLTYPE * yylloc;
# endif
-# endif
+%endif
#endif
%% [7.0] user's declarations go here
@@ -1864,14 +1868,14 @@ void yyFlexLexer::LexerError( yyconst char msg[] )
%push
%c-only
-#ifdef YY_REENTRANT
+%if-reentrant
#ifndef YY_NO_GET_EXTRA
YY_EXTRA_TYPE yyget_extra YYFARGS0(void)
{
return yyextra;
}
#endif /* !YY_NO_GET_EXTRA */
-#endif /* YY_REENTRANT */
+%endif
#ifndef YY_NO_GET_LINENO
int yyget_lineno YYFARGS0(void)
@@ -1908,14 +1912,14 @@ char *yyget_text YYFARGS0(void)
}
#endif /* !YY_NO_GET_TEXT */
-#ifdef YY_REENTRANT
+%if-reentrant
#ifndef YY_NO_SET_EXTRA
void yyset_extra YYFARGS1( YY_EXTRA_TYPE ,user_defined)
{
yyextra = user_defined ;
}
#endif /* !YY_NO_SET_EXTRA */
-#endif /* YY_REENTRANT */
+%endif
#ifndef YY_NO_SET_LINENO
void yyset_lineno YYFARGS1( int ,line_number)
@@ -1955,7 +1959,7 @@ void yyset_debug YYFARGS1( int ,bdebug)
#endif /* !YY_NO_SET_DEBUG */
%pop
-#ifdef YY_REENTRANT
+%if-reentrant
/* Accessor methods for yylval and yylloc */
#ifdef YY_BISON_BRIDGE
@@ -2067,7 +2071,7 @@ int yylex_init( ptr_yy_globals )
return yy_init_globals ( *ptr_yy_globals );
}
-#endif /* End YY_REENTRANT */
+%endif
/* yylex_destroy is for both reentrant and non-reentrant scanners. */
int yylex_destroy YYFARGS0(void)
@@ -2090,10 +2094,10 @@ int yylex_destroy YYFARGS0(void)
yyfree ( YY_G(yy_state_buf) YY_CALL_LAST_ARG);
#endif
-#ifdef YY_REENTRANT
+%if-reentrant
/* Destroy the main struct (reentrant only). */
yyfree ( yyscanner YY_CALL_LAST_ARG );
-#endif
+%endif
%pop
return 0;
}
@@ -2155,8 +2159,7 @@ void yyfree YYFARGS1( void *,ptr)
}
#endif
-%push
-%tables-serialization-code-begin definitions
+%if-tables-serialization definitions
m4_include(`tables_shared.c')
static int yytbl_read8 (void *v, struct yytbl_reader * rd)
@@ -2544,7 +2547,7 @@ int yytables_destroy YYFARGS0(void)
}
/* end table serialization code definitions */
-%pop
+%endif
#if YY_MAIN
int main YY_PARAMS((void));
@@ -2552,15 +2555,16 @@ int main YY_PARAMS((void));
int main ()
{
-#ifdef YY_REENTRANT
+%if-reentrant
yyscan_t lexer;
yylex_init(&lexer);
yylex( lexer );
yylex_destroy( lexer);
-#else
+%endif
+%if-not-reentrant
yylex();
-#endif
+%endif
return 0;
}
diff --git a/misc.c b/misc.c
index 056ec47..bab3df6 100644
--- a/misc.c
+++ b/misc.c
@@ -34,8 +34,7 @@
#include "flexdef.h"
#include "tables.h"
-#define CMD_TABLES_SER_BEGIN "%tables-serialization-code-begin"
-#define CMD_TABLES_SER_END "%tables-serialization-code-end"
+#define CMD_IF_TABLES_SER "%if-tables-serialization"
#define CMD_TABLES_YYDMAP "%tables-yydmap"
#define CMD_DEFINE_YYTABLES "%define-yytables"
#define CMD_CPP_ONLY "%c++-only"
@@ -45,15 +44,17 @@
#define CMD_OK_FOR_HEADER "%ok-for-header"
#define CMD_PUSH "%push"
#define CMD_POP "%pop"
+#define CMD_IF_REENTRANT "%if-reentrant"
+#define CMD_IF_NOT_REENTRANT "%if-not-reentrant"
+#define CMD_ENDIF "%endif"
/* we allow the skeleton to push and pop. */
struct sko_state {
bool dc; /**< do_copy */
- bool tt; /**< tables_toggle */
};
static struct sko_state *sko_stack=0;
static int sko_len=0,sko_sz=0;
-static void sko_push(bool dc, bool tt)
+static void sko_push(bool dc)
{
if(!sko_stack){
sko_sz = 1;
@@ -67,21 +68,18 @@ static void sko_push(bool dc, bool tt)
/* initialize to zero and push */
sko_stack[sko_len].dc = dc;
- sko_stack[sko_len].tt = tt;
sko_len++;
}
-static void sko_peek(bool *dc, bool* tt)
+static void sko_peek(bool *dc)
{
if(sko_len <= 0)
flex_die("peek attempt when sko stack is empty");
if(dc)
*dc = sko_stack[sko_len-1].dc;
- if(tt)
- *tt = sko_stack[sko_len-1].tt;
}
-static void sko_pop(bool* dc, bool *tt)
+static void sko_pop(bool* dc)
{
- sko_peek(dc,tt);
+ sko_peek(dc);
sko_len--;
if(sko_len < 0)
flex_die("popped too many times in skeleton.");
@@ -856,13 +854,12 @@ void skelout ()
char buf_storage[MAXLINE];
char *buf = buf_storage;
bool do_copy = true;
- bool tablestoggle=false;
/* "reset" the state by clearing the buffer and pushing a '1' */
if(sko_len > 0)
- sko_peek(&do_copy,&tablestoggle);
+ sko_peek(&do_copy);
sko_len = 0;
- sko_push(do_copy=true,tablestoggle);
+ sko_push(do_copy=true);
/* Loop pulling lines either from the skelfile, if we're using
@@ -897,26 +894,32 @@ void skelout ()
return;
}
else if (cmd_match (CMD_PUSH)){
- sko_push(do_copy,tablestoggle);
+ sko_push(do_copy);
if(ddebug){
- out_str("/*(state = (%s,",do_copy?"true":"false");
- out_str( "%s)*/",tablestoggle?"true":"false");
+ out_str("/*(state = (%s) */",do_copy?"true":"false");
out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
}
}
else if (cmd_match (CMD_POP)){
- sko_pop(&do_copy,&tablestoggle);
+ sko_pop(&do_copy);
if(ddebug){
- out_str("/*(state = (%s,",do_copy?"true":"false");
- out_str( "%s)*/",tablestoggle?"true":"false");
+ out_str("/*(state = (%s) */",do_copy?"true":"false");
out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : "");
}
}
- else if (cmd_match (CMD_TABLES_SER_BEGIN)) {
- tablestoggle = true;
- }
- else if (cmd_match (CMD_TABLES_SER_END)) {
- tablestoggle = false;
+ else if (cmd_match (CMD_IF_REENTRANT)){
+ sko_push(do_copy);
+ do_copy = reentrant && do_copy;
+ }
+ else if (cmd_match (CMD_IF_NOT_REENTRANT)){
+ sko_push(do_copy);
+ do_copy = !reentrant && do_copy;
+ }
+ else if (cmd_match (CMD_ENDIF)){
+ sko_pop(&do_copy);
+ }
+ else if (cmd_match (CMD_IF_TABLES_SER)) {
+ do_copy = do_copy && tablesext;
}
else if (cmd_match (CMD_TABLES_YYDMAP)) {
if (tablesext && yydmap_buf.elts)
@@ -954,10 +957,8 @@ void skelout ()
}
}
- else if (do_copy) {
- if (tablesext || !tablestoggle)
- outn (buf);
- }
+ else if (do_copy)
+ outn (buf);
} /* end while */
}