diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-01-15 19:55:04 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-01-15 19:55:04 +0000 |
| commit | ac736aa4ecf5dce7b1dbd4c5ef3758f8f2008ebc (patch) | |
| tree | b7d30f39fb13723d33de2b0a5f4029873f25a205 /src/types.c | |
| parent | 6fe25badf067d63c79999814f46be0ac79a39ef8 (diff) | |
Procedure overloading
Diffstat (limited to 'src/types.c')
| -rw-r--r-- | src/types.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/types.c b/src/types.c index c8ad70f68..a17aa98d2 100644 --- a/src/types.c +++ b/src/types.c @@ -822,6 +822,7 @@ bool are_types_identical(Type *x, Type *y) { case Type_Proc: if (y->kind == Type_Proc) { return x->Proc.calling_convention == y->Proc.calling_convention && + x->Proc.variadic == y->Proc.variadic && are_types_identical(x->Proc.params, y->Proc.params) && are_types_identical(x->Proc.results, y->Proc.results); } @@ -908,6 +909,60 @@ bool is_type_cte_safe(Type *type) { return false; } +typedef enum ProcTypeOverloadKind { + ProcOverload_Identical, // The types are identical + + ProcOverload_CallingConvention, + ProcOverload_ParamCount, + ProcOverload_ParamVariadic, + ProcOverload_ParamTypes, + ProcOverload_ResultCount, + ProcOverload_ResultTypes, + +} ProcTypeOverloadKind; + + +ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { + GB_ASSERT(is_type_proc(x)); + GB_ASSERT(is_type_proc(y)); + TypeProc *px = &base_type(x)->Proc; + TypeProc *py = &base_type(y)->Proc; + + if (px->calling_convention != py->calling_convention) { + return ProcOverload_CallingConvention; + } + + if (px->param_count != py->param_count) { + return ProcOverload_ParamCount; + } + + for (isize i = 0; i < px->param_count; i++) { + Entity *ex = px->params->Tuple.variables[i]; + Entity *ey = py->params->Tuple.variables[i]; + if (!are_types_identical(ex->type, ey->type)) { + return ProcOverload_ParamTypes; + } + } + // IMPORTANT TODO(bill): Determine the rules for overloading procedures with variadic parameters + if (px->variadic != py->variadic) { + return ProcOverload_ParamVariadic; + } + + if (px->result_count != py->result_count) { + return ProcOverload_ResultCount; + } + + for (isize i = 0; i < px->result_count; i++) { + Entity *ex = px->results->Tuple.variables[i]; + Entity *ey = py->results->Tuple.variables[i]; + if (!are_types_identical(ex->type, ey->type)) { + return ProcOverload_ResultTypes; + } + } + + return ProcOverload_Identical; +} + |