Appearance
| 1 | namespace Syntax.Process is | |
| 2 | ||
| 3 | use Logging | |
| 4 | use Trees | |
| 5 | use Source | |
| 6 | ||
| 7 | class RESOLVE_OVERRIDES: ScopedVisitor is | |
| 8 | _logger: Logger | |
| 9 | _symbol_table: Semantic.SYMBOL_TABLE | |
| 10 | ||
| 11 | _done_object: bool | |
| 12 | ||
| 13 | _duplicate_method_checker: Semantic.DUPLICATE_METHOD_CHECKER | |
| 14 | ||
| 15 | init( | |
| 16 | logger: Logger, | |
| 17 | symbol_table: Semantic.SYMBOL_TABLE, | |
| 18 | namespaces: Semantic.NAMESPACES | |
| 19 | ) | |
| 20 | is | |
| 21 | super.init(logger, symbol_table, namespaces) | |
| 22 | ||
| 23 | _logger = logger | |
| 24 | _symbol_table = symbol_table | |
| 25 | ||
| 26 | _duplicate_method_checker = Semantic.DUPLICATE_METHOD_CHECKER(logger) | |
| 27 | si | |
| 28 | ||
| 29 | apply(root: Trees.Node) is | |
| 30 | // FIXME: this isn't needed | |
| 31 | if !_done_object then | |
| 32 | let lookup = IoC.CONTAINER.instance.innate_symbol_lookup | |
| 33 | ||
| 34 | lookup.get_object_type().symbol.pull_down_super_symbols() | |
| 35 | lookup.get_value_type().symbol.pull_down_super_symbols() | |
| 36 | ||
| 37 | // An array family the compiler constructs has no declaration | |
| 38 | // of its own to visit; the members a library gives it in a | |
| 39 | // `partial` block override what its ancestors declare. | |
| 40 | if | |
| 41 | let array_generic = cast Semantic.Symbols.GENERIC?(lookup.get_array_type(lookup.get_int_type()).symbol), | |
| 42 | array = cast Semantic.Symbols.Classy?(array_generic.unspecialized_symbol) /\ | |
| 43 | !array.is_reflected | |
| 44 | then | |
| 45 | array.pull_down_super_symbols() | |
| 46 | fi | |
| 47 | ||
| 48 | // So has the string type, where a library declares it. | |
| 49 | if let string = cast Semantic.Symbols.Classy?(lookup.get_string_type().symbol) /\ !string.is_reflected then | |
| 50 | string.pull_down_super_symbols() | |
| 51 | fi | |
| 52 | ||
| 53 | // So have the scalar types, where a library declares them, | |
| 54 | // which inherit what the root declares as any struct does. | |
| 55 | let scalars = [ | |
| 56 | lookup.get_bool_type(), lookup.get_char_type(), | |
| 57 | lookup.get_byte_type(), lookup.get_ubyte_type(), | |
| 58 | lookup.get_short_type(), lookup.get_ushort_type(), | |
| 59 | lookup.get_int_type(), lookup.get_uint_type(), | |
| 60 | lookup.get_long_type(), lookup.get_ulong_type(), | |
| 61 | lookup.get_word_type(), lookup.get_uword_type(), | |
| 62 | lookup.get_single_type(), lookup.get_double_type() | |
| 63 | ] | |
| 64 | ||
| 65 | for scalar in scalars do | |
| 66 | if let declared = cast Semantic.Symbols.Classy?(scalar.symbol) /\ !declared.is_reflected then | |
| 67 | declared.pull_down_super_symbols() | |
| 68 | fi | |
| 69 | od | |
| 70 | ||
| 71 | // And bigint, and the tuple families, whose members a library | |
| 72 | // gives them in `partial` blocks override what `object` | |
| 73 | // declares, as a scalar's do. | |
| 74 | if let declared = cast Semantic.Symbols.Classy?(lookup.get_bigint_type().symbol) /\ !declared.is_reflected then | |
| 75 | declared.pull_down_super_symbols() | |
| 76 | fi | |
| 77 | ||
| 78 | for arity in 1::7 do | |
| 79 | let elements = Collections.LIST[Semantic.Types.Type]() | |
| 80 | ||
| 81 | for _ in 1::arity do | |
| 82 | elements.add(lookup.get_int_type()) | |
| 83 | od | |
| 84 | ||
| 85 | if | |
| 86 | let generic = cast Semantic.Symbols.GENERIC?(lookup.get_tuple_type(elements, null).symbol), | |
| 87 | family = cast Semantic.Symbols.Classy?(generic.unspecialized_symbol) /\ | |
| 88 | !family.is_reflected | |
| 89 | then | |
| 90 | family.pull_down_super_symbols() | |
| 91 | fi | |
| 92 | od | |
| 93 | ||
| 94 | _done_object = true | |
| 95 | fi | |
| 96 | ||
| 97 | root.walk(self) | |
| 98 | si | |
| 99 | ||
| 100 | check_duplicate_global_functions() is | |
| 101 | for ns in _namespaces do | |
| 102 | try | |
| 103 | _duplicate_method_checker.check(ns, "duplicate function") | |
| 104 | catch e: System.Exception | |
| 105 | _logger.exception(ns.location, e, "exception checking for duplicate global functions") | |
| 106 | yrt | |
| 107 | od | |
| 108 | si | |
| 109 | ||
| 110 | pre(`class: Trees.Definitions.CLASS) -> bool => true | |
| 111 | ||
| 112 | visit(`class: Definitions.CLASS) is | |
| 113 | let symbol = symbol_for(`class) | |
| 114 | ||
| 115 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 116 | _duplicate_method_checker.check(symbol, "duplicate method") | |
| 117 | ||
| 118 | symbol.pull_down_super_symbols() | |
| 119 | ||
| 120 | Semantic.Symbols.STATIC_INTERFACE_IMPLEMENTATION_CHECKER(_logger).check(symbol) | |
| 121 | fi | |
| 122 | si | |
| 123 | ||
| 124 | pre(`trait: Trees.Definitions.TRAIT) -> bool => true | |
| 125 | ||
| 126 | visit(`trait: Definitions.TRAIT) is | |
| 127 | let symbol = symbol_for(`trait) | |
| 128 | ||
| 129 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 130 | _duplicate_method_checker.check(symbol, "duplicate method") | |
| 131 | ||
| 132 | symbol.pull_down_super_symbols() | |
| 133 | ||
| 134 | Semantic.Symbols.VARIANCE_POSITION_CHECKER(symbol, _logger).check() | |
| 135 | fi | |
| 136 | si | |
| 137 | ||
| 138 | pre(`struct: Trees.Definitions.STRUCT) -> bool => true | |
| 139 | ||
| 140 | visit(`struct: Definitions.STRUCT) is | |
| 141 | let symbol = symbol_for(`struct) | |
| 142 | ||
| 143 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 144 | symbol.pull_down_super_symbols() | |
| 145 | ||
| 146 | Semantic.Symbols.STATIC_INTERFACE_IMPLEMENTATION_CHECKER(_logger).check(symbol) | |
| 147 | fi | |
| 148 | si | |
| 149 | ||
| 150 | // Walk into the union body so variants get visited (their | |
| 151 | // `pull_down_super_symbols()` runs in `visit(variant)` below). | |
| 152 | // Without this, variants never have inherited members like | |
| 153 | // `to_string` pulled into their scope, so member lookup on a | |
| 154 | // variant type misses anything inherited via the union from | |
| 155 | // `object`. | |
| 156 | pre(`union: Trees.Definitions.UNION) -> bool => false | |
| 157 | ||
| 158 | visit(`union: Definitions.UNION) is | |
| 159 | let symbol = symbol_for(`union) | |
| 160 | ||
| 161 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 162 | symbol.pull_down_super_symbols() | |
| 163 | fi | |
| 164 | si | |
| 165 | ||
| 166 | pre(variant: Trees.Definitions.VARIANT) -> bool => true | |
| 167 | ||
| 168 | visit(variant: Definitions.VARIANT) is | |
| 169 | let symbol = symbol_for(variant) | |
| 170 | ||
| 171 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 172 | symbol.pull_down_super_symbols() | |
| 173 | fi | |
| 174 | si | |
| 175 | ||
| 176 | pre(`enum: Trees.Definitions.ENUM) -> bool => true | |
| 177 | ||
| 178 | visit(`enum: Definitions.ENUM) is | |
| 179 | let symbol = symbol_for(`enum) | |
| 180 | ||
| 181 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 182 | symbol.pull_down_super_symbols() | |
| 183 | fi | |
| 184 | si | |
| 185 | si | |
| 186 | si |