Fix type in the changelog entry,
[official-gcc.git] / gcc / java / typeck.c
blob6cbb3561dcab3b16cea18a8ac4f92471aa0873b8
1 /* Handle types for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1996-2015 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)
9 any later version.
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> */
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "alias.h"
30 #include "tree.h"
31 #include "options.h"
32 #include "fold-const.h"
33 #include "stor-layout.h"
34 #include "stringpool.h"
35 #include "obstack.h"
36 #include "flags.h"
37 #include "java-tree.h"
38 #include "jcf.h"
39 #include "convert.h"
40 #include "diagnostic-core.h"
42 static tree convert_ieee_real_to_integer (tree, tree);
43 static tree parse_signature_type (const unsigned char **,
44 const unsigned char *);
45 static tree lookup_do (tree, int, tree, tree, tree (*)(tree));
46 static tree build_null_signature (tree);
48 tree * type_map;
50 /* Set the type of the local variable with index SLOT to TYPE. */
52 void
53 set_local_type (int slot, tree type)
55 int max_locals = DECL_MAX_LOCALS(current_function_decl);
56 int nslots = TYPE_IS_WIDE (type) ? 2 : 1;
58 gcc_assert (slot >= 0 && (slot + nslots - 1 < max_locals));
60 type_map[slot] = type;
61 while (--nslots > 0)
62 type_map[++slot] = void_type_node;
65 /* Convert an IEEE real to an integer type. The result of such a
66 conversion when the source operand is a NaN isn't defined by
67 IEEE754, but by the Java language standard: it must be zero. Also,
68 overflows must be clipped to within range. This conversion
69 produces something like:
71 ((expr >= (float)MAX_INT)
72 ? MAX_INT
73 : ((expr <= (float)MIN_INT)
74 ? MIN_INT
75 : ((expr != expr)
76 ? 0
77 : (int)expr))) */
79 static tree
80 convert_ieee_real_to_integer (tree type, tree expr)
82 tree result;
83 expr = save_expr (expr);
85 result = fold_build3 (COND_EXPR, type,
86 fold_build2 (NE_EXPR, boolean_type_node, expr, expr),
87 convert (type, integer_zero_node),
88 convert_to_integer (type, expr));
90 result = fold_build3 (COND_EXPR, type,
91 fold_build2 (LE_EXPR, boolean_type_node, expr,
92 convert (TREE_TYPE (expr),
93 TYPE_MIN_VALUE (type))),
94 TYPE_MIN_VALUE (type),
95 result);
97 result = fold_build3 (COND_EXPR, type,
98 fold_build2 (GE_EXPR, boolean_type_node, expr,
99 convert (TREE_TYPE (expr),
100 TYPE_MAX_VALUE (type))),
101 TYPE_MAX_VALUE (type),
102 result);
104 return result;
107 /* Create an expression whose value is that of EXPR,
108 converted to type TYPE. The TREE_TYPE of the value
109 is always TYPE. This function implements all reasonable
110 conversions; callers should filter out those that are
111 not permitted by the language being compiled. */
113 tree
114 convert (tree type, tree expr)
116 enum tree_code code = TREE_CODE (type);
118 if (!expr)
119 return error_mark_node;
121 if (type == TREE_TYPE (expr)
122 || TREE_CODE (expr) == ERROR_MARK)
123 return expr;
124 if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
125 return error_mark_node;
126 if (code == VOID_TYPE)
127 return build1 (CONVERT_EXPR, type, expr);
128 if (code == BOOLEAN_TYPE)
129 return fold_convert (type, expr);
130 if (code == INTEGER_TYPE)
132 if (type == char_type_node || type == promoted_char_type_node)
133 return fold_convert (type, expr);
134 if ((really_constant_p (expr) || ! flag_unsafe_math_optimizations)
135 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
136 return convert_ieee_real_to_integer (type, expr);
137 else
139 /* fold very helpfully sets the overflow status if a type
140 overflows in a narrowing integer conversion, but Java
141 doesn't care. */
142 tree tmp = fold (convert_to_integer (type, expr));
143 if (TREE_CODE (tmp) == INTEGER_CST)
144 TREE_OVERFLOW (tmp) = 0;
145 return tmp;
148 if (code == REAL_TYPE)
149 return fold (convert_to_real (type, expr));
150 if (code == POINTER_TYPE)
151 return fold (convert_to_pointer (type, expr));
152 error ("conversion to non-scalar type requested");
153 return error_mark_node;
157 /* Return a data type that has machine mode MODE.
158 If the mode is an integer,
159 then UNSIGNEDP selects between signed and unsigned types. */
161 tree
162 java_type_for_mode (machine_mode mode, int unsignedp)
164 if (mode == TYPE_MODE (int_type_node))
165 return unsignedp ? unsigned_int_type_node : int_type_node;
166 if (mode == TYPE_MODE (long_type_node))
167 return unsignedp ? unsigned_long_type_node : long_type_node;
168 if (mode == TYPE_MODE (short_type_node))
169 return unsignedp ? unsigned_short_type_node : short_type_node;
170 if (mode == TYPE_MODE (byte_type_node))
171 return unsignedp ? unsigned_byte_type_node : byte_type_node;
172 if (mode == TYPE_MODE (float_type_node))
173 return float_type_node;
174 if (mode == TYPE_MODE (double_type_node))
175 return double_type_node;
177 return 0;
180 /* Return an integer type with BITS bits of precision,
181 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
183 tree
184 java_type_for_size (unsigned bits, int unsignedp)
186 if (bits <= TYPE_PRECISION (byte_type_node))
187 return unsignedp ? unsigned_byte_type_node : byte_type_node;
188 if (bits <= TYPE_PRECISION (short_type_node))
189 return unsignedp ? unsigned_short_type_node : short_type_node;
190 if (bits <= TYPE_PRECISION (int_type_node))
191 return unsignedp ? unsigned_int_type_node : int_type_node;
192 if (bits <= TYPE_PRECISION (long_type_node))
193 return unsignedp ? unsigned_long_type_node : long_type_node;
194 return 0;
197 /* Thorough checking of the arrayness of TYPE. */
200 is_array_type_p (tree type)
202 return TREE_CODE (type) == POINTER_TYPE
203 && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
204 && TYPE_ARRAY_P (TREE_TYPE (type));
207 /* Return the length of a Java array type.
208 Return -1 if the length is unknown or non-constant. */
210 HOST_WIDE_INT
211 java_array_type_length (tree array_type)
213 tree arfld;
214 if (TREE_CODE (array_type) == POINTER_TYPE)
215 array_type = TREE_TYPE (array_type);
216 arfld = DECL_CHAIN (DECL_CHAIN (TYPE_FIELDS (array_type)));
217 if (arfld != NULL_TREE)
219 tree index_type = TYPE_DOMAIN (TREE_TYPE (arfld));
220 if (index_type != NULL_TREE)
222 tree high = TYPE_MAX_VALUE (index_type);
223 if (TREE_CODE (high) == INTEGER_CST)
224 return TREE_INT_CST_LOW (high) + 1;
227 return -1;
230 /* An array of unknown length will be ultimately given a length of
231 -2, so that we can still have `length' producing a negative value
232 even if found. This was part of an optimization aiming at removing
233 `length' from static arrays. We could restore it, FIXME. */
235 tree
236 build_prim_array_type (tree element_type, HOST_WIDE_INT length)
238 tree index = NULL;
240 if (length != -1)
242 tree max_index = build_int_cst (sizetype, length - 1);
243 index = build_index_type (max_index);
245 return build_array_type (element_type, index);
248 /* Return a Java array type with a given ELEMENT_TYPE and LENGTH.
249 These are hashed (shared) using IDENTIFIER_SIGNATURE_TYPE.
250 The LENGTH is -1 if the length is unknown. */
252 tree
253 build_java_array_type (tree element_type, HOST_WIDE_INT length)
255 tree sig, t, fld, atype, arfld;
256 char buf[23];
257 tree elsig = build_java_signature (element_type);
258 tree el_name = element_type;
259 buf[0] = '[';
260 if (length >= 0)
261 sprintf (buf+1, HOST_WIDE_INT_PRINT_DEC, length);
262 else
263 buf[1] = '\0';
264 sig = ident_subst (IDENTIFIER_POINTER (elsig), IDENTIFIER_LENGTH (elsig),
265 buf, 0, 0, "");
266 t = IDENTIFIER_SIGNATURE_TYPE (sig);
267 if (t != NULL_TREE)
268 return TREE_TYPE (t);
269 t = make_class ();
270 IDENTIFIER_SIGNATURE_TYPE (sig) = build_pointer_type (t);
271 TYPE_ARRAY_P (t) = 1;
273 if (TREE_CODE (el_name) == POINTER_TYPE)
274 el_name = TREE_TYPE (el_name);
275 el_name = TYPE_NAME (el_name);
276 if (TREE_CODE (el_name) == TYPE_DECL)
277 el_name = DECL_NAME (el_name);
279 char suffix[23];
280 if (length >= 0)
281 sprintf (suffix, "[%d]", (int)length);
282 else
283 strcpy (suffix, "[]");
284 TYPE_NAME (t)
285 = TYPE_STUB_DECL (t)
286 = build_decl (input_location, TYPE_DECL,
287 identifier_subst (el_name, "", '.', '.', suffix),
289 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (t)) = true;
292 set_java_signature (t, sig);
293 set_super_info (0, t, object_type_node, 0);
294 if (TREE_CODE (element_type) == RECORD_TYPE)
295 element_type = promote_type (element_type);
296 TYPE_ARRAY_ELEMENT (t) = element_type;
298 /* Add length pseudo-field. */
299 fld = build_decl (input_location,
300 FIELD_DECL, get_identifier ("length"), int_type_node);
301 TYPE_FIELDS (t) = fld;
302 DECL_CONTEXT (fld) = t;
303 FIELD_PUBLIC (fld) = 1;
304 FIELD_FINAL (fld) = 1;
305 TREE_READONLY (fld) = 1;
307 atype = build_prim_array_type (element_type, length);
308 arfld = build_decl (input_location,
309 FIELD_DECL, get_identifier ("data"), atype);
310 DECL_CONTEXT (arfld) = t;
311 DECL_CHAIN (fld) = arfld;
312 DECL_ALIGN (arfld) = TYPE_ALIGN (element_type);
314 /* We could layout_class, but that loads java.lang.Object prematurely.
315 * This is called by the parser, and it is a bad idea to do load_class
316 * in the middle of parsing, because of possible circularity problems. */
317 push_super_field (t, object_type_node);
318 layout_type (t);
320 return t;
323 /* Promote TYPE to the type actually used for fields and parameters. */
325 tree
326 promote_type (tree type)
328 switch (TREE_CODE (type))
330 case RECORD_TYPE:
331 return build_pointer_type (type);
332 case BOOLEAN_TYPE:
333 if (type == boolean_type_node)
334 return promoted_boolean_type_node;
335 goto handle_int;
336 case INTEGER_TYPE:
337 if (type == char_type_node)
338 return promoted_char_type_node;
339 handle_int:
340 if (TYPE_PRECISION (type) < TYPE_PRECISION (int_type_node))
342 if (type == short_type_node)
343 return promoted_short_type_node;
344 if (type == byte_type_node)
345 return promoted_byte_type_node;
346 return int_type_node;
348 /* ... else fall through ... */
349 default:
350 return type;
354 /* Parse a signature string, starting at *PTR and ending at LIMIT.
355 Return the seen TREE_TYPE, updating *PTR. */
357 static tree
358 parse_signature_type (const unsigned char **ptr, const unsigned char *limit)
360 tree type;
361 gcc_assert (*ptr < limit);
363 switch (**ptr)
365 case 'B': (*ptr)++; return byte_type_node;
366 case 'C': (*ptr)++; return char_type_node;
367 case 'D': (*ptr)++; return double_type_node;
368 case 'F': (*ptr)++; return float_type_node;
369 case 'S': (*ptr)++; return short_type_node;
370 case 'I': (*ptr)++; return int_type_node;
371 case 'J': (*ptr)++; return long_type_node;
372 case 'Z': (*ptr)++; return boolean_type_node;
373 case 'V': (*ptr)++; return void_type_node;
374 case '[':
375 for ((*ptr)++; (*ptr) < limit && ISDIGIT (**ptr); ) (*ptr)++;
376 type = parse_signature_type (ptr, limit);
377 type = build_java_array_type (type, -1);
378 break;
379 case 'L':
381 const unsigned char *start = ++(*ptr);
382 const unsigned char *str = start;
383 for ( ; ; str++)
385 gcc_assert (str < limit);
386 if (*str == ';')
387 break;
389 *ptr = str+1;
390 type = lookup_class (unmangle_classname ((const char *) start, str - start));
391 break;
393 default:
394 gcc_unreachable ();
396 return promote_type (type);
399 /* Parse a Java "mangled" signature string, starting at SIG_STRING,
400 and SIG_LENGTH bytes long.
401 Return a gcc type node. */
403 tree
404 parse_signature_string (const unsigned char *sig_string, int sig_length)
406 tree result_type;
407 const unsigned char *str = sig_string;
408 const unsigned char *limit = str + sig_length;
410 if (str < limit && str[0] == '(')
412 tree argtype_list = NULL_TREE;
413 str++;
414 while (str < limit && str[0] != ')')
416 tree argtype = parse_signature_type (&str, limit);
417 argtype_list = tree_cons (NULL_TREE, argtype, argtype_list);
419 if (str++, str >= limit)
420 abort ();
421 result_type = parse_signature_type (&str, limit);
422 argtype_list = chainon (nreverse (argtype_list), end_params_node);
423 result_type = build_function_type (result_type, argtype_list);
425 else
426 result_type = parse_signature_type (&str, limit);
427 if (str != limit)
428 error ("junk at end of signature string");
429 return result_type;
432 /* Convert a signature to its type.
433 * Uses IDENTIFIER_SIGNATURE_TYPE as a cache (except for primitive types).
436 tree
437 get_type_from_signature (tree signature)
439 const unsigned char *sig = (const unsigned char *) IDENTIFIER_POINTER (signature);
440 int len = IDENTIFIER_LENGTH (signature);
441 tree type;
442 /* Primitive types aren't cached. */
443 if (len <= 1)
444 return parse_signature_string (sig, len);
445 type = IDENTIFIER_SIGNATURE_TYPE (signature);
446 if (type == NULL_TREE)
448 type = parse_signature_string (sig, len);
449 IDENTIFIER_SIGNATURE_TYPE (signature) = type;
451 return type;
454 /* Ignore signature and always return null. Used by has_method. */
456 static tree
457 build_null_signature (tree type ATTRIBUTE_UNUSED)
459 return NULL_TREE;
462 /* Return the signature string for the arguments of method type TYPE. */
464 tree
465 build_java_argument_signature (tree type)
467 extern struct obstack temporary_obstack;
468 tree sig = TYPE_ARGUMENT_SIGNATURE (type);
469 if (sig == NULL_TREE)
471 tree args = TYPE_ARG_TYPES (type);
472 if (TREE_CODE (type) == METHOD_TYPE)
473 args = TREE_CHAIN (args); /* Skip "this" argument. */
474 for (; args != end_params_node; args = TREE_CHAIN (args))
476 tree t = build_java_signature (TREE_VALUE (args));
477 obstack_grow (&temporary_obstack,
478 IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
480 obstack_1grow (&temporary_obstack, '\0');
482 sig = get_identifier ((char *) obstack_base (&temporary_obstack));
483 TYPE_ARGUMENT_SIGNATURE (type) = sig;
484 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
486 return sig;
489 /* Return the signature of the given TYPE. */
491 tree
492 build_java_signature (tree type)
494 tree sig, t;
495 while (TREE_CODE (type) == POINTER_TYPE)
496 type = TREE_TYPE (type);
497 MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type);
498 sig = TYPE_SIGNATURE (type);
499 if (sig == NULL_TREE)
501 char sg[2];
502 switch (TREE_CODE (type))
504 case BOOLEAN_TYPE: sg[0] = 'Z'; goto native;
505 case VOID_TYPE: sg[0] = 'V'; goto native;
506 case INTEGER_TYPE:
507 if (type == char_type_node || type == promoted_char_type_node)
509 sg[0] = 'C';
510 goto native;
512 switch (TYPE_PRECISION (type))
514 case 8: sg[0] = 'B'; goto native;
515 case 16: sg[0] = 'S'; goto native;
516 case 32: sg[0] = 'I'; goto native;
517 case 64: sg[0] = 'J'; goto native;
518 default: goto bad_type;
520 case REAL_TYPE:
521 switch (TYPE_PRECISION (type))
523 case 32: sg[0] = 'F'; goto native;
524 case 64: sg[0] = 'D'; goto native;
525 default: goto bad_type;
527 native:
528 sg[1] = 0;
529 sig = get_identifier (sg);
530 break;
531 case RECORD_TYPE:
532 if (TYPE_ARRAY_P (type))
534 t = build_java_signature (TYPE_ARRAY_ELEMENT (type));
535 sig = ident_subst (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t),
536 "[", 0, 0, "");
538 else
540 t = DECL_NAME (TYPE_NAME (type));
541 sig = ident_subst (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t),
542 "L", '.', '/', ";");
544 break;
545 case METHOD_TYPE:
546 case FUNCTION_TYPE:
548 extern struct obstack temporary_obstack;
549 sig = build_java_argument_signature (type);
550 obstack_1grow (&temporary_obstack, '(');
551 obstack_grow (&temporary_obstack,
552 IDENTIFIER_POINTER (sig), IDENTIFIER_LENGTH (sig));
553 obstack_1grow (&temporary_obstack, ')');
555 t = build_java_signature (TREE_TYPE (type));
556 obstack_grow0 (&temporary_obstack,
557 IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
559 sig = get_identifier ((char *) obstack_base (&temporary_obstack));
560 obstack_free (&temporary_obstack,
561 obstack_base (&temporary_obstack));
563 break;
564 bad_type:
565 default:
566 gcc_unreachable ();
568 TYPE_SIGNATURE (type) = sig;
570 return sig;
573 /* Save signature string SIG (an IDENTIFIER_NODE) in TYPE for future use. */
575 void
576 set_java_signature (tree type, tree sig)
578 tree old_sig;
579 while (TREE_CODE (type) == POINTER_TYPE)
580 type = TREE_TYPE (type);
581 MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC (type);
582 old_sig = TYPE_SIGNATURE (type);
583 if (old_sig != NULL_TREE && old_sig != sig)
584 abort ();
585 TYPE_SIGNATURE (type) = sig;
586 #if 0 /* careful about METHOD_TYPE */
587 if (IDENTIFIER_SIGNATURE_TYPE (sig) == NULL_TREE && TREE_PERMANENT (type))
588 IDENTIFIER_SIGNATURE_TYPE (sig) = type;
589 #endif
592 /* Search in SEARCHED_CLASS and its superclasses for a method matching
593 METHOD_NAME and signature METHOD_SIGNATURE. This function will
594 only search for methods declared in the class hierarchy; interfaces
595 will not be considered. Returns NULL_TREE if the method is not
596 found. */
597 tree
598 lookup_argument_method (tree searched_class, tree method_name,
599 tree method_signature)
601 return lookup_do (searched_class, 0,
602 method_name, method_signature,
603 build_java_argument_signature);
606 /* Like lookup_argument_method, but lets the caller set any flags
607 desired. */
608 tree
609 lookup_argument_method_generic (tree searched_class, tree method_name,
610 tree method_signature, int flags)
612 return lookup_do (searched_class, flags,
613 method_name, method_signature,
614 build_java_argument_signature);
618 /* Search in class SEARCHED_CLASS (and its superclasses) for a method
619 matching METHOD_NAME and signature METHOD_SIGNATURE. Return a
620 FUNCTION_DECL on success, or NULL_TREE if none found. (Contrast
621 lookup_argument_method, which ignores return type.) If
622 SEARCHED_CLASS is an interface, search it too. */
623 tree
624 lookup_java_method (tree searched_class, tree method_name,
625 tree method_signature)
627 return lookup_do (searched_class, SEARCH_INTERFACE, method_name,
628 method_signature, build_java_signature);
631 /* Return true iff KLASS (or its ancestors) has a method METHOD_NAME.  */
633 has_method (tree klass, tree method_name)
635 return lookup_do (klass, SEARCH_INTERFACE,
636 method_name, NULL_TREE,
637 build_null_signature) != NULL_TREE;
640 /* Search in class SEARCHED_CLASS, but not its superclasses, for a
641 method matching METHOD_NAME and signature SIGNATURE. A private
642 helper for lookup_do. */
643 static tree
644 shallow_find_method (tree searched_class, int flags, tree method_name,
645 tree signature, tree (*signature_builder) (tree))
647 tree method;
648 for (method = TYPE_METHODS (searched_class);
649 method != NULL_TREE; method = DECL_CHAIN (method))
651 tree method_sig = (*signature_builder) (TREE_TYPE (method));
652 if (DECL_NAME (method) == method_name && method_sig == signature)
654 /* If the caller requires a visible method, then we
655 skip invisible methods here. */
656 if (! (flags & SEARCH_VISIBLE)
657 || ! METHOD_INVISIBLE (method))
658 return method;
661 return NULL_TREE;
664 /* Search in the superclasses of SEARCHED_CLASS for a method matching
665 METHOD_NAME and signature SIGNATURE. A private helper for
666 lookup_do. */
667 static tree
668 find_method_in_superclasses (tree searched_class, int flags,
669 tree method_name, tree signature,
670 tree (*signature_builder) (tree))
672 tree klass;
673 for (klass = CLASSTYPE_SUPER (searched_class); klass != NULL_TREE;
674 klass = CLASSTYPE_SUPER (klass))
676 tree method;
677 method = shallow_find_method (klass, flags, method_name,
678 signature, signature_builder);
679 if (method != NULL_TREE)
680 return method;
683 return NULL_TREE;
686 /* Search in the interfaces of SEARCHED_CLASS and its superinterfaces
687 for a method matching METHOD_NAME and signature SIGNATURE. A
688 private helper for lookup_do. */
689 static tree
690 find_method_in_interfaces (tree searched_class, int flags, tree method_name,
691 tree signature, tree (*signature_builder) (tree))
693 int i;
694 tree binfo, base_binfo;
696 for (binfo = TYPE_BINFO (searched_class), i = 1;
697 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
699 tree iclass = BINFO_TYPE (base_binfo);
700 tree method;
702 /* If the superinterface hasn't been loaded yet, do so now. */
703 if (!CLASS_LOADED_P (iclass))
704 load_class (iclass, 1);
706 /* First, we look in ICLASS. If that doesn't work we'll
707 recursively look through all its superinterfaces. */
708 method = shallow_find_method (iclass, flags, method_name,
709 signature, signature_builder);
710 if (method != NULL_TREE)
711 return method;
713 method = find_method_in_interfaces
714 (iclass, flags, method_name, signature, signature_builder);
715 if (method != NULL_TREE)
716 return method;
719 return NULL_TREE;
723 /* Search in class SEARCHED_CLASS (and its superclasses) for a method
724 matching METHOD_NAME and signature SIGNATURE. FLAGS control some
725 parameters of the search.
727 SEARCH_INTERFACE means also search interfaces and superinterfaces
728 of SEARCHED_CLASS.
730 SEARCH_SUPER means skip SEARCHED_CLASS and start with its
731 superclass.
733 SEARCH_VISIBLE means skip methods for which METHOD_INVISIBLE is
734 set.
736 Return the matched method DECL or NULL_TREE. SIGNATURE_BUILDER is
737 used on method candidates to build their (sometimes partial)
738 signature. */
739 static tree
740 lookup_do (tree searched_class, int flags, tree method_name,
741 tree signature, tree (*signature_builder) (tree))
743 tree method;
744 tree orig_class = searched_class;
746 if (searched_class == NULL_TREE)
747 return NULL_TREE;
749 if (flags & SEARCH_SUPER)
751 searched_class = CLASSTYPE_SUPER (searched_class);
752 if (searched_class == NULL_TREE)
753 return NULL_TREE;
756 /* First look in our own methods. */
757 method = shallow_find_method (searched_class, flags, method_name,
758 signature, signature_builder);
759 if (method)
760 return method;
762 /* Then look in our superclasses. */
763 if (! CLASS_INTERFACE (TYPE_NAME (searched_class)))
764 method = find_method_in_superclasses (searched_class, flags, method_name,
765 signature, signature_builder);
766 if (method)
767 return method;
769 /* If that doesn't work, look in our interfaces. */
770 if (flags & SEARCH_INTERFACE)
771 method = find_method_in_interfaces (orig_class, flags, method_name,
772 signature, signature_builder);
774 return method;
777 /* Search in class CLAS for a constructor matching METHOD_SIGNATURE.
778 Return a FUNCTION_DECL on success, or NULL_TREE if none found. */
780 tree
781 lookup_java_constructor (tree clas, tree method_signature)
783 tree method = TYPE_METHODS (clas);
784 for ( ; method != NULL_TREE; method = DECL_CHAIN (method))
786 tree method_sig = build_java_signature (TREE_TYPE (method));
787 if (DECL_CONSTRUCTOR_P (method) && method_sig == method_signature)
788 return method;
790 return NULL_TREE;
793 /* Return a type which is the Binary Numeric Promotion of the pair T1,
794 T2 and convert EXP1 and/or EXP2. See 5.6.2 Binary Numeric
795 Promotion. It assumes that both T1 and T2 are eligible to BNP. */
797 tree
798 binary_numeric_promotion (tree t1, tree t2, tree *exp1, tree *exp2)
800 if (t1 == double_type_node || t2 == double_type_node)
802 if (t1 != double_type_node)
803 *exp1 = convert (double_type_node, *exp1);
804 if (t2 != double_type_node)
805 *exp2 = convert (double_type_node, *exp2);
806 return double_type_node;
808 if (t1 == float_type_node || t2 == float_type_node)
810 if (t1 != float_type_node)
811 *exp1 = convert (float_type_node, *exp1);
812 if (t2 != float_type_node)
813 *exp2 = convert (float_type_node, *exp2);
814 return float_type_node;
816 if (t1 == long_type_node || t2 == long_type_node)
818 if (t1 != long_type_node)
819 *exp1 = convert (long_type_node, *exp1);
820 if (t2 != long_type_node)
821 *exp2 = convert (long_type_node, *exp2);
822 return long_type_node;
825 if (t1 != int_type_node)
826 *exp1 = convert (int_type_node, *exp1);
827 if (t2 != int_type_node)
828 *exp2 = convert (int_type_node, *exp2);
829 return int_type_node;