This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Update ObjC constant string handling
- To: gcc-patches at gcc dot gnu dot org
- Subject: Update ObjC constant string handling
- From: Stan Shebs <shebs at apple dot com>
- Date: Wed, 02 May 2001 15:01:05 -0700
This patch fixes ObjC to do the right thing for @"..." constructs
when -fnext-runtime, which is basically to lay down some globals
that the NeXT^H^H^H^HDarwin runtime knows how to process. This
has no effect if -fgnu-runtime. Tested on powerpc-apple-darwin1.3,
committed to mainline only.
Stan
2001-05-02 Stan Shebs <shebs@apple.com>
* objc/objc-act.c (STRING_OBJECT_CLASS_NAME): Default to
NSConstantString for NeXT-style runtimes.
(STRING_OBJECT_GLOBAL_NAME): New macro.
(enum objc_tree_index): Add values OCTI_CNST_STR_GLOB_ID and
OCTI_STRING_CLASS_DECL.
(constant_string_global_id): New macro.
(string_class_decl): Ditto.
(setup_string_decl): New function.
(build_objc_string_object): Use it to build a NeXT runtime
compatible string initializer.
Index: objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.79
diff -c -3 -p -r1.79 objc-act.c
*** objc-act.c 2001/05/01 20:45:55 1.79
--- objc-act.c 2001/05/02 21:43:53
*************** static tree lookup_method_in_protocol_li
*** 289,294 ****
--- 289,295 ----
static tree lookup_protocol_in_reflist PARAMS ((tree, tree));
static tree create_builtin_decl PARAMS ((enum tree_code,
tree, const char *));
+ static void setup_string_decl PARAMS ((void));
static tree my_build_string PARAMS ((int, const char *));
static void build_objc_symtab_template PARAMS ((void));
static tree init_def_list PARAMS ((tree));
*************** static void ggc_mark_hash_table PARAMS
*** 375,381 ****
--- 376,390 ----
#define UTAG_METHOD_PROTOTYPE "_objc_method_prototype"
#define UTAG_METHOD_PROTOTYPE_LIST "_objc__method_prototype_list"
+ #ifdef NEXT_OBJC_RUNTIME
+ #define STRING_OBJECT_CLASS_NAME "NSConstantString"
+ #else
#define STRING_OBJECT_CLASS_NAME "NXConstantString"
+ #endif
+ /* Note that the string object global name is only needed for the
+ NeXT runtime. */
+ #define STRING_OBJECT_GLOBAL_NAME "_NSConstantStringClassReference"
+
#define PROTOCOL_OBJECT_CLASS_NAME "Protocol"
static const char *constant_string_class_name = NULL;
*************** enum objc_tree_index
*** 455,460 ****
--- 464,471 ----
OCTI_ID_ID,
OCTI_CNST_STR_ID,
OCTI_CNST_STR_TYPE,
+ OCTI_CNST_STR_GLOB_ID,
+ OCTI_STRING_CLASS_DECL,
OCTI_SUPER_DECL,
OCTI_METH_CTX,
*************** static int cat_count = 0; /* `@category'
*** 576,581 ****
--- 587,594 ----
#define objc_id_id objc_global_trees[OCTI_ID_ID]
#define constant_string_id objc_global_trees[OCTI_CNST_STR_ID]
#define constant_string_type objc_global_trees[OCTI_CNST_STR_TYPE]
+ #define constant_string_global_id objc_global_trees[OCTI_CNST_STR_GLOB_ID]
+ #define string_class_decl objc_global_trees[OCTI_STRING_CLASS_DECL]
#define UOBJC_SUPER_decl objc_global_trees[OCTI_SUPER_DECL]
#define method_context objc_global_trees[OCTI_METH_CTX]
*************** create_builtin_decl (code, type, name)
*** 1243,1248 ****
--- 1256,1279 ----
return decl;
}
+ /* Find the decl for the constant string class. */
+
+ static void
+ setup_string_decl ()
+ {
+ if (!string_class_decl)
+ {
+ if (!constant_string_global_id)
+ {
+ constant_string_global_id =
+ get_identifier (STRING_OBJECT_GLOBAL_NAME);
+ if (constant_string_global_id == NULL_TREE)
+ return;
+ }
+ string_class_decl = lookup_name (constant_string_global_id);
+ }
+ }
+
/* Purpose: "play" parser, creating/installing representations
of the declarations that are required by Objective-C.
*************** build_objc_string_object (strings)
*** 1431,1438 ****
length = TREE_STRING_LENGTH (string) - 1;
/* & ((NXConstantString) {0, string, length}) */
- initlist = build_tree_list (NULL_TREE, build_int_2 (0, 0));
initlist
= tree_cons (NULL_TREE, copy_node (build_unary_op (ADDR_EXPR, string, 1)),
initlist);
--- 1462,1488 ----
length = TREE_STRING_LENGTH (string) - 1;
/* & ((NXConstantString) {0, string, length}) */
+
+ if (flag_next_runtime)
+ {
+ /* For the NeXT runtime, we can generate a literal reference
+ to the string class, don't need to run a constructor. */
+ setup_string_decl ();
+ if (string_class_decl == NULL_TREE)
+ {
+ error ("Cannot find reference tag for class `%s'",
+ IDENTIFIER_POINTER (constant_string_id));
+ return error_mark_node;
+ }
+ initlist = build_tree_list
+ (NULL_TREE,
+ copy_node (build_unary_op (ADDR_EXPR, string_class_decl, 0)));
+ }
+ else
+ {
+ initlist = build_tree_list (NULL_TREE, build_int_2 (0, 0));
+ }
initlist
= tree_cons (NULL_TREE, copy_node (build_unary_op (ADDR_EXPR, string, 1)),
initlist);