diff options
author | Dimitris Papavasiliou <dpapavas@gmail.com> | 2014-04-24 15:58:44 +0000 |
---|---|---|
committer | Mike Stump <mrs@gcc.gnu.org> | 2014-04-24 15:58:44 +0000 |
commit | dcaaa5a04a88256c5838696742be5efb6ced353a (patch) | |
tree | ba1651fb43cb7ce456f3f31e912458a294219553 /gcc/objc/objc-act.c | |
parent | 07fb62554c2667cc35033f7c6439acf3e35e1996 (diff) | |
download | gcc-dcaaa5a04a88256c5838696742be5efb6ced353a.zip gcc-dcaaa5a04a88256c5838696742be5efb6ced353a.tar.gz gcc-dcaaa5a04a88256c5838696742be5efb6ced353a.tar.bz2 |
flag-types.h (enum ivar_visibility): Add.
2014-04-24 Dimitris Papavasiliou <dpapavas@gmail.com>
* flag-types.h (enum ivar_visibility): Add.
c-family:
* c.opt (Wshadow-ivar, flocal-ivars, fivar-visibility): Add.
objc:
* objc-act.c (objc_ivar_visibility, objc_default_ivar_visibility): Add.
(objc_init): Initialize objc_default_ivar_visibility.
(objc_start_class_interface): Use objc_default_ivar_visibility.
(objc_start_class_implementation): Likewise.
(objc_lookup_ivar): Implement -fno-local-ivars.
From-SVN: r209753
Diffstat (limited to 'gcc/objc/objc-act.c')
-rw-r--r-- | gcc/objc/objc-act.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index cb0b5ac..cda345b 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -226,7 +226,7 @@ struct imp_entry *imp_list = 0; int imp_count = 0; /* `@implementation' */ int cat_count = 0; /* `@category' */ -objc_ivar_visibility_kind objc_ivar_visibility; +objc_ivar_visibility_kind objc_ivar_visibility, objc_default_ivar_visibility; /* Use to generate method labels. */ static int method_slot = 0; @@ -394,6 +394,22 @@ objc_init (void) if (!ok) return false; + /* Determine the default visibility for instance variables. */ + switch (default_ivar_visibility) + { + case IVAR_VISIBILITY_PRIVATE: + objc_default_ivar_visibility = OBJC_IVAR_VIS_PRIVATE; + break; + case IVAR_VISIBILITY_PUBLIC: + objc_default_ivar_visibility = OBJC_IVAR_VIS_PUBLIC; + break; + case IVAR_VISIBILITY_PACKAGE: + objc_default_ivar_visibility = OBJC_IVAR_VIS_PACKAGE; + break; + default: + objc_default_ivar_visibility = OBJC_IVAR_VIS_PROTECTED; + } + /* Generate general types and push runtime-specific decls to file scope. */ synth_module_prologue (); @@ -568,7 +584,7 @@ objc_start_class_interface (tree klass, tree super_class, objc_interface_context = objc_ivar_context = start_class (CLASS_INTERFACE_TYPE, klass, super_class, protos, attributes); - objc_ivar_visibility = OBJC_IVAR_VIS_PROTECTED; + objc_ivar_visibility = objc_default_ivar_visibility; } void @@ -646,7 +662,7 @@ objc_start_class_implementation (tree klass, tree super_class) = objc_ivar_context = start_class (CLASS_IMPLEMENTATION_TYPE, klass, super_class, NULL_TREE, NULL_TREE); - objc_ivar_visibility = OBJC_IVAR_VIS_PROTECTED; + objc_ivar_visibility = objc_default_ivar_visibility; } void @@ -9366,6 +9382,12 @@ objc_lookup_ivar (tree other, tree id) && other && other != error_mark_node) return other; + /* Don't look up the ivar if the user has explicitly advised against + it with -fno-local-ivars. */ + + if (!flag_local_ivars) + return other; + /* Look up the ivar, but do not use it if it is not accessible. */ ivar = is_ivar (objc_ivar_chain, id); @@ -9382,8 +9404,11 @@ objc_lookup_ivar (tree other, tree id) && !DECL_FILE_SCOPE_P (other)) #endif { - warning (0, "local declaration of %qE hides instance variable", id); - + if (warn_shadow_ivar == 1 || (warn_shadow && warn_shadow_ivar != 0)) { + warning (warn_shadow_ivar ? OPT_Wshadow_ivar : OPT_Wshadow, + "local declaration of %qE hides instance variable", id); + } + return other; } |