* tree.c (make_node): Set TREE_SIDE_EFFECTS for expressions that
[official-gcc.git] / gcc / java / typeck.c
blobc6c1708ec3a9890359abe6adc2d635b82efeb9db
1 /* Handle types for the GNU compiler for the Java(TM) language.
2 Copyright (C) 1996, 97-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Written by Per Bothner <bothner@cygnus.com> */
27 #include "config.h"
28 #include "system.h"
29 #include "tree.h"
30 #include "obstack.h"
31 #include "flags.h"
32 #include "java-tree.h"
33 #include "jcf.h"
34 #include "convert.h"
35 #include "toplev.h"
37 static tree convert_ieee_real_to_integer PROTO ((tree, tree));
38 static tree parse_signature_type PROTO ((const unsigned char **,
39 const unsigned char *));
41 tree * type_map;
42 extern struct obstack permanent_obstack;
44 /* Set the type of the local variable with index SLOT to TYPE. */
46 void
47 set_local_type (slot, type)
48 int slot;
49 tree type;
51 int max_locals = DECL_MAX_LOCALS(current_function_decl);
52 int nslots = TYPE_IS_WIDE (type) ? 2 : 1;
53 if (slot < 0 || slot + nslots - 1 >= max_locals)
54 fatal ("invalid local variable index");
55 type_map[slot] = type;
56 while (--nslots > 0)
57 type_map[++slot] = void_type_node;
60 /* Convert an IEEE real to an integer type. The result of such a
61 conversion when the source operand is a NaN isn't defined by
62 IEEE754, but by the Java language standard: it must be zero. Also,
63 overflows must be clipped to within range. This conversion
64 produces something like:
66 ((expr >= (float)MAX_INT)
67 ? MAX_INT
68 : ((expr <= (float)MIN_INT)
69 ? MIN_INT
70 : ((expr != expr)
71 ? 0
72 : (int)expr))) */
74 static tree
75 convert_ieee_real_to_integer (type, expr)
76 tree type, expr;
78 tree result;
79 expr = save_expr (expr);
81 result = build (COND_EXPR, type,
82 build (NE_EXPR, boolean_type_node, expr, expr),
83 convert (type, integer_zero_node),
84 convert_to_integer (type, expr));
86 result = build (COND_EXPR, type,
87 build (LE_EXPR, boolean_type_node, expr,
88 convert (TREE_TYPE (expr), TYPE_MIN_VALUE (type))),
89 TYPE_MIN_VALUE (type),
90 result);
92 result = build (COND_EXPR, type,
93 build (GE_EXPR, boolean_type_node, expr,
94 convert (TREE_TYPE (expr), TYPE_MAX_VALUE (type))),
95 TYPE_MAX_VALUE (type),
96 result);
98 return result;
101 /* Create an expression whose value is that of EXPR,
102 converted to type TYPE. The TREE_TYPE of the value
103 is always TYPE. This function implements all reasonable
104 conversions; callers should filter out those that are
105 not permitted by the language being compiled. */
107 tree
108 convert (type, expr)
109 tree type, expr;
111 register enum tree_code code = TREE_CODE (type);
113 if (do_not_fold)
114 return build1 (NOP_EXPR, type, expr);
116 if (type == TREE_TYPE (expr)
117 || TREE_CODE (expr) == ERROR_MARK)
118 return expr;
119 if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
120 return error_mark_node;
121 if (code == VOID_TYPE)
122 return build1 (CONVERT_EXPR, type, expr);
123 if (code == BOOLEAN_TYPE)
124 return fold (convert_to_boolean (type, expr));
125 if (code == INTEGER_TYPE)
127 if (! flag_fast_math
128 && ! flag_emit_class_files
129 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
130 && TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
131 return fold (convert_ieee_real_to_integer (type, expr));
132 else
133 return fold (convert_to_integer (type, expr));
135 if (code == REAL_TYPE)
136 return fold (convert_to_real (type, expr));
137 if (code == CHAR_TYPE)
138 return fold (convert_to_char (type, expr));
139 if (code == POINTER_TYPE)
140 return fold (convert_to_pointer (type, expr));
141 error ("conversion to non-scalar type requested");
142 return error_mark_node;
146 tree
147 convert_to_char (type, expr)
148 tree type, expr;
150 return build1 (NOP_EXPR, type, expr);
153 tree
154 convert_to_boolean (type, expr)
155 tree type, expr;
157 return build1 (NOP_EXPR, type, expr);
160 /* Print an error message for invalid use of an incomplete type.
161 VALUE is the expression that was used (or 0 if that isn't known)
162 and TYPE is the type that was invalid. */
164 void
165 incomplete_type_error (value, type)
166 tree value ATTRIBUTE_UNUSED;
167 tree type ATTRIBUTE_UNUSED;
169 error ("internal error - use of undefined type");
172 /* Return a data type that has machine mode MODE.
173 If the mode is an integer,
174 then UNSIGNEDP selects between signed and unsigned types. */
176 tree
177 type_for_mode (mode, unsignedp)
178 enum machine_mode mode;
179 int unsignedp;
181 if (mode == TYPE_MODE (int_type_node))
182 return unsignedp ? unsigned_int_type_node : int_type_node;
183 if (mode == TYPE_MODE (long_type_node))
184 return unsignedp ? unsigned_long_type_node : long_type_node;
185 if (mode == TYPE_MODE (short_type_node))
186 return unsignedp ? unsigned_short_type_node : short_type_node;
187 if (mode == TYPE_MODE (byte_type_node))
188 return unsignedp ? unsigned_byte_type_node : byte_type_node;
189 if (mode == TYPE_MODE (float_type_node))
190 return float_type_node;
191 if (mode == TYPE_MODE (double_type_node))
192 return double_type_node;
194 return 0;
197 /* Return an integer type with BITS bits of precision,
198 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
200 tree
201 type_for_size (bits, unsignedp)
202 unsigned bits;
203 int unsignedp;
205 if (bits <= TYPE_PRECISION (byte_type_node))
206 return unsignedp ? unsigned_byte_type_node : byte_type_node;
207 if (bits <= TYPE_PRECISION (short_type_node))
208 return unsignedp ? unsigned_short_type_node : short_type_node;
209 if (bits <= TYPE_PRECISION (int_type_node))
210 return unsignedp ? unsigned_int_type_node : int_type_node;
211 if (bits <= TYPE_PRECISION (long_type_node))
212 return unsignedp ? unsigned_long_type_node : long_type_node;
213 return 0;
216 /* Return a type the same as TYPE except unsigned or
217 signed according to UNSIGNEDP. */
219 tree
220 signed_or_unsigned_type (unsignedp, type)
221 int unsignedp;
222 tree type;
224 if (! INTEGRAL_TYPE_P (type))
225 return type;
226 if (TYPE_PRECISION (type) == TYPE_PRECISION (int_type_node))
227 return unsignedp ? unsigned_int_type_node : int_type_node;
228 if (TYPE_PRECISION (type) == TYPE_PRECISION (byte_type_node))
229 return unsignedp ? unsigned_byte_type_node : byte_type_node;
230 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_type_node))
231 return unsignedp ? unsigned_short_type_node : short_type_node;
232 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_type_node))
233 return unsignedp ? unsigned_long_type_node : long_type_node;
234 return type;
237 /* Return a signed type the same as TYPE in other respects. */
239 tree
240 signed_type (type)
241 tree type;
243 return signed_or_unsigned_type (0, type);
246 /* Return an unsigned type the same as TYPE in other respects. */
248 tree
249 unsigned_type (type)
250 tree type;
252 return signed_or_unsigned_type (1, type);
256 /* Mark EXP saying that we need to be able to take the
257 address of it; it should not be allocated in a register.
258 Value is 1 if successful. */
261 mark_addressable (exp)
262 tree exp;
264 register tree x = exp;
265 while (1)
266 switch (TREE_CODE (x))
268 case ADDR_EXPR:
269 case COMPONENT_REF:
270 case ARRAY_REF:
271 case REALPART_EXPR:
272 case IMAGPART_EXPR:
273 x = TREE_OPERAND (x, 0);
274 break;
276 case TRUTH_ANDIF_EXPR:
277 case TRUTH_ORIF_EXPR:
278 case COMPOUND_EXPR:
279 x = TREE_OPERAND (x, 1);
280 break;
282 case COND_EXPR:
283 return mark_addressable (TREE_OPERAND (x, 1))
284 & mark_addressable (TREE_OPERAND (x, 2));
286 case CONSTRUCTOR:
287 TREE_ADDRESSABLE (x) = 1;
288 return 1;
290 case INDIRECT_REF:
291 /* We sometimes add a cast *(TYPE*)&FOO to handle type and mode
292 incompatibility problems. Handle this case by marking FOO. */
293 if (TREE_CODE (TREE_OPERAND (x, 0)) == NOP_EXPR
294 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (x, 0), 0)) == ADDR_EXPR)
296 x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
297 break;
299 if (TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
301 x = TREE_OPERAND (x, 0);
302 break;
304 return 1;
306 case VAR_DECL:
307 case CONST_DECL:
308 case PARM_DECL:
309 case RESULT_DECL:
310 case FUNCTION_DECL:
311 TREE_ADDRESSABLE (x) = 1;
312 #if 0 /* poplevel deals with this now. */
313 if (DECL_CONTEXT (x) == 0)
314 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
315 #endif
316 /* drops through */
317 default:
318 return 1;
322 /* Thorough checking of the arrayness of TYPE. */
325 is_array_type_p (type)
326 tree type;
328 return TREE_CODE (type) == POINTER_TYPE
329 && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
330 && TYPE_ARRAY_P (TREE_TYPE (type));
333 /* Return the length of a Java array type.
334 Return -1 if the length is unknown or non-constant. */
336 HOST_WIDE_INT
337 java_array_type_length (array_type)
338 tree array_type;
340 tree arfld;
341 if (TREE_CODE (array_type) == POINTER_TYPE)
342 array_type = TREE_TYPE (array_type);
343 arfld = TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (array_type)));
344 if (arfld != NULL_TREE)
346 tree index_type = TYPE_DOMAIN (TREE_TYPE (arfld));
347 tree high = TYPE_MAX_VALUE (index_type);
348 if (TREE_CODE (high) == INTEGER_CST)
349 return TREE_INT_CST_LOW (high) + 1;
351 return -1;
354 tree
355 build_prim_array_type (element_type, length)
356 tree element_type;
357 HOST_WIDE_INT length;
359 tree max_index = build_int_2 (length - 1, 0);
360 TREE_TYPE (max_index) = sizetype;
361 return build_array_type (element_type, build_index_type (max_index));
364 /* Return a Java array type with a given ELEMENT_TYPE and LENGTH.
365 These are hashed (shared) using IDENTIFIER_SIGNATURE_TYPE.
366 The LENGTH is -1 if the length is unknown. */
368 tree
369 build_java_array_type (element_type, length)
370 tree element_type;
371 HOST_WIDE_INT length;
373 tree sig, t, fld;
374 char buf[12];
375 tree elsig = build_java_signature (element_type);
376 tree el_name = element_type;
377 sprintf (buf, length >= 0 ? "[%d" : "[", length);
378 sig = ident_subst (IDENTIFIER_POINTER (elsig), IDENTIFIER_LENGTH (elsig),
379 buf, 0, 0, "");
380 t = IDENTIFIER_SIGNATURE_TYPE (sig);
381 if (t != NULL_TREE)
382 return TREE_TYPE (t);
383 t = make_class ();
384 IDENTIFIER_SIGNATURE_TYPE (sig) = build_pointer_type (t);
385 TYPE_ARRAY_P (t) = 1;
387 if (TREE_CODE (el_name) == POINTER_TYPE)
388 el_name = TREE_TYPE (el_name);
389 el_name = TYPE_NAME (el_name);
390 if (TREE_CODE (el_name) == TYPE_DECL)
391 el_name = DECL_NAME (el_name);
392 TYPE_NAME (t) = identifier_subst (el_name, "", '.', '.', "[]");
394 set_java_signature (t, sig);
395 set_super_info (0, t, object_type_node, 0);
396 if (TREE_CODE (element_type) == RECORD_TYPE)
397 element_type = promote_type (element_type);
398 TYPE_ARRAY_ELEMENT (t) = element_type;
400 /* Add length pseudo-field. */
401 push_obstacks (&permanent_obstack, &permanent_obstack);
402 fld = build_decl (FIELD_DECL, get_identifier ("length"), int_type_node);
403 TYPE_FIELDS (t) = fld;
404 DECL_CONTEXT (fld) = t;
405 FIELD_PUBLIC (fld) = 1;
406 FIELD_FINAL (fld) = 1;
408 if (length >= 0)
410 tree atype = build_prim_array_type (element_type, length);
411 tree arfld = build_decl (FIELD_DECL, get_identifier ("data"), atype);
412 DECL_CONTEXT (arfld) = t;
413 TREE_CHAIN (fld) = arfld;
415 else
416 TYPE_ALIGN (t) = TYPE_ALIGN (element_type);
417 pop_obstacks ();
419 /* We could layout_class, but that loads java.lang.Object prematurely.
420 * This is called by the parser, and it is a bad idea to do load_class
421 * in the middle of parsing, because of possible circularity problems. */
422 push_super_field (t, object_type_node);
423 layout_type (t);
425 return t;
428 /* Promote TYPE to the type actually used for fields and parameters. */
430 tree
431 promote_type (type)
432 tree type;
434 switch (TREE_CODE (type))
436 case RECORD_TYPE:
437 return build_pointer_type (CLASS_TO_HANDLE_TYPE (type));
438 case BOOLEAN_TYPE:
439 if (type == boolean_type_node)
440 return promoted_boolean_type_node;
441 goto handle_int;
442 case CHAR_TYPE:
443 if (type == char_type_node)
444 return promoted_char_type_node;
445 goto handle_int;
446 case INTEGER_TYPE:
447 handle_int:
448 if (TYPE_PRECISION (type) < TYPE_PRECISION (int_type_node))
450 if (type == short_type_node)
451 return promoted_short_type_node;
452 if (type == byte_type_node)
453 return promoted_byte_type_node;
454 return int_type_node;
456 /* ... else fall through ... */
457 default:
458 return type;
462 /* Parse a signature string, starting at *PTR and ending at LIMIT.
463 Return the seen TREE_TYPE, updating *PTR. */
465 static tree
466 parse_signature_type (ptr, limit)
467 const unsigned char **ptr, *limit;
469 tree type;
470 if ((*ptr) >= limit)
471 fatal ("bad signature string");
472 switch (*(*ptr))
474 case 'B': (*ptr)++; return byte_type_node;
475 case 'C': (*ptr)++; return char_type_node;
476 case 'D': (*ptr)++; return double_type_node;
477 case 'F': (*ptr)++; return float_type_node;
478 case 'S': (*ptr)++; return short_type_node;
479 case 'I': (*ptr)++; return int_type_node;
480 case 'J': (*ptr)++; return long_type_node;
481 case 'Z': (*ptr)++; return boolean_type_node;
482 case 'V': (*ptr)++; return void_type_node;
483 case '[':
484 for ((*ptr)++; (*ptr) < limit && ISDIGIT (**ptr); ) (*ptr)++;
485 type = parse_signature_type (ptr, limit);
486 type = build_java_array_type (type, -1);
487 break;
488 case 'L':
490 const unsigned char *start = ++(*ptr);
491 register const unsigned char *str = start;
492 for ( ; ; str++)
494 if (str >= limit)
495 fatal ("bad signature string");
496 if (*str == ';')
497 break;
499 *ptr = str+1;
500 type = lookup_class (unmangle_classname (start, str - start));
501 break;
503 default:
504 fatal ("unrecognized signature string");
506 return promote_type (type);
509 /* Parse a Java "mangled" signature string, starting at SIG_STRING,
510 and SIG_LENGTH bytes long.
511 Return a gcc type node. */
513 tree
514 parse_signature_string (sig_string, sig_length)
515 const unsigned char *sig_string;
516 int sig_length;
518 tree result_type;
519 const unsigned char *str = sig_string;
520 const unsigned char *limit = str + sig_length;
522 push_obstacks (&permanent_obstack, &permanent_obstack);
523 if (str < limit && str[0] == '(')
525 tree argtype_list = NULL_TREE;
526 str++;
527 while (str < limit && str[0] != ')')
529 tree argtype = parse_signature_type (&str, limit);
530 argtype_list = tree_cons (NULL_TREE, argtype, argtype_list);
532 if (str++, str >= limit)
533 fatal ("bad signature string");
534 result_type = parse_signature_type (&str, limit);
535 argtype_list = chainon (nreverse (argtype_list), end_params_node);
536 result_type = build_function_type (result_type, argtype_list);
538 else
539 result_type = parse_signature_type (&str, limit);
540 if (str != limit)
541 error ("junk at end of signature string");
542 pop_obstacks ();
543 return result_type;
546 /* Convert a signature to its type.
547 * Uses IDENTIFIER_SIGNATURE_TYPE as a cache (except for primitive types).
550 tree
551 get_type_from_signature (tree signature)
553 const unsigned char *sig = (const unsigned char *) IDENTIFIER_POINTER (signature);
554 int len = IDENTIFIER_LENGTH (signature);
555 tree type;
556 /* Primitive types aren't cached. */
557 if (len <= 1)
558 return parse_signature_string (sig, len);
559 type = IDENTIFIER_SIGNATURE_TYPE (signature);
560 if (type == NULL_TREE)
562 type = parse_signature_string (sig, len);
563 IDENTIFIER_SIGNATURE_TYPE (signature) = type;
565 return type;
568 /* Return the signature string for the arguments of method type TYPE. */
570 tree
571 build_java_argument_signature (type)
572 tree type;
574 extern struct obstack temporary_obstack;
575 tree sig = TYPE_ARGUMENT_SIGNATURE (type);
576 if (sig == NULL_TREE)
578 tree args = TYPE_ARG_TYPES (type);
579 if (TREE_CODE (type) == METHOD_TYPE)
580 args = TREE_CHAIN (args); /* Skip "this" argument. */
581 for (; args != end_params_node; args = TREE_CHAIN (args))
583 tree t = build_java_signature (TREE_VALUE (args));
584 obstack_grow (&temporary_obstack,
585 IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
587 obstack_1grow (&temporary_obstack, '\0');
589 sig = get_identifier (obstack_base (&temporary_obstack));
590 TYPE_ARGUMENT_SIGNATURE (type) = sig;
591 obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
593 return sig;
596 /* Return the signature of the given TYPE. */
598 tree
599 build_java_signature (type)
600 tree type;
602 tree sig, t;
603 push_obstacks (&permanent_obstack, &permanent_obstack);
604 while (TREE_CODE (type) == POINTER_TYPE)
605 type = TREE_TYPE (type);
606 if (TYPE_LANG_SPECIFIC (type) == NULL)
608 TYPE_LANG_SPECIFIC (type) = (struct lang_type *)
609 perm_calloc (1, sizeof (struct lang_type));
611 sig = TYPE_LANG_SPECIFIC (type)->signature;
612 if (sig == NULL_TREE)
614 char sg[2];
615 switch (TREE_CODE (type))
617 case BOOLEAN_TYPE: sg[0] = 'Z'; goto native;
618 case CHAR_TYPE: sg[0] = 'C'; goto native;
619 case VOID_TYPE: sg[0] = 'V'; goto native;
620 case INTEGER_TYPE:
621 switch (TYPE_PRECISION (type))
623 case 8: sg[0] = 'B'; goto native;
624 case 16: sg[0] = 'S'; goto native;
625 case 32: sg[0] = 'I'; goto native;
626 case 64: sg[0] = 'J'; goto native;
627 default: goto bad_type;
629 case REAL_TYPE:
630 switch (TYPE_PRECISION (type))
632 case 32: sg[0] = 'F'; goto native;
633 case 64: sg[0] = 'D'; goto native;
634 default: goto bad_type;
636 native:
637 sg[1] = 0;
638 sig = get_identifier (sg);
639 break;
640 case RECORD_TYPE:
641 if (TYPE_ARRAY_P (type))
643 t = build_java_signature (TYPE_ARRAY_ELEMENT (type));
644 sig = ident_subst (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t),
645 "[", 0, 0, "");
647 else
649 t = DECL_NAME (TYPE_NAME (type));
650 sig = ident_subst (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t),
651 "L", '.', '/', ";");
653 break;
654 case METHOD_TYPE:
655 case FUNCTION_TYPE:
657 extern struct obstack temporary_obstack;
658 sig = build_java_argument_signature (type);
659 obstack_1grow (&temporary_obstack, '(');
660 obstack_grow (&temporary_obstack,
661 IDENTIFIER_POINTER (sig), IDENTIFIER_LENGTH (sig));
662 obstack_1grow (&temporary_obstack, ')');
664 t = build_java_signature (TREE_TYPE (type));
665 obstack_grow0 (&temporary_obstack,
666 IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
668 sig = get_identifier (obstack_base (&temporary_obstack));
669 obstack_free (&temporary_obstack,
670 obstack_base (&temporary_obstack));
672 break;
673 bad_type:
674 default:
675 fatal ("internal error - build_java_signature passed invalid type");
677 TYPE_LANG_SPECIFIC (type)->signature = sig;
679 pop_obstacks ();
680 return sig;
683 /* Save signature string SIG (an IDENTIFIER_NODE) in TYPE for future use. */
685 void
686 set_java_signature (type, sig)
687 tree type;
688 tree sig;
690 tree old_sig;
691 while (TREE_CODE (type) == POINTER_TYPE)
692 type = TREE_TYPE (type);
693 if (TYPE_LANG_SPECIFIC (type) == NULL)
695 TYPE_LANG_SPECIFIC (type) = (struct lang_type *)
696 perm_calloc (1, sizeof (struct lang_type));
699 old_sig = TYPE_LANG_SPECIFIC (type)->signature;
700 if (old_sig != NULL_TREE && old_sig != sig)
701 fatal ("internal error - set_java_signature");
702 TYPE_LANG_SPECIFIC (type)->signature = sig;
703 #if 0 /* careful about METHOD_TYPE */
704 if (IDENTIFIER_SIGNATURE_TYPE (sig) == NULL_TREE && TREE_PERMANENT (type))
705 IDENTIFIER_SIGNATURE_TYPE (sig) = type;
706 #endif
709 /* Search in class CLAS (and its superclasses) for a method
710 matching METHOD_NAME and argument signature METHOD_SIGNATURE.
711 Return a FUNCTION_DECL on success, or NULL_TREE if none found.
712 (Contrast lookup_java_method, which takes into account return type.) */
714 tree
715 lookup_argument_method (clas, method_name, method_signature)
716 tree clas, method_name, method_signature;
718 tree method;
719 while (clas != NULL_TREE)
721 for (method = TYPE_METHODS (clas);
722 method != NULL_TREE; method = TREE_CHAIN (method))
724 tree method_sig = build_java_argument_signature (TREE_TYPE (method));
725 tree name = DECL_NAME (method);
726 if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
727 EXPR_WFL_NODE (name) : name) == method_name
728 && method_sig == method_signature)
729 return method;
731 clas = CLASSTYPE_SUPER (clas);
733 return NULL_TREE;
736 /* Search in class CLAS (and its superclasses) for a method
737 matching METHOD_NAME and signature METHOD_SIGNATURE.
738 Return a FUNCTION_DECL on success, or NULL_TREE if none found.
739 (Contrast lookup_argument_method, which ignores return type.) */
741 tree
742 lookup_java_method (clas, method_name, method_signature)
743 tree clas, method_name, method_signature;
745 tree method;
746 while (clas != NULL_TREE)
748 for (method = TYPE_METHODS (clas);
749 method != NULL_TREE; method = TREE_CHAIN (method))
751 tree method_sig = build_java_signature (TREE_TYPE (method));
752 if (DECL_NAME (method) == method_name
753 && method_sig == method_signature)
754 return method;
756 clas = CLASSTYPE_SUPER (clas);
758 return NULL_TREE;
761 /* Search in class CLAS for a constructor matching METHOD_SIGNATURE.
762 Return a FUNCTION_DECL on success, or NULL_TREE if none found. */
764 tree
765 lookup_java_constructor (clas, method_signature)
766 tree clas, method_signature;
768 tree method = TYPE_METHODS (clas);
769 for ( ; method != NULL_TREE; method = TREE_CHAIN (method))
771 tree method_sig = build_java_signature (TREE_TYPE (method));
772 if (DECL_CONSTRUCTOR_P (method) && method_sig == method_signature)
773 return method;
775 return NULL_TREE;
778 /* Return a type which is the Binary Numeric Promotion of the pair T1,
779 T2 and convert EXP1 and/or EXP2. See 5.6.2 Binary Numeric
780 Promotion. It assumes that both T1 and T2 are elligible to BNP. */
782 tree
783 binary_numeric_promotion (t1, t2, exp1, exp2)
784 tree t1;
785 tree t2;
786 tree *exp1;
787 tree *exp2;
789 if (t1 == double_type_node || t2 == double_type_node)
791 if (t1 != double_type_node)
792 *exp1 = convert (double_type_node, *exp1);
793 if (t2 != double_type_node)
794 *exp2 = convert (double_type_node, *exp2);
795 return double_type_node;
797 if (t1 == float_type_node || t2 == float_type_node)
799 if (t1 != float_type_node)
800 *exp1 = convert (float_type_node, *exp1);
801 if (t2 != float_type_node)
802 *exp2 = convert (float_type_node, *exp2);
803 return float_type_node;
805 if (t1 == long_type_node || t2 == long_type_node)
807 if (t1 != long_type_node)
808 *exp1 = convert (long_type_node, *exp1);
809 if (t2 != long_type_node)
810 *exp2 = convert (long_type_node, *exp2);
811 return long_type_node;
814 if (t1 != int_type_node)
815 *exp1 = convert (int_type_node, *exp1);
816 if (t2 != int_type_node)
817 *exp2 = convert (int_type_node, *exp2);
818 return int_type_node;