vala r1638 - in trunk: . gobject vala vapi vapi/packages/gtk+-2.0 vapigen



Author: juergbi
Date: Mon Jun 23 13:46:49 2008
New Revision: 1638
URL: http://svn.gnome.org/viewvc/vala?rev=1638&view=rev

Log:
2008-06-23  JÃrg Billeter  <j bitron ch>

	* vala/valaattribute.vala:
	* vala/valafield.vala:
	* vala/valainterfacewriter.vala:
	* vala/valanamedargument.vala:
	* vala/valastringliteral.vala:
	* gobject/valaccodegenerator.vala:
	* vapigen/valagidlparser.vala:

	Support [CCode (type = "Foo")] to insert appropriate casts in
	generated C Code

	* vapi/packages/gtk+-2.0/:

	Fix GtkActionEntry binding, fixes bug 526874

	* vapi/gtk+-2.0.vapi: regenerated


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodegenerator.vala
   trunk/vala/valaattribute.vala
   trunk/vala/valafield.vala
   trunk/vala/valainterfacewriter.vala
   trunk/vala/valanamedargument.vala
   trunk/vala/valastringliteral.vala
   trunk/vapi/gtk+-2.0.vapi
   trunk/vapi/packages/gtk+-2.0/gtk+-2.0.metadata
   trunk/vapigen/valagidlparser.vala

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Mon Jun 23 13:46:49 2008
@@ -1257,11 +1257,42 @@
 	public override void visit_initializer_list (InitializerList list) {
 		list.accept_children (this);
 
-		var clist = new CCodeInitializerList ();
-		foreach (Expression expr in list.get_initializers ()) {
-			clist.append ((CCodeExpression) expr.ccodenode);
+		if (list.target_type.data_type is Struct) {
+			/* initializer is used as struct initializer */
+			var st = (Struct) list.target_type.data_type;
+
+			var clist = new CCodeInitializerList ();
+
+			var field_it = st.get_fields ().iterator ();
+			foreach (Expression expr in list.get_initializers ()) {
+				Field field = null;
+				while (field == null) {
+					field_it.next ();
+					field = field_it.get ();
+					if (field.binding != MemberBinding.INSTANCE) {
+						// we only initialize instance fields
+						field = null;
+					}
+				}
+
+				var cexpr = (CCodeExpression) expr.ccodenode;
+
+				string ctype = field.get_ctype ();
+				if (ctype != null) {
+					cexpr = new CCodeCastExpression (cexpr, ctype);
+				}
+
+				clist.append (cexpr);
+			}
+
+			list.ccodenode = clist;
+		} else {
+			var clist = new CCodeInitializerList ();
+			foreach (Expression expr in list.get_initializers ()) {
+				clist.append ((CCodeExpression) expr.ccodenode);
+			}
+			list.ccodenode = clist;
 		}
-		list.ccodenode = clist;
 	}
 
 	public LocalVariable get_temp_variable (DataType type, bool value_owned = true, CodeNode? node_reference = null) {

Modified: trunk/vala/valaattribute.vala
==============================================================================
--- trunk/vala/valaattribute.vala	(original)
+++ trunk/vala/valaattribute.vala	Mon Jun 23 13:46:49 2008
@@ -44,7 +44,7 @@
 	 * @param source_reference reference to source code
 	 * @return                 newly created attribute
 	 */
-	public Attribute (string name, SourceReference? source_reference) {
+	public Attribute (string name, SourceReference? source_reference = null) {
 		this.name = name;
 		this.source_reference = source_reference;
 	}

Modified: trunk/vala/valafield.vala
==============================================================================
--- trunk/vala/valafield.vala	(original)
+++ trunk/vala/valafield.vala	Mon Jun 23 13:46:49 2008
@@ -179,4 +179,21 @@
 			field_type = new_type;
 		}
 	}
+
+	public string? get_ctype () {
+		var attr = get_attribute ("CCode");
+		if (attr == null) {
+			return null;
+		}
+		return attr.get_string ("type");
+	}
+
+	public void set_ctype (string ctype) {
+		var attr = get_attribute ("CCode");
+		if (attr == null) {
+			attr = new Attribute ("CCode");
+			attributes.append (attr);
+		}
+		attr.add_argument (new NamedArgument ("type", new StringLiteral ("\"%s\"".printf (ctype))));
+	}
 }

