]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Minor refactoring of TypeRegisterFunction and its subclasses
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 21 Mar 2023 10:14:49 +0000 (11:14 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 21 Mar 2023 10:14:49 +0000 (11:14 +0100)
codegen/valaclassregisterfunction.vala
codegen/valaenumregisterfunction.vala
codegen/valaerrordomainregisterfunction.vala
codegen/valainterfaceregisterfunction.vala
codegen/valastructregisterfunction.vala
codegen/valatyperegisterfunction.vala

index e1433d2ddfb4e96e47e2ec5aac2ec763a20fccdb..e9490e3be5e857f3e70ecfb71d37886c35335c2c 100644 (file)
@@ -29,7 +29,11 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
        /**
         * Specifies the class to be registered.
         */
-       public weak Class class_reference { get; set; }
+       public weak Class class_reference {
+               get {
+                       return (Class) type_symbol;
+               }
+       }
 
        /**
         * Creates a new C function to register the specified class at runtime.
@@ -38,11 +42,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
         * @return   newly created class register function
         */
        public ClassRegisterFunction (Class cl) {
-               class_reference = cl;
-       }
-
-       public override TypeSymbol get_type_declaration () {
-               return class_reference;
+               base (cl);
        }
 
        public override string get_type_struct_name () {
@@ -101,10 +101,6 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
                }
        }
 
