OSDN Git Service

1999-02-09 Andrew Haley <aph@cygnus.com>
[pf3gnuchains/gcc-fork.git] / gcc / java / class.c
index dedff9e..6d748a4 100644 (file)
@@ -1,5 +1,5 @@
 /* Functions related to building classes and their related objects.
-   Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1996, 97-98, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -33,6 +33,8 @@ The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 #include "jcf.h"
 #include "obstack.h"
 #include "toplev.h"
+#include "output.h"
+#include "parse.h"
 
 static tree mangle_class_field PROTO ((tree class));
 
@@ -95,13 +97,13 @@ identifier_subst (old_id, prefix, old_char, new_char, suffix)
 
 tree
 mangled_classname (prefix, type)
-     char *prefix;
-     tree type;
+  const char *prefix;
+  tree type;
 {
   tree ident = TYPE_NAME (type);
   if (TREE_CODE (ident) != IDENTIFIER_NODE)
     ident = DECL_NAME (ident);
-  return identifier_subst (ident, prefix, '/', '_', "");
+  return identifier_subst (ident, prefix, '.', '_', "");
 }
 
 tree
@@ -354,6 +356,7 @@ add_interface (this_class, interface_class)
   add_interface_do (basetype_vec, interface_class, i);
 }
 
+#if 0
 /* Return the address of a pointer to the first FUNCTION_DECL
    in the list (*LIST) whose DECL_NAME is NAME. */
 
@@ -366,6 +369,7 @@ find_named_method (list, name)
     list = &TREE_CHAIN (*list);
   return list;
 }
+#endif
 
 tree
 build_java_method_type (fntype, this_class, access_flags)
