Commit f7b6a04f authored by Guillaume Charifi's avatar Guillaume Charifi

compiler/parser: Parse op_new.

parent 70c7a782
......@@ -490,6 +490,77 @@ failed:
return -1;
}
static int op_new_dtor(struct bm_ast_node *node)
{
destroy_type(&node->data.as_op_new.type);
return 0;
}
static int op_new_debug_data(const struct bm_ast_node *node, int indent_lvl)
{
const struct bm_ast_node_data_op_new *data = &node->data.as_op_new;
wprintf(L",\n%*ls\"class\": \"", indent_lvl * 2, L"");
debug_type(&data->type);
wprintf(L"\"");
return 0;
}
static int parse_op_new(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *out)
{
int result;
unsigned long i = *cur_tok_id;
unsigned long param_id;
struct bm_ast_node nnew;
struct bm_ast_node param;
if (ctx->in->tokens[i].type != BM_TOK_NEW)
return -1;
i++;
parser_node_init(&nnew, BM_AST_NODE_OP_NEW);
nnew.dtor = op_new_dtor;
nnew.debug_data = op_new_debug_data;
result = parse_type(ctx, &i, &nnew.data.as_op_new.type);
if (result < 0)
goto failed;
if (ctx->in->tokens[i].type != BM_TOK_BRACKET_OPEN)
goto failed;
i++;
param_id = BM_AST_NODE_OP_NEW_CHILD_PARAM0;
while (i < ctx->in->nb_tokens)
{
result = parse_expr(ctx, &i, &param);
if (result < 0)
break;
parser_node_set_child(&nnew, param_id, &param);
param_id++;
if (ctx->in->tokens[i].type != BM_TOK_COMMA)
break;
i++;
}
if (ctx->in->tokens[i].type != BM_TOK_BRACKET_CLOSE)
goto failed;
i++;
*out = nnew;
*cur_tok_id = i;
return 0;
failed:
parser_node_destroy(&nnew);
return -1;
}
static int parse_op_subscript(struct parser_ctx *ctx, unsigned long *cur_tok_id, struct bm_ast_node *left_expr, struct bm_ast_node *out)
{
int result;
......@@ -800,6 +871,7 @@ static const parse_expr_callback expr_callback_table[] = {
/* val_var_ext must be parsed before val_var. */
parse_val_var_ext,
parse_val_var,
parse_op_new,
parse_preop,
parse_block,
parse_dowhile,
......@@ -922,6 +994,7 @@ static const struct op_props *get_op_props(enum bm_ast_node_type type)
/* Left operators. */
[BM_AST_NODE_OP_CAST] = { OP_POS_LEFT, -2, 0 },
[BM_AST_NODE_OP_NEW] = { OP_POS_LEFT, -2, 0 },
[BM_AST_NODE_PREOP_BITWISE_NOT] = { OP_POS_LEFT, -2, 0 },
[BM_AST_NODE_PREOP_DEC] = { OP_POS_LEFT, -2, 0 },
[BM_AST_NODE_PREOP_INC] = { OP_POS_LEFT, -2, 0 },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment