diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-11 15:03:52 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2025-04-11 15:03:52 +0330 |
commit | 36b54e168fd18e7207860b7434a922e71475e96e (patch) | |
tree | 47915eeafa36f697f5b6dcce06a5465fad89b3d0 /src | |
parent | cb92cc5df12a77be438801bc5f80bcdea853fce7 (diff) |
more function overloading support
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/ast-tree.c | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c index 524469c..b5ab3a2 100644 --- a/src/compiler/ast-tree.c +++ b/src/compiler/ast-tree.c @@ -3468,15 +3468,6 @@ bool setTypesFunctionCall(AstTree *tree, AstTreeSetTypesHelper _helper) { if ((size_t)(arg.name_end - arg.name_begin) == param_name_size && strncmp(arg.name_begin, param.nameBegin, param_name_size) == 0) { initedArguments[j] = param; - AstTreeSetTypesHelper newHelper = { - .lookingType = arg.type, - .treeHelper = helper.treeHelper, - .dependencies = helper.dependencies, - }; - - if (!setAllTypes(param.value, newHelper, NULL, NULL)) { - return false; - } goto END_OF_NAMED_FOR; } } @@ -3491,18 +3482,9 @@ bool setTypesFunctionCall(AstTree *tree, AstTreeSetTypesHelper _helper) { AstTreeFunctionCallParam param = metadata->parameters[i]; if (param.nameBegin == param.nameEnd) { for (size_t j = 0; j < function->arguments_size; ++j) { - AstTreeTypeFunctionArgument arg = function->arguments[j]; + // AstTreeTypeFunctionArgument arg = function->arguments[j]; if (initedArguments[j].value == NULL) { initedArguments[j] = param; - AstTreeSetTypesHelper newHelper = { - .lookingType = arg.type, - .treeHelper = helper.treeHelper, - .dependencies = helper.dependencies, - }; - - if (!setAllTypes(param.value, newHelper, NULL, NULL)) { - return false; - } goto END_OF_UNNAMED_FOR; } } @@ -3535,11 +3517,41 @@ bool setTypesVariable(AstTree *tree, AstTreeSetTypesHelper helper, AstTreeVariable *variable = NULL; size_t variable_index = -1ULL; - if (functionCall == NULL) { + if (helper.lookingType != NULL) { for (size_t i = 0; i < variables->size; ++i) { AstTreeVariable *var = variables->data[i].variable; size_t index = variables->data[i].index; + if (!setTypesAstVariable(var, helper)) { + goto RETURN_ERROR; + } + + if (!typeIsEqual(var->type, helper.lookingType)) { + continue; + } + + if (variable != NULL) { + if (variable_index > index) { + continue; + } else if (variable != NULL && variable_index == index) { + printError(tree->str_begin, tree->str_end, + "Multiple candidate found"); + goto RETURN_ERROR; + } + } + + variable = var; + variable_index = index; + } + } else if (functionCall == NULL) { + for (size_t i = 0; i < variables->size; ++i) { + AstTreeVariable *var = variables->data[i].variable; + size_t index = variables->data[i].index; + + if (!setTypesAstVariable(var, helper)) { + goto RETURN_ERROR; + } + if (variable != NULL) { if (variable_index > index) { continue; |