Appearance
| 1 | namespace Semantic.Types is | |
| 2 | use System.Text.StringBuilder; | |
| 3 | ||
| 4 | use Source; | |
| 5 | ||
| 6 | class GenericArgument: NAMED abstract is | |
| 7 | is_wild: bool => true; | |
| 8 | is_function_generic_argument: bool => false; | |
| 9 | is_classy_generic_argument: bool => false; | |
| 10 | ||
| 11 | init(symbol: Symbols.Symbol) is | |
| 12 | super.init(symbol); | |
| 13 | si | |
| 14 | ||
| 15 | get_type_arguments_into(results: Collections.LIST[GenericArgument]) is | |
| 16 | results.add(self); | |
| 17 | si | |
| 18 | ||
| 19 | freeze() -> Type? is | |
| 20 | let frozen = symbol.freeze(); | |
| 21 | ||
| 22 | if !frozen? then | |
| 23 | return null; | |
| 24 | fi | |
| 25 | ||
| 26 | return frozen.type; | |
| 27 | si | |
| 28 | ||
| 29 | specialize(type_map: Collections.Map[string,Type]) -> Type is | |
| 30 | let result: Type mut; | |
| 31 | ||
| 32 | if type_map.try_get_value(name, result ref) then | |
| 33 | // A `T?` keeps its nullability across substitution. | |
| 34 | if is_optional then | |
| 35 | return result.as_optional(); | |
| 36 | else | |
| 37 | return result; | |
| 38 | fi | |
| 39 | fi | |
| 40 | ||
| 41 | return self; | |
| 42 | si | |
| 43 | ||
| 44 | bind_type_variables(other: Type, results: GENERIC_ARGUMENT_BIND_RESULTS) -> bool => | |
| 45 | results.bind(self, other); | |
| 46 | ||
| 47 | gen_class_name(buffer: System.Text.StringBuilder) is | |
| 48 | symbol.gen_class_name(buffer); | |
| 49 | si | |
| 50 | ||
| 51 | gen_type(buffer: System.Text.StringBuilder) is | |
| 52 | symbol.gen_type(buffer); | |
| 53 | si | |
| 54 | ||
| 55 | to_string() -> string => | |
| 56 | if is_optional then | |
| 57 | "{symbol.name}?"; | |
| 58 | else | |
| 59 | symbol.name; | |
| 60 | fi; | |
| 61 | si | |
| 62 | ||
| 63 | // TODO can get is classy vs is function from underlying symbol, | |
| 64 | // delete these sub-classes and go back to having just | |
| 65 | // one class representing a generic argument type | |
| 66 | class CLASSY_GENERIC_ARGUMENT: GenericArgument is | |
| 67 | is_classy_generic_argument: bool => true; | |
| 68 | ||
| 69 | init(symbol: Symbols.Symbol) is | |
| 70 | super.init(symbol); | |
| 71 | si | |
| 72 | si | |
| 73 | ||
| 74 | class FUNCTION_GENERIC_ARGUMENT: GenericArgument is | |
| 75 | is_function_generic_argument: bool => true; | |
| 76 | ||
| 77 | init(symbol: Symbols.Symbol) is | |
| 78 | super.init(symbol); | |
| 79 | si | |
| 80 | si | |
| 81 | si |