cxxfilt 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /* Demangler for g++ V3 ABI.
2
- Copyright (C) 2003-2018 Free Software Foundation, Inc.
2
+ Copyright (C) 2003-2025 Free Software Foundation, Inc.
3
3
  Written by Ian Lance Taylor <ian@wasabisystems.com>.
4
4
 
5
5
  This file is part of the libiberty library, which is part of GCC.
@@ -192,9 +192,9 @@ static void d_init_info (const char *, int, size_t, struct d_info *);
192
192
  #else
193
193
  #ifdef __STDC__
194
194
  #ifdef __STDC_VERSION__
195
- #if __STDC_VERSION__ >= 199901L
195
+ #if __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__
196
196
  #define CP_DYNAMIC_ARRAYS
197
- #endif /* __STDC__VERSION >= 199901L */
197
+ #endif /* __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__ */
198
198
  #endif /* defined (__STDC_VERSION__) */
199
199
  #endif /* defined (__STDC__) */
200
200
  #endif /* ! defined (__GNUC__) */
@@ -347,9 +347,9 @@ struct d_print_info
347
347
  /* Number of times d_print_comp was recursively called. Should not
348
348
  be bigger than MAX_RECURSION_COUNT. */
349
349
  int recursion;
350
- /* Non-zero if we're printing a lambda argument. A template
351
- parameter reference actually means 'auto'. */
352
- int is_lambda_arg;
350
+ /* 1 more than the number of explicit template parms of a lambda. Template
351
+ parm references >= are actually 'auto'. */
352
+ int lambda_tpl_parms;
353
353
  /* The current index into any template argument packs we are using
354
354
  for printing, or -1 to print the whole pack. */
355
355
  int pack_index;
@@ -425,13 +425,16 @@ is_ctor_dtor_or_conversion (struct demangle_component *);
425
425
 
426
426
  static struct demangle_component *d_encoding (struct d_info *, int);
427
427
 
428
- static struct demangle_component *d_name (struct d_info *);
428
+ static struct demangle_component *d_name (struct d_info *, int substable);
429
429
 
430
430
  static struct demangle_component *d_nested_name (struct d_info *);
431
431
 
432
- static struct demangle_component *d_prefix (struct d_info *);
432
+ static int d_maybe_module_name (struct d_info *, struct demangle_component **);
433
433
 
434
- static struct demangle_component *d_unqualified_name (struct d_info *);
434
+ static struct demangle_component *d_prefix (struct d_info *, int);
435
+
436
+ static struct demangle_component *d_unqualified_name (struct d_info *,
437
+ struct demangle_component *scope, struct demangle_component *module);
435
438
 
436
439
  static struct demangle_component *d_source_name (struct d_info *);
437
440
 
@@ -462,7 +465,7 @@ static struct demangle_component *
462
465
  d_bare_function_type (struct d_info *, int);
463
466
 
464
467
  static struct demangle_component *
465
- d_class_enum_type (struct d_info *);
468
+ d_class_enum_type (struct d_info *, int);
466
469
 
467
470
  static struct demangle_component *d_array_type (struct d_info *);
468
471
 
@@ -488,6 +491,10 @@ static struct demangle_component *d_local_name (struct d_info *);
488
491
 
489
492
  static int d_discriminator (struct d_info *);
490
493
 
494
+ static struct demangle_component *d_template_parm (struct d_info *, int *bad);
495
+
496
+ static struct demangle_component *d_template_head (struct d_info *, int *bad);
497
+
491
498
  static struct demangle_component *d_lambda (struct d_info *);
492
499
 
493
500
  static struct demangle_component *d_unnamed_type (struct d_info *);
@@ -517,7 +524,7 @@ d_growable_string_callback_adapter (const char *, size_t, void *);
517
524
 
518
525
  static void
519
526
  d_print_init (struct d_print_info *, demangle_callbackref, void *,
520
- const struct demangle_component *);
527
+ struct demangle_component *);
521
528
 
522
529
  static inline void d_print_error (struct d_print_info *);
523
530
 
@@ -574,6 +581,7 @@ static char *d_demangle (const char *, int, size_t *);
574
581
  case DEMANGLE_COMPONENT_CONST_THIS: \
575
582
  case DEMANGLE_COMPONENT_REFERENCE_THIS: \
576
583
  case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS: \
584
+ case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION: \
577
585
  case DEMANGLE_COMPONENT_TRANSACTION_SAFE: \
578
586
  case DEMANGLE_COMPONENT_NOEXCEPT: \
579
587
  case DEMANGLE_COMPONENT_THROW_SPEC
@@ -625,6 +633,9 @@ d_dump (struct demangle_component *dc, int indent)
625
633
  case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
626
634
  printf ("template parameter %ld\n", dc->u.s_number.number);
627
635
  return;
636
+ case DEMANGLE_COMPONENT_TPARM_OBJ:
637
+ printf ("template parameter object\n");
638
+ break;
628
639
  case DEMANGLE_COMPONENT_FUNCTION_PARAM:
629
640
  printf ("function parameter %ld\n", dc->u.s_number.number);
630
641
  return;
@@ -642,6 +653,13 @@ d_dump (struct demangle_component *dc, int indent)
642
653
  case DEMANGLE_COMPONENT_BUILTIN_TYPE:
643
654
  printf ("builtin type %s\n", dc->u.s_builtin.type->name);
644
655
  return;
656
+ case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE:
657
+ {
658
+ char suffix[2] = { dc->u.s_extended_builtin.suffix, 0 };
659
+ printf ("builtin type %s%d%s\n", dc->u.s_extended_builtin.type->name,
660
+ dc->u.s_extended_builtin.arg, suffix);
661
+ }
662
+ return;
645
663
  case DEMANGLE_COMPONENT_OPERATOR:
646
664
  printf ("operator %s\n", dc->u.s_operator.op->name);
647
665
  return;
@@ -732,6 +750,9 @@ d_dump (struct demangle_component *dc, int indent)
732
750
  case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
733
751
  printf ("rvalue reference this\n");
734
752
  break;
753
+ case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION:
754
+ printf ("explicit object parameter\n");
755
+ break;
735
756
  case DEMANGLE_COMPONENT_TRANSACTION_SAFE:
736
757
  printf ("transaction_safe this\n");
737
758
  break;
@@ -765,11 +786,6 @@ d_dump (struct demangle_component *dc, int indent)
765
786
  case DEMANGLE_COMPONENT_PTRMEM_TYPE:
766
787
  printf ("pointer to member type\n");
767
788
  break;
768
- case DEMANGLE_COMPONENT_FIXED_TYPE:
769
- printf ("fixed-point type, accum? %d, sat? %d\n",
770
- dc->u.s_fixed.accum, dc->u.s_fixed.sat);
771
- d_dump (dc->u.s_fixed.length, indent + 2);
772
- break;
773
789
  case DEMANGLE_COMPONENT_ARGLIST:
774
790
  printf ("argument list\n");
775
791
  break;
@@ -812,6 +828,9 @@ d_dump (struct demangle_component *dc, int indent)
812
828
  case DEMANGLE_COMPONENT_LITERAL_NEG:
813
829
  printf ("negative literal\n");
814
830
  break;
831
+ case DEMANGLE_COMPONENT_VENDOR_EXPR:
832
+ printf ("vendor expression\n");
833
+ break;
815
834
  case DEMANGLE_COMPONENT_JAVA_RESOURCE:
816
835
  printf ("java resource\n");
817
836
  break;
@@ -858,9 +877,10 @@ CP_STATIC_IF_GLIBCPP_V3
858
877
  int
859
878
  cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len)
860
879
  {
861
- if (p == NULL || s == NULL || len == 0)
880
+ if (p == NULL || s == NULL || len <= 0)
862
881
  return 0;
863
882
  p->d_printing = 0;
883
+ p->d_counting = 0;
864
884
  p->type = DEMANGLE_COMPONENT_NAME;
865
885
  p->u.s_name.s = s;
866
886
  p->u.s_name.len = len;
@@ -877,6 +897,7 @@ cplus_demangle_fill_extended_operator (struct demangle_component *p, int args,
877
897
  if (p == NULL || args < 0 || name == NULL)
878
898
  return 0;
879
899
  p->d_printing = 0;
900
+ p->d_counting = 0;
880
901
  p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR;
881
902
  p->u.s_extended_operator.args = args;
882
903
  p->u.s_extended_operator.name = name;
@@ -897,6 +918,7 @@ cplus_demangle_fill_ctor (struct demangle_component *p,
897
918
  || (int) kind > gnu_v3_object_ctor_group)
898
919
  return 0;
899
920
  p->d_printing = 0;
921
+ p->d_counting = 0;
900
922
  p->type = DEMANGLE_COMPONENT_CTOR;
901
923
  p->u.s_ctor.kind = kind;
902
924
  p->u.s_ctor.name = name;
@@ -917,6 +939,7 @@ cplus_demangle_fill_dtor (struct demangle_component *p,
917
939
  || (int) kind > gnu_v3_object_dtor_group)
918
940
  return 0;
919
941
  p->d_printing = 0;
942
+ p->d_counting = 0;
920
943
  p->type = DEMANGLE_COMPONENT_DTOR;
921
944
  p->u.s_dtor.kind = kind;
922
945
  p->u.s_dtor.name = name;
@@ -934,6 +957,7 @@ d_make_empty (struct d_info *di)
934
957
  return NULL;
935
958
  p = &di->comps[di->next_comp];
936
959
  p->d_printing = 0;
960
+ p->d_counting = 0;
937
961
  ++di->next_comp;
938
962
  return p;
939
963
  }
@@ -968,9 +992,12 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
968
992
  case DEMANGLE_COMPONENT_TRINARY_ARG1:
969
993
  case DEMANGLE_COMPONENT_LITERAL:
970
994
  case DEMANGLE_COMPONENT_LITERAL_NEG:
995
+ case DEMANGLE_COMPONENT_VENDOR_EXPR:
971
996
  case DEMANGLE_COMPONENT_COMPOUND_NAME:
972
997
  case DEMANGLE_COMPONENT_VECTOR_TYPE:
973
998
  case DEMANGLE_COMPONENT_CLONE:
999
+ case DEMANGLE_COMPONENT_MODULE_ENTITY:
1000
+ case DEMANGLE_COMPONENT_CONSTRAINTS:
974
1001
  if (left == NULL || right == NULL)
975
1002
  return NULL;
976
1003
  break;
@@ -1007,6 +1034,14 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
1007
1034
  case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
1008
1035
  case DEMANGLE_COMPONENT_NULLARY:
1009
1036
  case DEMANGLE_COMPONENT_TRINARY_ARG2:
1037
+ case DEMANGLE_COMPONENT_TPARM_OBJ:
1038
+ case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
1039
+ case DEMANGLE_COMPONENT_MODULE_INIT:
1040
+ case DEMANGLE_COMPONENT_TEMPLATE_HEAD:
1041
+ case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM:
1042
+ case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM:
1043
+ case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM:
1044
+ case DEMANGLE_COMPONENT_FRIEND:
1010
1045
  if (left == NULL)
1011
1046
  return NULL;
1012
1047
  break;
@@ -1015,6 +1050,8 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
1015
1050
  empty. */
1016
1051
  case DEMANGLE_COMPONENT_ARRAY_TYPE:
1017
1052
  case DEMANGLE_COMPONENT_INITIALIZER_LIST:
1053
+ case DEMANGLE_COMPONENT_MODULE_NAME:
1054
+ case DEMANGLE_COMPONENT_MODULE_PARTITION:
1018
1055
  if (right == NULL)
1019
1056
  return NULL;
1020
1057
  break;
@@ -1027,6 +1064,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
1027
1064
  case DEMANGLE_COMPONENT_CONST:
1028
1065
  case DEMANGLE_COMPONENT_ARGLIST:
1029
1066
  case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
1067
+ case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM:
1030
1068
  FNQUAL_COMPONENT_CASE:
1031
1069
  break;
1032
1070
 
@@ -1088,6 +1126,28 @@ d_make_builtin_type (struct d_info *di,
1088
1126
  return p;
1089
1127
  }
1090
1128
 
1129
+ /* Add a new extended builtin type component. */
1130
+
1131
+ static struct demangle_component *
1132
+ d_make_extended_builtin_type (struct d_info *di,
1133
+ const struct demangle_builtin_type_info *type,
1134
+ short arg, char suffix)
1135
+ {
1136
+ struct demangle_component *p;
1137
+
1138
+ if (type == NULL)
1139
+ return NULL;
1140
+ p = d_make_empty (di);
1141
+ if (p != NULL)
1142
+ {
1143
+ p->type = DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE;
1144
+ p->u.s_extended_builtin.type = type;
1145
+ p->u.s_extended_builtin.arg = arg;
1146
+ p->u.s_extended_builtin.suffix = suffix;
1147
+ }
1148
+ return p;
1149
+ }
1150
+
1091
1151
  /* Add a new operator component. */
1092
1152
 
1093
1153
  static struct demangle_component *
@@ -1290,6 +1350,22 @@ is_ctor_dtor_or_conversion (struct demangle_component *dc)
1290
1350
  }
