X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Fnum_exp.c;h=36be5f35ea92c4f3ec71d7350df366bf35b6172f;hp=4b8846a6312cd56b00727755f57f87c066a4e5e1;hb=216e7ac3b97aed5a5d65c511dc061c78be90e79d;hpb=c9384515a81cb64d345b299908b2852f51bb8e6e diff --git a/src/types/num_exp.c b/src/types/num_exp.c index 4b8846a..36be5f3 100644 --- a/src/types/num_exp.c +++ b/src/types/num_exp.c @@ -36,7 +36,7 @@ struct psi_num_exp *psi_num_exp_init_ternary(token_t op, struct psi_num_exp *cond, struct psi_num_exp *truthy, struct psi_num_exp *falsy) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = op; exp->data.t.cond = cond; @@ -49,7 +49,7 @@ struct psi_num_exp *psi_num_exp_init_ternary(token_t op, struct psi_num_exp *psi_num_exp_init_binary(token_t op, struct psi_num_exp *lhs, struct psi_num_exp *rhs) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = op; exp->data.b.lhs = lhs; @@ -61,7 +61,7 @@ struct psi_num_exp *psi_num_exp_init_binary(token_t op, struct psi_num_exp *psi_num_exp_init_unary(token_t op, struct psi_num_exp *u) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = op; exp->data.u = u; @@ -71,7 +71,7 @@ struct psi_num_exp *psi_num_exp_init_unary(token_t op, struct psi_num_exp *psi_num_exp_init_num(struct psi_number *n) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = PSI_T_NUMBER; exp->data.n = n; @@ -82,7 +82,7 @@ struct psi_num_exp *psi_num_exp_init_num(struct psi_number *n) struct psi_num_exp *psi_num_exp_init_cast(struct psi_decl_type *typ, struct psi_num_exp *num) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = PSI_T_CAST; exp->data.c.typ = typ; @@ -99,7 +99,7 @@ struct psi_num_exp *psi_num_exp_copy(struct psi_num_exp *exp) return NULL; } - cpy = malloc(sizeof(*cpy)); + cpy = pemalloc(sizeof(*cpy), 1); *cpy = *exp; switch (exp->op) { @@ -216,9 +216,7 @@ void psi_num_exp_free(struct psi_num_exp **c_ptr) assert(0); } - if (c->token) { - free(c->token); - } + psi_token_free(&c->token); free(c); } @@ -306,7 +304,7 @@ struct psi_plist *psi_num_exp_tokens(struct psi_num_exp *exp, list = psi_plist_add(list, &ntoken); ntoken = psi_token_copy(exp->data.c.typ->token); list = psi_plist_add(list, &ntoken); - ntoken = psi_token_init(PSI_T_RPAREN, ")", 1, ntoken->col+ntoken->size, ntoken->line, ntoken->file); + ntoken = psi_token_init(PSI_T_RPAREN, ")", 1, ntoken->col+ntoken->text->len, ntoken->line, ntoken->file); list = psi_plist_add(list, &ntoken); break; @@ -323,7 +321,7 @@ struct psi_plist *psi_num_exp_tokens(struct psi_num_exp *exp, list = psi_plist_add(list, &ntoken); list = psi_num_exp_tokens(exp->data.u, list); psi_plist_top(list, &ntoken); - ntoken = psi_token_init(PSI_T_RPAREN, ")", 1, ntoken->col+ntoken->size, ntoken->line, ntoken->file); + ntoken = psi_token_init(PSI_T_RPAREN, ")", 1, ntoken->col+ntoken->text->len, ntoken->line, ntoken->file); list = psi_plist_add(list, &ntoken); break; @@ -363,7 +361,7 @@ struct psi_plist *psi_num_exp_tokens(struct psi_num_exp *exp, list = psi_plist_add(list, &ntoken); list = psi_num_exp_tokens(exp->data.t.truthy, list); psi_plist_top(list, &ntoken); - ntoken = psi_token_init(PSI_T_COLON, ":", 1, ntoken->col+ntoken->size, ntoken->line, ntoken->file); + ntoken = psi_token_init(PSI_T_COLON, ":", 1, ntoken->col+ntoken->text->len, ntoken->line, ntoken->file); list = psi_plist_add(list, &ntoken); list = psi_plist_add(list, &ntoken); list = psi_num_exp_tokens(exp->data.t.falsy, list);