OSDN Git Service

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