1291
1351
  }
1292
1352
 
1353
+ /* [ Q <constraint-expression> ] */
1354
+
1355
+ static struct demangle_component *
1356
+ d_maybe_constraints (struct d_info *di, struct demangle_component *dc)
1357
+ {
1358
+ if (d_peek_char (di) == 'Q')
1359
+ {
1360
+ d_advance (di, 1);
1361
+ struct demangle_component *expr = d_expression (di);
1362
+ if (expr == NULL)
1363
+ return NULL;
1364
+ dc = d_make_comp (di, DEMANGLE_COMPONENT_CONSTRAINTS, dc, expr);
1365
+ }
1366
+ return dc;
1367
+ }
1368
+
1293
1369
  /* <encoding> ::= <(function) name> <bare-function-type>
1294
1370
  ::= <(data) name>
1295
1371
  ::= <special-name>
@@ -1309,7 +1385,7 @@ d_encoding (struct d_info *di, int top_level)
1309
1385
  dc = d_special_name (di);
1310
1386
  else
1311
1387
  {
1312
- dc = d_name (di);
1388
+ dc = d_name (di, 0);
1313
1389
 
1314
1390
  if (!dc)
1315
1391
  /* Failed already. */;
@@ -1326,8 +1402,14 @@ d_encoding (struct d_info *di, int top_level)
1326
1402
  really apply here; this happens when parsing a class
1327
1403
  which is local to a function. */
1328
1404
  if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
1329
- while (is_fnqual_component_type (d_right (dc)->type))
1330
- d_right (dc) = d_left (d_right (dc));
1405
+ {
1406
+ while (d_right (dc) != NULL
1407
+ && is_fnqual_component_type (d_right (dc)->type))
1408
+ d_right (dc) = d_left (d_right (dc));
1409
+
1410
+ if (d_right (dc) == NULL)
1411
+ dc = NULL;
1412
+ }
1331
1413
  }
1332
1414
  else
1333
1415
  {
@@ -1337,21 +1419,21 @@ d_encoding (struct d_info *di, int top_level)
1337
1419
  struct demangle_component *ftype;
1338
1420
 
1339
1421
  ftype = d_bare_function_type (di, has_return_type (dc));
1340
- if (ftype)
1341
- {
1342
- /* If this is a non-top-level local-name, clear the
1343
- return type, so it doesn't confuse the user by
1344
- being confused with the return type of whaever
1345
- this is nested within. */
1346
- if (!top_level && dc->type == DEMANGLE_COMPONENT_LOCAL_NAME
1347
- && ftype->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
1348
- d_left (ftype) = NULL;
1349
-
1350
- dc = d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME,
1351
- dc, ftype);
1352
- }
1353
- else
1354
- dc = NULL;
1422
+ if (!ftype)
1423
+ return NULL;
1424
+
1425
+ /* If this is a non-top-level local-name, clear the
1426
+ return type, so it doesn't confuse the user by
1427
+ being confused with the return type of whaever
1428
+ this is nested within. */
1429
+ if (!top_level && dc->type == DEMANGLE_COMPONENT_LOCAL_NAME
1430
+ && ftype->type == DEMANGLE_COMPONENT_FUNCTION_TYPE)
1431
+ d_left (ftype) = NULL;
1432
+
1433
+ ftype = d_maybe_constraints (di, ftype);
1434
+
1435
+ dc = d_make_comp (di, DEMANGLE_COMPONENT_TYPED_NAME,
1436
+ dc, ftype);
1355
1437
  }
1356
1438
  }
1357
1439
  }
@@ -1397,84 +1479,80 @@ d_abi_tags (struct d_info *di, struct demangle_component *dc)
1397
1479
  */
1398
1480
 
1399
1481
  static struct demangle_component *
1400
- d_name (struct d_info *di)
1482
+ d_name (struct d_info *di, int substable)
1401
1483
  {
1402
1484
  char peek = d_peek_char (di);
1403
- struct demangle_component *dc;
1485
+ struct demangle_component *dc = NULL;
1486
+ struct demangle_component *module = NULL;
1487
+ int subst = 0;
1404
1488
 
1405
1489
  switch (peek)
1406
1490
  {
1407
1491
  case 'N':
1408
- return d_nested_name (di);
1492
+ dc = d_nested_name (di);
1493
+ break;
1409
1494
 
1410
1495
  case 'Z':
1411
- return d_local_name (di);
1496
+ dc = d_local_name (di);
1497
+ break;
1412
1498
 
1413
1499
  case 'U':
1414
- return d_unqualified_name (di);
1500
+ dc = d_unqualified_name (di, NULL, NULL);
1501
+ break;
1415
1502
 
1416
1503
  case 'S':
1417
1504
  {
1418
- int subst;
1419
-
1420
- if (d_peek_next_char (di) != 't')
1421
- {
1422
- dc = d_substitution (di, 0);
1423
- subst = 1;
1424
- }
1425
- else
1505
+ if (d_peek_next_char (di) == 't')
1426
1506
  {
1427
1507
  d_advance (di, 2);
1428
- dc = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME,
1429
- d_make_name (di, "std", 3),
1430
- d_unqualified_name (di));
1508
+ dc = d_make_name (di, "std", 3);
1431
1509
  di->expansion += 3;
1432
- subst = 0;
1433
1510
  }
1434
1511
 
1435
- if (d_peek_char (di) != 'I')
1512
+ if (d_peek_char (di) == 'S')
1436
1513
  {
1437
- /* The grammar does not permit this case to occur if we
1438
- called d_substitution() above (i.e., subst == 1). We
1439
- don't bother to check. */
1440
- }
1441
- else
1442
- {
1443
- /* This is <template-args>, which means that we just saw
1444
- <unscoped-template-name>, which is a substitution
1445
- candidate if we didn't just get it from a
1446
- substitution. */
1447
- if (! subst)
1514
+ module = d_substitution (di, 0);
1515
+ if (!module)
1516
+ return NULL;
1517
+ if (!(module->type == DEMANGLE_COMPONENT_MODULE_NAME
1518
+ || module->type == DEMANGLE_COMPONENT_MODULE_PARTITION))
1448
1519
  {
1449
- if (! d_add_substitution (di, dc))
1520
+ if (dc)
1450
1521
  return NULL;
1522
+ subst = 1;
1523
+ dc = module;
1524
+ module = NULL;
1451
1525
  }
1452
- dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1453
- d_template_args (di));
1454
1526
  }
1455
-
1456
- return dc;
1457
1527
  }
1528
+ /* FALLTHROUGH */
1458
1529
 
1459
1530
  case 'L':
1460
1531
  default:
1461
- dc = d_unqualified_name (di);
1532
+ if (!subst)
1533
+ dc = d_unqualified_name (di, dc, module);
1462
1534
  if (d_peek_char (di) == 'I')
1463
1535
  {
1464
1536
  /* This is <template-args>, which means that we just saw
1465
1537
  <unscoped-template-name>, which is a substitution
1466
1538
  candidate. */
1467
- if (! d_add_substitution (di, dc))
1539
+ if (!subst && !d_add_substitution (di, dc))
1468
1540
  return NULL;
1469
1541
  dc = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, dc,
1470
1542
  d_template_args (di));
1543
+ subst = 0;
1471
1544
  }
1472
- return dc;
1545
+ break;
1473
1546
  }
1547
+ if (substable && !subst && !d_add_substitution (di, dc))
1548
+ return NULL;
1549
+ return dc;
1474
1550
  }
1475
1551
 
1476
1552
  /* <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
1477
1553
  ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E
1554
+ ::= N H <prefix> <unqualified-name> E
1555
+ ::= N H <template-prefix> <template-args> E
1478
1556
  */
1479
1557
 
1480
1558
  static struct demangle_component *
@@ -1487,15 +1565,26 @@ d_nested_name (struct d_info *di)
1487
1565
  if (! d_check_char (di, 'N'))
1488
1566
  return NULL;
1489
1567
 
1490
- pret = d_cv_qualifiers (di, &ret, 1);
1491
- if (pret == NULL)
1492
- return NULL;
1568
+ if (d_peek_char (di) == 'H')
1569
+ {
1570
+ d_advance (di, 1);
1571
+ di->expansion += sizeof "this";
1572
+ pret = &ret;
1573
+ rqual = d_make_comp (di, DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION,
1574
+ NULL, NULL);
1575
+ }
1576
+ else
1577
+ {
1578
+ pret = d_cv_qualifiers (di, &ret, 1);
1579
+ if (pret == NULL)
1580
+ return NULL;
1493
1581
 
1494
- /* Parse the ref-qualifier now and then attach it
1495
- once we have something to attach it to. */
1496
- rqual = d_ref_qualifier (di, NULL);
1582
+ /* Parse the ref-qualifier now and then attach it
1583
+ once we have something to attach it to. */
1584
+ rqual = d_ref_qualifier (di, NULL);
1585
+ }
1497
1586
 
1498
- *pret = d_prefix (di);
1587
+ *pret = d_prefix (di, 1);
1499
1588
  if (*pret == NULL)
1500
1589
  return NULL;
1501
1590
 
@@ -1521,105 +1610,149 @@ d_nested_name (struct d_info *di)
1521
1610
  <template-prefix> ::= <prefix> <(template) unqualified-name>
1522
1611
  ::= <template-param>
1523
1612
  ::= <substitution>
1524
- */
1613
+
1614
+ SUBST is true if we should add substitutions (as normal), false
1615
+ if not (in an unresolved-name). */
1525
1616
 
1526
1617
  static struct demangle_component *
1527
- d_prefix (struct d_info *di)
1618
+ d_prefix (struct d_info *di, int substable)
1528
1619
  {
1529
1620
  struct demangle_component *ret = NULL;
1530
1621
 
1531
- while (1)
1622
+ for (;;)
1532
1623
  {
1533
- char peek;
1534
- enum demangle_component_type comb_type;
1535
- struct demangle_component *dc;
1536
-
1537
- peek = d_peek_char (di);
1538
- if (peek == '\0')
1539
- return NULL;
1624
+ char peek = d_peek_char (di);
1540
1625
 
1541
1626
  /* The older code accepts a <local-name> here, but I don't see
1542
1627
  that in the grammar. The older code does not accept a
1543
1628
  <template-param> here. */
1544
1629
 
1545
- comb_type = DEMANGLE_COMPONENT_QUAL_NAME;
1546
- if (peek == 'D')
1630
+ if (peek == 'D'
1631
+ && (d_peek_next_char (di) == 'T'
1632
+ || d_peek_next_char (di) == 't'))
1547
1633
  {
1548
- char peek2 = d_peek_next_char (di);
1549
- if (peek2 == 'T' || peek2 == 't')
1550
- /* Decltype. */
1551
- dc = cplus_demangle_type (di);
1552
- else
1553
- /* Destructor name. */
1554
- dc = d_unqualified_name (di);
1634
+ /* Decltype. */
1635
+ if (ret)
1636
+ return NULL;
1637
+ ret = cplus_demangle_type (di);
1555
1638
  }
1556
- else if (IS_DIGIT (peek)
1557
- || IS_LOWER (peek)
1558
- || peek == 'C'
1559
- || peek == 'U'
1560
- || peek == 'L')
1561
- dc = d_unqualified_name (di);
1562
- else if (peek == 'S')
1563
- dc = d_substitution (di, 1);
1564
1639
  else if (peek == 'I')
1565
1640
  {
1566
1641
  if (ret == NULL)
1567
1642
  return NULL;
1568
- comb_type = DEMANGLE_COMPONENT_TEMPLATE;
1569
- dc = d_template_args (di);
1643
+ struct demangle_component *dc = d_template_args (di);
1644
+ if (!dc)
1645
+ return NULL;
1646
+ ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret, dc);
1570
1647
  }
1571
1648
  else if (peek == 'T')
1572
- dc = d_template_param (di);
1573
- else if (peek == 'E')
1574
- return ret;
1575
- else if (peek == 'M')
1576
1649
  {
1577
- /* Initializer scope for a lambda. We don't need to represent
1578
- this; the normal code will just treat the variable as a type
1579
- scope, which gives appropriate output. */
1580
- if (ret == NULL)
1650
+ if (ret)
1581
1651
  return NULL;
1652
+ ret = d_template_param (di);
1653
+ }
1654
+ else if (peek == 'M')
1655
+ {
1656
+ /* Initializer scope for a lambda. We already added it as a
1657
+ substitution candidate, don't do that again. */
1582
1658
  d_advance (di, 1);
1583
1659
  continue;
1584
1660
  }
1585
1661
  else
1662
+ {
1663
+ struct demangle_component *module = NULL;
1664
+ if (peek == 'S')
1665
+ {
1666
+ module = d_substitution (di, 1);
1667
+ if (!module)
1668
+ return NULL;
1669
+ if (!(module->type == DEMANGLE_COMPONENT_MODULE_NAME
1670
+ || module->type == DEMANGLE_COMPONENT_MODULE_PARTITION))
1671
+ {
1672
+ if (ret)
1673
+ return NULL;
1674
+ ret = module;
1675
+ continue;
1676
+ }
1677
+ }
1678
+ ret = d_unqualified_name (di, ret, module);
1679
+ }
1680
+
1681
+ if (!ret)
1682
+ break;
1683
+
1684
+ if (d_peek_char (di) == 'E')
1685
+ break;
1686
+
1687
+ if (substable && !d_add_substitution (di, ret))
1586
1688
  return NULL;
1689
+ }
1587
1690
 
