]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Drop deprecated support for assigning to construct-only properties
authorJürg Billeter <j@bitron.ch>
Mon, 9 Aug 2010 20:50:48 +0000 (22:50 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 9 Aug 2010 20:53:35 +0000 (22:53 +0200)
codegen/valaccodemethodmodule.vala
vala/valaassignment.vala
vala/valacreationmethod.vala
vala/valaexpressionstatement.vala

index 0b35b9960585524c439d99c592c3d179002a7557..2bf57854b99494aebaa2164bd0006bf270308154 100644 (file)
@@ -1,6 +1,6 @@
 /* valaccodemethodmodule.vala
  *
- * Copyright (C) 2007-2009  Jürg Billeter
+ * Copyright (C) 2007-2010  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
@@ -321,73 +321,11 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
 
                if (m is CreationMethod) {
                        if (in_gobject_creation_method && m.body != null) {
-                               if (!((CreationMethod) m).chain_up) {
-                                       if (m.body.captured) {
-                                               Report.error (m.source_reference, "Closures are not supported in GObject-style creation methods");
-                                       }
-
-                                       var cblock = new CCodeBlock ();
-
-                                       // last property assignment statement
-                                       CodeNode last_stmt = null;
-
-                                       // set construct properties
-                                       foreach (CodeNode stmt in m.body.get_statements ()) {
-                                               var expr_stmt = stmt as ExpressionStatement;
-                                               if (expr_stmt != null) {
-                                                       var prop = expr_stmt.assigned_property ();
-                                                       if (prop != null && prop.set_accessor.construction) {
-                                                               last_stmt = stmt;
-                                                       }
-                                               }
-                                       }
-                                       if (last_stmt != null) {
-                                               foreach (CodeNode stmt in m.body.get_statements ()) {
-                                                       if (stmt.ccodenode is CCodeFragment) {
-                                                               foreach (CCodeNode cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) {
-                                                                       cblock.add_statement (cstmt);
-                                                               }
-                                                       } else {
-                                                               cblock.add_statement (stmt.ccodenode);
-                                                       }
-                                                       if (last_stmt == stmt) {
-                                                               break;
-                                                       }
-                                               }
-                                       }
-
-                                       add_object_creation (cblock, ((CreationMethod) m).n_construction_params > 0 || current_class.get_type_parameters ().size > 0);
+                               var cblock = (CCodeBlock) m.body.ccodenode;
 
-                                       // other initialization code
-                                       foreach (CodeNode stmt in m.body.get_statements ()) {
-                                               if (last_stmt != null) {
-                                                       if (last_stmt == stmt) {
-                                                               last_stmt = null;
-                                                       }
-                                                       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);
-                                               }
-                                       }
-
-                                       foreach (LocalVariable local in m.body.get_local_variables ()) {
-                                               if (!local.floating && requires_destroy (local.variable_type)) {
-                                                       var ma = new MemberAccess.simple (local.name);
-                                                       ma.symbol_reference = local;
-                                                       ma.value_type = local.variable_type.copy ();
-                                                       cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (get_variable_cexpression (local.name), local.variable_type, ma)));
-                                               }
-                                       }
-
-                                       m.body.ccodenode = cblock;
+                               if (!((CreationMethod) m).chain_up) {
+                                       prepend_object_creation (cblock, current_class.get_type_parameters ().size > 0);
                                } else {
-                                       var cblock = (CCodeBlock) m.body.ccodenode;
-
                                        var cdeclaration = new CCodeDeclaration ("%s *".printf (((Class) current_type_symbol).get_cname ()));
                                        cdeclaration.add_declarator (new CCodeVariableDeclarator ("self"));
 
@@ -605,14 +543,12 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                        
                                if (m is CreationMethod) {
                                        if (in_gobject_creation_method) {
-                                               int n_params = ((CreationMethod) m).n_construction_params;
-
                                                if (!((CreationMethod) m).chain_up) {
-                                                       if (n_params > 0 || current_class.get_type_parameters ().size > 0) {
+                                                       if (current_class.get_type_parameters ().size > 0) {
                                                                // declare construction parameter array
                                                                var cparamsinit = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
                                                                cparamsinit.add_argument (new CCodeIdentifier ("GParameter"));
-                                                               cparamsinit.add_argument (new CCodeConstant ((n_params + 3 * current_class.get_type_parameters ().size).to_string ()));
+                                                               cparamsinit.add_argument (new CCodeConstant ((current_class.get_type_parameters ().size).to_string ()));
                                                
                                                                var cdecl = new CCodeDeclaration ("GParameter *");
                                                                cdecl.add_declarator (new CCodeVariableDeclarator ("__params", cparamsinit));
@@ -649,7 +585,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                                                cinit.append (cdeclaration);
 
                                                if (!((CreationMethod) m).chain_up) {
-                                                       // TODO implicitly chain up to base class as in add_object_creation
+                                                       // TODO implicitly chain up to base class as in prepend_object_creation
                                                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_create_instance"));
                                                        ccall.add_argument (new CCodeIdentifier ("object_type"));
                                                        cdecl.initializer = new CCodeCastExpression (ccall, cl.get_cname () + "*");
@@ -682,7 +618,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                                                cinit.append (cdeclaration);
 
                                                if (!((CreationMethod) m).chain_up) {
-                                                       // TODO implicitly chain up to base class as in add_object_creation
+                                                       // TODO implicitly chain up to base class as in prepend_object_creation
                                                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
                                                        ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
                                                        cdecl.initializer = ccall;
@@ -1095,7 +1031,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                return null;
        }
 
-       private void add_object_creation (CCodeBlock b, bool has_params) {
+       private void prepend_object_creation (CCodeBlock b, bool has_params) {
                var cl = (Class) current_type_symbol;
 
                if (!has_params && cl.base_class != gobject_type) {
@@ -1117,7 +1053,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                var cdeclaration = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
                cdeclaration.add_declarator (cdecl);
                
-               b.add_statement (cdeclaration);
+               b.prepend_statement (cdeclaration);
        }
 
        public override void visit_creation_method (CreationMethod m) {
@@ -1160,7 +1096,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
                }
 
                if (current_type_symbol is Class && gobject_type != null && current_class.is_subtype_of (gobject_type)
-                   && (((CreationMethod) m).n_construction_params > 0 || current_class.get_type_parameters ().size > 0)
+                   && current_class.get_type_parameters ().size > 0
                    && !((CreationMethod) m).chain_up) {
                        var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, new CCodeIdentifier ("__params_it"), new CCodeIdentifier ("__params"));
                        var cdofreeparam = new CCodeBlock ();
index 0e381fea7315016cb8c539a8d7ac0102de370280..bcbe96a21353f64fbfa5fae1039dbf95ab456a03 100644 (file)
@@ -318,7 +318,8 @@ public class Vala.Assignment : Expression {
                                                Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
                                                return false;
                                        } else {
-                                               Report.warning (ma.source_reference, "assigning to construct-only properties is deprecated, use Object (property: value) constructor chain up");
+                                               Report.error (ma.source_reference, "Cannot assign to construct-only properties, use Object (property: value) constructor chain up");
+                                               return false;
                                        }
                                }
                        } else if (ma.symbol_reference is Variable && right.value_type == null) {
index 46f96b14b0af4436ccce5f682f8e1398dd506c96..10891d3bd2c4c93a1a708eddd738ec2c6e549e2e 100644 (file)
@@ -1,6 +1,6 @@
 /* valacreationmethod.vala
  *
- * Copyright (C) 2007-2009  Jürg Billeter
+ * Copyright (C) 2007-2010  Jürg Billeter
  * Copyright (C) 2007-2008  Raffaele Sandrini
  *
  * This library is free software; you can redistribute it and/or
@@ -33,11 +33,6 @@ public class Vala.CreationMethod : Method {
         */
        public string class_name { get; set; }
 
-       /**
-        * Specifies the number of parameters this creation method sets.
-        */
-       public int n_construction_params { get; set; }
-
        /**
         * Specifies a custom C return type for that creation method.
         * Only the idl parser and the interface writer should use this.
@@ -189,32 +184,12 @@ public class Vala.CreationMethod : Method {
 
                        var cl = parent_symbol as Class;
 
-                       // count construction property assignments
-                       if (analyzer.context.profile == Profile.GOBJECT && cl != null
-                           && cl.is_subtype_of (analyzer.object_type)) {
-                               int n_params = 0;
-                               foreach (Statement stmt in body.get_statements ()) {
-                                       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++;
-                                               }
-                                       }
-                               }
-                               n_construction_params = n_params;
-                       }
-
                        // ensure we chain up to base constructor
                        if (!chain_up && cl != null && cl.base_class != null) {
                                if (analyzer.context.profile == Profile.GOBJECT
                                    && cl.base_class.default_construction_method != null
                                    && !cl.base_class.default_construction_method.has_construct_function) {
                                        // chain up impossible
-                               } else if (analyzer.context.profile == Profile.GOBJECT
-                                          && cl.is_subtype_of (analyzer.object_type)
-                                          && (n_construction_params > 0 || cl.constructor != null)) {
-                                       // no chain up when using GObject construct properties or constructor
                                } else if (cl.base_class.default_construction_method == null
                                    || cl.base_class.default_construction_method.access == SymbolAccessibility.PRIVATE) {
                                        if (analyzer.context.profile == Profile.GOBJECT) {
index 75f6bab1a4d0b0ea743ec6376b9a885e0f9ed856..50d0debc949a0d88a7930f538524d980f2a35b0e 100644 (file)
@@ -1,6 +1,6 @@
 /* valaexpressionstatement.vala
  *
- * Copyright (C) 2006-2008  Jürg Billeter
+ * Copyright (C) 2006-2010  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
@@ -67,26 +67,6 @@ public class Vala.ExpressionStatement : CodeNode, Statement {
                }
        }
 
-       /**
-        * Returns the property this statement sets, if any.
-        *
-        * @return the property this statement sets, or null if it doesn't set
-        *         a property
-        */
-       public Property? assigned_property () {
-               if (expression is Assignment) {
-                       var assign = (Assignment) expression;
-                       if (assign.left is MemberAccess) {
-                               var ma = (MemberAccess) assign.left;
-                               if (ma.symbol_reference is Property) {
-                                       return (Property) ma.symbol_reference;
-                               }
-                       }
-               }
-
-               return null;
-       }
-
        public override bool check (SemanticAnalyzer analyzer) {
                if (checked) {
                        return !error;