Skip to content
← Back

src/semantic/alike_named_symbols.ghul

1
namespace Semantic is
2
use Symbols.Symbol
3
use Types.Type
4
5
// Collects, across the types one diagnostic mentions, the distinct
6
// declarations that share a name. Rendered relative to the reader's
7
// scope two of those can come out as the same text, so each one found
8
// is rendered fully qualified instead.
9
class ALIKE_NAMED_SYMBOLS is
10
_first_by_name: Collections.MAP[string, Symbol]
11
_alike: Collections.LIST[Symbol]
12
13
symbols: Collections.List[Symbol] => _alike
14
15
init() is
16
_first_by_name = Collections.MAP[string, Symbol]()
17
_alike = Collections.LIST[Symbol]()
18
si
19
20
add(type: Type?) is
21
if !type? then
22
return
23
fi
24
25
if isa Types.NAMED(type) then
26
_add_symbol(type.symbol.unspecialized_symbol)
27
28
for argument in type.arguments do
29
add(argument)
30
od
31
fi
32
si
33
34
add_function(function: Symbols.Function) is
35
for argument in function.arguments do
36
add(argument)
37
od
38
39
for argument in function.generic_arguments do
40
add(argument)
41
od
42
43
add(function.return_type)
44
si
45
46
_add_symbol(symbol: Symbol) is
47
let name = symbol.name
48
let first: Symbol mut
49
50
if _first_by_name.try_get_value(name, first ref) then
51
if first != symbol then
52
_note(first)
53
_note(symbol)
54
fi
55
else
56
_first_by_name[name] = symbol
57
fi
58
si
59
60
_note(symbol: Symbol) is
61
for s in _alike do
62
if s == symbol then
63
return
64
fi
65
od
66
67
_alike.add(symbol)
68
si
69
si
70
si