1588
- if (ret == NULL)
1589
- ret = dc;
1590
- else
1591
- ret = d_make_comp (di, comb_type, ret, dc);
1691
+ return ret;
1692
+ }
1592
1693
 
1593
- if (peek != 'S' && d_peek_char (di) != 'E')
1694
+ static int
1695
+ d_maybe_module_name (struct d_info *di, struct demangle_component **name)
1696
+ {
1697
+ while (d_peek_char (di) == 'W')
1698
+ {
1699
+ d_advance (di, 1);
1700
+ enum demangle_component_type code = DEMANGLE_COMPONENT_MODULE_NAME;
1701
+ if (d_peek_char (di) == 'P')
1594
1702
  {
1595
- if (! d_add_substitution (di, ret))
1596
- return NULL;
1703
+ code = DEMANGLE_COMPONENT_MODULE_PARTITION;
1704
+ d_advance (di, 1);
1597
1705
  }
1706
+
1707
+ *name = d_make_comp (di, code, *name, d_source_name (di));
1708
+ if (!*name)
1709
+ return 0;
1710
+ if (!d_add_substitution (di, *name))
1711
+ return 0;
1598
1712
  }
1713
+ return 1;
1599
1714
  }
1600
1715
 
1601
- /* <unqualified-name> ::= <operator-name>
1602
- ::= <ctor-dtor-name>
1603
- ::= <source-name>
1604
- ::= <local-source-name>
1605
-
1606
- <local-source-name> ::= L <source-name> <discriminator>
1716
+ /* <unqualified-name> ::= [<module-name>] <operator-name> [<abi-tags>]
1717
+ ::= [<module-name>] <ctor-dtor-name> [<abi-tags>]
1718
+ ::= [<module-name>] <source-name> [<abi-tags>]
1719
+ ::= [<module-name>] F <source-name> [<abi-tags>]
1720
+ ::= [<module-name>] <local-source-name> [<abi-tags>]
1721
+ ::= [<module-name>] DC <source-name>+ E [<abi-tags>]
1722
+ <local-source-name> ::= L <source-name> <discriminator> [<abi-tags>]
1607
1723
  */
1608
1724
 
1609
1725
  static struct demangle_component *
1610
- d_unqualified_name (struct d_info *di)
1726
+ d_unqualified_name (struct d_info *di, struct demangle_component *scope,
1727
+ struct demangle_component *module)
1611
1728
  {
1612
1729
  struct demangle_component *ret;
1613
1730
  char peek;
1731
+ int member_like_friend = 0;
1732
+
1733
+ if (!d_maybe_module_name (di, &module))
1734
+ return NULL;
1614
1735
 
1615
1736
  peek = d_peek_char (di);
1737
+ if (peek == 'F')
1738
+ {
1739
+ member_like_friend = 1;
1740
+ d_advance (di, 1);
1741
+ peek = d_peek_char (di);
1742
+ }
1616
1743
  if (IS_DIGIT (peek))
1617
1744
  ret = d_source_name (di);
1618
1745
  else if (IS_LOWER (peek))
1619
1746
  {
1747
+ int was_expr = di->is_expression;
1620
1748
  if (peek == 'o' && d_peek_next_char (di) == 'n')
1621
- d_advance (di, 2);
1749
+ {
1750
+ d_advance (di, 2);
1751
+ /* Treat cv as naming a conversion operator. */
1752
+ di->is_expression = 0;
1753
+ }
1622
1754
  ret = d_operator_name (di);
1755
+ di->is_expression = was_expr;
1623
1756
  if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR)
1624
1757
  {
1625
1758
  di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2;
@@ -1628,6 +1761,28 @@ d_unqualified_name (struct d_info *di)
1628
1761
  d_source_name (di));
1629
1762
  }
1630
1763
  }
1764
+ else if (peek == 'D' && d_peek_next_char (di) == 'C')
1765
+ {
1766
+ // structured binding
1767
+ d_advance (di, 2);
1768
+ struct demangle_component *prev = NULL;
1769
+ do
1770
+ {
1771
+ struct demangle_component *next =
1772
+ d_make_comp (di, DEMANGLE_COMPONENT_STRUCTURED_BINDING,
1773
+ d_source_name (di), NULL);
1774
+ if (prev)
1775
+ d_right (prev) = next;
1776
+ else
1777
+ ret = next;
1778
+ prev = next;
1779
+ }
1780
+ while (prev && d_peek_char (di) != 'E');
1781
+ if (prev)
1782
+ d_advance (di, 1);
1783
+ else
1784
+ ret = NULL;
1785
+ }
1631
1786
  else if (peek == 'C' || peek == 'D')
1632
1787
  ret = d_ctor_dtor_name (di);
1633
1788
  else if (peek == 'L')
@@ -1657,8 +1812,15 @@ d_unqualified_name (struct d_info *di)
1657
1812
  else
1658
1813
  return NULL;
1659
1814
 
1815
+ if (module)
1816
+ ret = d_make_comp (di, DEMANGLE_COMPONENT_MODULE_ENTITY, ret, module);
1660
1817
  if (d_peek_char (di) == 'B')
1661
1818
  ret = d_abi_tags (di, ret);
1819
+ if (member_like_friend)
1820
+ ret = d_make_comp (di, DEMANGLE_COMPONENT_FRIEND, ret, NULL);
1821
+ if (scope)
1822
+ ret = d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, scope, ret);
1823
+
1662
1824
  return ret;
1663
1825
  }
1664
1826
 
@@ -1707,7 +1869,7 @@ d_number (struct d_info *di)
1707
1869
  }
1708
1870
  if (ret > ((INT_MAX - (peek - '0')) / 10))
1709
1871
  return -1;
1710
- ret = ret * 10 + peek - '0';
1872
+ ret = ret * 10 + (peek - '0');
1711
1873
  d_advance (di, 1);
1712
1874
  peek = d_peek_char (di);
1713
1875
  }
@@ -1787,19 +1949,23 @@ const struct demangle_operator_info cplus_demangle_operators[] =
1787
1949
  { "ad", NL ("&"), 1 },
1788
1950
  { "an", NL ("&"), 2 },
1789
1951
  { "at", NL ("alignof "), 1 },
1952
+ { "aw", NL ("co_await "), 1 },
1790
1953
  { "az", NL ("alignof "), 1 },
1791
1954
  { "cc", NL ("const_cast"), 2 },
1792
1955
  { "cl", NL ("()"), 2 },
1793
1956
  { "cm", NL (","), 2 },
1794
1957
  { "co", NL ("~"), 1 },
1795
1958
  { "dV", NL ("/="), 2 },
1959
+ { "dX", NL ("[...]="), 3 }, /* [expr...expr] = expr */
1796
1960
  { "da", NL ("delete[] "), 1 },
1797
1961
  { "dc", NL ("dynamic_cast"), 2 },
1798
1962
  { "de", NL ("*"), 1 },
1963
+ { "di", NL ("="), 2 }, /* .name = expr */
1799
1964
  { "dl", NL ("delete "), 1 },
1800
1965
  { "ds", NL (".*"), 2 },
1801
1966
  { "dt", NL ("."), 2 },
1802
1967
  { "dv", NL ("/"), 2 },
1968
+ { "dx", NL ("]="), 2 }, /* [expr] = expr */
1803
1969
  { "eO", NL ("^="), 2 },
1804
1970
  { "eo", NL ("^"), 2 },
1805
1971
  { "eq", NL ("=="), 2 },
@@ -1826,6 +1992,7 @@ const struct demangle_operator_info cplus_demangle_operators[] =
1826
1992
  { "ng", NL ("-"), 1 },
1827
1993
  { "nt", NL ("!"), 1 },
1828
1994
  { "nw", NL ("new"), 3 },
1995
+ { "nx", NL ("noexcept"), 1 },
1829
1996
  { "oR", NL ("|="), 2 },
1830
1997
  { "oo", NL ("||"), 2 },
1831
1998
  { "or", NL ("|"), 2 },
@@ -1844,6 +2011,7 @@ const struct demangle_operator_info cplus_demangle_operators[] =
1844
2011
  { "sP", NL ("sizeof..."), 1 },
1845
2012
  { "sZ", NL ("sizeof..."), 1 },
1846
2013
  { "sc", NL ("static_cast"), 2 },
2014
+ { "ss", NL ("<=>"), 2 },
1847
2015
  { "st", NL ("sizeof "), 1 },
1848
2016
  { "sz", NL ("sizeof "), 1 },
1849
2017
  { "tr", NL ("throw"), 0 },
@@ -2007,6 +2175,7 @@ d_java_resource (struct d_info *di)
2007
2175
  ::= TT <type>
2008
2176
  ::= TI <type>
2009
2177
  ::= TS <type>
2178
+ ::= TA <template-arg>
2010
2179
  ::= GV <(object) name>
2011
2180
  ::= T <call-offset> <(base) encoding>
2012
2181
  ::= Tc <call-offset> <call-offset> <(base) encoding>
@@ -2093,11 +2262,15 @@ d_special_name (struct d_info *di)
2093
2262
 
2094
2263
  case 'H':
2095
2264
  return d_make_comp (di, DEMANGLE_COMPONENT_TLS_INIT,
2096
- d_name (di), NULL);
2265
+ d_name (di, 0), NULL);
2097
2266
 
2098
2267
  case 'W':
2099
2268
  return d_make_comp (di, DEMANGLE_COMPONENT_TLS_WRAPPER,
2100
- d_name (di), NULL);
2269
+ d_name (di, 0), NULL);
2270
+
2271
+ case 'A':
2272
+ return d_make_comp (di, DEMANGLE_COMPONENT_TPARM_OBJ,
2273
+ d_template_arg (di), NULL);
2101
2274
 
2102
2275
  default:
2103
2276
  return NULL;
@@ -2109,11 +2282,11 @@ d_special_name (struct d_info *di)
2109
2282
  {
2110
2283
  case 'V':
2111
2284
  return d_make_comp (di, DEMANGLE_COMPONENT_GUARD,
2112
- d_name (di), NULL);
2285
+ d_name (di, 0), NULL);
2113
2286
 
2114
2287
  case 'R':
2115
2288
  {
2116
- struct demangle_component *name = d_name (di);
2289
+ struct demangle_component *name = d_name (di, 0);
2117
2290
  return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name,
2118
2291
  d_number_component (di));
2119
2292
  }
@@ -2122,6 +2295,14 @@ d_special_name (struct d_info *di)
2122
2295
  return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS,
2123
2296
  d_encoding (di, 0), NULL);
2124
2297
 
2298
+ case 'I':
2299
+ {
2300
+ struct demangle_component *module = NULL;
2301
+ if (!d_maybe_module_name (di, &module) || !module)
2302
+ return NULL;
2303
+ return d_make_comp (di, DEMANGLE_COMPONENT_MODULE_INIT,
2304
+ module, NULL);
2305
+ }
2125
2306
  case 'T':
2126
2307
  switch (d_next_char (di))
