/*
* 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
if (!e) {
if (pos + 6 >= bufsize)
goto full;
- strncpy(buf + pos, "(null)", 6);
+ util_strncpy(buf + pos, "(null)", 6);
return pos + 6;
}
switch (e->expression.vtype) {
case TYPE_VARIANT:
- strncpy(buf + pos, "(variant)", 9);
+ util_strncpy(buf + pos, "(variant)", 9);
return pos + 9;
case TYPE_FIELD:
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++] = ']';
typelen = strlen(typestr);
if (pos + typelen >= bufsize)
goto full;
- strncpy(buf + pos, typestr, typelen);
+ util_strncpy(buf + pos, typestr, typelen);
return pos + typelen;
}
self->isfield = false;
self->cvq = CV_NONE;
self->hasvalue = false;
- self->uses = 0;
+ self->isimm = false;
+ self->uses = 0;
memset(&self->constval, 0, sizeof(self->constval));
+ self->initlist = NULL;
self->ir_v = NULL;
self->ir_values = NULL;
if (self->desc)
mem_d(self->desc);
+ if (self->initlist) {
+ if (self->expression.next->expression.vtype == TYPE_STRING) {
+ /* strings are allocated, free them */
+ size_t i, len = vec_size(self->initlist);
+ /* in theory, len should be expression.count
+ * but let's not take any chances */
+ for (i = 0; i < len; ++i) {
+ if (self->initlist[i].vstring)
+ mem_d(self->initlist[i].vstring);
+ }
+ }
+ vec_free(self->initlist);
+ }
+
ast_expression_delete((ast_expression*)self);
mem_d(self);
}
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);
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);
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);
} 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);
*/
}