This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Still more Objective-C frontend cleanup
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: Still more Objective-C frontend cleanup
- From: Stan Shebs <shebs at apple dot com>
- Date: Tue, 27 Mar 2001 18:49:38 -0800
A continuation of output cleanup inspired by a Neil Booth comment,
plus additional warnings imported from Apple's code, plus a fix for
a crash if -gen-decls is used (I'll be nice and not research into
who changed the code to try to initialize a variable with itself,
tsk tsk... :-) ). Bootstrapped on powerpc-apple-darwin1.3, committed
to mainline, testsuite cases to follow when I figure out how they
should be structured.
Stan
2001-03-27 Stan Shebs <shebs@apple.com>
* objc/objc-act.c (objc_init): Use dump_base_name.
(gen_declaration): Clear the buffer arg.
(gen_declaration_1): New function, body of gen_declaration.
(adorn_decl): Call gen_declaration_1 instead of gen_declaration.
(gen_method_decl): Ditto, plus always clear buffer arg.
(error_with_ivar): Simplify.
(warn_with_method): Ditto.
(build_message_expr): Don't clear buffers.
(dump_interface): Ditto.
(objc_debug): Ditto.
(build_keyword_selector): Clear the buffer by only zeroing
the first element.
(objc_implementation_context): Declare.
(start_class): Warn about missing @end.
(finish_objc): Ditto.
Index: objc-act.c
===================================================================
RCS file: /cvs/repository/CoreTools/gcc3/gcc/objc/objc-act.c,v
retrieving revision 1.1.1.10
diff -c -3 -p -r1.1.1.10 objc-act.c
*** objc-act.c 2001/03/27 01:42:18 1.1.1.10
--- objc-act.c 2001/03/28 02:18:22
*************** char *util_firstobj;
*** 142,147 ****
--- 142,150 ----
#define OBJC_ENCODE_INLINE_DEFS 0
#define OBJC_ENCODE_DONT_INLINE_DEFS 1
+ /* Needed to help fix missing @end situations. */
+ extern tree objc_implementation_context;
+
/*** Private Interface (procedures) ***/
/* Used by compile_file. */
*************** static void warn_with_method PARAMS ((
*** 272,277 ****
--- 275,281 ----
static void error_with_ivar PARAMS ((const char *, tree, tree));
static char *gen_method_decl PARAMS ((tree, char *));
static char *gen_declaration PARAMS ((tree, char *));
+ static void gen_declaration_1 PARAMS ((tree, char *));
static char *gen_declarator PARAMS ((tree, char *,
const char *));
static int is_complex_decl PARAMS ((tree));
*************** objc_init ()
*** 727,733 ****
/* If gen_declaration desired, open the output file. */
if (flag_gen_declaration)
{
! register char * const dumpname = concat (dumpname, ".decl", NULL);
gen_declaration_file = fopen (dumpname, "w");
if (gen_declaration_file == 0)
fatal_io_error ("can't open %s", dumpname);
--- 731,737 ----
/* If gen_declaration desired, open the output file. */
if (flag_gen_declaration)
{
! register char * const dumpname = concat (dump_base_name, ".decl", NULL);
gen_declaration_file = fopen (dumpname, "w");
if (gen_declaration_file == 0)
fatal_io_error ("can't open %s", dumpname);
*************** get_object_reference (protocols)
*** 1146,1152 ****
type = TREE_TYPE (type_decl);
if (TYPE_MAIN_VARIANT (type) != id_type)
warning ("Unexpected type for `id' (%s)",
! gen_declaration (type, errbuf));
}
else
{
--- 1150,1156 ----
type = TREE_TYPE (type_decl);
if (TYPE_MAIN_VARIANT (type) != id_type)
warning ("Unexpected type for `id' (%s)",
! gen_declaration (type, errbuf));
}
else
{
*************** error_with_ivar (message, decl, rawdecl)
*** 3616,3628 ****
report_error_function (DECL_SOURCE_FILE (decl));
- strcpy (errbuf, message);
- strcat (errbuf, " `");
- gen_declaration (rawdecl, errbuf + strlen (errbuf));
- strcat (errbuf, "'");
error_with_file_and_line (DECL_SOURCE_FILE (decl),
DECL_SOURCE_LINE (decl),
! errbuf);
}
#define USERTYPE(t) \
--- 3620,3630 ----
report_error_function (DECL_SOURCE_FILE (decl));
error_with_file_and_line (DECL_SOURCE_FILE (decl),
DECL_SOURCE_LINE (decl),
! "%s `%s'",
! message, gen_declaration (rawdecl, errbuf));
!
}
#define USERTYPE(t) \
*************** build_keyword_selector (selector)
*** 4717,4722 ****
--- 4719,4725 ----
tree key_chain, key_name;
char *buf;
+ /* Scan the selector to see how much space we'll need. */
for (key_chain = selector; key_chain; key_chain = TREE_CHAIN (key_chain))
{
if (TREE_CODE (selector) == KEYWORD_DECL)
*************** build_keyword_selector (selector)
*** 4733,4740 ****
len++;
}
! buf = (char *)alloca (len + 1);
! memset (buf, 0, len + 1);
for (key_chain = selector; key_chain; key_chain = TREE_CHAIN (key_chain))
{
--- 4736,4744 ----
len++;
}
! buf = (char *) alloca (len + 1);
! /* Start the buffer out as an empty string. */
! buf[0] = '\0';
for (key_chain = selector; key_chain; key_chain = TREE_CHAIN (key_chain))
{
*************** build_message_expr (mess)
*** 4970,4976 ****
/* Allow any type that matches objc_class_type. */
&& ! comptypes (rtype, objc_class_type))
{
- memset (errbuf, 0, BUFSIZE);
warning ("invalid receiver type `%s'",
gen_declaration (rtype, errbuf));
}
--- 4974,4979 ----
*************** start_class (code, class_name, super_nam
*** 6135,6140 ****
--- 6138,6151 ----
{
tree class, decl;
+ if (objc_implementation_context)
+ {
+ warning ("`@end' missing in implementation context");
+ finish_class (objc_implementation_context);
+ objc_ivar_chain = NULL_TREE;
+ objc_implementation_context = NULL_TREE;
+ }
+
class = make_node (code);
TYPE_BINFO (class) = make_tree_vec (5);
*************** warn_with_method (message, mtype, method
*** 7047,7059 ****
report_error_function (DECL_SOURCE_FILE (method));
/* Add a readable method name to the warning. */
- sprintf (errbuf, "%s `%c", message, mtype);
- gen_method_decl (method, errbuf + strlen (errbuf));
- strcat (errbuf, "'");
-
warning_with_file_and_line (DECL_SOURCE_FILE (method),
DECL_SOURCE_LINE (method),
! errbuf);
}
/* Return 1 if METHOD is consistent with PROTO. */
--- 7058,7068 ----
report_error_function (DECL_SOURCE_FILE (method));
/* Add a readable method name to the warning. */
warning_with_file_and_line (DECL_SOURCE_FILE (method),
DECL_SOURCE_LINE (method),
! "%s `%c%s'",
! message, mtype,
! gen_method_decl (method, errbuf));
}
/* Return 1 if METHOD is consistent with PROTO. */
*************** adorn_decl (decl, str)
*** 7477,7483 ****
strcat (str, "(");
while (chain)
{
! gen_declaration (chain, str);
chain = TREE_CHAIN (chain);
if (chain)
strcat (str, ", ");
--- 7486,7492 ----
strcat (str, "(");
while (chain)
{
! gen_declaration_1 (chain, str);
chain = TREE_CHAIN (chain);
if (chain)
strcat (str, ", ");
*************** adorn_decl (decl, str)
*** 7492,7498 ****
strcat (str, "(");
while (chain && TREE_VALUE (chain) != void_type_node)
{
! gen_declaration (TREE_VALUE (chain), str);
chain = TREE_CHAIN (chain);
if (chain && TREE_VALUE (chain) != void_type_node)
strcat (str, ", ");
--- 7501,7507 ----
strcat (str, "(");
while (chain && TREE_VALUE (chain) != void_type_node)
{
! gen_declaration_1 (TREE_VALUE (chain), str);
chain = TREE_CHAIN (chain);
if (chain && TREE_VALUE (chain) != void_type_node)
strcat (str, ", ");
*************** gen_declspecs (declspecs, buf, raw)
*** 7885,7895 ****
--- 7894,7920 ----
}
}
+ /* Given a tree node, produce a printable description of it in the given
+ buffer, overwriting the buffer. */
+
static char *
gen_declaration (atype_or_adecl, buf)
tree atype_or_adecl;
char *buf;
{
+ buf[0] = '\0';
+ gen_declaration_1 (atype_or_adecl, buf);
+ return buf;
+ }
+
+ /* Given a tree node, append a printable description to the end of the
+ given buffer. */
+
+ static void
+ gen_declaration_1 (atype_or_adecl, buf)
+ tree atype_or_adecl;
+ char *buf;
+ {
char declbuf[256];
if (TREE_CODE (atype_or_adecl) == TREE_LIST)
*************** gen_declaration (atype_or_adecl, buf)
*** 7969,7980 ****
strcat (buf, gen_declarator (declarator, declbuf, ""));
}
}
-
- return buf;
}
#define RAW_TYPESPEC(meth) (TREE_VALUE (TREE_PURPOSE (TREE_TYPE (meth))))
static char *
gen_method_decl (method, buf)
tree method;
--- 7994,8006 ----
strcat (buf, gen_declarator (declarator, declbuf, ""));
}
}
}
#define RAW_TYPESPEC(meth) (TREE_VALUE (TREE_PURPOSE (TREE_TYPE (meth))))
+ /* Given a method tree, put a printable description into the given
+ buffer (overwriting) and return a pointer to the buffer. */
+
static char *
gen_method_decl (method, buf)
tree method;
*************** gen_method_decl (method, buf)
*** 7982,7991 ****
{
tree chain;
if (RAW_TYPESPEC (method) != objc_object_reference)
{
! strcpy (buf, "(");
! gen_declaration (TREE_TYPE (method), buf);
strcat (buf, ")");
}
--- 8008,8018 ----
{
tree chain;
+ buf[0] = '\0';
if (RAW_TYPESPEC (method) != objc_object_reference)
{
! strcat (buf, "(");
! gen_declaration_1 (TREE_TYPE (method), buf);
strcat (buf, ")");
}
*************** gen_method_decl (method, buf)
*** 8002,8008 ****
if (RAW_TYPESPEC (chain) != objc_object_reference)
{
strcat (buf, "(");
! gen_declaration (TREE_TYPE (chain), buf);
strcat (buf, ")");
}
--- 8029,8035 ----
if (RAW_TYPESPEC (chain) != objc_object_reference)
{
strcat (buf, "(");
! gen_declaration_1 (TREE_TYPE (chain), buf);
strcat (buf, ")");
}
*************** gen_method_decl (method, buf)
*** 8023,8029 ****
while (chain)
{
strcat (buf, ", ");
! gen_declaration (chain, buf);
chain = TREE_CHAIN (chain);
}
}
--- 8050,8056 ----
while (chain)
{
strcat (buf, ", ");
! gen_declaration_1 (chain, buf);
chain = TREE_CHAIN (chain);
}
}
*************** dump_interface (fp, chain)
*** 8064,8070 ****
fprintf (fp, "{\n");
do
{
- memset (buf, 0, 256);
fprintf (fp, "\t%s;\n", gen_declaration (ivar_decls, buf));
ivar_decls = TREE_CHAIN (ivar_decls);
}
--- 8091,8096 ----
*************** dump_interface (fp, chain)
*** 8074,8087 ****
while (nst_methods)
{
- memset (buf, 0, 256);
fprintf (fp, "- %s;\n", gen_method_decl (nst_methods, buf));
nst_methods = TREE_CHAIN (nst_methods);
}
while (cls_methods)
{
- memset (buf, 0, 256);
fprintf (fp, "+ %s;\n", gen_method_decl (cls_methods, buf));
cls_methods = TREE_CHAIN (cls_methods);
}
--- 8100,8111 ----
*************** finish_objc ()
*** 8196,8201 ****
--- 8220,8234 ----
int save_warn_missing_braces = warn_missing_braces;
warn_missing_braces = 0;
+ /* A missing @end may not be detected by the parser. */
+ if (objc_implementation_context)
+ {
+ warning ("`@end' missing in implementation context");
+ finish_class (implementation_context);
+ objc_ivar_chain = NULL_TREE;
+ objc_implementation_context = NULL_TREE;
+ }
+
generate_forward_declaration_to_string_table ();
#ifdef OBJC_PROLOGUE
*************** objc_debug (fp)
*** 8480,8488 ****
if (TREE_CODE (loop) == FUNCTION_DECL && DECL_INITIAL (loop))
{
/* We have a function definition: generate prototype. */
! memset (errbuf, 0, BUFSIZE);
! gen_declaration (loop, errbuf);
! fprintf (fp, "%s;\n", errbuf);
}
loop = TREE_CHAIN (loop);
}
--- 8513,8519 ----
if (TREE_CODE (loop) == FUNCTION_DECL && DECL_INITIAL (loop))
{
/* We have a function definition: generate prototype. */
! fprintf (fp, "%s;\n", gen_declaration (loop, errbuf));
}
loop = TREE_CHAIN (loop);
}
*************** objc_debug (fp)
*** 8500,8506 ****
fprintf (fp, "\n\nnst_method_hash_list[%d]:\n", i);
do
{
- memset (buf, 0, 256);
fprintf (fp, "-%s;\n", gen_method_decl (hashlist->key, buf));
hashlist = hashlist->next;
}
--- 8531,8536 ----
*************** objc_debug (fp)
*** 8515,8521 ****
fprintf (fp, "\n\ncls_method_hash_list[%d]:\n", i);
do
{
- memset (buf, 0, 256);
fprintf (fp, "-%s;\n", gen_method_decl (hashlist->key, buf));
hashlist = hashlist->next;
}
--- 8545,8550 ----