1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Written by Per Bothner <bothner@cygnus.com> */
31 #include "java-tree.h"
36 static tree mangle_class_field
PROTO ((tree
class));
38 static rtx registerClass_libfunc
;
40 extern struct obstack permanent_obstack
;
41 extern struct obstack temporary_obstack
;
43 /* Return an IDENTIFIER_NODE the same as (OLD_NAME, OLD_LENGTH).
44 except that characters matching OLD_CHAR are substituted by NEW_CHAR.
45 Also, PREFIX is prepended, and SUFFIX is appended. */
48 ident_subst (old_name
, old_length
, prefix
, old_char
, new_char
, suffix
)
56 int prefix_len
= strlen (prefix
);
57 int suffix_len
= strlen (suffix
);
58 int i
= prefix_len
+ old_length
+ suffix_len
+ 1;
62 char *buffer
= (char *)alloca (i
);
64 strcpy (buffer
, prefix
);
65 for (i
= 0; i
< old_length
; i
++)
67 char ch
= old_name
[i
];
70 buffer
[prefix_len
+ i
] = ch
;
72 strcpy (buffer
+ prefix_len
+ old_length
, suffix
);
73 return get_identifier (buffer
);
76 /* Return an IDENTIFIER_NODE the same as OLD_ID,
77 except that characters matching OLD_CHAR are substituted by NEW_CHAR.
78 Also, PREFIX is prepended, and SUFFIX is appended. */
81 identifier_subst (old_id
, prefix
, old_char
, new_char
, suffix
)
88 return ident_subst (IDENTIFIER_POINTER (old_id
), IDENTIFIER_LENGTH (old_id
),
89 prefix
, old_char
, new_char
, suffix
);
92 /* Generate a valid C identifier from the name of the class TYPE,
93 prefixed by PREFIX. */
96 mangled_classname (prefix
, type
)
100 tree ident
= TYPE_NAME (type
);
101 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
102 ident
= DECL_NAME (ident
);
103 return identifier_subst (ident
, prefix
, '/', '_', "");
110 push_obstacks (&permanent_obstack
, &permanent_obstack
);
111 type
= make_node (RECORD_TYPE
);
112 #ifdef JAVA_USE_HANDLES
113 tree field1
= build_decl (FIELD_DECL
, get_identifier ("obj"),
114 build_pointer_type (type
));
115 tree field2
= build_decl (FIELD_DECL
, get_identifier ("methods"),
116 methodtable_ptr_type
);
117 tree handle_type
= make_node (RECORD_TYPE
);
118 TREE_CHAIN (field1
) = field2
;
119 TYPE_FIELDS (handle_type
) = field1
;
120 TYPE_BINFO (type
) = make_tree_vec (7);
121 TYPE_BINFO (handle_type
) = make_tree_vec (7);
122 BINFO_HANDLE (TYPE_BINFO (handle_type
)) = type
;
123 BINFO_HANDLE (TYPE_BINFO (type
)) = handle_type
;
125 TYPE_BINFO (type
) = make_tree_vec (6);
133 /* Given a fully-qualified classname in NAME (whose length is NAME_LENGTH),
134 and where each of the constituents is separated by '/',
135 return a corresponding IDENTIFIER_NODE, except using '.' as separator. */
138 unmangle_classname (name
, name_length
)
139 const char *name
; int name_length
;
141 return ident_subst (name
, name_length
, "", '/', '.', "");
145 push_class (class_type
, class_name
)
146 tree class_type
, class_name
;
148 tree decl
, signature
;
149 char *save_input_filename
= input_filename
;
150 int save_lineno
= lineno
;
151 tree source_name
= identifier_subst (class_name
, "", '.', '/', ".java");
152 push_obstacks (&permanent_obstack
, &permanent_obstack
);
153 input_filename
= IDENTIFIER_POINTER (source_name
);
155 decl
= build_decl (TYPE_DECL
, class_name
, class_type
);
156 input_filename
= save_input_filename
;
157 lineno
= save_lineno
;
158 signature
= identifier_subst (class_name
, "L", '.', '/', ";");
159 IDENTIFIER_SIGNATURE_TYPE (signature
) = build_pointer_type (class_type
);
161 /* Setting DECL_ARTIFICAL forces dbxout.c to specific the type is
162 both a typedef and in the struct name-space. We may want to re-visit
163 this later, but for now it reduces the changes needed for gdb. */
164 DECL_ARTIFICIAL (decl
) = 1;
166 pushdecl_top_level (decl
);
167 #ifdef JAVA_USE_HANDLES
169 tree handle_name
= identifier_subst (class_name
,
170 "Handle$", '.', '.', "");
171 tree handle_decl
= build_decl (TYPE_DECL
, handle_name
,
172 CLASS_TO_HANDLE_TYPE (class_type
));
173 pushdecl (handle_decl
);
181 /* Finds the (global) class named NAME. Creates the class if not found.
182 Also creates associated TYPE_DECL.
183 Does not check if the class actually exists, load the class,
184 fill in field or methods, or do layout_type. */
190 tree decl
= IDENTIFIER_CLASS_VALUE (name
);
191 if (decl
== NULL_TREE
)
192 decl
= push_class (make_class (), name
);
193 return TREE_TYPE (decl
);
197 set_super_info (access_flags
, this_class
, super_class
, interfaces_count
)
201 int interfaces_count
;
203 int total_supers
= interfaces_count
;
204 tree class_decl
= TYPE_NAME (this_class
);
208 push_obstacks (&permanent_obstack
, &permanent_obstack
);
209 TYPE_BINFO_BASETYPES (this_class
) = make_tree_vec (total_supers
);
212 tree super_binfo
= make_tree_vec (6);
213 BINFO_TYPE (super_binfo
) = super_class
;
214 BINFO_OFFSET (super_binfo
) = integer_zero_node
;
215 TREE_VIA_PUBLIC (super_binfo
) = 1;
216 TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (this_class
)), 0)
218 CLASS_HAS_SUPER (this_class
) = 1;
222 if (access_flags
& ACC_PUBLIC
) CLASS_PUBLIC (class_decl
) = 1;
223 if (access_flags
& ACC_FINAL
) CLASS_FINAL (class_decl
) = 1;
224 if (access_flags
& ACC_SUPER
) CLASS_SUPER (class_decl
) = 1;
225 if (access_flags
& ACC_INTERFACE
) CLASS_INTERFACE (class_decl
) = 1;
226 if (access_flags
& ACC_ABSTRACT
) CLASS_ABSTRACT (class_decl
) = 1;
229 /* Return length of inheritance chain of CLAS, where java.lang.Object is 0,
230 direct sub-classes of Object are 1, and so on. */
237 if (! CLASS_LOADED_P (clas
))
238 load_class (clas
, 1);
239 while (clas
!= object_type_node
)
242 clas
= TYPE_BINFO_BASETYPE (clas
, 0);
247 /* Return true iff TYPE2 is an interface that extends interface TYPE1 */
250 interface_of_p (type1
, type2
)
256 if (!(basetype_vec
= TYPE_BINFO_BASETYPES (type2
)))
258 n
= TREE_VEC_LENGTH (basetype_vec
);
259 for (i
= 0; i
< n
; i
++)
261 tree vec_elt
= TREE_VEC_ELT (basetype_vec
, i
);
262 if (vec_elt
&& BINFO_TYPE (vec_elt
) == type1
)
265 for (i
= 0; i
< n
; i
++)
267 tree vec_elt
= TREE_VEC_ELT (basetype_vec
, i
);
268 if (vec_elt
&& BINFO_TYPE (vec_elt
)
269 && interface_of_p (type1
, BINFO_TYPE (vec_elt
)))
275 /* Return true iff TYPE1 inherits from TYPE2. */
278 inherits_from_p (type1
, type2
)
281 while (type1
!= NULL_TREE
&& TREE_CODE (type1
) == RECORD_TYPE
)
285 type1
= CLASSTYPE_SUPER (type1
);
291 add_interface_do (basetype_vec
, interface_class
, i
)
292 tree basetype_vec
, interface_class
;
295 tree interface_binfo
= make_tree_vec (6);
296 BINFO_TYPE (interface_binfo
) = interface_class
;
297 BINFO_OFFSET (interface_binfo
) = integer_zero_node
;
298 TREE_VIA_VIRTUAL (interface_binfo
) = 1;
299 TREE_VIA_PUBLIC (interface_binfo
) = 1;
300 TREE_VEC_ELT (basetype_vec
, i
) = interface_binfo
;
303 /* Add INTERFACE_CLASS to THIS_CLASS iff INTERFACE_CLASS can't be
304 found in THIS_CLASS. Returns NULL_TREE upon success, INTERFACE_CLASS
305 if attempt is made to add it twice. */
308 maybe_add_interface (this_class
, interface_class
)
309 tree this_class
, interface_class
;
311 tree basetype_vec
= TYPE_BINFO_BASETYPES (this_class
);
312 tree interface_binfo
= make_tree_vec (6);
314 int n
= TREE_VEC_LENGTH (basetype_vec
);
319 error ("internal error - too many interface type");
322 else if (TREE_VEC_ELT (basetype_vec
, i
) == NULL_TREE
)
324 else if (BINFO_TYPE (TREE_VEC_ELT (basetype_vec
, i
)) == interface_class
)
325 return interface_class
;
327 add_interface_do (basetype_vec
, interface_class
, i
);
331 /* Add the INTERFACE_CLASS as one of the interfaces of THIS_CLASS. */
334 add_interface (this_class
, interface_class
)
335 tree this_class
, interface_class
;
337 tree basetype_vec
= TYPE_BINFO_BASETYPES (this_class
);
339 int n
= TREE_VEC_LENGTH (basetype_vec
);
344 error ("internal error - too many interface type");
347 else if (TREE_VEC_ELT (basetype_vec
, i
) == NULL_TREE
)
350 add_interface_do (basetype_vec
, interface_class
, i
);
353 /* Return the address of a pointer to the first FUNCTION_DECL
354 in the list (*LIST) whose DECL_NAME is NAME. */
357 find_named_method (list
, name
)
361 while (*list
&& DECL_NAME (*list
) != name
)
362 list
= &TREE_CHAIN (*list
);
367 build_java_method_type (fntype
, this_class
, access_flags
)
372 if (access_flags
& ACC_STATIC
)
374 return build_method_type (CLASS_TO_HANDLE_TYPE (this_class
), fntype
);
378 add_method_1 (handle_class
, access_flags
, name
, function_type
)
384 tree method_type
, fndecl
;
385 push_obstacks (&permanent_obstack
, &permanent_obstack
);
387 method_type
= build_java_method_type (function_type
,
388 handle_class
, access_flags
);
390 fndecl
= build_decl (FUNCTION_DECL
, name
, method_type
);
391 DECL_CONTEXT (fndecl
) = handle_class
;
393 DECL_LANG_SPECIFIC (fndecl
)
394 = (struct lang_decl
*) permalloc (sizeof (struct lang_decl
));
395 bzero (DECL_LANG_SPECIFIC (fndecl
), sizeof (struct lang_decl
));
397 TREE_CHAIN (fndecl
) = TYPE_METHODS (handle_class
);
398 TYPE_METHODS (handle_class
) = fndecl
;
401 if (access_flags
& ACC_PUBLIC
) METHOD_PUBLIC (fndecl
) = 1;
402 if (access_flags
& ACC_PROTECTED
) METHOD_PROTECTED (fndecl
) = 1;
403 if (access_flags
& ACC_PRIVATE
) METHOD_PRIVATE (fndecl
) = 1;
404 if (access_flags
& ACC_NATIVE
) METHOD_NATIVE (fndecl
) = 1;
405 if (access_flags
& ACC_STATIC
) METHOD_STATIC (fndecl
) = 1;
406 if (access_flags
& ACC_FINAL
) METHOD_FINAL (fndecl
) = 1;
407 if (access_flags
& ACC_SYNCHRONIZED
) METHOD_SYNCHRONIZED (fndecl
) = 1;
408 if (access_flags
& ACC_ABSTRACT
) METHOD_ABSTRACT (fndecl
) = 1;
409 if (access_flags
& ACC_TRANSIENT
) METHOD_TRANSIENT (fndecl
) = 1;
413 /* Add a method to THIS_CLASS.
414 The method's name is NAME.
415 Its signature (mangled type) is METHOD_SIG (an IDENTIFIER_NODE). */
418 add_method (this_class
, access_flags
, name
, method_sig
)
424 tree handle_class
= CLASS_TO_HANDLE_TYPE (this_class
);
425 tree function_type
, method_type
, fndecl
;
426 unsigned char *sig
= (unsigned char*)IDENTIFIER_POINTER (method_sig
);
427 push_obstacks (&permanent_obstack
, &permanent_obstack
);
429 fatal ("bad method signature");
430 function_type
= get_type_from_signature (method_sig
);
431 fndecl
= add_method_1 (handle_class
, access_flags
, name
, function_type
);
432 set_java_signature (TREE_TYPE (fndecl
), method_sig
);
438 add_field (class, name
, field_type
, flags
)
444 int is_static
= (flags
& ACC_STATIC
) != 0;
446 /* Push the obstack of field_type ? FIXME */
447 push_obstacks (&permanent_obstack
, &permanent_obstack
);
448 field
= build_decl (is_static
? VAR_DECL
: FIELD_DECL
, name
, field_type
);
450 TREE_CHAIN (field
) = TYPE_FIELDS (class);
451 TYPE_FIELDS (class) = field
;
452 DECL_CONTEXT (field
) = class;
454 if (flags
& ACC_PUBLIC
) FIELD_PUBLIC (field
) = 1;
455 if (flags
& ACC_PROTECTED
) FIELD_PROTECTED (field
) = 1;
456 if (flags
& ACC_PRIVATE
) FIELD_PRIVATE (field
) = 1;
457 if (flags
& ACC_FINAL
) FIELD_FINAL (field
) = 1;
458 if (flags
& ACC_VOLATILE
) FIELD_VOLATILE (field
) = 1;
459 if (flags
& ACC_TRANSIENT
) FIELD_TRANSIENT (field
) = 1;
462 FIELD_STATIC (field
) = 1;
463 /* Always make field externally visible. This is required so
464 that native methods can always access the field. */
465 TREE_PUBLIC (field
) = 1;
470 /* Associate a constant value CONSTANT with VAR_DECL FIELD. */
473 set_constant_value (field
, constant
)
474 tree field
, constant
;
476 if (field
== NULL_TREE
)
477 warning ("misplaced ConstantValue attribute (not in any field)");
478 else if (DECL_INITIAL (field
) != NULL_TREE
)
479 warning ("duplicate ConstanValue atribute for field '%s'",
480 IDENTIFIER_POINTER (DECL_NAME (field
)));
482 DECL_INITIAL (field
) = constant
;
485 /* Count the number of Unicode chars encoded in a given Ut8 string. */
488 strLengthUtf8 (str
, len
)
492 register unsigned char* ptr
= (unsigned char*) str
;
493 register unsigned char *limit
= ptr
+ len
;
495 for (; ptr
< limit
; str_length
++) {
496 if (UTF8_GET (ptr
, limit
) < 0)
503 /* Calculate a hash value for a string encoded in Utf8 format.
504 * This returns the same hash value as specified for java.lang.String.hashCode.
508 hashUtf8String (str
, len
)
512 register unsigned char* ptr
= (unsigned char*) str
;
513 register unsigned char *limit
= ptr
+ len
;
517 int ch
= UTF8_GET (ptr
, limit
);
518 /* Updated specification from
519 http://www.javasoft.com/docs/books/jls/clarify.html. */
520 hash
= (31 * hash
) + ch
;
525 tree utf8_decl_list
= NULL_TREE
;
528 build_utf8_ref (name
)
531 char* name_ptr
= IDENTIFIER_POINTER(name
);
532 int name_len
= IDENTIFIER_LENGTH(name
);
535 tree ctype
, field
, str_type
, cinit
, string
;
536 static int utf8_count
= 0;
538 tree ref
= IDENTIFIER_UTF8_REF (name
);
540 if (ref
!= NULL_TREE
)
543 push_obstacks (&permanent_obstack
, &permanent_obstack
);
544 ctype
= make_node (RECORD_TYPE
);
545 str_type
= build_prim_array_type (unsigned_byte_type_node
,
546 name_len
+ 1); /* Allow for final '\0'. */
547 PUSH_FIELD (ctype
, field
, "hash", unsigned_short_type_node
);
548 PUSH_FIELD (ctype
, field
, "length", unsigned_short_type_node
);
549 PUSH_FIELD (ctype
, field
, "data", str_type
);
550 FINISH_RECORD (ctype
);
551 START_RECORD_CONSTRUCTOR (cinit
, ctype
);
552 name_hash
= hashUtf8String (name_ptr
, name_len
) & 0xFFFF;
553 PUSH_FIELD_VALUE (cinit
, "hash", build_int_2 (name_hash
, 0));
554 PUSH_FIELD_VALUE (cinit
, "length", build_int_2 (name_len
, 0));
555 string
= build_string (name_len
, name_ptr
);
556 TREE_TYPE (string
) = str_type
;
557 PUSH_FIELD_VALUE (cinit
, "data", string
);
558 FINISH_RECORD_CONSTRUCTOR (cinit
);
560 /* Build a unique identifier based on buf. */
561 sprintf(buf
, "_Utf%d", ++utf8_count
);
562 buf_ptr
= &buf
[strlen (buf
)];
563 while (--name_len
>= 0)
565 char c
= *name_ptr
++;
568 if (!isalpha(c
) && !isdigit(c
))
571 if (buf_ptr
>= buf
+ 50)
576 decl
= build_decl (VAR_DECL
, get_identifier (buf
), utf8const_type
);
577 /* FIXME get some way to force this into .text, not .data. */
578 TREE_STATIC (decl
) = 1;
579 DECL_ARTIFICIAL (decl
) = 1;
580 DECL_IGNORED_P (decl
) = 1;
581 TREE_READONLY (decl
) = 1;
582 DECL_INITIAL (decl
) = cinit
;
583 TREE_CHAIN (decl
) = utf8_decl_list
;
584 layout_decl (decl
, 0);
586 rest_of_decl_compilation (decl
, (char*) 0, global_bindings_p (), 0);
587 utf8_decl_list
= decl
;
588 make_decl_rtl (decl
, (char*) 0, 1);
589 ref
= build1 (ADDR_EXPR
, utf8const_ptr_type
, decl
);
590 IDENTIFIER_UTF8_REF (name
) = ref
;
595 /* Build a reference to the class TYPE.
596 Also handles primitive types and array types. */
599 build_class_ref (type
)
602 int is_compiled
= is_compiled_class (type
);
605 tree ref
, decl_name
, decl
;
606 if (TREE_CODE (type
) == POINTER_TYPE
)
607 type
= TREE_TYPE (type
);
608 if (TREE_CODE (type
) == RECORD_TYPE
)
610 if (TYPE_SIZE (type
) == error_mark_node
)
611 return null_pointer_node
;
612 decl_name
= identifier_subst (DECL_NAME (TYPE_NAME (type
)),
613 "", '/', '/', ".class");
614 decl
= IDENTIFIER_GLOBAL_VALUE (decl_name
);
615 if (decl
== NULL_TREE
)
617 push_obstacks (&permanent_obstack
, &permanent_obstack
);
618 decl
= build_decl (VAR_DECL
, decl_name
, class_type_node
);
619 DECL_SIZE (decl
) = TYPE_SIZE (class_type_node
);
620 TREE_STATIC (decl
) = 1;
621 TREE_PUBLIC (decl
) = 1;
622 DECL_IGNORED_P (decl
) = 1;
623 DECL_ARTIFICIAL (decl
) = 1;
624 DECL_ASSEMBLER_NAME (decl
) = mangle_class_field (type
);
625 make_decl_rtl (decl
, NULL
, 1);
626 pushdecl_top_level (decl
);
627 if (is_compiled
== 1)
628 DECL_EXTERNAL (decl
) = 1;
636 decl_name
= TYPE_NAME (type
);
637 if (TREE_CODE (decl_name
) == TYPE_DECL
)
638 decl_name
= DECL_NAME (decl_name
);
639 name
= IDENTIFIER_POINTER (decl_name
);
640 if (strncmp (name
, "promoted_", 9) == 0)
642 sprintf (buffer
, "%sClass", name
);
643 decl_name
= get_identifier (buffer
);
644 decl
= IDENTIFIER_GLOBAL_VALUE (decl_name
);
645 if (decl
== NULL_TREE
)
647 push_obstacks (&permanent_obstack
, &permanent_obstack
);
648 decl
= build_decl (VAR_DECL
, decl_name
, class_type_node
);
649 TREE_STATIC (decl
) = 1;
650 TREE_PUBLIC (decl
) = 1;
651 make_decl_rtl (decl
, NULL
, 1);
652 pushdecl_top_level (decl
);
653 if (is_compiled
== 1)
654 DECL_EXTERNAL (decl
) = 1;
659 ref
= build1 (ADDR_EXPR
, class_ptr_type
, decl
);
666 push_obstacks (&permanent_obstack
, &permanent_obstack
);
667 index
= alloc_class_constant (type
);
668 cl
= build_ref_from_constant_pool (index
);
669 TREE_TYPE (cl
) = promote_type (class_ptr_type
);
676 build_static_field_ref (fdecl
)
679 tree fclass
= DECL_CONTEXT (fdecl
);
680 int is_compiled
= is_compiled_class (fclass
);
683 if (DECL_RTL (fdecl
) == 0)
685 push_obstacks (&permanent_obstack
, &permanent_obstack
);
686 make_decl_rtl (fdecl
, NULL
, 1);
688 if (is_compiled
== 1)
689 DECL_EXTERNAL (fdecl
) = 1;
696 * *(FTYPE*)build_class_ref(FCLASS)->fields[INDEX].info.addr
698 static tree fields_ident
= NULL_TREE
;
699 static tree info_ident
= NULL_TREE
;
700 tree ref
= build_class_ref (fclass
);
703 ref
= build1 (INDIRECT_REF
, class_type_node
, ref
);
704 if (fields_ident
== NULL_TREE
)
705 fields_ident
= get_identifier ("fields");
706 if (info_ident
== NULL_TREE
)
707 info_ident
= get_identifier ("info");
708 ref
= build (COMPONENT_REF
, field_ptr_type_node
, ref
,
709 lookup_field (&class_type_node
, fields_ident
));
711 for (fld
= TYPE_FIELDS (fclass
); ; fld
= TREE_CHAIN (fld
))
715 if (fld
== NULL_TREE
)
716 fatal ("field '%s' not found in class",
717 IDENTIFIER_POINTER (DECL_NAME (fdecl
)));
718 if (FIELD_STATIC (fld
))
721 field_index
*= int_size_in_bytes (field_type_node
);
722 ref
= fold (build (PLUS_EXPR
, field_ptr_type_node
,
723 ref
, build_int_2 (field_index
, 0)));
724 ref
= build1 (INDIRECT_REF
, field_type_node
, ref
);
725 ref
= build (COMPONENT_REF
, field_info_union_node
,
726 ref
, lookup_field (&field_type_node
, info_ident
));
727 ref
= build (COMPONENT_REF
, ptr_type_node
,
728 ref
, TREE_CHAIN (TYPE_FIELDS (field_info_union_node
)));
729 return fold (build1 (INDIRECT_REF
, TREE_TYPE(fdecl
), ref
));
734 get_access_flags_from_decl (decl
)
737 int access_flags
= 0;
738 if (TREE_CODE (decl
) == FIELD_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
740 if (FIELD_STATIC (decl
))
741 access_flags
|= ACC_STATIC
;
742 if (FIELD_PUBLIC (decl
))
743 access_flags
|= ACC_PUBLIC
;
744 if (FIELD_PROTECTED (decl
))
745 access_flags
|= ACC_PROTECTED
;
746 if (FIELD_PRIVATE (decl
))
747 access_flags
|= ACC_PRIVATE
;
748 if (FIELD_FINAL (decl
))
749 access_flags
|= ACC_FINAL
;
750 if (FIELD_VOLATILE (decl
))
751 access_flags
|= ACC_VOLATILE
;
752 if (FIELD_TRANSIENT (decl
))
753 access_flags
|= ACC_TRANSIENT
;
756 if (TREE_CODE (decl
) == TYPE_DECL
)
758 if (CLASS_PUBLIC (decl
))
759 access_flags
|= ACC_PUBLIC
;
760 if (CLASS_FINAL (decl
))
761 access_flags
|= ACC_FINAL
;
762 if (CLASS_SUPER (decl
))
763 access_flags
|= ACC_SUPER
;
764 if (CLASS_INTERFACE (decl
))
765 access_flags
|= ACC_INTERFACE
;
766 if (CLASS_ABSTRACT (decl
))
767 access_flags
|= ACC_ABSTRACT
;
770 if (TREE_CODE (decl
) == FUNCTION_DECL
)
772 if (METHOD_PUBLIC (decl
))
773 access_flags
|= ACC_PUBLIC
;
774 if (METHOD_PRIVATE (decl
))
775 access_flags
|= ACC_PRIVATE
;
776 if (METHOD_PROTECTED (decl
))
777 access_flags
|= ACC_PROTECTED
;
778 if (METHOD_STATIC (decl
))
779 access_flags
|= ACC_STATIC
;
780 if (METHOD_FINAL (decl
))
781 access_flags
|= ACC_FINAL
;
782 if (METHOD_SYNCHRONIZED (decl
))
783 access_flags
|= ACC_SYNCHRONIZED
;
784 if (METHOD_NATIVE (decl
))
785 access_flags
|= ACC_NATIVE
;
786 if (METHOD_ABSTRACT (decl
))
787 access_flags
|= ACC_ABSTRACT
;
788 if (METHOD_TRANSIENT (decl
))
789 access_flags
|= ACC_TRANSIENT
;
796 make_field_value (tree fdecl
)
800 tree type
= TREE_TYPE (fdecl
);
801 int resolved
= is_compiled_class (type
);
802 START_RECORD_CONSTRUCTOR (finit
, field_type_node
);
803 PUSH_FIELD_VALUE (finit
, "name", build_utf8_ref (DECL_NAME (fdecl
)));
805 type
= build_class_ref (type
);
807 type
= build_utf8_ref (build_java_signature (type
));
808 PUSH_FIELD_VALUE (finit
, "type", type
);
809 flags
= get_access_flags_from_decl (fdecl
);
811 flags
|= 0x8000 /* FIELD_UNRESOLVED_FLAG */;
812 PUSH_FIELD_VALUE (finit
, "accflags", build_int_2 (flags
, 0));
813 bsize
= TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (fdecl
))) / BITS_PER_UNIT
;
814 PUSH_FIELD_VALUE (finit
, "bsize", build_int_2 (bsize
, 0));
815 if (FIELD_STATIC (fdecl
))
817 tree cfield
= TREE_CHAIN (TYPE_FIELDS(field_info_union_node
));
818 tree faddr
= build_address_of (build_static_field_ref (fdecl
));
819 info
= build (CONSTRUCTOR
, field_info_union_node
, NULL_TREE
,
820 build_tree_list (cfield
, faddr
));
825 = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (fdecl
)) / BITS_PER_UNIT
;
826 info
= build (CONSTRUCTOR
, field_info_union_node
, NULL_TREE
,
827 build_tree_list (TYPE_FIELDS(field_info_union_node
),
828 build_int_2 (boffset
, 0)));
830 PUSH_FIELD_VALUE (finit
, "info", info
);
832 FINISH_RECORD_CONSTRUCTOR (finit
);
837 make_method_value (mdecl
, this_class_addr
)
839 tree this_class_addr
;
843 #define ACC_TRANSLATED 0x4000
844 int accflags
= get_access_flags_from_decl (mdecl
) | ACC_TRANSLATED
;
845 code
= null_pointer_node
;
846 if (DECL_RTL (mdecl
))
847 code
= build1 (ADDR_EXPR
, nativecode_ptr_type_node
, mdecl
);
848 START_RECORD_CONSTRUCTOR (minit
, method_type_node
);
849 PUSH_FIELD_VALUE (minit
, "name",
850 build_utf8_ref (DECL_CONSTRUCTOR_P (mdecl
) ?
852 : DECL_NAME (mdecl
)));
853 PUSH_FIELD_VALUE (minit
, "signature",
854 build_utf8_ref (build_java_signature (TREE_TYPE (mdecl
))));
855 PUSH_FIELD_VALUE (minit
, "accflags", build_int_2 (accflags
, 0));
856 PUSH_FIELD_VALUE (minit
, "ncode", code
);
857 FINISH_RECORD_CONSTRUCTOR (minit
);
862 get_dispatch_vector (type
)
865 tree vtable
= TYPE_VTABLE (type
);
870 tree super
= CLASSTYPE_SUPER (type
);
871 int nvirtuals
= TREE_INT_CST_LOW (TYPE_NVIRTUALS (type
));
872 vtable
= make_tree_vec (nvirtuals
);
873 TYPE_VTABLE (type
) = vtable
;
874 if (super
!= NULL_TREE
)
876 tree super_vtable
= get_dispatch_vector (super
);
877 for ( i
= TREE_INT_CST_LOW (TYPE_NVIRTUALS (super
)); --i
>= 0; )
878 TREE_VEC_ELT (vtable
, i
) = TREE_VEC_ELT (super_vtable
, i
);
880 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
881 method
= TREE_CHAIN (method
))
883 if (DECL_VINDEX (method
) != NULL_TREE
884 && TREE_CODE (DECL_VINDEX (method
)) == INTEGER_CST
)
886 TREE_VEC_ELT (vtable
, TREE_INT_CST_LOW (DECL_VINDEX (method
)))
895 get_dispatch_table (type
, this_class_addr
)
896 tree type
, this_class_addr
;
898 tree vtable
= get_dispatch_vector (type
);
900 tree list
= NULL_TREE
;
901 int nvirtuals
= TREE_VEC_LENGTH (vtable
);
902 for (i
= nvirtuals
; --i
>= 0; )
904 tree method
= TREE_VEC_ELT (vtable
, i
);
905 if (METHOD_ABSTRACT (method
))
906 warning_with_decl (method
, "abstract method in non-abstract class");
907 if (DECL_RTL (method
) == 0)
908 make_decl_rtl (method
, NULL
, 1);
909 list
= tree_cons (NULL_TREE
/*DECL_VINDEX (method) + 2*/,
910 build1 (ADDR_EXPR
, nativecode_ptr_type_node
, method
),
913 /* Dummy entry for compatibility with G++ -fvtable-thunks. */
914 list
= tree_cons (integer_zero_node
, null_pointer_node
, list
);
915 list
= tree_cons (integer_zero_node
, this_class_addr
, list
);
916 return build (CONSTRUCTOR
, build_prim_array_type (nativecode_ptr_type_node
,
922 make_class_data (type
)
925 tree decl
, cons
, temp
;
926 tree field
, fields_decl
;
927 tree static_fields
= NULL_TREE
;
928 tree instance_fields
= NULL_TREE
;
929 HOST_WIDE_INT static_field_count
= 0;
930 HOST_WIDE_INT instance_field_count
= 0;
931 HOST_WIDE_INT field_count
;
932 tree field_array_type
;
934 tree methods
= NULL_TREE
;
935 tree dtable_decl
= NULL_TREE
;
936 HOST_WIDE_INT method_count
= 0;
937 tree method_array_type
;
940 tree this_class_addr
;
941 tree constant_pool_constructor
;
942 tree interfaces
= null_pointer_node
;
943 int interface_len
= 0;
944 tree type_decl
= TYPE_NAME (type
);
946 this_class_addr
= build_class_ref (type
);
947 decl
= TREE_OPERAND (this_class_addr
, 0);
949 /* Build Field array. */
950 field
= TYPE_FIELDS (type
);
951 if (DECL_NAME (field
) == NULL_TREE
)
952 field
= TREE_CHAIN (field
); /* Skip dummy field for inherited data. */
953 for ( ; field
!= NULL_TREE
; field
= TREE_CHAIN (field
))
955 if (! DECL_ARTIFICIAL (field
))
957 tree init
= make_field_value (field
);
958 if (FIELD_STATIC (field
))
960 static_field_count
++;
961 static_fields
= tree_cons (NULL_TREE
, init
, static_fields
);
962 rest_of_decl_compilation (field
, (char*) 0, 1, 1);
966 instance_field_count
++;
967 instance_fields
= tree_cons (NULL_TREE
, init
, instance_fields
);
971 field_count
= static_field_count
+ instance_field_count
;
974 static_fields
= nreverse (static_fields
);
975 instance_fields
= nreverse (instance_fields
);
976 static_fields
= chainon (static_fields
, instance_fields
);
977 field_array_type
= build_prim_array_type (field_type_node
, field_count
);
978 fields_decl
= build_decl (VAR_DECL
, mangled_classname ("_FL_", type
),
980 DECL_INITIAL (fields_decl
) = build (CONSTRUCTOR
, field_array_type
,
981 NULL_TREE
, static_fields
);
982 TREE_STATIC (fields_decl
) = 1;
983 DECL_ARTIFICIAL (fields_decl
) = 1;
984 DECL_IGNORED_P (fields_decl
) = 1;
985 rest_of_decl_compilation (fields_decl
, (char*) 0, 1, 0);
988 fields_decl
= NULL_TREE
;
990 /* Build Method array. */
991 for (method
= TYPE_METHODS (CLASS_TO_HANDLE_TYPE (type
));
992 method
!= NULL_TREE
; method
= TREE_CHAIN (method
))
994 tree init
= make_method_value (method
, this_class_addr
);
996 methods
= tree_cons (NULL_TREE
, init
, methods
);
998 method_array_type
= build_prim_array_type (method_type_node
, method_count
);
999 methods_decl
= build_decl (VAR_DECL
, mangled_classname ("_MT_", type
),
1001 DECL_INITIAL (methods_decl
) = build (CONSTRUCTOR
, method_array_type
,
1002 NULL_TREE
, nreverse (methods
));
1003 TREE_STATIC (methods_decl
) = 1;
1004 DECL_ARTIFICIAL (methods_decl
) = 1;
1005 DECL_IGNORED_P (methods_decl
) = 1;
1006 rest_of_decl_compilation (methods_decl
, (char*) 0, 1, 0);
1008 if (flag_assume_compiled
1009 && ! CLASS_ABSTRACT (type_decl
) && ! CLASS_INTERFACE (type_decl
))
1011 tree dtable
= get_dispatch_table (type
, this_class_addr
);
1012 dtable_decl
= build_dtable_decl (type
);
1013 DECL_INITIAL (dtable_decl
) = dtable
;
1014 TREE_STATIC (dtable_decl
) = 1;
1015 DECL_ARTIFICIAL (dtable_decl
) = 1;
1016 DECL_IGNORED_P (dtable_decl
) = 1;
1017 TREE_PUBLIC (dtable_decl
) = 1;
1018 rest_of_decl_compilation (dtable_decl
, (char*) 0, 1, 0);
1021 super
= CLASSTYPE_SUPER (type
);
1022 if (super
== NULL_TREE
)
1023 super
= null_pointer_node
;
1024 else if (flag_assume_compiled
)
1025 super
= build_class_ref (super
);
1028 int super_index
= alloc_class_constant (super
);
1029 super
= build_int_2 (super_index
, 0);
1030 TREE_TYPE (super
) == ptr_type_node
;
1033 /* Build and emit the array of implemented interfaces. */
1034 if (type
!= object_type_node
)
1035 interface_len
= TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) - 1;
1036 if (interface_len
> 0)
1038 tree init
= NULL_TREE
;
1040 tree interface_array_type
, idecl
;
1041 interface_array_type
1042 = build_prim_array_type (class_ptr_type
, interface_len
);
1043 idecl
= build_decl (VAR_DECL
, mangled_classname ("_IF_", type
),
1044 interface_array_type
);
1045 for (i
= interface_len
; i
> 0; i
--)
1047 tree child
= TREE_VEC_ELT (TYPE_BINFO_BASETYPES (type
), i
);
1048 tree iclass
= BINFO_TYPE (child
);
1050 if (flag_assume_compiled
)
1051 index
= build_class_ref (iclass
);
1054 int int_index
= alloc_class_constant (iclass
);
1055 index
= build_int_2 (int_index
, 0);
1056 TREE_TYPE (index
) == ptr_type_node
;
1058 init
= tree_cons (NULL_TREE
, index
, init
);
1060 DECL_INITIAL (idecl
) = build (CONSTRUCTOR
, interface_array_type
,
1062 TREE_STATIC (idecl
) = 1;
1063 DECL_ARTIFICIAL (idecl
) = 1;
1064 DECL_IGNORED_P (idecl
) = 1;
1065 interfaces
= build1 (ADDR_EXPR
, ptr_type_node
, idecl
);
1066 rest_of_decl_compilation (idecl
, (char*) 0, 1, 0);
1069 constant_pool_constructor
= build_constants_constructor ();
1071 START_RECORD_CONSTRUCTOR (temp
, object_type_node
);
1073 PUSH_FIELD_VALUE (temp
, "dtable", NULL_TREE
);
1075 PUSH_FIELD_VALUE (temp
, "dtable",
1076 build1 (ADDR_EXPR
, dtable_ptr_type
, class_dtable_decl
));
1078 PUSH_FIELD_VALUE (temp
, "sync_info", null_pointer_node
);
1079 FINISH_RECORD_CONSTRUCTOR (temp
);
1080 START_RECORD_CONSTRUCTOR (cons
, class_type_node
);
1081 PUSH_SUPER_VALUE (cons
, temp
);
1082 PUSH_FIELD_VALUE (cons
, "next", null_pointer_node
);
1083 PUSH_FIELD_VALUE (cons
, "name",
1084 build_utf8_ref (build_internal_class_name (type
)));
1085 PUSH_FIELD_VALUE (cons
, "accflags",
1086 build_int_2 (get_access_flags_from_decl (type_decl
), 0));
1088 PUSH_FIELD_VALUE (cons
, "superclass", super
);
1089 PUSH_FIELD_VALUE (cons
, "constants", constant_pool_constructor
);
1090 PUSH_FIELD_VALUE (cons
, "methods",
1091 build1 (ADDR_EXPR
, method_ptr_type_node
, methods_decl
));
1092 PUSH_FIELD_VALUE (cons
, "method_count", build_int_2 (method_count
, 0));
1093 PUSH_FIELD_VALUE (cons
, "dtable_method_count", TYPE_NVIRTUALS (type
));
1094 PUSH_FIELD_VALUE (cons
, "fields",
1095 fields_decl
== NULL_TREE
? null_pointer_node
1096 : build1 (ADDR_EXPR
, field_ptr_type_node
, fields_decl
));
1097 PUSH_FIELD_VALUE (cons
, "size_in_bytes", size_in_bytes (type
));
1098 PUSH_FIELD_VALUE (cons
, "field_count", build_int_2 (field_count
, 0));
1099 PUSH_FIELD_VALUE (cons
, "static_field_count",
1100 build_int_2 (static_field_count
, 0));
1101 /* For now, we let Kaffe fill in the dtable. */
1102 PUSH_FIELD_VALUE (cons
, "dtable",
1103 dtable_decl
== NULL_TREE
? null_pointer_node
1104 : build1 (ADDR_EXPR
, dtable_ptr_type
, dtable_decl
));
1105 PUSH_FIELD_VALUE (cons
, "interfaces", interfaces
);
1106 PUSH_FIELD_VALUE (cons
, "loader", null_pointer_node
);
1107 PUSH_FIELD_VALUE (cons
, "interface_count", build_int_2 (interface_len
, 0));
1108 PUSH_FIELD_VALUE (cons
, "state", integer_zero_node
);
1110 PUSH_FIELD_VALUE (cons
, "thread", null_pointer_node
);
1112 FINISH_RECORD_CONSTRUCTOR (cons
);
1114 DECL_INITIAL (decl
) = cons
;
1115 rest_of_decl_compilation (decl
, (char*) 0, 1, 0);
1118 /* Return 2 if CLASS is compiled by this compilation job;
1119 return 1 if CLASS can otherwise be assumed to be compiled;
1120 return 0 if we cannot assume that CLASS is compiled.
1121 Returns 1 for primitive and 0 for array types. */
1123 is_compiled_class (class)
1127 if (TREE_CODE (class) == POINTER_TYPE
)
1128 class = TREE_TYPE (class);
1129 if (TREE_CODE (class) != RECORD_TYPE
) /* Primitive types are static. */
1131 if (TYPE_ARRAY_P (class))
1133 if (class == current_class
)
1136 seen_in_zip
= (TYPE_LANG_SPECIFIC (class) && TYPE_LANG_SPECIFIC (class)->jcf
1137 && TYPE_LANG_SPECIFIC (class)->jcf
->seen_in_zip
);
1138 if (CLASS_FROM_CURRENTLY_COMPILED_SOURCE_P (class) || seen_in_zip
)
1140 /* The class was seen in the current ZIP file and will be
1141 available as a compiled class in the future but may not have
1142 been loaded already. Load it if necessary. This prevent
1143 build_class_ref () from crashing. */
1145 if (seen_in_zip
&& !CLASS_LOADED_P (class))
1146 load_class (class, 1);
1148 /* We return 2 for class seen in ZIP and class from files
1149 belonging to the same compilation unit */
1153 if (flag_assume_compiled
)
1155 if (!CLASS_LOADED_P (class))
1156 load_class (class, 1);
1163 /* Append the mangled name of TYPE onto OBSTACK. */
1166 append_gpp_mangled_type (obstack
, type
)
1167 struct obstack
*obstack
;
1173 switch (TREE_CODE (type
))
1176 case BOOLEAN_TYPE
: code
= 'b'; goto primitive
;
1177 case CHAR_TYPE
: code
= 'w'; goto primitive
;
1178 case VOID_TYPE
: code
= 'v'; goto primitive
;
1180 /* Get the original type instead of the arguments promoted type.
1181 Avoid symbol name clashes. Should call a function to do that.
1183 if (type
== promoted_short_type_node
)
1184 type
= short_type_node
;
1185 if (type
== promoted_byte_type_node
)
1186 type
= byte_type_node
;
1187 switch (TYPE_PRECISION (type
))
1189 case 8: code
= 'c'; goto primitive
;
1190 case 16: code
= 's'; goto primitive
;
1191 case 32: code
= 'i'; goto primitive
;
1192 case 64: code
= 'x'; goto primitive
;
1193 default: goto bad_type
;
1196 obstack_1grow (obstack
, code
);
1199 switch (TYPE_PRECISION (type
))
1201 case 32: code
= 'f'; goto primitive
;
1202 case 64: code
= 'd'; goto primitive
;
1203 default: goto bad_type
;
1206 type
= TREE_TYPE (type
);
1207 obstack_1grow (obstack
, 'P');
1209 if (TYPE_ARRAY_P (type
))
1211 obstack_grow (obstack
, "t6JArray1Z", sizeof("t6JArray1Z")-1);
1212 append_gpp_mangled_type (obstack
, TYPE_ARRAY_ELEMENT (type
));
1216 char *class_name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
1217 append_gpp_mangled_classtype (obstack
, class_name
);
1222 fatal ("internal error - trying to mangle unknown type");
1226 /* Build the mangled name of the `class' field. */
1229 mangle_class_field (class)
1233 obstack_grow (&temporary_obstack
, "_CL_", 4);
1234 append_gpp_mangled_type (&temporary_obstack
, class);
1235 obstack_1grow (&temporary_obstack
, '\0');
1236 name
= get_identifier (obstack_base (&temporary_obstack
));
1237 obstack_free (&temporary_obstack
, obstack_base (&temporary_obstack
));
1241 /* Build the mangled (assembly-level) name of the static field FIELD. */
1244 mangle_static_field (field
)
1247 tree
class = DECL_CONTEXT (field
);
1248 tree name
= DECL_NAME (field
);
1250 #if ! defined (NO_DOLLAR_IN_LABEL) || ! defined (NO_DOT_IN_LABEL)
1251 obstack_1grow (&temporary_obstack
, '_');
1253 obstack_grow (&temporary_obstack
, "__static_", 9);
1255 append_gpp_mangled_type (&temporary_obstack
, class);
1256 encoded_len
= unicode_mangling_length (IDENTIFIER_POINTER (name
),
1257 IDENTIFIER_LENGTH (name
));
1258 if (encoded_len
> 0)
1260 obstack_1grow (&temporary_obstack
, 'U');
1262 #ifndef NO_DOLLAR_IN_LABEL
1263 obstack_1grow (&temporary_obstack
, '$');
1264 #else /* NO_DOLLAR_IN_LABEL */
1265 #ifndef NO_DOT_IN_LABEL
1266 obstack_1grow (&temporary_obstack
, '.');
1267 #else /* NO_DOT_IN_LABEL */
1268 obstack_1grow (&temporary_obstack
, '_');
1269 #endif /* NO_DOT_IN_LABEL */
1270 #endif /* NO_DOLLAR_IN_LABEL */
1271 if (encoded_len
> 0)
1273 emit_unicode_mangled_name (&temporary_obstack
,
1274 IDENTIFIER_POINTER (name
),
1275 IDENTIFIER_LENGTH (name
));
1279 obstack_grow (&temporary_obstack
,
1280 IDENTIFIER_POINTER (name
),
1281 IDENTIFIER_LENGTH (name
));
1283 obstack_1grow (&temporary_obstack
, '\0');
1284 name
= get_identifier (obstack_base (&temporary_obstack
));
1285 obstack_free (&temporary_obstack
, obstack_base (&temporary_obstack
));
1289 /* Build a VAR_DECL for the dispatch table (vtable) for class TYPE. */
1292 build_dtable_decl (type
)
1296 obstack_grow (&temporary_obstack
, "__vt_", 5);
1297 append_gpp_mangled_type (&temporary_obstack
, type
);
1298 obstack_1grow (&temporary_obstack
, '\0');
1299 name
= get_identifier (obstack_base (&temporary_obstack
));
1300 obstack_free (&temporary_obstack
, obstack_base (&temporary_obstack
));
1301 return build_decl (VAR_DECL
, name
, dtable_type
);
1304 /* Pre-pend the TYPE_FIELDS of THIS_CLASS with a dummy FIELD_DECL for the
1305 fields inherited from SUPER_CLASS. */
1308 push_super_field (this_class
, super_class
)
1309 tree this_class
, super_class
;
1312 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1313 base_decl
= build_decl (FIELD_DECL
, NULL_TREE
, super_class
);
1315 DECL_IGNORED_P (base_decl
) = 1;
1316 TREE_CHAIN (base_decl
) = TYPE_FIELDS (this_class
);
1317 TYPE_FIELDS (this_class
) = base_decl
;
1318 DECL_SIZE (base_decl
) = TYPE_SIZE (super_class
);
1322 layout_class (this_class
)
1325 tree super_class
= CLASSTYPE_SUPER (this_class
);
1326 tree handle_type
= CLASS_TO_HANDLE_TYPE (this_class
);
1327 tree method_decl
, field
;
1333 /* Class seen in source are now complete and can be layed out.
1334 Once layed out, a class seen in the source has its
1335 CLASS_LOADED_P flag set */
1336 if (CLASS_FROM_SOURCE_P (super_class
) && !CLASS_LOADED_P (super_class
))
1337 safe_layout_class (super_class
);
1338 if (! CLASS_LOADED_P (super_class
))
1339 load_class (super_class
, 1);
1340 if (TREE_CODE (TYPE_SIZE (super_class
)) == ERROR_MARK
)
1342 TYPE_SIZE (this_class
) = error_mark_node
;
1345 dtable_count
= TYPE_NVIRTUALS (super_class
);
1347 if (TYPE_SIZE (this_class
) == NULL_TREE
)
1348 push_super_field (this_class
, super_class
);
1352 dtable_count
= integer_zero_node
;
1355 for (field
= TYPE_FIELDS (this_class
);
1356 field
!= NULL_TREE
; field
= TREE_CHAIN (field
))
1358 if (FIELD_STATIC (field
))
1360 /* Set DECL_ASSEMBLER_NAME to something suitably mangled. */
1361 DECL_ASSEMBLER_NAME (field
) = mangle_static_field (field
);
1365 layout_type (this_class
);
1367 TYPE_METHODS (handle_type
) = nreverse (TYPE_METHODS (handle_type
));
1369 for (method_decl
= TYPE_METHODS (handle_type
), i
= 0;
1370 method_decl
; method_decl
= TREE_CHAIN (method_decl
), i
++)
1375 tree method_name
= DECL_NAME (method_decl
);
1377 /* Remove this once we no longer need old (Kaffe / JDK 1.0) mangling. */
1378 if (! flag_assume_compiled
&& METHOD_NATIVE (method_decl
))
1380 for (ptr
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (this_class
)));
1386 obstack_1grow (&temporary_obstack
, (char) ch
);
1388 obstack_1grow (&temporary_obstack
, (char) '_');
1389 if (method_name
== init_identifier_node
)
1390 obstack_grow (&temporary_obstack
, "INIT", 4);
1392 obstack_grow (&temporary_obstack
,
1393 IDENTIFIER_POINTER (method_name
),
1394 IDENTIFIER_LENGTH (method_name
));
1399 int len
; tree arg
, arglist
, t
;
1400 int method_name_needs_escapes
= 0;
1401 if (method_name
!= init_identifier_node
1402 && method_name
!= finit_identifier_node
)
1405 = unicode_mangling_length (IDENTIFIER_POINTER (method_name
),
1406 IDENTIFIER_LENGTH (method_name
));
1407 if (encoded_len
> 0)
1409 method_name_needs_escapes
= 1;
1410 emit_unicode_mangled_name (&temporary_obstack
,
1411 IDENTIFIER_POINTER (method_name
),
1412 IDENTIFIER_LENGTH (method_name
));
1416 obstack_grow (&temporary_obstack
,
1417 IDENTIFIER_POINTER (method_name
),
1418 IDENTIFIER_LENGTH (method_name
));
1422 obstack_grow (&temporary_obstack
, "__", 2);
1423 if (method_name
== finit_identifier_node
)
1424 obstack_grow (&temporary_obstack
, "finit", 5);
1425 append_gpp_mangled_type (&temporary_obstack
, this_class
);
1426 TREE_PUBLIC (method_decl
) = 1;
1428 t
= TREE_TYPE (method_decl
);
1429 arglist
= TYPE_ARG_TYPES (t
);
1430 if (TREE_CODE (t
) == METHOD_TYPE
)
1431 arglist
= TREE_CHAIN (arglist
);
1432 for (arg
= arglist
; arg
!= NULL_TREE
; )
1435 tree argtype
= TREE_VALUE (arg
);
1437 if (TREE_CODE (argtype
) == POINTER_TYPE
)
1439 /* This is O(N**2). Do we care? Cfr gcc/cp/method.c. */
1440 while (a
!= arg
&& argtype
!= TREE_VALUE (a
))
1441 a
= TREE_CHAIN (a
), tindex
++;
1451 arg
= TREE_CHAIN (arg
); nrepeats
++;
1453 while (arg
!= NULL_TREE
&& argtype
== TREE_VALUE (arg
));
1456 obstack_1grow (&temporary_obstack
, 'N');
1457 sprintf (buf
, "%d", nrepeats
);
1458 obstack_grow (&temporary_obstack
, buf
, strlen (buf
));
1460 obstack_1grow (&temporary_obstack
, '_');
1463 obstack_1grow (&temporary_obstack
, 'T');
1464 sprintf (buf
, "%d", tindex
);
1465 obstack_grow (&temporary_obstack
, buf
, strlen (buf
));
1467 obstack_1grow (&temporary_obstack
, '_');
1471 append_gpp_mangled_type (&temporary_obstack
, argtype
);
1472 arg
= TREE_CHAIN (arg
);
1475 if (method_name_needs_escapes
)
1476 obstack_1grow (&temporary_obstack
, 'U');
1478 obstack_1grow (&temporary_obstack
, '\0');
1479 asm_name
= obstack_finish (&temporary_obstack
);
1480 DECL_ASSEMBLER_NAME (method_decl
) = get_identifier (asm_name
);
1481 if (! METHOD_ABSTRACT (method_decl
))
1482 make_function_rtl (method_decl
);
1483 obstack_free (&temporary_obstack
, asm_name
);
1485 if (method_name
== init_identifier_node
)
1487 char *p
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (this_class
)));
1488 for (ptr
= p
; *ptr
; )
1493 DECL_NAME (method_decl
) = get_identifier (p
);
1494 DECL_CONSTRUCTOR_P (method_decl
) = 1;
1496 else if (! METHOD_STATIC (method_decl
) && !DECL_ARTIFICIAL (method_decl
))
1498 tree method_sig
= build_java_argument_signature (TREE_TYPE (method_decl
));
1499 tree super_method
= lookup_argument_method (super_class
, method_name
,
1501 if (super_method
!= NULL_TREE
)
1503 DECL_VINDEX (method_decl
) = DECL_VINDEX (super_method
);
1504 if (DECL_VINDEX (method_decl
) == NULL_TREE
)
1505 error_with_decl (method_decl
,
1506 "non-static method '%s' overrides static method");
1508 else if (TREE_TYPE (TREE_TYPE (method_decl
))
1509 != TREE_TYPE (TREE_TYPE (super_method
)))
1511 error_with_decl (method_decl
,
1512 "Method `%s' redefined with different return type");
1513 error_with_decl (super_method
,
1514 "Overridden decl is here");
1518 else if (! METHOD_FINAL (method_decl
)
1519 && ! CLASS_FINAL (TYPE_NAME (this_class
)))
1521 DECL_VINDEX (method_decl
) = dtable_count
;
1522 dtable_count
= build_int_2 (1+TREE_INT_CST_LOW (dtable_count
), 0);
1526 TYPE_NVIRTUALS (this_class
) = dtable_count
;
1528 #ifdef JAVA_USE_HANDLES
1529 layout_type (handle_type
);
1533 static tree registered_class
= NULL_TREE
;
1539 tree node
= TREE_OPERAND (build_class_ref (current_class
), 0);
1540 tree current
= copy_node (node
);
1542 XEXP (DECL_RTL (current
), 0) = copy_rtx (XEXP (DECL_RTL(node
), 0));
1543 if (!registered_class
)
1544 registered_class
= current
;
1546 TREE_CHAIN (end
) = current
;
1551 /* Generate a function that gets called at start-up (static contructor) time,
1552 which calls registerClass for all the compiled classes. */
1555 emit_register_classes ()
1557 tree decl
= getdecls ();
1559 extern tree get_file_function_name
PROTO((int));
1560 tree init_name
= get_file_function_name ('I');
1561 tree init_type
= build_function_type (void_type_node
, NULL_TREE
);
1566 init_decl
= build_decl (FUNCTION_DECL
, init_name
, init_type
);
1567 DECL_ASSEMBLER_NAME (init_decl
) = init_name
;
1568 TREE_STATIC (init_decl
) = 1;
1569 current_function_decl
= init_decl
;
1570 DECL_RESULT (init_decl
) = build_decl(RESULT_DECL
, NULL_TREE
, void_type_node
);
1571 /* DECL_EXTERNAL (init_decl) = 1;*/
1572 TREE_PUBLIC (init_decl
) = 1;
1574 make_function_rtl (init_decl
);
1575 init_function_start (init_decl
, input_filename
, 0);
1576 expand_function_start (init_decl
, 0);
1578 for ( t
= registered_class
; t
; t
= TREE_CHAIN (t
))
1579 emit_library_call (registerClass_libfunc
, 0, VOIDmode
, 1,
1580 XEXP (DECL_RTL (t
), 0), Pmode
);
1582 expand_function_end (input_filename
, 0, 0);
1585 /* Force generation, even with -O3 or deeper. Gross hack. FIXME */
1586 extern int flag_inline_functions
;
1587 int saved_flag
= flag_inline_functions
;
1588 flag_inline_functions
= 0;
1589 rest_of_compilation (init_decl
);
1590 flag_inline_functions
= saved_flag
;
1592 current_function_decl
= NULL_TREE
;
1593 assemble_constructor (IDENTIFIER_POINTER (init_name
));
1597 init_class_processing ()
1599 registerClass_libfunc
= gen_rtx (SYMBOL_REF
, Pmode
, "_Jv_RegisterClass");