Commit 50ea5861 by Nicola Pero Committed by Nicola Pero

objc-act.c (get_objc_string_decl): Use a switch instead of a chain of ifs.

2010-10-21  Nicola Pero  <nicola.pero@meta-innovation.com>

        * objc-act.c (get_objc_string_decl): Use a switch instead of a
        chain of ifs.  Use gcc_unreachable instead of abort.
        (add_objc_string): Same change.
        (generate_protocol_list): Same change - twice.
        (synth_id_with_class_suffix): Same change.
        (build_keyword_selector): Same change - twice.
        (objc_build_message_expr): Same change.
        (objc_build_selector_expr): Same change.
        (check_methods): Same change - and added missing gcc_unreachable
        for default case.
        (check_methods_accessible): Same change - twice, and added missing
        gcc_unreachable for default case in one of them.
        (start_class): Same change - and added missing gcc_unreachable for
        default case.
        (continue_class): Same change.
        (objc_gen_property_data): Same change.
        (finish_class): Same change.
        (encode_type_qualifiers): Added missing gcc_unreachable.
        (encode_type): Small code tidy up to reduce duplicated code.  Use
        gcc_unreachable instead of abort - twice.
        (encode_gnu_bitfield): Use a switch instead of a chain of ifs -
        twice.  Added missing gcc_unreachable for default case - twice.
        (dump_interface): Use a switch instead of a chain of ifs.
        (handle_impent): Same change.

