X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.c;h=3e5d304d1e53c6ba9666f56ddfd6aafdc4bc94c8;hp=38c95a4f3dcf3d8b3ff449162a18ecf3439dd5c8;hb=69b55ccc03b56af1f6c05eb45866ab198307487f;hpb=48d6375817d3834e934bec6849cdd08daaa3c9b2 diff --git a/ast.c b/ast.c index 38c95a4..3e5d304 100644 --- a/ast.c +++ b/ast.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2012, 2013 * Wolfgang Bumiller - * Dale Weiler + * Dale Weiler * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -42,7 +42,7 @@ static GMQCC_NORETURN void _ast_node_destroy(ast_node *self) { (void)self; con_err("ast node missing destroy()\n"); - abort(); + exit(EXIT_FAILURE); } /* Initialize main ast node aprts */ @@ -87,6 +87,8 @@ static void ast_expression_delete(ast_expression *self) ast_delete(self->expression.params[i]); } vec_free(self->expression.params); + if (self->expression.varparam) + ast_delete(self->expression.varparam); } static void ast_expression_delete_full(ast_expression *self) @@ -218,7 +220,7 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi if (!e) { if (pos + 6 >= bufsize) goto full; - strncpy(buf + pos, "(null)", 6); + util_strncpy(buf + pos, "(null)", 6); return pos + 6; } @@ -227,7 +229,7 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi switch (e->expression.vtype) { case TYPE_VARIANT: - strncpy(buf + pos, "(variant)", 9); + util_strncpy(buf + pos, "(variant)", 9); return pos + 9; case TYPE_FIELD: @@ -273,7 +275,7 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi if (pos + 1 >= bufsize) goto full; buf[pos++] = '['; - pos += snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->expression.count); + pos += util_snprintf(buf + pos, bufsize - pos - 1, "%i", (int)e->expression.count); if (pos + 1 >= bufsize) goto full; buf[pos++] = ']'; @@ -284,7 +286,7 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi typelen = strlen(typestr); if (pos + typelen >= bufsize) goto full; - strncpy(buf + pos, typestr, typelen); + util_strncpy(buf + pos, typestr, typelen); return pos + typelen; } @@ -314,6 +316,7 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t) self->isfield = false; self->cvq = CV_NONE; self->hasvalue = false; + self->isimm = false; self->uses = 0; memset(&self->constval, 0, sizeof(self->constval)); @@ -584,6 +587,7 @@ void ast_member_delete(ast_member *self) * purpose that is not garbage-collected. */ ast_expression_delete((ast_expression*)self); + mem_d(self->name); mem_d(self); } @@ -1216,12 +1220,12 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) namelen = strlen(self->name); name = (char*)mem_a(namelen + 16); - strncpy(name, self->name, namelen); + util_strncpy(name, self->name, namelen); array->ir_values = (ir_value**)mem_a(sizeof(array->ir_values[0]) * array->expression.count); array->ir_values[0] = v; for (ai = 1; ai < array->expression.count; ++ai) { - snprintf(name + namelen, 16, "[%u]", (unsigned int)ai); + util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai); array->ir_values[ai] = ir_builder_create_field(ir, name, vtype); if (!array->ir_values[ai]) { mem_d(name); @@ -1274,12 +1278,12 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield) namelen = strlen(self->name); name = (char*)mem_a(namelen + 16); - strncpy(name, self->name, namelen); + util_strncpy(name, self->name, namelen); self->ir_values = (ir_value**)mem_a(sizeof(self->ir_values[0]) * self->expression.count); self->ir_values[0] = v; for (ai = 1; ai < self->expression.count; ++ai) { - snprintf(name + namelen, 16, "[%u]", (unsigned int)ai); + util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai); self->ir_values[ai] = ir_builder_create_global(ir, name, vtype); if (!self->ir_values[ai]) { mem_d(name); @@ -1416,11 +1420,11 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param) namelen = strlen(self->name); name = (char*)mem_a(namelen + 16); - strncpy(name, self->name, namelen); + util_strncpy(name, self->name, namelen); self->ir_values[0] = v; for (ai = 1; ai < self->expression.count; ++ai) { - snprintf(name + namelen, 16, "[%u]", (unsigned int)ai); + util_snprintf(name + namelen, 16, "[%u]", (unsigned int)ai); self->ir_values[ai] = ir_function_create_local(func, name, vtype, param); if (!self->ir_values[ai]) { compile_error(ast_ctx(self), "internal_error: ir_builder_create_global failed on `%s`", name); @@ -1430,6 +1434,7 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param) self->ir_values[ai]->unique_life = true; self->ir_values[ai]->locked = true; } + mem_d(name); } else { @@ -2127,7 +2132,7 @@ bool ast_entfield_codegen(ast_entfield *self, ast_function *func, bool lvalue, i } else { *out = ir_block_create_load_from_ent(func->curblock, ast_ctx(self), ast_function_label(func, "efv"), ent, field, self->expression.vtype); - /* Done AFTER error checking: + /* Done AFTER error checking: codegen_output_type(self, *out); */ }