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

📄 objc-actions.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
{  tree type = TREE_TYPE (decl);  static int alreadyWarned = 0;  if (TREE_CODE (type) == RECORD_TYPE && TREE_STATIC_TEMPLATE (type))    {      if (!alreadyWarned)	{	  error ("GNU compiler does not support statically allocated objects");	  alreadyWarned = 1;	}      error_with_decl (decl, "`%s' cannot be statically allocated");    }}/* implement static typing. at this point, we know we have an interface... */treeget_static_reference (interface)     tree interface;{  return xref_tag (RECORD_TYPE, CLASS_NAME (interface));}/* Create and push a decl for a built-in external variable or field NAME.   CODE says which.   TYPE is its data type.  */static treecreate_builtin_decl (code, type, name)     enum tree_code code;     tree type;     char *name;{  tree decl = build_decl (code, get_identifier (name), type);  if (code == VAR_DECL)    {      TREE_STATIC (decl) = 1;      make_decl_rtl (decl, 0, 1);      pushdecl (decl);    }  return decl;}/* *	purpose: "play" parser, creating/installing representations *		 of the declarations that are required by Objective-C. * *	model: * *		type_spec--------->sc_spec *		(tree_list)        (tree_list) *		    |                  | *		    |                  | *		identifier_node    identifier_node */static voidsynth_module_prologue (){  tree expr_decl, temp_type;  /* defined in `objc.h' */  objc_object_id = get_identifier (TAG_OBJECT);  objc_object_reference = xref_tag (RECORD_TYPE, objc_object_id);  id_type = build_pointer_type (objc_object_reference);  objc_class_id = get_identifier (TAG_CLASS);    class_type = build_pointer_type (xref_tag (RECORD_TYPE, objc_class_id));  /* Declare type of selector-objects that represent an operation name.  */#ifdef OBJC_INT_SELECTORS  /* `unsigned int' */  selector_type = unsigned_type_node;#else  /* `struct objc_selector *' */  selector_type    = build_pointer_type (xref_tag (RECORD_TYPE,				    get_identifier (TAG_SELECTOR)));#endif /* not OBJC_INT_SELECTORS */  /* struct objc_object *objc_msgSend (id, SEL, ...); */  temp_type    = build_function_type (id_type,			   tree_cons (NULL_TREE, id_type,				      tree_cons (NULLT, selector_type, NULLT)));  _msg_decl = builtin_function ("objc_msgSend", temp_type, NOT_BUILT_IN, 0);  /* struct objc_object *objc_msgSendSuper (void *, SEL, ...); */  temp_type    = build_function_type (id_type,			   tree_cons (NULL_TREE, ptr_type_node,				      tree_cons (NULLT, selector_type, NULLT)));  _msgSuper_decl = builtin_function ("objc_msgSendSuper",				     temp_type, NOT_BUILT_IN, 0);  /* id objc_getClass (); */    temp_type = build_function_type (id_type, NULLT);  objc_getClass_decl    = builtin_function ("objc_getClass", temp_type, NOT_BUILT_IN, 0);  /* id objc_getMetaClass (); */  objc_getMetaClass_decl    = builtin_function ("objc_getMetaClass", temp_type, NOT_BUILT_IN, 0);  /* extern SEL _OBJC_SELECTOR_REFERENCES[]; */#ifdef OBJC_SELECTORS_WITHOUT_LABELS  _OBJC_SELECTOR_REFERENCES_decl    = create_builtin_decl (VAR_DECL, build_array_type (selector_type, NULLT),			   "_OBJC_SELECTOR_REFERENCES");#endif}/* * custom "build_string ()" which sets TREE_TYPE! */static treemy_build_string (len, str)     int len;     char *str;{  int wide_flag = 0;  tree aString = build_string (len, str);  /*   *  some code from "combine_strings ()", which is local to c-parse.y.   */  if (TREE_TYPE (aString) == int_array_type_node)    wide_flag = 1;  TREE_TYPE (aString) =    build_array_type (wide_flag ? integer_type_node : char_type_node,		      build_index_type (build_int_2 (len - 1, 0)));  TREE_CONSTANT (aString) = 1;	/* puts string in the ".text" segment */  TREE_STATIC (aString) = 1;  return aString;}/* Take care of defining and initializing _OBJC_SYMBOLS.  *//* Predefine the following data type:	struct _objc_symtab {		long sel_ref_cnt;		SEL *refs;		short cls_def_cnt;		short cat_def_cnt;		void *defs[cls_def_cnt + cat_def_cnt];	}; */static voidbuild_objc_symtab_template (){  tree field_decl, field_decl_chain, index;  objc_symtab_template = start_struct (RECORD_TYPE, get_identifier (_TAG_SYMTAB));  /* long sel_ref_cnt; */  field_decl = create_builtin_decl (FIELD_DECL,				    long_integer_type_node,				    "sel_ref_cnt");  field_decl_chain = field_decl;  /* SEL *refs; */  field_decl = create_builtin_decl (FIELD_DECL,				    build_pointer_type (selector_type),				    "refs");  chainon (field_decl_chain, field_decl);  /* short cls_def_cnt; */  field_decl = create_builtin_decl (FIELD_DECL,				    short_integer_type_node,				    "cls_def_cnt");  chainon (field_decl_chain, field_decl);  /* short cat_def_cnt; */  field_decl = create_builtin_decl (FIELD_DECL,				    short_integer_type_node,				    "cat_def_cnt");  chainon (field_decl_chain, field_decl);  /* void *defs[cls_def_cnt + cat_def_cnt]; */  index = build_index_type (build_int_2 (imp_count + cat_count - 1, 0));  field_decl = create_builtin_decl (FIELD_DECL,				    build_array_type (ptr_type_node, index),				    "defs");  chainon (field_decl_chain, field_decl);  finish_struct (objc_symtab_template, field_decl_chain);}/* Create the initial value for the `defs' field of _objc_symtab.   This is a CONSTRUCTOR.  */static treeinit_def_list (){  tree expr, initlist = NULLT;  struct imp_entry *impent;  if (imp_count)    for (impent = imp_list; impent; impent = impent->next)      {	if (TREE_CODE (impent->imp_context) == IMPLEMENTATION_TYPE)	  {	    expr = build_unary_op (ADDR_EXPR, impent->class_decl, 0);	    initlist = tree_cons (NULLT, expr, initlist);	  }      }  if (cat_count)    for (impent = imp_list; impent; impent = impent->next)      {	if (TREE_CODE (impent->imp_context) == CATEGORY_TYPE)	  {	    expr = build_unary_op (ADDR_EXPR, impent->class_decl, 0);	    initlist = tree_cons (NULLT, expr, initlist);	  }      }  return build_nt (CONSTRUCTOR, NULLT, nreverse (initlist));}/* Construct the initial value for all of _objc_symtab.  */static treeinit_objc_symtab (){  tree initlist;  /* sel_ref_cnt = { ..., 5, ... } */  if (sel_ref_chain)    initlist = build_tree_list (NULLT, build_int_2 (max_selector_index, 0));  else    initlist = build_tree_list (NULLT, build_int_2 (0, 0));  /* refs = { ..., _OBJC_SELECTOR_REFERENCES, ... } */#ifndef OBJC_SELECTORS_WITHOUT_LABELS  initlist = tree_cons (NULLT, build_int_2 (0, 0), initlist);#else  if (sel_ref_chain)    initlist = tree_cons (NULLT, _OBJC_SELECTOR_REFERENCES_decl, initlist);  else    initlist = tree_cons (NULLT, build_int_2 (0, 0), initlist);#endif  /* cls_def_cnt = { ..., 5, ... } */  initlist = tree_cons (NULLT, build_int_2 (imp_count, 0), initlist);  /* cat_def_cnt = { ..., 5, ... } */  initlist = tree_cons (NULLT, build_int_2 (cat_count, 0), initlist);  /* cls_def = { ..., { &Foo, &Bar, ...}, ... } */  if (imp_count || cat_count)    initlist = tree_cons (NULLT, init_def_list (), initlist);  return build_nt (CONSTRUCTOR, NULLT, nreverse (initlist));}/* Push forward-declarations of all the categories   so that init_def_list can use them in a CONSTRUCTOR.  */static voidforward_declare_categories (){  struct imp_entry *impent;  tree sav = implementation_context;  for (impent = imp_list; impent; impent = impent->next)    {      if (TREE_CODE (impent->imp_context) == CATEGORY_TYPE)	{	  /* Set an invisible arg to synth_id_with_class_suffix.  */	  implementation_context = impent->imp_context;	  impent->class_decl	    = create_builtin_decl (VAR_DECL, objc_category_template,				   IDENTIFIER_POINTER (synth_id_with_class_suffix ("_OBJC_CATEGORY")));	}    }  implementation_context = sav;}/* Create the declaration of _OBJC_SYMBOLS, with type `strict _objc_symtab'   and initialized appropriately.  */static voidgenerate_objc_symtab_decl (){  tree sc_spec;  if (!objc_category_template)    build_category_template ();  /* forward declare categories */  if (cat_count)    forward_declare_categories ();  if (!objc_symtab_template)    build_objc_symtab_template ();  sc_spec = build_tree_list (NULLT, ridpointers[(int) RID_STATIC]);  _OBJC_SYMBOLS_decl = start_decl (get_identifier ("_OBJC_SYMBOLS"),				   tree_cons (NULLT, objc_symtab_template, sc_spec), 1);  finish_decl (_OBJC_SYMBOLS_decl, init_objc_symtab (), NULLT);}/* *	tree_node------->tree_node----->... *          |                | *          | (value)        | (value) *          |                | *	  expr             expr */static treeinit_module_descriptor (){  tree initlist, expr;  /* version = { 1, ... } */  expr = build_int_2 (OBJC_VERSION, 0);  initlist = build_tree_list (NULLT, expr);  /* size = { ..., sizeof (struct objc_module), ... } */  expr = build_int_2 (TREE_INT_CST_LOW (TYPE_SIZE (objc_module_template)) /		      BITS_PER_UNIT, 0);  initlist = tree_cons (NULLT, expr, initlist);  /* name = { ..., "foo.m", ... } */  expr = build_msg_pool_reference (				   add_objc_string (get_identifier (input_filename)));  initlist = tree_cons (NULLT, expr, initlist);  /* symtab = { ..., _OBJC_SYMBOLS, ... } */  if (_OBJC_SYMBOLS_decl)    expr = build_unary_op (ADDR_EXPR, _OBJC_SYMBOLS_decl, 0);  else    expr = build_int_2 (0, 0);  initlist = tree_cons (NULLT, expr, initlist);  return build_nt (CONSTRUCTOR, NULLT, nreverse (initlist));}/* Write out the data structures to describe Objective C classes defined.   If appropriate, compile and output a setup function to initialize them.   Return a string which is the name of a function to call to initialize   the Objective C data structures for this file (and perhaps for other files   also).  */static char *build_module_descriptor (){  tree decl_specs, field_decl, field_decl_chain;  objc_module_template = start_struct (RECORD_TYPE, get_identifier (_TAG_MODULE));  /* long version; */  decl_specs = build_tree_list (NULLT, ridpointers[(int) RID_LONG]);  field_decl = get_identifier ("version");  field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULLT);  field_decl_chain = field_decl;  /* long  size; */  decl_specs = build_tree_list (NULLT, ridpointers[(int) RID_LONG]);  field_decl = get_identifier ("size");  field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULLT);  chainon (field_decl_chain, field_decl);  /* char  *name; */  decl_specs = build_tree_list (NULLT, ridpointers[(int) RID_CHAR]);  field_decl = build1 (INDIRECT_REF, NULLT, get_identifier ("name"));  field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULLT);  chainon (field_decl_chain, field_decl);  /* struct objc_symtab *symtab; */  decl_specs = get_identifier (_TAG_SYMTAB);  decl_specs = build_tree_list (NULLT, xref_tag (RECORD_TYPE, decl_specs));  field_decl = build1 (INDIRECT_REF, NULLT, get_identifier ("symtab"));  field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULLT);  chainon (field_decl_chain, field_decl);  finish_struct (objc_module_template, field_decl_chain);  /* create an instance of "objc_module" */  decl_specs = tree_cons (NULLT, objc_module_template,			  build_tree_list (NULLT, ridpointers[(int) RID_STATIC]));  _OBJC_MODULES_decl = start_decl (get_identifier ("_OBJC_MODULES"),				   decl_specs, 1);  finish_decl (_OBJC_MODULES_decl, init_module_descriptor (), NULLT);  /* Mark the decl to avoid "defined but not used" warning. */  DECL_IN_SYSTEM_HEADER (_OBJC_MODULES_decl) = 1;  /* Generate a constructor call for the module descriptor.      This code was generated by reading the grammar rules     of c-parse.y;  Therefore, it may not be the most efficient     way of generating the requisite code. */#ifndef NEXT_OBJC_RUNTIME  {    tree parms, function_decl, decelerator, void_list_node;    tree function_type;    char *buf;    char *global_object_name = 0;    tree t;    /* Use a global object (which is already required to be unique over       the program) rather than the file name (which imposes extra       constraints).  -- Raeburn@MIT.EDU, 10 Jan 1990.  */    /* Find the name of some global object defined in this file.  */    for (t = getdecls (); t; t = TREE_CHAIN (t))      if (TREE_PUBLIC (t) && !DECL_EXTERNAL (t) && DECL_INITIAL (t) != 0)	{	  global_object_name = IDENTIFIER_POINTER (DECL_NAME (t));	  break;	}    /* If none, use the name of the file.  */    if (!global_object_name)      {	char *p, *q;	global_object_name	  = (char *) alloca (strlen (main_input_filename) + 1);	p = main_input_filename;	q = global_object_name;	/* Replace any weird characters in the file name.  */	for (; *p; p++)	  if (! ((*p >= '0' && *p <= '9')		 || (*p >= 'A' && *p <= 'Z')		 || (*p >= 'a' && *p <= 'z')))	    *q++ = '_';	  else	    *q++ = *p;

⌨️ 快捷键说明

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