OSDN Git Service

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