From: Evan Nemerson Date: Thu, 18 Feb 2010 08:40:36 +0000 (-0800) Subject: vapigen: Add support for array_length_cname for fields X-Git-Tag: 0.8.0~241 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f88e8f45509c6eb7539bc13be8a500162bbb5cf2;p=thirdparty%2Fvala.git vapigen: Add support for array_length_cname for fields --- diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index d56d984c0..98eee7c7d 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -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 ())); } } diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index 5664b416d..e971ac092 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -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; }