Skip to content

Commit ed5f487

Browse files
committed
Dump variable template specializations
Signed-off-by: Roberto Raggi <[email protected]>
1 parent 68bb271 commit ed5f487

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/parser/cxx/symbol_printer.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,35 @@ struct DumpSymbols {
288288
if (symbol->isConstinit()) out << " constinit";
289289
if (symbol->isInline()) out << " inline";
290290

291-
out << std::format(" {}\n", to_string(symbol->type(), symbol->name()));
291+
out << std::format(" {}", to_string(symbol->type(), symbol->name()));
292+
293+
if (!symbol->templateArguments().empty()) {
294+
out << "<";
295+
std::string_view sep = "";
296+
for (auto arg : symbol->templateArguments()) {
297+
auto symbol = std::get_if<Symbol*>(&arg);
298+
if (!symbol) continue;
299+
auto sym = *symbol;
300+
if (sym->isTypeAlias()) {
301+
out << std::format("{}{}", sep, to_string(sym->type()));
302+
} else if (auto var = symbol_cast<VariableSymbol>(sym)) {
303+
auto cst = std::get<std::intmax_t>(var->constValue().value());
304+
out << std::format("{}{}", sep, cst);
305+
} else {
306+
cxx_runtime_error("todo");
307+
}
308+
sep = ", ";
309+
}
310+
out << std::format(">");
311+
}
312+
313+
out << "\n";
292314

293315
if (symbol->templateParameters()) {
294316
dumpScope(symbol->templateParameters());
295317
}
318+
319+
dumpSpecializations(symbol->specializations());
296320
}
297321

298322
void operator()(FieldSymbol* symbol) {

tests/unit_tests/sema/template_var_01.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ constexpr bool is_integral_v = __is_integral(T);
66
static_assert(is_integral_v<int>);
77
static_assert(is_integral_v<char>);
88
static_assert(is_integral_v<void*> == false);
9+
10+
// clang-format off
11+
// CHECK:namespace
12+
// CHECK-NEXT: template variable constexpr const bool is_integral_v
13+
// CHECK-NEXT: parameter typename<0, 0> T
14+
// CHECK-NEXT: [specializations]
15+
// CHECK-NEXT: variable constexpr bool is_integral_v<int>
16+
// CHECK-NEXT: variable constexpr bool is_integral_v<char>
17+
// CHECK-NEXT: variable constexpr bool is_integral_v<void*>

0 commit comments

Comments
 (0)