1 /* Handle types for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1996-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC 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 3, or (at your option)
11 GCC 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 GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>.
20 Java and all Java-based marks are trademarks or registered trademarks
21 of Sun Microsystems, Inc. in the United States and other countries.
22 The Free Software Foundation is independent of Sun Microsystems, Inc. */
24 /* Written by Per Bothner <bothner@cygnus.com> */
28 #include "coretypes.h"
31 #include "stringpool.h"
32 #include "diagnostic-core.h"
33 #include "fold-const.h"
34 #include "stor-layout.h"
35 #include "java-tree.h"
38 static tree
convert_ieee_real_to_integer (tree
, tree
);
39 static tree
parse_signature_type (const unsigned char **,
40 const unsigned char *);
41 static tree
lookup_do (tree
, int, tree
, tree
, tree (*)(tree
));
42 static tree
build_null_signature (tree
);
46 /* Set the type of the local variable with index SLOT to TYPE. */
49 set_local_type (int slot
, tree type
)
51 int max_locals
= DECL_MAX_LOCALS(current_function_decl
);
52 int nslots
= TYPE_IS_WIDE (type
) ? 2 : 1;
54 gcc_assert (slot
>= 0 && (slot
+ nslots
- 1 < max_locals
));
56 type_map
[slot
] = type
;
58 type_map
[++slot
] = void_type_node
;
61 /* Convert an IEEE real to an integer type. The result of such a
62 conversion when the source operand is a NaN isn't defined by
63 IEEE754, but by the Java language standard: it must be zero. Also,
64 overflows must be clipped to within range. This conversion
65 produces something like:
67 ((expr >= (float)MAX_INT)
69 : ((expr <= (float)MIN_INT)
76 convert_ieee_real_to_integer (tree type
, tree expr
)
79 expr
= save_expr (expr
);
81 result
= fold_build3 (COND_EXPR
, type
,
82 fold_build2 (NE_EXPR
, boolean_type_node
, expr
, expr
),
83 convert (type
, integer_zero_node
),
84 convert_to_integer (type
, expr
));
86 result
= fold_build3 (COND_EXPR
, type
,
87 fold_build2 (LE_EXPR
, boolean_type_node
, expr
,
88 convert (TREE_TYPE (expr
),
89 TYPE_MIN_VALUE (type
))),
90 TYPE_MIN_VALUE (type
),
93 result
= fold_build3 (COND_EXPR
, type
,
94 fold_build2 (GE_EXPR
, boolean_type_node
, expr
,
95 convert (TREE_TYPE (expr
),
96 TYPE_MAX_VALUE (type
))),
97 TYPE_MAX_VALUE (type
),
103 /* Create an expression whose value is that of EXPR,
104 converted to type TYPE. The TREE_TYPE of the value
105 is always TYPE. This function implements all reasonable
106 conversions; callers should filter out those that are
107 not permitted by the language being compiled. */
110 convert (tree type
, tree expr
)
112 enum tree_code code
= TREE_CODE (type
);
115 return error_mark_node
;
117 if (type
== TREE_TYPE (expr
)
118 || TREE_CODE (expr
) == ERROR_MARK
)
120 if (TREE_CODE (TREE_TYPE (expr
)) == ERROR_MARK
)
121 return error_mark_node
;
122 if (code
== VOID_TYPE
)
123 return build1 (CONVERT_EXPR
, type
, expr
);
124 if (code
== BOOLEAN_TYPE
)
125 return fold_convert (type
, expr
);
126 if (code
== INTEGER_TYPE
)
128 if (type
== char_type_node
|| type
== promoted_char_type_node
)
129 return fold_convert (type
, expr
);
130 if ((really_constant_p (expr
) || ! flag_unsafe_math_optimizations
)
131 && TREE_CODE (TREE_TYPE (expr
)) == REAL_TYPE
)
132 return convert_ieee_real_to_integer (type
, expr
);
135 /* fold very helpfully sets the overflow status if a type
136 overflows in a narrowing integer conversion, but Java
138 tree tmp
= fold (convert_to_integer (type
, expr
));
139 if (TREE_CODE (tmp
) == INTEGER_CST
)
140 TREE_OVERFLOW (tmp
) = 0;
144 if (code
== REAL_TYPE
)
145 return fold (convert_to_real (type
, expr
));
146 if (code
== POINTER_TYPE
)
147 return fold (convert_to_pointer (type
, expr
));
148 error ("conversion to non-scalar type requested");
149 return error_mark_node
;
153 /* Return a data type that has machine mode MODE.
154 If the mode is an integer,
155 then UNSIGNEDP selects between signed and unsigned types. */
158 java_type_for_mode (machine_mode mode
, int unsignedp
)
160 if (mode
== TYPE_MODE (int_type_node
))
161 return unsignedp
? unsigned_int_type_node
: int_type_node
;
162 if (mode
== TYPE_MODE (long_type_node
))
163 return unsignedp
? unsigned_long_type_node
: long_type_node
;
164 if (mode
== TYPE_MODE (short_type_node
))
165 return unsignedp
? unsigned_short_type_node
: short_type_node
;
166 if (mode
== TYPE_MODE (byte_type_node
))
167 return unsignedp
? unsigned_byte_type_node
: byte_type_node
;
168 if (mode
== TYPE_MODE (float_type_node
))
169 return float_type_node
;
170 if (mode
== TYPE_MODE (double_type_node
))
171 return double_type_node
;
176 /* Return an integer type with BITS bits of precision,
177 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
180 java_type_for_size (unsigned bits
, int unsignedp
)
182 if (bits
<= TYPE_PRECISION (byte_type_node
))
183 return unsignedp
? unsigned_byte_type_node
: byte_type_node
;
184 if (bits
<= TYPE_PRECISION (short_type_node
))
185 return unsignedp
? unsigned_short_type_node
: short_type_node
;
186 if (bits
<= TYPE_PRECISION (int_type_node
))
187 return unsignedp
? unsigned_int_type_node
: int_type_node
;
188 if (bits
<= TYPE_PRECISION (long_type_node
))
189 return unsignedp
? unsigned_long_type_node
: long_type_node
;
193 /* Thorough checking of the arrayness of TYPE. */
196 is_array_type_p (tree type
)
198 return TREE_CODE (type
) == POINTER_TYPE
199 && TREE_CODE (TREE_TYPE (type
)) == RECORD_TYPE
200 && TYPE_ARRAY_P (TREE_TYPE (type
));
203 /* Return the length of a Java array type.
204 Return -1 if the length is unknown or non-constant. */
207 java_array_type_length (tree array_type
)
210 if (TREE_CODE (array_type
) == POINTER_TYPE
)
211 array_type
= TREE_TYPE (array_type
);
212 arfld
= DECL_CHAIN (DECL_CHAIN (TYPE_FIELDS (array_type
)));
213 if (arfld
!= NULL_TREE
)
215 tree index_type
= TYPE_DOMAIN (TREE_TYPE (arfld
));
216 if (index_type
!= NULL_TREE
)
218 tree high
= TYPE_MAX_VALUE (index_type
);
219 if (TREE_CODE (high
) == INTEGER_CST
)
220 return TREE_INT_CST_LOW (high
) + 1;
226 /* An array of unknown length will be ultimately given a length of
227 -2, so that we can still have `length' producing a negative value
228 even if found. This was part of an optimization aiming at removing
229 `length' from static arrays. We could restore it, FIXME. */
232 build_prim_array_type (tree element_type
, HOST_WIDE_INT length
)
238 tree max_index
= build_int_cst (sizetype
, length
- 1);
239 index
= build_index_type (max_index
);
241 return build_array_type (element_type
, index
);
244 /* Return a Java array type with a given ELEMENT_TYPE and LENGTH.
245 These are hashed (shared) using IDENTIFIER_SIGNATURE_TYPE.
246 The LENGTH is -1 if the length is unknown. */
249 build_java_array_type (tree element_type
, HOST_WIDE_INT length
)
251 tree sig
, t
, fld
, atype
, arfld
;
253 tree elsig
= build_java_signature (element_type
);
254 tree el_name
= element_type
;
257 sprintf (buf
+1, HOST_WIDE_INT_PRINT_DEC
, length
);
260 sig
= ident_subst (IDENTIFIER_POINTER (elsig
), IDENTIFIER_LENGTH (elsig
),
262 t
= IDENTIFIER_SIGNATURE_TYPE (sig
);
264 return TREE_TYPE (t
);
266 IDENTIFIER_SIGNATURE_TYPE (sig
) = build_pointer_type (t
);
267 TYPE_ARRAY_P (t
) = 1;
269 if (TREE_CODE (el_name
) == POINTER_TYPE
)
270 el_name
= TREE_TYPE (el_name
);
271 el_name
= TYPE_NAME (el_name
);
272 if (TREE_CODE (el_name
) == TYPE_DECL
)
273 el_name
= DECL_NAME (el_name
);
277 sprintf (suffix
, "[%d]", (int)length
);
279 strcpy (suffix
, "[]");
282 = build_decl (input_location
, TYPE_DECL
,
283 identifier_subst (el_name
, "", '.', '.', suffix
),
285 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (t
)) = true;
288 set_java_signature (t
, sig
);
289 set_super_info (0, t
, object_type_node
, 0);
290 if (TREE_CODE (element_type
) == RECORD_TYPE
)
291 element_type
= promote_type (element_type
);
292 TYPE_ARRAY_ELEMENT (t
) = element_type
;
294 /* Add length pseudo-field. */
295 fld
= build_decl (input_location
,
296 FIELD_DECL
, get_identifier ("length"), int_type_node
);
297 TYPE_FIELDS (t
) = fld
;
298 DECL_CONTEXT (fld
) = t
;
299 FIELD_PUBLIC (fld
) = 1;
300 FIELD_FINAL (fld
) = 1;
301 TREE_READONLY (fld
) = 1;
303 atype
= build_prim_array_type (element_type
, length
);
304 arfld
= build_decl (input_location
,
305 FIELD_DECL
, get_identifier ("data"), atype
);
306 DECL_CONTEXT (arfld
) = t
;
307 DECL_CHAIN (fld
) = arfld
;
308 SET_DECL_ALIGN (arfld
, TYPE_ALIGN (element_type
));
310 /* We could layout_class, but that loads java.lang.Object prematurely.
311 * This is called by the parser, and it is a bad idea to do load_class
312 * in the middle of parsing, because of possible circularity problems. */
313 push_super_field (t
, object_type_node
);
319 /* Promote TYPE to the type actually used for fields and parameters. */
322 promote_type (tree type
)
324 switch (TREE_CODE (type
))
327 return build_pointer_type (type
);
329 if (type
== boolean_type_node
)
330 return promoted_boolean_type_node
;
333 if (type
== char_type_node
)
334 return promoted_char_type_node
;
336 if (TYPE_PRECISION (type
) < TYPE_PRECISION (int_type_node
))
338 if (type
== short_type_node
)
339 return promoted_short_type_node
;
340 if (type
== byte_type_node
)
341 return promoted_byte_type_node
;
342 return int_type_node
;
344 /* ... else fall through ... */
350 /* Parse a signature string, starting at *PTR and ending at LIMIT.
351 Return the seen TREE_TYPE, updating *PTR. */
354 parse_signature_type (const unsigned char **ptr
, const unsigned char *limit
)
357 gcc_assert (*ptr
< limit
);
361 case 'B': (*ptr
)++; return byte_type_node
;
362 case 'C': (*ptr
)++; return char_type_node
;
363 case 'D': (*ptr
)++; return double_type_node
;
364 case 'F': (*ptr
)++; return float_type_node
;
365 case 'S': (*ptr
)++; return short_type_node
;
366 case 'I': (*ptr
)++; return int_type_node
;
367 case 'J': (*ptr
)++; return long_type_node
;
368 case 'Z': (*ptr
)++; return boolean_type_node
;
369 case 'V': (*ptr
)++; return void_type_node
;
371 for ((*ptr
)++; (*ptr
) < limit
&& ISDIGIT (**ptr
); ) (*ptr
)++;
372 type
= parse_signature_type (ptr
, limit
);
373 type
= build_java_array_type (type
, -1);
377 const unsigned char *start
= ++(*ptr
);
378 const unsigned char *str
= start
;
381 gcc_assert (str
< limit
);
386 type
= lookup_class (unmangle_classname ((const char *) start
, str
- start
));
392 return promote_type (type
);
395 /* Parse a Java "mangled" signature string, starting at SIG_STRING,
396 and SIG_LENGTH bytes long.
397 Return a gcc type node. */
400 parse_signature_string (const unsigned char *sig_string
, int sig_length
)
403 const unsigned char *str
= sig_string
;
404 const unsigned char *limit
= str
+ sig_length
;
406 if (str
< limit
&& str
[0] == '(')
408 tree argtype_list
= NULL_TREE
;
410 while (str
< limit
&& str
[0] != ')')
412 tree argtype
= parse_signature_type (&str
, limit
);
413 argtype_list
= tree_cons (NULL_TREE
, argtype
, argtype_list
);
415 if (str
++, str
>= limit
)
417 result_type
= parse_signature_type (&str
, limit
);
418 argtype_list
= chainon (nreverse (argtype_list
), end_params_node
);
419 result_type
= build_function_type (result_type
, argtype_list
);
422 result_type
= parse_signature_type (&str
, limit
);
424 error ("junk at end of signature string");
428 /* Convert a signature to its type.
429 * Uses IDENTIFIER_SIGNATURE_TYPE as a cache (except for primitive types).
433 get_type_from_signature (tree signature
)
435 const unsigned char *sig
= (const unsigned char *) IDENTIFIER_POINTER (signature
);
436 int len
= IDENTIFIER_LENGTH (signature
);
438 /* Primitive types aren't cached. */
440 return parse_signature_string (sig
, len
);
441 type
= IDENTIFIER_SIGNATURE_TYPE (signature
);
442 if (type
== NULL_TREE
)
444 type
= parse_signature_string (sig
, len
);
445 IDENTIFIER_SIGNATURE_TYPE (signature
) = type
;
450 /* Ignore signature and always return null. Used by has_method. */
453 build_null_signature (tree type ATTRIBUTE_UNUSED
)
458 /* Return the signature string for the arguments of method type TYPE. */
461 build_java_argument_signature (tree type
)
463 extern struct obstack temporary_obstack
;
464 tree sig
= TYPE_ARGUMENT_SIGNATURE (type
);
465 if (sig
== NULL_TREE
)
467 tree args
= TYPE_ARG_TYPES (type
);
468 if (TREE_CODE (type
) == METHOD_TYPE
)
469 args
= TREE_CHAIN (args
); /* Skip "this" argument. */
470 for (; args
!= end_params_node
; args
= TREE_CHAIN (args
))
472 tree t
= build_java_signature (TREE_VALUE (args
));
473 obstack_grow (&temporary_obstack
,
474 IDENTIFIER_POINTER (t
), IDENTIFIER_LENGTH (t
));
476 obstack_1grow (&temporary_obstack
, '\0');
478 sig
= get_identifier ((char *) obstack_base (&temporary_obstack
));
479 TYPE_ARGUMENT_SIGNATURE (type
) = sig
;
480 obstack_free (&temporary_obstack
, obstack_base (&temporary_obstack
));
485 /* Return the signature of the given TYPE. */
488 build_java_signature (tree type
)
491 while (TREE_CODE (type
) == POINTER_TYPE
)
492 type
= TREE_TYPE (type
);
493 MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type
);
494 sig
= TYPE_SIGNATURE (type
);
495 if (sig
== NULL_TREE
)
498 switch (TREE_CODE (type
))
500 case BOOLEAN_TYPE
: sg
[0] = 'Z'; goto native
;
501 case VOID_TYPE
: sg
[0] = 'V'; goto native
;
503 if (type
== char_type_node
|| type
== promoted_char_type_node
)
508 switch (TYPE_PRECISION (type
))
510 case 8: sg
[0] = 'B'; goto native
;
511 case 16: sg
[0] = 'S'; goto native
;
512 case 32: sg
[0] = 'I'; goto native
;
513 case 64: sg
[0] = 'J'; goto native
;
514 default: goto bad_type
;
517 switch (TYPE_PRECISION (type
))
519 case 32: sg
[0] = 'F'; goto native
;
520 case 64: sg
[0] = 'D'; goto native
;
521 default: goto bad_type
;
525 sig
= get_identifier (sg
);
528 if (TYPE_ARRAY_P (type
))
530 t
= build_java_signature (TYPE_ARRAY_ELEMENT (type
));
531 sig
= ident_subst (IDENTIFIER_POINTER (t
), IDENTIFIER_LENGTH (t
),
536 t
= DECL_NAME (TYPE_NAME (type
));
537 sig
= ident_subst (IDENTIFIER_POINTER (t
), IDENTIFIER_LENGTH (t
),
544 extern struct obstack temporary_obstack
;
545 sig
= build_java_argument_signature (type
);
546 obstack_1grow (&temporary_obstack
, '(');
547 obstack_grow (&temporary_obstack
,
548 IDENTIFIER_POINTER (sig
), IDENTIFIER_LENGTH (sig
));
549 obstack_1grow (&temporary_obstack
, ')');
551 t
= build_java_signature (TREE_TYPE (type
));
552 obstack_grow0 (&temporary_obstack
,
553 IDENTIFIER_POINTER (t
), IDENTIFIER_LENGTH (t
));
555 sig
= get_identifier ((char *) obstack_base (&temporary_obstack
));
556 obstack_free (&temporary_obstack
,
557 obstack_base (&temporary_obstack
));
564 TYPE_SIGNATURE (type
) = sig
;
569 /* Save signature string SIG (an IDENTIFIER_NODE) in TYPE for future use. */
572 set_java_signature (tree type
, tree sig
)
575 while (TREE_CODE (type
) == POINTER_TYPE
)
576 type
= TREE_TYPE (type
);
577 MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type
);
578 old_sig
= TYPE_SIGNATURE (type
);
579 if (old_sig
!= NULL_TREE
&& old_sig
!= sig
)
581 TYPE_SIGNATURE (type
) = sig
;
582 #if 0 /* careful about METHOD_TYPE */
583 if (IDENTIFIER_SIGNATURE_TYPE (sig
) == NULL_TREE
&& TREE_PERMANENT (type
))
584 IDENTIFIER_SIGNATURE_TYPE (sig
) = type
;
588 /* Search in SEARCHED_CLASS and its superclasses for a method matching
589 METHOD_NAME and signature METHOD_SIGNATURE. This function will
590 only search for methods declared in the class hierarchy; interfaces
591 will not be considered. Returns NULL_TREE if the method is not
594 lookup_argument_method (tree searched_class
, tree method_name
,
595 tree method_signature
)
597 return lookup_do (searched_class
, 0,
598 method_name
, method_signature
,
599 build_java_argument_signature
);
602 /* Like lookup_argument_method, but lets the caller set any flags
605 lookup_argument_method_generic (tree searched_class
, tree method_name
,
606 tree method_signature
, int flags
)
608 return lookup_do (searched_class
, flags
,
609 method_name
, method_signature
,
610 build_java_argument_signature
);
614 /* Search in class SEARCHED_CLASS (and its superclasses) for a method
615 matching METHOD_NAME and signature METHOD_SIGNATURE. Return a
616 FUNCTION_DECL on success, or NULL_TREE if none found. (Contrast
617 lookup_argument_method, which ignores return type.) If
618 SEARCHED_CLASS is an interface, search it too. */
620 lookup_java_method (tree searched_class
, tree method_name
,
621 tree method_signature
)
623 return lookup_do (searched_class
, SEARCH_INTERFACE
, method_name
,
624 method_signature
, build_java_signature
);
627 /* Return true iff KLASS (or its ancestors) has a method METHOD_NAME. */
629 has_method (tree klass
, tree method_name
)
631 return lookup_do (klass
, SEARCH_INTERFACE
,
632 method_name
, NULL_TREE
,
633 build_null_signature
) != NULL_TREE
;
636 /* Search in class SEARCHED_CLASS, but not its superclasses, for a
637 method matching METHOD_NAME and signature SIGNATURE. A private
638 helper for lookup_do. */
640 shallow_find_method (tree searched_class
, int flags
, tree method_name
,
641 tree signature
, tree (*signature_builder
) (tree
))
644 for (method
= TYPE_METHODS (searched_class
);
645 method
!= NULL_TREE
; method
= DECL_CHAIN (method
))
647 tree method_sig
= (*signature_builder
) (TREE_TYPE (method
));
648 if (DECL_NAME (method
) == method_name
&& method_sig
== signature
)
650 /* If the caller requires a visible method, then we
651 skip invisible methods here. */
652 if (! (flags
& SEARCH_VISIBLE
)
653 || ! METHOD_INVISIBLE (method
))
660 /* Search in the superclasses of SEARCHED_CLASS for a method matching
661 METHOD_NAME and signature SIGNATURE. A private helper for
664 find_method_in_superclasses (tree searched_class
, int flags
,
665 tree method_name
, tree signature
,
666 tree (*signature_builder
) (tree
))
669 for (klass
= CLASSTYPE_SUPER (searched_class
); klass
!= NULL_TREE
;
670 klass
= CLASSTYPE_SUPER (klass
))
673 method
= shallow_find_method (klass
, flags
, method_name
,
674 signature
, signature_builder
);
675 if (method
!= NULL_TREE
)
682 /* Search in the interfaces of SEARCHED_CLASS and its superinterfaces
683 for a method matching METHOD_NAME and signature SIGNATURE. A
684 private helper for lookup_do. */
686 find_method_in_interfaces (tree searched_class
, int flags
, tree method_name
,
687 tree signature
, tree (*signature_builder
) (tree
))
690 tree binfo
, base_binfo
;
692 for (binfo
= TYPE_BINFO (searched_class
), i
= 1;
693 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
695 tree iclass
= BINFO_TYPE (base_binfo
);
698 /* If the superinterface hasn't been loaded yet, do so now. */
699 if (!CLASS_LOADED_P (iclass
))
700 load_class (iclass
, 1);
702 /* First, we look in ICLASS. If that doesn't work we'll
703 recursively look through all its superinterfaces. */
704 method
= shallow_find_method (iclass
, flags
, method_name
,
705 signature
, signature_builder
);
706 if (method
!= NULL_TREE
)
709 method
= find_method_in_interfaces
710 (iclass
, flags
, method_name
, signature
, signature_builder
);
711 if (method
!= NULL_TREE
)
719 /* Search in class SEARCHED_CLASS (and its superclasses) for a method
720 matching METHOD_NAME and signature SIGNATURE. FLAGS control some
721 parameters of the search.
723 SEARCH_INTERFACE means also search interfaces and superinterfaces
726 SEARCH_SUPER means skip SEARCHED_CLASS and start with its
729 SEARCH_VISIBLE means skip methods for which METHOD_INVISIBLE is
732 Return the matched method DECL or NULL_TREE. SIGNATURE_BUILDER is
733 used on method candidates to build their (sometimes partial)
736 lookup_do (tree searched_class
, int flags
, tree method_name
,
737 tree signature
, tree (*signature_builder
) (tree
))
740 tree orig_class
= searched_class
;
742 if (searched_class
== NULL_TREE
)
745 if (flags
& SEARCH_SUPER
)
747 searched_class
= CLASSTYPE_SUPER (searched_class
);
748 if (searched_class
== NULL_TREE
)
752 /* First look in our own methods. */
753 method
= shallow_find_method (searched_class
, flags
, method_name
,
754 signature
, signature_builder
);
758 /* Then look in our superclasses. */
759 if (! CLASS_INTERFACE (TYPE_NAME (searched_class
)))
760 method
= find_method_in_superclasses (searched_class
, flags
, method_name
,
761 signature
, signature_builder
);
765 /* If that doesn't work, look in our interfaces. */
766 if (flags
& SEARCH_INTERFACE
)
767 method
= find_method_in_interfaces (orig_class
, flags
, method_name
,
768 signature
, signature_builder
);
773 /* Search in class CLAS for a constructor matching METHOD_SIGNATURE.
774 Return a FUNCTION_DECL on success, or NULL_TREE if none found. */
777 lookup_java_constructor (tree clas
, tree method_signature
)
779 tree method
= TYPE_METHODS (clas
);
780 for ( ; method
!= NULL_TREE
; method
= DECL_CHAIN (method
))
782 tree method_sig
= build_java_signature (TREE_TYPE (method
));
783 if (DECL_CONSTRUCTOR_P (method
) && method_sig
== method_signature
)
789 /* Return a type which is the Binary Numeric Promotion of the pair T1,
790 T2 and convert EXP1 and/or EXP2. See 5.6.2 Binary Numeric
791 Promotion. It assumes that both T1 and T2 are eligible to BNP. */
794 binary_numeric_promotion (tree t1
, tree t2
, tree
*exp1
, tree
*exp2
)
796 if (t1
== double_type_node
|| t2
== double_type_node
)
798 if (t1
!= double_type_node
)
799 *exp1
= convert (double_type_node
, *exp1
);
800 if (t2
!= double_type_node
)
801 *exp2
= convert (double_type_node
, *exp2
);
802 return double_type_node
;
804 if (t1
== float_type_node
|| t2
== float_type_node
)
806 if (t1
!= float_type_node
)
807 *exp1
= convert (float_type_node
, *exp1
);
808 if (t2
!= float_type_node
)
809 *exp2
= convert (float_type_node
, *exp2
);
810 return float_type_node
;
812 if (t1
== long_type_node
|| t2
== long_type_node
)
814 if (t1
!= long_type_node
)
815 *exp1
= convert (long_type_node
, *exp1
);
816 if (t2
!= long_type_node
)
817 *exp2
= convert (long_type_node
, *exp2
);
818 return long_type_node
;
821 if (t1
!= int_type_node
)
822 *exp1
= convert (int_type_node
, *exp1
);
823 if (t2
!= int_type_node
)
824 *exp2
= convert (int_type_node
, *exp2
);
825 return int_type_node
;