sheepy

build system (sheepy) and package manager (spm) for C
git clone https://spartatek.se/git/sheepy.git
Log | Files | Refs | README | LICENSE

TokenPolicy (7130B)


      1 /* -*- C++ -*- vim: set syntax=cpp: 
      2  * (C) 2005-2009 Frank-Rene Schaefer
      3  *
      4  * NO INCLUDE GUARDS -- THIS FILE MIGHT BE INCLUDED TWICE FOR MULTIPLE
      5  *                      LEXICAL ANALYZERS
      6  *
      7  * NOT: #ifndef  __QUEX_INCLUDE_GUARD__TOKEN__TOKEN_POLICY
      8  * NOT: #define  __QUEX_INCLUDE_GUARD__TOKEN__TOKEN_POLICY              
      9  *
     10  * Instead of an include guard, there is an include indicator 
     11  *
     12  *         __QUEX_INCLUDE_INDICATOR__TOKEN_POLICY__
     13  *
     14  * If the indicator is defined at the entry of this file, all internally 
     15  * defined macros are undefined right at the beginning, so they can be 
     16  * safely redefined.                                                     */
     17 #ifdef __QUEX_INCLUDE_INDICATOR__TOKEN_POLICY__
     18 #    undef QUEX_ASSERT_NO_TOKEN_SENDING_AFTER_TOKEN_TERMINATION
     19 #    undef QUEX_TOKEN_POLICY_PREPARE_NEXT
     20 #    undef __QUEX_TOKEN_POLICY_SET_ID
     21 #    undef __QUEX_ASSERT_SEND_ENTRY
     22 #    undef __QUEX_CURRENT_TOKEN_P
     23 #    undef __QUEX_STAMP_COLUMN_NUMBER
     24 #    undef __QUEX_STAMP_LINE_NUMBER
     25 #    undef self_token_get_id
     26 #    undef self_token_set_id
     27 #else
     28 #    define __QUEX_INCLUDE_INDICATOR__TOKEN_POLICY__
     29 #endif
     30 /*_______________________________________________________________________*/
     31 
     32 #ifdef QUEX_OPTION_TOKEN_POLICY_QUEUE
     33 
     34 #   define __QUEX_CURRENT_TOKEN_P  (self._token_queue.write_iterator)
     35 
     36 #   define QUEX_TOKEN_POLICY_PREPARE_NEXT() \
     37            ++(self._token_queue.write_iterator); 
     38 
     39 #   if        defined(__QUEX_OPTION_PLAIN_C)
     40 #      define self_token_get_id()   __QUEX_CURRENT_TOKEN_P->_id
     41 #   else
     42 #      define self_token_get_id()   __QUEX_CURRENT_TOKEN_P->type_id()
     43 #   endif
     44 #   define self_token_set_id(ID)    __QUEX_TOKEN_POLICY_SET_ID(ID)
     45 
     46 #else
     47 
     48 #   define __QUEX_CURRENT_TOKEN_P  (self.token)
     49 
     50 #   define QUEX_TOKEN_POLICY_PREPARE_NEXT() \
     51            /* empty */
     52 
     53 /*  Important: Currently the token class needs to contain a token identifier.
     54  *             When this changes, the 'get_id' function can rely solely on 
     55  *             __self_result_token_id. HOWEVER, then 'on_entry', 'on_exit', 
     56  *             and 'on_indent', 'on_dedent' need to be revised-->test then carefully. */
     57 /* #   define self_token_get_id()    (__self_result_token_id) */
     58 #   if        defined(__QUEX_OPTION_PLAIN_C)
     59 #      define self_token_get_id()   __QUEX_CURRENT_TOKEN_P->_id
     60 #   else
     61 #      define self_token_get_id()   __QUEX_CURRENT_TOKEN_P->type_id()
     62 #   endif
     63 #   define self_token_set_id(ID)  do { __self_result_token_id = ID; __QUEX_TOKEN_POLICY_SET_ID(ID); } while( 0 )
     64 
     65 #endif
     66 
     67 /* Option: QUEX_OPTION_TOKEN_STAMPING_WITH_LINE_AND_COLUMN
     68  *
     69  * This option enables the stamping of tokens at the time that they are sent
     70  * with the current position of the lexeme in terms of line and column
     71  * numbers. Note, that if line or column numbering is disabled than also
     72  * the stamping of the corresponding value is disabled. 
     73  *
     74  * In the default token class the members '_line_n' and '_column_n' only 
     75  * exist if the corresponding stamping is active.                            */
     76 #if    defined(QUEX_OPTION_TOKEN_STAMPING_WITH_LINE_AND_COLUMN) \
     77     && defined(QUEX_OPTION_LINE_NUMBER_COUNTING)
     78 #       define __QUEX_STAMP_LINE_NUMBER(TOKEN)    TOKEN->_line_n = self.counter._line_number_at_begin;
     79 #else
     80 #       define __QUEX_STAMP_LINE_NUMBER(TOKEN)    /* empty */
     81 #endif
     82 
     83 #if    defined(QUEX_OPTION_TOKEN_STAMPING_WITH_LINE_AND_COLUMN) \
     84     && defined(QUEX_OPTION_COLUMN_NUMBER_COUNTING)
     85 #       define __QUEX_STAMP_COLUMN_NUMBER(TOKEN)    TOKEN->_column_n = self.counter._column_number_at_begin;
     86 #else
     87 #       define __QUEX_STAMP_COLUMN_NUMBER(TOKEN)  /* empty */
     88 #endif
     89 
     90 /* We do not define QUEX_ACTION_TOKEN_STAMP in 'configuration/derived' since
     91  * the derived configuration is included before the user's header.  The user's
     92  * header requires the configuration parameters.                             */
     93 #if ! defined(QUEX_ACTION_TOKEN_STAMP) 
     94 #     define  QUEX_ACTION_TOKEN_STAMP(TOKEN_P)   \
     95               __QUEX_STAMP_LINE_NUMBER(TOKEN_P)  \
     96               __QUEX_STAMP_COLUMN_NUMBER(TOKEN_P) 
     97 #endif
     98 
     99 /* Setting a token value. 
    100  *  
    101  *  This may include the stamping of line and/or column numbers. The macros to
    102  *  do that are empty in case that the stamping is disabled (see the above
    103  *  definitions). The last element of the subsequent macro provides access to
    104  *  the current token. This access depends on whether the token policy 'users
    105  *  token' or a queue policy is used.                                           */
    106                                     
    107 #if  defined(QUEX_TOKEN_CONTAINS_NO_ID)
    108 #   define __QUEX_TOKEN_POLICY_SET_ID(ID) \
    109            QUEX_ERROR_EXIT("TokenID can only be set in token objects with token ids.");
    110 #else
    111 #   define __QUEX_TOKEN_POLICY_SET_ID(ID)                       \
    112            do {                                                 \
    113                QUEX_ACTION_TOKEN_STAMP(__QUEX_CURRENT_TOKEN_P); \
    114                (__QUEX_CURRENT_TOKEN_P)->_id = (ID);            \
    115            } while(0)
    116 #endif
    117 
    118 #ifdef     QUEX_OPTION_TOKEN_POLICY_QUEUE
    119     /* -- Assert consistency of the token queue
    120      * -- Assert no token is sent after token 'TERMINATION'. 
    121      *    If files are included the token queue is reset.   */
    122 #   if ! defined(QUEX_OPTION_SEND_AFTER_TERMINATION_ADMISSIBLE)
    123 #       define __QUEX_ASSERT_SEND_ENTRY()                                                                   \
    124                do {                                                                                         \
    125                    QUEX_TOKEN_QUEUE_ASSERT(&self._token_queue);                                             \
    126                    if(   self._token_queue.write_iterator != self._token_queue.begin                        \
    127                       && (self._token_queue.write_iterator-1)->_id == __QUEX_SETTING_TOKEN_ID_TERMINATION ) \
    128                        QUEX_ERROR_EXIT("Detected attempt to send a token after 'TERMINATION'.\n"            \
    129                                        "If this is intended, compile with -DQUEX_OPTION_SEND_AFTER_TERMINATION_ADMISSIBLE'.\n"); \
    130                } while( 0 )
    131 #   else
    132 #       define __QUEX_ASSERT_SEND_ENTRY()                   \
    133                QUEX_TOKEN_QUEUE_ASSERT(&self._token_queue) 
    134 #   endif
    135 #else
    136     /* No assert about token object                         */
    137     /* No assert on not __QUEX_SETTING_TOKEN_ID_TERMINATION */
    138 #   define __QUEX_ASSERT_SEND_ENTRY()              /* EMPTY */
    139 #endif
    140 
    141 #ifdef  QUEX_OPTION_TOKEN_REPETITION_SUPPORT
    142 
    143 #   define __QUEX_REPEATED_TOKEN_DECREMENT_N(TokenP) \
    144             QUEX_NAME_TOKEN(repetition_n_set)((TokenP),                      \
    145                             (QUEX_NAME_TOKEN(repetition_n_get)(TokenP) - 1))
    146 
    147 #   ifdef QUEX_OPTION_ASSERTS 
    148 #      define QUEX_ASSERT_REPEATED_TOKEN_NOT_ZERO(TokenP) \
    149            if( QUEX_NAME_TOKEN(repetition_n_get)(TokenP) == 0 ) {               \
    150                QUEX_ERROR_EXIT("\nToken has been sent with zero repetitions.\n" \
    151                                "Did you call self_send_n(N,T) with N = 0?\n");  \
    152            }
    153 #   else
    154 #      define QUEX_ASSERT_REPEATED_TOKEN_NOT_ZERO(TokenP) /* empty */
    155       
    156 #   endif
    157 
    158 #endif