vala r2323 - in trunk: . gobject vala vapigen



Author: juergbi
Date: Sat Jan 10 14:25:40 2009
New Revision: 2323
URL: http://svn.gnome.org/viewvc/vala?rev=2323&view=rev

Log:
2009-01-10  JÃrg Billeter  <j bitron ch>

	* vala/valacodewriter.vala:
	* vala/valagenieparser.vala:
	* vala/valamemberaccess.vala:
	* vala/valaparser.vala:
	* vala/valapropertyaccessor.vala:
	* vala/valasemanticanalyzer.vala:
	* gobject/valaccodebasemodule.vala:
	* gobject/valaccodememberaccessmodule.vala:
	* vapigen/valagidlparser.vala:
	* vapigen/valagirparser.vala:

	Replace `#' in property declarations by `owned' modifier
	before `get'


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodebasemodule.vala
   trunk/gobject/valaccodememberaccessmodule.vala
   trunk/vala/valacodewriter.vala
   trunk/vala/valagenieparser.vala
   trunk/vala/valamemberaccess.vala
   trunk/vala/valaparser.vala
   trunk/vala/valapropertyaccessor.vala
   trunk/vala/valasemanticanalyzer.vala
   trunk/vapigen/valagidlparser.vala
   trunk/vapigen/valagirparser.vala

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Sat Jan 10 14:25:40 2009
@@ -1123,14 +1123,11 @@
 			this_type = new ObjectType ((Interface) t);
 		}
 		var cselfparam = new CCodeFormalParameter ("self", this_type.get_cname ());
-		var value_type = prop.property_type.copy ();
 		CCodeFormalParameter cvalueparam;
 		if (returns_real_struct) {
-			cvalueparam = new CCodeFormalParameter ("value", value_type.get_cname () + "*");
+			cvalueparam = new CCodeFormalParameter ("value", acc.value_type.get_cname () + "*");
 		} else {
-			// property setters never take ownership
-			value_type.value_owned = false;
-			cvalueparam = new CCodeFormalParameter ("value", value_type.get_cname ());
+			cvalueparam = new CCodeFormalParameter ("value", acc.value_type.get_cname ());
 		}
 
 		if (prop.is_abstract || prop.is_virtual) {
@@ -1217,7 +1214,7 @@
 			if (acc.writable || acc.construction || returns_real_struct) {
 				function = new CCodeFunction (cname, "void");
 			} else {
-				function = new CCodeFunction (cname, prop.property_type.get_cname ());
+				function = new CCodeFunction (cname, acc.value_type.get_cname ());
 			}
 
 			ObjectType base_type = null;

Modified: trunk/gobject/valaccodememberaccessmodule.vala
==============================================================================
--- trunk/gobject/valaccodememberaccessmodule.vala	(original)
+++ trunk/gobject/valaccodememberaccessmodule.vala	Sat Jan 10 14:25:40 2009
@@ -206,7 +206,7 @@
 				// The value is returned by out parameter
 				if (base_property.property_type.is_real_struct_type ()) {
 					var ccomma = new CCodeCommaExpression ();
-					var temp_var = get_temp_variable (base_property.property_type);
+					var temp_var = get_temp_variable (base_property.get_accessor.value_type);
 					var ctemp = new CCodeIdentifier (temp_var.name);
 					temp_vars.add (temp_var);
 					ccall.add_argument (new CCodeUnaryExpression(CCodeUnaryOperator.ADDRESS_OF, ctemp));

Modified: trunk/vala/valacodewriter.vala
==============================================================================
--- trunk/vala/valacodewriter.vala	(original)
+++ trunk/vala/valacodewriter.vala	Sat Jan 10 14:25:40 2009
@@ -952,20 +952,24 @@
 			write_string ("virtual ");
 		}
 
-		if (prop.property_type.value_owned) {
-			write_string ("owned ");
-		}
-
 		write_type (prop.property_type);
 
 		write_string (" ");
 		write_identifier (prop.name);
 		write_string (" {");
 		if (prop.get_accessor != null) {
+			if (prop.get_accessor.value_type.value_owned) {
+				write_string ("owned ");
+			}
+
 			write_string (" get");
 			write_code_block (prop.get_accessor.body);
 		}
 		if (prop.set_accessor != null) {
+			if (prop.set_accessor.value_type.value_owned) {
+				write_string ("owned ");
+			}
+
 			if (prop.set_accessor.writable) {
 				write_string (" set");
 			}

Modified: trunk/vala/valagenieparser.vala
==============================================================================
--- trunk/vala/valagenieparser.vala	(original)
+++ trunk/vala/valagenieparser.vala	Sat Jan 10 14:25:40 2009
@@ -2749,6 +2749,10 @@
 			while (current () != TokenType.DEDENT) {
 				var accessor_begin = get_location ();
 				parse_attributes ();
+
+				var value_type = type.copy ();
+				value_type.value_owned = false;
+
 				if (accept (TokenType.GET)) {
 					if (prop.get_accessor != null) {
 						throw new ParseError.SYNTAX (get_error ("property get accessor already defined"));
@@ -2757,7 +2761,7 @@
 					if (accept_block ()) {
 						block = parse_block ();
 					}
-					prop.get_accessor = new PropertyAccessor (true, false, false, block, get_src (accessor_begin));
+					prop.get_accessor = new PropertyAccessor (true, false, false, type.copy (), block, get_src (accessor_begin));
 					prop.get_accessor.access = SymbolAccessibility.PUBLIC;
 				} else {
 					bool _construct = false;
@@ -2780,18 +2784,24 @@
 					if (accept_block ()) {
 						block = parse_block ();
 					}
-					prop.set_accessor = new PropertyAccessor (false, !readonly, _construct, block, get_src (accessor_begin));
+					prop.set_accessor = new PropertyAccessor (false, !readonly, _construct, value_type, block, get_src (accessor_begin));
 					prop.set_accessor.access = SymbolAccessibility.PUBLIC;
 				}
 			}
 			accept (TokenType.EOL);
 			expect (TokenType.DEDENT);
 		} else {
-			prop.get_accessor = new PropertyAccessor (true, false, false, null, get_src (begin));
+			var value_type = type.copy ();
+			value_type.value_owned = false;
+
+			prop.get_accessor = new PropertyAccessor (true, false, false, value_type, null, get_src (begin));
 			prop.get_accessor.access = SymbolAccessibility.PUBLIC;
 
 			if (!readonly) {
-				prop.set_accessor = new PropertyAccessor (false, true, false, null, get_src (begin));
+				value_type = type.copy ();
+				value_type.value_owned = false;
+
+				prop.set_accessor = new PropertyAccessor (false, true, false, value_type, null, get_src (begin));
 				prop.set_accessor.access = SymbolAccessibility.PUBLIC;
 			
 			}

Modified: trunk/vala/valamemberaccess.vala
==============================================================================
--- trunk/vala/valamemberaccess.vala	(original)
+++ trunk/vala/valamemberaccess.vala	Sat Jan 10 14:25:40 2009
@@ -350,7 +350,7 @@
 						// dynamic property assignment
 						var prop = new DynamicProperty (inner.value_type, member_name, source_reference);
 						prop.access = SymbolAccessibility.PUBLIC;
-						prop.set_accessor = new PropertyAccessor (false, true, false, null, prop.source_reference);
+						prop.set_accessor = new PropertyAccessor (false, true, false, prop.property_type.copy (), null, prop.source_reference);
 						prop.set_accessor.access = SymbolAccessibility.PUBLIC;
 						prop.owner = inner.value_type.data_type.scope;
 						dynamic_object_type.type_symbol.scope.add (null, prop);
@@ -367,7 +367,7 @@
 						prop.property_type = inner.value_type.copy ();
 					}
 					prop.access = SymbolAccessibility.PUBLIC;
-					prop.get_accessor = new PropertyAccessor (true, false, false, null, prop.source_reference);
+					prop.get_accessor = new PropertyAccessor (true, false, false, prop.property_type.copy (), null, prop.source_reference);
 					prop.get_accessor.access = SymbolAccessibility.PUBLIC;
 					prop.owner = inner.value_type.data_type.scope;
 					dynamic_object_type.type_symbol.scope.add (null, prop);

Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala	(original)
+++ trunk/vala/valaparser.vala	Sat Jan 10 14:25:40 2009
@@ -430,7 +430,7 @@
 
 		if (!owned_by_default) {
 			if (accept (TokenType.HASH)) {
-				// TODO enable warning after releasing Vala 0.5.4
+				// TODO enable warning after releasing Vala 0.5.5
 				// Report.warning (get_last_src (), "deprecated syntax, use `owned` modifier");
 				value_owned = true;
 			}
@@ -805,7 +805,7 @@
 		}
 		switch (current ()) {
 		case TokenType.HASH:
-			// TODO enable warning after releasing Vala 0.5.4
+			// TODO enable warning after releasing Vala 0.5.5
 			// Report.warning (get_last_src (), "deprecated syntax, use `(owned)` cast");
 			next ();
 			var op = parse_unary_expression ();
@@ -2195,8 +2195,14 @@
 		var begin = get_location ();
 		var access = parse_access_modifier ();
 		var flags = parse_member_declaration_modifiers ();
-		bool is_weak = accept (TokenType.UNOWNED) || accept (TokenType.WEAK);
-		var type = parse_type (false);
+		var type = parse_type ();
+
+		bool getter_owned = false;
+		if (accept (TokenType.HASH) && !context.deprecated) {
+			Report.warning (get_last_src (), "deprecated syntax, use `owned` modifier before `get'");
+			getter_owned = true;
+		}
+
 		string id = parse_identifier ();
 		var prop = new Property (id, type, null, null, get_src_com (begin));
 		prop.access = access;
