Skip to content

Commit

Permalink
Check results of list functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dekrain committed Nov 20, 2022
1 parent d64cd45 commit 57aab24
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 35 deletions.
6 changes: 4 additions & 2 deletions src/driver/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ static int yf_add_file(struct yf_args * args, char * file) {
yf_set_error(args);
return 1;
}
yf_list_add(&args->files, file);
if (yf_list_add(&args->files, file) != YF_OK)
abort();
return 0;
}

Expand All @@ -65,7 +66,8 @@ void yf_parse_args(int argc, char ** argv, struct yf_args * args) {
memset(args, 0, sizeof *args);
args->wanted_output = YF_INFO_NONE;
args->run_c_comp = true;
yf_list_init(&args->files);
if (yf_list_init(&args->files) != YF_OK)
abort();

/* Start at 1 - avoid program name */
for (i = 1; i < argc; ++i) {
Expand Down
21 changes: 14 additions & 7 deletions src/driver/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,16 @@ static int yf_create_compiler_jobs(
yf_backend_find_compiler(args);

struct yf_list link_objs;
yf_list_init(&link_objs);
if (yf_list_init(&link_objs) != YF_OK)
abort();

/* Fill project info */
compilation->project_name = data->project_name;
yf_list_init(&compilation->jobs);
if (yf_list_init(&compilation->jobs) != YF_OK)
abort();
yfh_init(&compilation->symtables);
yf_list_init(&compilation->garbage);
if (yf_list_init(&compilation->garbage) != YF_OK)
abort();

struct yfh_cursor cursor;
for (yfh_cursor_init(&cursor, &data->files); yfh_cursor_next(&cursor) == YF_OK; ) {
Expand All @@ -186,7 +189,8 @@ static int yf_create_compiler_jobs(
YF_COMPILE_FULL;

yfh_cursor_set(&cursor, ujob); // Set the job for further stages
yf_list_add(&compilation->jobs, ujob);
if (yf_list_add(&compilation->jobs, ujob) != YF_OK)
abort();
}

for (yfh_cursor_init(&cursor, &data->files); yfh_cursor_next(&cursor) == YF_OK; ) {
Expand All @@ -197,11 +201,13 @@ static int yf_create_compiler_jobs(
cjob = malloc(sizeof(struct yf_compile_compile_job));
cjob->job.type = YF_COMPILATION_COMPILE;
cjob->unit = ujob;
yf_list_add(&compilation->jobs, cjob);
if (yf_list_add(&compilation->jobs, cjob) != YF_OK)
abort();

if (ujob->stage >= YF_COMPILE_CODEGENONLY) {
char * object_file = yf_backend_add_compile_job(compilation, args, ujob->unit_info);
yf_list_add(&link_objs, object_file);
if (yf_list_add(&link_objs, object_file) != YF_OK)
abort();
has_compiled_files = true;
}
}
Expand All @@ -210,7 +216,8 @@ static int yf_create_compiler_jobs(
yf_backend_add_link_job(compilation, args, &link_objs);
}

yf_list_merge(&compilation->garbage, &link_objs);
if (yf_list_merge(&compilation->garbage, &link_objs) != YF_OK)
abort();
yfh_destroy(&data->files, NULL);

return 0;
Expand Down
13 changes: 9 additions & 4 deletions src/driver/compiler-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ char * yf_backend_add_compile_job(
cjob->command[5] = "-fdollars-in-identifiers";
cjob->command[6] = NULL;

yf_list_add(&compilation->jobs, cjob);
if (yf_list_add(&compilation->jobs, cjob) != YF_OK)
abort();

return object_file;

Expand Down Expand Up @@ -214,8 +215,11 @@ int yf_backend_add_link_job(
struct yf_list_cursor link_objs_cur;
yf_list_reset_cursor(&link_objs_cur, link_objs);
for (obj_it = 0; obj_it < num_objs; ++obj_it) {
yf_list_get(&link_objs_cur, (void **)it);
yf_list_next(&link_objs_cur);
if (yf_list_get(&link_objs_cur, (void **)it) != YF_OK ||
yf_list_next(&link_objs_cur) != YF_OK)

abort();

++it;
}

Expand All @@ -234,7 +238,8 @@ int yf_backend_add_link_job(
ljob->job.type = YF_COMPILATION_EXEC;
ljob->command = link_cmd;

yf_list_add(&compilation->jobs, ljob);
if (yf_list_add(&compilation->jobs, ljob) != YF_OK)
abort();

return 0;

Expand Down
6 changes: 4 additions & 2 deletions src/parser/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ int yfp_funcdecl(struct yf_parse_node * node, struct yf_lexer * lexer) {
node->funcdecl.extc = false;

/* Start arg list for writing */
yf_list_init(&node->funcdecl.params);
if (yf_list_init(&node->funcdecl.params) != YF_OK)
abort();
argct = 0;

for (;;) {
Expand Down Expand Up @@ -61,7 +62,8 @@ int yfp_funcdecl(struct yf_parse_node * node, struct yf_lexer * lexer) {
++argct;

/* Add to arg list */
yf_list_add(&node->funcdecl.params, argp);
if (yf_list_add(&node->funcdecl.params, argp) != YF_OK)
abort();

}

Expand Down
12 changes: 8 additions & 4 deletions src/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ int yfp_program(struct yf_parse_node * node, struct yf_lexer * lexer) {
node->loc.line = node->loc.column = -1;

node->type = YFCS_PROGRAM;
yf_list_init(&node->program.decls);
if (yf_list_init(&node->program.decls) != YF_OK)
abort();

for (;;) {

Expand Down Expand Up @@ -78,7 +79,8 @@ int yfp_program(struct yf_parse_node * node, struct yf_lexer * lexer) {
}

/* Now, we have a node - add it to the list. */
yf_list_add(&node->program.decls, decl);
if (yf_list_add(&node->program.decls, decl) != YF_OK)
abort();

}

Expand Down Expand Up @@ -258,7 +260,8 @@ int yfp_bstmt(struct yf_parse_node * node, struct yf_lexer * lexer) {
P_GETCT(node, tok);

node->type = YFCS_BSTMT;
yf_list_init(&node->bstmt.stmts);
if (yf_list_init(&node->bstmt.stmts) != YF_OK)
abort();

for (;;) {
P_PEEK(lexer, &tok);
Expand All @@ -272,7 +275,8 @@ int yfp_bstmt(struct yf_parse_node * node, struct yf_lexer * lexer) {
free(stmt);
return 1;
}
yf_list_add(&node->bstmt.stmts, stmt);
if (yf_list_add(&node->bstmt.stmts, stmt) != YF_OK)
abort();
}

}
6 changes: 4 additions & 2 deletions src/parser/stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ int yfp_funccall(struct yf_parse_node * node, struct yf_lexer * lexer) {
*/

/* Start arg list for writing */
yf_list_init(&node->expr.call.args);
if (yf_list_init(&node->expr.call.args) != YF_OK)
abort();
argct = 0;

for (;;) {
Expand Down Expand Up @@ -143,7 +144,8 @@ int yfp_funccall(struct yf_parse_node * node, struct yf_lexer * lexer) {
++argct;

/* Add to arg list */
yf_list_add(&node->expr.call.args, argp);
if (yf_list_add(&node->expr.call.args, argp) != YF_OK)
abort();

}

Expand Down
6 changes: 4 additions & 2 deletions src/semantics/symtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ static int yfs_add_fn(struct yf_hashmap * symtab, struct yf_parse_node * f) {

fsym->fn.name = fn->name.name;

yf_list_init(&fsym->fn.params);
if (yf_list_init(&fsym->fn.params) != YF_OK)
abort();

/* Adding parameters to symbol */
YF_LIST_FOREACH(fn->params, narg) {
Expand All @@ -99,7 +100,8 @@ static int yfs_add_fn(struct yf_hashmap * symtab, struct yf_parse_node * f) {

param->name = arg->name.name;
param->type = arg->type.databuf;
yf_list_add(&fsym->fn.params, param);
if (yf_list_add(&fsym->fn.params, param) != YF_OK)
abort();

}

Expand Down
11 changes: 7 additions & 4 deletions src/semantics/validate/validate-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ static int validate_funccall(
* the types are compatible for each one and the number of arguments
* matches.
*/
yf_list_init(&a->args);
if (yf_list_init(&a->args) != YF_OK)
abort();
yf_list_reset_cursor(&param_cursor, &a->name->fn.params);
yf_list_reset_cursor(&arg_cursor, &c->args);
for (;;) {
Expand Down Expand Up @@ -256,9 +257,11 @@ static int validate_funccall(
return 1;
}

yf_list_add(&a->args, aarg);
yf_list_next(&arg_cursor);
yf_list_next(&param_cursor);
if (yf_list_add(&a->args, aarg) != YF_OK ||
yf_list_next(&arg_cursor) != YF_OK ||
yf_list_next(&param_cursor) != YF_OK)

abort();

}

Expand Down
12 changes: 8 additions & 4 deletions src/semantics/validate/validate-func.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ int validate_funcdecl(
enter_scope(validator, &a->param_scope);

/* Add the arguments to the scope. */
yf_list_init(&a->params);
if (yf_list_init(&a->params) != YF_OK)
abort();
YF_LIST_FOREACH(c->params, cv) {
av = yf_malloc(sizeof (struct yf_ast_node));
if (!av)
Expand All @@ -51,7 +52,8 @@ int validate_funcdecl(
validator->error = 1;
return 1;
}
yf_list_add(&a->params, av);
if (yf_list_add(&a->params, av) != YF_OK)
abort();
}

/* Validate the return type. */
Expand Down Expand Up @@ -131,7 +133,8 @@ int validate_bstmt(
enter_scope(validator, &a->symtab);

/* Validate each statement */
yf_list_init(&a->stmts);
if (yf_list_init(&a->stmts) != YF_OK)
abort();

*returns = 0;

Expand Down Expand Up @@ -161,7 +164,8 @@ int validate_bstmt(
} else {

/* Move to abstract list */
yf_list_add(&a->stmts, asub);
if (yf_list_add(&a->stmts, asub) != YF_OK)
abort();

/* Probably redundant */
if (asub->type == YFA_RETURN) {
Expand Down
11 changes: 7 additions & 4 deletions src/semantics/validate/validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ int validate_program(
aprog = &ain->program;
ain->type = YFA_PROGRAM;

yf_list_init(&aprog->decls);

if (yf_list_init(&aprog->decls) != YF_OK)
abort();

/* Iterate through all decls, construct abstract instances of them, and move
them into the abstract list. */
YF_LIST_FOREACH(cprog->decls, cnode) {
Expand All @@ -130,8 +131,10 @@ int validate_program(
}

/* Move to abstract list */
if (anode)
yf_list_add(&aprog->decls, anode);
if (anode) {
if (yf_list_add(&aprog->decls, anode) != YF_OK)
abort();
}
}

return err;
Expand Down
1 change: 1 addition & 0 deletions src/util/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "allocator.h"
#include "result.h"
#include "platform.h"
#include <stdbool.h>

#define YFH_INIT_BUCKETS (0x1000 / sizeof(void*))
Expand Down

0 comments on commit 57aab24

Please sign in to comment.