8 #include "src/torque/declarable.h" 14 DEFINE_CONTEXTUAL_VARIABLE(CurrentScope);
16 std::ostream& operator<<(std::ostream& os,
const QualifiedName& name) {
18 for (
const std::string& qualifier : name.namespace_qualification) {
25 return os << name.name;
28 std::ostream& operator<<(std::ostream& os,
const Callable& m) {
29 os <<
"callable " << m.ReadableName() <<
"(";
30 if (m.signature().implicit_count != 0) {
32 TypeVector implicit_parameter_types(
33 m.signature().parameter_types.types.begin(),
34 m.signature().parameter_types.types.begin() +
35 m.signature().implicit_count);
36 os << implicit_parameter_types <<
")(";
37 TypeVector explicit_parameter_types(
38 m.signature().parameter_types.types.begin() +
39 m.signature().implicit_count,
40 m.signature().parameter_types.types.end());
41 os << explicit_parameter_types;
43 os << m.signature().parameter_types;
45 os <<
"): " << *m.signature().return_type;
49 std::ostream& operator<<(std::ostream& os,
const Builtin& b) {
50 os <<
"builtin " << *b.signature().return_type <<
" " << b.ReadableName()
51 << b.signature().parameter_types;
55 std::ostream& operator<<(std::ostream& os,
const RuntimeFunction& b) {
56 os <<
"runtime function " << *b.signature().return_type <<
" " 57 << b.ReadableName() << b.signature().parameter_types;
61 std::ostream& operator<<(std::ostream& os,
const Generic& g) {
62 os <<
"generic " << g.name() <<
"<";
63 PrintCommaSeparatedList(os, g.declaration()->generic_parameters);
69 base::Optional<const Type*> Generic::InferTypeArgument(
70 size_t i,
const TypeVector& arguments) {
71 const std::string type_name = declaration()->generic_parameters[
i];
72 const std::vector<TypeExpression*>& parameters =
73 declaration()->callable->signature->parameters.types;
74 size_t j = declaration()->callable->signature->parameters.implicit_count;
75 for (
size_t i = 0;
i < arguments.size() && j < parameters.size(); ++
i, ++j) {
76 BasicTypeExpression* basic =
77 BasicTypeExpression::DynamicCast(parameters[j]);
78 if (basic && basic->namespace_qualification.empty() &&
79 !basic->is_constexpr && basic->name == type_name) {
86 base::Optional<TypeVector> Generic::InferSpecializationTypes(
87 const TypeVector& explicit_specialization_types,
88 const TypeVector& arguments) {
89 TypeVector result = explicit_specialization_types;
90 size_t type_parameter_count = declaration()->generic_parameters.size();
91 if (explicit_specialization_types.size() > type_parameter_count) {
94 for (
size_t i = explicit_specialization_types.size();
95 i < type_parameter_count; ++
i) {
96 base::Optional<const Type*> inferred = InferTypeArgument(
i, arguments);
97 if (!inferred)
return base::nullopt;
98 result.push_back(*inferred);