]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fixed bugs in the ObjC -gen-decls option
authorNicola Pero <n.pero@mi.flashnet.it>
Fri, 6 Sep 2002 15:25:35 +0000 (17:25 +0200)
committerNicola Pero <nicola@gcc.gnu.org>
Fri, 6 Sep 2002 15:25:35 +0000 (15:25 +0000)
From-SVN: r56884

gcc/ChangeLog
gcc/objc/objc-act.c

index 815e75ba14054593f7a36ad5aa1c916dfc0f715c..b7bbfa1b413563e995f67b1216e46bbcd28e2fd5 100644 (file)
@@ -1,3 +1,13 @@
+Fri Sep  6 16:17:33 2002  Nicola Pero  <n.pero@mi.flashnet.it>
+
+       * objc/objc-act.c (dump_interface): Enlarged the char * buffer to
+       10k.  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.
+
 2002-09-06  Jason Thorpe  <thorpej@wasabisystems.com>
 
        * config/arm/arm-protos.h (arm_gen_return_addr_mask): New 
index cba9ddea8a3d16aa6497e0341a719a8710d1a4c7..a9e02d9585be4c67747d7fb6b2ed2929b73f8a5e 100644 (file)
@@ -7836,12 +7836,21 @@ gen_method_decl (method, buf)
 \f
 /* 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 * 10);
   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 +7858,26 @@ dump_interface (fp, chain)
 
   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 +7901,8 @@ dump_interface (fp, chain)
       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 */
@@ -8000,7 +8022,16 @@ finish_objc ()
 
       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...  */
@@ -8051,12 +8082,6 @@ finish_objc ()
 
   generate_strings ();
 
-  if (flag_gen_declaration)
-    {
-      add_class (objc_implementation_context);
-      dump_interface (gen_declaration_file, objc_implementation_context);
-    }
-
   if (warn_selector)
     {
       int slot;