+2008-05-29 Jürg Billeter <j@bitron.ch>
+
+ * gobject/valaccodeclassbinding.vala:
+ * gobject/valaccodegenerator.vala:
+ * gobject/valaccodemethodbinding.vala:
+ * gobject/valaclassregisterfunction.vala:
+
+ Simplify generated _new functions for non-GObject classes
+
2008-05-29 Jaap A. Haitsma <jaap@haitsma.org>
* tests/strings.vala:
}
private void add_instance_init_function (Class cl) {
- var instance_init = new CCodeFunction ("%s_init".printf (cl.get_lower_case_cname (null)), "void");
+ var instance_init = new CCodeFunction ("%s_instance_init".printf (cl.get_lower_case_cname (null)), "void");
instance_init.add_parameter (new CCodeFormalParameter ("self", "%s *".printf (cl.get_cname ())));
instance_init.modifiers = CCodeModifiers.STATIC;
}
init_block.add_statement (codegen.instance_init_fragment);
-
- var init_sym = cl.scope.lookup ("init");
- if (init_sym != null) {
- var init_fun = (Method) init_sym;
- init_block.add_statement (init_fun.body.ccodenode);
- }
-
+
codegen.source_type_member_definition.append (instance_init);
}
if (expr.type_reference.data_type is Struct && !(m.cinstance_parameter_position < 0)) {
creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
- } else if (expr.type_reference.data_type is Class) {
- var cl = (Class) expr.type_reference.data_type;
- if (!cl.is_compact && cl.base_class == null) {
- creation_call.add_argument (new CCodeIdentifier (cl.get_type_id ()));
- }
}
if (expr.type_reference.data_type is Class && expr.type_reference.data_type.is_subtype_of (gobject_type)) {
cparam_map.set (codegen.get_param_pos (m.cinstance_parameter_position), class_param);
}
- if (in_fundamental_creation_method) {
- cparam_map.set (codegen.get_param_pos (0.1), new CCodeFormalParameter ("type", "GType"));
- }
-
if (in_gobject_creation_method) {
// memory management for generic types
int type_param_index = 0;
param_name = new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()));
cinit.append (new CCodeExpressionStatement (get_construct_property_assignment (prop_name, new PointerType (new VoidType ()), param_name)));
}
- } else if (in_fundamental_creation_method) {
- var cl = (Class) m.parent_symbol;
- var cdecl = new CCodeDeclaration (cl.get_cname () + "*");
- var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_create_instance"));
- ccall.add_argument (new CCodeIdentifier ("type"));
- cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", new CCodeCastExpression (ccall, cl.get_cname () + "*")));
- cinit.append (cdecl);
} else if (in_gtypeinstance_creation_method) {
var cl = (Class) m.parent_symbol;
var cdecl = new CCodeDeclaration (cl.get_cname () + "*");
- var fundamental_class = find_fundamental_class (cl);
- var ccall = new CCodeFunctionCall (new CCodeIdentifier (fundamental_class.default_construction_method.get_cname ()));
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_create_instance"));
ccall.add_argument (new CCodeIdentifier (cl.get_type_id ()));
- cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", ccall));
+ cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", new CCodeCastExpression (ccall, cl.get_cname () + "*")));
cinit.append (cdecl);
} else if (codegen.current_type_symbol is Class) {
var cl = (Class) m.parent_symbol;