protected fun compile_default_new(ccinfo: ClassCompilationInfo, v: SeparateCompilerVisitor)
do
var mclass = ccinfo.mclass
var mtype = ccinfo.mtype
var c_name = ccinfo.mclass.c_name
var is_dead = ccinfo.is_dead
#Build NEW
self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}(const struct type* type);")
v.add_decl("/* allocate {mtype} */")
v.add_decl("{mtype.ctype} NEW_{c_name}(const struct type* type) \{")
if is_dead then
v.add_abort("{mclass} is DEAD")
else
var res = v.new_named_var(mtype, "self")
res.is_exact = true
var attrs = self.attr_tables.get_or_null(mclass)
if attrs == null then
var alloc = v.nit_alloc("sizeof(struct instance)", mclass.full_name)
v.add("{res} = {alloc};")
else
var alloc = v.nit_alloc("sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t)", mclass.full_name)
v.add("{res} = {alloc};")
end
if modelbuilder.toolcontext.opt_trace.value then
v.add("tracepoint(Nit_Compiler, Object_Instance,\"{mtype}\", (uintptr_t)self);")
v.add("GC_register_finalizer(self, object_destroy_callback, NULL, NULL, NULL);")
end
v.add("{res}->type = type;")
hardening_live_type(v, "type")
v.require_declaration("class_{c_name}")
v.add("{res}->class = &class_{c_name};")
if attrs != null then
self.generate_init_attr(v, res, mtype)
v.set_finalizer res
end
v.add("return {res};")
end
v.add("\}")
end
src/compiler/separate_compiler.nit:1013,2--1053,4
redef fun compile_default_new(ccinfo, v)
do
var mclass = ccinfo.mclass
var mtype = ccinfo.mtype
var c_name = mclass.c_name
var is_dead = ccinfo.is_dead
#Build NEW
self.provide_declaration("NEW_{c_name}", "{mtype.ctype} NEW_{c_name}(void);")
v.add_decl("/* allocate {mtype} */")
v.add_decl("{mtype.ctype} NEW_{c_name}(void) \{")
if is_dead then
v.add_abort("{mclass} is DEAD")
else
var res = v.new_named_var(mtype, "self")
res.is_exact = true
var attrs = self.attr_tables.get_or_null(mclass)
if attrs == null then
v.add("{res} = nit_alloc(sizeof(struct instance));")
else
v.add("{res} = nit_alloc(sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t));")
end
v.require_declaration("class_{c_name}")
v.add("{res}->class = &class_{c_name};")
if attrs != null then
self.generate_init_attr(v, res, mtype)
v.set_finalizer res
end
v.add("return {res};")
end
v.add("\}")
end
src/compiler/separate_erasure_compiler.nit:374,2--406,4