OSDN Git Service

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