vala r1895 - in trunk: . gobject vala



Author: juergbi
Date: Fri Oct 24 13:59:42 2008
New Revision: 1895
URL: http://svn.gnome.org/viewvc/vala?rev=1895&view=rev

Log:
2008-10-24  JÃrg Billeter  <j bitron ch>

	* vala/valacodegenerator.vala:
	* vala/valadynamicproperty.vala:
	* gobject/Makefile.am:
	* gobject/valaccodedynamicpropertymodule.vala:
	* gobject/valaccodegenerator.vala:
	* gobject/valaccodememberaccessmodule.vala:
	* gobject/valaccodemodule.vala:

	Add CCodeDynamicPropertyModule


Added:
   trunk/gobject/valaccodedynamicpropertymodule.vala   (contents, props changed)
      - copied, changed from r1880, /trunk/gobject/valaccodedynamicpropertybinding.vala
Removed:
   trunk/gobject/valaccodedynamicpropertybinding.vala
Modified:
   trunk/ChangeLog
   trunk/gobject/Makefile.am
   trunk/gobject/valaccodegenerator.vala
   trunk/gobject/valaccodememberaccessmodule.vala
   trunk/gobject/valaccodemodule.vala
   trunk/vala/valacodegenerator.vala
   trunk/vala/valadynamicproperty.vala

Modified: trunk/gobject/Makefile.am
==============================================================================
--- trunk/gobject/Makefile.am	(original)
+++ trunk/gobject/Makefile.am	Fri Oct 24 13:59:42 2008
@@ -17,7 +17,7 @@
 	valaccodebasemodule.vala \
 	valaccodebinding.vala \
 	valaccodecompiler.vala \
-	valaccodedynamicpropertybinding.vala \
+	valaccodedynamicpropertymodule.vala \
 	valaccodedynamicsignalbinding.vala \
 	valaccodeelementaccessmodule.vala \
 	valaccodegenerator.vala \

Copied: trunk/gobject/valaccodedynamicpropertymodule.vala (from r1880, /trunk/gobject/valaccodedynamicpropertybinding.vala)
==============================================================================
--- /trunk/gobject/valaccodedynamicpropertybinding.vala	(original)
+++ trunk/gobject/valaccodedynamicpropertymodule.vala	Fri Oct 24 13:59:42 2008
@@ -1,4 +1,4 @@
-/* valaccodedynamicpropertybinding.vala
+/* valaccodedynamicpropertymodule.vala
  *
  * Copyright (C) 2008  JÃrg Billeter
  *
@@ -26,25 +26,15 @@
 /**
  * The link between a dynamic property and generated code.
  */
