modernc.org/ccgo/v3@v3.16.14/lib/testdata/bug/init2.c (about) 1 #include <stdbool.h> 2 #include <stdint.h> 3 4 typedef struct TSLexer TSLexer; 5 typedef int Length; 6 typedef struct{ int x; } TSRange; 7 typedef struct{ int y; } TSInput; 8 typedef struct{ int z; } TSLogger; 9 10 struct TSLexer { 11 int lookahead; 12 int result_symbol; 13 void (*advance)(TSLexer *, bool); 14 void (*mark_end)(TSLexer *); 15 uint32_t (*get_column)(TSLexer *); 16 bool (*is_at_included_range_start)(const TSLexer *); 17 bool (*eof)(const TSLexer *); 18 }; 19 20 typedef struct { 21 TSLexer data; 22 Length current_position; 23 Length token_start_position; 24 Length token_end_position; 25 26 TSRange *included_ranges; 27 const char *chunk; 28 TSInput input; 29 TSLogger logger; 30 31 uint32_t included_range_count; 32 uint32_t current_included_range_index; 33 uint32_t chunk_start; 34 uint32_t chunk_size; 35 uint32_t lookahead_size; 36 bool did_get_column; 37 38 char debug_buffer[100]; 39 } Lexer; 40 41 void advance(TSLexer *a, bool b) {} 42 void mark_end(TSLexer *a) {} 43 uint32_t get_column(TSLexer * a) { return 0; }; 44 bool is_at_included_range_start(const TSLexer *a) { return 0; } 45 bool eof(const TSLexer *a) { return 0; } 46 47 void ts_lexer_init(Lexer *self) { 48 *self = (Lexer) { 49 .data = { 50 // The lexer's methods are stored as struct fields so that generated 51 // parsers can call them without needing to be linked against this 52 // library. 53 .advance = advance, 54 .mark_end = mark_end, 55 .get_column = get_column, 56 .is_at_included_range_start = is_at_included_range_start, 57 .eof = eof, 58 .lookahead = 42, 59 .result_symbol = 43, 60 }, 61 .current_position = 44, 62 }; 63 } 64 65 int main() { 66 Lexer l; 67 ts_lexer_init(&l); 68 if (l.data.lookahead != 42) { 69 return __LINE__; 70 } 71 72 if (l.data.result_symbol != 43) { 73 return __LINE__; 74 } 75 76 if (l.data.advance != advance) { 77 return __LINE__; 78 } 79 80 if (l.data.mark_end != mark_end) { 81 return __LINE__; 82 } 83 84 if (l.data.get_column != get_column) { 85 return __LINE__; 86 } 87 88 if (l.data.is_at_included_range_start != is_at_included_range_start) { 89 return __LINE__; 90 } 91 92 if (l.data.eof != eof) { 93 return __LINE__; 94 } 95 96 return 0; 97 }