2127
2308
  {
@@ -2355,10 +2536,13 @@ cplus_demangle_builtin_types[D_BUILTIN_TYPE_COUNT] =
2355
2536
  /* 27 */ { NL ("decimal64"), NL ("decimal64"), D_PRINT_DEFAULT },
2356
2537
  /* 28 */ { NL ("decimal128"), NL ("decimal128"), D_PRINT_DEFAULT },
2357
2538
  /* 29 */ { NL ("half"), NL ("half"), D_PRINT_FLOAT },
2358
- /* 30 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT },
2359
- /* 31 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT },
2360
- /* 32 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2539
+ /* 30 */ { NL ("char8_t"), NL ("char8_t"), D_PRINT_DEFAULT },
2540
+ /* 31 */ { NL ("char16_t"), NL ("char16_t"), D_PRINT_DEFAULT },
2541
+ /* 32 */ { NL ("char32_t"), NL ("char32_t"), D_PRINT_DEFAULT },
2542
+ /* 33 */ { NL ("decltype(nullptr)"), NL ("decltype(nullptr)"),
2361
2543
  D_PRINT_DEFAULT },
2544
+ /* 34 */ { NL ("_Float"), NL ("_Float"), D_PRINT_FLOAT },
2545
+ /* 35 */ { NL ("std::bfloat16_t"), NL ("std::bfloat16_t"), D_PRINT_FLOAT },
2362
2546
  };
2363
2547
 
2364
2548
  CP_STATIC_IF_GLIBCPP_V3
@@ -2443,13 +2627,6 @@ cplus_demangle_type (struct d_info *di)
2443
2627
  ret = d_function_type (di);
2444
2628
  break;
2445
2629
 
2446
- case '0': case '1': case '2': case '3': case '4':
2447
- case '5': case '6': case '7': case '8': case '9':
2448
- case 'N':
2449
- case 'Z':
2450
- ret = d_class_enum_type (di);
2451
- break;
2452
-
2453
2630
  case 'A':
2454
2631
  ret = d_array_type (di);
2455
2632
  break;
@@ -2520,39 +2697,6 @@ cplus_demangle_type (struct d_info *di)
2520
2697
  }
2521
2698
  break;
2522
2699
 
2523
- case 'S':
2524
- /* If this is a special substitution, then it is the start of
2525
- <class-enum-type>. */
2526
- {
2527
- char peek_next;
2528
-
2529
- peek_next = d_peek_next_char (di);
2530
- if (IS_DIGIT (peek_next)
2531
- || peek_next == '_'
2532
- || IS_UPPER (peek_next))
2533
- {
2534
- ret = d_substitution (di, 0);
2535
- /* The substituted name may have been a template name and
2536
- may be followed by tepmlate args. */
2537
- if (d_peek_char (di) == 'I')
2538
- ret = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, ret,
2539
- d_template_args (di));
2540
- else
2541
- can_subst = 0;
2542
- }
2543
- else
2544
- {
2545
- ret = d_class_enum_type (di);
2546
- /* If the substitution was a complete type, then it is not
2547
- a new substitution candidate. However, if the
2548
- substitution was followed by template arguments, then
2549
- the whole thing is a substitution candidate. */
2550
- if (ret != NULL && ret->type == DEMANGLE_COMPONENT_SUB_STD)
2551
- can_subst = 0;
2552
- }
2553
- }
2554
- break;
2555
-
2556
2700
  case 'O':
2557
2701
  d_advance (di, 1);
2558
2702
  ret = d_make_comp (di, DEMANGLE_COMPONENT_RVALUE_REFERENCE,
@@ -2645,31 +2789,54 @@ cplus_demangle_type (struct d_info *di)
2645
2789
  ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[29]);
2646
2790
  di->expansion += ret->u.s_builtin.type->len;
2647
2791
  break;
2792
+ case 'u':
2793
+ /* char8_t */
2794
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[30]);
2795
+ di->expansion += ret->u.s_builtin.type->len;
2796
+ break;
2648
2797
  case 's':
2649
2798
  /* char16_t */
2650
- ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[30]);
2799
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[31]);
2651
2800
  di->expansion += ret->u.s_builtin.type->len;
2652
2801
  break;
2653
2802
  case 'i':
2654
2803
  /* char32_t */
2655
- ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[31]);
2804
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[32]);
2656
2805
  di->expansion += ret->u.s_builtin.type->len;
2657
2806
  break;
2658
2807
 
2659
2808
  case 'F':
2660
- /* Fixed point types. DF<int bits><length><fract bits><sat> */
2661
- ret = d_make_empty (di);
2662
- ret->type = DEMANGLE_COMPONENT_FIXED_TYPE;
2663
- if ((ret->u.s_fixed.accum = IS_DIGIT (d_peek_char (di))))
2664
- /* For demangling we don't care about the bits. */
2665
- d_number (di);
2666
- ret->u.s_fixed.length = cplus_demangle_type (di);
2667
- if (ret->u.s_fixed.length == NULL)
2668
- return NULL;
2669
- d_number (di);
2670
- peek = d_next_char (di);
2671
- ret->u.s_fixed.sat = (peek == 's');
2672
- break;
2809
+ /* DF<number>_ - _Float<number>.
2810
+ DF<number>x - _Float<number>x
2811
+ DF16b - std::bfloat16_t. */
2812
+ {
2813
+ int arg = d_number (di);
2814
+ char buf[12];
2815
+ char suffix = 0;
2816
+ if (d_peek_char (di) == 'b')
2817
+ {
2818
+ if (arg != 16)
2819
+ return NULL;
2820
+ d_advance (di, 1);
2821
+ ret = d_make_builtin_type (di,
2822
+ &cplus_demangle_builtin_types[35]);
2823
+ di->expansion += ret->u.s_builtin.type->len;
2824
+ break;
2825
+ }
2826
+ if (d_peek_char (di) == 'x')
2827
+ suffix = 'x';
2828
+ if (!suffix && d_peek_char (di) != '_')
2829
+ return NULL;
2830
+ ret
2831
+ = d_make_extended_builtin_type (di,
2832
+ &cplus_demangle_builtin_types[34],
2833
+ arg, suffix);
2834
+ d_advance (di, 1);
2835
+ sprintf (buf, "%d", arg);
2836
+ di->expansion += ret->u.s_extended_builtin.type->len
2837
+ + strlen (buf) + (suffix != 0);
2838
+ break;
2839
+ }
2673
2840
 
2674
2841
  case 'v':
2675
2842
  ret = d_vector_type (di);
@@ -2678,7 +2845,7 @@ cplus_demangle_type (struct d_info *di)
2678
2845
 
2679
2846
  case 'n':
2680
2847
  /* decltype(nullptr) */
2681
- ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[32]);
2848
+ ret = d_make_builtin_type (di, &cplus_demangle_builtin_types[33]);
2682
2849
  di->expansion += ret->u.s_builtin.type->len;
2683
2850
  break;
2684
2851
 
@@ -2688,7 +2855,7 @@ cplus_demangle_type (struct d_info *di)
2688
2855
  break;
2689
2856
 
2690
2857
  default:
2691
- return NULL;
2858
+ return d_class_enum_type (di, 1);
2692
2859
  }
2693
2860
 
2694
2861
  if (can_subst)
@@ -2843,21 +3010,35 @@ d_ref_qualifier (struct d_info *di, struct demangle_component *sub)
2843
3010
  static struct demangle_component *
2844
3011
  d_function_type (struct d_info *di)
2845
3012
  {
2846
- struct demangle_component *ret;
3013
+ struct demangle_component *ret = NULL;
2847
3014
 
2848
- if (! d_check_char (di, 'F'))
2849
- return NULL;
2850
- if (d_peek_char (di) == 'Y')
3015
+ if ((di->options & DMGL_NO_RECURSE_LIMIT) == 0)
2851
3016
  {
2852
- /* Function has C linkage. We don't print this information.
2853
- FIXME: We should print it in verbose mode. */
2854
- d_advance (di, 1);
3017
+ if (di->recursion_level > DEMANGLE_RECURSION_LIMIT)
3018
+ /* FIXME: There ought to be a way to report
3019
+ that the recursion limit has been reached. */
3020
+ return NULL;
3021
+
3022
+ di->recursion_level ++;
2855
3023
  }
2856
- ret = d_bare_function_type (di, 1);
2857
- ret = d_ref_qualifier (di, ret);
2858
3024
 
2859
- if (! d_check_char (di, 'E'))
2860
- return NULL;
3025
+ if (d_check_char (di, 'F'))
3026
+ {
3027
+ if (d_peek_char (di) == 'Y')
3028
+ {
3029
+ /* Function has C linkage. We don't print this information.
3030
+ FIXME: We should print it in verbose mode. */
3031
+ d_advance (di, 1);
3032
+ }
3033
+ ret = d_bare_function_type (di, 1);
3034
+ ret = d_ref_qualifier (di, ret);
3035
+
3036
+ if (! d_check_char (di, 'E'))
3037
+ ret = NULL;
3038
+ }
3039
+
3040
+ if ((di->options & DMGL_NO_RECURSE_LIMIT) == 0)
3041
+ di->recursion_level --;
2861
3042
  return ret;
2862
3043
  }
2863
3044
 
@@ -2876,7 +3057,7 @@ d_parmlist (struct d_info *di)
2876
3057
  struct demangle_component *type;
2877
3058
 
2878
3059
  char peek = d_peek_char (di);
2879
- if (peek == '\0' || peek == 'E' || peek == '.')
3060
+ if (peek == '\0' || peek == 'E' || peek == '.' || peek == 'Q')
2880
3061
  break;
2881
3062
  if ((peek == 'R' || peek == 'O')
2882
3063
  && d_peek_next_char (di) == 'E')
@@ -2947,9 +3128,9 @@ d_bare_function_type (struct d_info *di, int has_return_type)
2947
3128
  /* <class-enum-type> ::= <name> */
2948
3129
 
2949
3130
  static struct demangle_component *
2950
- d_class_enum_type (struct d_info *di)
3131
+ d_class_enum_type (struct d_info *di, int substable)
2951
3132
  {
2952
- return d_name (di);
3133
+ return d_name (di, substable);
2953
3134
  }
2954
3135
 
2955
3136
  /* <array-type> ::= A <(positive dimension) number> _ <(element) type>
@@ -3112,7 +3293,7 @@ d_template_args (struct d_info *di)
3112
3293
  return d_template_args_1 (di);
3113
3294
  }
3114
3295
 
3115
- /* <template-arg>* E */
3296
+ /* <template-arg>* [Q <constraint-expression>] E */
3116
3297
 
3117
3298
  static struct demangle_component *
3118
3299
  d_template_args_1 (struct d_info *di)
@@ -3148,13 +3329,17 @@ d_template_args_1 (struct d_info *di)
3148
3329
  return NULL;
3149
3330
  pal = &d_right (*pal);
3150
3331
 
3151
- if (d_peek_char (di) == 'E')
3152
- {
3153
- d_advance (di, 1);
3154
- break;
3155
- }
3332
+ char peek = d_peek_char (di);
3333
+ if (peek == 'E' || peek == 'Q')
3334
+ break;
3156
3335
  }
3157
3336
 
3337
+ al = d_maybe_constraints (di, al);
3338
+
3339
+ if (d_peek_char (di) != 'E')
3340
+ return NULL;
3341
+ d_advance (di, 1);
3342
+
3158
3343
  di->last_name = hold_last_name;
3159
3344
 
3160
3345
  return al;
@@ -3240,18 +3425,69 @@ op_is_new_cast (struct demangle_component *op)
3240
3425
  || code[0] == 'c' || code[0] == 'r'));
3241
3426
  }
3242
3427
 
