}
} else if (current_type_symbol is Class) {
var cl = (Class) m.parent_symbol;
- var cdecl = new CCodeDeclaration (cl.get_cname () + "*");
- var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
- ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
- cdecl.add_declarator (new CCodeVariableDeclarator ("self", ccall));
- cinit.append (cdecl);
+ var cdeclaration = new CCodeDeclaration (cl.get_cname () + "*");
+ var cdecl = new CCodeVariableDeclarator ("self");
+ cdeclaration.add_declarator (cdecl);
+ cinit.append (cdeclaration);
- var cinitcall = new CCodeFunctionCall (new CCodeIdentifier ("%s_instance_init".printf (cl.get_lower_case_cname (null))));
- cinitcall.add_argument (new CCodeIdentifier ("self"));
- cinit.append (new CCodeExpressionStatement (cinitcall));
+ if (!((CreationMethod) m).chain_up) {
+ // TODO implicitly chain up to base class as in add_object_creation
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
+ ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
+ cdecl.initializer = ccall;
+ }
+
+ if (cl.base_class == null) {
+ // derived compact classes do not have fields
+ var cinitcall = new CCodeFunctionCall (new CCodeIdentifier ("%s_instance_init".printf (cl.get_lower_case_cname (null))));
+ cinitcall.add_argument (new CCodeIdentifier ("self"));
+ cinit.append (new CCodeExpressionStatement (cinitcall));
+ }
} else {
var st = (Struct) m.parent_symbol;
decl_space.add_type_declaration (new CCodeNewline ());
}
- decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (cl.get_cname ()), new CCodeVariableDeclarator (cl.get_cname ())));
+ if (cl.is_compact && cl.base_class != null) {
+ decl_space.add_type_declaration (new CCodeTypeDefinition (cl.base_class.get_cname (), new CCodeVariableDeclarator (cl.get_cname ())));
+ } else {
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (cl.get_cname ()), new CCodeVariableDeclarator (cl.get_cname ())));
+ }
if (is_fundamental) {
var ref_fun = new CCodeFunction (cl.get_lower_case_cprefix () + "ref", "gpointer");
if (cl.source_reference.comment != null) {
decl_space.add_type_definition (new CCodeComment (cl.source_reference.comment));
}
- decl_space.add_type_definition (instance_struct);
+ if (!cl.is_compact || cl.base_class == null) {
+ // derived compact classes do not have a struct
+ decl_space.add_type_definition (instance_struct);
+ }
if (is_gtypeinstance) {
decl_space.add_type_definition (type_struct);
}
decl_space.add_type_member_declaration (prop_enum);
} else {
- var function = new CCodeFunction (cl.get_lower_case_cprefix () + "free", "void");
- if (cl.access == SymbolAccessibility.PRIVATE) {
- function.modifiers = CCodeModifiers.STATIC;
- }
-
if (cl.has_private_fields) {
Report.error (cl.source_reference, "Private fields not supported in compact classes");
}
- function.add_parameter (new CCodeFormalParameter ("self", cl.get_cname () + "*"));
+ if (cl.base_class == null) {
+ var function = new CCodeFunction (cl.get_lower_case_cprefix () + "free", "void");
+ if (cl.access == SymbolAccessibility.PRIVATE) {
+ function.modifiers = CCodeModifiers.STATIC;
+ }
+
+ function.add_parameter (new CCodeFormalParameter ("self", cl.get_cname () + "*"));
- decl_space.add_type_member_declaration (function);
+ decl_space.add_type_member_declaration (function);
+ }
}
}
source_type_member_definition.append (unref_fun);
}
} else {
- add_instance_init_function (cl);
+ if (cl.base_class == null) {
+ // derived compact classes do not have fields
+ add_instance_init_function (cl);
- var function = new CCodeFunction (cl.get_lower_case_cprefix () + "free", "void");
- if (cl.access == SymbolAccessibility.PRIVATE) {
- function.modifiers = CCodeModifiers.STATIC;
- }
+ var function = new CCodeFunction (cl.get_lower_case_cprefix () + "free", "void");
+ if (cl.access == SymbolAccessibility.PRIVATE) {
+ function.modifiers = CCodeModifiers.STATIC;
+ }
- function.add_parameter (new CCodeFormalParameter ("self", cl.get_cname () + "*"));
+ function.add_parameter (new CCodeFormalParameter ("self", cl.get_cname () + "*"));
- var cblock = new CCodeBlock ();
+ var cblock = new CCodeBlock ();
- cblock.add_statement (instance_finalize_fragment);
+ cblock.add_statement (instance_finalize_fragment);
- if (cl.destructor != null) {
- cblock.add_statement (cl.destructor.ccodenode);
- }
+ if (cl.destructor != null) {
+ cblock.add_statement (cl.destructor.ccodenode);
+ }
- var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
- ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
- ccall.add_argument (new CCodeIdentifier ("self"));
- cblock.add_statement (new CCodeExpressionStatement (ccall));
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
+ ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
+ ccall.add_argument (new CCodeIdentifier ("self"));
+ cblock.add_statement (new CCodeExpressionStatement (ccall));
- function.block = cblock;
+ function.block = cblock;
- source_type_member_definition.append (function);
+ source_type_member_definition.append (function);
+ }
}
current_symbol = old_symbol;