sheepy

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

reset.i (10384B)


      1 /* -*- C++ -*- vim:set syntax=cpp:
      2  * (C)  Frank-Rene Schaefer
      3  * ABSOLUTELY NO WARRANTY                                                    */
      4 #ifndef __QUEX_INCLUDE_GUARD__ANALYZER__STRUCT__RESET_I
      5 #define __QUEX_INCLUDE_GUARD__ANALYZER__STRUCT__RESET_I
      6 
      7 #include "Buffer.i"
      8 #include "analyzerReset"
      9 
     10 QUEX_NAMESPACE_MAIN_OPEN
     11 
     12 /* Level (0) __________________________________________________________________
     13  *                                                                           */
     14 QUEX_INLINE void
     15 QUEX_MEMBER_FUNCTIONO(reset)  
     16 {
     17     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
     18     QUEX_NAME(LexatomLoader)* filler = me->buffer.filler;
     19 
     20     if( filler ) {
     21         QUEX_NAME(LexatomLoader_reset)(filler, filler->byte_loader);
     22     }
     23 
     24     QUEX_MEMBER_FUNCTION_CALL1(reset, LexatomLoader, filler);
     25 }
     26 
     27 /* Level (1) __________________________________________________________________
     28  *                                                                           */
     29 QUEX_INLINE void
     30 QUEX_MEMBER_FUNCTION2(reset, file_name, 
     31                       const char* FileName, 
     32                       const char* CodecName /* = 0x0 */) 
     33 {
     34     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
     35     QUEX_NAME(ByteLoader)*   byte_loader;
     36 
     37     byte_loader = QUEX_NAME(ByteLoader_FILE_new_from_file_name)(FileName);
     38     /* NOT: Abort/return if byte_loader == 0 !!
     39      *      Incomplete construction => propper destruction IMPOSSIBLE!       */
     40     if( byte_loader ) {
     41         byte_loader->ownership = E_Ownership_LEXICAL_ANALYZER;
     42     }
     43     QUEX_MEMBER_FUNCTION_CALL2(reset, ByteLoader, byte_loader, CodecName); 
     44 }
     45 
     46 /* Level (2) __________________________________________________________________
     47  *                                                                           */
     48 QUEX_INLINE void
     49 QUEX_MEMBER_FUNCTION3(reset, FILE,
     50                       __QUEX_STD_FILE* fh, 
     51                       const char*      CodecName /* = 0x0   */,
     52                       bool             BinaryModeF)
     53 {
     54     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
     55     QUEX_NAME(ByteLoader)*   byte_loader;
     56     __quex_assert( fh );
     57 
     58     /* At the time of this writing 'stdin' as located in the C++ global
     59      * namespace.  This seemed suspicous to the author. To avoid compilation
     60      * errors in the future the test for the standard input is only active in
     61      * 'C'. It is only about user information anyway. So better no risks taken.
     62      * <fschaef 2010y02m06d>                                                 */
     63     setbuf(fh, 0);   /* turn off system based buffering! 
     64     **               ** this is essential to profit from the quex buffer!    */
     65     byte_loader = QUEX_NAME(ByteLoader_FILE_new)(fh, BinaryModeF);
     66     /* NOT: Abort/return if byte_loader == 0 !!
     67      *      Incomplete construction => propper destruction IMPOSSIBLE!       */
     68     if( byte_loader ) {
     69         byte_loader->ownership = E_Ownership_LEXICAL_ANALYZER;
     70     }
     71     QUEX_MEMBER_FUNCTION_CALL2(reset, ByteLoader, byte_loader, CodecName); 
     72 }
     73 
     74 #ifndef __QUEX_OPTION_PLAIN_C
     75 QUEX_INLINE void
     76 QUEX_MEMBER_FUNCTION3(reset, istream,
     77                       std::istream*   istream_p, 
     78                       const char*     CodecName   /* = 0x0   */,
     79                       bool            BinaryModeF /* = false */)
     80 {
     81     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
     82     QUEX_NAME(ByteLoader)*   byte_loader;
     83     __quex_assert( istream_p );
     84 
     85     byte_loader = QUEX_NAME(ByteLoader_stream_new)(istream_p);
     86     byte_loader->binary_mode_f = BinaryModeF;
     87 
     88     /* NOT: Abort/return if byte_loader == 0 !!
     89      *      Incomplete construction => propper destruction IMPOSSIBLE!       */
     90     if( byte_loader ) {
     91         byte_loader->ownership = E_Ownership_LEXICAL_ANALYZER;
     92     }
     93     QUEX_MEMBER_FUNCTION_CALL2(reset, ByteLoader, byte_loader, CodecName); 
     94 }
     95 #endif
     96 
     97 
     98 #if defined(__QUEX_OPTION_WCHAR_T) && ! defined(__QUEX_OPTION_PLAIN_C)
     99 QUEX_INLINE void
    100 QUEX_MEMBER_FUNCTION3(reset, wistream,
    101                       std::wistream*  istream_p, 
    102                       const char*     CodecName   /* = 0x0   */,
    103                       bool            BinaryModeF /* = false */)
    104 {
    105     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
    106     QUEX_NAME(ByteLoader)*   byte_loader;
    107     __quex_assert( istream_p );
    108     byte_loader = QUEX_NAME(ByteLoader_stream_new)(istream_p);
    109     byte_loader->binary_mode_f = BinaryModeF;
    110 
    111     /* NOT: Abort/return if byte_loader == 0 !!
    112      *      Incomplete construction => propper destruction IMPOSSIBLE!       */
    113     if( byte_loader ) {
    114         byte_loader->ownership = E_Ownership_LEXICAL_ANALYZER;
    115     }
    116     QUEX_MEMBER_FUNCTION_CALL2(reset, ByteLoader, byte_loader, CodecName); 
    117 }
    118 #endif
    119 
    120 #if defined(__QUEX_OPTION_UNIT_TEST) && ! defined (__QUEX_OPTION_PLAIN_C)
    121 /* StrangeStreams are not for C-language stuff */
    122 template<class UnderlyingStreamT> QUEX_INLINE void
    123 QUEX_MEMBER_FUNCTION2(reset_StrangeStream, strange_stream, 
    124                       quex::StrangeStream<UnderlyingStreamT>*  istream_p, 
    125                       const char*                              CodecName /* = 0x0   */)
    126 {
    127     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
    128     QUEX_NAME(ByteLoader)*   byte_loader;
    129     __quex_assert( istream_p );
    130     byte_loader = QUEX_NAME(ByteLoader_stream_new)(istream_p);
    131     byte_loader->binary_mode_f = false;
    132 
    133     /* NOT: Abort/return if byte_loader == 0 !!
    134      *      Incomplete construction => propper destruction IMPOSSIBLE!       */
    135     if( byte_loader ) {
    136         byte_loader->ownership = E_Ownership_LEXICAL_ANALYZER;
    137     }
    138     QUEX_MEMBER_FUNCTION_CALL2(reset, ByteLoader, byte_loader, CodecName); 
    139 }
    140 #endif
    141 
    142 
    143 /* Level (3) __________________________________________________________________
    144  *                                                                           */
    145 QUEX_INLINE void
    146 QUEX_MEMBER_FUNCTION2(reset, ByteLoader,
    147                       QUEX_NAME(ByteLoader)*  byte_loader,
    148                       const char*             CodecName) 
    149 {
    150     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
    151     QUEX_NAME(LexatomLoader)* filler = me->buffer.filler;
    152     QUEX_NAME(Asserts_construct)(CodecName);
    153     
    154     if( filler ) {
    155         QUEX_NAME(LexatomLoader_reset)(filler, byte_loader);
    156     }
    157     else {
    158         filler = QUEX_NAME(LexatomLoader_new_DEFAULT)(byte_loader, CodecName);
    159         /* NOT: Abort/return if filler == 0 !!
    160          *      Incomplete construction => propper destruction IMPOSSIBLE!   */
    161         if( filler ) {
    162             filler->ownership = E_Ownership_LEXICAL_ANALYZER;
    163         }
    164     }
    165 
    166     QUEX_MEMBER_FUNCTION_CALL1(reset, LexatomLoader, filler);
    167 }
    168 
    169 /* Level (4) __________________________________________________________________
    170  *                                                                           */
    171 QUEX_INLINE void
    172 QUEX_MEMBER_FUNCTION1(reset, LexatomLoader,
    173                       QUEX_NAME(LexatomLoader)* filler)
    174 {
    175     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
    176     if( filler != me->buffer.filler ) {
    177         if( me->buffer.filler && me->buffer.filler->ownership == E_Ownership_LEXICAL_ANALYZER ) {
    178             me->buffer.filler->delete_self(me->buffer.filler); 
    179         }
    180         me->buffer.filler = filler;
    181     }
    182     else {
    183         /* Assume, that buffer filler has been reset.                        */
    184     }
    185     QUEX_NAME(Buffer_init_content)(&me->buffer, (QUEX_TYPE_LEXATOM*)0);
    186     QUEX_NAME(Buffer_init_analyzis)(&me->buffer); 
    187     QUEX_MEMBER_FUNCTION_CALLO1(basic_reset, (const char*)"<unknown>");
    188 }
    189 
    190 /* Level (5) __________________________________________________________________
    191  *                                                                           */
    192 QUEX_INLINE QUEX_TYPE_LEXATOM*
    193 QUEX_MEMBER_FUNCTION3(reset, memory,
    194                       QUEX_TYPE_LEXATOM*    Memory,
    195                       const size_t          MemorySize,
    196                       QUEX_TYPE_LEXATOM*    EndOfFileP)
    197 /* When memory is provided from extern, the 'external entity' is
    198  * responsible for filling it. There is no 'file/stream handle', no 'byte
    199  * loader', and 'no buffer filler'.                                          
    200  *
    201  * RETURN: != 0, previous buffer memory, in case that the user is responsible
    202  *               for deleting it.
    203  *         == 0  if the previous memory was owned by the lexical analyzer and
    204  *               accordingly, it deleted it itself.                          */
    205 {
    206     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
    207     QUEX_TYPE_LEXATOM*       previous_buffer_memory;
    208     QUEX_ASSERT_MEMORY(Memory, MemorySize, EndOfFileP);
    209 
    210     QUEX_NAME(Buffer_destruct)(&me->buffer); 
    211     /* In case, that the memory was owned by the analyzer, the destructor did
    212      * not delete it and did not set 'me->buffer._memory._front' to zero.    */
    213     previous_buffer_memory = me->buffer._memory._front;
    214     QUEX_NAME(Buffer_construct)(&me->buffer, 
    215                                 (QUEX_NAME(LexatomLoader)*)0,
    216                                 Memory, MemorySize, EndOfFileP,
    217                                 E_Ownership_EXTERNAL);
    218     QUEX_MEMBER_FUNCTION_CALLO1(basic_reset, (const char*)"<memory>");
    219 
    220     return previous_buffer_memory;
    221 }
    222 
    223 QUEX_INLINE void
    224 QUEX_MEMBER_FUNCTIONO1(basic_reset, const char* InputNameP)
    225 {
    226     QUEX_MAP_THIS_TO_ME(QUEX_TYPE_ANALYZER)
    227     bool  byte_order_reversion_f = me->buffer.filler ? 
    228                                      me->buffer.filler->_byte_order_reversion_active_f
    229                                    : false;
    230     QUEX_NAME(Tokens_destruct)(me);
    231     QUEX_NAME(Tokens_construct)(me);
    232 
    233     QUEX_NAME(ModeStack_construct)(me);
    234 
    235     __QUEX_IF_INCLUDE_STACK(     QUEX_MEMBER_FUNCTION_CALLO(include_stack_delete));
    236 
    237     __QUEX_IF_STRING_ACCUMULATOR(QUEX_NAME(Accumulator_destruct)(&me->accumulator));
    238     __QUEX_IF_STRING_ACCUMULATOR(QUEX_NAME(Accumulator_construct)(&me->accumulator, me));
    239 
    240     __QUEX_IF_POST_CATEGORIZER(  QUEX_NAME(PostCategorizer_destruct)(&me->post_categorizer));
    241     __QUEX_IF_POST_CATEGORIZER(  QUEX_NAME(PostCategorizer_construct)(&me->post_categorizer));
    242 
    243     __QUEX_IF_COUNT(             QUEX_NAME(Counter_construct)(&me->counter); )
    244 
    245     QUEX_NAME(set_mode_brutally_by_id)(me, __QUEX_SETTING_INITIAL_LEXER_MODE_ID);
    246 
    247     if( me->buffer.filler && byte_order_reversion_f )
    248     {
    249         me->buffer.filler->_byte_order_reversion_active_f = true;
    250     }
    251 
    252     (void)QUEX_MEMBER_FUNCTION_CALLO1(input_name_set, InputNameP);
    253 
    254     QUEX_MEMBER_FUNCTION_CALLO(user_reset);
    255 }
    256 
    257 
    258 QUEX_NAMESPACE_MAIN_CLOSE
    259 
    260 #endif /* __QUEX_INCLUDE_GUARD__ANALYZER__STRUCT__RESET_I */