Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
v420v committed Sep 17, 2024
1 parent b287a84 commit 3b94216
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/parser/header.ibu
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ func parse_ty(p *Parser) *Type;
func parse_params_types(p *Parser, types *Vec) bool;
func parse_expr(p *Parser) *Node;
func parse_func_call_args(p *Parser) *Vec;
func parse_ref(p *Parser) *Node;
func parse_not(p *Parser) *Node;
func parse_unary(p *Parser) *Node;
func parse_sizeof(p *Parser) *Node;
func find_object(p *Parser, name *u8) *Object;
Expand Down
49 changes: 27 additions & 22 deletions src/parser/parser.ibu
Original file line number Diff line number Diff line change
Expand Up @@ -608,26 +608,32 @@ func params_length_without_argv_argc(ty *Type) i32 {
}
}

func parse_unary(p *Parser) *Node {
let node *Node;
func parse_ref(p *Parser) *Node {
parser_skip(p, "&");
let node *Node = new_node(ND_REF);
node.lhs = parse_unary(p);
return node;
}

func parse_not(p *Parser) *Node {
parser_skip(p, "!");
let node *Node = new_node(ND_NOT);
node.lhs = parse_unary(p);
return node;
}

func parse_unary(p *Parser) *Node {
if strcmp(p.tokens.lit, "*") {
return parse_deref(p);
}
if strcmp(p.tokens.lit, "&") {
parser_next(p);
node = new_node(ND_REF);
node.lhs = parse_unary(p);
return node;
return parse_ref(p);
}
if strcmp(p.tokens.lit, "!") {
parser_next(p);
node = new_node(ND_NOT);
node.lhs = parse_unary(p);
return node;
return parse_not(p);
}

node = parse_number(p);
let node *Node = parse_number(p);

while {
if strcmp(p.tokens.lit, "(") {
Expand All @@ -636,7 +642,7 @@ func parse_unary(p *Parser) *Node {

add_type(p, node);

if node.ty.kind != TY_FUNC {
if node.ty.kind != TY_FUNC {
print_error(lpar_tok, "cannot call a none function type object\n");
}

Expand Down Expand Up @@ -682,8 +688,7 @@ func parse_unary(p *Parser) *Node {
print_error(access_tok, "`[]` cannot access to none pointer type.");
}

let base_number_node *Node;
base_number_node = new_node(ND_NUM);
let base_number_node *Node = new_node(ND_NUM);
base_number_node.int_val = node.ty.pointer_to.size;
base_number_node.ty = p.ty_i32;

Expand Down Expand Up @@ -749,10 +754,10 @@ func parse_mul(p *Parser) *Node {
parser_next(p);
node = new_binop(ND_MOD, node, parse_unary(p));
} else {
goto end;
goto break;
}
}
end:
break:

return node;
}
Expand All @@ -768,10 +773,10 @@ func parse_add(p *Parser) *Node {
parser_next(p);
node = new_binop(ND_SUB, node, parse_mul(p));
} else {
goto end;
goto break;
}
}
end:
break:

return node;
}
Expand Down Expand Up @@ -890,10 +895,10 @@ func parse_relational(p *Parser) *Node {
node = new_binop(ND_GT, node, rhs);
}
} else {
goto end;
goto break;
}
}
end:
break:

return node;
}
Expand Down Expand Up @@ -924,10 +929,10 @@ func parse_equality(p *Parser) *Node {
node = new_binop(ND_NE, node, rhs);
}
} else {
goto end;
goto break;
}
}
end:
break:

return node;
}
Expand Down

0 comments on commit 3b94216

Please sign in to comment.