]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add support for a 'use_const' CCode attribute and GIDL XML attribute that,
authorRyan Lortie <desrt@desrt.ca>
Mon, 16 Feb 2009 22:17:18 +0000 (22:17 +0000)
committerRyan Lortie <ryanl@src.gnome.org>
Mon, 16 Feb 2009 22:17:18 +0000 (22:17 +0000)
2009-02-17  Ryan Lortie  <desrt@desrt.ca>

        * 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

ChangeLog
gobject/valaccodebasemodule.vala
vala/valacodewriter.vala
vala/valastruct.vala
vapi/gtk+-2.0.vapi
vapi/packages/gtk+-2.0/gtk+-2.0.metadata
vapigen/valagidlparser.vala

index 1e9272f51d369a2dcfa62282c8bf1a64ccc74bd2..88927d6b6d9a76b20f13b86ff85e292b14126ef0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-02-17  Ryan Lortie  <desrt@desrt.ca>
+
+       * 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  <desrt@desrt.ca>
 
        * vala/valaclass.vala: only use g_value_set_pointer if the GType of a
index bb66a04af8ca01ddf2cd5a00a624eceb6a764fe8..874b8df494a347bb40ed26cd57dbbcdbf4338466 100644 (file)
@@ -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
index 457b13553f9c753fef1ca9f0ce4702c50138c47d..aef68650a7c878bb174aca972b262e8ad8a8e020 100644 (file)
@@ -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 ()) {
index 6962b2938678bbd7d2a90e003feb6756b1d1b640..4d13ac76196243bc47ba7add46adaef5994b3847 100644 (file)
@@ -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
index da800fe22642bcdaf7d54263e8799656f5c146d0..ea3043f4e32f4e5333cad9397f34b07a4072d4b8 100644 (file)
@@ -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;
index 408312ba9f489ef7aff846d60806c175be756fb4..4a19c4165a32b46813ceb03a58a08f0882f32af8 100644 (file)
@@ -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"
index daaabf5e676b01c1c7f9f3de4a54c808a1587332..3cebf3651f85387127e8bbbbc49574311a7b596c 100644 (file)
@@ -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