vala r1677 - in trunk: . gobject vala



Author: juergbi
Date: Sat Jul  5 14:21:12 2008
New Revision: 1677
URL: http://svn.gnome.org/viewvc/vala?rev=1677&view=rev

Log:
2008-07-05  JÃrg Billeter  <j bitron ch>

	* vala/valaattributeprocessor.vala:
	* vala/valaparser.vala:
	* vala/valapropertyaccessor.vala:
	* gobject/valaccodegenerator.vala:
	* gobject/valaccodememberaccessbinding.vala:

	Add support for [CCode (cname = "foo")] to property accessors,
	based on patch by Jared Moore


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodegenerator.vala
   trunk/gobject/valaccodememberaccessbinding.vala
   trunk/vala/valaattributeprocessor.vala
   trunk/vala/valaparser.vala
   trunk/vala/valapropertyaccessor.vala

Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala	(original)
+++ trunk/gobject/valaccodegenerator.vala	Sat Jul  5 14:21:12 2008
@@ -810,9 +810,9 @@
 
 		if (prop.is_abstract || prop.is_virtual) {
 			if (acc.readable) {
-				function = new CCodeFunction ("%s_get_%s".printf (t.get_lower_case_cname (null), prop.name), prop.property_type.get_cname ());
+				function = new CCodeFunction (acc.get_cname (), prop.property_type.get_cname ());
 			} else {
-				function = new CCodeFunction ("%s_set_%s".printf (t.get_lower_case_cname (null), prop.name), "void");
+				function = new CCodeFunction (acc.get_cname (), "void");
 			}
 			function.add_parameter (cselfparam);
 			if (acc.writable || acc.construction) {
@@ -885,20 +885,28 @@
 		if (!prop.is_abstract) {
 			bool is_virtual = prop.base_property != null || prop.base_interface_property != null;
 
-			string prefix = t.get_lower_case_cname (null);
+			string cname;
 			if (is_virtual) {
-				prefix += "_real";
+				if (acc.readable) {
+					cname = "%s_real_get_%s".printf (t.get_lower_case_cname (null), prop.name);
+				} else {
+					cname = "%s_real_set_%s".printf (t.get_lower_case_cname (null), prop.name);
+				}
+			} else {
+				cname = acc.get_cname ();
 			}
+
 			if (acc.readable) {
 				if (returns_real_struct) {
 					// return non simple structs as out parameter
-					function = new CCodeFunction ("%s_get_%s".printf (prefix, prop.name), "void");
+					function = new CCodeFunction (cname, "void");
 				} else {
-					function = new CCodeFunction ("%s_get_%s".printf (prefix, prop.name), prop.property_type.get_cname ());
+					function = new CCodeFunction (cname, prop.property_type.get_cname ());
 				}
 			} else {
-				function = new CCodeFunction ("%s_set_%s".printf (prefix, prop.name), "void");
+				function = new CCodeFunction (cname, "void");
 			}
+
 			if (is_virtual) {
 				function.modifiers |= CCodeModifiers.STATIC;
 			}

Modified: trunk/gobject/valaccodememberaccessbinding.vala
==============================================================================
--- trunk/gobject/valaccodememberaccessbinding.vala	(original)
+++ trunk/gobject/valaccodememberaccessbinding.vala	Sat Jul  5 14:21:12 2008
@@ -135,8 +135,11 @@
 		} else if (expr.symbol_reference is Property) {
 			var prop = (Property) expr.symbol_reference;
 
-			if (prop.get_accessor != null &&
-			    prop.get_accessor.automatic_body &&
+			if (prop.get_accessor == null) {
+				return;
+			}
+
+			if (prop.get_accessor.automatic_body &&
 			    codegen.current_type_symbol == prop.parent_symbol &&
 			    prop.base_property == null &&
 			    prop.base_interface_property == null) {
@@ -150,12 +153,11 @@
 				} else if (prop.base_interface_property != null) {
 					base_property = prop.base_interface_property;
 				}
-				var base_property_type = (TypeSymbol) base_property.parent_symbol;
 				string getter_cname;
 				if (prop is DynamicProperty) {
 					getter_cname = codegen.dynamic_property_binding ((DynamicProperty) prop).get_getter_cname ();
 				} else {
-					getter_cname = "%s_get_%s".printf (base_property_type.get_lower_case_cname (null), base_property.name);
+					getter_cname = base_property.get_accessor.get_cname ();
 				}
 				var ccall = new CCodeFunctionCall (new CCodeIdentifier (getter_cname));
 

Modified: trunk/vala/valaattributeprocessor.vala
==============================================================================
--- trunk/vala/valaattributeprocessor.vala	(original)
+++ trunk/vala/valaattributeprocessor.vala	Sat Jul  5 14:21:12 2008
@@ -98,6 +98,12 @@
 
 	public override void visit_property (Property prop) {
 		prop.process_attributes ();
+
+		prop.accept_children (this);
+	}
+
+	public override void visit_property_accessor (PropertyAccessor p) {
+		p.process_attributes ();
 	}
 
 	public override void visit_delegate (Delegate d) {

Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala	(original)
+++ trunk/vala/valaparser.vala	Sat Jul  5 14:21:12 2008
@@ -2181,7 +2181,7 @@
 				expect (TokenType.SEMICOLON);
 			} else {
 				var accessor_begin = get_location ();
-				parse_attributes ();
+				var attrs = parse_attributes ();
 				var accessor_access = parse_access_modifier (SymbolAccessibility.PUBLIC);
 				if (accept (TokenType.GET)) {
 					if (prop.get_accessor != null) {
@@ -2192,6 +2192,7 @@
 						block = parse_block ();
 					}
 					prop.get_accessor = new PropertyAccessor (true, false, false, block, get_src (accessor_begin));
+					set_attributes (prop.get_accessor, attrs);
 					prop.get_accessor.access = accessor_access;
 				} else {
 					bool writable, _construct;
@@ -2212,6 +2213,7 @@
 						block = parse_block ();
 					}
 					prop.set_accessor = new PropertyAccessor (false, writable, _construct, block, get_src (accessor_begin));
+					set_attributes (prop.set_accessor, attrs);
 					prop.set_accessor.access = accessor_access;
 				}
 			}

Modified: trunk/vala/valapropertyaccessor.vala
==============================================================================
--- trunk/vala/valapropertyaccessor.vala	(original)
+++ trunk/vala/valapropertyaccessor.vala	Sat Jul  5 14:21:12 2008
@@ -70,6 +70,26 @@
 	 * Represents the generated value parameter in a set accessor.
 	 */
 	public FormalParameter value_parameter { get; set; }
+
+	/**
+	 * The publicly accessible name of the function that performs the
+	 * access in C code.
+	 */
+	public string get_cname () {
+		if (_cname != null) {
+			return _cname;
+		}
+
+		var t = (TypeSymbol) prop.parent_symbol;
+
+		if (readable) {
+			return "%s_get_%s".printf (t.get_lower_case_cname (null), prop.name);
+		} else {
+			return "%s_set_%s".printf (t.get_lower_case_cname (null), prop.name);
+		}
+	}
+
+	private string? _cname;
 	
 	/**
 	 * Creates a new property accessor.
@@ -98,4 +118,17 @@
 			body.accept (visitor);
 		}
 	}
+
+	/**
+	 * Process all associated attributes.
+	 */
+	public void process_attributes () {
+		foreach (Attribute a in attributes) {
+			if (a.name == "CCode") {
+				if (a.has_argument ("cname")) {
+					_cname = a.get_string ("cname");
+				}
+			}
+		}
+	}
 }



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