mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-07 15:01:10 +00:00
Fix array-index codegen conditions
This commit is contained in:
parent
22d6ff2309
commit
feec2d74ee
1 changed files with 33 additions and 38 deletions
23
ast.c
23
ast.c
|
@ -1537,16 +1537,20 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ast_istype(self->index, ast_value)) {
|
arr = (ast_value*)self->array;
|
||||||
if (lvalue) {
|
idx = (ast_value*)self->index;
|
||||||
asterror(ast_ctx(self), "array indexing here needs a compile-time constant");
|
|
||||||
return false;
|
if (!ast_istype(self->index, ast_value) || !idx->isconst) {
|
||||||
} else {
|
|
||||||
/* Time to use accessor functions */
|
/* Time to use accessor functions */
|
||||||
ast_expression_codegen *cgen;
|
ast_expression_codegen *cgen;
|
||||||
ir_value *iridx, *funval;
|
ir_value *iridx, *funval;
|
||||||
ir_instr *call;
|
ir_instr *call;
|
||||||
|
|
||||||
|
if (lvalue) {
|
||||||
|
asterror(ast_ctx(self), "(.2) array indexing here needs a compile-time constant");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!arr->getter) {
|
if (!arr->getter) {
|
||||||
asterror(ast_ctx(self), "value has no getter, don't know how to index it");
|
asterror(ast_ctx(self), "value has no getter, don't know how to index it");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1570,15 +1574,6 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
|
||||||
self->expression.outr = *out;
|
self->expression.outr = *out;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
arr = (ast_value*)self->array;
|
|
||||||
idx = (ast_value*)self->index;
|
|
||||||
|
|
||||||
if (!idx->isconst) {
|
|
||||||
asterror(ast_ctx(self), "(.2) array indexing here needs a compile-time constant");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idx->expression.vtype == TYPE_FLOAT)
|
if (idx->expression.vtype == TYPE_FLOAT)
|
||||||
*out = arr->ir_values[(int)idx->constval.vfloat];
|
*out = arr->ir_values[(int)idx->constval.vfloat];
|
||||||
|
|
Loading…
Reference in a new issue