self->cvq = CV_NONE;
self->hasvalue = false;
self->isimm = false;
- self->uses = 0;
+ 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);
}
* typedef float foo;
* is like creating a 'float foo', foo serving as the type's name.
*/
+typedef union {
+ double vfloat;
+ int vint;
+ vector vvec;
+ const char *vstring;
+ int ventity;
+ ast_function *vfunc;
+ ast_value *vfield;
+} basic_value_t;
struct ast_value_s
{
ast_expression_common expression;
bool isfield; /* this declares a field */
bool isimm; /* an immediate, not just const */
bool hasvalue;
- union {
- double vfloat;
- int vint;
- vector vvec;
- const char *vstring;
- int ventity;
- ast_function *vfunc;
- ast_value *vfield;
- } constval;
+ basic_value_t constval;
+ /* for TYPE_ARRAY we have an optional vector
+ * of constants when an initializer list
+ * was provided.
+ */
+ basic_value_t *initlist;
/* usecount for the parser */
size_t uses;
break;
}
}
- else if (parser->tok == '{' || parser->tok == '[')
+ else if (var->expression.vtype == TYPE_ARRAY && parser->tok == '{')
+ {
+ if (localblock) {
+ /* Note that fteqcc and most others don't even *have*
+ * local arrays, so this is not a high priority.
+ */
+ parseerror(parser, "TODO: initializers for local arrays");
+ break;
+ }
+ /*
+static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels);
+*/
+ parseerror(parser, "TODO: initializing global arrays is not supported yet!");
+ break;
+ }
+ else if (var->expression.vtype == TYPE_FUNCTION && (parser->tok == '{' || parser->tok == '['))
{
if (localblock) {
parseerror(parser, "cannot declare functions within functions");