diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-03-21 11:14:49 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-03-21 11:14:49 +0100 |
commit | 736c5f33673759b22ec19698e47619f2e49592e6 (patch) | |
tree | 1b50a69c74cf4a412e72c21a6daceadf31a61d27 | |
parent | 9f5d3a7a9b56417eaa4489c5616da9e18583bb8f (diff) | |
download | vala-736c5f33673759b22ec19698e47619f2e49592e6.tar.gz |
codegen: Minor refactoring of TypeRegisterFunction and its subclasses
-rw-r--r-- | codegen/valaclassregisterfunction.vala | 16 | ||||
-rw-r--r-- | codegen/valaenumregisterfunction.vala | 16 | ||||
-rw-r--r-- | codegen/valaerrordomainregisterfunction.vala | 16 | ||||
-rw-r--r-- | codegen/valainterfaceregisterfunction.vala | 16 | ||||
-rw-r--r-- | codegen/valastructregisterfunction.vala | 16 | ||||
-rw-r--r-- | codegen/valatyperegisterfunction.vala | 27 |
6 files changed, 41 insertions, 66 deletions
diff --git a/codegen/valaclassregisterfunction.vala b/codegen/valaclassregisterfunction.vala index e1433d2dd..e9490e3be 100644 --- a/codegen/valaclassregisterfunction.vala +++ b/codegen/valaclassregisterfunction.vala @@ -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 ) diff --git a/codegen/valaenumregisterfunction.vala b/codegen/valaenumregisterfunction.vala index c2235a3a0..b8e0d2e8c 100644 --- a/codegen/valaenumregisterfunction.vala +++ b/codegen/valaenumregisterfunction.vala @@ -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); } } diff --git a/codegen/valaerrordomainregisterfunction.vala b/codegen/valaerrordomainregisterfunction.vala index b4be3295e..af41178a4 100644 --- a/codegen/valaerrordomainregisterfunction.vala +++ b/codegen/valaerrordomainregisterfunction.vala @@ -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); } } diff --git a/codegen/valainterfaceregisterfunction.vala b/codegen/valainterfaceregisterfunction.vala index 3a35f995c..f0b363ea6 100644 --- a/codegen/valainterfaceregisterfunction.vala +++ b/codegen/valainterfaceregisterfunction.vala @@ -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 ()) { diff --git a/codegen/valastructregisterfunction.vala b/codegen/valastructregisterfunction.vala index c210f8631..ddc0ee34d 100644 --- a/codegen/valastructregisterfunction.vala +++ b/codegen/valastructregisterfunction.vala @@ -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); } } diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala index c1cd2b615..bea70762e 100644 --- a/codegen/valatyperegisterfunction.vala +++ b/codegen/valatyperegisterfunction.vala @@ -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 { @@ -309,13 +316,6 @@ public abstract class Vala.TypeRegisterFunction { } /** - * 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. * * @return C struct name @@ -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 (); } |