3428
+ /* <unresolved-name> ::= [gs] <base-unresolved-name> # x or (with "gs") ::x
3429
+ ::= sr <unresolved-type> <base-unresolved-name> # T::x / decltype(p)::x
3430
+ # T::N::x /decltype(p)::N::x
3431
+ ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name>
3432
+ # A::x, N::y, A<T>::z; "gs" means leading "::"
3433
+ ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>
3434
+
3435
+ "gs" is handled elsewhere, as a unary operator. */
3436
+
3437
+ static struct demangle_component *
3438
+ d_unresolved_name (struct d_info *di)
3439
+ {
3440
+ struct demangle_component *type;
3441
+ struct demangle_component *name;
3442
+ char peek;
3443
+
3444
+ /* Consume the "sr". */
3445
+ d_advance (di, 2);
3446
+
3447
+ peek = d_peek_char (di);
3448
+ if (di->unresolved_name_state
3449
+ && (IS_DIGIT (peek)
3450
+ || IS_LOWER (peek)
3451
+ || peek == 'C'
3452
+ || peek == 'U'
3453
+ || peek == 'L'))
3454
+ {
3455
+ /* The third production is ambiguous with the old unresolved-name syntax
3456
+ of <type> <base-unresolved-name>; in the old mangling, A::x was mangled
3457
+ as sr1A1x, now sr1AE1x. So we first try to demangle using the new
3458
+ mangling, then with the old if that fails. */
3459
+ di->unresolved_name_state = -1;
3460
+ type = d_prefix (di, 0);
3461
+ if (d_peek_char (di) == 'E')
3462
+ d_advance (di, 1);
3463
+ }
3464
+ else
3465
+ type = cplus_demangle_type (di);
3466
+ name = d_unqualified_name (di, type, NULL);
3467
+ if (d_peek_char (di) == 'I')
3468
+ name = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
3469
+ d_template_args (di));
3470
+ return name;
3471
+ }
3472
+
3243
3473
  /* <expression> ::= <(unary) operator-name> <expression>
3244
3474
  ::= <(binary) operator-name> <expression> <expression>
3245
3475
  ::= <(trinary) operator-name> <expression> <expression> <expression>
3246
3476
  ::= cl <expression>+ E
3247
3477
  ::= st <type>
3248
3478
  ::= <template-param>
3249
- ::= sr <type> <unqualified-name>
3250
- ::= sr <type> <unqualified-name> <template-args>
3479
+ ::= u <source-name> <template-arg>* E # vendor extended expression
3480
+ ::= <unresolved-name>
3251
3481
  ::= <expr-primary>
3482
+
3483
+ <braced-expression> ::= <expression>
3484
+ ::= di <field source-name> <braced-expression> # .name = expr
3485
+ ::= dx <index expression> <braced-expression> # [expr] = expr
3486
+ ::= dX <range begin expression> <range end expression> <braced-expression>
3487
+ # [expr ... expr] = expr
3252
3488
  */
3253
3489
 
3254
- static inline struct demangle_component *
3490
+ static struct demangle_component *
3255
3491
  d_expression_1 (struct d_info *di)
3256
3492
  {
3257
3493
  char peek;
@@ -3262,20 +3498,7 @@ d_expression_1 (struct d_info *di)
3262
3498
  else if (peek == 'T')
3263
3499
  return d_template_param (di);
3264
3500
  else if (peek == 's' && d_peek_next_char (di) == 'r')
3265
- {
3266
- struct demangle_component *type;
3267
- struct demangle_component *name;
3268
-
3269
- d_advance (di, 2);
3270
- type = cplus_demangle_type (di);
3271
- name = d_unqualified_name (di);
3272
- if (d_peek_char (di) != 'I')
3273
- return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type, name);
3274
- else
3275
- return d_make_comp (di, DEMANGLE_COMPONENT_QUAL_NAME, type,
3276
- d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE, name,
3277
- d_template_args (di)));
3278
- }
3501
+ return d_unresolved_name (di);
3279
3502
  else if (peek == 's' && d_peek_next_char (di) == 'p')
3280
3503
  {
3281
3504
  d_advance (di, 2);
@@ -3313,7 +3536,7 @@ d_expression_1 (struct d_info *di)
3313
3536
  /* operator-function-id, i.e. operator+(t). */
3314
3537
  d_advance (di, 2);
3315
3538
 
3316
- name = d_unqualified_name (di);
3539
+ name = d_unqualified_name (di, NULL, NULL);
3317
3540
  if (name == NULL)
3318
3541
  return NULL;
3319
3542
  if (d_peek_char (di) == 'I')
@@ -3327,14 +3550,23 @@ d_expression_1 (struct d_info *di)
3327
3550
  {
3328
3551
  /* Brace-enclosed initializer list, untyped or typed. */
3329
3552
  struct demangle_component *type = NULL;
3553
+ d_advance (di, 2);
3330
3554
  if (peek == 't')
3331
3555
  type = cplus_demangle_type (di);
3332
- if (!d_peek_next_char (di))
3556
+ if (!d_peek_char (di) || !d_peek_next_char (di))
3333
3557
  return NULL;
3334
- d_advance (di, 2);
3335
3558
  return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST,
3336
3559
  type, d_exprlist (di, 'E'));
3337
3560
  }
3561
+ else if (peek == 'u')
3562
+ {
3563
+ /* A vendor extended expression. */
3564
+ struct demangle_component *name, *args;
3565
+ d_advance (di, 1);
3566
+ name = d_source_name (di);
3567
+ args = d_template_args_1 (di);
3568
+ return d_make_comp (di, DEMANGLE_COMPONENT_VENDOR_EXPR, name, args);
3569
+ }
3338
3570
  else
3339
3571
  {
3340
3572
  struct demangle_component *op;
@@ -3411,16 +3643,30 @@ d_expression_1 (struct d_info *di)
3411
3643
  else if (code[0] == 'f')
3412
3644
  /* fold-expression. */
3413
3645
  left = d_operator_name (di);
3646
+ else if (!strcmp (code, "di"))
3647
+ left = d_unqualified_name (di, NULL, NULL);
3414
3648
  else
3415
3649
  left = d_expression_1 (di);
3416
3650
  if (!strcmp (code, "cl"))
3417
3651
  right = d_exprlist (di, 'E');
3418
3652
  else if (!strcmp (code, "dt") || !strcmp (code, "pt"))
3419
3653
  {
3420
- right = d_unqualified_name (di);
3421
- if (d_peek_char (di) == 'I')
3422
- right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
3423
- right, d_template_args (di));
3654
+ peek = d_peek_char (di);
3655
+ /* These codes start a qualified name. */
3656
+ if ((peek == 'g' && d_peek_next_char (di) == 's')
3657
+ || (peek == 's' && d_peek_next_char (di) == 'r'))
3658
+ right = d_expression_1 (di);
3659
+ else
3660
+ {
3661
+ /* Otherwise it's an unqualified name. We use
3662
+ d_unqualified_name rather than d_expression_1 here for
3663
+ old mangled names that didn't add 'on' before operator
3664
+ names. */
3665
+ right = d_unqualified_name (di, NULL, NULL);
3666
+ if (d_peek_char (di) == 'I')
3667
+ right = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE,
3668
+ right, d_template_args (di));
3669
+ }
3424
3670
  }
3425
3671
  else
3426
3672
  right = d_expression_1 (di);
@@ -3438,7 +3684,8 @@ d_expression_1 (struct d_info *di)
3438
3684
 
3439
3685
  if (code == NULL)
3440
3686
  return NULL;
3441
- else if (!strcmp (code, "qu"))
3687
+ else if (!strcmp (code, "qu")
3688
+ || !strcmp (code, "dX"))
3442
3689
  {
3443
3690
  /* ?: expression. */
3444
3691
  first = d_expression_1 (di);
@@ -3542,6 +3789,17 @@ d_expr_primary (struct d_info *di)
3542
3789
  && type->u.s_builtin.type->print != D_PRINT_DEFAULT)
3543
3790
  di->expansion -= type->u.s_builtin.type->len;
3544
3791
 
3792
+ if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
3793
+ && strcmp (type->u.s_builtin.type->name,
3794
+ cplus_demangle_builtin_types[33].name) == 0)
3795
+ {
3796
+ if (d_peek_char (di) == 'E')
3797
+ {
3798
+ d_advance (di, 1);
3799
+ return type;
3800
+ }
3801
+ }
3802
+
3545
3803
  /* Rather than try to interpret the literal value, we just
3546
3804
  collect it as a string. Note that it's possible to have a
3547
3805
  floating point literal here. The ABI specifies that the
@@ -3614,7 +3872,7 @@ d_local_name (struct d_info *di)
3614
3872
  return NULL;
3615
3873
  }
3616
3874
 
3617
- name = d_name (di);
3875
+ name = d_name (di, 0);
3618
3876
 
3619
3877
  if (name
3620
3878
  /* Lambdas and unnamed types have internal discriminators
@@ -3678,32 +3936,120 @@ d_discriminator (struct d_info *di)
3678
3936
  return 1;
3679
3937
  }
3680
3938
 
3681
- /* <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ */
3939
+ /* <template-parm> ::= Ty
3940
+ ::= Tn <type>
3941
+ ::= Tt <template-head> E
3942
+ ::= Tp <template-parm> */
3682
3943
 
3683
3944
  static struct demangle_component *
3684
- d_lambda (struct d_info *di)
3945
+ d_template_parm (struct d_info *di, int *bad)
3685
3946
  {
3686
- struct demangle_component *tl;
3687
- struct demangle_component *ret;
3688
- int num;
3947
+ if (d_peek_char (di) != 'T')
3948
+ return NULL;
3949
+
3950
+ struct demangle_component *op;
3951
+ enum demangle_component_type kind;
3952
+ switch (d_peek_next_char (di))
3953
+ {
3954
+ default:
3955
+ return NULL;
3689
3956
 
3957
+ case 'p': /* Pack */
3958
+ d_advance (di, 2);
3959
+ op = d_template_parm (di, bad);
3960
+ kind = DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM;
3961
+ if (!op)
3962
+ {
3963
+ *bad = 1;
3964
+ return NULL;
3965
+ }
3966
+ break;
3967
+
3968
+ case 'y': /* Typename */
3969
+ d_advance (di, 2);
3970
+ op = NULL;
3971
+ kind = DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM;
3972
+ break;
3973
+
3974
+ case 'n': /* Non-Type */
3975
+ d_advance (di, 2);
3976
+ op = cplus_demangle_type (di);
3977
+ kind = DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM;
3978
+ if (!op)
3979
+ {
3980
+ *bad = 1;
3981
+ return NULL;
3982
+ }
3983
+ break;
3984
+
3985
+ case 't': /* Template */
3986
+ d_advance (di, 2);
3987
+ op = d_template_head (di, bad);
3988
+ kind = DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM;
3989
+ if (!op || !d_check_char (di, 'E'))
3990
+ {
3991
+ *bad = 1;
3992
+ return NULL;
3993
+ }
3994
+ }
3995
+
3996
+ return d_make_comp (di, kind, op, NULL);
3997
+ }
3998
+
3999
+ /* <template-head> ::= <template-head>? <template-parm> */
4000
+
4001
+ static struct demangle_component *
4002
+ d_template_head (struct d_info *di, int *bad)
4003
+ {
4004
+ struct demangle_component *res = NULL, **slot = &res;
4005
+ struct demangle_component *op;
4006
+
4007
+ while ((op = d_template_parm (di, bad)))
4008
+ {
4009
+ *slot = op;
4010
+ slot = &d_right (op);
4011
+ }
4012
+
4013
+ /* Wrap it in a template head, to make concatenating with any parm list, and
4014
+ printing simpler. */
4015
+ if (res)
4016
+ res = d_make_comp (di, DEMANGLE_COMPONENT_TEMPLATE_HEAD, res, NULL);
4017
+
4018
+ return res;
4019
+ }
4020
+
4021
+ /* <closure-type-name> ::= Ul <template-head>? <lambda-sig> E [ <nonnegative number> ] _ */
4022
+
4023
+ static struct demangle_component *
4024
+ d_lambda (struct d_info *di)
4025
+ {
3690
4026
  if (! d_check_char (di, 'U'))
3691
4027
  return NULL;
3692
4028
  if (! d_check_char (di, 'l'))
3693
4029
  return NULL;
3694
4030
 
3695
- tl = d_parmlist (di);
4031
+ int bad = 0;
4032
+ struct demangle_component *head = d_template_head (di, &bad);
4033
+ if (bad)
4034
+ return NULL;
4035
+
4036
+ struct demangle_component *tl = d_parmlist (di);
3696
4037
  if (tl == NULL)
3697
4038
  return NULL;
4039
+ if (head)
4040
+ {
4041
+ d_right (head) = tl;
4042
+ tl = head;
4043
+ }
3698
4044
 
3699
4045
  if (! d_check_char (di, 'E'))
3700
4046
  return NULL;
3701
4047
 
3702
- num = d_compact_number (di);
4048
+ int num = d_compact_number (di);
3703
4049
  if (num < 0)
3704
4050
  return NULL;
3705
4051
 
3706
- ret = d_make_empty (di);
4052
+ struct demangle_component *ret = d_make_empty (di);
3707
4053
  if (ret)
3708
4054
  {
3709
4055
  ret->type = DEMANGLE_COMPONENT_LAMBDA;
@@ -3711,9 +4057,6 @@ d_lambda (struct d_info *di)
3711
4057
  ret->u.s_unary_num.num = num;
3712
4058
  }
3713
4059
 
3714
- if (! d_add_substitution (di, ret))
3715
- return NULL;
3716
-
3717
4060
  return ret;
3718
4061
  }
3719
4062
 
@@ -3757,10 +4100,11 @@ d_clone_suffix (struct d_info *di, struct demangle_component *encoding)
3757
4100
  const char *pend = suffix;
3758
4101
  struct demangle_component *n;
3759
4102
 