@@ -566,10 +570,10 @@ build_utf8_ref (name)
   buf_ptr = &buf[strlen (buf)];
   while (--name_len >= 0)
     {
-      char c = *name_ptr++;
+      unsigned char c = *name_ptr++;
       if (c & 0x80)
        continue;
-      if (!isalpha(c) && !isdigit(c))
+      if (!ISALPHA(c) && !ISDIGIT(c))
        c = '_';
       *buf_ptr++ = c;
       if (buf_ptr >= buf + 50)
@@ -637,6 +641,34 @@ build_class_ref (type)
        {
          char *name;
          char buffer[25];
+         if (flag_emit_class_files)
+           {
+             const char *prim_class_name;
+             tree prim_class;
+             if (type == char_type_node)
+               prim_class_name = "java.lang.Character";
+             else if (type == boolean_type_node)
+               prim_class_name = "java.lang.Boolean";
+             else if (type == byte_type_node)
+               prim_class_name = "java.lang.Byte";
+             else if (type == short_type_node)
+               prim_class_name = "java.lang.Short";
+             else if (type == int_type_node)
+               prim_class_name = "java.lang.Integer";
+             else if (type == long_type_node)
+               prim_class_name = "java.lang.Long";
+             else if (type == float_type_node)
+                prim_class_name = "java.lang.Float";
+             else if (type == double_type_node)
+                prim_class_name = "java.lang.Double";
+             else if (type == void_type_node)
+                prim_class_name = "java.lang.Void";
+             else
+               fatal ("internal error - bad type to build_class_ref");
+             prim_class = lookup_class (get_identifier (prim_class_name));
+             return build (COMPONENT_REF, NULL_TREE,
+                           prim_class, TYPE_identifier_node);
+           }
          decl_name = TYPE_NAME (type);
          if (TREE_CODE (decl_name) == TYPE_DECL)
            decl_name = DECL_NAME (decl_name);
@@ -808,7 +840,12 @@ make_field_value (tree fdecl)
   if (resolved)
     type = build_class_ref (type);
   else
-    type = build_utf8_ref (build_java_signature (type));
+    {
+      tree signature = build_java_signature (type);
+      type = build_utf8_ref (unmangle_classname 
+                            (IDENTIFIER_POINTER(signature),
+                             IDENTIFIER_LENGTH(signature)));
+    }
   PUSH_FIELD_VALUE (finit, "type", type);
   flags = get_access_flags_from_decl (fdecl);
   if (! resolved)
@@ -854,8 +891,14 @@ make_method_value (mdecl, this_class_addr)
                    build_utf8_ref (DECL_CONSTRUCTOR_P (mdecl) ?
                                    init_identifier_node
                                    : DECL_NAME (mdecl)));
-  PUSH_FIELD_VALUE (minit, "signature",
-                   build_utf8_ref (build_java_signature (TREE_TYPE (mdecl))));
+  {
+    tree signature = build_java_signature (TREE_TYPE (mdecl));
+    PUSH_FIELD_VALUE (minit, "signature", 
+                     (build_utf8_ref 
+                      (unmangle_classname 
+                       (IDENTIFIER_POINTER(signature),
+                        IDENTIFIER_LENGTH(signature)))));
+  }
   PUSH_FIELD_VALUE (minit, "accflags", build_int_2 (accflags, 0));
   PUSH_FIELD_VALUE (minit, "ncode", code);
   FINISH_RECORD_CONSTRUCTOR (minit);
@@ -1078,9 +1121,9 @@ make_class_data (type)
 
   START_RECORD_CONSTRUCTOR (temp, object_type_node);
 #if 0
-  PUSH_FIELD_VALUE (temp, "dtable", NULL_TREE);
+  PUSH_FIELD_VALUE (temp, "vtable", NULL_TREE);
 #else
-  PUSH_FIELD_VALUE (temp, "dtable",
+  PUSH_FIELD_VALUE (temp, "vtable",
                    build1 (ADDR_EXPR, dtable_ptr_type, class_dtable_decl));
 #endif
   PUSH_FIELD_VALUE (temp, "sync_info", null_pointer_node);
@@ -1088,22 +1131,17 @@ make_class_data (type)
   START_RECORD_CONSTRUCTOR (cons, class_type_node);
   PUSH_SUPER_VALUE (cons, temp);
   PUSH_FIELD_VALUE (cons, "next", null_pointer_node);
-#if 0
-  /* Need to fix _Jv_FindClassFromSignature. */
   PUSH_FIELD_VALUE (cons, "name", build_utf8_ref (DECL_NAME (type_decl)));
-#else
-  PUSH_FIELD_VALUE (cons, "name",
-                   build_utf8_ref (build_internal_class_name (type)));
-#endif
   PUSH_FIELD_VALUE (cons, "accflags",
                    build_int_2 (get_access_flags_from_decl (type_decl), 0));
 
-  PUSH_FIELD_VALUE (cons, "superclass", super);
+  PUSH_FIELD_VALUE (cons, "superclass", 
+                   CLASS_INTERFACE (type_decl) ? null_pointer_node : super);
   PUSH_FIELD_VALUE (cons, "constants", constant_pool_constructor);
   PUSH_FIELD_VALUE (cons, "methods",
                    build1 (ADDR_EXPR, method_ptr_type_node, methods_decl));
   PUSH_FIELD_VALUE (cons, "method_count",  build_int_2 (method_count, 0));
-  PUSH_FIELD_VALUE (cons, "dtable_method_count", TYPE_NVIRTUALS (type));
+  PUSH_FIELD_VALUE (cons, "vtable_method_count", TYPE_NVIRTUALS (type));
   PUSH_FIELD_VALUE (cons, "fields",
                    fields_decl == NULL_TREE ? null_pointer_node
                    : build1 (ADDR_EXPR, field_ptr_type_node, fields_decl));
@@ -1111,7 +1149,7 @@ make_class_data (type)
   PUSH_FIELD_VALUE (cons, "field_count", build_int_2 (field_count, 0));
   PUSH_FIELD_VALUE (cons, "static_field_count",
                    build_int_2 (static_field_count, 0));
-  PUSH_FIELD_VALUE (cons, "dtable",
+  PUSH_FIELD_VALUE (cons, "vtable",
                    dtable_decl == NULL_TREE ? null_pointer_node
                    : build1 (ADDR_EXPR, dtable_ptr_type, dtable_decl));
   PUSH_FIELD_VALUE (cons, "interfaces", interfaces);
@@ -1383,7 +1421,7 @@ maybe_layout_super_class (super_class)
       load_class (name, 1);
       super_class = IDENTIFIER_CLASS_VALUE (name);
       if (!super_class)
-           return;
+       return NULL_TREE;       /* FIXME, NULL_TREE not checked by caller. */
       super_class = TREE_TYPE (super_class);
     }
   if (!TYPE_SIZE (super_class))
@@ -1471,7 +1509,6 @@ layout_class_method (this_class, super_class, method_decl, dtable_count)
      tree this_class, super_class, method_decl, dtable_count;
 {
   char *ptr;
-  char buf[8];
   char *asm_name;
   tree arg, arglist, t;
   int method_name_needs_escapes = 0;
@@ -1578,6 +1615,7 @@ layout_class_method (this_class, super_class, method_decl, dtable_count)
       else
        DECL_NAME (method_decl) = get_identifier (p);
       DECL_CONSTRUCTOR_P (method_decl) = 1;
+      build_java_argument_signature (TREE_TYPE (method_decl));
     }
   else if (! METHOD_STATIC (method_decl) && !DECL_ARTIFICIAL (method_decl))
     {