-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, qc_type t)
-{
- ast_instantiate(ast_value, ctx, ast_value_delete);
- ast_expression_init((ast_expression*)self,
- (ast_expression_codegen*)&ast_value_codegen);
- self->m_keep_node = true; /* keep */
-
- self->m_name = name ? util_strdup(name) : nullptr;
- self->m_vtype = t;
- self->m_next = nullptr;
- self->m_isfield = false;
- self->m_cvq = CV_NONE;
- self->m_hasvalue = false;
- self->m_isimm = false;
- self->m_inexact = false;
- self->m_uses = 0;
- memset(&self->m_constval, 0, sizeof(self->m_constval));
-
- self->m_ir_v = nullptr;
- self->m_ir_values = nullptr;
- self->m_ir_value_count = 0;
-
- self->m_setter = nullptr;
- self->m_getter = nullptr;
- self->m_desc = nullptr;
-
- self->m_argcounter = nullptr;
- self->m_intrinsic = false;
-
- return self;
-}
-
-void ast_value_delete(ast_value* self)
-{
- if (self->m_name)
- mem_d((void*)self->m_name);
- if (self->m_argcounter)
- mem_d((void*)self->m_argcounter);
- if (self->m_hasvalue) {
- switch (self->m_vtype)
- {
- case TYPE_STRING:
- mem_d((void*)self->m_constval.vstring);
- break;
- case TYPE_FUNCTION:
- /* unlink us from the function node */
- self->m_constval.vfunc->m_function_type = nullptr;
- break;
- /* NOTE: delete function? currently collected in
- * the parser structure
- */
- default:
- break;
- }
- }
- if (self->m_ir_values)
- mem_d(self->m_ir_values);
-
- if (self->m_desc)
- mem_d(self->m_desc);
-
- // initlist imples an array which implies .next in the expression exists.
- if (self->m_initlist.size() && self->m_next->m_vtype == TYPE_STRING) {
- for (auto &it : self->m_initlist)
- if (it.vstring)
- mem_d(it.vstring);
- }
-
- ast_expression_delete((ast_expression*)self);
- self->~ast_value();
- mem_d(self);
-}
-
-void ast_value_params_add(ast_value *self, ast_value *p)