@@ -2231,16 +2237,25 @@
 				var accessor_begin = get_location ();
 				var attrs = parse_attributes ();
 				var accessor_access = parse_access_modifier (SymbolAccessibility.PUBLIC);
+
+				var value_type = type.copy ();
+				value_type.value_owned = accept (TokenType.OWNED);
+
 				if (accept (TokenType.GET)) {
 					if (prop.get_accessor != null) {
 						throw new ParseError.SYNTAX (get_error ("property get accessor already defined"));
 					}
+
+					if (getter_owned) {
+						value_type.value_owned = true;
+					}
+
 					Block block = null;
 					if (!accept (TokenType.SEMICOLON)) {
 						block = parse_block ();
 						prop.external = false;
 					}
-					prop.get_accessor = new PropertyAccessor (true, false, false, block, get_src (accessor_begin));
+					prop.get_accessor = new PropertyAccessor (true, false, false, value_type, block, get_src (accessor_begin));
 					set_attributes (prop.get_accessor, attrs);
 					prop.get_accessor.access = accessor_access;
 				} else {
@@ -2262,7 +2277,7 @@
 						block = parse_block ();
 						prop.external = false;
 					}
-					prop.set_accessor = new PropertyAccessor (false, writable, _construct, block, get_src (accessor_begin));
+					prop.set_accessor = new PropertyAccessor (false, writable, _construct, value_type, block, get_src (accessor_begin));
 					set_attributes (prop.set_accessor, attrs);
 					prop.set_accessor.access = accessor_access;
 				}
