diff options
Diffstat (limited to 'src/analyze.c')
-rw-r--r-- | src/analyze.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/analyze.c b/src/analyze.c index 077e7d8..ab08f01 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -2,6 +2,7 @@ /* Copyright 2024 Kim Kuparinen < kimi.h.kuparinen@gmail.com > */ #include <fwd/analyze.h> +#include <stdlib.h> #include <string.h> #include <assert.h> @@ -41,7 +42,17 @@ static int analyze_proc(struct state *state, struct scope *scope, return -1; } + size_t group = 0; foreach_node(param, proc_params(node)) { + if (param->ol == NULL && param->or == NULL) + group++; /* no opt group */ + + if (param->ol == NULL && param->or) + group++; /* start of new group */ + + /* otherwise same or ending group, don't increment */ + + param->t->group = group; type_append(&callable->t0, clone_type(param->t)); } @@ -113,6 +124,7 @@ static int analyze_comparison(struct state *state, struct scope *scope, node->t = tgen_id(tf, node->loc); if (!node->t) { internal_error("failed allocating comparison bool type"); + free(tf); return -1; } @@ -132,7 +144,12 @@ static int analyze_block(struct state *state, struct scope *scope, if (analyze_list(state, block_scope, block_body(node))) return -1; - node->t = ast_last(block_body(node))->t; + struct ast *last = ast_last(block_body(node)); + if (last) + node->t = last->t; + else + node->t = tgen_void(node->loc); + return 0; } @@ -179,7 +196,8 @@ static int analyze_init(struct state *state, struct scope *scope, /** @todo check that all parameters match, though that requires that the * type is defined in fwd and not in C++, so this might have to wait a * bit */ - node->t = tgen_construct(init_id(node), init_args(node), node->loc); + node->t = tgen_construct(strdup(init_id(node)), init_args(node), + node->loc); if (!node->t) { internal_error("failed allocating type for construct"); return -1; @@ -220,6 +238,8 @@ static int analyze_call(struct state *state, struct scope *scope, return -1; } + /* clone group info */ + arg->t->group = type->group; type = type->n; } @@ -305,6 +325,7 @@ static int analyze_int(struct state *state, struct scope *scope, node->t = tgen_id(i, node->loc); if (!node->t) { internal_error("failed allocating constant int type"); + free(i); return -1; } @@ -324,6 +345,7 @@ static int analyze_str(struct state *state, struct scope *scope, struct type *ch = tgen_id(i, node->loc); if (!ch) { internal_error("failed allocating constant char type"); + free(i); return -1; } @@ -417,6 +439,11 @@ static int analyze(struct state *state, struct scope *scope, struct ast *node) break; case AST_CONST_STR: ret = analyze_str (state, scope, node); break; + + case AST_EMPTY: + node->t = tgen_void(node->loc); + ret = 0; + break; default: internal_error("missing ast analysis for %s", ast_str(node->k)); return -1; |