From-SVN: r165803
parent 05b7a48a
2010-10-21 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-act.c (get_objc_string_decl): Use a switch instead of a
chain of ifs. Use gcc_unreachable instead of abort.
(add_objc_string): Same change.
(generate_protocol_list): Same change - twice.
(synth_id_with_class_suffix): Same change.
(build_keyword_selector): Same change - twice.
(objc_build_message_expr): Same change.
(objc_build_selector_expr): Same change.
(check_methods): Same change - and added missing gcc_unreachable
for default case.
(check_methods_accessible): Same change - twice, and added missing
gcc_unreachable for default case in one of them.
(start_class): Same change - and added missing gcc_unreachable for
default case.
(continue_class): Same change.
(objc_gen_property_data): Same change.
(finish_class): Same change.
(encode_type_qualifiers): Added missing gcc_unreachable.
(encode_type): Small code tidy up to reduce duplicated code. Use
gcc_unreachable instead of abort - twice.
(encode_gnu_bitfield): Use a switch instead of a chain of ifs -
twice. Added missing gcc_unreachable for default case - twice.
(dump_interface): Use a switch instead of a chain of ifs.
(handle_impent): Same change.
2010-10-20 Nicola Pero <nicola.pero@meta-innovation.com> 2010-10-20 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-act.h (objc_inherit_code): Removed. * objc-act.h (objc_inherit_code): Removed.
......
...@@ -3089,20 +3089,26 @@ get_objc_string_decl (tree ident, enum string_section section) ...@@ -3089,20 +3089,26 @@ get_objc_string_decl (tree ident, enum string_section section)
{ {
tree chain; tree chain;
if (section == class_names) switch (section)
chain = class_names_chain; {
else if (section == meth_var_names) case class_names:
chain = meth_var_names_chain; chain = class_names_chain;
else if (section == meth_var_types) break;
chain = meth_var_types_chain; case meth_var_names:
else chain = meth_var_names_chain;
abort (); break;
case meth_var_types:
chain = meth_var_types_chain;
break;
default:
gcc_unreachable ();
}
for (; chain != 0; chain = TREE_CHAIN (chain)) for (; chain != 0; chain = TREE_CHAIN (chain))
if (TREE_VALUE (chain) == ident) if (TREE_VALUE (chain) == ident)
return (TREE_PURPOSE (chain)); return (TREE_PURPOSE (chain));
abort (); gcc_unreachable ();
return NULL_TREE; return NULL_TREE;
} }
...@@ -3519,23 +3525,23 @@ add_objc_string (tree ident, enum string_section section) ...@@ -3519,23 +3525,23 @@ add_objc_string (tree ident, enum string_section section)
char buf[256]; char buf[256];
buf[0] = 0; buf[0] = 0;
if (section == class_names) switch (section)
{ {
case class_names:
chain = &class_names_chain; chain = &class_names_chain;
sprintf (buf, "_OBJC_CLASS_NAME_%d", class_names_idx++); sprintf (buf, "_OBJC_CLASS_NAME_%d", class_names_idx++);
} break;
else if (section == meth_var_names) case meth_var_names:
{
chain = &meth_var_names_chain; chain = &meth_var_names_chain;
sprintf (buf, "_OBJC_METH_VAR_NAME_%d", meth_var_names_idx++); sprintf (buf, "_OBJC_METH_VAR_NAME_%d", meth_var_names_idx++);
} break;
else if (section == meth_var_types) case meth_var_types:
{
chain = &meth_var_types_chain; chain = &meth_var_types_chain;
sprintf (buf, "_OBJC_METH_VAR_TYPE_%d", meth_var_types_idx++); sprintf (buf, "_OBJC_METH_VAR_TYPE_%d", meth_var_types_idx++);
break;
default:
gcc_unreachable ();
} }
else
gcc_unreachable ();
while (*chain) while (*chain)
{ {
...@@ -6100,13 +6106,18 @@ generate_protocol_list (tree i_or_p) ...@@ -6100,13 +6106,18 @@ generate_protocol_list (tree i_or_p)
const char *ref_name; const char *ref_name;
VEC(constructor_elt,gc) *v = NULL; VEC(constructor_elt,gc) *v = NULL;
if (TREE_CODE (i_or_p) == CLASS_INTERFACE_TYPE switch (TREE_CODE (i_or_p))
|| TREE_CODE (i_or_p) == CATEGORY_INTERFACE_TYPE) {
plist = CLASS_PROTOCOL_LIST (i_or_p); case CLASS_INTERFACE_TYPE:
else if (TREE_CODE (i_or_p) == PROTOCOL_INTERFACE_TYPE) case CATEGORY_INTERFACE_TYPE:
plist = PROTOCOL_LIST (i_or_p); plist = CLASS_PROTOCOL_LIST (i_or_p);
else break;
abort (); case PROTOCOL_INTERFACE_TYPE:
plist = PROTOCOL_LIST (i_or_p);
break;
default:
gcc_unreachable ();
}
/* Compute size. */ /* Compute size. */
for (lproto = plist; lproto; lproto = TREE_CHAIN (lproto)) for (lproto = plist; lproto; lproto = TREE_CHAIN (lproto))
...@@ -6134,14 +6145,20 @@ generate_protocol_list (tree i_or_p) ...@@ -6134,14 +6145,20 @@ generate_protocol_list (tree i_or_p)
/* static struct objc_protocol *refs[n]; */ /* static struct objc_protocol *refs[n]; */
if (TREE_CODE (i_or_p) == PROTOCOL_INTERFACE_TYPE) switch (TREE_CODE (i_or_p))
ref_name = synth_id_with_class_suffix ("_OBJC_PROTOCOL_REFS", i_or_p); {
else if (TREE_CODE (i_or_p) == CLASS_INTERFACE_TYPE) case PROTOCOL_INTERFACE_TYPE:
ref_name = synth_id_with_class_suffix ("_OBJC_CLASS_PROTOCOLS", i_or_p); ref_name = synth_id_with_class_suffix ("_OBJC_PROTOCOL_REFS", i_or_p);
else if (TREE_CODE (i_or_p) == CATEGORY_INTERFACE_TYPE) break;
ref_name = synth_id_with_class_suffix ("_OBJC_CATEGORY_PROTOCOLS", i_or_p); case CLASS_INTERFACE_TYPE:
else ref_name = synth_id_with_class_suffix ("_OBJC_CLASS_PROTOCOLS", i_or_p);
abort (); break;
case CATEGORY_INTERFACE_TYPE:
ref_name = synth_id_with_class_suffix ("_OBJC_CATEGORY_PROTOCOLS", i_or_p);
break;
default:
gcc_unreachable ();
}
ptype = build_pointer_type (objc_protocol_template); ptype = build_pointer_type (objc_protocol_template);
array_type = build_sized_array_type (ptype, size + 3); array_type = build_sized_array_type (ptype, size + 3);
...@@ -6465,29 +6482,33 @@ synth_id_with_class_suffix (const char *preamble, tree ctxt) ...@@ -6465,29 +6482,33 @@ synth_id_with_class_suffix (const char *preamble, tree ctxt)
{ {
static char string[BUFSIZE]; static char string[BUFSIZE];
if (TREE_CODE (ctxt) == CLASS_IMPLEMENTATION_TYPE switch (TREE_CODE (ctxt))
|| TREE_CODE (ctxt) == CLASS_INTERFACE_TYPE)
{ {
case CLASS_IMPLEMENTATION_TYPE:
case CLASS_INTERFACE_TYPE:
sprintf (string, "%s_%s", preamble, sprintf (string, "%s_%s", preamble,
IDENTIFIER_POINTER (CLASS_NAME (ctxt))); IDENTIFIER_POINTER (CLASS_NAME (ctxt)));
break;
case CATEGORY_IMPLEMENTATION_TYPE:
case CATEGORY_INTERFACE_TYPE:
{
/* We have a category. */
const char *const class_name
= IDENTIFIER_POINTER (CLASS_NAME (objc_implementation_context));
const char *const class_super_name
= IDENTIFIER_POINTER (CLASS_SUPER_NAME (objc_implementation_context));
sprintf (string, "%s_%s_%s", preamble, class_name, class_super_name);
break;
} }
else if (TREE_CODE (ctxt) == CATEGORY_IMPLEMENTATION_TYPE case PROTOCOL_INTERFACE_TYPE:
|| TREE_CODE (ctxt) == CATEGORY_INTERFACE_TYPE) {
{ const char *protocol_name = IDENTIFIER_POINTER (PROTOCOL_NAME (ctxt));
/* We have a category. */ sprintf (string, "%s_%s", preamble, protocol_name);
const char *const class_name break;
= IDENTIFIER_POINTER (CLASS_NAME (objc_implementation_context)); }
const char *const class_super_name default:
= IDENTIFIER_POINTER (CLASS_SUPER_NAME (objc_implementation_context)); gcc_unreachable ();
sprintf (string, "%s_%s_%s", preamble, class_name, class_super_name);
}
else if (TREE_CODE (ctxt) == PROTOCOL_INTERFACE_TYPE)
{
const char *protocol_name = IDENTIFIER_POINTER (PROTOCOL_NAME (ctxt));
sprintf (string, "%s_%s", preamble, protocol_name);
} }
else
abort ();
return string; return string;
} }
...@@ -6562,12 +6583,17 @@ build_keyword_selector (tree selector) ...@@ -6562,12 +6583,17 @@ build_keyword_selector (tree selector)
/* Scan the selector to see how much space we'll need. */ /* Scan the selector to see how much space we'll need. */
for (key_chain = selector; key_chain; key_chain = TREE_CHAIN (key_chain)) for (key_chain = selector; key_chain; key_chain = TREE_CHAIN (key_chain))
{ {
if (TREE_CODE (selector) == KEYWORD_DECL) switch (TREE_CODE (selector))
key_name = KEYWORD_KEY_NAME (key_chain); {
else if (TREE_CODE (selector) == TREE_LIST) case KEYWORD_DECL:
key_name = TREE_PURPOSE (key_chain); key_name = KEYWORD_KEY_NAME (key_chain);
else break;
abort (); case TREE_LIST:
key_name = TREE_PURPOSE (key_chain);
break;
default:
gcc_unreachable ();
}
if (key_name) if (key_name)
len += IDENTIFIER_LENGTH (key_name) + 1; len += IDENTIFIER_LENGTH (key_name) + 1;
...@@ -6582,18 +6608,21 @@ build_keyword_selector (tree selector) ...@@ -6582,18 +6608,21 @@ build_keyword_selector (tree selector)
for (key_chain = selector; key_chain; key_chain = TREE_CHAIN (key_chain)) for (key_chain = selector; key_chain; key_chain = TREE_CHAIN (key_chain))
{ {
if (TREE_CODE (selector) == KEYWORD_DECL) switch (TREE_CODE (selector))
key_name = KEYWORD_KEY_NAME (key_chain);
else if (TREE_CODE (selector) == TREE_LIST)
{ {
case KEYWORD_DECL:
key_name = KEYWORD_KEY_NAME (key_chain);
break;
case TREE_LIST:
key_name = TREE_PURPOSE (key_chain); key_name = TREE_PURPOSE (key_chain);
/* The keyword decl chain will later be used as a function argument /* The keyword decl chain will later be used as a function
chain. Unhook the selector itself so as to not confuse other argument chain. Unhook the selector itself so as to not
parts of the compiler. */ confuse other parts of the compiler. */
TREE_PURPOSE (key_chain) = NULL_TREE; TREE_PURPOSE (key_chain) = NULL_TREE;
break;
default:
gcc_unreachable ();
} }
else
abort ();
if (key_name) if (key_name)
strcat (buf, IDENTIFIER_POINTER (key_name)); strcat (buf, IDENTIFIER_POINTER (key_name));
...@@ -6885,13 +6914,18 @@ objc_build_message_expr (tree mess) ...@@ -6885,13 +6914,18 @@ objc_build_message_expr (tree mess)
return error_mark_node; return error_mark_node;
/* Obtain the full selector name. */ /* Obtain the full selector name. */
if (TREE_CODE (args) == IDENTIFIER_NODE) switch (TREE_CODE (args))
/* A unary selector. */ {
sel_name = args; case IDENTIFIER_NODE:
else if (TREE_CODE (args) == TREE_LIST) /* A unary selector. */
sel_name = build_keyword_selector (args); sel_name = args;
else break;
abort (); case TREE_LIST:
sel_name = build_keyword_selector (args);
break;
default:
gcc_unreachable ();
}
/* Build the parameter list to give to the method. */ /* Build the parameter list to give to the method. */
if (TREE_CODE (args) == TREE_LIST) if (TREE_CODE (args) == TREE_LIST)
...@@ -7382,13 +7416,18 @@ objc_build_selector_expr (location_t loc, tree selnamelist) ...@@ -7382,13 +7416,18 @@ objc_build_selector_expr (location_t loc, tree selnamelist)
tree selname; tree selname;
/* Obtain the full selector name. */ /* Obtain the full selector name. */
if (TREE_CODE (selnamelist) == IDENTIFIER_NODE) switch (TREE_CODE (selnamelist))
/* A unary selector. */ {
selname = selnamelist; case IDENTIFIER_NODE:
else if (TREE_CODE (selnamelist) == TREE_LIST) /* A unary selector. */
selname = build_keyword_selector (selnamelist); selname = selnamelist;
else break;
abort (); case TREE_LIST:
selname = build_keyword_selector (selnamelist);
break;
default:
gcc_unreachable ();
}
/* If we are required to check @selector() expressions as they /* If we are required to check @selector() expressions as they
are found, check that the selector has been declared. */ are found, check that the selector has been declared. */
...@@ -8069,14 +8108,19 @@ check_methods (tree chain, tree list, int mtype) ...@@ -8069,14 +8108,19 @@ check_methods (tree chain, tree list, int mtype)
{ {
if (first) if (first)
{ {
if (TREE_CODE (objc_implementation_context) switch (TREE_CODE (objc_implementation_context))
== CLASS_IMPLEMENTATION_TYPE) {
warning (0, "incomplete implementation of class %qE", case CLASS_IMPLEMENTATION_TYPE:
CLASS_NAME (objc_implementation_context)); warning (0, "incomplete implementation of class %qE",
else if (TREE_CODE (objc_implementation_context) CLASS_NAME (objc_implementation_context));
== CATEGORY_IMPLEMENTATION_TYPE) break;
warning (0, "incomplete implementation of category %qE", case CATEGORY_IMPLEMENTATION_TYPE:
CLASS_SUPER_NAME (objc_implementation_context)); warning (0, "incomplete implementation of category %qE",
CLASS_SUPER_NAME (objc_implementation_context));
break;
default:
gcc_unreachable ();
}
first = 0; first = 0;
} }
...@@ -8138,33 +8182,42 @@ check_methods_accessible (tree chain, tree context, int mtype) ...@@ -8138,33 +8182,42 @@ check_methods_accessible (tree chain, tree context, int mtype)
if (lookup_method (list, chain)) if (lookup_method (list, chain))
break; break;
else if (TREE_CODE (context) == CLASS_IMPLEMENTATION_TYPE switch (TREE_CODE (context))
|| TREE_CODE (context) == CLASS_INTERFACE_TYPE) {
context = (CLASS_SUPER_NAME (context) case CLASS_IMPLEMENTATION_TYPE:
? lookup_interface (CLASS_SUPER_NAME (context)) case CLASS_INTERFACE_TYPE:
: NULL_TREE); context = (CLASS_SUPER_NAME (context)
? lookup_interface (CLASS_SUPER_NAME (context))
else if (TREE_CODE (context) == CATEGORY_IMPLEMENTATION_TYPE : NULL_TREE);
|| TREE_CODE (context) == CATEGORY_INTERFACE_TYPE) break;
context = (CLASS_NAME (context) case CATEGORY_IMPLEMENTATION_TYPE:
? lookup_interface (CLASS_NAME (context)) case CATEGORY_INTERFACE_TYPE:
: NULL_TREE); context = (CLASS_NAME (context)
else ? lookup_interface (CLASS_NAME (context))
abort (); : NULL_TREE);
break;
default:
gcc_unreachable ();
}
} }
if (context == NULL_TREE) if (context == NULL_TREE)
{ {
if (first) if (first)
{ {
if (TREE_CODE (objc_implementation_context) switch (TREE_CODE (objc_implementation_context))
== CLASS_IMPLEMENTATION_TYPE) {
warning (0, "incomplete implementation of class %qE", case CLASS_IMPLEMENTATION_TYPE:
CLASS_NAME (objc_implementation_context)); warning (0, "incomplete implementation of class %qE",
else if (TREE_CODE (objc_implementation_context) CLASS_NAME (objc_implementation_context));
== CATEGORY_IMPLEMENTATION_TYPE) break;
warning (0, "incomplete implementation of category %qE", case CATEGORY_IMPLEMENTATION_TYPE:
CLASS_SUPER_NAME (objc_implementation_context)); warning (0, "incomplete implementation of category %qE",
CLASS_SUPER_NAME (objc_implementation_context));
break;
default:
gcc_unreachable ();
}
first = 0; first = 0;
} }
warning (0, "method definition for %<%c%E%> not found", warning (0, "method definition for %<%c%E%> not found",
...@@ -8307,19 +8360,20 @@ start_class (enum tree_code code, tree class_name, tree super_name, ...@@ -8307,19 +8360,20 @@ start_class (enum tree_code code, tree class_name, tree super_name,
decl); decl);
} }
if (code == CLASS_IMPLEMENTATION_TYPE) switch (code)
{ {
case CLASS_IMPLEMENTATION_TYPE:
{ {
tree chain; tree chain;
for (chain = implemented_classes; chain; chain = TREE_CHAIN (chain)) for (chain = implemented_classes; chain; chain = TREE_CHAIN (chain))
if (TREE_VALUE (chain) == class_name) if (TREE_VALUE (chain) == class_name)
{ {
error ("reimplementation of class %qE", error ("reimplementation of class %qE",
class_name); class_name);
return error_mark_node; return error_mark_node;
} }
implemented_classes = tree_cons (NULL_TREE, class_name, implemented_classes = tree_cons (NULL_TREE, class_name,
implemented_classes); implemented_classes);
} }
...@@ -8343,7 +8397,7 @@ start_class (enum tree_code code, tree class_name, tree super_name, ...@@ -8343,7 +8397,7 @@ start_class (enum tree_code code, tree class_name, tree super_name,
if (super_name if (super_name
&& (super_name != CLASS_SUPER_NAME (implementation_template))) && (super_name != CLASS_SUPER_NAME (implementation_template)))
{ {
tree previous_name = CLASS_SUPER_NAME (implementation_template); tree previous_name = CLASS_SUPER_NAME (implementation_template);
error ("conflicting super class name %qE", error ("conflicting super class name %qE",
super_name); super_name);
...@@ -8351,56 +8405,53 @@ start_class (enum tree_code code, tree class_name, tree super_name, ...@@ -8351,56 +8405,53 @@ start_class (enum tree_code code, tree class_name, tree super_name,
error ("previous declaration of %qE", previous_name); error ("previous declaration of %qE", previous_name);
else else
error ("previous declaration"); error ("previous declaration");
} }
else if (! super_name) else if (! super_name)
{ {
CLASS_SUPER_NAME (objc_implementation_context) CLASS_SUPER_NAME (objc_implementation_context)
= CLASS_SUPER_NAME (implementation_template); = CLASS_SUPER_NAME (implementation_template);
} }
} break;
else if (code == CLASS_INTERFACE_TYPE) case CLASS_INTERFACE_TYPE:
{
if (lookup_interface (class_name)) if (lookup_interface (class_name))
#ifdef OBJCPLUS #ifdef OBJCPLUS
error ("duplicate interface declaration for class %qE", error ("duplicate interface declaration for class %qE", class_name);
#else #else
warning (0, "duplicate interface declaration for class %qE", warning (0, "duplicate interface declaration for class %qE", class_name);
#endif #endif
class_name);
else else
add_class (klass, class_name); add_class (klass, class_name);
if (protocol_list) if (protocol_list)
CLASS_PROTOCOL_LIST (klass) CLASS_PROTOCOL_LIST (klass)
= lookup_and_install_protocols (protocol_list); = lookup_and_install_protocols (protocol_list);
} break;
else if (code == CATEGORY_INTERFACE_TYPE) case CATEGORY_INTERFACE_TYPE:
{ {
tree class_category_is_assoc_with; tree class_category_is_assoc_with;
/* For a category, class_name is really the name of the class that /* For a category, class_name is really the name of the class that
the following set of methods will be associated with. We must the following set of methods will be associated with. We must
find the interface so that can derive the objects template. */ find the interface so that can derive the objects template. */
if (!(class_category_is_assoc_with = lookup_interface (class_name)))
if (!(class_category_is_assoc_with = lookup_interface (class_name))) {
{ error ("cannot find interface declaration for %qE",
error ("cannot find interface declaration for %qE", class_name);
class_name); exit (FATAL_EXIT_CODE);
exit (FATAL_EXIT_CODE); }
} else
else add_category (class_category_is_assoc_with, klass);
add_category (class_category_is_assoc_with, klass);
if (protocol_list)
if (protocol_list) CLASS_PROTOCOL_LIST (klass)
CLASS_PROTOCOL_LIST (klass) = lookup_and_install_protocols (protocol_list);
= lookup_and_install_protocols (protocol_list); }
} break;
else if (code == CATEGORY_IMPLEMENTATION_TYPE) case CATEGORY_IMPLEMENTATION_TYPE:
{
/* Reset for multiple classes per file. */ /* Reset for multiple classes per file. */
method_slot = 0; method_slot = 0;
...@@ -8416,6 +8467,9 @@ start_class (enum tree_code code, tree class_name, tree super_name, ...@@ -8416,6 +8467,9 @@ start_class (enum tree_code code, tree class_name, tree super_name,
class_name); class_name);
exit (FATAL_EXIT_CODE); exit (FATAL_EXIT_CODE);
} }
break;
default:
gcc_unreachable ();
} }
return klass; return klass;
} }
...@@ -8423,70 +8477,67 @@ start_class (enum tree_code code, tree class_name, tree super_name, ...@@ -8423,70 +8477,67 @@ start_class (enum tree_code code, tree class_name, tree super_name,
static tree static tree
continue_class (tree klass) continue_class (tree klass)
{ {
if (TREE_CODE (klass) == CLASS_IMPLEMENTATION_TYPE switch (TREE_CODE (klass))
|| TREE_CODE (klass) == CATEGORY_IMPLEMENTATION_TYPE)
{ {
struct imp_entry *imp_entry; case CLASS_IMPLEMENTATION_TYPE:
case CATEGORY_IMPLEMENTATION_TYPE:
/* Check consistency of the instance variables. */ {
struct imp_entry *imp_entry;
if (CLASS_RAW_IVARS (klass))
check_ivars (implementation_template, klass);
/* code generation */ /* Check consistency of the instance variables. */
if (CLASS_RAW_IVARS (klass))
check_ivars (implementation_template, klass);
/* code generation */
#ifdef OBJCPLUS #ifdef OBJCPLUS
push_lang_context (lang_name_c); push_lang_context (lang_name_c);
#endif #endif
build_private_template (implementation_template);
uprivate_record = CLASS_STATIC_TEMPLATE (implementation_template);
objc_instance_type = build_pointer_type (uprivate_record);
build_private_template (implementation_template); imp_entry = ggc_alloc_imp_entry ();
uprivate_record = CLASS_STATIC_TEMPLATE (implementation_template);
objc_instance_type = build_pointer_type (uprivate_record);
imp_entry = ggc_alloc_imp_entry (); imp_entry->next = imp_list;
imp_entry->imp_context = klass;
imp_entry->imp_template = implementation_template;
imp_entry->next = imp_list; synth_forward_declarations ();
imp_entry->imp_context = klass; imp_entry->class_decl = UOBJC_CLASS_decl;
imp_entry->imp_template = implementation_template; imp_entry->meta_decl = UOBJC_METACLASS_decl;
imp_entry->has_cxx_cdtors = 0;
synth_forward_declarations ();
imp_entry->class_decl = UOBJC_CLASS_decl;
imp_entry->meta_decl = UOBJC_METACLASS_decl;
imp_entry->has_cxx_cdtors = 0;
/* Append to front and increment count. */
imp_list = imp_entry;
if (TREE_CODE (klass) == CLASS_IMPLEMENTATION_TYPE)
imp_count++;
else
cat_count++;
/* Append to front and increment count. */
imp_list = imp_entry;
if (TREE_CODE (klass) == CLASS_IMPLEMENTATION_TYPE)
imp_count++;
else
cat_count++;
#ifdef OBJCPLUS #ifdef OBJCPLUS
pop_lang_context (); pop_lang_context ();
#endif /* OBJCPLUS */ #endif /* OBJCPLUS */
return get_class_ivars (implementation_template, true); return get_class_ivars (implementation_template, true);
} break;
}
else if (TREE_CODE (klass) == CLASS_INTERFACE_TYPE) case CLASS_INTERFACE_TYPE:
{ {
#ifdef OBJCPLUS #ifdef OBJCPLUS
push_lang_context (lang_name_c); push_lang_context (lang_name_c);
#endif /* OBJCPLUS */ #endif /* OBJCPLUS */
objc_collecting_ivars = 1;
objc_collecting_ivars = 1; build_private_template (klass);
build_private_template (klass); objc_collecting_ivars = 0;
objc_collecting_ivars = 0;
#ifdef OBJCPLUS #ifdef OBJCPLUS
pop_lang_context (); pop_lang_context ();
#endif /* OBJCPLUS */ #endif /* OBJCPLUS */
return NULL_TREE;
return NULL_TREE; break;
}
default:
return error_mark_node;
} }
else
return error_mark_node;
} }
/* This routine builds a property ivar name. */ /* This routine builds a property ivar name. */
...@@ -8844,102 +8895,106 @@ objc_gen_property_data (tree klass, tree class_methods) ...@@ -8844,102 +8895,106 @@ objc_gen_property_data (tree klass, tree class_methods)
static void static void
finish_class (tree klass) finish_class (tree klass)
{ {
if (TREE_CODE (klass) == CLASS_IMPLEMENTATION_TYPE) switch (TREE_CODE (klass))
{
/* All code generation is done in finish_objc. */
/* Generate what needed for property; setters, getters, etc. */
objc_gen_property_data (implementation_template, implementation_template);
if (implementation_template != objc_implementation_context)
{
/* Ensure that all method listed in the interface contain bodies. */
check_methods (CLASS_CLS_METHODS (implementation_template),
CLASS_CLS_METHODS (objc_implementation_context), '+');
check_methods (CLASS_NST_METHODS (implementation_template),
CLASS_NST_METHODS (objc_implementation_context), '-');
if (CLASS_PROTOCOL_LIST (implementation_template))
check_protocols (CLASS_PROTOCOL_LIST (implementation_template),
"class",
CLASS_NAME (objc_implementation_context));
}
}
else if (TREE_CODE (klass) == CATEGORY_IMPLEMENTATION_TYPE)
{ {
tree category = lookup_category (implementation_template, CLASS_SUPER_NAME (klass)); case CLASS_IMPLEMENTATION_TYPE:
{
if (category) /* All code generation is done in finish_objc. */
{
/* Generate what needed for property; setters, getters, etc. */ /* Generate what needed for property; setters, getters, etc. */
objc_gen_property_data (implementation_template, category); objc_gen_property_data (implementation_template, implementation_template);
/* Ensure all method listed in the interface contain bodies. */
check_methods (CLASS_CLS_METHODS (category),
CLASS_CLS_METHODS (objc_implementation_context), '+');
check_methods (CLASS_NST_METHODS (category),
CLASS_NST_METHODS (objc_implementation_context), '-');
if (CLASS_PROTOCOL_LIST (category))
check_protocols (CLASS_PROTOCOL_LIST (category),
"category",
CLASS_SUPER_NAME (objc_implementation_context));
}
}
else
{
/* Process properties of the class. */
tree x;
for (x = CLASS_PROPERTY_DECL (objc_interface_context); x; x = TREE_CHAIN (x))
{
tree type = TREE_TYPE (x);
tree prop_name = PROPERTY_NAME (x);
/* Build an instance method declaration: - (type) prop_name; */
if (PROPERTY_GETTER_NAME (x) == NULL_TREE)
{
/* No getter attribute specified. Generate an instance method for the
getter. */
tree rettype = build_tree_list (NULL_TREE, type);
tree getter_decl = build_method_decl (INSTANCE_METHOD_DECL,
rettype, prop_name,
NULL_TREE, false);
objc_add_method (objc_interface_context, getter_decl, false, false);
METHOD_PROPERTY_CONTEXT (getter_decl) = x;
}
else
warning (0, "getter = %qs may not be specified in an interface",
IDENTIFIER_POINTER (PROPERTY_GETTER_NAME (x)));
/* Build an instance method declaration: - (void) setName: (type)value; */ if (implementation_template != objc_implementation_context)
if (PROPERTY_SETTER_NAME (x) == NULL_TREE {
&& PROPERTY_READONLY (x) == boolean_false_node) /* Ensure that all method listed in the interface contain bodies. */
{ check_methods (CLASS_CLS_METHODS (implementation_template),
/* Declare a setter instance method in the interface. */ CLASS_CLS_METHODS (objc_implementation_context), '+');
tree key_name, arg_type, arg_name; check_methods (CLASS_NST_METHODS (implementation_template),
tree setter_decl, selector; CLASS_NST_METHODS (objc_implementation_context), '-');
tree ret_type = build_tree_list (NULL_TREE, void_type_node);
/* setter name. */ if (CLASS_PROTOCOL_LIST (implementation_template))
key_name = get_identifier (objc_build_property_setter_name ( check_protocols (CLASS_PROTOCOL_LIST (implementation_template),
PROPERTY_NAME (x), false)); "class",
arg_type = build_tree_list (NULL_TREE, type); CLASS_NAME (objc_implementation_context));
arg_name = get_identifier ("_value"); }
/* For now, no attributes. */ break;
selector = objc_build_keyword_decl (key_name, arg_type, arg_name, NULL); }
setter_decl = build_method_decl (INSTANCE_METHOD_DECL, case CATEGORY_IMPLEMENTATION_TYPE:
ret_type, selector, {
build_tree_list (NULL_TREE, NULL_TREE), tree category = lookup_category (implementation_template, CLASS_SUPER_NAME (klass));
false);
objc_add_method (objc_interface_context, setter_decl, false, false); if (category)
METHOD_PROPERTY_CONTEXT (setter_decl) = x; {
} /* Generate what needed for property; setters, getters, etc. */
else if (PROPERTY_SETTER_NAME (x)) objc_gen_property_data (implementation_template, category);
warning (0, "setter = %qs may not be specified in an interface",
IDENTIFIER_POINTER (PROPERTY_SETTER_NAME (x))); /* Ensure all method listed in the interface contain bodies. */
if (PROPERTY_IVAR_NAME (x)) check_methods (CLASS_CLS_METHODS (category),
warning (0, "ivar = %qs attribute may not be specified in an interface", CLASS_CLS_METHODS (objc_implementation_context), '+');
IDENTIFIER_POINTER (PROPERTY_IVAR_NAME (x))); check_methods (CLASS_NST_METHODS (category),
} CLASS_NST_METHODS (objc_implementation_context), '-');
if (CLASS_PROTOCOL_LIST (category))
check_protocols (CLASS_PROTOCOL_LIST (category),
"category",
CLASS_SUPER_NAME (objc_implementation_context));
}
break;
}
default:
{
/* Process properties of the class. */
tree x;
for (x = CLASS_PROPERTY_DECL (objc_interface_context); x; x = TREE_CHAIN (x))
{
tree type = TREE_TYPE (x);
tree prop_name = PROPERTY_NAME (x);
/* Build an instance method declaration: - (type) prop_name; */
if (PROPERTY_GETTER_NAME (x) == NULL_TREE)
{
/* No getter attribute specified. Generate an instance method for the
getter. */
tree rettype = build_tree_list (NULL_TREE, type);
tree getter_decl = build_method_decl (INSTANCE_METHOD_DECL,
rettype, prop_name,
NULL_TREE, false);
objc_add_method (objc_interface_context, getter_decl, false, false);
METHOD_PROPERTY_CONTEXT (getter_decl) = x;
}
else
warning (0, "getter = %qs may not be specified in an interface",
IDENTIFIER_POINTER (PROPERTY_GETTER_NAME (x)));
/* Build an instance method declaration: - (void) setName: (type)value; */
if (PROPERTY_SETTER_NAME (x) == NULL_TREE
&& PROPERTY_READONLY (x) == boolean_false_node)
{
/* Declare a setter instance method in the interface. */
tree key_name, arg_type, arg_name;
tree setter_decl, selector;
tree ret_type = build_tree_list (NULL_TREE, void_type_node);
/* setter name. */
key_name = get_identifier (objc_build_property_setter_name
(PROPERTY_NAME (x), false));
arg_type = build_tree_list (NULL_TREE, type);
arg_name = get_identifier ("_value");
/* For now, no attributes. */
selector = objc_build_keyword_decl (key_name, arg_type, arg_name, NULL);
setter_decl = build_method_decl (INSTANCE_METHOD_DECL,
ret_type, selector,
build_tree_list (NULL_TREE, NULL_TREE),
false);
objc_add_method (objc_interface_context, setter_decl, false, false);
METHOD_PROPERTY_CONTEXT (setter_decl) = x;
}
else if (PROPERTY_SETTER_NAME (x))
warning (0, "setter = %qs may not be specified in an interface",
IDENTIFIER_POINTER (PROPERTY_SETTER_NAME (x)));
if (PROPERTY_IVAR_NAME (x))
warning (0, "ivar = %qs attribute may not be specified in an interface",
IDENTIFIER_POINTER (PROPERTY_IVAR_NAME (x)));
}
}
} }
} }
...@@ -9089,6 +9144,8 @@ encode_type_qualifiers (tree declspecs) ...@@ -9089,6 +9144,8 @@ encode_type_qualifiers (tree declspecs)
obstack_1grow (&util_obstack, 'R'); obstack_1grow (&util_obstack, 'R');
else if (ridpointers[(int) RID_ONEWAY] == TREE_VALUE (spec)) else if (ridpointers[(int) RID_ONEWAY] == TREE_VALUE (spec))
obstack_1grow (&util_obstack, 'V'); obstack_1grow (&util_obstack, 'V');
else
gcc_unreachable ();
} }
} }
...@@ -9492,38 +9549,31 @@ encode_type (tree type, int curtype, int format) ...@@ -9492,38 +9549,31 @@ encode_type (tree type, int curtype, int format)
case 8: c = TYPE_UNSIGNED (type) ? 'C' : 'c'; break; case 8: c = TYPE_UNSIGNED (type) ? 'C' : 'c'; break;
case 16: c = TYPE_UNSIGNED (type) ? 'S' : 's'; break; case 16: c = TYPE_UNSIGNED (type) ? 'S' : 's'; break;
case 32: case 32:
if (flag_next_runtime) {
{ tree int_type = type;
tree int_type; if (flag_next_runtime)
/* Another legacy kludge for compatiblity with {
gcc-3.3: 32-bit longs are encoded as 'l' or 'L', /* Another legacy kludge for compatiblity with
but not always. For typedefs, we need to use 'i' gcc-3.3: 32-bit longs are encoded as 'l' or 'L',
or 'I' instead if encoding a struct field, or a but not always. For typedefs, we need to use 'i'
pointer! */ or 'I' instead if encoding a struct field, or a
int_type = ((!generating_instance_variables pointer! */
&& (obstack_object_size (&util_obstack) int_type = ((!generating_instance_variables
== (unsigned) curtype)) && (obstack_object_size (&util_obstack)
? TYPE_MAIN_VARIANT (type) == (unsigned) curtype))
: type); ? TYPE_MAIN_VARIANT (type)
: type);
if (int_type == long_unsigned_type_node }
|| int_type == long_integer_type_node) if (int_type == long_unsigned_type_node
c = TYPE_UNSIGNED (type) ? 'L' : 'l'; || int_type == long_integer_type_node)
else c = TYPE_UNSIGNED (type) ? 'L' : 'l';
c = TYPE_UNSIGNED (type) ? 'I' : 'i'; else
} c = TYPE_UNSIGNED (type) ? 'I' : 'i';
else }
{
if (type == long_unsigned_type_node
|| type == long_integer_type_node)
c = TYPE_UNSIGNED (type) ? 'L' : 'l';
else
c = TYPE_UNSIGNED (type) ? 'I' : 'i';
}
break; break;
case 64: c = TYPE_UNSIGNED (type) ? 'Q' : 'q'; break; case 64: c = TYPE_UNSIGNED (type) ? 'Q' : 'q'; break;
case 128: c = TYPE_UNSIGNED (type) ? 'T' : 't'; break; case 128: c = TYPE_UNSIGNED (type) ? 'T' : 't'; break;
default: abort (); default: gcc_unreachable ();
} }
obstack_1grow (&util_obstack, c); obstack_1grow (&util_obstack, c);
break; break;
...@@ -9538,7 +9588,7 @@ encode_type (tree type, int curtype, int format) ...@@ -9538,7 +9588,7 @@ encode_type (tree type, int curtype, int format)
case 64: c = 'd'; break; case 64: c = 'd'; break;
case 96: case 96:
case 128: c = 'D'; break; case 128: c = 'D'; break;
default: abort (); default: gcc_unreachable ();
} }
obstack_1grow (&util_obstack, c); obstack_1grow (&util_obstack, c);
break; break;
...@@ -9622,37 +9672,48 @@ encode_gnu_bitfield (int position, tree type, int size) ...@@ -9622,37 +9672,48 @@ encode_gnu_bitfield (int position, tree type, int size)
if (integer_zerop (TYPE_MIN_VALUE (type))) if (integer_zerop (TYPE_MIN_VALUE (type)))
/* Unsigned integer types. */ /* Unsigned integer types. */
{ {
if (TYPE_MODE (type) == QImode) switch (TYPE_MODE (type))
charType = 'C';
else if (TYPE_MODE (type) == HImode)
charType = 'S';
else if (TYPE_MODE (type) == SImode)
{ {
if (type == long_unsigned_type_node) case QImode:
charType = 'L'; charType = 'C'; break;
else case HImode:
charType = 'I'; charType = 'S'; break;
case SImode:
{
if (type == long_unsigned_type_node)
charType = 'L';
else
charType = 'I';
break;
}
case DImode:
charType = 'Q'; break;
default:
gcc_unreachable ();
} }
else if (TYPE_MODE (type) == DImode)
charType = 'Q';
} }
else else
/* Signed integer types. */ /* Signed integer types. */
{ {
if (TYPE_MODE (type) == QImode) switch (TYPE_MODE (type))
charType = 'c';
else if (TYPE_MODE (type) == HImode)
charType = 's';
else if (TYPE_MODE (type) == SImode)
{ {
if (type == long_integer_type_node) case QImode:
charType = 'l'; charType = 'c'; break;
else case HImode:
charType = 'i'; charType = 's'; break;
case SImode:
{
if (type == long_integer_type_node)
charType = 'l';
else
charType = 'i';
break;
}
case DImode:
charType = 'q'; break;
default:
gcc_unreachable ();
} }
else if (TYPE_MODE (type) == DImode)
charType = 'q';
} }
} }
else else
...@@ -10501,14 +10562,15 @@ dump_interface (FILE *fp, tree chain) ...@@ -10501,14 +10562,15 @@ dump_interface (FILE *fp, tree chain)
{ {
const char *name = IDENTIFIER_POINTER (CLASS_SUPER_NAME (chain)); const char *name = IDENTIFIER_POINTER (CLASS_SUPER_NAME (chain));
if (TREE_CODE (chain) == CATEGORY_IMPLEMENTATION_TYPE switch (TREE_CODE (chain))
|| TREE_CODE (chain) == CATEGORY_INTERFACE_TYPE)
{ {
case CATEGORY_IMPLEMENTATION_TYPE:
case CATEGORY_INTERFACE_TYPE:
fprintf (fp, " (%s)\n", name); fprintf (fp, " (%s)\n", name);
} break;
else default:
{
fprintf (fp, " : %s\n", name); fprintf (fp, " : %s\n", name);
break;
} }
} }
else else
...@@ -10815,34 +10877,40 @@ handle_impent (struct imp_entry *impent) ...@@ -10815,34 +10877,40 @@ handle_impent (struct imp_entry *impent)
objc_implementation_context = impent->imp_context; objc_implementation_context = impent->imp_context;
implementation_template = impent->imp_template; implementation_template = impent->imp_template;
if (TREE_CODE (impent->imp_context) == CLASS_IMPLEMENTATION_TYPE) switch (TREE_CODE (impent->imp_context))
{ {
const char *const class_name = case CLASS_IMPLEMENTATION_TYPE:
IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context)); {
const char *const class_name =
string = (char *) alloca (strlen (class_name) + 30); IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context));
sprintf (string, "%sobjc_class_name_%s", string = (char *) alloca (strlen (class_name) + 30);
(flag_next_runtime ? "." : "__"), class_name);
} sprintf (string, "%sobjc_class_name_%s",
else if (TREE_CODE (impent->imp_context) == CATEGORY_IMPLEMENTATION_TYPE) (flag_next_runtime ? "." : "__"), class_name);
{ break;
const char *const class_name = }
IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context)); case CATEGORY_IMPLEMENTATION_TYPE:
const char *const class_super_name = {
IDENTIFIER_POINTER (CLASS_SUPER_NAME (impent->imp_context)); const char *const class_name =
IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context));
string = (char *) alloca (strlen (class_name) const char *const class_super_name =
+ strlen (class_super_name) + 30); IDENTIFIER_POINTER (CLASS_SUPER_NAME (impent->imp_context));
/* Do the same for categories. Even though no references to string = (char *) alloca (strlen (class_name)
these symbols are generated automatically by the compiler, it + strlen (class_super_name) + 30);
gives you a handle to pull them into an archive by hand. */
sprintf (string, "*%sobjc_category_name_%s_%s", /* Do the same for categories. Even though no references to
(flag_next_runtime ? "." : "__"), class_name, class_super_name); these symbols are generated automatically by the compiler,
it gives you a handle to pull them into an archive by
hand. */
sprintf (string, "*%sobjc_category_name_%s_%s",
(flag_next_runtime ? "." : "__"), class_name, class_super_name);
break;
}
default:
return;
} }
else
return;
#ifdef ASM_DECLARE_CLASS_REFERENCE #ifdef ASM_DECLARE_CLASS_REFERENCE
if (flag_next_runtime) if (flag_next_runtime)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment