OSDN Git Service

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