vala r1825 - in trunk: . gobject



Author: juergbi
Date: Fri Oct 10 09:40:22 2008
New Revision: 1825
URL: http://svn.gnome.org/viewvc/vala?rev=1825&view=rev

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

	* gobject/valaccodecreationmethodbinding.vala:
	* gobject/valaccodemethodbinding.vala:

	Lift restriction on statements in creation methods of GObjects
	in preparation to support more flexible construction scheme


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodecreationmethodbinding.vala
   trunk/gobject/valaccodemethodbinding.vala

Modified: trunk/gobject/valaccodecreationmethodbinding.vala
==============================================================================
--- trunk/gobject/valaccodecreationmethodbinding.vala	(original)
+++ trunk/gobject/valaccodecreationmethodbinding.vala	Fri Oct 10 09:40:22 2008
@@ -41,20 +41,12 @@
 		if (m.body != null && codegen.current_type_symbol is Class && codegen.current_class.is_subtype_of (codegen.gobject_type)) {
 			int n_params = 0;
 			foreach (Statement stmt in m.body.get_statements ()) {
-				if (!(stmt is ExpressionStatement) || ((ExpressionStatement) stmt).assigned_property () == null) {
-					m.error = true;
-					Report.error (stmt.source_reference, "class creation methods only allow property assignment statements");
-					return;
-				}
-
-				Property prop = ((ExpressionStatement) stmt).assigned_property ();
-				if (prop.access == SymbolAccessibility.PRIVATE) {
-					m.error = true;
-					Report.error (stmt.source_reference, "class creation methods only allow assignments to public and protected properties");
-					return;
-				}
-				if (prop.set_accessor.construction) {
-					n_params++;
+				var expr_stmt = stmt as ExpressionStatement;
+				if (expr_stmt != null) {
+					Property prop = expr_stmt.assigned_property ();
+					if (prop != null && prop.set_accessor.construction) {
+						n_params++;
+					}
 				}
 			}
 			m.n_construction_params = n_params;

Modified: trunk/gobject/valaccodemethodbinding.vala
==============================================================================
--- trunk/gobject/valaccodemethodbinding.vala	(original)
+++ trunk/gobject/valaccodemethodbinding.vala	Fri Oct 10 09:40:22 2008
@@ -99,31 +99,42 @@
 		if (m is CreationMethod) {
 			if (in_gobject_creation_method && m.body != null) {
 				var cblock = new CCodeBlock ();
-				
+
+				// set construct properties
 				foreach (CodeNode stmt in m.body.get_statements ()) {
-					if (((ExpressionStatement) stmt).assigned_property ().set_accessor.construction) {
-						if (stmt.ccodenode is CCodeFragment) {
-							foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
-								cblock.add_statement (cstmt);
+					var expr_stmt = stmt as ExpressionStatement;
+					if (expr_stmt != null) {
+						var prop = expr_stmt.assigned_property ();
+						if (prop != null && prop.set_accessor.construction) {
+							if (stmt.ccodenode is CCodeFragment) {
+								foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
+									cblock.add_statement (cstmt);
+								}
+							} else {
+								cblock.add_statement (stmt.ccodenode);
 							}
-						} else {
-							cblock.add_statement (stmt.ccodenode);
 						}
 					}
 				}
 
 				add_object_creation (cblock, ((CreationMethod) m).n_construction_params > 0 || codegen.current_class.get_type_parameters ().size > 0);
-				
+
+				// other initialization code
 				foreach (CodeNode stmt in m.body.get_statements ()) {
-					if (!((ExpressionStatement) stmt).assigned_property ().set_accessor.construction) {
-						if (stmt.ccodenode is CCodeFragment) {
-							foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
-								cblock.add_statement (cstmt);
-							}
-						} else {
-							cblock.add_statement (stmt.ccodenode);
+					var expr_stmt = stmt as ExpressionStatement;
+					if (expr_stmt != null) {
+						var prop = expr_stmt.assigned_property ();
+						if (prop != null && prop.set_accessor.construction) {
+							continue;
 						}
 					}
+					if (stmt.ccodenode is CCodeFragment) {
+						foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
+							cblock.add_statement (cstmt);
+						}
+					} else {
+						cblock.add_statement (stmt.ccodenode);
+					}
 				}
 				
 				m.body.ccodenode = cblock;



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