polar-objc 5.44
An Objective-C runtime library
Loading...
Searching...
No Matches
polar-class-table-node.c
1/* Internal API: Class table node type for polar-objc.
2 Copyright (C) 2022-2025 Michael Malicoat <[email protected]>
3
4 This file is part of polar-objc.
5
6 polar-objc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
8
9 polar-objc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 details.
12
13 You should have received a copy of the GNU General Public License along with this program; see the file LICENSE. If
14 not, see <http://www.gnu.org/licenses/>.
15*/
16
17// polar_class_table_node **********************************************************************************************
18// Private =============================================================================================================
19
20// This variable is initialized in polar_class_table_node_get_type()
21static polar_class_table_node_class class_polar_class_table_node;
22
23// This variable is initialized in _polar_class_table_node_class_init()
24static polar_runtime_object_class *superclass_polar_class_table_node = NULL;
25
26// ---------------------------------------------------------------------------------------------------------------------
27
28POLAR_FUNCTION_INTERNAL polar_class_table_node *
29_polar_class_table_node_init( polar_class_table_node *self )
30{
31 // Chain up first
32 self = (polar_class_table_node *)
33 POLAR_RUNTIME_OBJECT_CLASS(superclass_polar_class_table_node)->init( (polar_runtime_object *)self );
34
35 if( self != NULL )
36 {
37 self->count_references = 1;
38 self->class_target = Nil;
39 }
40
41 return self;
42}
43
44POLAR_FUNCTION_INTERNAL polar_runtime_object *
45_polar_class_table_node_finalize( polar_class_table_node *self )
46{
47 objc_atomic_exchange_pointer( (void **)(&self->class_target), Nil );
48
49 polar_list_node_list_free( (polar_list_node **)(&self->list_class_duplicates) );
50
51 polar_memory_free(self->array_inheritance, self->count_superclasses << OBJC_SIZE_SHIFT_POINTER);
52 self->array_inheritance = NULL;
53
54 self->count_references = 0;
55
56 // Chain up
57 return POLAR_RUNTIME_OBJECT_CLASS(superclass_polar_class_table_node)->finalize( (polar_runtime_object *)self );
58}
59
60POLAR_FUNCTION_INTERNAL void
61_polar_class_table_node_class_init( polar_class_table_node_class *self )
62{
63 // Acquire our superclass
64 superclass_polar_class_table_node = POLAR_RUNTIME_OBJECT_CLASS(self)->class_superclass;
65
66 // Establish our virtual methods
67 ( (polar_runtime_object_class *)self )->init = (polar_func_runtime_object_lifecycle)_polar_class_table_node_init;
68
69 ( (polar_runtime_object_class *)self )->finalize =
70 (polar_func_runtime_object_lifecycle)_polar_class_table_node_finalize;
71}
72
73static struct polar_internal_type_info pti_polar_class_table_node =
74{
75 .name_type = "polar_class_table_node",
76 .size_type_instance = sizeof(polar_class_table_node),
77 .size_type_class = sizeof(polar_class_table_node_class),
78 .type_class_init = (polar_func_runtime_object_class_lifecycle)_polar_class_table_node_class_init
79};
80
81// Public ==============================================================================================================
82
83POLAR_FUNCTION_INTERNAL OBJC_FUNCTION_CONSTANT polar_internal_type
84polar_class_table_node_get_type( void )
85{
86 static polar_internal_type pt_polar_class_table_node = POLAR_INTERNAL_TYPE_INVALID;
87
88 if( pt_polar_class_table_node != POLAR_INTERNAL_TYPE_INVALID )
89 return pt_polar_class_table_node;
90
91 pt_polar_class_table_node = polar_internal_type_init( POLAR_TYPE_HASH_TABLE_NODE_STRING_KEY,
92 &class_polar_class_table_node, &pti_polar_class_table_node );
93
94 return pt_polar_class_table_node;
95}
96
97POLAR_FUNCTION_INTERNAL void
98polar_class_table_node_copy_inheritance( polar_class_table_node *self, polar_class_table_node *node_superclass )
99{
100 assert( POLAR_IS_CLASS_TABLE_NODE(self) );
101 assert( self->array_inheritance == NULL );
102
103 if( POLAR_IS_CLASS_TABLE_NODE(node_superclass) )
104 {
105 self->ofs_class_private_data = node_superclass->ofs_class_private_data;
106
107 self->count_superclasses = ( node_superclass->count_superclasses + 1 );
108 self->array_inheritance = (struct objc_class **)
109 polar_memory_allocate( self->count_superclasses << OBJC_SIZE_SHIFT_POINTER );
110
111 if( node_superclass->array_inheritance != NULL )
112 {
113 assert( self->count_superclasses >= 1 );
114
115 objc_memcpy( &self->array_inheritance[1], &node_superclass->array_inheritance[0],
116 node_superclass->count_superclasses << OBJC_SIZE_SHIFT_POINTER );
117 }
118
119 self->array_inheritance[0] = node_superclass->class_target;
120 }
121}
Definition polar-class-table-node.h:38
Definition polar-class-table-node.h:24
Definition polar-internal-type.h:34
Definition polar-list-node.h:25
Definition polar-runtime-object.h:36
Definition polar-runtime-object.h:31