self->name = name ? util_strdup(name) : NULL;
self->expression.vtype = t;
self->expression.next = NULL;
- self->isconst = false;
+ self->hasvalue = false;
self->uses = 0;
memset(&self->constval, 0, sizeof(self->constval));
{
if (self->name)
mem_d((void*)self->name);
- if (self->isconst) {
+ if (self->hasvalue) {
switch (self->expression.vtype)
{
case TYPE_STRING:
ast_instantiate(ast_function, ctx, ast_function_delete);
if (!vtype ||
- vtype->isconst ||
+ vtype->hasvalue ||
vtype->expression.vtype != TYPE_FUNCTION)
{
asterror(ast_ctx(self), "internal error: ast_function_new condition %i %i type=%i",
(int)!vtype,
- (int)vtype->isconst,
+ (int)vtype->hasvalue,
vtype->expression.vtype);
mem_d(self);
return NULL;
self->breakblock = NULL;
self->continueblock = NULL;
- vtype->isconst = true;
+ vtype->hasvalue = true;
vtype->constval.vfunc = self;
return self;
mem_d((void*)self->name);
if (self->vtype) {
/* ast_value_delete(self->vtype); */
- self->vtype->isconst = false;
+ self->vtype->hasvalue = false;
self->vtype->constval.vfunc = NULL;
/* We use unref - if it was stored in a global table it is supposed
* to be deleted from *there*
{
ir_value *v = NULL;
- if (self->isconst && self->expression.vtype == TYPE_FUNCTION)
+ if (self->hasvalue && self->expression.vtype == TYPE_FUNCTION)
{
ir_function *func = ir_builder_create_function(ir, self->name, self->expression.next->expression.vtype);
if (!func)
if (isfield && self->expression.vtype == TYPE_FIELD) {
ast_expression *fieldtype = self->expression.next;
- if (self->isconst) {
+ if (self->hasvalue) {
asterror(ast_ctx(self), "TODO: constant field pointers with value");
goto error;
}
v->context = ast_ctx(self);
}
- if (self->isconst) {
+ if (self->hasvalue) {
switch (self->expression.vtype)
{
case TYPE_FLOAT:
bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
{
ir_value *v = NULL;
- if (self->isconst && self->expression.vtype == TYPE_FUNCTION)
+ if (self->hasvalue && self->expression.vtype == TYPE_FUNCTION)
{
/* Do we allow local functions? I think not...
* this is NOT a function pointer atm.
/* A constant local... hmmm...
* I suppose the IR will have to deal with this
*/
- if (self->isconst) {
+ if (self->hasvalue) {
switch (self->expression.vtype)
{
case TYPE_FLOAT:
ai = (ast_array_index*)self->dest;
idx = (ast_value*)ai->index;
- if (ast_istype(ai->index, ast_value) && idx->isconst)
+ if (ast_istype(ai->index, ast_value) && idx->hasvalue)
ai = NULL;
}
ai = (ast_array_index*)self->dest;
idx = (ast_value*)ai->index;
- if (ast_istype(ai->index, ast_value) && idx->isconst)
+ if (ast_istype(ai->index, ast_value) && idx->hasvalue)
ai = NULL;
}
arr = (ast_value*)self->array;
idx = (ast_value*)self->index;
- if (!ast_istype(self->index, ast_value) || !idx->isconst) {
+ if (!ast_istype(self->index, ast_value) || !idx->hasvalue) {
/* Time to use accessor functions */
ast_expression_codegen *cgen;
ir_value *iridx, *funval;
return parser->imm_float[i];
}
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_FLOAT);
- out->isconst = true;
+ out->hasvalue = true;
out->constval.vfloat = d;
vec_push(parser->imm_float, out);
return out;
out = ast_value_new(parser_ctx(parser), name, TYPE_STRING);
} else
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_STRING);
- out->isconst = true;
+ out->hasvalue = true;
out->constval.vstring = parser_strdup(str);
vec_push(parser->imm_string, out);
return out;
return parser->imm_vector[i];
}
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_VECTOR);
- out->isconst = true;
+ out->hasvalue = true;
out->constval.vvec = v;
vec_push(parser->imm_vector, out);
return out;
(exprs[0]->expression.vtype != exprs[1]->expression.vtype || \
exprs[0]->expression.vtype != T)
#define CanConstFold1(A) \
- (ast_istype((A), ast_value) && ((ast_value*)(A))->isconst)
+ (ast_istype((A), ast_value) && ((ast_value*)(A))->hasvalue)
#define CanConstFold(A, B) \
(CanConstFold1(A) && CanConstFold1(B))
#define ConstV(i) (asvalue[(i)]->constval.vvec)
if (!OPTS_FLAG(RELAXED_SWITCH)) {
opval = (ast_value*)operand;
- if (!ast_istype(operand, ast_value) || !opval->isconst) {
+ if (!ast_istype(operand, ast_value) || !opval->hasvalue) {
parseerror(parser, "case on non-constant values need to be explicitly enabled via -frelaxed-switch");
ast_unref(operand);
return false;
parseerror(parser, "expected a framenumber constant in[frame,think] notation");
return false;
}
- if (!ast_istype(framenum, ast_value) || !( (ast_value*)framenum )->isconst) {
+ if (!ast_istype(framenum, ast_value) || !( (ast_value*)framenum )->hasvalue) {
ast_unref(framenum);
parseerror(parser, "framenumber in [frame,think] notation must be a constant");
return false;
}
}
- if (is_const)
- var->isconst = true;
-
/* Part 2:
* Create the global/local, and deal with vector types.
*/
break;
}
- if (var->isconst) {
+ if (var->hasvalue) {
(void)!parsewarning(parser, WARN_DOUBLE_DECLARATION,
"builtin `%s` has already been defined\n"
" -> previous declaration here: %s:%i",
if (!localblock) {
cval = (ast_value*)cexp;
- if (!ast_istype(cval, ast_value) || !cval->isconst)
+ if (!ast_istype(cval, ast_value) || !cval->hasvalue)
parseerror(parser, "cannot initialize a global constant variable with a non-constant expression");
else
{
- var->isconst = true;
+ var->hasvalue = true;
if (cval->expression.vtype == TYPE_STRING)
var->constval.vstring = parser_strdup(cval->constval.vstring);
else
for (i = 0; i < vec_size(parser->fields); ++i) {
ast_value *field;
- bool isconst;
+ bool hasvalue;
if (!ast_istype(parser->fields[i], ast_value))
continue;
field = (ast_value*)parser->fields[i];
- isconst = field->isconst;
- field->isconst = false;
+ hasvalue = field->hasvalue;
+ field->hasvalue = false;
if (!ast_global_codegen((ast_value*)field, ir, true)) {
con_out("failed to generate field %s\n", field->name);
ir_builder_delete(ir);
return false;
}
- if (isconst) {
+ if (hasvalue) {
ir_value *ifld;
ast_expression *subtype;
- field->isconst = true;
+ field->hasvalue = true;
subtype = field->expression.next;
ifld = ir_builder_create_field(ir, field->name, subtype->expression.vtype);
if (subtype->expression.vtype == TYPE_FIELD)
if (!ast_istype(parser->globals[i], ast_value))
continue;
asvalue = (ast_value*)(parser->globals[i]);
- if (!asvalue->uses && !asvalue->isconst && asvalue->expression.vtype != TYPE_FUNCTION) {
+ if (!asvalue->uses && !asvalue->hasvalue && asvalue->expression.vtype != TYPE_FUNCTION) {
if (strcmp(asvalue->name, "end_sys_globals") &&
strcmp(asvalue->name, "end_sys_fields"))
{