#define TREE_STATIC_TEMPLATE(record_type) (TREE_PUBLIC (record_type))
#define TYPED_OBJECT(type) \
(TREE_CODE (type) == RECORD_TYPE && TREE_STATIC_TEMPLATE (type))
+
/* Some commonly used instances of "identifier_node". */
static tree self_id, ucmd_id;
static tree super_type, selector_type, id_type, objc_class_type;
static tree instance_type, protocol_type;
+/* Type checking macros. */
+
+#define IS_ID(TYPE) \
+ (TYPE_MAIN_VARIANT (TYPE) == TYPE_MAIN_VARIANT (id_type))
+#define IS_PROTOCOL_QUALIFIED_ID(TYPE) \
+ (IS_ID (TYPE) && TYPE_PROTOCOL_LIST (TYPE))
+#define IS_SUPER(TYPE) \
+ (super_type && TYPE_MAIN_VARIANT (TYPE) == TYPE_MAIN_VARIANT (super_type))
+
static tree class_chain = NULLT;
static tree alias_chain = NULLT;
static tree interface_chain = NULLT;
&& TREE_CODE (rhs) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (rhs)) == RECORD_TYPE)
{
- int lhs_is_proto = (TYPE_MAIN_VARIANT (lhs) == TYPE_MAIN_VARIANT (id_type)
- && TYPE_PROTOCOL_LIST (lhs));
- int rhs_is_proto = (TYPE_MAIN_VARIANT (rhs) == TYPE_MAIN_VARIANT (id_type)
- && TYPE_PROTOCOL_LIST (rhs));
+ int lhs_is_proto = IS_PROTOCOL_QUALIFIED_ID (lhs);
+ int rhs_is_proto = IS_PROTOCOL_QUALIFIED_ID (rhs);
if (lhs_is_proto)
{
{
tree s = build_string (len, str);
- TREE_CODE (s) = OBJC_STRING_CST;
+ TREE_SET_CODE (s, OBJC_STRING_CST);
return s;
}
/* combine_strings will work for OBJC_STRING_CST's too. */
string = combine_strings (strings);
- TREE_CODE (string) = STRING_CST;
+ TREE_SET_CODE (string, STRING_CST);
length = TREE_STRING_LENGTH (string) - 1;
/* & ((NXConstantString) {0, string, length}) */
{
tree params;
- add_class_reference (CLASS_NAME (ident));
+ add_class_reference (ident);
params = build_tree_list (NULLT,
my_build_string (IDENTIFIER_LENGTH (ident) + 1,
tree parms;
/* Hack to avoid problem with static typing of self arg. */
- TREE_CODE (nst_methods) = CLASS_METHOD_DECL;
+ TREE_SET_CODE (nst_methods, CLASS_METHOD_DECL);
start_method_def (nst_methods);
- TREE_CODE (nst_methods) = INSTANCE_METHOD_DECL;
+ TREE_SET_CODE (nst_methods, INSTANCE_METHOD_DECL);
if (METHOD_ADD_ARGS (nst_methods) == (tree) 1)
parms = get_parm_info (0); /* we have a `, ...' */
/* receiver type */
if (flag_next_runtime && superflag)
- {
- arglist = build_tree_list (NULLT, super_type);
- }
+ arglist = build_tree_list (NULLT, super_type);
+ else if (context == METHOD_DEF)
+ arglist = build_tree_list (NULLT, TREE_TYPE (self_decl));
else
- {
- if (context == METHOD_DEF)
- arglist = build_tree_list (NULLT, TREE_TYPE (self_decl));
- else
- arglist = build_tree_list (NULLT, id_type);
- }
+ arglist = build_tree_list (NULLT, id_type);
/* selector type - will eventually change to `int' */
chainon (arglist, build_tree_list (NULLT, selector_type));
return meth;
}
+/* If RECEIVER is a class reference, return the identifier node for the
+ referenced class. RECEIVER is created by get_class_reference, so we
+ check the exact form created depending on which runtimes are used. */
+
static tree
receiver_is_class_object (receiver)
tree receiver;
{
+ tree chain, exp, arg;
if (flag_next_runtime)
{
- tree chain;
+ /* The receiver is a variable created by build_class_reference_decl. */
if (TREE_CODE (receiver) == VAR_DECL
&& TREE_TYPE (receiver) == objc_class_type)
- /* Look up the identifier corresponding to this string decl. */
- for (chain = class_names_chain; chain; chain = TREE_CHAIN (chain))
+ /* Look up the identifier. */
+ for (chain = cls_ref_chain; chain; chain = TREE_CHAIN (chain))
if (TREE_PURPOSE (chain) == receiver)
return TREE_VALUE (chain);
}
else
{
- /* The receiver is a function call that returns an id...
- ...check if it is a call to objc_getClass, if so, give it
- special treatment. */
- tree exp, arg;
-
+ /* The receiver is a function call that returns an id. Check if
+ it is a call to objc_getClass, if so, pick up the class name. */
if ((exp = TREE_OPERAND (receiver, 0))
&& TREE_CODE (exp) == ADDR_EXPR
&& (exp = TREE_OPERAND (exp, 0))
/* we have a call to objc_getClass! */
&& (arg = TREE_OPERAND (receiver, 1))
&& TREE_CODE (arg) == TREE_LIST
- && (arg = TREE_VALUE (arg))
- && TREE_CODE (arg) == NOP_EXPR
- && (arg = TREE_OPERAND (arg, 0))
- && TREE_CODE (arg) == ADDR_EXPR
- && (arg = TREE_OPERAND (arg, 0))
- && TREE_CODE (arg) == STRING_CST)
- /* finally, we have the class name */
- return get_identifier (TREE_STRING_POINTER (arg));
+ && (arg = TREE_VALUE (arg)))
+ {
+ STRIP_NOPS (arg);
+ if (TREE_CODE (arg) == ADDR_EXPR
+ && (arg = TREE_OPERAND (arg, 0))
+ && TREE_CODE (arg) == STRING_CST)
+ /* finally, we have the class name */
+ return get_identifier (TREE_STRING_POINTER (arg));
+ }
}
return 0;
}
/* determine receiver type */
rtype = TREE_TYPE (receiver);
- super = (TREE_TYPE (receiver) == super_type);
+ super = IS_SUPER (rtype);
if (! super)
{
else if (TREE_CODE (rtype) == POINTER_TYPE
&& TREE_STATIC_TEMPLATE (TREE_TYPE (rtype)))
statically_typed = 1;
- /* classfix -smn */
else if ((flag_next_runtime
- || (TREE_CODE (receiver) == CALL_EXPR
- && TYPE_MAIN_VARIANT (rtype) == TYPE_MAIN_VARIANT (id_type)))
+ || (TREE_CODE (receiver) == CALL_EXPR && IS_ID (rtype)))
&& (class_ident = receiver_is_class_object (receiver)))
;
- else if (TYPE_MAIN_VARIANT (rtype) != TYPE_MAIN_VARIANT (id_type)
- && TYPE_MAIN_VARIANT (rtype) != TYPE_MAIN_VARIANT (objc_class_type))
+ else if (! IS_ID (rtype)
+ /* Allow any type that matches objc_class_type. */
+ && ! comptypes (rtype, objc_class_type))
{
bzero (errbuf, BUFSIZE);
warning ("invalid receiver type `%s'",
/* Determine operation return type. */
- if (super_type != 0
- && TYPE_MAIN_VARIANT (rtype) == TYPE_MAIN_VARIANT (super_type))
+ if (IS_SUPER (rtype))
{
tree iface;
IDENTIFIER_POINTER (sel_name));
}
}
- else if (TYPE_MAIN_VARIANT (rtype) == TYPE_MAIN_VARIANT (id_type)
- && TYPE_PROTOCOL_LIST (rtype))
+ else if (IS_PROTOCOL_QUALIFIED_ID (rtype))
{
/* An anonymous object that has been qualified with a protocol. */
{
return (TREE_CODE (type) == ARRAY_TYPE
|| TREE_CODE (type) == FUNCTION_TYPE
- || (TREE_CODE (type) == POINTER_TYPE
- && TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (id_type)));
+ || (TREE_CODE (type) == POINTER_TYPE && ! IS_ID (type)));
}
\f
case ARRAY_TYPE:
case FUNCTION_TYPE:
case POINTER_TYPE:
- str = strcpy (buf, name);
+ strcpy (buf, name);
+ str = buf;
/* this clause is done iteratively...rather than recursively */
do
case IDENTIFIER_NODE:
/* will only happen if we are processing a "raw" expr-decl. */
- return strcpy (buf, IDENTIFIER_POINTER (decl));
+ strcpy (buf, IDENTIFIER_POINTER (decl));
+ return buf;
}
return str;
}
else /* we have an abstract declarator or a _DECL node */
- return strcpy (buf, name);
+ {
+ strcpy (buf, name);
+ return buf;
+ }
}
static void
strcat (buf, IDENTIFIER_POINTER (DECL_NAME (aspec)));
}
/* NEW!!! */
- else if (TREE_CODE (aspec) == POINTER_TYPE
- && TYPE_MAIN_VARIANT (aspec) == TYPE_MAIN_VARIANT (id_type))
+ else if (IS_ID (aspec))
{
tree protocol_list = TYPE_PROTOCOL_LIST (aspec);