]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Move find_parent_type_symbol/get_this_type() to SemanticAnalyzer ba8122d3a64e44eac44c5254c93fb181df601b0a
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 25 Aug 2019 13:18:04 +0000 (15:18 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 28 Aug 2019 18:25:37 +0000 (20:25 +0200)
codegen/valaccodemethodmodule.vala
vala/valasemanticanalyzer.vala

index 7b8702e118b1a17129fe30c5813e70c61072eba2..864d6a93e8c5e8d111fe6db413822648c30aab71 100644 (file)
@@ -946,20 +946,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        }
                } else if ((m.binding == MemberBinding.INSTANCE || (m.parent_symbol is Struct && m is CreationMethod))
                    && (direction != 2 || get_ccode_finish_instance (m))) {
-                       TypeSymbol parent_type = find_parent_type (m);
-                       DataType this_type;
-                       if (parent_type is Class) {
-                               this_type = new ObjectType ((Class) parent_type);
-                       } else if (parent_type is Interface) {
-                               this_type = new ObjectType ((Interface) parent_type);
-                       } else if (parent_type is Struct) {
-                               this_type = new StructValueType ((Struct) parent_type);
-                       } else if (parent_type is Enum) {
-                               this_type = new EnumValueType ((Enum) parent_type);
-                       } else {
-                               Report.error (parent_type.source_reference, "internal: Unsupported symbol type");
-                               this_type = new InvalidType ();
-                       }
+                       var this_type = SemanticAnalyzer.get_this_type (m);
 
                        generate_type_declaration (this_type, decl_space);
 
@@ -979,9 +966,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        }
                        cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), instance_param);
                } else if (m.binding == MemberBinding.CLASS) {
-                       TypeSymbol parent_type = find_parent_type (m);
-                       DataType this_type;
-                       this_type = new ClassType ((Class) parent_type);
+                       var this_type = SemanticAnalyzer.get_this_type (m);
                        var class_param = new CCodeParameter ("klass", get_ccode_name (this_type));
                        cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), class_param);
                }
@@ -1216,16 +1201,6 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                ccode.add_expression (ccheck);
        }
 
-       private TypeSymbol? find_parent_type (Symbol sym) {
-               while (sym != null) {
-                       if (sym is TypeSymbol) {
-                               return (TypeSymbol) sym;
-                       }
-                       sym = sym.parent_symbol;
-               }
-               return null;
-       }
-
        public override void visit_creation_method (CreationMethod m) {
                push_line (m.source_reference);
 
index fa90deb7aa12f394332ce9b2b287deaf27e63d45..f81921296494ddc1ab44341cc2657ee01894f6be 100644 (file)
@@ -1116,6 +1116,56 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                }
        }
 
+       public static unowned TypeSymbol? find_parent_type_symbol (Symbol sym) {
+               while (sym != null) {
+                       if (sym is TypeSymbol) {
+                               return (TypeSymbol) sym;
+                       }
+                       sym = sym.parent_symbol;
+               }
+               return null;
+       }
+
+       public static DataType? get_this_type (Method m) {
+               unowned TypeSymbol? parent_type = find_parent_type_symbol (m);
+               if (parent_type == null) {
+                       Report.error (parent_type.source_reference, "internal: Unsupported symbol type");
+                       return new InvalidType ();
+               }
+
+               DataType? this_type = null;
+               switch (m.binding) {
+               case MemberBinding.INSTANCE:
+                       if (parent_type is Class) {
+                               this_type = new ObjectType ((Class) parent_type);
+                       } else if (parent_type is Interface) {
+                               this_type = new ObjectType ((Interface) parent_type);
+                       } else if (parent_type is Struct) {
+                               this_type = new StructValueType ((Struct) parent_type);
+                       } else if (parent_type is Enum) {
+                               this_type = new EnumValueType ((Enum) parent_type);
+                       } else {
+                               Report.error (parent_type.source_reference, "internal: Unsupported symbol type");
+                               this_type = new InvalidType ();
+                       }
+                       break;
+               case MemberBinding.CLASS:
+                       if (parent_type is Class) {
+                               this_type = new ClassType ((Class) parent_type);
+                       } else {
+                               Report.error (parent_type.source_reference, "internal: Unsupported symbol type");
+                               this_type = new InvalidType ();
+                       }
+                       break;
+               case MemberBinding.STATIC:
+               default:
+                       Report.error (m.source_reference, "internal: Does not support a parent instance");
+                       this_type = new InvalidType ();
+                       break;
+               }
+               return this_type;
+       }
+
        public bool is_in_constructor () {
                var sym = current_symbol;
                while (sym != null) {