summaryrefslogtreecommitdiff
path: root/gcc/objc/objc-act.c
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2015-04-22 10:21:45 +0000
committer <>2015-04-25 21:44:09 +0000
commitf80b5ea1605c9f9408c5aa386ba71c16d918ebbf (patch)
treebb7eafaa81fc4b8c5c215bc08d517fd158db234a /gcc/objc/objc-act.c
parentc27a97d04853380f1e80525391b3f0d156ed4c84 (diff)
downloadgcc-tarball-f80b5ea1605c9f9408c5aa386ba71c16d918ebbf.tar.gz
Imported from /home/lorry/working-area/delta_gcc-tarball/gcc-5.1.0.tar.bz2.gcc-5.1.0
Diffstat (limited to 'gcc/objc/objc-act.c')
-rw-r--r--gcc/objc/objc-act.c165
1 files changed, 110 insertions, 55 deletions
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index cb0b5ac6a7..6bd4dcc29e 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -1,5 +1,5 @@
/* Implement classes and message passing for Objective C.
- Copyright (C) 1992-2014 Free Software Foundation, Inc.
+ Copyright (C) 1992-2015 Free Software Foundation, Inc.
Contributed by Steve Naroff.
This file is part of GCC.
@@ -22,7 +22,18 @@ along with GCC; see the file COPYING3. If not see
#include "system.h"
#include "coretypes.h"
#include "tm.h"
+#include "hash-set.h"
+#include "machmode.h"
+#include "vec.h"
+#include "double-int.h"
+#include "input.h"
+#include "alias.h"
+#include "symtab.h"
+#include "options.h"
+#include "wide-int.h"
+#include "inchash.h"
#include "tree.h"
+#include "fold-const.h"
#include "stringpool.h"
#include "stor-layout.h"
#include "attribs.h"
@@ -43,15 +54,21 @@ along with GCC; see the file COPYING3. If not see
#include "objc-act.h"
#include "objc-map.h"
#include "input.h"
+#include "hard-reg-set.h"
#include "function.h"
#include "toplev.h"
#include "debug.h"
#include "c-family/c-target.h"
#include "diagnostic-core.h"
#include "intl.h"
+#include "hash-map.h"
+#include "is-a.h"
+#include "plugin-api.h"
+#include "ipa-ref.h"
#include "cgraph.h"
#include "tree-iterator.h"
#include "hash-table.h"
+#include "wide-int.h"
#include "langhooks-def.h"
/* Different initialization, code gen and meta data generation for each
runtime. */
@@ -226,7 +243,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;
@@ -252,7 +269,7 @@ vec<tree, va_gc> *local_variables_to_volatilize = NULL;
/* Store all constructed constant strings in a hash table so that
they get uniqued properly. */
-struct GTY(()) string_descriptor {
+struct GTY((for_user)) string_descriptor {
/* The literal argument . */
tree literal;
@@ -260,7 +277,13 @@ struct GTY(()) string_descriptor {
tree constructor;
};
-static GTY((param_is (struct string_descriptor))) htab_t string_htab;
+struct objc_string_hasher : ggc_hasher<string_descriptor *>
+{
+ static hashval_t hash (string_descriptor *);
+ static bool equal (string_descriptor *, string_descriptor *);
+};
+
+static GTY(()) hash_table<objc_string_hasher> *string_htab;
FILE *gen_declaration_file;
@@ -394,6 +417,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 ();
@@ -446,7 +485,7 @@ objc_write_global_declarations (void)
char * const dumpname = concat (dump_base_name, ".decl", NULL);
gen_declaration_file = fopen (dumpname, "w");
if (gen_declaration_file == 0)
- fatal_error ("can%'t open %s: %m", dumpname);
+ fatal_error (input_location, "can%'t open %s: %m", dumpname);
free (dumpname);
}
@@ -568,7 +607,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 +685,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
@@ -1999,7 +2038,8 @@ objc_add_method_declaration (bool is_class_method, tree decl, tree attributes)
impossible to get here. But it's good to have the check in
case the parser changes.
*/
- fatal_error ("method declaration not in @interface context");
+ fatal_error (input_location,
+ "method declaration not in @interface context");
}
if (flag_objc1_only && attributes)
@@ -2678,12 +2718,16 @@ objc_copy_binfo (tree binfo)
static void
objc_xref_basetypes (tree ref, tree basetype)
{
+ tree variant;
tree binfo = make_tree_binfo (basetype ? 1 : 0);
-
TYPE_BINFO (ref) = binfo;
BINFO_OFFSET (binfo) = size_zero_node;
BINFO_TYPE (binfo) = ref;
+ gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
+ for (variant = ref; variant; variant = TYPE_NEXT_VARIANT (variant))
+ TYPE_BINFO (variant) = binfo;
+
if (basetype)
{
tree base_binfo = objc_copy_binfo (TYPE_BINFO (basetype));
@@ -2820,7 +2864,7 @@ check_protocol_recursively (tree proto, tree list)
/* definition_required */ false);
if (pp == proto)
- fatal_error ("protocol %qE has circular dependency",
+ fatal_error (input_location, "protocol %qE has circular dependency",
PROTOCOL_NAME (pp));
if (pp)
check_protocol_recursively (proto, PROTOCOL_LIST (pp));
@@ -3086,10 +3130,10 @@ my_build_string_pointer (int len, const char *str)
return build1 (ADDR_EXPR, ptrtype, string);
}
-static hashval_t
-string_hash (const void *ptr)
+hashval_t
+objc_string_hasher::hash (string_descriptor *ptr)
{
- const_tree const str = ((const struct string_descriptor *)ptr)->literal;
+ const_tree const str = ptr->literal;
const unsigned char *p = (const unsigned char *) TREE_STRING_POINTER (str);
int i, len = TREE_STRING_LENGTH (str);
hashval_t h = len;
@@ -3100,11 +3144,11 @@ string_hash (const void *ptr)
return h;
}
-static int
-string_eq (const void *ptr1, const void *ptr2)
+bool
+objc_string_hasher::equal (string_descriptor *ptr1, string_descriptor *ptr2)
{
- const_tree const str1 = ((const struct string_descriptor *)ptr1)->literal;
- const_tree const str2 = ((const struct string_descriptor *)ptr2)->literal;
+ const_tree const str1 = ptr1->literal;
+ const_tree const str2 = ptr2->literal;
int len1 = TREE_STRING_LENGTH (str1);
return (len1 == TREE_STRING_LENGTH (str2)
@@ -3126,7 +3170,6 @@ objc_build_string_object (tree string)
int length;
tree addr;
struct string_descriptor *desc, key;
- void **loc;
/* We should be passed a STRING_CST. */
gcc_checking_assert (TREE_CODE (string) == STRING_CST);
@@ -3177,12 +3220,12 @@ objc_build_string_object (tree string)
/* Perhaps we already constructed a constant string just like this one? */
key.literal = string;
- loc = htab_find_slot (string_htab, &key, INSERT);
- desc = (struct string_descriptor *) *loc;
+ string_descriptor **loc = string_htab->find_slot (&key, INSERT);
+ desc = *loc;
if (!desc)
{
- *loc = desc = ggc_alloc_string_descriptor ();
+ *loc = desc = ggc_alloc<string_descriptor> ();
desc->literal = string;
desc->constructor =
(*runtime.build_const_string_constructor) (input_location, string, length);
@@ -3923,8 +3966,7 @@ objc_detect_field_duplicates (bool check_superclasses_only)
{
/* First, build the hashtable by putting all the instance
variables of superclasses in it. */
- hash_table <decl_name_hash> htab;
- htab.create (37);
+ hash_table<decl_name_hash> htab (37);
tree interface;
for (interface = lookup_interface (CLASS_SUPER_NAME
(objc_interface_context));
@@ -4001,7 +4043,6 @@ objc_detect_field_duplicates (bool check_superclasses_only)
}
}
}
- htab.dispose ();
return true;
}
}
@@ -4631,16 +4672,14 @@ mark_referenced_methods (void)
chain = CLASS_CLS_METHODS (impent->imp_context);
while (chain)
{
- cgraph_mark_force_output_node (
- cgraph_get_create_node (METHOD_DEFINITION (chain)));
+ cgraph_node::get_create (METHOD_DEFINITION (chain))->mark_force_output ();
chain = DECL_CHAIN (chain);
}
chain = CLASS_NST_METHODS (impent->imp_context);
while (chain)
{
- cgraph_mark_force_output_node (
- cgraph_get_create_node (METHOD_DEFINITION (chain)));
+ cgraph_node::get_create (METHOD_DEFINITION (chain))->mark_force_output ();
chain = DECL_CHAIN (chain);
}
}
@@ -4883,12 +4922,10 @@ objc_decl_method_attributes (tree *node, tree attributes, int flags)
number = TREE_VALUE (second_argument);
if (number
&& TREE_CODE (number) == INTEGER_CST
- && TREE_INT_CST_HIGH (number) == 0)
- {
- TREE_VALUE (second_argument)
- = build_int_cst (integer_type_node,
- TREE_INT_CST_LOW (number) + 2);
- }
+ && !wi::eq_p (number, 0))
+ TREE_VALUE (second_argument)
+ = wide_int_to_tree (TREE_TYPE (number),
+ wi::add (number, 2));
/* This is the third argument, the "first-to-check",
which specifies the index of the first argument to
@@ -4898,13 +4935,10 @@ objc_decl_method_attributes (tree *node, tree attributes, int flags)
number = TREE_VALUE (third_argument);
if (number
&& TREE_CODE (number) == INTEGER_CST
- && TREE_INT_CST_HIGH (number) == 0
- && TREE_INT_CST_LOW (number) != 0)
- {
- TREE_VALUE (third_argument)
- = build_int_cst (integer_type_node,
- TREE_INT_CST_LOW (number) + 2);
- }
+ && !wi::eq_p (number, 0))
+ TREE_VALUE (third_argument)
+ = wide_int_to_tree (TREE_TYPE (number),
+ wi::add (number, 2));
}
filtered_attributes = chainon (filtered_attributes,
new_attribute);
@@ -4936,15 +4970,11 @@ objc_decl_method_attributes (tree *node, tree attributes, int flags)
{
/* Get the value of the argument and add 2. */
tree number = TREE_VALUE (argument);
- if (number
- && TREE_CODE (number) == INTEGER_CST
- && TREE_INT_CST_HIGH (number) == 0
- && TREE_INT_CST_LOW (number) != 0)
- {
- TREE_VALUE (argument)
- = build_int_cst (integer_type_node,
- TREE_INT_CST_LOW (number) + 2);
- }
+ if (number && TREE_CODE (number) == INTEGER_CST
+ && !wi::eq_p (number, 0))
+ TREE_VALUE (argument)
+ = wide_int_to_tree (TREE_TYPE (number),
+ wi::add (number, 2));
argument = TREE_CHAIN (argument);
}
@@ -5768,8 +5798,7 @@ hash_init (void)
alias_name_map = objc_map_alloc_ggc (200);
/* Initialize the hash table used to hold the constant string objects. */
- string_htab = htab_create_ggc (31, string_hash,
- string_eq, NULL);
+ string_htab = hash_table<objc_string_hasher>::create_ggc (31);
}
/* Use the following to add a method to class_method_map or
@@ -7024,7 +7053,7 @@ continue_class (tree klass)
uprivate_record = CLASS_STATIC_TEMPLATE (implementation_template);
objc_instance_type = build_pointer_type (uprivate_record);
- imp_entry = ggc_alloc_imp_entry ();
+ imp_entry = ggc_alloc<struct imp_entry> ();
imp_entry->next = imp_list;
imp_entry->imp_context = klass;
@@ -9366,6 +9395,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 +9417,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;
}
@@ -10096,4 +10134,21 @@ objc_common_init_ts (void)
MARK_TS_TYPED (PROPERTY_REF);
}
+size_t
+objc_common_tree_size (enum tree_code code)
+{
+ switch (code)
+ {
+ case CLASS_METHOD_DECL:
+ case INSTANCE_METHOD_DECL:
+ case KEYWORD_DECL:
+ case PROPERTY_DECL:
+ return sizeof (struct tree_decl_non_common);
+ default:
+ gcc_unreachable ();
+
+ }
+}
+
+
#include "gt-objc-objc-act.h"