]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Set TypeParameter as symbol of GenericType
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 28 Sep 2021 22:29:20 +0000 (00:29 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 1 Oct 2021 18:52:01 +0000 (20:52 +0200)
codegen/valaccodeattribute.vala
codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala
codegen/valagirwriter.vala
vala/valadatatype.vala
vala/valagenerictype.vala
vala/valatypeparameter.vala

index d39fc284eb4afa74cd40d3f73d20339889a823d3..c3144e0c68c2cc62223dca0e2b91406d007075dd 100644 (file)
@@ -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);
                        }
index 14a8efa91d46977fb9883ab51574fe0d8ad43e52..ff41d344a48a3b947caaff822b1f5447d62c0030 100644 (file)
@@ -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));
index 4e411c73e0cc64a737c0de7561353f6ab89c78c7..4f0b6a97ece619ae0db3234508531287b2f839cc 100644 (file)
@@ -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));
                        }
                }
index 22b0245139f2400da5c9a704f6440d451387c4d0..696c6c8a634b00add6963f602165acb78db64b0b 100644 (file)
@@ -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 ());
index 8d190e0adb4e68f04b0b2bc9c7a834e423282d62..4a0f94a65d9c6bd746b6fc47dee88dc9ed42e8c8 100644 (file)
@@ -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;
                }
index 673b606dbf0653530ab4b983dee525ba082d53d7..32b32ba0e57147662db7b16b96dd0f0584bcf9ba 100644 (file)
@@ -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;
        }
index d148d6eebc180e492eb5a7974ec6dd7e39fb2751..5c126098212bc494b5eda0432c14fe7aef35b363 100644 (file)
@@ -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) {