]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
ast_entfield node
authorWolfgang Bumiller <wolfgang.linux@bumiller.com>
Tue, 1 May 2012 13:08:54 +0000 (15:08 +0200)
committerWolfgang Bumiller <wolfgang.linux@bumiller.com>
Tue, 1 May 2012 13:08:54 +0000 (15:08 +0200)
ast.c
ast.h

diff --git a/ast.c b/ast.c
index 3474dfca472735545e6689529e1b642b753a2beb..0fe0362cc4901f56dd490a78aebe447fd22935db 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -132,6 +132,24 @@ void ast_binary_delete(ast_binary *self)
     mem_d(self);
 }
 
+ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expression *field)
+{
+    ast_instantiate(ast_entfield, ctx, ast_entfield_delete);
+    ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_entfield_codegen);
+
+    self->entity = entity;
+    self->field  = field;
+
+    return self;
+}
+
+void ast_entfield_delete(ast_entfield *self)
+{
+    ast_unref(self->entity);
+    ast_unref(self->field);
+    mem_d(self);
+}
+
 ast_store* ast_store_new(lex_ctx ctx, int op,
                          ast_value *dest, ast_expression *source)
 {
@@ -316,3 +334,8 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, ir_value **out)
 {
     return false;
 }
+
+bool ast_entfield_codegen(ast_entfield *self, ast_function *func, ir_value **out)
+{
+    return false;
+}
diff --git a/ast.h b/ast.h
index bcc04f1e31fb680107abd7079950010a2e1fd3c1..cd73230bf09f90df3ae3e60af181babbf97cf8c3 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -36,6 +36,7 @@ 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_entfield_s   ast_entfield;
 
 /* Node interface with common components
  */
@@ -137,6 +138,32 @@ bool ast_block_codegen(ast_block*, ast_function*, ir_value**);
  */
 bool ast_binary_codegen(ast_binary*, ast_function*, ir_value**);
 
+/* Entity-field
+ *
+ * This must do 2 things:
+ * -) Provide a way to fetch an entity field value. (Rvalue)
+ * -) Provide a pointer to an entity field. (Lvalue)
+ * The problem:
+ * In original QC, there's only a STORE via pointer, but
+ * no LOAD via pointer.
+ * So we must know beforehand if we are going to read or assign
+ * the field.
+ * For this we will have to extend the codegen() functions with
+ * a flag saying whether or not we need an L or an R-value.
+ */
+struct ast_entfield_s
+{
+    ast_expression_common expression;
+    /* The entity can come from an expression of course. */
+    ast_expression *entity;
+    /* As can the field, it just must result in a value of TYPE_FIELD */
+    ast_expression *field;
+};
+ast_entfield* ast_entfield_new(lex_ctx ctx, ast_expression *entity, ast_expression *field);
+void ast_entfield_delete(ast_entfield*);
+
+bool ast_entfield_codegen(ast_entfield*, ast_function*, ir_value**);
+
 /* Store
  *
  * Stores left<-right and returns left.