ast_member_new now fixed up for fields, ast_shallow_type added for creation of a type-only ast_expression

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-11 22:14:16 +02:00
parent 060bddb922
commit 56c23dc11e

30
ast.c
View file

@ -94,6 +94,15 @@ static ast_value* ast_value_copy(const ast_value *self)
return cp;
}
static ast_expression* ast_shallow_type(lex_ctx ctx, int vtype)
{
ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
self->expression.codegen = NULL;
self->expression.next = NULL;
self->expression.vtype = vtype;
return self;
}
static ast_expression* ast_type_copy(lex_ctx ctx, const ast_expression *ex)
{
size_t i;
@ -294,10 +303,22 @@ ast_member* ast_member_new(lex_ctx ctx, ast_expression *owner, unsigned int fiel
return NULL;
}
if (owner->expression.vtype != TYPE_FLOAT &&
owner->expression.vtype != TYPE_FIELD) {
printf("ast_member on an invalid owner of type %i\n", (int)owner->expression.vtype);
mem_d(self);
return NULL;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen);
self->expression.vtype = TYPE_FLOAT;
self->expression.next = NULL;
if (owner->expression.vtype == TYPE_VECTOR) {
self->expression.vtype = TYPE_FLOAT;
self->expression.next = NULL;
} else {
self->expression.vtype = TYPE_FIELD;
self->expression.next = ast_shallow_type(ctx, TYPE_FLOAT);
}
self->owner = owner;
self->field = field;
@ -958,8 +979,11 @@ bool ast_member_codegen(ast_member *self, ast_function *func, bool lvalue, ir_va
if (!(*cgen)((ast_expression*)(self->owner), func, true, &vec))
return false;
if (vec->vtype != TYPE_VECTOR)
if (vec->vtype != TYPE_VECTOR &&
!(vec->vtype == TYPE_FIELD && self->owner->expression.next->expression.vtype == TYPE_VECTOR))
{
return false;
}
*out = ir_value_vector_member(vec, self->field);