This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Make ObjC an extension of C


Hi all,

The main purpose of this patch is to remove clk_objective_c as
a distinct language supported by the C-flavored front-ends. Instead,
Objective-C acquires the status of an _extension_ to the C language;
the 'compiling_objc' flag is introduced to keep track of whether this
extension is being used. Currently, compiling_objc is unconditionally
set by cc1obj, and left cleared by cc1. As we move towards a unified
front-end, however, compiling_objc will have to be controlled by its
own flag ('-fobjc'?). This control will be independent of the specific
variant of C (e.g., C94, C99, etc.) desired.

Such an arrangement results in a much cleaner separation of the
ObjC machinery from the base language. In the case of the FSF,
the base language can currently be any of the C variants. In Apple's
case, the base language can also be C++, which is how Objective-C++
is implemented. Hopefully, future work on the unified, recursive-
descent parser will allow Objective-C++ to appear in the FSF as well.

This patch is just the initial one in a series of fixes to ObjC that
we have done in gcc 3.1 in preparation for the Mac OS X 10.2
(aka Jaguar) release. It is only now that we actually have the time
to prepare the FSF submissions. :(

This has bootstrapped cleanly on i686-pc-linux-gnu, with no regressions
in any of the dejagnu test suites. We'd like to put it in TOT so that
it winds up on the 3.3 release branch later.

OK?


2002-08-08 Ziemowit Laski <zlaski@apple.com>

* c-common.c (c_common_init_options): Remove uses of
clk_objective_c, replace with compiling_objc as needed.
* c-common.h (c_language_kind): Get rid of clk_objective_c
enum value.
(compiling_objc): New extern declaration.
* c-decl.c (implicitly_declare): Call objc_check_decl
instead of maybe_objc_check_decl.
(finish_decl): Likewise.
(grokfield): Likewise.
(finish_struct): Likewise.
* c-lang.c (maybe_objc_check_decl): Rename to objc_check_decl.
(maybe_objc_comptypes): Rename to objc_comptypes.
(maybe_building_objc_message_expr): Rename to
objc_message_selector.
* c-lex.c (c_common_init_options): Remove uses of
clk_objective_c, replace with compiling_objc as needed.
(c_common_decode_option): Likewise.
* c-parse.in (init_reswords): Likewise.
* c-tree.h (maybe_objc_check_decl): Rename to objc_check_decl.
(maybe_objc_comptypes): Rename to objc_comptypes.
(maybe_building_objc_message_expr): Rename to
objc_message_selector.
* c-typeck.c (comptypes): Call objc_comptypes instead of
maybe_objc_comptypes, and/or objc_message_selector instead of
maybe_building_objc_message_expr.
(comp_target_types): Likewise.
(convert_for_assignment): Likewise.
(warn_for_assignment): Likewise.
cppinit.c (set_lang): Adjust for how Objective-C mode is
represented.
(init_standard_includes): Likewise.
(cpp_handle_option): Move case OPT_lang_objc so that it
falls through to OPT_lang_c.
* cpplib.h (compiling_objc): Add extern declaration.
* cppmain.c (compiling_objc): Add definition.
* fix_header.c (compiling_objc): Likewise.
* objc/objc-act.c (maybe_objc_comptypes): Delete.
(maybe_objc_check_decl): Delete.
(maybe_building_objc_message_expr): Rename to
objc_message_selector.
* objc/objc-lang.c (objc_init_options): Use clk_c instead of
clk_objective_c; set compiling_objc flag.


Index: gcc/c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.359
diff -c -3 -p -r1.359 c-common.c
*** gcc/c-common.c 2 Aug 2002 04:18:16 -0000 1.359
--- gcc/c-common.c 7 Aug 2002 21:01:09 -0000
*************** c_common_init_options (lang)
*** 4652,4660 ****
enum c_language_kind lang;
{
c_language = lang;
! parse_in = cpp_create_reader (lang == clk_c || lang == clk_objective_c
! ? CLK_GNUC89 : CLK_GNUCXX);
! if (lang == clk_objective_c)
cpp_get_options (parse_in)->objc = 1;

flag_const_strings = (lang == clk_cplusplus);
--- 4652,4659 ----
enum c_language_kind lang;
{
c_language = lang;
! parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX);
! if (compiling_objc)
cpp_get_options (parse_in)->objc = 1;

flag_const_strings = (lang == clk_cplusplus);
Index: gcc/c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.147
diff -c -3 -p -r1.147 c-common.h
*** gcc/c-common.h 1 Aug 2002 06:20:30 -0000 1.147
--- gcc/c-common.h 7 Aug 2002 21:01:10 -0000
*************** typedef enum c_language_kind
*** 240,247 ****
{
clk_c, /* A dialect of C: K&R C, ANSI/ISO C89, C2000,
etc. */
! clk_cplusplus, /* ANSI/ISO C++ */
! clk_objective_c /* Objective C */
}
c_language_kind;

--- 240,246 ----
{
clk_c, /* A dialect of C: K&R C, ANSI/ISO C89, C2000,
etc. */
! clk_cplusplus /* ANSI/ISO C++ */
}
c_language_kind;

*************** struct c_lang_decl GTY(()) {
*** 367,372 ****
--- 366,375 ----

extern c_language_kind c_language;

+ /* The following flag is non-zero whenever ObjC or ObjC++ is being
+ compiled. */
+
+ extern int compiling_objc;

/* Switches common to the C front ends. */

*************** extern int warn_deprecated;
*** 793,801 ****
infinite template instantiations. */

extern int max_tinst_depth;
-
-
-

/* C types are partitioned into three subsets: object, function, and
incomplete types. */
--- 796,801 ----
Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.344
diff -c -3 -p -r1.344 c-decl.c
*** gcc/c-decl.c 1 Aug 2002 06:20:30 -0000 1.344
--- gcc/c-decl.c 7 Aug 2002 21:01:13 -0000
*************** implicitly_declare (functionid)
*** 2307,2314 ****
So we record the decl in the standard fashion. */
pushdecl (decl);

! /* This is a no-op in c-lang.c or something real in objc-actions.c. */
! maybe_objc_check_decl (decl);

rest_of_decl_compilation (decl, NULL, 0, 0);

--- 2307,2315 ----
So we record the decl in the standard fashion. */
pushdecl (decl);

! /* This is a no-op in c-lang.c or something real in objc-act.c. */
! if (compiling_objc)
! objc_check_decl (decl);

rest_of_decl_compilation (decl, NULL, 0, 0);

*************** finish_decl (decl, init, asmspec_tree)
*** 3345,3352 ****

if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
{
! /* This is a no-op in c-lang.c or something real in objc-actions.c. */
! maybe_objc_check_decl (decl);

if (!DECL_CONTEXT (decl))
{
--- 3346,3354 ----

if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
{
! /* This is a no-op in c-lang.c or something real in objc-act.c. */
! if (compiling_objc)
! objc_check_decl (decl);

if (!DECL_CONTEXT (decl))
{
*************** finish_decl (decl, init, asmspec_tree)
*** 3408,3415 ****

if (TREE_CODE (decl) == TYPE_DECL)
{
! /* This is a no-op in c-lang.c or something real in objc-actions.c. */
! maybe_objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == 0, 0);
}

--- 3410,3418 ----

if (TREE_CODE (decl) == TYPE_DECL)
{
! /* This is a no-op in c-lang.c or something real in objc-act.c. */
! if (compiling_objc)
! objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == 0, 0);
}

*************** grokfield (filename, line, declarator, d
*** 5257,5263 ****
finish_decl (value, NULL_TREE, NULL_TREE);
DECL_INITIAL (value) = width;

! maybe_objc_check_decl (value);
return value;
}


--- 5260,5267 ----
finish_decl (value, NULL_TREE, NULL_TREE);
DECL_INITIAL (value) = width;

! if (compiling_objc)
! objc_check_decl (value);
return value;
}


*************** finish_struct (t, fieldlist, attributes)
*** 5545,5552 ****
&& TREE_CODE (decl) != TYPE_DECL)
{
layout_decl (decl, 0);
! /* This is a no-op in c-lang.c or something real in objc-actions.c. */
! maybe_objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, toplevel, 0);
if (! toplevel)
expand_decl (decl);
--- 5549,5557 ----
&& TREE_CODE (decl) != TYPE_DECL)
{
layout_decl (decl, 0);
! /* This is a no-op in c-lang.c or something real in objc-act.c. */
! if (compiling_objc)
! objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, toplevel, 0);
if (! toplevel)
expand_decl (decl);
*************** finish_struct (t, fieldlist, attributes)
*** 5568,5574 ****
if (TREE_CODE (decl) != TYPE_DECL)
{
layout_decl (decl, 0);
! maybe_objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, toplevel, 0);
if (! toplevel)
expand_decl (decl);
--- 5573,5580 ----
if (TREE_CODE (decl) != TYPE_DECL)
{
layout_decl (decl, 0);
! if (compiling_objc)
! objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, toplevel, 0);
if (! toplevel)
expand_decl (decl);
Index: gcc/c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.95
diff -c -3 -p -r1.95 c-lang.c
*** gcc/c-lang.c 26 Jul 2002 13:45:33 -0000 1.95
--- gcc/c-lang.c 7 Aug 2002 21:01:14 -0000
*************** is_class_name (arg)
*** 183,195 ****
}

void
! maybe_objc_check_decl (decl)
tree decl ATTRIBUTE_UNUSED;
{
}

int
! maybe_objc_comptypes (lhs, rhs, reflexive)
tree lhs ATTRIBUTE_UNUSED;
tree rhs ATTRIBUTE_UNUSED;
int reflexive ATTRIBUTE_UNUSED;
--- 183,195 ----
}

