Yume
substitution.cpp
Go to the documentation of this file.
1#include "ty/substitution.hpp"
2#include "ty/type.hpp"
3#include <stdexcept>
4#include <variant>
5
6namespace yume {
8 auto iter = std::ranges::find(m_keys, generic);
9
10 if (iter == m_keys.end())
11 return nullptr;
12
13 return &m_values.at(std::distance(m_keys.begin(), iter));
14}
15
17 auto iter = std::ranges::find(m_keys, generic);
18
19 if (iter == m_keys.end())
20 return nullptr;
21
22 return &m_values.at(std::distance(m_keys.begin(), iter));
23}
24
25auto Substitutions::type_mappings() const -> std::map<string, ty::Type> {
26 auto mapping = std::map<string, ty::Type>{};
27
28 for (const auto& [k, v] : llvm::zip(m_keys, m_values))
29 if (k.holds_type() && !v.unassigned())
30 mapping.insert_or_assign(k.name, v.as_type());
31
32 return mapping;
33}
34auto Substitutions::get_generic_fallback(string_view generic_name) const -> ty::Generic* {
35 auto iter = std::ranges::find(m_generic_type_fallbacks, generic_name, &ty::Generic::name);
36
37 if (iter == m_generic_type_fallbacks.end())
38 return nullptr;
39
40 return *iter;
41}
42} // namespace yume
An unsubstituted generic type variable, usually something like T.
Definition: type.hpp:178
auto name() const -> string override
Definition: type.hpp:181
Definition: ast.cpp:8
T nullable
Definition: util.hpp:72
auto get_generic_fallback(string_view generic_name) const -> ty::Generic *
auto mapping_ref_or_null(const GenericKey &generic) -> nullable< GenericValue * >
Definition: substitution.cpp:7
auto type_mappings() const -> std::map< string, ty::Type >