]> granicus.if.org Git - flex/commitdiff
Serialization works in headers (%option headers).
authorJohn Millaway <john43@users.sourceforge.net>
Mon, 16 Sep 2002 18:38:46 +0000 (18:38 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Mon, 16 Sep 2002 18:38:46 +0000 (18:38 +0000)
Serialization code (Tables API) is complete.

TODO
flex.skl
flex.texi
main.c
tables_shared.h
tests/test-multiple-scanners-r/main.c
tests/test-multiple-scanners-r/scanner-1.l
tests/test-multiple-scanners-r/scanner-2.l

diff --git a/TODO b/TODO
index 0d38515b4e361255c44633defc14722df193f038..79134477545ab861b7a791db5a60b5fa4bc9393c 100644 (file)
--- a/TODO
+++ b/TODO
 
 ** 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
index 858a011836e0b5f1b386182db49b8733975b2dd3..64d559f5449f62aa4495e750a7416fbe937c1b31 100644 (file)
--- 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.
index 1e0b49971e603066be856e1e47e3d4516ba5960a..f0004ed31c45548b1737dc5296362f114859b666 100644 (file)
--- 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 19ed11bb16f68bb8c3a7ba3c374488e2252e7815..f6112a09c27fd8ff00f7f18aee29e6f9a4b0abba 100644 (file)
--- 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 ("");
        }
 
index f52ee23137f9dc1f876b1eb6361e6e384a9e9206..a46c05755615929550d102d45b740240930c6c5c 100644 (file)
@@ -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: */
index 7ea1037afe8355405f91017e1f9def86da2be836..3c07266dc3fd65e395597d00725b7bf4bd0a8bec 100644 (file)
@@ -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");
index 9fa1bc0ced41c1e38d67e811de874bd898f61320..84f87192b5219fe122241637d6fa4c05be0dfd1a 100644 (file)
@@ -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
index 209ceca6b8cde6482babb4d103695d0bb045fcab..f0d5c2dd0c7ade93a29fee556b83d4f53ba04c4e 100644 (file)
@@ -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