File: | build/gcc/objc/objc-gnu-runtime-abi-01.cc |
Warning: | line 718, column 3 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* GNU Runtime ABI version 8 | ||||
2 | Copyright (C) 2011-2023 Free Software Foundation, Inc. | ||||
3 | Contributed by Iain Sandoe (split from objc-act.cc) | ||||
4 | |||||
5 | This file is part of GCC. | ||||
6 | |||||
7 | GCC is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 3, or (at your option) | ||||
10 | any later version. | ||||
11 | |||||
12 | GCC is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | |||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with GCC; see the file COPYING3. If not see | ||||
19 | <http://www.gnu.org/licenses/>. */ | ||||
20 | |||||
21 | #include "config.h" | ||||
22 | #include "system.h" | ||||
23 | #include "coretypes.h" | ||||
24 | #include "options.h" | ||||
25 | #include "tree.h" | ||||
26 | #include "stringpool.h" | ||||
27 | #include "attribs.h" | ||||
28 | |||||
29 | #ifdef OBJCPLUS | ||||
30 | #include "cp/cp-tree.h" | ||||
31 | #else | ||||
32 | #include "c/c-tree.h" | ||||
33 | #include "c/c-lang.h" | ||||
34 | #endif | ||||
35 | |||||
36 | #include "langhooks.h" | ||||
37 | #include "c-family/c-objc.h" | ||||
38 | #include "objc-act.h" | ||||
39 | |||||
40 | /* When building Objective-C++, we are not linking against the C front-end | ||||
41 | and so need to replicate the C tree-construction functions in some way. */ | ||||
42 | #ifdef OBJCPLUS | ||||
43 | #define OBJCP_REMAP_FUNCTIONS | ||||
44 | #include "objcp-decl.h" | ||||
45 | #endif /* OBJCPLUS */ | ||||
46 | |||||
47 | #include "toplev.h" | ||||
48 | #include "tree-iterator.h" | ||||
49 | |||||
50 | #include "objc-runtime-hooks.h" | ||||
51 | #include "objc-runtime-shared-support.h" | ||||
52 | #include "objc-encoding.h" | ||||
53 | |||||
54 | /* GNU runtime private definitions. */ | ||||
55 | #define DEF_CONSTANT_STRING_CLASS_NAME"NXConstantString" "NXConstantString" | ||||
56 | |||||
57 | #define TAG_GETCLASS"objc_get_class" "objc_get_class" | ||||
58 | #define TAG_GETMETACLASS"objc_get_meta_class" "objc_get_meta_class" | ||||
59 | |||||
60 | #define TAG_MSGSEND"objc_msg_lookup" "objc_msg_lookup" | ||||
61 | #define TAG_MSGSENDSUPER"objc_msg_lookup_super" "objc_msg_lookup_super" | ||||
62 | |||||
63 | /* GNU-specific tags. */ | ||||
64 | |||||
65 | #define TAG_EXECCLASS"__objc_exec_class" "__objc_exec_class" | ||||
66 | #define TAG_GNUINIT"__objc_gnu_init" "__objc_gnu_init" | ||||
67 | |||||
68 | /* The version identifies which language generation and runtime | ||||
69 | the module (file) was compiled for, and is recorded in the | ||||
70 | module descriptor. */ | ||||
71 | #define OBJC_VERSION8 8 | ||||
72 | |||||
73 | #define PROTOCOL_VERSION2 2 | ||||
74 | |||||
75 | /* This macro provides a method of removing ambiguity between runtimes | ||||
76 | when LTO is in use on targets supporting multiple runtimes. | ||||
77 | |||||
78 | For example, at present, any target that includes an implementation of | ||||
79 | the NeXT runtime needs to place Objective-C meta-data into specific | ||||
80 | named sections. This should _not_ be done for the GNU runtime, and the | ||||
81 | following macro is used to attach Objective-C private attributes that may | ||||
82 | be used to identify the runtime for which the meta-data are intended. */ | ||||
83 | |||||
84 | #define OBJCMETA(DECL,VERS,KIND)if (VERS) ((contains_struct_check ((DECL), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 84, __FUNCTION__))->decl_common.attributes) = build_tree_list ((VERS), (KIND)); \ | ||||
85 | if (VERS) \ | ||||
86 | DECL_ATTRIBUTES (DECL)((contains_struct_check ((DECL), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 86, __FUNCTION__))->decl_common.attributes) = build_tree_list ((VERS), (KIND)); | ||||
87 | |||||
88 | static void gnu_runtime_01_initialize (void); | ||||
89 | |||||
90 | static void build_selector_template (void); | ||||
91 | |||||
92 | static tree gnu_runtime_abi_01_super_superclassfield_id (void); | ||||
93 | |||||
94 | static tree gnu_runtime_abi_01_class_decl (tree); | ||||
95 | static tree gnu_runtime_abi_01_metaclass_decl (tree); | ||||
96 | static tree gnu_runtime_abi_01_category_decl (tree); | ||||
97 | static tree gnu_runtime_abi_01_protocol_decl (tree); | ||||
98 | static tree gnu_runtime_abi_01_string_decl (tree, const char *, string_section); | ||||
99 | |||||
100 | static tree gnu_runtime_abi_01_get_class_reference (tree); | ||||
101 | static tree gnu_runtime_abi_01_build_typed_selector_reference (location_t, tree, | ||||
102 | tree); | ||||
103 | static tree gnu_runtime_abi_01_get_protocol_reference (location_t, tree); | ||||
104 | static tree gnu_runtime_abi_01_build_ivar_ref (location_t, tree, tree); | ||||
105 | static tree gnu_runtime_abi_01_get_class_super_ref (location_t, struct imp_entry *, bool); | ||||
106 | static tree gnu_runtime_abi_01_get_category_super_ref (location_t, struct imp_entry *, bool); | ||||
107 | |||||
108 | static tree gnu_runtime_abi_01_receiver_is_class_object (tree); | ||||
109 | static void gnu_runtime_abi_01_get_arg_type_list_base (vec<tree, va_gc> **, | ||||
110 | tree, int, int); | ||||
111 | static tree gnu_runtime_abi_01_build_objc_method_call (location_t, tree, tree, | ||||
112 | tree, tree, tree, int); | ||||
113 | |||||
114 | static bool gnu_runtime_abi_01_setup_const_string_class_decl (void); | ||||
115 | static tree gnu_runtime_abi_01_build_const_string_constructor (location_t, tree,int); | ||||
116 | |||||
117 | static void objc_generate_v1_gnu_metadata (void); | ||||
118 | |||||
119 | static tree objc_eh_runtime_type (tree type); | ||||
120 | static tree objc_eh_personality (void); | ||||
121 | static tree objc_build_exc_ptr (struct objc_try_context **); | ||||
122 | static tree build_throw_stmt (location_t, tree, bool); | ||||
123 | static tree begin_catch (struct objc_try_context **, tree, tree, tree, bool); | ||||
124 | static void finish_catch (struct objc_try_context **, tree); | ||||
125 | static tree finish_try_stmt (struct objc_try_context **); | ||||
126 | |||||
127 | bool | ||||
128 | objc_gnu_runtime_abi_01_init (objc_runtime_hooks *rthooks) | ||||
129 | { | ||||
130 | /* GNU runtime does not need the compiler to change code in order to do GC. */ | ||||
131 | if (flag_objc_gcglobal_options.x_flag_objc_gc) | ||||
132 | { | ||||
133 | warning_at (UNKNOWN_LOCATION((location_t) 0), 0, | ||||
134 | "%<-fobjc-gc%> is ignored for %<-fgnu-runtime%>"); | ||||
135 | flag_objc_gcglobal_options.x_flag_objc_gc = 0; | ||||
136 | } | ||||
137 | |||||
138 | /* Although I guess we could, we don't currently support SJLJ exceptions for the | ||||
139 | GNU runtime. */ | ||||
140 | if (flag_objc_sjlj_exceptionsglobal_options.x_flag_objc_sjlj_exceptions) | ||||
141 | { | ||||
142 | inform (UNKNOWN_LOCATION((location_t) 0), "%<-fobjc-sjlj-exceptions%> is ignored for %<-fgnu-runtime%>"); | ||||
143 | flag_objc_sjlj_exceptionsglobal_options.x_flag_objc_sjlj_exceptions = 0; | ||||
144 | } | ||||
145 | |||||
146 | /* TODO: Complain if -fobjc-abi-version=N was used. */ | ||||
147 | |||||
148 | /* TODO: Complain if -fobj-nilcheck was used. */ | ||||
149 | |||||
150 | rthooks->initialize = gnu_runtime_01_initialize; | ||||
151 | rthooks->default_constant_string_class_name = DEF_CONSTANT_STRING_CLASS_NAME"NXConstantString"; | ||||
152 | rthooks->tag_getclass = TAG_GETCLASS"objc_get_class"; | ||||
153 | rthooks->super_superclassfield_ident = gnu_runtime_abi_01_super_superclassfield_id; | ||||
154 | |||||
155 | rthooks->class_decl = gnu_runtime_abi_01_class_decl; | ||||
156 | rthooks->metaclass_decl = gnu_runtime_abi_01_metaclass_decl; | ||||
157 | rthooks->category_decl = gnu_runtime_abi_01_category_decl; | ||||
158 | rthooks->protocol_decl = gnu_runtime_abi_01_protocol_decl; | ||||
159 | rthooks->string_decl = gnu_runtime_abi_01_string_decl; | ||||
160 | |||||
161 | rthooks->get_class_reference = gnu_runtime_abi_01_get_class_reference; | ||||
162 | rthooks->build_selector_reference = gnu_runtime_abi_01_build_typed_selector_reference; | ||||
163 | rthooks->get_protocol_reference = gnu_runtime_abi_01_get_protocol_reference; | ||||
164 | rthooks->build_ivar_reference = gnu_runtime_abi_01_build_ivar_ref; | ||||
165 | rthooks->get_class_super_ref = gnu_runtime_abi_01_get_class_super_ref; | ||||
166 | rthooks->get_category_super_ref = gnu_runtime_abi_01_get_category_super_ref; | ||||
167 | |||||
168 | rthooks->receiver_is_class_object = gnu_runtime_abi_01_receiver_is_class_object; | ||||
169 | rthooks->get_arg_type_list_base = gnu_runtime_abi_01_get_arg_type_list_base; | ||||
170 | rthooks->build_objc_method_call = gnu_runtime_abi_01_build_objc_method_call; | ||||
171 | |||||
172 | rthooks->setup_const_string_class_decl = | ||||
173 | gnu_runtime_abi_01_setup_const_string_class_decl; | ||||
174 | rthooks->build_const_string_constructor = | ||||
175 | gnu_runtime_abi_01_build_const_string_constructor; | ||||
176 | |||||
177 | rthooks->build_throw_stmt = build_throw_stmt; | ||||
178 | rthooks->build_exc_ptr = objc_build_exc_ptr; | ||||
179 | rthooks->begin_catch = begin_catch; | ||||
180 | rthooks->finish_catch = finish_catch; | ||||
181 | rthooks->finish_try_stmt = finish_try_stmt; | ||||
182 | |||||
183 | rthooks->generate_metadata = objc_generate_v1_gnu_metadata; | ||||
184 | return true; | ||||
185 | } | ||||
186 | |||||
187 | static void build_selector_table_decl (void); | ||||
188 | static void build_class_template (void); | ||||
189 | static void build_category_template (void); | ||||
190 | static void build_protocol_template (void); | ||||
191 | |||||
192 | static GTY(()) tree objc_meta; | ||||
193 | static GTY(()) tree meta_base; | ||||
194 | |||||
195 | static void gnu_runtime_01_initialize (void) | ||||
196 | { | ||||
197 | tree type, ftype, IMP_type; | ||||
198 | |||||
199 | /* We do not need to mark GNU ObjC metadata for different sections, | ||||
200 | however, we do need to make sure that it is not mistaken for NeXT | ||||
201 | metadata. */ | ||||
202 | objc_meta = get_identifier ("OBJC1METG")(__builtin_constant_p ("OBJC1METG") ? get_identifier_with_length (("OBJC1METG"), strlen ("OBJC1METG")) : get_identifier ("OBJC1METG" )); | ||||
203 | meta_base = get_identifier ("NONE")(__builtin_constant_p ("NONE") ? get_identifier_with_length ( ("NONE"), strlen ("NONE")) : get_identifier ("NONE")); | ||||
204 | |||||
205 | /* Declare type of selector-objects that represent an operation name. */ | ||||
206 | /* `const struct objc_selector *' */ | ||||
207 | type = xref_tag (RECORD_TYPE, get_identifier (TAG_SELECTOR)(__builtin_constant_p ("objc_selector") ? get_identifier_with_length (("objc_selector"), strlen ("objc_selector")) : get_identifier ("objc_selector"))); | ||||
208 | type = build_qualified_type (type, TYPE_QUAL_CONST); | ||||
209 | objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE] = build_pointer_type (type); | ||||
210 | |||||
211 | /* SEL typedef. */ | ||||
212 | type = lang_hooks.decls.pushdecl (build_decl (input_location, | ||||
213 | TYPE_DECL, | ||||
214 | objc_selector_nameobjc_global_trees[OCTI_SEL_NAME], | ||||
215 | objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE])); | ||||
216 | suppress_warning (type); | ||||
217 | |||||
218 | /* typedef id (*IMP)(id, SEL, ...); */ | ||||
219 | ftype = build_varargs_function_type_list (objc_object_typeobjc_global_trees[OCTI_ID_TYPE], | ||||
220 | objc_object_typeobjc_global_trees[OCTI_ID_TYPE], | ||||
221 | objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE], | ||||
222 | NULL_TREE(tree) nullptr); | ||||
223 | |||||
224 | IMP_type = build_pointer_type (ftype); | ||||
225 | |||||
226 | build_class_template (); | ||||
227 | build_super_template (); | ||||
228 | build_protocol_template (); | ||||
229 | build_category_template (); | ||||
230 | |||||
231 | /* GNU runtime messenger entry points. */ | ||||
232 | /* TREE_NOTHROW is cleared for the message-sending functions, | ||||
233 | because the function that gets called can throw in Obj-C++, or | ||||
234 | could itself call something that can throw even in Obj-C. */ | ||||
235 | |||||
236 | /* IMP objc_msg_lookup (id, SEL); */ | ||||
237 | type = build_function_type_list (IMP_type, | ||||
238 | objc_object_typeobjc_global_trees[OCTI_ID_TYPE], | ||||
239 | objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE], | ||||
240 | NULL_TREE(tree) nullptr); | ||||
241 | |||||
242 | umsg_declobjc_global_trees[OCTI_UMSG_DECL] = add_builtin_function (TAG_MSGSEND"objc_msg_lookup", | ||||
243 | type, 0, NOT_BUILT_IN, | ||||
244 | NULLnullptr, NULL_TREE(tree) nullptr); | ||||
245 | TREE_NOTHROW (umsg_decl)((objc_global_trees[OCTI_UMSG_DECL])->base.nothrow_flag) = 0; | ||||
246 | |||||
247 | /* IMP objc_msg_lookup_super (struct objc_super *, SEL); */ | ||||
248 | type = build_function_type_list (IMP_type, | ||||
249 | objc_super_typeobjc_global_trees[OCTI_SUPER_TYPE], | ||||
250 | objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE], | ||||
251 | NULL_TREE(tree) nullptr); | ||||
252 | |||||
253 | umsg_super_declobjc_global_trees[OCTI_UMSG_SUPER_DECL] = add_builtin_function (TAG_MSGSENDSUPER"objc_msg_lookup_super", | ||||
254 | type, 0, NOT_BUILT_IN, | ||||
255 | NULLnullptr, NULL_TREE(tree) nullptr); | ||||
256 | TREE_NOTHROW (umsg_super_decl)((objc_global_trees[OCTI_UMSG_SUPER_DECL])->base.nothrow_flag ) = 0; | ||||
257 | |||||
258 | /* The following GNU runtime entry point is called to initialize | ||||
259 | each module: | ||||
260 | |||||
261 | __objc_exec_class (void *); */ | ||||
262 | type = build_function_type_list (void_type_nodeglobal_trees[TI_VOID_TYPE], | ||||
263 | ptr_type_nodeglobal_trees[TI_PTR_TYPE], | ||||
264 | NULL_TREE(tree) nullptr); | ||||
265 | |||||
266 | execclass_declobjc_global_trees[OCTI_EXECCLASS_DECL] = add_builtin_function (TAG_EXECCLASS"__objc_exec_class", | ||||
267 | type, 0, NOT_BUILT_IN, | ||||
268 | NULLnullptr, NULL_TREE(tree) nullptr); | ||||
269 | |||||
270 | type = build_function_type_list (objc_object_typeobjc_global_trees[OCTI_ID_TYPE], | ||||
271 | const_string_type_nodec_global_trees[CTI_CONST_STRING_TYPE], | ||||
272 | NULL_TREE(tree) nullptr); | ||||
273 | |||||
274 | /* id objc_getClass (const char *); */ | ||||
275 | objc_get_class_declobjc_global_trees[OCTI_GET_CLASS_DECL] | ||||
276 | = add_builtin_function (TAG_GETCLASS"objc_get_class", type, 0, NOT_BUILT_IN, | ||||
277 | NULLnullptr, NULL_TREE(tree) nullptr); | ||||
278 | |||||
279 | /* id objc_getMetaClass (const char *); */ | ||||
280 | objc_get_meta_class_declobjc_global_trees[OCTI_GET_MCLASS_DECL] = add_builtin_function (TAG_GETMETACLASS"objc_get_meta_class", type, | ||||
281 | 0, NOT_BUILT_IN, NULLnullptr, | ||||
282 | NULL_TREE(tree) nullptr); | ||||
283 | |||||
284 | /* static SEL _OBJC_SELECTOR_TABLE[]; */ | ||||
285 | build_selector_table_decl (); | ||||
286 | |||||
287 | /* Stuff for properties. | ||||
288 | The codegen relies on this being NULL for GNU. */ | ||||
289 | objc_copyStruct_declobjc_global_trees[OCTI_COPY_STRUCT_DECL] = NULL_TREE(tree) nullptr; | ||||
290 | |||||
291 | /* This is the type of all of the following functions | ||||
292 | bjc_getPropertyStruct() and objc_setPropertyStruct(). */ | ||||
293 | type = build_function_type_list (void_type_nodeglobal_trees[TI_VOID_TYPE], | ||||
294 | ptr_type_nodeglobal_trees[TI_PTR_TYPE], | ||||
295 | const_ptr_type_nodeglobal_trees[TI_CONST_PTR_TYPE], | ||||
296 | ptrdiff_type_nodeglobal_trees[TI_PTRDIFF_TYPE], | ||||
297 | boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], | ||||
298 | boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], | ||||
299 | NULL_TREE(tree) nullptr); | ||||
300 | |||||
301 | /* Declare the following function: | ||||
302 | void | ||||
303 | objc_getPropertyStruct (void *destination, const void *source, | ||||
304 | ptrdiff_t size, BOOL is_atomic, BOOL has_strong); */ | ||||
305 | objc_getPropertyStruct_declobjc_global_trees[OCTI_GET_PROPERTY_STRUCT_DECL] = add_builtin_function ("objc_getPropertyStruct", | ||||
306 | type, 0, NOT_BUILT_IN, | ||||
307 | NULLnullptr, NULL_TREE(tree) nullptr); | ||||
308 | TREE_NOTHROW (objc_getPropertyStruct_decl)((objc_global_trees[OCTI_GET_PROPERTY_STRUCT_DECL])->base. nothrow_flag) = 0; | ||||
309 | /* Declare the following function: | ||||
310 | void | ||||
311 | objc_setPropertyStruct (void *destination, const void *source, | ||||
312 | ptrdiff_t size, BOOL is_atomic, BOOL has_strong); */ | ||||
313 | objc_setPropertyStruct_declobjc_global_trees[OCTI_SET_PROPERTY_STRUCT_DECL] = add_builtin_function ("objc_setPropertyStruct", | ||||
314 | type, 0, NOT_BUILT_IN, | ||||
315 | NULLnullptr, NULL_TREE(tree) nullptr); | ||||
316 | TREE_NOTHROW (objc_setPropertyStruct_decl)((objc_global_trees[OCTI_SET_PROPERTY_STRUCT_DECL])->base. nothrow_flag) = 0; | ||||
317 | |||||
318 | using_eh_for_cleanups (); | ||||
319 | lang_hooks.eh_runtime_type = objc_eh_runtime_type; | ||||
320 | lang_hooks.eh_personality = objc_eh_personality; | ||||
321 | } | ||||
322 | |||||
323 | /* --- templates --- */ | ||||
324 | /* struct _objc_selector { | ||||
325 | SEL sel_id; | ||||
326 | char *sel_type; | ||||
327 | }; */ | ||||
328 | |||||
329 | static void | ||||
330 | build_selector_template (void) | ||||
331 | { | ||||
332 | tree decls, *chain = NULLnullptr; | ||||
333 | |||||
334 | objc_selector_templateobjc_global_trees[OCTI_SEL_TEMPL] = objc_start_struct (get_identifier (UTAG_SELECTOR)(__builtin_constant_p ("_objc_selector") ? get_identifier_with_length (("_objc_selector"), strlen ("_objc_selector")) : get_identifier ("_objc_selector"))); | ||||
335 | |||||
336 | /* SEL sel_id; */ | ||||
337 | decls = add_field_decl (objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE], "sel_id", &chain); | ||||
338 | |||||
339 | /* char *sel_type; */ | ||||
340 | add_field_decl (string_type_nodec_global_trees[CTI_STRING_TYPE], "sel_type", &chain); | ||||
341 | |||||
342 | objc_finish_struct (objc_selector_templateobjc_global_trees[OCTI_SEL_TEMPL], decls); | ||||
343 | } | ||||
344 | |||||
345 | /* struct _objc_class { | ||||
346 | struct _objc_class *isa; | ||||
347 | struct _objc_class *super_class; | ||||
348 | char *name; | ||||
349 | long version; | ||||
350 | long info; | ||||
351 | long instance_size; | ||||
352 | struct _objc_ivar_list *ivars; | ||||
353 | struct _objc_method_list *methods; | ||||
354 | struct sarray *dtable; | ||||
355 | struct _objc_class *subclass_list; | ||||
356 | struct _objc_class *sibling_class; | ||||
357 | struct _objc_protocol_list *protocols; | ||||
358 | void *gc_object_type; | ||||
359 | }; */ | ||||
360 | |||||
361 | static void | ||||
362 | build_class_template (void) | ||||
363 | { | ||||
364 | tree ptype, decls, *chain = NULLnullptr; | ||||
365 | |||||
366 | objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL] = objc_start_struct (get_identifier (UTAG_CLASS)(__builtin_constant_p ("_objc_class") ? get_identifier_with_length (("_objc_class"), strlen ("_objc_class")) : get_identifier ( "_objc_class"))); | ||||
367 | |||||
368 | /* struct _objc_class *isa; */ | ||||
369 | decls = add_field_decl (build_pointer_type (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL]), | ||||
370 | "isa", &chain); | ||||
371 | |||||
372 | /* struct _objc_class *super_class; */ | ||||
373 | add_field_decl (build_pointer_type (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL]), | ||||
374 | "super_class", &chain); | ||||
375 | |||||
376 | /* char *name; */ | ||||
377 | add_field_decl (string_type_nodec_global_trees[CTI_STRING_TYPE], "name", &chain); | ||||
378 | |||||
379 | /* long version; */ | ||||
380 | add_field_decl (long_integer_type_nodeinteger_types[itk_long], "version", &chain); | ||||
381 | |||||
382 | /* long info; */ | ||||
383 | add_field_decl (long_integer_type_nodeinteger_types[itk_long], "info", &chain); | ||||
384 | |||||
385 | /* long instance_size; */ | ||||
386 | add_field_decl (long_integer_type_nodeinteger_types[itk_long], "instance_size", &chain); | ||||
387 | |||||
388 | /* struct _objc_ivar_list *ivars; */ | ||||
389 | add_field_decl (objc_ivar_list_ptrobjc_global_trees[OCTI_IVAR_LIST_TEMPL],"ivars", &chain); | ||||
390 | |||||
391 | /* struct _objc_method_list *methods; */ | ||||
392 | add_field_decl (objc_method_list_ptrobjc_global_trees[OCTI_METH_LIST_TEMPL], "methods", &chain); | ||||
393 | |||||
394 | /* struct sarray *dtable; */ | ||||
395 | ptype = build_pointer_type(xref_tag (RECORD_TYPE, | ||||
396 | get_identifier ("sarray")(__builtin_constant_p ("sarray") ? get_identifier_with_length (("sarray"), strlen ("sarray")) : get_identifier ("sarray")))); | ||||
397 | add_field_decl (ptype, "dtable", &chain); | ||||
398 | |||||
399 | /* struct objc_class *subclass_list; */ | ||||
400 | ptype = build_pointer_type (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL]); | ||||
401 | add_field_decl (ptype, "subclass_list", &chain); | ||||
402 | |||||
403 | /* struct objc_class *sibling_class; */ | ||||
404 | ptype = build_pointer_type (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL]); | ||||
405 | add_field_decl (ptype, "sibling_class", &chain); | ||||
406 | |||||
407 | /* struct _objc_protocol **protocol_list; */ | ||||
408 | ptype = build_pointer_type (build_pointer_type | ||||
409 | (xref_tag (RECORD_TYPE, | ||||
410 | get_identifier (UTAG_PROTOCOL)(__builtin_constant_p ("_objc_protocol") ? get_identifier_with_length (("_objc_protocol"), strlen ("_objc_protocol")) : get_identifier ("_objc_protocol"))))); | ||||
411 | add_field_decl (ptype, "protocol_list", &chain); | ||||
412 | |||||
413 | /* void *gc_object_type; */ | ||||
414 | add_field_decl (build_pointer_type (void_type_nodeglobal_trees[TI_VOID_TYPE]), | ||||
415 | "gc_object_type", &chain); | ||||
416 | |||||
417 | objc_finish_struct (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL], decls); | ||||
418 | } | ||||
419 | |||||
420 | /* struct _objc_category { | ||||
421 | char *category_name; | ||||
422 | char *class_name; | ||||
423 | struct _objc_method_list *instance_methods; | ||||
424 | struct _objc_method_list *class_methods; | ||||
425 | struct _objc_protocol_list *protocols; | ||||
426 | }; */ | ||||
427 | |||||
428 | static void | ||||
429 | build_category_template (void) | ||||
430 | { | ||||
431 | tree ptype, decls, *chain = NULLnullptr; | ||||
432 | |||||
433 | objc_category_templateobjc_global_trees[OCTI_CAT_TEMPL] = objc_start_struct (get_identifier (UTAG_CATEGORY)(__builtin_constant_p ("_objc_category") ? get_identifier_with_length (("_objc_category"), strlen ("_objc_category")) : get_identifier ("_objc_category"))); | ||||
434 | |||||
435 | /* char *category_name; */ | ||||
436 | decls = add_field_decl (string_type_nodec_global_trees[CTI_STRING_TYPE], "category_name", &chain); | ||||
437 | |||||
438 | /* char *class_name; */ | ||||
439 | add_field_decl (string_type_nodec_global_trees[CTI_STRING_TYPE], "class_name", &chain); | ||||
440 | |||||
441 | /* struct _objc_method_list *instance_methods; */ | ||||
442 | add_field_decl (objc_method_list_ptrobjc_global_trees[OCTI_METH_LIST_TEMPL], "instance_methods", &chain); | ||||
443 | |||||
444 | /* struct _objc_method_list *class_methods; */ | ||||
445 | add_field_decl (objc_method_list_ptrobjc_global_trees[OCTI_METH_LIST_TEMPL], "class_methods", &chain); | ||||
446 | |||||
447 | /* struct _objc_protocol **protocol_list; */ | ||||
448 | ptype = build_pointer_type (build_pointer_type (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL])); | ||||
449 | add_field_decl (ptype, "protocol_list", &chain); | ||||
450 | |||||
451 | objc_finish_struct (objc_category_templateobjc_global_trees[OCTI_CAT_TEMPL], decls); | ||||
452 | } | ||||
453 | |||||
454 | /* struct _objc_protocol { | ||||
455 | struct _objc_class *isa; | ||||
456 | char *protocol_name; | ||||
457 | struct _objc_protocol **protocol_list; | ||||
458 | struct _objc__method_prototype_list *instance_methods; | ||||
459 | struct _objc__method_prototype_list *class_methods; | ||||
460 | }; */ | ||||
461 | |||||
462 | static void | ||||
463 | build_protocol_template (void) | ||||
464 | { | ||||
465 | tree ptype, decls, *chain = NULLnullptr; | ||||
466 | |||||
467 | objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL] = objc_start_struct (get_identifier (UTAG_PROTOCOL)(__builtin_constant_p ("_objc_protocol") ? get_identifier_with_length (("_objc_protocol"), strlen ("_objc_protocol")) : get_identifier ("_objc_protocol"))); | ||||
468 | |||||
469 | /* struct _objc_class *isa; */ | ||||
470 | ptype = build_pointer_type (xref_tag (RECORD_TYPE, | ||||
471 | get_identifier (UTAG_CLASS)(__builtin_constant_p ("_objc_class") ? get_identifier_with_length (("_objc_class"), strlen ("_objc_class")) : get_identifier ( "_objc_class")))); | ||||
472 | decls = add_field_decl (ptype, "isa", &chain); | ||||
473 | |||||
474 | /* char *protocol_name; */ | ||||
475 | add_field_decl (string_type_nodec_global_trees[CTI_STRING_TYPE], "protocol_name", &chain); | ||||
476 | |||||
477 | /* struct _objc_protocol **protocol_list; */ | ||||
478 | ptype = build_pointer_type (build_pointer_type (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL])); | ||||
479 | add_field_decl (ptype, "protocol_list", &chain); | ||||
480 | |||||
481 | /* struct _objc__method_prototype_list *instance_methods; */ | ||||
482 | add_field_decl (objc_method_proto_list_ptrobjc_global_trees[OCTI_METH_PROTO_LIST_TEMPL], "instance_methods", &chain); | ||||
483 | |||||
484 | /* struct _objc__method_prototype_list *class_methods; */ | ||||
485 | add_field_decl (objc_method_proto_list_ptrobjc_global_trees[OCTI_METH_PROTO_LIST_TEMPL], "class_methods", &chain); | ||||
486 | |||||
487 | objc_finish_struct (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL], decls); | ||||
488 | } | ||||
489 | |||||
490 | /* --- names, decls + identifiers --- */ | ||||
491 | |||||
492 | static void | ||||
493 | build_selector_table_decl (void) | ||||
494 | { | ||||
495 | tree temp; | ||||
496 | |||||
497 | build_selector_template (); | ||||
498 | temp = build_array_type (objc_selector_templateobjc_global_trees[OCTI_SEL_TEMPL], NULL_TREE(tree) nullptr); | ||||
499 | |||||
500 | UOBJC_SELECTOR_TABLE_declobjc_global_trees[OCTI_SEL_TABLE_DECL] = start_var_decl (temp, "_OBJC_SELECTOR_TABLE"); | ||||
501 | /* Squash `defined but not used' warning check_global_declaration. */ | ||||
502 | TREE_USED (UOBJC_SELECTOR_TABLE_decl)((objc_global_trees[OCTI_SEL_TABLE_DECL])->base.used_flag) = 1; | ||||
503 | OBJCMETA (UOBJC_SELECTOR_TABLE_decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((objc_global_trees[OCTI_SEL_TABLE_DECL ]), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 503, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
504 | } | ||||
505 | |||||
506 | |||||
507 | static tree | ||||
508 | gnu_runtime_abi_01_super_superclassfield_id (void) | ||||
509 | { | ||||
510 | if (!super_superclassfield_idobjc_global_trees[OCTI_SUPER_SUPERFIELD_ID]) | ||||
511 | super_superclassfield_idobjc_global_trees[OCTI_SUPER_SUPERFIELD_ID] = get_identifier ("super_class")(__builtin_constant_p ("super_class") ? get_identifier_with_length (("super_class"), strlen ("super_class")) : get_identifier ( "super_class")); | ||||
512 | return super_superclassfield_idobjc_global_trees[OCTI_SUPER_SUPERFIELD_ID]; | ||||
513 | } | ||||
514 | |||||
515 | |||||
516 | static tree | ||||
517 | gnu_runtime_abi_01_class_decl (tree klass) | ||||
518 | { | ||||
519 | tree decl; | ||||
520 | char buf[BUFSIZE1024]; | ||||
521 | snprintf (buf, BUFSIZE1024, "_OBJC_Class_%s", | ||||
522 | IDENTIFIER_POINTER (CLASS_NAME (klass))((const char *) (tree_check (((((tree_class_check ((klass), ( tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 522, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 522, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
523 | decl = start_var_decl (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL], buf); | ||||
524 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 524, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
525 | return decl; | ||||
526 | } | ||||
527 | |||||
528 | static tree | ||||
529 | gnu_runtime_abi_01_metaclass_decl (tree klass) | ||||
530 | { | ||||
531 | tree decl; | ||||
532 | char buf[BUFSIZE1024]; | ||||
533 | snprintf (buf, BUFSIZE1024, "_OBJC_MetaClass_%s", | ||||
534 | IDENTIFIER_POINTER (CLASS_NAME (klass))((const char *) (tree_check (((((tree_class_check ((klass), ( tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 534, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 534, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
535 | decl = start_var_decl (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL], buf); | ||||
536 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 536, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
537 | return decl; | ||||
538 | } | ||||
539 | |||||
540 | static tree | ||||
541 | gnu_runtime_abi_01_category_decl (tree klass) | ||||
542 | { | ||||
543 | tree decl; | ||||
544 | char buf[BUFSIZE1024]; | ||||
545 | snprintf (buf, BUFSIZE1024, "_OBJC_Category_%s_on_%s", | ||||
546 | IDENTIFIER_POINTER (CLASS_SUPER_NAME (klass))((const char *) (tree_check (((((tree_class_check ((klass), ( tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 546, __FUNCTION__))->type_common.context))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 546, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ), | ||||
547 | IDENTIFIER_POINTER (CLASS_NAME (klass))((const char *) (tree_check (((((tree_class_check ((klass), ( tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 547, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 547, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
548 | decl = start_var_decl (objc_category_templateobjc_global_trees[OCTI_CAT_TEMPL], buf); | ||||
549 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 549, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
550 | return decl; | ||||
551 | } | ||||
552 | |||||
553 | static tree | ||||
554 | gnu_runtime_abi_01_protocol_decl (tree p) | ||||
555 | { | ||||
556 | tree decl; | ||||
557 | char buf[BUFSIZE1024]; | ||||
558 | |||||
559 | /* static struct _objc_protocol _OBJC_Protocol_<mumble>; */ | ||||
560 | snprintf (buf, BUFSIZE1024, "_OBJC_Protocol_%s", | ||||
561 | IDENTIFIER_POINTER (PROTOCOL_NAME (p))((const char *) (tree_check (((((tree_class_check ((p), (tcc_type ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 561, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 561, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
562 | decl = start_var_decl (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL], buf); | ||||
563 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 563, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
564 | return decl; | ||||
565 | } | ||||
566 | |||||
567 | static tree | ||||
568 | gnu_runtime_abi_01_string_decl (tree type, const char *name, | ||||
569 | string_section where ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
570 | { | ||||
571 | tree decl = start_var_decl (type, name); | ||||
572 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 572, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
573 | return decl; | ||||
574 | } | ||||
575 | |||||
576 | /* --- entry --- */ | ||||
577 | |||||
578 | static tree | ||||
579 | gnu_runtime_abi_01_get_class_reference (tree ident) | ||||
580 | { | ||||
581 | tree params; | ||||
582 | |||||
583 | add_class_reference (ident); | ||||
584 | |||||
585 | params = build_tree_list (NULL_TREE(tree) nullptr, my_build_string_pointer | ||||
586 | (IDENTIFIER_LENGTH (ident)((tree_check ((ident), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 586, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len ) + 1, | ||||
587 | IDENTIFIER_POINTER (ident)((const char *) (tree_check ((ident), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 587, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ))); | ||||
588 | |||||
589 | return build_function_call (input_location, objc_get_class_declobjc_global_trees[OCTI_GET_CLASS_DECL], params); | ||||
590 | } | ||||
591 | |||||
592 | /* Used by build_function_type_for_method. Append the types for | ||||
593 | receiver & _cmd at the start of a method argument list to ARGTYPES. | ||||
594 | CONTEXT is either METHOD_DEF or METHOD_REF, saying whether we are | ||||
595 | trying to define a method or call one. SUPERFLAG says this is for a | ||||
596 | send to super. METH may be NULL, in the case that there is no | ||||
597 | prototype. */ | ||||
598 | |||||
599 | static void | ||||
600 | gnu_runtime_abi_01_get_arg_type_list_base (vec<tree, va_gc> **argtypes, | ||||
601 | tree meth, int context, | ||||
602 | int superflag ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
603 | { | ||||
604 | tree receiver_type; | ||||
605 | |||||
606 | if (context == METHOD_DEF0 && TREE_CODE (meth)((enum tree_code) (meth)->base.code) == INSTANCE_METHOD_DECL) | ||||
607 | receiver_type = objc_instance_typeobjc_global_trees[OCTI_NST_TYPE]; | ||||
608 | else | ||||
609 | receiver_type = objc_object_typeobjc_global_trees[OCTI_ID_TYPE]; | ||||
610 | |||||
611 | vec_safe_push (*argtypes, receiver_type); | ||||
612 | /* Selector type - will eventually change to `int'. */ | ||||
613 | vec_safe_push (*argtypes, objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE]); | ||||
614 | } | ||||
615 | |||||
616 | /* Unused for GNU runtime. */ | ||||
617 | static tree | ||||
618 | gnu_runtime_abi_01_receiver_is_class_object (tree a ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
619 | { | ||||
620 | return NULL_TREE(tree) nullptr; | ||||
621 | } | ||||
622 | |||||
623 | /* sel_ref_chain is a list whose "value" fields will be instances of | ||||
624 | identifier_node that represent the selector. LOC is the location of | ||||
625 | the @selector. */ | ||||
626 | |||||
627 | static tree | ||||
628 | gnu_runtime_abi_01_build_typed_selector_reference (location_t loc, tree ident, | ||||
629 | tree prototype) | ||||
630 | { | ||||
631 | tree *chain = &sel_ref_chainobjc_global_trees[OCTI_SEL_REF_CHAIN]; | ||||
632 | tree expr; | ||||
633 | int index = 0; | ||||
634 | |||||
635 | while (*chain) | ||||
636 | { | ||||
637 | /* When we do a lookup for @selector () we have no idea of the | ||||
638 | prototype - so match the first we find. */ | ||||
639 | if (TREE_VALUE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 639, __FUNCTION__, (TREE_LIST)))->list.value) == ident | ||||
640 | && (!prototype || TREE_PURPOSE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 640, __FUNCTION__, (TREE_LIST)))->list.purpose) == prototype)) | ||||
641 | goto return_at_index; | ||||
642 | |||||
643 | index++; | ||||
644 | chain = &TREE_CHAIN (*chain)((contains_struct_check ((*chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 644, __FUNCTION__))->common.chain); | ||||
645 | } | ||||
646 | |||||
647 | *chain = tree_cons (prototype, ident, NULL_TREE(tree) nullptr); | ||||
648 | |||||
649 | /* TODO: Use a vec and keep this in it to (a) avoid re-creating and | ||||
650 | (b) provide better diagnostics for the first time an undefined | ||||
651 | selector is used. */ | ||||
652 | return_at_index: | ||||
653 | expr = build_unary_op (loc, ADDR_EXPR, | ||||
654 | build_array_ref (loc, UOBJC_SELECTOR_TABLE_declobjc_global_trees[OCTI_SEL_TABLE_DECL], | ||||
655 | build_int_cst (NULL_TREE(tree) nullptr, index)), | ||||
656 | 1); | ||||
657 | return convert (objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE], expr); | ||||
658 | } | ||||
659 | |||||
660 | /* Build a tree expression to send OBJECT the operation SELECTOR, | ||||
661 | looking up the method on object LOOKUP_OBJECT (often same as OBJECT), | ||||
662 | assuming the method has prototype METHOD_PROTOTYPE. | ||||
663 | (That is an INSTANCE_METHOD_DECL or CLASS_METHOD_DECL.) | ||||
664 | LOC is the location of the expression to build. | ||||
665 | Use METHOD_PARAMS as list of args to pass to the method. | ||||
666 | If SUPER_FLAG is nonzero, we look up the superclass's method. */ | ||||
667 | |||||
668 | static tree | ||||
669 | build_objc_method_call (location_t loc, int super_flag, tree method_prototype, | ||||
670 | tree lookup_object, tree selector, | ||||
671 | tree method_params) | ||||
672 | { | ||||
673 | tree sender = (super_flag ? umsg_super_declobjc_global_trees[OCTI_UMSG_SUPER_DECL] | ||||
674 | : (flag_objc_direct_dispatchglobal_options.x_flag_objc_direct_dispatch ? umsg_fast_declobjc_global_trees[OCTI_UMSG_FAST_DECL] | ||||
675 | : umsg_declobjc_global_trees[OCTI_UMSG_DECL])); | ||||
676 | tree rcv_p = (super_flag
| ||||
677 | vec<tree, va_gc> *parms; | ||||
678 | vec<tree, va_gc> *tv; | ||||
679 | unsigned nparm = (method_params ? list_length (method_params) : 0); | ||||
680 | |||||
681 | /* If a prototype for the method to be called exists, then cast | ||||
682 | the sender's return type and arguments to match that of the method. | ||||
683 | Otherwise, leave sender as is. */ | ||||
684 | tree ret_type | ||||
685 | = (method_prototype | ||||
686 | ? TREE_VALUE (TREE_TYPE (method_prototype))((tree_check ((((contains_struct_check ((method_prototype), ( TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 686, __FUNCTION__))->typed.type)), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 686, __FUNCTION__, (TREE_LIST)))->list.value) | ||||
687 | : objc_object_typeobjc_global_trees[OCTI_ID_TYPE]); | ||||
688 | tree ftype | ||||
689 | = build_function_type_for_method (ret_type, method_prototype, | ||||
690 | METHOD_REF1, super_flag); | ||||
691 | tree sender_cast; | ||||
692 | tree method, t; | ||||
693 | |||||
694 | if (method_prototype
, 694, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_common.abstract_origin)) | ||||
695 | ftype = build_type_attribute_variant (ftype, | ||||
696 | METHOD_TYPE_ATTRIBUTES((tree_check2 ((method_prototype), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 697, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_common.abstract_origin) | ||||
697 | (method_prototype)((tree_check2 ((method_prototype), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 697, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_common.abstract_origin)); | ||||
698 | |||||
699 | sender_cast = build_pointer_type (ftype); | ||||
700 | |||||
701 | lookup_object = build_c_cast (loc, rcv_p, lookup_object); | ||||
702 | |||||
703 | /* Use SAVE_EXPR to avoid evaluating the receiver twice. */ | ||||
704 | lookup_object = save_expr (lookup_object); | ||||
705 | |||||
706 | /* Param list + 2 slots for object and selector. */ | ||||
707 | vec_alloc (parms, nparm + 2); | ||||
708 | vec_alloc (tv, 2); | ||||
709 | |||||
710 | /* First, call the lookup function to get a pointer to the method, | ||||
711 | then cast the pointer, then call it with the method arguments. */ | ||||
712 | tv->quick_push (lookup_object); | ||||
713 | tv->quick_push (selector); | ||||
714 | method = build_function_call_vec (loc, vNULL, sender, tv, NULLnullptr); | ||||
715 | vec_free (tv); | ||||
716 | |||||
717 | /* Pass the appropriate object to the method. */ | ||||
718 | parms->quick_push ((super_flag
| ||||
| |||||
719 | |||||
720 | /* Pass the selector to the method. */ | ||||
721 | parms->quick_push (selector); | ||||
722 | /* Now append the remainder of the parms. */ | ||||
723 | if (nparm) | ||||
724 | for (; method_params; method_params = TREE_CHAIN (method_params)((contains_struct_check ((method_params), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 724, __FUNCTION__))->common.chain)) | ||||
725 | parms->quick_push (TREE_VALUE (method_params)((tree_check ((method_params), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 725, __FUNCTION__, (TREE_LIST)))->list.value)); | ||||
726 | |||||
727 | /* Build an obj_type_ref, with the correct cast for the method call. */ | ||||
728 | t = build3 (OBJ_TYPE_REF, sender_cast, method, lookup_object, | ||||
729 | build_int_cst (TREE_TYPE (lookup_object)((contains_struct_check ((lookup_object), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 729, __FUNCTION__))->typed.type), 0)); | ||||
730 | t = build_function_call_vec (loc, vNULL, t, parms, NULLnullptr); | ||||
731 | vec_free (parms); | ||||
732 | return t; | ||||
733 | } | ||||
734 | |||||
735 | static tree | ||||
736 | gnu_runtime_abi_01_build_objc_method_call (location_t loc, | ||||
737 | tree method_prototype, | ||||
738 | tree receiver, | ||||
739 | tree rtype ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | ||||
740 | tree sel_name, | ||||
741 | tree method_params, | ||||
742 | int super ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
743 | { | ||||
744 | tree selector = | ||||
745 | gnu_runtime_abi_01_build_typed_selector_reference (loc, | ||||
746 | sel_name, | ||||
747 | method_prototype); | ||||
748 | |||||
749 | return build_objc_method_call (loc, super, method_prototype, receiver, | ||||
| |||||
750 | selector, method_params); | ||||
751 | } | ||||
752 | |||||
753 | static tree | ||||
754 | gnu_runtime_abi_01_get_protocol_reference (location_t loc, tree p) | ||||
755 | { | ||||
756 | tree expr, protocol_struct_type, *chain; | ||||
757 | if (!PROTOCOL_FORWARD_DECL (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 757, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 757, __FUNCTION__)))))) | ||||
758 | PROTOCOL_FORWARD_DECL (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 758, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 758, __FUNCTION__))))) = gnu_runtime_abi_01_protocol_decl (p); | ||||
759 | |||||
760 | expr = build_unary_op (loc, ADDR_EXPR, PROTOCOL_FORWARD_DECL (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 760, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 760, __FUNCTION__))))), 0); | ||||
761 | |||||
762 | /* ??? Ideally we'd build the reference with objc_protocol_type directly, | ||||
763 | if we have it, rather than converting it here. */ | ||||
764 | expr = convert (objc_protocol_typeobjc_global_trees[OCTI_PROTO_TYPE], expr); | ||||
765 | |||||
766 | /* The @protocol() expression is being compiled into a pointer to a | ||||
767 | statically allocated instance of the Protocol class. To become | ||||
768 | usable at runtime, the 'isa' pointer of the instance need to be | ||||
769 | fixed up at runtime by the runtime library, to point to the | ||||
770 | actual 'Protocol' class. */ | ||||
771 | |||||
772 | /* For the GNU runtime, put the static Protocol instance in the list | ||||
773 | of statically allocated instances, so that we make sure that its | ||||
774 | 'isa' pointer is fixed up at runtime by the GNU runtime library | ||||
775 | to point to the Protocol class (at runtime, when loading the | ||||
776 | module, the GNU runtime library loops on the statically allocated | ||||
777 | instances (as found in the defs field in objc_symtab) and fixups | ||||
778 | all the 'isa' pointers of those objects). */ | ||||
779 | |||||
780 | /* This type is a struct containing the fields of a Protocol | ||||
781 | object. (Cfr. objc_protocol_type instead is the type of a pointer | ||||
782 | to such a struct). */ | ||||
783 | protocol_struct_type = xref_tag (RECORD_TYPE, | ||||
784 | get_identifier (PROTOCOL_OBJECT_CLASS_NAME)(__builtin_constant_p ("Protocol") ? get_identifier_with_length (("Protocol"), strlen ("Protocol")) : get_identifier ("Protocol" ))); | ||||
785 | |||||
786 | /* Look for the list of Protocol statically allocated instances | ||||
787 | to fixup at runtime. Create a new list to hold Protocol | ||||
788 | statically allocated instances, if the list is not found. At | ||||
789 | present there is only another list, holding NSConstantString | ||||
790 | static instances to be fixed up at runtime. */ | ||||
791 | |||||
792 | for (chain = &objc_static_instancesobjc_global_trees[OCTI_STATIC_NST]; | ||||
793 | *chain && TREE_VALUE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 793, __FUNCTION__, (TREE_LIST)))->list.value) != protocol_struct_type; | ||||
794 | chain = &TREE_CHAIN (*chain)((contains_struct_check ((*chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 794, __FUNCTION__))->common.chain)); | ||||
795 | |||||
796 | if (!*chain) | ||||
797 | { | ||||
798 | *chain = tree_cons (NULL_TREE(tree) nullptr, protocol_struct_type, NULL_TREE(tree) nullptr); | ||||
799 | add_objc_string (OBJC_TYPE_NAME (protocol_struct_type)((tree_class_check ((protocol_struct_type), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 799, __FUNCTION__))->type_common.name), | ||||
800 | class_names); | ||||
801 | } | ||||
802 | |||||
803 | /* Add this statically allocated instance to the Protocol list. */ | ||||
804 | TREE_PURPOSE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 804, __FUNCTION__, (TREE_LIST)))->list.purpose) = tree_cons (NULL_TREE(tree) nullptr, | ||||
805 | PROTOCOL_FORWARD_DECL (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 805, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 805, __FUNCTION__))))), | ||||
806 | TREE_PURPOSE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 806, __FUNCTION__, (TREE_LIST)))->list.purpose)); | ||||
807 | return expr; | ||||
808 | } | ||||
809 | |||||
810 | /* For ABI 8 an IVAR is just a fixed offset in the class struct. */ | ||||
811 | |||||
812 | static tree | ||||
813 | gnu_runtime_abi_01_build_ivar_ref (location_t loc ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | ||||
814 | tree base, tree id) | ||||
815 | { | ||||
816 | return objc_build_component_ref (base, id); | ||||
817 | } | ||||
818 | |||||
819 | /* We build super class references as we need them (but keep them once | ||||
820 | built for the sake of efficiency). */ | ||||
821 | |||||
822 | static tree | ||||
823 | gnu_runtime_abi_01_get_class_super_ref (location_t loc ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | ||||
824 | struct imp_entry *imp, bool inst_meth) | ||||
825 | { | ||||
826 | if (inst_meth) | ||||
827 | { | ||||
828 | if (!ucls_super_refobjc_global_trees[OCTI_UCLS_SUPER_REF]) | ||||
829 | ucls_super_refobjc_global_trees[OCTI_UCLS_SUPER_REF] = | ||||
830 | objc_build_component_ref (imp->class_decl, | ||||
831 | get_identifier ("super_class")(__builtin_constant_p ("super_class") ? get_identifier_with_length (("super_class"), strlen ("super_class")) : get_identifier ( "super_class"))); | ||||
832 | return ucls_super_refobjc_global_trees[OCTI_UCLS_SUPER_REF]; | ||||
833 | } | ||||
834 | else | ||||
835 | { | ||||
836 | if (!uucls_super_refobjc_global_trees[OCTI_UUCLS_SUPER_REF]) | ||||
837 | uucls_super_refobjc_global_trees[OCTI_UUCLS_SUPER_REF] = | ||||
838 | objc_build_component_ref (imp->meta_decl, | ||||
839 | get_identifier ("super_class")(__builtin_constant_p ("super_class") ? get_identifier_with_length (("super_class"), strlen ("super_class")) : get_identifier ( "super_class"))); | ||||
840 | return uucls_super_refobjc_global_trees[OCTI_UUCLS_SUPER_REF]; | ||||
841 | } | ||||
842 | } | ||||
843 | |||||
844 | static tree | ||||
845 | gnu_runtime_abi_01_get_category_super_ref (location_t loc ATTRIBUTE_UNUSED__attribute__ ((__unused__)), | ||||
846 | struct imp_entry *imp, bool inst_meth) | ||||
847 | { | ||||
848 | tree super_name = CLASS_SUPER_NAME (imp->imp_template)(((tree_class_check ((imp->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 848, __FUNCTION__))->type_common.context)); | ||||
849 | tree super_class; | ||||
850 | |||||
851 | add_class_reference (super_name); | ||||
852 | super_class = (inst_meth ? objc_get_class_declobjc_global_trees[OCTI_GET_CLASS_DECL] : objc_get_meta_class_declobjc_global_trees[OCTI_GET_MCLASS_DECL]); | ||||
853 | super_name = my_build_string_pointer (IDENTIFIER_LENGTH (super_name)((tree_check ((super_name), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 853, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len ) + 1, | ||||
854 | IDENTIFIER_POINTER (super_name)((const char *) (tree_check ((super_name), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 854, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
855 | /* super_class = get_{meta_}class("CLASS_SUPER_NAME"); */ | ||||
856 | return build_function_call (input_location, | ||||
857 | super_class, | ||||
858 | build_tree_list (NULL_TREE(tree) nullptr, super_name)); | ||||
859 | } | ||||
860 | |||||
861 | static bool | ||||
862 | gnu_runtime_abi_01_setup_const_string_class_decl (void) | ||||
863 | { | ||||
864 | /* Do nothing, and create no error. */ | ||||
865 | return true; | ||||
866 | } | ||||
867 | |||||
868 | /* Declare a static instance of CLASS_DECL initialized by CONSTRUCTOR. */ | ||||
869 | |||||
870 | static GTY(()) int num_static_inst; | ||||
871 | |||||
872 | static tree | ||||
873 | objc_add_static_instance (tree constructor, tree class_decl) | ||||
874 | { | ||||
875 | tree *chain, decl; | ||||
876 | char buf[BUFSIZE1024]; | ||||
877 | |||||
878 | /* Find the list of static instances for the CLASS_DECL. Create one if | ||||
879 | not found. */ | ||||
880 | for (chain = &objc_static_instancesobjc_global_trees[OCTI_STATIC_NST]; | ||||
881 | *chain && TREE_VALUE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 881, __FUNCTION__, (TREE_LIST)))->list.value) != class_decl; | ||||
882 | chain = &TREE_CHAIN (*chain)((contains_struct_check ((*chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 882, __FUNCTION__))->common.chain)); | ||||
883 | if (!*chain) | ||||
884 | { | ||||
885 | *chain = tree_cons (NULL_TREE(tree) nullptr, class_decl, NULL_TREE(tree) nullptr); | ||||
886 | add_objc_string (OBJC_TYPE_NAME (class_decl)((tree_class_check ((class_decl), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 886, __FUNCTION__))->type_common.name), class_names); | ||||
887 | } | ||||
888 | |||||
889 | snprintf (buf, BUFSIZE1024, "_OBJC_INSTANCE_%d", num_static_inst++); | ||||
890 | decl = build_decl (input_location, | ||||
891 | VAR_DECL, get_identifier (buf)(__builtin_constant_p (buf) ? get_identifier_with_length ((buf ), strlen (buf)) : get_identifier (buf)), class_decl); | ||||
892 | TREE_STATIC (decl)((decl)->base.static_flag) = 1; | ||||
893 | DECL_ARTIFICIAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 893, __FUNCTION__))->decl_common.artificial_flag) = 1; | ||||
894 | TREE_USED (decl)((decl)->base.used_flag) = 1; | ||||
895 | DECL_INITIAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 895, __FUNCTION__))->decl_common.initial) = constructor; | ||||
896 | DECL_CONTEXT (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 896, __FUNCTION__))->decl_minimal.context) = NULLnullptr; | ||||
897 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 897, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
898 | |||||
899 | /* We may be writing something else just now. | ||||
900 | Postpone till end of input. */ | ||||
901 | DECL_DEFER_OUTPUT (decl)((contains_struct_check ((decl), (TS_DECL_WITH_VIS), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 901, __FUNCTION__))->decl_with_vis.defer_output) = 1; | ||||
902 | lang_hooks.decls.pushdecl (decl); | ||||
903 | rest_of_decl_compilation (decl, 1, 0); | ||||
904 | |||||
905 | /* Add the DECL to the head of this CLASS' list. */ | ||||
906 | TREE_PURPOSE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 906, __FUNCTION__, (TREE_LIST)))->list.purpose) = tree_cons (NULL_TREE(tree) nullptr, decl, TREE_PURPOSE (*chain)((tree_check ((*chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 906, __FUNCTION__, (TREE_LIST)))->list.purpose)); | ||||
907 | |||||
908 | return decl; | ||||
909 | } | ||||
910 | |||||
911 | static tree | ||||
912 | gnu_runtime_abi_01_build_const_string_constructor (location_t loc, tree string, | ||||
913 | int length) | ||||
914 | { | ||||
915 | tree constructor, fields; | ||||
916 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
917 | |||||
918 | /* GNU: (NXConstantString *) & ((__builtin_ObjCString) { NULL, string, length }) */ | ||||
919 | fields = TYPE_FIELDS (internal_const_str_type)((tree_check3 ((objc_global_trees[OCTI_INTERNAL_CNST_STR_TYPE ]), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 919, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE )))->type_non_common.values); | ||||
920 | CONSTRUCTOR_APPEND_ELT (v, fields, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {fields, build_int_cst ((tree) nullptr , 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
921 | |||||
922 | fields = DECL_CHAIN (fields)(((contains_struct_check (((contains_struct_check ((fields), ( TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 922, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 922, __FUNCTION__))->common.chain)); | ||||
923 | CONSTRUCTOR_APPEND_ELT (v, fields, build_unary_op (loc,do { constructor_elt _ce___ = {fields, build_unary_op (loc, ADDR_EXPR , string, 1)}; vec_safe_push ((v), _ce___); } while (0) | ||||
924 | ADDR_EXPR, string, 1))do { constructor_elt _ce___ = {fields, build_unary_op (loc, ADDR_EXPR , string, 1)}; vec_safe_push ((v), _ce___); } while (0); | ||||
925 | |||||
926 | fields = DECL_CHAIN (fields)(((contains_struct_check (((contains_struct_check ((fields), ( TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 926, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 926, __FUNCTION__))->common.chain)); | ||||
927 | CONSTRUCTOR_APPEND_ELT (v, fields, build_int_cst (NULL_TREE, length))do { constructor_elt _ce___ = {fields, build_int_cst ((tree) nullptr , length)}; vec_safe_push ((v), _ce___); } while (0); | ||||
928 | constructor = objc_build_constructor (internal_const_str_typeobjc_global_trees[OCTI_INTERNAL_CNST_STR_TYPE], v); | ||||
929 | |||||
930 | constructor = objc_add_static_instance (constructor, constant_string_typeobjc_global_trees[OCTI_CNST_STR_TYPE]); | ||||
931 | return constructor; | ||||
932 | } | ||||
933 | |||||
934 | /* --- metadata - module initializer --- */ | ||||
935 | |||||
936 | /* The GNU runtime requires us to provide a static initializer function | ||||
937 | for each module: | ||||
938 | |||||
939 | static void __objc_gnu_init (void) { | ||||
940 | __objc_exec_class (&L_OBJC_MODULES); | ||||
941 | } */ | ||||
942 | |||||
943 | |||||
944 | static void | ||||
945 | build_module_initializer_routine (void) | ||||
946 | { | ||||
947 | tree body; | ||||
948 | |||||
949 | #ifdef OBJCPLUS | ||||
950 | push_lang_context (lang_name_c); /* extern "C" */ | ||||
951 | #endif | ||||
952 | |||||
953 | objc_push_parm (build_decl (input_location, | ||||
954 | PARM_DECL, NULL_TREE(tree) nullptr, void_type_nodeglobal_trees[TI_VOID_TYPE])); | ||||
955 | #ifdef OBJCPLUS | ||||
956 | objc_start_function (get_identifier (TAG_GNUINIT)(__builtin_constant_p ("__objc_gnu_init") ? get_identifier_with_length (("__objc_gnu_init"), strlen ("__objc_gnu_init")) : get_identifier ("__objc_gnu_init")), | ||||
957 | build_function_type_list (void_type_nodeglobal_trees[TI_VOID_TYPE], NULL_TREE(tree) nullptr), | ||||
958 | NULL_TREE(tree) nullptr, NULL_TREE(tree) nullptr); | ||||
959 | #else | ||||
960 | objc_start_function (get_identifier (TAG_GNUINIT)(__builtin_constant_p ("__objc_gnu_init") ? get_identifier_with_length (("__objc_gnu_init"), strlen ("__objc_gnu_init")) : get_identifier ("__objc_gnu_init")), | ||||
961 | build_function_type_list (void_type_nodeglobal_trees[TI_VOID_TYPE], NULL_TREE(tree) nullptr), | ||||
962 | NULL_TREE(tree) nullptr, objc_get_parm_info (0, NULL_TREE(tree) nullptr)); | ||||
963 | #endif | ||||
964 | body = c_begin_compound_stmt (true); | ||||
965 | add_stmt (build_function_call | ||||
966 | (input_location, | ||||
967 | execclass_declobjc_global_trees[OCTI_EXECCLASS_DECL], | ||||
968 | build_tree_list | ||||
969 | (NULL_TREE(tree) nullptr, | ||||
970 | build_unary_op (input_location, ADDR_EXPR, | ||||
971 | UOBJC_MODULES_declobjc_global_trees[OCTI_MODULES_DECL], 0)))); | ||||
972 | add_stmt (c_end_compound_stmt (input_location, body, true)); | ||||
973 | |||||
974 | TREE_PUBLIC (current_function_decl)((current_function_decl)->base.public_flag) = 0; | ||||
975 | |||||
976 | #ifndef OBJCPLUS | ||||
977 | /* For Objective-C++, we will need to call __objc_gnu_init | ||||
978 | from objc_generate_static_init_call() below. */ | ||||
979 | DECL_STATIC_CONSTRUCTOR (current_function_decl)((tree_check ((current_function_decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 979, __FUNCTION__, (FUNCTION_DECL)))->function_decl.static_ctor_flag ) = 1; | ||||
980 | #endif | ||||
981 | |||||
982 | GNU_INIT_declobjc_global_trees[OCTI_GNU_INIT_DECL] = current_function_decl; | ||||
983 | finish_function (); | ||||
984 | |||||
985 | #ifdef OBJCPLUS | ||||
986 | pop_lang_context (); | ||||
987 | #endif | ||||
988 | } | ||||
989 | |||||
990 | #ifdef OBJCPLUS | ||||
991 | /* Return 1 if the __objc_gnu_init function has been synthesized and needs | ||||
992 | to be called by the module initializer routine. */ | ||||
993 | |||||
994 | int | ||||
995 | objc_static_init_needed_p (void) | ||||
996 | { | ||||
997 | return (GNU_INIT_declobjc_global_trees[OCTI_GNU_INIT_DECL] != NULL_TREE(tree) nullptr); | ||||
998 | } | ||||
999 | |||||
1000 | /* Generate a call to the __objc_gnu_init initializer function. */ | ||||
1001 | |||||
1002 | tree | ||||
1003 | objc_generate_static_init_call (tree ctors ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
1004 | { | ||||
1005 | add_stmt (build_stmt (input_location, EXPR_STMT, | ||||
1006 | build_function_call (input_location, | ||||
1007 | GNU_INIT_declobjc_global_trees[OCTI_GNU_INIT_DECL], NULL_TREE(tree) nullptr))); | ||||
1008 | |||||
1009 | return ctors; | ||||
1010 | } | ||||
1011 | #endif /* OBJCPLUS */ | ||||
1012 | |||||
1013 | /* --- Output GNU Meta-data --- */ | ||||
1014 | |||||
1015 | static void | ||||
1016 | generate_classref_translation_entry (tree chain) | ||||
1017 | { | ||||
1018 | tree expr, decl, type; | ||||
1019 | |||||
1020 | decl = TREE_PURPOSE (chain)((tree_check ((chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1020, __FUNCTION__, (TREE_LIST)))->list.purpose); | ||||
1021 | type = TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1021, __FUNCTION__))->typed.type); | ||||
1022 | |||||
1023 | expr = add_objc_string (TREE_VALUE (chain)((tree_check ((chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1023, __FUNCTION__, (TREE_LIST)))->list.value), class_names); | ||||
1024 | expr = convert (type, expr); /* cast! */ | ||||
1025 | |||||
1026 | /* This is a class reference. It is re-written by the runtime, | ||||
1027 | but will be optimized away unless we force it. */ | ||||
1028 | DECL_PRESERVE_P (decl)(contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1028, __FUNCTION__))->decl_common.preserve_flag = 1; | ||||
1029 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1029, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
1030 | finish_var_decl (decl, expr); | ||||
1031 | return; | ||||
1032 | } | ||||
1033 | |||||
1034 | |||||
1035 | static void | ||||
1036 | handle_impent (struct imp_entry *impent) | ||||
1037 | { | ||||
1038 | char *string; | ||||
1039 | |||||
1040 | /* objc_implementation_context = impent->imp_context; | ||||
1041 | implementation_template = impent->imp_template;*/ | ||||
1042 | |||||
1043 | switch (TREE_CODE (impent->imp_context)((enum tree_code) (impent->imp_context)->base.code)) | ||||
1044 | { | ||||
1045 | case CLASS_IMPLEMENTATION_TYPE: | ||||
1046 | { | ||||
1047 | const char *const class_name = | ||||
1048 | IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context))((const char *) (tree_check (((((tree_class_check ((impent-> imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1048, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1048, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ); | ||||
1049 | |||||
1050 | string = (char *) alloca (strlen (class_name) + 30)__builtin_alloca(strlen (class_name) + 30); | ||||
1051 | |||||
1052 | sprintf (string, "__objc_class_name_%s", class_name); | ||||
1053 | break; | ||||
1054 | } | ||||
1055 | case CATEGORY_IMPLEMENTATION_TYPE: | ||||
1056 | { | ||||
1057 | const char *const class_name = | ||||
1058 | IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context))((const char *) (tree_check (((((tree_class_check ((impent-> imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1058, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1058, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ); | ||||
1059 | const char *const class_super_name = | ||||
1060 | IDENTIFIER_POINTER (CLASS_SUPER_NAME (impent->imp_context))((const char *) (tree_check (((((tree_class_check ((impent-> imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1060, __FUNCTION__))->type_common.context))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1060, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ); | ||||
1061 | |||||
1062 | string = (char *) alloca (strlen (class_name)__builtin_alloca(strlen (class_name) + strlen (class_super_name ) + 30) | ||||
1063 | + strlen (class_super_name) + 30)__builtin_alloca(strlen (class_name) + strlen (class_super_name ) + 30); | ||||
1064 | |||||
1065 | /* Do the same for categories. Even though no references to | ||||
1066 | these symbols are generated automatically by the compiler, | ||||
1067 | it gives you a handle to pull them into an archive by | ||||
1068 | hand. */ | ||||
1069 | sprintf (string, "*__objc_category_name_%s_%s", class_name, class_super_name); | ||||
1070 | break; | ||||
1071 | } | ||||
1072 | default: | ||||
1073 | return; | ||||
1074 | } | ||||
1075 | |||||
1076 | { | ||||
1077 | tree decl, init; | ||||
1078 | |||||
1079 | init = integer_zero_nodeglobal_trees[TI_INTEGER_ZERO]; | ||||
1080 | decl = build_decl (input_location, | ||||
1081 | VAR_DECL, get_identifier (string)(__builtin_constant_p (string) ? get_identifier_with_length ( (string), strlen (string)) : get_identifier (string)), TREE_TYPE (init)((contains_struct_check ((init), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1081, __FUNCTION__))->typed.type)); | ||||
1082 | TREE_PUBLIC (decl)((decl)->base.public_flag) = 1; | ||||
1083 | TREE_READONLY (decl)((non_type_check ((decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1083, __FUNCTION__))->base.readonly_flag) = 1; | ||||
1084 | TREE_USED (decl)((decl)->base.used_flag) = 1; | ||||
1085 | TREE_CONSTANT (decl)((non_type_check ((decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1085, __FUNCTION__))->base.constant_flag) = 1; | ||||
1086 | DECL_CONTEXT (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1086, __FUNCTION__))->decl_minimal.context) = NULL_TREE(tree) nullptr; | ||||
1087 | DECL_ARTIFICIAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1087, __FUNCTION__))->decl_common.artificial_flag) = 1; | ||||
1088 | TREE_STATIC (decl)((decl)->base.static_flag) = 1; | ||||
1089 | DECL_INITIAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1089, __FUNCTION__))->decl_common.initial) = error_mark_nodeglobal_trees[TI_ERROR_MARK]; /* A real initializer is coming... */ | ||||
1090 | /* We must force the reference. */ | ||||
1091 | DECL_PRESERVE_P (decl)(contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1091, __FUNCTION__))->decl_common.preserve_flag = 1; | ||||
1092 | |||||
1093 | finish_var_decl(decl, init) ; | ||||
1094 | } | ||||
1095 | } | ||||
1096 | |||||
1097 | tree | ||||
1098 | build_protocol_initializer (tree type, tree protocol_name, tree protocol_list, | ||||
1099 | tree inst_methods, tree class_methods) | ||||
1100 | { | ||||
1101 | tree expr, ttyp; | ||||
1102 | location_t loc; | ||||
1103 | vec<constructor_elt, va_gc> *inits = NULLnullptr; | ||||
1104 | |||||
1105 | /* TODO: pass the loc in or find it from args. */ | ||||
1106 | loc = input_location; | ||||
1107 | ttyp = build_pointer_type (xref_tag (RECORD_TYPE, | ||||
1108 | get_identifier (UTAG_CLASS)(__builtin_constant_p ("_objc_class") ? get_identifier_with_length (("_objc_class"), strlen ("_objc_class")) : get_identifier ( "_objc_class")))); | ||||
1109 | /* Filling the "isa" in with a version allows the runtime system to | ||||
1110 | detect this ... */ | ||||
1111 | expr = build_int_cst (ttyp, PROTOCOL_VERSION2); | ||||
1112 | |||||
1113 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((inits), _ce___); } while (0); | ||||
1114 | |||||
1115 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, protocol_name)do { constructor_elt _ce___ = {(tree) nullptr, protocol_name} ; vec_safe_push ((inits), _ce___); } while (0); | ||||
1116 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, protocol_list)do { constructor_elt _ce___ = {(tree) nullptr, protocol_list} ; vec_safe_push ((inits), _ce___); } while (0); | ||||
1117 | |||||
1118 | ttyp = objc_method_proto_list_ptrobjc_global_trees[OCTI_METH_PROTO_LIST_TEMPL]; | ||||
1119 | if (inst_methods) | ||||
1120 | expr = convert (ttyp, build_unary_op (loc, ADDR_EXPR, inst_methods, 0)); | ||||
1121 | else | ||||
1122 | expr = convert (ttyp, null_pointer_nodeglobal_trees[TI_NULL_POINTER]); | ||||
1123 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((inits), _ce___); } while (0); | ||||
1124 | |||||
1125 | if (class_methods) | ||||
1126 | expr = convert (ttyp, build_unary_op (loc, ADDR_EXPR, class_methods, 0)); | ||||
1127 | else | ||||
1128 | expr = convert (ttyp, null_pointer_nodeglobal_trees[TI_NULL_POINTER]); | ||||
1129 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((inits), _ce___); } while (0); | ||||
1130 | |||||
1131 | return objc_build_constructor (type, inits); | ||||
1132 | } | ||||
1133 | |||||
1134 | static tree | ||||
1135 | generate_protocol_list (tree i_or_p, tree klass_ctxt) | ||||
1136 | { | ||||
1137 | tree array_type, ptype, refs_decl, lproto, e, plist; | ||||
1138 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
1139 | char buf[BUFSIZE1024]; | ||||
1140 | int size = 0; | ||||
1141 | |||||
1142 | switch (TREE_CODE (i_or_p)((enum tree_code) (i_or_p)->base.code)) | ||||
1143 | { | ||||
1144 | case CLASS_INTERFACE_TYPE: | ||||
1145 | case CATEGORY_INTERFACE_TYPE: | ||||
1146 | plist = CLASS_PROTOCOL_LIST (i_or_p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((i_or_p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1146, __FUNCTION__))->type_non_common.lang_1)), (4), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1146, __FUNCTION__))))); | ||||
1147 | break; | ||||
1148 | case PROTOCOL_INTERFACE_TYPE: | ||||
1149 | plist = PROTOCOL_LIST (i_or_p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((i_or_p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1149, __FUNCTION__))->type_non_common.lang_1)), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1149, __FUNCTION__))))); | ||||
1150 | break; | ||||
1151 | default: | ||||
1152 | gcc_unreachable ()(fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1152, __FUNCTION__)); | ||||
1153 | } | ||||
1154 | |||||
1155 | /* Compute size. */ | ||||
1156 | for (lproto = plist; lproto; lproto = TREE_CHAIN (lproto)((contains_struct_check ((lproto), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1156, __FUNCTION__))->common.chain)) | ||||
1157 | if (TREE_CODE (TREE_VALUE (lproto))((enum tree_code) (((tree_check ((lproto), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1157, __FUNCTION__, (TREE_LIST)))->list.value))->base .code) == PROTOCOL_INTERFACE_TYPE | ||||
1158 | && PROTOCOL_FORWARD_DECL (TREE_VALUE (lproto))(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((((tree_check ((lproto), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1158, __FUNCTION__, (TREE_LIST)))->list.value)), (tcc_type ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1158, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1158, __FUNCTION__)))))) | ||||
1159 | size++; | ||||
1160 | |||||
1161 | /* Build initializer. */ | ||||
1162 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1163 | e = build_int_cst (build_pointer_type (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL]), size); | ||||
1164 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, e)do { constructor_elt _ce___ = {(tree) nullptr, e}; vec_safe_push ((v), _ce___); } while (0); | ||||
1165 | |||||
1166 | for (lproto = plist; lproto; lproto = TREE_CHAIN (lproto)((contains_struct_check ((lproto), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1166, __FUNCTION__))->common.chain)) | ||||
1167 | { | ||||
1168 | tree pval = TREE_VALUE (lproto)((tree_check ((lproto), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1168, __FUNCTION__, (TREE_LIST)))->list.value); | ||||
1169 | |||||
1170 | if (TREE_CODE (pval)((enum tree_code) (pval)->base.code) == PROTOCOL_INTERFACE_TYPE | ||||
1171 | && PROTOCOL_FORWARD_DECL (pval)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((pval), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1171, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1171, __FUNCTION__)))))) | ||||
1172 | { | ||||
1173 | tree fwref = PROTOCOL_FORWARD_DECL (pval)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((pval), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1173, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1173, __FUNCTION__))))); | ||||
1174 | location_t loc = DECL_SOURCE_LOCATION (fwref)((contains_struct_check ((fwref), (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1174, __FUNCTION__))->decl_minimal.locus) ; | ||||
1175 | e = build_unary_op (loc, ADDR_EXPR, fwref, 0); | ||||
1176 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, e)do { constructor_elt _ce___ = {(tree) nullptr, e}; vec_safe_push ((v), _ce___); } while (0); | ||||
1177 | } | ||||
1178 | } | ||||
1179 | |||||
1180 | /* static struct objc_protocol *refs[n]; */ | ||||
1181 | |||||
1182 | switch (TREE_CODE (i_or_p)((enum tree_code) (i_or_p)->base.code)) | ||||
1183 | { | ||||
1184 | case PROTOCOL_INTERFACE_TYPE: | ||||
1185 | snprintf (buf, BUFSIZE1024, "_OBJC_ProtocolRefs_%s", | ||||
1186 | IDENTIFIER_POINTER (PROTOCOL_NAME (i_or_p))((const char *) (tree_check (((((tree_class_check ((i_or_p), ( tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1186, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1186, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1187 | break; | ||||
1188 | case CLASS_INTERFACE_TYPE: | ||||
1189 | snprintf (buf, BUFSIZE1024, "_OBJC_ClassProtocols_%s", | ||||
1190 | IDENTIFIER_POINTER (CLASS_NAME (i_or_p))((const char *) (tree_check (((((tree_class_check ((i_or_p), ( tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1190, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1190, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1191 | break; | ||||
1192 | case CATEGORY_INTERFACE_TYPE: | ||||
1193 | snprintf (buf, BUFSIZE1024, "_OBJC_CategoryProtocols_%s_%s", | ||||
1194 | IDENTIFIER_POINTER (CLASS_NAME (klass_ctxt))((const char *) (tree_check (((((tree_class_check ((klass_ctxt ), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1194, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1194, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ), | ||||
1195 | IDENTIFIER_POINTER (CLASS_SUPER_NAME (klass_ctxt))((const char *) (tree_check (((((tree_class_check ((klass_ctxt ), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1195, __FUNCTION__))->type_common.context))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1195, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1196 | break; | ||||
1197 | default: | ||||
1198 | gcc_unreachable ()(fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1198, __FUNCTION__)); | ||||
1199 | } | ||||
1200 | |||||
1201 | ptype = build_pointer_type (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL]); | ||||
1202 | array_type = build_sized_array_type (ptype, size + 3); | ||||
1203 | refs_decl = start_var_decl (array_type, buf); | ||||
1204 | OBJCMETA (refs_decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((refs_decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1204, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
1205 | finish_var_decl (refs_decl, | ||||
1206 | objc_build_constructor (TREE_TYPE (refs_decl)((contains_struct_check ((refs_decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1206, __FUNCTION__))->typed.type), v)); | ||||
1207 | |||||
1208 | return refs_decl; | ||||
1209 | } | ||||
1210 | |||||
1211 | static tree | ||||
1212 | generate_v1_meth_descriptor_table (tree chain, tree protocol, const char *prefix) | ||||
1213 | { | ||||
1214 | tree method_list_template, initlist, decl; | ||||
1215 | int size; | ||||
1216 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
1217 | char buf[BUFSIZE1024]; | ||||
1218 | |||||
1219 | if (!chain || !prefix) | ||||
1220 | return NULL_TREE(tree) nullptr; | ||||
1221 | |||||
1222 | if (!objc_method_prototype_templateobjc_global_trees[OCTI_METH_PROTO_TEMPL]) | ||||
1223 | objc_method_prototype_templateobjc_global_trees[OCTI_METH_PROTO_TEMPL] = build_method_prototype_template (); | ||||
1224 | |||||
1225 | size = list_length (chain); | ||||
1226 | method_list_template = | ||||
1227 | build_method_prototype_list_template (objc_method_prototype_templateobjc_global_trees[OCTI_METH_PROTO_TEMPL], | ||||
1228 | size); | ||||
1229 | snprintf (buf, BUFSIZE1024, "%s_%s", prefix, | ||||
1230 | IDENTIFIER_POINTER (PROTOCOL_NAME (protocol))((const char *) (tree_check (((((tree_class_check ((protocol) , (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1230, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1230, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1231 | |||||
1232 | decl = start_var_decl (method_list_template, buf); | ||||
1233 | |||||
1234 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, size))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, size)}; vec_safe_push ((v), _ce___); } while ( 0); | ||||
1235 | initlist = | ||||
1236 | build_descriptor_table_initializer (objc_method_prototype_templateobjc_global_trees[OCTI_METH_PROTO_TEMPL], | ||||
1237 | chain); | ||||
1238 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, initlist)do { constructor_elt _ce___ = {(tree) nullptr, initlist}; vec_safe_push ((v), _ce___); } while (0); | ||||
1239 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1239, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
1240 | finish_var_decl (decl, objc_build_constructor (method_list_template, v)); | ||||
1241 | return decl; | ||||
1242 | } | ||||
1243 | |||||
1244 | /* For each protocol which was referenced either from a @protocol() | ||||
1245 | expression, or because a class/category implements it (then a | ||||
1246 | pointer to the protocol is stored in the struct describing the | ||||
1247 | class/category), we create a statically allocated instance of the | ||||
1248 | Protocol class. The code is written in such a way as to generate | ||||
1249 | as few Protocol objects as possible; we generate a unique Protocol | ||||
1250 | instance for each protocol, and we don't generate a Protocol | ||||
1251 | instance if the protocol is never referenced (either from a | ||||
1252 | @protocol() or from a class/category implementation). These | ||||
1253 | statically allocated objects can be referred to via the static | ||||
1254 | (that is, private to this module) symbols _OBJC_PROTOCOL_n. | ||||
1255 | |||||
1256 | The statically allocated Protocol objects that we generate here | ||||
1257 | need to be fixed up at runtime in order to be used: the 'isa' | ||||
1258 | pointer of the objects need to be set up to point to the 'Protocol' | ||||
1259 | class, as known at runtime. | ||||
1260 | |||||
1261 | The GNU runtime fixes up all protocols before user code from the module | ||||
1262 | is executed; it requires pointers to those symbols | ||||
1263 | to be put in the objc_symtab (which is then passed as argument to | ||||
1264 | the function __objc_exec_class() which the compiler sets up to be | ||||
1265 | executed automatically when the module is loaded); setup of those | ||||
1266 | Protocol objects happen in two ways in the GNU runtime: all | ||||
1267 | Protocol objects referred to by a class or category implementation | ||||
1268 | are fixed up when the class/category is loaded; all Protocol | ||||
1269 | objects referred to by a @protocol() expression are added by the | ||||
1270 | compiler to the list of statically allocated instances to fixup | ||||
1271 | (the same list holding the statically allocated constant string | ||||
1272 | objects). Because, as explained above, the compiler generates as | ||||
1273 | few Protocol objects as possible, some Protocol object might end up | ||||
1274 | being referenced multiple times when compiled with the GNU runtime, | ||||
1275 | and end up being fixed up multiple times at runtime initialization. | ||||
1276 | But that doesn't hurt, it's just a little inefficient. */ | ||||
1277 | |||||
1278 | static void | ||||
1279 | generate_protocols (void) | ||||
1280 | { | ||||
1281 | tree p, encoding; | ||||
1282 | tree decl; | ||||
1283 | tree initlist, protocol_name_expr, refs_decl, refs_expr; | ||||
1284 | |||||
1285 | /* If a protocol was directly referenced, pull in indirect references. */ | ||||
1286 | for (p = protocol_chainobjc_global_trees[OCTI_PROTO_CHAIN]; p; p = TREE_CHAIN (p)((contains_struct_check ((p), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1286, __FUNCTION__))->common.chain)) | ||||
1287 | if (PROTOCOL_FORWARD_DECL (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1287, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1287, __FUNCTION__))))) && PROTOCOL_LIST (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1287, __FUNCTION__))->type_non_common.lang_1)), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1287, __FUNCTION__)))))) | ||||
1288 | generate_protocol_references (PROTOCOL_LIST (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1288, __FUNCTION__))->type_non_common.lang_1)), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1288, __FUNCTION__)))))); | ||||
1289 | |||||
1290 | for (p = protocol_chainobjc_global_trees[OCTI_PROTO_CHAIN]; p; p = TREE_CHAIN (p)((contains_struct_check ((p), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1290, __FUNCTION__))->common.chain)) | ||||
1291 | { | ||||
1292 | tree nst_methods = PROTOCOL_NST_METHODS (p)(((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1292, __FUNCTION__))->type_non_common.minval)); | ||||
1293 | tree cls_methods = PROTOCOL_CLS_METHODS (p)(((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1293, __FUNCTION__))->type_non_common.maxval)); | ||||
1294 | |||||
1295 | /* If protocol wasn't referenced, don't generate any code. */ | ||||
1296 | decl = PROTOCOL_FORWARD_DECL (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1296, __FUNCTION__))->type_non_common.lang_1)), (1), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1296, __FUNCTION__))))); | ||||
1297 | |||||
1298 | if (!decl) | ||||
1299 | continue; | ||||
1300 | |||||
1301 | /* Make sure we link in the Protocol class. */ | ||||
1302 | add_class_reference (get_identifier (PROTOCOL_OBJECT_CLASS_NAME)(__builtin_constant_p ("Protocol") ? get_identifier_with_length (("Protocol"), strlen ("Protocol")) : get_identifier ("Protocol" ))); | ||||
1303 | |||||
1304 | while (nst_methods) | ||||
1305 | { | ||||
1306 | if (! METHOD_ENCODING (nst_methods)((tree_check2 ((nst_methods), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1306, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_minimal.context)) | ||||
1307 | { | ||||
1308 | encoding = encode_method_prototype (nst_methods); | ||||
1309 | METHOD_ENCODING (nst_methods)((tree_check2 ((nst_methods), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1309, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_minimal.context) = encoding; | ||||
1310 | } | ||||
1311 | nst_methods = DECL_CHAIN (nst_methods)(((contains_struct_check (((contains_struct_check ((nst_methods ), (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1311, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1311, __FUNCTION__))->common.chain)); | ||||
1312 | } | ||||
1313 | |||||
1314 | UOBJC_INSTANCE_METHODS_declobjc_global_trees[OCTI_NST_METH_DECL] = | ||||
1315 | generate_v1_meth_descriptor_table (PROTOCOL_NST_METHODS (p)(((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1315, __FUNCTION__))->type_non_common.minval)), p, | ||||
1316 | "_OBJC_PROTOCOL_INSTANCE_METHODS"); | ||||
1317 | |||||
1318 | while (cls_methods) | ||||
1319 | { | ||||
1320 | if (! METHOD_ENCODING (cls_methods)((tree_check2 ((cls_methods), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1320, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_minimal.context)) | ||||
1321 | { | ||||
1322 | encoding = encode_method_prototype (cls_methods); | ||||
1323 | METHOD_ENCODING (cls_methods)((tree_check2 ((cls_methods), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1323, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_minimal.context) = encoding; | ||||
1324 | } | ||||
1325 | |||||
1326 | cls_methods = DECL_CHAIN (cls_methods)(((contains_struct_check (((contains_struct_check ((cls_methods ), (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1326, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1326, __FUNCTION__))->common.chain)); | ||||
1327 | } | ||||
1328 | |||||
1329 | UOBJC_CLASS_METHODS_declobjc_global_trees[OCTI_CLS_METH_DECL] = | ||||
1330 | generate_v1_meth_descriptor_table (PROTOCOL_CLS_METHODS (p)(((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1330, __FUNCTION__))->type_non_common.maxval)), p, | ||||
1331 | "_OBJC_PROTOCOL_CLASS_METHODS"); | ||||
1332 | /* generate_method_descriptors (p);*/ | ||||
1333 | |||||
1334 | if (PROTOCOL_LIST (p)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1334, __FUNCTION__))->type_non_common.lang_1)), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1334, __FUNCTION__)))))) | ||||
1335 | refs_decl = generate_protocol_list (p, NULL_TREE(tree) nullptr); | ||||
1336 | else | ||||
1337 | refs_decl = 0; | ||||
1338 | |||||
1339 | /* static struct objc_protocol _OBJC_PROTOCOL_<mumble>; */ | ||||
1340 | protocol_name_expr = add_objc_string (PROTOCOL_NAME (p)(((tree_class_check ((p), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1340, __FUNCTION__))->type_common.name)), class_names); | ||||
1341 | |||||
1342 | if (refs_decl) | ||||
1343 | refs_expr = convert (build_pointer_type (build_pointer_type | ||||
1344 | (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL])), | ||||
1345 | build_unary_op (input_location, | ||||
1346 | ADDR_EXPR, refs_decl, 0)); | ||||
1347 | else | ||||
1348 | refs_expr = build_int_cst (NULL_TREE(tree) nullptr, 0); | ||||
1349 | |||||
1350 | /* UOBJC_INSTANCE_METHODS_decl/UOBJC_CLASS_METHODS_decl are set | ||||
1351 | by generate_method_descriptors, which is called above. */ | ||||
1352 | initlist = build_protocol_initializer (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1352, __FUNCTION__))->typed.type), | ||||
1353 | protocol_name_expr, refs_expr, | ||||
1354 | UOBJC_INSTANCE_METHODS_declobjc_global_trees[OCTI_NST_METH_DECL], | ||||
1355 | UOBJC_CLASS_METHODS_declobjc_global_trees[OCTI_CLS_METH_DECL]); | ||||
1356 | finish_var_decl (decl, initlist); | ||||
1357 | } | ||||
1358 | } | ||||
1359 | |||||
1360 | static tree | ||||
1361 | generate_dispatch_table (tree chain, const char *name) | ||||
1362 | { | ||||
1363 | tree decl, method_list_template, initlist; | ||||
1364 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
1365 | int size = list_length (chain); | ||||
1366 | |||||
1367 | if (!objc_method_templateobjc_global_trees[OCTI_METH_TEMPL]) | ||||
1368 | objc_method_templateobjc_global_trees[OCTI_METH_TEMPL] = build_method_template (); | ||||
1369 | |||||
1370 | method_list_template = build_method_list_template (objc_method_templateobjc_global_trees[OCTI_METH_TEMPL], | ||||
1371 | size); | ||||
1372 | initlist = build_dispatch_table_initializer (objc_method_templateobjc_global_trees[OCTI_METH_TEMPL], chain); | ||||
1373 | |||||
1374 | decl = start_var_decl (method_list_template, name); | ||||
1375 | |||||
1376 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, integer_zero_node)do { constructor_elt _ce___ = {(tree) nullptr, global_trees[TI_INTEGER_ZERO ]}; vec_safe_push ((v), _ce___); } while (0); | ||||
1377 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_int], size)}; vec_safe_push ((v), _ce___); } while (0) | ||||
1378 | build_int_cst (integer_type_node, size))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_int], size)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1379 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, initlist)do { constructor_elt _ce___ = {(tree) nullptr, initlist}; vec_safe_push ((v), _ce___); } while (0); | ||||
1380 | |||||
1381 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1381, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
1382 | finish_var_decl (decl, | ||||
1383 | objc_build_constructor (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1383, __FUNCTION__))->typed.type), v)); | ||||
1384 | |||||
1385 | return decl; | ||||
1386 | } | ||||
1387 | |||||
1388 | /* Init a category. */ | ||||
1389 | static tree | ||||
1390 | build_category_initializer (tree type, tree cat_name, tree class_name, | ||||
1391 | tree inst_methods, tree class_methods, | ||||
1392 | tree protocol_list) | ||||
1393 | { | ||||
1394 | tree expr, ltyp; | ||||
1395 | location_t loc; | ||||
1396 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
1397 | |||||
1398 | /* TODO: pass the loc in or find it from args. */ | ||||
1399 | /* TODO: pass the loc in or find it from args. */ | ||||
1400 | loc = UNKNOWN_LOCATION((location_t) 0); | ||||
1401 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, cat_name)do { constructor_elt _ce___ = {(tree) nullptr, cat_name}; vec_safe_push ((v), _ce___); } while (0); | ||||
1402 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, class_name)do { constructor_elt _ce___ = {(tree) nullptr, class_name}; vec_safe_push ((v), _ce___); } while (0); | ||||
1403 | |||||
1404 | ltyp = objc_method_list_ptrobjc_global_trees[OCTI_METH_LIST_TEMPL]; | ||||
1405 | if (inst_methods) | ||||
1406 | expr = convert (ltyp, build_unary_op (loc, ADDR_EXPR, inst_methods, 0)); | ||||
1407 | else | ||||
1408 | expr = convert (ltyp, null_pointer_nodeglobal_trees[TI_NULL_POINTER]); | ||||
1409 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1410 | |||||
1411 | if (class_methods) | ||||
1412 | expr = convert (ltyp, build_unary_op (loc, ADDR_EXPR, class_methods, 0)); | ||||
1413 | else | ||||
1414 | expr = convert (ltyp, null_pointer_nodeglobal_trees[TI_NULL_POINTER]); | ||||
1415 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1416 | |||||
1417 | /* protocol_list = */ | ||||
1418 | ltyp = build_pointer_type (build_pointer_type (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL])); | ||||
1419 | if (protocol_list) | ||||
1420 | expr = convert (ltyp, build_unary_op (loc, ADDR_EXPR, protocol_list, 0)); | ||||
1421 | else | ||||
1422 | expr = convert (ltyp, null_pointer_nodeglobal_trees[TI_NULL_POINTER]); | ||||
1423 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1424 | |||||
1425 | return objc_build_constructor (type, v); | ||||
1426 | } | ||||
1427 | |||||
1428 | /* static struct objc_category _OBJC_CATEGORY_<name> = { ... }; */ | ||||
1429 | |||||
1430 | static void | ||||
1431 | generate_category (struct imp_entry *impent) | ||||
1432 | { | ||||
1433 | tree initlist, cat_name_expr, class_name_expr; | ||||
1434 | tree protocol_decl, category, cat_decl; | ||||
1435 | tree inst_methods = NULL_TREE(tree) nullptr, class_methods = NULL_TREE(tree) nullptr; | ||||
1436 | tree cat = impent->imp_context; | ||||
1437 | char buf[BUFSIZE1024]; | ||||
1438 | |||||
1439 | cat_decl = impent->class_decl; | ||||
1440 | |||||
1441 | add_class_reference (CLASS_NAME (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1441, __FUNCTION__))->type_common.name))); | ||||
1442 | cat_name_expr = add_objc_string (CLASS_SUPER_NAME (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1442, __FUNCTION__))->type_common.context)), class_names); | ||||
1443 | |||||
1444 | class_name_expr = add_objc_string (CLASS_NAME (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1444, __FUNCTION__))->type_common.name)), class_names); | ||||
1445 | |||||
1446 | category = lookup_category (impent->imp_template, CLASS_SUPER_NAME (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1446, __FUNCTION__))->type_common.context))); | ||||
1447 | |||||
1448 | if (category && CLASS_PROTOCOL_LIST (category)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((category), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1448, __FUNCTION__))->type_non_common.lang_1)), (4), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1448, __FUNCTION__)))))) | ||||
1449 | { | ||||
1450 | generate_protocol_references (CLASS_PROTOCOL_LIST (category)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((category), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1450, __FUNCTION__))->type_non_common.lang_1)), (4), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1450, __FUNCTION__)))))); | ||||
1451 | protocol_decl = generate_protocol_list (category, cat); | ||||
1452 | } | ||||
1453 | else | ||||
1454 | protocol_decl = 0; | ||||
1455 | |||||
1456 | if (CLASS_NST_METHODS (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1456, __FUNCTION__))->type_non_common.minval))) | ||||
1457 | { | ||||
1458 | snprintf (buf, BUFSIZE1024, "_OBJC_CategoryInstanceMethods_%s_%s", | ||||
1459 | IDENTIFIER_POINTER (CLASS_NAME (cat))((const char *) (tree_check (((((tree_class_check ((cat), (tcc_type ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1459, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1459, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ), | ||||
1460 | IDENTIFIER_POINTER (CLASS_SUPER_NAME (cat))((const char *) (tree_check (((((tree_class_check ((cat), (tcc_type ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1460, __FUNCTION__))->type_common.context))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1460, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1461 | inst_methods = generate_dispatch_table (CLASS_NST_METHODS (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1461, __FUNCTION__))->type_non_common.minval)), buf); | ||||
1462 | } | ||||
1463 | |||||
1464 | if (CLASS_CLS_METHODS (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1464, __FUNCTION__))->type_non_common.maxval))) | ||||
1465 | { | ||||
1466 | snprintf (buf, BUFSIZE1024, "_OBJC_CategoryClassMethods_%s_%s", | ||||
1467 | IDENTIFIER_POINTER (CLASS_NAME (cat))((const char *) (tree_check (((((tree_class_check ((cat), (tcc_type ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1467, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1467, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ), | ||||
1468 | IDENTIFIER_POINTER (CLASS_SUPER_NAME (cat))((const char *) (tree_check (((((tree_class_check ((cat), (tcc_type ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1468, __FUNCTION__))->type_common.context))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1468, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1469 | class_methods = generate_dispatch_table (CLASS_CLS_METHODS (cat)(((tree_class_check ((cat), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1469, __FUNCTION__))->type_non_common.maxval)), buf); | ||||
1470 | } | ||||
1471 | |||||
1472 | initlist = build_category_initializer (TREE_TYPE (cat_decl)((contains_struct_check ((cat_decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1472, __FUNCTION__))->typed.type), | ||||
1473 | cat_name_expr, class_name_expr, | ||||
1474 | inst_methods, class_methods, | ||||
1475 | protocol_decl); | ||||
1476 | /* Finish and initialize the forward decl. */ | ||||
1477 | finish_var_decl (cat_decl, initlist); | ||||
1478 | impent->class_decl = cat_decl; | ||||
1479 | } | ||||
1480 | |||||
1481 | /* struct _objc_class { | ||||
1482 | struct objc_class *isa; | ||||
1483 | struct objc_class *super_class; | ||||
1484 | char *name; | ||||
1485 | long version; | ||||
1486 | long info; | ||||
1487 | long instance_size; | ||||
1488 | struct objc_ivar_list *ivars; | ||||
1489 | struct objc_method_list *methods; | ||||
1490 | struct sarray *dtable; | ||||
1491 | struct objc_class *subclass_list; | ||||
1492 | struct objc_class *sibling_class; | ||||
1493 | struct objc_protocol_list *protocols; | ||||
1494 | void *gc_object_type; | ||||
1495 | }; */ | ||||
1496 | |||||
1497 | static tree | ||||
1498 | build_shared_structure_initializer (tree type, tree isa, tree super, | ||||
1499 | tree name, tree size, int status, | ||||
1500 | tree dispatch_table, tree ivar_list, | ||||
1501 | tree protocol_list) | ||||
1502 | { | ||||
1503 | tree expr, ltyp; | ||||
1504 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
1505 | |||||
1506 | /* isa = */ | ||||
1507 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, isa)do { constructor_elt _ce___ = {(tree) nullptr, isa}; vec_safe_push ((v), _ce___); } while (0); | ||||
1508 | |||||
1509 | /* super_class = */ | ||||
1510 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, super)do { constructor_elt _ce___ = {(tree) nullptr, super}; vec_safe_push ((v), _ce___); } while (0); | ||||
1511 | |||||
1512 | /* name = */ | ||||
1513 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, default_conversion (name))do { constructor_elt _ce___ = {(tree) nullptr, default_conversion (name)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1514 | |||||
1515 | /* version = */ | ||||
1516 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_long], 0)}; vec_safe_push ((v), _ce___); } while (0) | ||||
1517 | build_int_cst (long_integer_type_node, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_long], 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1518 | |||||
1519 | /* info = */ | ||||
1520 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_long], status)}; vec_safe_push ((v), _ce___ ); } while (0) | ||||
1521 | build_int_cst (long_integer_type_node, status))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_long], status)}; vec_safe_push ((v), _ce___ ); } while (0); | ||||
1522 | |||||
1523 | /* instance_size = */ | ||||
1524 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, convert (integer_types [itk_long], size)}; vec_safe_push ((v), _ce___); } while (0) | ||||
1525 | convert (long_integer_type_node, size))do { constructor_elt _ce___ = {(tree) nullptr, convert (integer_types [itk_long], size)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1526 | |||||
1527 | /* objc_ivar_list = */ | ||||
1528 | if (!ivar_list) | ||||
1529 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( objc_global_trees[OCTI_IVAR_LIST_TEMPL], 0)}; vec_safe_push ( (v), _ce___); } while (0) | ||||
1530 | build_int_cst (objc_ivar_list_ptr, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( objc_global_trees[OCTI_IVAR_LIST_TEMPL], 0)}; vec_safe_push ( (v), _ce___); } while (0); | ||||
1531 | else | ||||
1532 | { | ||||
1533 | expr = convert (objc_ivar_list_ptrobjc_global_trees[OCTI_IVAR_LIST_TEMPL], | ||||
1534 | build_unary_op (input_location, ADDR_EXPR, | ||||
1535 | ivar_list, 0)); | ||||
1536 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1537 | } | ||||
1538 | |||||
1539 | /* objc_method_list = */ | ||||
1540 | if (!dispatch_table) | ||||
1541 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, convert (objc_global_trees [OCTI_METH_LIST_TEMPL], global_trees[TI_NULL_POINTER])}; vec_safe_push ((v), _ce___); } while (0) | ||||
1542 | convert (objc_method_list_ptr, null_pointer_node))do { constructor_elt _ce___ = {(tree) nullptr, convert (objc_global_trees [OCTI_METH_LIST_TEMPL], global_trees[TI_NULL_POINTER])}; vec_safe_push ((v), _ce___); } while (0); | ||||
1543 | else | ||||
1544 | { | ||||
1545 | expr = convert (objc_method_list_ptrobjc_global_trees[OCTI_METH_LIST_TEMPL], | ||||
1546 | build_unary_op (input_location, ADDR_EXPR, | ||||
1547 | dispatch_table, 0)); | ||||
1548 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1549 | } | ||||
1550 | |||||
1551 | /* dtable = */ | ||||
1552 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1553 | |||||
1554 | /* subclass_list = */ | ||||
1555 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1556 | |||||
1557 | /* sibling_class = */ | ||||
1558 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1559 | |||||
1560 | /* protocol_list = */ | ||||
1561 | ltyp = build_pointer_type (build_pointer_type (objc_protocol_templateobjc_global_trees[OCTI_PROTO_TEMPL])); | ||||
1562 | if (! protocol_list) | ||||
1563 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (ltyp, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( ltyp, 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1564 | else | ||||
1565 | { | ||||
1566 | expr = convert (ltyp, | ||||
1567 | build_unary_op (input_location, ADDR_EXPR, | ||||
1568 | protocol_list, 0)); | ||||
1569 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1570 | } | ||||
1571 | |||||
1572 | /* gc_object_type = NULL */ | ||||
1573 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1574 | |||||
1575 | return objc_build_constructor (type, v); | ||||
1576 | } | ||||
1577 | |||||
1578 | |||||
1579 | static tree | ||||
1580 | generate_ivars_list (tree chain, const char *name) | ||||
1581 | { | ||||
1582 | tree initlist, ivar_list_template, decl; | ||||
1583 | int size; | ||||
1584 | vec<constructor_elt, va_gc> *inits = NULLnullptr; | ||||
1585 | |||||
1586 | if (!chain) | ||||
1587 | return NULL_TREE(tree) nullptr; | ||||
1588 | |||||
1589 | if (!objc_ivar_templateobjc_global_trees[OCTI_IVAR_TEMPL]) | ||||
1590 | objc_ivar_templateobjc_global_trees[OCTI_IVAR_TEMPL] = build_ivar_template (); | ||||
1591 | |||||
1592 | size = ivar_list_length (chain); | ||||
1593 | |||||
1594 | generating_instance_variables = 1; | ||||
1595 | ivar_list_template = build_ivar_list_template (objc_ivar_templateobjc_global_trees[OCTI_IVAR_TEMPL], size); | ||||
1596 | initlist = build_ivar_list_initializer (objc_ivar_templateobjc_global_trees[OCTI_IVAR_TEMPL], chain); | ||||
1597 | generating_instance_variables = 0; | ||||
1598 | |||||
1599 | decl = start_var_decl (ivar_list_template, name); | ||||
1600 | |||||
1601 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, build_int_cst (NULL_TREE, size))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, size)}; vec_safe_push ((inits), _ce___); } while (0); | ||||
1602 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, initlist)do { constructor_elt _ce___ = {(tree) nullptr, initlist}; vec_safe_push ((inits), _ce___); } while (0); | ||||
1603 | |||||
1604 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1604, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
1605 | finish_var_decl (decl, | ||||
1606 | objc_build_constructor (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1606, __FUNCTION__))->typed.type), inits)); | ||||
1607 | |||||
1608 | return decl; | ||||
1609 | } | ||||
1610 | |||||
1611 | /* static struct objc_class _OBJC_METACLASS_Foo={ ... }; | ||||
1612 | static struct objc_class _OBJC_CLASS_Foo={ ... }; */ | ||||
1613 | |||||
1614 | static void | ||||
1615 | generate_class_structures (struct imp_entry *impent) | ||||
1616 | { | ||||
1617 | tree name_expr, super_expr, root_expr, class_decl, meta_decl; | ||||
1618 | tree my_root_id, my_super_id; | ||||
1619 | tree cast_type, initlist, protocol_decl; | ||||
1620 | tree inst_methods = NULL_TREE(tree) nullptr, class_methods = NULL_TREE(tree) nullptr; | ||||
1621 | tree chain, inst_ivars = NULL_TREE(tree) nullptr, class_ivars = NULL_TREE(tree) nullptr; | ||||
1622 | location_t loc; | ||||
1623 | char buf[BUFSIZE1024]; | ||||
1624 | int cls_flags = 0 ; | ||||
1625 | |||||
1626 | /* objc_implementation_context = impent->imp_context; | ||||
1627 | implementation_template = impent->imp_template;*/ | ||||
1628 | class_decl = impent->class_decl; | ||||
1629 | meta_decl = impent->meta_decl; | ||||
1630 | /* UOBJC_CLASS_decl = impent->class_decl; | ||||
1631 | UOBJC_METACLASS_decl = impent->meta_decl;*/ | ||||
1632 | |||||
1633 | loc = DECL_SOURCE_LOCATION (impent->class_decl)((contains_struct_check ((impent->class_decl), (TS_DECL_MINIMAL ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1633, __FUNCTION__))->decl_minimal.locus); | ||||
1634 | |||||
1635 | my_super_id = CLASS_SUPER_NAME (impent->imp_template)(((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1635, __FUNCTION__))->type_common.context)); | ||||
1636 | if (my_super_id) | ||||
1637 | { | ||||
1638 | add_class_reference (my_super_id); | ||||
1639 | |||||
1640 | /* Compute "my_root_id" - this is required for code generation. | ||||
1641 | the "isa" for all meta class structures points to the root of | ||||
1642 | the inheritance hierarchy (e.g. "__Object")... */ | ||||
1643 | my_root_id = my_super_id; | ||||
1644 | do | ||||
1645 | { | ||||
1646 | tree my_root_int = lookup_interface (my_root_id); | ||||
1647 | |||||
1648 | if (my_root_int && CLASS_SUPER_NAME (my_root_int)(((tree_class_check ((my_root_int), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1648, __FUNCTION__))->type_common.context))) | ||||
1649 | my_root_id = CLASS_SUPER_NAME (my_root_int)(((tree_class_check ((my_root_int), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1649, __FUNCTION__))->type_common.context)); | ||||
1650 | else | ||||
1651 | break; | ||||
1652 | } | ||||
1653 | while (1); | ||||
1654 | } | ||||
1655 | else | ||||
1656 | /* No super class. */ | ||||
1657 | my_root_id = CLASS_NAME (impent->imp_template)(((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1657, __FUNCTION__))->type_common.name)); | ||||
1658 | |||||
1659 | cast_type = build_pointer_type (objc_class_templateobjc_global_trees[OCTI_CLS_TEMPL]); | ||||
1660 | name_expr = add_objc_string (CLASS_NAME (impent->imp_template)(((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1660, __FUNCTION__))->type_common.name)), | ||||
1661 | class_names); | ||||
1662 | |||||
1663 | /* Install class `isa' and `super' pointers at runtime. */ | ||||
1664 | if (my_super_id) | ||||
1665 | super_expr = add_objc_string (my_super_id, class_names); | ||||
1666 | else | ||||
1667 | super_expr = null_pointer_nodeglobal_trees[TI_NULL_POINTER]; | ||||
1668 | |||||
1669 | super_expr = build_c_cast (loc, cast_type, super_expr); | ||||
1670 | |||||
1671 | root_expr = add_objc_string (my_root_id, class_names); | ||||
1672 | root_expr = build_c_cast (loc, cast_type, root_expr); | ||||
1673 | |||||
1674 | if (CLASS_PROTOCOL_LIST (impent->imp_template)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1674, __FUNCTION__))->type_non_common.lang_1)), (4), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1674, __FUNCTION__)))))) | ||||
1675 | { | ||||
1676 | generate_protocol_references (CLASS_PROTOCOL_LIST (impent->imp_template)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1676, __FUNCTION__))->type_non_common.lang_1)), (4), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1676, __FUNCTION__)))))); | ||||
1677 | protocol_decl = generate_protocol_list (impent->imp_template, | ||||
1678 | impent->imp_context); | ||||
1679 | } | ||||
1680 | else | ||||
1681 | protocol_decl = NULL_TREE(tree) nullptr; | ||||
1682 | |||||
1683 | if (CLASS_CLS_METHODS (impent->imp_context)(((tree_class_check ((impent->imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1683, __FUNCTION__))->type_non_common.maxval))) | ||||
1684 | { | ||||
1685 | snprintf (buf, BUFSIZE1024, "_OBJC_ClassMethods_%s", | ||||
1686 | IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context))((const char *) (tree_check (((((tree_class_check ((impent-> imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1686, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1686, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1687 | class_methods = generate_dispatch_table (CLASS_CLS_METHODS (impent->imp_context)(((tree_class_check ((impent->imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1687, __FUNCTION__))->type_non_common.maxval)), | ||||
1688 | buf); | ||||
1689 | } | ||||
1690 | |||||
1691 | if (CLASS_SUPER_NAME (impent->imp_template)(((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1691, __FUNCTION__))->type_common.context)) == NULL_TREE(tree) nullptr | ||||
1692 | && (chain = TYPE_FIELDS (objc_class_template)((tree_check3 ((objc_global_trees[OCTI_CLS_TEMPL]), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1692, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE )))->type_non_common.values))) | ||||
1693 | { | ||||
1694 | snprintf (buf, BUFSIZE1024, "_OBJC_ClassIvars_%s", | ||||
1695 | IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context))((const char *) (tree_check (((((tree_class_check ((impent-> imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1695, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1695, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1696 | class_ivars = generate_ivars_list (chain, buf); | ||||
1697 | } | ||||
1698 | |||||
1699 | /* static struct objc_class _OBJC_METACLASS_Foo = { ... }; */ | ||||
1700 | |||||
1701 | initlist = | ||||
1702 | build_shared_structure_initializer | ||||
1703 | (TREE_TYPE (meta_decl)((contains_struct_check ((meta_decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1703, __FUNCTION__))->typed.type), | ||||
1704 | root_expr, super_expr, name_expr, | ||||
1705 | convert (integer_type_nodeinteger_types[itk_int], | ||||
1706 | TYPE_SIZE_UNIT (objc_class_template)((tree_class_check ((objc_global_trees[OCTI_CLS_TEMPL]), (tcc_type ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1706, __FUNCTION__))->type_common.size_unit)), | ||||
1707 | CLS_META0x0002L, class_methods, class_ivars, | ||||
1708 | protocol_decl); | ||||
1709 | |||||
1710 | finish_var_decl (meta_decl, initlist); | ||||
1711 | impent->meta_decl = meta_decl; | ||||
1712 | |||||
1713 | /* static struct objc_class _OBJC_CLASS_Foo={ ... }; */ | ||||
1714 | if (CLASS_NST_METHODS (impent->imp_context)(((tree_class_check ((impent->imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1714, __FUNCTION__))->type_non_common.minval))) | ||||
1715 | { | ||||
1716 | snprintf (buf, BUFSIZE1024, "_OBJC_InstanceMethods_%s", | ||||
1717 | IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context))((const char *) (tree_check (((((tree_class_check ((impent-> imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1717, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1717, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1718 | inst_methods = generate_dispatch_table (CLASS_NST_METHODS (impent->imp_context)(((tree_class_check ((impent->imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1718, __FUNCTION__))->type_non_common.minval)), | ||||
1719 | buf); | ||||
1720 | } | ||||
1721 | |||||
1722 | if ((chain = CLASS_IVARS (impent->imp_template)(*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1722, __FUNCTION__))->type_non_common.lang_1)), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1722, __FUNCTION__))))))) | ||||
1723 | { | ||||
1724 | snprintf (buf, BUFSIZE1024, "_OBJC_InstanceIvars_%s", | ||||
1725 | IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context))((const char *) (tree_check (((((tree_class_check ((impent-> imp_context), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1725, __FUNCTION__))->type_common.name))), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1725, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
1726 | inst_ivars = generate_ivars_list (chain, buf); | ||||
1727 | } | ||||
1728 | |||||
1729 | initlist = | ||||
1730 | build_shared_structure_initializer | ||||
1731 | (TREE_TYPE (class_decl)((contains_struct_check ((class_decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1731, __FUNCTION__))->typed.type), | ||||
1732 | build_unary_op (loc, ADDR_EXPR, meta_decl, 0), | ||||
1733 | super_expr, name_expr, | ||||
1734 | convert (integer_type_nodeinteger_types[itk_int], | ||||
1735 | TYPE_SIZE_UNIT (CLASS_STATIC_TEMPLATE((tree_class_check (((*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1736, __FUNCTION__))->type_non_common.lang_1)), (2), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1736, __FUNCTION__)))))), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1736, __FUNCTION__))->type_common.size_unit) | ||||
1736 | (impent->imp_template))((tree_class_check (((*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((impent->imp_template), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1736, __FUNCTION__))->type_non_common.lang_1)), (2), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1736, __FUNCTION__)))))), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1736, __FUNCTION__))->type_common.size_unit)), | ||||
1737 | CLS_FACTORY0x0001L | cls_flags, inst_methods, inst_ivars, | ||||
1738 | protocol_decl); | ||||
1739 | |||||
1740 | finish_var_decl (class_decl, initlist); | ||||
1741 | impent->class_decl = class_decl; | ||||
1742 | } | ||||
1743 | |||||
1744 | /* --- Output GNU Metadata --- */ | ||||
1745 | |||||
1746 | /* TODO: Make this into an array of refs. */ | ||||
1747 | static void | ||||
1748 | handle_class_ref (tree chain) | ||||
1749 | { | ||||
1750 | const char *name = IDENTIFIER_POINTER (TREE_VALUE (chain))((const char *) (tree_check ((((tree_check ((chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1750, __FUNCTION__, (TREE_LIST)))->list.value)), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1750, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str ); | ||||
1751 | char *string = (char *) alloca (strlen (name) + 30)__builtin_alloca(strlen (name) + 30); | ||||
1752 | tree decl; | ||||
1753 | tree exp; | ||||
1754 | |||||
1755 | sprintf (string, "__objc_class_name_%s", name); | ||||
1756 | |||||
1757 | /* Make a decl for this name, so we can use its address in a tree. */ | ||||
1758 | decl = build_decl (input_location, | ||||
1759 | VAR_DECL, get_identifier (string)(__builtin_constant_p (string) ? get_identifier_with_length ( (string), strlen (string)) : get_identifier (string)), TREE_TYPE (integer_zero_node)((contains_struct_check ((global_trees[TI_INTEGER_ZERO]), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1759, __FUNCTION__))->typed.type)); | ||||
1760 | DECL_EXTERNAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1760, __FUNCTION__))->decl_common.decl_flag_1) = 1; | ||||
1761 | TREE_PUBLIC (decl)((decl)->base.public_flag) = 1; | ||||
1762 | DECL_CONTEXT (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1762, __FUNCTION__))->decl_minimal.context) = NULL_TREE(tree) nullptr; | ||||
1763 | finish_var_decl (decl, 0); | ||||
1764 | |||||
1765 | /* Make a decl for the address. */ | ||||
1766 | sprintf (string, "__objc_class_ref_%s", name); | ||||
1767 | exp = build1 (ADDR_EXPR, string_type_nodec_global_trees[CTI_STRING_TYPE], decl); | ||||
1768 | decl = build_decl (input_location, | ||||
1769 | VAR_DECL, get_identifier (string)(__builtin_constant_p (string) ? get_identifier_with_length ( (string), strlen (string)) : get_identifier (string)), string_type_nodec_global_trees[CTI_STRING_TYPE]); | ||||
1770 | TREE_STATIC (decl)((decl)->base.static_flag) = 1; | ||||
1771 | TREE_USED (decl)((decl)->base.used_flag) = 1; | ||||
1772 | DECL_READ_P (decl)((tree_check2 ((decl), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1772, __FUNCTION__, (VAR_DECL), (PARM_DECL)))->decl_common .decl_read_flag) = 1; | ||||
1773 | DECL_ARTIFICIAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1773, __FUNCTION__))->decl_common.artificial_flag) = 1; | ||||
1774 | DECL_INITIAL (decl)((contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1774, __FUNCTION__))->decl_common.initial) = error_mark_nodeglobal_trees[TI_ERROR_MARK]; | ||||
1775 | |||||
1776 | /* We must force the reference. */ | ||||
1777 | DECL_PRESERVE_P (decl)(contains_struct_check ((decl), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1777, __FUNCTION__))->decl_common.preserve_flag = 1; | ||||
1778 | |||||
1779 | DECL_CONTEXT (decl)((contains_struct_check ((decl), (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1779, __FUNCTION__))->decl_minimal.context) = NULL_TREE(tree) nullptr; | ||||
1780 | finish_var_decl (decl, exp); | ||||
1781 | } | ||||
1782 | |||||
1783 | static tree | ||||
1784 | get_proto_encoding (tree proto) | ||||
1785 | { | ||||
1786 | tree encoding; | ||||
1787 | if (proto) | ||||
1788 | { | ||||
1789 | if (! METHOD_ENCODING (proto)((tree_check2 ((proto), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1789, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_minimal.context)) | ||||
1790 | { | ||||
1791 | encoding = encode_method_prototype (proto); | ||||
1792 | METHOD_ENCODING (proto)((tree_check2 ((proto), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1792, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_minimal.context) = encoding; | ||||
1793 | } | ||||
1794 | else | ||||
1795 | encoding = METHOD_ENCODING (proto)((tree_check2 ((proto), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1795, __FUNCTION__, (INSTANCE_METHOD_DECL), (CLASS_METHOD_DECL )))->decl_minimal.context); | ||||
1796 | |||||
1797 | return add_objc_string (encoding, meth_var_types); | ||||
1798 | } | ||||
1799 | else | ||||
1800 | return build_int_cst (NULL_TREE(tree) nullptr, 0); | ||||
1801 | } | ||||
1802 | |||||
1803 | static void | ||||
1804 | build_gnu_selector_translation_table (void) | ||||
1805 | { | ||||
1806 | tree chain, expr; | ||||
1807 | vec<constructor_elt, va_gc> *inits = NULLnullptr; | ||||
1808 | vec<constructor_elt, va_gc> *v ; | ||||
1809 | |||||
1810 | /* Cause the selector table (previously forward-declared) | ||||
1811 | to be actually output. */ | ||||
1812 | |||||
1813 | for (chain = sel_ref_chainobjc_global_trees[OCTI_SEL_REF_CHAIN]; chain; chain = TREE_CHAIN (chain)((contains_struct_check ((chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1813, __FUNCTION__))->common.chain)) | ||||
1814 | { | ||||
1815 | tree encoding; | ||||
1816 | if (warn_selectorglobal_options.x_warn_selector) | ||||
1817 | { | ||||
1818 | /* TODO: improve on the location for the diagnostic. */ | ||||
1819 | location_t loc = input_location; | ||||
1820 | diagnose_missing_method (TREE_VALUE (chain)((tree_check ((chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1820, __FUNCTION__, (TREE_LIST)))->list.value), loc); | ||||
1821 | } | ||||
1822 | |||||
1823 | v = NULLnullptr; | ||||
1824 | expr = build_selector (TREE_VALUE (chain)((tree_check ((chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1824, __FUNCTION__, (TREE_LIST)))->list.value)); | ||||
1825 | encoding = get_proto_encoding (TREE_PURPOSE (chain)((tree_check ((chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1825, __FUNCTION__, (TREE_LIST)))->list.purpose)); | ||||
1826 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1827 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, encoding)do { constructor_elt _ce___ = {(tree) nullptr, encoding}; vec_safe_push ((v), _ce___); } while (0); | ||||
1828 | expr = objc_build_constructor (objc_selector_templateobjc_global_trees[OCTI_SEL_TEMPL], v); | ||||
1829 | |||||
1830 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((inits), _ce___); } while (0); | ||||
1831 | } /* each element in the chain */ | ||||
1832 | |||||
1833 | /* List terminator. */ | ||||
1834 | v = NULLnullptr; | ||||
1835 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, integer_zero_node)do { constructor_elt _ce___ = {(tree) nullptr, global_trees[TI_INTEGER_ZERO ]}; vec_safe_push ((v), _ce___); } while (0); | ||||
1836 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, integer_zero_node)do { constructor_elt _ce___ = {(tree) nullptr, global_trees[TI_INTEGER_ZERO ]}; vec_safe_push ((v), _ce___); } while (0); | ||||
1837 | expr = objc_build_constructor (objc_selector_templateobjc_global_trees[OCTI_SEL_TEMPL], v); | ||||
1838 | |||||
1839 | CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((inits), _ce___); } while (0); | ||||
1840 | expr = objc_build_constructor (TREE_TYPE (UOBJC_SELECTOR_TABLE_decl)((contains_struct_check ((objc_global_trees[OCTI_SEL_TABLE_DECL ]), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1840, __FUNCTION__))->typed.type), | ||||
1841 | inits); | ||||
1842 | finish_var_decl (UOBJC_SELECTOR_TABLE_declobjc_global_trees[OCTI_SEL_TABLE_DECL], expr); | ||||
1843 | } | ||||
1844 | |||||
1845 | /* Output references to all statically allocated objects. Return the DECL | ||||
1846 | for the array built. */ | ||||
1847 | |||||
1848 | static void | ||||
1849 | generate_static_references (void) | ||||
1850 | { | ||||
1851 | tree expr = NULL_TREE(tree) nullptr; | ||||
1852 | tree class_name, klass, decl; | ||||
1853 | tree cl_chain, in_chain, type | ||||
1854 | = build_array_type (build_pointer_type (void_type_nodeglobal_trees[TI_VOID_TYPE]), NULL_TREE(tree) nullptr); | ||||
1855 | int num_class; | ||||
1856 | char buf[BUFSIZE1024]; | ||||
1857 | vec<constructor_elt, va_gc> *decls = NULLnullptr; | ||||
1858 | |||||
1859 | for (cl_chain = objc_static_instancesobjc_global_trees[OCTI_STATIC_NST], num_class = 0; | ||||
1860 | cl_chain; cl_chain = TREE_CHAIN (cl_chain)((contains_struct_check ((cl_chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1860, __FUNCTION__))->common.chain), num_class++) | ||||
1861 | { | ||||
1862 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
1863 | |||||
1864 | for (in_chain = TREE_PURPOSE (cl_chain)((tree_check ((cl_chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1864, __FUNCTION__, (TREE_LIST)))->list.purpose); | ||||
1865 | in_chain; in_chain = TREE_CHAIN (in_chain)((contains_struct_check ((in_chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1865, __FUNCTION__))->common.chain)); | ||||
1866 | |||||
1867 | snprintf (buf, BUFSIZE1024, "_OBJC_STATIC_INSTANCES_%d", num_class); | ||||
1868 | decl = start_var_decl (type, buf); | ||||
1869 | |||||
1870 | /* Output {class_name, ...}. */ | ||||
1871 | klass = TREE_VALUE (cl_chain)((tree_check ((cl_chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1871, __FUNCTION__, (TREE_LIST)))->list.value); | ||||
1872 | class_name = get_objc_string_decl (OBJC_TYPE_NAME (klass)((tree_class_check ((klass), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1872, __FUNCTION__))->type_common.name), class_names); | ||||
1873 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_unary_op (input_location, ADDR_EXPR, class_name, 1)}; vec_safe_push ( (v), _ce___); } while (0) | ||||
1874 | build_unary_op (input_location,do { constructor_elt _ce___ = {(tree) nullptr, build_unary_op (input_location, ADDR_EXPR, class_name, 1)}; vec_safe_push ( (v), _ce___); } while (0) | ||||
1875 | ADDR_EXPR, class_name, 1))do { constructor_elt _ce___ = {(tree) nullptr, build_unary_op (input_location, ADDR_EXPR, class_name, 1)}; vec_safe_push ( (v), _ce___); } while (0); | ||||
1876 | |||||
1877 | /* Output {..., instance, ...}. */ | ||||
1878 | for (in_chain = TREE_PURPOSE (cl_chain)((tree_check ((cl_chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1878, __FUNCTION__, (TREE_LIST)))->list.purpose); | ||||
1879 | in_chain; in_chain = TREE_CHAIN (in_chain)((contains_struct_check ((in_chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1879, __FUNCTION__))->common.chain)) | ||||
1880 | { | ||||
1881 | expr = build_unary_op (input_location, | ||||
1882 | ADDR_EXPR, TREE_VALUE (in_chain)((tree_check ((in_chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1882, __FUNCTION__, (TREE_LIST)))->list.value), 1); | ||||
1883 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1884 | } | ||||
1885 | |||||
1886 | /* Output {..., NULL}. */ | ||||
1887 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
1888 | |||||
1889 | expr = objc_build_constructor (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1889, __FUNCTION__))->typed.type), v); | ||||
1890 | OBJCMETA (decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((decl), (TS_DECL_COMMON ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1890, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
1891 | finish_var_decl (decl, expr); | ||||
1892 | CONSTRUCTOR_APPEND_ELT (decls, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_unary_op (input_location, ADDR_EXPR, decl, 1)}; vec_safe_push ((decls ), _ce___); } while (0) | ||||
1893 | build_unary_op (input_location,do { constructor_elt _ce___ = {(tree) nullptr, build_unary_op (input_location, ADDR_EXPR, decl, 1)}; vec_safe_push ((decls ), _ce___); } while (0) | ||||
1894 | ADDR_EXPR, decl, 1))do { constructor_elt _ce___ = {(tree) nullptr, build_unary_op (input_location, ADDR_EXPR, decl, 1)}; vec_safe_push ((decls ), _ce___); } while (0); | ||||
1895 | } | ||||
1896 | |||||
1897 | CONSTRUCTOR_APPEND_ELT (decls, NULL_TREE, build_int_cst (NULL_TREE, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( (tree) nullptr, 0)}; vec_safe_push ((decls), _ce___); } while (0); | ||||
1898 | expr = objc_build_constructor (type, decls); | ||||
1899 | static_instances_declobjc_global_trees[OCTI_STATIC_NST_DECL] = start_var_decl (type, "_OBJC_STATIC_INSTANCES"); | ||||
1900 | OBJCMETA (static_instances_decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((objc_global_trees[OCTI_STATIC_NST_DECL ]), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1900, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
1901 | finish_var_decl (static_instances_declobjc_global_trees[OCTI_STATIC_NST_DECL], expr); | ||||
1902 | } | ||||
1903 | |||||
1904 | /* Create the initial value for the `defs' field of _objc_symtab. | ||||
1905 | This is a CONSTRUCTOR. */ | ||||
1906 | |||||
1907 | static tree | ||||
1908 | init_def_list (tree type) | ||||
1909 | { | ||||
1910 | tree expr; | ||||
1911 | struct imp_entry *impent; | ||||
1912 | location_t loc; | ||||
1913 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
1914 | |||||
1915 | if (imp_count) | ||||
1916 | for (impent = imp_list; impent; impent = impent->next) | ||||
1917 | { | ||||
1918 | if (TREE_CODE (impent->imp_context)((enum tree_code) (impent->imp_context)->base.code) == CLASS_IMPLEMENTATION_TYPE) | ||||
1919 | { | ||||
1920 | loc = DECL_SOURCE_LOCATION (impent->class_decl)((contains_struct_check ((impent->class_decl), (TS_DECL_MINIMAL ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1920, __FUNCTION__))->decl_minimal.locus); | ||||
1921 | expr = build_unary_op (loc, | ||||
1922 | ADDR_EXPR, impent->class_decl, 0); | ||||
1923 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1924 | } | ||||
1925 | } | ||||
1926 | |||||
1927 | if (cat_count) | ||||
1928 | for (impent = imp_list; impent; impent = impent->next) | ||||
1929 | { | ||||
1930 | if (TREE_CODE (impent->imp_context)((enum tree_code) (impent->imp_context)->base.code) == CATEGORY_IMPLEMENTATION_TYPE) | ||||
1931 | { | ||||
1932 | loc = DECL_SOURCE_LOCATION (impent->class_decl)((contains_struct_check ((impent->class_decl), (TS_DECL_MINIMAL ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 1932, __FUNCTION__))->decl_minimal.locus); | ||||
1933 | expr = build_unary_op (loc, | ||||
1934 | ADDR_EXPR, impent->class_decl, 0); | ||||
1935 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1936 | } | ||||
1937 | } | ||||
1938 | |||||
1939 | loc = UNKNOWN_LOCATION((location_t) 0); | ||||
1940 | /* statics = { ..., _OBJC_STATIC_INSTANCES, ... } */ | ||||
1941 | if (static_instances_declobjc_global_trees[OCTI_STATIC_NST_DECL]) | ||||
1942 | expr = build_unary_op (loc, ADDR_EXPR, static_instances_declobjc_global_trees[OCTI_STATIC_NST_DECL], 0); | ||||
1943 | else | ||||
1944 | expr = integer_zero_nodeglobal_trees[TI_INTEGER_ZERO]; | ||||
1945 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
1946 | |||||
1947 | return objc_build_constructor (type, v); | ||||
1948 | } | ||||
1949 | |||||
1950 | /* Take care of defining and initializing _OBJC_SYMBOLS. */ | ||||
1951 | |||||
1952 | /* Predefine the following data type: | ||||
1953 | |||||
1954 | struct _objc_symtab | ||||
1955 | { | ||||
1956 | long sel_ref_cnt; | ||||
1957 | SEL *refs; | ||||
1958 | short cls_def_cnt; | ||||
1959 | short cat_def_cnt; | ||||
1960 | void *defs[cls_def_cnt + cat_def_cnt]; | ||||
1961 | }; */ | ||||
1962 | |||||
1963 | static void | ||||
1964 | build_objc_symtab_template (void) | ||||
1965 | { | ||||
1966 | tree fields, array_type, *chain = NULLnullptr; | ||||
1967 | int index; | ||||
1968 | |||||
1969 | objc_symtab_templateobjc_global_trees[OCTI_SYMTAB_TEMPL] = objc_start_struct (get_identifier (UTAG_SYMTAB)(__builtin_constant_p ("_objc_symtab") ? get_identifier_with_length (("_objc_symtab"), strlen ("_objc_symtab")) : get_identifier ("_objc_symtab"))); | ||||
1970 | |||||
1971 | /* long sel_ref_cnt; */ | ||||
1972 | fields = add_field_decl (long_integer_type_nodeinteger_types[itk_long], "sel_ref_cnt", &chain); | ||||
1973 | |||||
1974 | /* SEL *refs; */ | ||||
1975 | add_field_decl (build_pointer_type (objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE]), "refs", &chain); | ||||
1976 | |||||
1977 | /* short cls_def_cnt; */ | ||||
1978 | add_field_decl (short_integer_type_nodeinteger_types[itk_short], "cls_def_cnt", &chain); | ||||
1979 | |||||
1980 | /* short cat_def_cnt; */ | ||||
1981 | add_field_decl (short_integer_type_nodeinteger_types[itk_short], "cat_def_cnt", &chain); | ||||
1982 | |||||
1983 | /* Note that padding will be added here on LP64. */ | ||||
1984 | |||||
1985 | /* void *defs[imp_count + cat_count (+ 1)]; */ | ||||
1986 | /* NB: The index is one less than the size of the array. */ | ||||
1987 | index = imp_count + cat_count; | ||||
1988 | array_type = build_sized_array_type (ptr_type_nodeglobal_trees[TI_PTR_TYPE], index + 1); | ||||
1989 | add_field_decl (array_type, "defs", &chain); | ||||
1990 | |||||
1991 | objc_finish_struct (objc_symtab_templateobjc_global_trees[OCTI_SYMTAB_TEMPL], fields); | ||||
1992 | } | ||||
1993 | /* Construct the initial value for all of _objc_symtab. */ | ||||
1994 | |||||
1995 | static tree | ||||
1996 | init_objc_symtab (tree type) | ||||
1997 | { | ||||
1998 | tree field, expr, ltyp; | ||||
1999 | location_t loc; | ||||
2000 | vec<constructor_elt, va_gc> *v = NULLnullptr; | ||||
2001 | |||||
2002 | loc = UNKNOWN_LOCATION((location_t) 0); | ||||
2003 | |||||
2004 | /* sel_ref_cnt = { ..., 5, ... } */ | ||||
2005 | |||||
2006 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_long], 0)}; vec_safe_push ((v), _ce___); } while (0) | ||||
2007 | build_int_cst (long_integer_type_node, 0))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_long], 0)}; vec_safe_push ((v), _ce___); } while (0); | ||||
2008 | |||||
2009 | /* refs = { ..., _OBJC_SELECTOR_TABLE, ... } */ | ||||
2010 | |||||
2011 | ltyp = build_pointer_type (objc_selector_typeobjc_global_trees[OCTI_SEL_TYPE]); | ||||
2012 | if (sel_ref_chainobjc_global_trees[OCTI_SEL_REF_CHAIN]) | ||||
2013 | expr = convert (ltyp, build_unary_op (loc, ADDR_EXPR, | ||||
2014 | UOBJC_SELECTOR_TABLE_declobjc_global_trees[OCTI_SEL_TABLE_DECL], 1)); | ||||
2015 | else | ||||
2016 | expr = convert (ltyp, null_pointer_nodeglobal_trees[TI_NULL_POINTER]); | ||||
2017 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr)do { constructor_elt _ce___ = {(tree) nullptr, expr}; vec_safe_push ((v), _ce___); } while (0); | ||||
2018 | |||||
2019 | /* cls_def_cnt = { ..., 5, ... } */ | ||||
2020 | |||||
2021 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_short], imp_count)}; vec_safe_push ((v), _ce___ ); } while (0) | ||||
2022 | build_int_cst (short_integer_type_node, imp_count))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_short], imp_count)}; vec_safe_push ((v), _ce___ ); } while (0); | ||||
2023 | |||||
2024 | /* cat_def_cnt = { ..., 5, ... } */ | ||||
2025 | |||||
2026 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_short], cat_count)}; vec_safe_push ((v), _ce___ ); } while (0) | ||||
2027 | build_int_cst (short_integer_type_node, cat_count))do { constructor_elt _ce___ = {(tree) nullptr, build_int_cst ( integer_types[itk_short], cat_count)}; vec_safe_push ((v), _ce___ ); } while (0); | ||||
2028 | |||||
2029 | /* cls_def = { ..., { &Foo, &Bar, ...}, ... } */ | ||||
2030 | |||||
2031 | field = TYPE_FIELDS (type)((tree_check3 ((type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2031, __FUNCTION__, (RECORD_TYPE), (UNION_TYPE), (QUAL_UNION_TYPE )))->type_non_common.values); | ||||
2032 | field = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (field))))(((contains_struct_check (((contains_struct_check (((((contains_struct_check (((contains_struct_check (((((contains_struct_check (((contains_struct_check (((((contains_struct_check (((contains_struct_check ((field) , (TS_DECL_MINIMAL), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))->common.chain))), (TS_DECL_MINIMAL) , "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))->common.chain))), (TS_DECL_MINIMAL) , "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))->common.chain))), (TS_DECL_MINIMAL) , "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2032, __FUNCTION__))->common.chain)); | ||||
2033 | |||||
2034 | CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init_def_list (TREE_TYPE (field)))do { constructor_elt _ce___ = {(tree) nullptr, init_def_list ( ((contains_struct_check ((field), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2034, __FUNCTION__))->typed.type))}; vec_safe_push ((v), _ce___); } while (0); | ||||
2035 | |||||
2036 | return objc_build_constructor (type, v); | ||||
2037 | } | ||||
2038 | |||||
2039 | /* Create the declaration of _OBJC_SYMBOLS, with type `struct _objc_symtab' | ||||
2040 | and initialized appropriately. */ | ||||
2041 | |||||
2042 | static void | ||||
2043 | generate_objc_symtab_decl (void) | ||||
2044 | { | ||||
2045 | build_objc_symtab_template (); | ||||
2046 | UOBJC_SYMBOLS_declobjc_global_trees[OCTI_SYMBOLS_DECL] = start_var_decl (objc_symtab_templateobjc_global_trees[OCTI_SYMTAB_TEMPL], "_OBJC_SYMBOLS"); | ||||
2047 | OBJCMETA (UOBJC_SYMBOLS_decl, objc_meta, meta_base)if (objc_meta) ((contains_struct_check ((objc_global_trees[OCTI_SYMBOLS_DECL ]), (TS_DECL_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2047, __FUNCTION__))->decl_common.attributes) = build_tree_list ((objc_meta), (meta_base));; | ||||
2048 | finish_var_decl (UOBJC_SYMBOLS_declobjc_global_trees[OCTI_SYMBOLS_DECL], | ||||
2049 | init_objc_symtab (TREE_TYPE (UOBJC_SYMBOLS_decl)((contains_struct_check ((objc_global_trees[OCTI_SYMBOLS_DECL ]), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2049, __FUNCTION__))->typed.type))); | ||||
2050 | } | ||||
2051 | |||||
2052 | static void | ||||
2053 | objc_generate_v1_gnu_metadata (void) | ||||
2054 | { | ||||
2055 | struct imp_entry *impent; | ||||
2056 | tree chain; | ||||
2057 | |||||
2058 | /* Process the static instances here because initialization of objc_symtab | ||||
2059 | depends on them. */ | ||||
2060 | if (objc_static_instancesobjc_global_trees[OCTI_STATIC_NST]) | ||||
2061 | generate_static_references (); | ||||
2062 | |||||
2063 | objc_implementation_contextobjc_global_trees[OCTI_IMPL_CTX] = | ||||
2064 | implementation_templateobjc_global_trees[OCTI_IMPL_TEMPL] = | ||||
2065 | UOBJC_CLASS_declobjc_global_trees[OCTI_CLS_DECL] = | ||||
2066 | UOBJC_METACLASS_declobjc_global_trees[OCTI_MCLS_DECL] = NULL_TREE(tree) nullptr; | ||||
2067 | |||||
2068 | for (impent = imp_list; impent; impent = impent->next) | ||||
2069 | { | ||||
2070 | /* If -gen-decls is present, Dump the @interface of each class. | ||||
2071 | TODO: Dump the classes in the order they were found, rather than in | ||||
2072 | reverse order as we are doing now. */ | ||||
2073 | if (flag_gen_declarationglobal_options.x_flag_gen_declaration) | ||||
2074 | dump_interface (gen_declaration_file, impent->imp_context); | ||||
2075 | |||||
2076 | /* all of the following reference the string pool... */ | ||||
2077 | if (TREE_CODE (impent->imp_context)((enum tree_code) (impent->imp_context)->base.code) == CLASS_IMPLEMENTATION_TYPE) | ||||
2078 | generate_class_structures (impent); | ||||
2079 | else | ||||
2080 | generate_category (impent); | ||||
2081 | } | ||||
2082 | |||||
2083 | /* If we are using an array of selectors, we must always | ||||
2084 | finish up the array decl even if no selectors were used. */ | ||||
2085 | build_gnu_selector_translation_table (); | ||||
2086 | |||||
2087 | if (protocol_chainobjc_global_trees[OCTI_PROTO_CHAIN]) | ||||
2088 | generate_protocols (); | ||||
2089 | |||||
2090 | /* Arrange for ObjC data structures to be initialized at run time. */ | ||||
2091 | /* FIXME: Have some more elegant way to determine if we need to | ||||
2092 | generate objc_symtab_decl or not, instead of checking these | ||||
2093 | global symbols. */ | ||||
2094 | if (imp_list || class_names_chainobjc_global_trees[OCTI_CLS_NAMES_CHAIN] | ||||
2095 | || meth_var_names_chainobjc_global_trees[OCTI_METH_VAR_NAMES_CHAIN] || meth_var_types_chainobjc_global_trees[OCTI_METH_VAR_TYPES_CHAIN] || sel_ref_chainobjc_global_trees[OCTI_SEL_REF_CHAIN] | ||||
2096 | || prop_names_attr_chainobjc_global_trees[OCTI_V1_PROP_NAME_ATTR_CHAIN]) | ||||
2097 | generate_objc_symtab_decl (); | ||||
2098 | |||||
2099 | if (imp_list || class_names_chainobjc_global_trees[OCTI_CLS_NAMES_CHAIN] || objc_static_instancesobjc_global_trees[OCTI_STATIC_NST] | ||||
2100 | || meth_var_names_chainobjc_global_trees[OCTI_METH_VAR_NAMES_CHAIN] || meth_var_types_chainobjc_global_trees[OCTI_METH_VAR_TYPES_CHAIN] || sel_ref_chainobjc_global_trees[OCTI_SEL_REF_CHAIN]) | ||||
2101 | { | ||||
2102 | /* Make sure that the meta-data are identified as being | ||||
2103 | GNU-runtime. */ | ||||
2104 | build_module_descriptor (OBJC_VERSION8, | ||||
2105 | build_tree_list (objc_meta, meta_base)); | ||||
2106 | build_module_initializer_routine (); | ||||
2107 | } | ||||
2108 | |||||
2109 | /* Dump the class references. This forces the appropriate classes | ||||
2110 | to be linked into the executable image, preserving unix archive | ||||
2111 | semantics. This can be removed when we move to a more dynamically | ||||
2112 | linked environment. */ | ||||
2113 | |||||
2114 | for (chain = cls_ref_chainobjc_global_trees[OCTI_CLS_REF_CHAIN]; chain; chain = TREE_CHAIN (chain)((contains_struct_check ((chain), (TS_COMMON), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2114, __FUNCTION__))->common.chain)) | ||||
2115 | { | ||||
2116 | handle_class_ref (chain); | ||||
2117 | if (TREE_PURPOSE (chain)((tree_check ((chain), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2117, __FUNCTION__, (TREE_LIST)))->list.purpose)) | ||||
2118 | generate_classref_translation_entry (chain); | ||||
2119 | } | ||||
2120 | |||||
2121 | for (impent = imp_list; impent; impent = impent->next) | ||||
2122 | handle_impent (impent); | ||||
2123 | |||||
2124 | generate_strings (); | ||||
2125 | } | ||||
2126 | |||||
2127 | /* --- exceptions --- */ | ||||
2128 | |||||
2129 | static GTY(()) tree objc_eh_personality_decl; | ||||
2130 | |||||
2131 | static tree | ||||
2132 | objc_eh_runtime_type (tree type) | ||||
2133 | { | ||||
2134 | tree ident, eh_id, decl, str; | ||||
2135 | |||||
2136 | if (type == error_mark_nodeglobal_trees[TI_ERROR_MARK] | ||||
2137 | || errorcount(global_dc)->diagnostic_count[(int) (DK_ERROR)] || sorrycount(global_dc)->diagnostic_count[(int) (DK_SORRY)]) | ||||
2138 | { | ||||
2139 | /* Use 'ErrorMarkNode' as class name when error_mark_node is found | ||||
2140 | to prevent an ICE. Note that we know that the compiler will | ||||
2141 | terminate with an error and this 'ErrorMarkNode' class name will | ||||
2142 | never be actually used. */ | ||||
2143 | ident = get_identifier ("ErrorMarkNode")(__builtin_constant_p ("ErrorMarkNode") ? get_identifier_with_length (("ErrorMarkNode"), strlen ("ErrorMarkNode")) : get_identifier ("ErrorMarkNode")); | ||||
2144 | goto make_err_class; | ||||
2145 | } | ||||
2146 | |||||
2147 | if (POINTER_TYPE_P (type)(((enum tree_code) (type)->base.code) == POINTER_TYPE || ( (enum tree_code) (type)->base.code) == REFERENCE_TYPE) && objc_is_object_id (TREE_TYPE (type))(((tree_class_check ((((contains_struct_check ((type), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2147, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2147, __FUNCTION__))->type_common.name) == objc_global_trees [OCTI_OBJ_ID])) | ||||
2148 | /* We don't want to identify 'id' for GNU. Instead, build a 0 | ||||
2149 | entry in the exceptions table. */ | ||||
2150 | return null_pointer_nodeglobal_trees[TI_NULL_POINTER]; | ||||
2151 | |||||
2152 | if (!POINTER_TYPE_P (type)(((enum tree_code) (type)->base.code) == POINTER_TYPE || ( (enum tree_code) (type)->base.code) == REFERENCE_TYPE) || !TYPED_OBJECT (TREE_TYPE (type))(((enum tree_code) (((contains_struct_check ((type), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))->typed.type))->base.code) == RECORD_TYPE && (((tree_class_check ((((contains_struct_check ((type ), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))->type_with_lang_specific.lang_specific ) && ((tree_class_check ((((contains_struct_check ((type ), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))->type_with_lang_specific.lang_specific )->objc_info) && (*((const_cast<tree *> (tree_vec_elt_check ((((tree_class_check ((((contains_struct_check ((type), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))->type_with_lang_specific.lang_specific )->objc_info), (0), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2152, __FUNCTION__))))))) | ||||
2153 | { | ||||
2154 | #ifdef OBJCPLUS | ||||
2155 | /* This routine is also called for c++ catch clauses; in which case, | ||||
2156 | we use the c++ typeinfo decl. */ | ||||
2157 | return build_eh_type_type (type); | ||||
2158 | #else | ||||
2159 | error ("non-objective-c type %qT cannot be caught", type); | ||||
2160 | ident = get_identifier ("ErrorMarkNode")(__builtin_constant_p ("ErrorMarkNode") ? get_identifier_with_length (("ErrorMarkNode"), strlen ("ErrorMarkNode")) : get_identifier ("ErrorMarkNode")); | ||||
2161 | goto make_err_class; | ||||
2162 | #endif | ||||
2163 | } | ||||
2164 | else | ||||
2165 | ident = OBJC_TYPE_NAME (TREE_TYPE (type))((tree_class_check ((((contains_struct_check ((type), (TS_TYPED ), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2165, __FUNCTION__))->typed.type)), (tcc_type), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2165, __FUNCTION__))->type_common.name); | ||||
2166 | |||||
2167 | make_err_class: | ||||
2168 | /* If this class was already referenced, then it will be output during | ||||
2169 | meta-data emission, so we don't need to do it here. */ | ||||
2170 | decl = get_objc_string_decl (ident, class_names); | ||||
2171 | eh_id = add_objc_string (ident, class_names); | ||||
2172 | if (!decl) | ||||
2173 | { | ||||
2174 | /* Not found ... so we need to build it - from the freshly-entered id. */ | ||||
2175 | decl = get_objc_string_decl (ident, class_names); | ||||
2176 | str = my_build_string (IDENTIFIER_LENGTH (ident)((tree_check ((ident), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2176, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.len ) + 1, | ||||
2177 | IDENTIFIER_POINTER (ident)((const char *) (tree_check ((ident), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2177, __FUNCTION__, (IDENTIFIER_NODE)))->identifier.id.str )); | ||||
2178 | /* We have to finalize this var here, because this might be called after | ||||
2179 | all the other metadata strings have been emitted. */ | ||||
2180 | finish_var_decl (decl, str); | ||||
2181 | } | ||||
2182 | return eh_id; | ||||
2183 | } | ||||
2184 | |||||
2185 | static tree | ||||
2186 | objc_eh_personality (void) | ||||
2187 | { | ||||
2188 | if (!objc_eh_personality_decl) | ||||
2189 | #ifndef OBJCPLUS | ||||
2190 | objc_eh_personality_decl = build_personality_function ("gnu_objc"); | ||||
2191 | #else | ||||
2192 | objc_eh_personality_decl = build_personality_function ("gxx"); | ||||
2193 | #endif | ||||
2194 | return objc_eh_personality_decl; | ||||
2195 | } | ||||
2196 | |||||
2197 | /* -- interfaces --- */ | ||||
2198 | |||||
2199 | static tree | ||||
2200 | build_throw_stmt (location_t loc, tree throw_expr, bool rethrown ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
2201 | { | ||||
2202 | tree t; | ||||
2203 | vec<tree, va_gc> *parms; | ||||
2204 | vec_alloc (parms, 1); | ||||
2205 | /* A throw is just a call to the runtime throw function with the | ||||
2206 | object as a parameter. */ | ||||
2207 | parms->quick_push (throw_expr); | ||||
2208 | t = build_function_call_vec (loc, vNULL, objc_exception_throw_declobjc_global_trees[OCTI_EXCEPTION_THROW_DECL], parms, | ||||
2209 | NULLnullptr); | ||||
2210 | vec_free (parms); | ||||
2211 | return add_stmt (t); | ||||
2212 | } | ||||
2213 | |||||
2214 | /* Build __builtin_eh_pointer. */ | ||||
2215 | |||||
2216 | static tree | ||||
2217 | objc_build_exc_ptr (struct objc_try_context **x ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
2218 | { | ||||
2219 | tree t; | ||||
2220 | t = builtin_decl_explicit (BUILT_IN_EH_POINTER); | ||||
2221 | t = build_call_expr (t, 1, integer_zero_nodeglobal_trees[TI_INTEGER_ZERO]); | ||||
2222 | return fold_convert (objc_object_type, t)fold_convert_loc (((location_t) 0), objc_global_trees[OCTI_ID_TYPE ], t); | ||||
2223 | } | ||||
2224 | |||||
2225 | static tree | ||||
2226 | begin_catch (struct objc_try_context **cur_try_context, tree type, | ||||
2227 | tree decl, tree compound, bool ellipsis ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
2228 | { | ||||
2229 | tree t; | ||||
2230 | /* Record the data for the catch in the try context so that we can | ||||
2231 | finalize it later. */ | ||||
2232 | if (ellipsis) | ||||
2233 | t = build_stmt (input_location, CATCH_EXPR, NULLnullptr, compound); | ||||
2234 | else | ||||
2235 | t = build_stmt (input_location, CATCH_EXPR, type, compound); | ||||
2236 | (*cur_try_context)->current_catch = t; | ||||
2237 | |||||
2238 | /* Initialize the decl from the EXC_PTR_EXPR we get from the runtime. */ | ||||
2239 | t = objc_build_exc_ptr (cur_try_context); | ||||
2240 | t = convert (TREE_TYPE (decl)((contains_struct_check ((decl), (TS_TYPED), "/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/objc/objc-gnu-runtime-abi-01.cc" , 2240, __FUNCTION__))->typed.type), t); | ||||
2241 | return build2 (MODIFY_EXPR, void_type_nodeglobal_trees[TI_VOID_TYPE], decl, t); | ||||
2242 | } | ||||
2243 | |||||
2244 | static void | ||||
2245 | finish_catch (struct objc_try_context **cur_try_context, tree current_catch) | ||||
2246 | { | ||||
2247 | append_to_statement_list (current_catch, &((*cur_try_context)->catch_list)); | ||||
2248 | } | ||||
2249 | |||||
2250 | static tree | ||||
2251 | finish_try_stmt (struct objc_try_context **cur_try_context) | ||||
2252 | { | ||||
2253 | struct objc_try_context *c = *cur_try_context; | ||||
2254 | tree stmt = c->try_body; | ||||
2255 | if (c->catch_list) | ||||
2256 | stmt = build_stmt (c->try_locus, TRY_CATCH_EXPR, stmt, c->catch_list); | ||||
2257 | if (c->finally_body) | ||||
2258 | stmt = build_stmt (c->try_locus, TRY_FINALLY_EXPR, stmt, c->finally_body); | ||||
2259 | return stmt; | ||||
2260 | } | ||||
2261 | |||||
2262 | #include "gt-objc-objc-gnu-runtime-abi-01.h" |
1 | /* Vector API for GNU compiler. | ||||
2 | Copyright (C) 2004-2023 Free Software Foundation, Inc. | ||||
3 | Contributed by Nathan Sidwell <nathan@codesourcery.com> | ||||
4 | Re-implemented in C++ by Diego Novillo <dnovillo@google.com> | ||||
5 | |||||
6 | This file is part of GCC. | ||||
7 | |||||
8 | GCC is free software; you can redistribute it and/or modify it under | ||||
9 | the terms of the GNU General Public License as published by the Free | ||||
10 | Software Foundation; either version 3, or (at your option) any later | ||||
11 | version. | ||||
12 | |||||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||
16 | for more details. | ||||
17 | |||||
18 | You should have received a copy of the GNU General Public License | ||||
19 | along with GCC; see the file COPYING3. If not see | ||||
20 | <http://www.gnu.org/licenses/>. */ | ||||
21 | |||||
22 | #ifndef GCC_VEC_H | ||||
23 | #define GCC_VEC_H | ||||
24 | |||||
25 | /* Some gen* file have no ggc support as the header file gtype-desc.h is | ||||
26 | missing. Provide these definitions in case ggc.h has not been included. | ||||
27 | This is not a problem because any code that runs before gengtype is built | ||||
28 | will never need to use GC vectors.*/ | ||||
29 | |||||
30 | extern void ggc_free (void *); | ||||
31 | extern size_t ggc_round_alloc_size (size_t requested_size); | ||||
32 | extern void *ggc_realloc (void *, size_t MEM_STAT_DECL); | ||||
33 | |||||
34 | /* Templated vector type and associated interfaces. | ||||
35 | |||||
36 | The interface functions are typesafe and use inline functions, | ||||
37 | sometimes backed by out-of-line generic functions. The vectors are | ||||
38 | designed to interoperate with the GTY machinery. | ||||
39 | |||||
40 | There are both 'index' and 'iterate' accessors. The index accessor | ||||
41 | is implemented by operator[]. The iterator returns a boolean | ||||
42 | iteration condition and updates the iteration variable passed by | ||||
43 | reference. Because the iterator will be inlined, the address-of | ||||
44 | can be optimized away. | ||||
45 | |||||
46 | Each operation that increases the number of active elements is | ||||
47 | available in 'quick' and 'safe' variants. The former presumes that | ||||
48 | there is sufficient allocated space for the operation to succeed | ||||
49 | (it dies if there is not). The latter will reallocate the | ||||
50 | vector, if needed. Reallocation causes an exponential increase in | ||||
51 | vector size. If you know you will be adding N elements, it would | ||||
52 | be more efficient to use the reserve operation before adding the | ||||
53 | elements with the 'quick' operation. This will ensure there are at | ||||
54 | least as many elements as you ask for, it will exponentially | ||||
55 | increase if there are too few spare slots. If you want reserve a | ||||
56 | specific number of slots, but do not want the exponential increase | ||||
57 | (for instance, you know this is the last allocation), use the | ||||
58 | reserve_exact operation. You can also create a vector of a | ||||
59 | specific size from the get go. | ||||
60 | |||||
61 | You should prefer the push and pop operations, as they append and | ||||
62 | remove from the end of the vector. If you need to remove several | ||||
63 | items in one go, use the truncate operation. The insert and remove | ||||
64 | operations allow you to change elements in the middle of the | ||||
65 | vector. There are two remove operations, one which preserves the | ||||
66 | element ordering 'ordered_remove', and one which does not | ||||
67 | 'unordered_remove'. The latter function copies the end element | ||||
68 | into the removed slot, rather than invoke a memmove operation. The | ||||
69 | 'lower_bound' function will determine where to place an item in the | ||||
70 | array using insert that will maintain sorted order. | ||||
71 | |||||
72 | Vectors are template types with three arguments: the type of the | ||||
73 | elements in the vector, the allocation strategy, and the physical | ||||
74 | layout to use | ||||
75 | |||||
76 | Four allocation strategies are supported: | ||||
77 | |||||
78 | - Heap: allocation is done using malloc/free. This is the | ||||
79 | default allocation strategy. | ||||
80 | |||||
81 | - GC: allocation is done using ggc_alloc/ggc_free. | ||||
82 | |||||
83 | - GC atomic: same as GC with the exception that the elements | ||||
84 | themselves are assumed to be of an atomic type that does | ||||
85 | not need to be garbage collected. This means that marking | ||||
86 | routines do not need to traverse the array marking the | ||||
87 | individual elements. This increases the performance of | ||||
88 | GC activities. | ||||
89 | |||||
90 | Two physical layouts are supported: | ||||
91 | |||||
92 | - Embedded: The vector is structured using the trailing array | ||||
93 | idiom. The last member of the structure is an array of size | ||||
94 | 1. When the vector is initially allocated, a single memory | ||||
95 | block is created to hold the vector's control data and the | ||||
96 | array of elements. These vectors cannot grow without | ||||
97 | reallocation (see discussion on embeddable vectors below). | ||||
98 | |||||
99 | - Space efficient: The vector is structured as a pointer to an | ||||
100 | embedded vector. This is the default layout. It means that | ||||
101 | vectors occupy a single word of storage before initial | ||||
102 | allocation. Vectors are allowed to grow (the internal | ||||
103 | pointer is reallocated but the main vector instance does not | ||||
104 | need to relocate). | ||||
105 | |||||
106 | The type, allocation and layout are specified when the vector is | ||||
107 | declared. | ||||
108 | |||||
109 | If you need to directly manipulate a vector, then the 'address' | ||||
110 | accessor will return the address of the start of the vector. Also | ||||
111 | the 'space' predicate will tell you whether there is spare capacity | ||||
112 | in the vector. You will not normally need to use these two functions. | ||||
113 | |||||
114 | Notes on the different layout strategies | ||||
115 | |||||
116 | * Embeddable vectors (vec<T, A, vl_embed>) | ||||
117 | |||||
118 | These vectors are suitable to be embedded in other data | ||||
119 | structures so that they can be pre-allocated in a contiguous | ||||
120 | memory block. | ||||
121 | |||||
122 | Embeddable vectors are implemented using the trailing array | ||||
123 | idiom, thus they are not resizeable without changing the address | ||||
124 | of the vector object itself. This means you cannot have | ||||
125 | variables or fields of embeddable vector type -- always use a | ||||
126 | pointer to a vector. The one exception is the final field of a | ||||
127 | structure, which could be a vector type. | ||||
128 | |||||
129 | You will have to use the embedded_size & embedded_init calls to | ||||
130 | create such objects, and they will not be resizeable (so the | ||||
131 | 'safe' allocation variants are not available). | ||||
132 | |||||
133 | Properties of embeddable vectors: | ||||
134 | |||||
135 | - The whole vector and control data are allocated in a single | ||||
136 | contiguous block. It uses the trailing-vector idiom, so | ||||
137 | allocation must reserve enough space for all the elements | ||||
138 | in the vector plus its control data. | ||||
139 | - The vector cannot be re-allocated. | ||||
140 | - The vector cannot grow nor shrink. | ||||
141 | - No indirections needed for access/manipulation. | ||||
142 | - It requires 2 words of storage (prior to vector allocation). | ||||
143 | |||||
144 | |||||
145 | * Space efficient vector (vec<T, A, vl_ptr>) | ||||
146 | |||||
147 | These vectors can grow dynamically and are allocated together | ||||
148 | with their control data. They are suited to be included in data | ||||
149 | structures. Prior to initial allocation, they only take a single | ||||
150 | word of storage. | ||||
151 | |||||
152 | These vectors are implemented as a pointer to embeddable vectors. | ||||
153 | The semantics allow for this pointer to be NULL to represent | ||||
154 | empty vectors. This way, empty vectors occupy minimal space in | ||||
155 | the structure containing them. | ||||
156 | |||||
157 | Properties: | ||||
158 | |||||
159 | - The whole vector and control data are allocated in a single | ||||
160 | contiguous block. | ||||
161 | - The whole vector may be re-allocated. | ||||
162 | - Vector data may grow and shrink. | ||||
163 | - Access and manipulation requires a pointer test and | ||||
164 | indirection. | ||||
165 | - It requires 1 word of storage (prior to vector allocation). | ||||
166 | |||||
167 | An example of their use would be, | ||||
168 | |||||
169 | struct my_struct { | ||||
170 | // A space-efficient vector of tree pointers in GC memory. | ||||
171 | vec<tree, va_gc, vl_ptr> v; | ||||
172 | }; | ||||
173 | |||||
174 | struct my_struct *s; | ||||
175 | |||||
176 | if (s->v.length ()) { we have some contents } | ||||
177 | s->v.safe_push (decl); // append some decl onto the end | ||||
178 | for (ix = 0; s->v.iterate (ix, &elt); ix++) | ||||
179 | { do something with elt } | ||||
180 | */ | ||||
181 | |||||
182 | /* Support function for statistics. */ | ||||
183 | extern void dump_vec_loc_statistics (void); | ||||
184 | |||||
185 | /* Hashtable mapping vec addresses to descriptors. */ | ||||
186 | extern htab_t vec_mem_usage_hash; | ||||
187 | |||||
188 | /* Control data for vectors. This contains the number of allocated | ||||
189 | and used slots inside a vector. */ | ||||
190 | |||||
191 | struct vec_prefix | ||||
192 | { | ||||
193 | /* FIXME - These fields should be private, but we need to cater to | ||||
194 | compilers that have stricter notions of PODness for types. */ | ||||
195 | |||||
196 | /* Memory allocation support routines in vec.cc. */ | ||||
197 | void register_overhead (void *, size_t, size_t CXX_MEM_STAT_INFO); | ||||
198 | void release_overhead (void *, size_t, size_t, bool CXX_MEM_STAT_INFO); | ||||
199 | static unsigned calculate_allocation (vec_prefix *, unsigned, bool); | ||||
200 | static unsigned calculate_allocation_1 (unsigned, unsigned); | ||||
201 | |||||
202 | /* Note that vec_prefix should be a base class for vec, but we use | ||||
203 | offsetof() on vector fields of tree structures (e.g., | ||||
204 | tree_binfo::base_binfos), and offsetof only supports base types. | ||||
205 | |||||
206 | To compensate, we make vec_prefix a field inside vec and make | ||||
207 | vec a friend class of vec_prefix so it can access its fields. */ | ||||
208 | template <typename, typename, typename> friend struct vec; | ||||
209 | |||||
210 | /* The allocator types also need access to our internals. */ | ||||
211 | friend struct va_gc; | ||||
212 | friend struct va_gc_atomic; | ||||
213 | friend struct va_heap; | ||||
214 | |||||
215 | unsigned m_alloc : 31; | ||||
216 | unsigned m_using_auto_storage : 1; | ||||
217 | unsigned m_num; | ||||
218 | }; | ||||
219 | |||||
220 | /* Calculate the number of slots to reserve a vector, making sure that | ||||
221 | RESERVE slots are free. If EXACT grow exactly, otherwise grow | ||||
222 | exponentially. PFX is the control data for the vector. */ | ||||
223 | |||||
224 | inline unsigned | ||||
225 | vec_prefix::calculate_allocation (vec_prefix *pfx, unsigned reserve, | ||||
226 | bool exact) | ||||
227 | { | ||||
228 | if (exact) | ||||
229 | return (pfx ? pfx->m_num : 0) + reserve; | ||||
230 | else if (!pfx) | ||||
231 | return MAX (4, reserve)((4) > (reserve) ? (4) : (reserve)); | ||||
232 | return calculate_allocation_1 (pfx->m_alloc, pfx->m_num + reserve); | ||||
233 | } | ||||
234 | |||||
235 | template<typename, typename, typename> struct vec; | ||||
236 | |||||
237 | /* Valid vector layouts | ||||
238 | |||||
239 | vl_embed - Embeddable vector that uses the trailing array idiom. | ||||
240 | vl_ptr - Space efficient vector that uses a pointer to an | ||||
241 | embeddable vector. */ | ||||
242 | struct vl_embed { }; | ||||
243 | struct vl_ptr { }; | ||||
244 | |||||
245 | |||||
246 | /* Types of supported allocations | ||||
247 | |||||
248 | va_heap - Allocation uses malloc/free. | ||||
249 | va_gc - Allocation uses ggc_alloc. | ||||
250 | va_gc_atomic - Same as GC, but individual elements of the array | ||||
251 | do not need to be marked during collection. */ | ||||
252 | |||||
253 | /* Allocator type for heap vectors. */ | ||||
254 | struct va_heap | ||||
255 | { | ||||
256 | /* Heap vectors are frequently regular instances, so use the vl_ptr | ||||
257 | layout for them. */ | ||||
258 | typedef vl_ptr default_layout; | ||||
259 | |||||
260 | template<typename T> | ||||
261 | static void reserve (vec<T, va_heap, vl_embed> *&, unsigned, bool | ||||
262 | CXX_MEM_STAT_INFO); | ||||
263 | |||||
264 | template<typename T> | ||||
265 | static void release (vec<T, va_heap, vl_embed> *&); | ||||
266 | }; | ||||
267 | |||||
268 | |||||
269 | /* Allocator for heap memory. Ensure there are at least RESERVE free | ||||
270 | slots in V. If EXACT is true, grow exactly, else grow | ||||
271 | exponentially. As a special case, if the vector had not been | ||||
272 | allocated and RESERVE is 0, no vector will be created. */ | ||||
273 | |||||
274 | template<typename T> | ||||
275 | inline void | ||||
276 | va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact | ||||
277 | MEM_STAT_DECL) | ||||
278 | { | ||||
279 | size_t elt_size = sizeof (T); | ||||
280 | unsigned alloc | ||||
281 | = vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, exact); | ||||
282 | gcc_checking_assert (alloc)((void)(!(alloc) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 282, __FUNCTION__), 0 : 0)); | ||||
283 | |||||
284 | if (GATHER_STATISTICS0 && v) | ||||
285 | v->m_vecpfx.release_overhead (v, elt_size * v->allocated (), | ||||
286 | v->allocated (), false); | ||||
287 | |||||
288 | size_t size = vec<T, va_heap, vl_embed>::embedded_size (alloc); | ||||
289 | unsigned nelem = v ? v->length () : 0; | ||||
290 | v = static_cast <vec<T, va_heap, vl_embed> *> (xrealloc (v, size)); | ||||
291 | v->embedded_init (alloc, nelem); | ||||
292 | |||||
293 | if (GATHER_STATISTICS0) | ||||
294 | v->m_vecpfx.register_overhead (v, alloc, elt_size PASS_MEM_STAT); | ||||
295 | } | ||||
296 | |||||
297 | |||||
298 | #if GCC_VERSION(4 * 1000 + 2) >= 4007 | ||||
299 | #pragma GCC diagnostic push | ||||
300 | #pragma GCC diagnostic ignored "-Wfree-nonheap-object" | ||||
301 | #endif | ||||
302 | |||||
303 | /* Free the heap space allocated for vector V. */ | ||||
304 | |||||
305 | template<typename T> | ||||
306 | void | ||||
307 | va_heap::release (vec<T, va_heap, vl_embed> *&v) | ||||
308 | { | ||||
309 | size_t elt_size = sizeof (T); | ||||
310 | if (v == NULLnullptr) | ||||
311 | return; | ||||
312 | |||||
313 | if (GATHER_STATISTICS0) | ||||
314 | v->m_vecpfx.release_overhead (v, elt_size * v->allocated (), | ||||
315 | v->allocated (), true); | ||||
316 | ::free (v); | ||||
317 | v = NULLnullptr; | ||||
318 | } | ||||
319 | |||||
320 | #if GCC_VERSION(4 * 1000 + 2) >= 4007 | ||||
321 | #pragma GCC diagnostic pop | ||||
322 | #endif | ||||
323 | |||||
324 | /* Allocator type for GC vectors. Notice that we need the structure | ||||
325 | declaration even if GC is not enabled. */ | ||||
326 | |||||
327 | struct va_gc | ||||
328 | { | ||||
329 | /* Use vl_embed as the default layout for GC vectors. Due to GTY | ||||
330 | limitations, GC vectors must always be pointers, so it is more | ||||
331 | efficient to use a pointer to the vl_embed layout, rather than | ||||
332 | using a pointer to a pointer as would be the case with vl_ptr. */ | ||||
333 | typedef vl_embed default_layout; | ||||
334 | |||||
335 | template<typename T, typename A> | ||||
336 | static void reserve (vec<T, A, vl_embed> *&, unsigned, bool | ||||
337 | CXX_MEM_STAT_INFO); | ||||
338 | |||||
339 | template<typename T, typename A> | ||||
340 | static void release (vec<T, A, vl_embed> *&v); | ||||
341 | }; | ||||
342 | |||||
343 | |||||
344 | /* Free GC memory used by V and reset V to NULL. */ | ||||
345 | |||||
346 | template<typename T, typename A> | ||||
347 | inline void | ||||
348 | va_gc::release (vec<T, A, vl_embed> *&v) | ||||
349 | { | ||||
350 | if (v) | ||||
351 | ::ggc_free (v); | ||||
352 | v = NULLnullptr; | ||||
353 | } | ||||
354 | |||||
355 | |||||
356 | /* Allocator for GC memory. Ensure there are at least RESERVE free | ||||
357 | slots in V. If EXACT is true, grow exactly, else grow | ||||
358 | exponentially. As a special case, if the vector had not been | ||||
359 | allocated and RESERVE is 0, no vector will be created. */ | ||||
360 | |||||
361 | template<typename T, typename A> | ||||
362 | void | ||||
363 | va_gc::reserve (vec<T, A, vl_embed> *&v, unsigned reserve, bool exact | ||||
364 | MEM_STAT_DECL) | ||||
365 | { | ||||
366 | unsigned alloc | ||||
367 | = vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, exact); | ||||
368 | if (!alloc) | ||||
369 | { | ||||
370 | ::ggc_free (v); | ||||
371 | v = NULLnullptr; | ||||
372 | return; | ||||
373 | } | ||||
374 | |||||
375 | /* Calculate the amount of space we want. */ | ||||
376 | size_t size = vec<T, A, vl_embed>::embedded_size (alloc); | ||||
377 | |||||
378 | /* Ask the allocator how much space it will really give us. */ | ||||
379 | size = ::ggc_round_alloc_size (size); | ||||
380 | |||||
381 | /* Adjust the number of slots accordingly. */ | ||||
382 | size_t vec_offset = sizeof (vec_prefix); | ||||
383 | size_t elt_size = sizeof (T); | ||||
384 | alloc = (size - vec_offset) / elt_size; | ||||
385 | |||||
386 | /* And finally, recalculate the amount of space we ask for. */ | ||||
387 | size = vec_offset + alloc * elt_size; | ||||
388 | |||||
389 | unsigned nelem = v ? v->length () : 0; | ||||
390 | v = static_cast <vec<T, A, vl_embed> *> (::ggc_realloc (v, size | ||||
391 | PASS_MEM_STAT)); | ||||
392 | v->embedded_init (alloc, nelem); | ||||
393 | } | ||||
394 | |||||
395 | |||||
396 | /* Allocator type for GC vectors. This is for vectors of types | ||||
397 | atomics w.r.t. collection, so allocation and deallocation is | ||||
398 | completely inherited from va_gc. */ | ||||
399 | struct va_gc_atomic : va_gc | ||||
400 | { | ||||
401 | }; | ||||
402 | |||||
403 | |||||
404 | /* Generic vector template. Default values for A and L indicate the | ||||
405 | most commonly used strategies. | ||||
406 | |||||
407 | FIXME - Ideally, they would all be vl_ptr to encourage using regular | ||||
408 | instances for vectors, but the existing GTY machinery is limited | ||||
409 | in that it can only deal with GC objects that are pointers | ||||
410 | themselves. | ||||
411 | |||||
412 | This means that vector operations that need to deal with | ||||
413 | potentially NULL pointers, must be provided as free | ||||
414 | functions (see the vec_safe_* functions above). */ | ||||
415 | template<typename T, | ||||
416 | typename A = va_heap, | ||||
417 | typename L = typename A::default_layout> | ||||
418 | struct GTY((user)) vec | ||||
419 | { | ||||
420 | }; | ||||
421 | |||||
422 | /* Allow C++11 range-based 'for' to work directly on vec<T>*. */ | ||||
423 | template<typename T, typename A, typename L> | ||||
424 | T* begin (vec<T,A,L> *v) { return v ? v->begin () : nullptr; } | ||||
425 | template<typename T, typename A, typename L> | ||||
426 | T* end (vec<T,A,L> *v) { return v ? v->end () : nullptr; } | ||||
427 | template<typename T, typename A, typename L> | ||||
428 | const T* begin (const vec<T,A,L> *v) { return v ? v->begin () : nullptr; } | ||||
429 | template<typename T, typename A, typename L> | ||||
430 | const T* end (const vec<T,A,L> *v) { return v ? v->end () : nullptr; } | ||||
431 | |||||
432 | /* Generic vec<> debug helpers. | ||||
433 | |||||
434 | These need to be instantiated for each vec<TYPE> used throughout | ||||
435 | the compiler like this: | ||||
436 | |||||
437 | DEFINE_DEBUG_VEC (TYPE) | ||||
438 | |||||
439 | The reason we have a debug_helper() is because GDB can't | ||||
440 | disambiguate a plain call to debug(some_vec), and it must be called | ||||
441 | like debug<TYPE>(some_vec). */ | ||||
442 | |||||
443 | template<typename T> | ||||
444 | void | ||||
445 | debug_helper (vec<T> &ref) | ||||
446 | { | ||||
447 | unsigned i; | ||||
448 | for (i = 0; i < ref.length (); ++i) | ||||
449 | { | ||||
450 | fprintf (stderrstderr, "[%d] = ", i); | ||||
451 | debug_slim (ref[i]); | ||||
452 | fputc ('\n', stderrstderr); | ||||
453 | } | ||||
454 | } | ||||
455 | |||||
456 | /* We need a separate va_gc variant here because default template | ||||
457 | argument for functions cannot be used in c++-98. Once this | ||||
458 | restriction is removed, those variant should be folded with the | ||||
459 | above debug_helper. */ | ||||
460 | |||||
461 | template<typename T> | ||||
462 | void | ||||
463 | debug_helper (vec<T, va_gc> &ref) | ||||
464 | { | ||||
465 | unsigned i; | ||||
466 | for (i = 0; i < ref.length (); ++i) | ||||
467 | { | ||||
468 | fprintf (stderrstderr, "[%d] = ", i); | ||||
469 | debug_slim (ref[i]); | ||||
470 | fputc ('\n', stderrstderr); | ||||
471 | } | ||||
472 | } | ||||
473 | |||||
474 | /* Macro to define debug(vec<T>) and debug(vec<T, va_gc>) helper | ||||
475 | functions for a type T. */ | ||||
476 | |||||
477 | #define DEFINE_DEBUG_VEC(T)template void debug_helper (vec<T> &); template void debug_helper (vec<T, va_gc> &); __attribute__ ((__used__ )) void debug (vec<T> &ref) { debug_helper <T> (ref); } __attribute__ ((__used__)) void debug (vec<T> *ptr) { if (ptr) debug (*ptr); else fprintf (stderr, "<nil>\n" ); } __attribute__ ((__used__)) void debug (vec<T, va_gc> &ref) { debug_helper <T> (ref); } __attribute__ (( __used__)) void debug (vec<T, va_gc> *ptr) { if (ptr) debug (*ptr); else fprintf (stderr, "<nil>\n"); } \ | ||||
478 | template void debug_helper (vec<T> &); \ | ||||
479 | template void debug_helper (vec<T, va_gc> &); \ | ||||
480 | /* Define the vec<T> debug functions. */ \ | ||||
481 | DEBUG_FUNCTION__attribute__ ((__used__)) void \ | ||||
482 | debug (vec<T> &ref) \ | ||||
483 | { \ | ||||
484 | debug_helper <T> (ref); \ | ||||
485 | } \ | ||||
486 | DEBUG_FUNCTION__attribute__ ((__used__)) void \ | ||||
487 | debug (vec<T> *ptr) \ | ||||
488 | { \ | ||||
489 | if (ptr) \ | ||||
490 | debug (*ptr); \ | ||||
491 | else \ | ||||
492 | fprintf (stderrstderr, "<nil>\n"); \ | ||||
493 | } \ | ||||
494 | /* Define the vec<T, va_gc> debug functions. */ \ | ||||
495 | DEBUG_FUNCTION__attribute__ ((__used__)) void \ | ||||
496 | debug (vec<T, va_gc> &ref) \ | ||||
497 | { \ | ||||
498 | debug_helper <T> (ref); \ | ||||
499 | } \ | ||||
500 | DEBUG_FUNCTION__attribute__ ((__used__)) void \ | ||||
501 | debug (vec<T, va_gc> *ptr) \ | ||||
502 | { \ | ||||
503 | if (ptr) \ | ||||
504 | debug (*ptr); \ | ||||
505 | else \ | ||||
506 | fprintf (stderrstderr, "<nil>\n"); \ | ||||
507 | } | ||||
508 | |||||
509 | /* Default-construct N elements in DST. */ | ||||
510 | |||||
511 | template <typename T> | ||||
512 | inline void | ||||
513 | vec_default_construct (T *dst, unsigned n) | ||||
514 | { | ||||
515 | #ifdef BROKEN_VALUE_INITIALIZATION | ||||
516 | /* Versions of GCC before 4.4 sometimes leave certain objects | ||||
517 | uninitialized when value initialized, though if the type has | ||||
518 | user defined default ctor, that ctor is invoked. As a workaround | ||||
519 | perform clearing first and then the value initialization, which | ||||
520 | fixes the case when value initialization doesn't initialize due to | ||||
521 | the bugs and should initialize to all zeros, but still allows | ||||
522 | vectors for types with user defined default ctor that initializes | ||||
523 | some or all elements to non-zero. If T has no user defined | ||||
524 | default ctor and some non-static data members have user defined | ||||
525 | default ctors that initialize to non-zero the workaround will | ||||
526 | still not work properly; in that case we just need to provide | ||||
527 | user defined default ctor. */ | ||||
528 | memset (dst, '\0', sizeof (T) * n); | ||||
529 | #endif | ||||
530 | for ( ; n; ++dst, --n) | ||||
531 | ::new (static_cast<void*>(dst)) T (); | ||||
532 | } | ||||
533 | |||||
534 | /* Copy-construct N elements in DST from *SRC. */ | ||||
535 | |||||
536 | template <typename T> | ||||
537 | inline void | ||||
538 | vec_copy_construct (T *dst, const T *src, unsigned n) | ||||
539 | { | ||||
540 | for ( ; n; ++dst, ++src, --n) | ||||
541 | ::new (static_cast<void*>(dst)) T (*src); | ||||
542 | } | ||||
543 | |||||
544 | /* Type to provide zero-initialized values for vec<T, A, L>. This is | ||||
545 | used to provide nil initializers for vec instances. Since vec must | ||||
546 | be a trivially copyable type that can be copied by memcpy and zeroed | ||||
547 | out by memset, it must have defaulted default and copy ctor and copy | ||||
548 | assignment. To initialize a vec either use value initialization | ||||
549 | (e.g., vec() or vec v{ };) or assign it the value vNULL. This isn't | ||||
550 | needed for file-scope and function-local static vectors, which are | ||||
551 | zero-initialized by default. */ | ||||
552 | struct vnull { }; | ||||
553 | constexpr vnull vNULL{ }; | ||||
554 | |||||
555 | |||||
556 | /* Embeddable vector. These vectors are suitable to be embedded | ||||
557 | in other data structures so that they can be pre-allocated in a | ||||
558 | contiguous memory block. | ||||
559 | |||||
560 | Embeddable vectors are implemented using the trailing array idiom, | ||||
561 | thus they are not resizeable without changing the address of the | ||||
562 | vector object itself. This means you cannot have variables or | ||||
563 | fields of embeddable vector type -- always use a pointer to a | ||||
564 | vector. The one exception is the final field of a structure, which | ||||
565 | could be a vector type. | ||||
566 | |||||
567 | You will have to use the embedded_size & embedded_init calls to | ||||
568 | create such objects, and they will not be resizeable (so the 'safe' | ||||
569 | allocation variants are not available). | ||||
570 | |||||
571 | Properties: | ||||
572 | |||||
573 | - The whole vector and control data are allocated in a single | ||||
574 | contiguous block. It uses the trailing-vector idiom, so | ||||
575 | allocation must reserve enough space for all the elements | ||||
576 | in the vector plus its control data. | ||||
577 | - The vector cannot be re-allocated. | ||||
578 | - The vector cannot grow nor shrink. | ||||
579 | - No indirections needed for access/manipulation. | ||||
580 | - It requires 2 words of storage (prior to vector allocation). */ | ||||
581 | |||||
582 | template<typename T, typename A> | ||||
583 | struct GTY((user)) vec<T, A, vl_embed> | ||||
584 | { | ||||
585 | public: | ||||
586 | unsigned allocated (void) const { return m_vecpfx.m_alloc; } | ||||
587 | unsigned length (void) const { return m_vecpfx.m_num; } | ||||
588 | bool is_empty (void) const { return m_vecpfx.m_num == 0; } | ||||
589 | T *address (void) { return reinterpret_cast <T *> (this + 1); } | ||||
590 | const T *address (void) const | ||||
591 | { return reinterpret_cast <const T *> (this + 1); } | ||||
592 | T *begin () { return address (); } | ||||
593 | const T *begin () const { return address (); } | ||||
594 | T *end () { return address () + length (); } | ||||
595 | const T *end () const { return address () + length (); } | ||||
596 | const T &operator[] (unsigned) const; | ||||
597 | T &operator[] (unsigned); | ||||
598 | T &last (void); | ||||
599 | bool space (unsigned) const; | ||||
600 | bool iterate (unsigned, T *) const; | ||||
601 | bool iterate (unsigned, T **) const; | ||||
602 | vec *copy (ALONE_CXX_MEM_STAT_INFO) const; | ||||
603 | void splice (const vec &); | ||||
604 | void splice (const vec *src); | ||||
605 | T *quick_push (const T &); | ||||
606 | T &pop (void); | ||||
607 | void truncate (unsigned); | ||||
608 | void quick_insert (unsigned, const T &); | ||||
609 | void ordered_remove (unsigned); | ||||
610 | void unordered_remove (unsigned); | ||||
611 | void block_remove (unsigned, unsigned); | ||||
612 | void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *)); | ||||
613 | void sort (int (*) (const void *, const void *, void *), void *); | ||||
614 | void stablesort (int (*) (const void *, const void *, void *), void *); | ||||
615 | T *bsearch (const void *key, int (*compar) (const void *, const void *)); | ||||
616 | T *bsearch (const void *key, | ||||
617 | int (*compar)(const void *, const void *, void *), void *); | ||||
618 | unsigned lower_bound (const T &, bool (*) (const T &, const T &)) const; | ||||
619 | bool contains (const T &search) const; | ||||
620 | static size_t embedded_size (unsigned); | ||||
621 | void embedded_init (unsigned, unsigned = 0, unsigned = 0); | ||||
622 | void quick_grow (unsigned len); | ||||
623 | void quick_grow_cleared (unsigned len); | ||||
624 | |||||
625 | /* vec class can access our internal data and functions. */ | ||||
626 | template <typename, typename, typename> friend struct vec; | ||||
627 | |||||
628 | /* The allocator types also need access to our internals. */ | ||||
629 | friend struct va_gc; | ||||
630 | friend struct va_gc_atomic; | ||||
631 | friend struct va_heap; | ||||
632 | |||||
633 | /* FIXME - This field should be private, but we need to cater to | ||||
634 | compilers that have stricter notions of PODness for types. */ | ||||
635 | /* Align m_vecpfx to simplify address (). */ | ||||
636 | alignas (T) alignas (vec_prefix) vec_prefix m_vecpfx; | ||||
637 | }; | ||||
638 | |||||
639 | |||||
640 | /* Convenience wrapper functions to use when dealing with pointers to | ||||
641 | embedded vectors. Some functionality for these vectors must be | ||||
642 | provided via free functions for these reasons: | ||||
643 | |||||
644 | 1- The pointer may be NULL (e.g., before initial allocation). | ||||
645 | |||||
646 | 2- When the vector needs to grow, it must be reallocated, so | ||||
647 | the pointer will change its value. | ||||
648 | |||||
649 | Because of limitations with the current GC machinery, all vectors | ||||
650 | in GC memory *must* be pointers. */ | ||||
651 | |||||
652 | |||||
653 | /* If V contains no room for NELEMS elements, return false. Otherwise, | ||||
654 | return true. */ | ||||
655 | template<typename T, typename A> | ||||
656 | inline bool | ||||
657 | vec_safe_space (const vec<T, A, vl_embed> *v, unsigned nelems) | ||||
658 | { | ||||
659 | return v ? v->space (nelems) : nelems == 0; | ||||
660 | } | ||||
661 | |||||
662 | |||||
663 | /* If V is NULL, return 0. Otherwise, return V->length(). */ | ||||
664 | template<typename T, typename A> | ||||
665 | inline unsigned | ||||
666 | vec_safe_length (const vec<T, A, vl_embed> *v) | ||||
667 | { | ||||
668 | return v ? v->length () : 0; | ||||
669 | } | ||||
670 | |||||
671 | |||||
672 | /* If V is NULL, return NULL. Otherwise, return V->address(). */ | ||||
673 | template<typename T, typename A> | ||||
674 | inline T * | ||||
675 | vec_safe_address (vec<T, A, vl_embed> *v) | ||||
676 | { | ||||
677 | return v ? v->address () : NULLnullptr; | ||||
678 | } | ||||
679 | |||||
680 | |||||
681 | /* If V is NULL, return true. Otherwise, return V->is_empty(). */ | ||||
682 | template<typename T, typename A> | ||||
683 | inline bool | ||||
684 | vec_safe_is_empty (vec<T, A, vl_embed> *v) | ||||
685 | { | ||||
686 | return v ? v->is_empty () : true; | ||||
687 | } | ||||
688 | |||||
689 | /* If V does not have space for NELEMS elements, call | ||||
690 | V->reserve(NELEMS, EXACT). */ | ||||
691 | template<typename T, typename A> | ||||
692 | inline bool | ||||
693 | vec_safe_reserve (vec<T, A, vl_embed> *&v, unsigned nelems, bool exact = false | ||||
694 | CXX_MEM_STAT_INFO) | ||||
695 | { | ||||
696 | bool extend = nelems ? !vec_safe_space (v, nelems) : false; | ||||
697 | if (extend
| ||||
698 | A::reserve (v, nelems, exact PASS_MEM_STAT); | ||||
699 | return extend; | ||||
700 | } | ||||
701 | |||||
702 | template<typename T, typename A> | ||||
703 | inline bool | ||||
704 | vec_safe_reserve_exact (vec<T, A, vl_embed> *&v, unsigned nelems | ||||
705 | CXX_MEM_STAT_INFO) | ||||
706 | { | ||||
707 | return vec_safe_reserve (v, nelems, true PASS_MEM_STAT); | ||||
708 | } | ||||
709 | |||||
710 | |||||
711 | /* Allocate GC memory for V with space for NELEMS slots. If NELEMS | ||||
712 | is 0, V is initialized to NULL. */ | ||||
713 | |||||
714 | template<typename T, typename A> | ||||
715 | inline void | ||||
716 | vec_alloc (vec<T, A, vl_embed> *&v, unsigned nelems CXX_MEM_STAT_INFO) | ||||
717 | { | ||||
718 | v = NULLnullptr; | ||||
719 | vec_safe_reserve (v, nelems, false PASS_MEM_STAT); | ||||
720 | } | ||||
721 | |||||
722 | |||||
723 | /* Free the GC memory allocated by vector V and set it to NULL. */ | ||||
724 | |||||
725 | template<typename T, typename A> | ||||
726 | inline void | ||||
727 | vec_free (vec<T, A, vl_embed> *&v) | ||||
728 | { | ||||
729 | A::release (v); | ||||
730 | } | ||||
731 | |||||
732 | |||||
733 | /* Grow V to length LEN. Allocate it, if necessary. */ | ||||
734 | template<typename T, typename A> | ||||
735 | inline void | ||||
736 | vec_safe_grow (vec<T, A, vl_embed> *&v, unsigned len, | ||||
737 | bool exact = false CXX_MEM_STAT_INFO) | ||||
738 | { | ||||
739 | unsigned oldlen = vec_safe_length (v); | ||||
740 | gcc_checking_assert (len >= oldlen)((void)(!(len >= oldlen) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 740, __FUNCTION__), 0 : 0)); | ||||
741 | vec_safe_reserve (v, len - oldlen, exact PASS_MEM_STAT); | ||||
742 | v->quick_grow (len); | ||||
743 | } | ||||
744 | |||||
745 | |||||
746 | /* If V is NULL, allocate it. Call V->safe_grow_cleared(LEN). */ | ||||
747 | template<typename T, typename A> | ||||
748 | inline void | ||||
749 | vec_safe_grow_cleared (vec<T, A, vl_embed> *&v, unsigned len, | ||||
750 | bool exact = false CXX_MEM_STAT_INFO) | ||||
751 | { | ||||
752 | unsigned oldlen = vec_safe_length (v); | ||||
753 | vec_safe_grow (v, len, exact PASS_MEM_STAT); | ||||
754 | vec_default_construct (v->address () + oldlen, len - oldlen); | ||||
755 | } | ||||
756 | |||||
757 | |||||
758 | /* Assume V is not NULL. */ | ||||
759 | |||||
760 | template<typename T> | ||||
761 | inline void | ||||
762 | vec_safe_grow_cleared (vec<T, va_heap, vl_ptr> *&v, | ||||
763 | unsigned len, bool exact = false CXX_MEM_STAT_INFO) | ||||
764 | { | ||||
765 | v->safe_grow_cleared (len, exact PASS_MEM_STAT); | ||||
766 | } | ||||
767 | |||||
768 | /* If V does not have space for NELEMS elements, call | ||||
769 | V->reserve(NELEMS, EXACT). */ | ||||
770 | |||||
771 | template<typename T> | ||||
772 | inline bool | ||||
773 | vec_safe_reserve (vec<T, va_heap, vl_ptr> *&v, unsigned nelems, bool exact = false | ||||
774 | CXX_MEM_STAT_INFO) | ||||
775 | { | ||||
776 | return v->reserve (nelems, exact); | ||||
777 | } | ||||
778 | |||||
779 | |||||
780 | /* If V is NULL return false, otherwise return V->iterate(IX, PTR). */ | ||||
781 | template<typename T, typename A> | ||||
782 | inline bool | ||||
783 | vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T **ptr) | ||||
784 | { | ||||
785 | if (v) | ||||
786 | return v->iterate (ix, ptr); | ||||
787 | else | ||||
788 | { | ||||
789 | *ptr = 0; | ||||
790 | return false; | ||||
791 | } | ||||
792 | } | ||||
793 | |||||
794 | template<typename T, typename A> | ||||
795 | inline bool | ||||
796 | vec_safe_iterate (const vec<T, A, vl_embed> *v, unsigned ix, T *ptr) | ||||
797 | { | ||||
798 | if (v) | ||||
799 | return v->iterate (ix, ptr); | ||||
800 | else | ||||
801 | { | ||||
802 | *ptr = 0; | ||||
803 | return false; | ||||
804 | } | ||||
805 | } | ||||
806 | |||||
807 | |||||
808 | /* If V has no room for one more element, reallocate it. Then call | ||||
809 | V->quick_push(OBJ). */ | ||||
810 | template<typename T, typename A> | ||||
811 | inline T * | ||||
812 | vec_safe_push (vec<T, A, vl_embed> *&v, const T &obj CXX_MEM_STAT_INFO) | ||||
813 | { | ||||
814 | vec_safe_reserve (v, 1, false PASS_MEM_STAT); | ||||
815 | return v->quick_push (obj); | ||||
816 | } | ||||
817 | |||||
818 | |||||
819 | /* if V has no room for one more element, reallocate it. Then call | ||||
820 | V->quick_insert(IX, OBJ). */ | ||||
821 | template<typename T, typename A> | ||||
822 | inline void | ||||
823 | vec_safe_insert (vec<T, A, vl_embed> *&v, unsigned ix, const T &obj | ||||
824 | CXX_MEM_STAT_INFO) | ||||
825 | { | ||||
826 | vec_safe_reserve (v, 1, false PASS_MEM_STAT); | ||||
827 | v->quick_insert (ix, obj); | ||||
828 | } | ||||
829 | |||||
830 | |||||
831 | /* If V is NULL, do nothing. Otherwise, call V->truncate(SIZE). */ | ||||
832 | template<typename T, typename A> | ||||
833 | inline void | ||||
834 | vec_safe_truncate (vec<T, A, vl_embed> *v, unsigned size) | ||||
835 | { | ||||
836 | if (v) | ||||
837 | v->truncate (size); | ||||
838 | } | ||||
839 | |||||
840 | |||||
841 | /* If SRC is not NULL, return a pointer to a copy of it. */ | ||||
842 | template<typename T, typename A> | ||||
843 | inline vec<T, A, vl_embed> * | ||||
844 | vec_safe_copy (vec<T, A, vl_embed> *src CXX_MEM_STAT_INFO) | ||||
845 | { | ||||
846 | return src ? src->copy (ALONE_PASS_MEM_STAT) : NULLnullptr; | ||||
847 | } | ||||
848 | |||||
849 | /* Copy the elements from SRC to the end of DST as if by memcpy. | ||||
850 | Reallocate DST, if necessary. */ | ||||
851 | template<typename T, typename A> | ||||
852 | inline void | ||||
853 | vec_safe_splice (vec<T, A, vl_embed> *&dst, const vec<T, A, vl_embed> *src | ||||
854 | CXX_MEM_STAT_INFO) | ||||
855 | { | ||||
856 | unsigned src_len = vec_safe_length (src); | ||||
857 | if (src_len) | ||||
858 | { | ||||
859 | vec_safe_reserve_exact (dst, vec_safe_length (dst) + src_len | ||||
860 | PASS_MEM_STAT); | ||||
861 | dst->splice (*src); | ||||
862 | } | ||||
863 | } | ||||
864 | |||||
865 | /* Return true if SEARCH is an element of V. Note that this is O(N) in the | ||||
866 | size of the vector and so should be used with care. */ | ||||
867 | |||||
868 | template<typename T, typename A> | ||||
869 | inline bool | ||||
870 | vec_safe_contains (vec<T, A, vl_embed> *v, const T &search) | ||||
871 | { | ||||
872 | return v ? v->contains (search) : false; | ||||
873 | } | ||||
874 | |||||
875 | /* Index into vector. Return the IX'th element. IX must be in the | ||||
876 | domain of the vector. */ | ||||
877 | |||||
878 | template<typename T, typename A> | ||||
879 | inline const T & | ||||
880 | vec<T, A, vl_embed>::operator[] (unsigned ix) const | ||||
881 | { | ||||
882 | gcc_checking_assert (ix < m_vecpfx.m_num)((void)(!(ix < m_vecpfx.m_num) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 882, __FUNCTION__), 0 : 0)); | ||||
883 | return address ()[ix]; | ||||
884 | } | ||||
885 | |||||
886 | template<typename T, typename A> | ||||
887 | inline T & | ||||
888 | vec<T, A, vl_embed>::operator[] (unsigned ix) | ||||
889 | { | ||||
890 | gcc_checking_assert (ix < m_vecpfx.m_num)((void)(!(ix < m_vecpfx.m_num) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 890, __FUNCTION__), 0 : 0)); | ||||
891 | return address ()[ix]; | ||||
892 | } | ||||
893 | |||||
894 | |||||
895 | /* Get the final element of the vector, which must not be empty. */ | ||||
896 | |||||
897 | template<typename T, typename A> | ||||
898 | inline T & | ||||
899 | vec<T, A, vl_embed>::last (void) | ||||
900 | { | ||||
901 | gcc_checking_assert (m_vecpfx.m_num > 0)((void)(!(m_vecpfx.m_num > 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 901, __FUNCTION__), 0 : 0)); | ||||
902 | return (*this)[m_vecpfx.m_num - 1]; | ||||
903 | } | ||||
904 | |||||
905 | |||||
906 | /* If this vector has space for NELEMS additional entries, return | ||||
907 | true. You usually only need to use this if you are doing your | ||||
908 | own vector reallocation, for instance on an embedded vector. This | ||||
909 | returns true in exactly the same circumstances that vec::reserve | ||||
910 | will. */ | ||||
911 | |||||
912 | template<typename T, typename A> | ||||
913 | inline bool | ||||
914 | vec<T, A, vl_embed>::space (unsigned nelems) const | ||||
915 | { | ||||
916 | return m_vecpfx.m_alloc - m_vecpfx.m_num >= nelems; | ||||
917 | } | ||||
918 | |||||
919 | |||||
920 | /* Return iteration condition and update *PTR to (a copy of) the IX'th | ||||
921 | element of this vector. Use this to iterate over the elements of a | ||||
922 | vector as follows, | ||||
923 | |||||
924 | for (ix = 0; v->iterate (ix, &val); ix++) | ||||
925 | continue; */ | ||||
926 | |||||
927 | template<typename T, typename A> | ||||
928 | inline bool | ||||
929 | vec<T, A, vl_embed>::iterate (unsigned ix, T *ptr) const | ||||
930 | { | ||||
931 | if (ix < m_vecpfx.m_num) | ||||
932 | { | ||||
933 | *ptr = address ()[ix]; | ||||
934 | return true; | ||||
935 | } | ||||
936 | else | ||||
937 | { | ||||
938 | *ptr = 0; | ||||
939 | return false; | ||||
940 | } | ||||
941 | } | ||||
942 | |||||
943 | |||||
944 | /* Return iteration condition and update *PTR to point to the | ||||
945 | IX'th element of this vector. Use this to iterate over the | ||||
946 | elements of a vector as follows, | ||||
947 | |||||
948 | for (ix = 0; v->iterate (ix, &ptr); ix++) | ||||
949 | continue; | ||||
950 | |||||
951 | This variant is for vectors of objects. */ | ||||
952 | |||||
953 | template<typename T, typename A> | ||||
954 | inline bool | ||||
955 | vec<T, A, vl_embed>::iterate (unsigned ix, T **ptr) const | ||||
956 | { | ||||
957 | if (ix < m_vecpfx.m_num) | ||||
958 | { | ||||
959 | *ptr = CONST_CAST (T *, &address ()[ix])(const_cast<T *> ((&address ()[ix]))); | ||||
960 | return true; | ||||
961 | } | ||||
962 | else | ||||
963 | { | ||||
964 | *ptr = 0; | ||||
965 | return false; | ||||
966 | } | ||||
967 | } | ||||
968 | |||||
969 | |||||
970 | /* Return a pointer to a copy of this vector. */ | ||||
971 | |||||
972 | template<typename T, typename A> | ||||
973 | inline vec<T, A, vl_embed> * | ||||
974 | vec<T, A, vl_embed>::copy (ALONE_MEM_STAT_DECLvoid) const | ||||
975 | { | ||||
976 | vec<T, A, vl_embed> *new_vec = NULLnullptr; | ||||
977 | unsigned len = length (); | ||||
978 | if (len) | ||||
979 | { | ||||
980 | vec_alloc (new_vec, len PASS_MEM_STAT); | ||||
981 | new_vec->embedded_init (len, len); | ||||
982 | vec_copy_construct (new_vec->address (), address (), len); | ||||
983 | } | ||||
984 | return new_vec; | ||||
985 | } | ||||
986 | |||||
987 | |||||
988 | /* Copy the elements from SRC to the end of this vector as if by memcpy. | ||||
989 | The vector must have sufficient headroom available. */ | ||||
990 | |||||
991 | template<typename T, typename A> | ||||
992 | inline void | ||||
993 | vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> &src) | ||||
994 | { | ||||
995 | unsigned len = src.length (); | ||||
996 | if (len) | ||||
997 | { | ||||
998 | gcc_checking_assert (space (len))((void)(!(space (len)) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 998, __FUNCTION__), 0 : 0)); | ||||
999 | vec_copy_construct (end (), src.address (), len); | ||||
1000 | m_vecpfx.m_num += len; | ||||
1001 | } | ||||
1002 | } | ||||
1003 | |||||
1004 | template<typename T, typename A> | ||||
1005 | inline void | ||||
1006 | vec<T, A, vl_embed>::splice (const vec<T, A, vl_embed> *src) | ||||
1007 | { | ||||
1008 | if (src) | ||||
1009 | splice (*src); | ||||
1010 | } | ||||
1011 | |||||
1012 | |||||
1013 | /* Push OBJ (a new element) onto the end of the vector. There must be | ||||
1014 | sufficient space in the vector. Return a pointer to the slot | ||||
1015 | where OBJ was inserted. */ | ||||
1016 | |||||
1017 | template<typename T, typename A> | ||||
1018 | inline T * | ||||
1019 | vec<T, A, vl_embed>::quick_push (const T &obj) | ||||
1020 | { | ||||
1021 | gcc_checking_assert (space (1))((void)(!(space (1)) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1021, __FUNCTION__), 0 : 0)); | ||||
1022 | T *slot = &address ()[m_vecpfx.m_num++]; | ||||
1023 | *slot = obj; | ||||
1024 | return slot; | ||||
1025 | } | ||||
1026 | |||||
1027 | |||||
1028 | /* Pop and return the last element off the end of the vector. */ | ||||
1029 | |||||
1030 | template<typename T, typename A> | ||||
1031 | inline T & | ||||
1032 | vec<T, A, vl_embed>::pop (void) | ||||
1033 | { | ||||
1034 | gcc_checking_assert (length () > 0)((void)(!(length () > 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1034, __FUNCTION__), 0 : 0)); | ||||
1035 | return address ()[--m_vecpfx.m_num]; | ||||
1036 | } | ||||
1037 | |||||
1038 | |||||
1039 | /* Set the length of the vector to SIZE. The new length must be less | ||||
1040 | than or equal to the current length. This is an O(1) operation. */ | ||||
1041 | |||||
1042 | template<typename T, typename A> | ||||
1043 | inline void | ||||
1044 | vec<T, A, vl_embed>::truncate (unsigned size) | ||||
1045 | { | ||||
1046 | gcc_checking_assert (length () >= size)((void)(!(length () >= size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1046, __FUNCTION__), 0 : 0)); | ||||
1047 | m_vecpfx.m_num = size; | ||||
1048 | } | ||||
1049 | |||||
1050 | |||||
1051 | /* Insert an element, OBJ, at the IXth position of this vector. There | ||||
1052 | must be sufficient space. */ | ||||
1053 | |||||
1054 | template<typename T, typename A> | ||||
1055 | inline void | ||||
1056 | vec<T, A, vl_embed>::quick_insert (unsigned ix, const T &obj) | ||||
1057 | { | ||||
1058 | gcc_checking_assert (length () < allocated ())((void)(!(length () < allocated ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1058, __FUNCTION__), 0 : 0)); | ||||
1059 | gcc_checking_assert (ix <= length ())((void)(!(ix <= length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1059, __FUNCTION__), 0 : 0)); | ||||
1060 | T *slot = &address ()[ix]; | ||||
1061 | memmove (slot + 1, slot, (m_vecpfx.m_num++ - ix) * sizeof (T)); | ||||
1062 | *slot = obj; | ||||
1063 | } | ||||
1064 | |||||
1065 | |||||
1066 | /* Remove an element from the IXth position of this vector. Ordering of | ||||
1067 | remaining elements is preserved. This is an O(N) operation due to | ||||
1068 | memmove. */ | ||||
1069 | |||||
1070 | template<typename T, typename A> | ||||
1071 | inline void | ||||
1072 | vec<T, A, vl_embed>::ordered_remove (unsigned ix) | ||||
1073 | { | ||||
1074 | gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1074, __FUNCTION__), 0 : 0)); | ||||
1075 | T *slot = &address ()[ix]; | ||||
1076 | memmove (slot, slot + 1, (--m_vecpfx.m_num - ix) * sizeof (T)); | ||||
1077 | } | ||||
1078 | |||||
1079 | |||||
1080 | /* Remove elements in [START, END) from VEC for which COND holds. Ordering of | ||||
1081 | remaining elements is preserved. This is an O(N) operation. */ | ||||
1082 | |||||
1083 | #define VEC_ORDERED_REMOVE_IF_FROM_TO(vec, read_index, write_index, \{ ((void)(!((end) <= (vec).length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1084, __FUNCTION__), 0 : 0)); for (read_index = write_index = (start); read_index < (end); ++read_index) { elem_ptr = &(vec)[read_index]; bool remove_p = (cond); if (remove_p ) continue; if (read_index != write_index) (vec)[write_index] = (vec)[read_index]; write_index++; } if (read_index - write_index > 0) (vec).block_remove (write_index, read_index - write_index ); } | ||||
1084 | elem_ptr, start, end, cond){ ((void)(!((end) <= (vec).length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1084, __FUNCTION__), 0 : 0)); for (read_index = write_index = (start); read_index < (end); ++read_index) { elem_ptr = &(vec)[read_index]; bool remove_p = (cond); if (remove_p ) continue; if (read_index != write_index) (vec)[write_index] = (vec)[read_index]; write_index++; } if (read_index - write_index > 0) (vec).block_remove (write_index, read_index - write_index ); } \ | ||||
1085 | { \ | ||||
1086 | gcc_assert ((end) <= (vec).length ())((void)(!((end) <= (vec).length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1086, __FUNCTION__), 0 : 0)); \ | ||||
1087 | for (read_index = write_index = (start); read_index < (end); \ | ||||
1088 | ++read_index) \ | ||||
1089 | { \ | ||||
1090 | elem_ptr = &(vec)[read_index]; \ | ||||
1091 | bool remove_p = (cond); \ | ||||
1092 | if (remove_p) \ | ||||
1093 | continue; \ | ||||
1094 | \ | ||||
1095 | if (read_index != write_index) \ | ||||
1096 | (vec)[write_index] = (vec)[read_index]; \ | ||||
1097 | \ | ||||
1098 | write_index++; \ | ||||
1099 | } \ | ||||
1100 | \ | ||||
1101 | if (read_index - write_index > 0) \ | ||||
1102 | (vec).block_remove (write_index, read_index - write_index); \ | ||||
1103 | } | ||||
1104 | |||||
1105 | |||||
1106 | /* Remove elements from VEC for which COND holds. Ordering of remaining | ||||
1107 | elements is preserved. This is an O(N) operation. */ | ||||
1108 | |||||
1109 | #define VEC_ORDERED_REMOVE_IF(vec, read_index, write_index, elem_ptr, \{ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1110, __FUNCTION__), 0 : 0)); for (read_index = write_index = (0); read_index < ((vec).length ()); ++read_index) { elem_ptr = &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p ) continue; if (read_index != write_index) ((vec))[write_index ] = ((vec))[read_index]; write_index++; } if (read_index - write_index > 0) ((vec)).block_remove (write_index, read_index - write_index ); } | ||||
1110 | cond){ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1110, __FUNCTION__), 0 : 0)); for (read_index = write_index = (0); read_index < ((vec).length ()); ++read_index) { elem_ptr = &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p ) continue; if (read_index != write_index) ((vec))[write_index ] = ((vec))[read_index]; write_index++; } if (read_index - write_index > 0) ((vec)).block_remove (write_index, read_index - write_index ); } \ | ||||
1111 | VEC_ORDERED_REMOVE_IF_FROM_TO ((vec), read_index, write_index, \{ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1112, __FUNCTION__), 0 : 0)); for (read_index = write_index = (0); read_index < ((vec).length ()); ++read_index) { elem_ptr = &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p ) continue; if (read_index != write_index) ((vec))[write_index ] = ((vec))[read_index]; write_index++; } if (read_index - write_index > 0) ((vec)).block_remove (write_index, read_index - write_index ); } | ||||
1112 | elem_ptr, 0, (vec).length (), (cond)){ ((void)(!(((vec).length ()) <= ((vec)).length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1112, __FUNCTION__), 0 : 0)); for (read_index = write_index = (0); read_index < ((vec).length ()); ++read_index) { elem_ptr = &((vec))[read_index]; bool remove_p = ((cond)); if (remove_p ) continue; if (read_index != write_index) ((vec))[write_index ] = ((vec))[read_index]; write_index++; } if (read_index - write_index > 0) ((vec)).block_remove (write_index, read_index - write_index ); } | ||||
1113 | |||||
1114 | /* Remove an element from the IXth position of this vector. Ordering of | ||||
1115 | remaining elements is destroyed. This is an O(1) operation. */ | ||||
1116 | |||||
1117 | template<typename T, typename A> | ||||
1118 | inline void | ||||
1119 | vec<T, A, vl_embed>::unordered_remove (unsigned ix) | ||||
1120 | { | ||||
1121 | gcc_checking_assert (ix < length ())((void)(!(ix < length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1121, __FUNCTION__), 0 : 0)); | ||||
1122 | T *p = address (); | ||||
1123 | p[ix] = p[--m_vecpfx.m_num]; | ||||
1124 | } | ||||
1125 | |||||
1126 | |||||
1127 | /* Remove LEN elements starting at the IXth. Ordering is retained. | ||||
1128 | This is an O(N) operation due to memmove. */ | ||||
1129 | |||||
1130 | template<typename T, typename A> | ||||
1131 | inline void | ||||
1132 | vec<T, A, vl_embed>::block_remove (unsigned ix, unsigned len) | ||||
1133 | { | ||||
1134 | gcc_checking_assert (ix + len <= length ())((void)(!(ix + len <= length ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1134, __FUNCTION__), 0 : 0)); | ||||
1135 | T *slot = &address ()[ix]; | ||||
1136 | m_vecpfx.m_num -= len; | ||||
1137 | memmove (slot, slot + len, (m_vecpfx.m_num - ix) * sizeof (T)); | ||||
1138 | } | ||||
1139 | |||||
1140 | |||||
1141 | /* Sort the contents of this vector with qsort. CMP is the comparison | ||||
1142 | function to pass to qsort. */ | ||||
1143 | |||||
1144 | template<typename T, typename A> | ||||
1145 | inline void | ||||
1146 | vec<T, A, vl_embed>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *)) | ||||
1147 | { | ||||
1148 | if (length () > 1) | ||||
1149 | gcc_qsort (address (), length (), sizeof (T), cmp); | ||||
1150 | } | ||||
1151 | |||||
1152 | /* Sort the contents of this vector with qsort. CMP is the comparison | ||||
1153 | function to pass to qsort. */ | ||||
1154 | |||||
1155 | template<typename T, typename A> | ||||
1156 | inline void | ||||
1157 | vec<T, A, vl_embed>::sort (int (*cmp) (const void *, const void *, void *), | ||||
1158 | void *data) | ||||
1159 | { | ||||
1160 | if (length () > 1) | ||||
1161 | gcc_sort_r (address (), length (), sizeof (T), cmp, data); | ||||
1162 | } | ||||
1163 | |||||
1164 | /* Sort the contents of this vector with gcc_stablesort_r. CMP is the | ||||
1165 | comparison function to pass to qsort. */ | ||||
1166 | |||||
1167 | template<typename T, typename A> | ||||
1168 | inline void | ||||
1169 | vec<T, A, vl_embed>::stablesort (int (*cmp) (const void *, const void *, | ||||
1170 | void *), void *data) | ||||
1171 | { | ||||
1172 | if (length () > 1) | ||||
1173 | gcc_stablesort_r (address (), length (), sizeof (T), cmp, data); | ||||
1174 | } | ||||
1175 | |||||
1176 | /* Search the contents of the sorted vector with a binary search. | ||||
1177 | CMP is the comparison function to pass to bsearch. */ | ||||
1178 | |||||
1179 | template<typename T, typename A> | ||||
1180 | inline T * | ||||
1181 | vec<T, A, vl_embed>::bsearch (const void *key, | ||||
1182 | int (*compar) (const void *, const void *)) | ||||
1183 | { | ||||
1184 | const void *base = this->address (); | ||||
1185 | size_t nmemb = this->length (); | ||||
1186 | size_t size = sizeof (T); | ||||
1187 | /* The following is a copy of glibc stdlib-bsearch.h. */ | ||||
1188 | size_t l, u, idx; | ||||
1189 | const void *p; | ||||
1190 | int comparison; | ||||
1191 | |||||
1192 | l = 0; | ||||
1193 | u = nmemb; | ||||
1194 | while (l < u) | ||||
1195 | { | ||||
1196 | idx = (l + u) / 2; | ||||
1197 | p = (const void *) (((const char *) base) + (idx * size)); | ||||
1198 | comparison = (*compar) (key, p); | ||||
1199 | if (comparison < 0) | ||||
1200 | u = idx; | ||||
1201 | else if (comparison > 0) | ||||
1202 | l = idx + 1; | ||||
1203 | else | ||||
1204 | return (T *)const_cast<void *>(p); | ||||
1205 | } | ||||
1206 | |||||
1207 | return NULLnullptr; | ||||
1208 | } | ||||
1209 | |||||
1210 | /* Search the contents of the sorted vector with a binary search. | ||||
1211 | CMP is the comparison function to pass to bsearch. */ | ||||
1212 | |||||
1213 | template<typename T, typename A> | ||||
1214 | inline T * | ||||
1215 | vec<T, A, vl_embed>::bsearch (const void *key, | ||||
1216 | int (*compar) (const void *, const void *, | ||||
1217 | void *), void *data) | ||||
1218 | { | ||||
1219 | const void *base = this->address (); | ||||
1220 | size_t nmemb = this->length (); | ||||
1221 | size_t size = sizeof (T); | ||||
1222 | /* The following is a copy of glibc stdlib-bsearch.h. */ | ||||
1223 | size_t l, u, idx; | ||||
1224 | const void *p; | ||||
1225 | int comparison; | ||||
1226 | |||||
1227 | l = 0; | ||||
1228 | u = nmemb; | ||||
1229 | while (l < u) | ||||
1230 | { | ||||
1231 | idx = (l + u) / 2; | ||||
1232 | p = (const void *) (((const char *) base) + (idx * size)); | ||||
1233 | comparison = (*compar) (key, p, data); | ||||
1234 | if (comparison < 0) | ||||
1235 | u = idx; | ||||
1236 | else if (comparison > 0) | ||||
1237 | l = idx + 1; | ||||
1238 | else | ||||
1239 | return (T *)const_cast<void *>(p); | ||||
1240 | } | ||||
1241 | |||||
1242 | return NULLnullptr; | ||||
1243 | } | ||||
1244 | |||||
1245 | /* Return true if SEARCH is an element of V. Note that this is O(N) in the | ||||
1246 | size of the vector and so should be used with care. */ | ||||
1247 | |||||
1248 | template<typename T, typename A> | ||||
1249 | inline bool | ||||
1250 | vec<T, A, vl_embed>::contains (const T &search) const | ||||
1251 | { | ||||
1252 | unsigned int len = length (); | ||||
1253 | const T *p = address (); | ||||
1254 | for (unsigned int i = 0; i < len; i++) | ||||
1255 | { | ||||
1256 | const T *slot = &p[i]; | ||||
1257 | if (*slot == search) | ||||
1258 | return true; | ||||
1259 | } | ||||
1260 | |||||
1261 | return false; | ||||
1262 | } | ||||
1263 | |||||
1264 | /* Find and return the first position in which OBJ could be inserted | ||||
1265 | without changing the ordering of this vector. LESSTHAN is a | ||||
1266 | function that returns true if the first argument is strictly less | ||||
1267 | than the second. */ | ||||
1268 | |||||
1269 | template<typename T, typename A> | ||||
1270 | unsigned | ||||
1271 | vec<T, A, vl_embed>::lower_bound (const T &obj, | ||||
1272 | bool (*lessthan)(const T &, const T &)) | ||||
1273 | const | ||||
1274 | { | ||||
1275 | unsigned int len = length (); | ||||
1276 | unsigned int half, middle; | ||||
1277 | unsigned int first = 0; | ||||
1278 | while (len > 0) | ||||
1279 | { | ||||
1280 | half = len / 2; | ||||
1281 | middle = first; | ||||
1282 | middle += half; | ||||
1283 | const T &middle_elem = address ()[middle]; | ||||
1284 | if (lessthan (middle_elem, obj)) | ||||
1285 | { | ||||
1286 | first = middle; | ||||
1287 | ++first; | ||||
1288 | len = len - half - 1; | ||||
1289 | } | ||||
1290 | else | ||||
1291 | len = half; | ||||
1292 | } | ||||
1293 | return first; | ||||
1294 | } | ||||
1295 | |||||
1296 | |||||
1297 | /* Return the number of bytes needed to embed an instance of an | ||||
1298 | embeddable vec inside another data structure. | ||||
1299 | |||||
1300 | Use these methods to determine the required size and initialization | ||||
1301 | of a vector V of type T embedded within another structure (as the | ||||
1302 | final member): | ||||
1303 | |||||
1304 | size_t vec<T, A, vl_embed>::embedded_size (unsigned alloc); | ||||
1305 | void v->embedded_init (unsigned alloc, unsigned num); | ||||
1306 | |||||
1307 | These allow the caller to perform the memory allocation. */ | ||||
1308 | |||||
1309 | template<typename T, typename A> | ||||
1310 | inline size_t | ||||
1311 | vec<T, A, vl_embed>::embedded_size (unsigned alloc) | ||||
1312 | { | ||||
1313 | struct alignas (T) U { char data[sizeof (T)]; }; | ||||
1314 | typedef vec<U, A, vl_embed> vec_embedded; | ||||
1315 | typedef typename std::conditional<std::is_standard_layout<T>::value, | ||||
1316 | vec, vec_embedded>::type vec_stdlayout; | ||||
1317 | static_assert (sizeof (vec_stdlayout) == sizeof (vec), ""); | ||||
1318 | static_assert (alignof (vec_stdlayout) == alignof (vec), ""); | ||||
1319 | return sizeof (vec_stdlayout) + alloc * sizeof (T); | ||||
1320 | } | ||||
1321 | |||||
1322 | |||||
1323 | /* Initialize the vector to contain room for ALLOC elements and | ||||
1324 | NUM active elements. */ | ||||
1325 | |||||
1326 | template<typename T, typename A> | ||||
1327 | inline void | ||||
1328 | vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num, unsigned aut) | ||||
1329 | { | ||||
1330 | m_vecpfx.m_alloc = alloc; | ||||
1331 | m_vecpfx.m_using_auto_storage = aut; | ||||
1332 | m_vecpfx.m_num = num; | ||||
1333 | } | ||||
1334 | |||||
1335 | |||||
1336 | /* Grow the vector to a specific length. LEN must be as long or longer than | ||||
1337 | the current length. The new elements are uninitialized. */ | ||||
1338 | |||||
1339 | template<typename T, typename A> | ||||
1340 | inline void | ||||
1341 | vec<T, A, vl_embed>::quick_grow (unsigned len) | ||||
1342 | { | ||||
1343 | gcc_checking_assert (length () <= len && len <= m_vecpfx.m_alloc)((void)(!(length () <= len && len <= m_vecpfx.m_alloc ) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1343, __FUNCTION__), 0 : 0)); | ||||
1344 | m_vecpfx.m_num = len; | ||||
1345 | } | ||||
1346 | |||||
1347 | |||||
1348 | /* Grow the vector to a specific length. LEN must be as long or longer than | ||||
1349 | the current length. The new elements are initialized to zero. */ | ||||
1350 | |||||
1351 | template<typename T, typename A> | ||||
1352 | inline void | ||||
1353 | vec<T, A, vl_embed>::quick_grow_cleared (unsigned len) | ||||
1354 | { | ||||
1355 | unsigned oldlen = length (); | ||||
1356 | size_t growby = len - oldlen; | ||||
1357 | quick_grow (len); | ||||
1358 | if (growby != 0) | ||||
1359 | vec_default_construct (address () + oldlen, growby); | ||||
1360 | } | ||||
1361 | |||||
1362 | /* Garbage collection support for vec<T, A, vl_embed>. */ | ||||
1363 | |||||
1364 | template<typename T> | ||||
1365 | void | ||||
1366 | gt_ggc_mx (vec<T, va_gc> *v) | ||||
1367 | { | ||||
1368 | extern void gt_ggc_mx (T &); | ||||
1369 | for (unsigned i = 0; i < v->length (); i++) | ||||
1370 | gt_ggc_mx ((*v)[i]); | ||||
1371 | } | ||||
1372 | |||||
1373 | template<typename T> | ||||
1374 | void | ||||
1375 | gt_ggc_mx (vec<T, va_gc_atomic, vl_embed> *v ATTRIBUTE_UNUSED__attribute__ ((__unused__))) | ||||
1376 | { | ||||
1377 | /* Nothing to do. Vectors of atomic types wrt GC do not need to | ||||
1378 | be traversed. */ | ||||
1379 | } | ||||
1380 | |||||
1381 | |||||
1382 | /* PCH support for vec<T, A, vl_embed>. */ | ||||
1383 | |||||
1384 | template<typename T, typename A> | ||||
1385 | void | ||||
1386 | gt_pch_nx (vec<T, A, vl_embed> *v) | ||||
1387 | { | ||||
1388 | extern void gt_pch_nx (T &); | ||||
1389 | for (unsigned i = 0; i < v->length (); i++) | ||||
1390 | gt_pch_nx ((*v)[i]); | ||||
1391 | } | ||||
1392 | |||||
1393 | template<typename T, typename A> | ||||
1394 | void | ||||
1395 | gt_pch_nx (vec<T *, A, vl_embed> *v, gt_pointer_operator op, void *cookie) | ||||
1396 | { | ||||
1397 | for (unsigned i = 0; i < v->length (); i++) | ||||
1398 | op (&((*v)[i]), NULLnullptr, cookie); | ||||
1399 | } | ||||
1400 | |||||
1401 | template<typename T, typename A> | ||||
1402 | void | ||||
1403 | gt_pch_nx (vec<T, A, vl_embed> *v, gt_pointer_operator op, void *cookie) | ||||
1404 | { | ||||
1405 | extern void gt_pch_nx (T *, gt_pointer_operator, void *); | ||||
1406 | for (unsigned i = 0; i < v->length (); i++) | ||||
1407 | gt_pch_nx (&((*v)[i]), op, cookie); | ||||
1408 | } | ||||
1409 | |||||
1410 | |||||
1411 | /* Space efficient vector. These vectors can grow dynamically and are | ||||
1412 | allocated together with their control data. They are suited to be | ||||
1413 | included in data structures. Prior to initial allocation, they | ||||
1414 | only take a single word of storage. | ||||
1415 | |||||
1416 | These vectors are implemented as a pointer to an embeddable vector. | ||||
1417 | The semantics allow for this pointer to be NULL to represent empty | ||||
1418 | vectors. This way, empty vectors occupy minimal space in the | ||||
1419 | structure containing them. | ||||
1420 | |||||
1421 | Properties: | ||||
1422 | |||||
1423 | - The whole vector and control data are allocated in a single | ||||
1424 | contiguous block. | ||||
1425 | - The whole vector may be re-allocated. | ||||
1426 | - Vector data may grow and shrink. | ||||
1427 | - Access and manipulation requires a pointer test and | ||||
1428 | indirection. | ||||
1429 | - It requires 1 word of storage (prior to vector allocation). | ||||
1430 | |||||
1431 | |||||
1432 | Limitations: | ||||
1433 | |||||
1434 | These vectors must be PODs because they are stored in unions. | ||||
1435 | (http://en.wikipedia.org/wiki/Plain_old_data_structures). | ||||
1436 | As long as we use C++03, we cannot have constructors nor | ||||
1437 | destructors in classes that are stored in unions. */ | ||||
1438 | |||||
1439 | template<typename T, size_t N = 0> | ||||
1440 | class auto_vec; | ||||
1441 | |||||
1442 | template<typename T> | ||||
1443 | struct vec<T, va_heap, vl_ptr> | ||||
1444 | { | ||||
1445 | public: | ||||
1446 | /* Default ctors to ensure triviality. Use value-initialization | ||||
1447 | (e.g., vec() or vec v{ };) or vNULL to create a zero-initialized | ||||
1448 | instance. */ | ||||
1449 | vec () = default; | ||||
1450 | vec (const vec &) = default; | ||||
1451 | /* Initialization from the generic vNULL. */ | ||||
1452 | vec (vnull): m_vec () { } | ||||
1453 | /* Same as default ctor: vec storage must be released manually. */ | ||||
1454 | ~vec () = default; | ||||
1455 | |||||
1456 | /* Defaulted same as copy ctor. */ | ||||
1457 | vec& operator= (const vec &) = default; | ||||
1458 | |||||
1459 | /* Prevent implicit conversion from auto_vec. Use auto_vec::to_vec() | ||||
1460 | instead. */ | ||||
1461 | template <size_t N> | ||||
1462 | vec (auto_vec<T, N> &) = delete; | ||||
1463 | |||||
1464 | template <size_t N> | ||||
1465 | void operator= (auto_vec<T, N> &) = delete; | ||||
1466 | |||||
1467 | /* Memory allocation and deallocation for the embedded vector. | ||||
1468 | Needed because we cannot have proper ctors/dtors defined. */ | ||||
1469 | void create (unsigned nelems CXX_MEM_STAT_INFO); | ||||
1470 | void release (void); | ||||
1471 | |||||
1472 | /* Vector operations. */ | ||||
1473 | bool exists (void) const | ||||
1474 | { return m_vec != NULLnullptr; } | ||||
1475 | |||||
1476 | bool is_empty (void) const | ||||
1477 | { return m_vec ? m_vec->is_empty () : true; } | ||||
1478 | |||||
1479 | unsigned allocated (void) const | ||||
1480 | { return m_vec ? m_vec->allocated () : 0; } | ||||
1481 | |||||
1482 | unsigned length (void) const | ||||
1483 | { return m_vec ? m_vec->length () : 0; } | ||||
1484 | |||||
1485 | T *address (void) | ||||
1486 | { return m_vec ? m_vec->address () : NULLnullptr; } | ||||
1487 | |||||
1488 | const T *address (void) const | ||||
1489 | { return m_vec ? m_vec->address () : NULLnullptr; } | ||||
1490 | |||||
1491 | T *begin () { return address (); } | ||||
1492 | const T *begin () const { return address (); } | ||||
1493 | T *end () { return begin () + length (); } | ||||
1494 | const T *end () const { return begin () + length (); } | ||||
1495 | const T &operator[] (unsigned ix) const | ||||
1496 | { return (*m_vec)[ix]; } | ||||
1497 | |||||
1498 | bool operator!=(const vec &other) const | ||||
1499 | { return !(*this == other); } | ||||
1500 | |||||
1501 | bool operator==(const vec &other) const | ||||
1502 | { return address () == other.address (); } | ||||
1503 | |||||
1504 | T &operator[] (unsigned ix) | ||||
1505 | { return (*m_vec)[ix]; } | ||||
1506 | |||||
1507 | T &last (void) | ||||
1508 | { return m_vec->last (); } | ||||
1509 | |||||
1510 | bool space (int nelems) const | ||||
1511 | { return m_vec ? m_vec->space (nelems) : nelems == 0; } | ||||
1512 | |||||
1513 | bool iterate (unsigned ix, T *p) const; | ||||
1514 | bool iterate (unsigned ix, T **p) const; | ||||
1515 | vec copy (ALONE_CXX_MEM_STAT_INFO) const; | ||||
1516 | bool reserve (unsigned, bool = false CXX_MEM_STAT_INFO); | ||||
1517 | bool reserve_exact (unsigned CXX_MEM_STAT_INFO); | ||||
1518 | void splice (const vec &); | ||||
1519 | void safe_splice (const vec & CXX_MEM_STAT_INFO); | ||||
1520 | T *quick_push (const T &); | ||||
1521 | T *safe_push (const T &CXX_MEM_STAT_INFO); | ||||
1522 | T &pop (void); | ||||
1523 | void truncate (unsigned); | ||||
1524 | void safe_grow (unsigned, bool = false CXX_MEM_STAT_INFO); | ||||
1525 | void safe_grow_cleared (unsigned, bool = false CXX_MEM_STAT_INFO); | ||||
1526 | void quick_grow (unsigned); | ||||
1527 | void quick_grow_cleared (unsigned); | ||||
1528 | void quick_insert (unsigned, const T &); | ||||
1529 | void safe_insert (unsigned, const T & CXX_MEM_STAT_INFO); | ||||
1530 | void ordered_remove (unsigned); | ||||
1531 | void unordered_remove (unsigned); | ||||
1532 | void block_remove (unsigned, unsigned); | ||||
1533 | void qsort (int (*) (const void *, const void *))qsort (int (*) (const void *, const void *)); | ||||
1534 | void sort (int (*) (const void *, const void *, void *), void *); | ||||
1535 | void stablesort (int (*) (const void *, const void *, void *), void *); | ||||
1536 | T *bsearch (const void *key, int (*compar)(const void *, const void *)); | ||||
1537 | T *bsearch (const void *key, | ||||
1538 | int (*compar)(const void *, const void *, void *), void *); | ||||
1539 | unsigned lower_bound (T, bool (*)(const T &, const T &)) const; | ||||
1540 | bool contains (const T &search) const; | ||||
1541 | void reverse (void); | ||||
1542 | |||||
1543 | bool using_auto_storage () const; | ||||
1544 | |||||
1545 | /* FIXME - This field should be private, but we need to cater to | ||||
1546 | compilers that have stricter notions of PODness for types. */ | ||||
1547 | vec<T, va_heap, vl_embed> *m_vec; | ||||
1548 | }; | ||||
1549 | |||||
1550 | |||||
1551 | /* auto_vec is a subclass of vec that automatically manages creating and | ||||
1552 | releasing the internal vector. If N is non zero then it has N elements of | ||||
1553 | internal storage. The default is no internal storage, and you probably only | ||||
1554 | want to ask for internal storage for vectors on the stack because if the | ||||
1555 | size of the vector is larger than the internal storage that space is wasted. | ||||
1556 | */ | ||||
1557 | template<typename T, size_t N /* = 0 */> | ||||
1558 | class auto_vec : public vec<T, va_heap> | ||||
1559 | { | ||||
1560 | public: | ||||
1561 | auto_vec () | ||||
1562 | { | ||||
1563 | m_auto.embedded_init (N, 0, 1); | ||||
1564 | /* ??? Instead of initializing m_vec from &m_auto directly use an | ||||
1565 | expression that avoids refering to a specific member of 'this' | ||||
1566 | to derail the -Wstringop-overflow diagnostic code, avoiding | ||||
1567 | the impression that data accesses are supposed to be to the | ||||
1568 | m_auto member storage. */ | ||||
1569 | size_t off = (char *) &m_auto - (char *) this; | ||||
1570 | this->m_vec = (vec<T, va_heap, vl_embed> *) ((char *) this + off); | ||||
1571 | } | ||||
1572 | |||||
1573 | auto_vec (size_t s CXX_MEM_STAT_INFO) | ||||
1574 | { | ||||
1575 | if (s > N) | ||||
1576 | { | ||||
1577 | this->create (s PASS_MEM_STAT); | ||||
1578 | return; | ||||
1579 | } | ||||
1580 | |||||
1581 | m_auto.embedded_init (N, 0, 1); | ||||
1582 | /* ??? See above. */ | ||||
1583 | size_t off = (char *) &m_auto - (char *) this; | ||||
1584 | this->m_vec = (vec<T, va_heap, vl_embed> *) ((char *) this + off); | ||||
1585 | } | ||||
1586 | |||||
1587 | ~auto_vec () | ||||
1588 | { | ||||
1589 | this->release (); | ||||
1590 | } | ||||
1591 | |||||
1592 | /* Explicitly convert to the base class. There is no conversion | ||||
1593 | from a const auto_vec because a copy of the returned vec can | ||||
1594 | be used to modify *THIS. | ||||
1595 | This is a legacy function not to be used in new code. */ | ||||
1596 | vec<T, va_heap> to_vec_legacy () { | ||||
1597 | return *static_cast<vec<T, va_heap> *>(this); | ||||
1598 | } | ||||
1599 | |||||
1600 | private: | ||||
1601 | vec<T, va_heap, vl_embed> m_auto; | ||||
1602 | unsigned char m_data[sizeof (T) * N]; | ||||
1603 | }; | ||||
1604 | |||||
1605 | /* auto_vec is a sub class of vec whose storage is released when it is | ||||
1606 | destroyed. */ | ||||
1607 | template<typename T> | ||||
1608 | class auto_vec<T, 0> : public vec<T, va_heap> | ||||
1609 | { | ||||
1610 | public: | ||||
1611 | auto_vec () { this->m_vec = NULLnullptr; } | ||||
1612 | auto_vec (size_t n CXX_MEM_STAT_INFO) { this->create (n PASS_MEM_STAT); } | ||||
1613 | ~auto_vec () { this->release (); } | ||||
1614 | |||||
1615 | auto_vec (vec<T, va_heap>&& r) | ||||
1616 | { | ||||
1617 | gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1617, __FUNCTION__), 0 : 0)); | ||||
1618 | this->m_vec = r.m_vec; | ||||
1619 | r.m_vec = NULLnullptr; | ||||
1620 | } | ||||
1621 | |||||
1622 | auto_vec (auto_vec<T> &&r) | ||||
1623 | { | ||||
1624 | gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1624, __FUNCTION__), 0 : 0)); | ||||
1625 | this->m_vec = r.m_vec; | ||||
1626 | r.m_vec = NULLnullptr; | ||||
1627 | } | ||||
1628 | |||||
1629 | auto_vec& operator= (vec<T, va_heap>&& r) | ||||
1630 | { | ||||
1631 | if (this == &r) | ||||
1632 | return *this; | ||||
1633 | |||||
1634 | gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1634, __FUNCTION__), 0 : 0)); | ||||
1635 | this->release (); | ||||
1636 | this->m_vec = r.m_vec; | ||||
1637 | r.m_vec = NULLnullptr; | ||||
1638 | return *this; | ||||
1639 | } | ||||
1640 | |||||
1641 | auto_vec& operator= (auto_vec<T> &&r) | ||||
1642 | { | ||||
1643 | if (this == &r) | ||||
1644 | return *this; | ||||
1645 | |||||
1646 | gcc_assert (!r.using_auto_storage ())((void)(!(!r.using_auto_storage ()) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 1646, __FUNCTION__), 0 : 0)); | ||||
1647 | this->release (); | ||||
1648 | this->m_vec = r.m_vec; | ||||
1649 | r.m_vec = NULLnullptr; | ||||
1650 | return *this; | ||||
1651 | } | ||||
1652 | |||||
1653 | /* Explicitly convert to the base class. There is no conversion | ||||
1654 | from a const auto_vec because a copy of the returned vec can | ||||
1655 | be used to modify *THIS. | ||||
1656 | This is a legacy function not to be used in new code. */ | ||||
1657 | vec<T, va_heap> to_vec_legacy () { | ||||
1658 | return *static_cast<vec<T, va_heap> *>(this); | ||||
1659 | } | ||||
1660 | |||||
1661 | // You probably don't want to copy a vector, so these are deleted to prevent | ||||
1662 | // unintentional use. If you really need a copy of the vectors contents you | ||||
1663 | // can use copy (). | ||||
1664 | auto_vec(const auto_vec &) = delete; | ||||
1665 | auto_vec &operator= (const auto_vec &) = delete; | ||||
1666 | }; | ||||
1667 | |||||
1668 | |||||
1669 | /* Allocate heap memory for pointer V and create the internal vector | ||||
1670 | with space for NELEMS elements. If NELEMS is 0, the internal | ||||
1671 | vector is initialized to empty. */ | ||||
1672 | |||||
1673 | template<typename T> | ||||
1674 | inline void | ||||
1675 | vec_alloc (vec<T> *&v, unsigned nelems CXX_MEM_STAT_INFO) | ||||
1676 | { | ||||
1677 | v = new vec<T>; | ||||
1678 | v->create (nelems PASS_MEM_STAT); | ||||
1679 | } | ||||
1680 | |||||
1681 | |||||
1682 | /* A subclass of auto_vec <char *> that frees all of its elements on | ||||
1683 | deletion. */ | ||||
1684 | |||||
1685 | class auto_string_vec : public auto_vec <char *> | ||||
1686 | { | ||||
1687 | public: | ||||
1688 | ~auto_string_vec (); | ||||
1689 | }; | ||||
1690 | |||||
1691 | /* A subclass of auto_vec <T *> that deletes all of its elements on | ||||
1692 | destruction. | ||||
1693 | |||||
1694 | This is a crude way for a vec to "own" the objects it points to | ||||
1695 | and clean up automatically. | ||||
1696 | |||||
1697 | For example, no attempt is made to delete elements when an item | ||||
1698 | within the vec is overwritten. | ||||
1699 | |||||
1700 | We can't rely on gnu::unique_ptr within a container, | ||||
1701 | since we can't rely on move semantics in C++98. */ | ||||
1702 | |||||
1703 | template <typename T> | ||||
1704 | class auto_delete_vec : public auto_vec <T *> | ||||
1705 | { | ||||
1706 | public: | ||||
1707 | auto_delete_vec () {} | ||||
1708 | auto_delete_vec (size_t s) : auto_vec <T *> (s) {} | ||||
1709 | |||||
1710 | ~auto_delete_vec (); | ||||
1711 | |||||
1712 | private: | ||||
1713 | DISABLE_COPY_AND_ASSIGN(auto_delete_vec)auto_delete_vec (const auto_delete_vec&) = delete; void operator = (const auto_delete_vec &) = delete; | ||||
1714 | }; | ||||
1715 | |||||
1716 | /* Conditionally allocate heap memory for VEC and its internal vector. */ | ||||
1717 | |||||
1718 | template<typename T> | ||||
1719 | inline void | ||||
1720 | vec_check_alloc (vec<T, va_heap> *&vec, unsigned nelems CXX_MEM_STAT_INFO) | ||||
1721 | { | ||||
1722 | if (!vec) | ||||
1723 | vec_alloc (vec, nelems PASS_MEM_STAT); | ||||
1724 | } | ||||
1725 | |||||
1726 | |||||
1727 | /* Free the heap memory allocated by vector V and set it to NULL. */ | ||||
1728 | |||||
1729 | template<typename T> | ||||
1730 | inline void | ||||
1731 | vec_free (vec<T> *&v) | ||||
1732 | { | ||||
1733 | if (v == NULLnullptr) | ||||
1734 | return; | ||||
1735 | |||||
1736 | v->release (); | ||||
1737 | delete v; | ||||
1738 | v = NULLnullptr; | ||||
1739 | } | ||||
1740 | |||||
1741 | |||||
1742 | /* Return iteration condition and update PTR to point to the IX'th | ||||
1743 | element of this vector. Use this to iterate over the elements of a | ||||
1744 | vector as follows, | ||||
1745 | |||||
1746 | for (ix = 0; v.iterate (ix, &ptr); ix++) | ||||
1747 | continue; */ | ||||
1748 | |||||
1749 | template<typename T> | ||||
1750 | inline bool | ||||
1751 | vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T *ptr) const | ||||
1752 | { | ||||
1753 | if (m_vec) | ||||
1754 | return m_vec->iterate (ix, ptr); | ||||
1755 | else | ||||
1756 | { | ||||
1757 | *ptr = 0; | ||||
1758 | return false; | ||||
1759 | } | ||||
1760 | } | ||||
1761 | |||||
1762 | |||||
1763 | /* Return iteration condition and update *PTR to point to the | ||||
1764 | IX'th element of this vector. Use this to iterate over the | ||||
1765 | elements of a vector as follows, | ||||
1766 | |||||
1767 | for (ix = 0; v->iterate (ix, &ptr); ix++) | ||||
1768 | continue; | ||||
1769 | |||||
1770 | This variant is for vectors of objects. */ | ||||
1771 | |||||
1772 | template<typename T> | ||||
1773 | inline bool | ||||
1774 | vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T **ptr) const | ||||
1775 | { | ||||
1776 | if (m_vec) | ||||
1777 | return m_vec->iterate (ix, ptr); | ||||
1778 | else | ||||
1779 | { | ||||
1780 | *ptr = 0; | ||||
1781 | return false; | ||||
1782 | } | ||||
1783 | } | ||||
1784 | |||||
1785 | |||||
1786 | /* Convenience macro for forward iteration. */ | ||||
1787 | #define FOR_EACH_VEC_ELT(V, I, P)for (I = 0; (V).iterate ((I), &(P)); ++(I)) \ | ||||
1788 | for (I = 0; (V).iterate ((I), &(P)); ++(I)) | ||||
1789 | |||||
1790 | #define FOR_EACH_VEC_SAFE_ELT(V, I, P)for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I)) \ | ||||
1791 | for (I = 0; vec_safe_iterate ((V), (I), &(P)); ++(I)) | ||||
1792 | |||||
1793 | /* Likewise, but start from FROM rather than 0. */ | ||||
1794 | #define FOR_EACH_VEC_ELT_FROM(V, I, P, FROM)for (I = (FROM); (V).iterate ((I), &(P)); ++(I)) \ | ||||
1795 | for (I = (FROM); (V).iterate ((I), &(P)); ++(I)) | ||||
1796 | |||||
1797 | /* Convenience macro for reverse iteration. */ | ||||
1798 | #define FOR_EACH_VEC_ELT_REVERSE(V, I, P)for (I = (V).length () - 1; (V).iterate ((I), &(P)); (I)-- ) \ | ||||
1799 | for (I = (V).length () - 1; \ | ||||
1800 | (V).iterate ((I), &(P)); \ | ||||
1801 | (I)--) | ||||
1802 | |||||
1803 | #define FOR_EACH_VEC_SAFE_ELT_REVERSE(V, I, P)for (I = vec_safe_length (V) - 1; vec_safe_iterate ((V), (I), &(P)); (I)--) \ | ||||
1804 | for (I = vec_safe_length (V) - 1; \ | ||||
1805 | vec_safe_iterate ((V), (I), &(P)); \ | ||||
1806 | (I)--) | ||||
1807 | |||||
1808 | /* auto_string_vec's dtor, freeing all contained strings, automatically | ||||
1809 | chaining up to ~auto_vec <char *>, which frees the internal buffer. */ | ||||
1810 | |||||
1811 | inline | ||||
1812 | auto_string_vec::~auto_string_vec () | ||||
1813 | { | ||||
1814 | int i; | ||||
1815 | char *str; | ||||
1816 | FOR_EACH_VEC_ELT (*this, i, str)for (i = 0; (*this).iterate ((i), &(str)); ++(i)) | ||||
1817 | free (str); | ||||
1818 | } | ||||
1819 | |||||
1820 | /* auto_delete_vec's dtor, deleting all contained items, automatically | ||||
1821 | chaining up to ~auto_vec <T*>, which frees the internal buffer. */ | ||||
1822 | |||||
1823 | template <typename T> | ||||
1824 | inline | ||||
1825 | auto_delete_vec<T>::~auto_delete_vec () | ||||
1826 | { | ||||
1827 | int i; | ||||
1828 | T *item; | ||||
1829 | FOR_EACH_VEC_ELT (*this, i, item)for (i = 0; (*this).iterate ((i), &(item)); ++(i)) | ||||
1830 | delete item; | ||||
1831 | } | ||||
1832 | |||||
1833 | |||||
1834 | /* Return a copy of this vector. */ | ||||
1835 | |||||
1836 | template<typename T> | ||||
1837 | inline vec<T, va_heap, vl_ptr> | ||||
1838 | vec<T, va_heap, vl_ptr>::copy (ALONE_MEM_STAT_DECLvoid) const | ||||
1839 | { | ||||
1840 | vec<T, va_heap, vl_ptr> new_vec{ }; | ||||
1841 | if (length ()) | ||||
1842 | new_vec.m_vec = m_vec->copy (ALONE_PASS_MEM_STAT); | ||||
1843 | return new_vec; | ||||
1844 | } | ||||
1845 | |||||
1846 | |||||
1847 | /* Ensure that the vector has at least RESERVE slots available (if | ||||
1848 | EXACT is false), or exactly RESERVE slots available (if EXACT is | ||||
1849 | true). | ||||
1850 | |||||
1851 | This may create additional headroom if EXACT is false. | ||||
1852 | |||||
1853 | Note that this can cause the embedded vector to be reallocated. | ||||
1854 | Returns true iff reallocation actually occurred. */ | ||||
1855 | |||||
1856 | template<typename T> | ||||
1857 | inline bool | ||||
1858 | vec<T, va_heap, vl_ptr>::reserve (unsigned nelems, bool exact MEM_STAT_DECL) | ||||
1859 | { | ||||
1860 | if (space (nelems)) | ||||
1861 | return false; | ||||
1862 | |||||
1863 | /* For now play a game with va_heap::reserve to hide our auto storage if any, | ||||
1864 | this is necessary because it doesn't have enough information to know the | ||||
1865 | embedded vector is in auto storage, and so should not be freed. */ | ||||
1866 | vec<T, va_heap, vl_embed> *oldvec = m_vec; | ||||
1867 | unsigned int oldsize = 0; | ||||
1868 | bool handle_auto_vec = m_vec && using_auto_storage (); | ||||
1869 | if (handle_auto_vec) | ||||
1870 | { | ||||
1871 | m_vec = NULLnullptr; | ||||
1872 | oldsize = oldvec->length (); | ||||
1873 | nelems += oldsize; | ||||
1874 | } | ||||
1875 | |||||
1876 | va_heap::reserve (m_vec, nelems, exact PASS_MEM_STAT); | ||||
1877 | if (handle_auto_vec) | ||||
1878 | { | ||||
1879 | vec_copy_construct (m_vec->address (), oldvec->address (), oldsize); | ||||
1880 | m_vec->m_vecpfx.m_num = oldsize; | ||||
1881 | } | ||||
1882 | |||||
1883 | return true; | ||||
1884 | } | ||||
1885 | |||||
1886 | |||||
1887 | /* Ensure that this vector has exactly NELEMS slots available. This | ||||
1888 | will not create additional headroom. Note this can cause the | ||||
1889 | embedded vector to be reallocated. Returns true iff reallocation | ||||
1890 | actually occurred. */ | ||||
1891 | |||||
1892 | template<typename T> | ||||
1893 | inline bool | ||||
1894 | vec<T, va_heap, vl_ptr>::reserve_exact (unsigned nelems MEM_STAT_DECL) | ||||
1895 | { | ||||
1896 | return reserve (nelems, true PASS_MEM_STAT); | ||||
1897 | } | ||||
1898 | |||||
1899 | |||||
1900 | /* Create the internal vector and reserve NELEMS for it. This is | ||||
1901 | exactly like vec::reserve, but the internal vector is | ||||
1902 | unconditionally allocated from scratch. The old one, if it | ||||
1903 | existed, is lost. */ | ||||
1904 | |||||
1905 | template<typename T> | ||||
1906 | inline void | ||||
1907 | vec<T, va_heap, vl_ptr>::create (unsigned nelems MEM_STAT_DECL) | ||||
1908 | { | ||||
1909 | m_vec = NULLnullptr; | ||||
1910 | if (nelems > 0) | ||||
1911 | reserve_exact (nelems PASS_MEM_STAT); | ||||
1912 | } | ||||
1913 | |||||
1914 | |||||
1915 | /* Free the memory occupied by the embedded vector. */ | ||||
1916 | |||||
1917 | template<typename T> | ||||
1918 | inline void | ||||
1919 | vec<T, va_heap, vl_ptr>::release (void) | ||||
1920 | { | ||||
1921 | if (!m_vec) | ||||
1922 | return; | ||||
1923 | |||||
1924 | if (using_auto_storage ()) | ||||
1925 | { | ||||
1926 | m_vec->m_vecpfx.m_num = 0; | ||||
1927 | return; | ||||
1928 | } | ||||
1929 | |||||
1930 | va_heap::release (m_vec); | ||||
1931 | } | ||||
1932 | |||||
1933 | /* Copy the elements from SRC to the end of this vector as if by memcpy. | ||||
1934 | SRC and this vector must be allocated with the same memory | ||||
1935 | allocation mechanism. This vector is assumed to have sufficient | ||||
1936 | headroom available. */ | ||||
1937 | |||||
1938 | template<typename T> | ||||
1939 | inline void | ||||
1940 | vec<T, va_heap, vl_ptr>::splice (const vec<T, va_heap, vl_ptr> &src) | ||||
1941 | { | ||||
1942 | if (src.length ()) | ||||
1943 | m_vec->splice (*(src.m_vec)); | ||||
1944 | } | ||||
1945 | |||||
1946 | |||||
1947 | /* Copy the elements in SRC to the end of this vector as if by memcpy. | ||||
1948 | SRC and this vector must be allocated with the same mechanism. | ||||
1949 | If there is not enough headroom in this vector, it will be reallocated | ||||
1950 | as needed. */ | ||||
1951 | |||||
1952 | template<typename T> | ||||
1953 | inline void | ||||
1954 | vec<T, va_heap, vl_ptr>::safe_splice (const vec<T, va_heap, vl_ptr> &src | ||||
1955 | MEM_STAT_DECL) | ||||
1956 | { | ||||
1957 | if (src.length ()) | ||||
1958 | { | ||||
1959 | reserve_exact (src.length ()); | ||||
1960 | splice (src); | ||||
1961 | } | ||||
1962 | } | ||||
1963 | |||||
1964 | |||||
1965 | /* Push OBJ (a new element) onto the end of the vector. There must be | ||||
1966 | sufficient space in the vector. Return a pointer to the slot | ||||
1967 | where OBJ was inserted. */ | ||||
1968 | |||||
1969 | template<typename T> | ||||
1970 | inline T * | ||||
1971 | vec<T, va_heap, vl_ptr>::quick_push (const T &obj) | ||||
1972 | { | ||||
1973 | return m_vec->quick_push (obj); | ||||
1974 | } | ||||
1975 | |||||
1976 | |||||
1977 | /* Push a new element OBJ onto the end of this vector. Reallocates | ||||
1978 | the embedded vector, if needed. Return a pointer to the slot where | ||||
1979 | OBJ was inserted. */ | ||||
1980 | |||||
1981 | template<typename T> | ||||
1982 | inline T * | ||||
1983 | vec<T, va_heap, vl_ptr>::safe_push (const T &obj MEM_STAT_DECL) | ||||
1984 | { | ||||
1985 | reserve (1, false PASS_MEM_STAT); | ||||
1986 | return quick_push (obj); | ||||
1987 | } | ||||
1988 | |||||
1989 | |||||
1990 | /* Pop and return the last element off the end of the vector. */ | ||||
1991 | |||||
1992 | template<typename T> | ||||
1993 | inline T & | ||||
1994 | vec<T, va_heap, vl_ptr>::pop (void) | ||||
1995 | { | ||||
1996 | return m_vec->pop (); | ||||
1997 | } | ||||
1998 | |||||
1999 | |||||
2000 | /* Set the length of the vector to LEN. The new length must be less | ||||
2001 | than or equal to the current length. This is an O(1) operation. */ | ||||
2002 | |||||
2003 | template<typename T> | ||||
2004 | inline void | ||||
2005 | vec<T, va_heap, vl_ptr>::truncate (unsigned size) | ||||
2006 | { | ||||
2007 | if (m_vec) | ||||
2008 | m_vec->truncate (size); | ||||
2009 | else | ||||
2010 | gcc_checking_assert (size == 0)((void)(!(size == 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2010, __FUNCTION__), 0 : 0)); | ||||
2011 | } | ||||
2012 | |||||
2013 | |||||
2014 | /* Grow the vector to a specific length. LEN must be as long or | ||||
2015 | longer than the current length. The new elements are | ||||
2016 | uninitialized. Reallocate the internal vector, if needed. */ | ||||
2017 | |||||
2018 | template<typename T> | ||||
2019 | inline void | ||||
2020 | vec<T, va_heap, vl_ptr>::safe_grow (unsigned len, bool exact MEM_STAT_DECL) | ||||
2021 | { | ||||
2022 | unsigned oldlen = length (); | ||||
2023 | gcc_checking_assert (oldlen <= len)((void)(!(oldlen <= len) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2023, __FUNCTION__), 0 : 0)); | ||||
2024 | reserve (len - oldlen, exact PASS_MEM_STAT); | ||||
2025 | if (m_vec) | ||||
2026 | m_vec->quick_grow (len); | ||||
2027 | else | ||||
2028 | gcc_checking_assert (len == 0)((void)(!(len == 0) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2028, __FUNCTION__), 0 : 0)); | ||||
2029 | } | ||||
2030 | |||||
2031 | |||||
2032 | /* Grow the embedded vector to a specific length. LEN must be as | ||||
2033 | long or longer than the current length. The new elements are | ||||
2034 | initialized to zero. Reallocate the internal vector, if needed. */ | ||||
2035 | |||||
2036 | template<typename T> | ||||
2037 | inline void | ||||
2038 | vec<T, va_heap, vl_ptr>::safe_grow_cleared (unsigned len, bool exact | ||||
2039 | MEM_STAT_DECL) | ||||
2040 | { | ||||
2041 | unsigned oldlen = length (); | ||||
2042 | size_t growby = len - oldlen; | ||||
2043 | safe_grow (len, exact PASS_MEM_STAT); | ||||
2044 | if (growby != 0) | ||||
2045 | vec_default_construct (address () + oldlen, growby); | ||||
2046 | } | ||||
2047 | |||||
2048 | |||||
2049 | /* Same as vec::safe_grow but without reallocation of the internal vector. | ||||
2050 | If the vector cannot be extended, a runtime assertion will be triggered. */ | ||||
2051 | |||||
2052 | template<typename T> | ||||
2053 | inline void | ||||
2054 | vec<T, va_heap, vl_ptr>::quick_grow (unsigned len) | ||||
2055 | { | ||||
2056 | gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2056, __FUNCTION__), 0 : 0)); | ||||
2057 | m_vec->quick_grow (len); | ||||
2058 | } | ||||
2059 | |||||
2060 | |||||
2061 | /* Same as vec::quick_grow_cleared but without reallocation of the | ||||
2062 | internal vector. If the vector cannot be extended, a runtime | ||||
2063 | assertion will be triggered. */ | ||||
2064 | |||||
2065 | template<typename T> | ||||
2066 | inline void | ||||
2067 | vec<T, va_heap, vl_ptr>::quick_grow_cleared (unsigned len) | ||||
2068 | { | ||||
2069 | gcc_checking_assert (m_vec)((void)(!(m_vec) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2069, __FUNCTION__), 0 : 0)); | ||||
2070 | m_vec->quick_grow_cleared (len); | ||||
2071 | } | ||||
2072 | |||||
2073 | |||||
2074 | /* Insert an element, OBJ, at the IXth position of this vector. There | ||||
2075 | must be sufficient space. */ | ||||
2076 | |||||
2077 | template<typename T> | ||||
2078 | inline void | ||||
2079 | vec<T, va_heap, vl_ptr>::quick_insert (unsigned ix, const T &obj) | ||||
2080 | { | ||||
2081 | m_vec->quick_insert (ix, obj); | ||||
2082 | } | ||||
2083 | |||||
2084 | |||||
2085 | /* Insert an element, OBJ, at the IXth position of the vector. | ||||
2086 | Reallocate the embedded vector, if necessary. */ | ||||
2087 | |||||
2088 | template<typename T> | ||||
2089 | inline void | ||||
2090 | vec<T, va_heap, vl_ptr>::safe_insert (unsigned ix, const T &obj MEM_STAT_DECL) | ||||
2091 | { | ||||
2092 | reserve (1, false PASS_MEM_STAT); | ||||
2093 | quick_insert (ix, obj); | ||||
2094 | } | ||||
2095 | |||||
2096 | |||||
2097 | /* Remove an element from the IXth position of this vector. Ordering of | ||||
2098 | remaining elements is preserved. This is an O(N) operation due to | ||||
2099 | a memmove. */ | ||||
2100 | |||||
2101 | template<typename T> | ||||
2102 | inline void | ||||
2103 | vec<T, va_heap, vl_ptr>::ordered_remove (unsigned ix) | ||||
2104 | { | ||||
2105 | m_vec->ordered_remove (ix); | ||||
2106 | } | ||||
2107 | |||||
2108 | |||||
2109 | /* Remove an element from the IXth position of this vector. Ordering | ||||
2110 | of remaining elements is destroyed. This is an O(1) operation. */ | ||||
2111 | |||||
2112 | template<typename T> | ||||
2113 | inline void | ||||
2114 | vec<T, va_heap, vl_ptr>::unordered_remove (unsigned ix) | ||||
2115 | { | ||||
2116 | m_vec->unordered_remove (ix); | ||||
2117 | } | ||||
2118 | |||||
2119 | |||||
2120 | /* Remove LEN elements starting at the IXth. Ordering is retained. | ||||
2121 | This is an O(N) operation due to memmove. */ | ||||
2122 | |||||
2123 | template<typename T> | ||||
2124 | inline void | ||||
2125 | vec<T, va_heap, vl_ptr>::block_remove (unsigned ix, unsigned len) | ||||
2126 | { | ||||
2127 | m_vec->block_remove (ix, len); | ||||
2128 | } | ||||
2129 | |||||
2130 | |||||
2131 | /* Sort the contents of this vector with qsort. CMP is the comparison | ||||
2132 | function to pass to qsort. */ | ||||
2133 | |||||
2134 | template<typename T> | ||||
2135 | inline void | ||||
2136 | vec<T, va_heap, vl_ptr>::qsort (int (*cmp) (const void *, const void *))qsort (int (*cmp) (const void *, const void *)) | ||||
2137 | { | ||||
2138 | if (m_vec) | ||||
2139 | m_vec->qsort (cmp)qsort (cmp); | ||||
2140 | } | ||||
2141 | |||||
2142 | /* Sort the contents of this vector with qsort. CMP is the comparison | ||||
2143 | function to pass to qsort. */ | ||||
2144 | |||||
2145 | template<typename T> | ||||
2146 | inline void | ||||
2147 | vec<T, va_heap, vl_ptr>::sort (int (*cmp) (const void *, const void *, | ||||
2148 | void *), void *data) | ||||
2149 | { | ||||
2150 | if (m_vec) | ||||
2151 | m_vec->sort (cmp, data); | ||||
2152 | } | ||||
2153 | |||||
2154 | /* Sort the contents of this vector with gcc_stablesort_r. CMP is the | ||||
2155 | comparison function to pass to qsort. */ | ||||
2156 | |||||
2157 | template<typename T> | ||||
2158 | inline void | ||||
2159 | vec<T, va_heap, vl_ptr>::stablesort (int (*cmp) (const void *, const void *, | ||||
2160 | void *), void *data) | ||||
2161 | { | ||||
2162 | if (m_vec) | ||||
2163 | m_vec->stablesort (cmp, data); | ||||
2164 | } | ||||
2165 | |||||
2166 | /* Search the contents of the sorted vector with a binary search. | ||||
2167 | CMP is the comparison function to pass to bsearch. */ | ||||
2168 | |||||
2169 | template<typename T> | ||||
2170 | inline T * | ||||
2171 | vec<T, va_heap, vl_ptr>::bsearch (const void *key, | ||||
2172 | int (*cmp) (const void *, const void *)) | ||||
2173 | { | ||||
2174 | if (m_vec) | ||||
2175 | return m_vec->bsearch (key, cmp); | ||||
2176 | return NULLnullptr; | ||||
2177 | } | ||||
2178 | |||||
2179 | /* Search the contents of the sorted vector with a binary search. | ||||
2180 | CMP is the comparison function to pass to bsearch. */ | ||||
2181 | |||||
2182 | template<typename T> | ||||
2183 | inline T * | ||||
2184 | vec<T, va_heap, vl_ptr>::bsearch (const void *key, | ||||
2185 | int (*cmp) (const void *, const void *, | ||||
2186 | void *), void *data) | ||||
2187 | { | ||||
2188 | if (m_vec) | ||||
2189 | return m_vec->bsearch (key, cmp, data); | ||||
2190 | return NULLnullptr; | ||||
2191 | } | ||||
2192 | |||||
2193 | |||||
2194 | /* Find and return the first position in which OBJ could be inserted | ||||
2195 | without changing the ordering of this vector. LESSTHAN is a | ||||
2196 | function that returns true if the first argument is strictly less | ||||
2197 | than the second. */ | ||||
2198 | |||||
2199 | template<typename T> | ||||
2200 | inline unsigned | ||||
2201 | vec<T, va_heap, vl_ptr>::lower_bound (T obj, | ||||
2202 | bool (*lessthan)(const T &, const T &)) | ||||
2203 | const | ||||
2204 | { | ||||
2205 | return m_vec ? m_vec->lower_bound (obj, lessthan) : 0; | ||||
2206 | } | ||||
2207 | |||||
2208 | /* Return true if SEARCH is an element of V. Note that this is O(N) in the | ||||
2209 | size of the vector and so should be used with care. */ | ||||
2210 | |||||
2211 | template<typename T> | ||||
2212 | inline bool | ||||
2213 | vec<T, va_heap, vl_ptr>::contains (const T &search) const | ||||
2214 | { | ||||
2215 | return m_vec ? m_vec->contains (search) : false; | ||||
2216 | } | ||||
2217 | |||||
2218 | /* Reverse content of the vector. */ | ||||
2219 | |||||
2220 | template<typename T> | ||||
2221 | inline void | ||||
2222 | vec<T, va_heap, vl_ptr>::reverse (void) | ||||
2223 | { | ||||
2224 | unsigned l = length (); | ||||
2225 | T *ptr = address (); | ||||
2226 | |||||
2227 | for (unsigned i = 0; i < l / 2; i++) | ||||
2228 | std::swap (ptr[i], ptr[l - i - 1]); | ||||
2229 | } | ||||
2230 | |||||
2231 | template<typename T> | ||||
2232 | inline bool | ||||
2233 | vec<T, va_heap, vl_ptr>::using_auto_storage () const | ||||
2234 | { | ||||
2235 | return m_vec ? m_vec->m_vecpfx.m_using_auto_storage : false; | ||||
2236 | } | ||||
2237 | |||||
2238 | /* Release VEC and call release of all element vectors. */ | ||||
2239 | |||||
2240 | template<typename T> | ||||
2241 | inline void | ||||
2242 | release_vec_vec (vec<vec<T> > &vec) | ||||
2243 | { | ||||
2244 | for (unsigned i = 0; i < vec.length (); i++) | ||||
2245 | vec[i].release (); | ||||
2246 | |||||
2247 | vec.release (); | ||||
2248 | } | ||||
2249 | |||||
2250 | // Provide a subset of the std::span functionality. (We can't use std::span | ||||
2251 | // itself because it's a C++20 feature.) | ||||
2252 | // | ||||
2253 | // In addition, provide an invalid value that is distinct from all valid | ||||
2254 | // sequences (including the empty sequence). This can be used to return | ||||
2255 | // failure without having to use std::optional. | ||||
2256 | // | ||||
2257 | // There is no operator bool because it would be ambiguous whether it is | ||||
2258 | // testing for a valid value or an empty sequence. | ||||
2259 | template<typename T> | ||||
2260 | class array_slice | ||||
2261 | { | ||||
2262 | template<typename OtherT> friend class array_slice; | ||||
2263 | |||||
2264 | public: | ||||
2265 | using value_type = T; | ||||
2266 | using iterator = T *; | ||||
2267 | using const_iterator = const T *; | ||||
2268 | |||||
2269 | array_slice () : m_base (nullptr), m_size (0) {} | ||||
2270 | |||||
2271 | template<typename OtherT> | ||||
2272 | array_slice (array_slice<OtherT> other) | ||||
2273 | : m_base (other.m_base), m_size (other.m_size) {} | ||||
2274 | |||||
2275 | array_slice (iterator base, unsigned int size) | ||||
2276 | : m_base (base), m_size (size) {} | ||||
2277 | |||||
2278 | template<size_t N> | ||||
2279 | array_slice (T (&array)[N]) : m_base (array), m_size (N) {} | ||||
2280 | |||||
2281 | template<typename OtherT> | ||||
2282 | array_slice (const vec<OtherT> &v) | ||||
2283 | : m_base (v.address ()), m_size (v.length ()) {} | ||||
2284 | |||||
2285 | template<typename OtherT> | ||||
2286 | array_slice (vec<OtherT> &v) | ||||
2287 | : m_base (v.address ()), m_size (v.length ()) {} | ||||
2288 | |||||
2289 | template<typename OtherT> | ||||
2290 | array_slice (const vec<OtherT, va_gc> *v) | ||||
2291 | : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} | ||||
2292 | |||||
2293 | template<typename OtherT> | ||||
2294 | array_slice (vec<OtherT, va_gc> *v) | ||||
2295 | : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} | ||||
2296 | |||||
2297 | iterator begin () { return m_base; } | ||||
2298 | iterator end () { return m_base + m_size; } | ||||
2299 | |||||
2300 | const_iterator begin () const { return m_base; } | ||||
2301 | const_iterator end () const { return m_base + m_size; } | ||||
2302 | |||||
2303 | value_type &front (); | ||||
2304 | value_type &back (); | ||||
2305 | value_type &operator[] (unsigned int i); | ||||
2306 | |||||
2307 | const value_type &front () const; | ||||
2308 | const value_type &back () const; | ||||
2309 | const value_type &operator[] (unsigned int i) const; | ||||
2310 | |||||
2311 | size_t size () const { return m_size; } | ||||
2312 | size_t size_bytes () const { return m_size * sizeof (T); } | ||||
2313 | bool empty () const { return m_size == 0; } | ||||
2314 | |||||
2315 | // An invalid array_slice that represents a failed operation. This is | ||||
2316 | // distinct from an empty slice, which is a valid result in some contexts. | ||||
2317 | static array_slice invalid () { return { nullptr, ~0U }; } | ||||
2318 | |||||
2319 | // True if the array is valid, false if it is an array like INVALID. | ||||
2320 | bool is_valid () const { return m_base || m_size == 0; } | ||||
2321 | |||||
2322 | private: | ||||
2323 | iterator m_base; | ||||
2324 | unsigned int m_size; | ||||
2325 | }; | ||||
2326 | |||||
2327 | template<typename T> | ||||
2328 | inline typename array_slice<T>::value_type & | ||||
2329 | array_slice<T>::front () | ||||
2330 | { | ||||
2331 | gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2331, __FUNCTION__), 0 : 0)); | ||||
2332 | return m_base[0]; | ||||
2333 | } | ||||
2334 | |||||
2335 | template<typename T> | ||||
2336 | inline const typename array_slice<T>::value_type & | ||||
2337 | array_slice<T>::front () const | ||||
2338 | { | ||||
2339 | gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2339, __FUNCTION__), 0 : 0)); | ||||
2340 | return m_base[0]; | ||||
2341 | } | ||||
2342 | |||||
2343 | template<typename T> | ||||
2344 | inline typename array_slice<T>::value_type & | ||||
2345 | array_slice<T>::back () | ||||
2346 | { | ||||
2347 | gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2347, __FUNCTION__), 0 : 0)); | ||||
2348 | return m_base[m_size - 1]; | ||||
2349 | } | ||||
2350 | |||||
2351 | template<typename T> | ||||
2352 | inline const typename array_slice<T>::value_type & | ||||
2353 | array_slice<T>::back () const | ||||
2354 | { | ||||
2355 | gcc_checking_assert (m_size)((void)(!(m_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2355, __FUNCTION__), 0 : 0)); | ||||
2356 | return m_base[m_size - 1]; | ||||
2357 | } | ||||
2358 | |||||
2359 | template<typename T> | ||||
2360 | inline typename array_slice<T>::value_type & | ||||
2361 | array_slice<T>::operator[] (unsigned int i) | ||||
2362 | { | ||||
2363 | gcc_checking_assert (i < m_size)((void)(!(i < m_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2363, __FUNCTION__), 0 : 0)); | ||||
2364 | return m_base[i]; | ||||
2365 | } | ||||
2366 | |||||
2367 | template<typename T> | ||||
2368 | inline const typename array_slice<T>::value_type & | ||||
2369 | array_slice<T>::operator[] (unsigned int i) const | ||||
2370 | { | ||||
2371 | gcc_checking_assert (i < m_size)((void)(!(i < m_size) ? fancy_abort ("/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/vec.h" , 2371, __FUNCTION__), 0 : 0)); | ||||
2372 | return m_base[i]; | ||||
2373 | } | ||||
2374 | |||||
2375 | template<typename T> | ||||
2376 | array_slice<T> | ||||
2377 | make_array_slice (T *base, unsigned int size) | ||||
2378 | { | ||||
2379 | return array_slice<T> (base, size); | ||||
2380 | } | ||||
2381 | |||||
2382 | #if (GCC_VERSION(4 * 1000 + 2) >= 3000) | ||||
2383 | # pragma GCC poison m_vec m_vecpfx m_vecdata | ||||
2384 | #endif | ||||
2385 | |||||
2386 | #endif // GCC_VEC_H |