OSDN Git Service

PR middle-end/16585
[pf3gnuchains/gcc-fork.git] / gcc / java / decl.c
1 /* Process declarations and variables for the GNU compiler for the
2    Java(TM) language.
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
22
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc.  */
26
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
28
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "tree.h"
34 #include "rtl.h"
35 #include "real.h"
36 #include "toplev.h"
37 #include "flags.h"
38 #include "java-tree.h"
39 #include "jcf.h"
40 #include "function.h"
41 #include "expr.h"
42 #include "libfuncs.h"
43 #include "except.h"
44 #include "java-except.h"
45 #include "ggc.h"
46 #include "timevar.h"
47 #include "cgraph.h"
48 #include "tree-inline.h"
49 #include "target.h"
50 #include "version.h"
51
52 #if defined (DEBUG_JAVA_BINDING_LEVELS)
53 extern void indent (void);
54 #endif
55
56 static tree push_jvm_slot (int, tree);
57 static tree lookup_name_current_level (tree);
58 static tree push_promoted_type (const char *, tree);
59 static struct binding_level *make_binding_level (void);
60 static tree create_primitive_vtable (const char *);
61 static tree check_local_unnamed_variable (tree, tree, tree);
62 static void parse_version (void);
63
64 /* Used when computing the ABI version.  */
65 #define GCJ_BINARYCOMPAT_ADDITION 5
66
67 /* The ABI version number.  */
68 tree gcj_abi_version;
69
70 /* Name of the Cloneable class.  */
71 tree java_lang_cloneable_identifier_node;
72
73 /* Name of the Serializable class.  */
74 tree java_io_serializable_identifier_node;
75
76 /* The DECL_MAP is a mapping from (index, type) to a decl node.
77    If index < max_locals, it is the index of a local variable.
78    if index >= max_locals, then index-max_locals is a stack slot.
79    The DECL_MAP mapping is represented as a TREE_VEC whose elements
80    are a list of decls (VAR_DECL or PARM_DECL) chained by
81    DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
82    we search the chain for a decl with a matching TREE_TYPE. */
83
84 static GTY(()) tree decl_map;
85
86 /* The base_decl_map is contains one variable of ptr_type: this is
87    used to contain every variable of reference type that is ever
88    stored in a local variable slot.  */
89
90 static GTY(()) tree base_decl_map;
91
92 /* An index used to make temporary identifiers unique.  */
93 static int uniq;
94
95 /* A list of local variables VAR_DECLs for this method that we have seen
96    debug information, but we have not reached their starting (byte) PC yet. */
97
98 static GTY(()) tree pending_local_decls;
99
100 #if defined(DEBUG_JAVA_BINDING_LEVELS)
101 int binding_depth = 0;
102 int is_class_level = 0;
103 int current_pc;
104
105 void
106 indent (void)
107 {
108   int i;
109
110   for (i = 0; i < binding_depth*2; i++)
111     putc (' ', stderr);
112 }
113 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
114
115 /* True if decl is a named local variable, i.e. if it is an alias
116    that's used only for debugging purposes.  */
117
118 static bool
119 debug_variable_p (tree decl)
120 {
121   if (TREE_CODE (decl) == PARM_DECL)
122     return false;
123
124   if (LOCAL_SLOT_P (decl))
125     return false;
126
127   return true;
128 }
129  
130 /* Copy the value in decl into every live alias in the same local
131    variable slot.  Some of these will be dead stores removed by the
132    optimizer.  */
133
134 void 
135 update_aliases (tree decl, int index, int pc)
136 {
137   tree decl_type = TREE_TYPE (decl);
138   tree tmp;
139
140   if (debug_variable_p (decl))
141     abort ();
142
143   for (tmp = TREE_VEC_ELT (decl_map, index); 
144        tmp != NULL_TREE; 
145        tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
146     {
147       tree tmp_type = TREE_TYPE (tmp);
148       if (tmp != decl
149           && LOCAL_SLOT_P (tmp) == 0
150           && (pc == -1
151               || (pc >= DECL_LOCAL_START_PC (tmp)
152                   && pc <= DECL_LOCAL_END_PC (tmp)))
153           && (tmp_type == decl_type
154               || (INTEGRAL_TYPE_P (tmp_type)
155                   && INTEGRAL_TYPE_P (decl_type)
156                   && TYPE_PRECISION (decl_type) <= 32
157                   && TYPE_PRECISION (tmp_type) <= 32)
158               || (TREE_CODE (tmp_type) == POINTER_TYPE
159                   && TREE_CODE (decl_type) == POINTER_TYPE)))
160         {
161           tree src = build1 (NOP_EXPR, tmp_type, decl);
162           if (LOCAL_VAR_OUT_OF_SCOPE_P (tmp))
163             abort ();
164           java_add_stmt (build2 (MODIFY_EXPR, tmp_type, tmp, src));
165         }
166     }
167 }
168
169 static tree
170 push_jvm_slot (int index, tree decl)
171 {
172   DECL_CONTEXT (decl) = current_function_decl;
173   layout_decl (decl, 0);
174
175   /* Now link the decl into the decl_map. */
176   if (DECL_LANG_SPECIFIC (decl) == NULL)
177     {
178       MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
179       DECL_LOCAL_START_PC (decl) = 0;
180       DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
181       DECL_LOCAL_SLOT_NUMBER (decl) = index;
182     }
183   DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
184   TREE_VEC_ELT (decl_map, index) = decl;
185
186   return decl;
187 }
188
189 /*  At the point of its creation a local variable decl inherits
190     whatever is already in the same slot.  In the case of a local
191     variable that is declared but unused, we won't find anything.  */
192
193 static void
194 initialize_local_variable (tree decl, int index)
195 {
196   tree decl_type = TREE_TYPE (decl);
197   if (TREE_CODE (decl_type) == POINTER_TYPE)
198     {
199       tree tmp = TREE_VEC_ELT (base_decl_map, index);
200
201       if (tmp)
202         {
203           /* At the point of its creation this decl inherits whatever
204              is in the slot.  */
205           tree src = build1 (NOP_EXPR, decl_type, tmp);
206           java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, src));   
207         }
208     }
209   else
210     {
211       tree tmp;
212   
213       for (tmp = TREE_VEC_ELT (decl_map, index); 
214            tmp != NULL_TREE; 
215            tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
216         {
217           tree tmp_type = TREE_TYPE (tmp);
218           if (tmp != decl
219               && ! debug_variable_p (tmp)
220               && (tmp_type == decl_type
221                   || (INTEGRAL_TYPE_P (tmp_type)
222                       && INTEGRAL_TYPE_P (decl_type)
223                       && TYPE_PRECISION (decl_type) <= 32
224                       && TYPE_PRECISION (tmp_type) <= 32
225                       && TYPE_PRECISION (tmp_type)
226                          >= TYPE_PRECISION (decl_type))))
227             {
228               java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, tmp));       
229               return;
230             }
231         }  
232     }
233 }
234
235 /* Find the best declaration based upon type.  If 'decl' fits 'type' better
236    than 'best', return 'decl'.  Otherwise return 'best'.  */
237
238 static tree
239 check_local_unnamed_variable (tree best, tree decl, tree type)
240 {
241   tree decl_type = TREE_TYPE (decl);
242   
243   if (LOCAL_VAR_OUT_OF_SCOPE_P (decl))
244     abort ();
245
246   /* Use the same decl for all integer types <= 32 bits.  This is
247      necessary because sometimes a value is stored as (for example)
248      boolean but loaded as int.  */
249   if (decl_type == type
250       || (INTEGRAL_TYPE_P (decl_type)
251           && INTEGRAL_TYPE_P (type)
252           && TYPE_PRECISION (decl_type) <= 32
253           && TYPE_PRECISION (type) <= 32
254           && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))      
255       /*  ptr_type_node is used for null pointers, which are
256           assignment compatible with everything.  */
257       || (TREE_CODE (decl_type) == POINTER_TYPE
258           && type == ptr_type_node)
259       /* Whenever anyone wants to use a slot that is initially
260          occupied by a PARM_DECL of pointer type they must get that
261          decl, even if they asked for a pointer to a different type.
262          However, if someone wants a scalar variable in a slot that
263          initially held a pointer arg -- or vice versa -- we create a
264          new VAR_DECL.  
265
266          ???: As long as verification is correct, this will be a
267          compatible type.  But maybe we should create a dummy variable
268          and replace all references to it with the DECL and a
269          NOP_EXPR.
270       */
271       || (TREE_CODE (decl_type) == POINTER_TYPE
272           && TREE_CODE (decl) == PARM_DECL
273           && TREE_CODE (type) == POINTER_TYPE)
274
275       /* The new verifier requires a similar treatment in the
276          situation where the parameter has an integral type which
277          promotes to `int'.  */
278       || (flag_new_verifier
279           && TREE_CODE (decl) == PARM_DECL
280           && INTEGRAL_TYPE_P (decl_type)
281           && TYPE_PRECISION (decl_type) <= 32
282           && INTEGRAL_TYPE_P (type)
283           && TYPE_PRECISION (type) <= 32))
284     {
285       if (best == NULL_TREE
286           || (decl_type == type && TREE_TYPE (best) != type))
287         return decl;
288     }
289
290   return best;
291 }
292
293
294 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
295    that is valid at PC (or -1 if any pc).
296    If there is no existing matching decl, allocate one.  */
297
298 tree
299 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
300 {
301   tree tmp = TREE_VEC_ELT (decl_map, index);
302   tree decl = NULL_TREE;
303
304   /* Scan through every declaration that has been created in this
305      slot.  We're only looking for variables that correspond to local
306      index declarations and PARM_DECLs, not named variables: such
307      local variables are used only for debugging information.  */
308   while (tmp != NULL_TREE)
309     {
310       if (! debug_variable_p (tmp))
311         decl = check_local_unnamed_variable (decl, tmp, type);
312       tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
313     }
314
315   /* If we don't find a match, create one with the type passed in.
316      The name of the variable is #n#m, which n is the variable index
317      in the local variable area and m is a dummy identifier for
318      uniqueness -- multiple variables may share the same local
319      variable index.  We don't call pushdecl() to push pointer types
320      into a binding expr because they'll all be replaced by a single
321      variable that is used for every reference in that local variable
322      slot.  */
323   if (! decl)
324     {
325       char buf[64];
326       tree name;
327       sprintf (buf, "#slot#%d#%d", index, uniq++);
328       name = get_identifier (buf);
329       decl = build_decl (VAR_DECL, name, type);
330       DECL_IGNORED_P (decl) = 1;
331       DECL_ARTIFICIAL (decl) = 1;
332       decl = push_jvm_slot (index, decl);
333       LOCAL_SLOT_P (decl) = 1;
334
335       if (TREE_CODE (type) != POINTER_TYPE)
336         pushdecl_function_level (decl);
337     }
338
339   /* As well as creating a local variable that matches the type, we
340      also create a base variable (of ptr_type) that will hold all its
341      aliases.  */
342   if (TREE_CODE (type) == POINTER_TYPE
343       && ! TREE_VEC_ELT (base_decl_map, index))
344     {
345       char buf[64];
346       tree name;
347       tree base_decl;
348       sprintf (buf, "#ref#%d#%d", index, uniq++);
349       name = get_identifier (buf);
350       base_decl
351         = TREE_VEC_ELT (base_decl_map, index)
352         = build_decl (VAR_DECL, name, ptr_type_node);
353       pushdecl_function_level (base_decl);
354       DECL_IGNORED_P (base_decl) = 1;
355       DECL_ARTIFICIAL (base_decl) = 1;
356     }
357
358   return decl;
359 }
360
361 /* Called during gimplification for every variable.  If the variable
362    is a temporary of pointer type, replace it with a common variable
363    thath is used to hold all pointer types that are ever stored in
364    that slot.  Set WANT_LVALUE if you want a variable that is to be
365    written to.  */
366
367 tree 
368 java_replace_reference (tree var_decl, bool want_lvalue)
369 {
370   tree decl_type;
371
372   if (! base_decl_map)
373     return var_decl;
374
375   decl_type = TREE_TYPE (var_decl);
376
377   if (TREE_CODE (decl_type) == POINTER_TYPE)
378     {
379       if (DECL_LANG_SPECIFIC (var_decl)
380           && LOCAL_SLOT_P (var_decl))
381         {
382           int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
383           tree base_decl = TREE_VEC_ELT (base_decl_map, index); 
384
385           if (! base_decl)
386             abort ();
387
388           if (! want_lvalue)
389             base_decl = build1 (NOP_EXPR, decl_type, base_decl);
390
391           return base_decl;
392         }
393     }
394
395   return var_decl;
396 }
397
398
399 /* Same as find_local_index, except that INDEX is a stack index. */
400
401 tree
402 find_stack_slot (int index, tree type)
403 {
404   return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
405                               type, -1);
406 }
407
408 struct binding_level GTY(())
409   {
410     /* A chain of _DECL nodes for all variables, constants, functions,
411      * and typedef types.  These are in the reverse of the order supplied.
412      */
413     tree names;
414
415     /* For each level, a list of shadowed outer-level local definitions
416        to be restored when this level is popped.
417        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
418        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
419     tree shadowed;
420
421     /* For each level (except not the global one),
422        a chain of BLOCK nodes for all the levels
423        that were entered and exited one level down.  */
424     tree blocks;
425
426     /* The binding level which this one is contained in (inherits from).  */
427     struct binding_level *level_chain;
428
429     /* The bytecode PC that marks the end of this level. */
430     int end_pc;
431     /* The bytecode PC that marks the start of this level. */
432     int start_pc;
433
434     /* The statements in this binding level.  */
435     tree stmts;
436
437     /* An exception range associated with this binding level.  */
438     struct eh_range * GTY((skip (""))) exception_range;
439
440     /* Binding depth at which this level began.  Used only for debugging.  */
441     unsigned binding_depth;
442   };
443
444 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
445
446 /* The binding level currently in effect.  */
447
448 static GTY(()) struct binding_level *current_binding_level;
449
450 /* A chain of binding_level structures awaiting reuse.  */
451
452 static GTY(()) struct binding_level *free_binding_level;
453
454 /* The outermost binding level, for names of file scope.
455    This is created when the compiler is started and exists
456    through the entire run.  */
457
458 static GTY(()) struct binding_level *global_binding_level;
459
460 /* The binding level that holds variables declared at the outermost
461    level within a function body.  */
462
463 static struct binding_level *function_binding_level;
464
465 /* A PC value bigger than any PC value we may ever may encounter. */
466
467 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
468
469 /* Binding level structures are initialized by copying this one.  */
470
471 static const struct binding_level clear_binding_level
472 = {
473     NULL_TREE, /* names */
474     NULL_TREE, /* shadowed */
475     NULL_TREE, /* blocks */
476     NULL_BINDING_LEVEL, /* level_chain */
477     LARGEST_PC, /* end_pc */
478     0, /* start_pc */
479     NULL, /* stmts */
480     NULL, /* exception_range */
481     0, /* binding_depth */
482   };
483
484 #if 0
485 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
486    that have names.  Here so we can clear out their names' definitions
487    at the end of the function.  */
488
489 static tree named_labels;
490
491 /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
492
493 static tree shadowed_labels;
494 #endif
495
496 tree java_global_trees[JTI_MAX];
497   
498 /* Build (and pushdecl) a "promoted type" for all standard
499    types shorter than int.  */
500
501 static tree
502 push_promoted_type (const char *name, tree actual_type)
503 {
504   tree type = make_node (TREE_CODE (actual_type));
505 #if 1
506   tree in_min = TYPE_MIN_VALUE (int_type_node);
507   tree in_max = TYPE_MAX_VALUE (int_type_node);
508 #else
509   tree in_min = TYPE_MIN_VALUE (actual_type);
510   tree in_max = TYPE_MAX_VALUE (actual_type);
511 #endif
512   TYPE_MIN_VALUE (type) = copy_node (in_min);
513   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
514   TYPE_MAX_VALUE (type) = copy_node (in_max);
515   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
516   TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
517   layout_type (type);
518   pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
519   return type;
520 }
521
522 /* Return a definition for a builtin function named NAME and whose data type
523    is TYPE.  TYPE should be a function type with argument types.
524    FUNCTION_CODE tells later passes how to compile calls to this function.
525    See tree.h for its possible values.
526
527    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
528    the name to be called if we can't opencode the function.  If
529    ATTRS is nonzero, use that for the function's attribute list.  */
530
531 tree
532 builtin_function (const char *name,
533                   tree type,
534                   int function_code,
535                   enum built_in_class cl,
536                   const char *library_name,
537                   tree ARG_UNUSED (attrs))
538 {
539   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
540   DECL_EXTERNAL (decl) = 1;
541   TREE_PUBLIC (decl) = 1;
542   if (library_name)
543     SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
544   make_decl_rtl (decl);
545   pushdecl (decl);
546   DECL_BUILT_IN_CLASS (decl) = cl;
547   DECL_FUNCTION_CODE (decl) = function_code;
548   return decl;
549 }
550
551 /* Return tree that represents a vtable for a primitive array.  */
552 static tree
553 create_primitive_vtable (const char *name)
554 {
555   tree r;
556   char buf[50];
557
558   sprintf (buf, "_Jv_%sVTable", name);
559   r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
560   DECL_EXTERNAL (r) = 1;
561   return r;
562 }
563
564 static tree
565 do_nothing (tree t)
566 {
567   return t;
568 }
569
570 /* Parse the version string and compute the ABI version number.  */
571 static void
572 parse_version (void)
573 {
574   const char *p = version_string;
575   unsigned int major = 0, minor = 0;
576   unsigned int abi_version;
577
578   /* Skip leading junk.  */
579   while (*p && !ISDIGIT (*p))
580     ++p;
581   gcc_assert (*p);
582
583   /* Extract major version.  */
584   while (ISDIGIT (*p))
585     {
586       major = major * 10 + *p - '0';
587       ++p;
588     }
589
590   gcc_assert (*p == '.' && ISDIGIT (p[1]));
591   ++p;
592
593   /* Extract minor version.  */
594   while (ISDIGIT (*p))
595     {
596       minor = minor * 10 + *p - '0';
597       ++p;
598     }
599
600   /* Implicit in this computation is the idea that we won't break the
601      old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
602      4.0.1).  */
603   abi_version = 10000 * major + 10 * minor;
604   /* It is helpful to distinguish BC ABI from ordinary ABI at this
605      level, since at some point we will recognize a variety of BC ABIs
606      (objects generated by different version of gcj), but will
607      probably always require strict matching for ordinary ABI.  */
608   if (flag_indirect_dispatch)
609     abi_version += GCJ_BINARYCOMPAT_ADDITION;
610
611   gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
612 }
613
614 void
615 java_init_decl_processing (void)
616 {
617   tree endlink;
618   tree field = NULL_TREE;
619   tree t;
620
621   init_class_processing ();
622
623   current_function_decl = NULL;
624   current_binding_level = NULL_BINDING_LEVEL;
625   free_binding_level = NULL_BINDING_LEVEL;
626   pushlevel (0);        /* make the binding_level structure for global names */
627   global_binding_level = current_binding_level;
628
629   /* The code here must be similar to build_common_tree_nodes{,_2} in
630      tree.c, especially as to the order of initializing common nodes.  */
631   error_mark_node = make_node (ERROR_MARK);
632   TREE_TYPE (error_mark_node) = error_mark_node;
633
634   /* Create sizetype first - needed for other types. */
635   initialize_sizetypes (false);
636
637   byte_type_node = make_signed_type (8);
638   pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
639   short_type_node = make_signed_type (16);
640   pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
641   int_type_node = make_signed_type (32);
642   pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
643   long_type_node = make_signed_type (64);
644   pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
645
646   unsigned_byte_type_node = make_unsigned_type (8);
647   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
648                         unsigned_byte_type_node));
649   unsigned_short_type_node = make_unsigned_type (16);
650   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
651                         unsigned_short_type_node));
652   unsigned_int_type_node = make_unsigned_type (32);
653   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
654                         unsigned_int_type_node));
655   unsigned_long_type_node = make_unsigned_type (64);
656   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
657                         unsigned_long_type_node));
658
659   /* This is not a java type, however tree-dfa requires a definition for
660      size_type_node.  */
661   size_type_node = make_unsigned_type (POINTER_SIZE);
662   set_sizetype (size_type_node);
663
664   /* Define these next since types below may used them.  */
665   integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
666   integer_zero_node = build_int_cst (NULL_TREE, 0);
667   integer_one_node = build_int_cst (NULL_TREE, 1);
668   integer_two_node = build_int_cst (NULL_TREE, 2);
669   integer_four_node = build_int_cst (NULL_TREE, 4);
670   integer_minus_one_node = build_int_cst (NULL_TREE, -1);
671
672   /* A few values used for range checking in the lexer.  */
673   decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
674 #if HOST_BITS_PER_WIDE_INT == 64
675   decimal_long_max = build_int_cstu (unsigned_long_type_node,
676                                      0x8000000000000000LL);
677 #elif HOST_BITS_PER_WIDE_INT == 32
678   decimal_long_max = build_int_cst_wide (unsigned_long_type_node,
679                                          0, 0x80000000);
680 #else
681  #error "unsupported size"
682 #endif
683
684   size_zero_node = size_int (0);
685   size_one_node = size_int (1);
686   bitsize_zero_node = bitsize_int (0);
687   bitsize_one_node = bitsize_int (1);
688   bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
689
690   long_zero_node = build_int_cst (long_type_node, 0);
691
692   void_type_node = make_node (VOID_TYPE);
693   pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
694   layout_type (void_type_node); /* Uses size_zero_node */
695   ptr_type_node = build_pointer_type (void_type_node);
696   t = make_node (VOID_TYPE);
697   layout_type (t); /* Uses size_zero_node */
698   return_address_type_node = build_pointer_type (t);
699
700   null_pointer_node = build_int_cst (ptr_type_node, 0);
701
702 #if 0
703   /* Make a type to be the domain of a few array types
704      whose domains don't really matter.
705      200 is small enough that it always fits in size_t
706      and large enough that it can hold most function names for the
707      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
708   short_array_type_node = build_prim_array_type (short_type_node, 200);
709 #endif
710   char_type_node = make_node (CHAR_TYPE);
711   TYPE_PRECISION (char_type_node) = 16;
712   fixup_unsigned_type (char_type_node);
713   pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
714
715   boolean_type_node = make_node (BOOLEAN_TYPE);
716   TYPE_PRECISION (boolean_type_node) = 1;
717   fixup_unsigned_type (boolean_type_node);
718   pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
719                         boolean_type_node));
720   boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
721   boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
722
723   promoted_byte_type_node
724     = push_promoted_type ("promoted_byte", byte_type_node);
725   promoted_short_type_node
726     = push_promoted_type ("promoted_short", short_type_node);
727   promoted_char_type_node
728     = push_promoted_type ("promoted_char", char_type_node);
729   promoted_boolean_type_node
730     = push_promoted_type ("promoted_boolean", boolean_type_node);
731
732   float_type_node = make_node (REAL_TYPE);
733   TYPE_PRECISION (float_type_node) = 32;
734   pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
735                         float_type_node));
736   layout_type (float_type_node);
737
738   double_type_node = make_node (REAL_TYPE);
739   TYPE_PRECISION (double_type_node) = 64;
740   pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
741                         double_type_node));
742   layout_type (double_type_node);
743
744   float_zero_node = build_real (float_type_node, dconst0);
745   double_zero_node = build_real (double_type_node, dconst0);
746
747   /* These are the vtables for arrays of primitives.  */
748   boolean_array_vtable = create_primitive_vtable ("boolean");
749   byte_array_vtable = create_primitive_vtable ("byte");
750   char_array_vtable = create_primitive_vtable ("char");
751   short_array_vtable = create_primitive_vtable ("short");
752   int_array_vtable = create_primitive_vtable ("int");
753   long_array_vtable = create_primitive_vtable ("long");
754   float_array_vtable = create_primitive_vtable ("float");
755   double_array_vtable = create_primitive_vtable ("double");
756
757   one_elt_array_domain_type = build_index_type (integer_one_node);
758   utf8const_type = make_node (RECORD_TYPE);
759   PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
760   PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
761   FINISH_RECORD (utf8const_type);
762   utf8const_ptr_type = build_pointer_type (utf8const_type);
763
764   atable_type = build_array_type (ptr_type_node, 
765                                   one_elt_array_domain_type);
766   TYPE_NONALIASED_COMPONENT (atable_type) = 1;
767   atable_ptr_type = build_pointer_type (atable_type);
768
769   itable_type = build_array_type (ptr_type_node, 
770                                   one_elt_array_domain_type);
771   TYPE_NONALIASED_COMPONENT (itable_type) = 1;
772   itable_ptr_type = build_pointer_type (itable_type);
773
774   symbol_type = make_node (RECORD_TYPE);
775   PUSH_FIELD (symbol_type, field, "clname", utf8const_ptr_type);
776   PUSH_FIELD (symbol_type, field, "name", utf8const_ptr_type);
777   PUSH_FIELD (symbol_type, field, "signature", utf8const_ptr_type);
778   FINISH_RECORD (symbol_type);
779
780   symbols_array_type = build_array_type (symbol_type, 
781                                          one_elt_array_domain_type);
782   symbols_array_ptr_type = build_pointer_type (symbols_array_type);
783
784   assertion_entry_type = make_node (RECORD_TYPE);
785   PUSH_FIELD (assertion_entry_type, field, "assertion_code", integer_type_node);
786   PUSH_FIELD (assertion_entry_type, field, "op1", utf8const_ptr_type);
787   PUSH_FIELD (assertion_entry_type, field, "op2", utf8const_ptr_type);
788   FINISH_RECORD (assertion_entry_type);
789   
790   assertion_table_type = build_array_type (assertion_entry_type,
791                                            one_elt_array_domain_type);
792
793   /* As you're adding items here, please update the code right after
794      this section, so that the filename containing the source code of
795      the pre-defined class gets registered correctly. */
796   unqualified_object_id_node = get_identifier ("Object");
797   object_type_node = lookup_class (get_identifier ("java.lang.Object"));
798   object_ptr_type_node = promote_type (object_type_node);
799   string_type_node = lookup_class (get_identifier ("java.lang.String"));
800   string_ptr_type_node = promote_type (string_type_node);
801   class_type_node = lookup_class (get_identifier ("java.lang.Class"));
802   throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
803   exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
804   runtime_exception_type_node = 
805     lookup_class (get_identifier ("java.lang.RuntimeException"));
806   error_exception_type_node = 
807     lookup_class (get_identifier ("java.lang.Error"));
808
809   rawdata_ptr_type_node
810     = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
811
812   add_predefined_file (get_identifier ("java/lang/Class.java"));
813   add_predefined_file (get_identifier ("java/lang/Error.java"));
814   add_predefined_file (get_identifier ("java/lang/Object.java"));
815   add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
816   add_predefined_file (get_identifier ("java/lang/String.java"));
817   add_predefined_file (get_identifier ("java/lang/Throwable.java"));
818   add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
819   add_predefined_file (get_identifier ("java/lang/Exception.java"));
820   add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
821   add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
822
823   methodtable_type = make_node (RECORD_TYPE);
824   layout_type (methodtable_type);
825   build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
826   methodtable_ptr_type = build_pointer_type (methodtable_type);
827
828   TYPE_identifier_node = get_identifier ("TYPE");
829   init_identifier_node = get_identifier ("<init>");
830   clinit_identifier_node = get_identifier ("<clinit>");
831   finit_identifier_node = get_identifier ("finit$");
832   instinit_identifier_node = get_identifier ("instinit$");
833   void_signature_node = get_identifier ("()V");
834   length_identifier_node = get_identifier ("length");
835   finalize_identifier_node = get_identifier ("finalize");
836   this_identifier_node = get_identifier ("this");
837   super_identifier_node = get_identifier ("super");
838   continue_identifier_node = get_identifier ("continue");
839   access0_identifier_node = get_identifier ("access$0");
840   classdollar_identifier_node = get_identifier ("class$");
841
842   java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
843   java_io_serializable_identifier_node =
844     get_identifier ("java.io.Serializable");
845
846   /* for lack of a better place to put this stub call */
847   init_expr_processing();
848
849   constants_type_node = make_node (RECORD_TYPE);
850   PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
851   PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
852   PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
853   FINISH_RECORD (constants_type_node);
854   build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
855
856   access_flags_type_node = unsigned_short_type_node;
857
858   dtable_type = make_node (RECORD_TYPE);
859   dtable_ptr_type = build_pointer_type (dtable_type);
860
861   otable_type = build_array_type (integer_type_node, 
862                                   one_elt_array_domain_type);
863   TYPE_NONALIASED_COMPONENT (otable_type) = 1;
864   otable_ptr_type = build_pointer_type (otable_type);
865
866   PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
867   DECL_FCONTEXT (field) = object_type_node;
868   TYPE_VFIELD (object_type_node) = field;
869
870   /* This isn't exactly true, but it is what we have in the source.
871      There is an unresolved issue here, which is whether the vtable
872      should be marked by the GC.  */
873   if (! flag_hash_synchronization)
874     PUSH_FIELD (object_type_node, field, "sync_info",
875                 build_pointer_type (object_type_node));
876   for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
877     FIELD_PRIVATE (t) = 1;
878   FINISH_RECORD (object_type_node);
879
880   field_type_node = make_node (RECORD_TYPE);
881   field_ptr_type_node = build_pointer_type (field_type_node);
882   method_type_node = make_node (RECORD_TYPE);
883   method_ptr_type_node = build_pointer_type (method_type_node);
884
885   set_super_info (0, class_type_node, object_type_node, 0);
886   set_super_info (0, string_type_node, object_type_node, 0);
887   class_ptr_type = build_pointer_type (class_type_node);
888
889   PUSH_FIELD (class_type_node, field, "next_or_version", class_ptr_type);
890   PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
891   PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
892   PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
893   PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
894   PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
895   PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
896   PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
897   PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
898   PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
899   PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
900   PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
901   PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
902   PUSH_FIELD (class_type_node, field, "otable", otable_ptr_type);
903   PUSH_FIELD (class_type_node, field, "otable_syms", 
904               symbols_array_ptr_type);
905   PUSH_FIELD (class_type_node, field, "atable", atable_ptr_type);
906   PUSH_FIELD (class_type_node, field, "atable_syms", 
907               symbols_array_ptr_type);
908   PUSH_FIELD (class_type_node, field, "itable", itable_ptr_type);
909   PUSH_FIELD (class_type_node, field, "itable_syms", 
910               symbols_array_ptr_type);
911   PUSH_FIELD (class_type_node, field, "catch_classes", ptr_type_node);
912   PUSH_FIELD (class_type_node, field, "interfaces",
913               build_pointer_type (class_ptr_type));
914   PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
915   PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
916   PUSH_FIELD (class_type_node, field, "state", byte_type_node);
917   PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
918   PUSH_FIELD (class_type_node, field, "depth", short_type_node);
919   PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
920   PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);  
921   PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);  
922   PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
923   PUSH_FIELD (class_type_node, field, "assertion_table", ptr_type_node);
924   PUSH_FIELD (class_type_node, field, "hack_signers", ptr_type_node);
925   PUSH_FIELD (class_type_node, field, "chain", ptr_type_node);
926   PUSH_FIELD (class_type_node, field, "aux_info", ptr_type_node);
927   PUSH_FIELD (class_type_node, field, "engine", ptr_type_node);
928   for (t = TYPE_FIELDS (class_type_node);  t != NULL_TREE;  t = TREE_CHAIN (t))
929     FIELD_PRIVATE (t) = 1;
930   push_super_field (class_type_node, object_type_node);
931
932   FINISH_RECORD (class_type_node);
933   build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
934
935   field_info_union_node = make_node (UNION_TYPE);
936   PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
937   PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
938 #if 0
939   PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
940 #endif
941   layout_type (field_info_union_node);
942
943   PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
944   PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
945   PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
946   PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
947   PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
948   FINISH_RECORD (field_type_node);
949   build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
950
951   nativecode_ptr_array_type_node
952     = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
953
954   PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
955   PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
956   FINISH_RECORD (dtable_type);
957   build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
958
959   jexception_type = make_node (RECORD_TYPE);
960   PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
961   PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
962   PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
963   PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
964   FINISH_RECORD (jexception_type);
965   build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
966   jexception_ptr_type = build_pointer_type (jexception_type);
967
968   lineNumberEntry_type = make_node (RECORD_TYPE);
969   PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
970   PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
971   FINISH_RECORD (lineNumberEntry_type);
972
973   lineNumbers_type = make_node (RECORD_TYPE);
974   PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
975   FINISH_RECORD (lineNumbers_type);
976
977   PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
978   PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
979   PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
980   PUSH_FIELD (method_type_node, field, "index", unsigned_short_type_node);
981   PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
982   PUSH_FIELD (method_type_node, field, "throws", ptr_type_node);
983   FINISH_RECORD (method_type_node);
984   build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
985
986   endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
987
988   t = tree_cons (NULL_TREE, class_ptr_type,
989                  tree_cons (NULL_TREE, int_type_node, endlink));
990   alloc_object_node = builtin_function ("_Jv_AllocObject",
991                                         build_function_type (ptr_type_node, t),
992                                         0, NOT_BUILT_IN, NULL, NULL_TREE);
993   DECL_IS_MALLOC (alloc_object_node) = 1;
994   alloc_no_finalizer_node = 
995     builtin_function ("_Jv_AllocObjectNoFinalizer",
996                       build_function_type (ptr_type_node, t),
997                       0, NOT_BUILT_IN, NULL, NULL_TREE);
998   DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
999
1000   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1001   soft_initclass_node = builtin_function ("_Jv_InitClass",
1002                                           build_function_type (void_type_node,
1003                                                                t),
1004                                           0, NOT_BUILT_IN, NULL, NULL_TREE);
1005
1006   throw_node = builtin_function ("_Jv_Throw",
1007                                  build_function_type (ptr_type_node, t),
1008                                  0, NOT_BUILT_IN, NULL, NULL_TREE);
1009   /* Mark throw_nodes as `noreturn' functions with side effects.  */
1010   TREE_THIS_VOLATILE (throw_node) = 1;
1011   TREE_SIDE_EFFECTS (throw_node) = 1;
1012
1013   t = build_function_type (int_type_node, endlink);
1014   soft_monitorenter_node 
1015     = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1016                         NULL, NULL_TREE);
1017   soft_monitorexit_node 
1018     = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1019                         NULL, NULL_TREE);
1020   
1021   t = tree_cons (NULL_TREE, int_type_node, 
1022                  tree_cons (NULL_TREE, int_type_node, endlink));
1023   soft_newarray_node
1024       = builtin_function ("_Jv_NewPrimArray",
1025                           build_function_type(ptr_type_node, t),
1026                           0, NOT_BUILT_IN, NULL, NULL_TREE);
1027   DECL_IS_MALLOC (soft_newarray_node) = 1;
1028
1029   t = tree_cons (NULL_TREE, int_type_node,
1030                  tree_cons (NULL_TREE, class_ptr_type,
1031                             tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
1032   soft_anewarray_node
1033       = builtin_function ("_Jv_NewObjectArray",
1034                           build_function_type (ptr_type_node, t),
1035                           0, NOT_BUILT_IN, NULL, NULL_TREE);
1036   DECL_IS_MALLOC (soft_anewarray_node) = 1;
1037
1038   /* There is no endlink here because _Jv_NewMultiArray is a varargs
1039      function.  */
1040   t = tree_cons (NULL_TREE, ptr_type_node,
1041                  tree_cons (NULL_TREE, int_type_node, NULL_TREE));
1042   soft_multianewarray_node
1043       = builtin_function ("_Jv_NewMultiArray",
1044                           build_function_type (ptr_type_node, t),
1045                           0, NOT_BUILT_IN, NULL, NULL_TREE);
1046   DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1047
1048   t = build_function_type (void_type_node, 
1049                            tree_cons (NULL_TREE, int_type_node, endlink));
1050   soft_badarrayindex_node
1051       = builtin_function ("_Jv_ThrowBadArrayIndex", t, 
1052                           0, NOT_BUILT_IN, NULL, NULL_TREE);
1053   /* Mark soft_badarrayindex_node as a `noreturn' function with side
1054      effects.  */
1055   TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1056   TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1057
1058   soft_nullpointer_node
1059     = builtin_function ("_Jv_ThrowNullPointerException",
1060                         build_function_type (void_type_node, endlink),
1061                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1062   /* Mark soft_nullpointer_node as a `noreturn' function with side
1063      effects.  */
1064   TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1065   TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1066
1067   t = tree_cons (NULL_TREE, class_ptr_type,
1068                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1069   soft_checkcast_node
1070     = builtin_function ("_Jv_CheckCast",
1071                         build_function_type (ptr_type_node, t),
1072                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1073   t = tree_cons (NULL_TREE, object_ptr_type_node,
1074                  tree_cons (NULL_TREE, class_ptr_type, endlink));
1075   soft_instanceof_node
1076     = builtin_function ("_Jv_IsInstanceOf",
1077                         build_function_type (boolean_type_node, t),
1078                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1079   DECL_IS_PURE (soft_instanceof_node) = 1;
1080   t = tree_cons (NULL_TREE, object_ptr_type_node,
1081                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1082   soft_checkarraystore_node
1083     = builtin_function ("_Jv_CheckArrayStore",
1084                         build_function_type (void_type_node, t),
1085                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1086   t = tree_cons (NULL_TREE, ptr_type_node,
1087                  tree_cons (NULL_TREE, ptr_type_node,
1088                             tree_cons (NULL_TREE, int_type_node, endlink)));
1089   soft_lookupinterfacemethod_node 
1090     = builtin_function ("_Jv_LookupInterfaceMethodIdx",
1091                         build_function_type (ptr_type_node, t),
1092                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1093   DECL_IS_PURE (soft_lookupinterfacemethod_node) = 1;
1094   t = tree_cons (NULL_TREE, ptr_type_node,
1095                  tree_cons (NULL_TREE, ptr_type_node,
1096                             tree_cons (NULL_TREE, ptr_type_node, endlink)));
1097   soft_lookupinterfacemethodbyname_node 
1098     = builtin_function ("_Jv_LookupInterfaceMethod",
1099                         build_function_type (ptr_type_node, t),
1100                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1101   t = tree_cons (NULL_TREE, object_ptr_type_node,
1102                  tree_cons (NULL_TREE, ptr_type_node,
1103                             tree_cons (NULL_TREE, ptr_type_node, 
1104                                        tree_cons (NULL_TREE, int_type_node, 
1105                                                   endlink))));
1106   soft_lookupjnimethod_node
1107     = builtin_function ("_Jv_LookupJNIMethod",
1108                         build_function_type (ptr_type_node, t),
1109                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1110   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1111   soft_getjnienvnewframe_node
1112     = builtin_function ("_Jv_GetJNIEnvNewFrame",
1113                         build_function_type (ptr_type_node, t),
1114                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1115   soft_jnipopsystemframe_node
1116     = builtin_function ("_Jv_JNI_PopSystemFrame",
1117                         build_function_type (ptr_type_node, t),
1118                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1119
1120   soft_idiv_node
1121     = builtin_function ("_Jv_divI",
1122                         build_function_type (int_type_node, t),
1123                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1124
1125   soft_irem_node
1126     = builtin_function ("_Jv_remI",
1127                         build_function_type (int_type_node, t),
1128                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1129
1130   soft_ldiv_node
1131     = builtin_function ("_Jv_divJ",
1132                         build_function_type (long_type_node, t),
1133                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1134
1135   soft_lrem_node
1136     = builtin_function ("_Jv_remJ",
1137                         build_function_type (long_type_node, t),
1138                         0, NOT_BUILT_IN, NULL, NULL_TREE);
1139
1140   /* Initialize variables for except.c.  */
1141   eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
1142                                              ? "__gcj_personality_sj0"
1143                                              : "__gcj_personality_v0");
1144
1145   lang_eh_runtime_type = do_nothing;
1146
1147   init_jcf_parse ();
1148     
1149   initialize_builtins ();
1150   soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1151 #if 0
1152   soft_fmodf_node = built_in_decls[BUILT_IN_FMODF];
1153 #endif
1154
1155   parse_version ();
1156 }
1157
1158
1159 /* Look up NAME in the current binding level and its superiors
1160    in the namespace of variables, functions and typedefs.
1161    Return a ..._DECL node of some kind representing its definition,
1162    or return 0 if it is undefined.  */
1163
1164 tree
1165 lookup_name (tree name)
1166 {
1167   tree val;
1168   if (current_binding_level != global_binding_level
1169       && IDENTIFIER_LOCAL_VALUE (name))
1170     val = IDENTIFIER_LOCAL_VALUE (name);
1171   else
1172     val = IDENTIFIER_GLOBAL_VALUE (name);
1173   return val;
1174 }
1175
1176 /* Similar to `lookup_name' but look only at current binding level and
1177    the previous one if its the parameter level.  */
1178
1179 static tree
1180 lookup_name_current_level (tree name)
1181 {
1182   tree t;
1183
1184   if (current_binding_level == global_binding_level)
1185     return IDENTIFIER_GLOBAL_VALUE (name);
1186
1187   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1188     return 0;
1189
1190   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
1191     if (DECL_NAME (t) == name)
1192       break;
1193
1194   return t;
1195 }
1196
1197 /* Use a binding level to record a labeled block declaration */
1198
1199 void
1200 push_labeled_block (tree lb)
1201 {
1202   tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
1203   struct binding_level *b = current_binding_level;
1204   tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1205   if (oldlocal != 0)
1206       b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1207   TREE_CHAIN (lb) = b->names;
1208   b->names = lb;
1209   IDENTIFIER_LOCAL_VALUE (name) = lb;
1210 }
1211
1212 /* Pop the current binding level, reinstalling values for the previous
1213    labeled block */
1214
1215 void
1216 pop_labeled_block (void)
1217 {
1218   struct binding_level *b = current_binding_level;
1219   tree label =  b->names;
1220   IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) = 
1221     NULL_TREE;
1222   if (b->shadowed)
1223     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) = 
1224       TREE_VALUE (b->shadowed);
1225
1226   /* Pop the current level, and free the structure for reuse.  */
1227   current_binding_level = current_binding_level->level_chain;
1228   b->level_chain = free_binding_level;
1229   free_binding_level = b;
1230 }
1231
1232 /* Record a decl-node X as belonging to the current lexical scope.
1233    Check for errors (such as an incompatible declaration for the same
1234    name already seen in the same scope).
1235
1236    Returns either X or an old decl for the same name.
1237    If an old decl is returned, it may have been smashed
1238    to agree with what X says.  */
1239
1240 tree
1241 pushdecl (tree x)
1242 {
1243   tree t;
1244   tree name = DECL_NAME (x);
1245   struct binding_level *b = current_binding_level;
1246   
1247   if (TREE_CODE (x) != TYPE_DECL)
1248     DECL_CONTEXT (x) = current_function_decl;
1249   if (name)
1250     {
1251       t = lookup_name_current_level (name);
1252       if (t != 0 && t == error_mark_node)
1253         /* error_mark_node is 0 for a while during initialization!  */
1254         {
1255           t = 0;
1256           error ("%J'%D' used prior to declaration", x, x);
1257         }
1258
1259       /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1260          to point to the TYPE_DECL.
1261          Since Java does not have typedefs, a type can only have
1262          one (true) name, given by a class, interface, or builtin. */
1263       if (TREE_CODE (x) == TYPE_DECL
1264           && TYPE_NAME (TREE_TYPE (x)) == 0
1265           && TREE_TYPE (x) != error_mark_node)
1266         {
1267           TYPE_NAME (TREE_TYPE (x)) = x;
1268           TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1269         }
1270
1271       /* This name is new in its binding level.
1272          Install the new declaration and return it.  */
1273       if (b == global_binding_level)
1274         {
1275           /* Install a global value.  */
1276           
1277           IDENTIFIER_GLOBAL_VALUE (name) = x;
1278         }
1279       else
1280         {
1281           /* Here to install a non-global value.  */
1282           tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1283           IDENTIFIER_LOCAL_VALUE (name) = x;
1284
1285 #if 0
1286           /* Warn if shadowing an argument at the top level of the body.  */
1287           if (oldlocal != 0 && !DECL_EXTERNAL (x)
1288               /* This warning doesn't apply to the parms of a nested fcn.  */
1289               && ! current_binding_level->parm_flag
1290               /* Check that this is one level down from the parms.  */
1291               && current_binding_level->level_chain->parm_flag
1292               /* Check that the decl being shadowed
1293                  comes from the parm level, one level up.  */
1294               && chain_member (oldlocal, current_binding_level->level_chain->names))
1295             {
1296               if (TREE_CODE (oldlocal) == PARM_DECL)
1297                 pedwarn ("declaration of %qs shadows a parameter",
1298                          IDENTIFIER_POINTER (name));
1299               else
1300                 pedwarn ("declaration of %qs shadows a symbol from the parameter list",
1301                          IDENTIFIER_POINTER (name));
1302             }
1303
1304           /* Maybe warn if shadowing something else.  */
1305           else if (warn_shadow && !DECL_EXTERNAL (x)
1306                    /* No shadow warnings for internally generated vars.  */
1307                    && DECL_SOURCE_LINE (x) != 0
1308                    /* No shadow warnings for vars made for inlining.  */
1309                    && ! DECL_FROM_INLINE (x))
1310             {
1311               const char *warnstring = 0;
1312
1313               if (TREE_CODE (x) == PARM_DECL
1314                   && current_binding_level->level_chain->parm_flag)
1315                 /* Don't warn about the parm names in function declarator
1316                    within a function declarator.
1317                    It would be nice to avoid warning in any function
1318                    declarator in a declaration, as opposed to a definition,
1319                    but there is no way to tell it's not a definition.  */
1320                 ;
1321               else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1322                 warnstring = "declaration of %qs shadows a parameter";
1323               else if (oldlocal != 0)
1324                 warnstring = "declaration of %qs shadows previous local";
1325               else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1326                        && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1327                 warnstring = "declaration of %qs shadows global declaration";
1328
1329               if (warnstring)
1330                 warning (warnstring, IDENTIFIER_POINTER (name));
1331             }
1332 #endif
1333
1334           /* If storing a local value, there may already be one (inherited).
1335              If so, record it for restoration when this binding level ends.  */
1336           if (oldlocal != 0)
1337             b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1338         }
1339     }
1340
1341   /* Put decls on list in reverse order.
1342      We will reverse them later if necessary.  */
1343   TREE_CHAIN (x) = b->names;
1344   b->names = x;
1345
1346   return x;
1347 }
1348
1349 void
1350 pushdecl_force_head (tree x)
1351 {
1352   current_binding_level->names = x;
1353 }
1354
1355 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate.  */
1356
1357 tree
1358 pushdecl_top_level (tree x)
1359 {
1360   tree t;
1361   struct binding_level *b = current_binding_level;
1362
1363   current_binding_level = global_binding_level;
1364   t = pushdecl (x);
1365   current_binding_level = b;
1366   return t;
1367 }
1368
1369 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate.  */
1370
1371 tree
1372 pushdecl_function_level (tree x)
1373 {
1374   tree t;
1375   struct binding_level *b = current_binding_level;
1376
1377   current_binding_level = function_binding_level;
1378   t = pushdecl (x);
1379   current_binding_level = b;
1380   return t;
1381 }
1382
1383 /* Nonzero if we are currently in the global binding level.  */
1384
1385 int
1386 global_bindings_p (void)
1387 {
1388   return current_binding_level == global_binding_level;
1389 }
1390
1391 /* Return the list of declarations of the current level.
1392    Note that this list is in reverse order unless/until
1393    you nreverse it; and when you do nreverse it, you must
1394    store the result back using `storedecls' or you will lose.  */
1395
1396 tree
1397 getdecls (void)
1398 {
1399   return current_binding_level->names;
1400 }
1401
1402 /* Create a new `struct binding_level'.  */
1403
1404 static struct binding_level *
1405 make_binding_level (void)
1406 {
1407   /* NOSTRICT */
1408   return ggc_alloc_cleared (sizeof (struct binding_level));
1409 }
1410
1411 void
1412 pushlevel (int unused ATTRIBUTE_UNUSED)
1413 {
1414   struct binding_level *newlevel = NULL_BINDING_LEVEL;
1415
1416 #if 0
1417   /* If this is the top level of a function,
1418      just make sure that NAMED_LABELS is 0.  */
1419
1420   if (current_binding_level == global_binding_level)
1421     named_labels = 0;
1422 #endif
1423
1424   /* Reuse or create a struct for this binding level.  */
1425
1426   if (free_binding_level)
1427     {
1428       newlevel = free_binding_level;
1429       free_binding_level = free_binding_level->level_chain;
1430     }
1431   else
1432     {
1433       newlevel = make_binding_level ();
1434     }
1435
1436   /* Add this level to the front of the chain (stack) of levels that
1437      are active.  */
1438
1439   *newlevel = clear_binding_level;
1440   newlevel->level_chain = current_binding_level;
1441   current_binding_level = newlevel;
1442 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1443   newlevel->binding_depth = binding_depth;
1444   indent ();
1445   fprintf (stderr, "push %s level %p pc %d\n",
1446            (is_class_level) ? "class" : "block", newlevel, current_pc);
1447   is_class_level = 0;
1448   binding_depth++;
1449 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1450 }
1451
1452 /* Exit a binding level.
1453    Pop the level off, and restore the state of the identifier-decl mappings
1454    that were in effect when this level was entered.
1455
1456    If KEEP is nonzero, this level had explicit declarations, so
1457    and create a "block" (a BLOCK node) for the level
1458    to record its declarations and subblocks for symbol table output.
1459
1460    If FUNCTIONBODY is nonzero, this level is the body of a function,
1461    so create a block as if KEEP were set and also clear out all
1462    label names.
1463
1464    If REVERSE is nonzero, reverse the order of decls before putting
1465    them into the BLOCK.  */
1466
1467 tree
1468 poplevel (int keep, int reverse, int functionbody)
1469 {
1470   tree link;
1471   /* The chain of decls was accumulated in reverse order.
1472      Put it into forward order, just for cleanliness.  */
1473   tree decls;
1474   tree subblocks = current_binding_level->blocks;
1475   tree block = 0;
1476   tree decl;
1477   tree bind = 0;
1478
1479 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1480   binding_depth--;
1481   indent ();
1482   if (current_binding_level->end_pc != LARGEST_PC)
1483     fprintf (stderr, "pop  %s level %p pc %d (end pc %d)\n",
1484              (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1485              current_binding_level->end_pc);
1486   else
1487     fprintf (stderr, "pop  %s level %p pc %d\n",
1488              (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1489 #if 0
1490   if (is_class_level != (current_binding_level == class_binding_level))
1491     {
1492       indent ();
1493       fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1494     }
1495   is_class_level = 0;
1496 #endif
1497 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1498
1499   /* Get the decls in the order they were written.
1500      Usually current_binding_level->names is in reverse order.
1501      But parameter decls were previously put in forward order.  */
1502
1503   if (reverse)
1504     current_binding_level->names
1505       = decls = nreverse (current_binding_level->names);
1506   else
1507     decls = current_binding_level->names;
1508
1509   for (decl = decls; decl; decl = TREE_CHAIN (decl))
1510     if (TREE_CODE (decl) == VAR_DECL
1511         && DECL_LANG_SPECIFIC (decl) != NULL
1512         && DECL_LOCAL_SLOT_NUMBER (decl))
1513       LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1514
1515   /* If there were any declarations in that level,
1516      or if this level is a function body,
1517      create a BLOCK to record them for the life of this function.  */
1518
1519   block = 0;
1520   if (keep || functionbody)
1521     {
1522       block = make_node (BLOCK);
1523       TREE_TYPE (block) = void_type_node;
1524     }
1525
1526   if (current_binding_level->exception_range)
1527     expand_end_java_handler (current_binding_level->exception_range);
1528
1529   if (block != 0)
1530     {
1531       /* If any statements have been generated at this level, create a
1532          BIND_EXPR to hold them and copy the variables to it.  This
1533          only applies to the bytecode compiler.  */
1534       if (current_binding_level->stmts)
1535         {
1536           tree decl = decls;
1537           tree *var = &BLOCK_VARS (block);
1538
1539           /* Copy decls from names list, ignoring labels.  */
1540           while (decl)
1541             {
1542               tree next = TREE_CHAIN (decl);
1543               if (TREE_CODE (decl) != LABEL_DECL)
1544                 {
1545                   *var = decl;
1546                   var = &TREE_CHAIN (decl);
1547                 }
1548               decl = next;
1549             }
1550           *var = NULL;
1551             
1552           bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block), 
1553                          BLOCK_EXPR_BODY (block), block);
1554           BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1555           
1556           if (BIND_EXPR_BODY (bind)
1557               && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1558             TREE_SIDE_EFFECTS (bind) = 1;
1559           
1560           /* FIXME: gimplifier brain damage.  */
1561           if (BIND_EXPR_BODY (bind) == NULL)
1562             BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1563
1564           current_binding_level->stmts = NULL;
1565         }
1566       else
1567         {
1568           BLOCK_VARS (block) = decls;
1569         }
1570       BLOCK_SUBBLOCKS (block) = subblocks;
1571     }   
1572
1573   /* In each subblock, record that this is its superior.  */
1574
1575   for (link = subblocks; link; link = TREE_CHAIN (link))
1576     BLOCK_SUPERCONTEXT (link) = block;
1577
1578   /* Clear out the meanings of the local variables of this level.  */
1579
1580   for (link = decls; link; link = TREE_CHAIN (link))
1581     {
1582       tree name = DECL_NAME (link);
1583       if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1584         {
1585           /* If the ident. was used or addressed via a local extern decl,
1586              don't forget that fact.  */
1587           if (DECL_EXTERNAL (link))
1588             {
1589               if (TREE_USED (link))
1590                 TREE_USED (name) = 1;
1591               if (TREE_ADDRESSABLE (link))
1592                 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1593             }
1594           IDENTIFIER_LOCAL_VALUE (name) = 0;
1595         }
1596     }
1597
1598   /* Restore all name-meanings of the outer levels
1599      that were shadowed by this level.  */
1600
1601   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1602     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1603
1604   /* If the level being exited is the top level of a function,
1605      check over all the labels, and clear out the current
1606      (function local) meanings of their names.  */
1607
1608   if (functionbody)
1609     {
1610       /* If this is the top level block of a function,
1611          the vars are the function's parameters.
1612          Don't leave them in the BLOCK because they are
1613          found in the FUNCTION_DECL instead.  */
1614
1615       BLOCK_VARS (block) = 0;
1616
1617       /* Clear out the definitions of all label names,
1618          since their scopes end here,
1619          and add them to BLOCK_VARS.  */
1620
1621 #if 0
1622       for (link = named_labels; link; link = TREE_CHAIN (link))
1623         {
1624           tree label = TREE_VALUE (link);
1625
1626           if (DECL_INITIAL (label) == 0)
1627             {
1628               error ("%Jlabel '%D' used but not defined", label, label);
1629               /* Avoid crashing later.  */
1630               define_label (input_location, DECL_NAME (label));
1631             }
1632           else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
1633             warning ("%Jlabel '%D' defined but not used", label, label);
1634           IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1635
1636           /* Put the labels into the "variables" of the
1637              top-level block, so debugger can see them.  */
1638           TREE_CHAIN (label) = BLOCK_VARS (block);
1639           BLOCK_VARS (block) = label;
1640         }
1641 #endif
1642     }
1643
1644   /* Pop the current level, and free the structure for reuse.  */
1645
1646   {
1647     struct binding_level *level = current_binding_level;
1648     current_binding_level = current_binding_level->level_chain;
1649
1650     level->level_chain = free_binding_level;
1651     free_binding_level = level;
1652   }
1653
1654   /* Dispose of the block that we just made inside some higher level.  */
1655   if (functionbody)
1656     {
1657       DECL_INITIAL (current_function_decl) = block;
1658       DECL_SAVED_TREE (current_function_decl) = bind;
1659     }
1660   else 
1661     {
1662       if (block)
1663         {
1664           current_binding_level->blocks
1665             = chainon (current_binding_level->blocks, block);
1666         }
1667       /* If we did not make a block for the level just exited,
1668          any blocks made for inner levels
1669          (since they cannot be recorded as subblocks in that level)
1670          must be carried forward so they will later become subblocks
1671          of something else.  */
1672       else if (subblocks)
1673         current_binding_level->blocks
1674           = chainon (current_binding_level->blocks, subblocks);
1675
1676       if (bind)
1677         java_add_stmt (bind);
1678     }
1679
1680   if (block)
1681     TREE_USED (block) = 1;
1682   return block;
1683 }
1684
1685 void
1686 maybe_pushlevels (int pc)
1687 {
1688 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1689   current_pc = pc;
1690 #endif
1691
1692   while (pending_local_decls != NULL_TREE &&
1693          DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1694     {
1695       tree *ptr = &pending_local_decls;
1696       tree decl = *ptr, next;
1697       int end_pc = DECL_LOCAL_END_PC (decl);
1698
1699       while (*ptr != NULL_TREE
1700              && DECL_LOCAL_START_PC (*ptr) <= pc
1701              && DECL_LOCAL_END_PC (*ptr) == end_pc)
1702         ptr = &TREE_CHAIN (*ptr);
1703       pending_local_decls = *ptr;
1704       *ptr = NULL_TREE;
1705
1706       /* Force non-nested range to be nested in current range by
1707          truncating variable lifetimes. */
1708       if (end_pc > current_binding_level->end_pc)
1709         {
1710           end_pc = current_binding_level->end_pc;
1711           DECL_LOCAL_END_PC (decl) = end_pc;
1712         }
1713
1714       maybe_start_try (pc, end_pc);
1715       
1716       pushlevel (1);
1717
1718       current_binding_level->end_pc = end_pc;
1719       current_binding_level->start_pc = pc;      
1720       current_binding_level->names = NULL;
1721       for ( ; decl != NULL_TREE; decl = next)
1722         {
1723           next = TREE_CHAIN (decl);
1724           push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1725           pushdecl (decl);
1726           initialize_local_variable (decl, DECL_LOCAL_SLOT_NUMBER (decl));
1727         }
1728     }      
1729
1730   maybe_start_try (pc, 0);
1731 }
1732
1733 void
1734 maybe_poplevels (int pc)
1735 {
1736 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1737   current_pc = pc;
1738 #endif
1739
1740   while (current_binding_level->end_pc <= pc)
1741     poplevel (1, 0, 0);
1742 }
1743
1744 /* Terminate any binding which began during the range beginning at
1745    start_pc.  This tidies up improperly nested local variable ranges
1746    and exception handlers; a variable declared within an exception
1747    range is forcibly terminated when that exception ends. */
1748
1749 void
1750 force_poplevels (int start_pc)
1751 {
1752   while (current_binding_level->start_pc > start_pc)
1753     {
1754       if (pedantic && current_binding_level->start_pc > start_pc)
1755         warning ("%JIn %D: overlapped variable and exception ranges at %d",
1756                  current_function_decl, current_function_decl,
1757                  current_binding_level->start_pc);
1758       poplevel (1, 0, 0);
1759     }
1760 }
1761
1762 /* Insert BLOCK at the end of the list of subblocks of the
1763    current binding level.  This is used when a BIND_EXPR is expanded,
1764    to handle the BLOCK node inside the BIND_EXPR.  */
1765
1766 void
1767 insert_block (tree block)
1768 {
1769   TREE_USED (block) = 1;
1770   current_binding_level->blocks
1771     = chainon (current_binding_level->blocks, block);
1772 }
1773
1774 /* integrate_decl_tree calls this function. */
1775
1776 void
1777 java_dup_lang_specific_decl (tree node)
1778 {
1779   int lang_decl_size;
1780   struct lang_decl *x;
1781
1782   if (!DECL_LANG_SPECIFIC (node))
1783     return;
1784
1785   lang_decl_size = sizeof (struct lang_decl);
1786   x = ggc_alloc (lang_decl_size);
1787   memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1788   DECL_LANG_SPECIFIC (node) = x;
1789 }
1790
1791 void
1792 give_name_to_locals (JCF *jcf)
1793 {
1794   int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1795   int code_offset = DECL_CODE_OFFSET (current_function_decl);
1796   tree parm;
1797   pending_local_decls = NULL_TREE;
1798   if (n == 0)
1799     return;
1800   JCF_SEEK (jcf, n);
1801   n = JCF_readu2 (jcf);
1802   for (i = 0; i < n; i++)
1803     {
1804       int start_pc = JCF_readu2 (jcf);
1805       int length = JCF_readu2 (jcf);
1806       int name_index = JCF_readu2 (jcf);
1807       int signature_index = JCF_readu2 (jcf);
1808       int slot = JCF_readu2 (jcf);
1809       tree name = get_name_constant (jcf, name_index);
1810       tree type = parse_signature (jcf, signature_index);
1811       if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1812           && start_pc == 0
1813           && length == DECL_CODE_LENGTH (current_function_decl))
1814         {
1815           tree decl = TREE_VEC_ELT (decl_map, slot);
1816           DECL_NAME (decl) = name;
1817           SET_DECL_ASSEMBLER_NAME (decl, name);
1818           if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1819             warning ("bad type in parameter debug info");
1820         }
1821       else
1822         {
1823           tree *ptr;
1824           int end_pc = start_pc + length;
1825           tree decl = build_decl (VAR_DECL, name, type);
1826           if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1827             {
1828               warning ("%Jbad PC range for debug info for local '%D'",
1829                        decl, decl);
1830               end_pc = DECL_CODE_LENGTH (current_function_decl);
1831             }
1832
1833           /* Adjust start_pc if necessary so that the local's first
1834              store operation will use the relevant DECL as a
1835              destination. Fore more information, read the leading
1836              comments for expr.c:maybe_adjust_start_pc. */
1837           start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1838
1839           MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1840           DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1841           DECL_LOCAL_START_PC (decl) = start_pc;
1842 #if 0
1843           /* FIXME: The range used internally for exceptions and local
1844              variable ranges, is a half-open interval: 
1845              start_pc <= pc < end_pc.  However, the range used in the
1846              Java VM spec is inclusive at both ends: 
1847              start_pc <= pc <= end_pc. */
1848           end_pc++;
1849 #endif
1850           DECL_LOCAL_END_PC (decl) = end_pc;
1851
1852           /* Now insert the new decl in the proper place in
1853              pending_local_decls.  We are essentially doing an insertion sort,
1854              which works fine, since the list input will normally already
1855              be sorted. */
1856           ptr = &pending_local_decls;
1857           while (*ptr != NULL_TREE
1858                  && (DECL_LOCAL_START_PC (*ptr) > start_pc
1859                      || (DECL_LOCAL_START_PC (*ptr) == start_pc
1860                          && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1861             ptr = &TREE_CHAIN (*ptr);
1862           TREE_CHAIN (decl) = *ptr;
1863           *ptr = decl;
1864         }
1865     }
1866
1867   pending_local_decls = nreverse (pending_local_decls);
1868
1869   /* Fill in default names for the parameters. */ 
1870   for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1871        parm != NULL_TREE;  parm = TREE_CHAIN (parm), i++)
1872     {
1873       if (DECL_NAME (parm) == NULL_TREE)
1874         {
1875           int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1876           if (arg_i == 0)
1877             DECL_NAME (parm) = get_identifier ("this");
1878           else
1879             {
1880               char buffer[12];
1881               sprintf (buffer, "ARG_%d", arg_i);
1882               DECL_NAME (parm) = get_identifier (buffer);
1883             }
1884           SET_DECL_ASSEMBLER_NAME (parm, DECL_NAME (parm));
1885         }
1886     }
1887 }
1888
1889 tree
1890 build_result_decl (tree fndecl)
1891 {
1892   tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1893   tree result = DECL_RESULT (fndecl);
1894   if (! result)
1895     {
1896       /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1897       if (INTEGRAL_TYPE_P (restype)
1898           && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1899         restype = integer_type_node;
1900       result = build_decl (RESULT_DECL, NULL_TREE, restype);
1901       DECL_ARTIFICIAL (result) = 1;
1902       DECL_IGNORED_P (result) = 1;
1903       DECL_CONTEXT (result) = fndecl;
1904       DECL_RESULT (fndecl) = result;
1905     }
1906   return result;
1907 }
1908
1909 void
1910 start_java_method (tree fndecl)
1911 {
1912   tree tem, *ptr;
1913   int i;
1914
1915   uniq = 0;
1916
1917   current_function_decl = fndecl;
1918   announce_function (fndecl);
1919
1920   i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1921   decl_map = make_tree_vec (i);
1922   base_decl_map = make_tree_vec (i);
1923   type_map = xrealloc (type_map, i * sizeof (tree));
1924
1925 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1926   fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1927   current_pc = 0;
1928 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1929   pushlevel (1);  /* Push parameters. */
1930
1931   ptr = &DECL_ARGUMENTS (fndecl);
1932   for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1933        tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1934     {
1935       tree parm_name = NULL_TREE, parm_decl;
1936       tree parm_type = TREE_VALUE (tem);
1937       if (i >= DECL_MAX_LOCALS (fndecl))
1938         abort ();
1939
1940       parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1941       DECL_CONTEXT (parm_decl) = fndecl;
1942       if (targetm.calls.promote_prototypes (parm_type)
1943           && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1944           && INTEGRAL_TYPE_P (parm_type))
1945         parm_type = integer_type_node;
1946       DECL_ARG_TYPE (parm_decl) = parm_type;
1947
1948       *ptr = parm_decl;
1949       ptr = &TREE_CHAIN (parm_decl);
1950
1951       /* Add parm_decl to the decl_map. */
1952       push_jvm_slot (i, parm_decl);
1953
1954       type_map[i] = TREE_TYPE (parm_decl);
1955       if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1956         {
1957           i++;
1958           type_map[i] = void_type_node;
1959         }
1960     }
1961   *ptr = NULL_TREE;
1962   DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1963
1964   while (i < DECL_MAX_LOCALS(fndecl))
1965     type_map[i++] = NULL_TREE;
1966
1967   build_result_decl (fndecl);
1968
1969   /* Push local variables.  */
1970   pushlevel (2);
1971
1972   function_binding_level = current_binding_level;
1973 }
1974
1975 void
1976 end_java_method (void)
1977 {
1978   tree fndecl = current_function_decl;
1979
1980   /* pop out of function */
1981   poplevel (1, 1, 0);
1982
1983   /* pop out of its parameters */
1984   poplevel (1, 0, 1);
1985
1986   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1987   
1988   if (DECL_SAVED_TREE (fndecl))
1989     {
1990       tree fbody, block_body;
1991       /* Before we check initialization, attached all class initialization
1992          variable to the block_body */
1993       fbody = DECL_SAVED_TREE (fndecl);
1994       block_body = BIND_EXPR_BODY (fbody);
1995       htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1996                      attach_init_test_initialization_flags, block_body);
1997     }
1998
1999   flag_unit_at_a_time = 0;
2000   finish_method (fndecl);
2001
2002   if (! flag_unit_at_a_time)
2003     {
2004       /* Nulling these fields when we no longer need them saves
2005          memory.  */
2006       DECL_SAVED_TREE (fndecl) = NULL;
2007       DECL_STRUCT_FUNCTION (fndecl) = NULL;
2008       DECL_INITIAL (fndecl) = NULL_TREE;
2009     }
2010   current_function_decl = NULL_TREE;
2011 }
2012
2013 /* Prepare a method for expansion.  */
2014
2015 void
2016 finish_method (tree fndecl)
2017 {
2018   tree *tp = &DECL_SAVED_TREE (fndecl);
2019
2020   /* Wrap body of synchronized methods in a monitorenter,
2021      plus monitorexit cleanup.  */
2022   if (METHOD_SYNCHRONIZED (fndecl))
2023     {
2024       tree enter, exit, lock;
2025       if (METHOD_STATIC (fndecl))
2026         lock = build_class_ref (DECL_CONTEXT (fndecl));
2027       else
2028         lock = DECL_ARGUMENTS (fndecl);
2029       BUILD_MONITOR_ENTER (enter, lock);
2030       BUILD_MONITOR_EXIT (exit, lock);
2031       *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
2032                     build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
2033     }
2034
2035   /* Prepend class initialization for static methods reachable from
2036      other classes.  */
2037   if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
2038       && ! DECL_CLINIT_P (fndecl)
2039       && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl))))
2040     {
2041       tree clas = DECL_CONTEXT (fndecl);
2042       tree init = build3 (CALL_EXPR, void_type_node,
2043                           build_address_of (soft_initclass_node),
2044                           build_tree_list (NULL_TREE, build_class_ref (clas)),
2045                           NULL_TREE);
2046       *tp = build2 (COMPOUND_EXPR, TREE_TYPE (*tp), init, *tp);
2047     }
2048
2049   /* Convert function tree to GENERIC prior to inlining.  */
2050   java_genericize (fndecl);
2051
2052   /* Store the end of the function, so that we get good line number
2053      info for the epilogue.  */
2054   if (DECL_STRUCT_FUNCTION (fndecl))
2055     cfun = DECL_STRUCT_FUNCTION (fndecl);
2056   else
2057     allocate_struct_function (fndecl);
2058 #ifdef USE_MAPPED_LOCATION
2059   cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
2060 #else
2061   cfun->function_end_locus.file = DECL_SOURCE_FILE (fndecl);
2062   cfun->function_end_locus.line = DECL_FUNCTION_LAST_LINE (fndecl);
2063 #endif
2064
2065   /* Defer inlining and expansion to the cgraph optimizers.  */
2066   cgraph_finalize_function (fndecl, false);
2067 }
2068
2069 /* Optimize and expand a function's entire body.  */
2070
2071 void
2072 java_expand_body (tree fndecl)
2073 {
2074   tree_rest_of_compilation (fndecl);
2075 }
2076
2077 /* We pessimistically marked all methods and fields external until we
2078    knew what set of classes we were planning to compile.  Now mark those
2079    associated with CLASS to be generated locally as not external.  */
2080
2081 static void
2082 java_mark_decl_local (tree decl)
2083 {
2084   DECL_EXTERNAL (decl) = 0;
2085
2086   /* If we've already constructed DECL_RTL, give encode_section_info
2087      a second chance, now that we've changed the flags.  */
2088   if (DECL_RTL_SET_P (decl))
2089     make_decl_rtl (decl);
2090 }
2091
2092 void
2093 java_mark_class_local (tree class)
2094 {
2095   tree t;
2096
2097   for (t = TYPE_FIELDS (class); t ; t = TREE_CHAIN (t))
2098     if (FIELD_STATIC (t))
2099       java_mark_decl_local (t);
2100
2101   for (t = TYPE_METHODS (class); t ; t = TREE_CHAIN (t))
2102     if (!METHOD_ABSTRACT (t) && (!METHOD_NATIVE (t) || flag_jni))
2103       java_mark_decl_local (t);
2104 }
2105
2106 /* Add a statement to a compound_expr.  */
2107
2108 tree
2109 add_stmt_to_compound (tree existing, tree type, tree stmt)
2110 {
2111   if (!stmt)
2112     return existing;
2113   else if (existing)
2114     {
2115       tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
2116       TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
2117                                  | TREE_SIDE_EFFECTS (stmt);
2118       return expr;
2119     }
2120   else
2121     return stmt;
2122 }
2123
2124 /* Add a statement to the compound_expr currently being
2125    constructed.  */
2126
2127 tree
2128 java_add_stmt (tree stmt)
2129 {
2130   if (input_filename)
2131     SET_EXPR_LOCATION (stmt, input_location);
2132   
2133   return current_binding_level->stmts 
2134     = add_stmt_to_compound (current_binding_level->stmts, 
2135                             TREE_TYPE (stmt), stmt);
2136 }
2137
2138 /* Add a variable to the current scope.  */
2139
2140 tree
2141 java_add_local_var (tree decl)
2142 {
2143   tree *vars = &current_binding_level->names;
2144   tree next = *vars;
2145   TREE_CHAIN (decl) = next;
2146   *vars = decl;
2147   DECL_CONTEXT (decl) = current_function_decl;
2148   MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2149   return decl;
2150 }
2151
2152 /* Return a pointer to the compound_expr currently being
2153    constructed.  */
2154
2155 tree *
2156 get_stmts (void)
2157 {
2158   return &current_binding_level->stmts;
2159 }
2160
2161 /* Register an exception range as belonging to the current binding
2162    level.  There may only be one: if there are more, we'll create more
2163    binding levels.  However, each range can have multiple handlers,
2164    and these are expanded when we call expand_end_java_handler().  */
2165
2166 void
2167 register_exception_range (struct eh_range *range, int pc, int end_pc)
2168 {
2169   if (current_binding_level->exception_range)
2170     abort ();
2171   current_binding_level->exception_range = range;
2172   current_binding_level->end_pc = end_pc;
2173   current_binding_level->start_pc = pc;      
2174 }
2175
2176 #include "gt-java-decl.h"