diff options
author | zlaski <zlaski@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-31 06:17:55 +0000 |
---|---|---|
committer | zlaski <zlaski@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-31 06:17:55 +0000 |
commit | e913c82d52f267ae5b7e1e651c74b21482bd8f03 (patch) | |
tree | fd41069a69da16dfa7e8da375572cb0cbfc16ce8 /gcc/objc | |
parent | 2a9fdfe18a6ba0d2c24542e8f2191b995fa92646 (diff) | |
download | gcc-e913c82d52f267ae5b7e1e651c74b21482bd8f03.tar.gz |
[gcc/ChangeLog]
2004-10-30 Ziemowit Laski <zlaski@apple.com>
* c-common.h (objc_lookup_ivar): Add second parameter to
prototype.
* c-typeck.c (build_external_ref): After looking up symbol,
pass it to objc_lookup_ivar() to decide whether it or the
ivar should be used, rather than deciding the issue locally.
* stub-objc.c (objc_lookup_ivar): Add an OTHER parameter,
which is simply returned in the non-ObjC case.
[gcc/objc/ChangeLog]
2004-10-30 Ziemowit Laski <zlaski@apple.com>
* objc-act.c (objc_lookup_ivar): The new OTHER parameter
contains the result of the ID lookup by the C or C++
front-end; in class methods, use OTHER if it exists;
in instance methods, use OTHER only if it is locally
declared.
[gcc/testsuite/ChangeLog]
2004-10-30 Ziemowit Laski <zlaski@apple.com>
* objc.dg/local-decl-1.m: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89912 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/objc')
-rw-r--r-- | gcc/objc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 46 |
2 files changed, 43 insertions, 11 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 7bb40f7cac9..700cb04fea3 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,11 @@ +2004-10-30 Ziemowit Laski <zlaski@apple.com> + + * objc-act.c (objc_lookup_ivar): The new OTHER parameter + contains the result of the ID lookup by the C or C++ + front-end; in class methods, use OTHER if it exists; + in instance methods, use OTHER only if it is locally + declared. + 2004-10-26 Ziemowit Laski <zlaski@apple.com> * objc-act.c (finish_class): Do not synthesize bogus diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 7b21ede8cdf..3474ded418f 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -8435,25 +8435,49 @@ generate_objc_image_info (void) finish_var_decl (decl, initlist); } -/* Look up ID as an instance variable. */ +/* Look up ID as an instance variable. OTHER contains the result of + the C or C++ lookup, which we may want to use instead. */ tree -objc_lookup_ivar (tree id) +objc_lookup_ivar (tree other, tree id) { - tree decl; + tree ivar; + + /* If we are not inside of an ObjC method, ivar lookup makes no sense. */ + if (!objc_method_context) + return other; - if (objc_method_context && !strcmp (IDENTIFIER_POINTER (id), "super")) + if (!strcmp (IDENTIFIER_POINTER (id), "super")) /* We have a message to super. */ return get_super_receiver (); - else if (objc_method_context && (decl = is_ivar (objc_ivar_chain, id))) + + /* In a class method, look up an instance variable only as a last + resort. */ + if (TREE_CODE (objc_method_context) == CLASS_METHOD_DECL + && other && other != error_mark_node) + return other; + + /* Look up the ivar, but do not use it if it is not accessible. */ + ivar = is_ivar (objc_ivar_chain, id); + + if (!ivar || is_private (ivar)) + return other; + + /* In an instance method, a local variable (or parameter) may hide the + instance variable. */ + if (TREE_CODE (objc_method_context) == INSTANCE_METHOD_DECL + && other && other != error_mark_node && !DECL_FILE_SCOPE_P (other)) { - if (is_private (decl)) - return 0; - else - return build_ivar_reference (id); + warning ("local declaration of %qs hides instance variable", + IDENTIFIER_POINTER (id)); + + return other; } - else - return 0; + + /* At this point, we are either in an instance method with no obscuring + local definitions, or in a class method with no alternate definitions + at all. */ + return build_ivar_reference (id); } #include "gt-objc-objc-act.h" |