# define DEBUGSHUNTDO(x)
#endif
+/* With regular precedence rules, ent.foo[n] is the same as (ent.foo)[n],
+ * so we need to rotate it to become ent.(foo[n]).
+ */
+static bool rotate_entfield_array_index_nodes(ast_expression **out)
+{
+ ast_array_index *index;
+ ast_entfield *entfield;
+
+ ast_value *field;
+ ast_expression *sub;
+ ast_expression *entity;
+
+ lex_ctx ctx = ast_ctx(*out);
+
+ if (!ast_istype(*out, ast_array_index))
+ return false;
+ index = (ast_array_index*)*out;
+
+ if (!ast_istype(index->array, ast_entfield))
+ return false;
+ entfield = (ast_entfield*)index->array;
+
+ if (!ast_istype(entfield->field, ast_value))
+ return false;
+ field = (ast_value*)entfield->field;
+
+ sub = index->index;
+ entity = entfield->entity;
+
+ ast_delete(index);
+
+ index = ast_array_index_new(ctx, (ast_expression*)field, sub);
+ entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
+ *out = (ast_expression*)entfield;
+
+ return true;
+}
+
static bool parser_sy_pop(parser_t *parser, shunt *sy)
{
const oper_info *op;
break;
case opid1('['):
- if (exprs[0]->expression.vtype != TYPE_ARRAY) {
+ if (exprs[0]->expression.vtype != TYPE_ARRAY &&
+ !(exprs[0]->expression.vtype == TYPE_FIELD &&
+ exprs[0]->expression.next->expression.vtype == TYPE_ARRAY))
+ {
ast_type_to_string(exprs[0], ty1, sizeof(ty1));
parseerror(parser, "cannot index value of type %s", ty1);
return false;
return false;
}
out = (ast_expression*)ast_array_index_new(ctx, exprs[0], exprs[1]);
+ if (rotate_entfield_array_index_nodes(&out))
+ {
+ if (opts_standard != COMPILER_GMQCC) {
+ /* this error doesn't need to make us bail out */
+ (void)!parsewarning(parser, WARN_EXTENSIONS,
+ "accessing array-field members of an entity without parenthesis\n"
+ " -> this is an extension from -std=gmqcc");
+ }
+ }
break;
case opid1(','):
ast_return *ret;
ast_entfield *entfield;
ast_array_index *subscript;
- int assignop = type_store_instr[value->expression.vtype];
+ int assignop = type_storep_instr[value->expression.vtype];
if (value->expression.vtype == TYPE_FIELD && value->expression.next->expression.vtype == TYPE_VECTOR)
- assignop = INSTR_STORE_V;
+ assignop = INSTR_STOREP_V;
subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)parser_const_float(parser, from));
if (!subscript)
return NULL;
- entfield = ast_entfield_new(ctx, (ast_expression*)entity, (ast_expression*)subscript);
+ entfield = ast_entfield_new_force(ctx,
+ (ast_expression*)entity,
+ (ast_expression*)subscript,
+ (ast_expression*)subscript);
if (!entfield) {
ast_delete(subscript);
return NULL;
!ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
!ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
{
- printf("failed to generate setter for %s\n", parser->globals[i].name);
+ printf("failed to generate setter for %s\n", parser->fields[i].name);
ir_builder_delete(ir);
return false;
}
!ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
!ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
{
- printf("failed to generate getter for %s\n", parser->globals[i].name);
+ printf("failed to generate getter for %s\n", parser->fields[i].name);
ir_builder_delete(ir);
return false;
}