From: Ryan Lortie Date: Mon, 16 Feb 2009 22:17:18 +0000 (+0000) Subject: Add support for a 'use_const' CCode attribute and GIDL XML attribute that, X-Git-Tag: 0.5.7~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76af93cfca0cb9cf35c5a144dd59fcc75f80f8cf;p=thirdparty%2Fvala.git Add support for a 'use_const' CCode attribute and GIDL XML attribute that, 2009-02-17 Ryan Lortie * gobject/valaccodebasemodule.vala: * vala/valacodewriter.vala: * vala/valastruct.vala: * vapigen/valagidlparser.vala: Add support for a 'use_const' CCode attribute and GIDL XML attribute that, when set to false, causes Vala not to emit the 'const' modifier on structure type input arguments. This is useful for structure types that, by convention, are not used with const (eg: GtkTreeIter). * vapi/packages/gtk+-2.0/gtk+-2.0.metadata: * vapi/gtk+-2.0.vapi: Add 'use_const' for GtkTreeIter to the gtk+-2.0 metadata. Regenerate vapi. svn path=/trunk/; revision=2446 --- diff --git a/ChangeLog b/ChangeLog index 1e9272f51..88927d6b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2009-02-17 Ryan Lortie + + * gobject/valaccodebasemodule.vala: + * vala/valacodewriter.vala: + * vala/valastruct.vala: + * vapigen/valagidlparser.vala: + + Add support for a 'use_const' CCode attribute and GIDL XML attribute + that, when set to false, causes Vala not to emit the 'const' modifier + on structure type input arguments. This is useful for structure types + that, by convention, are not used with const (eg: GtkTreeIter). + + * vapi/packages/gtk+-2.0/gtk+-2.0.metadata: + * vapi/gtk+-2.0.vapi: + + Add 'use_const' for GtkTreeIter to the gtk+-2.0 metadata. Regenerate + vapi. + 2009-02-16 Ryan Lortie * vala/valaclass.vala: only use g_value_set_pointer if the GType of a diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala index bb66a04af..874b8df49 100644 --- a/gobject/valaccodebasemodule.vala +++ b/gobject/valaccodebasemodule.vala @@ -1093,7 +1093,10 @@ internal class Vala.CCodeBaseModule : CCodeModule { if (p.parameter_type.data_type is Struct) { var st = (Struct) p.parameter_type.data_type; if (!st.is_simple_type () && p.direction == ParameterDirection.IN) { - ctypename = "const " + ctypename; + if (st.use_const) { + ctypename = "const " + ctypename; + } + if (!p.parameter_type.nullable) { ctypename += "*"; } @@ -3709,3 +3712,5 @@ internal class Vala.CCodeBaseModule : CCodeModule { return node.ccodenode; } } + +// vim:sw=8 noet diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index 457b13553..aef68650a 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -285,6 +285,10 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("type_id = \"%s\", ".printf (st.get_type_id ())); } + if (!st.use_const) { + write_string ("use_const = false, "); + } + bool first = true; string cheaders = ""; foreach (string cheader in st.get_cheader_filenames ()) { diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 6962b2938..4d13ac761 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -80,6 +80,12 @@ public class Vala.Struct : TypeSymbol { */ public Method default_construction_method { get; set; } + /** + * Specifies if 'const' should be emitted for input parameters + * of this type. + */ + public bool use_const { get; set; default = true; } + /** * Specifies whether this struct has a registered GType. */ @@ -392,6 +398,9 @@ public class Vala.Struct : TypeSymbol { if (a.has_argument ("destroy_function")) { set_destroy_function (a.get_string ("destroy_function")); } + if (a.has_argument ("use_const")) { + use_const = a.get_bool ("use_const"); + } } private void process_boolean_type_attribute (Attribute a) { @@ -720,3 +729,5 @@ public class Vala.Struct : TypeSymbol { return !error; } } + +// vim:sw=8 noet diff --git a/vapi/gtk+-2.0.vapi b/vapi/gtk+-2.0.vapi index da800fe22..ea3043f4e 100644 --- a/vapi/gtk+-2.0.vapi +++ b/vapi/gtk+-2.0.vapi @@ -5682,7 +5682,7 @@ namespace Gtk { public weak Gtk.ActionCallback callback; public bool is_active; } - [CCode (type_id = "GTK_TYPE_TREE_ITER", cheader_filename = "gtk/gtk.h")] + [CCode (type_id = "GTK_TYPE_TREE_ITER", use_const = false, cheader_filename = "gtk/gtk.h")] public struct TreeIter { public int stamp; public void* user_data; diff --git a/vapi/packages/gtk+-2.0/gtk+-2.0.metadata b/vapi/packages/gtk+-2.0/gtk+-2.0.metadata index 408312ba9..4a19c4165 100644 --- a/vapi/packages/gtk+-2.0/gtk+-2.0.metadata +++ b/vapi/packages/gtk+-2.0/gtk+-2.0.metadata @@ -393,7 +393,7 @@ GtkToolbar.GtkTooltips hidden="1" GtkToolbar.gpointer hidden="1" gtk_tool_item_toolbar_reconfigured hidden="1" GtkToolItem::set_tooltip hidden="1" -GtkTreeIter is_value_type="1" +GtkTreeIter is_value_type="1" use_const="0" gtk_tree_model_filter_new.root nullable="1" gtk_tree_model_get ellipsis="1" sentinel="-1" gtk_tree_model_get_iter.iter is_out="1" diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index daaabf5e6..3cebf3651 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -407,6 +407,10 @@ public class Vala.GIdlParser : CodeVisitor { if (eval (nv[1]) == "1") { st.set_simple_type (true); } + } else if (nv[0] == "use_const") { + if (eval (nv[1]) == "0") { + st.use_const = false; + } } } } @@ -682,6 +686,10 @@ public class Vala.GIdlParser : CodeVisitor { var nv = attr.split ("=", 2); if (nv[0] == "cheader_filename") { st.add_cheader_filename (eval (nv[1])); + } else if (nv[0] == "use_const") { + if (eval (nv[1]) == "0") { + st.use_const = false; + } } } } @@ -1044,7 +1052,7 @@ public class Vala.GIdlParser : CodeVisitor { var m = parse_function ((IdlNodeFunction) member, true); if (m != null) { iface.add_method (m); - } + } } } else if (member.type == IdlNodeTypeId.VFUNC) { var m = parse_virtual ((IdlNodeVFunc) member, current_type_func_map.get (member.name), true); @@ -1955,3 +1963,5 @@ public class Vala.GIdlParser : CodeVisitor { return sig; } } + +// vim:sw=8 noet