OSDN Git Service

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