?? objc-act.c
字號:
rest_of_decl_compilation (decl, 0, 1, 0); /* Do this here so it gets output later instead of possibly inside something else we are writing. */ DECL_INITIAL (decl) = constructor; /* Add the DECL to the head of this CLASS' list. */ TREE_PURPOSE (*chain) = tree_cons (NULL_TREE, decl, TREE_PURPOSE (*chain)); pop_obstacks (); return decl;}/* Build a static constant CONSTRUCTOR with type TYPE and elements ELTS. */static treebuild_constructor (type, elts) tree type, elts;{ tree constructor = build (CONSTRUCTOR, type, NULL_TREE, elts); TREE_CONSTANT (constructor) = 1; TREE_STATIC (constructor) = 1; TREE_READONLY (constructor) = 1; return constructor;}/* 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 (UTAG_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]; */ if (!flag_next_runtime) index = build_index_type (build_int_2 (imp_count + cat_count, 0)); else index = build_index_type (build_int_2 (imp_count + cat_count - 1, imp_count == 0 && cat_count == 0 ? -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, NULL_TREE);}/* Create the initial value for the `defs' field of _objc_symtab. This is a CONSTRUCTOR. */static treeinit_def_list (type) tree type;{ tree expr, initlist = NULL_TREE; struct imp_entry *impent; if (imp_count) for (impent = imp_list; impent; impent = impent->next) { if (TREE_CODE (impent->imp_context) == CLASS_IMPLEMENTATION_TYPE) { expr = build_unary_op (ADDR_EXPR, impent->class_decl, 0); initlist = tree_cons (NULL_TREE, expr, initlist); } } if (cat_count) for (impent = imp_list; impent; impent = impent->next) { if (TREE_CODE (impent->imp_context) == CATEGORY_IMPLEMENTATION_TYPE) { expr = build_unary_op (ADDR_EXPR, impent->class_decl, 0); initlist = tree_cons (NULL_TREE, expr, initlist); } } if (!flag_next_runtime) { /* statics = { ..., _OBJC_STATIC_INSTANCES, ... } */ tree expr; if (static_instances_decl) expr = build_unary_op (ADDR_EXPR, static_instances_decl, 0); else expr = build_int_2 (0, 0); initlist = tree_cons (NULL_TREE, expr, initlist); } return build_constructor (type, nreverse (initlist));}/* Construct the initial value for all of _objc_symtab. */static treeinit_objc_symtab (type) tree type;{ tree initlist; /* sel_ref_cnt = { ..., 5, ... } */ initlist = build_tree_list (NULL_TREE, build_int_2 (0, 0)); /* refs = { ..., _OBJC_SELECTOR_TABLE, ... } */ if (flag_next_runtime || ! sel_ref_chain) initlist = tree_cons (NULL_TREE, build_int_2 (0, 0), initlist); else initlist = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, UOBJC_SELECTOR_TABLE_decl, 1), initlist); /* cls_def_cnt = { ..., 5, ... } */ initlist = tree_cons (NULL_TREE, build_int_2 (imp_count, 0), initlist); /* cat_def_cnt = { ..., 5, ... } */ initlist = tree_cons (NULL_TREE, build_int_2 (cat_count, 0), initlist); /* cls_def = { ..., { &Foo, &Bar, ...}, ... } */ if (imp_count || cat_count || static_instances_decl) { tree field = TYPE_FIELDS (type); field = TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (field)))); initlist = tree_cons (NULL_TREE, init_def_list (TREE_TYPE (field)), initlist); } return build_constructor (type, 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_IMPLEMENTATION_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))); } } 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 (NULL_TREE, ridpointers[(int) RID_STATIC]); UOBJC_SYMBOLS_decl = start_decl (get_identifier ("_OBJC_SYMBOLS"), tree_cons (NULL_TREE, objc_symtab_template, sc_spec), 1, NULL_TREE, NULL_TREE); TREE_USED (UOBJC_SYMBOLS_decl) = 1; DECL_IGNORED_P (UOBJC_SYMBOLS_decl) = 1; DECL_ARTIFICIAL (UOBJC_SYMBOLS_decl) = 1; finish_decl (UOBJC_SYMBOLS_decl, init_objc_symtab (TREE_TYPE (UOBJC_SYMBOLS_decl)), NULL_TREE);}static treeinit_module_descriptor (type) tree type;{ tree initlist, expr; /* version = { 1, ... } */ expr = build_int_2 (OBJC_VERSION, 0); initlist = build_tree_list (NULL_TREE, expr); /* size = { ..., sizeof (struct objc_module), ... } */ expr = size_in_bytes (objc_module_template); initlist = tree_cons (NULL_TREE, expr, initlist); /* name = { ..., "foo.m", ... } */ expr = add_objc_string (get_identifier (input_filename), class_names); initlist = tree_cons (NULL_TREE, expr, initlist); /* symtab = { ..., _OBJC_SYMBOLS, ... } */ if (UOBJC_SYMBOLS_decl) expr = build_unary_op (ADDR_EXPR, UOBJC_SYMBOLS_decl, 0); else expr = build_int_2 (0, 0); initlist = tree_cons (NULL_TREE, expr, initlist); return build_constructor (type, 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). struct objc_module { ... } _OBJC_MODULE = { ... }; */static char *build_module_descriptor (){ tree decl_specs, field_decl, field_decl_chain; objc_module_template = start_struct (RECORD_TYPE, get_identifier (UTAG_MODULE)); /* Long version; */ decl_specs = build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG]); field_decl = get_identifier ("version"); field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULL_TREE); field_decl_chain = field_decl; /* long size; */ decl_specs = build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG]); field_decl = get_identifier ("size"); field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULL_TREE); chainon (field_decl_chain, field_decl); /* char *name; */ decl_specs = build_tree_list (NULL_TREE, ridpointers[(int) RID_CHAR]); field_decl = build1 (INDIRECT_REF, NULL_TREE, get_identifier ("name")); field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULL_TREE); chainon (field_decl_chain, field_decl); /* struct objc_symtab *symtab; */ decl_specs = get_identifier (UTAG_SYMTAB); decl_specs = build_tree_list (NULL_TREE, xref_tag (RECORD_TYPE, decl_specs)); field_decl = build1 (INDIRECT_REF, NULL_TREE, get_identifier ("symtab")); field_decl = grokfield (input_filename, lineno, field_decl, decl_specs, NULL_TREE); chainon (field_decl_chain, field_decl); finish_struct (objc_module_template, field_decl_chain, NULL_TREE); /* Create an instance of "objc_module". */ decl_specs = tree_cons (NULL_TREE, objc_module_template, build_tree_list (NULL_TREE, ridpointers[(int) RID_STATIC])); UOBJC_MODULES_decl = start_decl (get_identifier ("_OBJC_MODULES"), decl_specs, 1, NULL_TREE, NULL_TREE); DECL_ARTIFICIAL (UOBJC_MODULES_decl) = 1; DECL_IGNORED_P (UOBJC_MODULES_decl) = 1; finish_decl (UOBJC_MODULES_decl, init_module_descriptor (TREE_TYPE (UOBJC_MODULES_decl)), NULL_TREE); /* Mark the decl to avoid "defined but not used" warning. */ DECL_IN_SYSTEM_HEADER (UOBJC_MODULES_decl) = 1; /* Generate a constructor call for the module descriptor. This code was generated by reading the grammar rules of c-parse.in; Therefore, it may not be the most efficient way of generating the requisite code. */ if (flag_next_runtime) return 0; { tree parms, function_decl, decelerator, void_list_node; tree function_type; extern tree get_file_function_name (); tree init_function_name = get_file_function_name ('I'); /* Declare void __objc_execClass (void *); */ void_list_node = build_tree_list (NULL_TREE, void_type_node); function_type = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node, void_list_node)); function_decl = build_decl (FUNCTION_DECL, get_identifier (TAG_EXECCLASS), function_type); DECL_EXTERNAL (function_decl) = 1; DECL_ARTIFICIAL (function_decl) = 1; TREE_PUBLIC (function_decl) = 1; pushdecl (function_decl); rest_of_decl_compilation (function_decl, 0, 0, 0); parms = build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, UOBJC_MODULES_decl, 0)); decelerator = build_function_call (function_decl, parms); /* void _GLOBAL_$I$<gnyf> () {objc_execClass (&L_OBJC_MODULES);} */ start_function (void_list_node, build_parse_node (CALL_EXPR, init_function_name, /* This has the format of the output of get_parm_info. */ tree_cons (NULL_TREE, NULL_TREE, void_list_node), NULL_TREE), NULL_TREE, NULL_TREE, 0);#if 0 /* This should be turned back on later for the systems where collect is not needed. */ /* Make these functions nonglobal so each file can use the same name. */ TREE_PUBLIC (current_function_decl) = 0;#endif TREE_USED (current_function_decl) = 1; store_parm_decls (); assemble_external (function_decl); c_expand_expr_stmt (decelerator); TREE_PUBLIC (current_function_decl) = 1; function_decl = current_function_decl; finish_function (0); /* Return the name of the constructor function. */ return XSTR (XEXP (DECL_RTL (function_decl), 0), 0); }}/* extern const char _OBJC_STRINGS[]; */static voidgenerate_forward_declaration_to_string_table (){ tree sc_spec, decl_specs, expr_decl; sc_spec = tree_cons (NULL_TREE, ridpointers[(int) RID_EXTERN], NULL_TREE); decl_specs = tree_cons (NULL_TREE, ridpointers[(int) RID_CHAR], sc_spec); expr_decl = build_nt (ARRAY_REF, get_identifier ("_OBJC_STRINGS"), NULL_TREE); UOBJC_STRINGS_decl = define_decl (expr_decl, decl_specs);}/* Return the DECL of the string IDENT in the SECTION. */static treeget_objc_string_decl (ident, section) tree ident; enum string_section section;{ tree chain, decl; if (section == class_names) chain = class_names_chain; else if (section == meth_var_names) chain = meth_var_names_chain; else if (section == meth_var_types) chain = meth_var_types_chain; for (; chain != 0; chain = TREE_VALUE (chain)) if (TREE_VALUE (chain) == ident) return (TREE_PURPOSE (chain)); abort (); return NULL_TREE;}/* Output references to all statically allocated objects. Return the DECL for the array built. */static voidgenerate_static_references (){ tree decls = NULL_TREE, ident, decl_spec, expr_decl, expr = NULL_TREE; tree class_name, class, decl, instance, idecl, initlist;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -