This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch partially fixing the ObjC -gen-decls option
- From: Nicola Pero <nicola at brainstorm dot co dot uk>
- To: shebs at apple dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 30 Aug 2002 11:45:05 +0100 (BST)
- Subject: Patch partially fixing the ObjC -gen-decls option
While documenting the ObjC options, I found about the -gen-decls option,
and I had a look at it, but it looks like it is horribly buggy :-(
While reading the code, I tidied it up a little, fixed some stuff, and
commented some rough bits. I didn't too much, anyway with this patch it
works definitely much better for me. Before, it didn't work at all.
Ok to apply ?
Fri Aug 30 01:49:42 2002 Nicola Pero <n.pero@mi.flashnet.it>
* objc/objc-act.c (dump_interface): Enlarged the char * buffer to
1024 chars. Fixed category dumping - print out category names
with the proper syntax. Print '@end\n' and not '\n@end' at the
end of the interface.
(finish_objc): Fixed the -gen-decls option. It was printing out
only the last class. Dump an interface declaration of all classes
being compiled instead.
Index: objc-act.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-act.c,v
retrieving revision 1.154
diff -u -r1.154 objc-act.c
--- objc-act.c 27 Aug 2002 21:57:47 -0000 1.154
+++ objc-act.c 30 Aug 2002 00:30:58 -0000
@@ -7836,12 +7836,20 @@
/* Debug info. */
+/* Dump an @interface declaration of the supplied class CHAIN to the
+ supplied file FP. Used to implement the -gen-decls option (which
+ prints out an @interface declaration of all classes compiled in
+ this run); potentially useful for debugging the compiler too. */
static void
dump_interface (fp, chain)
FILE *fp;
tree chain;
{
- char *buf = (char *) xmalloc (256);
+ /* FIXME: A heap overflow here [!!] whenever a method (or ivar)
+ declaration is so long that it doesn't fit in the buffer. The
+ code and all the related functions should be rewritten to avoid
+ using fixed size buffers. */
+ char *buf = (char *) xmalloc (1024);
const char *my_name = IDENTIFIER_POINTER (CLASS_NAME (chain));
tree ivar_decls = CLASS_RAW_IVARS (chain);
tree nst_methods = CLASS_NST_METHODS (chain);
@@ -7849,14 +7857,26 @@
fprintf (fp, "\n@interface %s", my_name);
+ /* CLASS_SUPER_NAME is used to store the superclass name for
+ classes, and the category name for categories. */
if (CLASS_SUPER_NAME (chain))
{
- const char *super_name = IDENTIFIER_POINTER (CLASS_SUPER_NAME (chain));
- fprintf (fp, " : %s\n", super_name);
+ const char *name = IDENTIFIER_POINTER (CLASS_SUPER_NAME (chain));
+
+ if (TREE_CODE (chain) == CATEGORY_IMPLEMENTATION_TYPE
+ || TREE_CODE (chain) == CATEGORY_INTERFACE_TYPE)
+ {
+ fprintf (fp, " (%s)\n", name);
+ }
+ else
+ {
+ fprintf (fp, " : %s\n", name);
+ }
}
else
fprintf (fp, "\n");
+ /* FIXME - the following doesn't seem to work at the moment. */
if (ivar_decls)
{
fprintf (fp, "{\n");
@@ -7880,7 +7900,7 @@
fprintf (fp, "+ %s;\n", gen_method_decl (cls_methods, buf));
cls_methods = TREE_CHAIN (cls_methods);
}
- fprintf (fp, "\n@end");
+ fprintf (fp, "@end\n");
}
/* Demangle function for Objective-C */
@@ -8001,6 +8021,15 @@
UOBJC_CLASS_decl = impent->class_decl;
UOBJC_METACLASS_decl = impent->meta_decl;
+ /* Dump the @interface of each class as we compile it, if the
+ -gen-decls option is in use. TODO: Dump the classes in the
+ order they were found, rather than in reverse order as we
+ are doing now. */
+ if (flag_gen_declaration)
+ {
+ dump_interface (gen_declaration_file, objc_implementation_context);
+ }
+
if (TREE_CODE (objc_implementation_context) == CLASS_IMPLEMENTATION_TYPE)
{
/* all of the following reference the string pool... */
@@ -8031,7 +8060,7 @@
if (init_sym && targetm.have_ctors_dtors)
(* targetm.asm_out.constructor) (init_sym, DEFAULT_INIT_PRIORITY);
}
-
+
/* Dump the class references. This forces the appropriate classes
to be linked into the executable image, preserving unix archive
semantics. This can be removed when we move to a more dynamically
@@ -8050,12 +8079,6 @@
/* Dump the string table last. */
generate_strings ();
-
- if (flag_gen_declaration)
- {
- add_class (objc_implementation_context);
- dump_interface (gen_declaration_file, objc_implementation_context);
- }
if (warn_selector)
{