]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support array_length_type for fields
authorEvan Nemerson <evan@coeus-group.com>
Sat, 13 Mar 2010 17:05:14 +0000 (18:05 +0100)
committerJürg Billeter <j@bitron.ch>
Sat, 13 Mar 2010 17:05:51 +0000 (18:05 +0100)
Fixes part of bug 529866.

codegen/valaccodearraymodule.vala
vala/valacodewriter.vala
vala/valafield.vala
vapigen/valagidlparser.vala

index ec7dd838f6a9a1468915c51986324725bb41c0c8..72d169f322eb8c8d38ec4c61d5df609939596951 100644 (file)
@@ -311,6 +311,10 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
                                                } else {
                                                        length_expr = new CCodeMemberAccess (inst, length_cname);
                                                }
+
+                                               if (field.array_length_type != null) {
+                                                       length_expr = new CCodeCastExpression (length_expr, "gint");
+                                               }
                                        } else {
                                                length_expr = new CCodeIdentifier (get_array_length_cname (field.get_cname (), dim));
                                        }
index 98eee7c7de0bfdae64471911a6c302727cd0577d..bcfc8aa5187df3338bfb3ea75c2ddd78aedffae6 100644 (file)
@@ -628,7 +628,8 @@ public class Vala.CodeWriter : CodeVisitor {
                bool custom_ctype = (f.get_ctype () != null);
                bool custom_cheaders = (f.parent_symbol is Namespace);
                bool custom_array_length_cname = (f.get_array_length_cname () != null);
-               if (custom_cname || custom_ctype || custom_cheaders || custom_array_length_cname || (f.no_array_length && f.field_type is ArrayType)) {
+               bool custom_array_length_type = (f.array_length_type != null);
+               if (custom_cname || custom_ctype || custom_cheaders || custom_array_length_cname || custom_array_length_type || (f.no_array_length && f.field_type is ArrayType)) {
                        write_indent ();
                        write_string ("[CCode (");
 
@@ -663,12 +664,22 @@ public class Vala.CodeWriter : CodeVisitor {
                                        if (f.array_null_terminated) {
                                                write_string (", array_null_terminated = true");
                                        }
-                               } else if (custom_array_length_cname) {
-                                       if (custom_cname || custom_ctype || custom_cheaders) {
-                                               write_string (", ");
+                               } else {
+                                       if (custom_array_length_cname) {
+                                               if (custom_cname || custom_ctype || custom_cheaders) {
+                                                       write_string (", ");
+                                               }
+
+                                               write_string ("array_length_cname = \"%s\"".printf (f.get_array_length_cname ()));
                                        }
 
-                                       write_string ("array_length_cname = \"%s\"".printf (f.get_array_length_cname ()));
+                                       if (custom_array_length_type) {
+                                               if (custom_cname || custom_ctype || custom_cheaders || custom_array_length_cname) {
+                                                       write_string (", ");
+                                               }
+
+                                               write_string ("array_length_type = \"%s\"".printf (f.array_length_type));
+                                       }
                                }
                        }
 
index 209c024e0b63718af30fb46af3ad65259292abe2..87d12c12c0534cefb4526d643f915bfddf011bde 100644 (file)
@@ -93,6 +93,11 @@ public class Vala.Field : Member, Lockable {
                get { return (array_length_cexpr != null); }
        }
 
+       /**
+        * Specifies a custom type for the array length.
+        */
+       public string? array_length_type { get; set; default = null; }
+
        private string? array_length_cname;
 
        private string? array_length_cexpr;
@@ -229,6 +234,9 @@ public class Vala.Field : Member, Lockable {
                if (a.has_argument ("array_length_cexpr")) {
                        set_array_length_cexpr (a.get_string ("array_length_cexpr"));
                }
+               if (a.has_argument ("array_length_type")) {
+                       array_length_type = a.get_string ("array_length_type");
+               }
                if (a.has_argument ("delegate_target")) {
                        no_delegate_target = !a.get_bool ("delegate_target");
                }
index 47e1fea529df5d7b21afbd104d1fbe5999b67f09..72f10179bdaf9601f6e32c298c7594e6bd992c56 100644 (file)
@@ -1974,6 +1974,7 @@ public class Vala.GIdlParser : CodeVisitor {
                string cheader_filename = null;
                string ctype = null;
                string array_length_cname = null;
+               string array_length_type = null;
                bool array_null_terminated = false;
 
                var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name));
@@ -2018,6 +2019,8 @@ public class Vala.GIdlParser : CodeVisitor {
                                        }
                                } else if (nv[0] == "array_length_cname") {
                                        array_length_cname = eval (nv[1]);
+                               } else if (nv[0] == "array_length_type") {
+                                       array_length_type = eval (nv[1]);
                                }
                        }
                }
@@ -2055,8 +2058,13 @@ public class Vala.GIdlParser : CodeVisitor {
                        field.array_null_terminated = true;
                }
 
-               if (array_length_cname != null) {
-                       field.set_array_length_cname (array_length_cname);
+               if (array_length_cname != null || array_length_type != null) {
+                       if (array_length_cname != null) {
+                               field.set_array_length_cname (array_length_cname);
+                       }
+                       if (array_length_type != null) {
+                               field.array_length_type = array_length_type;
+                       }
                } else {
                        field.no_array_length = true;
                }