OSDN Git Service

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