[vala] vapigen: Add support for array_length_cname for fields



commit f88e8f45509c6eb7539bc13be8a500162bbb5cf2
Author: Evan Nemerson <evan coeus-group com>
Date:   Thu Feb 18 00:40:36 2010 -0800

    vapigen: Add support for array_length_cname for fields

 vala/valacodewriter.vala    |   25 +++++++++++++++++--------
 vapigen/valagidlparser.vala |   10 +++++++++-
 2 files changed, 26 insertions(+), 9 deletions(-)
---
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index d56d984..98eee7c 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 5664b41..e971ac0 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;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]