Appearance
| 1 | namespace Semantic is | |
| 2 | use System.NotImplementedException; | |
| 3 | ||
| 4 | use IoC; | |
| 5 | use Logging; | |
| 6 | use Source; | |
| 7 | ||
| 8 | use Types.Type; | |
| 9 | use Symbols.Symbol; | |
| 10 | ||
| 11 | class BLOCK_SCOPE: Scope, DeclarationContext is | |
| 12 | _enclosing: Scope?; | |
| 13 | _symbols: Semantic.SYMBOL_STORE; | |
| 14 | ||
| 15 | name: string => "[block]"; | |
| 16 | qualified_name: string => | |
| 17 | if let self._enclosing? then | |
| 18 | "{_enclosing.qualified_name}.[block]" | |
| 19 | else | |
| 20 | "[block]" | |
| 21 | fi; | |
| 22 | ||
| 23 | symbols: Collections.Iterable[Symbols.Symbol] => _symbols.values; | |
| 24 | ||
| 25 | type: Type => Types.NONE.instance; | |
| 26 | ||
| 27 | unspecialized_symbol: Symbols.Symbol? => null; | |
| 28 | ||
| 29 | init() is | |
| 30 | init(null); | |
| 31 | si | |
| 32 | ||
| 33 | init(enclosing: Scope) is | |
| 34 | _enclosing = enclosing; | |
| 35 | _symbols = Semantic.SYMBOL_STORE(); | |
| 36 | si | |
| 37 | ||
| 38 | qualify(name: string) -> string => | |
| 39 | if let self._enclosing? then | |
| 40 | _enclosing.qualify(name) | |
| 41 | else | |
| 42 | name | |
| 43 | fi; | |
| 44 | ||
| 45 | find_direct(name: string) -> Symbols.Symbol? => | |
| 46 | _symbols[name]; | |
| 47 | ||
| 48 | find_direct_matches(prefix: string, matches: Collections.MutableMap[string,Semantic.Symbols.Symbol]) is | |
| 49 | _symbols.find_matches(prefix, matches); | |
| 50 | si | |
| 51 | ||
| 52 | find_member(name: string) -> Symbols.Symbol? => throw NotImplementedException("cannot search for member {name} in block scope"); | |
| 53 | find_member_matches(prefix: string, matches: Collections.MutableMap[string,Semantic.Symbols.Symbol]) => throw NotImplementedException("cannot search for member matches {prefix} in block scope"); | |
| 54 | find_enclosing(name: string) -> Symbols.Symbol? is | |
| 55 | let result = find_direct(name); | |
| 56 | ||
| 57 | if result? then | |
| 58 | return result; | |
| 59 | elif _enclosing? then | |
| 60 | return _enclosing.find_enclosing(name); | |
| 61 | else | |
| 62 | return null; | |
| 63 | fi | |
| 64 | si | |
| 65 | ||
| 66 | find_enclosing_matches(prefix: string, matches: Collections.MutableMap[string,Semantic.Symbols.Symbol]) is | |
| 67 | find_direct_matches(prefix, matches); | |
| 68 | ||
| 69 | if let self._enclosing? then | |
| 70 | _enclosing.find_enclosing_matches(prefix, matches); | |
| 71 | fi | |
| 72 | si | |
| 73 | ||
| 74 | declare_undefined(location: LOCATION, kind: string, name: string) -> Semantic.Symbols.Symbol is | |
| 75 | CONTAINER.instance.logger.error(location, "cannot declare {kind} here"); | |
| 76 | ||
| 77 | return Symbols.UNDEFINED(location, self, name); | |
| 78 | si | |
| 79 | ||
| 80 | declare_class(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 81 | declare_undefined(location, "class", name); | |
| 82 | ||
| 83 | declare_trait(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 84 | declare_undefined(location, "trait", name); | |
| 85 | ||
| 86 | declare_struct(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 87 | declare_undefined(location, "struct", name); | |
| 88 | ||
| 89 | declare_union(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 90 | declare_undefined(location, "union", name); | |
| 91 | ||
| 92 | declare_variant(location: LOCATION, span: LOCATION, name: string, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 93 | declare_undefined(location, "variant", name); | |
| 94 | ||
| 95 | declare_type(location: LOCATION, name: string, index: int, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 96 | declare_undefined(location, "type", name); | |
| 97 | ||
| 98 | declare_enum(location: LOCATION, span: LOCATION, name: string, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 99 | declare_undefined(location, "enum", name); | |
| 100 | ||
| 101 | declare_enum_member(location: LOCATION, name: string, value: string?, symbol_definition_listener: SymbolDefinitionListener?) is | |
| 102 | declare_undefined(location, "enum member", name); | |
| 103 | si | |
| 104 | ||
| 105 | declare_innate(location: LOCATION, name: string, innate_name: string, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 106 | declare_undefined(location, "innate", name); | |
| 107 | ||
| 108 | declare_function(location: LOCATION, span: LOCATION, name: string, is_static: bool, is_private: bool, has_body: bool, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 109 | declare_undefined(location, "function", name); | |
| 110 | ||
| 111 | declare_generator_function(location: LOCATION, span: LOCATION, name: string, is_static: bool, is_private: bool, has_body: bool, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 112 | declare_undefined(location, "generator function", name); | |
| 113 | ||
| 114 | declare_async_function(location: LOCATION, span: LOCATION, name: string, is_static: bool, is_private: bool, has_body: bool, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 115 | declare_undefined(location, "async function", name); | |
| 116 | ||
| 117 | declare_namespace(location: LOCATION, name: string, `namespace: Symbols.NAMESPACE, symbol_definition_listener: SymbolDefinitionListener?) is | |
| 118 | declare_undefined(location, "namespace", name); | |
| 119 | si | |
| 120 | ||
| 121 | declare_label(location: LOCATION, name: string, symbol_definition_listener: SymbolDefinitionListener?) is | |
| 122 | let label = Symbols.LABEL(location, self, name); | |
| 123 | declare(location, label, symbol_definition_listener); | |
| 124 | si | |
| 125 | ||
| 126 | declare_variable(location: LOCATION, name: string, is_static: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 127 | // FIXME: IoC | |
| 128 | let owner = cast Scope(IoC.CONTAINER.instance.symbol_table.current_capture_context!); | |
| 129 | ||
| 130 | let variable = Symbols.LOCAL_VARIABLE(location, owner, name); | |
| 131 | declare(location, variable, symbol_definition_listener); | |
| 132 | return variable; | |
| 133 | si | |
| 134 | ||
| 135 | declare_closure(location: LOCATION, name: string, owner: Scope, enclosing: Scope, is_recursive: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => declare_undefined(location, "anonymous function", name); | |
| 136 | declare_async_closure(location: LOCATION, name: string, owner: Scope, enclosing: Scope, is_recursive: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => declare_undefined(location, "anonymous async function", name); | |
| 137 | declare_property(location: LOCATION, span: LOCATION, name: string, is_static: bool, is_private: bool, is_assignable: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol => | |
| 138 | declare_undefined(location, "property", name); | |
| 139 | ||
| 140 | declare(location: LOCATION, symbol: Symbols.Symbol, symbol_definition_listener: SymbolDefinitionListener?) is | |
| 141 | let name = symbol.name; | |
| 142 | let existing = find_direct(name); | |
| 143 | ||
| 144 | if existing? then | |
| 145 | CONTAINER.instance.logger.error(location, "redefining symbol {symbol.name} originally defined at {existing.location}"); | |
| 146 | CONTAINER.instance.logger.error(existing.location, "symbol {symbol.name} is redefined at {location}"); | |
| 147 | fi | |
| 148 | ||
| 149 | if symbol_definition_listener? then | |
| 150 | symbol_definition_listener.add_symbol_definition(location, symbol); | |
| 151 | fi | |
| 152 | ||
| 153 | _symbols[name] = symbol; | |
| 154 | si | |
| 155 | ||
| 156 | gen_dot(buffer: System.Text.StringBuilder) is | |
| 157 | buffer.append("."); | |
| 158 | si | |
| 159 | ||
| 160 | gen_dotted_name(buffer: System.Text.StringBuilder, qualifying: Scope) is | |
| 161 | si | |
| 162 | ||
| 163 | gen_type_spec(buffer: System.Text.StringBuilder) => throw System.NotImplementedException("not implemented by {get_type()}"); | |
| 164 | gen_class_name(buffer: System.Text.StringBuilder) => throw System.NotImplementedException("not implemented by {get_type()}"); | |
| 165 | gen_reference(buffer: System.Text.StringBuilder) => throw System.NotImplementedException("not implemented by {get_type()}"); | |
| 166 | gen_type(buffer: System.Text.StringBuilder) => throw System.NotImplementedException("not implemented by {get_type()}"); | |
| 167 | to_string() -> string => | |
| 168 | "{get_type()} {_symbols}"; | |
| 169 | si | |
| 170 | si |