[vala/staging: 5/7] vala: Unify "this_parameter" creation using SemanticAnalyzer.get_this_type()



commit 5e8005f0b244c22fe6f1e7bfb38f2b30bb49c220
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Nov 17 12:49:11 2019 +0100

    vala: Unify "this_parameter" creation using SemanticAnalyzer.get_this_type()

 codegen/valagasyncmodule.vala  |  2 +-
 vala/valaclass.vala            | 31 ++++++++++++++++++++++---------
 vala/valaconstructor.vala      |  3 ---
 vala/valainterface.vala        | 10 ++++++----
 vala/valaobjecttypesymbol.vala | 12 +-----------
 vala/valastruct.vala           |  8 +++++---
 6 files changed, 35 insertions(+), 31 deletions(-)
---
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index 48f53d47e..de2e34845 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -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"));
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index 6cad8e00a..e9312c415 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -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) {
diff --git a/vala/valaconstructor.vala b/vala/valaconstructor.vala
index 4195da9ea..0aee16ac8 100644
--- a/vala/valaconstructor.vala
+++ b/vala/valaconstructor.vala
@@ -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) {
diff --git a/vala/valainterface.vala b/vala/valainterface.vala
index eb63e9a05..019003936 100644
--- a/vala/valainterface.vala
+++ b/vala/valainterface.vala
@@ -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 () {
diff --git a/vala/valaobjecttypesymbol.vala b/vala/valaobjecttypesymbol.vala
index c0ca11bb2..c79df83a3 100644
--- a/vala/valaobjecttypesymbol.vala
+++ b/vala/valaobjecttypesymbol.vala
@@ -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) {
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 7685b0819..8eff5c723 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -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);


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