mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-23 20:33:05 +00:00
ast_value now has an initializer list array, still unused but it's there for later
This commit is contained in:
parent
b3e9ef3ad9
commit
9f8bee4bf1
3 changed files with 47 additions and 11 deletions
17
ast.c
17
ast.c
|
@ -317,8 +317,9 @@ ast_value* ast_value_new(lex_ctx ctx, const char *name, int t)
|
|||
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;
|
||||
|
@ -362,6 +363,20 @@ void ast_value_delete(ast_value* self)
|
|||
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);
|
||||
}
|
||||
|
|
24
ast.h
24
ast.h
|
@ -161,6 +161,15 @@ typedef struct
|
|||
* 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;
|
||||
|
@ -179,15 +188,12 @@ struct ast_value_s
|
|||
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;
|
||||
|
|
17
parser.c
17
parser.c
|
@ -5725,7 +5725,22 @@ skipvar:
|
|||
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");
|
||||
|
|
Loading…
Reference in a new issue