vala r1830 - in trunk: . gobject vala vapigen
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1830 - in trunk: . gobject vala vapigen
- Date: Sat, 11 Oct 2008 11:08:00 +0000 (UTC)
Author: juergbi
Date: Sat Oct 11 11:08:00 2008
New Revision: 1830
URL: http://svn.gnome.org/viewvc/vala?rev=1830&view=rev
Log:
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
Modified:
trunk/ChangeLog
trunk/gobject/valaccodemethodbinding.vala
trunk/vala/valainterfacewriter.vala
trunk/vala/valamethod.vala
trunk/vapigen/valagidlparser.vala
Modified: trunk/gobject/valaccodemethodbinding.vala
==============================================================================
--- trunk/gobject/valaccodemethodbinding.vala (original)
+++ trunk/gobject/valaccodemethodbinding.vala Sat Oct 11 11:08:00 2008
@@ -846,19 +846,41 @@
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);
Modified: trunk/vala/valainterfacewriter.vala
==============================================================================
--- trunk/vala/valainterfacewriter.vala (original)
+++ trunk/vala/valainterfacewriter.vala Sat Oct 11 11:08:00 2008
@@ -802,6 +802,11 @@
}
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) {
Modified: trunk/vala/valamethod.vala
==============================================================================
--- trunk/vala/valamethod.vala (original)
+++ trunk/vala/valamethod.vala Sat Oct 11 11:08:00 2008
@@ -194,6 +194,12 @@
*/
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;
@@ -373,6 +379,9 @@
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");
+ }
}
/**
Modified: trunk/vapigen/valagidlparser.vala
==============================================================================
--- trunk/vapigen/valagidlparser.vala (original)
+++ trunk/vapigen/valagidlparser.vala Sat Oct 11 11:08:00 2008
@@ -1264,6 +1264,7 @@
Method m;
if (!is_interface && (is_constructor || name.has_prefix ("new"))) {
m = new CreationMethod (null, name, current_source_reference);
+ m.has_construct_function = false;
if (m.name == "new") {
m.name = null;
} else if (m.name.has_prefix ("new_")) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]