Skip to content
← Back

src/semantic/symbols/duplicate_method_checker.ghul

1
namespace Semantic is
2
use IO.Std
3
4
use Collections.Iterable
5
use Collections.Iterator
6
7
use Collections.LIST
8
use Collections.SET
9
10
use Pair = Collections.KeyValuePair
11
12
use Symbols.Symbol
13
use Symbols.Scope
14
use Symbols.Function
15
use Symbols.FUNCTION_GROUP
16
17
use Types.Type
18
19
use Ghul.Pipes
20
21
class DUPLICATE_METHOD_CHECKER is
22
_logger: Logging.Logger
23
24
init(logger: Logging.Logger) is
25
_logger = logger
26
si
27
28
check(scope: Scope, message: string) is
29
for function_group in scope.symbols |> filter(s => s.is_function_group) |> map(f => cast Symbols.FUNCTION_GROUP?(f)!) do
30
check(function_group.name, function_group.functions |> filter(f => f.is_instance), message)
31
check(function_group.name, function_group.functions |> filter(f => !f.is_instance), message)
32
od
33
si
34
35
check(name: string, functions: Iterable[Function], message: string) is
36
let map = METHOD_OVERRIDE_MAP(name)
37
38
map.add(functions)
39
40
for s in map do
41
if s.count > 1 then
42
let duplicates = LIST[Function](s.iterable |> filter(s => !s.is_internal))
43
44
for function in duplicates do
45
let others = LIST[Logging.RELATED_LOCATION]()
46
47
for other in duplicates do
48
if other != function then
49
others.add(Logging.RELATED_LOCATION(other.location, "also declared here"))
50
fi
51
od
52
53
_logger.error(function.location, message, others)
54
od
55
fi
56
od
57
si
58
si
59
si