[BACK]Return to tables_shared.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / lex

Annotation of src/usr.bin/lex/tables_shared.h, Revision 1.2

1.2     ! tedu        1: /* $OpenBSD: tables_shared.h,v 1.1 2015/11/19 19:43:40 tedu Exp $ */
1.1       tedu        2:
                      3: #ifdef FLEX_SCANNER
                      4: /*
                      5: dnl  tables_shared.h - tables serialization header
                      6: dnl
                      7: dnl  Copyright (c) 1990 The Regents of the University of California.
                      8: dnl  All rights reserved.
                      9: dnl
                     10: dnl  This code is derived from software contributed to Berkeley by
                     11: dnl  Vern Paxson.
                     12: dnl
                     13: dnl  The United States Government has rights in this work pursuant
                     14: dnl  to contract no. DE-AC03-76SF00098 between the United States
                     15: dnl  Department of Energy and the University of California.
                     16: dnl
                     17: dnl  This file is part of flex.
                     18: dnl
                     19: dnl  Redistribution and use in source and binary forms, with or without
                     20: dnl  modification, are permitted provided that the following conditions
                     21: dnl  are met:
                     22: dnl
                     23: dnl  1. Redistributions of source code must retain the above copyright
                     24: dnl     notice, this list of conditions and the following disclaimer.
                     25: dnl  2. Redistributions in binary form must reproduce the above copyright
                     26: dnl     notice, this list of conditions and the following disclaimer in the
                     27: dnl     documentation and/or other materials provided with the distribution.
                     28: dnl
                     29: dnl  Neither the name of the University nor the names of its contributors
                     30: dnl  may be used to endorse or promote products derived from this software
                     31: dnl  without specific prior written permission.
                     32: dnl
                     33: dnl  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     34: dnl  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     35: dnl  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     36: dnl  PURPOSE.
                     37: 
                     38: dnl
                     39: dnl  This file is meant to be included in both the skeleton and the actual
                     40: dnl  flex code (hence the name "_shared").
                     41: */
                     42: #ifndef yyskel_static
                     43: #define yyskel_static static
                     44: #endif
                     45: #else
                     46: #ifndef yyskel_static
                     47: #define yyskel_static
                     48: #endif
                     49: #endif
                     50:
                     51: /* Structures and prototypes for serializing flex tables.  The
                     52:  * binary format is documented in the manual.
                     53:  *
                     54:  * Design considerations:
                     55:  *
                     56:  *  -  The format allows many tables per file.
                     57:  *  -  The tables can be streamed.
                     58:  *  -  All data is stored in network byte order.
                     59:  *  -  We do not hinder future unicode support.
                     60:  *  -  We can lookup tables by name.
                     61:  */
                     62:
                     63: /** Magic number for serialized format. */
                     64: #ifndef YYTBL_MAGIC
                     65: #define YYTBL_MAGIC 0xF13C57B1
                     66: #endif
                     67:
                     68: /** Calculate (0-7) = number bytes needed to pad n to next 64-bit boundary. */
                     69: #ifndef yypad64
                     70: #define yypad64(n) ((8-((n)%8))%8)
                     71: #endif
                     72:
                     73:
                     74: #ifndef YYTABLES_TYPES
                     75: #define YYTABLES_TYPES
                     76: /** Possible values for td_id field. Each one corresponds to a
                     77:  *  scanner table of the same name.
                     78:  */
                     79: enum yytbl_id {
                     80:        YYTD_ID_ACCEPT = 0x01,          /**< 1-dim ints */
                     81:        YYTD_ID_BASE = 0x02,            /**< 1-dim ints */
                     82:        YYTD_ID_CHK = 0x03,             /**< 1-dim ints */
                     83:        YYTD_ID_DEF = 0x04,             /**< 1-dim ints */
                     84:        YYTD_ID_EC = 0x05,              /**< 1-dim ints */
                     85:        YYTD_ID_META = 0x06,            /**< 1-dim ints */
                     86:        YYTD_ID_NUL_TRANS = 0x07,       /**< 1-dim ints, maybe indices */
                     87:        YYTD_ID_NXT = 0x08,             /**< may be 2 dimensional ints */
                     88:        YYTD_ID_RULE_CAN_MATCH_EOL = 0x09, /**< 1-dim ints */
                     89:        YYTD_ID_START_STATE_LIST = 0x0A,        /**< 1-dim indices into trans tbl  */
                     90:        YYTD_ID_TRANSITION = 0x0B,      /**< structs */
                     91:        YYTD_ID_ACCLIST = 0x0C          /**< 1-dim ints */
                     92: };
                     93:
                     94: /** bit flags for t_flags field of struct yytbl_data */
                     95: enum yytbl_flags {
                     96:        /* These first three are mutually exclusive */
                     97:        YYTD_DATA8 = 0x01,   /**< data is an array of type flex_int8_t */
                     98:        YYTD_DATA16 = 0x02,  /**< data is an array of type flex_int16_t */
                     99:        YYTD_DATA32 = 0x04,  /**< data is an array of type flex_int32_t */
                    100:
                    101:        /* These two are mutually exclusive. */
                    102:        YYTD_PTRANS = 0x08,  /**< data is a list of indexes of entries
                    103:                                  into the expanded `yy_transition'
                    104:                                  array. See notes in manual. */
                    105:        YYTD_STRUCT = 0x10  /**< data consists of yy_trans_info structs */
                    106: };
                    107:
                    108: /* The serialized tables header. */
                    109: struct yytbl_hdr {
                    110:        flex_uint32_t th_magic;  /**< Must be 0xF13C57B1 (comes from "Flex Table") */
                    111:        flex_uint32_t th_hsize;  /**< Size of this header in bytes. */
                    112:        flex_uint32_t th_ssize;  /**< Size of this dataset, in bytes, including header. */
                    113:        flex_uint16_t th_flags;  /**< Currently unused, must be 0 */
                    114:        char   *th_version; /**< Flex version string. NUL terminated. */
                    115:        char   *th_name;    /**< The name of this table set. NUL terminated. */
                    116: };
                    117:
                    118: /** A single serialized table */
                    119: struct yytbl_data {
                    120:        flex_uint16_t td_id;      /**< enum yytbl_id table identifier */
                    121:        flex_uint16_t td_flags;   /**< how to interpret this data */
                    122:        flex_uint32_t td_hilen;   /**< num elements in highest dimension array */
                    123:        flex_uint32_t td_lolen;   /**< num elements in lowest dimension array */
                    124:        void   *td_data;     /**< table data */
                    125: };
                    126: #endif
                    127:
                    128: /** Extract corresponding data size_t from td_flags */
                    129: #ifndef YYTDFLAGS2BYTES
                    130: #define YYTDFLAGS2BYTES(td_flags)\
                    131:         (((td_flags) & YYTD_DATA8)\
                    132:             ? sizeof(flex_int8_t)\
                    133:             :(((td_flags) & YYTD_DATA16)\
                    134:                 ? sizeof(flex_int16_t)\
                    135:                 :sizeof(flex_int32_t)))
                    136: #endif
                    137:
                    138: #ifdef FLEX_SCANNER
                    139: %not-for-header
                    140: #endif
                    141: yyskel_static flex_int32_t yytbl_calc_total_len (const struct yytbl_data *tbl);
                    142: #ifdef FLEX_SCANNER
                    143: %ok-for-header
                    144: #endif