Better support for Type types, squashing bugs due to pointer confusion etc.
This commit is contained in:
19
ccodegen.cpp
19
ccodegen.cpp
@@ -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(")");
|
||||
|
||||
Reference in New Issue
Block a user