void
! objc_check_decl (decl)
tree decl ATTRIBUTE_UNUSED;
{
}

int
! objc_comptypes (lhs, rhs, reflexive)
tree lhs ATTRIBUTE_UNUSED;
tree rhs ATTRIBUTE_UNUSED;
int reflexive ATTRIBUTE_UNUSED;
*************** maybe_objc_comptypes (lhs, rhs, reflexiv
*** 198,204 ****
}

tree
! maybe_building_objc_message_expr ()
{
return 0;
}
--- 198,204 ----
}

tree
! building_objc_message_expr ()
{
return 0;
}
Index: gcc/c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.185
diff -c -3 -p -r1.185 c-lex.c
*** gcc/c-lex.c 21 Jul 2002 21:59:02 -0000 1.185
--- gcc/c-lex.c 7 Aug 2002 21:01:16 -0000
*************** lex_charconst (token)
*** 1078,1084 ****
type = wchar_type_node;
/* In C, a character constant has type 'int'.
In C++ 'char', but multi-char charconsts have type 'int'. */
! else if ((c_language == clk_c || c_language == clk_objective_c)
|| chars_seen > 1)
type = integer_type_node;
else
--- 1078,1084 ----
type = wchar_type_node;
/* In C, a character constant has type 'int'.
In C++ 'char', but multi-char charconsts have type 'int'. */
! else if (c_language == clk_c
|| chars_seen > 1)
type = integer_type_node;
else
Index: gcc/c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.150
diff -c -3 -p -r1.150 c-parse.in
*** gcc/c-parse.in 26 Jul 2002 16:23:05 -0000 1.150
--- gcc/c-parse.in 7 Aug 2002 21:01:17 -0000
*************** init_reswords ()
*** 3546,3552 ****
int mask = (flag_isoc99 ? 0 : D_C89)
| (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);

