OSDN Git Service

211e4b69cc47680ea32eb6ad1c735cc42285dab9
[pf3gnuchains/gcc-fork.git] / gcc / java / typeck.c
1 /* Handle types for the GNU compiler for the Java(TM) language.
2    Copyright (C) 1996 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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.
10
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.
15
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.  
20
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.  */
24
25 /* Written by Per Bothner <bothner@cygnus.com> */
26
27 #include "config.h"
28 #include "tree.h"
29 #include "obstack.h"
30 #include "java-tree.h"
31 #include "jcf.h"
32 #include "convert.h"
33
34 tree * type_map;
35 extern struct obstack permanent_obstack;
36
37 /* Set the type of the local variable with index SLOT to TYPE. */
38
39 void
40 set_local_type (slot, type)
41      int slot;
42      tree type;
43 {
44   int max_locals = DECL_MAX_LOCALS(current_function_decl);
45   int nslots = TYPE_IS_WIDE (type) ? 2 : 1;
46   if (slot < 0 || slot + nslots - 1 >= max_locals)
47     fatal ("invalid local variable index");
48   type_map[slot] = type;
49   while (--nslots > 0)
50     type_map[++slot] = void_type_node;
51 }
52
53 extern tree convert_to_integer (tree type, tree expr);
54 extern tree convert_to_real (tree type, tree expr);
55 extern tree convert_to_pointer (tree type, tree expr);
56
57 /* Create an expression whose value is that of EXPR,
58    converted to type TYPE.  The TREE_TYPE of the value
59    is always TYPE.  This function implements all reasonable
60    conversions; callers should filter out those that are
61    not permitted by the language being compiled.  */
62
63 tree
64 convert (type, expr)
65      tree type, expr;
66 {
67   register enum tree_code code = TREE_CODE (type);
68
69   if (type == TREE_TYPE (expr)
70       || TREE_CODE (expr) == ERROR_MARK)
71     return expr;
72   if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
73     return error_mark_node;
74   if (code == BOOLEAN_TYPE)
75     return fold (convert_to_boolean (type, expr));
76   if (code == INTEGER_TYPE)
77     return fold (convert_to_integer (type, expr));
78   if (code == REAL_TYPE)
79     return fold (convert_to_real (type, expr));
80   if (code == CHAR_TYPE)
81     return fold (convert_to_char (type, expr));
82   if (code == POINTER_TYPE)
83     return fold (convert_to_pointer (type, expr));
84   error ("conversion to non-scalar type requested");
85   return error_mark_node;
86 }
87
88 tree
89 convert_to_char (type, expr)
90     tree type, expr;
91 {
92   return build1 (NOP_EXPR, type, expr);
93 }
94
95 tree
96 convert_to_boolean (type, expr)
97      tree type, expr;
98 {
99   return build1 (NOP_EXPR, type, expr);
100 }
101
102 /* Print an error message for invalid use of an incomplete type.
103    VALUE is the expression that was used (or 0 if that isn't known)
104    and TYPE is the type that was invalid.  */
105
106 void
107 incomplete_type_error (value, type)
108      tree value;
109      tree type;
110 {
111   error ("internal error - use of undefined type");
112 }
113
114 /* Return a data type that has machine mode MODE.
115    If the mode is an integer,
116    then UNSIGNEDP selects between signed and unsigned types.  */
117
118 tree
119 type_for_mode (mode, unsignedp)
120      enum machine_mode mode;
121      int unsignedp;
122 {
123   if (mode == TYPE_MODE (int_type_node))
124     return unsignedp ? unsigned_int_type_node : int_type_node;
125   if (mode == TYPE_MODE (long_type_node))
126     return unsignedp ? unsigned_long_type_node : long_type_node;
127   if (mode == TYPE_MODE (short_type_node))
128     return unsignedp ? unsigned_short_type_node : short_type_node;
129   if (mode == TYPE_MODE (byte_type_node))
130     return unsignedp ? unsigned_byte_type_node : byte_type_node;
131   if (mode == TYPE_MODE (float_type_node))
132     return float_type_node;
133   if (mode == TYPE_MODE (double_type_node))
134     return double_type_node;
135
136 #if 0
137   if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
138     return build_pointer_type (char_type_node);
139
140   if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
141     return build_pointer_type (integer_type_node);
142 #endif
143
144   return 0;
145 }
146
147 /* Return an integer type with BITS bits of precision,
148    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
149
150 tree
151 type_for_size (bits, unsignedp)
152      unsigned bits;
153      int unsignedp;
154 {
155   if (bits <= TYPE_PRECISION (byte_type_node))
156     return unsignedp ? unsigned_byte_type_node : byte_type_node;
157   if (bits <= TYPE_PRECISION (short_type_node))
158     return unsignedp ? unsigned_short_type_node : short_type_node;
159   if (bits <= TYPE_PRECISION (int_type_node))
160     return unsignedp ? unsigned_int_type_node : int_type_node;
161   if (bits <= TYPE_PRECISION (long_type_node))
162     return unsignedp ? unsigned_long_type_node : long_type_node;
163   return 0;
164 }
165
166 /* Return a type the same as TYPE except unsigned or
167    signed according to UNSIGNEDP.  */
168
169 tree
170 signed_or_unsigned_type (unsignedp, type)
171      int unsignedp;
172      tree type;
173 {
174   if (! INTEGRAL_TYPE_P (type))
175     return type;
176   if (TYPE_PRECISION (type) == TYPE_PRECISION (int_type_node))
177     return unsignedp ? unsigned_int_type_node : int_type_node;
178   if (TYPE_PRECISION (type) == TYPE_PRECISION (byte_type_node))
179     return unsignedp ? unsigned_byte_type_node : byte_type_node;
180   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_type_node))
181     return unsignedp ? unsigned_short_type_node : short_type_node;
182   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_type_node))
183     return unsignedp ? unsigned_long_type_node : long_type_node;
184   return type;
185 }
186
187 /* Return a signed type the same as TYPE in other respects.  */
188
189 tree
190 signed_type (type)
191      tree type;
192 {
193   return signed_or_unsigned_type (0, type);
194 }
195
196 /* Return an unsigned type the same as TYPE in other respects.  */
197
198 tree
199 unsigned_type (type)
200      tree type;
201 {
202   return signed_or_unsigned_type (1, type);
203
204 }
205
206 /* Mark EXP saying that we need to be able to take the
207    address of it; it should not be allocated in a register.
208    Value is 1 if successful.  */
209
210 int
211 mark_addressable (exp)
212      tree exp;
213 {
214   register tree x = exp;
215   while (1)
216     switch (TREE_CODE (x))
217       {
218       case ADDR_EXPR:
219       case COMPONENT_REF:
220       case ARRAY_REF:
221       case REALPART_EXPR:
222       case IMAGPART_EXPR:
223         x = TREE_OPERAND (x, 0);
224         break;
225
226       case TRUTH_ANDIF_EXPR:
227       case TRUTH_ORIF_EXPR:
228       case COMPOUND_EXPR:
229         x = TREE_OPERAND (x, 1);
230         break;
231
232       case COND_EXPR:
233         return mark_addressable (TREE_OPERAND (x, 1))
234           & mark_addressable (TREE_OPERAND (x, 2));
235
236       case CONSTRUCTOR:
237         TREE_ADDRESSABLE (x) = 1;
238         return 1;
239
240       case INDIRECT_REF:
241         /* We sometimes add a cast *(TYPE*)&FOO to handle type and mode
242            incompatibility problems.  Handle this case by marking FOO.  */
243         if (TREE_CODE (TREE_OPERAND (x, 0)) == NOP_EXPR
244             && TREE_CODE (TREE_OPERAND (TREE_OPERAND (x, 0), 0)) == ADDR_EXPR)
245           {
246             x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
247             break;
248           }
249         if (TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
250           {
251             x = TREE_OPERAND (x, 0);
252             break;
253           }
254         return 1;
255
256       case VAR_DECL:
257       case CONST_DECL:
258       case PARM_DECL:
259       case RESULT_DECL:
260       case FUNCTION_DECL:
261         TREE_ADDRESSABLE (x) = 1;
262 #if 0  /* poplevel deals with this now.  */
263         if (DECL_CONTEXT (x) == 0)
264           TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
265 #endif
266         /* drops through */
267       default:
268         return 1;
269     }
270 }
271
272 /* Thorough checking of the arrayness of TYPE.  */
273
274 int
275 is_array_type_p (type)
276      tree type;
277 {
278   return TREE_CODE (type) == POINTER_TYPE
279     && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE
280     && TYPE_ARRAY_P (TREE_TYPE (type));
281 }
282
283 /* Return the length of a Java array type.
284    Return -1 if the length is unknown or non-constant. */
285
286 HOST_WIDE_INT
287 java_array_type_length (array_type)
288      tree array_type;
289 {
290   tree arfld;
291   if (TREE_CODE (array_type) == POINTER_TYPE)
292     array_type = TREE_TYPE (array_type);
293   arfld = TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (array_type)));
294   if (arfld != NULL_TREE)
295     {
296       tree index_type = TYPE_DOMAIN (TREE_TYPE (arfld));
297       tree high = TYPE_MAX_VALUE (index_type);
298       if (TREE_CODE (high) == INTEGER_CST)
299         return TREE_INT_CST_LOW (high) + 1;
300     }
301   return -1;
302 }
303
304 tree
305 build_prim_array_type (element_type, length)
306      tree element_type;
307      HOST_WIDE_INT length;
308 {
309   tree max_index = build_int_2 (length - 1, 0);
310   TREE_TYPE (max_index) = sizetype;
311   return build_array_type (element_type, build_index_type (max_index));
312 }
313
314 /* Return a Java array type with a given ELEMENT_TYPE and LENGTH.
315    These are hashed (shared) using IDENTIFIER_SIGNATURE_TYPE.
316    The LENGTH is -1 if the length is unknown. */
317
318 tree
319 build_java_array_type (element_type, length)
320      tree element_type;
321      HOST_WIDE_INT length;
322 {
323   tree sig, t, fld;
324   char buf[12];
325   tree elsig = build_java_signature (element_type);
326   tree el_name = element_type;
327   sprintf (buf, length >= 0 ? "[%d" : "[", length);
328   sig = ident_subst (IDENTIFIER_POINTER (elsig), IDENTIFIER_LENGTH (elsig),
329                      buf, 0, 0, "");
330   t = IDENTIFIER_SIGNATURE_TYPE (sig);
331   if (t != NULL_TREE)
332     return t;
333   t = make_class ();
334   IDENTIFIER_SIGNATURE_TYPE (sig) = t;
335   TYPE_ARRAY_P (t) = 1;
336
337   if (TREE_CODE (el_name) == POINTER_TYPE)
338     el_name = TREE_TYPE (el_name);
339   el_name = TYPE_NAME (el_name);
340   if (TREE_CODE (el_name) == TYPE_DECL)
341     el_name = DECL_NAME (el_name);
342   TYPE_NAME (t) = identifier_subst (el_name, "", '.', '.', "[]");
343
344   set_java_signature (t, sig);
345   set_super_info (0, t, object_type_node, 0);
346   TYPE_ARRAY_ELEMENT (t) = element_type;
347
348   /* Add length pseudo-field. */
349   push_obstacks (&permanent_obstack, &permanent_obstack);
350   fld = build_decl (FIELD_DECL, get_identifier ("length"), int_type_node);
351   TYPE_FIELDS (t) = fld;
352   DECL_CONTEXT (fld) = t;
353   FIELD_PUBLIC (fld) = 1;
354   FIELD_FINAL (fld) = 1;
355
356   if (length >= 0)
357     {
358       tree atype = build_prim_array_type (element_type, length);
359       tree arfld = build_decl (FIELD_DECL, get_identifier ("data"), atype);
360       DECL_CONTEXT (arfld) = t;
361       TREE_CHAIN (fld) = arfld;
362     }
363   else
364     TYPE_ALIGN (t) = TYPE_ALIGN (element_type);
365   pop_obstacks ();
366
367   layout_class (t);
368   return t;
369 }
370
371 /* Promote TYPE to the type actually used for fields and parameters. */
372
373 tree
374 promote_type (type)
375      tree type;
376 {
377   switch (TREE_CODE (type))
378     {
379     case RECORD_TYPE:
380       return build_pointer_type (CLASS_TO_HANDLE_TYPE (type));
381     case BOOLEAN_TYPE:
382       if (type == boolean_type_node)
383         return promoted_boolean_type_node;
384       goto handle_int;
385     case CHAR_TYPE:
386       if (type == char_type_node)
387         return promoted_char_type_node;
388       goto handle_int;
389     case INTEGER_TYPE:
390     handle_int:
391       if (TYPE_PRECISION (type) < TYPE_PRECISION (int_type_node))
392         {
393           if (type == short_type_node)
394             return promoted_short_type_node;
395           if (type == byte_type_node)
396             return promoted_byte_type_node;
397           return int_type_node;
398         }
399       /* ... else fall through ... */
400     default:
401       return type;
402     }
403 }
404
405 /* Parse a signature string, starting at *PTR and ending at LIMIT.
406    Return the seen TREE_TYPE, updating *PTR. */
407
408 static tree
409 parse_signature_type (ptr, limit)
410      const unsigned char **ptr, *limit;
411 {
412   if ((*ptr) >= limit)
413     fatal ("bad signature string");
414   switch (*(*ptr))
415     {
416     case 'B':  (*ptr)++;  return byte_type_node;
417     case 'C':  (*ptr)++;  return char_type_node;
418     case 'D':  (*ptr)++;  return double_type_node;
419     case 'F':  (*ptr)++;  return float_type_node;
420     case 'S':  (*ptr)++;  return short_type_node;
421     case 'I':  (*ptr)++;  return int_type_node;
422     case 'J':  (*ptr)++;  return long_type_node;
423     case 'Z':  (*ptr)++;  return boolean_type_node;
424     case 'V':  (*ptr)++;  return void_type_node;
425     case '[':
426       for ((*ptr)++; (*ptr) < limit && isdigit (**ptr); ) (*ptr)++;
427       {
428         tree element_type = parse_signature_type (ptr, limit);
429         if (TREE_CODE (element_type) == RECORD_TYPE)
430           element_type = promote_type (element_type);
431         return build_java_array_type (element_type, -1);
432       }
433     case 'L':
434       {
435         const unsigned char *start = ++(*ptr);
436         register const unsigned char *str = start;
437         for ( ; ; str++)
438           {
439             if (str >= limit)
440               fatal ("bad signature string");
441             if (*str == ';')
442               break;
443           }
444         *ptr = str+1;
445         return lookup_class (unmangle_classname (start, str - start));
446       }
447     default:
448       fatal ("unrecognized signature string");
449     }
450 }
451
452 /* Parse a Java "mangled" signature string, starting at SIG_STRING,
453    and SIG_LENGTH bytes long.
454    Return a gcc type node. */
455
456 tree
457 parse_signature_string (sig_string, sig_length)
458      const unsigned char *sig_string;
459      int sig_length;
460 {
461   tree result_type;
462   const unsigned char *str = sig_string;
463   const unsigned char *limit = str + sig_length;
464
465   push_obstacks (&permanent_obstack, &permanent_obstack);
466   if (str < limit && str[0] == '(')
467     {
468       tree argtype_list = NULL_TREE;
469       str++;
470       while (str < limit && str[0] != ')')
471         {
472           tree argtype = promote_type (parse_signature_type (&str, limit));
473           argtype_list = tree_cons (NULL_TREE, argtype, argtype_list);
474         }
475       if (str++, str >= limit)
476         fatal ("bad signature string");
477       result_type = promote_type (parse_signature_type (&str, limit));
478       result_type = build_function_type (result_type,
479                                          nreverse (argtype_list));
480     }
481   else
482     result_type = parse_signature_type (&str, limit);
483   if (str != limit)
484     error ("junk at end of signature string");
485   pop_obstacks ();
486   return result_type;
487 }
488
489 /* Convert a signature to its type.
490  * Uses IDENTIFIER_SIGNATURE_TYPE as a cache (except for primitive types).
491  */
492
493 tree
494 get_type_from_signature (tree signature)
495 {
496   unsigned char *sig = (unsigned char *) IDENTIFIER_POINTER (signature);
497   int len = IDENTIFIER_LENGTH (signature);
498   tree type;
499   /* Primitive types aren't cached. */
500   if (len <= 1)
501     return parse_signature_string (sig, len);
502   type = IDENTIFIER_SIGNATURE_TYPE (signature);
503   if (type == NULL_TREE)
504     {
505       type = parse_signature_string (sig, len);
506       IDENTIFIER_SIGNATURE_TYPE (signature) = type;
507     }
508   return type;
509 }
510
511 /* Return the signature string for the arguments of method type TYPE. */
512
513 tree
514 build_java_argument_signature (type)
515      tree type;
516 {
517   extern struct obstack temporary_obstack;
518   tree sig = TYPE_ARGUMENT_SIGNATURE (type);
519   if (sig == NULL_TREE)
520     {
521       tree args = TYPE_ARG_TYPES (type);
522       if (TREE_CODE (type) == METHOD_TYPE)
523         args = TREE_CHAIN (args);  /* Skip "this" argument. */
524       for (; args != NULL_TREE; args = TREE_CHAIN (args))
525         {
526           tree t = build_java_signature (TREE_VALUE (args));
527           obstack_grow (&temporary_obstack,
528                         IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
529         }
530       obstack_1grow (&temporary_obstack, '\0');
531
532       sig = get_identifier (obstack_base (&temporary_obstack));
533       TYPE_ARGUMENT_SIGNATURE (type) = sig;
534       obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
535     }
536   return sig;
537 }
538
539 /* Return the signature of the given TYPE. */
540
541 tree
542 build_java_signature (type)
543      tree type;
544 {
545   tree sig, t;
546   push_obstacks (&permanent_obstack, &permanent_obstack);
547   while (TREE_CODE (type) == POINTER_TYPE)
548     type = TREE_TYPE (type);
549   if (TYPE_LANG_SPECIFIC (type) == NULL)
550     {
551       TYPE_LANG_SPECIFIC (type) = (struct lang_type *)
552         perm_calloc (1, sizeof (struct lang_type));
553
554     }
555   sig = TYPE_LANG_SPECIFIC (type)->signature;
556   if (sig == NULL_TREE)
557     {
558       char sg[2];
559       switch (TREE_CODE (type))
560         {
561         case BOOLEAN_TYPE: sg[0] = 'Z';  goto native;
562         case CHAR_TYPE:    sg[0] = 'C';  goto native;
563         case VOID_TYPE:    sg[0] = 'V';  goto native;
564         case INTEGER_TYPE:
565           switch (TYPE_PRECISION (type))
566             {
567             case  8:       sg[0] = 'B';  goto native;
568             case 16:       sg[0] = 'S';  goto native;
569             case 32:       sg[0] = 'I';  goto native;
570             case 64:       sg[0] = 'J';  goto native;
571             default:  goto bad_type;
572             }
573         case REAL_TYPE:
574           switch (TYPE_PRECISION (type))
575             {
576             case 32:       sg[0] = 'F';  goto native;
577             case 64:       sg[0] = 'D';  goto native;
578             default:  goto bad_type;
579             }
580         native:
581           sg[1] = 0;
582           sig = get_identifier (sg);
583           break;
584         case RECORD_TYPE:
585           if (TYPE_ARRAY_P (type))
586             {
587               t = build_java_signature (TYPE_ARRAY_ELEMENT (type));
588               sig = ident_subst (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t),
589                                  "[", 0, 0, "");
590             }
591           else
592             {
593               t = DECL_NAME (TYPE_NAME (type));
594               sig = ident_subst (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t),
595                                  "L", '.', '/', ";");
596             }
597           break;
598         case METHOD_TYPE:
599         case FUNCTION_TYPE:
600           {
601             extern struct obstack temporary_obstack;
602             sig = build_java_argument_signature (type);
603             obstack_1grow (&temporary_obstack, '(');
604             obstack_grow (&temporary_obstack,
605                           IDENTIFIER_POINTER (sig), IDENTIFIER_LENGTH (sig));
606             obstack_1grow (&temporary_obstack, ')');
607   
608             t = build_java_signature (TREE_TYPE (type));
609             obstack_grow0 (&temporary_obstack,
610                            IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
611
612             sig = get_identifier (obstack_base (&temporary_obstack));
613             obstack_free (&temporary_obstack,
614                           obstack_base (&temporary_obstack));
615           }
616           break;
617         bad_type:
618         default:
619           fatal ("internal error - build_java_signature passed invalid type");
620         }
621       TYPE_LANG_SPECIFIC (type)->signature = sig;
622     }
623   pop_obstacks ();
624   return sig;
625 }
626
627 /* Save signature string SIG (an IDENTIFIER_NODE) in TYPE for future use. */
628
629 void
630 set_java_signature (type, sig)
631      tree type;
632      tree sig;
633 {
634   tree old_sig;
635   while (TREE_CODE (type) == POINTER_TYPE)
636     type = TREE_TYPE (type);
637   if (TYPE_LANG_SPECIFIC (type) == NULL)
638     {
639       TYPE_LANG_SPECIFIC (type) = (struct lang_type *)
640         perm_calloc (1, sizeof (struct lang_type));
641       
642     }
643   old_sig = TYPE_LANG_SPECIFIC (type)->signature;
644   if (old_sig != NULL_TREE && old_sig != sig)
645     fatal ("internal error - set_java_signature");
646   TYPE_LANG_SPECIFIC (type)->signature = sig;
647 #if 0 /* careful about METHOD_TYPE */
648   if (IDENTIFIER_SIGNATURE_TYPE (sig) == NULL_TREE && TREE_PERMANENT (type))
649     IDENTIFIER_SIGNATURE_TYPE (sig) = type;
650 #endif
651 }
652
653 /* Search in class CLAS (and its superclasses) for a method
654    matching METHOD_NAME and argument signature METHOD_SIGNATURE.
655    Return a FUNCTION_DECL on success, or NULL_TREE if none found.
656    (Contrast lookup_java_method, which takes into account return type.) */
657
658 tree
659 lookup_argument_method (clas, method_name, method_signature)
660      tree clas, method_name, method_signature;
661 {
662   tree method;
663   while (clas != NULL_TREE)
664     {
665       for (method = TYPE_METHODS (clas);
666            method != NULL_TREE;  method = TREE_CHAIN (method))
667         {
668           tree method_sig = build_java_argument_signature (TREE_TYPE (method));
669           if (DECL_NAME (method) == method_name && method_sig == method_signature)
670             return method;
671         }
672       clas = CLASSTYPE_SUPER (clas);
673     }
674   return NULL_TREE;
675 }
676
677 /* Search in class CLAS (and its superclasses) for a method
678    matching METHOD_NAME and signature METHOD_SIGNATURE.
679    Return a FUNCTION_DECL on success, or NULL_TREE if none found.
680    (Contrast lookup_argument_method, which ignores return type.) */
681
682 tree
683 lookup_java_method (clas, method_name, method_signature)
684      tree clas, method_name, method_signature;
685 {
686   tree method;
687   while (clas != NULL_TREE)
688     {
689       for (method = TYPE_METHODS (clas);
690            method != NULL_TREE;  method = TREE_CHAIN (method))
691         {
692           tree method_sig = build_java_signature (TREE_TYPE (method));
693           if (DECL_NAME (method) == method_name && method_sig == method_signature)
694             return method;
695         }
696       clas = CLASSTYPE_SUPER (clas);
697     }
698   return NULL_TREE;
699 }
700
701 /* Search in class CLAS (and its superclasses) for methods matching
702    METHOD_NAME and METHOD_SIGNATURE. Return a list of FUNCTION_DECLs.
703    When called from here, build_java_signature doesn't take the
704    returned type into account. */
705
706 tree
707 match_java_method (clas, method_name, method_signature)
708      tree clas, method_name, method_signature;
709 {
710   tree method;
711   tree list = NULL_TREE;
712   while (clas != NULL_TREE)
713     {
714       for (method = TYPE_METHODS (clas);
715            method != NULL_TREE;  method = TREE_CHAIN (method))
716         {
717           tree method_sig = build_java_argument_signature (TREE_TYPE (method));
718           if (DECL_NAME (method) == method_name 
719               && method_sig == method_signature)
720             list = tree_cons (NULL_TREE, method, list);
721         }
722       clas = CLASSTYPE_SUPER (clas);
723     }
724   return list;
725 }
726
727 /* Search in class CLAS for a constructor matching METHOD_SIGNATURE.
728    Return a FUNCTION_DECL on success, or NULL_TREE if none found. */
729
730 tree
731 lookup_java_constructor (clas, method_signature)
732      tree clas, method_signature;
733 {
734   tree method = TYPE_METHODS (clas);
735   for ( ; method != NULL_TREE;  method = TREE_CHAIN (method))
736     {
737       tree method_sig = build_java_signature (TREE_TYPE (method));
738       if (DECL_CONSTRUCTOR_P (method) && method_sig == method_signature)
739         return method;
740     }
741   return NULL_TREE;
742 }
743
744 /* Return a type which is the Binary Numeric Promotion of the pair T1,
745    T2 and convert EXP1 and/or EXP2. See 5.6.2 Binary Numeric
746    Promotion. It assumes that both T1 and T2 are elligible to BNP. */
747
748 tree
749 binary_numeric_promotion (t1, t2, exp1, exp2)
750      tree t1;
751      tree t2;
752      tree *exp1;
753      tree *exp2;
754 {
755   if (t1 == double_type_node || t2 == double_type_node)
756     {
757       if (t1 != double_type_node)
758         *exp1 = convert (double_type_node, *exp1);
759       if (t2 != double_type_node)
760         *exp2 = convert (double_type_node, *exp2);
761       return double_type_node;
762     }
763   if (t1 == float_type_node || t2 == float_type_node)
764     {
765       if (t1 != float_type_node)
766         *exp1 = convert (float_type_node, *exp1);
767       if (t2 != float_type_node)
768         *exp2 = convert (float_type_node, *exp2);
769       return float_type_node;
770     }
771   if (t1 == long_type_node || t2 == long_type_node)
772     {
773       if (t1 != long_type_node)
774         *exp1 = convert (long_type_node, *exp1);
775       if (t2 != long_type_node)
776         *exp2 = convert (long_type_node, *exp2);
777       return long_type_node;
778     }
779
780   if (t1 != int_type_node)
781     *exp1 = convert (int_type_node, *exp1);
782   if (t2 != int_type_node)
783     *exp2 = convert (int_type_node, *exp2);
784   return int_type_node;
785 }