@@ -66,6 +66,8 @@ static const struct {
66
66
67
67
static int equal_list (struct string_list * a , struct string_list * b );
68
68
static void print_list (FILE * f , struct string_list * list );
69
+ static struct string_list * concat_list (struct string_list * start , ...);
70
+ static struct string_list * mk_node (const char * string );
69
71
static void print_location (void );
70
72
static void print_type_name (enum symbol_type type , const char * name );
71
73
@@ -299,6 +301,35 @@ void free_list(struct string_list *s, struct string_list *e)
299
301
}
300
302
}
301
303
304
+ static struct string_list * mk_node (const char * string )
305
+ {
306
+ struct string_list * newnode ;
307
+
308
+ newnode = xmalloc (sizeof (* newnode ));
309
+ newnode -> string = xstrdup (string );
310
+ newnode -> tag = SYM_NORMAL ;
311
+ newnode -> next = NULL ;
312
+
313
+ return newnode ;
314
+ }
315
+
316
+ static struct string_list * concat_list (struct string_list * start , ...)
317
+ {
318
+ va_list ap ;
319
+ struct string_list * n , * n2 ;
320
+
321
+ if (!start )
322
+ return NULL ;
323
+ for (va_start (ap , start ); (n = va_arg (ap , struct string_list * ));) {
324
+ for (n2 = n ; n2 -> next ; n2 = n2 -> next )
325
+ ;
326
+ n2 -> next = start ;
327
+ start = n ;
328
+ }
329
+ va_end (ap );
330
+ return start ;
331
+ }
332
+
302
333
struct string_list * copy_node (struct string_list * node )
303
334
{
304
335
struct string_list * newnode ;
@@ -499,42 +530,17 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
499
530
case SYM_ENUM :
500
531
subsym = find_symbol (cur -> string , cur -> tag );
501
532
if (!subsym ) {
502
- struct string_list * n , * t = NULL ;
533
+ struct string_list * n ;
503
534
504
535
error_with_pos ("expand undefined %s %s" ,
505
536
symbol_types [cur -> tag ].name ,
506
537
cur -> string );
507
-
508
- n = xmalloc (sizeof (* n ));
509
- n -> string = xstrdup (symbol_types [cur -> tag ].name );
510
- n -> tag = SYM_NORMAL ;
511
- n -> next = t ;
512
- t = n ;
513
-
514
- n = xmalloc (sizeof (* n ));
515
- n -> string = xstrdup (cur -> string );
516
- n -> tag = SYM_NORMAL ;
517
- n -> next = t ;
518
- t = n ;
519
-
520
- n = xmalloc (sizeof (* n ));
521
- n -> string = xstrdup ("{" );
522
- n -> tag = SYM_NORMAL ;
523
- n -> next = t ;
524
- t = n ;
525
-
526
- n = xmalloc (sizeof (* n ));
527
- n -> string = xstrdup ("UNKNOWN" );
528
- n -> tag = SYM_NORMAL ;
529
- n -> next = t ;
530
- t = n ;
531
-
532
- n = xmalloc (sizeof (* n ));
533
- n -> string = xstrdup ("}" );
534
- n -> tag = SYM_NORMAL ;
535
- n -> next = t ;
536
- t = n ;
537
-
538
+ n = concat_list (mk_node
539
+ (symbol_types [cur -> tag ].name ),
540
+ mk_node (cur -> string ),
541
+ mk_node ("{" ),
542
+ mk_node ("UNKNOWN" ),
543
+ mk_node ("}" ), NULL );
538
544
subsym =
539
545
add_symbol (cur -> string , cur -> tag , n , 0 );
540
546
}
0 commit comments