@@ -1025,69 +1025,75 @@ class ASTVisitor
1025
1025
return DD->getType ();
1026
1026
}
1027
1027
1028
- std::unique_ptr<TParam>
1028
+ void
1029
1029
buildTemplateParam (
1030
+ std::unique_ptr<TParam>& I,
1030
1031
const NamedDecl* N)
1031
1032
{
1032
- auto TP = visit (N, [&]<typename DeclTy>(
1033
- const DeclTy* P) ->
1034
- std::unique_ptr<TParam>
1033
+ visit (N, [&]<typename DeclTy>(const DeclTy* P)
1035
1034
{
1036
1035
constexpr Decl::Kind kind =
1037
1036
DeclToKind<DeclTy>();
1038
1037
1039
1038
if constexpr (kind == Decl::TemplateTypeParm)
1040
1039
{
1041
- auto R = std::make_unique<TypeTParam>();
1040
+ if (! I)
1041
+ I = std::make_unique<TypeTParam>();
1042
+ auto * R = static_cast <TypeTParam*>(I.get ());
1042
1043
if (P->wasDeclaredWithTypename ())
1043
1044
R->KeyKind = TParamKeyKind::Typename;
1044
- if (P->hasDefaultArgument ())
1045
+ if (P->hasDefaultArgument () && !R-> Default )
1045
1046
R->Default = buildTemplateArg (
1046
1047
P->getDefaultArgument ().getArgument ());
1047
- return R ;
1048
+ return ;
1048
1049
}
1049
1050
else if constexpr (kind == Decl::NonTypeTemplateParm)
1050
1051
{
1051
- auto R = std::make_unique<NonTypeTParam>();
1052
+ if (! I)
1053
+ I = std::make_unique<NonTypeTParam>();
1054
+ auto * R = static_cast <NonTypeTParam*>(I.get ());
1052
1055
R->Type = buildTypeInfo (P->getType ());
1053
- if (P->hasDefaultArgument ())
1056
+ if (P->hasDefaultArgument () && !R-> Default )
1054
1057
R->Default = buildTemplateArg (
1055
1058
P->getDefaultArgument ().getArgument ());
1056
- return R ;
1059
+ return ;
1057
1060
}
1058
1061
else if constexpr (kind == Decl::TemplateTemplateParm)
1059
1062
{
1060
- auto R = std::make_unique<TemplateTParam>();
1061
- for (const NamedDecl* NP : *P->getTemplateParameters ())
1062
- R->Params .emplace_back (
1063
- buildTemplateParam (NP));
1064
-
1065
- if (P->hasDefaultArgument ())
1063
+ if (! I)
1064
+ I = std::make_unique<TemplateTParam>();
1065
+ auto * R = static_cast <TemplateTParam*>(I.get ());
1066
+ if (R->Params .empty ())
1067
+ {
1068
+ for (const NamedDecl* NP : *P->getTemplateParameters ())
1069
+ buildTemplateParam (R->Params .emplace_back (), NP);
1070
+ }
1071
+ if (P->hasDefaultArgument () && !R->Default )
1066
1072
R->Default = buildTemplateArg (
1067
1073
P->getDefaultArgument ().getArgument ());
1068
- return R ;
1074
+ return ;
1069
1075
}
1070
1076
MRDOCS_UNREACHABLE ();
1071
1077
});
1072
1078
1073
- TP->Name = extractName (N);
1079
+ if (I->Name .empty ())
1080
+ I->Name = extractName (N);
1074
1081
// KRYSTIAN NOTE: Decl::isParameterPack
1075
1082
// returns true for function parameter packs
1076
- TP ->IsParameterPack =
1083
+ I ->IsParameterPack =
1077
1084
N->isTemplateParameterPack ();
1078
-
1079
- return TP;
1080
1085
}
1081
1086
1082
1087
void
1083
1088
buildTemplateParams (
1084
- TemplateInfo& I ,
1089
+ TemplateInfo& TI ,
1085
1090
const TemplateParameterList* TPL)
1086
1091
{
1087
- for (const NamedDecl* ND : * TPL)
1092
+ for (std:: size_t I = 0 ; I < TPL-> size (); ++I )
1088
1093
{
1089
- I.Params .emplace_back (
1090
- buildTemplateParam (ND));
1094
+ auto & PI = I < TI.Params .size () ?
1095
+ TI.Params [I] : TI.Params .emplace_back ();
1096
+ buildTemplateParam (PI, TPL->getParam (I));
1091
1097
}
1092
1098
}
1093
1099
@@ -2049,15 +2055,12 @@ class ASTVisitor
2049
2055
2050
2056
for (const ParmVarDecl* P : D->parameters ())
2051
2057
{
2052
- auto index = P->getFunctionScopeIndex ();
2053
- Param& param = index < I.Params .size () ?
2054
- I.Params [index ] : I.Params .emplace_back ();
2055
- // KRYSTIAN NOTE: it's not clear what the correct thing
2056
- // to do here is. this will use the longest name seen
2057
- // in any redeclaration
2058
- if (std::string_view name = P->getName ();
2059
- name.size () > param.Name .size ())
2060
- param.Name = name;
2058
+ Param& param = created ?
2059
+ I.Params .emplace_back () :
2060
+ I.Params [P->getFunctionScopeIndex ()];
2061
+
2062
+ if (param.Name .empty ())
2063
+ param.Name = P->getName ();
2061
2064
2062
2065
if (! param.Type )
2063
2066
param.Type = buildTypeInfo (P->getOriginalType ());
@@ -2693,13 +2696,14 @@ traverse(
2693
2696
// explicit specialization, and the described template otherwise
2694
2697
if (CTD)
2695
2698
{
2696
- auto & Template = I.Template = std::make_unique<TemplateInfo>();
2699
+ if (! I.Template )
2700
+ I.Template = std::make_unique<TemplateInfo>();
2697
2701
// if D is a partial/explicit specialization, extract the template arguments
2698
2702
if (auto * CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
2699
2703
{
2700
- extractSymbolID (getInstantiatedFrom (CTD), Template->Primary );
2704
+ extractSymbolID (getInstantiatedFrom (CTD), I. Template ->Primary );
2701
2705
// extract the template arguments of the specialization
2702
- buildTemplateArgs (Template->Args , CTSD->getTemplateArgsAsWritten ());
2706
+ buildTemplateArgs (I. Template ->Args , CTSD->getTemplateArgsAsWritten ());
2703
2707
// extract the template parameters if this is a partial specialization
2704
2708
if (auto * CTPSD = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
2705
2709
buildTemplateParams (*I.Template , CTPSD->getTemplateParameters ());
@@ -2730,13 +2734,14 @@ traverse(
2730
2734
// explicit specialization, and the described template otherwise
2731
2735
if (VTD)
2732
2736
{
2733
- auto & Template = I.Template = std::make_unique<TemplateInfo>();
2737
+ if (! I.Template )
2738
+ I.Template = std::make_unique<TemplateInfo>();
2734
2739
// if D is a partial/explicit specialization, extract the template arguments
2735
2740
if (auto * VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
2736
2741
{
2737
- extractSymbolID (getInstantiatedFrom (VTD), Template->Primary );
2742
+ extractSymbolID (getInstantiatedFrom (VTD), I. Template ->Primary );
2738
2743
// extract the template arguments of the specialization
2739
- buildTemplateArgs (Template->Args , VTSD->getTemplateArgsAsWritten ());
2744
+ buildTemplateArgs (I. Template ->Args , VTSD->getTemplateArgsAsWritten ());
2740
2745
// extract the template parameters if this is a partial specialization
2741
2746
if (auto * VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(D))
2742
2747
buildTemplateParams (*I.Template , VTPSD->getTemplateParameters ());
@@ -2764,8 +2769,9 @@ traverse(
2764
2769
// D is the templated declaration if FTD is non-null
2765
2770
if (FTD)
2766
2771
{
2767
- auto & Template = I.Template = std::make_unique<TemplateInfo>();
2768
- buildTemplateParams (*Template, FTD->getTemplateParameters ());
2772
+ if (! I.Template )
2773
+ I.Template = std::make_unique<TemplateInfo>();
2774
+ buildTemplateParams (*I.Template , FTD->getTemplateParameters ());
2769
2775
}
2770
2776
2771
2777
buildGuide (I, created, D);
@@ -2785,31 +2791,32 @@ traverse(
2785
2791
// D is the templated declaration if FTD is non-null
2786
2792
if (FTD || D->isFunctionTemplateSpecialization ())
2787
2793
{
2788
- auto & Template = I.Template = std::make_unique<TemplateInfo>();
2794
+ if (! I.Template )
2795
+ I.Template = std::make_unique<TemplateInfo>();
2789
2796
2790
2797
if (auto * FTSI = D->getTemplateSpecializationInfo ())
2791
2798
{
2792
2799
extractSymbolID (getInstantiatedFrom (
2793
- FTSI->getTemplate ()), Template->Primary );
2800
+ FTSI->getTemplate ()), I. Template ->Primary );
2794
2801
// TemplateArguments is used instead of TemplateArgumentsAsWritten
2795
2802
// because explicit specializations of function templates may have
2796
2803
// template arguments deduced from their return type and parameters
2797
2804
if (auto * Args = FTSI->TemplateArguments )
2798
- buildTemplateArgs (Template->Args , Args->asArray ());
2805
+ buildTemplateArgs (I. Template ->Args , Args->asArray ());
2799
2806
}
2800
2807
else if (auto * DFTSI = D->getDependentSpecializationInfo ())
2801
2808
{
2802
2809
// Only extract the ID of the primary template if there is
2803
2810
// a single candidate primary template.
2804
2811
if (auto Candidates = DFTSI->getCandidates (); Candidates.size () == 1 )
2805
2812
extractSymbolID (getInstantiatedFrom (
2806
- Candidates.front ()), Template->Primary );
2813
+ Candidates.front ()), I. Template ->Primary );
2807
2814
if (auto * Args = DFTSI->TemplateArgumentsAsWritten )
2808
- buildTemplateArgs (Template->Args , Args);
2815
+ buildTemplateArgs (I. Template ->Args , Args);
2809
2816
}
2810
2817
else
2811
2818
{
2812
- buildTemplateParams (*Template, FTD->getTemplateParameters ());
2819
+ buildTemplateParams (*I. Template , FTD->getTemplateParameters ());
2813
2820
}
2814
2821
}
2815
2822
@@ -2835,7 +2842,8 @@ traverse(
2835
2842
2836
2843
if (ATD)
2837
2844
{
2838
- I.Template = std::make_unique<TemplateInfo>();
2845
+ if (! I.Template )
2846
+ I.Template = std::make_unique<TemplateInfo>();
2839
2847
buildTemplateParams (*I.Template ,
2840
2848
ATD->getTemplateParameters ());
2841
2849
}
0 commit comments