comparison libiberty/cp-demangle.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
300 /* Set to 1 if we saw a demangling error. */ 300 /* Set to 1 if we saw a demangling error. */
301 int demangle_failure; 301 int demangle_failure;
302 /* The current index into any template argument packs we are using 302 /* The current index into any template argument packs we are using
303 for printing. */ 303 for printing. */
304 int pack_index; 304 int pack_index;
305 /* Number of d_print_flush calls so far. */
306 unsigned long int flush_count;
305 }; 307 };
306 308
307 #ifdef CP_DEMANGLE_DEBUG 309 #ifdef CP_DEMANGLE_DEBUG
308 static void d_dump (struct demangle_component *, int); 310 static void d_dump (struct demangle_component *, int);
309 #endif 311 #endif
316 struct demangle_component *, 318 struct demangle_component *,
317 struct demangle_component *); 319 struct demangle_component *);
318 320
319 static struct demangle_component * 321 static struct demangle_component *
320 d_make_name (struct d_info *, const char *, int); 322 d_make_name (struct d_info *, const char *, int);
323
324 static struct demangle_component *
325 d_make_demangle_mangled_name (struct d_info *, const char *);
321 326
322 static struct demangle_component * 327 static struct demangle_component *
323 d_make_builtin_type (struct d_info *, 328 d_make_builtin_type (struct d_info *,
324 const struct demangle_builtin_type_info *); 329 const struct demangle_builtin_type_info *);
325 330
863 p->type = type; 868 p->type = type;
864 p->u.s_binary.left = left; 869 p->u.s_binary.left = left;
865 p->u.s_binary.right = right; 870 p->u.s_binary.right = right;
866 } 871 }
867 return p; 872 return p;
873 }
874
875 /* Add a new demangle mangled name component. */
876
877 static struct demangle_component *
878 d_make_demangle_mangled_name (struct d_info *di, const char *s)
879 {
880 if (d_peek_char (di) != '_' || d_peek_next_char (di) != 'Z')
881 return d_make_name (di, s, strlen (s));
882 d_advance (di, 2);
883 return d_encoding (di, 0);
868 } 884 }
869 885
870 /* Add a new name component. */ 886 /* Add a new name component. */
871 887
872 static struct demangle_component * 888 static struct demangle_component *
3283 dpi->options = options; 3299 dpi->options = options;
3284 dpi->len = 0; 3300 dpi->len = 0;
3285 dpi->last_char = '\0'; 3301 dpi->last_char = '\0';
3286 dpi->templates = NULL; 3302 dpi->templates = NULL;
3287 dpi->modifiers = NULL; 3303 dpi->modifiers = NULL;
3304 dpi->flush_count = 0;
3288 3305
3289 dpi->callback = callback; 3306 dpi->callback = callback;
3290 dpi->opaque = opaque; 3307 dpi->opaque = opaque;
3291 3308
3292 dpi->demangle_failure = 0; 3309 dpi->demangle_failure = 0;
3312 d_print_flush (struct d_print_info *dpi) 3329 d_print_flush (struct d_print_info *dpi)
3313 { 3330 {
3314 dpi->buf[dpi->len] = '\0'; 3331 dpi->buf[dpi->len] = '\0';
3315 dpi->callback (dpi->buf, dpi->len, dpi->opaque); 3332 dpi->callback (dpi->buf, dpi->len, dpi->opaque);
3316 dpi->len = 0; 3333 dpi->len = 0;
3334 dpi->flush_count++;
3317 } 3335 }
3318 3336
3319 /* Append characters and buffers for printing. */ 3337 /* Append characters and buffers for printing. */
3320 3338
3321 static inline void 3339 static inline void
3474 return NULL; 3492 return NULL;
3475 3493
3476 case DEMANGLE_COMPONENT_PACK_EXPANSION: 3494 case DEMANGLE_COMPONENT_PACK_EXPANSION:
3477 return NULL; 3495 return NULL;
3478 3496
3497 case DEMANGLE_COMPONENT_LAMBDA:
3479 case DEMANGLE_COMPONENT_NAME: 3498 case DEMANGLE_COMPONENT_NAME:
3480 case DEMANGLE_COMPONENT_OPERATOR: 3499 case DEMANGLE_COMPONENT_OPERATOR:
3481 case DEMANGLE_COMPONENT_BUILTIN_TYPE: 3500 case DEMANGLE_COMPONENT_BUILTIN_TYPE:
3482 case DEMANGLE_COMPONENT_SUB_STD: 3501 case DEMANGLE_COMPONENT_SUB_STD:
3483 case DEMANGLE_COMPONENT_CHARACTER: 3502 case DEMANGLE_COMPONENT_CHARACTER:
4045 if (d_left (dc) != NULL) 4064 if (d_left (dc) != NULL)
4046 d_print_comp (dpi, d_left (dc)); 4065 d_print_comp (dpi, d_left (dc));
4047 if (d_right (dc) != NULL) 4066 if (d_right (dc) != NULL)
4048 { 4067 {
4049 size_t len; 4068 size_t len;
4069 unsigned long int flush_count;
4070 /* Make sure ", " isn't flushed by d_append_string, otherwise
4071 dpi->len -= 2 wouldn't work. */
4072 if (dpi->len >= sizeof (dpi->buf) - 2)
4073 d_print_flush (dpi);
4050 d_append_string (dpi, ", "); 4074 d_append_string (dpi, ", ");
4051 len = dpi->len; 4075 len = dpi->len;
4076 flush_count = dpi->flush_count;
4052 d_print_comp (dpi, d_right (dc)); 4077 d_print_comp (dpi, d_right (dc));
4053 /* If that didn't print anything (which can happen with empty 4078 /* If that didn't print anything (which can happen with empty
4054 template argument packs), remove the comma and space. */ 4079 template argument packs), remove the comma and space. */
4055 if (dpi->len == len) 4080 if (dpi->flush_count == flush_count && dpi->len == len)
4056 dpi->len -= 2; 4081 dpi->len -= 2;
4057 } 4082 }
4058 return; 4083 return;
4059 4084
4060 case DEMANGLE_COMPONENT_OPERATOR: 4085 case DEMANGLE_COMPONENT_OPERATOR:
4533 d_print_function_type (struct d_print_info *dpi, 4558 d_print_function_type (struct d_print_info *dpi,
4534 const struct demangle_component *dc, 4559 const struct demangle_component *dc,
4535 struct d_print_mod *mods) 4560 struct d_print_mod *mods)
4536 { 4561 {
4537 int need_paren; 4562 int need_paren;
4538 int saw_mod;
4539 int need_space; 4563 int need_space;
4540 struct d_print_mod *p; 4564 struct d_print_mod *p;
4541 struct d_print_mod *hold_modifiers; 4565 struct d_print_mod *hold_modifiers;
4542 4566
4543 need_paren = 0; 4567 need_paren = 0;
4544 saw_mod = 0;
4545 need_space = 0; 4568 need_space = 0;
4546 for (p = mods; p != NULL; p = p->next) 4569 for (p = mods; p != NULL; p = p->next)
4547 { 4570 {
4548 if (p->printed) 4571 if (p->printed)
4549 break; 4572 break;
4550 4573
4551 saw_mod = 1;
4552 switch (p->mod->type) 4574 switch (p->mod->type)
4553 { 4575 {
4554 case DEMANGLE_COMPONENT_POINTER: 4576 case DEMANGLE_COMPONENT_POINTER:
4555 case DEMANGLE_COMPONENT_REFERENCE: 4577 case DEMANGLE_COMPONENT_REFERENCE:
4556 case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 4578 case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
4575 } 4597 }
4576 if (need_paren) 4598 if (need_paren)
4577 break; 4599 break;
4578 } 4600 }
4579 4601
4580 if (d_left (dc) != NULL && ! saw_mod)
4581 need_paren = 1;
4582
4583 if (need_paren) 4602 if (need_paren)
4584 { 4603 {
4585 if (! need_space) 4604 if (! need_space)
4586 { 4605 {
4587 if (d_last_char (dpi) != '(' 4606 if (d_last_char (dpi) != '('
4816 d_advance (&di, 11); 4835 d_advance (&di, 11);
4817 dc = d_make_comp (&di, 4836 dc = d_make_comp (&di,
4818 (type == DCT_GLOBAL_CTORS 4837 (type == DCT_GLOBAL_CTORS
4819 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS 4838 ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
4820 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS), 4839 : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS),
4821 d_make_name (&di, d_str (&di), strlen (d_str (&di))), 4840 d_make_demangle_mangled_name (&di, d_str (&di)),
4822 NULL); 4841 NULL);
4823 d_advance (&di, strlen (d_str (&di))); 4842 d_advance (&di, strlen (d_str (&di)));
4824 break; 4843 break;
4825 } 4844 }
4826 4845