! if (c_language != clk_objective_c)
mask |= D_OBJC;

/* It is not necessary to register ridpointers as a GC root, because
--- 3546,3552 ----
int mask = (flag_isoc99 ? 0 : D_C89)
| (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0);

! if (!compiling_objc)
mask |= D_OBJC;

/* It is not necessary to register ridpointers as a GC root, because
Index: gcc/c-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.102
diff -c -3 -p -r1.102 c-tree.h
*** gcc/c-tree.h 1 Aug 2002 06:20:31 -0000 1.102
--- gcc/c-tree.h 7 Aug 2002 21:01:18 -0000
*************** struct lang_type GTY(())
*** 165,174 ****
/* in c-lang.c and objc-act.c */
extern tree lookup_interface PARAMS ((tree));
extern tree is_class_name PARAMS ((tree));
! extern void maybe_objc_check_decl PARAMS ((tree));
extern void finish_file PARAMS ((void));
! extern int maybe_objc_comptypes PARAMS ((tree, tree, int));
! extern tree maybe_building_objc_message_expr PARAMS ((void));
extern int recognize_objc_keyword PARAMS ((void));
extern tree lookup_objc_ivar PARAMS ((tree));

--- 165,174 ----
/* in c-lang.c and objc-act.c */
extern tree lookup_interface PARAMS ((tree));
extern tree is_class_name PARAMS ((tree));
! extern void objc_check_decl PARAMS ((tree));
extern void finish_file PARAMS ((void));
! extern int objc_comptypes PARAMS ((tree, tree, int));
! extern tree building_objc_message_expr PARAMS ((void));
extern int recognize_objc_keyword PARAMS ((void));
extern tree lookup_objc_ivar PARAMS ((tree));

Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.248
diff -c -3 -p -r1.248 cppinit.c
*** gcc/cppinit.c 2 Aug 2002 04:18:16 -0000 1.248
--- gcc/cppinit.c 7 Aug 2002 21:01:20 -0000
*************** set_lang (pfile, lang)
*** 412,417 ****
--- 412,418 ----
const struct lang_flags *l = &lang_defaults[(int) lang];

