@@ -425,7 +425,7 @@ is_ctor_dtor_or_conversion (struct demangle_component *);
425425
426426static struct demangle_component * d_encoding (struct d_info * , int );
427427
428- static struct demangle_component * d_name (struct d_info * , int );
428+ static struct demangle_component * d_name (struct d_info * );
429429
430430static struct demangle_component * d_nested_name (struct d_info * );
431431
@@ -484,7 +484,7 @@ static struct demangle_component *d_expression (struct d_info *);
484484
485485static struct demangle_component * d_expr_primary (struct d_info * );
486486
487- static struct demangle_component * d_local_name (struct d_info * , int );
487+ static struct demangle_component * d_local_name (struct d_info * );
488488
489489static int d_discriminator (struct d_info * );
490490
@@ -1259,6 +1259,8 @@ has_return_type (struct demangle_component *dc)
12591259 {
12601260 default :
12611261 return 0 ;
1262+ case DEMANGLE_COMPONENT_LOCAL_NAME :
1263+ return has_return_type (d_right (dc ));
12621264 case DEMANGLE_COMPONENT_TEMPLATE :
12631265 return ! is_ctor_dtor_or_conversion (d_left (dc ));
12641266 FNQUAL_COMPONENT_CASE :
@@ -1301,48 +1303,50 @@ static struct demangle_component *
13011303d_encoding (struct d_info * di , int top_level )
13021304{
13031305 char peek = d_peek_char (di );
1306+ struct demangle_component * dc ;
13041307
13051308 if (peek == 'G' || peek == 'T' )
1306- return d_special_name (di );
1309+ dc = d_special_name (di );
13071310 else
13081311 {
1309- struct demangle_component * dc , * dcr ;
1310-
1311- dc = d_name (di , top_level );
1312+ dc = d_name (di );
13121313
1313- if (dc != NULL && top_level && (di -> options & DMGL_PARAMS ) == 0 )
1314+ if (!dc )
1315+ /* Failed already. */ ;
1316+ else if (top_level && (di -> options & DMGL_PARAMS ) == 0 )
13141317 {
13151318 /* Strip off any initial CV-qualifiers, as they really apply
13161319 to the `this' parameter, and they were not output by the
13171320 v2 demangler without DMGL_PARAMS. */
1318- while (dc -> type == DEMANGLE_COMPONENT_RESTRICT_THIS
1319- || dc -> type == DEMANGLE_COMPONENT_VOLATILE_THIS
1320- || dc -> type == DEMANGLE_COMPONENT_CONST_THIS
1321- || dc -> type == DEMANGLE_COMPONENT_REFERENCE_THIS
1322- || dc -> type == DEMANGLE_COMPONENT_RVALUE_REFERENCE_THIS )
1321+ while (is_fnqual_component_type (dc -> type ))
13231322 dc = d_left (dc );
13241323
13251324 /* If the top level is a DEMANGLE_COMPONENT_LOCAL_NAME, then
13261325 there may be function-qualifiers on its right argument which
13271326 really apply here; this happens when parsing a class
13281327 which is local to a function. */
13291328 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 ));
1331+ }
1332+ else
1333+ {
1334+ peek = d_peek_char (di );
1335+ if (peek != '\0' && peek != 'E' )
13301336 {
1331- dcr = d_right (dc );
1332- while (is_fnqual_component_type (dcr -> type ))
1333- dcr = d_left (dcr );
1334- dc -> u .s_binary .right = dcr ;
1335- }
1337+ struct demangle_component * ftype ;
13361338
1337- return dc ;
1339+ ftype = d_bare_function_type (di , has_return_type (dc ));
1340+ if (ftype )
1341+ dc = d_make_comp (di , DEMANGLE_COMPONENT_TYPED_NAME ,
1342+ dc , ftype );
1343+ else
1344+ dc = NULL ;
1345+ }
13381346 }
1339-
1340- peek = d_peek_char (di );
1341- if (dc == NULL || peek == '\0' || peek == 'E' )
1342- return dc ;
1343- dcr = d_bare_function_type (di , has_return_type (dc ));
1344- return d_make_comp (di , DEMANGLE_COMPONENT_TYPED_NAME , dc , dcr );
13451347 }
1348+
1349+ return dc ;
13461350}
13471351
13481352/* <tagged-name> ::= <name> B <source-name> */
@@ -1383,7 +1387,7 @@ d_abi_tags (struct d_info *di, struct demangle_component *dc)
13831387*/
13841388
13851389static struct demangle_component *
1386- d_name (struct d_info * di , int top_level )
1390+ d_name (struct d_info * di )
13871391{
13881392 char peek = d_peek_char (di );
13891393 struct demangle_component * dc ;
@@ -1394,7 +1398,7 @@ d_name (struct d_info *di, int top_level)
13941398 return d_nested_name (di );
13951399
13961400 case 'Z' :
1397- return d_local_name (di , top_level );
1401+ return d_local_name (di );
13981402
13991403 case 'U' :
14001404 return d_unqualified_name (di );
@@ -2079,11 +2083,11 @@ d_special_name (struct d_info *di)
20792083
20802084 case 'H' :
20812085 return d_make_comp (di , DEMANGLE_COMPONENT_TLS_INIT ,
2082- d_name (di , 0 ), NULL );
2086+ d_name (di ), NULL );
20832087
20842088 case 'W' :
20852089 return d_make_comp (di , DEMANGLE_COMPONENT_TLS_WRAPPER ,
2086- d_name (di , 0 ), NULL );
2090+ d_name (di ), NULL );
20872091
20882092 default :
20892093 return NULL ;
@@ -2095,11 +2099,11 @@ d_special_name (struct d_info *di)
20952099 {
20962100 case 'V' :
20972101 return d_make_comp (di , DEMANGLE_COMPONENT_GUARD ,
2098- d_name (di , 0 ), NULL );
2102+ d_name (di ), NULL );
20992103
21002104 case 'R' :
21012105 {
2102- struct demangle_component * name = d_name (di , 0 );
2106+ struct demangle_component * name = d_name (di );
21032107 return d_make_comp (di , DEMANGLE_COMPONENT_REFTEMP , name ,
21042108 d_number_component (di ));
21052109 }
@@ -2935,7 +2939,7 @@ d_bare_function_type (struct d_info *di, int has_return_type)
29352939static struct demangle_component *
29362940d_class_enum_type (struct d_info * di )
29372941{
2938- return d_name (di , 0 );
2942+ return d_name (di );
29392943}
29402944
29412945/* <array-type> ::= A <(positive dimension) number> _ <(element) type>
@@ -3380,13 +3384,10 @@ d_expression_1 (struct d_info *di)
33803384
33813385 if (suffix )
33823386 /* Indicate the suffix variant for d_print_comp. */
3383- return d_make_comp (di , DEMANGLE_COMPONENT_UNARY , op ,
3384- d_make_comp (di ,
3385- DEMANGLE_COMPONENT_BINARY_ARGS ,
3386- operand , operand ));
3387- else
3388- return d_make_comp (di , DEMANGLE_COMPONENT_UNARY , op ,
3389- operand );
3387+ operand = d_make_comp (di , DEMANGLE_COMPONENT_BINARY_ARGS ,
3388+ operand , operand );
3389+
3390+ return d_make_comp (di , DEMANGLE_COMPONENT_UNARY , op , operand );
33903391 }
33913392 case 2 :
33923393 {
@@ -3568,7 +3569,7 @@ d_expr_primary (struct d_info *di)
35683569*/
35693570
35703571static struct demangle_component *
3571- d_local_name (struct d_info * di , int top_level )
3572+ d_local_name (struct d_info * di )
35723573{
35733574 struct demangle_component * function ;
35743575 struct demangle_component * name ;
@@ -3577,6 +3578,8 @@ d_local_name (struct d_info *di, int top_level)
35773578 return NULL ;
35783579
35793580 function = d_encoding (di , 0 );
3581+ if (!function )
3582+ return NULL ;
35803583
35813584 if (! d_check_char (di , 'E' ))
35823585 return NULL ;
@@ -3601,26 +3604,14 @@ d_local_name (struct d_info *di, int top_level)
36013604 return NULL ;
36023605 }
36033606
3604- name = d_name (di , 0 );
3607+ name = d_name (di );
36053608
36063609 if (name
36073610 /* Lambdas and unnamed types have internal discriminators
36083611 and are not functions. */
36093612 && name -> type != DEMANGLE_COMPONENT_LAMBDA
36103613 && name -> type != DEMANGLE_COMPONENT_UNNAMED_TYPE )
36113614 {
3612- if (!top_level
3613- && d_peek_char (di ) != 0 /* Not end of string. */
3614- && d_peek_char (di ) != 'E' /* Not end of nested encoding. */
3615- && d_peek_char (di ) != '_' ) /* Not discriminator. */
3616- {
3617- struct demangle_component * args ;
3618-
3619- args = d_bare_function_type (di , has_return_type (name ));
3620- name = d_make_comp (di , DEMANGLE_COMPONENT_TYPED_NAME ,
3621- name , args );
3622- }
3623-
36243615 /* Read and ignore an optional discriminator. */
36253616 if (! d_discriminator (di ))
36263617 return NULL ;
@@ -4710,32 +4701,21 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
47104701 return ;
47114702 }
47124703
4713- /* If typed_name is a template, then it applies to the
4714- function type as well. */
4715- if (typed_name -> type == DEMANGLE_COMPONENT_TEMPLATE )
4716- {
4717- dpt .next = dpi -> templates ;
4718- dpi -> templates = & dpt ;
4719- dpt .template_decl = typed_name ;
4720- }
4721-
47224704 /* If typed_name is a DEMANGLE_COMPONENT_LOCAL_NAME, then
47234705 there may be CV-qualifiers on its right argument which
4724- really apply here; this happens when parsing a class which
4706+ really apply here; this happens when parsing a class that
47254707 is local to a function. */
47264708 if (typed_name -> type == DEMANGLE_COMPONENT_LOCAL_NAME )
47274709 {
4728- struct demangle_component * local_name ;
4729-
4730- local_name = d_right (typed_name );
4731- if (local_name -> type == DEMANGLE_COMPONENT_DEFAULT_ARG )
4732- local_name = local_name -> u .s_unary_num .sub ;
4733- if (local_name == NULL )
4710+ typed_name = d_right (typed_name );
4711+ if (typed_name -> type == DEMANGLE_COMPONENT_DEFAULT_ARG )
4712+ typed_name = typed_name -> u .s_unary_num .sub ;
4713+ if (typed_name == NULL )
47344714 {
47354715 d_print_error (dpi );
47364716 return ;
47374717 }
4738- while (is_fnqual_component_type (local_name -> type ))
4718+ while (is_fnqual_component_type (typed_name -> type ))
47394719 {
47404720 if (i >= sizeof adpm / sizeof adpm [0 ])
47414721 {
@@ -4747,15 +4727,24 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
47474727 adpm [i ].next = & adpm [i - 1 ];
47484728 dpi -> modifiers = & adpm [i ];
47494729
4750- adpm [i - 1 ].mod = local_name ;
4730+ adpm [i - 1 ].mod = typed_name ;
47514731 adpm [i - 1 ].printed = 0 ;
47524732 adpm [i - 1 ].templates = dpi -> templates ;
47534733 ++ i ;
47544734
4755- local_name = d_left (local_name );
4735+ typed_name = d_left (typed_name );
47564736 }
47574737 }
47584738
4739+ /* If typed_name is a template, then it applies to the
4740+ function type as well. */
4741+ if (typed_name -> type == DEMANGLE_COMPONENT_TEMPLATE )
4742+ {
4743+ dpt .next = dpi -> templates ;
4744+ dpi -> templates = & dpt ;
4745+ dpt .template_decl = typed_name ;
4746+ }
4747+
47594748 d_print_comp (dpi , options , d_right (dc ));
47604749
47614750 if (typed_name -> type == DEMANGLE_COMPONENT_TEMPLATE )
0 commit comments