OSDN Git Service

[gcc/objc/ChangeLog]
[pf3gnuchains/gcc-fork.git] / gcc / objc / objc-act.h
1 /* Declarations for objc-act.c.
2    Copyright (C) 1990, 2000, 2001, 2002, 2003, 2004
3    Free Software Foundation, Inc.
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 2, 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 COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #ifndef GCC_OBJC_ACT_H
23 #define GCC_OBJC_ACT_H
24
25 /*** Language hooks ***/
26
27 bool objc_init (void);
28 const char *objc_printable_name (tree, int);
29 void objc_finish_file (void);
30 tree objc_fold_obj_type_ref (tree, tree);
31
32 /* NB: The remaining public functions are prototyped in c-common.h, for the
33    benefit of stub-objc.c and objc-act.c.  */
34
35 /* Objective-C structures */
36
37 #define CLASS_LANG_SLOT_ELTS            5
38 #define PROTOCOL_LANG_SLOT_ELTS         2
39
40 /* KEYWORD_DECL */
41 #define KEYWORD_KEY_NAME(DECL) ((DECL)->decl.name)
42 #define KEYWORD_ARG_NAME(DECL) ((DECL)->decl.arguments)
43
44 /* INSTANCE_METHOD_DECL, CLASS_METHOD_DECL */
45 #define METHOD_SEL_NAME(DECL) ((DECL)->decl.name)
46 #define METHOD_SEL_ARGS(DECL) ((DECL)->decl.arguments)
47 #define METHOD_ADD_ARGS(DECL) ((DECL)->decl.result)
48 #define METHOD_DEFINITION(DECL) ((DECL)->decl.initial)
49 #define METHOD_ENCODING(DECL) ((DECL)->decl.context)
50
51 /* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE,
52    CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE,
53    PROTOCOL_INTERFACE_TYPE */
54 #define CLASS_NAME(CLASS) ((CLASS)->type.name)
55 #define CLASS_SUPER_NAME(CLASS) (TYPE_CHECK (CLASS)->type.context)
56 #define CLASS_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 0)
57 #define CLASS_RAW_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 1)
58 #define CLASS_NST_METHODS(CLASS) ((CLASS)->type.minval)
59 #define CLASS_CLS_METHODS(CLASS) ((CLASS)->type.maxval)
60 #define CLASS_STATIC_TEMPLATE(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 2)
61 #define CLASS_CATEGORY_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 3)
62 #define CLASS_PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 4)
63 #define PROTOCOL_NAME(CLASS) ((CLASS)->type.name)
64 #define PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 0)
65 #define PROTOCOL_NST_METHODS(CLASS) ((CLASS)->type.minval)
66 #define PROTOCOL_CLS_METHODS(CLASS) ((CLASS)->type.maxval)
67 #define PROTOCOL_FORWARD_DECL(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 1)
68 #define PROTOCOL_DEFINED(CLASS) TREE_USED (CLASS)
69
70 /* We need to distinguish TYPE_PROTOCOL_LISTs from TYPE_CONTEXTs, both of which
71    are stored in the same accessor slot.  */
72 #define TYPE_PROTOCOL_LIST(TYPE)                                \
73         ((TYPE_CHECK (TYPE)->type.context                       \
74           && TREE_CODE ((TYPE)->type.context) == TREE_LIST)     \
75          ? (TYPE)->type.context : NULL_TREE)
76 #define SET_TYPE_PROTOCOL_LIST(TYPE, P) (TYPE_CHECK (TYPE)->type.context = (P))
77
78 #define TREE_STATIC_TEMPLATE(record_type) (TREE_PUBLIC (record_type))
79 #define TYPED_OBJECT(type) \
80        (TREE_CODE (type) == RECORD_TYPE && TREE_STATIC_TEMPLATE (type))
81 #define OBJC_TYPE_NAME(type) TYPE_NAME(type)
82 #define OBJC_SET_TYPE_NAME(type, name) (TYPE_NAME (type) = name)
83
84 /* Define the Objective-C or Objective-C++ language-specific tree codes.  */
85
86 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
87 enum objc_tree_code {
88 #if defined (GCC_CP_TREE_H)
89   LAST_BASE_TREE_CODE = LAST_CPLUS_TREE_CODE,
90 #else 
91 #if defined (GCC_C_TREE_H)
92   LAST_BASE_TREE_CODE = LAST_C_TREE_CODE,
93 #else
94   #error You must include <c-tree.h> or <cp/cp-tree.h> before <objc/objc-act.h>
95 #endif
96 #endif
97 #include "objc-tree.def"
98   LAST_OBJC_TREE_CODE
99 };
100 #undef DEFTREECODE
101
102 /* Hash tables to manage the global pool of method prototypes.  */
103
104 typedef struct hashed_entry     *hash;
105 typedef struct hashed_attribute *attr;
106
107 struct hashed_attribute GTY(())
108 {
109   attr next;
110   tree value;
111 };
112 struct hashed_entry GTY(())
113 {
114   attr list;
115   hash next;
116   tree key;
117 };
118
119 extern GTY ((length ("SIZEHASHTABLE"))) hash *nst_method_hash_list;
120 extern GTY ((length ("SIZEHASHTABLE"))) hash *cls_method_hash_list;
121
122 #define SIZEHASHTABLE           257
123
124 /* Objective-C/Objective-C++ @implementation list.  */
125
126 struct imp_entry GTY(())
127 {
128   struct imp_entry *next;
129   tree imp_context;
130   tree imp_template;
131   tree class_decl;              /* _OBJC_CLASS_<my_name>; */
132   tree meta_decl;               /* _OBJC_METACLASS_<my_name>; */
133 };
134
135 extern GTY(()) struct imp_entry *imp_list;
136 extern GTY(()) int imp_count;   /* `@implementation' */
137 extern GTY(()) int cat_count;   /* `@category' */
138
139 extern GTY(()) enum tree_code objc_inherit_code;
140 extern GTY(()) int objc_public_flag;
141
142 /* Objective-C/Objective-C++ global tree enumeration.  */
143
144 enum objc_tree_index
145 {
146     OCTI_STATIC_NST,
147     OCTI_STATIC_NST_DECL,
148     OCTI_SELF_ID,
149     OCTI_UCMD_ID,
150     OCTI_UNUSED_LIST,
151
152     OCTI_SELF_DECL,
153     OCTI_UMSG_DECL,
154     OCTI_UMSG_SUPER_DECL,
155     OCTI_UMSG_STRET_DECL,
156     OCTI_UMSG_SUPER_STRET_DECL,
157     OCTI_GET_CLASS_DECL,
158     OCTI_GET_MCLASS_DECL,
159     OCTI_SUPER_TYPE,
160     OCTI_SEL_TYPE,
161     OCTI_ID_TYPE,
162     OCTI_CLS_TYPE,
163     OCTI_NST_TYPE,
164     OCTI_PROTO_TYPE,
165
166     OCTI_CLS_CHAIN,
167     OCTI_ALIAS_CHAIN,
168     OCTI_INTF_CHAIN,
169     OCTI_PROTO_CHAIN,
170     OCTI_IMPL_CHAIN,
171     OCTI_CLS_REF_CHAIN,
172     OCTI_SEL_REF_CHAIN,
173     OCTI_IVAR_CHAIN,
174     OCTI_CLS_NAMES_CHAIN,
175     OCTI_METH_VAR_NAMES_CHAIN,
176     OCTI_METH_VAR_TYPES_CHAIN,
177
178     OCTI_SYMBOLS_DECL,
179     OCTI_NST_VAR_DECL,
180     OCTI_CLS_VAR_DECL,
181     OCTI_NST_METH_DECL,
182     OCTI_CLS_METH_DECL,
183     OCTI_CLS_DECL,
184     OCTI_MCLS_DECL,
185     OCTI_SEL_TABLE_DECL,
186     OCTI_MODULES_DECL,
187     OCTI_GNU_INIT_DECL,
188
189     OCTI_INTF_CTX,
190     OCTI_IMPL_CTX,
191     OCTI_METH_CTX,
192     OCTI_IVAR_CTX,
193
194     OCTI_IMPL_TEMPL,
195     OCTI_CLS_TEMPL,
196     OCTI_CAT_TEMPL,
197     OCTI_UPRIV_REC,
198     OCTI_PROTO_TEMPL,
199     OCTI_SEL_TEMPL,
200     OCTI_UCLS_SUPER_REF,
201     OCTI_UUCLS_SUPER_REF,
202     OCTI_METH_TEMPL,
203     OCTI_IVAR_TEMPL,
204     OCTI_SYMTAB_TEMPL,
205     OCTI_MODULE_TEMPL,
206     OCTI_SUPER_TEMPL,
207     OCTI_OBJ_REF,
208     OCTI_CLS_REF,
209     OCTI_METH_PROTO_TEMPL,
210     OCTI_FUNCTION1_TEMPL,
211     OCTI_FUNCTION2_TEMPL,
212
213     OCTI_OBJ_ID,
214     OCTI_CLS_ID,
215     OCTI_ID_NAME,
216     OCTI_CLASS_NAME,
217     OCTI_CNST_STR_ID,
218     OCTI_CNST_STR_TYPE,
219     OCTI_CNST_STR_GLOB_ID,
220     OCTI_STRING_CLASS_DECL,
221     OCTI_SUPER_DECL,
222     OCTI_UMSG_NONNIL_DECL,
223     OCTI_UMSG_NONNIL_STRET_DECL,
224     OCTI_STORAGE_CLS,
225     OCTI_EXCEPTION_EXTRACT_DECL,
226     OCTI_EXCEPTION_TRY_ENTER_DECL,
227     OCTI_EXCEPTION_TRY_EXIT_DECL,
228     OCTI_EXCEPTION_MATCH_DECL,
229     OCTI_EXCEPTION_THROW_DECL,
230     OCTI_SYNC_ENTER_DECL,
231     OCTI_SYNC_EXIT_DECL,
232     OCTI_SETJMP_DECL,
233     OCTI_EXCDATA_TEMPL,
234     OCTI_STACK_EXCEPTION_DATA_DECL,
235     OCTI_LOCAL_EXCEPTION_DECL,
236     OCTI_RETHROW_EXCEPTION_DECL,
237     OCTI_EVAL_ONCE_DECL,
238     OCTI_CATCH_TYPE,
239     OCTI_EXECCLASS_DECL,
240
241     OCTI_MAX
242 };
243
244 extern GTY(()) tree objc_global_trees[OCTI_MAX];
245
246 /* List of classes with list of their static instances.  */
247 #define objc_static_instances   objc_global_trees[OCTI_STATIC_NST]
248
249 /* The declaration of the array administrating the static instances.  */
250 #define static_instances_decl   objc_global_trees[OCTI_STATIC_NST_DECL]
251
252 /* Some commonly used instances of "identifier_node".  */
253
254 #define self_id                 objc_global_trees[OCTI_SELF_ID]
255 #define ucmd_id                 objc_global_trees[OCTI_UCMD_ID]
256 #define unused_list             objc_global_trees[OCTI_UNUSED_LIST]
257
258 #define self_decl               objc_global_trees[OCTI_SELF_DECL]
259 #define umsg_decl               objc_global_trees[OCTI_UMSG_DECL]
260 #define umsg_super_decl         objc_global_trees[OCTI_UMSG_SUPER_DECL]
261 #define umsg_stret_decl         objc_global_trees[OCTI_UMSG_STRET_DECL]
262 #define umsg_super_stret_decl   objc_global_trees[OCTI_UMSG_SUPER_STRET_DECL]
263 #define objc_get_class_decl     objc_global_trees[OCTI_GET_CLASS_DECL]
264 #define objc_get_meta_class_decl                        \
265                                 objc_global_trees[OCTI_GET_MCLASS_DECL]
266
267 #define objc_super_type         objc_global_trees[OCTI_SUPER_TYPE]
268 #define objc_selector_type              objc_global_trees[OCTI_SEL_TYPE]
269 #define objc_object_type        objc_global_trees[OCTI_ID_TYPE]
270 #define objc_class_type         objc_global_trees[OCTI_CLS_TYPE]
271 #define objc_instance_type      objc_global_trees[OCTI_NST_TYPE]
272 #define objc_protocol_type      objc_global_trees[OCTI_PROTO_TYPE]
273
274 /* Type checking macros.  */
275
276 #define IS_ID(TYPE) \
277   (POINTER_TYPE_P (TYPE) && TREE_TYPE (TYPE) == TREE_TYPE (objc_object_type))
278 #define IS_CLASS(TYPE) \
279   (POINTER_TYPE_P (TYPE) && TREE_TYPE (TYPE) == TREE_TYPE (objc_class_type))
280 #define IS_PROTOCOL_QUALIFIED_ID(TYPE) \
281   (IS_ID (TYPE) && TYPE_PROTOCOL_LIST (TYPE))
282 #define IS_SUPER(TYPE) \
283   (POINTER_TYPE_P (TYPE) && TREE_TYPE (TYPE) == objc_super_template)
284
285 #define class_chain             objc_global_trees[OCTI_CLS_CHAIN]
286 #define alias_chain             objc_global_trees[OCTI_ALIAS_CHAIN]
287 #define interface_chain         objc_global_trees[OCTI_INTF_CHAIN]
288 #define protocol_chain          objc_global_trees[OCTI_PROTO_CHAIN]
289 #define implemented_classes     objc_global_trees[OCTI_IMPL_CHAIN]
290
291 /* Chains to manage selectors that are referenced and defined in the
292    module.  */
293
294 #define cls_ref_chain           objc_global_trees[OCTI_CLS_REF_CHAIN]   /* Classes referenced.  */
295 #define sel_ref_chain           objc_global_trees[OCTI_SEL_REF_CHAIN]   /* Selectors referenced.  */
296 #define objc_ivar_chain         objc_global_trees[OCTI_IVAR_CHAIN]
297
298 /* Chains to manage uniquing of strings.  */
299
300 #define class_names_chain       objc_global_trees[OCTI_CLS_NAMES_CHAIN]
301 #define meth_var_names_chain    objc_global_trees[OCTI_METH_VAR_NAMES_CHAIN]
302 #define meth_var_types_chain    objc_global_trees[OCTI_METH_VAR_TYPES_CHAIN]
303
304
305 /* Backend data declarations.  */
306
307 #define UOBJC_SYMBOLS_decl              objc_global_trees[OCTI_SYMBOLS_DECL]
308 #define UOBJC_INSTANCE_VARIABLES_decl   objc_global_trees[OCTI_NST_VAR_DECL]
309 #define UOBJC_CLASS_VARIABLES_decl      objc_global_trees[OCTI_CLS_VAR_DECL]
310 #define UOBJC_INSTANCE_METHODS_decl     objc_global_trees[OCTI_NST_METH_DECL]
311 #define UOBJC_CLASS_METHODS_decl        objc_global_trees[OCTI_CLS_METH_DECL]
312 #define UOBJC_CLASS_decl                objc_global_trees[OCTI_CLS_DECL]
313 #define UOBJC_METACLASS_decl            objc_global_trees[OCTI_MCLS_DECL]
314 #define UOBJC_SELECTOR_TABLE_decl       objc_global_trees[OCTI_SEL_TABLE_DECL]
315 #define UOBJC_MODULES_decl              objc_global_trees[OCTI_MODULES_DECL]
316 #define GNU_INIT_decl                   objc_global_trees[OCTI_GNU_INIT_DECL]
317
318 /* The following are used when compiling a class implementation.
319    implementation_template will normally be an interface, however if
320    none exists this will be equal to objc_implementation_context...it is
321    set in start_class.  */
322
323 #define objc_interface_context          objc_global_trees[OCTI_INTF_CTX]
324 #define objc_implementation_context     objc_global_trees[OCTI_IMPL_CTX]
325 #define objc_method_context             objc_global_trees[OCTI_METH_CTX]
326 #define objc_ivar_context               objc_global_trees[OCTI_IVAR_CTX]
327
328 #define implementation_template objc_global_trees[OCTI_IMPL_TEMPL]
329 #define objc_class_template     objc_global_trees[OCTI_CLS_TEMPL]
330 #define objc_category_template  objc_global_trees[OCTI_CAT_TEMPL]
331 #define uprivate_record         objc_global_trees[OCTI_UPRIV_REC]
332 #define objc_protocol_template  objc_global_trees[OCTI_PROTO_TEMPL]
333 #define objc_selector_template  objc_global_trees[OCTI_SEL_TEMPL]
334 #define ucls_super_ref          objc_global_trees[OCTI_UCLS_SUPER_REF]
335 #define uucls_super_ref         objc_global_trees[OCTI_UUCLS_SUPER_REF]
336
337 #define umsg_nonnil_decl        objc_global_trees[OCTI_UMSG_NONNIL_DECL]
338 #define umsg_nonnil_stret_decl  objc_global_trees[OCTI_UMSG_NONNIL_STRET_DECL]
339 #define objc_storage_class      objc_global_trees[OCTI_STORAGE_CLS]
340 #define objc_exception_extract_decl             \
341                                 objc_global_trees[OCTI_EXCEPTION_EXTRACT_DECL]
342 #define objc_exception_try_enter_decl           \
343                                 objc_global_trees[OCTI_EXCEPTION_TRY_ENTER_DECL]
344 #define objc_exception_try_exit_decl            \
345                                 objc_global_trees[OCTI_EXCEPTION_TRY_EXIT_DECL]
346 #define objc_exception_match_decl               \
347                                 objc_global_trees[OCTI_EXCEPTION_MATCH_DECL]
348 #define objc_exception_throw_decl               \
349                                 objc_global_trees[OCTI_EXCEPTION_THROW_DECL]
350 #define objc_sync_enter_decl    objc_global_trees[OCTI_SYNC_ENTER_DECL]
351 #define objc_sync_exit_decl     objc_global_trees[OCTI_SYNC_EXIT_DECL]
352 #define objc_exception_data_template            \
353                                 objc_global_trees[OCTI_EXCDATA_TEMPL]
354 #define objc_setjmp_decl        objc_global_trees[OCTI_SETJMP_DECL]
355 #define objc_stack_exception_data               \
356                                 objc_global_trees[OCTI_STACK_EXCEPTION_DATA_DECL]
357 #define objc_caught_exception   objc_global_trees[OCTI_LOCAL_EXCEPTION_DECL]    
358 #define objc_rethrow_exception  objc_global_trees[OCTI_RETHROW_EXCEPTION_DECL]  
359 #define objc_eval_once          objc_global_trees[OCTI_EVAL_ONCE_DECL]  
360 #define objc_catch_type         objc_global_trees[OCTI_CATCH_TYPE]
361
362 #define execclass_decl          objc_global_trees[OCTI_EXECCLASS_DECL]
363
364 #define objc_method_template    objc_global_trees[OCTI_METH_TEMPL]
365 #define objc_ivar_template      objc_global_trees[OCTI_IVAR_TEMPL]
366 #define objc_symtab_template    objc_global_trees[OCTI_SYMTAB_TEMPL]
367 #define objc_module_template    objc_global_trees[OCTI_MODULE_TEMPL]
368 #define objc_super_template     objc_global_trees[OCTI_SUPER_TEMPL]
369 #define objc_object_reference   objc_global_trees[OCTI_OBJ_REF]
370 #define objc_class_reference    objc_global_trees[OCTI_CLS_REF]
371 #define objc_method_prototype_template          \
372                                 objc_global_trees[OCTI_METH_PROTO_TEMPL]
373 #define function1_template      objc_global_trees[OCTI_FUNCTION1_TEMPL]
374 #define function2_template      objc_global_trees[OCTI_FUNCTION2_TEMPL]
375
376 #define objc_object_id          objc_global_trees[OCTI_OBJ_ID]
377 #define objc_class_id           objc_global_trees[OCTI_CLS_ID]
378 #define objc_object_name                objc_global_trees[OCTI_ID_NAME]
379 #define objc_class_name         objc_global_trees[OCTI_CLASS_NAME]
380 #define constant_string_id      objc_global_trees[OCTI_CNST_STR_ID]
381 #define constant_string_type    objc_global_trees[OCTI_CNST_STR_TYPE]
382 #define constant_string_global_id               \
383                                 objc_global_trees[OCTI_CNST_STR_GLOB_ID]
384 #define string_class_decl       objc_global_trees[OCTI_STRING_CLASS_DECL]
385 #define UOBJC_SUPER_decl        objc_global_trees[OCTI_SUPER_DECL]
386
387 #endif /* GCC_OBJC_ACT_H */