CPP_OPTION (pfile, lang) = lang;
+ CPP_OPTION (pfile, objc) = compiling_objc;

CPP_OPTION (pfile, c99) = l->c99;
CPP_OPTION (pfile, cplusplus) = l->cplusplus;
*************** init_standard_includes (pfile)
*** 727,733 ****
if (path != 0 && *path != 0)
path_include (pfile, path, BRACKET);

! switch ((CPP_OPTION (pfile, objc) << 1) + CPP_OPTION (pfile, cplusplus))
{
case 0:
GET_ENVIRONMENT (path, "C_INCLUDE_PATH");
--- 728,734 ----
if (path != 0 && *path != 0)
path_include (pfile, path, BRACKET);

! switch ((CPP_OPTION (pfile, objc) ? 2 : 0) + CPP_OPTION (pfile, cplusplus))
{
case 0:
GET_ENVIRONMENT (path, "C_INCLUDE_PATH");
*************** cpp_handle_option (pfile, argc, argv)
*** 1440,1453 ****
CPP_OPTION (pfile, include_prefix) = arg;
CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
break;
case OPT_lang_c:
set_lang (pfile, CLK_GNUC89);
break;
case OPT_lang_cplusplus:
set_lang (pfile, CLK_GNUCXX);
- break;
- case OPT_lang_objc:
- CPP_OPTION (pfile, objc) = 1;
break;
case OPT_lang_asm:
set_lang (pfile, CLK_ASM);
--- 1441,1454 ----
CPP_OPTION (pfile, include_prefix) = arg;
CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
break;
+ case OPT_lang_objc:
+ compiling_objc = 1;
+ /* Fall through. */
case OPT_lang_c:
set_lang (pfile, CLK_GNUC89);
break;
case OPT_lang_cplusplus:
set_lang (pfile, CLK_GNUCXX);
break;
case OPT_lang_asm:
set_lang (pfile, CLK_ASM);
Index: gcc/cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.227
diff -c -3 -p -r1.227 cpplib.h
*** gcc/cpplib.h 23 Jul 2002 22:57:44 -0000 1.227
--- gcc/cpplib.h 7 Aug 2002 21:01:22 -0000
*************** enum cpp_ttype
*** 154,159 ****
--- 154,160 ----
/* C language kind, used when calling cpp_reader_init. */
enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99,
CLK_GNUCXX, CLK_CXX98, CLK_ASM};
+ extern int compiling_objc;

/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
struct cpp_string
Index: gcc/cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.101
diff -c -3 -p -r1.101 cppmain.c
*** gcc/cppmain.c 29 Jun 2002 15:49:23 -0000 1.101
--- gcc/cppmain.c 7 Aug 2002 21:01:23 -0000
*************** static void cb_ident PARAMS ((cpp_read
*** 62,67 ****
--- 62,71 ----
static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int));

+ /* ObjC and ObjC++ no longer have their own rows; instead, compiling_objc is
+ set on top of another C/C++ dialect. */
+ int compiling_objc = 0;
+
static cpp_options *options; /* Options of pfile. */
static struct printer print;

Index: gcc/fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.83
diff -c -3 -p -r1.83 fix-header.c
*** gcc/fix-header.c 23 Jul 2002 06:21:52 -0000 1.83
--- gcc/fix-header.c 7 Aug 2002 21:01:24 -0000
*************** fatal VPARAMS ((const char *str, ...))
*** 1324,1326 ****
--- 1324,1330 ----
v_fatal (str, ap);
VA_CLOSE (ap);
}
+
+ /* ObjC and ObjC++ no longer have their own rows; instead, compiling_objc is
+ set on top of another C/C++ dialect. */
+ int compiling_objc = 0;
Index: gcc/objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.147
diff -c -3 -p -r1.147 objc-act.c
*** gcc/objc/objc-act.c 1 Aug 2002 15:43:51 -0000 1.147
--- gcc/objc/objc-act.c 7 Aug 2002 21:01:26 -0000
*************** define_decl (declarator, declspecs)
*** 559,572 ****
`a' and `b' are the same class type, or
`a' and `b' are of class types A and B such that B is a descendant of A. */

