Bulletproofing operator overloads using generated data

This commit is contained in:
Krzosa Karol
2022-09-30 13:36:48 +02:00
parent 62faf8a78c
commit 4ca3ab95df
10 changed files with 79 additions and 159 deletions

View File

@@ -847,15 +847,27 @@ parse_decl(B32 is_global){
if(!expr->scope){
compiler_error(tname, "Operator overload doesn't have body");
}
if(!is_valid_operator_overload(pctx, tname->intern_val)){
Operator_Info *op_info = get_operator_info(tname->intern_val);
if(!op_info){
compiler_error(tname, "This operator cannot be overloaded");
}
// if(is_binary && expr->args.len == 2){
// }
if(expr->args.len == 1){
if(!op_info->valid_unary_expr){
compiler_error(tname, "This operator cannot have a unary expression");
}
}
else if(expr->args.len == 2){
if(!op_info->valid_binary_expr){
compiler_error(tname, "This operator cannot have a binary expression");
}
}
else {
compiler_error(tname, "Invalid argument count for operator overload, unhandled operator");
}
result = ast_const(tname, tname->intern_val, expr);
result->overload_op_info = op_info;
result->kind = AST_LAMBDA;
result->flags = set_flag(result->flags, AST_OPERATOR_OVERLOAD);
}