Skip to content

Commit dc850fa

Browse files
committed
fix(parse): add pretty_print_visualize for specialization template arguments
1 parent b7b09e6 commit dc850fa

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

regression-tests/pure2-print.cpp2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ outer: @print type = {
9999

100100
}
101101

102+
std: namespace = {
103+
common_type: @struct @print specialize<outer, outer> type = {
104+
type: type == outer;
105+
}
106+
numbers: namespace = {
107+
pi_v: /*@print*/ specialize<outer> const double = pi_v<double>;
108+
}
109+
}
110+
102111
main: () = {
103112
outer::test();
104113
}

regression-tests/test-results/pure2-print.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
#line 4 "pure2-print.cpp2"
1111
class outer;
1212

13+
#line 102 "pure2-print.cpp2"
14+
namespace std {
15+
16+
#line 106 "pure2-print.cpp2"
17+
namespace numbers {
18+
19+
}
20+
}
21+
1322

1423
//=== Cpp2 type definitions and function declarations ===========================
1524

@@ -84,6 +93,15 @@ CPP2_REQUIRES_ (cpp2::cmp_greater_eq(sizeof(Args)...,0))
8493
#line 100 "pure2-print.cpp2"
8594
};
8695

96+
namespace std {
97+
template<> class common_type<outer,outer> {
98+
public: using type = outer;
99+
};
100+
namespace numbers {
101+
/*@print*/
102+
}
103+
}
104+
87105
auto main() -> int;
88106

89107

@@ -200,6 +218,14 @@ requires (cpp2::cmp_greater_eq(sizeof(Args)...,0))
200218
return (... && args); }
201219

202220
#line 102 "pure2-print.cpp2"
221+
namespace std {
222+
223+
#line 106 "pure2-print.cpp2"
224+
namespace numbers {
225+
template<> double const pi_v<outer> {pi_v<double>};
226+
}
227+
}
228+
203229
auto main() -> int{
204230
outer::test();
205231
}

regression-tests/test-results/pure2-print.cpp2.output

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,11 @@ outer: type =
146146

147147
all: <Args...: type>(in args...: Args) -> move bool = (... && args);
148148
}
149+
150+
151+
common_type: specialize<outer, outer> type =
152+
{
153+
public type: type == outer;
154+
}
149155
ok (all Cpp2, passes safety checks)
150156

source/parse.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4748,6 +4748,11 @@ auto pretty_print_visualize(declaration_node const& n, int indent, bool include_
47484748
template_params += " " + pretty_print_visualize(*n.template_parameters, indent + 1, true);
47494749
}
47504750

4751+
auto specialization_params = std::string{};
4752+
if (n.specialization_template_arguments) {
4753+
specialization_params += " " + pretty_print_visualize(*n.specialization_template_arguments, indent + 1);
4754+
}
4755+
47514756
auto requires_clause = std::string{};
47524757
if (n.requires_clause_expression) {
47534758
requires_clause += " requires (" + pretty_print_visualize(*n.requires_clause_expression, indent) + ")";
@@ -4832,7 +4837,8 @@ auto pretty_print_visualize(declaration_node const& n, int indent, bool include_
48324837
auto& type_id = std::get<declaration_node::an_object>(n.type);
48334838
assert(type_id);
48344839
ret += metafunctions
4835-
+ template_params;
4840+
+ template_params
4841+
+ specialization_params;
48364842
if (!n.has_wildcard_type()) {
48374843
ret += " " + pretty_print_visualize(*type_id, indent);
48384844
}
@@ -4844,6 +4850,7 @@ auto pretty_print_visualize(declaration_node const& n, int indent, bool include_
48444850
assert(t);
48454851
ret += metafunctions
48464852
+ template_params
4853+
+ specialization_params
48474854
+ " " + pretty_print_visualize(*t)
48484855
+ initializer;
48494856
}

0 commit comments

Comments
 (0)