OSDN Git Service

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