3760
- if (*pend == '.' && (IS_LOWER (pend[1]) || pend[1] == '_'))
4103
+ if (*pend == '.' && (IS_LOWER (pend[1]) || IS_DIGIT (pend[1])
4104
+ || pend[1] == '_'))
3761
4105
  {
3762
4106
  pend += 2;
3763
- while (IS_LOWER (*pend) || *pend == '_')
4107
+ while (IS_LOWER (*pend) || IS_DIGIT (*pend) || *pend == '_')
3764
4108
  ++pend;
3765
4109
  }
3766
4110
  while (*pend == '.' && IS_DIGIT (pend[1]))
@@ -4032,12 +4376,14 @@ d_growable_string_callback_adapter (const char *s, size_t l, void *opaque)
4032
4376
  are larger than the actual numbers encountered. */
4033
4377
 
4034
4378
  static void
4035
- d_count_templates_scopes (int *num_templates, int *num_scopes,
4036
- const struct demangle_component *dc)
4379
+ d_count_templates_scopes (struct d_print_info *dpi,
4380
+ struct demangle_component *dc)
4037
4381
  {
4038
- if (dc == NULL)
4382
+ if (dc == NULL || dc->d_counting > 1 || dpi->recursion > MAX_RECURSION_COUNT)
4039
4383
  return;
4040
4384
 
4385
+ ++ dc->d_counting;
4386
+
4041
4387
  switch (dc->type)
4042
4388
  {
4043
4389
  case DEMANGLE_COMPONENT_NAME:
@@ -4045,20 +4391,31 @@ d_count_templates_scopes (int *num_templates, int *num_scopes,
4045
4391
  case DEMANGLE_COMPONENT_FUNCTION_PARAM:
4046
4392
  case DEMANGLE_COMPONENT_SUB_STD:
4047
4393
  case DEMANGLE_COMPONENT_BUILTIN_TYPE:
4394
+ case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE:
4048
4395
  case DEMANGLE_COMPONENT_OPERATOR:
4049
4396
  case DEMANGLE_COMPONENT_CHARACTER:
4050
4397
  case DEMANGLE_COMPONENT_NUMBER:
4051
4398
  case DEMANGLE_COMPONENT_UNNAMED_TYPE:
4399
+ case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
4400
+ case DEMANGLE_COMPONENT_MODULE_NAME:
4401
+ case DEMANGLE_COMPONENT_MODULE_PARTITION:
4402
+ case DEMANGLE_COMPONENT_MODULE_INIT:
4403
+ case DEMANGLE_COMPONENT_FIXED_TYPE:
4404
+ case DEMANGLE_COMPONENT_TEMPLATE_HEAD:
4405
+ case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM:
4406
+ case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM:
4407
+ case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM:
4408
+ case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM:
4052
4409
  break;
4053
4410
 
4054
4411
  case DEMANGLE_COMPONENT_TEMPLATE:
4055
- (*num_templates)++;
4412
+ dpi->num_copy_templates++;
4056
4413
  goto recurse_left_right;
4057
4414
 
4058
4415
  case DEMANGLE_COMPONENT_REFERENCE:
4059
4416
  case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
4060
4417
  if (d_left (dc)->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
4061
- (*num_scopes)++;
4418
+ dpi->num_saved_scopes++;
4062
4419
  goto recurse_left_right;
4063
4420
 
4064
4421
  case DEMANGLE_COMPONENT_QUAL_NAME:
@@ -4087,6 +4444,7 @@ d_count_templates_scopes (int *num_templates, int *num_scopes,
4087
4444
  case DEMANGLE_COMPONENT_CONST_THIS:
4088
4445
  case DEMANGLE_COMPONENT_REFERENCE_THIS:
4089
4446
  case DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS:
4447
+ case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION:
4090
4448
  case DEMANGLE_COMPONENT_TRANSACTION_SAFE:
4091
4449
  case DEMANGLE_COMPONENT_NOEXCEPT:
4092
4450
  case DEMANGLE_COMPONENT_THROW_SPEC:
@@ -4101,6 +4459,7 @@ d_count_templates_scopes (int *num_templates, int *num_scopes,
4101
4459
  case DEMANGLE_COMPONENT_VECTOR_TYPE:
4102
4460
  case DEMANGLE_COMPONENT_ARGLIST:
4103
4461
  case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
4462
+ case DEMANGLE_COMPONENT_TPARM_OBJ:
4104
4463
  case DEMANGLE_COMPONENT_INITIALIZER_LIST:
4105
4464
  case DEMANGLE_COMPONENT_CAST:
4106
4465
  case DEMANGLE_COMPONENT_CONVERSION:
@@ -4113,6 +4472,7 @@ d_count_templates_scopes (int *num_templates, int *num_scopes,
4113
4472
  case DEMANGLE_COMPONENT_TRINARY_ARG2:
4114
4473
  case DEMANGLE_COMPONENT_LITERAL:
4115
4474
  case DEMANGLE_COMPONENT_LITERAL_NEG:
4475
+ case DEMANGLE_COMPONENT_VENDOR_EXPR:
4116
4476
  case DEMANGLE_COMPONENT_JAVA_RESOURCE:
4117
4477
  case DEMANGLE_COMPONENT_COMPOUND_NAME:
4118
4478
  case DEMANGLE_COMPONENT_DECLTYPE:
@@ -4121,43 +4481,42 @@ d_count_templates_scopes (int *num_templates, int *num_scopes,
4121
4481
  case DEMANGLE_COMPONENT_PACK_EXPANSION:
4122
4482
  case DEMANGLE_COMPONENT_TAGGED_NAME:
4123
4483
  case DEMANGLE_COMPONENT_CLONE:
4484
+ case DEMANGLE_COMPONENT_CONSTRAINTS:
4124
4485
  recurse_left_right:
4125
- d_count_templates_scopes (num_templates, num_scopes,
4126
- d_left (dc));
4127
- d_count_templates_scopes (num_templates, num_scopes,
4128
- d_right (dc));
4486
+ /* PR 89394 - Check for too much recursion. */
4487
+ if (dpi->recursion > DEMANGLE_RECURSION_LIMIT)
4488
+ /* FIXME: There ought to be a way to report to the
4489
+ user that the recursion limit has been reached. */
4490
+ return;
4491
+
4492
+ ++ dpi->recursion;
4493
+ d_count_templates_scopes (dpi, d_left (dc));
4494
+ d_count_templates_scopes (dpi, d_right (dc));
4495
+ -- dpi->recursion;
4129
4496
  break;
4130
4497
 
4131
4498
  case DEMANGLE_COMPONENT_CTOR:
4132
- d_count_templates_scopes (num_templates, num_scopes,
4133
- dc->u.s_ctor.name);
4499
+ d_count_templates_scopes (dpi, dc->u.s_ctor.name);
4134
4500
  break;
4135
4501
 
4136
4502
  case DEMANGLE_COMPONENT_DTOR:
4137
- d_count_templates_scopes (num_templates, num_scopes,
4138
- dc->u.s_dtor.name);
4503
+ d_count_templates_scopes (dpi, dc->u.s_dtor.name);
4139
4504
  break;
4140
4505
 
4141
4506
  case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
4142
- d_count_templates_scopes (num_templates, num_scopes,
4143
- dc->u.s_extended_operator.name);
4144
- break;
4145
-
4146
- case DEMANGLE_COMPONENT_FIXED_TYPE:
4147
- d_count_templates_scopes (num_templates, num_scopes,
4148
- dc->u.s_fixed.length);
4507
+ d_count_templates_scopes (dpi, dc->u.s_extended_operator.name);
4149
4508
  break;
4150
4509
 
4151
4510
  case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
4152
4511
  case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
4153
- d_count_templates_scopes (num_templates, num_scopes,
4154
- d_left (dc));
4512
+ case DEMANGLE_COMPONENT_MODULE_ENTITY:
4513
+ case DEMANGLE_COMPONENT_FRIEND:
4514
+ d_count_templates_scopes (dpi, d_left (dc));
4155
4515
  break;
4156
4516
 
4157
4517
  case DEMANGLE_COMPONENT_LAMBDA:
4158
4518
  case DEMANGLE_COMPONENT_DEFAULT_ARG:
4159
- d_count_templates_scopes (num_templates, num_scopes,
4160
- dc->u.s_unary_num.sub);
4519
+ d_count_templates_scopes (dpi, dc->u.s_unary_num.sub);
4161
4520
  break;
4162
4521
  }
4163
4522
  }
@@ -4166,7 +4525,7 @@ d_count_templates_scopes (int *num_templates, int *num_scopes,
4166
4525
 
4167
4526
  static void
4168
4527
  d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
4169
- void *opaque, const struct demangle_component *dc)
4528
+ void *opaque, struct demangle_component *dc)
4170
4529
  {
4171
4530
  dpi->len = 0;
4172
4531
  dpi->last_char = '\0';
@@ -4180,7 +4539,7 @@ d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
4180
4539
 
4181
4540
  dpi->demangle_failure = 0;
4182
4541
  dpi->recursion = 0;
4183
- dpi->is_lambda_arg = 0;
4542
+ dpi->lambda_tpl_parms = 0;
4184
4543
 
4185
4544
  dpi->component_stack = NULL;
4186
4545
 
@@ -4192,8 +4551,12 @@ d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
4192
4551
  dpi->next_copy_template = 0;
4193
4552
  dpi->num_copy_templates = 0;
4194
4553
 
4195
- d_count_templates_scopes (&dpi->num_copy_templates,
4196
- &dpi->num_saved_scopes, dc);
4554
+ d_count_templates_scopes (dpi, dc);
4555
+ /* If we did not reach the recursion limit, then reset the
4556
+ current recursion value back to 0, so that we can print
4557
+ the templates. */
4558
+ if (dpi->recursion < DEMANGLE_RECURSION_LIMIT)
4559
+ dpi->recursion = 0;
4197
4560
  dpi->num_copy_templates *= dpi->num_saved_scopes;
4198
4561
 
4199
4562
  dpi->current_template = NULL;
@@ -4412,11 +4775,11 @@ d_find_pack (struct d_print_info *dpi,
4412
4775
  case DEMANGLE_COMPONENT_TAGGED_NAME:
4413
4776
  case DEMANGLE_COMPONENT_OPERATOR:
4414
4777
  case DEMANGLE_COMPONENT_BUILTIN_TYPE:
4778
+ case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE:
4415
4779
  case DEMANGLE_COMPONENT_SUB_STD:
4416
4780
  case DEMANGLE_COMPONENT_CHARACTER:
4417
4781
  case DEMANGLE_COMPONENT_FUNCTION_PARAM:
4418
4782
  case DEMANGLE_COMPONENT_UNNAMED_TYPE:
4419
- case DEMANGLE_COMPONENT_FIXED_TYPE:
4420
4783
  case DEMANGLE_COMPONENT_DEFAULT_ARG:
4421
4784
  case DEMANGLE_COMPONENT_NUMBER:
4422
4785
  return NULL;
@@ -4615,6 +4978,91 @@ d_maybe_print_fold_expression (struct d_print_info *dpi, int options,
4615
4978
  return 1;
4616
4979
  }
4617
4980
 
4981
+ /* True iff DC represents a C99-style designated initializer. */
4982
+
4983
+ static int
4984
+ is_designated_init (struct demangle_component *dc)
4985
+ {
4986
+ if (dc->type != DEMANGLE_COMPONENT_BINARY
4987
+ && dc->type != DEMANGLE_COMPONENT_TRINARY)
4988
+ return 0;
4989
+
4990
+ struct demangle_component *op = d_left (dc);
4991
+ const char *code = op->u.s_operator.op->code;
4992
+ return (code[0] == 'd'
4993
+ && (code[1] == 'i' || code[1] == 'x' || code[1] == 'X'));
4994
+ }
4995
+
4996
+ /* If DC represents a C99-style designated initializer, print it and return
4997
+ true; otherwise, return false. */
4998
+
4999
+ static int
5000
+ d_maybe_print_designated_init (struct d_print_info *dpi, int options,
5001
+ struct demangle_component *dc)
5002
+ {
5003
+ if (!is_designated_init (dc))
5004
+ return 0;
5005
+
5006
+ const char *code = d_left (dc)->u.s_operator.op->code;
5007
+
5008
+ struct demangle_component *operands = d_right (dc);
5009
+ struct demangle_component *op1 = d_left (operands);
5010
+ struct demangle_component *op2 = d_right (operands);
5011
+
5012
+ if (code[1] == 'i')
5013
+ d_append_char (dpi, '.');
5014
+ else
5015
+ d_append_char (dpi, '[');
5016
+
5017
+ d_print_comp (dpi, options, op1);
5018
+ if (code[1] == 'X')
5019
+ {
5020
+ d_append_string (dpi, " ... ");
5021
+ d_print_comp (dpi, options, d_left (op2));
5022
+ op2 = d_right (op2);
5023
+ }
5024
+ if (code[1] != 'i')
5025
+ d_append_char (dpi, ']');
5026
+ if (is_designated_init (op2))
5027
+ {
5028
+ /* Don't put '=' or '(' between chained designators. */
5029
+ d_print_comp (dpi, options, op2);
5030
+ }
5031
+ else
5032
+ {
5033
+ d_append_char (dpi, '=');
5034
+ d_print_subexpr (dpi, options, op2);
5035
+ }
5036
+ return 1;
5037
+ }
5038
+
5039
+ static void
5040
+ d_print_lambda_parm_name (struct d_print_info *dpi, int type, unsigned index)
5041
+ {
5042
+ const char *str;
5043
+ switch (type)
5044
+ {
5045
+ default:
5046
+ dpi->demangle_failure = 1;
5047
+ str = "";
5048
+ break;
5049
+
5050
+ case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM:
5051
+ str = "$T";
5052
+ break;
5053
+
5054
+ case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM:
5055
+ str = "$N";
5056
+ break;
5057
+
5058
+ case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM:
5059
+ str = "$TT";
5060
+ break;
5061
+ }
5062
+ d_append_string (dpi, str);
5063
+ d_append_num (dpi, index);
5064
+ }
5065
+
4618
5066
  /* Subroutine to handle components. */
4619
5067
 
4620
5068
  static void
@@ -4656,6 +5104,38 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4656
5104
  d_append_char (dpi, ']');
4657
5105
  return;
4658
5106
 
5107
+ case DEMANGLE_COMPONENT_STRUCTURED_BINDING:
5108
+ d_append_char (dpi, '[');
5109
+ for (;;)
5110
+ {
5111
+ d_print_comp (dpi, options, d_left (dc));
5112
+ dc = d_right (dc);
5113
+ if (!dc)
5114
+ break;
5115
+ d_append_string (dpi, ", ");
5116
+ }
5117
+ d_append_char (dpi, ']');
5118
+ return;
5119
+
5120
+ case DEMANGLE_COMPONENT_MODULE_ENTITY:
5121
+ d_print_comp (dpi, options, d_left (dc));
5122
+ d_append_char (dpi, '@');
5123
+ d_print_comp (dpi, options, d_right (dc));
5124
+ return;
5125
+
5126
+ case DEMANGLE_COMPONENT_MODULE_NAME:
5127
+ case DEMANGLE_COMPONENT_MODULE_PARTITION:
5128
+ {
5129
+ if (d_left (dc))
5130
+ d_print_comp (dpi, options, d_left (dc));
5131
+ char c = dc->type == DEMANGLE_COMPONENT_MODULE_PARTITION
5132
+ ? ':' : d_left (dc) ? '.' : 0;
5133
+ if (c)
5134
+ d_append_char (dpi, c);
5135
+ d_print_comp (dpi, options, d_right (dc));
5136
+ }
5137
+ return;
5138
+
4659
5139
  case DEMANGLE_COMPONENT_QUAL_NAME:
4660
5140
  case DEMANGLE_COMPONENT_LOCAL_NAME:
4661
5141
  d_print_comp (dpi, options, d_left (dc));
@@ -4727,12 +5207,8 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4727
5207
  typed_name = d_right (typed_name);
4728
5208
  if (typed_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
4729
5209
  typed_name = typed_name->u.s_unary_num.sub;
4730
- if (typed_name == NULL)
4731
- {
4732
- d_print_error (dpi);
4733
- return;
4734
- }
4735
- while (is_fnqual_component_type (typed_name->type))
5210
+ while (typed_name != NULL
5211
+ && is_fnqual_component_type (typed_name->type))
4736
5212
  {
4737
5213
  if (i >= sizeof adpm / sizeof adpm[0])
4738
5214
  {
@@ -4751,6 +5227,11 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4751
5227
 
4752
5228
  typed_name = d_left (typed_name);
4753
5229
  }
5230
+ if (typed_name == NULL)
5231
+ {
5232
+ d_print_error (dpi);
5233
+ return;
5234
+ }
4754
5235
  }
4755
5236
 
4756
5237
  /* If typed_name is a template, then it applies to the
@@ -4760,6 +5241,22 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4760
5241
  dpt.next = dpi->templates;
4761
5242
  dpi->templates = &dpt;
4762
5243
  dpt.template_decl = typed_name;
5244
+
5245
+ /* Constraints are mangled as part of the template argument list,
5246
+ so they wrap the _TEMPLATE_ARGLIST. But
5247
+ d_lookup_template_argument expects the RHS of _TEMPLATE to be
5248
+ the _ARGLIST, and constraints need to refer to these args. So
5249
+ move the _CONSTRAINTS out of the _TEMPLATE and onto the type.
5250
+ This will result in them being printed after the () like a
5251
+ trailing requires-clause, but that seems like our best option
5252
+ given that we aren't printing a template-head. */
5253
+ struct demangle_component *tnr = d_right (typed_name);
5254
+ if (tnr->type == DEMANGLE_COMPONENT_CONSTRAINTS)
5255
+ {
5256
+ d_right (typed_name) = d_left (tnr);
5257
+ d_left (tnr) = d_right (dc);
5258
+ d_right (dc) = tnr;
5259
+ }
4763
5260
  }
4764
5261
 
4765
5262
  d_print_comp (dpi, options, d_right (dc));
@@ -4836,7 +5333,21 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4836
5333
  }
4837
5334
 
4838
5335
  case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
4839
- if (dpi->is_lambda_arg)
5336
+ if (dpi->lambda_tpl_parms > dc->u.s_number.number + 1)
5337
+ {
5338
+ const struct demangle_component *a
5339
+ = d_left (dpi->templates->template_decl);
5340
+ unsigned c;
5341
+ for (c = dc->u.s_number.number; a && c; c--)
5342
+ a = d_right (a);
5343
+ if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM)
5344
+ a = d_left (a);
5345
+ if (!a)
5346
+ dpi->demangle_failure = 1;
5347
+ else
5348
+ d_print_lambda_parm_name (dpi, a->type, dc->u.s_number.number);
5349
+ }
5350
+ else if (dpi->lambda_tpl_parms)
4840
5351
  {
4841
5352
  /* Show the template parm index, as that's how g++ displays
4842
5353
  these, and future proofs us against potential
@@ -4872,6 +5383,11 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4872
5383
  }
4873
5384
  return;
4874
5385
 
5386
+ case DEMANGLE_COMPONENT_TPARM_OBJ:
5387
+ d_append_string (dpi, "template parameter object for ");
5388
+ d_print_comp (dpi, options, d_left (dc));
5389
+ return;
5390
+
4875
5391
  case DEMANGLE_COMPONENT_CTOR:
4876
5392
  d_print_comp (dpi, options, dc->u.s_ctor.name);
4877
5393
  return;
@@ -4881,6 +5397,11 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
4881
5397
  d_print_comp (dpi, options, dc->u.s_dtor.name);
4882
5398
  return;
4883
5399
 
5400
+ case DEMANGLE_COMPONENT_MODULE_INIT:
5401
+ d_append_string (dpi, "initializer for module ");
5402
+ d_print_comp (dpi, options, d_left (dc));
5403
+ return;
5404
+
4884
5405
  case DEMANGLE_COMPONENT_VTABLE:
4885
5406
  d_append_string (dpi, "vtable for ");
4886
5407
  d_print_comp (dpi, options, d_left (dc));
@@ -5007,7 +5528,7 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5007
5528
  {
5008
5529
  /* Handle reference smashing: & + && = &. */
5009
5530
  struct demangle_component *sub = d_left (dc);
5010
- if (!dpi->is_lambda_arg
5531
+ if (!dpi->lambda_tpl_parms
5011
5532
  && sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
5012
5533
  {
5013
5534
  struct d_saved_scope *scope = d_get_saved_scope (dpi, sub);
@@ -5118,6 +5639,14 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5118
5639
  dc->u.s_builtin.type->java_len);
5119
5640
  return;
5120
5641
 
5642
+ case DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE:
5643
+ d_append_buffer (dpi, dc->u.s_extended_builtin.type->name,
5644
+ dc->u.s_extended_builtin.type->len);
5645
+ d_append_num (dpi, dc->u.s_extended_builtin.arg);
5646
+ if (dc->u.s_extended_builtin.suffix)
5647
+ d_append_buffer (dpi, &dc->u.s_extended_builtin.suffix, 1);
5648
+ return;
5649
+
5121
5650
  case DEMANGLE_COMPONENT_VENDOR_TYPE:
5122
5651
  d_print_comp (dpi, options, d_left (dc));
5123
5652
  return;
@@ -5256,22 +5785,6 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5256
5785
  return;
5257
5786
  }
5258
5787
 
5259
- case DEMANGLE_COMPONENT_FIXED_TYPE:
5260
- if (dc->u.s_fixed.sat)
5261
- d_append_string (dpi, "_Sat ");
5262
- /* Don't print "int _Accum". */
5263
- if (dc->u.s_fixed.length->u.s_builtin.type
5264
- != &cplus_demangle_builtin_types['i'-'a'])
5265
- {
5266
- d_print_comp (dpi, options, dc->u.s_fixed.length);
5267
- d_append_char (dpi, ' ');
5268
- }
5269
- if (dc->u.s_fixed.accum)
5270
- d_append_string (dpi, "_Accum");
5271
- else
5272
- d_append_string (dpi, "_Fract");
5273
- return;
5274
-
5275
5788
  case DEMANGLE_COMPONENT_ARGLIST:
5276
5789
  case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
5277
5790
  if (d_left (dc) != NULL)
@@ -5392,8 +5905,8 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5392
5905
  if (code && !strcmp (code, "gs"))
5393
5906
  /* Avoid parens after '::'. */
5394
5907
  d_print_comp (dpi, options, operand);
5395
- else if (code && !strcmp (code, "st"))
5396
- /* Always print parens for sizeof (type). */
5908
+ else if (code && (!strcmp (code, "st") || !strcmp (code, "nx")))
5909
+ /* Always print parens for sizeof (type) and noexcept(expr). */
5397
5910
  {
5398
5911
  d_append_char (dpi, '(');
5399
5912
  d_print_comp (dpi, options, operand);
@@ -5425,6 +5938,9 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5425
5938
  if (d_maybe_print_fold_expression (dpi, options, dc))
5426
5939
  return;
5427
5940
 
5941
+ if (d_maybe_print_designated_init (dpi, options, dc))
5942
+ return;
5943
+
5428
5944
  /* We wrap an expression which uses the greater-than operator in
5429
5945
  an extra layer of parens so that it does not get confused
5430
5946
  with the '>' which ends the template parameters. */
@@ -5482,6 +5998,8 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5482
5998
  }
5483
5999
  if (d_maybe_print_fold_expression (dpi, options, dc))
5484
6000
  return;
6001
+ if (d_maybe_print_designated_init (dpi, options, dc))
6002
+ return;
5485
6003
  {
5486
6004
  struct demangle_component *op = d_left (dc);
5487
6005
  struct demangle_component *first = d_left (d_right (dc));
@@ -5601,6 +6119,13 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5601
6119
  }
5602
6120
  return;
5603
6121
 
6122
+ case DEMANGLE_COMPONENT_VENDOR_EXPR:
6123
+ d_print_comp (dpi, options, d_left (dc));
6124
+ d_append_char (dpi, '(');
6125
+ d_print_comp (dpi, options, d_right (dc));
6126
+ d_append_char (dpi, ')');
6127
+ return;
6128
+
5604
6129
  case DEMANGLE_COMPONENT_NUMBER:
5605
6130
  d_append_num (dpi, dc->u.s_number.number);
5606
6131
  return;
@@ -5627,9 +6152,10 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5627
6152
 
5628
6153
  case DEMANGLE_COMPONENT_PACK_EXPANSION:
5629
6154
  {
5630
- int len;
5631
- int i;
5632
- struct demangle_component *a = d_find_pack (dpi, d_left (dc));
6155
+ struct demangle_component *a = NULL;
6156
+
6157
+ if (!dpi->lambda_tpl_parms)
6158
+ a = d_find_pack (dpi, d_left (dc));
5633
6159
  if (a == NULL)
5634
6160
  {
5635
6161
  /* d_find_pack won't find anything if the only packs involved
@@ -5637,17 +6163,20 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5637
6163
  case, just print the pattern and "...". */
5638
6164
  d_print_subexpr (dpi, options, d_left (dc));
5639
6165
  d_append_string (dpi, "...");
5640
- return;
5641
6166
  }
5642
-
5643
- len = d_pack_length (a);
5644
- dc = d_left (dc);
5645
- for (i = 0; i < len; ++i)
6167
+ else
5646
6168
  {
5647
- dpi->pack_index = i;
5648
- d_print_comp (dpi, options, dc);
5649
- if (i < len-1)
5650
- d_append_string (dpi, ", ");
6169
+ int len = d_pack_length (a);
6170
+ int i;
6171
+
6172
+ dc = d_left (dc);
6173
+ for (i = 0; i < len; ++i)
6174
+ {
6175
+ if (i)
6176
+ d_append_string (dpi, ", ");
6177
+ dpi->pack_index = i;
6178
+ d_print_comp (dpi, options, dc);
6179
+ }
5651
6180
  }
5652
6181
  }
5653
6182
  return;
@@ -5677,15 +6206,50 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5677
6206
  return;
5678
6207
 
5679
6208
  case DEMANGLE_COMPONENT_LAMBDA:
5680
- d_append_string (dpi, "{lambda(");
5681
- /* Generic lambda auto parms are mangled as the template type
5682
- parm they are. */
5683
- dpi->is_lambda_arg++;
5684
- d_print_comp (dpi, options, dc->u.s_unary_num.sub);
5685
- dpi->is_lambda_arg--;
5686
- d_append_string (dpi, ")#");
5687
- d_append_num (dpi, dc->u.s_unary_num.num + 1);
5688
- d_append_char (dpi, '}');
6209
+ {
6210
+ d_append_string (dpi, "{lambda");
6211
+ struct demangle_component *parms = dc->u.s_unary_num.sub;
6212
+ struct d_print_template dpt;
6213
+ /* Generic lambda auto parms are mangled as the (synthedic) template
6214
+ type parm they are. We need to tell the printer that (a) we're in
6215
+ a lambda, and (b) the number of synthetic parms. */
6216
+ int saved_tpl_parms = dpi->lambda_tpl_parms;
6217
+ dpi->lambda_tpl_parms = 0;
6218
+ /* Hang any lambda head as-if template args. */
6219
+ dpt.template_decl = NULL;
6220
+ dpt.next = dpi->templates;
6221
+ dpi->templates = &dpt;
6222
+ if (parms && parms->type == DEMANGLE_COMPONENT_TEMPLATE_HEAD)
6223
+ {
6224
+ dpt.template_decl = parms;
6225
+
6226
+ d_append_char (dpi, '<');
6227
+ struct demangle_component *parm;
6228
+ for (parm = d_left (parms); parm; parm = d_right (parm))
6229
+ {
6230
+ if (dpi->lambda_tpl_parms++)
6231
+ d_append_string (dpi, ", ");
6232
+ d_print_comp (dpi, options, parm);
6233
+ d_append_char (dpi, ' ');
6234
+ if (parm->type == DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM)
6235
+ parm = d_left (parm);
6236
+ d_print_lambda_parm_name (dpi, parm->type,
6237
+ dpi->lambda_tpl_parms - 1);
6238
+ }
6239
+ d_append_char (dpi, '>');
6240
+
6241
+ parms = d_right (parms);
6242
+ }
6243
+ dpi->lambda_tpl_parms++;
6244
+
6245
+ d_append_char (dpi, '(');
6246
+ d_print_comp (dpi, options, parms);
6247
+ dpi->lambda_tpl_parms = saved_tpl_parms;
6248
+ dpi->templates = dpt.next;
6249
+ d_append_string (dpi, ")#");
6250
+ d_append_num (dpi, dc->u.s_unary_num.num + 1);
6251
+ d_append_char (dpi, '}');
6252
+ }
5689
6253
  return;
5690
6254
 
5691
6255
  case DEMANGLE_COMPONENT_UNNAMED_TYPE:
@@ -5701,6 +6265,51 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
5701
6265
  d_append_char (dpi, ']');
5702
6266
  return;
5703
6267
 
6268
+ case DEMANGLE_COMPONENT_FRIEND:
6269
+ d_print_comp (dpi, options, d_left (dc));
6270
+ d_append_string (dpi, "[friend]");
6271
+ return;
6272
+
6273
+ case DEMANGLE_COMPONENT_TEMPLATE_HEAD:
6274
+ {
6275
+ d_append_char (dpi, '<');
6276
+ int count = 0;
6277
+ struct demangle_component *parm;
6278
+ for (parm = d_left (dc); parm; parm = d_right (parm))
6279
+ {
6280
+ if (count++)
6281
+ d_append_string (dpi, ", ");
6282
+ d_print_comp (dpi, options, parm);
6283
+ }
6284
+ d_append_char (dpi, '>');
6285
+ }
6286
+ return;
6287
+
6288
+ case DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM:
6289
+ d_append_string (dpi, "typename");
6290
+ return;
6291
+
6292
+ case DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM:
6293
+ d_print_comp (dpi, options, d_left (dc));
6294
+ return;
6295
+
6296
+ case DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM:
6297
+ d_append_string (dpi, "template");
6298
+ d_print_comp (dpi, options, d_left (dc));
6299
+ d_append_string (dpi, " class");
6300
+ return;
6301
+
6302
+ case DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM:
6303
+ d_print_comp (dpi, options, d_left (dc));
6304
+ d_append_string (dpi, "...");
6305
+ return;
6306
+
6307
+ case DEMANGLE_COMPONENT_CONSTRAINTS:
6308
+ d_print_comp (dpi, options, d_left (dc));
6309
+ d_append_string (dpi, " requires ");
6310
+ d_print_comp (dpi, options, d_right (dc));
6311
+ return;
6312
+
5704
6313
  default:
5705
6314
  d_print_error (dpi);
5706
6315
  return;
@@ -5930,11 +6539,13 @@ d_print_mod (struct d_print_info *dpi, int options,
5930
6539
  case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
5931
6540
  d_append_string (dpi, "&&");
5932
6541
  return;
6542
+ case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION:
6543
+ return;
5933
6544
  case DEMANGLE_COMPONENT_COMPLEX:
5934
- d_append_string (dpi, "complex ");
6545
+ d_append_string (dpi, " _Complex");
5935
6546
  return;
5936
6547
  case DEMANGLE_COMPONENT_IMAGINARY:
5937
- d_append_string (dpi, "imaginary ");
6548
+ d_append_string (dpi, " _Imaginary");
5938
6549
  return;
5939
6550
  case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5940
6551
  if (d_last_char (dpi) != '(')
@@ -5968,11 +6579,13 @@ d_print_function_type (struct d_print_info *dpi, int options,
5968
6579
  {
5969
6580
  int need_paren;
5970
6581
  int need_space;
6582
+ int xobj_memfn;
5971
6583
  struct d_print_mod *p;
5972
6584
  struct d_print_mod *hold_modifiers;
5973
6585
 
5974
6586
  need_paren = 0;
5975
6587
  need_space = 0;
6588
+ xobj_memfn = 0;
5976
6589
  for (p = mods; p != NULL; p = p->next)
5977
6590
  {
5978
6591
  if (p->printed)
@@ -5995,7 +6608,8 @@ d_print_function_type (struct d_print_info *dpi, int options,
5995
6608
  need_space = 1;
5996
6609
  need_paren = 1;
5997
6610
  break;
5998
- FNQUAL_COMPONENT_CASE:
6611
+ case DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION:
6612
+ xobj_memfn = 1;
5999
6613
  break;
6000
6614
  default:
6001
6615
  break;
@@ -6026,6 +6640,8 @@ d_print_function_type (struct d_print_info *dpi, int options,
6026
6640
  d_append_char (dpi, ')');
6027
6641
 
6028
6642
  d_append_char (dpi, '(');
6643
+ if (xobj_memfn)
6644
+ d_append_string (dpi, "this ");
6029
6645
 
6030
6646
  if (d_right (dc) != NULL)
6031
6647
  d_print_comp (dpi, options, d_right (dc));
@@ -6130,32 +6746,10 @@ d_print_conversion (struct d_print_info *dpi, int options,
6130
6746
  dpt.template_decl = dpi->current_template;
6131
6747
  }
6132
6748
 
6133
- if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE)
6134
- {
6135
- d_print_comp (dpi, options, d_left (dc));
6136
- if (dpi->current_template != NULL)
6137
- dpi->templates = dpt.next;
6138
- }
6139
- else
6140
- {
6141
- d_print_comp (dpi, options, d_left (d_left (dc)));
6142
-
6143
- /* For a templated cast operator, we need to remove the template
6144
- parameters from scope after printing the operator name,
6145
- so we need to handle the template printing here. */
6146
- if (dpi->current_template != NULL)
6147
- dpi->templates = dpt.next;
6749
+ d_print_comp (dpi, options, d_left (dc));
6148
6750
 
6149
- if (d_last_char (dpi) == '<')
6150
- d_append_char (dpi, ' ');
6151
- d_append_char (dpi, '<');
6152
- d_print_comp (dpi, options, d_right (d_left (dc)));
6153
- /* Avoid generating two consecutive '>' characters, to avoid
6154
- the C++ syntactic ambiguity. */
6155
- if (d_last_char (dpi) == '>')
6156
- d_append_char (dpi, ' ');
6157
- d_append_char (dpi, '>');
6158
- }
6751
+ if (dpi->current_template != NULL)
6752
+ dpi->templates = dpt.next;
6159
6753
  }
6160
6754
 
6161
6755
  /* Initialize the information structure we use to pass around
@@ -6172,13 +6766,13 @@ cplus_demangle_init_info (const char *mangled, int options, size_t len,
6172
6766
 
6173
6767
  di->n = mangled;
6174
6768
 
6175
- /* We can not need more components than twice the number of chars in
6769
+ /* We cannot need more components than twice the number of chars in
6176
6770
  the mangled string. Most components correspond directly to
6177
6771
  chars, but the ARGLIST types are exceptions. */
6178
6772
  di->num_comps = 2 * len;
6179
6773
  di->next_comp = 0;
6180
6774
 
6181
- /* Similarly, we can not need more substitutions than there are
6775
+ /* Similarly, we cannot need more substitutions than there are
6182
6776
  chars in the mangled string. */
6183
6777
  di->num_subs = len;
6184
6778
  di->next_sub = 0;
@@ -6188,6 +6782,7 @@ cplus_demangle_init_info (const char *mangled, int options, size_t len,
6188
6782
  di->expansion = 0;
6189
6783
  di->is_expression = 0;
6190
6784
  di->is_conversion = 0;
6785
+ di->recursion_level = 0;
6191
6786
  }
6192
6787
 
6193
6788
  /* Internal implementation for the demangler. If MANGLED is a g++ v3 ABI
@@ -6225,8 +6820,25 @@ d_demangle_callback (const char *mangled, int options,
6225
6820
  type = DCT_TYPE;
6226
6821
  }
6227
6822
 
6823
+ di.unresolved_name_state = 1;
6824
+
6825
+ again:
6228
6826
  cplus_demangle_init_info (mangled, options, strlen (mangled), &di);
6229
6827
 
6828
+ /* PR 87675 - Check for a mangled string that is so long
6829
+ that we do not have enough stack space to demangle it. */
6830
+ if (((options & DMGL_NO_RECURSE_LIMIT) == 0)
6831
+ /* This check is a bit arbitrary, since what we really want to do is to
6832
+ compare the sizes of the di.comps and di.subs arrays against the
6833
+ amount of stack space remaining. But there is no portable way to do
6834
+ this, so instead we use the recursion limit as a guide to the maximum
6835
+ size of the arrays. */
6836
+ && (unsigned long) di.num_comps > DEMANGLE_RECURSION_LIMIT)
6837
+ {
6838
+ /* FIXME: We need a way to indicate that a stack limit has been reached. */
6839
+ return 0;
6840
+ }
6841
+
6230
6842
  {
6231
6843
  #ifdef CP_DYNAMIC_ARRAYS
6232
6844
  __extension__ struct demangle_component comps[di.num_comps];
@@ -6269,6 +6881,13 @@ d_demangle_callback (const char *mangled, int options,
6269
6881
  if (((options & DMGL_PARAMS) != 0) && d_peek_char (&di) != '\0')
6270
6882
  dc = NULL;
6271
6883
 
6884
+ /* See discussion in d_unresolved_name. */
6885
+ if (dc == NULL && di.unresolved_name_state == -1)
6886
+ {
6887
+ di.unresolved_name_state = 0;
6888
+ goto again;
6889
+ }
6890
+
6272
6891
  #ifdef CP_DEMANGLE_DEBUG
6273
6892
  d_dump (dc, 0);
6274
6893
  #endif