-public class Vala.CCodeDynamicPropertyBinding : CCodeBinding {
-	public Property node { get; set; }
+public class Vala.CCodeDynamicPropertyModule : CCodeModule {
+	int dynamic_property_id;
 
-	string? getter_cname;
-	string? setter_cname;
-
-	static int dynamic_property_id;
-
-	public CCodeDynamicPropertyBinding (CCodeGenerator codegen, DynamicProperty property) {
-		this.node = property;
-		this.codegen = codegen;
+	public CCodeDynamicPropertyModule (CCodeGenerator codegen, CCodeModule? next) {
+		base (codegen, next);
 	}
 
-	public string get_getter_cname () {
-		if (getter_cname != null) {
-			return getter_cname;
-		}
-
-		getter_cname = "_dynamic_get_%s%d".printf (node.name, dynamic_property_id++);
+	public override string get_dynamic_property_getter_cname (DynamicProperty node) {
+		string getter_cname = "_dynamic_get_%s%d".printf (node.name, dynamic_property_id++);
 
 		var dynamic_property = (DynamicProperty) node;
 
@@ -55,10 +45,10 @@
 
 		var block = new CCodeBlock ();
 		if (dynamic_property.dynamic_type.data_type == codegen.dbus_object_type) {
-			generate_dbus_property_getter_wrapper (block);
+			generate_dbus_property_getter_wrapper (node, block);
 		} else if (dynamic_property.dynamic_type.data_type != null
 		           && dynamic_property.dynamic_type.data_type.is_subtype_of (codegen.gobject_type)) {
-			generate_gobject_property_getter_wrapper (block);
+			generate_gobject_property_getter_wrapper (node, block);
 		} else {
 			Report.error (node.source_reference, "dynamic properties are not supported for `%s'".printf (dynamic_property.dynamic_type.to_string ()));
 		}
@@ -72,16 +62,12 @@
 		return getter_cname;
 	}
 
-	public string get_setter_cname () {
-		if (setter_cname != null) {
-			return setter_cname;
-		}
-
-		getter_cname = "_dynamic_set_%s%d".printf (node.name, dynamic_property_id++);
+	public override string get_dynamic_property_setter_cname (DynamicProperty node) {
+		string setter_cname = "_dynamic_set_%s%d".printf (node.name, dynamic_property_id++);
 
 		var dynamic_property = (DynamicProperty) node;
 
-		var func = new CCodeFunction (getter_cname, "void");
+		var func = new CCodeFunction (setter_cname, "void");
 		func.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.INLINE;
 
 		func.add_parameter (new CCodeFormalParameter ("obj", dynamic_property.dynamic_type.get_cname ()));
@@ -89,10 +75,10 @@
 
 		var block = new CCodeBlock ();
 		if (dynamic_property.dynamic_type.data_type == codegen.dbus_object_type) {
-			generate_dbus_property_setter_wrapper (block);
+			generate_dbus_property_setter_wrapper (node, block);
 		} else if (dynamic_property.dynamic_type.data_type != null
 		           && dynamic_property.dynamic_type.data_type.is_subtype_of (codegen.gobject_type)) {
-			generate_gobject_property_setter_wrapper (block);
+			generate_gobject_property_setter_wrapper (node, block);
 		} else {
 			Report.error (node.source_reference, "dynamic properties are not supported for `%s'".printf (dynamic_property.dynamic_type.to_string ()));
 		}
@@ -103,10 +89,10 @@
 		func.block = block;
 		codegen.source_type_member_definition.append (func);
 
-		return getter_cname;
+		return setter_cname;
 	}
 
-	void generate_gobject_property_getter_wrapper (CCodeBlock block) {
+	void generate_gobject_property_getter_wrapper (DynamicProperty node, CCodeBlock block) {
 		var cdecl = new CCodeDeclaration (node.property_type.get_cname ());
 		cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
 		block.add_statement (cdecl);
@@ -122,7 +108,7 @@
 		block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
 	}
 
-	void generate_gobject_property_setter_wrapper (CCodeBlock block) {
+	void generate_gobject_property_setter_wrapper (DynamicProperty node, CCodeBlock block) {
 		var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_set"));
 		call.add_argument (new CCodeIdentifier ("obj"));
 		call.add_argument (node.get_canonical_cconstant ());
@@ -132,7 +118,7 @@
 		block.add_statement (new CCodeExpressionStatement (call));
 	}
 
-	void create_dbus_property_proxy (CCodeBlock block) {
+	void create_dbus_property_proxy (DynamicProperty node, CCodeBlock block) {
 		var prop_proxy_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_g_proxy_new_from_proxy"));
 		prop_proxy_call.add_argument (new CCodeIdentifier ("obj"));
 		prop_proxy_call.add_argument (new CCodeConstant ("DBUS_INTERFACE_PROPERTIES"));
@@ -143,8 +129,8 @@
 		block.add_statement (prop_proxy_decl);
 	}
 
-	void generate_dbus_property_getter_wrapper (CCodeBlock block) {
-		create_dbus_property_proxy (block);
+	void generate_dbus_property_getter_wrapper (DynamicProperty node, CCodeBlock block) {
+		create_dbus_property_proxy (node, block);
 
 		// initialize GValue
 		var cvalinit = new CCodeInitializerList ();
@@ -198,8 +184,8 @@
 		block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
 	}
 
-	void generate_dbus_property_setter_wrapper (CCodeBlock block) {
-		create_dbus_property_proxy (block);
+	void generate_dbus_property_setter_wrapper (DynamicProperty node, CCodeBlock block) {
+		create_dbus_property_proxy (node, block);
 
 		// initialize GValue
 		var cvalinit = new CCodeInitializerList ();

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Fri Oct 24 13:59:42 2008
@@ -148,6 +148,7 @@
 		head = new CCodeAssignmentModule (this, head);
 		head = new CCodeInvocationExpressionModule (this, head);
 		head = new CCodeArrayModule (this, head);
+		head = new CCodeDynamicPropertyModule (this, head);
 		head = new GObjectModule (this, head);
 		head = new GObjectClassModule (this, head);
 		head = new GObjectInterfaceModule (this, head);
@@ -4162,7 +4163,7 @@
 			var base_property_type = (TypeSymbol) base_property.parent_symbol;
 			set_func = "%s_set_%s".printf (base_property_type.get_lower_case_cname (null), base_property.name);
 			if (prop is DynamicProperty) {
-				set_func = dynamic_property_binding ((DynamicProperty) prop).get_setter_cname ();
+				set_func = head.get_dynamic_property_setter_cname ((DynamicProperty) prop);
 			}
 		}
 		
@@ -4367,10 +4368,6 @@
 		return node.ccodenode;
 	}
 
-	public override CodeBinding? create_dynamic_property_binding (DynamicProperty node) {
-		return new CCodeDynamicPropertyBinding (this, node);
-	}
-
 	public override CodeBinding? create_dynamic_signal_binding (DynamicSignal node) {
 		return new CCodeDynamicSignalBinding (this, node);
 	}
@@ -4379,10 +4376,6 @@
 		return (CCodeBinding) node.get_code_binding (this);
 	}
 
-	public CCodeDynamicPropertyBinding dynamic_property_binding (DynamicProperty node) {
-		return (CCodeDynamicPropertyBinding) node.get_code_binding (this);
-	}
-
 	public CCodeDynamicSignalBinding dynamic_signal_binding (DynamicSignal node) {
 		return (CCodeDynamicSignalBinding) node.get_code_binding (this);
 	}

Modified: trunk/gobject/valaccodememberaccessmodule.vala
==============================================================================
--- trunk/gobject/valaccodememberaccessmodule.vala	(original)
+++ trunk/gobject/valaccodememberaccessmodule.vala	Fri Oct 24 13:59:42 2008
@@ -168,7 +168,7 @@
 				}
 				string getter_cname;
 				if (prop is DynamicProperty) {
-					getter_cname = codegen.dynamic_property_binding ((DynamicProperty) prop).get_getter_cname ();
+					getter_cname = head.get_dynamic_property_getter_cname ((DynamicProperty) prop);
 				} else {
 					getter_cname = base_property.get_accessor.get_cname ();
 				}

Modified: trunk/gobject/valaccodemodule.vala
==============================================================================
--- trunk/gobject/valaccodemodule.vala	(original)
+++ trunk/gobject/valaccodemodule.vala	Fri Oct 24 13:59:42 2008
@@ -123,4 +123,12 @@
 	public virtual CCodeFragment register_dbus_info (ObjectTypeSymbol bindable) {
 		return next.register_dbus_info (bindable);
 	}
+
+	public virtual string get_dynamic_property_getter_cname (DynamicProperty node) {
+		return next.get_dynamic_property_getter_cname (node);
+	}
+
+	public virtual string get_dynamic_property_setter_cname (DynamicProperty node) {
+		return next.get_dynamic_property_setter_cname (node);
+	}
 }

Modified: trunk/vala/valacodegenerator.vala
==============================================================================
--- trunk/vala/valacodegenerator.vala	(original)
+++ trunk/vala/valacodegenerator.vala	Fri Oct 24 13:59:42 2008
@@ -34,10 +34,6 @@
 	public virtual void emit (CodeContext context) {
 	}
 
-	public virtual CodeBinding? create_dynamic_property_binding (DynamicProperty node) {
-		return null;
-	}
-
 	public virtual CodeBinding? create_dynamic_signal_binding (DynamicSignal node) {
 		return null;
 	}

Modified: trunk/vala/valadynamicproperty.vala
==============================================================================
--- trunk/vala/valadynamicproperty.vala	(original)
+++ trunk/vala/valadynamicproperty.vala	Fri Oct 24 13:59:42 2008
@@ -42,7 +42,4 @@
 		return new ArrayList<string> ();
 	}
 
-	public override CodeBinding? create_code_binding (CodeGenerator codegen) {
-		return codegen.create_dynamic_property_binding (this);
-	}
 }



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