diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/analyze.c | 176 | ||||
| -rw-r--r-- | src/compiler.c | 6 | ||||
| -rw-r--r-- | src/debug.c | 8 | ||||
| -rw-r--r-- | src/move.c | 22 | ||||
| -rw-r--r-- | src/rewrite.c | 4 | ||||
| -rw-r--r-- | src/scope.c | 8 |
6 files changed, 145 insertions, 79 deletions
diff --git a/src/analyze.c b/src/analyze.c index fc94e15..fd1aabb 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -21,7 +21,8 @@ struct state { }; static int analyze(struct state *state, struct scope *scope, struct ast *node); -static int analyze_known_block(struct state *state, struct scope *scope, struct ast *node); +static int analyze_known_block(struct state *state, struct scope *scope, + struct ast *node); static int analyze_list(struct state *state, struct scope *scope, struct ast *nodes); @@ -157,7 +158,8 @@ static int analyze_comparison(struct state *state, struct scope *scope, return 0; } -static int analyze_known_block(struct state *state, struct scope *scope, struct ast *node) +static int analyze_known_block(struct state *state, struct scope *scope, + struct ast *node) { assert(node && node->k == AST_BLOCK); @@ -229,7 +231,8 @@ static int analyze_init(struct state *state, struct scope *scope, return -1; } -static int deduce_closure_types(struct scope *scope, struct ast *node, struct type *type) +static int deduce_closure_types(struct scope *scope, struct ast *node, + struct type *type) { /* a bit of checking duplication here, hmm */ if (node->k != AST_CLOSURE) @@ -242,13 +245,15 @@ static int deduce_closure_types(struct scope *scope, struct ast *node, struct ty struct ast *param = closure_bindings(node); struct type *t = (type->k == TYPE_CLOSURE) - ? tclosure_args(type) - : tpure_closure_args(type) - ; + ? tclosure_args(type) + : tpure_closure_args(type) + ; if (ast_list_len(param) != type_list_len(t)) { - semantic_error(scope, node, "expected %zu closure parameters, got %zu", - type_list_len(t), ast_list_len(param)); + semantic_error(scope, node, + "expected %zu closure parameters, got %zu", + type_list_len(t), ast_list_len(param) + ); return -1; } @@ -286,7 +291,8 @@ static int analyze_call(struct state *state, struct scope *scope, size_t got = ast_list_len(args); if (expected != got) { semantic_error(scope, node, "expected %d params, got %d", - expected, got); + expected, got + ); return -1; } @@ -351,15 +357,18 @@ static int analyze_deref(struct state *state, struct scope *scope, if (expr->t->k == TYPE_PTR) { semantic_error(node->scope, node, - "deref of raw ptr not allowed"); + "deref of raw ptr not allowed" + ); semantic_info(node->scope, node, - "use a nil check to convert to ref"); + "use a nil check to convert to ref" + ); return -1; } if (expr->t->k != TYPE_REF) { semantic_error(node->scope, node, - "deref of something not a reference"); + "deref of something not a reference" + ); return -1; } @@ -373,7 +382,8 @@ static int analyze_id(struct state *state, struct scope *scope, struct ast *found = file_scope_find_symbol(scope, id_str(node)); if (!found) { semantic_error(scope, node, "no symbol named \"%s\"", - id_str(node)); + id_str(node) + ); return -1; } @@ -468,7 +478,8 @@ static int analyze_str(struct state *state, struct scope *scope, return 0; } -static int analyze_template(struct state *state, struct scope *scope, struct ast *node) +static int analyze_template(struct state *state, struct scope *scope, + struct ast *node) { struct scope *template_scope = create_scope(); scope_add_scope(scope, template_scope); @@ -479,14 +490,17 @@ static int analyze_template(struct state *state, struct scope *scope, struct ast return 0; } -static int analyze_instance(struct state *state, struct scope *scope, struct ast *node) +static int analyze_instance(struct state *state, struct scope *scope, + struct ast *node) { (void)state; struct ast *id = instance_templ(node); struct ast *template = file_scope_find_template(scope, id_str(id)); if (!template) { - semantic_error(scope, node, "no such template: %s\n", id_str(id)); + semantic_error(scope, node, "no such template: %s\n", + id_str(id) + ); return -1; } @@ -495,7 +509,8 @@ static int analyze_instance(struct state *state, struct scope *scope, struct ast struct type *args = instance_type_args(node); if (ast_list_len(params) != type_list_len(args)) { semantic_error(scope, node, "expected %zu types, got %zu\n", - ast_list_len(params), type_list_len(args)); + ast_list_len(params), type_list_len(args) + ); return -1; } @@ -528,7 +543,8 @@ static int analyze_instance(struct state *state, struct scope *scope, struct ast return 0; } -static int analyze_struct(struct state *state, struct scope *scope, struct ast *node) +static int analyze_struct(struct state *state, struct scope *scope, + struct ast *node) { struct scope *struct_scope = create_scope(); scope_add_scope(scope, struct_scope); @@ -541,11 +557,14 @@ static int analyze_struct(struct state *state, struct scope *scope, struct ast * return 0; } -static int analyze_construct(struct state *state, struct scope *scope, struct ast *node) +static int analyze_construct(struct state *state, struct scope *scope, + struct ast *node) { struct ast *def = file_scope_find_type(scope, construct_id(node)); if (!def) { - semantic_error(scope, node, "no such type: %s", construct_id(node)); + semantic_error(scope, node, "no such type: %s", + construct_id(node) + ); return -1; } @@ -559,15 +578,20 @@ static int analyze_construct(struct state *state, struct scope *scope, struct as if (ast_list_len(params) != ast_list_len(args)) { semantic_error(scope, node, "expected %zu args, got %zu\n", - ast_list_len(params), ast_list_len(args)); + ast_list_len(params), ast_list_len(args) + ); return -1; } foreach_node(arg, args) { - struct ast *exists = scope_find_symbol(def->scope, construction_id(arg)); + struct ast *exists = scope_find_symbol(def->scope, + construction_id(arg) + ); if (!exists) { semantic_error(scope, arg, "no member %s in %s\n", - construction_id(arg), construct_id(node)); + construction_id(arg), + construct_id(node) + ); return -1; } @@ -588,7 +612,8 @@ static int analyze_construct(struct state *state, struct scope *scope, struct as return 0; } -static int analyze_explode(struct state *state, struct scope *scope, struct ast *node) +static int analyze_explode(struct state *state, struct scope *scope, + struct ast *node) { if (analyze(state, scope, explode_expr(node))) return -1; @@ -597,8 +622,9 @@ static int analyze_explode(struct state *state, struct scope *scope, struct ast if (type->k != TYPE_ID) { char *str = type_str(type); semantic_error(scope, explode_expr(node), - "expected struct type, got %s\n", - str); + "expected struct type, got %s\n", + str + ); free(str); return -1; } @@ -606,8 +632,9 @@ static int analyze_explode(struct state *state, struct scope *scope, struct ast struct ast *def = file_scope_find_type(scope, type->id); if (!def || def->k != AST_STRUCT_DEF) { semantic_error(scope, explode_expr(node), - "no such struct type: %s\n", - type->id); + "no such struct type: %s\n", + type->id + ); return -1; } @@ -616,16 +643,20 @@ static int analyze_explode(struct state *state, struct scope *scope, struct ast if (ast_list_len(params) != ast_list_len(args)) { semantic_error(scope, node, "expected %zu args, got %zu\n", - ast_list_len(params), ast_list_len(args)); + ast_list_len(params), ast_list_len(args) + ); return -1; } foreach_node(arg, args) { struct ast *var = deconstruction_var(arg); - struct ast *exists = scope_find_symbol(def->scope, deconstruction_id(arg)); + struct ast *exists = scope_find_symbol(def->scope, + deconstruction_id(arg) + ); if (!exists) { semantic_error(scope, arg, "no member %s in %s\n", - deconstruction_id(arg), type->id); + deconstruction_id(arg), type->id + ); return -1; } @@ -672,7 +703,8 @@ static int analyze_if(struct state *state, struct scope *scope, return 0; } -static int analyze_nil(struct state *state, struct scope *scope, struct ast *node) +static int analyze_nil(struct state *state, struct scope *scope, + struct ast *node) { (void)state; (void)scope; @@ -703,7 +735,8 @@ static bool castable_type(struct type *type) return false; } -static int analyze_as(struct state *state, struct scope *scope, struct ast *node) +static int analyze_as(struct state *state, struct scope *scope, + struct ast *node) { if (analyze(state, scope, as_expr(node))) return -1; @@ -734,7 +767,8 @@ static int analyze_as(struct state *state, struct scope *scope, struct ast *node return 0; } -static int analyze_sizeof(struct state *state, struct scope *scope, struct ast *node) +static int analyze_sizeof(struct state *state, struct scope *scope, + struct ast *node) { if (analyze_type(state, scope, sizeof_type(node))) return -1; @@ -744,7 +778,8 @@ static int analyze_sizeof(struct state *state, struct scope *scope, struct ast * return 0; } -static int analyze_nil_check(struct state *state, struct scope *scope, struct ast *node) +static int analyze_nil_check(struct state *state, struct scope *scope, + struct ast *node) { struct ast *expr = nil_check_expr(node); if (analyze(state, scope, expr)) @@ -781,7 +816,8 @@ static int analyze_nil_check(struct state *state, struct scope *scope, struct as return 0; } -static int analyze_forget(struct state *state, struct scope *scope, struct ast *node) +static int analyze_forget(struct state *state, struct scope *scope, + struct ast *node) { struct ast *def = file_scope_find_symbol(scope, forget_id(node)); if (!def) { @@ -793,7 +829,8 @@ static int analyze_forget(struct state *state, struct scope *scope, struct ast * return 0; } -static int analyze_put(struct state *state, struct scope *scope, struct ast *put) +static int analyze_put(struct state *state, struct scope *scope, + struct ast *put) { struct ast *dst = put_dst(put); if (analyze(state, scope, dst)) @@ -802,7 +839,9 @@ static int analyze_put(struct state *state, struct scope *scope, struct ast *put struct type *type = dst->t; if (type->k != TYPE_REF) { char *str = type_str(type); - semantic_error(scope, put, "trying to write to non-ref type %s\n", str); + semantic_error(scope, put, + "trying to write to non-ref type %s\n", str + ); free(str); return -1; } @@ -811,7 +850,8 @@ static int analyze_put(struct state *state, struct scope *scope, struct ast *put return 0; } -static int analyze_write(struct state *state, struct scope *scope, struct ast *write) +static int analyze_write(struct state *state, struct scope *scope, + struct ast *write) { struct ast *src = write_src(write); if (analyze(state, scope, src)) @@ -1125,14 +1165,15 @@ static struct type *fwd_type_kind(fwd_type_t type) case FWD_U64: return tgen_type(TYPE_U64, NULL, NULL, NULL_LOC()); case FWD_PTR: return tgen_nil(NULL_LOC()); default: - break; + break; } abort(); return NULL; } -int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, fwd_type_t rtype, ...) +int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, + fwd_type_t rtype, ...) { struct scope *scope = (void *)state; struct ast *vars = NULL; @@ -1153,7 +1194,9 @@ int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, f assert(name); sprintf(name, "%s%zu", "var", idx); - struct ast *new = gen_var(name, fwd_type_kind(type), NULL_LOC()); + struct ast *new = gen_var(name, fwd_type_kind(type), + NULL_LOC() + ); if (vars) new->n = vars; @@ -1167,8 +1210,12 @@ int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, f if (rtype != FWD_VOID) { char *name = strdup("ret"); struct ast *new = gen_var(name, - tgen_closure(fwd_type_kind(rtype), NULL_LOC()), - NULL_LOC()); + tgen_closure( + fwd_type_kind(rtype), + NULL_LOC() + ), + NULL_LOC() + ); if (vars) new->n = vars; @@ -1178,7 +1225,8 @@ int fwd_register(struct fwd_state *state, const char *name, fwd_extern_t func, f vars = reverse_ast_list(vars); struct ast *def = gen_proc(strdup(name), vars, - fwd_type_kind(rtype), NULL, NULL_LOC()); + fwd_type_kind(rtype), NULL, NULL_LOC() + ); if (scope_add_symbol(scope, def)) return -1; @@ -1191,23 +1239,23 @@ int analyze_root(struct scope *scope, struct ast *root) foreach_node(node, root) { switch (node->k) { case AST_PROC_DEF: - if (scope_add_symbol(scope, node)) - return -1; - break; + if (scope_add_symbol(scope, node)) + return -1; + break; case AST_STRUCT_DEF: - if (scope_add_type(scope, node)) - return -1; - break; + if (scope_add_type(scope, node)) + return -1; + break; case AST_STRUCT_CONT: - abort(); - break; + abort(); + break; case AST_TRAIT_DEF: - if (scope_add_trait(scope, node)) - return -1; - break; + if (scope_add_trait(scope, node)) + return -1; + break; case AST_IMPORT: { if (!try_import_mod(scope, node)) @@ -1220,20 +1268,20 @@ int analyze_root(struct scope *scope, struct ast *root) } case AST_TEMPLATE: - if (scope_add_template(scope, node)) - return -1; - break; + if (scope_add_template(scope, node)) + return -1; + break; case AST_SUPERTEMPLATE: - if (scope_add_template(scope, node)) - return -1; - break; + if (scope_add_template(scope, node)) + return -1; + break; case AST_INSTANCE: - break; + break; default: - abort(); + abort(); } } diff --git a/src/compiler.c b/src/compiler.c index 5de992d..f367f9a 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -151,7 +151,8 @@ struct scope *compile_file(const char *file) if (*dir != 0 && chdir(dir)) { error("couldn't change to directory %s: %s", dir, - strerror(errno)); + strerror(errno) + ); goto out; } @@ -176,7 +177,8 @@ struct scope *compile_file(const char *file) if (chdir(cwd)) { error("couldn't change back to directory %s: %s", cwd, - strerror(errno)); + strerror(errno) + ); goto out; } diff --git a/src/debug.c b/src/debug.c index 538fdfe..2426277 100644 --- a/src/debug.c +++ b/src/debug.c @@ -74,7 +74,8 @@ static void _issue(struct src_issue issue, const char *fmt, va_list args) { /* get start and end of current line in buffer */ const char *line_start = find_lineno(issue.fctx.fbuf, - (size_t)issue.loc.first_line); + (size_t)issue.loc.first_line + ); const char *line_end = strchr(line_start, '\n'); if (!line_end) line_end = strchr(line_start, 0); @@ -84,7 +85,8 @@ static void _issue(struct src_issue issue, const char *fmt, va_list args) fprintf(stderr, "%s:%i:%i: %s: ", issue.fctx.fname, issue.loc.first_line, issue.loc.first_col, - issue_level_str(issue.level)); + issue_level_str(issue.level) + ); vfprintf(stderr, fmt, args); fputc('\n', stderr); @@ -135,7 +137,7 @@ void semantic_error(struct scope *scope, struct ast *node, } void type_error(struct scope *scope, struct type *type, - const char *fmt, ...) + const char *fmt, ...) { va_list args; va_start(args, fmt); @@ -140,7 +140,8 @@ static void forget_references(struct state *state) static int mvcheck_expr(struct state *state, struct ast *node); static int mvcheck_expr_list(struct state *state, struct ast *nodes); -static int mvcheck_statements(struct state *state, struct ast *nodes, bool last); +static int mvcheck_statements(struct state *state, struct ast *nodes, + bool last); static int refcheck_id(struct state *state, struct ast *node) { @@ -176,7 +177,8 @@ static int refcheck(struct state *state, struct ast *node) case AST_ID: return refcheck_id(state, node); default: internal_error("unhandled node %s for refcheck", - ast_str(node->k)); + ast_str(node->k) + ); return -1; } @@ -213,7 +215,9 @@ static int total_check_single(struct state *state, struct scope *scope) if (prev) continue; - semantic_warn(scope, def, "%s not moved, might leak", var_id(def)); + semantic_warn(scope, def, "%s not moved, might leak", + var_id(def) + ); ret |= 1; } @@ -304,7 +308,8 @@ static int mvcheck_call(struct state *state, struct ast *node, bool last) if (!last && (groups > 0)) { semantic_error(node->scope, node, - "calls with closures must currently be exit points, sorry!"); + "calls with closures must currently be exit points, sorry!" + ); return -1; } @@ -390,7 +395,8 @@ static int mvcheck_id(struct state *state, struct ast *node) if (in_pure(state)) { semantic_error(node->scope, node, - "move in pure context not allowed"); + "move in pure context not allowed" + ); return -1; } @@ -432,7 +438,8 @@ static int mvcheck_if(struct state *state, struct ast *node, bool last) { if (!last) { semantic_error(node->scope, node, - "`if` statements must currently be exit points, sorry!"); + "`if` statements must currently be exit points, sorry!" + ); return -1; } @@ -518,7 +525,8 @@ static int mvcheck_nil_check(struct state *state, struct ast *node, bool last) if (!last) { /** @todo would this be an internal error? */ semantic_error(node->scope, node, - "`nil check` must be exit point, sorry"); + "`nil check` must be exit point, sorry" + ); return -1; } diff --git a/src/rewrite.c b/src/rewrite.c index e3cea01..c5a497a 100644 --- a/src/rewrite.c +++ b/src/rewrite.c @@ -36,7 +36,9 @@ static int rewrite_type_visit(struct ast *node, struct type_helper *helper) int rewrite_types(struct ast *node, char *orig, char *new) { struct type_helper helper = {.orig = orig, .new = new}; - return ast_visit((ast_callback_t)rewrite_type_visit, NULL, node, &helper); + return ast_visit((ast_callback_t)rewrite_type_visit, NULL, node, + &helper + ); } /* not the fastest thing in the world but should work well enough for now */ diff --git a/src/scope.c b/src/scope.c index e49b828..251edef 100644 --- a/src/scope.c +++ b/src/scope.c @@ -71,7 +71,9 @@ void destroy_scope(struct scope *scope) int scope_add_symbol(struct scope *scope, struct ast *symbol) { assert(symbol->k == AST_VAR_DEF || symbol->k == AST_PROC_DEF); - struct ast **exists = visible_insert(&scope->symbols, symbol->s, symbol); + struct ast **exists = visible_insert(&scope->symbols, symbol->s, + symbol + ); if (!exists) { internal_error("failed inserting symbol into scope"); return -1; @@ -187,7 +189,9 @@ struct ast *file_scope_find_trait(struct scope *scope, char *id) int scope_add_template(struct scope *scope, struct ast *template) { - struct ast **exists = visible_insert(&scope->templates, template->s, template); + struct ast **exists = visible_insert(&scope->templates, template->s, + template + ); if (!exists) { internal_error("failed inserting template into scope"); return -1; |
