diff options
author | iains <iains@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-13 08:24:48 +0000 |
---|---|---|
committer | iains <iains@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-13 08:24:48 +0000 |
commit | 40c8d1dd9270673b786230c1a649fd5a12641562 (patch) | |
tree | dd26564b609fa5c247334c65f3d8f1bb72743eea /gcc/objc | |
parent | 570c5a3d4bf441cde795a9f759d1f4b0c4302688 (diff) | |
download | gcc-40c8d1dd9270673b786230c1a649fd5a12641562.tar.gz |
implement method attributes.
gcc/c-family:
merge from FSF apple 'trunk' branch.
2006-04-26 Fariborz Jahanian <fjahanian@apple.com>
Radar 3803157 (method attributes)
* c-common.c (handle_deprecated_attribute): Recognize
objc methods as valid declarations.
* c-common.h: Declare objc_method_decl ().
* stub-objc.c (objc_method_decl): New stub.
gcc/objc:
merge from FSF apple 'trunk' branch.
2006-04-26 Fariborz Jahanian <fjahanian@apple.com>
Radar 3803157 (method attributes)
* objc/objc-act.h (METHOD_TYPE_ATTRIBUTES): New macro.
* objc/objc-act.c (objc_decl_method_attributes): New.
(objc_add_method_declaration): Process method's attribute.
(objc_start_method_definition): Ditto.
(build_objc_method_call): Inject method attribute into
built function type.
(objc_method_decl): New.
(objc_warn_deprecated)use): New.
testsuite:
* objc.dg/attributes/method-attribute-1.m: Update to respond
to implemented method attributes..
* objc.dg/attributes/method-attribute-2.m: Likewise.
* objc.dg/attributes/method-attribute-3.m: Likewise.
* obj-c++.dg/attributes/method-attribute-1.mm: Likewise.
* obj-c++.dg/attributes/method-attribute-2.mm: Likewise.
* obj-c++.dg/attributes/method-attribute-3.mm: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165415 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/objc')
-rw-r--r-- | gcc/objc/ChangeLog | 15 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 89 | ||||
-rw-r--r-- | gcc/objc/objc-act.h | 1 |
3 files changed, 89 insertions, 16 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 133141c3219..ed1bc2e5ed0 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,18 @@ +2010-10-13 Iain Sandoe <iains@gcc.gnu.org> + + merge from FSF apple 'trunk' branch. + + 2006-04-26 Fariborz Jahanian <fjahanian@apple.com> + Radar 3803157 (method attributes) + * objc/objc-act.h (METHOD_TYPE_ATTRIBUTES): New macro. + * objc/objc-act.c (objc_decl_method_attributes): New. + (objc_add_method_declaration): Process method's attribute. + (objc_start_method_definition): Ditto. + (build_objc_method_call): Inject method attribute into + built function type. + (objc_method_decl): New. + (objc_warn_deprecated)use): New. + 2010-10-07 Andi Kleen <ak@linux.intel.com> * Make-lang.in (cc1obj-dummy): Remove. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 3a135196f88..26d490efb2b 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -52,6 +52,9 @@ along with GCC; see the file COPYING3. If not see #include "hashtab.h" #include "langhooks-def.h" +/* For default_tree_printer (). */ +#include "tree-pretty-print.h" + /* For enum gimplify_status */ #include "gimple.h" @@ -177,6 +180,9 @@ static void build_fast_enumeration_state_template (void); static void objc_generate_cxx_cdtors (void); #endif +/* objc attribute */ +static void objc_decl_method_attributes (tree*, tree, int); +static tree build_keyword_selector (tree); static const char *synth_id_with_class_suffix (const char *, tree); /* Hash tables to manage the global pool of method prototypes. */ @@ -215,6 +221,7 @@ static void really_start_method (tree, tree); static void really_start_method (tree, struct c_arg_info *); #endif static int comp_proto_with_proto (tree, tree, int); +static tree get_arg_type_list (tree, int, int); static tree objc_decay_parm_type (tree); static void objc_push_parm (tree); #ifdef OBJCPLUS @@ -511,6 +518,30 @@ generate_struct_by_value_array (void) exit (0); } +/* FIXME: We need to intercept calls to warn_deprecated_use, since that + ultimately calls warning () with a "qD" formatter for decls. The 'D' + formatter does not handle ObjC-specific decls (in ObjC++). For now, we + interpose a switch to the default handler which simply prints the decl + identifier. + Eventually, we should handle this within the objc{,p}/ code. */ + +static void +objc_warn_deprecated_use (tree depitem, tree attr) +{ + if (DECL_P (depitem)) + { + static bool (*sav_printer) (pretty_printer *, text_info *, const char *, + int, bool, bool, bool) = NULL ; + if (sav_printer == NULL) + sav_printer = diagnostic_format_decoder (global_dc) ; + diagnostic_format_decoder (global_dc) = &default_tree_printer; + warn_deprecated_use (depitem, attr); + diagnostic_format_decoder (global_dc) = sav_printer; + } + else + warn_deprecated_use (depitem, attr); +} + bool objc_init (void) { @@ -804,11 +835,7 @@ objc_add_method_declaration (tree decl, tree attributes) fatal_error ("method declaration not in @interface context"); } - if (attributes) - warning_at (input_location, OPT_Wattributes, - "method attributes are not available in this version" - " of the compiler, (ignored)"); - + objc_decl_method_attributes (&decl, attributes, 0); objc_add_method (objc_interface_context, decl, objc_inherit_code == CLASS_METHOD_DECL, @@ -830,11 +857,6 @@ objc_start_method_definition (tree decl, tree attributes) if (decl != NULL_TREE && METHOD_SEL_NAME (decl) == error_mark_node) return false; - if (attributes) - warning_at (input_location, OPT_Wattributes, - "method attributes are not available in this version" - " of the compiler, (ignored)"); - #ifndef OBJCPLUS /* Indicate no valid break/continue context by setting these variables to some non-null, non-label value. We'll notice and emit the proper @@ -842,6 +864,7 @@ objc_start_method_definition (tree decl, tree attributes) c_break_label = c_cont_label = size_zero_node; #endif + objc_decl_method_attributes (&decl, attributes, 0); objc_add_method (objc_implementation_context, decl, objc_inherit_code == CLASS_METHOD_DECL, @@ -6154,6 +6177,32 @@ build_method_decl (enum tree_code code, tree ret_type, tree selector, #define METHOD_DEF 0 #define METHOD_REF 1 +/* This routine processes objective-c method attributes. */ + +static void +objc_decl_method_attributes (tree *node, tree attributes, int flags) +{ + tree sentinel_attr = lookup_attribute ("sentinel", attributes); + if (sentinel_attr) + { + /* hackery to make an obj method look like a function type. */ + tree rettype = TREE_TYPE (*node); + TREE_TYPE (*node) = build_function_type (TREE_VALUE (rettype), + get_arg_type_list (*node, METHOD_REF, 0)); + decl_attributes (node, attributes, flags); + METHOD_TYPE_ATTRIBUTES (*node) = TYPE_ATTRIBUTES (TREE_TYPE (*node)); + TREE_TYPE (*node) = rettype; + } + else + decl_attributes (node, attributes, flags); +} + +bool +objc_method_decl (enum tree_code opcode) +{ + return opcode == INSTANCE_METHOD_DECL || opcode == CLASS_METHOD_DECL; +} + /* Used by `build_objc_method_call' and `comp_proto_with_proto'. Return an argument list for method METH. CONTEXT is either METHOD_DEF or METHOD_REF, saying whether we are trying to define a method or call @@ -6699,14 +6748,22 @@ build_objc_method_call (location_t loc, int super_flag, tree method_prototype, = (method_prototype ? TREE_VALUE (TREE_TYPE (method_prototype)) : objc_object_type); - tree sender_cast - = build_pointer_type - (build_function_type - (ret_type, - get_arg_type_list - (method_prototype, METHOD_REF, super_flag))); + + tree method_param_types = + get_arg_type_list (method_prototype, METHOD_REF, super_flag); + tree ftype = build_function_type (ret_type, method_param_types); + tree sender_cast; tree method, t; + if (method_prototype && METHOD_TYPE_ATTRIBUTES (method_prototype)) + ftype = build_type_attribute_variant ( + ftype, METHOD_TYPE_ATTRIBUTES (method_prototype)); + + sender_cast = build_pointer_type (ftype); + + if (method_prototype && TREE_DEPRECATED (method_prototype)) + objc_warn_deprecated_use (method_prototype, NULL_TREE); + lookup_object = build_c_cast (loc, rcv_p, lookup_object); /* Use SAVE_EXPR to avoid evaluating the receiver twice. */ diff --git a/gcc/objc/objc-act.h b/gcc/objc/objc-act.h index 9f6ddcac724..f7a075569d2 100644 --- a/gcc/objc/objc-act.h +++ b/gcc/objc/objc-act.h @@ -52,6 +52,7 @@ tree objc_eh_personality (void); #define METHOD_ADD_ARGS_ELLIPSIS_P(DECL) ((DECL)->decl_common.lang_flag_0) #define METHOD_DEFINITION(DECL) ((DECL)->decl_common.initial) #define METHOD_ENCODING(DECL) ((DECL)->decl_minimal.context) +#define METHOD_TYPE_ATTRIBUTES(DECL) ((DECL)->decl_common.abstract_origin) /* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE, CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE, |