+2008-10-11 Jürg Billeter <j@bitron.ch>
+
+ * vala/valainterfacewriter.vala:
+ * vala/valamethod.vala:
+ * gobject/valaccodemethodbinding.vala:
+ * vapigen/valagidlparser.vala:
+
+ Always chain up to base constructor when possible,
+ add has_construct_function attribute
+
2008-10-11 Jürg Billeter <j@bitron.ch>
* vala/valaclass.vala:
private void add_object_creation (CCodeBlock b, bool has_params) {
var cl = (Class) codegen.current_type_symbol;
-
- var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
- ccall.add_argument (new CCodeIdentifier ("object_type"));
- if (has_params) {
- ccall.add_argument (new CCodeConstant ("__params_it - __params"));
- ccall.add_argument (new CCodeConstant ("__params"));
- } else {
- ccall.add_argument (new CCodeConstant ("0"));
- ccall.add_argument (new CCodeConstant ("NULL"));
+
+ bool chain_up = false;
+ CreationMethod cm = null;
+ if (cl.base_class != null) {
+ cm = cl.base_class.default_construction_method as CreationMethod;
+ if (cm != null && cm.get_parameters ().size == 0
+ && cm.has_construct_function) {
+ if (!has_params) {
+ chain_up = true;
+ }
+ }
}
-
+
+ if (!has_params && !chain_up
+ && cl.base_class != codegen.gobject_type) {
+ // possibly report warning or error about missing base call
+ }
+
var cdecl = new CCodeVariableDeclarator ("self");
- cdecl.initializer = ccall;
+ if (chain_up) {
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier (cm.get_real_cname ()));
+ ccall.add_argument (new CCodeIdentifier ("object_type"));
+ cdecl.initializer = new CCodeCastExpression (ccall, "%s*".printf (cl.get_cname ()));
+ } else {
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
+ ccall.add_argument (new CCodeIdentifier ("object_type"));
+ if (has_params) {
+ ccall.add_argument (new CCodeConstant ("__params_it - __params"));
+ ccall.add_argument (new CCodeConstant ("__params"));
+ } else {
+ ccall.add_argument (new CCodeConstant ("0"));
+ ccall.add_argument (new CCodeConstant ("NULL"));
+ }
+ cdecl.initializer = ccall;
+ }
var cdeclaration = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
cdeclaration.add_declarator (cdecl);
}
if (m is CreationMethod && ((CreationMethod)m).custom_return_type_cname != null) {
ccode_params.append_printf ("%stype = \"%s\"", separator, ((CreationMethod)m).custom_return_type_cname);
+ separator = ", ";
+ }
+ if (m is CreationMethod && !m.has_construct_function) {
+ ccode_params.append_printf ("%shas_construct_function = false", separator);
+ separator = ", ";
}
if (ccode_params.len > 0) {
*/
public bool printf_format { get; set; }
+ /**
+ * Specifies whether a construct function with a GType parameter is
+ * available. This is only applicable to creation methods.
+ */
+ public bool has_construct_function { get; set; default = true; }
+
private Gee.List<FormalParameter> parameters = new ArrayList<FormalParameter> ();
private string cname;
private string _vfunc_name;
if (a.has_argument ("delegate_target_pos")) {
cdelegate_target_parameter_position = a.get_double ("delegate_target_pos");
}
+ if (a.has_argument ("has_construct_function")) {
+ has_construct_function = a.get_bool ("has_construct_function");
+ }
}
/**