sheepy

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

Buffer_fill.i (4546B)


      1 /* -*- C++ -*- vim: set syntax=cpp: */
      2 #ifndef __QUEX_INCLUDE_GUARD__BUFFER__BUFFER_FILL_I
      3 #define __QUEX_INCLUDE_GUARD__BUFFER__BUFFER_FILL_I
      4 
      5 #include "bufferBuffer"
      6 
      7 QUEX_NAMESPACE_MAIN_OPEN
      8 
      9 QUEX_INLINE void*
     10 QUEX_NAME(Buffer_fill)(QUEX_NAME(Buffer)*  me, 
     11                        const void*         ContentBegin,
     12                        const void*         ContentEnd)
     13 {
     14     ptrdiff_t      copy_n;
     15     void*          begin_p;
     16     const void*    end_p;
     17 
     18     /* Prepare the buffer for the reception of new input an acquire the
     19      * border pointers of where new content can be filled.                   */
     20     me->fill_prepare(me, &begin_p, &end_p);
     21 
     22     /* Copy as much as possible of the new content into the designated
     23      * region in memory. This may be the engine's buffer or a 'raw' buffer
     24      * whose content still needs to be converted.                            */
     25     copy_n = (ptrdiff_t)QUEXED(MemoryManager_insert)((uint8_t*)begin_p,  
     26                                                      (uint8_t*)end_p,
     27                                                      (uint8_t*)ContentBegin, 
     28                                                      (uint8_t*)ContentEnd);
     29 
     30     /* Flush into buffer what has been filled from &begin[0] to 
     31      * &begin[inserted_byte_n].                                              */
     32     me->fill_finish(me, &((uint8_t*)begin_p)[copy_n]);
     33 
     34     /* Report a pointer to the first content element that has not yet 
     35      * been treated (== ContentEnd if all complete).                         */
     36     return (void*)&((uint8_t*)ContentBegin)[copy_n];
     37 }
     38 
     39 QUEX_INLINE void
     40 QUEX_NAME(Buffer_fill_prepare)(QUEX_NAME(Buffer)*  me, 
     41                                void**              begin_p, 
     42                                const void**        end_p)
     43 /* SETS: *begin_p: position where the next content needs to be filled. 
     44  *       *end_p:   address directly behind the last byte that can be filled.
     45  *
     46  * The content may be filled into the engine's buffer or an intermediate 
     47  * 'raw' buffer which still needs to be converted.                          */
     48 {
     49     (void)QUEX_NAME(Buffer_move_away_passed_content)(me, (QUEX_TYPE_LEXATOM**)0, 0);
     50 
     51     /* Get the pointers for the border where to fill content.               */
     52     me->filler->derived.fill_prepare(me->filler, me, begin_p, end_p);
     53 
     54     __quex_assert(*end_p >= *begin_p);
     55 }
     56 
     57 QUEX_INLINE void
     58 QUEX_NAME(Buffer_fill_finish)(QUEX_NAME(Buffer)* me,
     59                               const void*        FilledEndP)
     60 /* Uses the content that has been inserted until 'FilledEndP' to fill the
     61  * engine's lexatom buffer (if it is not already done). A fille of type
     62  * 'LexatomLoader_Converter' takes the content of the raw buffer and converts
     63  * it into the engine's buffer from 'me->input.end_p' to 'me->_memory._back'.
     64  *                                                                           */
     65 {
     66     QUEX_TYPE_LEXATOM*   BeginP = &me->_memory._front[1];
     67     __quex_assert((QUEX_TYPE_LEXATOM*)FilledEndP <= me->_memory._back);
     68 
     69     /* Place new content in the engine's buffer.                             */
     70     ptrdiff_t inserted_lexatom_n = me->filler->derived.fill_finish(me->filler, 
     71                                                                    me->input.end_p,
     72                                                                    me->_memory._back, 
     73                                                                    FilledEndP);
     74 
     75     /* Assume: content from 'input.end_p' to 'input.end_p[CharN]'
     76      * has been filled with data.                                            */
     77     if( me->filler->_byte_order_reversion_active_f ) {
     78         QUEX_NAME(LexatomLoader_reverse_byte_order)(me->input.end_p, 
     79                                                    &me->input.end_p[inserted_lexatom_n]);
     80     }
     81 
     82     /* -- Manual buffer filling requires the end-of-stream pointer always
     83      *    to be set. 
     84      * -- The 'lexatom_index_begin' has been set in 'fill_prepare()'.
     85      *    '-1' => no change.
     86      * -- The 'lexatom_index_end_of_stream' can now be set, since it is
     87      *    known how many lexatoms have been inserted.
     88      *                                                                       */
     89     QUEX_NAME(Buffer_register_content)(me, &me->input.end_p[inserted_lexatom_n], -1);
     90     QUEX_NAME(Buffer_register_eos)(me,   me->input.lexatom_index_begin
     91                                        + (me->input.end_p - BeginP));
     92 
     93     QUEX_BUFFER_ASSERT_CONSISTENCY(me);
     94 }
     95 
     96 QUEX_NAMESPACE_MAIN_CLOSE
     97 
     98 #endif /* __QUEX_INCLUDE_GUARD__BUFFER__BUFFER_FILL_I */