Better support for Type types, squashing bugs due to pointer confusion etc.

This commit is contained in:
Krzosa Karol
2022-06-19 10:18:57 +02:00
parent 94b820a071
commit ade2638255
6 changed files with 56 additions and 17 deletions

View File

@@ -284,6 +284,11 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
BREAK();
}
CASE(ARRAY, Array){
gen("%d", node->resolved_type->type_id);
BREAK();
}
CASE(INDEX, Index){
gen("(");
gen_expr(node->expr);
@@ -332,7 +337,19 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){
CASE(UNARY, Unary){
gen("(");
if(node->op != TK_PostIncrement && node->op != TK_PostDecrement) gen("%s", name(node->op));
if(node->op != TK_PostIncrement && node->op != TK_PostDecrement){
if(node->op == TK_Pointer){
// Normal types are usually generated with gen_simple_decl
// if they are part of the expression they are a value
// which means we need to shortcircuit here with proper type_id
Ast_Type *base = get_type_base(node->resolved_type);
if(base == type_type){
gen("%d)", node->resolved_type_val->type_id);
return true;
}
}
gen("%s", name(node->op));
}
gen_expr(node->expr);
if(node->op == TK_PostIncrement || node->op == TK_PostDecrement) gen("%s", name(node->op));
gen(")");