]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
WIP writer where clause
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 17 Apr 2023 15:46:09 +0000 (17:46 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 21 Apr 2024 11:41:43 +0000 (13:41 +0200)
vala/valacodewriter.vala

index c016497b5d2f6c78ba189db26a7f913ec39fc671..7a497b7b483b12ebba2b8e79066a62a29d69c9d2 100644 (file)
@@ -268,6 +268,9 @@ public class Vala.CodeWriter : CodeVisitor {
                                write_type (base_type);
                        }
                }
+
+               write_type_parameter_constraints (cl.get_type_parameters ());
+
                write_begin_block ();
 
                current_scope = cl.scope;
@@ -357,6 +360,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_type (st.base_type);
                }
 
+               write_type_parameter_constraints (st.get_type_parameters ());
+
                write_begin_block ();
 
                current_scope = st.scope;
@@ -410,6 +415,9 @@ public class Vala.CodeWriter : CodeVisitor {
                                write_type (prerequisite);
                        }
                }
+
+               write_type_parameter_constraints (iface.get_type_parameters ());
+
                write_begin_block ();
 
                current_scope = iface.scope;
@@ -735,6 +743,8 @@ public class Vala.CodeWriter : CodeVisitor {
                cb.get_error_types (error_types);
                write_error_domains (error_types);
 
+               write_type_parameter_constraints (cb.get_type_parameters ());
+
                write_string (";");
 
                write_newline ();
@@ -853,6 +863,8 @@ public class Vala.CodeWriter : CodeVisitor {
                m.get_error_types (error_types);
                write_error_domains (error_types);
 
+               write_type_parameter_constraints (m.get_type_parameters ());
+
                write_code_block (m.body);
 
                write_newline ();
@@ -1777,6 +1789,30 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_string (">");
                }
        }
+
+       void write_type_parameter_constraints (List<TypeParameter> type_params) {
+               if (type_params.size > 0) {
+                       foreach (TypeParameter type_param in type_params) {
+                               unowned DataType? type_constraint = type_param.type_constraint;
+                               if (type_constraint == null) {
+                                       continue;
+                               }
+                               write_string (" where ");
+                               write_identifier (type_param.name);
+                               write_string (" : ");
+                               bool first = true;
+                               //FIXME
+                               foreach (DataType type in new DataType[] { type_constraint }) {
+                                       if (first) {
+                                               first = false;
+                                       } else {
+                                               write_string (",");
+                                       }
+                                       write_type (type);
+                               }
+                       }
+               }
+       }
 }
 
 public enum Vala.CodeWriterType {