#include "fold.h"
//#include "parser.h"
+#include "algo.h"
+
#define ast_instantiate(T, ctx, destroyfn) \
T* self = (T*)mem_a(sizeof(T)); \
if (!self) { \
}
}
-static ast_expression* ast_shallow_type(lex_ctx_t ctx, int vtype)
+static ast_expression* ast_shallow_type(lex_ctx_t ctx, qc_type vtype)
{
ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
ast_expression_init(self, nullptr);
}
static bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_value **out);
-ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t)
+ast_value* ast_value_new(lex_ctx_t ctx, const char *name, qc_type t)
{
ast_instantiate(ast_value, ctx, ast_value_delete);
ast_expression_init((ast_expression*)self,
}
ast_expression_delete((ast_expression*)self);
+ self->~ast_value();
mem_d(self);
}
if (self->refs & AST_REF_RIGHT) ast_unref(self->right);
ast_expression_delete((ast_expression*)self);
+ self->~ast_binary();
mem_d(self);
}
ast_unref(self->dest);
ast_unref(self->source);
ast_expression_delete((ast_expression*)self);
+ self->~ast_binstore();
mem_d(self);
}
{
if (self->operand) ast_unref(self->operand);
ast_expression_delete((ast_expression*)self);
+ self->~ast_unary();
mem_d(self);
}
if (self->operand)
ast_unref(self->operand);
ast_expression_delete((ast_expression*)self);
+ self->~ast_return();
mem_d(self);
}
ast_unref(self->entity);
ast_unref(self->field);
ast_expression_delete((ast_expression*)self);
+ self->~ast_entfield();
mem_d(self);
}
*/
ast_expression_delete((ast_expression*)self);
mem_d(self->name);
+ self->~ast_member();
mem_d(self);
}
if (self->index)
ast_unref(self->index);
ast_expression_delete((ast_expression*)self);
+ self->~ast_argpipe();
mem_d(self);
}
if (self->on_false)
ast_unref(self->on_false);
ast_expression_delete((ast_expression*)self);
+ self->~ast_ifthen();
mem_d(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);
}
if (self->body)
ast_unref(self->body);
ast_expression_delete((ast_expression*)self);
+ self->~ast_loop();
mem_d(self);
}
void ast_breakcont_delete(ast_breakcont *self)
{
ast_expression_delete((ast_expression*)self);
+ self->~ast_breakcont();
mem_d(self);
}
}
ast_expression_delete((ast_expression*)self);
+ self->~ast_switch();
mem_d(self);
}
{
mem_d((void*)self->name);
ast_expression_delete((ast_expression*)self);
+ self->~ast_label();
mem_d(self);
}
{
mem_d((void*)self->name);
ast_expression_delete((ast_expression*)self);
+ self->~ast_goto();
mem_d(self);
}
ast_unref(self->nextthink);
ast_expression_delete((ast_expression*)self);
+ self->~ast_state();
mem_d(self);
}
ast_unref(self->va_count);
ast_expression_delete((ast_expression*)self);
+ self->~ast_call();
mem_d(self);
}
ast_unref(self->dest);
ast_unref(self->source);
ast_expression_delete((ast_expression*)self);
+ self->~ast_store();
mem_d(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);
}
}
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)
ast_unref(self->fixedparams);
if (self->return_value)
ast_unref(self->return_value);
+ self->~ast_function();
mem_d(self);
}
size_t namelen;
ast_expression *elemtype;
- int vtype;
+ qc_type vtype;
ast_value *array = (ast_value*)fieldtype;
if (!ast_istype(fieldtype, ast_value)) {
size_t namelen;
ast_expression *elemtype = self->next;
- int vtype = elemtype->vtype;
+ qc_type vtype = elemtype->vtype;
if (self->flags & AST_FLAG_ARRAY_INIT && !self->count) {
compile_error(ast_ctx(self), "array `%s' has no size", self->name);
return true;
error: /* clean up */
- if(v) ir_value_delete(v);
+ if (v) delete v;
return false;
}
size_t namelen;
ast_expression *elemtype = self->next;
- int vtype = elemtype->vtype;
+ qc_type vtype = elemtype->vtype;
func->flags |= IR_FLAG_HAS_ARRAYS;
return true;
error: /* clean up */
- ir_value_delete(v);
+ delete v;
return false;
}
compile_error(ast_ctx(self), "internal error: not all array values have been generated for `%s`", self->name);
return false;
}
- if (self->ir_values[i]->life) {
+ if (!self->ir_values[i]->life.empty()) {
compile_error(ast_ctx(self), "internal error: function containing `%s` already generated", self->name);
return false;
}
return false;
}
}
- for (i = 0; i < self->count; ++i) {
- vec_free(self->ir_values[i]->life);
- }
+ for (i = 0; i < self->count; ++i)
+ self->ir_values[i]->life.clear();
opts_set(opts.warn, WARN_USED_UNINITIALIZED, warn);
return true;
}
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;
}
}
else if (compile_warning(ast_ctx(self), WARN_MISSING_RETURN_VALUES,
"control reaches end of non-void function (`%s`) via %s",
- self->name, self->curblock->label))
+ self->name, self->curblock->label.c_str()))
{
return false;
}
size_t merge_id;
/* prepare end-block */
- merge_id = vec_size(func->ir_func->blocks);
+ merge_id = func->ir_func->blocks.size();
merge = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "sce_merge"));
/* generate the left expression */
if (!ir_block_create_jump(func->curblock, ast_ctx(self), merge))
return false;
- vec_remove(func->ir_func->blocks, merge_id, 1);
- vec_push(func->ir_func->blocks, 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),
bpostcond = end_bpostcond = nullptr;
}
- bout_id = vec_size(func->ir_func->blocks);
+ bout_id = func->ir_func->blocks.size();
bout = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "after_loop"));
if (!bout)
return false;
}
/* Move 'bout' to the end */
- vec_remove(func->ir_func->blocks, bout_id, 1);
- vec_push(func->ir_func->blocks, 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<unique_ptr<>>
+ //func->ir_func->blocks.erase(func->ir_func->blocks.begin() + bout_id);
+ //func->ir_func->blocks.emplace_back(bout);
return true;
}
return false;
}
- bout_id = vec_size(func->ir_func->blocks);
+ bout_id = func->ir_func->blocks.size();
bout = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "after_switch"));
if (!bout)
return false;
return false;
bcase = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "case"));
- bnot_id = vec_size(func->ir_func->blocks);
+ bnot_id = func->ir_func->blocks.size();
bnot = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "not_case"));
if (!bcase || !bnot)
return false;
/* enter the else and move it down */
func->curblock = bnot;
- vec_remove(func->ir_func->blocks, bnot_id, 1);
- vec_push(func->ir_func->blocks, 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: */
func->breakblocks.pop_back();
/* Move 'bout' to the end, it's nicer */
- vec_remove(func->ir_func->blocks, bout_id, 1);
- vec_push(func->ir_func->blocks, 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;
}