?? objc-act.c
字號:
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); } } 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) { 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); if (!flag_next_runtime) { /* statics = { ..., _OBJC_STATIC_INSTANCES, ... } */ 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); } /* 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); if (!flag_next_runtime) { /* void *statics */ decl_specs = get_identifier (UTAG_STATICS); decl_specs = build_tree_list (NULL_TREE, xref_tag (RECORD_TYPE, decl_specs)); field_decl = build1 (INDIRECT_REF, NULL_TREE, get_identifier ("statics")); 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 treegenerate_static_references (){ tree decls = NULL_TREE, ident, decl_spec, expr_decl, expr = NULL_TREE; tree class_name, class, decl, instance, idecl, initlist; tree cl_chain, in_chain, type; int num_inst, num_class; char buf[256]; if (flag_next_runtime) abort (); for (cl_chain = objc_static_instances, num_class = 0; cl_chain; cl_chain = TREE_CHAIN (cl_chain), num_class++) { for (num_inst = 0, in_chain = TREE_PURPOSE (cl_chain); in_chain; num_inst++, in_chain = TREE_CHAIN (in_chain)); sprintf (buf, "_OBJC_STATIC_INSTANCES_%d", num_class); ident = get_identifier (buf); expr_decl = build_nt (ARRAY_REF, ident, NULL_TREE); decl_spec = tree_cons (NULL_TREE, build_pointer_type (void_type_node), build_tree_list (NULL_TREE, ridpointers[(int) RID_STATIC])); decl = start_decl (expr_decl, decl_spec, 1, NULL_TREE, NULL_TREE); DECL_CONTEXT (decl) = 0; DECL_ARTIFICIAL (decl) = 1; /* Output {class_name, ...}. */ class = TREE_VALUE (cl_chain); class_name = get_objc_string_decl (TYPE_NAME (class), class_names); initlist = build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, class_name, 1)); /* Output {..., instance, ...}. */ for (in_chain = TREE_PURPOSE (cl_chain); in_chain; in_chain = TREE_CHAIN (in_chain)) { expr = build_unary_op (ADDR_EXPR, TREE_VALUE (in_chain), 1); initlist = tree_cons (NULL_TREE, expr, initlist); } /* Output {..., NULL}. */ initlist = tree_cons (NULL_TREE, build_int_2 (0, 0), initlist); expr = build_constructor (TREE_TYPE (decl), nreverse (initlist)); finish_decl (decl, expr, NULL_TREE); TREE_USED (decl) = 1; type = build_array_type (build_pointer_type (void_type_node), 0); decl = build_decl (VAR_DECL, ident, type); make_decl_rtl (decl, 0, 1); TREE_USED (decl) = 1; decls = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, decl, 1), decls); } decls = tree_cons (NULL_TREE, build_int_2 (0, 0), decls); ident = get_identifier ("_OBJC_STATIC_INSTANCES"); expr_decl = build_nt (ARRAY_REF, ident, NULL_TREE); decl_spec = tree_cons (NULL_TREE, build_pointer_type (void_type_node), build_tree_list (NULL_TREE, ridpointers[(int) RID_STATIC])); static_instances_decl = start_decl (expr_decl, decl_spec, 1, NULL_TREE, NULL_TREE); DECL_CONTEXT (static_instances_decl) = 0; DECL_ARTIFICIAL (static_instances_decl) = 1; end_temporary_allocation (); expr = build_constructor (TREE_TYPE (static_instances_decl), nreverse (decls)); finish_decl (static_instances_decl, expr, NULL_TREE);}/* Output all strings. */static voidgenerate_strings (){ tree sc_spec, decl_specs, expr_decl; tree chain, string_expr; tree string, decl; for (chain = class_names_chain; chain; chain = TREE_CHAIN (chain)) { string = TREE_VALUE (chain); decl = TREE_PURPOSE (chain); sc_spec = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC], NULL_TREE);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -