]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use SemanticAnalyzer.get_data_type_for_symbol()
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 9 Nov 2019 14:20:11 +0000 (15:20 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 9 Nov 2019 14:20:11 +0000 (15:20 +0100)
codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala
codegen/valaccodemethodmodule.vala
codegen/valaccodestructmodule.vala
codegen/valagirwriter.vala
codegen/valagtypemodule.vala
tests/girwriter/GirTest-1.0.gir-expected

index f3c044a44f063ba843cc0ab10e758a0821d2a4f2..615180dbe8b667c68b858d10f654bce13964a108 100644 (file)
@@ -1582,7 +1582,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                if (prop.binding == MemberBinding.INSTANCE) {
                        var t = (TypeSymbol) prop.parent_symbol;
-                       var this_type = get_data_type_for_symbol (t);
+                       var this_type = SemanticAnalyzer.get_data_type_for_symbol (t);
                        generate_type_declaration (this_type, decl_space);
                        var cselfparam = new CCodeParameter ("self", get_ccode_name (this_type));
                        if (t is Struct && !((Struct) t).is_simple_type ()) {
@@ -1664,7 +1664,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return;
                }
 
-               var this_type = get_data_type_for_symbol (t);
+               var this_type = SemanticAnalyzer.get_data_type_for_symbol (t);
                var cselfparam = new CCodeParameter ("self", get_ccode_name (this_type));
                if (t is Struct && !((Struct) t).is_simple_type ()) {
                        cselfparam.type_name += "*";
@@ -2032,7 +2032,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                data.add_field ("Block%dData *".printf (parent_block_id), "_data%d_".printf (parent_block_id));
                        } else {
                                if (get_this_type () != null) {
-                                       data.add_field (get_ccode_name (get_data_type_for_symbol (current_type_symbol)), "self");
+                                       data.add_field (get_ccode_name (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol)), "self");
                                }
 
                                if (current_method != null) {
@@ -2099,7 +2099,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                bool in_creation_method_with_chainup = (current_method is CreationMethod && current_class != null && current_class.base_class != null);
 
                                if (get_this_type () != null && (!in_creation_method_with_chainup || current_method.body != b)) {
-                                       var ref_call = new CCodeFunctionCall (get_dup_func_expression (get_data_type_for_symbol (current_type_symbol), b.source_reference));
+                                       var ref_call = new CCodeFunctionCall (get_dup_func_expression (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol), b.source_reference));
                                        ref_call.add_argument (get_this_cexpression ());
 
                                        // never increase reference count for self in finalizers to avoid infinite recursion on following unref
@@ -2196,7 +2196,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                        if (get_this_type () != null) {
                                // assign "self" for type parameters
-                               ccode.add_declaration(get_ccode_name (get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self"));
+                               ccode.add_declaration(get_ccode_name (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self"));
                                ccode.add_assignment (new CCodeIdentifier ("self"), new CCodeMemberAccess.pointer (outer_block, "self"));
                        }
 
@@ -2296,7 +2296,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        this_type.value_owned = true;
                                        if (this_type.is_disposable () && !is_in_destructor ()) {
                                                // reference count for self is not increased in finalizers
-                                               var this_value = new GLibValue (get_data_type_for_symbol (current_type_symbol), new CCodeIdentifier ("self"), true);
+                                               var this_value = new GLibValue (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol), new CCodeIdentifier ("self"), true);
                                                ccode.add_expression (destroy_value (this_value));
                                        }
                                }
@@ -4973,7 +4973,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        foreach (MemberInitializer init in expr.get_object_initializer ()) {
                                if (init.symbol_reference is Field) {
                                        var f = (Field) init.symbol_reference;
-                                       var instance_target_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
+                                       var instance_target_type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
                                        var typed_inst = transform_value (new GLibValue (expr.type_reference, instance, true), instance_target_type, init);
                                        store_field (f, typed_inst, init.initializer.target_value, init.source_reference);
 
@@ -4983,7 +4983,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        }
                                } else if (init.symbol_reference is Property) {
                                        var p = (Property) init.symbol_reference;
-                                       var instance_target_type = get_data_type_for_symbol ((TypeSymbol) p.parent_symbol);
+                                       var instance_target_type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) p.parent_symbol);
                                        var typed_inst = transform_value (new GLibValue (expr.type_reference, instance), instance_target_type, init);
                                        var inst_ma = new MemberAccess.simple ("fake");
                                        inst_ma.target_value = typed_inst;
@@ -6191,37 +6191,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                return generated_external_symbols.add (external_symbol);
        }
 
-       public static DataType get_data_type_for_symbol (TypeSymbol sym) {
-               DataType type = null;
-
-               if (sym is Class) {
-                       type = new ObjectType ((Class) sym);
-               } else if (sym is Interface) {
-                       type = new ObjectType ((Interface) sym);
-               } else if (sym is Struct) {
-                       var st = (Struct) sym;
-                       if (st.is_boolean_type ()) {
-                               type = new BooleanType (st);
-                       } else if (st.is_integer_type ()) {
-                               type = new IntegerType (st);
-                       } else if (st.is_floating_type ()) {
-                               type = new FloatingType (st);
-                       } else {
-                               type = new StructValueType (st);
-                       }
-               } else if (sym is Enum) {
-                       type = new EnumValueType ((Enum) sym);
-               } else if (sym is ErrorDomain) {
-                       type = new ErrorType ((ErrorDomain) sym, null);
-               } else if (sym is ErrorCode) {
-                       type = new ErrorType ((ErrorDomain) sym.parent_symbol, (ErrorCode) sym);
-               } else {
-                       Report.error (null, "internal error: `%s' is not a supported type".printf (sym.get_full_name ()));
-                       return new InvalidType ();
-               }
-
-               return type;
-       }
 
        public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression, bool on_error = false) {
                unowned Struct? st = type.type_symbol as Struct;
@@ -6396,7 +6365,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                push_context (new EmitContext ());
                push_function (function);
 
-               var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true);
+               var dest_struct = new GLibValue (SemanticAnalyzer.get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true);
                foreach (Field f in st.get_fields ()) {
                        if (f.binding == MemberBinding.INSTANCE) {
                                var value = load_field (f, load_this_parameter ((TypeSymbol) st));
index e520ede93b6742b833c588591abb90e8bb22be1f..3d082b21e9ca8fee3b51f29a84f03224ae55efa5 100644 (file)
@@ -594,7 +594,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                pub_inst = get_cvalue_ (instance);
                        }
 
-                       var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol);
+                       var instance_target_type = SemanticAnalyzer.get_data_type_for_symbol (field.parent_symbol);
 
                        unowned Class? cl = instance_target_type.type_symbol as Class;
                        bool is_gtypeinstance = ((instance_target_type.type_symbol == cl) && (cl == null || !cl.is_compact));
@@ -812,7 +812,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 
        /* Convenience method returning access to "this" */
        public override TargetValue load_this_parameter (TypeSymbol sym) {
-               var param = new Parameter ("this", get_data_type_for_symbol (sym));
+               var param = new Parameter ("this", SemanticAnalyzer.get_data_type_for_symbol (sym));
                return load_parameter (param);
        }
 
index 7a4b30394f3ee56ee1b9fad5c099d6eaac9828b2..860783b8924e34b62a8f0fe8935c3634cc4867f3 100644 (file)
@@ -511,7 +511,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                                        // as closures have block data parameter
                                        if (m.binding == MemberBinding.INSTANCE) {
                                                var cself = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self");
-                                               ccode.add_declaration (get_ccode_name (get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self"));
+                                               ccode.add_declaration (get_ccode_name (SemanticAnalyzer.get_data_type_for_symbol (current_type_symbol)), new CCodeVariableDeclarator ("self"));
                                                ccode.add_assignment (new CCodeIdentifier ("self"), cself);
                                        }
 
index 83c1a67a33720c625019db9e77fab2ae6fab74bd..e432e60606157452bcb9a5738c6ff9ee475827e0 100644 (file)
@@ -302,7 +302,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 
                push_function (function);
 
-               var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true);
+               var dest_struct = new GLibValue (SemanticAnalyzer.get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true);
                unowned Struct sym = st;
                while (sym.base_struct != null) {
                        sym = sym.base_struct;
index c30384d3818700c0f3032050d9eeb31dee1436b6..65fafeadac9d7450d487ab9defa7887ec888f61c 100644 (file)
@@ -1294,7 +1294,7 @@ public class Vala.GIRWriter : CodeVisitor {
 
                DataType instance_type = null;
                if (instance) {
-                       instance_type = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol);
+                       instance_type = SemanticAnalyzer.get_data_type_for_symbol (m.parent_symbol);
                }
 
                write_params_and_return (params, m.get_type_parameters (), return_type, get_ccode_array_length (m), return_comment, false, instance_type);
@@ -1340,7 +1340,7 @@ public class Vala.GIRWriter : CodeVisitor {
 
                write_doc (get_method_comment (m));
 
-               var datatype = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol);
+               var datatype = SemanticAnalyzer.get_data_type_for_symbol (m.parent_symbol);
                List<TypeParameter>? type_params = null;
                if (m.parent_symbol is Class) {
                        type_params = ((Class) m.parent_symbol).get_type_parameters ();
index 51e69c3d7e1f33f9a1805d1bbb0fe8493c20662b..67c36a5372a542b1e9f52760968afd3f951c5ef4 100644 (file)
@@ -1396,7 +1396,7 @@ public class Vala.GTypeModule : GErrorModule {
 
                var function = new CCodeFunction (name, return_type);
                function.modifiers = CCodeModifiers.STATIC;
-               var this_type = get_data_type_for_symbol (cl);
+               var this_type = SemanticAnalyzer.get_data_type_for_symbol (cl);
                function.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type)));
                push_function (function);
                ccode.add_return (expression);
@@ -1468,7 +1468,7 @@ public class Vala.GTypeModule : GErrorModule {
                if (iface.get_attribute ("GenericAccessors") != null) {
                        foreach (TypeParameter p in iface.get_type_parameters ()) {
                                GenericType p_type = new GenericType (p);
-                               DataType p_data_type = p_type.get_actual_type (get_data_type_for_symbol (cl), null, cl);
+                               DataType p_data_type = p_type.get_actual_type (SemanticAnalyzer.get_data_type_for_symbol (cl), null, cl);
 
                                add_generic_accessor_function ("get_%s_type".printf (p.name.down ()),
                                                               "GType",
@@ -2118,7 +2118,7 @@ public class Vala.GTypeModule : GErrorModule {
                        foreach (TypeParameter p in iface.get_type_parameters ()) {
                                string method_name = "get_%s_type".printf (p.name.down ());
                                var vdeclarator = new CCodeFunctionDeclarator (method_name);
-                               var this_type = get_data_type_for_symbol (iface);
+                               var this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
                                vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type)));
 
                                var vdecl = new CCodeDeclaration ("GType");
@@ -2127,7 +2127,7 @@ public class Vala.GTypeModule : GErrorModule {
 
                                method_name = "get_%s_dup_func".printf (p.name.down ());
                                vdeclarator = new CCodeFunctionDeclarator (method_name);
-                               this_type = get_data_type_for_symbol (iface);
+                               this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
                                vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type)));
 
                                vdecl = new CCodeDeclaration ("GBoxedCopyFunc");
@@ -2136,7 +2136,7 @@ public class Vala.GTypeModule : GErrorModule {
 
                                method_name = "get_%s_destroy_func".printf (p.name.down ());
                                vdeclarator = new CCodeFunctionDeclarator (method_name);
-                               this_type = get_data_type_for_symbol (iface);
+                               this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
                                vdeclarator.add_parameter (new CCodeParameter ("self", get_ccode_name (this_type)));
 
                                vdecl = new CCodeDeclaration ("GDestroyNotify");
index c4020e58054d414043ba16c4c5774d3112ee39a7..0db2fc63658fd7b403cbb1a9357eab5c892fdd15 100644 (file)
                </field>
                <constructor name="new" c:identifier="gir_test_generics_test_new">
                        <return-value transfer-ownership="full">
-                               <type name="GirTest.GenericsTest" c:type="GirTestGenericsTest*"/>
+                               <type name="GirTest.GenericsTest" c:type="GirTestGenericsTest*">
+                                       <type name="gpointer" c:type="gpointer"/>
+                                       <type name="gpointer" c:type="gpointer"/>
+                               </type>
                        </return-value>
                        <parameters>
                                <parameter name="g_type" transfer-ownership="none">
                </constructor>
                <constructor name="typed" c:identifier="gir_test_generics_test_new_typed">
                        <return-value transfer-ownership="full">
-                               <type name="GirTest.GenericsTest" c:type="GirTestGenericsTest*"/>
+                               <type name="GirTest.GenericsTest" c:type="GirTestGenericsTest*">
+                                       <type name="gpointer" c:type="gpointer"/>
+                                       <type name="gpointer" c:type="gpointer"/>
+                               </type>
                        </return-value>
                        <parameters>
                                <parameter name="g_type" transfer-ownership="none">
                </method>
                <constructor name="new" c:identifier="gir_test_generics_object_test_new">
                        <return-value transfer-ownership="full">
-                               <type name="GirTest.GenericsObjectTest" c:type="GirTestGenericsObjectTest*"/>
+                               <type name="GirTest.GenericsObjectTest" c:type="GirTestGenericsObjectTest*">
+                                       <type name="gpointer" c:type="gpointer"/>
+                                       <type name="gpointer" c:type="gpointer"/>
+                               </type>
                        </return-value>
                        <parameters>
                                <parameter name="g_type" transfer-ownership="none">