mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-23 12:22:26 +00:00
ast_entfield node
This commit is contained in:
parent
eb21f1e733
commit
281bd8657a
2 changed files with 50 additions and 0 deletions
23
ast.c
23
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;
|
||||
}
|
||||
|
|
27
ast.h
27
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.
|
||||
|
|
Loading…
Reference in a new issue