2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / objc / objc-act.h
blobabbf65627311ed50554252ae5d71bc727857939a
1 /* Declarations for objc-act.c.
2 Copyright (C) 1990, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GCC.
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 2, or (at your option)
10 any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #ifndef GCC_OBJC_ACT_H
23 #define GCC_OBJC_ACT_H
25 /*** Public Interface (procedures) ***/
27 bool objc_init (void);
28 const char *objc_printable_name (tree, int);
30 /* used by yyparse */
32 void finish_file (void);
33 tree start_class (enum tree_code, tree, tree, tree);
34 tree continue_class (tree);
35 void finish_class (tree);
36 void start_method_def (tree);
37 void continue_method_def (void);
38 void finish_method_def (void);
39 tree start_protocol (enum tree_code, tree, tree);
40 void finish_protocol (tree);
42 tree objc_build_throw_stmt (tree);
43 tree objc_build_try_catch_finally_stmt (int, int);
44 void objc_build_synchronized_prologue (tree);
45 tree objc_build_synchronized_epilogue (void);
46 tree objc_build_try_prologue (void);
47 void objc_build_try_epilogue (int);
48 void objc_build_catch_stmt (tree);
49 void objc_build_catch_epilogue (void);
50 tree objc_build_finally_prologue (void);
51 tree objc_build_finally_epilogue (void);
53 tree is_ivar (tree, tree);
54 int is_private (tree);
55 int is_public (tree, tree);
56 tree add_instance_variable (tree, int, tree, tree, tree);
57 tree objc_add_method (tree, tree, int);
58 tree get_super_receiver (void);
59 void objc_clear_super_receiver (void);
60 tree get_class_ivars_from_name (tree);
61 tree get_class_reference (tree);
62 tree get_static_reference (tree, tree);
63 tree get_object_reference (tree);
64 tree build_message_expr (tree);
65 tree finish_message_expr (tree, tree, tree);
66 tree build_selector_expr (tree);
67 tree build_ivar_reference (tree);
68 tree build_keyword_decl (tree, tree, tree);
69 tree build_method_decl (enum tree_code, tree, tree, tree);
70 tree build_protocol_expr (tree);
71 tree build_objc_string_object (tree);
73 void objc_declare_alias (tree, tree);
74 void objc_declare_class (tree);
75 void objc_declare_protocols (tree);
77 /* the following routines are used to implement statically typed objects */
79 int objc_comptypes (tree, tree, int);
80 void objc_check_decl (tree);
82 /* NeXT extensions */
84 tree build_encode_expr (tree);
86 /* Objective-C structures */
88 #define CLASS_BINFO_ELTS 6
89 #define PROTOCOL_BINFO_ELTS 2
91 /* KEYWORD_DECL */
92 #define KEYWORD_KEY_NAME(DECL) ((DECL)->decl.name)
93 #define KEYWORD_ARG_NAME(DECL) ((DECL)->decl.arguments)
95 /* INSTANCE_METHOD_DECL, CLASS_METHOD_DECL */
96 #define METHOD_SEL_NAME(DECL) ((DECL)->decl.name)
97 #define METHOD_SEL_ARGS(DECL) ((DECL)->decl.arguments)
98 #define METHOD_ADD_ARGS(DECL) ((DECL)->decl.result)
99 #define METHOD_DEFINITION(DECL) ((DECL)->decl.initial)
100 #define METHOD_ENCODING(DECL) ((DECL)->decl.context)
102 /* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE,
103 CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE,
104 PROTOCOL_INTERFACE_TYPE */
105 #define CLASS_NAME(CLASS) ((CLASS)->type.name)
106 #define CLASS_SUPER_NAME(CLASS) (TYPE_CHECK (CLASS)->type.context)
107 #define CLASS_IVARS(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 0)
108 #define CLASS_RAW_IVARS(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 1)
109 #define CLASS_NST_METHODS(CLASS) ((CLASS)->type.minval)
110 #define CLASS_CLS_METHODS(CLASS) ((CLASS)->type.maxval)
111 #define CLASS_STATIC_TEMPLATE(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 2)
112 #define CLASS_CATEGORY_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 3)
113 #define CLASS_PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 4)
114 #define CLASS_OWN_IVARS(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 5)
115 #define PROTOCOL_NAME(CLASS) ((CLASS)->type.name)
116 #define PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 0)
117 #define PROTOCOL_NST_METHODS(CLASS) ((CLASS)->type.minval)
118 #define PROTOCOL_CLS_METHODS(CLASS) ((CLASS)->type.maxval)
119 #define PROTOCOL_FORWARD_DECL(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 1)
120 #define PROTOCOL_DEFINED(CLASS) TREE_USED (CLASS)
121 /* We need to distinguish TYPE_PROTOCOL_LISTs from TYPE_CONTEXTs, both of which
122 are stored in the same accessor slot. */
123 #define TYPE_PROTOCOL_LIST(TYPE) \
124 ((TYPE_CHECK (TYPE)->type.context \
125 && TREE_CODE ((TYPE)->type.context) == TREE_LIST) \
126 ? (TYPE)->type.context : NULL_TREE)
127 #define SET_TYPE_PROTOCOL_LIST(TYPE, P) (TYPE_CHECK (TYPE)->type.context = (P))
129 /* Set by `continue_class' and checked by `is_public'. */
131 #define TREE_STATIC_TEMPLATE(record_type) (TREE_PUBLIC (record_type))
132 #define TYPED_OBJECT(type) \
133 (TREE_CODE (type) == RECORD_TYPE && TREE_STATIC_TEMPLATE (type))
134 #define OBJC_TYPE_NAME(type) TYPE_NAME(type)
136 /* Define the Objective-C or Objective-C++ language-specific tree codes. */
138 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
139 enum objc_tree_code {
140 #if defined (GCC_CP_TREE_H)
141 LAST_BASE_TREE_CODE = LAST_CPLUS_TREE_CODE,
142 #else
143 #if defined (GCC_C_TREE_H)
144 LAST_BASE_TREE_CODE = LAST_C_TREE_CODE,
145 #else
146 #error You must include <c-tree.h> or <cp/cp-tree.h> before <objc/objc-act.h>
147 #endif
148 #endif
149 #include "objc-tree.def"
150 LAST_OBJC_TREE_CODE
152 #undef DEFTREECODE
154 /* Hash tables to manage the global pool of method prototypes. */
156 typedef struct hashed_entry *hash;
157 typedef struct hashed_attribute *attr;
159 struct hashed_attribute GTY(())
161 attr next;
162 tree value;
164 struct hashed_entry GTY(())
166 attr list;
167 hash next;
168 tree key;
171 extern GTY ((length ("SIZEHASHTABLE"))) hash *nst_method_hash_list;
172 extern GTY ((length ("SIZEHASHTABLE"))) hash *cls_method_hash_list;
174 #define SIZEHASHTABLE 257
176 /* Objective-C/Objective-C++ @implementation list. */
178 struct imp_entry GTY(())
180 struct imp_entry *next;
181 tree imp_context;
182 tree imp_template;
183 tree class_decl; /* _OBJC_CLASS_<my_name>; */
184 tree meta_decl; /* _OBJC_METACLASS_<my_name>; */
187 extern GTY(()) struct imp_entry *imp_list;
188 extern int imp_count; /* `@implementation' */
189 extern int cat_count; /* `@category' */
191 /* Objective-C/Objective-C++ global tree enumeration. */
193 enum objc_tree_index
195 OCTI_STATIC_NST,
196 OCTI_STATIC_NST_DECL,
197 OCTI_SELF_ID,
198 OCTI_UCMD_ID,
199 OCTI_UNUSED_LIST,
200 OCTI_ELLIPSIS_NODE,
202 OCTI_SELF_DECL,
203 OCTI_UMSG_DECL,
204 OCTI_UMSG_SUPER_DECL,
205 OCTI_UMSG_STRET_DECL,
206 OCTI_UMSG_SUPER_STRET_DECL,
207 OCTI_GET_CLASS_DECL,
208 OCTI_GET_MCLASS_DECL,
209 OCTI_SUPER_TYPE,
210 OCTI_SEL_TYPE,
211 OCTI_ID_TYPE,
212 OCTI_CLS_TYPE,
213 OCTI_NST_TYPE,
214 OCTI_PROTO_TYPE,
216 OCTI_CLS_CHAIN,
217 OCTI_ALIAS_CHAIN,
218 OCTI_INTF_CHAIN,
219 OCTI_PROTO_CHAIN,
220 OCTI_IMPL_CHAIN,
221 OCTI_CLS_REF_CHAIN,
222 OCTI_SEL_REF_CHAIN,
223 OCTI_IVAR_CHAIN,
224 OCTI_CLS_NAMES_CHAIN,
225 OCTI_METH_VAR_NAMES_CHAIN,
226 OCTI_METH_VAR_TYPES_CHAIN,
228 OCTI_SYMBOLS_DECL,
229 OCTI_NST_VAR_DECL,
230 OCTI_CLS_VAR_DECL,
231 OCTI_NST_METH_DECL,
232 OCTI_CLS_METH_DECL,
233 OCTI_CLS_DECL,
234 OCTI_MCLS_DECL,
235 OCTI_SEL_TABLE_DECL,
236 OCTI_MODULES_DECL,
237 OCTI_STRG_DECL,
239 OCTI_INTF_CTX,
240 OCTI_IMPL_CTX,
241 OCTI_METH_CTX,
242 OCTI_IVAR_CTX,
244 OCTI_IMPL_TEMPL,
245 OCTI_CLS_TEMPL,
246 OCTI_CAT_TEMPL,
247 OCTI_UPRIV_REC,
248 OCTI_PROTO_TEMPL,
249 OCTI_SEL_TEMPL,
250 OCTI_UCLS_SUPER_REF,
251 OCTI_UUCLS_SUPER_REF,
252 OCTI_METH_TEMPL,
253 OCTI_IVAR_TEMPL,
254 OCTI_SYMTAB_TEMPL,
255 OCTI_MODULE_TEMPL,
256 OCTI_SUPER_TEMPL,
257 OCTI_OBJ_REF,
258 OCTI_METH_PROTO_TEMPL,
259 OCTI_FUNCTION1_TEMPL,
260 OCTI_FUNCTION2_TEMPL,
262 OCTI_OBJ_ID,
263 OCTI_CLS_ID,
264 OCTI_ID_ID,
265 OCTI_CNST_STR_ID,
266 OCTI_CNST_STR_TYPE,
267 OCTI_CNST_STR_GLOB_ID,
268 OCTI_STRING_CLASS_DECL,
269 OCTI_SUPER_DECL,
270 OCTI_UMSG_NONNIL_DECL,
271 OCTI_UMSG_NONNIL_STRET_DECL,
272 OCTI_STORAGE_CLS,
273 OCTI_EXCEPTION_EXTRACT_DECL,
274 OCTI_EXCEPTION_TRY_ENTER_DECL,
275 OCTI_EXCEPTION_TRY_EXIT_DECL,
276 OCTI_EXCEPTION_MATCH_DECL,
277 OCTI_EXCEPTION_THROW_DECL,
278 OCTI_SYNC_ENTER_DECL,
279 OCTI_SYNC_EXIT_DECL,
280 OCTI_SETJMP_DECL,
281 OCTI_EXCDATA_TEMPL,
282 OCTI_STACK_EXCEPTION_DATA_DECL,
283 OCTI_LOCAL_EXCEPTION_DECL,
284 OCTI_RETHROW_EXCEPTION_DECL,
285 OCTI_EVAL_ONCE_DECL,
286 OCTI_EXCEPTION_BLK_STACK,
287 OCTI_CATCH_TYPE,
289 OCTI_MAX
292 extern GTY(()) tree objc_global_trees[OCTI_MAX];
294 /* List of classes with list of their static instances. */
295 #define objc_static_instances objc_global_trees[OCTI_STATIC_NST]
297 /* The declaration of the array administrating the static instances. */
298 #define static_instances_decl objc_global_trees[OCTI_STATIC_NST_DECL]
300 /* Some commonly used instances of "identifier_node". */
302 #define self_id objc_global_trees[OCTI_SELF_ID]
303 #define ucmd_id objc_global_trees[OCTI_UCMD_ID]
304 #define unused_list objc_global_trees[OCTI_UNUSED_LIST]
305 #define objc_ellipsis_node objc_global_trees[OCTI_ELLIPSIS_NODE]
307 #define self_decl objc_global_trees[OCTI_SELF_DECL]
308 #define umsg_decl objc_global_trees[OCTI_UMSG_DECL]
309 #define umsg_super_decl objc_global_trees[OCTI_UMSG_SUPER_DECL]
310 #define umsg_stret_decl objc_global_trees[OCTI_UMSG_STRET_DECL]
311 #define umsg_super_stret_decl objc_global_trees[OCTI_UMSG_SUPER_STRET_DECL]
312 #define objc_get_class_decl objc_global_trees[OCTI_GET_CLASS_DECL]
313 #define objc_get_meta_class_decl \
314 objc_global_trees[OCTI_GET_MCLASS_DECL]
316 #define super_type objc_global_trees[OCTI_SUPER_TYPE]
317 #define selector_type objc_global_trees[OCTI_SEL_TYPE]
318 #define id_type objc_global_trees[OCTI_ID_TYPE]
319 #define objc_class_type objc_global_trees[OCTI_CLS_TYPE]
320 #define instance_type objc_global_trees[OCTI_NST_TYPE]
321 #define protocol_type objc_global_trees[OCTI_PROTO_TYPE]
323 /* Type checking macros. */
325 #define IS_ID(TYPE) \
326 (TYPE_MAIN_VARIANT (TYPE) == TYPE_MAIN_VARIANT (id_type))
327 #define IS_PROTOCOL_QUALIFIED_ID(TYPE) \
328 (IS_ID (TYPE) && TYPE_PROTOCOL_LIST (TYPE))
329 #define IS_SUPER(TYPE) \
330 (TREE_CODE (TYPE) == POINTER_TYPE && TREE_TYPE (TYPE) == objc_super_template)
332 #define class_chain objc_global_trees[OCTI_CLS_CHAIN]
333 #define alias_chain objc_global_trees[OCTI_ALIAS_CHAIN]
334 #define interface_chain objc_global_trees[OCTI_INTF_CHAIN]
335 #define protocol_chain objc_global_trees[OCTI_PROTO_CHAIN]
336 #define implemented_classes objc_global_trees[OCTI_IMPL_CHAIN]
338 /* Chains to manage selectors that are referenced and defined in the
339 module. */
341 #define cls_ref_chain objc_global_trees[OCTI_CLS_REF_CHAIN] /* Classes referenced. */
342 #define sel_ref_chain objc_global_trees[OCTI_SEL_REF_CHAIN] /* Selectors referenced. */
343 #define objc_ivar_chain objc_global_trees[OCTI_IVAR_CHAIN]
345 /* Chains to manage uniquing of strings. */
347 #define class_names_chain objc_global_trees[OCTI_CLS_NAMES_CHAIN]
348 #define meth_var_names_chain objc_global_trees[OCTI_METH_VAR_NAMES_CHAIN]
349 #define meth_var_types_chain objc_global_trees[OCTI_METH_VAR_TYPES_CHAIN]
352 /* Backend data declarations. */
354 #define UOBJC_SYMBOLS_decl objc_global_trees[OCTI_SYMBOLS_DECL]
355 #define UOBJC_INSTANCE_VARIABLES_decl objc_global_trees[OCTI_NST_VAR_DECL]
356 #define UOBJC_CLASS_VARIABLES_decl objc_global_trees[OCTI_CLS_VAR_DECL]
357 #define UOBJC_INSTANCE_METHODS_decl objc_global_trees[OCTI_NST_METH_DECL]
358 #define UOBJC_CLASS_METHODS_decl objc_global_trees[OCTI_CLS_METH_DECL]
359 #define UOBJC_CLASS_decl objc_global_trees[OCTI_CLS_DECL]
360 #define UOBJC_METACLASS_decl objc_global_trees[OCTI_MCLS_DECL]
361 #define UOBJC_SELECTOR_TABLE_decl objc_global_trees[OCTI_SEL_TABLE_DECL]
362 #define UOBJC_MODULES_decl objc_global_trees[OCTI_MODULES_DECL]
363 #define UOBJC_STRINGS_decl objc_global_trees[OCTI_STRG_DECL]
365 /* The following are used when compiling a class implementation.
366 implementation_template will normally be an interface, however if
367 none exists this will be equal to objc_implementation_context...it is
368 set in start_class. */
370 #define objc_interface_context objc_global_trees[OCTI_INTF_CTX]
371 #define objc_implementation_context objc_global_trees[OCTI_IMPL_CTX]
372 #define objc_method_context objc_global_trees[OCTI_METH_CTX]
373 #define objc_ivar_context objc_global_trees[OCTI_IVAR_CTX]
375 #define implementation_template objc_global_trees[OCTI_IMPL_TEMPL]
376 #define objc_class_template objc_global_trees[OCTI_CLS_TEMPL]
377 #define objc_category_template objc_global_trees[OCTI_CAT_TEMPL]
378 #define uprivate_record objc_global_trees[OCTI_UPRIV_REC]
379 #define objc_protocol_template objc_global_trees[OCTI_PROTO_TEMPL]
380 #define objc_selector_template objc_global_trees[OCTI_SEL_TEMPL]
381 #define ucls_super_ref objc_global_trees[OCTI_UCLS_SUPER_REF]
382 #define uucls_super_ref objc_global_trees[OCTI_UUCLS_SUPER_REF]
384 #define umsg_nonnil_decl objc_global_trees[OCTI_UMSG_NONNIL_DECL]
385 #define umsg_nonnil_stret_decl objc_global_trees[OCTI_UMSG_NONNIL_STRET_DECL]
386 #define objc_storage_class objc_global_trees[OCTI_STORAGE_CLS]
387 #define objc_exception_extract_decl \
388 objc_global_trees[OCTI_EXCEPTION_EXTRACT_DECL]
389 #define objc_exception_try_enter_decl \
390 objc_global_trees[OCTI_EXCEPTION_TRY_ENTER_DECL]
391 #define objc_exception_try_exit_decl \
392 objc_global_trees[OCTI_EXCEPTION_TRY_EXIT_DECL]
393 #define objc_exception_match_decl \
394 objc_global_trees[OCTI_EXCEPTION_MATCH_DECL]
395 #define objc_exception_throw_decl \
396 objc_global_trees[OCTI_EXCEPTION_THROW_DECL]
397 #define objc_sync_enter_decl objc_global_trees[OCTI_SYNC_ENTER_DECL]
398 #define objc_sync_exit_decl objc_global_trees[OCTI_SYNC_EXIT_DECL]
399 #define objc_exception_data_template \
400 objc_global_trees[OCTI_EXCDATA_TEMPL]
401 #define objc_setjmp_decl objc_global_trees[OCTI_SETJMP_DECL]
402 #define objc_stack_exception_data \
403 objc_global_trees[OCTI_STACK_EXCEPTION_DATA_DECL]
404 #define objc_caught_exception objc_global_trees[OCTI_LOCAL_EXCEPTION_DECL]
405 #define objc_rethrow_exception objc_global_trees[OCTI_RETHROW_EXCEPTION_DECL]
406 #define objc_eval_once objc_global_trees[OCTI_EVAL_ONCE_DECL]
407 #define objc_exception_block_stack \
408 objc_global_trees[OCTI_EXCEPTION_BLK_STACK]
409 #define objc_catch_type objc_global_trees[OCTI_CATCH_TYPE]
411 #define objc_method_template objc_global_trees[OCTI_METH_TEMPL]
412 #define objc_ivar_template objc_global_trees[OCTI_IVAR_TEMPL]
413 #define objc_symtab_template objc_global_trees[OCTI_SYMTAB_TEMPL]
414 #define objc_module_template objc_global_trees[OCTI_MODULE_TEMPL]
415 #define objc_super_template objc_global_trees[OCTI_SUPER_TEMPL]
416 #define objc_object_reference objc_global_trees[OCTI_OBJ_REF]
417 #define objc_method_prototype_template \
418 objc_global_trees[OCTI_METH_PROTO_TEMPL]
419 #define function1_template objc_global_trees[OCTI_FUNCTION1_TEMPL]
420 #define function2_template objc_global_trees[OCTI_FUNCTION2_TEMPL]
422 #define objc_object_id objc_global_trees[OCTI_OBJ_ID]
423 #define objc_class_id objc_global_trees[OCTI_CLS_ID]
424 #define objc_id_id objc_global_trees[OCTI_ID_ID]
425 #define constant_string_id objc_global_trees[OCTI_CNST_STR_ID]
426 #define constant_string_type objc_global_trees[OCTI_CNST_STR_TYPE]
427 #define constant_string_global_id \
428 objc_global_trees[OCTI_CNST_STR_GLOB_ID]
429 #define string_class_decl objc_global_trees[OCTI_STRING_CLASS_DECL]
430 #define UOBJC_SUPER_decl objc_global_trees[OCTI_SUPER_DECL]
432 #endif /* GCC_OBJC_ACT_H */