stage1 指针计算类型的错误修复 as运算符优先级的修改 ir2vm的bug修复
This commit is contained in:
1 parent
06f3884c30
commit
09d05e3a34
10 files changed
+191
-60
No files matched your search
+18
-8
@@ -148,6 +148,7 @@ static spl_ast_node_ref_t parse_param_decl_impl(parser_t *p);
|
||||
static spl_ast_node_ref_t parse_var_pattern(parser_t *p);
|
||||
static spl_ast_node_ref_t parse_match_pattern(parser_t *p);
|
||||
|
||||
static spl_ast_node_ref_t parse_cast(parser_t *p);
|
||||
static spl_ast_node_ref_t parse_prefix(parser_t *p);
|
||||
static spl_ast_node_ref_t parse_postfix(parser_t *p);
|
||||
static spl_ast_node_ref_t parse_primary(parser_t *p);
|
||||
@@ -1215,7 +1216,7 @@ static spl_binary_op_t token_to_binary_op(spl_tok_type_t tt) {
|
||||
}
|
||||
|
||||
static spl_ast_node_ref_t parse_expr_prec(parser_t *p, int min_prec) {
|
||||
spl_ast_node_ref_t left = parse_prefix(p);
|
||||
spl_ast_node_ref_t left = parse_cast(p);
|
||||
if (p->failed)
|
||||
return left;
|
||||
|
||||
@@ -1259,6 +1260,22 @@ static spl_ast_node_ref_t parse_expr(parser_t *p) {
|
||||
return parse_expr_prec(p, 1); // 最低优先级
|
||||
}
|
||||
|
||||
static spl_ast_node_ref_t parse_cast(parser_t *p) {
|
||||
spl_ast_node_ref_t expr = parse_prefix(p);
|
||||
while (!p->failed) {
|
||||
const spl_tok_t *t = peek(p);
|
||||
if (!t || t->type != KW_AS || p->stop_as)
|
||||
break;
|
||||
advance(p);
|
||||
spl_ast_node_ref_t type = parse_type_expr(p);
|
||||
spl_ast_node_ref_t ref = new_node(p, SPL_AST_EXPR_CAST, t);
|
||||
node_at(p->ast, ref)->cast.expr = expr;
|
||||
node_at(p->ast, ref)->cast.type = type;
|
||||
expr = ref;
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
static spl_ast_node_ref_t parse_prefix(parser_t *p) {
|
||||
const spl_tok_t *t = peek(p);
|
||||
if (!t)
|
||||
@@ -1393,13 +1410,6 @@ static spl_ast_node_ref_t parse_postfix(parser_t *p) {
|
||||
node_at(p->ast, ref)->index.index = begin;
|
||||
expr = ref;
|
||||
}
|
||||
} else if (t->type == KW_AS && !p->stop_as) {
|
||||
advance(p);
|
||||
spl_ast_node_ref_t type = parse_type_expr(p);
|
||||
spl_ast_node_ref_t ref = new_node(p, SPL_AST_EXPR_CAST, t);
|
||||
node_at(p->ast, ref)->cast.expr = expr;
|
||||
node_at(p->ast, ref)->cast.type = type;
|
||||
expr = ref;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user