44
55id_table * alloc_empty_table (void ) {
66 id_table * table = malloc (sizeof (id_table ));
7- table -> size = 10 ;
8- table -> count = 0 ;
9- table -> ids = calloc (10 , sizeof (ID ));
7+
8+ * table = (id_table ) {
9+ .size = 10 ,
10+ .count = 0 ,
11+ .ids = calloc (10 , sizeof (ID )),
12+ .next = NULL ,
13+ };
1014
1115 return table ;
1216}
1317
1418id_table * alloc_reset_table (void ) {
1519 id_table * table = malloc (sizeof (id_table ));
16- table -> size = 0 ;
20+
21+ * table = (id_table ) {
22+ .size = 0 ,
23+ .count = 0 ,
24+ .ids = NULL ,
25+ .next = NULL ,
26+ };
1727
1828 return table ;
1929}
@@ -182,15 +192,18 @@ VALUE get_comment(parserstate *state, int subject_line) {
182192}
183193
184194comment * alloc_comment (token comment_token , comment * last_comment ) {
185- comment * new_comment = calloc ( 1 , sizeof (comment ));
195+ comment * new_comment = malloc ( sizeof (comment ));
186196
187- new_comment -> next_comment = last_comment ;
197+ * new_comment = (comment ) {
198+ .start = comment_token .range .start ,
199+ .end = comment_token .range .end ,
188200
189- new_comment -> start = comment_token .range .start ;
190- new_comment -> end = comment_token .range .end ;
201+ .line_size = 0 ,
202+ .line_count = 0 ,
203+ .tokens = NULL ,
191204
192- new_comment -> line_size = 0 ;
193- new_comment -> line_count = 0 ;
205+ . next_comment = last_comment ,
206+ } ;
194207
195208 comment_insert_new_line (new_comment , comment_token );
196209
@@ -279,11 +292,25 @@ lexstate *alloc_lexer(VALUE string, int start_pos, int end_pos) {
279292 rb_raise (rb_eArgError , "negative position range: %d...%d" , start_pos , end_pos );
280293 }
281294
282- lexstate * lexer = calloc (1 , sizeof (lexstate ));
283- lexer -> string = string ;
284- lexer -> current .line = 1 ;
285- lexer -> start_pos = start_pos ;
286- lexer -> end_pos = end_pos ;
295+ lexstate * lexer = malloc (sizeof (lexstate ));
296+
297+ position start_position = (position ) {
298+ .byte_pos = 0 ,
299+ .char_pos = 0 ,
300+ .line = 1 ,
301+ .column = 0 ,
302+ };
303+
304+ * lexer = (lexstate ) {
305+ .string = string ,
306+ .start_pos = start_pos ,
307+ .end_pos = end_pos ,
308+ .current = start_position ,
309+ .start = { 0 },
310+ .first_token_of_line = false,
311+ .last_char = 0 ,
312+ };
313+
287314 skipn (lexer , start_pos );
288315 lexer -> start = lexer -> current ;
289316 lexer -> first_token_of_line = lexer -> current .column == 0 ;
@@ -292,13 +319,20 @@ lexstate *alloc_lexer(VALUE string, int start_pos, int end_pos) {
292319}
293320
294321parserstate * alloc_parser (VALUE buffer , lexstate * lexer , int start_pos , int end_pos , VALUE variables ) {
295- parserstate * parser = calloc (1 , sizeof (parserstate ));
296- parser -> lexstate = lexer ;
297- parser -> buffer = buffer ;
298- parser -> current_token = NullToken ;
299- parser -> next_token = NullToken ;
300- parser -> next_token2 = NullToken ;
301- parser -> next_token3 = NullToken ;
322+ parserstate * parser = malloc (sizeof (parserstate ));
323+
324+ * parser = (parserstate ) {
325+ .lexstate = lexer ,
326+
327+ .current_token = NullToken ,
328+ .next_token = NullToken ,
329+ .next_token2 = NullToken ,
330+ .next_token3 = NullToken ,
331+ .buffer = buffer ,
332+
333+ .vars = NULL ,
334+ .last_comment = NULL ,
335+ };
302336
303337 parser_advance (parser );
304338 parser_advance (parser );
0 commit comments