OSDN Git Service

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