From: John Millaway Date: Mon, 16 Sep 2002 18:38:46 +0000 (+0000) Subject: Serialization works in headers (%option headers). X-Git-Tag: flex-2-5-20~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5aebd0ff8a443e7dc59cee12526c76f3ab6255bc;p=flex Serialization works in headers (%option headers). Serialization code (Tables API) is complete. --- diff --git a/TODO b/TODO index 0d38515..7913447 100644 --- a/TODO +++ b/TODO @@ -50,10 +50,6 @@ ** revisit the C++ API. We get requests to make it more complete. -* Tables API - -** verify that new macros/functions work with %option header-file - * build system ** use bootstrapper diff --git a/flex.skl b/flex.skl index 858a011..64d559f 100644 --- a/flex.skl +++ b/flex.skl @@ -763,6 +763,7 @@ int yytables_fload YY_PARAMS ((FILE * fp YY_PROTO_LAST_ARG)); /* Unload the tables from memory. */ int yytables_destroy YY_PARAMS ((YY_PROTO_ONLY_ARG)); +%not-for-header /** Describes a mapping from a serialized table id to its deserialized state in * this scanner. This is the bridge between our "generic" deserialization code @@ -788,6 +789,7 @@ struct yytbl_reader { }; %tables-serialization-code-end structures and prototypes +%ok-for-header /* Default declaration of generated scanner - a define so the user can * easily add parameters. diff --git a/flex.texi b/flex.texi index 1e0b499..f0004ed 100644 --- a/flex.texi +++ b/flex.texi @@ -4758,8 +4758,6 @@ pooled memory mechanism will save you a lot of grief when writing parsers. @cindex serialization @cindex memory, serialized tables -@strong{This feature is currently under development. -It should be considered alpha quality.} @anchor{serialization} A @code{flex} scanner has the ability to save the DFA tables to a file, and load them runtime when needed. The motivation for this feature is to reduce diff --git a/main.c b/main.c index 19ed11b..f6112a0 100644 --- a/main.c +++ b/main.c @@ -440,6 +440,12 @@ void check_options () if (do_yywrap) GEN_PREFIX ("wrap"); + if (tablesext){ + GEN_PREFIX ("tables_fload"); + GEN_PREFIX ("tables_destroy"); + GEN_PREFIX ("TABLES_NAME"); + } + outn (""); } diff --git a/tables_shared.h b/tables_shared.h index f52ee23..a46c057 100644 --- a/tables_shared.h +++ b/tables_shared.h @@ -69,6 +69,8 @@ dnl flex code (hence the name "_shared"). #endif +#ifndef YYTABLES_TYPES +#define YYTABLES_TYPES /** Possible values for td_id field. Each one corresponds to a * scanner table of the same name. */ @@ -119,6 +121,7 @@ struct yytbl_data { uint32_t td_lolen; /**< num elements in lowest dimension array */ void *td_data; /**< table data */ }; +#endif /** Extract corresponding data size_t from td_flags */ #ifndef YYTDFLAGS2BYTES @@ -130,6 +133,12 @@ struct yytbl_data { :sizeof(int32_t))) #endif +#ifdef FLEX_SCANNER +%not-for-header +#endif yyskel_static int32_t yytbl_calc_total_len (const struct yytbl_data *tbl); +#ifdef FLEX_SCANNER +%ok-for-header +#endif /* vim:set noexpandtab cindent tabstop=8 softtabstop=0 shiftwidth=8 textwidth=0: */ diff --git a/tests/test-multiple-scanners-r/main.c b/tests/test-multiple-scanners-r/main.c index 7ea1037..3c07266 100644 --- a/tests/test-multiple-scanners-r/main.c +++ b/tests/test-multiple-scanners-r/main.c @@ -28,12 +28,33 @@ int main ( int argc, char** argv ) { int S1_ok=1, S2_ok=1; + FILE * fp; YY_BUFFER_STATE buff1, buff2; yyscan_t scan1, scan2; S1_lex_init(&scan1); S2_lex_init(&scan2); + if((fp = fopen("scanner-1.tables","r")) == 0){ + fprintf(stderr,"Could not open scanner-1.tables.\n"); + exit(1); + } + if(S1_tables_fload(fp,scan1) != 0){ + fprintf(stderr,"Could not load scanner-1.tables.\n"); + exit(1); + } + fclose(fp); + + if((fp = fopen("scanner-2.tables","r")) == 0){ + fprintf(stderr,"Could not open scanner-2.tables.\n"); + exit(1); + } + if(S2_tables_fload(fp,scan2) != 0){ + fprintf(stderr,"Could not load scanner-2.tables.\n"); + exit(1); + } + fclose(fp); + S1_set_out(stdout,scan1); S2_set_out(S1_get_out(scan1),scan2); @@ -51,6 +72,9 @@ main ( int argc, char** argv ) S1__delete_buffer(buff1, scan1); S2__delete_buffer(buff2, scan2); + S1_tables_destroy(scan1); + S2_tables_destroy(scan2); + S1_lex_destroy(scan1); S2_lex_destroy(scan2); printf("TEST RETURNING OK.\n"); diff --git a/tests/test-multiple-scanners-r/scanner-1.l b/tests/test-multiple-scanners-r/scanner-1.l index 9fa1bc0..84f8719 100644 --- a/tests/test-multiple-scanners-r/scanner-1.l +++ b/tests/test-multiple-scanners-r/scanner-1.l @@ -33,6 +33,7 @@ %option 8bit outfile="scanner-1.c" prefix="S1_" %option nounput nomain noyywrap noyy_top_state %option warn stack reentrant +%option tables-file="scanner-1.tables" %x ON %x OFF diff --git a/tests/test-multiple-scanners-r/scanner-2.l b/tests/test-multiple-scanners-r/scanner-2.l index 209ceca..f0d5c2d 100644 --- a/tests/test-multiple-scanners-r/scanner-2.l +++ b/tests/test-multiple-scanners-r/scanner-2.l @@ -33,6 +33,7 @@ %option 8bit outfile="scanner-2.c" prefix="S2_" %option nounput nomain noyywrap %option warn stack reentrant noyy_top_state +%option tables-file="scanner-2.tables" %x OFF %x ON