X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ast.cpp;h=10356bead71e9afd692dc05a9121d561b3988502;hp=c2c3b476e51cb0d5e310ff5285af5ed42876eee1;hb=5968e3faa02ce4b23a9b9980fde7e5021943f3d8;hpb=f09c6a5d63faaad1b915868c461b658efd374a34 diff --git a/ast.cpp b/ast.cpp index c2c3b47..10356be 100644 --- a/ast.cpp +++ b/ast.cpp @@ -8,6 +8,8 @@ #include "fold.h" //#include "parser.h" +#include "algo.h" + #define ast_instantiate(T, ctx, destroyfn) \ T* self = (T*)mem_a(sizeof(T)); \ if (!self) { \ @@ -387,6 +389,7 @@ void ast_value_delete(ast_value* self) } ast_expression_delete((ast_expression*)self); + self->~ast_value(); mem_d(self); } @@ -464,6 +467,7 @@ void ast_binary_delete(ast_binary *self) if (self->refs & AST_REF_RIGHT) ast_unref(self->right); ast_expression_delete((ast_expression*)self); + self->~ast_binary(); mem_d(self); } @@ -492,6 +496,7 @@ void ast_binstore_delete(ast_binstore *self) ast_unref(self->dest); ast_unref(self->source); ast_expression_delete((ast_expression*)self); + self->~ast_binstore(); mem_d(self); } @@ -537,6 +542,7 @@ void ast_unary_delete(ast_unary *self) { if (self->operand) ast_unref(self->operand); ast_expression_delete((ast_expression*)self); + self->~ast_unary(); mem_d(self); } @@ -558,6 +564,7 @@ void ast_return_delete(ast_return *self) if (self->operand) ast_unref(self->operand); ast_expression_delete((ast_expression*)self); + self->~ast_return(); mem_d(self); } @@ -596,6 +603,7 @@ void ast_entfield_delete(ast_entfield *self) ast_unref(self->entity); ast_unref(self->field); ast_expression_delete((ast_expression*)self); + self->~ast_entfield(); mem_d(self); } @@ -650,6 +658,7 @@ void ast_member_delete(ast_member *self) */ ast_expression_delete((ast_expression*)self); mem_d(self->name); + self->~ast_member(); mem_d(self); } @@ -718,6 +727,7 @@ void ast_argpipe_delete(ast_argpipe *self) if (self->index) ast_unref(self->index); ast_expression_delete((ast_expression*)self); + self->~ast_argpipe(); mem_d(self); } @@ -751,6 +761,7 @@ void ast_ifthen_delete(ast_ifthen *self) if (self->on_false) ast_unref(self->on_false); ast_expression_delete((ast_expression*)self); + self->~ast_ifthen(); mem_d(self); } @@ -788,6 +799,7 @@ void ast_ternary_delete(ast_ternary *self) if (self->on_true) ast_unref(self->on_true); if (self->on_false) ast_unref(self->on_false); ast_expression_delete((ast_expression*)self); + self->~ast_ternary(); mem_d(self); } @@ -837,6 +849,7 @@ void ast_loop_delete(ast_loop *self) if (self->body) ast_unref(self->body); ast_expression_delete((ast_expression*)self); + self->~ast_loop(); mem_d(self); } @@ -854,6 +867,7 @@ ast_breakcont* ast_breakcont_new(lex_ctx_t ctx, bool iscont, unsigned int levels void ast_breakcont_delete(ast_breakcont *self) { ast_expression_delete((ast_expression*)self); + self->~ast_breakcont(); mem_d(self); } @@ -880,6 +894,7 @@ void ast_switch_delete(ast_switch *self) } ast_expression_delete((ast_expression*)self); + self->~ast_switch(); mem_d(self); } @@ -901,6 +916,7 @@ void ast_label_delete(ast_label *self) { mem_d((void*)self->name); ast_expression_delete((ast_expression*)self); + self->~ast_label(); mem_d(self); } @@ -925,6 +941,7 @@ void ast_goto_delete(ast_goto *self) { mem_d((void*)self->name); ast_expression_delete((ast_expression*)self); + self->~ast_goto(); mem_d(self); } @@ -950,6 +967,7 @@ void ast_state_delete(ast_state *self) ast_unref(self->nextthink); ast_expression_delete((ast_expression*)self); + self->~ast_state(); mem_d(self); } @@ -986,6 +1004,7 @@ void ast_call_delete(ast_call *self) ast_unref(self->va_count); ast_expression_delete((ast_expression*)self); + self->~ast_call(); mem_d(self); } @@ -1111,6 +1130,7 @@ void ast_store_delete(ast_store *self) ast_unref(self->dest); ast_unref(self->source); ast_expression_delete((ast_expression*)self); + self->~ast_store(); mem_d(self); } @@ -1146,6 +1166,7 @@ void ast_block_delete(ast_block *self) for (auto &it : self->locals) ast_delete(it); for (auto &it : self->collect) ast_delete(it); ast_expression_delete((ast_expression*)self); + self->~ast_block(); mem_d(self); } @@ -1211,8 +1232,9 @@ void ast_function_delete(ast_function *self) } for (auto &it : self->static_names) mem_d(it); - for (auto &it : self->blocks) - ast_delete(it); + // FIXME::DELME:: unique_ptr used on ast_block + //for (auto &it : self->blocks) + // ast_delete(it); if (self->varargs) ast_delete(self->varargs); if (self->argc) @@ -1221,6 +1243,7 @@ void ast_function_delete(ast_function *self) ast_unref(self->fixedparams); if (self->return_value) ast_unref(self->return_value); + self->~ast_function(); mem_d(self); } @@ -1844,7 +1867,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir) for (auto &it : self->blocks) { cgen = it->codegen; - if (!(*cgen)((ast_expression*)it, self, false, &dummy)) + if (!(*cgen)(it.get(), self, false, &dummy)) return false; } @@ -2105,8 +2128,12 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_va if (!ir_block_create_jump(func->curblock, ast_ctx(self), merge)) return false; - func->ir_func->blocks.erase(func->ir_func->blocks.begin() + merge_id); - func->ir_func->blocks.emplace_back(merge); + algo::shiftback(func->ir_func->blocks.begin() + merge_id, + func->ir_func->blocks.end()); + // FIXME::DELME:: + //func->ir_func->blocks[merge_id].release(); + //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + merge_id); + //func->ir_func->blocks.emplace_back(merge); func->curblock = merge; phi = ir_block_create_phi(func->curblock, ast_ctx(self), @@ -3011,8 +3038,12 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value } /* Move 'bout' to the end */ - func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id); - func->ir_func->blocks.emplace_back(bout); + algo::shiftback(func->ir_func->blocks.begin() + bout_id, + func->ir_func->blocks.end()); + // FIXME::DELME:: + //func->ir_func->blocks[bout_id].release(); // it's a vector> + //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id); + //func->ir_func->blocks.emplace_back(bout); return true; } @@ -3151,8 +3182,12 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va /* enter the else and move it down */ func->curblock = bnot; - func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bnot_id); - func->ir_func->blocks.emplace_back(bnot); + algo::shiftback(func->ir_func->blocks.begin() + bnot_id, + func->ir_func->blocks.end()); + // FIXME::DELME:: + //func->ir_func->blocks[bnot_id].release(); + //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bnot_id); + //func->ir_func->blocks.emplace_back(bnot); } else { /* The default case */ /* Remember where to fall through from: */ @@ -3209,8 +3244,12 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va func->breakblocks.pop_back(); /* Move 'bout' to the end, it's nicer */ - func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id); - func->ir_func->blocks.emplace_back(bout); + algo::shiftback(func->ir_func->blocks.begin() + bout_id, + func->ir_func->blocks.end()); + // FIXME::DELME:: + //func->ir_func->blocks[bout_id].release(); + //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id); + //func->ir_func->blocks.emplace_back(bout); return true; }