PPLM_By_Function_Type,
PPLM_By_Arguments,
} PolyProcLookupMethod;
-AstFunction* polymorphic_proc_lookup(AstPolyProc* pp, PolyProcLookupMethod pp_lookup, ptr actual, OnyxFilePos pos);
-AstFunction* polymorphic_proc_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxFilePos pos);
-AstNode* polymorphic_proc_try_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxFilePos pos);
+AstFunction* polymorphic_proc_lookup(AstPolyProc* pp, PolyProcLookupMethod pp_lookup, ptr actual, OnyxToken* tkn);
+AstFunction* polymorphic_proc_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxToken* tkn);
+AstNode* polymorphic_proc_try_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxToken* tkn);
AstFunction* polymorphic_proc_build_only_header(AstPolyProc* pp, PolyProcLookupMethod pp_lookup, ptr actual);
}
if (callee->kind == Ast_Kind_Polymorphic_Proc) {
- call->callee = (AstTyped *) polymorphic_proc_lookup(
- (AstPolyProc *) call->callee,
- PPLM_By_Call,
- call,
- call->token->pos);
+ call->callee = (AstTyped *) polymorphic_proc_lookup((AstPolyProc *) call->callee, PPLM_By_Call, call, call->token);
if (call->callee == NULL) return Check_Error;
type_lookup_member(expected_range_type, "low", &smem);
if (!type_check_or_auto_cast(&range->low, smem.type)) {
- onyx_report_error(range->token->pos, "Expected left side of range to be a 32-bit integer.");
+ onyx_report_error(range->token->pos,
+ "Expected left side of range to be a 32-bit integer, got '%s'.",
+ type_get_name(range->low->type));
return Check_Error;
}
type_lookup_member(expected_range_type, "high", &smem);
if (!type_check_or_auto_cast(&range->high, smem.type)) {
- onyx_report_error(range->token->pos, "Expected right side of range to be a 32-bit integer.");
+ onyx_report_error(range->token->pos,
+ "Expected right side of range to be a 32-bit integer, got '%s'.",
+ type_get_name(range->high->type));
return Check_Error;
}
CheckStatus check_function(AstFunction* func) {
semstate.expected_return_type = func->type->Function.return_type;
- if (func->body) return check_block(func->body);
+ if (func->body) {
+ CheckStatus status = check_block(func->body);
+ if (status != Check_Success && func->generated_from)
+ onyx_report_error(func->generated_from->pos, "Error in polymorphic procedure generated from this location.");
+
+ return status;
+ }
return Check_Success;
}
case PSK_Value:
// CLEANUP: Maybe clone this?
+ assert(sln->value->flags & Ast_Flag_Comptime);
node = (AstNode *) sln->value;
break;
}
return NULL;
}
-AstFunction* polymorphic_proc_lookup(AstPolyProc* pp, PolyProcLookupMethod pp_lookup, ptr actual, OnyxFilePos pos) {
+AstFunction* polymorphic_proc_lookup(AstPolyProc* pp, PolyProcLookupMethod pp_lookup, ptr actual, OnyxToken* tkn) {
ensure_polyproc_cache_is_created(pp);
char *err_msg = NULL;
bh_arr(AstPolySolution) slns = find_polymorphic_slns(pp, pp_lookup, actual, &err_msg);
if (slns == NULL) {
- if (err_msg != NULL) onyx_report_error(pos, err_msg);
- else onyx_report_error(pos, "Some kind of error occured when generating a polymorphic procedure. You hopefully will not see this");
+ if (err_msg != NULL) onyx_report_error(tkn->pos, err_msg);
+ else onyx_report_error(tkn->pos, "Some kind of error occured when generating a polymorphic procedure. You hopefully will not see this");
}
- AstFunction* result = polymorphic_proc_solidify(pp, slns, pos);
+ AstFunction* result = polymorphic_proc_solidify(pp, slns, tkn);
bh_arr_free(slns);
return result;
return key_buf;
}
-b32 add_solidified_function_entities(AstSolidifiedFunction solidified_func, b32 header_already_processed) {
+static b32 add_solidified_function_entities(AstSolidifiedFunction solidified_func, b32 header_already_processed) {
solidified_func.func->flags |= Ast_Flag_Function_Used;
solidified_func.func->flags |= Ast_Flag_From_Polymorphism;
return 1;
}
-AstFunction* polymorphic_proc_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxFilePos pos) {
+AstFunction* polymorphic_proc_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxToken* tkn) {
ensure_polyproc_cache_is_created(pp);
// NOTE: Check if a version of this polyproc has already been created.
clone_function_body(semstate.node_allocator, solidified_func.func, pp->base_func);
if (!add_solidified_function_entities(solidified_func, 1)) {
- onyx_report_error(pos, "Error in polymorphic procedure header generated from this call site.");
+ onyx_report_error(tkn->pos, "Error in polymorphic procedure header generated from this call site.");
return NULL;
}
}
AstSolidifiedFunction solidified_func;
- solidified_func.poly_scope = scope_create(semstate.node_allocator, pp->poly_scope, pos);
+ solidified_func.poly_scope = scope_create(semstate.node_allocator, pp->poly_scope, tkn->pos);
insert_poly_slns_into_scope(solidified_func.poly_scope, slns);
solidified_func.func = (AstFunction *) ast_clone(semstate.node_allocator, pp->base_func);
bh_table_put(AstSolidifiedFunction, pp->concrete_funcs, unique_key, solidified_func);
+ solidified_func.func->generated_from = tkn;
+
if (!add_solidified_function_entities(solidified_func, 0)) {
- onyx_report_error(pos, "Error in polymorphic procedure header generated from this call site.");
+ onyx_report_error(tkn->pos, "Error in polymorphic procedure header generated from this call site.");
return NULL;
}
+
return solidified_func.func;
}
// NOTE: This can return either a AstFunction or an AstPolyProc, depending if enough parameters were
// supplied to remove all the polymorphic variables from the function.
-AstNode* polymorphic_proc_try_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxFilePos pos) {
+AstNode* polymorphic_proc_try_solidify(AstPolyProc* pp, bh_arr(AstPolySolution) slns, OnyxToken* tkn) {
i32 valid_argument_count = 0;
bh_arr_each(AstPolySolution, sln, slns) {
if (found_match) {
valid_argument_count++;
} else {
- onyx_report_error(pos, "'%b' is not a type variable of '%b'.",
+ onyx_report_error(tkn->pos, "'%b' is not a type variable of '%b'.",
sln->poly_sym->token->text, sln->poly_sym->token->length,
pp->token->text, pp->token->length);
return (AstNode *) pp;
}
if (valid_argument_count == bh_arr_length(pp->poly_params)) {
- return (AstNode *) polymorphic_proc_solidify(pp, slns, pos);
+ return (AstNode *) polymorphic_proc_solidify(pp, slns, tkn);
} else {
// HACK: Some of these initializations assume that the entity for this polyproc has