Parsing operator overloads
This commit is contained in:
@@ -834,13 +834,30 @@ parse_decl(B32 is_global){
|
||||
if(expr->kind == AST_LAMBDA_EXPR){
|
||||
auto a = (Ast_Lambda *)expr;
|
||||
if(a->scope || is_flag_set(flags, AST_FOREIGN)){
|
||||
result->kind = AST_LAMBDA;
|
||||
if(is_flag_set(flags, AST_FOREIGN))
|
||||
set_flag(expr->flags, flags);
|
||||
result->kind = AST_LAMBDA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(token_match(TK_StringLit, TK_DoubleColon)){
|
||||
Ast_Lambda *expr = (Ast_Lambda *)parse_expr();
|
||||
if(expr->kind != AST_LAMBDA_EXPR){
|
||||
compiler_error(tname, "Operator overload is required to be a lambda function");
|
||||
}
|
||||
if(!expr->scope){
|
||||
compiler_error(tname, "Operator overload doesn't have body");
|
||||
}
|
||||
|
||||
if(!is_valid_operator_overload(pctx, tname->intern_val)){
|
||||
compiler_error(tname, "This operator cannot be overloaded");
|
||||
}
|
||||
|
||||
result = ast_const(tname, tname->intern_val, expr);
|
||||
result->kind = AST_LAMBDA;
|
||||
result->flags = set_flag(result->flags, AST_OPERATOR_OVERLOAD);
|
||||
}
|
||||
else if(token_match(TK_Identifier, TK_Colon)){
|
||||
Ast_Expr *typespec = parse_expr();
|
||||
Ast_Expr *expr = parse_assign_expr();
|
||||
|
||||
Reference in New Issue
Block a user