]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.h
Preparing to generate accessors for field arrays
[xonotic/gmqcc.git] / ast.h
diff --git a/ast.h b/ast.h
index ffad71052805b881f93b15104921675f724af979..b46aee16b6063d348926fadb887617885a9fd596 100644 (file)
--- a/ast.h
+++ b/ast.h
 typedef union ast_node_u ast_node;
 typedef union ast_expression_u ast_expression;
 
-typedef struct ast_value_s      ast_value;
-typedef struct ast_function_s   ast_function;
-typedef struct ast_block_s      ast_block;
-typedef struct ast_binary_s     ast_binary;
-typedef struct ast_store_s      ast_store;
-typedef struct ast_binstore_s   ast_binstore;
-typedef struct ast_entfield_s   ast_entfield;
-typedef struct ast_ifthen_s     ast_ifthen;
-typedef struct ast_ternary_s    ast_ternary;
-typedef struct ast_loop_s       ast_loop;
-typedef struct ast_call_s       ast_call;
-typedef struct ast_unary_s      ast_unary;
-typedef struct ast_return_s     ast_return;
-typedef struct ast_member_s     ast_member;
+typedef struct ast_value_s       ast_value;
+typedef struct ast_function_s    ast_function;
+typedef struct ast_block_s       ast_block;
+typedef struct ast_binary_s      ast_binary;
+typedef struct ast_store_s       ast_store;
+typedef struct ast_binstore_s    ast_binstore;
+typedef struct ast_entfield_s    ast_entfield;
+typedef struct ast_ifthen_s      ast_ifthen;
+typedef struct ast_ternary_s     ast_ternary;
+typedef struct ast_loop_s        ast_loop;
+typedef struct ast_call_s        ast_call;
+typedef struct ast_unary_s       ast_unary;
+typedef struct ast_return_s      ast_return;
+typedef struct ast_member_s      ast_member;
+typedef struct ast_array_index_s ast_array_index;
 
 enum {
     TYPE_ast_node,
@@ -62,7 +63,8 @@ enum {
     TYPE_ast_call,
     TYPE_ast_unary,
     TYPE_ast_return,
-    TYPE_ast_member
+    TYPE_ast_member,
+    TYPE_ast_array_index
 };
 
 #define ast_istype(x, t) ( ((ast_node_common*)x)->nodetype == (TYPE_##t) )
@@ -116,6 +118,8 @@ typedef struct
     ast_expression_codegen *codegen;
     int                     vtype;
     ast_expression         *next;
+    /* arrays get a member-count */
+    size_t                  count;
     MEM_VECTOR_MAKE(ast_value*, params);
     bool                    variadic;
     /* The codegen functions should store their output values
@@ -160,6 +164,12 @@ struct ast_value_s
     size_t uses;
 
     ir_value *ir_v;
+    ir_value **ir_values;
+    size_t   ir_value_count;
+
+    /* ONLY for arrays in progs version up to 6 */
+    ast_value *setter;
+    ast_value *getter;
 };
 
 ast_value* ast_value_new(lex_ctx ctx, const char *name, int qctype);
@@ -301,6 +311,27 @@ void ast_member_delete(ast_member*);
 
 bool ast_member_codegen(ast_member*, ast_function*, bool lvalue, ir_value**);
 
+/* Array index access:
+ *
+ * QC forces us to take special action on arrays:
+ * an ast_store on an ast_array_index must not codegen the index,
+ * but call its setter - unless we have an instruction set which supports
+ * what we need.
+ * Any other array index access will be codegened to a call to the getter.
+ * In any case, accessing an element via a compiletime-constant index will
+ * result in quick access to that variable.
+ */
+struct ast_array_index_s
+{
+    ast_expression_common expression;
+    ast_expression *array;
+    ast_expression *index;
+};
+ast_array_index* ast_array_index_new(lex_ctx ctx, ast_expression *array, ast_expression *index);
+void ast_array_index_delete(ast_array_index*);
+
+bool ast_array_index_codegen(ast_array_index*, ast_function*, bool lvalue, ir_value**);
+
 /* Store
  *
  * Stores left<-right and returns left.