Skip to content
← Back

src/semantic/dotnet/symbol_store.ghul

1
@@IF.dotnet()
2
3
namespace Semantic.DotNet is
4
use TYPE = System.Type
5
6
use IO.Std
7
8
use Collections.MAP
9
10
class SYMBOL_STORE is
11
_symbols_by_dotnet_type: MAP[TYPE,Symbols.Scoped]
12
// The by-name entries are three-state: no entry at all, an
13
// entry with no symbol (the no-result marker cache_no_result
14
// writes), or a symbol.
15
_symbols_by_ghul_name: MAP[string,Symbols.Scoped?]
16
17
count: int => _symbols_by_ghul_name.count
18
19
init() is
20
_symbols_by_dotnet_type = MAP()
21
_symbols_by_ghul_name = MAP()
22
si
23
24
get_symbol(dotnet_type: TYPE) -> Symbols.Scoped? is
25
let result: Symbols.Scoped mut
26
27
_symbols_by_dotnet_type.try_get_value(dotnet_type, result ref)
28
29
return result
30
si
31
32
33
// True when the name has a by-name cache entry, including a
34
// null no-result marker. Distinct from get_symbol returning
35
// null, which conflates "cached no-result" with "never seen".
36
has_symbol(ghul_name: string) -> bool =>
37
_symbols_by_ghul_name.contains_key(ghul_name)
38
39
get_symbol(ghul_name: string) -> Symbols.Scoped? is
40
let result: Symbols.Scoped? mut = null
41
42
_symbols_by_ghul_name.try_get_value(ghul_name, result ref)
43
44
return result
45
si
46
47
// Drops every remembered miss, returning the names that were
48
// dropped: a name that resolved to nothing can resolve to
49
// something once another assembly has been imported.
50
forget_no_results() -> Collections.LIST[string] is
51
let forgotten = Collections.LIST[string]()
52
53
for entry in _symbols_by_ghul_name do
54
if !entry.value? then
55
forgotten.add(entry.key)
56
fi
57
od
58
59
for name in forgotten do
60
_symbols_by_ghul_name.remove(name)
61
od
62
63
return forgotten
64
si
65
66
cache_no_result(ghul_name: string) is
67
_symbols_by_ghul_name.add(ghul_name, null)
68
si
69
70
add_symbol(type: TYPE, ghul_name: string, symbol: Symbols.Scoped) is
71
// Idempotent: re-adding the same dotnet_type is a no-op.
72
// The backtick-suffix fallback path re-enters create_symbol
73
// for a .NET type already materialized via direct lookup
74
// (e.g. `Lazy\`1` source after `Lazy` was looked up); the
75
// earlier entry stays and the redundant add is skipped.
76
if !_symbols_by_dotnet_type.contains_key(type) then
77
_symbols_by_dotnet_type.add(type, symbol)
78
fi
79
80
// Argument-count overloading: when two reflected types share
81
// a ghul name (their `\`N` suffix was stripped on import),
82
// the first member to be materialized wins the bare-name
83
// cache slot. The caller
84
// (`symbol_table.materialize_type_group`) is responsible for
85
// then overwriting the entry with the assembled TYPE_GROUP
86
// via `set_name_symbol`.
87
if !_symbols_by_ghul_name.contains_key(ghul_name) then
88
_symbols_by_ghul_name.add(ghul_name, symbol)
89
fi
90
si
91
92
set_name_symbol(ghul_name: string, symbol: Symbols.Scoped) is
93
_symbols_by_ghul_name[ghul_name] = symbol
94
si
95
si
96
si