@@ -2286,7 +2301,6 @@
 			if (empty_get && empty_set) {
 				/* automatic property accessor body generation */
 				var field_type = prop.property_type.copy ();
-				field_type.value_owned = !is_weak;
 				prop.field = new Field ("_%s".printf (prop.name), field_type, prop.default_expression, prop.source_reference);
 				prop.field.access = SymbolAccessibility.PRIVATE;
 			}

Modified: trunk/vala/valapropertyaccessor.vala
==============================================================================
--- trunk/vala/valapropertyaccessor.vala	(original)
+++ trunk/vala/valapropertyaccessor.vala	Sat Jan 10 14:25:40 2009
@@ -1,6 +1,6 @@
 /* valapropertyaccessor.vala
  *
- * Copyright (C) 2006-2008  JÃrg Billeter
+ * Copyright (C) 2006-2009  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
@@ -32,6 +32,19 @@
 	public weak Property prop { get; set; }
 
 	/**
+	 * The property type.
+	 */
+	public DataType? value_type {
+		get { return _value_type; }
+		set {
+			_value_type = value;
+			if (value != null) {
+				_value_type.parent_node = this;
+			}
+		}
+	}
+
+	/**
 	 * Specifies whether this accessor may be used to get the property.
 	 */
 	public bool readable { get; set; }
@@ -89,6 +102,7 @@
 		}
 	}
 
+	private DataType _value_type;
 	private string? _cname;
 	
 	/**
@@ -101,10 +115,11 @@
 	 * @param source       reference to source code
 	 * @return             newly created property accessor
 	 */
-	public PropertyAccessor (bool readable, bool writable, bool construction, Block? body, SourceReference? source_reference) {
+	public PropertyAccessor (bool readable, bool writable, bool construction, DataType? value_type, Block? body, SourceReference? source_reference) {
 		this.readable = readable;
 		this.writable = writable;
 		this.construction = construction;
+		this.value_type = value_type;
 		this.body = body;
 		this.source_reference = source_reference;
 	}
@@ -114,6 +129,8 @@
 	}
 
 	public override void accept_children (CodeVisitor visitor) {
+		value_type.accept (visitor);
+
 		if (body != null) {
 			body.accept (visitor);
 		}
@@ -141,9 +158,14 @@
 
 		process_attributes ();
 
+		if (!value_type.check (analyzer)) {
+			error = true;
+			return false;
+		}
+
 		var old_return_type = analyzer.current_return_type;
 		if (readable) {
-			analyzer.current_return_type = prop.property_type;
+			analyzer.current_return_type = value_type;
 		} else {
 			// void
 			analyzer.current_return_type = new VoidType ();
@@ -170,7 +192,6 @@
 			}
 
 			if (body != null && (writable || construction)) {
-				var value_type = prop.property_type.copy ();
 				value_parameter = new FormalParameter ("value", value_type, source_reference);
 				body.scope.add (value_parameter.name, value_parameter);
 			}
@@ -184,4 +205,10 @@
 
 		return !error;
 	}
