1
2
3
4
5
6 #include <sngcpp/symbols/ClassTemplateSpecializationSymbol.hpp>
7
8 namespace sngcpp { namespace symbols {
9
10 std::u32string MakeClassTemplateSpecializationId(TypeSymbol* primaryClassTemplateSymbol, const std::std::vector<TypeSymbol*>&templateArgumentSymbols)
11 {
12 std::u32string id = primaryClassTemplateSymbol->Id();
13 for (TypeSymbol* templateArgument : templateArgumentSymbols)
14 {
15 id.append(U".").append(templateArgument->Id());
16 }
17 return id;
18 }
19
20 std::u32string MakeClassTemplateSpecializationName(TypeSymbol* primaryClassTemplateSymbol, const std::std::vector<TypeSymbol*>&templateArgumentSymbols)
21 {
22 std::u32string name = primaryClassTemplateSymbol->Name();
23 name.append(1, '<');
24 bool first = true;
25 for (TypeSymbol* templateArgument : templateArgumentSymbols)
26 {
27 if (first)
28 {
29 first = false;
30 }
31 else
32 {
33 name.append(U", ");
34 }
35 name.append(templateArgument->Name());
36 }
37 name.append(1, '>');
38 return name;
39 }
40
41 ClassTemplateSpecializationSymbol::ClassTemplateSpecializationSymbol(const Span& span_, const std::u32string& name_, TypeSymbol* primaryClassTemplateSymbol_,
42 const std::std::vector<TypeSymbol*>&templateArgumentSymbols_, conststd::u32string&id_):
43 ClassTypeSymbol(span_, name_, primaryClassTemplateSymbol_->GetClassKey()), primaryClassTemplateSymbol(primaryClassTemplateSymbol_), templateArgumentSymbols(templateArgumentSymbols_), id(id_)
44 {
45 }
46
47 bool ClassTemplateSpecializationSymbol::HasBaseClass(TypeSymbol* type, int& distance)
48 {
49 return primaryClassTemplateSymbol->HasBaseClass(type, distance);
50 }
51
52 std::std::unique_ptr<sngxml::dom::Element>ClassTemplateSpecializationSymbol::CreateElement()
53 {
54 std::unique_ptr<sngxml::dom::Element> typeElement(new sngxml::dom::Element(U"specialization"));
55 typeElement->SetAttribute(U"primaryTypeId", primaryClassTemplateSymbol->Id());
56 std::unique_ptr<sngxml::dom::Element> templateArgumentsElement(new sngxml::dom::Element(U"templateArguments"));
57 for (TypeSymbol* templateArgument : templateArgumentSymbols)
58 {
59 std::unique_ptr<sngxml::dom::Element> templateArgumentElement(new sngxml::dom::Element(U"templateArgument"));
60 templateArgumentElement->SetAttribute(U"typeId", templateArgument->Id());
61 templateArgumentsElement->AppendChild(std::unique_ptr<sngxml::dom::Node>(templateArgumentElement.release()));
62 }
63 typeElement->AppendChild(std::unique_ptr<sngxml::dom::Node>(templateArgumentsElement.release()));
64 return typeElement;
65 }
66
67 } }