Struct field access. Damn, I coded for like 30 minutes and then it just worked on the first try

This commit is contained in:
Krzosa Karol
2022-05-30 18:27:06 +02:00
parent 0e0b95ab52
commit 980a3b68b9
6 changed files with 186 additions and 41 deletions

View File

@@ -100,11 +100,20 @@ gen_expr(Ast_Expr *ast){
}
CASE(BINARY, Binary){
gen("(");
gen_expr(node->left);
gen("%s", token_kind_string(node->op).str);
gen_expr(node->right);
gen(")");
if(node->op == TK_Dot){
Sym *sym = resolved_get(node->left);
gen_expr(node->left);
if(sym->type->kind == TYPE_POINTER) gen("->");
else gen(".");
gen_expr(node->right);
}
else{
gen("(");
gen_expr(node->left);
gen("%s", token_kind_string(node->op).str);
gen_expr(node->right);
gen(")");
}
BREAK();
}