1 /* Declarations for objc-act.c.
2 Copyright (C) 1990, 2000, 2001, 2002, 2003, 2004
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)
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 /*** Language hooks ***/
27 bool objc_init (void);
28 const char *objc_printable_name (tree
, int);
29 void objc_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 void objc_begin_try_stmt (location_t
, tree
);
44 void objc_begin_catch_clause (tree
);
45 void objc_finish_catch_clause (void);
46 void objc_build_finally_clause (location_t
, tree
);
47 void objc_finish_try_stmt (void);
48 void objc_build_synchronized (location_t
, tree
, tree
);
50 tree
is_ivar (tree
, tree
);
51 int is_private (tree
);
52 int objc_is_public (tree
, tree
);
53 tree
add_instance_variable (tree
, int, tree
, tree
, tree
);
54 tree
objc_add_method (tree
, tree
, int);
55 tree
get_super_receiver (void);
56 void objc_clear_super_receiver (void);
57 tree
get_class_ivars_from_name (tree
);
58 tree
get_class_reference (tree
);
59 tree
get_static_reference (tree
, tree
);
60 tree
get_protocol_reference (tree
);
61 tree
build_message_expr (tree
);
62 tree
finish_message_expr (tree
, tree
, tree
);
63 tree
build_selector_expr (tree
);
64 tree
build_ivar_reference (tree
);
65 tree
build_keyword_decl (tree
, tree
, tree
);
66 tree
build_method_decl (enum tree_code
, tree
, tree
, tree
);
67 tree
build_protocol_expr (tree
);
68 tree
build_objc_string_object (tree
);
70 void objc_declare_alias (tree
, tree
);
71 void objc_declare_class (tree
);
72 void objc_declare_protocols (tree
);
74 /* the following routines are used to implement statically typed objects */
76 int objc_comptypes (tree
, tree
, int);
77 void objc_check_decl (tree
);
81 tree
build_encode_expr (tree
);
83 /* Objective-C structures */
85 #define CLASS_LANG_SLOT_ELTS 6
86 #define PROTOCOL_LANG_SLOT_ELTS 2
89 #define KEYWORD_KEY_NAME(DECL) ((DECL)->decl.name)
90 #define KEYWORD_ARG_NAME(DECL) ((DECL)->decl.arguments)
92 /* INSTANCE_METHOD_DECL, CLASS_METHOD_DECL */
93 #define METHOD_SEL_NAME(DECL) ((DECL)->decl.name)
94 #define METHOD_SEL_ARGS(DECL) ((DECL)->decl.arguments)
95 #define METHOD_ADD_ARGS(DECL) ((DECL)->decl.result)
96 #define METHOD_DEFINITION(DECL) ((DECL)->decl.initial)
97 #define METHOD_ENCODING(DECL) ((DECL)->decl.context)
99 /* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE,
100 CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE,
101 PROTOCOL_INTERFACE_TYPE */
102 #define CLASS_NAME(CLASS) ((CLASS)->type.name)
103 #define CLASS_SUPER_NAME(CLASS) (TYPE_CHECK (CLASS)->type.context)
104 #define CLASS_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 0)
105 #define CLASS_RAW_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 1)
106 #define CLASS_NST_METHODS(CLASS) ((CLASS)->type.minval)
107 #define CLASS_CLS_METHODS(CLASS) ((CLASS)->type.maxval)
108 #define CLASS_STATIC_TEMPLATE(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 2)
109 #define CLASS_CATEGORY_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 3)
110 #define CLASS_PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 4)
111 #define CLASS_OWN_IVARS(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 5)
112 #define PROTOCOL_NAME(CLASS) ((CLASS)->type.name)
113 #define PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 0)
114 #define PROTOCOL_NST_METHODS(CLASS) ((CLASS)->type.minval)
115 #define PROTOCOL_CLS_METHODS(CLASS) ((CLASS)->type.maxval)
116 #define PROTOCOL_FORWARD_DECL(CLASS) TREE_VEC_ELT (TYPE_LANG_SLOT_1 (CLASS), 1)
117 #define PROTOCOL_DEFINED(CLASS) TREE_USED (CLASS)
118 /* We need to distinguish TYPE_PROTOCOL_LISTs from TYPE_CONTEXTs, both of which
119 are stored in the same accessor slot. */
120 #define TYPE_PROTOCOL_LIST(TYPE) \
121 ((TYPE_CHECK (TYPE)->type.context \
122 && TREE_CODE ((TYPE)->type.context) == TREE_LIST) \
123 ? (TYPE)->type.context : NULL_TREE)
124 #define SET_TYPE_PROTOCOL_LIST(TYPE, P) (TYPE_CHECK (TYPE)->type.context = (P))
126 /* Set by `continue_class' and checked by `objc_is_public'. */
128 #define TREE_STATIC_TEMPLATE(record_type) (TREE_PUBLIC (record_type))
129 #define TYPED_OBJECT(type) \
130 (TREE_CODE (type) == RECORD_TYPE && TREE_STATIC_TEMPLATE (type))
131 #define OBJC_TYPE_NAME(type) TYPE_NAME(type)
133 /* Define the Objective-C or Objective-C++ language-specific tree codes. */
135 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
136 enum objc_tree_code
{
137 #if defined (GCC_CP_TREE_H)
138 LAST_BASE_TREE_CODE
= LAST_CPLUS_TREE_CODE
,
140 #if defined (GCC_C_TREE_H)
141 LAST_BASE_TREE_CODE
= LAST_C_TREE_CODE
,
143 #error You must include <c-tree.h> or <cp/cp-tree.h> before <objc/objc-act.h>
146 #include "objc-tree.def"
151 /* Hash tables to manage the global pool of method prototypes. */
153 typedef struct hashed_entry
*hash
;
154 typedef struct hashed_attribute
*attr
;
156 struct hashed_attribute
GTY(())
161 struct hashed_entry
GTY(())
168 extern GTY ((length ("SIZEHASHTABLE"))) hash
*nst_method_hash_list
;
169 extern GTY ((length ("SIZEHASHTABLE"))) hash
*cls_method_hash_list
;
171 #define SIZEHASHTABLE 257
173 /* Objective-C/Objective-C++ @implementation list. */
175 struct imp_entry
GTY(())
177 struct imp_entry
*next
;
180 tree class_decl
; /* _OBJC_CLASS_<my_name>; */
181 tree meta_decl
; /* _OBJC_METACLASS_<my_name>; */
184 extern GTY(()) struct imp_entry
*imp_list
;
185 extern int imp_count
; /* `@implementation' */
186 extern int cat_count
; /* `@category' */
188 /* Objective-C/Objective-C++ global tree enumeration. */
193 OCTI_STATIC_NST_DECL
,
201 OCTI_UMSG_SUPER_DECL
,
202 OCTI_UMSG_STRET_DECL
,
203 OCTI_UMSG_SUPER_STRET_DECL
,
205 OCTI_GET_MCLASS_DECL
,
221 OCTI_CLS_NAMES_CHAIN
,
222 OCTI_METH_VAR_NAMES_CHAIN
,
223 OCTI_METH_VAR_TYPES_CHAIN
,
247 OCTI_UUCLS_SUPER_REF
,
254 OCTI_METH_PROTO_TEMPL
,
255 OCTI_FUNCTION1_TEMPL
,
256 OCTI_FUNCTION2_TEMPL
,
263 OCTI_CNST_STR_GLOB_ID
,
264 OCTI_STRING_CLASS_DECL
,
266 OCTI_UMSG_NONNIL_DECL
,
267 OCTI_UMSG_NONNIL_STRET_DECL
,
269 OCTI_EXCEPTION_EXTRACT_DECL
,
270 OCTI_EXCEPTION_TRY_ENTER_DECL
,
271 OCTI_EXCEPTION_TRY_EXIT_DECL
,
272 OCTI_EXCEPTION_MATCH_DECL
,
273 OCTI_EXCEPTION_THROW_DECL
,
274 OCTI_SYNC_ENTER_DECL
,
278 OCTI_STACK_EXCEPTION_DATA_DECL
,
279 OCTI_LOCAL_EXCEPTION_DECL
,
280 OCTI_RETHROW_EXCEPTION_DECL
,
287 extern GTY(()) tree objc_global_trees
[OCTI_MAX
];
289 /* List of classes with list of their static instances. */
290 #define objc_static_instances objc_global_trees[OCTI_STATIC_NST]
292 /* The declaration of the array administrating the static instances. */
293 #define static_instances_decl objc_global_trees[OCTI_STATIC_NST_DECL]
295 /* Some commonly used instances of "identifier_node". */
297 #define self_id objc_global_trees[OCTI_SELF_ID]
298 #define ucmd_id objc_global_trees[OCTI_UCMD_ID]
299 #define unused_list objc_global_trees[OCTI_UNUSED_LIST]
300 #define objc_ellipsis_node objc_global_trees[OCTI_ELLIPSIS_NODE]
302 #define self_decl objc_global_trees[OCTI_SELF_DECL]
303 #define umsg_decl objc_global_trees[OCTI_UMSG_DECL]
304 #define umsg_super_decl objc_global_trees[OCTI_UMSG_SUPER_DECL]
305 #define umsg_stret_decl objc_global_trees[OCTI_UMSG_STRET_DECL]
306 #define umsg_super_stret_decl objc_global_trees[OCTI_UMSG_SUPER_STRET_DECL]
307 #define objc_get_class_decl objc_global_trees[OCTI_GET_CLASS_DECL]
308 #define objc_get_meta_class_decl \
309 objc_global_trees[OCTI_GET_MCLASS_DECL]
311 #define objc_super_type objc_global_trees[OCTI_SUPER_TYPE]
312 #define objc_selector_type objc_global_trees[OCTI_SEL_TYPE]
313 #define objc_id_type objc_global_trees[OCTI_ID_TYPE]
314 #define objc_class_type objc_global_trees[OCTI_CLS_TYPE]
315 #define objc_instance_type objc_global_trees[OCTI_NST_TYPE]
316 #define objc_protocol_type objc_global_trees[OCTI_PROTO_TYPE]
318 /* Type checking macros. */
320 #define IS_ID(TYPE) \
321 (TYPE_MAIN_VARIANT (TYPE) == TYPE_MAIN_VARIANT (objc_id_type))
322 #define IS_PROTOCOL_QUALIFIED_ID(TYPE) \
323 (IS_ID (TYPE) && TYPE_PROTOCOL_LIST (TYPE))
324 #define IS_SUPER(TYPE) \
325 (TREE_CODE (TYPE) == POINTER_TYPE && TREE_TYPE (TYPE) == objc_super_template)
327 #define class_chain objc_global_trees[OCTI_CLS_CHAIN]
328 #define alias_chain objc_global_trees[OCTI_ALIAS_CHAIN]
329 #define interface_chain objc_global_trees[OCTI_INTF_CHAIN]
330 #define protocol_chain objc_global_trees[OCTI_PROTO_CHAIN]
331 #define implemented_classes objc_global_trees[OCTI_IMPL_CHAIN]
333 /* Chains to manage selectors that are referenced and defined in the
336 #define cls_ref_chain objc_global_trees[OCTI_CLS_REF_CHAIN] /* Classes referenced. */
337 #define sel_ref_chain objc_global_trees[OCTI_SEL_REF_CHAIN] /* Selectors referenced. */
338 #define objc_ivar_chain objc_global_trees[OCTI_IVAR_CHAIN]
340 /* Chains to manage uniquing of strings. */
342 #define class_names_chain objc_global_trees[OCTI_CLS_NAMES_CHAIN]
343 #define meth_var_names_chain objc_global_trees[OCTI_METH_VAR_NAMES_CHAIN]
344 #define meth_var_types_chain objc_global_trees[OCTI_METH_VAR_TYPES_CHAIN]
347 /* Backend data declarations. */
349 #define UOBJC_SYMBOLS_decl objc_global_trees[OCTI_SYMBOLS_DECL]
350 #define UOBJC_INSTANCE_VARIABLES_decl objc_global_trees[OCTI_NST_VAR_DECL]
351 #define UOBJC_CLASS_VARIABLES_decl objc_global_trees[OCTI_CLS_VAR_DECL]
352 #define UOBJC_INSTANCE_METHODS_decl objc_global_trees[OCTI_NST_METH_DECL]
353 #define UOBJC_CLASS_METHODS_decl objc_global_trees[OCTI_CLS_METH_DECL]
354 #define UOBJC_CLASS_decl objc_global_trees[OCTI_CLS_DECL]
355 #define UOBJC_METACLASS_decl objc_global_trees[OCTI_MCLS_DECL]
356 #define UOBJC_SELECTOR_TABLE_decl objc_global_trees[OCTI_SEL_TABLE_DECL]
357 #define UOBJC_MODULES_decl objc_global_trees[OCTI_MODULES_DECL]
359 /* The following are used when compiling a class implementation.
360 implementation_template will normally be an interface, however if
361 none exists this will be equal to objc_implementation_context...it is
362 set in start_class. */
364 #define objc_interface_context objc_global_trees[OCTI_INTF_CTX]
365 #define objc_implementation_context objc_global_trees[OCTI_IMPL_CTX]
366 #define objc_method_context objc_global_trees[OCTI_METH_CTX]
367 #define objc_ivar_context objc_global_trees[OCTI_IVAR_CTX]
369 #define implementation_template objc_global_trees[OCTI_IMPL_TEMPL]
370 #define objc_class_template objc_global_trees[OCTI_CLS_TEMPL]
371 #define objc_category_template objc_global_trees[OCTI_CAT_TEMPL]
372 #define uprivate_record objc_global_trees[OCTI_UPRIV_REC]
373 #define objc_protocol_template objc_global_trees[OCTI_PROTO_TEMPL]
374 #define objc_selector_template objc_global_trees[OCTI_SEL_TEMPL]
375 #define ucls_super_ref objc_global_trees[OCTI_UCLS_SUPER_REF]
376 #define uucls_super_ref objc_global_trees[OCTI_UUCLS_SUPER_REF]
378 #define umsg_nonnil_decl objc_global_trees[OCTI_UMSG_NONNIL_DECL]
379 #define umsg_nonnil_stret_decl objc_global_trees[OCTI_UMSG_NONNIL_STRET_DECL]
380 #define objc_storage_class objc_global_trees[OCTI_STORAGE_CLS]
381 #define objc_exception_extract_decl \
382 objc_global_trees[OCTI_EXCEPTION_EXTRACT_DECL]
383 #define objc_exception_try_enter_decl \
384 objc_global_trees[OCTI_EXCEPTION_TRY_ENTER_DECL]
385 #define objc_exception_try_exit_decl \
386 objc_global_trees[OCTI_EXCEPTION_TRY_EXIT_DECL]
387 #define objc_exception_match_decl \
388 objc_global_trees[OCTI_EXCEPTION_MATCH_DECL]
389 #define objc_exception_throw_decl \
390 objc_global_trees[OCTI_EXCEPTION_THROW_DECL]
391 #define objc_sync_enter_decl objc_global_trees[OCTI_SYNC_ENTER_DECL]
392 #define objc_sync_exit_decl objc_global_trees[OCTI_SYNC_EXIT_DECL]
393 #define objc_exception_data_template \
394 objc_global_trees[OCTI_EXCDATA_TEMPL]
395 #define objc_setjmp_decl objc_global_trees[OCTI_SETJMP_DECL]
396 #define objc_stack_exception_data \
397 objc_global_trees[OCTI_STACK_EXCEPTION_DATA_DECL]
398 #define objc_caught_exception objc_global_trees[OCTI_LOCAL_EXCEPTION_DECL]
399 #define objc_rethrow_exception objc_global_trees[OCTI_RETHROW_EXCEPTION_DECL]
400 #define objc_eval_once objc_global_trees[OCTI_EVAL_ONCE_DECL]
401 #define objc_catch_type objc_global_trees[OCTI_CATCH_TYPE]
403 #define objc_method_template objc_global_trees[OCTI_METH_TEMPL]
404 #define objc_ivar_template objc_global_trees[OCTI_IVAR_TEMPL]
405 #define objc_symtab_template objc_global_trees[OCTI_SYMTAB_TEMPL]
406 #define objc_module_template objc_global_trees[OCTI_MODULE_TEMPL]
407 #define objc_super_template objc_global_trees[OCTI_SUPER_TEMPL]
408 #define objc_object_reference objc_global_trees[OCTI_OBJ_REF]
409 #define objc_method_prototype_template \
410 objc_global_trees[OCTI_METH_PROTO_TEMPL]
411 #define function1_template objc_global_trees[OCTI_FUNCTION1_TEMPL]
412 #define function2_template objc_global_trees[OCTI_FUNCTION2_TEMPL]
414 #define objc_object_id objc_global_trees[OCTI_OBJ_ID]
415 #define objc_class_id objc_global_trees[OCTI_CLS_ID]
416 #define objc_id_id objc_global_trees[OCTI_ID_ID]
417 #define constant_string_id objc_global_trees[OCTI_CNST_STR_ID]
418 #define constant_string_type objc_global_trees[OCTI_CNST_STR_TYPE]
419 #define constant_string_global_id \
420 objc_global_trees[OCTI_CNST_STR_GLOB_ID]
421 #define string_class_decl objc_global_trees[OCTI_STRING_CLASS_DECL]
422 #define UOBJC_SUPER_decl objc_global_trees[OCTI_SUPER_DECL]
424 #endif /* GCC_OBJC_ACT_H */