+
+	public override void replace_type (DataType old_type, DataType new_type) {
+		if (value_type == old_type) {
+			value_type = new_type;
+		}
+	}
 }

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Sat Jan 10 14:25:40 2009
@@ -162,13 +162,14 @@
 			return c.type_reference;
 		} else if (sym is Property) {
 			var prop = (Property) sym;
-			if (prop.property_type != null) {
-				var type = prop.property_type.copy ();
-				if (lvalue) {
-					// setters never take ownership
-					type.value_owned = false;
+			if (lvalue) {
+				if (prop.set_accessor != null) {
+					return prop.set_accessor.value_type.copy ();
+				}
+			} else {
+				if (prop.get_accessor != null) {
+					return prop.get_accessor.value_type.copy ();
 				}
-				return type;
 			}
 		} else if (sym is FormalParameter) {
 			var p = (FormalParameter) sym;

Modified: trunk/vapigen/valagidlparser.vala
==============================================================================
--- trunk/vapigen/valagidlparser.vala	(original)
+++ trunk/vapigen/valagidlparser.vala	Sat Jan 10 14:25:40 2009
@@ -1655,24 +1655,22 @@
 			prop_node.writable = true;
 		}
 		
-		PropertyAccessor get_acc = null;
-		PropertyAccessor set_acc = null;
+		var prop = new Property (fix_prop_name (node.name), parse_type (prop_node.type), null, null, current_source_reference);
+		prop.access = SymbolAccessibility.PUBLIC;
+		prop.interface_only = true;
+		
 		if (prop_node.readable) {
-			get_acc = new PropertyAccessor (true, false, false, null, null);
+			prop.get_accessor = new PropertyAccessor (true, false, false, prop.property_type.copy (), null, null);
 		}
 		if (prop_node.writable) {
-			set_acc = new PropertyAccessor (false, false, false, null, null);
+			prop.set_accessor = new PropertyAccessor (false, false, false, prop.property_type.copy (), null, null);
 			if (prop_node.construct_only) {
-				set_acc.construction = true;
+				prop.set_accessor.construction = true;
 			} else {
-				set_acc.writable = true;
-				set_acc.construction = prop_node  construct;
+				prop.set_accessor.writable = true;
+				prop.set_accessor.construction = prop_node  construct;
 			}
 		}
-		
-		var prop = new Property (fix_prop_name (node.name), parse_type (prop_node.type), get_acc, set_acc, current_source_reference);
-		prop.access = SymbolAccessibility.PUBLIC;
-		prop.interface_only = true;
 
 		var attributes = get_attributes ("%s:%s".printf (current_data_type.get_cname (), node.name));
 		if (attributes != null) {

Modified: trunk/vapigen/valagirparser.vala
==============================================================================
--- trunk/vapigen/valagirparser.vala	(original)
+++ trunk/vapigen/valagirparser.vala	Sat Jan 10 14:25:40 2009
@@ -1,6 +1,6 @@
 /* valagirparser.vala
  *
- * Copyright (C) 2008  JÃrg Billeter
+ * Copyright (C) 2008-2009  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
@@ -660,10 +660,10 @@
 		var prop = new Property (name, type, null, null, get_current_src ());
 		prop.access = SymbolAccessibility.PUBLIC;
 		if (readable != "0") {
-			prop.get_accessor = new PropertyAccessor (true, false, false, null, null);
+			prop.get_accessor = new PropertyAccessor (true, false, false, prop.property_type.copy (), null, null);
 		}
 		if (writable == "1" || construct_ == "1") {
-			prop.set_accessor = new PropertyAccessor (false, (writable == "1"), (construct_ == "1"), null, null);
+			prop.set_accessor = new PropertyAccessor (false, (writable == "1"), (construct_ == "1"), prop.property_type.copy (), null, null);
 		}
 		end_element ("property");
 		return prop;



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