]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Unify "this_parameter" creation using SemanticAnalyzer.get_this_type()
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 17 Nov 2019 11:49:11 +0000 (12:49 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 17 Nov 2019 13:12:07 +0000 (14:12 +0100)
codegen/valagasyncmodule.vala
vala/valaclass.vala
vala/valaconstructor.vala
vala/valainterface.vala
vala/valaobjecttypesymbol.vala
vala/valastruct.vala

index 48f53d47ee7f10b60c584774a070fe502d1bbd1a..de2e34845b16223b32c94931d5d778b2be7892c9 100644 (file)
@@ -533,7 +533,7 @@ public class Vala.GAsyncModule : GtkModule {
                        var type_sym = (TypeSymbol) m.parent_symbol;
                        if (type_sym is ObjectTypeSymbol) {
                                ccode.add_declaration (get_ccode_name (type_sym) + "*", new CCodeVariableDeclarator ("result"));
-                               return_type = ((ObjectTypeSymbol) type_sym).get_this_type ();
+                               return_type = SemanticAnalyzer.get_this_type (m, type_sym);
                        }
                } else if (!(return_type is VoidType) && !return_type.is_real_non_null_struct_type ()) {
                        ccode.add_declaration (get_ccode_name (m.return_type), new CCodeVariableDeclarator ("result"));
index 6cad8e00a2f7288655f8794138ea938c4ad3ec67..e9312c4158bae50b85d8d3030b5ff6b0272f9c75 100644 (file)
@@ -165,11 +165,6 @@ public class Vala.Class : ObjectTypeSymbol {
                        _destructor = value;
                        if (_destructor != null) {
                                _destructor.owner = scope;
-                               if (_destructor.this_parameter != null) {
-                                       _destructor.scope.remove (_destructor.this_parameter.name);
-                               }
-                               _destructor.this_parameter = new Parameter ("this", get_this_type ());
-                               _destructor.scope.add (_destructor.this_parameter.name, _destructor.this_parameter);
                        }
                }
        }
@@ -269,11 +264,11 @@ public class Vala.Class : ObjectTypeSymbol {
         * @param m a method
         */
        public override void add_method (Method m) {
-               if (m.binding == MemberBinding.INSTANCE || m is CreationMethod) {
+               if (m.binding != MemberBinding.STATIC || m is CreationMethod) {
                        if (m.this_parameter != null) {
                                m.scope.remove (m.this_parameter.name);
                        }
-                       m.this_parameter = new Parameter ("this", get_this_type ());
+                       m.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (m, this));
                        m.scope.add (m.this_parameter.name, m.this_parameter);
                }
                if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
@@ -323,8 +318,10 @@ public class Vala.Class : ObjectTypeSymbol {
        public override void add_property (Property prop) {
                base.add_property (prop);
 
-               prop.this_parameter = new Parameter ("this", get_this_type ());
-               prop.scope.add (prop.this_parameter.name, prop.this_parameter);
+               if (prop.binding != MemberBinding.STATIC) {
+                       prop.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (prop, this));
+                       prop.scope.add (prop.this_parameter.name, prop.this_parameter);
+               }
 
                if (prop.field != null) {
                        add_field (prop.field);
@@ -354,6 +351,14 @@ public class Vala.Class : ObjectTypeSymbol {
                default:
                        assert_not_reached ();
                }
+
+               if (c.binding != MemberBinding.STATIC) {
+                       if (c.this_parameter != null) {
+                               c.scope.remove (c.this_parameter.name);
+                       }
+                       c.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (c, this));
+                       c.scope.add (c.this_parameter.name, c.this_parameter);
+               }
        }
 
        public override void add_destructor (Destructor d) {
@@ -379,6 +384,14 @@ public class Vala.Class : ObjectTypeSymbol {
                default:
                        assert_not_reached ();
                }
+
+               if (d.binding != MemberBinding.STATIC) {
+                       if (d.this_parameter != null) {
+                               d.scope.remove (d.this_parameter.name);
+                       }
+                       d.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (d, this));
+                       d.scope.add (d.this_parameter.name, d.this_parameter);
+               }
        }
 
        public override void accept (CodeVisitor visitor) {
index 4195da9eaad2cea8607614c80176efc3638621a7..0aee16ac86a67ee184356fa44c90b9268df09efa 100644 (file)
@@ -67,9 +67,6 @@ public class Vala.Constructor : Subroutine {
 
                checked = true;
 
-               this_parameter = new Parameter ("this", new ObjectType ((ObjectTypeSymbol) parent_symbol));
-               scope.add (this_parameter.name, this_parameter);
-
                context.analyzer.current_symbol = this;
 
                if (body != null) {
index eb63e9a057bf3bebd62180a7ccb0135e018cd158..019003936118ccf342a7c34527b9e6268d285ca3 100644 (file)
@@ -73,8 +73,8 @@ public class Vala.Interface : ObjectTypeSymbol {
                        m.error = true;
                        return;
                }
-               if (m.binding == MemberBinding.INSTANCE) {
-                       m.this_parameter = new Parameter ("this", get_this_type ());
+               if (m.binding != MemberBinding.STATIC) {
+                       m.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (m, this));
                        m.scope.add (m.this_parameter.name, m.this_parameter);
                }
                if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
@@ -100,8 +100,10 @@ public class Vala.Interface : ObjectTypeSymbol {
 
                base.add_property (prop);
 
-               prop.this_parameter = new Parameter ("this", new ObjectType (this));
-               prop.scope.add (prop.this_parameter.name, prop.this_parameter);
+               if (prop.binding != MemberBinding.STATIC) {
+                       prop.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (prop, this));
+                       prop.scope.add (prop.this_parameter.name, prop.this_parameter);
+               }
        }
 
        public virtual List<Symbol> get_virtuals () {
index c0ca11bb2451f8c8129364ca80f0ffef4635e386..c79df83a39321675cfab3d1888a1a151ff16e977 100644 (file)
@@ -296,16 +296,6 @@ public abstract class Vala.ObjectTypeSymbol : TypeSymbol {
                return -1;
        }
 
-       public ObjectType get_this_type () {
-               var result = new ObjectType (this);
-               foreach (var type_parameter in get_type_parameters ()) {
-                       var type_arg = new GenericType (type_parameter);
-                       type_arg.value_owned = true;
-                       result.add_type_argument (type_arg);
-               }
-               return result;
-       }
-
        /**
         * Adds the specified method as a hidden member to this class,
         * primarily used for default signal handlers.
@@ -322,7 +312,7 @@ public abstract class Vala.ObjectTypeSymbol : TypeSymbol {
                        if (m.this_parameter != null) {
                                m.scope.remove (m.this_parameter.name);
                        }
-                       m.this_parameter = new Parameter ("this", get_this_type ());
+                       m.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (m, this));
                        m.scope.add (m.this_parameter.name, m.this_parameter);
                }
                if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
index 7685b08190357f2a94eb1195bd8cae3dcaf8fa8d..8eff5c7231eedb020207d498ca494c74672cd086 100644 (file)
@@ -234,7 +234,7 @@ public class Vala.Struct : TypeSymbol {
         */
        public override void add_method (Method m) {
                if (m.binding == MemberBinding.INSTANCE || m is CreationMethod) {
-                       m.this_parameter = new Parameter ("this", SemanticAnalyzer.get_data_type_for_symbol (this));
+                       m.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (m, this));
                        m.scope.add (m.this_parameter.name, m.this_parameter);
                }
                if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
@@ -278,8 +278,10 @@ public class Vala.Struct : TypeSymbol {
                properties.add (prop);
                scope.add (prop.name, prop);
 
-               prop.this_parameter = new Parameter ("this", SemanticAnalyzer.get_data_type_for_symbol (this));
-               prop.scope.add (prop.this_parameter.name, prop.this_parameter);
+               if (prop.binding == MemberBinding.INSTANCE) {
+                       prop.this_parameter = new Parameter ("this", SemanticAnalyzer.get_this_type (prop, this));
+                       prop.scope.add (prop.this_parameter.name, prop.this_parameter);
+               }
 
                if (prop.field != null) {
                        add_field (prop.field);