Appearance
| 1 | namespace Semantic.Symbols is | |
| 2 | use System.Text.StringBuilder | |
| 3 | ||
| 4 | use Logging | |
| 5 | use Source | |
| 6 | ||
| 7 | use IR.Values.Value | |
| 8 | ||
| 9 | use Types.Type | |
| 10 | ||
| 11 | // FIXME: doesn't really have a type, not sure how to represent this: | |
| 12 | class NAMESPACE: ScopedWithEnclosingScope, NamespaceContext, Types.Typed is | |
| 13 | qualified_name: string | |
| 14 | ||
| 15 | type: Type | |
| 16 | ||
| 17 | short_description: string => "namespace {name}" | |
| 18 | ||
| 19 | describe(context: DESCRIBE_CONTEXT) -> SignaturePart is | |
| 20 | let qn mut = qualified_name | |
| 21 | if qn.starts_with('.') then | |
| 22 | qn = qn.substring(1) | |
| 23 | fi | |
| 24 | return PARTS.literal("namespace {qn}") | |
| 25 | si | |
| 26 | ||
| 27 | symbol_kind: SymbolKind => SymbolKind.NAMESPACE | |
| 28 | completion_kind: CompletionKind => CompletionKind.MODULE | |
| 29 | ||
| 30 | is_namespace: bool => true | |
| 31 | is_classy: bool => false | |
| 32 | is_internal: bool => false | |
| 33 | is_compiler_generated: bool | |
| 34 | ||
| 35 | init( | |
| 36 | location: LOCATION, | |
| 37 | name: string, | |
| 38 | enclosing_scope: Scope?, | |
| 39 | qualified_name: string, | |
| 40 | is_compiler_generated: bool | |
| 41 | ) is | |
| 42 | super.init(location, self, name, enclosing_scope) | |
| 43 | ||
| 44 | self.qualified_name = qualified_name | |
| 45 | self.is_compiler_generated = is_compiler_generated | |
| 46 | ||
| 47 | type = Types.NAMED(self) | |
| 48 | si | |
| 49 | ||
| 50 | qualify(name: string) -> string is | |
| 51 | if is_compiler_generated then | |
| 52 | return name | |
| 53 | fi | |
| 54 | ||
| 55 | let q = qualified_name | |
| 56 | ||
| 57 | if q.length > 1 then | |
| 58 | return "{qualified_name.substring(1)}.{name}" | |
| 59 | fi | |
| 60 | ||
| 61 | return name | |
| 62 | si | |
| 63 | ||
| 64 | find_direct(name: string) -> Symbol? is | |
| 65 | let declared = super.find_direct(name) | |
| 66 | ||
| 67 | // A declaration of any other kind hides whatever an imported | |
| 68 | // assembly contributes under the name; a function joins the | |
| 69 | // imported overloads, as one declared in another file of this | |
| 70 | // compilation would. | |
| 71 | if declared? /\ !isa Function(declared) /\ !isa FUNCTION_GROUP(declared) then | |
| 72 | return declared | |
| 73 | fi | |
| 74 | ||
| 75 | let imported = _find_imported(name) | |
| 76 | ||
| 77 | if !declared? then | |
| 78 | return imported | |
| 79 | elif !imported? then | |
| 80 | return declared | |
| 81 | fi | |
| 82 | ||
| 83 | return DotNet.GLOBAL_OVERLOAD_MERGE.merge([declared, imported]) | |
| 84 | si | |
| 85 | ||
| 86 | _find_imported(name: string) -> Symbol? is | |
| 87 | let dotnet_symbol_table = IoC.CONTAINER.instance.dotnet_symbol_table.value | |
| 88 | ||
| 89 | let qn mut = qualified_name | |
| 90 | ||
| 91 | if qn =~ "." \/ qn.length == 0 then | |
| 92 | return null | |
| 93 | fi | |
| 94 | ||
| 95 | if qn.starts_with(".") then | |
| 96 | qn = qn.substring(1) | |
| 97 | fi | |
| 98 | ||
| 99 | if DotNet.HIDDEN_SYMBOLS.is_hidden_namespace(qn) then | |
| 100 | return null | |
| 101 | fi | |
| 102 | ||
| 103 | let direct = dotnet_symbol_table.get_symbol("{qn}.{name}") | |
| 104 | ||
| 105 | if direct? then | |
| 106 | return direct | |
| 107 | fi | |
| 108 | ||
| 109 | // Globals from a referenced assembly live as static members of | |
| 110 | // a synthetic `$globals` IL class. The .NET importer | |
| 111 | // materialises each one as a GLOBAL_FUNCTION / GLOBAL_VARIABLE / | |
| 112 | // GLOBAL_PROPERTY whose owner is *this* NAMESPACE - matching | |
| 113 | // how source-side globals are declared - but stashes them on | |
| 114 | // the Classy because that lookup-table outlives this | |
| 115 | // NAMESPACE's clear-between-compiles lifecycle. Resolving the | |
| 116 | // carrier name materialises every carrier the namespace has; | |
| 117 | // the member lookup then searches them all. | |
| 118 | let _ = dotnet_symbol_table.get_symbol("{qn}.{DotNet.GLOBALS_CARRIER.name}") | |
| 119 | ||
| 120 | return dotnet_symbol_table.find_global_member(qn, name) | |
| 121 | si | |
| 122 | ||
| 123 | find_member(name: string) -> Symbol? | |
| 124 | => find_direct(name) | |
| 125 | ||
| 126 | find_member_matches(prefix: string, matches: Collections.MutableMap[string, Symbols.Symbol]) is | |
| 127 | find_direct_matches(prefix, matches) | |
| 128 | ||
| 129 | let qn mut = qualified_name | |
| 130 | ||
| 131 | let namespaces = IoC.CONTAINER.instance.namespaces | |
| 132 | let dotnet_symbol_table = IoC.CONTAINER.instance.dotnet_symbol_table.value | |
| 133 | ||
| 134 | if qn =~ "." \/ qn.length == 0 then | |
| 135 | // FIXME: don't think this is ever hit: | |
| 136 | namespaces.find_root_matches(matches) | |
| 137 | dotnet_symbol_table.find_root_matches(matches) | |
| 138 | ||
| 139 | return | |
| 140 | fi | |
| 141 | ||
| 142 | if qn.starts_with(".") then | |
| 143 | qn = qn.substring(1) | |
| 144 | fi | |
| 145 | ||
| 146 | namespaces.find_namespace_matches(qn, matches) | |
| 147 | ||
| 148 | dotnet_symbol_table.find_member_matches(qn, matches) | |
| 149 | ||
| 150 | DotNet.HIDDEN_SYMBOLS.prune_hidden(qn, matches) | |
| 151 | si | |
| 152 | ||
| 153 | declare_namespace(location: LOCATION, name: string, `namespace: Symbols.NAMESPACE, symbol_definition_listener: SymbolDefinitionListener?) is | |
| 154 | declare(location, `namespace, symbol_definition_listener) | |
| 155 | si | |
| 156 | ||
| 157 | declare_class(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 158 | let result = Symbols.CLASS(location, span, self, name, arguments, enclosing) | |
| 159 | ||
| 160 | declare(location, result, symbol_definition_listener) | |
| 161 | ||
| 162 | return result | |
| 163 | si | |
| 164 | ||
| 165 | declare_trait(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 166 | let result = Symbols.TRAIT(location, span, self, name, arguments, enclosing) | |
| 167 | ||
| 168 | declare(location, result, symbol_definition_listener) | |
| 169 | ||
| 170 | return result | |
| 171 | si | |
| 172 | ||
| 173 | declare_struct(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 174 | let result = Symbols.STRUCT(location, span, self, name, arguments, enclosing) | |
| 175 | ||
| 176 | declare(location, result, symbol_definition_listener) | |
| 177 | ||
| 178 | return result | |
| 179 | si | |
| 180 | ||
| 181 | declare_union(location: LOCATION, span: LOCATION, name: string, arguments: Collections.List[string], enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 182 | let result = Symbols.UNION(location, span, self, name, arguments, enclosing) | |
| 183 | ||
| 184 | declare(location, result, symbol_definition_listener) | |
| 185 | ||
| 186 | return result | |
| 187 | si | |
| 188 | ||
| 189 | declare_enum(location: LOCATION, span: LOCATION, name: string, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 190 | let result = Symbols.ENUM_STRUCT(location, span, self, name, self) | |
| 191 | ||
| 192 | declare(location, result, symbol_definition_listener) | |
| 193 | ||
| 194 | ENUM_ORDER_OPERATOR.register(result) | |
| 195 | ENUM_EQUALITY_OPERATOR.register(result) | |
| 196 | ||
| 197 | // The bitwise operators are registered later, once a | |
| 198 | // `@System.Flags()` pragma (if any) is known — see | |
| 199 | // RESOLVE_TYPE_EXPRESSIONS._maybe_register_enum_bitwise_operators. | |
| 200 | ||
| 201 | return result | |
| 202 | si | |
| 203 | ||
| 204 | declare_innate(location: LOCATION, name: string, innate_name: string, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 205 | let result = Symbols.INNATE_FUNCTION(location, self, name, enclosing, innate_name) | |
| 206 | ||
| 207 | declare_function_group(location, result, symbol_definition_listener) | |
| 208 | ||
| 209 | return result | |
| 210 | si | |
| 211 | ||
| 212 | declare_function(location: LOCATION, span: LOCATION, name: string, is_static: bool, is_private: bool, has_body: bool, is_property_accessor: bool, enclosing: Scope, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 213 | let result = Symbols.GLOBAL_FUNCTION(location, span, self, name, enclosing) | |
| 214 | ||
| 215 | if is_private /\ IoC.CONTAINER.instance.build_flags.underscore_access != Compiler.UnderscoreAccess.LEGACY then | |
| 216 | result.emit_assembly = true | |
| 217 | fi | |
| 218 | ||
| 219 | declare_function_group(location, result, symbol_definition_listener) | |
| 220 | ||
| 221 | return result | |
| 222 | si | |
| 223 | ||
| 224 | 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 is | |
| 225 | let result = Symbols.GLOBAL_GENERATOR_FUNCTION(location, span, self, name, enclosing) | |
| 226 | ||
| 227 | declare_function_group(location, result, symbol_definition_listener) | |
| 228 | ||
| 229 | return result | |
| 230 | si | |
| 231 | ||
| 232 | 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 is | |
| 233 | let result = Symbols.GLOBAL_ASYNC_FUNCTION(location, span, self, name, enclosing) | |
| 234 | ||
| 235 | declare_function_group(location, result, symbol_definition_listener) | |
| 236 | ||
| 237 | return result | |
| 238 | si | |
| 239 | ||
| 240 | declare_variable(location: LOCATION, name: string, is_static: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 241 | let result = Symbols.GLOBAL_VARIABLE(location, self, name) | |
| 242 | ||
| 243 | declare(location, result, symbol_definition_listener) | |
| 244 | ||
| 245 | return result | |
| 246 | si | |
| 247 | ||
| 248 | declare_top_level_variable(location: LOCATION, name: string, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 249 | let result = Symbols.TOP_LEVEL_VARIABLE(location, self, name) | |
| 250 | ||
| 251 | declare(location, result, symbol_definition_listener) | |
| 252 | ||
| 253 | return result | |
| 254 | si | |
| 255 | ||
| 256 | declare_property(location: LOCATION, span: LOCATION, name: string, is_static: bool, is_private: bool, is_assignable: bool, symbol_definition_listener: SymbolDefinitionListener?) -> Symbol is | |
| 257 | let result = Symbols.GLOBAL_PROPERTY(location, span, self, name, is_assignable) | |
| 258 | ||
| 259 | declare(location, result, symbol_definition_listener) | |
| 260 | ||
| 261 | return result | |
| 262 | si | |
| 263 | ||
| 264 | load(location: LOCATION, from: Value?, loader: SYMBOL_LOADER) -> Value => loader.load_namespace(self) | |
| 265 | // Synthetic public sealed-abstract host for this namespace's globals. | |
| 266 | // Importer recognises by trailing simple name `$globals`. | |
| 267 | si | |
| 268 | si |