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 | _done_object = true; | |
| 38 | fi | |
| 39 | ||
| 40 | root.walk(self); | |
| 41 | si | |
| 42 | ||
| 43 | check_duplicate_global_functions() is | |
| 44 | for ns in _namespaces do | |
| 45 | try | |
| 46 | _duplicate_method_checker.check(ns, "duplicate function"); | |
| 47 | catch e: System.Exception | |
| 48 | _logger.exception(ns.location, e, "exception checking for duplicate global functions"); | |
| 49 | yrt | |
| 50 | od | |
| 51 | si | |
| 52 | ||
| 53 | pre(`class: Trees.Definitions.CLASS) -> bool => true; | |
| 54 | ||
| 55 | visit(`class: Definitions.CLASS) is | |
| 56 | let symbol = symbol_for(`class); | |
| 57 | ||
| 58 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 59 | _duplicate_method_checker.check(symbol, "duplicate method"); | |
| 60 | ||
| 61 | symbol.pull_down_super_symbols(); | |
| 62 | fi | |
| 63 | si | |
| 64 | ||
| 65 | pre(`trait: Trees.Definitions.TRAIT) -> bool => true; | |
| 66 | ||
| 67 | visit(`trait: Definitions.TRAIT) is | |
| 68 | let symbol = symbol_for(`trait); | |
| 69 | ||
| 70 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 71 | _duplicate_method_checker.check(symbol, "duplicate method"); | |
| 72 | ||
| 73 | symbol.pull_down_super_symbols(); | |
| 74 | ||
| 75 | Semantic.Symbols.VARIANCE_POSITION_CHECKER(symbol, _logger).check(); | |
| 76 | fi | |
| 77 | si | |
| 78 | ||
| 79 | pre(`struct: Trees.Definitions.STRUCT) -> bool => true; | |
| 80 | ||
| 81 | visit(`struct: Definitions.STRUCT) is | |
| 82 | let symbol = symbol_for(`struct); | |
| 83 | ||
| 84 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 85 | symbol.pull_down_super_symbols(); | |
| 86 | fi | |
| 87 | si | |
| 88 | ||
| 89 | // Walk into the union body so variants get visited (their | |
| 90 | // `pull_down_super_symbols()` runs in `visit(variant)` below). | |
| 91 | // Without this, variants never have inherited members like | |
| 92 | // `to_string` pulled into their scope, so member lookup on a | |
| 93 | // variant type misses anything inherited via the union from | |
| 94 | // `object`. | |
| 95 | pre(`union: Trees.Definitions.UNION) -> bool => false; | |
| 96 | ||
| 97 | visit(`union: Definitions.UNION) is | |
| 98 | let symbol = symbol_for(`union); | |
| 99 | ||
| 100 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 101 | symbol.pull_down_super_symbols(); | |
| 102 | fi | |
| 103 | si | |
| 104 | ||
| 105 | pre(variant: Trees.Definitions.VARIANT) -> bool => true; | |
| 106 | ||
| 107 | visit(variant: Definitions.VARIANT) is | |
| 108 | let symbol = symbol_for(variant); | |
| 109 | ||
| 110 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 111 | symbol.pull_down_super_symbols(); | |
| 112 | fi | |
| 113 | si | |
| 114 | ||
| 115 | pre(`enum: Trees.Definitions.ENUM) -> bool => true; | |
| 116 | ||
| 117 | visit(`enum: Definitions.ENUM) is | |
| 118 | let symbol = symbol_for(`enum); | |
| 119 | ||
| 120 | if symbol? /\ isa Semantic.Symbols.Classy(symbol) then | |
| 121 | symbol.pull_down_super_symbols(); | |
| 122 | fi | |
| 123 | si | |
| 124 | si | |
| 125 | si |