Skip to content
← Back

src/semantic/dotnet/global_overload_merge.ghul

1
namespace Semantic.DotNet is
2
use Symbols.Function
3
use Symbols.FUNCTION_GROUP
4
use Symbols.METHOD_OVERRIDE_CLASS
5
6
// Combines the symbols one global name resolves to in several places
7
// into the single symbol a lookup answers with.
8
class GLOBAL_OVERLOAD_MERGE is
9
// The first symbol when it is the only one, or when any of them is
10
// not a function; otherwise one group holding every function, the
11
// first declaration of each signature winning.
12
merge(found: Collections.List[Symbols.Symbol]) -> Symbols.Symbol static is
13
let first = found[0]
14
15
if found.count == 1 then
16
return first
17
fi
18
19
for s in found do
20
if !isa Function(s) /\ !isa FUNCTION_GROUP(s) then
21
return first
22
fi
23
od
24
25
let owner = first.owner
26
27
assert owner? else "global symbol has no owner: {first}"
28
29
let result = FUNCTION_GROUP(first.location, owner, first.name)
30
let seen = Collections.SET[METHOD_OVERRIDE_CLASS]()
31
32
for s in found do
33
if let f: Function = s then
34
_add(result, seen, f)
35
elif let group: FUNCTION_GROUP = s then
36
for f in group.functions do
37
_add(result, seen, f)
38
od
39
fi
40
od
41
42
return result
43
si
44
45
_add(result: FUNCTION_GROUP, seen: Collections.SET[METHOD_OVERRIDE_CLASS], f: Function) static is
46
if seen.contains(f.override_class) then
47
return
48
fi
49
50
seen.add(f.override_class)
51
result.add(f)
52
si
53
si
54
si