mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 12:00:38 +00:00
renaming some ast_node members before making ast_expression an ast_node to use the compiler to help find possible clashes
This commit is contained in:
parent
db9c37d18b
commit
1826971301
3 changed files with 18 additions and 18 deletions
16
ast.cpp
16
ast.cpp
|
@ -67,12 +67,12 @@ static GMQCC_NORETURN void _ast_node_destroy(ast_node *self)
|
|||
}
|
||||
|
||||
/* Initialize main ast node aprts */
|
||||
static void ast_node_init(ast_node *self, lex_ctx_t ctx, int nodetype)
|
||||
static void ast_node_init(ast_node *self, lex_ctx_t ctx, int node_type)
|
||||
{
|
||||
self->context = ctx;
|
||||
self->destroy = &_ast_node_destroy;
|
||||
self->keep = false;
|
||||
self->nodetype = nodetype;
|
||||
self->destroy = &_ast_node_destroy;
|
||||
self->keep_node = false;
|
||||
self->node_type = node_type;
|
||||
self->side_effects = false;
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t)
|
|||
ast_instantiate(ast_value, ctx, ast_value_delete);
|
||||
ast_expression_init((ast_expression*)self,
|
||||
(ast_expression_codegen*)&ast_value_codegen);
|
||||
self->expression.node.keep = true; /* keep */
|
||||
self->expression.node.keep_node = true; /* keep */
|
||||
|
||||
self->name = name ? util_strdup(name) : nullptr;
|
||||
self->expression.vtype = t;
|
||||
|
@ -617,7 +617,7 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi
|
|||
}
|
||||
|
||||
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen);
|
||||
self->expression.node.keep = true; /* keep */
|
||||
self->expression.node.keep_node = true; /* keep */
|
||||
|
||||
if (owner->vtype == TYPE_VECTOR) {
|
||||
self->expression.vtype = TYPE_FLOAT;
|
||||
|
@ -642,7 +642,7 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi
|
|||
|
||||
void ast_member_delete(ast_member *self)
|
||||
{
|
||||
/* The owner is always an ast_value, which has .keep=true,
|
||||
/* The owner is always an ast_value, which has .keep_node=true,
|
||||
* also: ast_members are usually deleted after the owner, thus
|
||||
* this will cause invalid access
|
||||
ast_unref(self->owner);
|
||||
|
@ -1139,7 +1139,7 @@ bool ast_block_add_expr(ast_block *self, ast_expression *e)
|
|||
void ast_block_collect(ast_block *self, ast_expression *expr)
|
||||
{
|
||||
self->collect.push_back(expr);
|
||||
expr->node.keep = true;
|
||||
expr->node.keep_node = true;
|
||||
}
|
||||
|
||||
void ast_block_delete(ast_block *self)
|
||||
|
|
18
ast.h
18
ast.h
|
@ -93,7 +93,7 @@ enum {
|
|||
TYPE_ast_state /* 22 */
|
||||
};
|
||||
|
||||
#define ast_istype(x, t) ( ((ast_node*)x)->nodetype == (TYPE_##t) )
|
||||
#define ast_istype(x, t) ( ((ast_node*)x)->node_type == (TYPE_##t) )
|
||||
#define ast_ctx(node) (((ast_node*)(node))->context)
|
||||
#define ast_side_effects(node) (((ast_node*)(node))->side_effects)
|
||||
|
||||
|
@ -106,20 +106,20 @@ struct ast_node
|
|||
lex_ctx_t context;
|
||||
/* I don't feel comfortable using keywords like 'delete' as names... */
|
||||
ast_node_delete *destroy;
|
||||
int nodetype;
|
||||
/* keep: if a node contains this node, 'keep'
|
||||
int node_type;
|
||||
/* keep_node: if a node contains this node, 'keep_node'
|
||||
* prevents its dtor from destroying this node as well.
|
||||
*/
|
||||
bool keep;
|
||||
bool keep_node;
|
||||
bool side_effects;
|
||||
};
|
||||
|
||||
#define ast_delete(x) (*( ((ast_node*)(x))->destroy ))((ast_node*)(x))
|
||||
#define ast_unref(x) do \
|
||||
{ \
|
||||
if (! (((ast_node*)(x))->keep) ) { \
|
||||
ast_delete(x); \
|
||||
} \
|
||||
#define ast_unref(x) do \
|
||||
{ \
|
||||
if (! (((ast_node*)(x))->keep_node) ) { \
|
||||
ast_delete(x); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/* Expression interface
|
||||
|
|
2
fold.cpp
2
fold.cpp
|
@ -1070,7 +1070,7 @@ ast_expression *fold::op_mul_vec(vec3_t vec, ast_value *sel, const char *set) {
|
|||
ast_expression *out;
|
||||
++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS];
|
||||
out = (ast_expression*)ast_member_new(ctx(), (ast_expression*)sel, set[0]-'x', nullptr);
|
||||
out->node.keep = false;
|
||||
out->node.keep_node = false;
|
||||
((ast_member*)out)->rvalue = true;
|
||||
if (x != -1.0f)
|
||||
return (ast_expression*)ast_binary_new(ctx(), INSTR_MUL_F, constgen_float(x, false), out);
|
||||
|
|
Loading…
Reference in a new issue