OSDN Git Service

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