1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Written by Per Bothner <bothner@cygnus.com> */
30 #include "coretypes.h"
35 #include "java-tree.h"
46 #include "tree-iterator.h"
48 /* DOS brain-damage */
50 #define O_BINARY 0 /* MS-DOS brain-damage */
53 static tree
make_method_value (tree
);
54 static tree
build_java_method_type (tree
, tree
, int);
55 static int32
hashUtf8String (const char *, int);
56 static tree
make_field_value (tree
);
57 static tree
get_dispatch_vector (tree
);
58 static tree
get_dispatch_table (tree
, tree
);
59 static int supers_all_compiled (tree type
);
60 static tree
maybe_layout_super_class (tree
, tree
);
61 static void add_miranda_methods (tree
, tree
);
62 static int assume_compiled (const char *);
63 static tree
build_symbol_entry (tree
);
65 struct obstack temporary_obstack
;
67 /* The compiler generates different code depending on whether or not
68 it can assume certain classes have been compiled down to native
69 code or not. The compiler options -fassume-compiled= and
70 -fno-assume-compiled= are used to create a tree of
71 class_flag_node objects. This tree is queried to determine if
72 a class is assume to be compiled or not. Each node in the tree
73 represents either a package or a specific class. */
75 typedef struct class_flag_node_struct
77 /* The class or package name. */
80 /* Nonzero if this represents an exclusion. */
83 /* Pointers to other nodes in the tree. */
84 struct class_flag_node_struct
*parent
;
85 struct class_flag_node_struct
*sibling
;
86 struct class_flag_node_struct
*child
;
89 static class_flag_node
*find_class_flag_node (class_flag_node
*, const char *);
90 static void add_class_flag (class_flag_node
**, const char *, int);
92 /* This is the root of the include/exclude tree. */
94 static class_flag_node
*assume_compiled_tree
;
96 static class_flag_node
*enable_assert_tree
;
98 static GTY(()) tree class_roots
[5];
99 #define registered_class class_roots[0]
100 #define fields_ident class_roots[1] /* get_identifier ("fields") */
101 #define info_ident class_roots[2] /* get_identifier ("info") */
102 #define class_list class_roots[3]
103 #define class_dtable_decl class_roots[4]
105 /* Return the node that most closely represents the class whose name
106 is IDENT. Start the search from NODE (followed by its siblings).
107 Return NULL if an appropriate node does not exist. */
109 static class_flag_node
*
110 find_class_flag_node (class_flag_node
*node
, const char *ident
)
114 size_t node_ident_length
= strlen (node
->ident
);
116 /* node_ident_length is zero at the root of the tree. If the
117 identifiers are the same length, then we have matching
118 classes. Otherwise check if we've matched an enclosing
121 if (node_ident_length
== 0
122 || (strncmp (ident
, node
->ident
, node_ident_length
) == 0
123 && (ident
[node_ident_length
] == '\0'
124 || ident
[node_ident_length
] == '.')))
126 /* We've found a match, however, there might be a more
129 class_flag_node
*found
= find_class_flag_node (node
->child
, ident
);
136 /* No match yet. Continue through the sibling list. */
137 node
= node
->sibling
;
140 /* No match at all in this tree. */
145 add_class_flag (class_flag_node
**rootp
, const char *ident
, int value
)
147 class_flag_node
*root
= *rootp
;
148 class_flag_node
*parent
, *node
;
150 /* Create the root of the tree if it doesn't exist yet. */
154 root
= xmalloc (sizeof (class_flag_node
));
157 root
->sibling
= NULL
;
163 /* Calling the function with the empty string means we're setting
164 value for the root of the hierarchy. */
172 /* Find the parent node for this new node. PARENT will either be a
173 class or a package name. Adjust PARENT accordingly. */
175 parent
= find_class_flag_node (root
, ident
);
176 if (strcmp (ident
, parent
->ident
) == 0)
177 parent
->value
= value
;
180 /* Insert new node into the tree. */
181 node
= xmalloc (sizeof (class_flag_node
));
183 node
->ident
= xstrdup (ident
);
187 node
->parent
= parent
;
188 node
->sibling
= parent
->child
;
189 parent
->child
= node
;
193 /* Add a new IDENT to the include/exclude tree. It's an exclusion
194 if EXCLUDEP is nonzero. */
197 add_assume_compiled (const char *ident
, int excludep
)
199 add_class_flag (&assume_compiled_tree
, ident
, excludep
);
202 /* The default value returned by enable_assertions. */
204 #define DEFAULT_ENABLE_ASSERT (flag_emit_class_files || optimize == 0)
206 /* Enter IDENT (a class or package name) into the enable-assertions table.
207 VALUE is true to enable and false to disable. */
210 add_enable_assert (const char *ident
, int value
)
212 if (enable_assert_tree
== NULL
)
213 add_class_flag (&enable_assert_tree
, "", DEFAULT_ENABLE_ASSERT
);
214 add_class_flag (&enable_assert_tree
, ident
, value
);
217 /* Returns nonzero if IDENT is the name of a class that the compiler
218 should assume has been compiled to object code. */
221 assume_compiled (const char *ident
)
226 if (NULL
== assume_compiled_tree
)
229 i
= find_class_flag_node (assume_compiled_tree
, ident
);
236 /* Return true if we should generate code to check assertions within KLASS. */
239 enable_assertions (tree klass
)
241 /* Check if command-line specifies whether we should check assertions. */
243 if (klass
!= NULL_TREE
&& DECL_NAME (klass
) && enable_assert_tree
!= NULL
)
245 const char *ident
= IDENTIFIER_POINTER (DECL_NAME (klass
));
246 class_flag_node
*node
247 = find_class_flag_node (enable_assert_tree
, ident
);
251 /* The default is to enable assertions if generating class files,
252 or not optimizing. */
253 return DEFAULT_ENABLE_ASSERT
;
256 /* Return an IDENTIFIER_NODE the same as (OLD_NAME, OLD_LENGTH).
257 except that characters matching OLD_CHAR are substituted by NEW_CHAR.
258 Also, PREFIX is prepended, and SUFFIX is appended. */
261 ident_subst (const char* old_name
,
268 int prefix_len
= strlen (prefix
);
269 int suffix_len
= strlen (suffix
);
270 int i
= prefix_len
+ old_length
+ suffix_len
+ 1;
271 char *buffer
= alloca (i
);
273 strcpy (buffer
, prefix
);
274 for (i
= 0; i
< old_length
; i
++)
276 char ch
= old_name
[i
];
279 buffer
[prefix_len
+ i
] = ch
;
281 strcpy (buffer
+ prefix_len
+ old_length
, suffix
);
282 return get_identifier (buffer
);
285 /* Return an IDENTIFIER_NODE the same as OLD_ID,
286 except that characters matching OLD_CHAR are substituted by NEW_CHAR.
287 Also, PREFIX is prepended, and SUFFIX is appended. */
290 identifier_subst (const tree old_id
,
296 return ident_subst (IDENTIFIER_POINTER (old_id
), IDENTIFIER_LENGTH (old_id
),
297 prefix
, old_char
, new_char
, suffix
);
300 /* Generate a valid C identifier from the name of the class TYPE,
301 prefixed by PREFIX. */
304 mangled_classname (const char *prefix
, tree type
)
306 tree ident
= TYPE_NAME (type
);
307 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
308 ident
= DECL_NAME (ident
);
309 return identifier_subst (ident
, prefix
, '.', '_', "");
316 type
= make_node (RECORD_TYPE
);
317 MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type
);
322 /* Given a fully-qualified classname in NAME (whose length is NAME_LENGTH),
323 and where each of the constituents is separated by '/',
324 return a corresponding IDENTIFIER_NODE, except using '.' as separator. */
327 unmangle_classname (const char *name
, int name_length
)
329 tree to_return
= ident_subst (name
, name_length
, "", '/', '.', "");
330 /* It's not sufficient to compare to_return and get_identifier
331 (name) to determine whether to_return is qualified. There are
332 cases in signature analysis where name will be stripped of a
334 name
= IDENTIFIER_POINTER (to_return
);
338 QUALIFIED_P (to_return
) = 1;
346 /* Given a class, create the DECLs for all its associated indirect
349 gen_indirect_dispatch_tables (tree type
)
351 const char *typename
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
354 char *buf
= alloca (strlen (typename
) + strlen ("_catch_classes_") + 1);
355 tree catch_class_type
= make_node (RECORD_TYPE
);
357 sprintf (buf
, "_catch_classes_%s", typename
);
358 PUSH_FIELD (catch_class_type
, field
, "address", utf8const_ptr_type
);
359 PUSH_FIELD (catch_class_type
, field
, "classname", ptr_type_node
);
360 FINISH_RECORD (catch_class_type
);
362 TYPE_CTABLE_DECL (type
)
363 = build_decl (VAR_DECL
, get_identifier (buf
),
364 build_array_type (catch_class_type
, 0));
365 DECL_EXTERNAL (TYPE_CTABLE_DECL (type
)) = 1;
366 TREE_STATIC (TYPE_CTABLE_DECL (type
)) = 1;
367 TREE_READONLY (TYPE_CTABLE_DECL (type
)) = 1;
368 TREE_CONSTANT (TYPE_CTABLE_DECL (type
)) = 1;
369 DECL_IGNORED_P (TYPE_CTABLE_DECL (type
)) = 1;
370 pushdecl (TYPE_CTABLE_DECL (type
));
373 if (flag_indirect_dispatch
)
376 char *buf
= alloca (strlen (typename
) + strlen ("_otable_syms_") + 1);
378 sprintf (buf
, "_otable_%s", typename
);
379 TYPE_OTABLE_DECL (type
) =
380 build_decl (VAR_DECL
, get_identifier (buf
), otable_type
);
381 DECL_EXTERNAL (TYPE_OTABLE_DECL (type
)) = 1;
382 TREE_STATIC (TYPE_OTABLE_DECL (type
)) = 1;
383 TREE_READONLY (TYPE_OTABLE_DECL (type
)) = 1;
384 TREE_CONSTANT (TYPE_OTABLE_DECL (type
)) = 1;
385 DECL_IGNORED_P (TYPE_OTABLE_DECL (type
)) = 1;
386 pushdecl (TYPE_OTABLE_DECL (type
));
387 sprintf (buf
, "_otable_syms_%s", typename
);
388 TYPE_OTABLE_SYMS_DECL (type
) =
389 build_decl (VAR_DECL
, get_identifier (buf
), symbols_array_type
);
390 TREE_STATIC (TYPE_OTABLE_SYMS_DECL (type
)) = 1;
391 TREE_CONSTANT (TYPE_OTABLE_SYMS_DECL (type
)) = 1;
392 DECL_IGNORED_P(TYPE_OTABLE_SYMS_DECL (type
)) = 1;
393 pushdecl (TYPE_OTABLE_SYMS_DECL (type
));
397 char *buf
= alloca (strlen (typename
) + strlen ("_atable_syms_") + 1);
400 sprintf (buf
, "_atable_%s", typename
);
401 TYPE_ATABLE_DECL (type
) = decl
=
402 build_decl (VAR_DECL
, get_identifier (buf
), atable_type
);
403 DECL_EXTERNAL (decl
) = 1;
404 TREE_STATIC (decl
) = 1;
405 TREE_READONLY (decl
) = 1;
406 TREE_CONSTANT (decl
) = 1;
407 DECL_IGNORED_P (decl
) = 1;
408 /* Mark the atable as belonging to this class. */
410 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
411 DECL_OWNER (decl
) = type
;
412 sprintf (buf
, "_atable_syms_%s", typename
);
413 TYPE_ATABLE_SYMS_DECL (type
) =
414 build_decl (VAR_DECL
, get_identifier (buf
), symbols_array_type
);
415 TREE_STATIC (TYPE_ATABLE_SYMS_DECL (type
)) = 1;
416 TREE_CONSTANT (TYPE_ATABLE_SYMS_DECL (type
)) = 1;
417 DECL_IGNORED_P (TYPE_ATABLE_SYMS_DECL (type
)) = 1;
418 pushdecl (TYPE_ATABLE_SYMS_DECL (type
));
424 push_class (tree class_type
, tree class_name
)
426 tree decl
, signature
;
427 location_t saved_loc
= input_location
;
428 #ifndef USE_MAPPED_LOCATION
429 tree source_name
= identifier_subst (class_name
, "", '.', '/', ".java");
430 input_filename
= IDENTIFIER_POINTER (source_name
);
433 CLASS_P (class_type
) = 1;
434 decl
= build_decl (TYPE_DECL
, class_name
, class_type
);
436 /* dbxout needs a DECL_SIZE if in gstabs mode */
437 DECL_SIZE (decl
) = integer_zero_node
;
439 input_location
= saved_loc
;
440 signature
= identifier_subst (class_name
, "L", '.', '/', ";");
441 IDENTIFIER_SIGNATURE_TYPE (signature
) = build_pointer_type (class_type
);
443 /* Setting DECL_ARTIFICIAL forces dbxout.c to specific the type is
444 both a typedef and in the struct name-space. We may want to re-visit
445 this later, but for now it reduces the changes needed for gdb. */
446 DECL_ARTIFICIAL (decl
) = 1;
448 pushdecl_top_level (decl
);
453 /* Finds the (global) class named NAME. Creates the class if not found.
454 Also creates associated TYPE_DECL.
455 Does not check if the class actually exists, load the class,
456 fill in field or methods, or do layout_type. */
459 lookup_class (tree name
)
461 tree decl
= IDENTIFIER_CLASS_VALUE (name
);
462 if (decl
== NULL_TREE
)
463 decl
= push_class (make_class (), name
);
464 return TREE_TYPE (decl
);
468 set_super_info (int access_flags
, tree this_class
,
469 tree super_class
, int interfaces_count
)
471 int total_supers
= interfaces_count
;
472 tree class_decl
= TYPE_NAME (this_class
);
477 TYPE_BINFO (this_class
) = make_tree_binfo (total_supers
);
478 TYPE_VFIELD (this_class
) = TYPE_VFIELD (object_type_node
);
481 tree super_binfo
= make_tree_binfo (0);
482 BINFO_TYPE (super_binfo
) = super_class
;
483 BINFO_OFFSET (super_binfo
) = integer_zero_node
;
484 BINFO_BASE_APPEND (TYPE_BINFO (this_class
), super_binfo
);
485 CLASS_HAS_SUPER_FLAG (TYPE_BINFO (this_class
)) = 1;
488 set_class_decl_access_flags (access_flags
, class_decl
);
492 set_class_decl_access_flags (int access_flags
, tree class_decl
)
494 if (access_flags
& ACC_PUBLIC
) CLASS_PUBLIC (class_decl
) = 1;
495 if (access_flags
& ACC_FINAL
) CLASS_FINAL (class_decl
) = 1;
496 if (access_flags
& ACC_SUPER
) CLASS_SUPER (class_decl
) = 1;
497 if (access_flags
& ACC_INTERFACE
) CLASS_INTERFACE (class_decl
) = 1;
498 if (access_flags
& ACC_ABSTRACT
) CLASS_ABSTRACT (class_decl
) = 1;
499 if (access_flags
& ACC_STATIC
) CLASS_STATIC (class_decl
) = 1;
500 if (access_flags
& ACC_PRIVATE
) CLASS_PRIVATE (class_decl
) = 1;
501 if (access_flags
& ACC_PROTECTED
) CLASS_PROTECTED (class_decl
) = 1;
502 if (access_flags
& ACC_STRICT
) CLASS_STRICTFP (class_decl
) = 1;
505 /* Return length of inheritance chain of CLAS, where java.lang.Object is 0,
506 direct sub-classes of Object are 1, and so on. */
509 class_depth (tree clas
)
512 if (! CLASS_LOADED_P (clas
))
513 load_class (clas
, 1);
514 if (TYPE_SIZE (clas
) == error_mark_node
)
516 while (clas
!= object_type_node
)
519 clas
= BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (clas
), 0));
524 /* Return true iff TYPE2 is an interface that extends interface TYPE1 */
527 interface_of_p (tree type1
, tree type2
)
530 tree binfo
, base_binfo
;
532 if (! TYPE_BINFO (type2
))
535 for (binfo
= TYPE_BINFO (type2
), i
= 0;
536 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
537 if (BINFO_TYPE (base_binfo
) == type1
)
540 for (binfo
= TYPE_BINFO (type2
), i
= 0;
541 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++) /* */
542 if (BINFO_TYPE (base_binfo
)
543 && interface_of_p (type1
, BINFO_TYPE (base_binfo
)))
549 /* Return true iff TYPE1 inherits from TYPE2. */
552 inherits_from_p (tree type1
, tree type2
)
554 while (type1
!= NULL_TREE
&& TREE_CODE (type1
) == RECORD_TYPE
)
558 type1
= CLASSTYPE_SUPER (type1
);
563 /* Return a 1 iff TYPE1 is an enclosing context for TYPE2 */
566 enclosing_context_p (tree type1
, tree type2
)
568 if (!INNER_CLASS_TYPE_P (type2
))
571 for (type2
= TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type2
)));
573 type2
= (INNER_CLASS_TYPE_P (type2
) ?
574 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type2
))) : NULL_TREE
))
584 /* Return 1 iff TYPE1 and TYPE2 share a common enclosing class, regardless of
588 common_enclosing_context_p (tree type1
, tree type2
)
593 for (current
= type2
; current
;
594 current
= (INNER_CLASS_TYPE_P (current
) ?
595 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current
))) :
597 if (type1
== current
)
600 if (INNER_CLASS_TYPE_P (type1
))
601 type1
= TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type1
)));
608 /* Return 1 iff there exists a common enclosing "this" between TYPE1
609 and TYPE2, without crossing any static context. */
612 common_enclosing_instance_p (tree type1
, tree type2
)
614 if (!PURE_INNER_CLASS_TYPE_P (type1
) || !PURE_INNER_CLASS_TYPE_P (type2
))
617 for (type1
= TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type1
))); type1
;
618 type1
= (PURE_INNER_CLASS_TYPE_P (type1
) ?
619 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type1
))) : NULL_TREE
))
622 for (current
= TREE_TYPE (DECL_CONTEXT (TYPE_NAME (type2
))); current
;
623 current
= (PURE_INNER_CLASS_TYPE_P (current
) ?
624 TREE_TYPE (DECL_CONTEXT (TYPE_NAME (current
))) :
626 if (type1
== current
)
632 /* Add INTERFACE_CLASS to THIS_CLASS iff INTERFACE_CLASS can't be
633 found in THIS_CLASS. Returns NULL_TREE upon success, INTERFACE_CLASS
634 if attempt is made to add it twice. */
637 maybe_add_interface (tree this_class
, tree interface_class
)
639 tree binfo
, base_binfo
;
642 for (binfo
= TYPE_BINFO (this_class
), i
= 0;
643 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
644 if (BINFO_TYPE (base_binfo
) == interface_class
)
645 return interface_class
;
646 add_interface (this_class
, interface_class
);
650 /* Add the INTERFACE_CLASS as one of the interfaces of THIS_CLASS. */
653 add_interface (tree this_class
, tree interface_class
)
655 tree interface_binfo
= make_tree_binfo (0);
657 BINFO_TYPE (interface_binfo
) = interface_class
;
658 BINFO_OFFSET (interface_binfo
) = integer_zero_node
;
659 BINFO_VPTR_FIELD (interface_binfo
) = integer_zero_node
;
660 BINFO_VIRTUAL_P (interface_binfo
) = 1;
662 BINFO_BASE_APPEND (TYPE_BINFO (this_class
), interface_binfo
);
666 /* Return the address of a pointer to the first FUNCTION_DECL
667 in the list (*LIST) whose DECL_NAME is NAME. */
670 find_named_method (tree
*list
, tree name
)
672 while (*list
&& DECL_NAME (*list
) != name
)
673 list
= &TREE_CHAIN (*list
);
679 build_java_method_type (tree fntype
, tree this_class
, int access_flags
)
681 if (access_flags
& ACC_STATIC
)
683 return build_method_type (this_class
, fntype
);
687 add_method_1 (tree this_class
, int access_flags
, tree name
, tree function_type
)
689 tree method_type
, fndecl
;
691 method_type
= build_java_method_type (function_type
,
692 this_class
, access_flags
);
694 fndecl
= build_decl (FUNCTION_DECL
, name
, method_type
);
695 DECL_CONTEXT (fndecl
) = this_class
;
697 DECL_LANG_SPECIFIC (fndecl
)
698 = ggc_alloc_cleared (sizeof (struct lang_decl
));
699 DECL_LANG_SPECIFIC (fndecl
)->desc
= LANG_DECL_FUNC
;
701 /* Initialize the static initializer test table. */
703 DECL_FUNCTION_INIT_TEST_TABLE (fndecl
) =
704 java_treetreehash_create (10, 1);
706 /* Initialize the initialized (static) class table. */
707 if (access_flags
& ACC_STATIC
)
708 DECL_FUNCTION_INITIALIZED_CLASS_TABLE (fndecl
) =
709 htab_create_ggc (50, htab_hash_pointer
, htab_eq_pointer
, NULL
);
711 /* Initialize the static method invocation compound list */
712 DECL_FUNCTION_STATIC_METHOD_INVOCATION_COMPOUND (fndecl
) = NULL_TREE
;
714 TREE_CHAIN (fndecl
) = TYPE_METHODS (this_class
);
715 TYPE_METHODS (this_class
) = fndecl
;
717 /* Notice that this is a finalizer and update the class type
718 accordingly. This is used to optimize instance allocation. */
719 if (name
== finalize_identifier_node
720 && TREE_TYPE (function_type
) == void_type_node
721 && TREE_VALUE (TYPE_ARG_TYPES (function_type
)) == void_type_node
)
722 HAS_FINALIZER_P (this_class
) = 1;
724 if (access_flags
& ACC_PUBLIC
) METHOD_PUBLIC (fndecl
) = 1;
725 if (access_flags
& ACC_PROTECTED
) METHOD_PROTECTED (fndecl
) = 1;
726 if (access_flags
& ACC_PRIVATE
)
727 METHOD_PRIVATE (fndecl
) = DECL_INLINE (fndecl
) = 1;
728 if (access_flags
& ACC_NATIVE
)
730 METHOD_NATIVE (fndecl
) = 1;
731 DECL_EXTERNAL (fndecl
) = 1;
733 if (access_flags
& ACC_STATIC
)
734 METHOD_STATIC (fndecl
) = DECL_INLINE (fndecl
) = 1;
735 if (access_flags
& ACC_FINAL
)
736 METHOD_FINAL (fndecl
) = DECL_INLINE (fndecl
) = 1;
737 if (access_flags
& ACC_SYNCHRONIZED
) METHOD_SYNCHRONIZED (fndecl
) = 1;
738 if (access_flags
& ACC_ABSTRACT
) METHOD_ABSTRACT (fndecl
) = 1;
739 if (access_flags
& ACC_STRICT
) METHOD_STRICTFP (fndecl
) = 1;
743 /* Add a method to THIS_CLASS.
744 The method's name is NAME.
745 Its signature (mangled type) is METHOD_SIG (an IDENTIFIER_NODE). */
748 add_method (tree this_class
, int access_flags
, tree name
, tree method_sig
)
750 tree function_type
, fndecl
;
751 const unsigned char *sig
752 = (const unsigned char *) IDENTIFIER_POINTER (method_sig
);
755 fatal_error ("bad method signature");
757 function_type
= get_type_from_signature (method_sig
);
758 fndecl
= add_method_1 (this_class
, access_flags
, name
, function_type
);
759 set_java_signature (TREE_TYPE (fndecl
), method_sig
);
764 add_field (tree
class, tree name
, tree field_type
, int flags
)
766 int is_static
= (flags
& ACC_STATIC
) != 0;
768 field
= build_decl (is_static
? VAR_DECL
: FIELD_DECL
, name
, field_type
);
769 TREE_CHAIN (field
) = TYPE_FIELDS (class);
770 TYPE_FIELDS (class) = field
;
771 DECL_CONTEXT (field
) = class;
773 if (flags
& ACC_PUBLIC
) FIELD_PUBLIC (field
) = 1;
774 if (flags
& ACC_PROTECTED
) FIELD_PROTECTED (field
) = 1;
775 if (flags
& ACC_PRIVATE
) FIELD_PRIVATE (field
) = 1;
776 if (flags
& ACC_FINAL
) FIELD_FINAL (field
) = 1;
777 if (flags
& ACC_VOLATILE
) FIELD_VOLATILE (field
) = 1;
778 if (flags
& ACC_TRANSIENT
) FIELD_TRANSIENT (field
) = 1;
781 FIELD_STATIC (field
) = 1;
782 /* Always make field externally visible. This is required so
783 that native methods can always access the field. */
784 TREE_PUBLIC (field
) = 1;
785 /* Considered external until we know what classes are being
786 compiled into this object file. */
787 DECL_EXTERNAL (field
) = 1;
793 /* Associate a constant value CONSTANT with VAR_DECL FIELD. */
796 set_constant_value (tree field
, tree constant
)
798 if (field
== NULL_TREE
)
799 warning ("misplaced ConstantValue attribute (not in any field)");
800 else if (DECL_INITIAL (field
) != NULL_TREE
)
801 warning ("duplicate ConstantValue attribute for field '%s'",
802 IDENTIFIER_POINTER (DECL_NAME (field
)));
805 DECL_INITIAL (field
) = constant
;
806 if (TREE_TYPE (constant
) != TREE_TYPE (field
)
807 && ! (TREE_TYPE (constant
) == int_type_node
808 && INTEGRAL_TYPE_P (TREE_TYPE (field
))
809 && TYPE_PRECISION (TREE_TYPE (field
)) <= 32)
810 && ! (TREE_TYPE (constant
) == utf8const_ptr_type
811 && TREE_TYPE (field
) == string_ptr_type_node
))
812 error ("ConstantValue attribute of field '%s' has wrong type",
813 IDENTIFIER_POINTER (DECL_NAME (field
)));
814 if (FIELD_FINAL (field
))
815 DECL_FIELD_FINAL_IUD (field
) = 1;
819 /* Count the number of Unicode chars encoded in a given Ut8 string. */
823 strLengthUtf8 (char *str
, int len
)
825 register unsigned char* ptr
= (unsigned char*) str
;
826 register unsigned char *limit
= ptr
+ len
;
828 for (; ptr
< limit
; str_length
++) {
829 if (UTF8_GET (ptr
, limit
) < 0)
837 /* Calculate a hash value for a string encoded in Utf8 format.
838 * This returns the same hash value as specified for java.lang.String.hashCode.
842 hashUtf8String (const char *str
, int len
)
844 const unsigned char* ptr
= (const unsigned char*) str
;
845 const unsigned char *limit
= ptr
+ len
;
849 int ch
= UTF8_GET (ptr
, limit
);
850 /* Updated specification from
851 http://www.javasoft.com/docs/books/jls/clarify.html. */
852 hash
= (31 * hash
) + ch
;
857 static GTY(()) tree utf8_decl_list
= NULL_TREE
;
860 build_utf8_ref (tree name
)
862 const char * name_ptr
= IDENTIFIER_POINTER(name
);
863 int name_len
= IDENTIFIER_LENGTH(name
);
865 tree ctype
, field
= NULL_TREE
, str_type
, cinit
, string
;
866 static int utf8_count
= 0;
868 tree ref
= IDENTIFIER_UTF8_REF (name
);
870 if (ref
!= NULL_TREE
)
873 ctype
= make_node (RECORD_TYPE
);
874 str_type
= build_prim_array_type (unsigned_byte_type_node
,
875 name_len
+ 1); /* Allow for final '\0'. */
876 PUSH_FIELD (ctype
, field
, "hash", unsigned_short_type_node
);
877 PUSH_FIELD (ctype
, field
, "length", unsigned_short_type_node
);
878 PUSH_FIELD (ctype
, field
, "data", str_type
);
879 FINISH_RECORD (ctype
);
880 START_RECORD_CONSTRUCTOR (cinit
, ctype
);
881 name_hash
= hashUtf8String (name_ptr
, name_len
) & 0xFFFF;
882 PUSH_FIELD_VALUE (cinit
, "hash", build_int_cst (NULL_TREE
, name_hash
));
883 PUSH_FIELD_VALUE (cinit
, "length", build_int_cst (NULL_TREE
, name_len
));
884 string
= build_string (name_len
, name_ptr
);
885 TREE_TYPE (string
) = str_type
;
886 PUSH_FIELD_VALUE (cinit
, "data", string
);
887 FINISH_RECORD_CONSTRUCTOR (cinit
);
888 TREE_CONSTANT (cinit
) = 1;
889 TREE_INVARIANT (cinit
) = 1;
891 /* Generate a unique-enough identifier. */
892 sprintf(buf
, "_Utf%d", ++utf8_count
);
894 decl
= build_decl (VAR_DECL
, get_identifier (buf
), utf8const_type
);
895 TREE_STATIC (decl
) = 1;
896 DECL_ARTIFICIAL (decl
) = 1;
897 DECL_IGNORED_P (decl
) = 1;
898 TREE_READONLY (decl
) = 1;
899 TREE_THIS_VOLATILE (decl
) = 0;
900 DECL_INITIAL (decl
) = cinit
;
902 if (HAVE_GAS_SHF_MERGE
)
905 /* Ensure decl_size is a multiple of utf8const_type's alignment. */
906 decl_size
= (name_len
+ 5 + TYPE_ALIGN_UNIT (utf8const_type
) - 1)
907 & ~(TYPE_ALIGN_UNIT (utf8const_type
) - 1);
908 if (flag_merge_constants
&& decl_size
< 256)
911 int flags
= (SECTION_OVERRIDE
912 | SECTION_MERGE
| (SECTION_ENTSIZE
& decl_size
));
913 sprintf (buf
, ".rodata.jutf8.%d", decl_size
);
914 named_section_flags (buf
, flags
);
915 DECL_SECTION_NAME (decl
) = build_string (strlen (buf
), buf
);
919 TREE_CHAIN (decl
) = utf8_decl_list
;
920 layout_decl (decl
, 0);
922 rest_of_decl_compilation (decl
, global_bindings_p (), 0);
923 utf8_decl_list
= decl
;
924 make_decl_rtl (decl
);
925 ref
= build1 (ADDR_EXPR
, utf8const_ptr_type
, decl
);
926 IDENTIFIER_UTF8_REF (name
) = ref
;
930 /* Like build_class_ref, but instead of a direct reference generate a
931 pointer into the constant pool. */
934 build_indirect_class_ref (tree type
)
938 index
= alloc_class_constant (type
);
939 cl
= build_ref_from_constant_pool (index
);
940 return convert (promote_type (class_ptr_type
), cl
);
943 /* Build a reference to the class TYPE.
944 Also handles primitive types and array types. */
947 build_class_ref (tree type
)
949 int is_compiled
= is_compiled_class (type
);
952 tree ref
, decl_name
, decl
;
953 if (TREE_CODE (type
) == POINTER_TYPE
)
954 type
= TREE_TYPE (type
);
956 /* FIXME: we really want an indirect reference to our
957 superclass. However, libgcj assumes that a superclass
958 pointer always points directly to a class. As a workaround
959 we always emit this hard superclass reference. */
960 if (flag_indirect_dispatch
961 && type
!= output_class
962 && type
!= CLASSTYPE_SUPER (output_class
)
963 && TREE_CODE (type
) == RECORD_TYPE
)
964 return build_indirect_class_ref (type
);
966 if (TREE_CODE (type
) == RECORD_TYPE
)
968 if (TYPE_SIZE (type
) == error_mark_node
)
969 return null_pointer_node
;
970 decl_name
= identifier_subst (DECL_NAME (TYPE_NAME (type
)),
971 "", '/', '/', ".class");
972 decl
= IDENTIFIER_GLOBAL_VALUE (decl_name
);
973 if (decl
== NULL_TREE
)
975 decl
= build_decl (VAR_DECL
, decl_name
, class_type_node
);
976 DECL_SIZE (decl
) = TYPE_SIZE (class_type_node
);
977 DECL_SIZE_UNIT (decl
) = TYPE_SIZE_UNIT (class_type_node
);
978 TREE_STATIC (decl
) = 1;
979 TREE_PUBLIC (decl
) = 1;
980 DECL_IGNORED_P (decl
) = 1;
981 DECL_ARTIFICIAL (decl
) = 1;
982 if (is_compiled
== 1)
983 DECL_EXTERNAL (decl
) = 1;
984 SET_DECL_ASSEMBLER_NAME (decl
,
985 java_mangle_class_field
986 (&temporary_obstack
, type
));
987 make_decl_rtl (decl
);
988 pushdecl_top_level (decl
);
995 if (flag_emit_class_files
)
997 const char *prim_class_name
;
999 if (type
== char_type_node
)
1000 prim_class_name
= "java.lang.Character";
1001 else if (type
== boolean_type_node
)
1002 prim_class_name
= "java.lang.Boolean";
1003 else if (type
== byte_type_node
)
1004 prim_class_name
= "java.lang.Byte";
1005 else if (type
== short_type_node
)
1006 prim_class_name
= "java.lang.Short";
1007 else if (type
== int_type_node
)
1008 prim_class_name
= "java.lang.Integer";
1009 else if (type
== long_type_node
)
1010 prim_class_name
= "java.lang.Long";
1011 else if (type
== float_type_node
)
1012 prim_class_name
= "java.lang.Float";
1013 else if (type
== double_type_node
)
1014 prim_class_name
= "java.lang.Double";
1015 else if (type
== void_type_node
)
1016 prim_class_name
= "java.lang.Void";
1020 prim_class
= lookup_class (get_identifier (prim_class_name
));
1021 return build3 (COMPONENT_REF
, NULL_TREE
,
1022 prim_class
, TYPE_identifier_node
, NULL_TREE
);
1024 decl_name
= TYPE_NAME (type
);
1025 if (TREE_CODE (decl_name
) == TYPE_DECL
)
1026 decl_name
= DECL_NAME (decl_name
);
1027 name
= IDENTIFIER_POINTER (decl_name
);
1028 if (strncmp (name
, "promoted_", 9) == 0)
1030 sprintf (buffer
, "_Jv_%sClass", name
);
1031 decl_name
= get_identifier (buffer
);
1032 decl
= IDENTIFIER_GLOBAL_VALUE (decl_name
);
1033 if (decl
== NULL_TREE
)
1035 decl
= build_decl (VAR_DECL
, decl_name
, class_type_node
);
1036 TREE_STATIC (decl
) = 1;
1037 TREE_PUBLIC (decl
) = 1;
1038 DECL_EXTERNAL (decl
) = 1;
1039 DECL_ARTIFICIAL (decl
) = 1;
1040 make_decl_rtl (decl
);
1041 pushdecl_top_level (decl
);
1045 ref
= build1 (ADDR_EXPR
, class_ptr_type
, decl
);
1049 return build_indirect_class_ref (type
);
1053 build_static_field_ref (tree fdecl
)
1055 tree fclass
= DECL_CONTEXT (fdecl
);
1056 int is_compiled
= is_compiled_class (fclass
);
1058 /* Allow static final fields to fold to a constant. When using
1059 -fno-assume-compiled, gcj will sometimes try to fold a field from
1060 an uncompiled class. This is required when the field in question
1061 meets the appropriate criteria for a compile-time constant.
1062 However, currently sometimes gcj is too eager and will end up
1063 returning the field itself, leading to an incorrect external
1064 reference being generated. */
1066 && (! flag_indirect_dispatch
|| current_class
== fclass
))
1067 || (FIELD_FINAL (fdecl
) && DECL_INITIAL (fdecl
) != NULL_TREE
1068 && (JSTRING_TYPE_P (TREE_TYPE (fdecl
))
1069 || JNUMERIC_TYPE_P (TREE_TYPE (fdecl
)))
1070 && TREE_CONSTANT (DECL_INITIAL (fdecl
))))
1072 if (!DECL_RTL_SET_P (fdecl
))
1074 if (is_compiled
== 1)
1075 DECL_EXTERNAL (fdecl
) = 1;
1076 make_decl_rtl (fdecl
);
1081 if (flag_indirect_dispatch
)
1084 = build_int_cst (NULL_TREE
, get_symbol_table_index
1085 (fdecl
, &TYPE_ATABLE_METHODS (output_class
)));
1087 = build4 (ARRAY_REF
, build_pointer_type (TREE_TYPE (fdecl
)),
1088 TYPE_ATABLE_DECL (output_class
), table_index
,
1089 NULL_TREE
, NULL_TREE
);
1090 return fold (build1 (INDIRECT_REF
, TREE_TYPE (fdecl
),
1096 * *(FTYPE*)build_class_ref(FCLASS)->fields[INDEX].info.addr */
1097 tree ref
= build_class_ref (fclass
);
1099 int field_index
= 0;
1100 ref
= build1 (INDIRECT_REF
, class_type_node
, ref
);
1101 ref
= build3 (COMPONENT_REF
, field_ptr_type_node
, ref
,
1102 lookup_field (&class_type_node
, fields_ident
),
1105 for (fld
= TYPE_FIELDS (fclass
); ; fld
= TREE_CHAIN (fld
))
1109 if (fld
== NULL_TREE
)
1110 fatal_error ("field '%s' not found in class",
1111 IDENTIFIER_POINTER (DECL_NAME (fdecl
)));
1112 if (FIELD_STATIC (fld
))
1115 field_index
*= int_size_in_bytes (field_type_node
);
1116 ref
= fold (build2 (PLUS_EXPR
, field_ptr_type_node
,
1117 ref
, build_int_cst (NULL_TREE
, field_index
)));
1118 ref
= build1 (INDIRECT_REF
, field_type_node
, ref
);
1119 ref
= build3 (COMPONENT_REF
, field_info_union_node
,
1120 ref
, lookup_field (&field_type_node
, info_ident
),
1122 ref
= build3 (COMPONENT_REF
, ptr_type_node
,
1123 ref
, TREE_CHAIN (TYPE_FIELDS (field_info_union_node
)),
1125 ref
= build1 (NOP_EXPR
, build_pointer_type (TREE_TYPE (fdecl
)), ref
);
1126 return fold (build1 (INDIRECT_REF
, TREE_TYPE(fdecl
), ref
));
1131 get_access_flags_from_decl (tree decl
)
1133 int access_flags
= 0;
1134 if (TREE_CODE (decl
) == FIELD_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
1136 if (FIELD_STATIC (decl
))
1137 access_flags
|= ACC_STATIC
;
1138 if (FIELD_PUBLIC (decl
))
1139 access_flags
|= ACC_PUBLIC
;
1140 if (FIELD_PROTECTED (decl
))
1141 access_flags
|= ACC_PROTECTED
;
1142 if (FIELD_PRIVATE (decl
))
1143 access_flags
|= ACC_PRIVATE
;
1144 if (FIELD_FINAL (decl
))
1145 access_flags
|= ACC_FINAL
;
1146 if (FIELD_VOLATILE (decl
))
1147 access_flags
|= ACC_VOLATILE
;
1148 if (FIELD_TRANSIENT (decl
))
1149 access_flags
|= ACC_TRANSIENT
;
1150 return access_flags
;
1152 if (TREE_CODE (decl
) == TYPE_DECL
)
1154 if (CLASS_PUBLIC (decl
))
1155 access_flags
|= ACC_PUBLIC
;
1156 if (CLASS_FINAL (decl
))
1157 access_flags
|= ACC_FINAL
;
1158 if (CLASS_SUPER (decl
))
1159 access_flags
|= ACC_SUPER
;
1160 if (CLASS_INTERFACE (decl
))
1161 access_flags
|= ACC_INTERFACE
;
1162 if (CLASS_ABSTRACT (decl
))
1163 access_flags
|= ACC_ABSTRACT
;
1164 if (CLASS_STATIC (decl
))
1165 access_flags
|= ACC_STATIC
;
1166 if (CLASS_PRIVATE (decl
))
1167 access_flags
|= ACC_PRIVATE
;
1168 if (CLASS_PROTECTED (decl
))
1169 access_flags
|= ACC_PROTECTED
;
1170 if (CLASS_STRICTFP (decl
))
1171 access_flags
|= ACC_STRICT
;
1172 return access_flags
;
1174 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1176 if (METHOD_PUBLIC (decl
))
1177 access_flags
|= ACC_PUBLIC
;
1178 if (METHOD_PRIVATE (decl
))
1179 access_flags
|= ACC_PRIVATE
;
1180 if (METHOD_PROTECTED (decl
))
1181 access_flags
|= ACC_PROTECTED
;
1182 if (METHOD_STATIC (decl
))
1183 access_flags
|= ACC_STATIC
;
1184 if (METHOD_FINAL (decl
))
1185 access_flags
|= ACC_FINAL
;
1186 if (METHOD_SYNCHRONIZED (decl
))
1187 access_flags
|= ACC_SYNCHRONIZED
;
1188 if (METHOD_NATIVE (decl
))
1189 access_flags
|= ACC_NATIVE
;
1190 if (METHOD_ABSTRACT (decl
))
1191 access_flags
|= ACC_ABSTRACT
;
1192 if (METHOD_STRICTFP (decl
))
1193 access_flags
|= ACC_STRICT
;
1194 if (METHOD_INVISIBLE (decl
))
1195 access_flags
|= ACC_INVISIBLE
;
1196 return access_flags
;
1201 static GTY (()) int alias_labelno
= 0;
1203 /* Create a private alias for METHOD. Using this alias instead of the method
1204 decl ensures that ncode entries in the method table point to the real function
1205 at runtime, not a PLT entry. */
1208 make_local_function_alias (tree method
)
1210 #ifdef ASM_OUTPUT_DEF
1212 const char *method_name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (method
));
1213 char *name
= alloca (strlen (method_name
) + 2);
1214 char *buf
= alloca (strlen (method_name
) + 128);
1216 /* Prefix method_name with 'L' for the alias label. */
1218 strcpy (name
+ 1, method_name
);
1220 ASM_GENERATE_INTERNAL_LABEL (buf
, name
, alias_labelno
++);
1221 alias
= build_decl (FUNCTION_DECL
, get_identifier (buf
),
1222 TREE_TYPE (method
));
1223 DECL_CONTEXT (alias
) = NULL
;
1224 TREE_READONLY (alias
) = TREE_READONLY (method
);
1225 TREE_THIS_VOLATILE (alias
) = TREE_THIS_VOLATILE (method
);
1226 TREE_PUBLIC (alias
) = 0;
1227 DECL_EXTERNAL (alias
) = 0;
1228 DECL_ARTIFICIAL (alias
) = 1;
1229 DECL_INLINE (alias
) = 0;
1230 DECL_INITIAL (alias
) = error_mark_node
;
1231 TREE_ADDRESSABLE (alias
) = 1;
1232 TREE_USED (alias
) = 1;
1233 SET_DECL_ASSEMBLER_NAME (alias
, DECL_NAME (alias
));
1234 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias
)) = 1;
1235 if (!flag_syntax_only
)
1236 assemble_alias (alias
, DECL_ASSEMBLER_NAME (method
));
1243 /** Make reflection data (_Jv_Field) for field FDECL. */
1246 make_field_value (tree fdecl
)
1250 tree type
= TREE_TYPE (fdecl
);
1251 int resolved
= is_compiled_class (type
) && ! flag_indirect_dispatch
;
1253 START_RECORD_CONSTRUCTOR (finit
, field_type_node
);
1254 PUSH_FIELD_VALUE (finit
, "name", build_utf8_ref (DECL_NAME (fdecl
)));
1256 type
= build_class_ref (type
);
1259 tree signature
= build_java_signature (type
);
1261 type
= build_utf8_ref (unmangle_classname
1262 (IDENTIFIER_POINTER (signature
),
1263 IDENTIFIER_LENGTH (signature
)));
1265 PUSH_FIELD_VALUE (finit
, "type", type
);
1267 flags
= get_access_flags_from_decl (fdecl
);
1269 flags
|= 0x8000 /* FIELD_UNRESOLVED_FLAG */;
1271 PUSH_FIELD_VALUE (finit
, "accflags", build_int_cst (NULL_TREE
, flags
));
1272 PUSH_FIELD_VALUE (finit
, "bsize", TYPE_SIZE_UNIT (TREE_TYPE (fdecl
)));
1276 build_constructor (field_info_union_node
,
1278 ((FIELD_STATIC (fdecl
)
1279 ? TREE_CHAIN (TYPE_FIELDS (field_info_union_node
))
1280 : TYPE_FIELDS (field_info_union_node
)),
1281 (FIELD_STATIC (fdecl
)
1282 ? build_address_of (build_static_field_ref (fdecl
))
1283 : byte_position (fdecl
)))));
1285 FINISH_RECORD_CONSTRUCTOR (finit
);
1289 /** Make reflection data (_Jv_Method) for method MDECL. */
1292 make_method_value (tree mdecl
)
1294 static int method_name_count
= 0;
1299 #define ACC_TRANSLATED 0x4000
1300 int accflags
= get_access_flags_from_decl (mdecl
) | ACC_TRANSLATED
;
1302 class_decl
= DECL_CONTEXT (mdecl
);
1303 /* For interfaces, the index field contains the dispatch index. */
1304 if (CLASS_INTERFACE (TYPE_NAME (class_decl
)))
1305 index
= build_int_cst (NULL_TREE
,
1306 get_interface_method_index (mdecl
, class_decl
));
1307 else if (!flag_indirect_dispatch
&& get_method_index (mdecl
) != NULL_TREE
)
1308 index
= get_method_index (mdecl
);
1310 index
= integer_minus_one_node
;
1312 code
= null_pointer_node
;
1313 if (DECL_RTL_SET_P (mdecl
))
1314 code
= build1 (ADDR_EXPR
, nativecode_ptr_type_node
,
1315 make_local_function_alias (mdecl
));
1316 START_RECORD_CONSTRUCTOR (minit
, method_type_node
);
1317 PUSH_FIELD_VALUE (minit
, "name",
1318 build_utf8_ref (DECL_CONSTRUCTOR_P (mdecl
) ?
1319 init_identifier_node
1320 : DECL_NAME (mdecl
)));
1322 tree signature
= build_java_signature (TREE_TYPE (mdecl
));
1323 PUSH_FIELD_VALUE (minit
, "signature",
1326 (IDENTIFIER_POINTER(signature
),
1327 IDENTIFIER_LENGTH(signature
)))));
1329 PUSH_FIELD_VALUE (minit
, "accflags", build_int_cst (NULL_TREE
, accflags
));
1330 PUSH_FIELD_VALUE (minit
, "index", index
);
1331 PUSH_FIELD_VALUE (minit
, "ncode", code
);
1334 /* Compute the `throws' information for the method. */
1335 tree table
= null_pointer_node
;
1336 if (DECL_FUNCTION_THROWS (mdecl
) != NULL_TREE
)
1338 int length
= 1 + list_length (DECL_FUNCTION_THROWS (mdecl
));
1339 tree iter
, type
, array
;
1342 table
= tree_cons (NULL_TREE
, table
, NULL_TREE
);
1343 for (iter
= DECL_FUNCTION_THROWS (mdecl
);
1345 iter
= TREE_CHAIN (iter
))
1347 tree sig
= DECL_NAME (TYPE_NAME (TREE_VALUE (iter
)));
1349 = build_utf8_ref (unmangle_classname (IDENTIFIER_POINTER (sig
),
1350 IDENTIFIER_LENGTH (sig
)));
1351 table
= tree_cons (NULL_TREE
, utf8
, table
);
1353 type
= build_prim_array_type (ptr_type_node
, length
);
1354 table
= build_constructor (type
, table
);
1355 /* Compute something unique enough. */
1356 sprintf (buf
, "_methods%d", method_name_count
++);
1357 array
= build_decl (VAR_DECL
, get_identifier (buf
), type
);
1358 DECL_INITIAL (array
) = table
;
1359 TREE_STATIC (array
) = 1;
1360 DECL_ARTIFICIAL (array
) = 1;
1361 DECL_IGNORED_P (array
) = 1;
1362 rest_of_decl_compilation (array
, 1, 0);
1364 table
= build1 (ADDR_EXPR
, ptr_type_node
, array
);
1367 PUSH_FIELD_VALUE (minit
, "throws", table
);
1370 FINISH_RECORD_CONSTRUCTOR (minit
);
1375 get_dispatch_vector (tree type
)
1377 tree vtable
= TYPE_VTABLE (type
);
1379 if (vtable
== NULL_TREE
)
1383 tree super
= CLASSTYPE_SUPER (type
);
1384 HOST_WIDE_INT nvirtuals
= tree_low_cst (TYPE_NVIRTUALS (type
), 0);
1385 vtable
= make_tree_vec (nvirtuals
);
1386 TYPE_VTABLE (type
) = vtable
;
1387 if (super
!= NULL_TREE
)
1389 tree super_vtable
= get_dispatch_vector (super
);
1391 for (i
= tree_low_cst (TYPE_NVIRTUALS (super
), 0); --i
>= 0; )
1392 TREE_VEC_ELT (vtable
, i
) = TREE_VEC_ELT (super_vtable
, i
);
1395 for (method
= TYPE_METHODS (type
); method
!= NULL_TREE
;
1396 method
= TREE_CHAIN (method
))
1398 tree method_index
= get_method_index (method
);
1399 if (method_index
!= NULL_TREE
1400 && host_integerp (method_index
, 0))
1401 TREE_VEC_ELT (vtable
, tree_low_cst (method_index
, 0)) = method
;
1409 get_dispatch_table (tree type
, tree this_class_addr
)
1411 int abstract_p
= CLASS_ABSTRACT (TYPE_NAME (type
));
1412 tree vtable
= get_dispatch_vector (type
);
1414 tree list
= NULL_TREE
;
1415 int nvirtuals
= TREE_VEC_LENGTH (vtable
);
1419 for (i
= nvirtuals
; --i
>= 0; )
1421 tree method
= TREE_VEC_ELT (vtable
, i
);
1422 if (METHOD_ABSTRACT (method
))
1425 warning ("%Jabstract method in non-abstract class", method
);
1427 if (TARGET_VTABLE_USES_DESCRIPTORS
)
1428 for (j
= 0; j
< TARGET_VTABLE_USES_DESCRIPTORS
; ++j
)
1429 list
= tree_cons (NULL_TREE
, null_pointer_node
, list
);
1431 list
= tree_cons (NULL_TREE
, null_pointer_node
, list
);
1435 if (!DECL_RTL_SET_P (method
))
1436 make_decl_rtl (method
);
1438 if (TARGET_VTABLE_USES_DESCRIPTORS
)
1439 for (j
= 0; j
< TARGET_VTABLE_USES_DESCRIPTORS
; ++j
)
1441 tree fdesc
= build2 (FDESC_EXPR
, nativecode_ptr_type_node
,
1442 method
, build_int_cst (NULL_TREE
, j
));
1443 TREE_CONSTANT (fdesc
) = 1;
1444 TREE_INVARIANT (fdesc
) = 1;
1445 list
= tree_cons (NULL_TREE
, fdesc
, list
);
1448 list
= tree_cons (NULL_TREE
,
1449 build1 (ADDR_EXPR
, nativecode_ptr_type_node
,
1455 /* Dummy entry for compatibility with G++ -fvtable-thunks. When
1456 using the Boehm GC we sometimes stash a GC type descriptor
1457 there. We set the PURPOSE to NULL_TREE not to interfere (reset)
1458 the emitted byte count during the output to the assembly file. */
1459 /* With TARGET_VTABLE_USES_DESCRIPTORS, we only add one extra
1460 fake "function descriptor". It's first word is the is the class
1461 pointer, and subsequent words (usually one) contain the GC descriptor.
1462 In all other cases, we reserve two extra vtable slots. */
1463 gc_descr
= get_boehm_type_descriptor (type
);
1464 list
= tree_cons (NULL_TREE
, gc_descr
, list
);
1465 for (j
= 1; j
< TARGET_VTABLE_USES_DESCRIPTORS
-1; ++j
)
1466 list
= tree_cons (NULL_TREE
, gc_descr
, list
);
1467 list
= tree_cons (NULL_TREE
, this_class_addr
, list
);
1469 /** Pointer to type_info object (to be implemented), according to g++ ABI. */
1470 list
= tree_cons (NULL_TREE
, null_pointer_node
, list
);
1471 /** Offset to start of whole object. Always (ptrdiff_t)0 for Java. */
1472 list
= tree_cons (integer_zero_node
, null_pointer_node
, list
);
1474 arraysize
= (TARGET_VTABLE_USES_DESCRIPTORS
? nvirtuals
+ 1 : nvirtuals
+ 2);
1475 if (TARGET_VTABLE_USES_DESCRIPTORS
)
1476 arraysize
*= TARGET_VTABLE_USES_DESCRIPTORS
;
1478 return build_constructor (build_prim_array_type (nativecode_ptr_type_node
,
1483 /* Set the method_index for a method decl. */
1485 set_method_index (tree decl
, tree method_index
)
1487 method_index
= fold (convert (sizetype
, method_index
));
1489 if (TARGET_VTABLE_USES_DESCRIPTORS
)
1490 /* Add one to skip bogus descriptor for class and GC descriptor. */
1491 method_index
= size_binop (PLUS_EXPR
, method_index
, size_int (1));
1493 /* Add 1 to skip "class" field of dtable, and 1 to skip GC descriptor. */
1494 method_index
= size_binop (PLUS_EXPR
, method_index
, size_int (2));
1496 DECL_VINDEX (decl
) = method_index
;
1499 /* Get the method_index for a method decl. */
1501 get_method_index (tree decl
)
1503 tree method_index
= DECL_VINDEX (decl
);
1508 if (TARGET_VTABLE_USES_DESCRIPTORS
)
1509 /* Sub one to skip bogus descriptor for class and GC descriptor. */
1510 method_index
= size_binop (MINUS_EXPR
, method_index
, size_int (1));
1512 /* Sub 1 to skip "class" field of dtable, and 1 to skip GC descriptor. */
1513 method_index
= size_binop (MINUS_EXPR
, method_index
, size_int (2));
1515 return method_index
;
1519 supers_all_compiled (tree type
)
1521 while (type
!= NULL_TREE
)
1523 if (!assume_compiled (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)))))
1525 type
= CLASSTYPE_SUPER (type
);
1531 make_class_data (tree type
)
1533 tree decl
, cons
, temp
;
1534 tree field
, fields_decl
;
1535 tree static_fields
= NULL_TREE
;
1536 tree instance_fields
= NULL_TREE
;
1537 HOST_WIDE_INT static_field_count
= 0;
1538 HOST_WIDE_INT instance_field_count
= 0;
1539 HOST_WIDE_INT field_count
;
1540 tree field_array_type
;
1542 tree methods
= NULL_TREE
;
1543 tree dtable_decl
= NULL_TREE
;
1544 HOST_WIDE_INT method_count
= 0;
1545 tree method_array_type
;
1548 tree this_class_addr
;
1549 tree constant_pool_constructor
;
1550 tree interfaces
= null_pointer_node
;
1551 int interface_len
= 0;
1552 tree type_decl
= TYPE_NAME (type
);
1553 /** Offset from start of virtual function table declaration
1554 to where objects actually point at, following new g++ ABI. */
1555 tree dtable_start_offset
= build_int_cst (NULL_TREE
,
1556 2 * POINTER_SIZE
/ BITS_PER_UNIT
);
1558 this_class_addr
= build_class_ref (type
);
1559 decl
= TREE_OPERAND (this_class_addr
, 0);
1561 /* Build Field array. */
1562 field
= TYPE_FIELDS (type
);
1563 if (DECL_NAME (field
) == NULL_TREE
)
1564 field
= TREE_CHAIN (field
); /* Skip dummy field for inherited data. */
1565 for ( ; field
!= NULL_TREE
; field
= TREE_CHAIN (field
))
1567 if (! DECL_ARTIFICIAL (field
))
1569 tree init
= make_field_value (field
);
1570 if (FIELD_STATIC (field
))
1572 tree initial
= DECL_INITIAL (field
);
1573 static_field_count
++;
1574 static_fields
= tree_cons (NULL_TREE
, init
, static_fields
);
1575 /* If the initial value is a string constant,
1576 prevent output_constant from trying to assemble the value. */
1577 if (initial
!= NULL_TREE
1578 && TREE_TYPE (initial
) == string_ptr_type_node
)
1579 DECL_INITIAL (field
) = NULL_TREE
;
1580 rest_of_decl_compilation (field
, 1, 1);
1581 DECL_INITIAL (field
) = initial
;
1585 instance_field_count
++;
1586 instance_fields
= tree_cons (NULL_TREE
, init
, instance_fields
);
1590 field_count
= static_field_count
+ instance_field_count
;
1591 if (field_count
> 0)
1593 static_fields
= nreverse (static_fields
);
1594 instance_fields
= nreverse (instance_fields
);
1595 static_fields
= chainon (static_fields
, instance_fields
);
1596 field_array_type
= build_prim_array_type (field_type_node
, field_count
);
1597 fields_decl
= build_decl (VAR_DECL
, mangled_classname ("_FL_", type
),
1599 DECL_INITIAL (fields_decl
) = build_constructor (field_array_type
,
1601 TREE_STATIC (fields_decl
) = 1;
1602 DECL_ARTIFICIAL (fields_decl
) = 1;
1603 DECL_IGNORED_P (fields_decl
) = 1;
1604 rest_of_decl_compilation (fields_decl
, 1, 0);
1607 fields_decl
= NULL_TREE
;
1609 /* Build Method array. */
1610 for (method
= TYPE_METHODS (type
);
1611 method
!= NULL_TREE
; method
= TREE_CHAIN (method
))
1614 if (METHOD_PRIVATE (method
)
1615 && ! flag_keep_inline_functions
1616 && (flag_inline_functions
|| optimize
))
1618 init
= make_method_value (method
);
1620 methods
= tree_cons (NULL_TREE
, init
, methods
);
1622 method_array_type
= build_prim_array_type (method_type_node
, method_count
);
1623 methods_decl
= build_decl (VAR_DECL
, mangled_classname ("_MT_", type
),
1625 DECL_INITIAL (methods_decl
) = build_constructor (method_array_type
,
1626 nreverse (methods
));
1627 TREE_STATIC (methods_decl
) = 1;
1628 DECL_ARTIFICIAL (methods_decl
) = 1;
1629 DECL_IGNORED_P (methods_decl
) = 1;
1630 rest_of_decl_compilation (methods_decl
, 1, 0);
1632 if (supers_all_compiled (type
) && ! CLASS_INTERFACE (type_decl
)
1633 && !flag_indirect_dispatch
)
1635 tree dtable
= get_dispatch_table (type
, this_class_addr
);
1636 dtable_decl
= build_dtable_decl (type
);
1637 DECL_INITIAL (dtable_decl
) = dtable
;
1638 TREE_STATIC (dtable_decl
) = 1;
1639 DECL_ARTIFICIAL (dtable_decl
) = 1;
1640 DECL_IGNORED_P (dtable_decl
) = 1;
1641 TREE_PUBLIC (dtable_decl
) = 1;
1642 rest_of_decl_compilation (dtable_decl
, 1, 0);
1643 if (type
== class_type_node
)
1644 class_dtable_decl
= dtable_decl
;
1647 if (class_dtable_decl
== NULL_TREE
)
1649 class_dtable_decl
= build_dtable_decl (class_type_node
);
1650 TREE_STATIC (class_dtable_decl
) = 1;
1651 DECL_ARTIFICIAL (class_dtable_decl
) = 1;
1652 DECL_IGNORED_P (class_dtable_decl
) = 1;
1653 if (is_compiled_class (class_type_node
) != 2)
1654 DECL_EXTERNAL (class_dtable_decl
) = 1;
1655 rest_of_decl_compilation (class_dtable_decl
, 1, 0);
1658 super
= CLASSTYPE_SUPER (type
);
1659 if (super
== NULL_TREE
)
1660 super
= null_pointer_node
;
1661 else if (/* FIXME: we should also test for (!
1662 flag_indirect_dispatch) here, but libgcj can't cope with
1663 a symbolic reference a superclass in the class data. */
1664 assume_compiled (IDENTIFIER_POINTER (DECL_NAME (type_decl
)))
1665 && assume_compiled (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (super
)))))
1666 super
= build_class_ref (super
);
1669 int super_index
= alloc_class_constant (super
);
1670 super
= build_int_cst (ptr_type_node
, super_index
);
1673 /* Build and emit the array of implemented interfaces. */
1674 if (type
!= object_type_node
)
1675 interface_len
= BINFO_N_BASE_BINFOS (TYPE_BINFO (type
)) - 1;
1677 if (interface_len
> 0)
1679 tree init
= NULL_TREE
;
1681 tree interface_array_type
, idecl
;
1682 interface_array_type
1683 = build_prim_array_type (class_ptr_type
, interface_len
);
1684 idecl
= build_decl (VAR_DECL
, mangled_classname ("_IF_", type
),
1685 interface_array_type
);
1687 for (i
= interface_len
; i
> 0; i
--)
1689 tree child
= BINFO_BASE_BINFO (TYPE_BINFO (type
), i
);
1690 tree iclass
= BINFO_TYPE (child
);
1692 if (! flag_indirect_dispatch
1694 (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (iclass
))))))
1695 index
= build_class_ref (iclass
);
1698 int int_index
= alloc_class_constant (iclass
);
1699 index
= build_int_cst (ptr_type_node
, int_index
);
1701 init
= tree_cons (NULL_TREE
, index
, init
);
1703 DECL_INITIAL (idecl
) = build_constructor (interface_array_type
, init
);
1704 TREE_STATIC (idecl
) = 1;
1705 DECL_ARTIFICIAL (idecl
) = 1;
1706 DECL_IGNORED_P (idecl
) = 1;
1707 interfaces
= build1 (ADDR_EXPR
, ptr_type_node
, idecl
);
1708 rest_of_decl_compilation (idecl
, 1, 0);
1711 constant_pool_constructor
= build_constants_constructor ();
1713 if (flag_indirect_dispatch
)
1715 TYPE_OTABLE_DECL (type
)
1717 (DECL_NAME (TYPE_OTABLE_DECL (type
)),
1718 TYPE_OTABLE_DECL (type
), TYPE_OTABLE_METHODS (type
),
1719 TYPE_OTABLE_SYMS_DECL (type
), integer_type_node
);
1721 TYPE_ATABLE_DECL (type
)
1723 (DECL_NAME (TYPE_ATABLE_DECL (type
)),
1724 TYPE_ATABLE_DECL (type
), TYPE_ATABLE_METHODS (type
),
1725 TYPE_ATABLE_SYMS_DECL (type
), ptr_type_node
);
1728 TYPE_CTABLE_DECL (type
) = emit_catch_table (type
);
1730 START_RECORD_CONSTRUCTOR (temp
, object_type_node
);
1731 PUSH_FIELD_VALUE (temp
, "vtable",
1732 build2 (PLUS_EXPR
, dtable_ptr_type
,
1733 build1 (ADDR_EXPR
, dtable_ptr_type
,
1735 dtable_start_offset
));
1736 if (! flag_hash_synchronization
)
1737 PUSH_FIELD_VALUE (temp
, "sync_info", null_pointer_node
);
1738 FINISH_RECORD_CONSTRUCTOR (temp
);
1739 START_RECORD_CONSTRUCTOR (cons
, class_type_node
);
1740 PUSH_SUPER_VALUE (cons
, temp
);
1741 PUSH_FIELD_VALUE (cons
, "next", null_pointer_node
);
1742 PUSH_FIELD_VALUE (cons
, "name", build_utf8_ref (DECL_NAME (type_decl
)));
1743 PUSH_FIELD_VALUE (cons
, "accflags",
1744 build_int_cst (NULL_TREE
,
1745 get_access_flags_from_decl (type_decl
)));
1747 PUSH_FIELD_VALUE (cons
, "superclass",
1748 CLASS_INTERFACE (type_decl
) ? null_pointer_node
: super
);
1749 PUSH_FIELD_VALUE (cons
, "constants", constant_pool_constructor
);
1750 PUSH_FIELD_VALUE (cons
, "methods",
1751 build1 (ADDR_EXPR
, method_ptr_type_node
, methods_decl
));
1752 PUSH_FIELD_VALUE (cons
, "method_count",
1753 build_int_cst (NULL_TREE
, method_count
));
1755 if (flag_indirect_dispatch
)
1756 PUSH_FIELD_VALUE (cons
, "vtable_method_count", integer_minus_one_node
);
1758 PUSH_FIELD_VALUE (cons
, "vtable_method_count", TYPE_NVIRTUALS (type
));
1760 PUSH_FIELD_VALUE (cons
, "fields",
1761 fields_decl
== NULL_TREE
? null_pointer_node
1762 : build1 (ADDR_EXPR
, field_ptr_type_node
, fields_decl
));
1763 PUSH_FIELD_VALUE (cons
, "size_in_bytes", size_in_bytes (type
));
1764 PUSH_FIELD_VALUE (cons
, "field_count",
1765 build_int_cst (NULL_TREE
, field_count
));
1766 PUSH_FIELD_VALUE (cons
, "static_field_count",
1767 build_int_cst (NULL_TREE
, static_field_count
));
1769 if (flag_indirect_dispatch
)
1770 PUSH_FIELD_VALUE (cons
, "vtable", null_pointer_node
);
1772 PUSH_FIELD_VALUE (cons
, "vtable",
1773 dtable_decl
== NULL_TREE
? null_pointer_node
1774 : build2 (PLUS_EXPR
, dtable_ptr_type
,
1775 build1 (ADDR_EXPR
, dtable_ptr_type
,
1777 dtable_start_offset
));
1778 if (TYPE_OTABLE_METHODS (type
) == NULL_TREE
)
1780 PUSH_FIELD_VALUE (cons
, "otable", null_pointer_node
);
1781 PUSH_FIELD_VALUE (cons
, "otable_syms", null_pointer_node
);
1785 PUSH_FIELD_VALUE (cons
, "otable",
1786 build1 (ADDR_EXPR
, otable_ptr_type
, TYPE_OTABLE_DECL (type
)));
1787 PUSH_FIELD_VALUE (cons
, "otable_syms",
1788 build1 (ADDR_EXPR
, symbols_array_ptr_type
,
1789 TYPE_OTABLE_SYMS_DECL (type
)));
1790 TREE_CONSTANT (TYPE_OTABLE_DECL (type
)) = 1;
1791 TREE_INVARIANT (TYPE_OTABLE_DECL (type
)) = 1;
1793 if (TYPE_ATABLE_METHODS(type
) == NULL_TREE
)
1795 PUSH_FIELD_VALUE (cons
, "atable", null_pointer_node
);
1796 PUSH_FIELD_VALUE (cons
, "atable_syms", null_pointer_node
);
1800 PUSH_FIELD_VALUE (cons
, "atable",
1801 build1 (ADDR_EXPR
, atable_ptr_type
, TYPE_ATABLE_DECL (type
)));
1802 PUSH_FIELD_VALUE (cons
, "atable_syms",
1803 build1 (ADDR_EXPR
, symbols_array_ptr_type
,
1804 TYPE_ATABLE_SYMS_DECL (type
)));
1805 TREE_CONSTANT (TYPE_ATABLE_DECL (type
)) = 1;
1806 TREE_INVARIANT (TYPE_ATABLE_DECL (type
)) = 1;
1809 PUSH_FIELD_VALUE (cons
, "catch_classes",
1810 build1 (ADDR_EXPR
, ptr_type_node
, TYPE_CTABLE_DECL (type
)));
1811 PUSH_FIELD_VALUE (cons
, "interfaces", interfaces
);
1812 PUSH_FIELD_VALUE (cons
, "loader", null_pointer_node
);
1813 PUSH_FIELD_VALUE (cons
, "interface_count",
1814 build_int_cst (NULL_TREE
, interface_len
));
1815 PUSH_FIELD_VALUE (cons
, "state", integer_zero_node
);
1817 PUSH_FIELD_VALUE (cons
, "thread", null_pointer_node
);
1818 PUSH_FIELD_VALUE (cons
, "depth", integer_zero_node
);
1819 PUSH_FIELD_VALUE (cons
, "ancestors", null_pointer_node
);
1820 PUSH_FIELD_VALUE (cons
, "idt", null_pointer_node
);
1821 PUSH_FIELD_VALUE (cons
, "arrayclass", null_pointer_node
);
1822 PUSH_FIELD_VALUE (cons
, "protectionDomain", null_pointer_node
);
1823 PUSH_FIELD_VALUE (cons
, "hack_signers", null_pointer_node
);
1824 PUSH_FIELD_VALUE (cons
, "chain", null_pointer_node
);
1825 PUSH_FIELD_VALUE (cons
, "aux_info", null_pointer_node
);
1827 FINISH_RECORD_CONSTRUCTOR (cons
);
1829 DECL_INITIAL (decl
) = cons
;
1831 /* Hash synchronization requires at least 64-bit alignment. */
1832 if (flag_hash_synchronization
&& POINTER_SIZE
< 64)
1833 DECL_ALIGN (decl
) = 64;
1835 rest_of_decl_compilation (decl
, 1, 0);
1841 java_expand_catch_classes (current_class
);
1843 current_function_decl
= NULL_TREE
;
1844 make_class_data (current_class
);
1846 rest_of_decl_compilation (TYPE_NAME (current_class
), 1, 0);
1849 /* Return 2 if CLASS is compiled by this compilation job;
1850 return 1 if CLASS can otherwise be assumed to be compiled;
1851 return 0 if we cannot assume that CLASS is compiled.
1852 Returns 1 for primitive and 0 for array types. */
1854 is_compiled_class (tree
class)
1857 if (TREE_CODE (class) == POINTER_TYPE
)
1858 class = TREE_TYPE (class);
1859 if (TREE_CODE (class) != RECORD_TYPE
) /* Primitive types are static. */
1861 if (TYPE_ARRAY_P (class))
1863 if (class == current_class
)
1866 seen_in_zip
= (TYPE_JCF (class) && JCF_SEEN_IN_ZIP (TYPE_JCF (class)));
1867 if (CLASS_FROM_CURRENTLY_COMPILED_P (class) || seen_in_zip
)
1869 /* The class was seen in the current ZIP file and will be
1870 available as a compiled class in the future but may not have
1871 been loaded already. Load it if necessary. This prevent
1872 build_class_ref () from crashing. */
1874 if (seen_in_zip
&& !CLASS_LOADED_P (class))
1875 load_class (class, 1);
1877 /* We return 2 for class seen in ZIP and class from files
1878 belonging to the same compilation unit */
1882 if (assume_compiled (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class)))))
1884 if (!CLASS_LOADED_P (class))
1886 if (CLASS_FROM_SOURCE_P (class))
1887 safe_layout_class (class);
1889 load_class (class, 1);
1897 /* Build a VAR_DECL for the dispatch table (vtable) for class TYPE. */
1900 build_dtable_decl (tree type
)
1904 /* We need to build a new dtable type so that its size is uniquely
1905 computed when we're dealing with the class for real and not just
1906 faking it (like java.lang.Class during the initialization of the
1907 compiler.) We know we're not faking a class when CURRENT_CLASS is
1909 if (current_class
== type
)
1911 tree dummy
= NULL_TREE
;
1914 dtype
= make_node (RECORD_TYPE
);
1916 PUSH_FIELD (dtype
, dummy
, "top_offset", ptr_type_node
);
1917 PUSH_FIELD (dtype
, dummy
, "type_info", ptr_type_node
);
1919 PUSH_FIELD (dtype
, dummy
, "class", class_ptr_type
);
1920 for (n
= 1; n
< TARGET_VTABLE_USES_DESCRIPTORS
; ++n
)
1922 tree tmp_field
= build_decl (FIELD_DECL
, NULL_TREE
, ptr_type_node
);
1923 TREE_CHAIN (dummy
) = tmp_field
;
1924 DECL_CONTEXT (tmp_field
) = dtype
;
1925 DECL_ARTIFICIAL (tmp_field
) = 1;
1929 PUSH_FIELD (dtype
, dummy
, "gc_descr", ptr_type_node
);
1930 for (n
= 1; n
< TARGET_VTABLE_USES_DESCRIPTORS
; ++n
)
1932 tree tmp_field
= build_decl (FIELD_DECL
, NULL_TREE
, ptr_type_node
);
1933 TREE_CHAIN (dummy
) = tmp_field
;
1934 DECL_CONTEXT (tmp_field
) = dtype
;
1935 DECL_ARTIFICIAL (tmp_field
) = 1;
1939 n
= TREE_VEC_LENGTH (get_dispatch_vector (type
));
1940 if (TARGET_VTABLE_USES_DESCRIPTORS
)
1941 n
*= TARGET_VTABLE_USES_DESCRIPTORS
;
1943 PUSH_FIELD (dtype
, dummy
, "methods",
1944 build_prim_array_type (nativecode_ptr_type_node
, n
));
1945 layout_type (dtype
);
1948 dtype
= dtable_type
;
1950 return build_decl (VAR_DECL
,
1951 java_mangle_vtable (&temporary_obstack
, type
), dtype
);
1954 /* Pre-pend the TYPE_FIELDS of THIS_CLASS with a dummy FIELD_DECL for the
1955 fields inherited from SUPER_CLASS. */
1958 push_super_field (tree this_class
, tree super_class
)
1961 /* Don't insert the field if we're just re-laying the class out. */
1962 if (TYPE_FIELDS (this_class
) && !DECL_NAME (TYPE_FIELDS (this_class
)))
1964 base_decl
= build_decl (FIELD_DECL
, NULL_TREE
, super_class
);
1965 DECL_IGNORED_P (base_decl
) = 1;
1966 TREE_CHAIN (base_decl
) = TYPE_FIELDS (this_class
);
1967 TYPE_FIELDS (this_class
) = base_decl
;
1968 DECL_SIZE (base_decl
) = TYPE_SIZE (super_class
);
1969 DECL_SIZE_UNIT (base_decl
) = TYPE_SIZE_UNIT (super_class
);
1972 /* Handle the different manners we may have to lay out a super class. */
1975 maybe_layout_super_class (tree super_class
, tree this_class
)
1977 if (TREE_CODE (super_class
) == RECORD_TYPE
)
1979 if (!CLASS_LOADED_P (super_class
) && CLASS_FROM_SOURCE_P (super_class
))
1980 safe_layout_class (super_class
);
1981 if (!CLASS_LOADED_P (super_class
))
1982 load_class (super_class
, 1);
1984 /* We might have to layout the class before its dependency on
1985 the super class gets resolved by java_complete_class */
1986 else if (TREE_CODE (super_class
) == POINTER_TYPE
)
1988 if (TREE_TYPE (super_class
) != NULL_TREE
)
1989 super_class
= TREE_TYPE (super_class
);
1992 /* do_resolve_class expects an EXPR_WITH_FILE_LOCATION, so
1994 tree this_wrap
= NULL_TREE
;
1998 tree this_decl
= TYPE_NAME (this_class
);
1999 #ifdef USE_MAPPED_LOCATION
2000 this_wrap
= build_expr_wfl (this_class
,
2001 DECL_SOURCE_LOCATION (this_decl
));
2003 this_wrap
= build_expr_wfl (this_class
,
2004 DECL_SOURCE_FILE (this_decl
),
2005 DECL_SOURCE_LINE (this_decl
), 0);
2008 super_class
= do_resolve_class (NULL_TREE
, /* FIXME? */
2009 super_class
, NULL_TREE
, this_wrap
);
2011 return NULL_TREE
; /* FIXME, NULL_TREE not checked by caller. */
2012 super_class
= TREE_TYPE (super_class
);
2015 if (!TYPE_SIZE (super_class
))
2016 safe_layout_class (super_class
);
2022 layout_class (tree this_class
)
2024 tree super_class
= CLASSTYPE_SUPER (this_class
);
2027 class_list
= tree_cons (this_class
, NULL_TREE
, class_list
);
2028 if (CLASS_BEING_LAIDOUT (this_class
))
2034 sprintf (buffer
, " with '%s'",
2035 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (this_class
))));
2036 obstack_grow (&temporary_obstack
, buffer
, strlen (buffer
));
2038 for (current
= TREE_CHAIN (class_list
); current
;
2039 current
= TREE_CHAIN (current
))
2041 tree decl
= TYPE_NAME (TREE_PURPOSE (current
));
2042 sprintf (buffer
, "\n which inherits from '%s' (%s:%d)",
2043 IDENTIFIER_POINTER (DECL_NAME (decl
)),
2044 DECL_SOURCE_FILE (decl
),
2045 DECL_SOURCE_LINE (decl
));
2046 obstack_grow (&temporary_obstack
, buffer
, strlen (buffer
));
2048 obstack_1grow (&temporary_obstack
, '\0');
2049 report
= obstack_finish (&temporary_obstack
);
2050 cyclic_inheritance_report
= ggc_strdup (report
);
2051 obstack_free (&temporary_obstack
, report
);
2052 TYPE_SIZE (this_class
) = error_mark_node
;
2055 CLASS_BEING_LAIDOUT (this_class
) = 1;
2057 if (super_class
&& !CLASS_BEING_LAIDOUT (super_class
))
2059 tree maybe_super_class
2060 = maybe_layout_super_class (super_class
, this_class
);
2061 if (maybe_super_class
== NULL
2062 || TREE_CODE (TYPE_SIZE (maybe_super_class
)) == ERROR_MARK
)
2064 TYPE_SIZE (this_class
) = error_mark_node
;
2065 CLASS_BEING_LAIDOUT (this_class
) = 0;
2066 class_list
= TREE_CHAIN (class_list
);
2069 if (TYPE_SIZE (this_class
) == NULL_TREE
)
2070 push_super_field (this_class
, maybe_super_class
);
2073 for (field
= TYPE_FIELDS (this_class
);
2074 field
!= NULL_TREE
; field
= TREE_CHAIN (field
))
2076 if (FIELD_STATIC (field
))
2078 /* Set DECL_ASSEMBLER_NAME to something suitably mangled. */
2079 SET_DECL_ASSEMBLER_NAME (field
,
2081 (&temporary_obstack
, field
));
2085 layout_type (this_class
);
2087 /* Also recursively load/layout any superinterfaces, but only if
2088 class was loaded from bytecode. The source parser will take care
2090 if (!CLASS_FROM_SOURCE_P (this_class
))
2094 for (i
= BINFO_N_BASE_BINFOS (TYPE_BINFO (this_class
)) - 1; i
> 0; i
--)
2096 tree binfo
= BINFO_BASE_BINFO (TYPE_BINFO (this_class
), i
);
2097 tree super_interface
= BINFO_TYPE (binfo
);
2098 tree maybe_super_interface
2099 = maybe_layout_super_class (super_interface
, NULL_TREE
);
2100 if (maybe_super_interface
== NULL
2101 || TREE_CODE (TYPE_SIZE (maybe_super_interface
)) == ERROR_MARK
)
2103 TYPE_SIZE (this_class
) = error_mark_node
;
2104 CLASS_BEING_LAIDOUT (this_class
) = 0;
2105 class_list
= TREE_CHAIN (class_list
);
2111 /* Convert the size back to an SI integer value. */
2112 TYPE_SIZE_UNIT (this_class
) =
2113 fold (convert (int_type_node
, TYPE_SIZE_UNIT (this_class
)));
2115 CLASS_BEING_LAIDOUT (this_class
) = 0;
2116 class_list
= TREE_CHAIN (class_list
);
2120 add_miranda_methods (tree base_class
, tree search_class
)
2122 tree binfo
, base_binfo
;
2125 for (binfo
= TYPE_BINFO (search_class
), i
= 1;
2126 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
2129 tree elt
= BINFO_TYPE (base_binfo
);
2131 /* Ensure that interface methods are seen in declared order. */
2132 if (!CLASS_LOADED_P (elt
))
2133 load_class (elt
, 1);
2134 layout_class_methods (elt
);
2136 /* All base classes will have been laid out at this point, so the order
2137 will be correct. This code must match similar layout code in the
2139 for (method_decl
= TYPE_METHODS (elt
);
2140 method_decl
; method_decl
= TREE_CHAIN (method_decl
))
2144 /* An interface can have <clinit>. */
2145 if (ID_CLINIT_P (DECL_NAME (method_decl
)))
2148 sig
= build_java_argument_signature (TREE_TYPE (method_decl
));
2149 override
= lookup_argument_method (base_class
,
2150 DECL_NAME (method_decl
), sig
);
2151 if (override
== NULL_TREE
)
2153 /* Found a Miranda method. Add it. */
2155 sig
= build_java_signature (TREE_TYPE (method_decl
));
2157 = add_method (base_class
,
2158 get_access_flags_from_decl (method_decl
),
2159 DECL_NAME (method_decl
), sig
);
2160 METHOD_INVISIBLE (new_method
) = 1;
2164 /* Try superinterfaces. */
2165 add_miranda_methods (base_class
, elt
);
2170 layout_class_methods (tree this_class
)
2172 tree method_decl
, dtable_count
;
2173 tree super_class
, type_name
;
2175 if (TYPE_NVIRTUALS (this_class
))
2178 super_class
= CLASSTYPE_SUPER (this_class
);
2182 super_class
= maybe_layout_super_class (super_class
, this_class
);
2183 if (!TYPE_NVIRTUALS (super_class
))
2184 layout_class_methods (super_class
);
2185 dtable_count
= TYPE_NVIRTUALS (super_class
);
2188 dtable_count
= integer_zero_node
;
2190 type_name
= TYPE_NAME (this_class
);
2191 if (CLASS_ABSTRACT (type_name
) || CLASS_INTERFACE (type_name
))
2193 /* An abstract class can have methods which are declared only in
2194 an implemented interface. These are called "Miranda
2195 methods". We make a dummy method entry for such methods
2197 add_miranda_methods (this_class
, this_class
);
2200 TYPE_METHODS (this_class
) = nreverse (TYPE_METHODS (this_class
));
2202 for (method_decl
= TYPE_METHODS (this_class
);
2203 method_decl
; method_decl
= TREE_CHAIN (method_decl
))
2204 dtable_count
= layout_class_method (this_class
, super_class
,
2205 method_decl
, dtable_count
);
2207 TYPE_NVIRTUALS (this_class
) = dtable_count
;
2210 /* Return the index of METHOD in INTERFACE. This index begins at 1 and is used as an
2211 argument for _Jv_LookupInterfaceMethodIdx(). */
2213 get_interface_method_index (tree method
, tree interface
)
2218 for (meth
= TYPE_METHODS (interface
); ; meth
= TREE_CHAIN (meth
), i
++)
2222 if (meth
== NULL_TREE
)
2227 /* Lay METHOD_DECL out, returning a possibly new value of
2228 DTABLE_COUNT. Also mangle the method's name. */
2231 layout_class_method (tree this_class
, tree super_class
,
2232 tree method_decl
, tree dtable_count
)
2234 tree method_name
= DECL_NAME (method_decl
);
2236 TREE_PUBLIC (method_decl
) = 1;
2237 /* Considered external until we know what classes are being
2238 compiled into this object file. */
2239 DECL_EXTERNAL (method_decl
) = 1;
2241 /* This is a good occasion to mangle the method's name */
2242 SET_DECL_ASSEMBLER_NAME (method_decl
,
2243 java_mangle_decl (&temporary_obstack
,
2245 /* We don't generate a RTL for the method if it's abstract, or if
2246 it's an interface method that isn't clinit. */
2247 if (! METHOD_ABSTRACT (method_decl
)
2248 || (CLASS_INTERFACE (TYPE_NAME (this_class
))
2249 && (DECL_CLINIT_P (method_decl
))))
2250 make_decl_rtl (method_decl
);
2252 if (ID_INIT_P (method_name
))
2254 const char *p
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (this_class
)));
2256 for (ptr
= p
; *ptr
; )
2261 DECL_CONSTRUCTOR_P (method_decl
) = 1;
2262 build_java_argument_signature (TREE_TYPE (method_decl
));
2264 else if (! METHOD_STATIC (method_decl
))
2267 build_java_argument_signature (TREE_TYPE (method_decl
));
2268 bool method_override
= false;
2269 tree super_method
= lookup_argument_method (super_class
, method_name
,
2271 if (super_method
!= NULL_TREE
)
2273 method_override
= true;
2274 if (! METHOD_PUBLIC (super_method
) &&
2275 ! METHOD_PROTECTED (super_method
))
2277 /* Don't override private method, or default-access method in
2279 if (METHOD_PRIVATE (super_method
) ||
2280 ! in_same_package (TYPE_NAME (this_class
),
2281 TYPE_NAME (super_class
)))
2282 method_override
= false;
2285 if (method_override
)
2287 tree method_index
= get_method_index (super_method
);
2288 set_method_index (method_decl
, method_index
);
2289 if (method_index
== NULL_TREE
2290 && !CLASS_FROM_SOURCE_P (this_class
))
2291 error ("%Jnon-static method '%D' overrides static method",
2292 method_decl
, method_decl
);
2294 else if (! METHOD_FINAL (method_decl
)
2295 && ! METHOD_PRIVATE (method_decl
)
2296 && ! CLASS_FINAL (TYPE_NAME (this_class
))
2299 set_method_index (method_decl
, dtable_count
);
2300 dtable_count
= fold (build2 (PLUS_EXPR
, integer_type_node
,
2301 dtable_count
, integer_one_node
));
2305 return dtable_count
;
2309 register_class (void)
2311 /* END does not need to be registered with the garbage collector
2312 because it always points into the list given by REGISTERED_CLASS,
2313 and that variable is registered with the collector. */
2315 tree node
= TREE_OPERAND (build_class_ref (current_class
), 0);
2316 tree current
= copy_node (node
);
2318 XEXP (DECL_RTL (current
), 0) = copy_rtx (XEXP (DECL_RTL(node
), 0));
2319 if (!registered_class
)
2320 registered_class
= current
;
2322 TREE_CHAIN (end
) = current
;
2327 /* Emit something to register classes at start-up time.
2329 The preferred mechanism is through the .jcr section, which contain
2330 a list of pointers to classes which get registered during constructor
2333 The fallback mechanism is to add statements to *LIST_P to call
2334 _Jv_RegisterClass for each class in this file. These statements will
2335 be added to a static constructor function for this translation unit. */
2338 emit_register_classes (tree
*list_p
)
2340 if (registered_class
== NULL
)
2343 /* ??? This isn't quite the correct test. We also have to know
2344 that the target is using gcc's crtbegin/crtend objects rather
2345 than the ones that come with the operating system. */
2346 if (SUPPORTS_WEAK
&& targetm
.have_named_sections
)
2348 #ifdef JCR_SECTION_NAME
2350 named_section_flags (JCR_SECTION_NAME
, SECTION_WRITE
);
2351 assemble_align (POINTER_SIZE
);
2352 for (t
= registered_class
; t
; t
= TREE_CHAIN (t
))
2353 assemble_integer (XEXP (DECL_RTL (t
), 0),
2354 POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
2361 tree klass
, t
, register_class_fn
;
2363 t
= build_function_type_list (void_type_node
, class_ptr_type
, NULL
);
2364 t
= build_decl (FUNCTION_DECL
, get_identifier ("_Jv_RegisterClass"), t
);
2365 TREE_PUBLIC (t
) = 1;
2366 DECL_EXTERNAL (t
) = 1;
2367 register_class_fn
= t
;
2369 for (klass
= registered_class
; klass
; klass
= TREE_CHAIN (klass
))
2371 t
= build_fold_addr_expr (klass
);
2372 t
= tree_cons (NULL
, t
, NULL
);
2373 t
= build_function_call_expr (register_class_fn
, t
);
2374 append_to_statement_list (t
, list_p
);
2379 /* Make a symbol_type (_Jv_MethodSymbol) node for DECL. */
2382 build_symbol_entry (tree decl
)
2384 tree clname
, name
, signature
, sym
;
2386 clname
= build_utf8_ref (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))));
2387 name
= build_utf8_ref (DECL_NAME (decl
));
2388 signature
= build_java_signature (TREE_TYPE (decl
));
2389 signature
= build_utf8_ref (unmangle_classname
2390 (IDENTIFIER_POINTER (signature
),
2391 IDENTIFIER_LENGTH (signature
)));
2393 START_RECORD_CONSTRUCTOR (sym
, symbol_type
);
2394 PUSH_FIELD_VALUE (sym
, "clname", clname
);
2395 PUSH_FIELD_VALUE (sym
, "name", name
);
2396 PUSH_FIELD_VALUE (sym
, "signature", signature
);
2397 FINISH_RECORD_CONSTRUCTOR (sym
);
2398 TREE_CONSTANT (sym
) = 1;
2399 TREE_INVARIANT (sym
) = 1;
2404 /* Emit a symbol table: used by -findirect-dispatch. */
2407 emit_symbol_table (tree name
, tree the_table
, tree decl_list
,
2408 tree the_syms_decl
, tree the_array_element_type
)
2410 tree method_list
, method
, table
, list
, null_symbol
;
2411 tree table_size
, the_array_type
;
2414 /* Only emit a table if this translation unit actually made any
2415 references via it. */
2416 if (decl_list
== NULL_TREE
)
2419 /* Build a list of _Jv_MethodSymbols for each entry in otable_methods. */
2421 method_list
= decl_list
;
2423 while (method_list
!= NULL_TREE
)
2425 method
= TREE_VALUE (method_list
);
2426 list
= tree_cons (NULL_TREE
, build_symbol_entry (method
), list
);
2427 method_list
= TREE_CHAIN (method_list
);
2431 /* Terminate the list with a "null" entry. */
2432 START_RECORD_CONSTRUCTOR (null_symbol
, symbol_type
);
2433 PUSH_FIELD_VALUE (null_symbol
, "clname", null_pointer_node
);
2434 PUSH_FIELD_VALUE (null_symbol
, "name", null_pointer_node
);
2435 PUSH_FIELD_VALUE (null_symbol
, "signature", null_pointer_node
);
2436 FINISH_RECORD_CONSTRUCTOR (null_symbol
);
2437 TREE_CONSTANT (null_symbol
) = 1;
2438 TREE_INVARIANT (null_symbol
) = 1;
2439 list
= tree_cons (NULL_TREE
, null_symbol
, list
);
2441 /* Put the list in the right order and make it a constructor. */
2442 list
= nreverse (list
);
2443 table
= build_constructor (symbols_array_type
, list
);
2445 /* Make it the initial value for otable_syms and emit the decl. */
2446 DECL_INITIAL (the_syms_decl
) = table
;
2447 DECL_ARTIFICIAL (the_syms_decl
) = 1;
2448 DECL_IGNORED_P (the_syms_decl
) = 1;
2449 rest_of_decl_compilation (the_syms_decl
, 1, 0);
2451 /* Now that its size is known, redefine the table as an
2452 uninitialized static array of INDEX + 1 elements. The extra entry
2453 is used by the runtime to track whether the table has been
2455 table_size
= build_index_type (build_int_cst (NULL_TREE
, index
));
2456 the_array_type
= build_array_type (the_array_element_type
, table_size
);
2457 the_table
= build_decl (VAR_DECL
, name
, the_array_type
);
2458 TREE_STATIC (the_table
) = 1;
2459 TREE_READONLY (the_table
) = 1;
2460 rest_of_decl_compilation (the_table
, 1, 0);
2465 /* make an entry for the catch_classes list. */
2467 make_catch_class_record (tree catch_class
, tree classname
)
2470 tree type
= TREE_TYPE (TREE_TYPE (TYPE_CTABLE_DECL (output_class
)));
2471 START_RECORD_CONSTRUCTOR (entry
, type
);
2472 PUSH_FIELD_VALUE (entry
, "address", catch_class
);
2473 PUSH_FIELD_VALUE (entry
, "classname", classname
);
2474 FINISH_RECORD_CONSTRUCTOR (entry
);
2479 /* Generate the list of Throwable classes that are caught by exception
2480 handlers in this class. */
2482 emit_catch_table (tree this_class
)
2484 tree table
, table_size
, array_type
;
2485 TYPE_CATCH_CLASSES (this_class
) =
2487 make_catch_class_record (null_pointer_node
, null_pointer_node
),
2488 TYPE_CATCH_CLASSES (this_class
));
2489 TYPE_CATCH_CLASSES (this_class
) = nreverse (TYPE_CATCH_CLASSES (this_class
));
2490 TYPE_CATCH_CLASSES (this_class
) =
2492 make_catch_class_record (null_pointer_node
, null_pointer_node
),
2493 TYPE_CATCH_CLASSES (this_class
));
2494 table_size
= build_index_type
2495 (build_int_cst (NULL_TREE
,
2496 list_length (TYPE_CATCH_CLASSES (this_class
))));
2498 = build_array_type (TREE_TYPE (TREE_TYPE (TYPE_CTABLE_DECL (this_class
))),
2501 build_decl (VAR_DECL
, DECL_NAME (TYPE_CTABLE_DECL (this_class
)), array_type
);
2502 DECL_INITIAL (table
) =
2503 build_constructor (array_type
, TYPE_CATCH_CLASSES (this_class
));
2504 TREE_STATIC (table
) = 1;
2505 TREE_READONLY (table
) = 1;
2506 DECL_IGNORED_P (table
) = 1;
2507 rest_of_decl_compilation (table
, 1, 0);
2513 init_class_processing (void)
2515 fields_ident
= get_identifier ("fields");
2516 info_ident
= get_identifier ("info");
2518 gcc_obstack_init (&temporary_obstack
);
2521 static hashval_t
java_treetreehash_hash (const void *);
2522 static int java_treetreehash_compare (const void *, const void *);
2524 /* A hash table mapping trees to trees. Used generally. */
2526 #define JAVA_TREEHASHHASH_H(t) (htab_hash_pointer (t))
2529 java_treetreehash_hash (const void *k_p
)
2531 struct treetreehash_entry
*k
= (struct treetreehash_entry
*) k_p
;
2532 return JAVA_TREEHASHHASH_H (k
->key
);
2536 java_treetreehash_compare (const void * k1_p
, const void * k2_p
)
2538 struct treetreehash_entry
* k1
= (struct treetreehash_entry
*) k1_p
;
2539 tree k2
= (tree
) k2_p
;
2540 return (k1
->key
== k2
);
2544 java_treetreehash_find (htab_t ht
, tree t
)
2546 struct treetreehash_entry
*e
;
2547 hashval_t hv
= JAVA_TREEHASHHASH_H (t
);
2548 e
= htab_find_with_hash (ht
, t
, hv
);
2556 java_treetreehash_new (htab_t ht
, tree t
)
2559 struct treetreehash_entry
*tthe
;
2560 hashval_t hv
= JAVA_TREEHASHHASH_H (t
);
2562 e
= htab_find_slot_with_hash (ht
, t
, hv
, INSERT
);
2565 tthe
= (*ht
->alloc_f
) (1, sizeof (*tthe
));
2570 tthe
= (struct treetreehash_entry
*) *e
;
2571 return &tthe
->value
;
2575 java_treetreehash_create (size_t size
, int gc
)
2578 return htab_create_ggc (size
, java_treetreehash_hash
,
2579 java_treetreehash_compare
, NULL
);
2581 return htab_create_alloc (size
, java_treetreehash_hash
,
2582 java_treetreehash_compare
, free
, xcalloc
, free
);
2585 /* Break down qualified IDENTIFIER into package and class-name components.
2586 For example, given SOURCE "pkg.foo.Bar", LEFT will be set to
2587 "pkg.foo", and RIGHT to "Bar". */
2590 split_qualified_name (tree
*left
, tree
*right
, tree source
)
2593 int l
= IDENTIFIER_LENGTH (source
);
2595 base
= alloca (l
+ 1);
2596 memcpy (base
, IDENTIFIER_POINTER (source
), l
+ 1);
2598 /* Breakdown NAME into REMAINDER . IDENTIFIER. */
2600 while (*p
!= '.' && p
!= base
)
2603 /* We didn't find a '.'. Return an error. */
2609 *right
= get_identifier (p
+1);
2610 *left
= get_identifier (base
);
2615 /* Given two classes (TYPE_DECL) or class names (IDENTIFIER), return TRUE
2616 if the classes are from the same package. */
2619 in_same_package (tree name1
, tree name2
)
2625 if (TREE_CODE (name1
) == TYPE_DECL
)
2626 name1
= DECL_NAME (name1
);
2627 if (TREE_CODE (name2
) == TYPE_DECL
)
2628 name2
= DECL_NAME (name2
);
2630 if (QUALIFIED_P (name1
) != QUALIFIED_P (name2
))
2631 /* One in empty package. */
2634 if (QUALIFIED_P (name1
) == 0 && QUALIFIED_P (name2
) == 0)
2635 /* Both in empty package. */
2638 split_qualified_name (&pkg1
, &tmp
, name1
);
2639 split_qualified_name (&pkg2
, &tmp
, name2
);
2641 return (pkg1
== pkg2
);
2644 #include "gt-java-class.h"