- int
- maybe_objc_comptypes (lhs, rhs, reflexive)
- tree lhs, rhs;
- int reflexive;
- {
- return objc_comptypes (lhs, rhs, reflexive);
- }
-
static tree
lookup_method_in_protocol_list (rproto_list, sel_name, class_meth)
tree rproto_list;
--- 559,564 ----
*************** objc_check_decl (decl)
*** 805,817 ****
error_with_decl (decl, "`%s' cannot be statically allocated");
}

- void
- maybe_objc_check_decl (decl)
- tree decl;
- {
- objc_check_decl (decl);
- }
-
/* Implement static typing. At this point, we know we have an interface. */

tree
--- 797,802 ----
*************** receiver_is_class_object (receiver)
*** 4705,4711 ****
static tree building_objc_message_expr = 0;

tree
! maybe_building_objc_message_expr ()
{
return building_objc_message_expr;
}
--- 4690,4696 ----
static tree building_objc_message_expr = 0;

tree
! building_objc_message_expr ()
{
return building_objc_message_expr;
}
Index: gcc/objc/objc-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-lang.c,v
retrieving revision 1.24
diff -c -3 -p -r1.24 objc-lang.c
*** gcc/objc/objc-lang.c 6 Jun 2002 09:25:48 -0000 1.24
--- gcc/objc/objc-lang.c 7 Aug 2002 21:01:27 -0000
*************** static void objc_init_options
*** 115,120 ****
--- 115,131 ----
/* Each front end provides its own hooks, for toplev.c. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;

+ static void
+ objc_init_options ()
+ {
+ compiling_objc = 1;
+ #ifdef OBJCPLUS
+ cxx_init_options (clk_cplusplus);
+ #else
+ c_common_init_options (clk_c);
+ #endif
+ }
+
/* Define the special tree codes that we use. */

/* Table indexed by tree code giving a string containing a character

--------------------------------------------------------------
Ziemowit Laski 1 Infinite Loop, MS 301-2K
Mac OS X Compiler Group Cupertino, CA USA 95014-2083
Apple Computer, Inc. +1.408.974.6229 Fax .5477


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]