⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objc-act.c

📁 gcc的组件
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Implement classes and message passing for Objective C.   Copyright (C) 1992, 1993, 1994, 1995, 1997, 1998, 1999, 2000,   2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.   Contributed by Steve Naroff.This file is part of GCC.GCC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GCC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GCC; see the file COPYING.  If not, write tothe Free Software Foundation, 51 Franklin Street, Fifth Floor,Boston, MA 02110-1301, USA.  *//* Purpose: This module implements the Objective-C 4.0 language.   compatibility issues (with the Stepstone translator):   - does not recognize the following 3.3 constructs.     @requires, @classes, @messages, = (...)   - methods with variable arguments must conform to ANSI standard.   - tagged structure definitions that appear in BOTH the interface     and implementation are not allowed.   - public/private: all instance variables are public within the     context of the implementation...I consider this to be a bug in     the translator.   - statically allocated objects are not supported. the user will     receive an error if this service is requested.   code generation `options':   */#include "config.h"#include "system.h"#include "coretypes.h"#include "tm.h"#include "tree.h"#include "rtl.h"#include "tm_p.h"#include "expr.h"#ifdef OBJCPLUS#include "cp-tree.h"#else#include "c-tree.h"#endif#include "c-common.h"#include "c-pragma.h"#include "flags.h"#include "langhooks.h"#include "objc-act.h"#include "input.h"#include "except.h"#include "function.h"#include "output.h"#include "toplev.h"#include "ggc.h"#include "varray.h"#include "debug.h"#include "target.h"#include "diagnostic.h"#include "cgraph.h"#include "tree-iterator.h"#include "libfuncs.h"#include "hashtab.h"#include "langhooks-def.h"#define OBJC_VOID_AT_END	void_list_nodestatic unsigned int should_call_super_dealloc = 0;/* When building Objective-C++, we are not linking against the C front-end   and so need to replicate the C tree-construction functions in some way.  */#ifdef OBJCPLUS#define OBJCP_REMAP_FUNCTIONS#include "objcp-decl.h"#endif  /* OBJCPLUS *//* This is the default way of generating a method name.  *//* I am not sure it is really correct.   Perhaps there's a danger that it will make name conflicts   if method names contain underscores. -- rms.  */#ifndef OBJC_GEN_METHOD_LABEL#define OBJC_GEN_METHOD_LABEL(BUF, IS_INST, CLASS_NAME, CAT_NAME, SEL_NAME, NUM) \  do {					    \    char *temp;				    \    sprintf ((BUF), "_%s_%s_%s_%s",	    \	     ((IS_INST) ? "i" : "c"),	    \	     (CLASS_NAME),		    \	     ((CAT_NAME)? (CAT_NAME) : ""), \	     (SEL_NAME));		    \    for (temp = (BUF); *temp; temp++)	    \      if (*temp == ':') *temp = '_';	    \  } while (0)#endif/* These need specifying.  */#ifndef OBJC_FORWARDING_STACK_OFFSET#define OBJC_FORWARDING_STACK_OFFSET 0#endif#ifndef OBJC_FORWARDING_MIN_OFFSET#define OBJC_FORWARDING_MIN_OFFSET 0#endif/* Set up for use of obstacks.  */#include "obstack.h"/* This obstack is used to accumulate the encoding of a data type.  */static struct obstack util_obstack;/* This points to the beginning of obstack contents, so we can free   the whole contents.  */char *util_firstobj;/* The version identifies which language generation and runtime   the module (file) was compiled for, and is recorded in the   module descriptor.  */#define OBJC_VERSION	(flag_next_runtime ? 6 : 8)#define PROTOCOL_VERSION 2/* (Decide if these can ever be validly changed.) */#define OBJC_ENCODE_INLINE_DEFS 	0#define OBJC_ENCODE_DONT_INLINE_DEFS	1/*** Private Interface (procedures) ***//* Used by compile_file.  */static void init_objc (void);static void finish_objc (void);/* Code generation.  */static tree objc_build_constructor (tree, tree);static tree build_objc_method_call (int, tree, tree, tree, tree);static tree get_proto_encoding (tree);static tree lookup_interface (tree);static tree objc_add_static_instance (tree, tree);static tree start_class (enum tree_code, tree, tree, tree);static tree continue_class (tree);static void finish_class (tree);static void start_method_def (tree);#ifdef OBJCPLUSstatic void objc_start_function (tree, tree, tree, tree);#elsestatic void objc_start_function (tree, tree, tree, struct c_arg_info *);#endifstatic tree start_protocol (enum tree_code, tree, tree);static tree build_method_decl (enum tree_code, tree, tree, tree, bool);static tree objc_add_method (tree, tree, int);static tree add_instance_variable (tree, int, tree);static tree build_ivar_reference (tree);static tree is_ivar (tree, tree);static void build_objc_exception_stuff (void);static void build_next_objc_exception_stuff (void);/* We only need the following for ObjC; ObjC++ will use C++'s definition   of DERIVED_FROM_P.  */#ifndef OBJCPLUSstatic bool objc_derived_from_p (tree, tree);#define DERIVED_FROM_P(PARENT, CHILD) objc_derived_from_p (PARENT, CHILD)#endifstatic void objc_xref_basetypes (tree, tree);static void build_class_template (void);static void build_selector_template (void);static void build_category_template (void);static void build_super_template (void);static tree build_protocol_initializer (tree, tree, tree, tree, tree);static tree get_class_ivars (tree, bool);static tree generate_protocol_list (tree);static void build_protocol_reference (tree);static tree objc_build_volatilized_type (tree);#ifdef OBJCPLUSstatic void objc_generate_cxx_cdtors (void);#endifstatic const char *synth_id_with_class_suffix (const char *, tree);/* Hash tables to manage the global pool of method prototypes.  */hash *nst_method_hash_list = 0;hash *cls_method_hash_list = 0;static hash hash_lookup (hash *, tree);static tree lookup_method (tree, tree);static tree lookup_method_static (tree, tree, int);enum string_section{  class_names,		/* class, category, protocol, module names */  meth_var_names,	/* method and variable names */  meth_var_types	/* method and variable type descriptors */};static tree add_objc_string (tree, enum string_section);static tree build_objc_string_decl (enum string_section);static void build_selector_table_decl (void);/* Protocol additions.  */static tree lookup_protocol (tree);static tree lookup_and_install_protocols (tree);/* Type encoding.  */static void encode_type_qualifiers (tree);static void encode_type (tree, int, int);static void encode_field_decl (tree, int, int);#ifdef OBJCPLUSstatic void really_start_method (tree, tree);#elsestatic void really_start_method (tree, struct c_arg_info *);#endifstatic int comp_proto_with_proto (tree, tree, int);static void objc_push_parm (tree);#ifdef OBJCPLUSstatic tree objc_get_parm_info (int);#elsestatic struct c_arg_info *objc_get_parm_info (int);#endif/* Utilities for debugging and error diagnostics.  */static void warn_with_method (const char *, int, tree);static char *gen_type_name (tree);static char *gen_type_name_0 (tree);static char *gen_method_decl (tree);static char *gen_declaration (tree);/* Everything else.  */static tree create_field_decl (tree, const char *);static void add_class_reference (tree);static void build_protocol_template (void);static tree encode_method_prototype (tree);static void generate_classref_translation_entry (tree);static void handle_class_ref (tree);static void generate_struct_by_value_array (void)     ATTRIBUTE_NORETURN;static void mark_referenced_methods (void);static void generate_objc_image_info (void);/*** Private Interface (data) ***//* Reserved tag definitions.  */#define OBJECT_TYPEDEF_NAME		"id"#define CLASS_TYPEDEF_NAME		"Class"#define TAG_OBJECT			"objc_object"#define TAG_CLASS			"objc_class"#define TAG_SUPER			"objc_super"#define TAG_SELECTOR			"objc_selector"#define UTAG_CLASS			"_objc_class"#define UTAG_IVAR			"_objc_ivar"#define UTAG_IVAR_LIST			"_objc_ivar_list"#define UTAG_METHOD			"_objc_method"#define UTAG_METHOD_LIST		"_objc_method_list"#define UTAG_CATEGORY			"_objc_category"#define UTAG_MODULE			"_objc_module"#define UTAG_SYMTAB			"_objc_symtab"#define UTAG_SUPER			"_objc_super"#define UTAG_SELECTOR			"_objc_selector"#define UTAG_PROTOCOL			"_objc_protocol"#define UTAG_METHOD_PROTOTYPE		"_objc_method_prototype"#define UTAG_METHOD_PROTOTYPE_LIST	"_objc__method_prototype_list"/* Note that the string object global name is only needed for the   NeXT runtime.  */#define STRING_OBJECT_GLOBAL_FORMAT	"_%sClassReference"#define PROTOCOL_OBJECT_CLASS_NAME	"Protocol"static const char *TAG_GETCLASS;static const char *TAG_GETMETACLASS;static const char *TAG_MSGSEND;static const char *TAG_MSGSENDSUPER;/* The NeXT Objective-C messenger may have two extra entry points, for use   when returning a structure. */static const char *TAG_MSGSEND_STRET;static const char *TAG_MSGSENDSUPER_STRET;static const char *default_constant_string_class_name;/* Runtime metadata flags.  */#define CLS_FACTORY			0x0001L#define CLS_META			0x0002L#define CLS_HAS_CXX_STRUCTORS		0x2000L#define OBJC_MODIFIER_STATIC		0x00000001#define OBJC_MODIFIER_FINAL		0x00000002#define OBJC_MODIFIER_PUBLIC		0x00000004#define OBJC_MODIFIER_PRIVATE		0x00000008#define OBJC_MODIFIER_PROTECTED		0x00000010#define OBJC_MODIFIER_NATIVE		0x00000020#define OBJC_MODIFIER_SYNCHRONIZED	0x00000040#define OBJC_MODIFIER_ABSTRACT		0x00000080#define OBJC_MODIFIER_VOLATILE		0x00000100#define OBJC_MODIFIER_TRANSIENT		0x00000200#define OBJC_MODIFIER_NONE_SPECIFIED	0x80000000/* NeXT-specific tags.  */#define TAG_MSGSEND_NONNIL		"objc_msgSendNonNil"#define TAG_MSGSEND_NONNIL_STRET	"objc_msgSendNonNil_stret"#define TAG_EXCEPTIONEXTRACT		"objc_exception_extract"#define TAG_EXCEPTIONTRYENTER		"objc_exception_try_enter"#define TAG_EXCEPTIONTRYEXIT		"objc_exception_try_exit"#define TAG_EXCEPTIONMATCH		"objc_exception_match"#define TAG_EXCEPTIONTHROW		"objc_exception_throw"#define TAG_SYNCENTER			"objc_sync_enter"#define TAG_SYNCEXIT			"objc_sync_exit"#define TAG_SETJMP			"_setjmp"#define UTAG_EXCDATA			"_objc_exception_data"#define TAG_ASSIGNIVAR			"objc_assign_ivar"#define TAG_ASSIGNGLOBAL		"objc_assign_global"#define TAG_ASSIGNSTRONGCAST		"objc_assign_strongCast"/* Branch entry points.  All that matters here are the addresses;   functions with these names do not really exist in libobjc.  */#define TAG_MSGSEND_FAST		"objc_msgSend_Fast"#define TAG_ASSIGNIVAR_FAST		"objc_assign_ivar_Fast"#define TAG_CXX_CONSTRUCT		".cxx_construct"#define TAG_CXX_DESTRUCT		".cxx_destruct"/* GNU-specific tags.  */#define TAG_EXECCLASS			"__objc_exec_class"#define TAG_GNUINIT			"__objc_gnu_init"/* Flags for lookup_method_static().  */#define OBJC_LOOKUP_CLASS	1	/* Look for class methods.  */#define OBJC_LOOKUP_NO_SUPER	2	/* Do not examine superclasses.  *//* The OCTI_... enumeration itself is in objc/objc-act.h.  */tree objc_global_trees[OCTI_MAX];static void handle_impent (struct imp_entry *);struct imp_entry *imp_list = 0;int imp_count = 0;	/* `@implementation' */int cat_count = 0;	/* `@category' */enum tree_code objc_inherit_code;int objc_public_flag;/* Use to generate method labels.  */static int method_slot = 0;#define BUFSIZE		1024static char *errbuf;	/* Buffer for error diagnostics *//* Data imported from tree.c.  */extern enum debug_info_type write_symbols;/* Data imported from toplev.c.  */extern const char *dump_base_name;static int flag_typed_selectors;/* Store all constructed constant strings in a hash table so that   they get uniqued properly.  */struct string_descriptor GTY(()){  /* The literal argument .  */  tree literal;  /* The resulting constant string.  */  tree constructor;};static GTY((param_is (struct string_descriptor))) htab_t string_htab;/* Store the EH-volatilized types in a hash table, for easy retrieval.  */struct volatilized_type GTY(()){  tree type;};static GTY((param_is (struct volatilized_type))) htab_t volatilized_htab;FILE *gen_declaration_file;/* Tells "encode_pointer/encode_aggregate" whether we are generating   type descriptors for instance variables (as opposed to methods).   Type descriptors for instance variables contain more information   than methods (for static typing and embedded structures).  */static int generating_instance_variables = 0;/* Some platforms pass small structures through registers versus   through an invisible pointer.  Determine at what size structure is   the transition point between the two possibilities.  */static voidgenerate_struct_by_value_array (void){  tree type;  tree field_decl, field_decl_chain;  int i, j;  int aggregate_in_mem[32];  int found = 0;  /* Presumably no platform passes 32 byte structures in a register.  */  for (i = 1; i < 32; i++)    {      char buffer[5];      /* Create an unnamed struct that has `i' character components */      type = start_struct (RECORD_TYPE, NULL_TREE);      strcpy (buffer, "c1");      field_decl = create_field_decl (char_type_node,				      buffer);      field_decl_chain = field_decl;      for (j = 1; j < i; j++)	{	  sprintf (buffer, "c%d", j + 1);	  field_decl = create_field_decl (char_type_node,					  buffer);	  chainon (field_decl_chain, field_decl);	}      finish_struct (type, field_decl_chain, NULL_TREE);      aggregate_in_mem[i] = aggregate_value_p (type, 0);      if (!aggregate_in_mem[i])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -