PATCH: Make ObjC an extension of C (Take 3.1)
Ziemowit Laski
zlaski@apple.com
Fri Aug 9 13:03:00 GMT 2002
(A ChangeLog would be nice, wouldn't it?)
Ok, after further comments from Neil and Stan, here's my third (and
hopefully final) approach. Since Neil already approved the cpplib
part, I just need someone to look at the non-cpplib bits.
Bootstrapped on i686-pc-linux-gnu, no regressions.
OK for TOT?
2002-08-09 Ziemowit Laski <zlaski@apple.com>
* c-common.c (flag_objc): New.
* c-common.h (c_language_kind): Get rid of clk_objective_c
enum value.
(flag_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 (lex_charconst): Remove uses of clk_objective_c,
replace with flag_objc as needed.
* c-opts.c (c_common_init_options): Likewise.
(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 (init_builtins): Set __OBJC__ manifest constant
independently of those for other languages.
* 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 flag_objc flag.
Index: gcc/c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.362
diff -c -3 -p -r1.362 c-common.c
*** gcc/c-common.c 7 Aug 2002 18:32:07 -0000 1.362
--- gcc/c-common.c 9 Aug 2002 19:52:21 -0000
*************** int flag_preprocess_only;
*** 200,205 ****
--- 200,208 ----
user's namespace. */
int flag_iso;
+ /* Nonzero whenever Objective-C functionality is being used. */
+ int flag_objc;
+
/* Nonzero if -undef was given. It suppresses target built-in macros
and assertions. */
int flag_undef;
Index: gcc/c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.148
diff -c -3 -p -r1.148 c-common.h
*** gcc/c-common.h 7 Aug 2002 18:32:07 -0000 1.148
--- gcc/c-common.h 9 Aug 2002 19:52:24 -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,373 ****
extern c_language_kind c_language;
-
/* Switches common to the C front ends. */
/* Nonzero if prepreprocessing only. */
--- 366,371 ----
*************** extern int flag_preprocess_only;
*** 377,382 ****
--- 375,383 ----
user's namespace. */
extern int flag_iso;
+ /* Nonzero whenever Objective-C functionality is being used. */
+ extern int flag_objc;
+
/* Nonzero if -undef was given. It suppresses target built-in macros
and assertions. */
extern int flag_undef;
*************** 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. */
--- 794,799 ----
Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.346
diff -c -3 -p -r1.346 c-decl.c
*** gcc/c-decl.c 7 Aug 2002 18:32:07 -0000 1.346
--- gcc/c-decl.c 9 Aug 2002 19:52:28 -0000
*************** implicitly_declare (functionid)
*** 2059,2066 ****
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);
--- 2059,2067 ----
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 (flag_objc)
! objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, 0, 0);
*************** finish_decl (decl, init, asmspec_tree)
*** 3097,3104 ****
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))
{
--- 3098,3106 ----
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 (flag_objc)
! objc_check_decl (decl);
if (!DECL_CONTEXT (decl))
{
*************** finish_decl (decl, init, asmspec_tree)
*** 3160,3167 ****
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);
}
--- 3162,3170 ----
if (TREE_CODE (decl) == TYPE_DECL)
{
! /* This is a no-op in c-lang.c or something real in objc-
act.c. */
! if (flag_objc)
! objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, DECL_CONTEXT (decl) == 0,
0);
}
*************** grokfield (filename, line, declarator, d
*** 5009,5015 ****
finish_decl (value, NULL_TREE, NULL_TREE);
DECL_INITIAL (value) = width;
! maybe_objc_check_decl (value);
return value;
}
--- 5012,5019 ----
finish_decl (value, NULL_TREE, NULL_TREE);
DECL_INITIAL (value) = width;
! if (flag_objc)
! objc_check_decl (value);
return value;
}
*************** finish_struct (t, fieldlist, attributes)
*** 5297,5304 ****
&& 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);
--- 5301,5309 ----
&& 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 (flag_objc)
! objc_check_decl (decl);
rest_of_decl_compilation (decl, NULL, toplevel, 0);
if (! toplevel)
expand_decl (decl);
*************** finish_struct (t, fieldlist, attributes)
*** 5320,5326 ****
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);
--- 5325,5332 ----
if (TREE_CODE (decl) != TYPE_DECL)
{
layout_decl (decl, 0);
! if (flag_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.96
diff -c -3 -p -r1.96 c-lang.c
*** gcc/c-lang.c 7 Aug 2002 18:32:07 -0000 1.96
--- gcc/c-lang.c 9 Aug 2002 19:52:29 -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
! objc_message_selector ()
{
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 9 Aug 2002 19:52:33 -0000
*************** lex_charconst (token)
*** 1078,1085 ****
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
type = char_type_node;
--- 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
type = char_type_node;
Index: gcc/c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 c-opts.c
*** gcc/c-opts.c 8 Aug 2002 06:30:12 -0000 1.2
--- gcc/c-opts.c 9 Aug 2002 19:52:36 -0000
*************** c_common_init_options (lang)
*** 366,376 ****
#endif
c_language = lang;
! parse_in = cpp_create_reader (lang == clk_c || lang ==
clk_objective_c
? CLK_GNUC89 : CLK_GNUCXX);
cpp_opts = cpp_get_options (parse_in);
! if (lang == clk_objective_c)
cpp_opts->objc = 1;
flag_const_strings = (lang == clk_cplusplus);
--- 366,376 ----
#endif
c_language = lang;
! parse_in = cpp_create_reader (lang == clk_c
? CLK_GNUC89 : CLK_GNUCXX);
cpp_opts = cpp_get_options (parse_in);
! if (flag_objc)
cpp_opts->objc = 1;
flag_const_strings = (lang == clk_cplusplus);
*************** c_common_decode_option (argc, argv)
*** 407,415 ****
switch (c_language)
{
! case clk_c: lang_flag = CL_C_ONLY; break;
! case clk_cplusplus: lang_flag = CL_CXX_ONLY; break;
! case clk_objective_c: lang_flag = CL_OBJC_ONLY; break;
default: abort ();
}
--- 407,420 ----
switch (c_language)
{
! case clk_c: lang_flag = (flag_objc
! ? CL_C
! : CL_C_ONLY);
! break;
! case clk_cplusplus: lang_flag = (flag_objc
! ? CL_CXX
! : CL_CXX_ONLY);
! break;
default: abort ();
}
*************** c_common_decode_option (argc, argv)
*** 493,499 ****
if (warn_uninitialized != 1)
warn_uninitialized = (on ? 2 : 0);
! if (c_language == clk_c || c_language == clk_objective_c)
/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
can turn it off only if it's not explicit. */
warn_main = on * 2;
--- 498,504 ----
if (warn_uninitialized != 1)
warn_uninitialized = (on ? 2 : 0);
! if (c_language == clk_c)
/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
can turn it off only if it's not explicit. */
warn_main = on * 2;
*************** c_common_decode_option (argc, argv)
*** 751,764 ****
break;
case OPT_Wwrite_strings:
! if (c_language == clk_c || c_language == clk_objective_c)
flag_const_strings = on;
else
warn_write_strings = on;
break;
case OPT_fcond_mismatch:
! if (c_language == clk_c || c_language == clk_objective_c)
{
flag_cond_mismatch = on;
break;
--- 756,769 ----
break;
case OPT_Wwrite_strings:
! if (c_language == clk_c)
flag_const_strings = on;
else
warn_write_strings = on;
break;
case OPT_fcond_mismatch:
! if (c_language == clk_c)
{
flag_cond_mismatch = on;
break;
*************** c_common_decode_option (argc, argv)
*** 1046,1052 ****
case OPT_std_iso9899_199409:
case OPT_ansi:
/* Note: -ansi is used by both the C and C++ front ends. */
! if (c_language == clk_c || c_language == clk_objective_c)
{
flag_no_asm = 1;
flag_writable_strings = 0;
--- 1051,1057 ----
case OPT_std_iso9899_199409:
case OPT_ansi:
/* Note: -ansi is used by both the C and C++ front ends. */
! if (c_language == clk_c)
{
flag_no_asm = 1;
flag_writable_strings = 0;
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 9 Aug 2002 19:52:37 -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 (!flag_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.103
diff -c -3 -p -r1.103 c-tree.h
*** gcc/c-tree.h 7 Aug 2002 18:32:07 -0000 1.103
--- gcc/c-tree.h 9 Aug 2002 19:52:38 -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 objc_message_selector PARAMS ((void));
extern int recognize_objc_keyword PARAMS ((void));
extern tree lookup_objc_ivar PARAMS ((tree));
Index: gcc/c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.201
diff -c -3 -p -r1.201 c-typeck.c
*** gcc/c-typeck.c 25 Jul 2002 08:58:02 -0000 1.201
--- gcc/c-typeck.c 9 Aug 2002 19:52:39 -0000
*************** comptypes (type1, type2)
*** 568,574 ****
}
case RECORD_TYPE:
! if (maybe_objc_comptypes (t1, t2, 0) == 1)
val = 1;
break;
--- 568,574 ----
}
case RECORD_TYPE:
! if (flag_objc && objc_comptypes (t1, t2, 0) == 1)
val = 1;
break;
*************** comp_target_types (ttl, ttr)
*** 588,594 ****
int val;
/* Give maybe_objc_comptypes a crack at letting these types
through. */
! if ((val = maybe_objc_comptypes (ttl, ttr, 1)) >= 0)
return val;
val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
--- 588,594 ----
int val;
/* Give maybe_objc_comptypes a crack at letting these types
through. */
! if ((val = objc_comptypes (ttl, ttr, 1)) >= 0)
return val;
val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
*************** convert_for_assignment (type, rhs, errty
*** 3985,3991 ****
overflow_warning (rhs);
/* Check for Objective-C protocols. This will issue a warning if
there are protocol violations. No need to use the return
value. */
! maybe_objc_comptypes (type, rhstype, 0);
return rhs;
}
--- 3985,3992 ----
overflow_warning (rhs);
/* Check for Objective-C protocols. This will issue a warning if
there are protocol violations. No need to use the return
value. */
! if (flag_objc)
! objc_comptypes (type, rhstype, 0);
return rhs;
}
*************** convert_for_assignment (type, rhs, errty
*** 4213,4219 ****
{
if (funname)
{
! tree selector = maybe_building_objc_message_expr ();
if (selector && parmnum > 2)
error ("incompatible type for argument %d of `%s'",
--- 4214,4220 ----
{
if (funname)
{
! tree selector = objc_message_selector ();
if (selector && parmnum > 2)
error ("incompatible type for argument %d of `%s'",
*************** warn_for_assignment (msgid, opname, func
*** 4271,4277 ****
{
if (opname == 0)
{
! tree selector = maybe_building_objc_message_expr ();
char * new_opname;
if (selector && argnum > 2)
--- 4272,4278 ----
{
if (opname == 0)
{
! tree selector = objc_message_selector ();
char * new_opname;
if (selector && argnum > 2)
Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.250
diff -c -3 -p -r1.250 cppinit.c
*** gcc/cppinit.c 8 Aug 2002 06:30:12 -0000 1.250
--- gcc/cppinit.c 9 Aug 2002 19:52:40 -0000
*************** init_builtins (pfile)
*** 695,709 ****
if (CPP_OPTION (pfile, cplusplus))
_cpp_define_builtin (pfile, "__cplusplus 1");
- else if (CPP_OPTION (pfile, objc))
- _cpp_define_builtin (pfile, "__OBJC__ 1");
else if (CPP_OPTION (pfile, lang) == CLK_ASM)
_cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
!
! if (CPP_OPTION (pfile, lang) == CLK_STDC94)
_cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
else if (CPP_OPTION (pfile, c99))
_cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
if (pfile->cb.register_builtins)
(*pfile->cb.register_builtins) (pfile);
--- 695,709 ----
if (CPP_OPTION (pfile, cplusplus))
_cpp_define_builtin (pfile, "__cplusplus 1");
else if (CPP_OPTION (pfile, lang) == CLK_ASM)
_cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
! else if (CPP_OPTION (pfile, lang) == CLK_STDC94)
_cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
else if (CPP_OPTION (pfile, c99))
_cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
+
+ if (CPP_OPTION (pfile, objc))
+ _cpp_define_builtin (pfile, "__OBJC__ 1");
if (pfile->cb.register_builtins)
(*pfile->cb.register_builtins) (pfile);
Index: gcc/objc/objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.148
diff -c -3 -p -r1.148 objc-act.c
*** gcc/objc/objc-act.c 7 Aug 2002 18:32:11 -0000 1.148
--- gcc/objc/objc-act.c 9 Aug 2002 19:52:42 -0000
*************** define_decl (declarator, declspecs)
*** 518,531 ****
`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;
--- 518,523 ----
*************** objc_check_decl (decl)
*** 764,776 ****
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
--- 756,761 ----
*************** receiver_is_class_object (receiver)
*** 4664,4670 ****
static tree building_objc_message_expr = 0;
tree
! maybe_building_objc_message_expr ()
{
return building_objc_message_expr;
}
--- 4649,4655 ----
static tree building_objc_message_expr = 0;
tree
! objc_message_selector ()
{
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.25
diff -c -3 -p -r1.25 objc-lang.c
*** gcc/objc/objc-lang.c 7 Aug 2002 18:32:11 -0000 1.25
--- gcc/objc/objc-lang.c 9 Aug 2002 19:52:43 -0000
*************** const char * const tree_code_name[] = {
*** 162,166 ****
static void
objc_init_options ()
{
! c_common_init_options (clk_objective_c);
! }
--- 162,167 ----
static void
objc_init_options ()
{
! flag_objc = 1;
! c_common_init_options (clk_c);
! }
--------------------------------------------------------------
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
More information about the Gcc-patches
mailing list