Modified: trunk/vala/valainterfacewriter.vala
==============================================================================
--- trunk/vala/valainterfacewriter.vala	(original)
+++ trunk/vala/valainterfacewriter.vala	Mon Jun 23 13:46:49 2008
@@ -516,8 +516,9 @@
 		}
 
 		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_cheaders) {
+		if (custom_cname || custom_ctype || custom_cheaders) {
 			write_indent ();
 			write_string ("[CCode (");
 
@@ -525,11 +526,19 @@
 				write_string ("cname = \"%s\"".printf (f.get_cname ()));
 			}
 
-			if (custom_cheaders) {
+			if (custom_ctype) {
 				if (custom_cname) {
 					write_string (", ");
 				}
 
+				write_string ("type = \"%s\"".printf (f.get_ctype ()));
+			}
+
+			if (custom_cheaders) {
+				if (custom_cname || custom_ctype) {
+					write_string (", ");
+				}
+
 				bool first = true;
 				string cheaders;
 				foreach (string cheader in f.get_cheader_filenames ()) {

Modified: trunk/vala/valanamedargument.vala
==============================================================================
--- trunk/vala/valanamedargument.vala	(original)
+++ trunk/vala/valanamedargument.vala	Mon Jun 23 13:46:49 2008
@@ -1,6 +1,6 @@
 /* valanamedargument.vala
  *
- * Copyright (C) 2006  JÃrg Billeter
+ * Copyright (C) 2006-2008  JÃrg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -45,10 +45,10 @@
 	 * @param source reference to source code
 	 * @return       newly created named argument
 	 */
-	public NamedArgument (string _name, Expression arg, SourceReference source) {
-		name = _name;
-		argument = arg;
-		source_reference = source;
+	public NamedArgument (string name, Expression argument, SourceReference? source_reference = null) {
+		this.name = name;
+		this.argument = argument;
+		this.source_reference = source_reference;
 	}
 	
 	public override void accept (CodeVisitor visitor) {

Modified: trunk/vala/valastringliteral.vala
==============================================================================
--- trunk/vala/valastringliteral.vala	(original)
+++ trunk/vala/valastringliteral.vala	Mon Jun 23 13:46:49 2008
@@ -38,9 +38,9 @@
 	 * @param source reference to source code
 	 * @return       newly created string literal
 	 */
-	public StringLiteral (string s, SourceReference source) {
-		value = s;
-		source_reference = source;
+	public StringLiteral (string value, SourceReference? source_reference = null) {
+		this.value = value;
+		this.source_reference = source_reference;
 	}
 
 	/**

Modified: trunk/vapi/gtk+-2.0.vapi
==============================================================================
--- trunk/vapi/gtk+-2.0.vapi	(original)
+++ trunk/vapi/gtk+-2.0.vapi	Mon Jun 23 13:46:49 2008
@@ -6212,6 +6212,7 @@
 		public weak string label;
 		public weak string accelerator;
 		public weak string tooltip;
+		[CCode (type = "GCallback")]
 		public weak Gtk.ActionCallback callback;
 	}
 	[CCode (cheader_filename = "gtk/gtk.h")]

Modified: trunk/vapi/packages/gtk+-2.0/gtk+-2.0.metadata
==============================================================================
--- trunk/vapi/packages/gtk+-2.0/gtk+-2.0.metadata	(original)
+++ trunk/vapi/packages/gtk+-2.0/gtk+-2.0.metadata	Mon Jun 23 13:46:49 2008
@@ -18,7 +18,7 @@
 gtk_action_new.stock_id nullable="1"
 GtkAction::activate has_emitter="1"
 GtkActionEntry is_value_type="1"
-GtkActionEntry.callback type_name="ActionCallback"
+GtkActionEntry.callback type_name="ActionCallback" ctype="GCallback"
 gtk_action_group_add_action_with_accel.accelerator nullable="1"
 gtk_action_group_add_actions.user_data hidden="0"
 gtk_action_group_add_actions_full.user_data hidden="0"

Modified: trunk/vapigen/valagidlparser.vala
==============================================================================
--- trunk/vapigen/valagidlparser.vala	(original)
+++ trunk/vapigen/valagidlparser.vala	Mon Jun 23 13:46:49 2008
@@ -1663,6 +1663,7 @@
 		}
 
 		string cheader_filename = null;
+		string ctype = null;
 
 		var attributes = get_attributes ("%s.%s".printf (current_data_type.get_cname (), node.name));
 		if (attributes != null) {
@@ -1693,6 +1694,8 @@
 					}
 				} else if (nv[0] == "cheader_filename") {
 					cheader_filename = eval (nv[1]);
+				} else if (nv[0] == "ctype") {
+					ctype = eval (nv[1]);
 				}
 			}
 		}
@@ -1718,6 +1721,10 @@
 			field.set_cname (node.name);
 		}
 
+		if (ctype != null) {
+			field.set_ctype (ctype);
+		}
+
 		if (cheader_filename != null) {
 			field.add_cheader_filename (cheader_filename);
 		}



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