[vala/staging] Set TypeParameter as symbol of GenericType



commit c5c59bed4061825294c417380445704994ba3182
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Sep 29 00:29:20 2021 +0200

    Set TypeParameter as symbol of GenericType

 codegen/valaccodeattribute.vala          | 16 ++++++++++++++++
 codegen/valaccodebasemodule.vala         |  2 +-
 codegen/valaccodememberaccessmodule.vala |  3 ++-
 codegen/valagirwriter.vala               |  8 ++++----
 vala/valadatatype.vala                   |  5 ++---
 vala/valagenerictype.vala                |  9 ++++++---
 vala/valatypeparameter.vala              |  1 +
 7 files changed, 32 insertions(+), 12 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index d39fc284e..c3144e0c6 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -798,6 +798,22 @@ public class Vala.CCodeAttribute : AttributeCache {
                                } else {
                                        return name;
                                }
+                       } else if (sym is TypeParameter) {
+                               assert (node is GenericType);
+                               var type = (GenericType) node;
+                               if (type.value_owned) {
+                                       if (CodeContext.get ().profile == Profile.GOBJECT) {
+                                               return "gpointer";
+                                       } else {
+                                               return "void *";
+                                       }
+                               } else {
+                                       if (CodeContext.get ().profile == Profile.GOBJECT) {
+                                               return "gconstpointer";
+                                       } else {
+                                               return "const void *";
+                                       }
+                               }
                        } else {
                                return "%s%s".printf (get_ccode_prefix (sym.parent_symbol), sym.name);
                        }
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 14a8efa91..ff41d344a 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5901,7 +5901,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, instance_domain, 
type_domain);
                } else {
                        CCodeFunctionCall ccheck;
-                       if (type.type_symbol == null || type.type_symbol.external_package) {
+                       if (type is GenericType || type.type_symbol == null || 
type.type_symbol.external_package) {
                                ccheck = new CCodeFunctionCall (new CCodeIdentifier 
("G_TYPE_CHECK_INSTANCE_TYPE"));
                                ccheck.add_argument ((CCodeExpression) ccodenode);
                                ccheck.add_argument (get_type_id_expression (type));
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 4e411c73e..4f0b6a97e 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -415,7 +415,8 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                // Add cast for narrowed type access of variables if needed
                if (expr.symbol_reference is Variable) {
                        unowned GLibValue cvalue = (GLibValue) expr.target_value;
-                       if (cvalue.value_type.type_symbol != null && cvalue.value_type.type_symbol != 
expr.value_type.type_symbol) {
+                       if (!(cvalue.value_type is GenericType) && cvalue.value_type.type_symbol != null
+                           && cvalue.value_type.type_symbol != expr.value_type.type_symbol) {
                                cvalue.cvalue = new CCodeCastExpression (cvalue.cvalue, get_ccode_name 
(expr.value_type));
                        }
                }
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 22b024513..696c6c8a6 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -1672,6 +1672,10 @@ public class Vala.GIRWriter : CodeVisitor {
                } else if (type is PointerType) {
                        write_indent ();
                        buffer.append_printf ("<type name=\"gpointer\" c:type=\"%s%s\"/>\n", get_ccode_name 
(type), direction == ParameterDirection.IN ? "" : "*");
+               } else if (type is GenericType) {
+                       // generic type parameters not supported in GIR
+                       write_indent ();
+                       buffer.append ("<type name=\"gpointer\" c:type=\"gpointer\"/>\n");
                } else if (type is DelegateType) {
                        var deleg_type = (DelegateType) type;
                        write_indent ();
@@ -1700,10 +1704,6 @@ public class Vala.GIRWriter : CodeVisitor {
                                write_indent ();
                                buffer.append_printf ("</%s>\n", is_array ? "array" : "type");
                        }
-               } else if (type is GenericType) {
-                       // generic type parameters not supported in GIR
-                       write_indent ();
-                       buffer.append ("<type name=\"gpointer\" c:type=\"gpointer\"/>\n");
                } else {
                        write_indent ();
                        buffer.append_printf ("<type name=\"%s\"/>\n", type.to_string ());
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 8d190e0ad..4a0f94a65 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -525,9 +525,8 @@ public abstract class Vala.DataType : CodeNode {
 
        public void replace_type_parameter (TypeParameter old_type_param, TypeParameter new_type_param) {
                if (this is GenericType) {
-                       unowned GenericType generic_type = (GenericType) this;
-                       if (generic_type.type_parameter == old_type_param) {
-                               generic_type.type_parameter = new_type_param;
+                       if (symbol == old_type_param) {
+                               symbol = new_type_param;
                        }
                        return;
                }
diff --git a/vala/valagenerictype.vala b/vala/valagenerictype.vala
index 673b606db..32b32ba0e 100644
--- a/vala/valagenerictype.vala
+++ b/vala/valagenerictype.vala
@@ -29,14 +29,17 @@ public class Vala.GenericType : DataType {
        /**
         * The referred generic type parameter.
         */
-       public weak TypeParameter type_parameter { get; set; }
+       public weak TypeParameter type_parameter {
+               get {
+                       return (TypeParameter) type_symbol;
+               }
+       }
 
        GenericDupField? dup_field;
        GenericDestroyField? destroy_field;
 
        public GenericType (TypeParameter type_parameter, SourceReference? source_reference = null) {
-               this.type_parameter = type_parameter;
-               this.source_reference = source_reference;
+               base.with_symbol (type_parameter, source_reference);
                // type parameters are always considered nullable
                this.nullable = true;
        }
diff --git a/vala/valatypeparameter.vala b/vala/valatypeparameter.vala
index d148d6eeb..5c1260982 100644
--- a/vala/valatypeparameter.vala
+++ b/vala/valatypeparameter.vala
@@ -35,6 +35,7 @@ public class Vala.TypeParameter : TypeSymbol {
         */
        public TypeParameter (string name, SourceReference? source_reference = null) {
                base (name, source_reference);
+               access = SymbolAccessibility.PUBLIC;
        }
 
        public override void accept (CodeVisitor visitor) {


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