OSDN Git Service

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