-       public override SymbolAccessibility get_accessibility () {
-               return class_reference.access;
-       }
-
        public override string? get_gtype_value_table_init_function_name () {
                bool is_fundamental = !class_reference.is_compact && class_reference.base_class == null;
                if ( is_fundamental )
index c2235a3a06923aad24f7cf189b4e09991185b56c..b8e0d2e8c3fbd454d2516c99f681d8df1648e33c 100644 (file)
@@ -30,7 +30,11 @@ public class Vala.EnumRegisterFunction : TypeRegisterFunction {
        /**
         * Specifies the enum to be registered.
         */
-       public weak Enum enum_reference { get; set; }
+       public weak Enum enum_reference {
+               get {
+                       return (Enum) type_symbol;
+               }
+       }
 
        /**
         * Creates a new C function to register the specified enum at runtime.
@@ -39,14 +43,6 @@ public class Vala.EnumRegisterFunction : TypeRegisterFunction {
         * @return   newly created enum register function
         */
        public EnumRegisterFunction (Enum en) {
-               enum_reference = en;
-       }
-
-       public override TypeSymbol get_type_declaration () {
-               return enum_reference;
-       }
-
-       public override SymbolAccessibility get_accessibility () {
-               return enum_reference.access;
+               base (en);
        }
 }
index b4be3295e791fcd7445af8887ed2f62088228f45..af41178a412760ffbb7c9625e2652f93c73c2494 100644 (file)
@@ -29,7 +29,11 @@ public class Vala.ErrorDomainRegisterFunction : TypeRegisterFunction {
        /**
         * Specifies the error domain to be registered.
         */
-       public weak ErrorDomain error_domain_reference { get; set; }
+       public weak ErrorDomain error_domain_reference {
+               get {
+                       return (ErrorDomain) type_symbol;
+               }
+       }
 
        /**
         * Creates a new C function to register the specified error domain at runtime.
@@ -38,14 +42,6 @@ public class Vala.ErrorDomainRegisterFunction : TypeRegisterFunction {
         * @return        newly created error domain register function
         */
        public ErrorDomainRegisterFunction (ErrorDomain edomain) {
-               error_domain_reference = edomain;
-       }
-
-       public override TypeSymbol get_type_declaration () {
-               return error_domain_reference;
-       }
-
-       public override SymbolAccessibility get_accessibility () {
-               return error_domain_reference.access;
+               base (edomain);
        }
 }
index 3a35f995c60789b0b38b7573bdf8dba728f76198..f0b363ea666e2bb7433a2aa1d60e25fe9f7a6bdb 100644 (file)
@@ -31,14 +31,14 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
        /**
         * Specifies the interface to be registered.
         */
-       public weak Interface interface_reference { get; set; }
-
-       public InterfaceRegisterFunction (Interface iface) {
-               interface_reference = iface;
+       public weak Interface interface_reference {
+               get {
+                       return (Interface) type_symbol;
+               }
        }
 
-       public override TypeSymbol get_type_declaration () {
-               return interface_reference;
+       public InterfaceRegisterFunction (Interface iface) {
+               base (iface);
        }
 
        public override string get_type_struct_name () {
@@ -73,10 +73,6 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction {
                return "G_TYPE_INTERFACE";
        }
 
-       public override SymbolAccessibility get_accessibility () {
-               return interface_reference.access;
-       }
-
        public override void get_type_interface_init_statements (CodeContext context, CCodeBlock block, bool plugin) {
                /* register all prerequisites */
                foreach (DataType prereq_ref in interface_reference.get_prerequisites ()) {
index c210f86315cd861880873f51bad841c17163c48e..ddc0ee34d9f6183a4b0808bd5c4e2a55c8a18d9c 100644 (file)
@@ -29,7 +29,11 @@ public class Vala.StructRegisterFunction : TypeRegisterFunction {
        /**
         * Specifies the struct to be registered.
         */
-       public weak Struct struct_reference { get; set; }
+       public weak Struct struct_reference {
+               get {
+                       return (Struct) type_symbol;
+               }
+       }
 
        /**
         * Creates a new C function to register the specified struct at runtime.
@@ -38,14 +42,6 @@ public class Vala.StructRegisterFunction : TypeRegisterFunction {
         * @return   newly created struct register function
         */
        public StructRegisterFunction (Struct st) {
-               struct_reference = st;
-       }
-
-       public override TypeSymbol get_type_declaration () {
-               return struct_reference;
-       }
-
-       public override SymbolAccessibility get_accessibility () {
-               return struct_reference.access;
+               base (st);
        }
 }
index c1cd2b615cd8c89c247681c34eb08a4afce65b03..bea70762e5b29dd29f98107f803ad59c8f52109a 100644 (file)
@@ -26,16 +26,23 @@ using GLib;
  * C function to register a type at runtime.
  */
 public abstract class Vala.TypeRegisterFunction {
+       /**
+        * Specifies the enum to be registered.
+        */
+       public weak TypeSymbol type_symbol { get; private set; }
+
        CCodeFragment source_declaration_fragment = new CCodeFragment ();
        CCodeFragment declaration_fragment = new CCodeFragment ();
        CCodeFragment definition_fragment = new CCodeFragment ();
 
+       protected TypeRegisterFunction (TypeSymbol sym) {
+               type_symbol = sym;
+       }
+
        /**
         * Constructs the C function from the specified type.
         */
        public void init_from_type (CodeContext context, bool plugin, bool declaration_only) {
-               var type_symbol = get_type_declaration ();
-
                bool fundamental = false;
                unowned Class? cl = type_symbol as Class;
                if (cl != null && !cl.is_compact && cl.base_class == null) {
@@ -70,10 +77,10 @@ public abstract class Vala.TypeRegisterFunction {
                        fun.modifiers = CCodeModifiers.CONST;
 
                        /* Function will not be prototyped anyway */
-                       if (get_accessibility () == SymbolAccessibility.PRIVATE) {
+                       if (type_symbol.access == SymbolAccessibility.PRIVATE) {
                                // avoid C warning as this function is not always used
                                fun.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.UNUSED;
-                       } else if (context.hide_internal && get_accessibility () == SymbolAccessibility.INTERNAL) {
+                       } else if (context.hide_internal && type_symbol.access == SymbolAccessibility.INTERNAL) {
                                // avoid C warning as this function is not always used
                                fun.modifiers |= CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
                        } else {
@@ -308,13 +315,6 @@ public abstract class Vala.TypeRegisterFunction {
                definition_fragment.append (fun);
        }
 
-       /**
-        * Returns the data type to be registered.
-        *
-        * @return type to be registered
-        */
-       public abstract TypeSymbol get_type_declaration ();
-
        /**
         * Returns the name of the type struct in C code.
         *
@@ -491,9 +491,4 @@ public abstract class Vala.TypeRegisterFunction {
        public CCodeFragment get_definition () {
                return definition_fragment;
        }
-
-       /**
-        * Returns the accessibility for this type.
-        */
-       public abstract SymbolAccessibility get_accessibility ();
 }