]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vapigen: Add support for array_length_cname for fields
authorEvan Nemerson <evan@coeus-group.com>
Thu, 18 Feb 2010 08:40:36 +0000 (00:40 -0800)
committerJürg Billeter <j@bitron.ch>
Mon, 1 Mar 2010 09:54:27 +0000 (10:54 +0100)
vala/valacodewriter.vala
vapigen/valagidlparser.vala

index d56d984c02a52ca5990e869188a2a6284d4a4099..98eee7c7de0bfdae64471911a6c302727cd0577d 100644 (file)
@@ -627,7 +627,8 @@ public class Vala.CodeWriter : CodeVisitor {
                bool custom_cname = (f.get_cname () != f.get_default_cname ());
                bool custom_ctype = (f.get_ctype () != null);
                bool custom_cheaders = (f.parent_symbol is Namespace);
-               if (custom_cname || custom_ctype || custom_cheaders || (f.no_array_length && f.field_type is ArrayType)) {
+               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)) {
                        write_indent ();
                        write_string ("[CCode (");
 
@@ -651,15 +652,23 @@ public class Vala.CodeWriter : CodeVisitor {
                                write_string ("cheader_filename = \"%s\"".printf (get_cheaders(f)));
                        }
 
-                       if (f.no_array_length && f.field_type is ArrayType) {
-                               if (custom_cname || custom_ctype || custom_cheaders) {
-                                       write_string (", ");
-                               }
+                       if (f.field_type is ArrayType) {
+                               if (f.no_array_length) {
+                                       if (custom_cname || custom_ctype || custom_cheaders) {
+                                               write_string (", ");
+                                       }
 
-                               write_string ("array_length = false");
+                                       write_string ("array_length = false");
+
+                                       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 (", ");
+                                       }
 
-                               if (f.array_null_terminated) {
-                                       write_string (", array_null_terminated = true");
+                                       write_string ("array_length_cname = \"%s\"".printf (f.get_array_length_cname ()));
                                }
                        }
 
index 5664b416d47c39bcfda6527da05afeb666ef8ba8..e971ac09208d033576313d9f3e5a9f581776f5fb 100644 (file)
@@ -1973,6 +1973,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
                string cheader_filename = null;
                string ctype = null;
+               string array_length_cname = null;
                bool array_null_terminated = false;
 
                var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name));
@@ -2010,6 +2011,8 @@ public class Vala.GIdlParser : CodeVisitor {
                                        if (eval (nv[1]) == "1") {
                                                array_null_terminated = true;
                                        }
+                               } else if (nv[0] == "array_length_cname") {
+                                       array_length_cname = eval (nv[1]);
                                }
                        }
                }
@@ -2043,11 +2046,16 @@ public class Vala.GIdlParser : CodeVisitor {
                        field.add_cheader_filename (cheader_filename);
                }
 
-               field.no_array_length = true;
                if (array_null_terminated) {
                        field.array_null_terminated = true;
                }
 
+               if (array_length_cname != null) {
+                       field.set_array_length_cname (array_length_cname);
+               } else {
+                       field.no_array_length = true;
+               }
+
                return field;
        }