aboutsummaryrefslogtreecommitdiff
path: root/libiberty/cp-demangle.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2008-10-07 01:28:01 +0000
committerDJ Delorie <dj@redhat.com>2008-10-07 01:28:01 +0000
commit1c08f2c880d39514a2917c24de11e5619bb81081 (patch)
tree0f041bd9cc7d44123e435a79c88fa2b590a385ea /libiberty/cp-demangle.c
parent06fa9cecf14fc788c1c11618295a00af8526339c (diff)
downloadgdb-1c08f2c880d39514a2917c24de11e5619bb81081.zip
gdb-1c08f2c880d39514a2917c24de11e5619bb81081.tar.gz
gdb-1c08f2c880d39514a2917c24de11e5619bb81081.tar.bz2
merge from gcc
Diffstat (limited to 'libiberty/cp-demangle.c')
-rw-r--r--libiberty/cp-demangle.c298
1 files changed, 225 insertions, 73 deletions
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 3d292f0..3fa5f1f 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -299,6 +299,9 @@ struct d_print_info
struct d_print_mod *modifiers;
/* Set to 1 if we saw a demangling error. */
int demangle_failure;
+ /* The current index into any template argument packs we are using
+ for printing. */
+ int pack_index;
};
#ifdef CP_DEMANGLE_DEBUG
@@ -663,6 +666,9 @@ d_dump (struct demangle_component *dc, int indent)
case DEMANGLE_COMPONENT_DECLTYPE:
printf ("decltype\n");
break;
+ case DEMANGLE_COMPONENT_PACK_EXPANSION:
+ printf ("pack expansion\n");
+ break;
}
d_dump (d_left (dc), indent + 2);
@@ -806,11 +812,10 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
case DEMANGLE_COMPONENT_COMPLEX:
case DEMANGLE_COMPONENT_IMAGINARY:
case DEMANGLE_COMPONENT_VENDOR_TYPE:
- case DEMANGLE_COMPONENT_ARGLIST:
- case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
case DEMANGLE_COMPONENT_CAST:
case DEMANGLE_COMPONENT_JAVA_RESOURCE:
case DEMANGLE_COMPONENT_DECLTYPE:
+ case DEMANGLE_COMPONENT_PACK_EXPANSION:
if (left == NULL)
return NULL;
break;
@@ -831,6 +836,8 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
case DEMANGLE_COMPONENT_RESTRICT_THIS:
case DEMANGLE_COMPONENT_VOLATILE_THIS:
case DEMANGLE_COMPONENT_CONST_THIS:
+ case DEMANGLE_COMPONENT_ARGLIST:
+ case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
break;
/* Other types should not be seen here. */
@@ -1433,6 +1440,7 @@ const struct demangle_operator_info cplus_demangle_operators[] =
{ "da", NL ("delete[]"), 1 },
{ "de", NL ("*"), 1 },
{ "dl", NL ("delete"), 1 },
+ { "dt", NL ("."), 2 },
{ "dv", NL ("/"), 2 },
{ "eO", NL ("^="), 2 },
{ "eo", NL ("^"), 2 },
@@ -1875,21 +1883,24 @@ cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] =
/* n */ { NL ("__int128"), NL ("__int128"), D_PRINT_DEFAULT },
/* o */ { NL ("unsigned __int128"), NL ("unsigned __int128"),
D_PRINT_DEFAULT },
- /* The decimal floating point and half-precision floating point types
- don't use the normal builtin type encoding, they're just stuck into
- holes in the table for convenience. */
- /* p */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT },
- /* q */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT },
- /* r */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT },
+ /* p */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
+ /* q */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
+ /* r */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
/* s */ { NL ("short"), NL ("short"), D_PRINT_DEFAULT },
/* t */ { NL ("unsigned short"), NL ("unsigned short"), D_PRINT_DEFAULT },
- /* u */ { NL ("half"), NL ("half"), D_PRINT_FLOAT },
+ /* u */ { NULL, 0, NULL, 0, D_PRINT_DEFAULT },
/* v */ { NL ("void"), NL ("void"), D_PRINT_VOID },
/* w */ { NL ("wchar_t"), NL ("char"), D_PRINT_DEFAULT },
/* x */ { NL ("long long"), NL ("long"), D_PRINT_LONG_LONG },
/* y */ { NL ("unsigned long long"), NL ("unsigned long long"),
D_PRINT_UNSIGNED_LONG_LONG },
/* z */ { NL ("..."), NL ("..."), D_PRINT_DEFAULT },
+ /* 26 */ { NL ("decimal32"), NL ("decimal32"), D_PRINT_DEFAULT },
+ /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT },
+ /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT },
+ /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT },
+ /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT },
+ /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT },
};
CP_STATIC_IF_GLIBCPP_V3
@@ -2070,30 +2081,38 @@ cplus_demangle_type (struct d_info *di)
case 'p':
/* Pack expansion. */
- return NULL;
+ ret = d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION,
+ cplus_demangle_type (di), NULL);
+ break;
case 'f':
- /* 32-bit DFP */
- ret = d_make_builtin_type (di,
- &cplus_demangle_builtin_types['p' - 'a']);
+ /* 32-bit decimal floating point */
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[26]);
di->expansion += ret->u.s_builtin.type->len;
break;
case 'd':
- /* 64-bit decimal floating point */
- ret = d_make_builtin_type (di,
- &cplus_demangle_builtin_types['q' - 'a']);
+ /* 64-bit DFP */
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[27]);
di->expansion += ret->u.s_builtin.type->len;
break;
case 'e':
/* 128-bit DFP */
- ret = d_make_builtin_type (di,
- &cplus_demangle_builtin_types['r' - 'a']);
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[28]);
di->expansion += ret->u.s_builtin.type->len;
break;
case 'h':
/* 16-bit half-precision FP */
- ret = d_make_builtin_type (di,
- &cplus_demangle_builtin_types['u' - 'a']);
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[29]);
+ di->expansion += ret->u.s_builtin.type->len;
+ break;
+ case 's':
+ /* char16_t */
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[30]);
+ di->expansion += ret->u.s_builtin.type->len;
+ break;
+ case 'i':
+ /* char32_t */
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[31]);
di->expansion += ret->u.s_builtin.type->len;
break;
}
@@ -2390,6 +2409,13 @@ d_template_args (struct d_info *di)
if (! d_check_char (di, 'I'))
return NULL;
+ if (d_peek_char (di) == 'E')
+ {
+ /* An argument pack can be empty. */
+ d_advance (di, 1);
+ return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_ARGLIST, NULL, NULL);
+ }
+
al = NULL;
pal = &al;
while (1)
@@ -2439,6 +2465,10 @@ d_template_arg (struct d_info *di)
case 'L':
return d_expr_primary (di);
+ case 'I':
+ /* An argument pack. */
+ return d_template_args (di);
+
default:
return cplus_demangle_type (di);
}
@@ -2452,6 +2482,12 @@ d_exprlist (struct d_info *di)
struct demangle_component *list = NULL;
struct demangle_component **p = &list;
+ if (d_peek_char (di) == 'E')
+ {
+ d_advance (di, 1);
+ return d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, NULL, NULL);
+ }
+
while (1)
{
struct demangle_component *arg = d_expression (di);
@@ -2515,6 +2551,19 @@ d_expression (struct d_info *di)
d_advance (di, 2);
return cplus_demangle_type (di);
}
+ else if (IS_DIGIT (peek))
+ {
+ /* We can get an unqualified name as an expression in the case of
+ a dependent member access, i.e. decltype(T().i). */
+ struct demangle_component *name = d_unqualified_name (di);
+ if (name == NULL)
+ return NULL;
+ if (d_peek_char (di) == 'I')
+ return d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
+ d_template_args (di));
+ else
+ return name;
+ }
else
{
struct demangle_component *op;
@@ -3067,6 +3116,123 @@ cplus_demangle_print (int options, const struct demangle_component *dc,
return dgs.buf;
}
+/* Returns the I'th element of the template arglist ARGS, or NULL on
+ failure. */
+
+static struct demangle_component *
+d_index_template_argument (struct demangle_component *args, int i)
+{
+ struct demangle_component *a;
+
+ for (a = args;
+ a != NULL;
+ a = d_right (a))
+ {
+ if (a->type != DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
+ return NULL;
+ if (i <= 0)
+ break;
+ --i;
+ }
+ if (i != 0 || a == NULL)
+ return NULL;
+
+ return d_left (a);
+}
+
+/* Returns the template argument from the current context indicated by DC,
+ which is a DEMANGLE_COMPONENT_TEMPLATE_PARAM, or NULL. */
+
+static struct demangle_component *
+d_lookup_template_argument (struct d_print_info *dpi,
+ const struct demangle_component *dc)
+{
+ if (dpi->templates == NULL)
+ {
+ d_print_error (dpi);
+ return NULL;
+ }
+
+ return d_index_template_argument
+ (d_right (dpi->templates->template_decl),
+ dc->u.s_number.number);
+}
+
+/* Returns a template argument pack used in DC (any will do), or NULL. */
+
+static struct demangle_component *
+d_find_pack (struct d_print_info *dpi,
+ const struct demangle_component *dc)
+{
+ struct demangle_component *a;
+ if (dc == NULL)
+ return NULL;
+
+ switch (dc->type)
+ {
+ case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
+ a = d_lookup_template_argument (dpi, dc);
+ if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
+ return a;
+ return NULL;
+
+ case DEMANGLE_COMPONENT_PACK_EXPANSION:
+ return NULL;
+
+ case DEMANGLE_COMPONENT_NAME:
+ case DEMANGLE_COMPONENT_OPERATOR:
+ case DEMANGLE_COMPONENT_BUILTIN_TYPE:
+ case DEMANGLE_COMPONENT_SUB_STD:
+ case DEMANGLE_COMPONENT_CHARACTER:
+ return NULL;
+
+ case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
+ return d_find_pack (dpi, dc->u.s_extended_operator.name);
+ case DEMANGLE_COMPONENT_CTOR:
+ return d_find_pack (dpi, dc->u.s_ctor.name);
+ case DEMANGLE_COMPONENT_DTOR:
+ return d_find_pack (dpi, dc->u.s_dtor.name);
+
+ default:
+ a = d_find_pack (dpi, d_left (dc));
+ if (a)
+ return a;
+ return d_find_pack (dpi, d_right (dc));
+ }
+}
+
+/* Returns the length of the template argument pack DC. */
+
+static int
+d_pack_length (const struct demangle_component *dc)
+{
+ int count = 0;
+ while (dc && dc->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST
+ && d_left (dc) != NULL)
+ {
+ ++count;
+ dc = d_right (dc);
+ }
+ return count;
+}
+
+/* DC is a component of a mangled expression. Print it, wrapped in parens
+ if needed. */
+
+static void
+d_print_subexpr (struct d_print_info *dpi,
+ const struct demangle_component *dc)
+{
+ int simple = 0;
+ if (dc->type == DEMANGLE_COMPONENT_NAME)
+ simple = 1;
+ if (!simple)
+ d_append_char (dpi, '(');
+ d_print_comp (dpi, dc);
+ if (!simple)
+ d_append_char (dpi, ')');
+}
+
/* Subroutine to handle components. */
static void
@@ -3252,30 +3418,13 @@ d_print_comp (struct d_print_info *dpi,
case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
{
- long i;
- struct demangle_component *a;
struct d_print_template *hold_dpt;
+ struct demangle_component *a = d_lookup_template_argument (dpi, dc);
- if (dpi->templates == NULL)
- {
- d_print_error (dpi);
- return;
- }
- i = dc->u.s_number.number;
- for (a = d_right (dpi->templates->template_decl);
- a != NULL;
- a = d_right (a))
- {
- if (a->type != DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
- {
- d_print_error (dpi);
- return;
- }
- if (i <= 0)
- break;
- --i;
- }
- if (i != 0 || a == NULL)
+ if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
+ a = d_index_template_argument (a, dpi->pack_index);
+
+ if (a == NULL)
{
d_print_error (dpi);
return;
@@ -3289,7 +3438,7 @@ d_print_comp (struct d_print_info *dpi,
hold_dpt = dpi->templates;
dpi->templates = hold_dpt->next;
- d_print_comp (dpi, d_left (a));
+ d_print_comp (dpi, a);
dpi->templates = hold_dpt;
@@ -3578,7 +3727,8 @@ d_print_comp (struct d_print_info *dpi,
case DEMANGLE_COMPONENT_ARGLIST:
case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
- d_print_comp (dpi, d_left (dc));
+ if (d_left (dc) != NULL)
+ d_print_comp (dpi, d_left (dc));
if (d_right (dc) != NULL)
{
d_append_string (dpi, ", ");
@@ -3618,11 +3768,12 @@ d_print_comp (struct d_print_info *dpi,
d_print_cast (dpi, d_left (dc));
d_append_char (dpi, ')');
}
- d_append_char (dpi, '(');
- if (d_left (dc)->type != DEMANGLE_COMPONENT_CAST
- || d_right (dc)->type != DEMANGLE_COMPONENT_BUILTIN_TYPE)
- d_print_comp (dpi, d_right (dc));
- d_append_char (dpi, ')');
+ if (d_left (dc)->type == DEMANGLE_COMPONENT_CAST
+ && d_right (dc)->type == DEMANGLE_COMPONENT_BUILTIN_TYPE)
+ /* type() -- FIXME what about type(multiple,args) */
+ d_append_string (dpi, "()");
+ else
+ d_print_subexpr (dpi, d_right (dc));
return;
case DEMANGLE_COMPONENT_BINARY:
@@ -3632,15 +3783,6 @@ d_print_comp (struct d_print_info *dpi,
return;
}
- if (!strcmp (d_left (dc)->u.s_operator.op->code, "cl"))
- {
- d_print_comp (dpi, d_left (d_right (dc)));
- d_append_string (dpi, " (");
- d_print_comp (dpi, d_right (d_right (dc)));
- d_append_char (dpi, ')');
- return;
- }
-
/* We wrap an expression which uses the greater-than operator in
an extra layer of parens so that it does not get confused
with the '>' which ends the template parameters. */
@@ -3649,13 +3791,10 @@ d_print_comp (struct d_print_info *dpi,
&& d_left (dc)->u.s_operator.op->name[0] == '>')
d_append_char (dpi, '(');
- d_append_char (dpi, '(');
- d_print_comp (dpi, d_left (d_right (dc)));
- d_append_string (dpi, ") ");
- d_print_expr_op (dpi, d_left (dc));
- d_append_string (dpi, " (");
- d_print_comp (dpi, d_right (d_right (dc)));
- d_append_char (dpi, ')');
+ d_print_subexpr (dpi, d_left (d_right (dc)));
+ if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") != 0)
+ d_print_expr_op (dpi, d_left (dc));
+ d_print_subexpr (dpi, d_right (d_right (dc)));
if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR
&& d_left (dc)->u.s_operator.op->len == 1
@@ -3676,15 +3815,11 @@ d_print_comp (struct d_print_info *dpi,
d_print_error (dpi);
return;
}
- d_append_char (dpi, '(');
- d_print_comp (dpi, d_left (d_right (dc)));
- d_append_string (dpi, ") ");
+ d_print_subexpr (dpi, d_left (d_right (dc)));
d_print_expr_op (dpi, d_left (dc));
- d_append_string (dpi, " (");
- d_print_comp (dpi, d_left (d_right (d_right (dc))));
- d_append_string (dpi, ") : (");
- d_print_comp (dpi, d_right (d_right (d_right (dc))));
- d_append_char (dpi, ')');
+ d_print_subexpr (dpi, d_left (d_right (d_right (dc))));
+ d_append_string (dpi, " : ");
+ d_print_subexpr (dpi, d_right (d_right (d_right (dc))));
return;
case DEMANGLE_COMPONENT_TRINARY_ARG1:
@@ -3797,6 +3932,23 @@ d_print_comp (struct d_print_info *dpi,
d_append_char (dpi, ')');
return;
+ case DEMANGLE_COMPONENT_PACK_EXPANSION:
+ {
+ struct demangle_component *a = d_find_pack (dpi, d_left (dc));
+ int len = d_pack_length (a);
+ int i;
+
+ dc = d_left (dc);
+ for (i = 0; i < len; ++i)
+ {
+ dpi->pack_index = i;
+ d_print_comp (dpi, dc);
+ if (i < len-1)
+ d_append_string (dpi, ", ");
+ }
+ }
+ return;
+
default:
d_print_error (dpi);
return;