self->inexact = 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->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);
+ // initlist imples an array which implies .next in the expression exists.
+ if (self->initlist.size() && self->expression.next->vtype == TYPE_STRING) {
+ for (auto &it : self->initlist)
+ if (it.vstring)
+ mem_d(it.vstring);
}
ast_expression_delete((ast_expression*)self);
static bool ast_global_array_set(ast_value *self)
{
- size_t count = vec_size(self->initlist);
+ size_t count = self->initlist.size();
size_t i;
if (count > self->expression.count) {
static bool check_array(ast_value *self, ast_value *array)
{
- if (array->expression.flags & AST_FLAG_ARRAY_INIT && !array->initlist) {
+ if (array->expression.flags & AST_FLAG_ARRAY_INIT && array->initlist.empty()) {
compile_error(ast_ctx(self), "array without size: %s", self->name);
return false;
}
* is like creating a 'float foo', foo serving as the type's name.
*/
union basic_value_t {
- qcfloat_t vfloat;
- int vint;
- vec3_t vvec;
- const char *vstring;
- int ventity;
+ qcfloat_t vfloat;
+ int vint;
+ vec3_t vvec;
+ const char *vstring;
+ int ventity;
ast_function *vfunc;
- ast_value *vfield;
+ ast_value *vfield;
};
struct ast_value
* of constants when an initializer list
* was provided.
*/
- basic_value_t *initlist;
+ std::vector<basic_value_t> initlist;
/* usecount for the parser */
size_t uses;
if (fold_can_1(a) && isstring(a))
return fold_constgen_float(fold, strlen(fold_immvalue_string(a)), false);
if (isarray(a))
- return fold_constgen_float(fold, vec_size(a->initlist), false);
+ return fold_constgen_float(fold, a->initlist.size(), false);
return NULL;
}
static bool parse_array(parser_t *parser, ast_value *array)
{
size_t i;
- if (array->initlist) {
+ if (array->initlist.size()) {
parseerror(parser, "array already initialized elsewhere");
return false;
}
parseerror(parser, "initializing element must be a compile time constant");
return false;
}
- vec_push(array->initlist, v->constval);
+ array->initlist.push_back(v->constval);
if (v->expression.vtype == TYPE_STRING) {
array->initlist[i].vstring = util_strdupe(array->initlist[i].vstring);
++i;
parseerror(parser, "array `%s' has already been initialized with %u elements",
array->name, (unsigned)array->expression.count);
}
- array->expression.count = vec_size(array->initlist);
+ array->expression.count = array->initlist.size();
if (!create_array_accessors(parser, array))
return false;
}