]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Lift restriction on statements in creation methods of GObjects in
authorJürg Billeter <j@bitron.ch>
Fri, 10 Oct 2008 09:40:22 +0000 (09:40 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 10 Oct 2008 09:40:22 +0000 (09:40 +0000)
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

svn path=/trunk/; revision=1825

ChangeLog
gobject/valaccodecreationmethodbinding.vala
gobject/valaccodemethodbinding.vala

index 1cb407af69aa67c3ea110742dcf5b4d5d4428924..681e4e1c47e0c287537ce6b92102c9c7b0ff8dae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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
+
 2008-10-09  Jürg Billeter  <j@bitron.ch>
 
        * vala/valainterfacewriter.vala:
index 411dea580fc8a1f3a9a326b0d58e5ac7473978eb..9c85145b900fc0faca2b2699f2497211ea5390f3 100644 (file)
@@ -41,20 +41,12 @@ public class Vala.CCodeCreationMethodBinding : CCodeMethodBinding {
                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;
index 31b8382e75e6f8a8306b9c4fd71b4e62c320e4e0..a355293c1ef1f090c8cb5b53f745509ae6c9da7d 100644 (file)
@@ -99,31 +99,42 @@ public class Vala.CCodeMethodBinding : CCodeBinding {
                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;