OSDN Git Service

fcf63539092712afaeff5872077e8cfefc5797fe
[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 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc.  */
26
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
28
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "tree.h"
34 #include "rtl.h"
35 #include "real.h"
36 #include "toplev.h"
37 #include "flags.h"
38 #include "java-tree.h"
39 #include "jcf.h"
40 #include "function.h"
41 #include "expr.h"
42 #include "libfuncs.h"
43 #include "except.h"
44 #include "java-except.h"
45 #include "ggc.h"
46 #include "timevar.h"
47 #include "cgraph.h"
48 #include "tree-inline.h"
49 #include "target.h"
50 #include "version.h"
51 #include "tree-iterator.h"
52 #include "langhooks.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   classdollar_identifier_node = get_identifier ("class$");
742
743   java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
744   java_io_serializable_identifier_node =
745     get_identifier ("java.io.Serializable");
746
747   /* for lack of a better place to put this stub call */
748   init_expr_processing();
749
750   constants_type_node = make_node (RECORD_TYPE);
751   PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
752   PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
753   PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
754   constants_data_field_decl_node = field;
755   FINISH_RECORD (constants_type_node);
756   build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
757
758   access_flags_type_node = unsigned_short_type_node;
759
760   dtable_type = make_node (RECORD_TYPE);
761   dtable_ptr_type = build_pointer_type (dtable_type);
762
763   otable_type = build_array_type (integer_type_node, 
764                                   one_elt_array_domain_type);
765   TYPE_NONALIASED_COMPONENT (otable_type) = 1;
766   otable_ptr_type = build_pointer_type (otable_type);
767
768   PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
769   DECL_FCONTEXT (field) = object_type_node;
770   TYPE_VFIELD (object_type_node) = field;
771
772   /* This isn't exactly true, but it is what we have in the source.
773      There is an unresolved issue here, which is whether the vtable
774      should be marked by the GC.  */
775   if (! flag_hash_synchronization)
776     PUSH_FIELD (object_type_node, field, "sync_info",
777                 build_pointer_type (object_type_node));
778   for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
779     FIELD_PRIVATE (t) = 1;
780   FINISH_RECORD (object_type_node);
781
782   field_type_node = make_node (RECORD_TYPE);
783   field_ptr_type_node = build_pointer_type (field_type_node);
784   method_type_node = make_node (RECORD_TYPE);
785   method_ptr_type_node = build_pointer_type (method_type_node);
786
787   set_super_info (0, class_type_node, object_type_node, 0);
788   set_super_info (0, string_type_node, object_type_node, 0);
789   class_ptr_type = build_pointer_type (class_type_node);
790
791   PUSH_FIELD (class_type_node, field, "next_or_version", class_ptr_type);
792   PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
793   PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
794   PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
795   PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
796   constants_field_decl_node = field;
797   PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
798   PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
799   PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
800   PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
801   PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
802   PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
803   PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
804   PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
805   PUSH_FIELD (class_type_node, field, "otable", otable_ptr_type);
806   PUSH_FIELD (class_type_node, field, "otable_syms", 
807               symbols_array_ptr_type);
808   PUSH_FIELD (class_type_node, field, "atable", atable_ptr_type);
809   PUSH_FIELD (class_type_node, field, "atable_syms", 
810               symbols_array_ptr_type);
811   PUSH_FIELD (class_type_node, field, "itable", itable_ptr_type);
812   PUSH_FIELD (class_type_node, field, "itable_syms", 
813               symbols_array_ptr_type);
814   PUSH_FIELD (class_type_node, field, "catch_classes", ptr_type_node);
815   PUSH_FIELD (class_type_node, field, "interfaces",
816               build_pointer_type (class_ptr_type));
817   PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
818   PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
819   PUSH_FIELD (class_type_node, field, "state", byte_type_node);
820   PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
821   PUSH_FIELD (class_type_node, field, "depth", short_type_node);
822   PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
823   PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);  
824   PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);  
825   PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
826   PUSH_FIELD (class_type_node, field, "assertion_table", ptr_type_node);
827   PUSH_FIELD (class_type_node, field, "hack_signers", ptr_type_node);
828   PUSH_FIELD (class_type_node, field, "chain", ptr_type_node);
829   PUSH_FIELD (class_type_node, field, "aux_info", ptr_type_node);
830   PUSH_FIELD (class_type_node, field, "engine", ptr_type_node);
831   PUSH_FIELD (class_type_node, field, "reflection_data", ptr_type_node);
832   for (t = TYPE_FIELDS (class_type_node);  t != NULL_TREE;  t = TREE_CHAIN (t))
833     FIELD_PRIVATE (t) = 1;
834   push_super_field (class_type_node, object_type_node);
835
836   FINISH_RECORD (class_type_node);
837   build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
838
839   field_info_union_node = make_node (UNION_TYPE);
840   PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
841   PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
842   layout_type (field_info_union_node);
843
844   PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
845   PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
846   PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
847   PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
848   PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
849   FINISH_RECORD (field_type_node);
850   build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
851
852   nativecode_ptr_array_type_node
853     = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
854
855   PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
856   PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
857   FINISH_RECORD (dtable_type);
858   build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
859
860   jexception_type = make_node (RECORD_TYPE);
861   PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
862   PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
863   PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
864   PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
865   FINISH_RECORD (jexception_type);
866   build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
867   jexception_ptr_type = build_pointer_type (jexception_type);
868
869   lineNumberEntry_type = make_node (RECORD_TYPE);
870   PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
871   PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
872   FINISH_RECORD (lineNumberEntry_type);
873
874   lineNumbers_type = make_node (RECORD_TYPE);
875   PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
876   FINISH_RECORD (lineNumbers_type);
877
878   PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
879   PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
880   PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
881   PUSH_FIELD (method_type_node, field, "index", unsigned_short_type_node);
882   PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
883   PUSH_FIELD (method_type_node, field, "throws", ptr_type_node);
884   FINISH_RECORD (method_type_node);
885   build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
886
887   endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
888
889   t = tree_cons (NULL_TREE, class_ptr_type, endlink);
890   alloc_object_node = add_builtin_function ("_Jv_AllocObject",
891                                             build_function_type (ptr_type_node, t),
892                                             0, NOT_BUILT_IN, NULL, NULL_TREE);
893   DECL_IS_MALLOC (alloc_object_node) = 1;
894   alloc_no_finalizer_node =
895     add_builtin_function ("_Jv_AllocObjectNoFinalizer",
896                           build_function_type (ptr_type_node, t),
897                           0, NOT_BUILT_IN, NULL, NULL_TREE);
898   DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
899
900   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
901   soft_initclass_node = add_builtin_function ("_Jv_InitClass",
902                                               build_function_type (void_type_node,
903                                                                    t),
904                                               0, NOT_BUILT_IN, NULL, NULL_TREE);
905   t = tree_cons (NULL_TREE, class_ptr_type,
906                  tree_cons (NULL_TREE, int_type_node, endlink));
907   soft_resolvepoolentry_node
908     = add_builtin_function ("_Jv_ResolvePoolEntry",
909                             build_function_type (ptr_type_node, t),
910                             0,NOT_BUILT_IN, NULL, NULL_TREE);
911   DECL_IS_PURE (soft_resolvepoolentry_node) = 1;
912   throw_node = add_builtin_function ("_Jv_Throw",
913                                      build_function_type (void_type_node, t),
914                                      0, NOT_BUILT_IN, NULL, NULL_TREE);
915   /* Mark throw_nodes as `noreturn' functions with side effects.  */
916   TREE_THIS_VOLATILE (throw_node) = 1;
917   TREE_SIDE_EFFECTS (throw_node) = 1;
918
919   t = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node,
920                                                       endlink));
921   soft_monitorenter_node
922     = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
923                             NULL, NULL_TREE);
924   soft_monitorexit_node
925     = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
926                             NULL, NULL_TREE);
927
928   t = tree_cons (NULL_TREE, ptr_type_node,
929                  tree_cons (NULL_TREE, int_type_node, endlink));
930   soft_newarray_node
931       = add_builtin_function ("_Jv_NewPrimArray",
932                               build_function_type (ptr_type_node, t),
933                               0, NOT_BUILT_IN, NULL, NULL_TREE);
934   DECL_IS_MALLOC (soft_newarray_node) = 1;
935
936   t = tree_cons (NULL_TREE, int_type_node,
937                  tree_cons (NULL_TREE, class_ptr_type,
938                             tree_cons (NULL_TREE, object_ptr_type_node,
939                                        endlink)));
940   soft_anewarray_node
941       = add_builtin_function ("_Jv_NewObjectArray",
942                               build_function_type (ptr_type_node, t),
943                               0, NOT_BUILT_IN, NULL, NULL_TREE);
944   DECL_IS_MALLOC (soft_anewarray_node) = 1;
945
946   /* There is no endlink here because _Jv_NewMultiArray is a varargs
947      function.  */
948   t = tree_cons (NULL_TREE, ptr_type_node,
949                  tree_cons (NULL_TREE, int_type_node, NULL_TREE));
950   soft_multianewarray_node
951       = add_builtin_function ("_Jv_NewMultiArray",
952                               build_function_type (ptr_type_node, t),
953                               0, NOT_BUILT_IN, NULL, NULL_TREE);
954   DECL_IS_MALLOC (soft_multianewarray_node) = 1;
955
956   t = build_function_type (void_type_node, 
957                            tree_cons (NULL_TREE, int_type_node, endlink));
958   soft_badarrayindex_node
959       = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
960                               0, NOT_BUILT_IN, NULL, NULL_TREE);
961   /* Mark soft_badarrayindex_node as a `noreturn' function with side
962      effects.  */
963   TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
964   TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
965
966   soft_nullpointer_node
967     = add_builtin_function ("_Jv_ThrowNullPointerException",
968                             build_function_type (void_type_node, endlink),
969                             0, NOT_BUILT_IN, NULL, NULL_TREE);
970   /* Mark soft_nullpointer_node as a `noreturn' function with side
971      effects.  */
972   TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
973   TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
974
975   soft_abstractmethod_node
976     = add_builtin_function ("_Jv_ThrowAbstractMethodError",
977                             build_function_type (void_type_node, endlink),
978                             0, NOT_BUILT_IN, NULL, NULL_TREE);
979   /* Mark soft_abstractmethod_node as a `noreturn' function with side
980      effects.  */
981   TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
982   TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
983
984   soft_nosuchfield_node
985     = add_builtin_function ("_Jv_ThrowNoSuchFieldError",
986                             build_function_type (void_type_node, endlink),
987                             0, NOT_BUILT_IN, NULL, NULL_TREE);
988   /* Mark soft_nosuchfield_node as a `noreturn' function with side
989      effects.  */
990   TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
991   TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
992
993   t = tree_cons (NULL_TREE, class_ptr_type,
994                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
995   soft_checkcast_node
996     = add_builtin_function ("_Jv_CheckCast",
997                             build_function_type (ptr_type_node, t),
998                             0, NOT_BUILT_IN, NULL, NULL_TREE);
999   t = tree_cons (NULL_TREE, object_ptr_type_node,
1000                  tree_cons (NULL_TREE, class_ptr_type, endlink));
1001   soft_instanceof_node
1002     = add_builtin_function ("_Jv_IsInstanceOf",
1003                             build_function_type (boolean_type_node, t),
1004                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1005   DECL_IS_PURE (soft_instanceof_node) = 1;
1006   t = tree_cons (NULL_TREE, object_ptr_type_node,
1007                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1008   soft_checkarraystore_node
1009     = add_builtin_function ("_Jv_CheckArrayStore",
1010                             build_function_type (void_type_node, t),
1011                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1012   t = tree_cons (NULL_TREE, ptr_type_node,
1013                  tree_cons (NULL_TREE, ptr_type_node,
1014                             tree_cons (NULL_TREE, int_type_node, endlink)));
1015   soft_lookupinterfacemethod_node
1016     = add_builtin_function ("_Jv_LookupInterfaceMethodIdx",
1017                             build_function_type (ptr_type_node, t),
1018                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1019   DECL_IS_PURE (soft_lookupinterfacemethod_node) = 1;
1020   t = tree_cons (NULL_TREE, ptr_type_node,
1021                  tree_cons (NULL_TREE, ptr_type_node,
1022                             tree_cons (NULL_TREE, ptr_type_node, endlink)));
1023   soft_lookupinterfacemethodbyname_node
1024     = add_builtin_function ("_Jv_LookupInterfaceMethod",
1025                             build_function_type (ptr_type_node, t),
1026                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1027   t = tree_cons (NULL_TREE, object_ptr_type_node,
1028                  tree_cons (NULL_TREE, ptr_type_node,
1029                             tree_cons (NULL_TREE, ptr_type_node, 
1030                                        tree_cons (NULL_TREE, int_type_node, 
1031                                                   endlink))));
1032   soft_lookupjnimethod_node
1033     = add_builtin_function ("_Jv_LookupJNIMethod",
1034                             build_function_type (ptr_type_node, t),
1035                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1036   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1037   soft_getjnienvnewframe_node
1038     = add_builtin_function ("_Jv_GetJNIEnvNewFrame",
1039                             build_function_type (ptr_type_node, t),
1040                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1041   soft_jnipopsystemframe_node
1042     = add_builtin_function ("_Jv_JNI_PopSystemFrame",
1043                             build_function_type (void_type_node, t),
1044                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1045
1046   t = tree_cons (NULL_TREE, object_ptr_type_node, endlink);
1047   soft_unwrapjni_node
1048     = add_builtin_function ("_Jv_UnwrapJNIweakReference",
1049                             build_function_type (object_ptr_type_node, t),
1050                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1051
1052   t = tree_cons (NULL_TREE, int_type_node,
1053                  tree_cons (NULL_TREE, int_type_node, endlink));
1054   soft_idiv_node
1055     = add_builtin_function ("_Jv_divI",
1056                             build_function_type (int_type_node, t),
1057                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1058
1059   soft_irem_node
1060     = add_builtin_function ("_Jv_remI",
1061                             build_function_type (int_type_node, t),
1062                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1063
1064   t = tree_cons (NULL_TREE, long_type_node,
1065                  tree_cons (NULL_TREE, long_type_node, endlink));
1066   soft_ldiv_node
1067     = add_builtin_function ("_Jv_divJ",
1068                             build_function_type (long_type_node, t),
1069                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1070
1071   soft_lrem_node
1072     = add_builtin_function ("_Jv_remJ",
1073                             build_function_type (long_type_node, t),
1074                             0, NOT_BUILT_IN, NULL, NULL_TREE);
1075
1076   /* Initialize variables for except.c.  */
1077   eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
1078                                              ? "__gcj_personality_sj0"
1079                                              : "__gcj_personality_v0");
1080   default_init_unwind_resume_libfunc ();
1081
1082   lang_eh_runtime_type = do_nothing;
1083
1084   initialize_builtins ();
1085   soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1086
1087   parse_version ();
1088 }
1089
1090
1091 /* Look up NAME in the current binding level and its superiors
1092    in the namespace of variables, functions and typedefs.
1093    Return a ..._DECL node of some kind representing its definition,
1094    or return 0 if it is undefined.  */
1095
1096 tree
1097 lookup_name (tree name)
1098 {
1099   tree val;
1100   if (current_binding_level != global_binding_level
1101       && IDENTIFIER_LOCAL_VALUE (name))
1102     val = IDENTIFIER_LOCAL_VALUE (name);
1103   else
1104     val = IDENTIFIER_GLOBAL_VALUE (name);
1105   return val;
1106 }
1107
1108 /* Similar to `lookup_name' but look only at current binding level and
1109    the previous one if it's the parameter level.  */
1110
1111 static tree
1112 lookup_name_current_level (tree name)
1113 {
1114   tree t;
1115
1116   if (current_binding_level == global_binding_level)
1117     return IDENTIFIER_GLOBAL_VALUE (name);
1118
1119   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1120     return 0;
1121
1122   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
1123     if (DECL_NAME (t) == name)
1124       break;
1125
1126   return t;
1127 }
1128
1129 /* Use a binding level to record a labeled block declaration */
1130
1131 void
1132 push_labeled_block (tree lb)
1133 {
1134   tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
1135   struct binding_level *b = current_binding_level;
1136   tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1137   if (oldlocal != 0)
1138       b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1139   TREE_CHAIN (lb) = b->names;
1140   b->names = lb;
1141   IDENTIFIER_LOCAL_VALUE (name) = lb;
1142 }
1143
1144 /* Pop the current binding level, reinstalling values for the previous
1145    labeled block */
1146
1147 void
1148 pop_labeled_block (void)
1149 {
1150   struct binding_level *b = current_binding_level;
1151   tree label =  b->names;
1152   IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) = 
1153     NULL_TREE;
1154   if (b->shadowed)
1155     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) = 
1156       TREE_VALUE (b->shadowed);
1157
1158   /* Pop the current level, and free the structure for reuse.  */
1159   current_binding_level = current_binding_level->level_chain;
1160   b->level_chain = free_binding_level;
1161   free_binding_level = b;
1162 }
1163
1164 /* Record a decl-node X as belonging to the current lexical scope.
1165    Check for errors (such as an incompatible declaration for the same
1166    name already seen in the same scope).
1167
1168    Returns either X or an old decl for the same name.
1169    If an old decl is returned, it may have been smashed
1170    to agree with what X says.  */
1171
1172 tree
1173 pushdecl (tree x)
1174 {
1175   tree t;
1176   tree name = DECL_NAME (x);
1177   struct binding_level *b = current_binding_level;
1178   
1179   if (TREE_CODE (x) != TYPE_DECL)
1180     DECL_CONTEXT (x) = current_function_decl;
1181   if (name)
1182     {
1183       t = lookup_name_current_level (name);
1184       if (t != 0 && t == error_mark_node)
1185         /* error_mark_node is 0 for a while during initialization!  */
1186         {
1187           t = 0;
1188           error ("%q+D used prior to declaration", x);
1189         }
1190
1191       /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1192          to point to the TYPE_DECL.
1193          Since Java does not have typedefs, a type can only have
1194          one (true) name, given by a class, interface, or builtin. */
1195       if (TREE_CODE (x) == TYPE_DECL
1196           && TYPE_NAME (TREE_TYPE (x)) == 0
1197           && TREE_TYPE (x) != error_mark_node)
1198         {
1199           TYPE_NAME (TREE_TYPE (x)) = x;
1200           TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1201         }
1202
1203       /* This name is new in its binding level.
1204          Install the new declaration and return it.  */
1205       if (b == global_binding_level)
1206         {
1207           /* Install a global value.  */
1208           
1209           IDENTIFIER_GLOBAL_VALUE (name) = x;
1210         }
1211       else
1212         {
1213           /* Here to install a non-global value.  */
1214           tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1215           IDENTIFIER_LOCAL_VALUE (name) = x;
1216
1217           /* If storing a local value, there may already be one (inherited).
1218              If so, record it for restoration when this binding level ends.  */
1219           if (oldlocal != 0)
1220             b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1221         }
1222     }
1223
1224   /* Put decls on list in reverse order.
1225      We will reverse them later if necessary.  */
1226   TREE_CHAIN (x) = b->names;
1227   b->names = x;
1228
1229   return x;
1230 }
1231
1232 void
1233 pushdecl_force_head (tree x)
1234 {
1235   current_binding_level->names = x;
1236 }
1237
1238 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate.  */
1239
1240 tree
1241 pushdecl_top_level (tree x)
1242 {
1243   tree t;
1244   struct binding_level *b = current_binding_level;
1245
1246   current_binding_level = global_binding_level;
1247   t = pushdecl (x);
1248   current_binding_level = b;
1249   return t;
1250 }
1251
1252 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate.  */
1253
1254 tree
1255 pushdecl_function_level (tree x)
1256 {
1257   tree t;
1258   struct binding_level *b = current_binding_level;
1259
1260   current_binding_level = function_binding_level;
1261   t = pushdecl (x);
1262   current_binding_level = b;
1263   return t;
1264 }
1265
1266 /* Nonzero if we are currently in the global binding level.  */
1267
1268 int
1269 global_bindings_p (void)
1270 {
1271   return current_binding_level == global_binding_level;
1272 }
1273
1274 /* Return the list of declarations of the current level.
1275    Note that this list is in reverse order unless/until
1276    you nreverse it; and when you do nreverse it, you must
1277    store the result back using `storedecls' or you will lose.  */
1278
1279 tree
1280 getdecls (void)
1281 {
1282   return current_binding_level->names;
1283 }
1284
1285 /* Create a new `struct binding_level'.  */
1286
1287 static struct binding_level *
1288 make_binding_level (void)
1289 {
1290   /* NOSTRICT */
1291   return ggc_alloc_cleared (sizeof (struct binding_level));
1292 }
1293
1294 void
1295 pushlevel (int unused ATTRIBUTE_UNUSED)
1296 {
1297   struct binding_level *newlevel = NULL_BINDING_LEVEL;
1298
1299   /* Reuse or create a struct for this binding level.  */
1300
1301   if (free_binding_level)
1302     {
1303       newlevel = free_binding_level;
1304       free_binding_level = free_binding_level->level_chain;
1305     }
1306   else
1307     {
1308       newlevel = make_binding_level ();
1309     }
1310
1311   /* Add this level to the front of the chain (stack) of levels that
1312      are active.  */
1313
1314   *newlevel = clear_binding_level;
1315   newlevel->level_chain = current_binding_level;
1316   current_binding_level = newlevel;
1317 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1318   newlevel->binding_depth = binding_depth;
1319   indent ();
1320   fprintf (stderr, "push %s level %p pc %d\n",
1321            (is_class_level) ? "class" : "block", newlevel, current_pc);
1322   is_class_level = 0;
1323   binding_depth++;
1324 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1325 }
1326
1327 /* Exit a binding level.
1328    Pop the level off, and restore the state of the identifier-decl mappings
1329    that were in effect when this level was entered.
1330
1331    If KEEP is nonzero, this level had explicit declarations, so
1332    and create a "block" (a BLOCK node) for the level
1333    to record its declarations and subblocks for symbol table output.
1334
1335    If FUNCTIONBODY is nonzero, this level is the body of a function,
1336    so create a block as if KEEP were set and also clear out all
1337    label names.
1338
1339    If REVERSE is nonzero, reverse the order of decls before putting
1340    them into the BLOCK.  */
1341
1342 tree
1343 poplevel (int keep, int reverse, int functionbody)
1344 {
1345   tree link;
1346   /* The chain of decls was accumulated in reverse order.
1347      Put it into forward order, just for cleanliness.  */
1348   tree decls;
1349   tree subblocks = current_binding_level->blocks;
1350   tree block = 0;
1351   tree decl;
1352   tree bind = 0;
1353
1354 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1355   binding_depth--;
1356   indent ();
1357   if (current_binding_level->end_pc != LARGEST_PC)
1358     fprintf (stderr, "pop  %s level %p pc %d (end pc %d)\n",
1359              (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1360              current_binding_level->end_pc);
1361   else
1362     fprintf (stderr, "pop  %s level %p pc %d\n",
1363              (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1364 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1365
1366   /* Get the decls in the order they were written.
1367      Usually current_binding_level->names is in reverse order.
1368      But parameter decls were previously put in forward order.  */
1369
1370   if (reverse)
1371     current_binding_level->names
1372       = decls = nreverse (current_binding_level->names);
1373   else
1374     decls = current_binding_level->names;
1375
1376   for (decl = decls; decl; decl = TREE_CHAIN (decl))
1377     if (TREE_CODE (decl) == VAR_DECL
1378         && DECL_LANG_SPECIFIC (decl) != NULL
1379         && DECL_LOCAL_SLOT_NUMBER (decl))
1380       LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1381
1382   /* If there were any declarations in that level,
1383      or if this level is a function body,
1384      create a BLOCK to record them for the life of this function.  */
1385
1386   block = 0;
1387   if (keep || functionbody)
1388     {
1389       block = make_node (BLOCK);
1390       TREE_TYPE (block) = void_type_node;
1391     }
1392
1393   if (current_binding_level->exception_range)
1394     expand_end_java_handler (current_binding_level->exception_range);
1395
1396   if (block != 0)
1397     {
1398       /* If any statements have been generated at this level, create a
1399          BIND_EXPR to hold them and copy the variables to it.  This
1400          only applies to the bytecode compiler.  */
1401       if (current_binding_level->stmts)
1402         {
1403           tree decl = decls;
1404           tree *var = &BLOCK_VARS (block);
1405
1406           /* Copy decls from names list, ignoring labels.  */
1407           while (decl)
1408             {
1409               tree next = TREE_CHAIN (decl);
1410               if (TREE_CODE (decl) != LABEL_DECL)
1411                 {
1412                   *var = decl;
1413                   var = &TREE_CHAIN (decl);
1414                 }
1415               decl = next;
1416             }
1417           *var = NULL;
1418             
1419           bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block), 
1420                          BLOCK_EXPR_BODY (block), block);
1421           BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1422           
1423           if (BIND_EXPR_BODY (bind)
1424               && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1425             TREE_SIDE_EFFECTS (bind) = 1;
1426           
1427           /* FIXME: gimplifier brain damage.  */
1428           if (BIND_EXPR_BODY (bind) == NULL)
1429             BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1430
1431           current_binding_level->stmts = NULL;
1432         }
1433       else
1434         {
1435           BLOCK_VARS (block) = decls;
1436         }
1437       BLOCK_SUBBLOCKS (block) = subblocks;
1438     }   
1439
1440   /* In each subblock, record that this is its superior.  */
1441
1442   for (link = subblocks; link; link = TREE_CHAIN (link))
1443     BLOCK_SUPERCONTEXT (link) = block;
1444
1445   /* Clear out the meanings of the local variables of this level.  */
1446
1447   for (link = decls; link; link = TREE_CHAIN (link))
1448     {
1449       tree name = DECL_NAME (link);
1450       if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1451         {
1452           /* If the ident. was used or addressed via a local extern decl,
1453              don't forget that fact.  */
1454           if (DECL_EXTERNAL (link))
1455             {
1456               if (TREE_USED (link))
1457                 TREE_USED (name) = 1;
1458               if (TREE_ADDRESSABLE (link))
1459                 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1460             }
1461           IDENTIFIER_LOCAL_VALUE (name) = 0;
1462         }
1463     }
1464
1465   /* Restore all name-meanings of the outer levels
1466      that were shadowed by this level.  */
1467
1468   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1469     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1470
1471   /* If the level being exited is the top level of a function,
1472      check over all the labels, and clear out the current
1473      (function local) meanings of their names.  */
1474
1475   if (functionbody)
1476     {
1477       /* If this is the top level block of a function,
1478          the vars are the function's parameters.
1479          Don't leave them in the BLOCK because they are
1480          found in the FUNCTION_DECL instead.  */
1481
1482       BLOCK_VARS (block) = 0;
1483     }
1484
1485   /* Pop the current level, and free the structure for reuse.  */
1486
1487   {
1488     struct binding_level *level = current_binding_level;
1489     current_binding_level = current_binding_level->level_chain;
1490
1491     level->level_chain = free_binding_level;
1492     free_binding_level = level;
1493   }
1494
1495   /* Dispose of the block that we just made inside some higher level.  */
1496   if (functionbody)
1497     {
1498       DECL_INITIAL (current_function_decl) = block;
1499       DECL_SAVED_TREE (current_function_decl) = bind;
1500     }
1501   else 
1502     {
1503       if (block)
1504         {
1505           current_binding_level->blocks
1506             = chainon (current_binding_level->blocks, block);
1507         }
1508       /* If we did not make a block for the level just exited,
1509          any blocks made for inner levels
1510          (since they cannot be recorded as subblocks in that level)
1511          must be carried forward so they will later become subblocks
1512          of something else.  */
1513       else if (subblocks)
1514         current_binding_level->blocks
1515           = chainon (current_binding_level->blocks, subblocks);
1516
1517       if (bind)
1518         java_add_stmt (bind);
1519     }
1520
1521   if (block)
1522     TREE_USED (block) = 1;
1523   return block;
1524 }
1525
1526 void
1527 maybe_pushlevels (int pc)
1528 {
1529 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1530   current_pc = pc;
1531 #endif
1532
1533   while (pending_local_decls != NULL_TREE &&
1534          DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1535     {
1536       tree *ptr = &pending_local_decls;
1537       tree decl = *ptr, next;
1538       int end_pc = DECL_LOCAL_END_PC (decl);
1539
1540       while (*ptr != NULL_TREE
1541              && DECL_LOCAL_START_PC (*ptr) <= pc
1542              && DECL_LOCAL_END_PC (*ptr) == end_pc)
1543         ptr = &TREE_CHAIN (*ptr);
1544       pending_local_decls = *ptr;
1545       *ptr = NULL_TREE;
1546
1547       /* Force non-nested range to be nested in current range by
1548          truncating variable lifetimes. */
1549       if (end_pc > current_binding_level->end_pc)
1550         {
1551           tree t;
1552           end_pc = current_binding_level->end_pc;
1553           for (t = decl; t != NULL_TREE; t = TREE_CHAIN (t))
1554             DECL_LOCAL_END_PC (t) = end_pc;
1555         }
1556
1557       maybe_start_try (pc, end_pc);
1558       
1559       pushlevel (1);
1560
1561       current_binding_level->end_pc = end_pc;
1562       current_binding_level->start_pc = pc;      
1563       current_binding_level->names = NULL;
1564       for ( ; decl != NULL_TREE; decl = next)
1565         {
1566           int index = DECL_LOCAL_SLOT_NUMBER (decl);
1567           tree base_decl;
1568           next = TREE_CHAIN (decl);
1569           push_jvm_slot (index, decl);
1570           pushdecl (decl);
1571           base_decl
1572             = find_local_variable (index, TREE_TYPE (decl), pc);
1573           if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1574             base_decl = TREE_VEC_ELT (base_decl_map, index);
1575           SET_DECL_VALUE_EXPR (decl, base_decl);
1576           DECL_HAS_VALUE_EXPR_P (decl) = 1;
1577         }
1578     }      
1579
1580   maybe_start_try (pc, 0);
1581 }
1582
1583 void
1584 maybe_poplevels (int pc)
1585 {
1586 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1587   current_pc = pc;
1588 #endif
1589
1590   /* FIXME: I'm pretty sure that this is wrong.  Variable scopes are
1591      inclusive, so a variable is live if pc == end_pc.  Here, we
1592      terminate a range if the current pc is equal to the end of the
1593      range, and this is *before* we have generated code for the
1594      instruction at end_pc.  We're closing a binding level one
1595      instruction too early.*/
1596   while (current_binding_level->end_pc <= pc)
1597     poplevel (1, 0, 0);
1598 }
1599
1600 /* Terminate any binding which began during the range beginning at
1601    start_pc.  This tidies up improperly nested local variable ranges
1602    and exception handlers; a variable declared within an exception
1603    range is forcibly terminated when that exception ends. */
1604
1605 void
1606 force_poplevels (int start_pc)
1607 {
1608   while (current_binding_level->start_pc > start_pc)
1609     {
1610       if (pedantic && current_binding_level->start_pc > start_pc)
1611         warning (0, "In %+D: overlapped variable and exception ranges at %d",
1612                  current_function_decl,
1613                  current_binding_level->start_pc);
1614       poplevel (1, 0, 0);
1615     }
1616 }
1617
1618 /* Insert BLOCK at the end of the list of subblocks of the
1619    current binding level.  This is used when a BIND_EXPR is expanded,
1620    to handle the BLOCK node inside the BIND_EXPR.  */
1621
1622 void
1623 insert_block (tree block)
1624 {
1625   TREE_USED (block) = 1;
1626   current_binding_level->blocks
1627     = chainon (current_binding_level->blocks, block);
1628 }
1629
1630 /* integrate_decl_tree calls this function. */
1631
1632 void
1633 java_dup_lang_specific_decl (tree node)
1634 {
1635   int lang_decl_size;
1636   struct lang_decl *x;
1637
1638   if (!DECL_LANG_SPECIFIC (node))
1639     return;
1640
1641   lang_decl_size = sizeof (struct lang_decl);
1642   x = ggc_alloc (lang_decl_size);
1643   memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1644   DECL_LANG_SPECIFIC (node) = x;
1645 }
1646
1647 void
1648 give_name_to_locals (JCF *jcf)
1649 {
1650   int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1651   int code_offset = DECL_CODE_OFFSET (current_function_decl);
1652   tree parm;
1653   pending_local_decls = NULL_TREE;
1654   if (n == 0)
1655     return;
1656   JCF_SEEK (jcf, n);
1657   n = JCF_readu2 (jcf);
1658   for (i = 0; i < n; i++)
1659     {
1660       int start_pc = JCF_readu2 (jcf);
1661       int length = JCF_readu2 (jcf);
1662       int name_index = JCF_readu2 (jcf);
1663       int signature_index = JCF_readu2 (jcf);
1664       int slot = JCF_readu2 (jcf);
1665       tree name = get_name_constant (jcf, name_index);
1666       tree type = parse_signature (jcf, signature_index);
1667       if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1668           && start_pc == 0
1669           && length == DECL_CODE_LENGTH (current_function_decl))
1670         {
1671           tree decl = TREE_VEC_ELT (decl_map, slot);
1672           DECL_NAME (decl) = name;
1673           if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1674             warning (0, "bad type in parameter debug info");
1675         }
1676       else
1677         {
1678           tree *ptr;
1679           int end_pc = start_pc + length;
1680           tree decl = build_decl (VAR_DECL, name, type);
1681           if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1682             {
1683               warning (0, "bad PC range for debug info for local %q+D",
1684                        decl);
1685               end_pc = DECL_CODE_LENGTH (current_function_decl);
1686             }
1687
1688           /* Adjust start_pc if necessary so that the local's first
1689              store operation will use the relevant DECL as a
1690              destination. Fore more information, read the leading
1691              comments for expr.c:maybe_adjust_start_pc. */
1692           start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1693
1694           MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1695           DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1696           DECL_LOCAL_START_PC (decl) = start_pc;
1697           DECL_LOCAL_END_PC (decl) = end_pc;
1698
1699           /* Now insert the new decl in the proper place in
1700              pending_local_decls.  We are essentially doing an insertion sort,
1701              which works fine, since the list input will normally already
1702              be sorted. */
1703           ptr = &pending_local_decls;
1704           while (*ptr != NULL_TREE
1705                  && (DECL_LOCAL_START_PC (*ptr) > start_pc
1706                      || (DECL_LOCAL_START_PC (*ptr) == start_pc
1707                          && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1708             ptr = &TREE_CHAIN (*ptr);
1709           TREE_CHAIN (decl) = *ptr;
1710           *ptr = decl;
1711         }
1712     }
1713
1714   pending_local_decls = nreverse (pending_local_decls);
1715
1716   /* Fill in default names for the parameters. */ 
1717   for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1718        parm != NULL_TREE;  parm = TREE_CHAIN (parm), i++)
1719     {
1720       if (DECL_NAME (parm) == NULL_TREE)
1721         {
1722           int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1723           if (arg_i == 0)
1724             DECL_NAME (parm) = get_identifier ("this");
1725           else
1726             {
1727               char buffer[12];
1728               sprintf (buffer, "ARG_%d", arg_i);
1729               DECL_NAME (parm) = get_identifier (buffer);
1730             }
1731         }
1732     }
1733 }
1734
1735 tree
1736 build_result_decl (tree fndecl)
1737 {
1738   tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1739   tree result = DECL_RESULT (fndecl);
1740   if (! result)
1741     {
1742       /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1743       if (INTEGRAL_TYPE_P (restype)
1744           && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1745         restype = integer_type_node;
1746       result = build_decl (RESULT_DECL, NULL_TREE, restype);
1747       DECL_ARTIFICIAL (result) = 1;
1748       DECL_IGNORED_P (result) = 1;
1749       DECL_CONTEXT (result) = fndecl;
1750       DECL_RESULT (fndecl) = result;
1751     }
1752   return result;
1753 }
1754
1755 void
1756 start_java_method (tree fndecl)
1757 {
1758   tree tem, *ptr;
1759   int i;
1760
1761   uniq = 0;
1762
1763   current_function_decl = fndecl;
1764   announce_function (fndecl);
1765
1766   i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1767   decl_map = make_tree_vec (i);
1768   base_decl_map = make_tree_vec (i);
1769   type_map = xrealloc (type_map, i * sizeof (tree));
1770
1771 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1772   fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1773   current_pc = 0;
1774 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1775   pushlevel (1);  /* Push parameters. */
1776
1777   ptr = &DECL_ARGUMENTS (fndecl);
1778   for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1779        tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1780     {
1781       tree parm_name = NULL_TREE, parm_decl;
1782       tree parm_type = TREE_VALUE (tem);
1783       gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1784
1785       parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1786       DECL_CONTEXT (parm_decl) = fndecl;
1787       if (targetm.calls.promote_prototypes (parm_type)
1788           && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1789           && INTEGRAL_TYPE_P (parm_type))
1790         parm_type = integer_type_node;
1791       DECL_ARG_TYPE (parm_decl) = parm_type;
1792
1793       *ptr = parm_decl;
1794       ptr = &TREE_CHAIN (parm_decl);
1795
1796       /* Add parm_decl to the decl_map. */
1797       push_jvm_slot (i, parm_decl);
1798
1799       type_map[i] = TREE_TYPE (parm_decl);
1800       if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1801         {
1802           i++;
1803           type_map[i] = void_type_node;
1804         }
1805     }
1806   *ptr = NULL_TREE;
1807   DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1808
1809   while (i < DECL_MAX_LOCALS(fndecl))
1810     type_map[i++] = NULL_TREE;
1811
1812   build_result_decl (fndecl);
1813
1814   /* Push local variables.  */
1815   pushlevel (2);
1816
1817   function_binding_level = current_binding_level;
1818 }
1819
1820 void
1821 end_java_method (void)
1822 {
1823   tree fndecl = current_function_decl;
1824
1825   /* pop out of function */
1826   poplevel (1, 1, 0);
1827
1828   /* pop out of its parameters */
1829   poplevel (1, 0, 1);
1830
1831   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1832   
1833   if (DECL_SAVED_TREE (fndecl))
1834     {
1835       tree fbody, block_body;
1836       /* Before we check initialization, attached all class initialization
1837          variable to the block_body */
1838       fbody = DECL_SAVED_TREE (fndecl);
1839       block_body = BIND_EXPR_BODY (fbody);
1840       htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1841                      attach_init_test_initialization_flags, block_body);
1842     }
1843
1844   finish_method (fndecl);
1845
1846   if (! flag_unit_at_a_time)
1847     {
1848       /* Nulling these fields when we no longer need them saves
1849          memory.  */
1850       DECL_SAVED_TREE (fndecl) = NULL;
1851       DECL_STRUCT_FUNCTION (fndecl) = NULL;
1852       DECL_INITIAL (fndecl) = NULL_TREE;
1853     }
1854   current_function_decl = NULL_TREE;
1855 }
1856
1857 /* Prepare a method for expansion.  */
1858
1859 void
1860 finish_method (tree fndecl)
1861 {
1862   tree *tp = &DECL_SAVED_TREE (fndecl);
1863
1864   /* Wrap body of synchronized methods in a monitorenter,
1865      plus monitorexit cleanup.  */
1866   if (METHOD_SYNCHRONIZED (fndecl))
1867     {
1868       tree enter, exit, lock;
1869       if (METHOD_STATIC (fndecl))
1870         lock = build_class_ref (DECL_CONTEXT (fndecl));
1871       else
1872         lock = DECL_ARGUMENTS (fndecl);
1873       BUILD_MONITOR_ENTER (enter, lock);
1874       BUILD_MONITOR_EXIT (exit, lock);
1875       *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1876                     build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1877     }
1878
1879   /* Prepend class initialization for static methods reachable from
1880      other classes.  */
1881   if (METHOD_STATIC (fndecl)
1882       && (! METHOD_PRIVATE (fndecl)
1883           || INNER_CLASS_P (DECL_CONTEXT (fndecl)))
1884       && ! DECL_CLINIT_P (fndecl)
1885       && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl))))
1886     {
1887       tree clas = DECL_CONTEXT (fndecl);
1888       tree init = build3 (CALL_EXPR, void_type_node,
1889                           build_address_of (soft_initclass_node),
1890                           build_tree_list (NULL_TREE, build_class_ref (clas)),
1891                           NULL_TREE);
1892       *tp = build2 (COMPOUND_EXPR, TREE_TYPE (*tp), init, *tp);
1893     }
1894
1895   /* Convert function tree to GENERIC prior to inlining.  */
1896   java_genericize (fndecl);
1897
1898   /* Store the end of the function, so that we get good line number
1899      info for the epilogue.  */
1900   if (DECL_STRUCT_FUNCTION (fndecl))
1901     cfun = DECL_STRUCT_FUNCTION (fndecl);
1902   else
1903     allocate_struct_function (fndecl);
1904 #ifdef USE_MAPPED_LOCATION
1905   cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1906 #else
1907   cfun->function_end_locus.file = DECL_SOURCE_FILE (fndecl);
1908   cfun->function_end_locus.line = DECL_FUNCTION_LAST_LINE (fndecl);
1909 #endif
1910
1911   /* Defer inlining and expansion to the cgraph optimizers.  */
1912   cgraph_finalize_function (fndecl, false);
1913 }
1914
1915 /* Optimize and expand a function's entire body.  */
1916
1917 void
1918 java_expand_body (tree fndecl)
1919 {
1920   tree_rest_of_compilation (fndecl);
1921 }
1922
1923 /* We pessimistically marked all methods and fields external until we
1924    knew what set of classes we were planning to compile.  Now mark those
1925    associated with CLASS to be generated locally as not external.  */
1926
1927 static void
1928 java_mark_decl_local (tree decl)
1929 {
1930   DECL_EXTERNAL (decl) = 0;
1931
1932   /* If we've already constructed DECL_RTL, give encode_section_info
1933      a second chance, now that we've changed the flags.  */
1934   /* ??? Ideally, we'd have flag_unit_at_a_time set, and not have done
1935      anything that would have referenced DECL_RTL so far.  But at the
1936      moment we force flag_unit_at_a_time off due to excessive memory
1937      consumption when compiling large jar files.  Which probably means
1938      that we need to re-order how we process jar files...  */
1939   if (DECL_RTL_SET_P (decl))
1940     make_decl_rtl (decl);
1941 }
1942
1943 /* Given appropriate target support, G++ will emit hidden aliases for native
1944    methods.  Using this hidden name is required for proper operation of
1945    _Jv_Method::ncode, but it doesn't hurt to use it everywhere.  Look for
1946    proper target support, then mark the method for aliasing.  */
1947
1948 static void
1949 java_mark_cni_decl_local (tree decl)
1950 {
1951   /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the mangler.
1952      We expect that we should not yet have referenced this decl in a 
1953      context that requires it.  Check this invariant even if we don't have
1954      support for hidden aliases.  */
1955   gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl));
1956
1957 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1958   return;
1959 #endif
1960
1961   DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1962   DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1963 }
1964
1965 /* Use the preceding two functions and mark all members of the class.  */
1966
1967 void
1968 java_mark_class_local (tree class)
1969 {
1970   tree t;
1971
1972   for (t = TYPE_FIELDS (class); t ; t = TREE_CHAIN (t))
1973     if (FIELD_STATIC (t))
1974       java_mark_decl_local (t);
1975
1976   for (t = TYPE_METHODS (class); t ; t = TREE_CHAIN (t))
1977     if (!METHOD_ABSTRACT (t))
1978       {
1979         if (METHOD_NATIVE (t) && !flag_jni)
1980           java_mark_cni_decl_local (t);
1981         else
1982           java_mark_decl_local (t);
1983       }
1984 }
1985
1986 /* Add a statement to a compound_expr.  */
1987
1988 tree
1989 add_stmt_to_compound (tree existing, tree type, tree stmt)
1990 {
1991   if (!stmt)
1992     return existing;
1993   else if (existing)
1994     {
1995       tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
1996       TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
1997                                  | TREE_SIDE_EFFECTS (stmt);
1998       return expr;
1999     }
2000   else
2001     return stmt;
2002 }
2003
2004 /* Add a statement to the statement_list currently being constructed.
2005    If the statement_list is null, we don't create a singleton list.
2006    This is necessary because poplevel() assumes that adding a
2007    statement to a null statement_list returns the statement.  */
2008
2009 tree
2010 java_add_stmt (tree new_stmt)
2011 {
2012   tree stmts = current_binding_level->stmts;
2013   tree_stmt_iterator i;
2014
2015   if (input_filename)
2016     SET_EXPR_LOCATION (new_stmt, input_location);
2017   
2018   if (stmts == NULL)
2019     return current_binding_level->stmts = new_stmt;
2020
2021   /* Force STMTS to be a statement_list.  */
2022   if (TREE_CODE (stmts) != STATEMENT_LIST)
2023     {
2024       tree t = make_node (STATEMENT_LIST);
2025       i = tsi_last (t);
2026       tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2027       stmts = t;
2028     }  
2029       
2030   i = tsi_last (stmts);
2031   tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2032   TREE_TYPE (stmts) = void_type_node;
2033
2034   return current_binding_level->stmts = stmts;
2035 }
2036
2037 /* Add a variable to the current scope.  */
2038
2039 tree
2040 java_add_local_var (tree decl)
2041 {
2042   tree *vars = &current_binding_level->names;
2043   tree next = *vars;
2044   TREE_CHAIN (decl) = next;
2045   *vars = decl;
2046   DECL_CONTEXT (decl) = current_function_decl;
2047   MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2048   return decl;
2049 }
2050
2051 /* Return a pointer to the compound_expr currently being
2052    constructed.  */
2053
2054 tree *
2055 get_stmts (void)
2056 {
2057   return &current_binding_level->stmts;
2058 }
2059
2060 /* Register an exception range as belonging to the current binding
2061    level.  There may only be one: if there are more, we'll create more
2062    binding levels.  However, each range can have multiple handlers,
2063    and these are expanded when we call expand_end_java_handler().  */
2064
2065 void
2066 register_exception_range (struct eh_range *range, int pc, int end_pc)
2067 {
2068   gcc_assert (! current_binding_level->exception_range);
2069   current_binding_level->exception_range = range;
2070   current_binding_level->end_pc = end_pc;
2071   current_binding_level->start_pc = pc;      
2072 }
2073
2074 #include "gt-java-decl.h"