1 /* Declarations for objc-act.c. 2 Copyright (C) 1990, 2000, 2001 Free Software Foundation, Inc. 3 4 This file is part of GNU CC. 5 6 GNU CC is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU CC is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU CC; see the file COPYING. If not, write to 18 the Free Software Foundation, 59 Temple Place - Suite 330, 19 Boston, MA 02111-1307, USA. */ 20 21 #ifndef GCC_OBJC_ACT_H 22 #define GCC_OBJC_ACT_H 23 24 /*** Public Interface (procedures) ***/ 25 26 const char *objc_init PARAMS ((const char *)); 27 const char *objc_printable_name PARAMS ((tree, int)); 28 29 /* used by yyparse */ 30 31 void finish_file PARAMS ((void)); 32 tree start_class PARAMS ((enum tree_code, tree, tree, tree)); 33 tree continue_class PARAMS ((tree)); 34 void finish_class PARAMS ((tree)); 35 void start_method_def PARAMS ((tree)); 36 void continue_method_def PARAMS ((void)); 37 void finish_method_def PARAMS ((void)); 38 tree start_protocol PARAMS ((enum tree_code, tree, tree)); 39 void finish_protocol PARAMS ((tree)); 40 void add_objc_decls PARAMS ((void)); 41 42 tree is_ivar PARAMS ((tree, tree)); 43 int is_private PARAMS ((tree)); 44 int is_public PARAMS ((tree, tree)); 45 tree add_instance_variable PARAMS ((tree, int, tree, tree, tree)); 46 tree add_class_method PARAMS ((tree, tree)); 47 tree add_instance_method PARAMS ((tree, tree)); 48 tree get_super_receiver PARAMS ((void)); 49 tree get_class_ivars PARAMS ((tree)); 50 tree get_class_reference PARAMS ((tree)); 51 tree get_static_reference PARAMS ((tree, tree)); 52 tree get_object_reference PARAMS ((tree)); 53 tree build_message_expr PARAMS ((tree)); 54 tree finish_message_expr PARAMS ((tree, tree, tree)); 55 tree build_selector_expr PARAMS ((tree)); 56 tree build_ivar_reference PARAMS ((tree)); 57 tree build_keyword_decl PARAMS ((tree, tree, tree)); 58 tree build_method_decl PARAMS ((enum tree_code, tree, tree, tree)); 59 tree build_protocol_expr PARAMS ((tree)); 60 tree build_objc_string_object PARAMS ((tree)); 61 62 void objc_declare_alias PARAMS ((tree, tree)); 63 void objc_declare_class PARAMS ((tree)); 64 void objc_declare_protocols PARAMS ((tree)); 65 66 /* the following routines are used to implement statically typed objects */ 67 68 int objc_comptypes PARAMS ((tree, tree, int)); 69 void objc_check_decl PARAMS ((tree)); 70 71 /* NeXT extensions */ 72 73 tree build_encode_expr PARAMS ((tree)); 74 75 /* Objective-C structures */ 76 77 /* KEYWORD_DECL */ 78 #define KEYWORD_KEY_NAME(DECL) ((DECL)->decl.name) 79 #define KEYWORD_ARG_NAME(DECL) ((DECL)->decl.arguments) 80 81 /* INSTANCE_METHOD_DECL, CLASS_METHOD_DECL */ 82 #define METHOD_SEL_NAME(DECL) ((DECL)->decl.name) 83 #define METHOD_SEL_ARGS(DECL) ((DECL)->decl.arguments) 84 #define METHOD_ADD_ARGS(DECL) ((DECL)->decl.result) 85 #define METHOD_DEFINITION(DECL) ((DECL)->decl.initial) 86 #define METHOD_ENCODING(DECL) ((DECL)->decl.context) 87 88 /* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE, 89 CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE, 90 PROTOCOL_INTERFACE_TYPE */ 91 #define CLASS_NAME(CLASS) ((CLASS)->type.name) 92 #define CLASS_SUPER_NAME(CLASS) ((CLASS)->type.context) 93 #define CLASS_IVARS(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 0) 94 #define CLASS_RAW_IVARS(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 1) 95 #define CLASS_NST_METHODS(CLASS) ((CLASS)->type.minval) 96 #define CLASS_CLS_METHODS(CLASS) ((CLASS)->type.maxval) 97 #define CLASS_STATIC_TEMPLATE(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 2) 98 #define CLASS_CATEGORY_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 3) 99 #define CLASS_PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 4) 100 #define CLASS_OWN_IVARS(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 5) 101 #define PROTOCOL_NAME(CLASS) ((CLASS)->type.name) 102 #define PROTOCOL_LIST(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 0) 103 #define PROTOCOL_NST_METHODS(CLASS) ((CLASS)->type.minval) 104 #define PROTOCOL_CLS_METHODS(CLASS) ((CLASS)->type.maxval) 105 #define PROTOCOL_FORWARD_DECL(CLASS) TREE_VEC_ELT (TYPE_BINFO (CLASS), 1) 106 #define PROTOCOL_DEFINED(CLASS) TREE_USED (CLASS) 107 #define TYPE_PROTOCOL_LIST(TYPE) ((TYPE)->type.context) 108 109 /* Set by `continue_class' and checked by `is_public'. */ 110 111 #define TREE_STATIC_TEMPLATE(record_type) (TREE_PUBLIC (record_type)) 112 #define TYPED_OBJECT(type) \ 113 (TREE_CODE (type) == RECORD_TYPE && TREE_STATIC_TEMPLATE (type)) 114 115 /* Define the Objective-C or Objective-C++ language-specific tree codes. */ 116 117 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM, 118 enum objc_tree_code { 119 #ifdef OBJCPLUS 120 LAST_BASE_TREE_CODE = LAST_CPLUS_TREE_CODE, 121 #else 122 LAST_BASE_TREE_CODE = LAST_C_TREE_CODE, 123 #endif 124 #include "objc-tree.def" 125 LAST_OBJC_TREE_CODE 126 }; 127 #undef DEFTREECODE 128 129 /* Hash tables to manage the global pool of method prototypes. */ 130 131 typedef struct hashed_entry *hash; 132 typedef struct hashed_attribute *attr; 133 134 struct hashed_attribute GTY(()) 135 { 136 attr next; 137 tree value; 138 }; 139 struct hashed_entry GTY(()) 140 { 141 attr list; 142 hash next; 143 tree key; 144 }; 145 146 extern GTY ((length ("SIZEHASHTABLE"))) hash *nst_method_hash_list; 147 extern GTY ((length ("SIZEHASHTABLE"))) hash *cls_method_hash_list; 148 149 #define SIZEHASHTABLE 257 150 151 /* Objective-C/Objective-C++ @implementation list. */ 152 153 struct imp_entry GTY(()) 154 { 155 struct imp_entry *next; 156 tree imp_context; 157 tree imp_template; 158 tree class_decl; /* _OBJC_CLASS_<my_name>; */ 159 tree meta_decl; /* _OBJC_METACLASS_<my_name>; */ 160 }; 161 162 extern GTY(()) struct imp_entry *imp_list; 163 extern int imp_count; /* `@implementation' */ 164 extern int cat_count; /* `@category' */ 165 166 /* Objective-C/Objective-C++ global tree enumeration. */ 167 168 enum objc_tree_index 169 { 170 OCTI_STATIC_NST, 171 OCTI_STATIC_NST_DECL, 172 OCTI_SELF_ID, 173 OCTI_UCMD_ID, 174 OCTI_UNUSED_LIST, 175 OCTI_ELLIPSIS_NODE, 176 177 OCTI_SELF_DECL, 178 OCTI_UMSG_DECL, 179 OCTI_UMSG_SUPER_DECL, 180 OCTI_GET_CLASS_DECL, 181 OCTI_GET_MCLASS_DECL, 182 OCTI_SUPER_TYPE, 183 OCTI_SEL_TYPE, 184 OCTI_ID_TYPE, 185 OCTI_CLS_TYPE, 186 OCTI_NST_TYPE, 187 OCTI_PROTO_TYPE, 188 189 OCTI_CLS_CHAIN, 190 OCTI_ALIAS_CHAIN, 191 OCTI_INTF_CHAIN, 192 OCTI_PROTO_CHAIN, 193 OCTI_IMPL_CHAIN, 194 OCTI_CLS_REF_CHAIN, 195 OCTI_SEL_REF_CHAIN, 196 OCTI_IVAR_CHAIN, 197 OCTI_CLS_NAMES_CHAIN, 198 OCTI_METH_VAR_NAMES_CHAIN, 199 OCTI_METH_VAR_TYPES_CHAIN, 200 201 OCTI_SYMBOLS_DECL, 202 OCTI_NST_VAR_DECL, 203 OCTI_CLS_VAR_DECL, 204 OCTI_NST_METH_DECL, 205 OCTI_CLS_METH_DECL, 206 OCTI_CLS_DECL, 207 OCTI_MCLS_DECL, 208 OCTI_SEL_TABLE_DECL, 209 OCTI_MODULES_DECL, 210 OCTI_STRG_DECL, 211 212 OCTI_INTF_CTX, 213 OCTI_IMPL_CTX, 214 OCTI_METH_CTX, 215 OCTI_IVAR_CTX, 216 217 OCTI_IMPL_TEMPL, 218 OCTI_CLS_TEMPL, 219 OCTI_CAT_TEMPL, 220 OCTI_UPRIV_REC, 221 OCTI_PROTO_TEMPL, 222 OCTI_SEL_TEMPL, 223 OCTI_UCLS_SUPER_REF, 224 OCTI_UUCLS_SUPER_REF, 225 OCTI_METH_TEMPL, 226 OCTI_IVAR_TEMPL, 227 OCTI_SYMTAB_TEMPL, 228 OCTI_MODULE_TEMPL, 229 OCTI_SUPER_TEMPL, 230 OCTI_OBJ_REF, 231 OCTI_METH_PROTO_TEMPL, 232 OCTI_FUNCTION1_TEMPL, 233 OCTI_FUNCTION2_TEMPL, 234 235 OCTI_OBJ_ID, 236 OCTI_CLS_ID, 237 OCTI_ID_ID, 238 OCTI_CNST_STR_ID, 239 OCTI_CNST_STR_TYPE, 240 OCTI_CNST_STR_GLOB_ID, 241 OCTI_STRING_CLASS_DECL, 242 OCTI_SUPER_DECL, 243 244 OCTI_MAX 245 }; 246 247 extern GTY(()) tree objc_global_trees[OCTI_MAX]; 248 249 /* List of classes with list of their static instances. */ 250 #define objc_static_instances objc_global_trees[OCTI_STATIC_NST] 251 252 /* The declaration of the array administrating the static instances. */ 253 #define static_instances_decl objc_global_trees[OCTI_STATIC_NST_DECL] 254 255 /* Some commonly used instances of "identifier_node". */ 256 257 #define self_id objc_global_trees[OCTI_SELF_ID] 258 #define ucmd_id objc_global_trees[OCTI_UCMD_ID] 259 #define unused_list objc_global_trees[OCTI_UNUSED_LIST] 260 #define objc_ellipsis_node objc_global_trees[OCTI_ELLIPSIS_NODE] 261 262 #define self_decl objc_global_trees[OCTI_SELF_DECL] 263 #define umsg_decl objc_global_trees[OCTI_UMSG_DECL] 264 #define umsg_super_decl objc_global_trees[OCTI_UMSG_SUPER_DECL] 265 #define objc_get_class_decl objc_global_trees[OCTI_GET_CLASS_DECL] 266 #define objc_get_meta_class_decl \ 267 objc_global_trees[OCTI_GET_MCLASS_DECL] 268 269 #define super_type objc_global_trees[OCTI_SUPER_TYPE] 270 #define selector_type objc_global_trees[OCTI_SEL_TYPE] 271 #define id_type objc_global_trees[OCTI_ID_TYPE] 272 #define objc_class_type objc_global_trees[OCTI_CLS_TYPE] 273 #define instance_type objc_global_trees[OCTI_NST_TYPE] 274 #define protocol_type objc_global_trees[OCTI_PROTO_TYPE] 275 276 /* Type checking macros. */ 277 278 #define IS_ID(TYPE) \ 279 (TYPE_MAIN_VARIANT (TYPE) == TYPE_MAIN_VARIANT (id_type)) 280 #define IS_PROTOCOL_QUALIFIED_ID(TYPE) \ 281 (IS_ID (TYPE) && TYPE_PROTOCOL_LIST (TYPE)) 282 #define IS_SUPER(TYPE) \ 283 (super_type && TYPE_MAIN_VARIANT (TYPE) == TYPE_MAIN_VARIANT (super_type)) 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 UOBJC_STRINGS_decl objc_global_trees[OCTI_STRG_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 objc_method_template objc_global_trees[OCTI_METH_TEMPL] 338 #define objc_ivar_template objc_global_trees[OCTI_IVAR_TEMPL] 339 #define objc_symtab_template objc_global_trees[OCTI_SYMTAB_TEMPL] 340 #define objc_module_template objc_global_trees[OCTI_MODULE_TEMPL] 341 #define objc_super_template objc_global_trees[OCTI_SUPER_TEMPL] 342 #define objc_object_reference objc_global_trees[OCTI_OBJ_REF] 343 #define objc_method_prototype_template \ 344 objc_global_trees[OCTI_METH_PROTO_TEMPL] 345 #define function1_template objc_global_trees[OCTI_FUNCTION1_TEMPL] 346 #define function2_template objc_global_trees[OCTI_FUNCTION2_TEMPL] 347 348 #define objc_object_id objc_global_trees[OCTI_OBJ_ID] 349 #define objc_class_id objc_global_trees[OCTI_CLS_ID] 350 #define objc_id_id objc_global_trees[OCTI_ID_ID] 351 #define constant_string_id objc_global_trees[OCTI_CNST_STR_ID] 352 #define constant_string_type objc_global_trees[OCTI_CNST_STR_TYPE] 353 #define constant_string_global_id \ 354 objc_global_trees[OCTI_CNST_STR_GLOB_ID] 355 #define string_class_decl objc_global_trees[OCTI_STRING_CLASS_DECL] 356 #define UOBJC_SUPER_decl objc_global_trees[OCTI_SUPER_DECL] 357 358 #endif /* GCC_OBJC_ACT_H */ 359