X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.c;h=3e5d304d1e53c6ba9666f56ddfd6aafdc4bc94c8;hp=b1b7ba826cc9b7a3d085c993fbcd3a1c24e0c58e;hb=75ceab8f51954450e6228d9d640969b8f5c387b8;hpb=ef528d6710d597bad5462f4fbf1c5a6a54cb2a10 diff --git a/ast.c b/ast.c index b1b7ba8..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 @@ -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)); @@ -1217,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); @@ -1275,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); @@ -1417,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); @@ -1431,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 { @@ -2128,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); */ }