Appearance
| 1 | namespace Semantic is | |
| 2 | use IO.Std; | |
| 3 | ||
| 4 | use System.Text.StringBuilder; | |
| 5 | ||
| 6 | use Collections.Iterable; | |
| 7 | use Collections.Iterator; | |
| 8 | use Collections.List; | |
| 9 | use Collections.LIST; | |
| 10 | use Collections.MAP; | |
| 11 | use Collections.SET; | |
| 12 | ||
| 13 | use Symbols.Function; | |
| 14 | ||
| 15 | use Types.Type; | |
| 16 | ||
| 17 | use Ghul.Pipes; | |
| 18 | ||
| 19 | class METHOD_OVERRIDE_CLASS is | |
| 20 | arguments: List[Type]; | |
| 21 | // Number of generic arguments. Functions only override / count as | |
| 22 | // duplicates of siblings with the same generic-argument count; | |
| 23 | // `foo()` and `foo[T]()` are distinct sibling functions, not one | |
| 24 | // overriding the other and not a duplicate. | |
| 25 | generic_arguments_count: int; | |
| 26 | ||
| 27 | init(arguments: List[Type]) is | |
| 28 | init(arguments, 0); | |
| 29 | si | |
| 30 | ||
| 31 | init(arguments: List[Type], generic_arguments_count: int) is | |
| 32 | assert arguments |> all(a => a?) else "override class arguments list contains null elements"; | |
| 33 | ||
| 34 | self.arguments = arguments; | |
| 35 | self.generic_arguments_count = generic_arguments_count; | |
| 36 | si | |
| 37 | ||
| 38 | =~(other: METHOD_OVERRIDE_CLASS) -> bool is | |
| 39 | if other.generic_arguments_count != generic_arguments_count then | |
| 40 | return false; | |
| 41 | fi | |
| 42 | ||
| 43 | if other.arguments.count != arguments.count then | |
| 44 | return false; | |
| 45 | fi | |
| 46 | ||
| 47 | for i in 0..arguments.count do | |
| 48 | if !arguments[i].matches(other.arguments[i]) then | |
| 49 | return false; | |
| 50 | fi | |
| 51 | od | |
| 52 | ||
| 53 | return true; | |
| 54 | si | |
| 55 | ||
| 56 | equals(other: object?) -> bool is | |
| 57 | if !other? then | |
| 58 | return false; | |
| 59 | fi | |
| 60 | ||
| 61 | if !isa METHOD_OVERRIDE_CLASS(other) then | |
| 62 | return false; | |
| 63 | fi | |
| 64 | ||
| 65 | return self =~ other; | |
| 66 | si | |
| 67 | ||
| 68 | get_hash_code() -> int is | |
| 69 | let result mut = generic_arguments_count; | |
| 70 | ||
| 71 | for a in arguments do | |
| 72 | result = result + a.get_hash_code(); | |
| 73 | od | |
| 74 | ||
| 75 | return result; | |
| 76 | si | |
| 77 | ||
| 78 | to_string() -> string => "({arguments|})"; | |
| 79 | si | |
| 80 | si |