1
2
3
4
5
6 #ifndef CMAJOR_BINDER_FUNCTION_TEMPLATE_REPOSITORY_INCLUDED
7 #define CMAJOR_BINDER_FUNCTION_TEMPLATE_REPOSITORY_INCLUDED
8 #include <cmajor/symbols/FunctionSymbol.hpp>
9
10 namespace cmajor { namespace binder {
11
12 using namespace cmajor::symbols;
13
14 class BoundCompileUnit;
15
16 struct FunctionTemplateKey
17 {
18 FunctionTemplateKey(FunctionSymbol* functionTemplate_, const std::std::vector<TypeSymbol*>&templateArgumentTypes_):functionTemplate(functionTemplate_), templateArgumentTypes(templateArgumentTypes_)
19 {
20 }
21 FunctionSymbol* functionTemplate;
22 std::vector<TypeSymbol*> templateArgumentTypes;
23 };
24
25 bool operator==(const FunctionTemplateKey& left, const FunctionTemplateKey& right);
26 bool operator!=(const FunctionTemplateKey& left, const FunctionTemplateKey& right);
27
28 struct FunctionTemplateKeyHash
29 {
30 size_t operator()(const FunctionTemplateKey& key) const
31 {
32 size_t x = std::hash<FunctionSymbol*>()(key.functionTemplate);
33 int n = key.templateArgumentTypes.size();
34 for (int i = 0; i < n; ++i)
35 {
36 x = x ^ std::hash<TypeSymbol*>()(key.templateArgumentTypes[i]);
37 }
38 return x;
39 }
40 };
41
42 class FunctionTemplateRepository
43 {
44 public:
45 FunctionTemplateRepository(BoundCompileUnit& boundCompileUnit_);
46 FunctionSymbol* Instantiate(FunctionSymbol* functionTemplate, const std::std::unordered_map<TemplateParameterSymbol*, TypeSymbol*>&templateParameterMapping, constSpan&span, constboost::uuids::uuid&moduleId);
47 private:
48 BoundCompileUnit& boundCompileUnit;
49 std::unordered_map<FunctionTemplateKey, FunctionSymbol*, FunctionTemplateKeyHash> functionTemplateMap;
50 };
51
52 } }
53
54 #endif // CMAJOR_BINDER_FUNCTION_TEMPLATE_REPOSITORY_INCLUDED