Skip to content
← Back

src/semantic/dotnet/ambiguous_method_checker.ghul

1
@@IF.dotnet()
2
3
namespace Semantic.DotNet is
4
use IO.Std
5
6
use Collections.Iterable
7
use Collections.Iterator
8
9
use Collections.SET
10
use Collections.LIST
11
use Collections.MAP
12
13
use Pair = Collections.KeyValuePair
14
15
use System.Reflection.MethodInfo
16
use System.Reflection.TypeInfo
17
18
use Ghul.Pipes
19
20
use Symbols.Symbol
21
use Symbols.Scope
22
use Symbols.Function
23
use Symbols.FUNCTION_GROUP
24
25
use Types.Type
26
27
class AMBIGUOUS_METHOD_CHECKER(_logger: Logging.Logger) is
28
29
check(
30
owner: Symbol,
31
functions: Iterable[(function: Function, method_info: MethodInfo)]
32
) is
33
let map = MAP[(name: string, number_of_arguments: int), LIST[(function: Function, method_info: MethodInfo)]]()
34
35
for f_mi in functions do
36
let list: LIST[(function: Function, method_info: MethodInfo)] mut
37
38
let name = f_mi.function.name
39
let number_of_arguments = f_mi.function.argument_names.count
40
41
if !map.try_get_value((name, number_of_arguments), list ref) then
42
list = LIST[(Function, MethodInfo)]()
43
map[(name, number_of_arguments)] = list
44
fi
45
46
list.add(f_mi)
47
od
48
49
for kv in map do
50
if kv.value.count <= 1 then
51
continue
52
fi
53
54
check(
55
owner,
56
kv.key.name,
57
kv.value |>
58
map(f_mi => f_mi.function) |>
59
filter(f => f.is_instance /\ !f.is_internal)
60
)
61
62
check(
63
owner,
64
kv.key.name,
65
kv.value |>
66
map(f_mi => f_mi.function) |>
67
filter(f => !f.is_instance /\ !f.is_internal)
68
)
69
od
70
si
71
72
check(owner: Symbol, name: string, functions: Iterable[Function]) is
73
let map = METHOD_OVERRIDE_MAP(name)
74
75
map.add(functions)
76
77
for s in map do
78
if s.count > 1 then
79
for function in s.iterable do
80
if function.owner != owner then
81
function.hide()
82
fi
83
od
84
fi
85
od
86
si
87
si
88
si