scf_node_add_child(node_cast, node_var);
// '(' lp action pushed a expr before
- scf_expr_t* parent0 = scf_stack_pop(md->lp_exprs);
- scf_expr_t* parent1 = scf_stack_pop(md->lp_exprs);
+ scf_expr_t* e = scf_stack_pop(md->lp_exprs);
- scf_logd("type cast 0: d->expr: %p, d->expr->parent: %p, 0: %p, 1: %p\n",
- d->expr, d->expr->parent, parent0, parent1);
+ scf_logd("type cast: d->expr: %p, d->expr->parent: %p, e: %p\n", d->expr, d->expr->parent, e);
- assert(parent0);
+ assert(e);
- if (parent1) {
- scf_expr_free(parent0);
- parent0 = NULL;
-
- scf_expr_add_node(parent1, node_cast);
- d->expr = parent1;
-
- } else {
- scf_expr_add_node(parent0, node_cast);
- d->expr = parent0;
- }
+ scf_expr_add_node(e, node_cast);
+ d->expr = e;
scf_stack_pop(d->current_identities);
free(id);
scf_variable_t* v = _scf_operand_get(pointer);
scf_type_t* t = NULL;
scf_node_t* add;
+ scf_node_t* neg;
int ret = scf_ast_find_type_type(&t, ast, v->type);
if (ret < 0)
parent->nodes[1] = NULL;
parent->nb_nodes = 1;
+ if (SCF_OP_SUB == parent->type) {
+ neg = scf_node_alloc(parent->w, SCF_OP_NEG, NULL);
+ if (!neg) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ v = _scf_operand_get(index);
+
+ ret = scf_ast_find_type_type(&t, ast, v->type);
+ if (ret < 0)
+ goto error;
+
+ r = SCF_VAR_ALLOC_BY_TYPE(parent->w, t, v->const_flag, 0, NULL);
+ if (!r) {
+ scf_node_free(neg);
+ goto error;
+ }
+ r->local_flag = 1;
+ r->tmp_flag = 1;
+
+ neg->result = r;
+ r = NULL;
+
+ ret = scf_node_add_child(neg, index);
+ if (ret < 0) {
+ scf_node_free(neg);
+ goto error;
+ }
+
+ add->nodes[1] = neg;
+ neg->parent = add;
+ }
+
+ ret = 0;
+error:
parent->op = scf_find_base_operator_by_type(SCF_OP_ADDRESS_OF);
parent->type = SCF_OP_ADDRESS_OF;
- return 0;
+ return ret;
}
static int _semantic_pointer_add_assign(scf_ast_t* ast, scf_node_t* parent, scf_node_t* pointer, scf_node_t* index)
if (ret < 0)
return ret;
- add = scf_node_alloc(parent->w, SCF_OP_ADD, NULL);
+ if (SCF_OP_ADD_ASSIGN == parent->type)
+ add = scf_node_alloc(parent->w, SCF_OP_ADD, NULL);
+ else
+ add = scf_node_alloc(parent->w, SCF_OP_SUB, NULL);
if (!add)
return -ENOMEM;
scf_loge("var calculated with a pointer should be a interger\n");
return -EINVAL;
} else {
- t = scf_block_find_type_type(ast->current_block, SCF_VAR_UINTPTR);
+ t = scf_block_find_type_type(ast->current_block, SCF_VAR_INTPTR);
v2 = SCF_VAR_ALLOC_BY_TYPE(v1->w, t, v1->const_flag, 0, NULL);
scf_loge("var calculated with a pointer should be a interger\n");
return -EINVAL;
} else {
- t = scf_block_find_type_type(ast->current_block, SCF_VAR_UINTPTR);
+ t = scf_block_find_type_type(ast->current_block, SCF_VAR_INTPTR);
v2 = SCF_VAR_ALLOC_BY_TYPE(v1->w, t, v1->const_flag, 0, NULL);
return -1;
}
- t = scf_block_find_type_type(ast->current_block, SCF_VAR_UINTPTR);
+ t = scf_block_find_type_type(ast->current_block, SCF_VAR_INTPTR);
v2 = SCF_VAR_ALLOC_BY_TYPE(v0->w, t, v0->const_flag, 0, NULL);