token-receiving.i (5362B)
1 /* -*- C++ -*- vim: set syntax=cpp: */ 2 #ifndef __QUEX_INCLUDE_GUARD__ANALYZER__MEMBER__TOKEN_RECEIVING_I 3 #define __QUEX_INCLUDE_GUARD__ANALYZER__MEMBER__TOKEN_RECEIVING_I 4 5 #ifndef QUEX_TYPE_ANALYZER 6 # error "This file requires the macro 'QUEX_TYPE_ANALYZER' to be defined." 7 #endif 8 9 #include "TokenPolicy" 10 #include "definitions" 11 12 QUEX_NAMESPACE_MAIN_OPEN 13 14 # define self (*me) 15 16 # ifdef QUEX_OPTION_TOKEN_POLICY_QUEUE 17 QUEX_INLINE void 18 QUEX_NAME(receive)(QUEX_TYPE_ANALYZER* me, QUEX_TYPE_TOKEN** result_pp) 19 { 20 __QUEX_IF_TOKEN_REPETITION_SUPPORT(register QUEX_TYPE_TOKEN* result_p = 0x0); 21 22 # if defined(QUEX_OPTION_ASSERTS) && defined(QUEX_OPTION_USER_MANAGED_TOKEN_MEMORY) 23 if( QUEX_NAME(TokenQueue_begin)(&me->_token_queue) == 0x0 ) { 24 QUEX_ERROR_EXIT("Token queue has not been set before call to .receive().\n" 25 "Please, consider function 'token_queue_memory_set()'."); 26 } 27 # endif 28 29 # if defined(QUEX_OPTION_TOKEN_REPETITION_SUPPORT) 30 if( __QUEX_SETTING_TOKEN_ID_REPETITION_TEST(self_token_p()->_id) ) { 31 if( QUEX_NAME_TOKEN(repetition_n_get)(self_token_p()) != 0 ) { 32 __QUEX_REPEATED_TOKEN_DECREMENT_N(self_token_p()); 33 *result_pp = self_token_p(); 34 return; 35 } else { 36 /* Pop the repeated token from the queue */ 37 (void)QUEX_NAME(TokenQueue_pop)(&me->_token_queue); 38 } 39 } 40 # endif 41 /* Tokens are in queue --> take next token from queue */ 42 if( QUEX_NAME(TokenQueue_is_empty)(&me->_token_queue) == false ) { 43 *result_pp = QUEX_NAME(TokenQueue_pop)(&me->_token_queue); 44 return; 45 } 46 47 /* Restart filling the queue from begin */ 48 QUEX_NAME(TokenQueue_reset)(&me->_token_queue); 49 50 /* Analyze until there is some content in the queue */ 51 do { 52 me->current_analyzer_function(me); 53 QUEX_ASSERT_TOKEN_QUEUE_AFTER_WRITE(&me->_token_queue); 54 # if defined(QUEX_OPTION_AUTOMATIC_ANALYSIS_CONTINUATION_ON_MODE_CHANGE) 55 } while( QUEX_NAME(TokenQueue_is_empty)(&self._token_queue) ); 56 # else 57 } while( false ); 58 # endif 59 60 61 # if defined(QUEX_OPTION_TOKEN_REPETITION_SUPPORT) 62 result_p = self_token_p(); 63 if( __QUEX_SETTING_TOKEN_ID_REPETITION_TEST(result_p->_id) ) { 64 QUEX_ASSERT_REPEATED_TOKEN_NOT_ZERO(result_p); 65 /* First rep. is sent below. */ 66 if( QUEX_NAME_TOKEN(repetition_n_get)(result_p) == 1 ) { 67 (void)QUEX_NAME(TokenQueue_pop)(&me->_token_queue); 68 } else { 69 __QUEX_REPEATED_TOKEN_DECREMENT_N(result_p); 70 } 71 *result_pp = result_p; 72 return; 73 } else 74 # endif 75 { 76 *result_pp = QUEX_NAME(TokenQueue_pop)(&me->_token_queue); 77 return; 78 } 79 } 80 81 # else 82 83 QUEX_INLINE QUEX_TYPE_TOKEN_ID 84 QUEX_NAME(receive)(QUEX_TYPE_ANALYZER* me) 85 { 86 register QUEX_TYPE_TOKEN_ID __self_result_token_id = (QUEX_TYPE_TOKEN_ID)-1; 87 88 # if defined(QUEX_OPTION_ASSERTS) && defined(QUEX_OPTION_USER_MANAGED_TOKEN_MEMORY) 89 if( &me->token == 0x0 ) { 90 QUEX_ERROR_EXIT("Token has not been set before call to .receive().\n" 91 "Please, consider function 'token_p_set()'."); 92 } 93 # endif 94 95 # if defined(QUEX_OPTION_TOKEN_REPETITION_SUPPORT) 96 if( __QUEX_SETTING_TOKEN_ID_REPETITION_TEST(self_token_p()->_id) 97 && (QUEX_NAME_TOKEN(repetition_n_get)(self_token_p()) != 0) ) { 98 __QUEX_REPEATED_TOKEN_DECREMENT_N(self_token_p()); 99 return self_token_p()->_id; 100 } 101 # endif 102 103 __quex_assert(me->token != 0x0); 104 me->token->_id = __QUEX_SETTING_TOKEN_ID_UNINITIALIZED; 105 do { 106 __self_result_token_id = me->current_analyzer_function(me); 107 /* Currently it is necessary to check whether the return value 108 * is appropriate, since event handlers may have set the token 109 * identifier, without setting __self_result_token_id. */ 110 if( __self_result_token_id != me->token->_id ) { 111 __self_result_token_id = me->token->_id; 112 } 113 # if defined(QUEX_OPTION_AUTOMATIC_ANALYSIS_CONTINUATION_ON_MODE_CHANGE) 114 } while( __self_result_token_id == __QUEX_SETTING_TOKEN_ID_UNINITIALIZED ); 115 # else 116 } while( false ); 117 # endif 118 119 # if defined(QUEX_OPTION_TOKEN_REPETITION_SUPPORT) 120 if( __QUEX_SETTING_TOKEN_ID_REPETITION_TEST(self_token_p()->_id) ) { 121 QUEX_ASSERT_REPEATED_TOKEN_NOT_ZERO(self_token_p()); 122 __QUEX_REPEATED_TOKEN_DECREMENT_N(self_token_p()); /* First rep. is sent now. */ 123 } 124 # endif 125 126 return __self_result_token_id; 127 } 128 # endif 129 130 # ifndef __QUEX_OPTION_PLAIN_C 131 # ifdef QUEX_OPTION_TOKEN_POLICY_QUEUE 132 QUEX_INLINE void QUEX_MEMBER(receive)(QUEX_TYPE_TOKEN** token_pp) 133 { QUEX_NAME(receive)(this, token_pp); } 134 # else 135 QUEX_INLINE QUEX_TYPE_TOKEN_ID QUEX_MEMBER(receive)() 136 { return QUEX_NAME(receive)(this); } 137 # endif 138 # endif 139 140 # undef self 141 142 QUEX_NAMESPACE_MAIN_CLOSE 143 #endif