Buffer_debug.i (15582B)
1 /* -*- C++ -*- vim: set syntax=cpp: 2 * 3 * (C) 2008 Frank-Rene Schaefer */ 4 #ifndef __QUEX_INCLUDE_GUARD__BUFFER__BUFFER_DEBUG_I 5 #define __QUEX_INCLUDE_GUARD__BUFFER__BUFFER_DEBUG_I 6 7 #include "definitions" 8 #include "bufferBuffer" 9 #include "LexatomLoader" 10 #include "bufferAsserts" 11 #include "bufferAsserts.i" 12 #include "Buffer_debug" 13 14 15 QUEX_NAMESPACE_MAIN_OPEN 16 17 QUEX_INLINE void 18 QUEX_NAME(Buffer_show_brief_content)(QUEX_NAME(Buffer)* buffer) 19 { 20 QUEX_NAME(LexatomLoader)* me = buffer->filler; 21 22 __quex_assert(buffer != 0x0); 23 __quex_assert(me != 0x0); 24 25 QUEX_BUFFER_ASSERT_CONSISTENCY(buffer); 26 __QUEX_STD_printf("Begin of Buffer Character Index: %i\n", (int)QUEX_NAME(Buffer_input_lexatom_index_begin)(buffer)); 27 __QUEX_STD_printf("End of Buffer Character Index: %i\n", (int)me->input_lexatom_tell(me)); 28 if( buffer->input.end_p == 0x0 ) 29 __QUEX_STD_printf("_memory.input.end_p (offset) = <0x0>\n"); 30 else 31 __QUEX_STD_printf("input.end_p (offset) = %08X\n", 32 (int)(buffer->input.end_p - buffer->_memory._front)); 33 __QUEX_STD_printf("_read_p (offset) = %08X\n", (int)(buffer->_read_p - buffer->_memory._front)); 34 __QUEX_STD_printf("_lexeme_start_p (offset) = %08X\n", (int)(buffer->_lexeme_start_p - buffer->_memory._front)); 35 __QUEX_STD_printf("_back (offset) = %08X\n", (int)(buffer->_memory._back - buffer->_memory._front)); 36 } 37 38 QUEX_INLINE void 39 QUEX_NAME(Buffer_x_show_content)(QUEX_NAME(Buffer)* buffer) 40 { 41 QUEX_NAME(Buffer_show_content_intern)(buffer); 42 QUEX_NAME(Buffer_show_brief_content)(buffer); 43 } 44 45 QUEX_INLINE QUEX_TYPE_LEXATOM 46 QUEX_NAME(__Buffer_get_border_char)(QUEX_NAME(Buffer)* buffer, const QUEX_TYPE_LEXATOM* C) 47 { 48 if ( *C != QUEX_SETTING_BUFFER_LIMIT_CODE ) 49 return (QUEX_TYPE_LEXATOM)'?'; 50 else if( buffer->input.end_p == C ) 51 return (QUEX_TYPE_LEXATOM)']'; /* End of stream sign. */ 52 else if( QUEX_NAME(Buffer_input_lexatom_index_begin)(buffer) == 0 && buffer->_memory._front == C ) 53 return (QUEX_TYPE_LEXATOM)'['; /* Begin of stream sign. */ 54 else 55 return (QUEX_TYPE_LEXATOM)'|'; 56 } 57 58 QUEX_INLINE void 59 QUEX_NAME(Buffer_show_content_intern)(QUEX_NAME(Buffer)* buffer) 60 { 61 size_t i = 0; 62 size_t length = 0; 63 64 QUEX_TYPE_LEXATOM EmptyChar = (QUEX_TYPE_LEXATOM)(-1); 65 QUEX_TYPE_LEXATOM* BeginP = &buffer->_memory._front[1]; 66 QUEX_TYPE_LEXATOM* BufferFront = buffer->_memory._front; 67 QUEX_TYPE_LEXATOM* BufferBack = buffer->_memory._back; 68 QUEX_TYPE_LEXATOM* iterator = 0x0; 69 QUEX_TYPE_LEXATOM* end_p = buffer->input.end_p; 70 bool end_p_error_f = ( end_p > buffer->_memory._back 71 || end_p < buffer->_memory._front); 72 73 end_p = QUEX_MIN(end_p, buffer->_memory._front); 74 end_p = QUEX_MAX(end_p, buffer->_memory._back); 75 76 __QUEX_STD_printf("|%c", (int)QUEX_NAME(__Buffer_get_border_char)(buffer, BufferFront)); 77 for(iterator = BeginP; iterator != end_p; ++iterator) { 78 __QUEX_STD_printf("%c", *iterator == EmptyChar ? (int)'~' 79 : *iterator == QUEX_SETTING_BUFFER_LIMIT_CODE ? (int)'*' 80 : (int)*iterator); 81 } 82 __QUEX_STD_printf("%c", (int)QUEX_NAME(__Buffer_get_border_char)(buffer, end_p)); 83 /**/ 84 length = (buffer->input.end_p == 0x0) ? 0 : (size_t)(BufferBack - end_p); 85 for(i=0; i < length; ++i) __QUEX_STD_printf("|"); 86 87 __QUEX_STD_printf("|"); 88 if( end_p_error_f ) { 89 __QUEX_STD_printf("ERROR: end_of_file_p: %p; front: %p; back %p;\n", 90 (void*)buffer->input.end_p, (void*)buffer->_memory._front, 91 (void*)buffer->_memory._back); 92 } 93 __QUEX_STD_printf("\n"); 94 } 95 96 QUEX_INLINE void 97 QUEX_NAME(Buffer_show_content)(QUEX_NAME(Buffer)* buffer) 98 /* Simple printing function for unit testing and debugging it is thought to 99 * print only ASCII characters (i.e. code points < 0xFF) */ 100 { 101 size_t i = 0; 102 char* tmp = 0; 103 const size_t ContentSize = QUEX_NAME(Buffer_content_size)(buffer); 104 QUEX_TYPE_LEXATOM* BeginP = &buffer->_memory._front[1]; 105 QUEX_TYPE_LEXATOM* BufferFront = buffer->_memory._front; 106 QUEX_TYPE_LEXATOM* BufferBack = buffer->_memory._back; 107 108 __quex_assert(buffer != 0x0); 109 /*__________________________________________________________________*/ 110 tmp = (char*)__QUEX_STD_malloc(ContentSize + 4); 111 /* tmp[0] = outer border*/ 112 /* tmp[1] = buffer limit*/ 113 /* tmp[2...ContentSize+1] = BeginP[0...ContentSize-1]*/ 114 /* tmp[ContentSize+2] = buffer limit*/ 115 /* tmp[ContentSize+3] = outer border*/ 116 /* tmp[ContentSize+4] = terminating zero*/ 117 for(i=2; i<ContentSize + 2 ; ++i) tmp[i] = ' '; 118 tmp[ContentSize+4] = '\0'; 119 tmp[ContentSize+3] = '|'; 120 tmp[ContentSize+2] = (char)QUEX_NAME(__Buffer_get_border_char)(buffer, BufferBack); 121 tmp[1] = (char)QUEX_NAME(__Buffer_get_border_char)(buffer, BufferFront); 122 tmp[0] = '|'; 123 /* tmp[_SHOW_current_fallback_n - 1 + 2] = ':'; */ 124 tmp[buffer->_read_p - BeginP + 2] = 'C'; 125 if( buffer->_lexeme_start_p >= BeginP && buffer->_lexeme_start_p <= BufferBack ) 126 tmp[(int)(buffer->_lexeme_start_p - BeginP) + 2] = 'S'; 127 /**/ 128 if ( buffer->_read_p == BeginP - 2 ) { 129 __QUEX_STD_printf("%s", tmp); 130 __QUEX_STD_printf(" <out>"); 131 } else { 132 __QUEX_STD_printf(" "); 133 if( *buffer->_read_p == QUEX_SETTING_BUFFER_LIMIT_CODE ) 134 __QUEX_STD_printf("BLC"); 135 else 136 __QUEX_STD_printf("'%c'", (char)(*buffer->_read_p)); 137 } 138 /* std::cout << " = 0x" << std::hex << int(*buffer->_read_p) << std::dec */ 139 __QUEX_STD_printf("\n"); 140 QUEX_NAME(Buffer_show_content_intern)(buffer); 141 __QUEX_STD_free(tmp); 142 } 143 144 QUEX_INLINE void 145 QUEX_NAME(Buffer_show_byte_content)(QUEX_NAME(Buffer)* buffer, const int IndentationN) 146 { 147 QUEX_NAME(BufferMemory)* memory = &buffer->_memory; 148 149 int i = 0, j = 0; 150 uint8_t* byte_p = (uint8_t*)memory->_front; 151 uint8_t* next_byte_p = (uint8_t*)memory->_front + 1; 152 uint8_t* End = (uint8_t*)(memory->_back + 1); 153 154 __quex_assert(buffer != 0x0); 155 __quex_assert(memory != 0x0); 156 157 for(j=0; j<IndentationN; ++j) fprintf(stdout, " "); 158 for(; byte_p != End; ++byte_p, ++next_byte_p, ++i) { 159 fprintf(stdout, "%02X", (int)*byte_p); 160 if ( next_byte_p == (uint8_t*)buffer->input.end_p ) 161 fprintf(stdout, "["); 162 else if( byte_p == (uint8_t*)buffer->input.end_p + sizeof(QUEX_TYPE_LEXATOM)-1) 163 fprintf(stdout, "]"); 164 else 165 fprintf(stdout, "."); 166 if( (i+1) % 0x8 == 0 ) fprintf(stdout, " "); 167 if( (i+1) % 0x10 == 0 ) { 168 fprintf(stdout, "\n"); 169 for(j=0; j<IndentationN; ++j) fprintf(stdout, " "); 170 } 171 } 172 fprintf(stdout, "\n"); 173 } 174 175 QUEX_INLINE void 176 QUEX_NAME(Buffer_show_debug_print_lines)(QUEX_TYPE_LEXATOM** iterator, 177 QUEX_TYPE_LEXATOM* Begin, 178 QUEX_TYPE_LEXATOM* TotalEnd, 179 QUEX_NAME(Buffer)* buffer) 180 { 181 int length = 0; 182 QUEX_TYPE_LEXATOM* end = Begin + 5 > TotalEnd ? TotalEnd : Begin + 5; 183 184 if( Begin > *iterator ) { 185 *iterator = Begin; 186 __QUEX_STD_fprintf(stderr, " ...\n"); 187 } else if( *iterator >= end ) { 188 return; 189 } 190 191 for(; *iterator < end; ++*iterator) { 192 length = 0; 193 __QUEX_STD_fprintf(stderr, " "); 194 195 if( *iterator == buffer->_memory._front ) { 196 __QUEX_STD_fprintf(stderr, "buffer front"); 197 length += 12; 198 } 199 if( *iterator == buffer->_lexeme_start_p ) { 200 if( length ) { __QUEX_STD_fprintf(stderr, ", "); length += 2; } 201 __QUEX_STD_fprintf(stderr, "lexeme start"); 202 length += 12; 203 } 204 if( *iterator == buffer->_read_p ) { 205 if( length ) { __QUEX_STD_fprintf(stderr, ", "); length += 2; } 206 __QUEX_STD_fprintf(stderr, "input"); 207 length += 5; 208 } 209 if( *iterator == buffer->input.end_p ) { 210 if( length ) { __QUEX_STD_fprintf(stderr, ", "); length += 2; } 211 __QUEX_STD_fprintf(stderr, "end of file"); 212 length += 11; 213 } 214 if( *iterator == buffer->_memory._back ) { 215 if( length ) { __QUEX_STD_fprintf(stderr, ", "); length += 2; } 216 __QUEX_STD_fprintf(stderr, "buffer back"); 217 length += 11; 218 } 219 if( length ) { 220 for(; length < 39; ++length) 221 __QUEX_STD_fprintf(stderr, "-"); 222 __QUEX_STD_fprintf(stderr, ">"); 223 } else { 224 __QUEX_STD_fprintf(stderr, " "); 225 } 226 227 /* Print the character information */ 228 __QUEX_STD_fprintf(stderr, "[%04X] 0x%04X\n", 229 (int)(*iterator - buffer->_memory._front), 230 (int)(**iterator)); 231 } 232 } 233 234 QUEX_INLINE void 235 QUEX_NAME(Buffer_show_debug_content)(QUEX_NAME(Buffer)* buffer) 236 { 237 /* Assumptions: 238 * (1) width of terminal = 80 chars 239 * (2) border right and left = 3 chars 240 * (3) display at least the last 5 chars at the begin of buffer. 241 * 5 chars around input_p. 242 * 5 chars from lexeme_start. 243 * 5 chars to the end of buffer. 244 * 245 * |12345 ... 12345 .... 12345 .... 12345| 246 * Begin lexeme start input_p buffer end */ 247 QUEX_TYPE_LEXATOM* iterator = buffer->_memory._front; 248 QUEX_TYPE_LEXATOM* total_end = buffer->_memory._back + 1; 249 250 __quex_assert(buffer != 0x0); 251 __QUEX_STD_fprintf(stderr, "_________________________________________________________________\n"); 252 QUEX_NAME(Buffer_show_debug_print_lines)(&iterator, buffer->_memory._front, total_end, buffer); 253 QUEX_NAME(Buffer_show_debug_print_lines)(&iterator, buffer->_lexeme_start_p - 2, total_end, buffer); 254 QUEX_NAME(Buffer_show_debug_print_lines)(&iterator, buffer->_read_p - 2, total_end, buffer); 255 if( buffer->input.end_p != 0x0 ) { 256 QUEX_NAME(Buffer_show_debug_print_lines)(&iterator, buffer->input.end_p - 4, total_end, buffer); 257 } 258 QUEX_NAME(Buffer_show_debug_print_lines)(&iterator, buffer->_memory._back - 4, total_end, buffer); 259 __QUEX_STD_fprintf(stderr, "_________________________________________________________________\n"); 260 } 261 262 QUEX_INLINE void 263 QUEX_NAME(Buffer_print_this)(QUEX_NAME(Buffer)* me) 264 { 265 QUEX_TYPE_LEXATOM* Offset = me->_memory._front; 266 267 __QUEX_STD_printf(" Buffer:\n"); 268 __QUEX_STD_printf(" Memory:\n"); 269 __QUEX_STD_printf(" _front = 0;\n"); 270 __QUEX_STD_printf(" _back = +0x%X;\n", (int)(me->_memory._back - Offset)); 271 if( me->input.end_p != 0x0 ) 272 __QUEX_STD_printf(" input.end_p = +0x%X;\n", (int)(me->input.end_p - Offset)); 273 else 274 __QUEX_STD_printf(" input.end_p = <void>;\n"); 275 276 /* Store whether the memory has an external owner */ 277 __QUEX_STD_printf(" _external_owner_f = %s;\n", me->_memory.ownership == E_Ownership_EXTERNAL ? "true" : "false"); 278 279 __QUEX_STD_printf(" _read_p = +0x%X;\n", (int)(me->_read_p - Offset)); 280 __QUEX_STD_printf(" _lexeme_start_p = +0x%X;\n", (int)(me->_lexeme_start_p - Offset)); 281 282 __QUEX_STD_printf(" _character_at_lexeme_start = %X;\n", (int)me->_lexatom_at_lexeme_start); 283 # ifdef __QUEX_OPTION_SUPPORT_BEGIN_OF_LINE_PRE_CONDITION 284 __QUEX_STD_printf(" _character_before_lexeme_start = %X;\n", (int)me->_lexatom_before_lexeme_start); 285 # endif 286 __QUEX_STD_printf(" _content_character_index_begin = %i;\n", (int)QUEX_NAME(Buffer_input_lexatom_index_begin)(me)); 287 __QUEX_STD_printf(" input.end_character_index = %i;\n", (int)QUEX_NAME(Buffer_input_lexatom_index_end)(me)); 288 if( me->filler ) { 289 __QUEX_STD_printf(" _byte_order_reversion_active_f = %s;\n", me->filler->_byte_order_reversion_active_f ? "true" : "false"); 290 } 291 } 292 293 QUEX_INLINE void 294 QUEX_NAME(Buffer_print_content)(QUEX_NAME(Buffer)* me) 295 { 296 QUEX_NAME(Buffer_print_content_core)(sizeof(QUEX_TYPE_LEXATOM), 297 (const uint8_t*)me->_memory._front, 298 (const uint8_t*)me->_memory._back, 299 (const uint8_t*)me->_read_p, 300 (const uint8_t*)me->input.end_p, 301 /* BordersF */ true); 302 303 } 304 305 QUEX_INLINE void 306 QUEX_NAME(Buffer_print_content_core)(const size_t ElementSize, 307 const uint8_t* Front, 308 const uint8_t* Back, 309 const uint8_t* ReadP, 310 const uint8_t* InputEndP, 311 bool BordersF) 312 { 313 const uint8_t* it; 314 __QUEX_STD_printf("["); 315 for(it=Front; it <= Back; it += ElementSize) { 316 if( it < InputEndP ) { 317 switch( ElementSize ) { 318 case 1: __QUEX_STD_printf("%02X", it[0]); break; 319 case 2: __QUEX_STD_printf("%04X", ((uint16_t*)it)[0]); break; 320 case 4: 321 default: __QUEX_STD_printf("%08X", ((uint32_t*)it)[0]); break; 322 } 323 } 324 else { 325 __QUEX_STD_printf("--"); 326 } 327 328 if( &it[ElementSize] == ReadP ) { 329 __QUEX_STD_printf(">"); 330 } 331 else if( BordersF && (it == Front || &it[1] == Back ) ) { 332 __QUEX_STD_printf("|"); 333 } 334 else if( it != Back && &it[ElementSize] != ReadP ) { 335 __QUEX_STD_printf("."); 336 } 337 } 338 __QUEX_STD_printf("]"); 339 } 340 341 342 QUEX_NAMESPACE_MAIN_CLOSE 343 344 345 #endif /* __QUEX_INCLUDE_GUARD__BUFFER__BUFFER_DEBUG_I */