xref: /openbsd/gnu/usr.bin/gcc/gcc/java/decl.c (revision c87b03e5)
1*c87b03e5Sespie /* Process declarations and variables for the GNU compiler for the
2*c87b03e5Sespie    Java(TM) language.
3*c87b03e5Sespie    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
4*c87b03e5Sespie    Free Software Foundation, Inc.
5*c87b03e5Sespie 
6*c87b03e5Sespie This file is part of GNU CC.
7*c87b03e5Sespie 
8*c87b03e5Sespie GNU CC is free software; you can redistribute it and/or modify
9*c87b03e5Sespie it under the terms of the GNU General Public License as published by
10*c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option)
11*c87b03e5Sespie any later version.
12*c87b03e5Sespie 
13*c87b03e5Sespie GNU CC is distributed in the hope that it will be useful,
14*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
15*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*c87b03e5Sespie GNU General Public License for more details.
17*c87b03e5Sespie 
18*c87b03e5Sespie You should have received a copy of the GNU General Public License
19*c87b03e5Sespie along with GNU CC; see the file COPYING.  If not, write to
20*c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330,
21*c87b03e5Sespie Boston, MA 02111-1307, USA.
22*c87b03e5Sespie 
23*c87b03e5Sespie Java and all Java-based marks are trademarks or registered trademarks
24*c87b03e5Sespie of Sun Microsystems, Inc. in the United States and other countries.
25*c87b03e5Sespie The Free Software Foundation is independent of Sun Microsystems, Inc.  */
26*c87b03e5Sespie 
27*c87b03e5Sespie /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
28*c87b03e5Sespie 
29*c87b03e5Sespie #include "config.h"
30*c87b03e5Sespie #include "system.h"
31*c87b03e5Sespie #include "tree.h"
32*c87b03e5Sespie #include "rtl.h"
33*c87b03e5Sespie #include "real.h"
34*c87b03e5Sespie #include "toplev.h"
35*c87b03e5Sespie #include "flags.h"
36*c87b03e5Sespie #include "java-tree.h"
37*c87b03e5Sespie #include "jcf.h"
38*c87b03e5Sespie #include "function.h"
39*c87b03e5Sespie #include "expr.h"
40*c87b03e5Sespie #include "libfuncs.h"
41*c87b03e5Sespie #include "except.h"
42*c87b03e5Sespie #include "java-except.h"
43*c87b03e5Sespie #include "ggc.h"
44*c87b03e5Sespie #include "timevar.h"
45*c87b03e5Sespie #include "tree-inline.h"
46*c87b03e5Sespie 
47*c87b03e5Sespie #if defined (DEBUG_JAVA_BINDING_LEVELS)
48*c87b03e5Sespie extern void indent PARAMS ((void));
49*c87b03e5Sespie #endif
50*c87b03e5Sespie 
51*c87b03e5Sespie static tree push_jvm_slot PARAMS ((int, tree));
52*c87b03e5Sespie static tree lookup_name_current_level PARAMS ((tree));
53*c87b03e5Sespie static tree push_promoted_type PARAMS ((const char *, tree));
54*c87b03e5Sespie static struct binding_level *make_binding_level PARAMS ((void));
55*c87b03e5Sespie static tree create_primitive_vtable PARAMS ((const char *));
56*c87b03e5Sespie static tree check_local_named_variable PARAMS ((tree, tree, int, int *));
57*c87b03e5Sespie static tree check_local_unnamed_variable PARAMS ((tree, tree, tree));
58*c87b03e5Sespie static void dump_function PARAMS ((enum tree_dump_index, tree));
59*c87b03e5Sespie 
60*c87b03e5Sespie /* Name of the Cloneable class.  */
61*c87b03e5Sespie tree java_lang_cloneable_identifier_node;
62*c87b03e5Sespie 
63*c87b03e5Sespie /* Name of the Serializable class.  */
64*c87b03e5Sespie tree java_io_serializable_identifier_node;
65*c87b03e5Sespie 
66*c87b03e5Sespie /* Set to nonzero value in order to emit class initilization code
67*c87b03e5Sespie    before static field references.  */
68*c87b03e5Sespie extern int always_initialize_class_p;
69*c87b03e5Sespie 
70*c87b03e5Sespie /* The DECL_MAP is a mapping from (index, type) to a decl node.
71*c87b03e5Sespie    If index < max_locals, it is the index of a local variable.
72*c87b03e5Sespie    if index >= max_locals, then index-max_locals is a stack slot.
73*c87b03e5Sespie    The DECL_MAP mapping is represented as a TREE_VEC whose elements
74*c87b03e5Sespie    are a list of decls (VAR_DECL or PARM_DECL) chained by
75*c87b03e5Sespie    DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
76*c87b03e5Sespie    we search the chain for a decl with a matching TREE_TYPE. */
77*c87b03e5Sespie 
78*c87b03e5Sespie static GTY(()) tree decl_map;
79*c87b03e5Sespie 
80*c87b03e5Sespie /* A list of local variables VAR_DECLs for this method that we have seen
81*c87b03e5Sespie    debug information, but we have not reached their starting (byte) PC yet. */
82*c87b03e5Sespie 
83*c87b03e5Sespie static GTY(()) tree pending_local_decls;
84*c87b03e5Sespie 
85*c87b03e5Sespie /* Push a local variable or stack slot into the decl_map,
86*c87b03e5Sespie    and assign it an rtl. */
87*c87b03e5Sespie 
88*c87b03e5Sespie #if defined(DEBUG_JAVA_BINDING_LEVELS)
89*c87b03e5Sespie int binding_depth = 0;
90*c87b03e5Sespie int is_class_level = 0;
91*c87b03e5Sespie int current_pc;
92*c87b03e5Sespie 
93*c87b03e5Sespie void
indent()94*c87b03e5Sespie indent ()
95*c87b03e5Sespie {
96*c87b03e5Sespie   register unsigned i;
97*c87b03e5Sespie 
98*c87b03e5Sespie   for (i = 0; i < binding_depth*2; i++)
99*c87b03e5Sespie     putc (' ', stderr);
100*c87b03e5Sespie }
101*c87b03e5Sespie #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
102*c87b03e5Sespie 
103*c87b03e5Sespie static tree
push_jvm_slot(index,decl)104*c87b03e5Sespie push_jvm_slot (index, decl)
105*c87b03e5Sespie      int index;
106*c87b03e5Sespie      tree decl;
107*c87b03e5Sespie {
108*c87b03e5Sespie   struct rtx_def *rtl = NULL;
109*c87b03e5Sespie   tree type = TREE_TYPE (decl);
110*c87b03e5Sespie   tree tmp;
111*c87b03e5Sespie 
112*c87b03e5Sespie   DECL_CONTEXT (decl) = current_function_decl;
113*c87b03e5Sespie   layout_decl (decl, 0);
114*c87b03e5Sespie 
115*c87b03e5Sespie   /* See if we have an appropriate rtl (i.e. same mode) at this index.
116*c87b03e5Sespie      If so, we must use it. */
117*c87b03e5Sespie   tmp = TREE_VEC_ELT (decl_map, index);
118*c87b03e5Sespie   while (tmp != NULL_TREE)
119*c87b03e5Sespie     {
120*c87b03e5Sespie       if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
121*c87b03e5Sespie 	rtl = DECL_RTL_IF_SET (tmp);
122*c87b03e5Sespie       if (rtl != NULL)
123*c87b03e5Sespie 	break;
124*c87b03e5Sespie      tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
125*c87b03e5Sespie     }
126*c87b03e5Sespie   if (rtl != NULL)
127*c87b03e5Sespie     SET_DECL_RTL (decl, rtl);
128*c87b03e5Sespie   else
129*c87b03e5Sespie     {
130*c87b03e5Sespie       if (index >= DECL_MAX_LOCALS (current_function_decl))
131*c87b03e5Sespie 	DECL_REGISTER (decl) = 1;
132*c87b03e5Sespie       expand_decl (decl);
133*c87b03e5Sespie     }
134*c87b03e5Sespie 
135*c87b03e5Sespie   /* Now link the decl into the decl_map. */
136*c87b03e5Sespie   if (DECL_LANG_SPECIFIC (decl) == NULL)
137*c87b03e5Sespie     {
138*c87b03e5Sespie       MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
139*c87b03e5Sespie       DECL_LOCAL_START_PC (decl) = 0;
140*c87b03e5Sespie       DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
141*c87b03e5Sespie       DECL_LOCAL_SLOT_NUMBER (decl) = index;
142*c87b03e5Sespie     }
143*c87b03e5Sespie   DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
144*c87b03e5Sespie   TREE_VEC_ELT (decl_map, index) = decl;
145*c87b03e5Sespie   return decl;
146*c87b03e5Sespie }
147*c87b03e5Sespie 
148*c87b03e5Sespie /* Find out if 'decl' passed in fits the defined PC location better than
149*c87b03e5Sespie    'best'.  Return decl if it does, return best if it doesn't.  If decl
150*c87b03e5Sespie    is returned, then updated is set to true.  */
151*c87b03e5Sespie 
152*c87b03e5Sespie static tree
check_local_named_variable(best,decl,pc,updated)153*c87b03e5Sespie check_local_named_variable (best, decl, pc, updated)
154*c87b03e5Sespie      tree best;
155*c87b03e5Sespie      tree decl;
156*c87b03e5Sespie      int pc;
157*c87b03e5Sespie      int *updated;
158*c87b03e5Sespie {
159*c87b03e5Sespie   if (pc >= DECL_LOCAL_START_PC (decl)
160*c87b03e5Sespie       && pc < DECL_LOCAL_END_PC (decl))
161*c87b03e5Sespie     {
162*c87b03e5Sespie       if (best == NULL_TREE
163*c87b03e5Sespie 	  || (DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
164*c87b03e5Sespie 	      && DECL_LOCAL_END_PC (decl) < DECL_LOCAL_END_PC (best)))
165*c87b03e5Sespie         {
166*c87b03e5Sespie 	  *updated = 1;
167*c87b03e5Sespie 	  return decl;
168*c87b03e5Sespie 	}
169*c87b03e5Sespie     }
170*c87b03e5Sespie 
171*c87b03e5Sespie   return best;
172*c87b03e5Sespie }
173*c87b03e5Sespie 
174*c87b03e5Sespie /* Find the best declaration based upon type.  If 'decl' fits 'type' better
175*c87b03e5Sespie    than 'best', return 'decl'.  Otherwise return 'best'.  */
176*c87b03e5Sespie 
177*c87b03e5Sespie static tree
check_local_unnamed_variable(best,decl,type)178*c87b03e5Sespie check_local_unnamed_variable (best, decl, type)
179*c87b03e5Sespie      tree best;
180*c87b03e5Sespie      tree decl;
181*c87b03e5Sespie      tree type;
182*c87b03e5Sespie {
183*c87b03e5Sespie     if (TREE_TYPE (decl) == type
184*c87b03e5Sespie 	|| (TREE_CODE (TREE_TYPE (decl)) == TREE_CODE (type)
185*c87b03e5Sespie 	    && TYPE_PRECISION (TREE_TYPE (decl)) <= 32
186*c87b03e5Sespie 	    && TYPE_PRECISION (type) <= 32
187*c87b03e5Sespie 	    && TREE_CODE (type) != POINTER_TYPE)
188*c87b03e5Sespie 	|| (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
189*c87b03e5Sespie 	    && type == ptr_type_node))
190*c87b03e5Sespie       {
191*c87b03e5Sespie 	if (best == NULL_TREE
192*c87b03e5Sespie 	    || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type))
193*c87b03e5Sespie 	  return decl;
194*c87b03e5Sespie       }
195*c87b03e5Sespie 
196*c87b03e5Sespie     return best;
197*c87b03e5Sespie }
198*c87b03e5Sespie 
199*c87b03e5Sespie 
200*c87b03e5Sespie /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
201*c87b03e5Sespie    that is valid at PC (or -1 if any pc).
202*c87b03e5Sespie    If there is no existing matching decl, allocate one.  */
203*c87b03e5Sespie 
204*c87b03e5Sespie tree
find_local_variable(index,type,pc)205*c87b03e5Sespie find_local_variable (index, type, pc)
206*c87b03e5Sespie      int index;
207*c87b03e5Sespie      tree type;
208*c87b03e5Sespie      int pc;
209*c87b03e5Sespie {
210*c87b03e5Sespie   tree decl = TREE_VEC_ELT (decl_map, index);
211*c87b03e5Sespie   tree best = NULL_TREE;
212*c87b03e5Sespie   int found_scoped_var = 0;
213*c87b03e5Sespie 
214*c87b03e5Sespie   /* Scan through every declaration that has been created in this slot. */
215*c87b03e5Sespie   while (decl != NULL_TREE)
216*c87b03e5Sespie     {
217*c87b03e5Sespie        /* Variables created in give_name_to_locals() have a name and have
218*c87b03e5Sespie  	 a specified scope, so we can handle them specifically.  We want
219*c87b03e5Sespie  	 to use the specific decls created for those so they are assigned
220*c87b03e5Sespie  	 the right variables in the debugging information. */
221*c87b03e5Sespie       if (DECL_NAME (decl) != NULL_TREE)
222*c87b03e5Sespie 	{
223*c87b03e5Sespie 	  /* This is a variable we have a name for, so it has a scope
224*c87b03e5Sespie 	     supplied in the class file.  But it only matters when we
225*c87b03e5Sespie 	     actually have a PC to use.  If pc<0, then we are asking
226*c87b03e5Sespie 	     for a stack slot and this decl won't be one of those. */
227*c87b03e5Sespie  	  if (pc >= 0)
228*c87b03e5Sespie  	    best = check_local_named_variable (best, decl, pc,
229*c87b03e5Sespie  					       &found_scoped_var);
230*c87b03e5Sespie  	}
231*c87b03e5Sespie       /* We scan for type information unless we found a variable in the
232*c87b03e5Sespie 	 proper scope already. */
233*c87b03e5Sespie       else if (!found_scoped_var)
234*c87b03e5Sespie  	{
235*c87b03e5Sespie  	  /* If we don't have scoping information for a variable, we use
236*c87b03e5Sespie  	     a different method to look it up. */
237*c87b03e5Sespie  	  best = check_local_unnamed_variable (best, decl, type);
238*c87b03e5Sespie  	}
239*c87b03e5Sespie 
240*c87b03e5Sespie       decl = DECL_LOCAL_SLOT_CHAIN (decl);
241*c87b03e5Sespie     }
242*c87b03e5Sespie 
243*c87b03e5Sespie   if (best != NULL_TREE)
244*c87b03e5Sespie     return best;
245*c87b03e5Sespie 
246*c87b03e5Sespie   /* If we don't find a match, create one with the type passed in. */
247*c87b03e5Sespie   return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
248*c87b03e5Sespie }
249*c87b03e5Sespie 
250*c87b03e5Sespie 
251*c87b03e5Sespie /* Same as find_local_index, except that INDEX is a stack index. */
252*c87b03e5Sespie 
253*c87b03e5Sespie tree
find_stack_slot(index,type)254*c87b03e5Sespie find_stack_slot (index, type)
255*c87b03e5Sespie      int index;
256*c87b03e5Sespie      tree type;
257*c87b03e5Sespie {
258*c87b03e5Sespie   return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
259*c87b03e5Sespie 			      type, -1);
260*c87b03e5Sespie }
261*c87b03e5Sespie 
262*c87b03e5Sespie struct binding_level
263*c87b03e5Sespie   {
264*c87b03e5Sespie     /* A chain of _DECL nodes for all variables, constants, functions,
265*c87b03e5Sespie      * and typedef types.  These are in the reverse of the order supplied.
266*c87b03e5Sespie      */
267*c87b03e5Sespie     tree names;
268*c87b03e5Sespie 
269*c87b03e5Sespie     /* For each level, a list of shadowed outer-level local definitions
270*c87b03e5Sespie        to be restored when this level is popped.
271*c87b03e5Sespie        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
272*c87b03e5Sespie        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
273*c87b03e5Sespie     tree shadowed;
274*c87b03e5Sespie 
275*c87b03e5Sespie     /* For each level (except not the global one),
276*c87b03e5Sespie        a chain of BLOCK nodes for all the levels
277*c87b03e5Sespie        that were entered and exited one level down.  */
278*c87b03e5Sespie     tree blocks;
279*c87b03e5Sespie 
280*c87b03e5Sespie     /* The BLOCK node for this level, if one has been preallocated.
281*c87b03e5Sespie        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
282*c87b03e5Sespie     tree this_block;
283*c87b03e5Sespie 
284*c87b03e5Sespie     /* The binding level which this one is contained in (inherits from).  */
285*c87b03e5Sespie     struct binding_level *level_chain;
286*c87b03e5Sespie 
287*c87b03e5Sespie     /* The bytecode PC that marks the end of this level. */
288*c87b03e5Sespie     int end_pc;
289*c87b03e5Sespie     /* The bytecode PC that marks the start of this level. */
290*c87b03e5Sespie     int start_pc;
291*c87b03e5Sespie 
292*c87b03e5Sespie #if defined(DEBUG_JAVA_BINDING_LEVELS)
293*c87b03e5Sespie     /* Binding depth at which this level began.  */
294*c87b03e5Sespie     unsigned binding_depth;
295*c87b03e5Sespie #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
296*c87b03e5Sespie   };
297*c87b03e5Sespie 
298*c87b03e5Sespie #define NULL_BINDING_LEVEL (struct binding_level *) NULL
299*c87b03e5Sespie 
300*c87b03e5Sespie /* The binding level currently in effect.  */
301*c87b03e5Sespie 
302*c87b03e5Sespie static struct binding_level *current_binding_level;
303*c87b03e5Sespie 
304*c87b03e5Sespie /* A chain of binding_level structures awaiting reuse.  */
305*c87b03e5Sespie 
306*c87b03e5Sespie static struct binding_level *free_binding_level;
307*c87b03e5Sespie 
308*c87b03e5Sespie /* The outermost binding level, for names of file scope.
309*c87b03e5Sespie    This is created when the compiler is started and exists
310*c87b03e5Sespie    through the entire run.  */
311*c87b03e5Sespie 
312*c87b03e5Sespie static struct binding_level *global_binding_level;
313*c87b03e5Sespie 
314*c87b03e5Sespie /* A PC value bigger than any PC value we may ever may encounter. */
315*c87b03e5Sespie 
316*c87b03e5Sespie #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
317*c87b03e5Sespie 
318*c87b03e5Sespie /* Binding level structures are initialized by copying this one.  */
319*c87b03e5Sespie 
320*c87b03e5Sespie static const struct binding_level clear_binding_level
321*c87b03e5Sespie   = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
322*c87b03e5Sespie        NULL_BINDING_LEVEL, LARGEST_PC, 0};
323*c87b03e5Sespie 
324*c87b03e5Sespie #if 0
325*c87b03e5Sespie /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
326*c87b03e5Sespie    that have names.  Here so we can clear out their names' definitions
327*c87b03e5Sespie    at the end of the function.  */
328*c87b03e5Sespie 
329*c87b03e5Sespie static tree named_labels;
330*c87b03e5Sespie 
331*c87b03e5Sespie /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
332*c87b03e5Sespie 
333*c87b03e5Sespie static tree shadowed_labels;
334*c87b03e5Sespie #endif
335*c87b03e5Sespie 
336*c87b03e5Sespie tree java_global_trees[JTI_MAX];
337*c87b03e5Sespie 
338*c87b03e5Sespie /* Build (and pushdecl) a "promoted type" for all standard
339*c87b03e5Sespie    types shorter than int.  */
340*c87b03e5Sespie 
341*c87b03e5Sespie static tree
push_promoted_type(name,actual_type)342*c87b03e5Sespie push_promoted_type (name, actual_type)
343*c87b03e5Sespie      const char *name;
344*c87b03e5Sespie      tree actual_type;
345*c87b03e5Sespie {
346*c87b03e5Sespie   tree type = make_node (TREE_CODE (actual_type));
347*c87b03e5Sespie #if 1
348*c87b03e5Sespie   tree in_min = TYPE_MIN_VALUE (int_type_node);
349*c87b03e5Sespie   tree in_max = TYPE_MAX_VALUE (int_type_node);
350*c87b03e5Sespie #else
351*c87b03e5Sespie   tree in_min = TYPE_MIN_VALUE (actual_type);
352*c87b03e5Sespie   tree in_max = TYPE_MAX_VALUE (actual_type);
353*c87b03e5Sespie #endif
354*c87b03e5Sespie   TYPE_MIN_VALUE (type) = copy_node (in_min);
355*c87b03e5Sespie   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
356*c87b03e5Sespie   TYPE_MAX_VALUE (type) = copy_node (in_max);
357*c87b03e5Sespie   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
358*c87b03e5Sespie   TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
359*c87b03e5Sespie   layout_type (type);
360*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
361*c87b03e5Sespie   return type;
362*c87b03e5Sespie }
363*c87b03e5Sespie 
364*c87b03e5Sespie /* Return a definition for a builtin function named NAME and whose data type
365*c87b03e5Sespie    is TYPE.  TYPE should be a function type with argument types.
366*c87b03e5Sespie    FUNCTION_CODE tells later passes how to compile calls to this function.
367*c87b03e5Sespie    See tree.h for its possible values.
368*c87b03e5Sespie 
369*c87b03e5Sespie    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
370*c87b03e5Sespie    the name to be called if we can't opencode the function.  If
371*c87b03e5Sespie    ATTRS is nonzero, use that for the function's attribute list.  */
372*c87b03e5Sespie 
373*c87b03e5Sespie tree
builtin_function(name,type,function_code,class,library_name,attrs)374*c87b03e5Sespie builtin_function (name, type, function_code, class, library_name, attrs)
375*c87b03e5Sespie      const char *name;
376*c87b03e5Sespie      tree type;
377*c87b03e5Sespie      int function_code;
378*c87b03e5Sespie      enum built_in_class class;
379*c87b03e5Sespie      const char *library_name;
380*c87b03e5Sespie      tree attrs ATTRIBUTE_UNUSED;
381*c87b03e5Sespie {
382*c87b03e5Sespie   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
383*c87b03e5Sespie   DECL_EXTERNAL (decl) = 1;
384*c87b03e5Sespie   TREE_PUBLIC (decl) = 1;
385*c87b03e5Sespie   if (library_name)
386*c87b03e5Sespie     SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
387*c87b03e5Sespie   make_decl_rtl (decl, NULL);
388*c87b03e5Sespie   pushdecl (decl);
389*c87b03e5Sespie   DECL_BUILT_IN_CLASS (decl) = class;
390*c87b03e5Sespie   DECL_FUNCTION_CODE (decl) = function_code;
391*c87b03e5Sespie   return decl;
392*c87b03e5Sespie }
393*c87b03e5Sespie 
394*c87b03e5Sespie /* Return tree that represents a vtable for a primitive array.  */
395*c87b03e5Sespie static tree
create_primitive_vtable(name)396*c87b03e5Sespie create_primitive_vtable (name)
397*c87b03e5Sespie      const char *name;
398*c87b03e5Sespie {
399*c87b03e5Sespie   tree r;
400*c87b03e5Sespie   char buf[50];
401*c87b03e5Sespie 
402*c87b03e5Sespie   sprintf (buf, "_Jv_%sVTable", name);
403*c87b03e5Sespie   r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
404*c87b03e5Sespie   DECL_EXTERNAL (r) = 1;
405*c87b03e5Sespie   return r;
406*c87b03e5Sespie }
407*c87b03e5Sespie 
408*c87b03e5Sespie void
java_init_decl_processing()409*c87b03e5Sespie java_init_decl_processing ()
410*c87b03e5Sespie {
411*c87b03e5Sespie   register tree endlink;
412*c87b03e5Sespie   tree field = NULL_TREE;
413*c87b03e5Sespie   tree t;
414*c87b03e5Sespie 
415*c87b03e5Sespie   init_class_processing ();
416*c87b03e5Sespie 
417*c87b03e5Sespie   current_function_decl = NULL;
418*c87b03e5Sespie   current_binding_level = NULL_BINDING_LEVEL;
419*c87b03e5Sespie   free_binding_level = NULL_BINDING_LEVEL;
420*c87b03e5Sespie   pushlevel (0);	/* make the binding_level structure for global names */
421*c87b03e5Sespie   global_binding_level = current_binding_level;
422*c87b03e5Sespie 
423*c87b03e5Sespie   /* The code here must be similar to build_common_tree_nodes{,_2} in
424*c87b03e5Sespie      tree.c, especially as to the order of initializing common nodes.  */
425*c87b03e5Sespie   error_mark_node = make_node (ERROR_MARK);
426*c87b03e5Sespie   TREE_TYPE (error_mark_node) = error_mark_node;
427*c87b03e5Sespie 
428*c87b03e5Sespie   /* Create sizetype first - needed for other types. */
429*c87b03e5Sespie   initialize_sizetypes ();
430*c87b03e5Sespie 
431*c87b03e5Sespie   byte_type_node = make_signed_type (8);
432*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
433*c87b03e5Sespie   short_type_node = make_signed_type (16);
434*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
435*c87b03e5Sespie   int_type_node = make_signed_type (32);
436*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
437*c87b03e5Sespie   long_type_node = make_signed_type (64);
438*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
439*c87b03e5Sespie 
440*c87b03e5Sespie   unsigned_byte_type_node = make_unsigned_type (8);
441*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
442*c87b03e5Sespie 			unsigned_byte_type_node));
443*c87b03e5Sespie   unsigned_short_type_node = make_unsigned_type (16);
444*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
445*c87b03e5Sespie 			unsigned_short_type_node));
446*c87b03e5Sespie   unsigned_int_type_node = make_unsigned_type (32);
447*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
448*c87b03e5Sespie 			unsigned_int_type_node));
449*c87b03e5Sespie   unsigned_long_type_node = make_unsigned_type (64);
450*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
451*c87b03e5Sespie 			unsigned_long_type_node));
452*c87b03e5Sespie 
453*c87b03e5Sespie   set_sizetype (make_unsigned_type (POINTER_SIZE));
454*c87b03e5Sespie 
455*c87b03e5Sespie   /* Define these next since types below may used them.  */
456*c87b03e5Sespie   integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
457*c87b03e5Sespie   integer_zero_node = build_int_2 (0, 0);
458*c87b03e5Sespie   integer_one_node = build_int_2 (1, 0);
459*c87b03e5Sespie   integer_two_node = build_int_2 (2, 0);
460*c87b03e5Sespie   integer_four_node = build_int_2 (4, 0);
461*c87b03e5Sespie   integer_minus_one_node = build_int_2 (-1, -1);
462*c87b03e5Sespie 
463*c87b03e5Sespie   /* A few values used for range checking in the lexer.  */
464*c87b03e5Sespie   decimal_int_max = build_int_2 (0x80000000, 0);
465*c87b03e5Sespie   TREE_TYPE (decimal_int_max) = unsigned_int_type_node;
466*c87b03e5Sespie #if HOST_BITS_PER_WIDE_INT == 64
467*c87b03e5Sespie   decimal_long_max = build_int_2 (0x8000000000000000LL, 0);
468*c87b03e5Sespie #else
469*c87b03e5Sespie #if HOST_BITS_PER_WIDE_INT == 32
470*c87b03e5Sespie   decimal_long_max = build_int_2 (0, 0x80000000);
471*c87b03e5Sespie #else
472*c87b03e5Sespie  #error "unsupported size"
473*c87b03e5Sespie #endif
474*c87b03e5Sespie #endif
475*c87b03e5Sespie   TREE_TYPE (decimal_long_max) = unsigned_long_type_node;
476*c87b03e5Sespie 
477*c87b03e5Sespie   size_zero_node = size_int (0);
478*c87b03e5Sespie   size_one_node = size_int (1);
479*c87b03e5Sespie   bitsize_zero_node = bitsize_int (0);
480*c87b03e5Sespie   bitsize_one_node = bitsize_int (1);
481*c87b03e5Sespie   bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
482*c87b03e5Sespie 
483*c87b03e5Sespie   long_zero_node = build_int_2 (0, 0);
484*c87b03e5Sespie   TREE_TYPE (long_zero_node) = long_type_node;
485*c87b03e5Sespie 
486*c87b03e5Sespie   void_type_node = make_node (VOID_TYPE);
487*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
488*c87b03e5Sespie   layout_type (void_type_node);	/* Uses size_zero_node */
489*c87b03e5Sespie   ptr_type_node = build_pointer_type (void_type_node);
490*c87b03e5Sespie   t = make_node (VOID_TYPE);
491*c87b03e5Sespie   layout_type (t); /* Uses size_zero_node */
492*c87b03e5Sespie   return_address_type_node = build_pointer_type (t);
493*c87b03e5Sespie 
494*c87b03e5Sespie   null_pointer_node = build_int_2 (0, 0);
495*c87b03e5Sespie   TREE_TYPE (null_pointer_node) = ptr_type_node;
496*c87b03e5Sespie 
497*c87b03e5Sespie   /* Used by the parser to represent empty statements and blocks. */
498*c87b03e5Sespie   empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
499*c87b03e5Sespie   CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
500*c87b03e5Sespie 
501*c87b03e5Sespie #if 0
502*c87b03e5Sespie   /* Make a type to be the domain of a few array types
503*c87b03e5Sespie      whose domains don't really matter.
504*c87b03e5Sespie      200 is small enough that it always fits in size_t
505*c87b03e5Sespie      and large enough that it can hold most function names for the
506*c87b03e5Sespie      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
507*c87b03e5Sespie   short_array_type_node = build_prim_array_type (short_type_node, 200);
508*c87b03e5Sespie #endif
509*c87b03e5Sespie   char_type_node = make_node (CHAR_TYPE);
510*c87b03e5Sespie   TYPE_PRECISION (char_type_node) = 16;
511*c87b03e5Sespie   fixup_unsigned_type (char_type_node);
512*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
513*c87b03e5Sespie 
514*c87b03e5Sespie   boolean_type_node = make_node (BOOLEAN_TYPE);
515*c87b03e5Sespie   TYPE_PRECISION (boolean_type_node) = 1;
516*c87b03e5Sespie   fixup_unsigned_type (boolean_type_node);
517*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
518*c87b03e5Sespie 			boolean_type_node));
519*c87b03e5Sespie   boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
520*c87b03e5Sespie   boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
521*c87b03e5Sespie 
522*c87b03e5Sespie   promoted_byte_type_node
523*c87b03e5Sespie     = push_promoted_type ("promoted_byte", byte_type_node);
524*c87b03e5Sespie   promoted_short_type_node
525*c87b03e5Sespie     = push_promoted_type ("promoted_short", short_type_node);
526*c87b03e5Sespie   promoted_char_type_node
527*c87b03e5Sespie     = push_promoted_type ("promoted_char", char_type_node);
528*c87b03e5Sespie   promoted_boolean_type_node
529*c87b03e5Sespie     = push_promoted_type ("promoted_boolean", boolean_type_node);
530*c87b03e5Sespie 
531*c87b03e5Sespie   float_type_node = make_node (REAL_TYPE);
532*c87b03e5Sespie   TYPE_PRECISION (float_type_node) = 32;
533*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
534*c87b03e5Sespie                         float_type_node));
535*c87b03e5Sespie   layout_type (float_type_node);
536*c87b03e5Sespie 
537*c87b03e5Sespie   double_type_node = make_node (REAL_TYPE);
538*c87b03e5Sespie   TYPE_PRECISION (double_type_node) = 64;
539*c87b03e5Sespie   pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
540*c87b03e5Sespie                         double_type_node));
541*c87b03e5Sespie   layout_type (double_type_node);
542*c87b03e5Sespie 
543*c87b03e5Sespie   float_zero_node = build_real (float_type_node, dconst0);
544*c87b03e5Sespie   double_zero_node = build_real (double_type_node, dconst0);
545*c87b03e5Sespie 
546*c87b03e5Sespie   /* These are the vtables for arrays of primitives.  */
547*c87b03e5Sespie   boolean_array_vtable = create_primitive_vtable ("boolean");
548*c87b03e5Sespie   byte_array_vtable = create_primitive_vtable ("byte");
549*c87b03e5Sespie   char_array_vtable = create_primitive_vtable ("char");
550*c87b03e5Sespie   short_array_vtable = create_primitive_vtable ("short");
551*c87b03e5Sespie   int_array_vtable = create_primitive_vtable ("int");
552*c87b03e5Sespie   long_array_vtable = create_primitive_vtable ("long");
553*c87b03e5Sespie   float_array_vtable = create_primitive_vtable ("float");
554*c87b03e5Sespie   double_array_vtable = create_primitive_vtable ("double");
555*c87b03e5Sespie 
556*c87b03e5Sespie   /* As you're adding items here, please update the code right after
557*c87b03e5Sespie      this section, so that the filename containing the source code of
558*c87b03e5Sespie      the pre-defined class gets registered correctly. */
559*c87b03e5Sespie   unqualified_object_id_node = get_identifier ("Object");
560*c87b03e5Sespie   object_type_node = lookup_class (get_identifier ("java.lang.Object"));
561*c87b03e5Sespie   object_ptr_type_node = promote_type (object_type_node);
562*c87b03e5Sespie   string_type_node = lookup_class (get_identifier ("java.lang.String"));
563*c87b03e5Sespie   string_ptr_type_node = promote_type (string_type_node);
564*c87b03e5Sespie   class_type_node = lookup_class (get_identifier ("java.lang.Class"));
565*c87b03e5Sespie   throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
566*c87b03e5Sespie   exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
567*c87b03e5Sespie   runtime_exception_type_node =
568*c87b03e5Sespie     lookup_class (get_identifier ("java.lang.RuntimeException"));
569*c87b03e5Sespie   error_exception_type_node =
570*c87b03e5Sespie     lookup_class (get_identifier ("java.lang.Error"));
571*c87b03e5Sespie   class_not_found_type_node =
572*c87b03e5Sespie     lookup_class (get_identifier ("java.lang.ClassNotFoundException"));
573*c87b03e5Sespie   no_class_def_found_type_node =
574*c87b03e5Sespie     lookup_class (get_identifier ("java.lang.NoClassDefFoundError"));
575*c87b03e5Sespie 
576*c87b03e5Sespie   rawdata_ptr_type_node
577*c87b03e5Sespie     = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
578*c87b03e5Sespie 
579*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/Class.java"));
580*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/Error.java"));
581*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/Object.java"));
582*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
583*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/String.java"));
584*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/Throwable.java"));
585*c87b03e5Sespie   add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
586*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/Exception.java"));
587*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
588*c87b03e5Sespie   add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
589*c87b03e5Sespie   add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
590*c87b03e5Sespie 
591*c87b03e5Sespie   methodtable_type = make_node (RECORD_TYPE);
592*c87b03e5Sespie   layout_type (methodtable_type);
593*c87b03e5Sespie   build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
594*c87b03e5Sespie   methodtable_ptr_type = build_pointer_type (methodtable_type);
595*c87b03e5Sespie 
596*c87b03e5Sespie   TYPE_identifier_node = get_identifier ("TYPE");
597*c87b03e5Sespie   init_identifier_node = get_identifier ("<init>");
598*c87b03e5Sespie   clinit_identifier_node = get_identifier ("<clinit>");
599*c87b03e5Sespie   finit_identifier_node = get_identifier ("finit$");
600*c87b03e5Sespie   instinit_identifier_node = get_identifier ("instinit$");
601*c87b03e5Sespie   void_signature_node = get_identifier ("()V");
602*c87b03e5Sespie   length_identifier_node = get_identifier ("length");
603*c87b03e5Sespie   finalize_identifier_node = get_identifier ("finalize");
604*c87b03e5Sespie   this_identifier_node = get_identifier ("this");
605*c87b03e5Sespie   super_identifier_node = get_identifier ("super");
606*c87b03e5Sespie   continue_identifier_node = get_identifier ("continue");
607*c87b03e5Sespie   access0_identifier_node = get_identifier ("access$0");
608*c87b03e5Sespie   classdollar_identifier_node = get_identifier ("class$");
609*c87b03e5Sespie 
610*c87b03e5Sespie   java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
611*c87b03e5Sespie   java_io_serializable_identifier_node =
612*c87b03e5Sespie     get_identifier ("java.io.Serializable");
613*c87b03e5Sespie 
614*c87b03e5Sespie   /* for lack of a better place to put this stub call */
615*c87b03e5Sespie   init_expr_processing();
616*c87b03e5Sespie 
617*c87b03e5Sespie   utf8const_type = make_node (RECORD_TYPE);
618*c87b03e5Sespie   PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
619*c87b03e5Sespie   PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
620*c87b03e5Sespie   FINISH_RECORD (utf8const_type);
621*c87b03e5Sespie   utf8const_ptr_type = build_pointer_type (utf8const_type);
622*c87b03e5Sespie 
623*c87b03e5Sespie   constants_type_node = make_node (RECORD_TYPE);
624*c87b03e5Sespie   PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
625*c87b03e5Sespie   PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
626*c87b03e5Sespie   PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
627*c87b03e5Sespie   FINISH_RECORD (constants_type_node);
628*c87b03e5Sespie   build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
629*c87b03e5Sespie 
630*c87b03e5Sespie   access_flags_type_node = unsigned_short_type_node;
631*c87b03e5Sespie 
632*c87b03e5Sespie   dtable_type = make_node (RECORD_TYPE);
633*c87b03e5Sespie   dtable_ptr_type = build_pointer_type (dtable_type);
634*c87b03e5Sespie 
635*c87b03e5Sespie   one_elt_array_domain_type = build_index_type (integer_one_node);
636*c87b03e5Sespie   otable_type = build_array_type (integer_type_node,
637*c87b03e5Sespie 				  one_elt_array_domain_type);
638*c87b03e5Sespie   TYPE_NONALIASED_COMPONENT (otable_type) = 1;
639*c87b03e5Sespie   otable_ptr_type = build_pointer_type (otable_type);
640*c87b03e5Sespie 
641*c87b03e5Sespie   method_symbol_type = make_node (RECORD_TYPE);
642*c87b03e5Sespie   PUSH_FIELD (method_symbol_type, field, "clname", utf8const_ptr_type);
643*c87b03e5Sespie   PUSH_FIELD (method_symbol_type, field, "name", utf8const_ptr_type);
644*c87b03e5Sespie   PUSH_FIELD (method_symbol_type, field, "signature", utf8const_ptr_type);
645*c87b03e5Sespie   FINISH_RECORD (method_symbol_type);
646*c87b03e5Sespie 
647*c87b03e5Sespie   method_symbols_array_type = build_array_type (method_symbol_type,
648*c87b03e5Sespie 						one_elt_array_domain_type);
649*c87b03e5Sespie   method_symbols_array_ptr_type = build_pointer_type
650*c87b03e5Sespie 				  (method_symbols_array_type);
651*c87b03e5Sespie 
652*c87b03e5Sespie   otable_decl = build_decl (VAR_DECL, get_identifier ("otable"), otable_type);
653*c87b03e5Sespie   DECL_EXTERNAL (otable_decl) = 1;
654*c87b03e5Sespie   TREE_STATIC (otable_decl) = 1;
655*c87b03e5Sespie   TREE_READONLY (otable_decl) = 1;
656*c87b03e5Sespie   pushdecl (otable_decl);
657*c87b03e5Sespie 
658*c87b03e5Sespie   otable_syms_decl = build_decl (VAR_DECL, get_identifier ("otable_syms"),
659*c87b03e5Sespie     method_symbols_array_type);
660*c87b03e5Sespie   TREE_STATIC (otable_syms_decl) = 1;
661*c87b03e5Sespie   TREE_CONSTANT (otable_syms_decl) = 1;
662*c87b03e5Sespie   pushdecl (otable_syms_decl);
663*c87b03e5Sespie 
664*c87b03e5Sespie   PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
665*c87b03e5Sespie   /* This isn't exactly true, but it is what we have in the source.
666*c87b03e5Sespie      There is an unresolved issue here, which is whether the vtable
667*c87b03e5Sespie      should be marked by the GC.  */
668*c87b03e5Sespie   if (! flag_hash_synchronization)
669*c87b03e5Sespie     PUSH_FIELD (object_type_node, field, "sync_info",
670*c87b03e5Sespie 		build_pointer_type (object_type_node));
671*c87b03e5Sespie   for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
672*c87b03e5Sespie     FIELD_PRIVATE (t) = 1;
673*c87b03e5Sespie   FINISH_RECORD (object_type_node);
674*c87b03e5Sespie 
675*c87b03e5Sespie   field_type_node = make_node (RECORD_TYPE);
676*c87b03e5Sespie   field_ptr_type_node = build_pointer_type (field_type_node);
677*c87b03e5Sespie   method_type_node = make_node (RECORD_TYPE);
678*c87b03e5Sespie   method_ptr_type_node = build_pointer_type (method_type_node);
679*c87b03e5Sespie 
680*c87b03e5Sespie   set_super_info (0, class_type_node, object_type_node, 0);
681*c87b03e5Sespie   set_super_info (0, string_type_node, object_type_node, 0);
682*c87b03e5Sespie   class_ptr_type = build_pointer_type (class_type_node);
683*c87b03e5Sespie 
684*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
685*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
686*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
687*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
688*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
689*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
690*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
691*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
692*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
693*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
694*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
695*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
696*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
697*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "otable", otable_ptr_type);
698*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "otable_syms",
699*c87b03e5Sespie   	      method_symbols_array_ptr_type);
700*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "interfaces",
701*c87b03e5Sespie 	      build_pointer_type (class_ptr_type));
702*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
703*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
704*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "state", byte_type_node);
705*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
706*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "depth", short_type_node);
707*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
708*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
709*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);
710*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
711*c87b03e5Sespie   PUSH_FIELD (class_type_node, field, "chain", ptr_type_node);
712*c87b03e5Sespie   for (t = TYPE_FIELDS (class_type_node);  t != NULL_TREE;  t = TREE_CHAIN (t))
713*c87b03e5Sespie     FIELD_PRIVATE (t) = 1;
714*c87b03e5Sespie   push_super_field (class_type_node, object_type_node);
715*c87b03e5Sespie 
716*c87b03e5Sespie   FINISH_RECORD (class_type_node);
717*c87b03e5Sespie   build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
718*c87b03e5Sespie 
719*c87b03e5Sespie   field_info_union_node = make_node (UNION_TYPE);
720*c87b03e5Sespie   PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
721*c87b03e5Sespie   PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
722*c87b03e5Sespie #if 0
723*c87b03e5Sespie   PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
724*c87b03e5Sespie #endif
725*c87b03e5Sespie   layout_type (field_info_union_node);
726*c87b03e5Sespie 
727*c87b03e5Sespie   PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
728*c87b03e5Sespie   PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
729*c87b03e5Sespie   PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
730*c87b03e5Sespie   PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
731*c87b03e5Sespie   PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
732*c87b03e5Sespie   FINISH_RECORD (field_type_node);
733*c87b03e5Sespie   build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
734*c87b03e5Sespie 
735*c87b03e5Sespie   nativecode_ptr_array_type_node
736*c87b03e5Sespie     = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
737*c87b03e5Sespie 
738*c87b03e5Sespie   PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
739*c87b03e5Sespie   PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
740*c87b03e5Sespie   FINISH_RECORD (dtable_type);
741*c87b03e5Sespie   build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
742*c87b03e5Sespie 
743*c87b03e5Sespie #define jint_type int_type_node
744*c87b03e5Sespie #define jint_ptr_type ptr_type_node
745*c87b03e5Sespie 
746*c87b03e5Sespie   jexception_type = make_node (RECORD_TYPE);
747*c87b03e5Sespie   PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
748*c87b03e5Sespie   PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
749*c87b03e5Sespie   PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
750*c87b03e5Sespie   PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
751*c87b03e5Sespie   FINISH_RECORD (jexception_type);
752*c87b03e5Sespie   build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
753*c87b03e5Sespie   jexception_ptr_type = build_pointer_type (jexception_type);
754*c87b03e5Sespie 
755*c87b03e5Sespie   lineNumberEntry_type = make_node (RECORD_TYPE);
756*c87b03e5Sespie   PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
757*c87b03e5Sespie   PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
758*c87b03e5Sespie   FINISH_RECORD (lineNumberEntry_type);
759*c87b03e5Sespie 
760*c87b03e5Sespie   lineNumbers_type = make_node (RECORD_TYPE);
761*c87b03e5Sespie   PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
762*c87b03e5Sespie   FINISH_RECORD (lineNumbers_type);
763*c87b03e5Sespie 
764*c87b03e5Sespie #define instn_ptr_type_node ptr_type_node	/* XXX JH */
765*c87b03e5Sespie 
766*c87b03e5Sespie #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
767*c87b03e5Sespie 
768*c87b03e5Sespie   PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
769*c87b03e5Sespie   PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
770*c87b03e5Sespie   PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
771*c87b03e5Sespie   PUSH_FIELD (method_type_node, field, "index", unsigned_short_type_node);
772*c87b03e5Sespie   PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
773*c87b03e5Sespie   PUSH_FIELD (method_type_node, field, "throws", ptr_type_node);
774*c87b03e5Sespie   FINISH_RECORD (method_type_node);
775*c87b03e5Sespie   build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
776*c87b03e5Sespie 
777*c87b03e5Sespie   endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
778*c87b03e5Sespie 
779*c87b03e5Sespie   t = tree_cons (NULL_TREE, class_ptr_type,
780*c87b03e5Sespie 		 tree_cons (NULL_TREE, int_type_node, endlink));
781*c87b03e5Sespie   alloc_object_node = builtin_function ("_Jv_AllocObject",
782*c87b03e5Sespie 					build_function_type (ptr_type_node, t),
783*c87b03e5Sespie 					0, NOT_BUILT_IN, NULL, NULL_TREE);
784*c87b03e5Sespie   DECL_IS_MALLOC (alloc_object_node) = 1;
785*c87b03e5Sespie   alloc_no_finalizer_node =
786*c87b03e5Sespie     builtin_function ("_Jv_AllocObjectNoFinalizer",
787*c87b03e5Sespie 		      build_function_type (ptr_type_node, t),
788*c87b03e5Sespie 		      0, NOT_BUILT_IN, NULL, NULL_TREE);
789*c87b03e5Sespie   DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
790*c87b03e5Sespie 
791*c87b03e5Sespie   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
792*c87b03e5Sespie   soft_initclass_node = builtin_function ("_Jv_InitClass",
793*c87b03e5Sespie 					  build_function_type (void_type_node,
794*c87b03e5Sespie 							       t),
795*c87b03e5Sespie 					  0, NOT_BUILT_IN, NULL, NULL_TREE);
796*c87b03e5Sespie 
797*c87b03e5Sespie   throw_node = builtin_function ("_Jv_Throw",
798*c87b03e5Sespie 				 build_function_type (ptr_type_node, t),
799*c87b03e5Sespie 				 0, NOT_BUILT_IN, NULL, NULL_TREE);
800*c87b03e5Sespie   /* Mark throw_nodes as `noreturn' functions with side effects.  */
801*c87b03e5Sespie   TREE_THIS_VOLATILE (throw_node) = 1;
802*c87b03e5Sespie   TREE_SIDE_EFFECTS (throw_node) = 1;
803*c87b03e5Sespie 
804*c87b03e5Sespie   t = build_function_type (int_type_node, endlink);
805*c87b03e5Sespie   soft_monitorenter_node
806*c87b03e5Sespie     = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
807*c87b03e5Sespie 			NULL, NULL_TREE);
808*c87b03e5Sespie   soft_monitorexit_node
809*c87b03e5Sespie     = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
810*c87b03e5Sespie 			NULL, NULL_TREE);
811*c87b03e5Sespie 
812*c87b03e5Sespie   t = tree_cons (NULL_TREE, int_type_node,
813*c87b03e5Sespie 		 tree_cons (NULL_TREE, int_type_node, endlink));
814*c87b03e5Sespie   soft_newarray_node
815*c87b03e5Sespie       = builtin_function ("_Jv_NewPrimArray",
816*c87b03e5Sespie 			  build_function_type(ptr_type_node, t),
817*c87b03e5Sespie 			  0, NOT_BUILT_IN, NULL, NULL_TREE);
818*c87b03e5Sespie   DECL_IS_MALLOC (soft_newarray_node) = 1;
819*c87b03e5Sespie 
820*c87b03e5Sespie   t = tree_cons (NULL_TREE, int_type_node,
821*c87b03e5Sespie 		 tree_cons (NULL_TREE, class_ptr_type,
822*c87b03e5Sespie 			    tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
823*c87b03e5Sespie   soft_anewarray_node
824*c87b03e5Sespie       = builtin_function ("_Jv_NewObjectArray",
825*c87b03e5Sespie 			  build_function_type (ptr_type_node, t),
826*c87b03e5Sespie 			  0, NOT_BUILT_IN, NULL, NULL_TREE);
827*c87b03e5Sespie   DECL_IS_MALLOC (soft_anewarray_node) = 1;
828*c87b03e5Sespie 
829*c87b03e5Sespie   /* There is no endlink here because _Jv_NewMultiArray is a varargs
830*c87b03e5Sespie      function.  */
831*c87b03e5Sespie   t = tree_cons (NULL_TREE, ptr_type_node,
832*c87b03e5Sespie 		 tree_cons (NULL_TREE, int_type_node, NULL_TREE));
833*c87b03e5Sespie   soft_multianewarray_node
834*c87b03e5Sespie       = builtin_function ("_Jv_NewMultiArray",
835*c87b03e5Sespie 			  build_function_type (ptr_type_node, t),
836*c87b03e5Sespie 			  0, NOT_BUILT_IN, NULL, NULL_TREE);
837*c87b03e5Sespie   DECL_IS_MALLOC (soft_multianewarray_node) = 1;
838*c87b03e5Sespie 
839*c87b03e5Sespie   t = build_function_type (void_type_node,
840*c87b03e5Sespie 			   tree_cons (NULL_TREE, int_type_node, endlink));
841*c87b03e5Sespie   soft_badarrayindex_node
842*c87b03e5Sespie       = builtin_function ("_Jv_ThrowBadArrayIndex", t,
843*c87b03e5Sespie 			  0, NOT_BUILT_IN, NULL, NULL_TREE);
844*c87b03e5Sespie   /* Mark soft_badarrayindex_node as a `noreturn' function with side
845*c87b03e5Sespie      effects.  */
846*c87b03e5Sespie   TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
847*c87b03e5Sespie   TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
848*c87b03e5Sespie 
849*c87b03e5Sespie   soft_nullpointer_node
850*c87b03e5Sespie     = builtin_function ("_Jv_ThrowNullPointerException",
851*c87b03e5Sespie 			build_function_type (void_type_node, endlink),
852*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
853*c87b03e5Sespie   /* Mark soft_nullpointer_node as a `noreturn' function with side
854*c87b03e5Sespie      effects.  */
855*c87b03e5Sespie   TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
856*c87b03e5Sespie   TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
857*c87b03e5Sespie 
858*c87b03e5Sespie   t = tree_cons (NULL_TREE, class_ptr_type,
859*c87b03e5Sespie 		 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
860*c87b03e5Sespie   soft_checkcast_node
861*c87b03e5Sespie     = builtin_function ("_Jv_CheckCast",
862*c87b03e5Sespie 			build_function_type (ptr_type_node, t),
863*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
864*c87b03e5Sespie   t = tree_cons (NULL_TREE, object_ptr_type_node,
865*c87b03e5Sespie 		 tree_cons (NULL_TREE, class_ptr_type, endlink));
866*c87b03e5Sespie   soft_instanceof_node
867*c87b03e5Sespie     = builtin_function ("_Jv_IsInstanceOf",
868*c87b03e5Sespie 			build_function_type (boolean_type_node, t),
869*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
870*c87b03e5Sespie   t = tree_cons (NULL_TREE, object_ptr_type_node,
871*c87b03e5Sespie 		 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
872*c87b03e5Sespie   soft_checkarraystore_node
873*c87b03e5Sespie     = builtin_function ("_Jv_CheckArrayStore",
874*c87b03e5Sespie 			build_function_type (void_type_node, t),
875*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
876*c87b03e5Sespie   t = tree_cons (NULL_TREE, ptr_type_node,
877*c87b03e5Sespie 		 tree_cons (NULL_TREE, ptr_type_node,
878*c87b03e5Sespie 			    tree_cons (NULL_TREE, int_type_node, endlink)));
879*c87b03e5Sespie   soft_lookupinterfacemethod_node
880*c87b03e5Sespie     = builtin_function ("_Jv_LookupInterfaceMethodIdx",
881*c87b03e5Sespie 			build_function_type (ptr_type_node, t),
882*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
883*c87b03e5Sespie 
884*c87b03e5Sespie   t = tree_cons (NULL_TREE, object_ptr_type_node,
885*c87b03e5Sespie 		 tree_cons (NULL_TREE, ptr_type_node,
886*c87b03e5Sespie 			    tree_cons (NULL_TREE, ptr_type_node,
887*c87b03e5Sespie 			               tree_cons (NULL_TREE, int_type_node,
888*c87b03e5Sespie 				                  endlink))));
889*c87b03e5Sespie   soft_lookupjnimethod_node
890*c87b03e5Sespie     = builtin_function ("_Jv_LookupJNIMethod",
891*c87b03e5Sespie 			build_function_type (ptr_type_node, t),
892*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
893*c87b03e5Sespie   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
894*c87b03e5Sespie   soft_getjnienvnewframe_node
895*c87b03e5Sespie     = builtin_function ("_Jv_GetJNIEnvNewFrame",
896*c87b03e5Sespie 			build_function_type (ptr_type_node, t),
897*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
898*c87b03e5Sespie   soft_jnipopsystemframe_node
899*c87b03e5Sespie     = builtin_function ("_Jv_JNI_PopSystemFrame",
900*c87b03e5Sespie 			build_function_type (ptr_type_node, t),
901*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
902*c87b03e5Sespie 
903*c87b03e5Sespie   t = tree_cons (NULL_TREE, double_type_node,
904*c87b03e5Sespie 		 tree_cons (NULL_TREE, double_type_node, endlink));
905*c87b03e5Sespie   soft_fmod_node
906*c87b03e5Sespie     = builtin_function ("__builtin_fmod",
907*c87b03e5Sespie 			build_function_type (double_type_node, t),
908*c87b03e5Sespie 			BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod", NULL_TREE);
909*c87b03e5Sespie 
910*c87b03e5Sespie #if 0
911*c87b03e5Sespie   t = tree_cons (NULL_TREE, float_type_node,
912*c87b03e5Sespie 		 tree_cons (NULL_TREE, float_type_node, endlink));
913*c87b03e5Sespie   soft_fmodf_node
914*c87b03e5Sespie     = builtin_function ("__builtin_fmodf",
915*c87b03e5Sespie 			build_function_type (float_type_node, t),
916*c87b03e5Sespie 			BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf", NULL_TREE);
917*c87b03e5Sespie #endif
918*c87b03e5Sespie 
919*c87b03e5Sespie   soft_idiv_node
920*c87b03e5Sespie     = builtin_function ("_Jv_divI",
921*c87b03e5Sespie 			build_function_type (int_type_node, t),
922*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
923*c87b03e5Sespie 
924*c87b03e5Sespie   soft_irem_node
925*c87b03e5Sespie     = builtin_function ("_Jv_remI",
926*c87b03e5Sespie 			build_function_type (int_type_node, t),
927*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
928*c87b03e5Sespie 
929*c87b03e5Sespie   soft_ldiv_node
930*c87b03e5Sespie     = builtin_function ("_Jv_divJ",
931*c87b03e5Sespie 			build_function_type (long_type_node, t),
932*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
933*c87b03e5Sespie 
934*c87b03e5Sespie   soft_lrem_node
935*c87b03e5Sespie     = builtin_function ("_Jv_remJ",
936*c87b03e5Sespie 			build_function_type (long_type_node, t),
937*c87b03e5Sespie 			0, NOT_BUILT_IN, NULL, NULL_TREE);
938*c87b03e5Sespie 
939*c87b03e5Sespie   /* Initialize variables for except.c.  */
940*c87b03e5Sespie   eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
941*c87b03e5Sespie                                              ? "__gcj_personality_sj0"
942*c87b03e5Sespie                                              : "__gcj_personality_v0");
943*c87b03e5Sespie   lang_eh_runtime_type = prepare_eh_table_type;
944*c87b03e5Sespie 
945*c87b03e5Sespie   init_jcf_parse ();
946*c87b03e5Sespie 
947*c87b03e5Sespie   initialize_builtins ();
948*c87b03e5Sespie }
949*c87b03e5Sespie 
950*c87b03e5Sespie 
951*c87b03e5Sespie /* Look up NAME in the current binding level and its superiors
952*c87b03e5Sespie    in the namespace of variables, functions and typedefs.
953*c87b03e5Sespie    Return a ..._DECL node of some kind representing its definition,
954*c87b03e5Sespie    or return 0 if it is undefined.  */
955*c87b03e5Sespie 
956*c87b03e5Sespie tree
lookup_name(name)957*c87b03e5Sespie lookup_name (name)
958*c87b03e5Sespie      tree name;
959*c87b03e5Sespie {
960*c87b03e5Sespie   register tree val;
961*c87b03e5Sespie   if (current_binding_level != global_binding_level
962*c87b03e5Sespie       && IDENTIFIER_LOCAL_VALUE (name))
963*c87b03e5Sespie     val = IDENTIFIER_LOCAL_VALUE (name);
964*c87b03e5Sespie   else
965*c87b03e5Sespie     val = IDENTIFIER_GLOBAL_VALUE (name);
966*c87b03e5Sespie   return val;
967*c87b03e5Sespie }
968*c87b03e5Sespie 
969*c87b03e5Sespie /* Similar to `lookup_name' but look only at current binding level and
970*c87b03e5Sespie    the previous one if its the parameter level.  */
971*c87b03e5Sespie 
972*c87b03e5Sespie static tree
lookup_name_current_level(name)973*c87b03e5Sespie lookup_name_current_level (name)
974*c87b03e5Sespie      tree name;
975*c87b03e5Sespie {
976*c87b03e5Sespie   register tree t;
977*c87b03e5Sespie 
978*c87b03e5Sespie   if (current_binding_level == global_binding_level)
979*c87b03e5Sespie     return IDENTIFIER_GLOBAL_VALUE (name);
980*c87b03e5Sespie 
981*c87b03e5Sespie   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
982*c87b03e5Sespie     return 0;
983*c87b03e5Sespie 
984*c87b03e5Sespie   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
985*c87b03e5Sespie     if (DECL_NAME (t) == name)
986*c87b03e5Sespie       break;
987*c87b03e5Sespie 
988*c87b03e5Sespie   return t;
989*c87b03e5Sespie }
990*c87b03e5Sespie 
991*c87b03e5Sespie /* Use a binding level to record a labeled block declaration */
992*c87b03e5Sespie 
993*c87b03e5Sespie void
push_labeled_block(lb)994*c87b03e5Sespie push_labeled_block (lb)
995*c87b03e5Sespie     tree lb;
996*c87b03e5Sespie {
997*c87b03e5Sespie   register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
998*c87b03e5Sespie   register struct binding_level *b = current_binding_level;
999*c87b03e5Sespie   tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1000*c87b03e5Sespie   if (oldlocal != 0)
1001*c87b03e5Sespie       b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1002*c87b03e5Sespie   TREE_CHAIN (lb) = b->names;
1003*c87b03e5Sespie   b->names = lb;
1004*c87b03e5Sespie   IDENTIFIER_LOCAL_VALUE (name) = lb;
1005*c87b03e5Sespie }
1006*c87b03e5Sespie 
1007*c87b03e5Sespie /* Pop the current binding level, reinstalling values for the previous
1008*c87b03e5Sespie    labeled block */
1009*c87b03e5Sespie 
1010*c87b03e5Sespie void
pop_labeled_block()1011*c87b03e5Sespie pop_labeled_block ()
1012*c87b03e5Sespie {
1013*c87b03e5Sespie   struct binding_level *b = current_binding_level;
1014*c87b03e5Sespie   tree label =  b->names;
1015*c87b03e5Sespie   IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
1016*c87b03e5Sespie     NULL_TREE;
1017*c87b03e5Sespie   if (b->shadowed)
1018*c87b03e5Sespie     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
1019*c87b03e5Sespie       TREE_VALUE (b->shadowed);
1020*c87b03e5Sespie 
1021*c87b03e5Sespie   /* Pop the current level, and free the structure for reuse.  */
1022*c87b03e5Sespie   current_binding_level = current_binding_level->level_chain;
1023*c87b03e5Sespie   b->level_chain = free_binding_level;
1024*c87b03e5Sespie   free_binding_level = b;
1025*c87b03e5Sespie }
1026*c87b03e5Sespie 
1027*c87b03e5Sespie /* Record a decl-node X as belonging to the current lexical scope.
1028*c87b03e5Sespie    Check for errors (such as an incompatible declaration for the same
1029*c87b03e5Sespie    name already seen in the same scope).
1030*c87b03e5Sespie 
1031*c87b03e5Sespie    Returns either X or an old decl for the same name.
1032*c87b03e5Sespie    If an old decl is returned, it may have been smashed
1033*c87b03e5Sespie    to agree with what X says.  */
1034*c87b03e5Sespie 
1035*c87b03e5Sespie tree
pushdecl(x)1036*c87b03e5Sespie pushdecl (x)
1037*c87b03e5Sespie      tree x;
1038*c87b03e5Sespie {
1039*c87b03e5Sespie   register tree t;
1040*c87b03e5Sespie   register tree name = DECL_NAME (x);
1041*c87b03e5Sespie   register struct binding_level *b = current_binding_level;
1042*c87b03e5Sespie 
1043*c87b03e5Sespie   if (TREE_CODE (x) != TYPE_DECL)
1044*c87b03e5Sespie     DECL_CONTEXT (x) = current_function_decl;
1045*c87b03e5Sespie   if (name)
1046*c87b03e5Sespie     {
1047*c87b03e5Sespie       const char *file;
1048*c87b03e5Sespie       int line;
1049*c87b03e5Sespie 
1050*c87b03e5Sespie       t = lookup_name_current_level (name);
1051*c87b03e5Sespie       if (t != 0 && t == error_mark_node)
1052*c87b03e5Sespie 	/* error_mark_node is 0 for a while during initialization!  */
1053*c87b03e5Sespie 	{
1054*c87b03e5Sespie 	  t = 0;
1055*c87b03e5Sespie 	  error_with_decl (x, "`%s' used prior to declaration");
1056*c87b03e5Sespie 	}
1057*c87b03e5Sespie 
1058*c87b03e5Sespie       if (t != 0)
1059*c87b03e5Sespie 	{
1060*c87b03e5Sespie 	  file = DECL_SOURCE_FILE (t);
1061*c87b03e5Sespie 	  line = DECL_SOURCE_LINE (t);
1062*c87b03e5Sespie 	}
1063*c87b03e5Sespie 
1064*c87b03e5Sespie       /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1065*c87b03e5Sespie 	 to point to the TYPE_DECL.
1066*c87b03e5Sespie 	 Since Java does not have typedefs, a type can only have
1067*c87b03e5Sespie 	 one (true) name, given by a class, interface, or builtin. */
1068*c87b03e5Sespie       if (TREE_CODE (x) == TYPE_DECL
1069*c87b03e5Sespie 	  && TYPE_NAME (TREE_TYPE (x)) == 0
1070*c87b03e5Sespie 	  && TREE_TYPE (x) != error_mark_node)
1071*c87b03e5Sespie 	{
1072*c87b03e5Sespie 	  TYPE_NAME (TREE_TYPE (x)) = x;
1073*c87b03e5Sespie 	  TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1074*c87b03e5Sespie 	}
1075*c87b03e5Sespie 
1076*c87b03e5Sespie       /* This name is new in its binding level.
1077*c87b03e5Sespie 	 Install the new declaration and return it.  */
1078*c87b03e5Sespie       if (b == global_binding_level)
1079*c87b03e5Sespie 	{
1080*c87b03e5Sespie 	  /* Install a global value.  */
1081*c87b03e5Sespie 
1082*c87b03e5Sespie 	  IDENTIFIER_GLOBAL_VALUE (name) = x;
1083*c87b03e5Sespie 	}
1084*c87b03e5Sespie       else
1085*c87b03e5Sespie 	{
1086*c87b03e5Sespie 	  /* Here to install a non-global value.  */
1087*c87b03e5Sespie 	  tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1088*c87b03e5Sespie 	  IDENTIFIER_LOCAL_VALUE (name) = x;
1089*c87b03e5Sespie 
1090*c87b03e5Sespie #if 0
1091*c87b03e5Sespie 	  /* Warn if shadowing an argument at the top level of the body.  */
1092*c87b03e5Sespie 	  if (oldlocal != 0 && !DECL_EXTERNAL (x)
1093*c87b03e5Sespie 	      /* This warning doesn't apply to the parms of a nested fcn.  */
1094*c87b03e5Sespie 	      && ! current_binding_level->parm_flag
1095*c87b03e5Sespie 	      /* Check that this is one level down from the parms.  */
1096*c87b03e5Sespie 	      && current_binding_level->level_chain->parm_flag
1097*c87b03e5Sespie 	      /* Check that the decl being shadowed
1098*c87b03e5Sespie 		 comes from the parm level, one level up.  */
1099*c87b03e5Sespie 	      && chain_member (oldlocal, current_binding_level->level_chain->names))
1100*c87b03e5Sespie 	    {
1101*c87b03e5Sespie 	      if (TREE_CODE (oldlocal) == PARM_DECL)
1102*c87b03e5Sespie 		pedwarn ("declaration of `%s' shadows a parameter",
1103*c87b03e5Sespie 			 IDENTIFIER_POINTER (name));
1104*c87b03e5Sespie 	      else
1105*c87b03e5Sespie 		pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1106*c87b03e5Sespie 			 IDENTIFIER_POINTER (name));
1107*c87b03e5Sespie 	    }
1108*c87b03e5Sespie 
1109*c87b03e5Sespie 	  /* Maybe warn if shadowing something else.  */
1110*c87b03e5Sespie 	  else if (warn_shadow && !DECL_EXTERNAL (x)
1111*c87b03e5Sespie 		   /* No shadow warnings for internally generated vars.  */
1112*c87b03e5Sespie 		   && DECL_SOURCE_LINE (x) != 0
1113*c87b03e5Sespie 		   /* No shadow warnings for vars made for inlining.  */
1114*c87b03e5Sespie 		   && ! DECL_FROM_INLINE (x))
1115*c87b03e5Sespie 	    {
1116*c87b03e5Sespie 	      const char *warnstring = 0;
1117*c87b03e5Sespie 
1118*c87b03e5Sespie 	      if (TREE_CODE (x) == PARM_DECL
1119*c87b03e5Sespie 		  && current_binding_level->level_chain->parm_flag)
1120*c87b03e5Sespie 		/* Don't warn about the parm names in function declarator
1121*c87b03e5Sespie 		   within a function declarator.
1122*c87b03e5Sespie 		   It would be nice to avoid warning in any function
1123*c87b03e5Sespie 		   declarator in a declaration, as opposed to a definition,
1124*c87b03e5Sespie 		   but there is no way to tell it's not a definition.  */
1125*c87b03e5Sespie 		;
1126*c87b03e5Sespie 	      else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1127*c87b03e5Sespie 		warnstring = "declaration of `%s' shadows a parameter";
1128*c87b03e5Sespie 	      else if (oldlocal != 0)
1129*c87b03e5Sespie 		warnstring = "declaration of `%s' shadows previous local";
1130*c87b03e5Sespie 	      else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1131*c87b03e5Sespie 		       && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1132*c87b03e5Sespie 		warnstring = "declaration of `%s' shadows global declaration";
1133*c87b03e5Sespie 
1134*c87b03e5Sespie 	      if (warnstring)
1135*c87b03e5Sespie 		warning (warnstring, IDENTIFIER_POINTER (name));
1136*c87b03e5Sespie 	    }
1137*c87b03e5Sespie #endif
1138*c87b03e5Sespie 
1139*c87b03e5Sespie 	  /* If storing a local value, there may already be one (inherited).
1140*c87b03e5Sespie 	     If so, record it for restoration when this binding level ends.  */
1141*c87b03e5Sespie 	  if (oldlocal != 0)
1142*c87b03e5Sespie 	    b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1143*c87b03e5Sespie 	}
1144*c87b03e5Sespie     }
1145*c87b03e5Sespie 
1146*c87b03e5Sespie   /* Put decls on list in reverse order.
1147*c87b03e5Sespie      We will reverse them later if necessary.  */
1148*c87b03e5Sespie   TREE_CHAIN (x) = b->names;
1149*c87b03e5Sespie   b->names = x;
1150*c87b03e5Sespie 
1151*c87b03e5Sespie   return x;
1152*c87b03e5Sespie }
1153*c87b03e5Sespie 
1154*c87b03e5Sespie void
pushdecl_force_head(x)1155*c87b03e5Sespie pushdecl_force_head (x)
1156*c87b03e5Sespie      tree x;
1157*c87b03e5Sespie {
1158*c87b03e5Sespie   current_binding_level->names = x;
1159*c87b03e5Sespie }
1160*c87b03e5Sespie 
1161*c87b03e5Sespie /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate.  */
1162*c87b03e5Sespie 
1163*c87b03e5Sespie tree
pushdecl_top_level(x)1164*c87b03e5Sespie pushdecl_top_level (x)
1165*c87b03e5Sespie      tree x;
1166*c87b03e5Sespie {
1167*c87b03e5Sespie   register tree t;
1168*c87b03e5Sespie   register struct binding_level *b = current_binding_level;
1169*c87b03e5Sespie 
1170*c87b03e5Sespie   current_binding_level = global_binding_level;
1171*c87b03e5Sespie   t = pushdecl (x);
1172*c87b03e5Sespie   current_binding_level = b;
1173*c87b03e5Sespie   return t;
1174*c87b03e5Sespie }
1175*c87b03e5Sespie 
1176*c87b03e5Sespie /* Nonzero if we are currently in the global binding level.  */
1177*c87b03e5Sespie 
1178*c87b03e5Sespie int
global_bindings_p()1179*c87b03e5Sespie global_bindings_p ()
1180*c87b03e5Sespie {
1181*c87b03e5Sespie   return current_binding_level == global_binding_level;
1182*c87b03e5Sespie }
1183*c87b03e5Sespie 
1184*c87b03e5Sespie /* Return the list of declarations of the current level.
1185*c87b03e5Sespie    Note that this list is in reverse order unless/until
1186*c87b03e5Sespie    you nreverse it; and when you do nreverse it, you must
1187*c87b03e5Sespie    store the result back using `storedecls' or you will lose.  */
1188*c87b03e5Sespie 
1189*c87b03e5Sespie tree
getdecls()1190*c87b03e5Sespie getdecls ()
1191*c87b03e5Sespie {
1192*c87b03e5Sespie   return current_binding_level->names;
1193*c87b03e5Sespie }
1194*c87b03e5Sespie 
1195*c87b03e5Sespie /* Create a new `struct binding_level'.  */
1196*c87b03e5Sespie 
1197*c87b03e5Sespie static struct binding_level *
make_binding_level()1198*c87b03e5Sespie make_binding_level ()
1199*c87b03e5Sespie {
1200*c87b03e5Sespie   /* NOSTRICT */
1201*c87b03e5Sespie   return xmalloc (sizeof (struct binding_level));
1202*c87b03e5Sespie }
1203*c87b03e5Sespie 
1204*c87b03e5Sespie void
pushlevel(unused)1205*c87b03e5Sespie pushlevel (unused)
1206*c87b03e5Sespie   int unused ATTRIBUTE_UNUSED;
1207*c87b03e5Sespie {
1208*c87b03e5Sespie   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1209*c87b03e5Sespie 
1210*c87b03e5Sespie #if 0
1211*c87b03e5Sespie   /* If this is the top level of a function,
1212*c87b03e5Sespie      just make sure that NAMED_LABELS is 0.  */
1213*c87b03e5Sespie 
1214*c87b03e5Sespie   if (current_binding_level == global_binding_level)
1215*c87b03e5Sespie     named_labels = 0;
1216*c87b03e5Sespie #endif
1217*c87b03e5Sespie 
1218*c87b03e5Sespie   /* Reuse or create a struct for this binding level.  */
1219*c87b03e5Sespie 
1220*c87b03e5Sespie   if (free_binding_level)
1221*c87b03e5Sespie     {
1222*c87b03e5Sespie       newlevel = free_binding_level;
1223*c87b03e5Sespie       free_binding_level = free_binding_level->level_chain;
1224*c87b03e5Sespie     }
1225*c87b03e5Sespie   else
1226*c87b03e5Sespie     {
1227*c87b03e5Sespie       newlevel = make_binding_level ();
1228*c87b03e5Sespie     }
1229*c87b03e5Sespie 
1230*c87b03e5Sespie   /* Add this level to the front of the chain (stack) of levels that
1231*c87b03e5Sespie      are active.  */
1232*c87b03e5Sespie 
1233*c87b03e5Sespie   *newlevel = clear_binding_level;
1234*c87b03e5Sespie   newlevel->level_chain = current_binding_level;
1235*c87b03e5Sespie   current_binding_level = newlevel;
1236*c87b03e5Sespie #if defined(DEBUG_JAVA_BINDING_LEVELS)
1237*c87b03e5Sespie   newlevel->binding_depth = binding_depth;
1238*c87b03e5Sespie   indent ();
1239*c87b03e5Sespie   fprintf (stderr, "push %s level 0x%08x pc %d\n",
1240*c87b03e5Sespie 	   (is_class_level) ? "class" : "block", newlevel, current_pc);
1241*c87b03e5Sespie   is_class_level = 0;
1242*c87b03e5Sespie   binding_depth++;
1243*c87b03e5Sespie #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1244*c87b03e5Sespie }
1245*c87b03e5Sespie 
1246*c87b03e5Sespie /* Exit a binding level.
1247*c87b03e5Sespie    Pop the level off, and restore the state of the identifier-decl mappings
1248*c87b03e5Sespie    that were in effect when this level was entered.
1249*c87b03e5Sespie 
1250*c87b03e5Sespie    If KEEP is nonzero, this level had explicit declarations, so
1251*c87b03e5Sespie    and create a "block" (a BLOCK node) for the level
1252*c87b03e5Sespie    to record its declarations and subblocks for symbol table output.
1253*c87b03e5Sespie 
1254*c87b03e5Sespie    If FUNCTIONBODY is nonzero, this level is the body of a function,
1255*c87b03e5Sespie    so create a block as if KEEP were set and also clear out all
1256*c87b03e5Sespie    label names.
1257*c87b03e5Sespie 
1258*c87b03e5Sespie    If REVERSE is nonzero, reverse the order of decls before putting
1259*c87b03e5Sespie    them into the BLOCK.  */
1260*c87b03e5Sespie 
1261*c87b03e5Sespie tree
poplevel(keep,reverse,functionbody)1262*c87b03e5Sespie poplevel (keep, reverse, functionbody)
1263*c87b03e5Sespie      int keep;
1264*c87b03e5Sespie      int reverse;
1265*c87b03e5Sespie      int functionbody;
1266*c87b03e5Sespie {
1267*c87b03e5Sespie   register tree link;
1268*c87b03e5Sespie   /* The chain of decls was accumulated in reverse order.
1269*c87b03e5Sespie      Put it into forward order, just for cleanliness.  */
1270*c87b03e5Sespie   tree decls;
1271*c87b03e5Sespie   tree subblocks = current_binding_level->blocks;
1272*c87b03e5Sespie   tree block = 0;
1273*c87b03e5Sespie   tree decl;
1274*c87b03e5Sespie   int block_previously_created;
1275*c87b03e5Sespie 
1276*c87b03e5Sespie #if defined(DEBUG_JAVA_BINDING_LEVELS)
1277*c87b03e5Sespie   binding_depth--;
1278*c87b03e5Sespie   indent ();
1279*c87b03e5Sespie   if (current_binding_level->end_pc != LARGEST_PC)
1280*c87b03e5Sespie     fprintf (stderr, "pop  %s level 0x%08x pc %d (end pc %d)\n",
1281*c87b03e5Sespie 	     (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1282*c87b03e5Sespie 	     current_binding_level->end_pc);
1283*c87b03e5Sespie   else
1284*c87b03e5Sespie     fprintf (stderr, "pop  %s level 0x%08x pc %d\n",
1285*c87b03e5Sespie 	     (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1286*c87b03e5Sespie #if 0
1287*c87b03e5Sespie   if (is_class_level != (current_binding_level == class_binding_level))
1288*c87b03e5Sespie     {
1289*c87b03e5Sespie       indent ();
1290*c87b03e5Sespie       fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1291*c87b03e5Sespie     }
1292*c87b03e5Sespie   is_class_level = 0;
1293*c87b03e5Sespie #endif
1294*c87b03e5Sespie #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1295*c87b03e5Sespie 
1296*c87b03e5Sespie   /* Get the decls in the order they were written.
1297*c87b03e5Sespie      Usually current_binding_level->names is in reverse order.
1298*c87b03e5Sespie      But parameter decls were previously put in forward order.  */
1299*c87b03e5Sespie 
1300*c87b03e5Sespie   if (reverse)
1301*c87b03e5Sespie     current_binding_level->names
1302*c87b03e5Sespie       = decls = nreverse (current_binding_level->names);
1303*c87b03e5Sespie   else
1304*c87b03e5Sespie     decls = current_binding_level->names;
1305*c87b03e5Sespie 
1306*c87b03e5Sespie   /* Output any nested inline functions within this block
1307*c87b03e5Sespie      if they weren't already output.  */
1308*c87b03e5Sespie 
1309*c87b03e5Sespie   for (decl = decls; decl; decl = TREE_CHAIN (decl))
1310*c87b03e5Sespie     if (TREE_CODE (decl) == FUNCTION_DECL
1311*c87b03e5Sespie 	&& ! TREE_ASM_WRITTEN (decl)
1312*c87b03e5Sespie 	&& DECL_INITIAL (decl) != 0
1313*c87b03e5Sespie 	&& TREE_ADDRESSABLE (decl))
1314*c87b03e5Sespie       {
1315*c87b03e5Sespie 	/* If this decl was copied from a file-scope decl
1316*c87b03e5Sespie 	   on account of a block-scope extern decl,
1317*c87b03e5Sespie 	   propagate TREE_ADDRESSABLE to the file-scope decl.
1318*c87b03e5Sespie 
1319*c87b03e5Sespie 	   DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1320*c87b03e5Sespie 	   true, since then the decl goes through save_for_inline_copying.  */
1321*c87b03e5Sespie 	if (DECL_ABSTRACT_ORIGIN (decl) != 0
1322*c87b03e5Sespie 	    && DECL_ABSTRACT_ORIGIN (decl) != decl)
1323*c87b03e5Sespie 	  TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1324*c87b03e5Sespie 	else
1325*c87b03e5Sespie 	  {
1326*c87b03e5Sespie 	    push_function_context ();
1327*c87b03e5Sespie 	    output_inline_function (decl);
1328*c87b03e5Sespie 	    pop_function_context ();
1329*c87b03e5Sespie 	  }
1330*c87b03e5Sespie       }
1331*c87b03e5Sespie 
1332*c87b03e5Sespie   /* If there were any declarations in that level,
1333*c87b03e5Sespie      or if this level is a function body,
1334*c87b03e5Sespie      create a BLOCK to record them for the life of this function.  */
1335*c87b03e5Sespie 
1336*c87b03e5Sespie   block = 0;
1337*c87b03e5Sespie   block_previously_created = (current_binding_level->this_block != 0);
1338*c87b03e5Sespie   if (block_previously_created)
1339*c87b03e5Sespie     block = current_binding_level->this_block;
1340*c87b03e5Sespie   else if (keep || functionbody)
1341*c87b03e5Sespie     block = make_node (BLOCK);
1342*c87b03e5Sespie   if (block != 0)
1343*c87b03e5Sespie     {
1344*c87b03e5Sespie       BLOCK_VARS (block) = decls;
1345*c87b03e5Sespie       BLOCK_SUBBLOCKS (block) = subblocks;
1346*c87b03e5Sespie     }
1347*c87b03e5Sespie 
1348*c87b03e5Sespie   /* In each subblock, record that this is its superior.  */
1349*c87b03e5Sespie 
1350*c87b03e5Sespie   for (link = subblocks; link; link = TREE_CHAIN (link))
1351*c87b03e5Sespie     BLOCK_SUPERCONTEXT (link) = block;
1352*c87b03e5Sespie 
1353*c87b03e5Sespie   /* Clear out the meanings of the local variables of this level.  */
1354*c87b03e5Sespie 
1355*c87b03e5Sespie   for (link = decls; link; link = TREE_CHAIN (link))
1356*c87b03e5Sespie     {
1357*c87b03e5Sespie       tree name = DECL_NAME (link);
1358*c87b03e5Sespie       if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1359*c87b03e5Sespie 	{
1360*c87b03e5Sespie 	  /* If the ident. was used or addressed via a local extern decl,
1361*c87b03e5Sespie 	     don't forget that fact.  */
1362*c87b03e5Sespie 	  if (DECL_EXTERNAL (link))
1363*c87b03e5Sespie 	    {
1364*c87b03e5Sespie 	      if (TREE_USED (link))
1365*c87b03e5Sespie 		TREE_USED (name) = 1;
1366*c87b03e5Sespie 	      if (TREE_ADDRESSABLE (link))
1367*c87b03e5Sespie 		TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1368*c87b03e5Sespie 	    }
1369*c87b03e5Sespie 	  IDENTIFIER_LOCAL_VALUE (name) = 0;
1370*c87b03e5Sespie 	}
1371*c87b03e5Sespie     }
1372*c87b03e5Sespie 
1373*c87b03e5Sespie   /* Restore all name-meanings of the outer levels
1374*c87b03e5Sespie      that were shadowed by this level.  */
1375*c87b03e5Sespie 
1376*c87b03e5Sespie   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1377*c87b03e5Sespie     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1378*c87b03e5Sespie 
1379*c87b03e5Sespie   /* If the level being exited is the top level of a function,
1380*c87b03e5Sespie      check over all the labels, and clear out the current
1381*c87b03e5Sespie      (function local) meanings of their names.  */
1382*c87b03e5Sespie 
1383*c87b03e5Sespie   if (functionbody)
1384*c87b03e5Sespie     {
1385*c87b03e5Sespie       /* If this is the top level block of a function,
1386*c87b03e5Sespie 	 the vars are the function's parameters.
1387*c87b03e5Sespie 	 Don't leave them in the BLOCK because they are
1388*c87b03e5Sespie 	 found in the FUNCTION_DECL instead.  */
1389*c87b03e5Sespie 
1390*c87b03e5Sespie       BLOCK_VARS (block) = 0;
1391*c87b03e5Sespie 
1392*c87b03e5Sespie       /* Clear out the definitions of all label names,
1393*c87b03e5Sespie 	 since their scopes end here,
1394*c87b03e5Sespie 	 and add them to BLOCK_VARS.  */
1395*c87b03e5Sespie 
1396*c87b03e5Sespie #if 0
1397*c87b03e5Sespie       for (link = named_labels; link; link = TREE_CHAIN (link))
1398*c87b03e5Sespie 	{
1399*c87b03e5Sespie 	  register tree label = TREE_VALUE (link);
1400*c87b03e5Sespie 
1401*c87b03e5Sespie 	  if (DECL_INITIAL (label) == 0)
1402*c87b03e5Sespie 	    {
1403*c87b03e5Sespie 	      error_with_decl (label, "label `%s' used but not defined");
1404*c87b03e5Sespie 	      /* Avoid crashing later.  */
1405*c87b03e5Sespie 	      define_label (input_filename, lineno,
1406*c87b03e5Sespie 			    DECL_NAME (label));
1407*c87b03e5Sespie 	    }
1408*c87b03e5Sespie 	  else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
1409*c87b03e5Sespie 	    warning_with_decl (label, "label `%s' defined but not used");
1410*c87b03e5Sespie 	  IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1411*c87b03e5Sespie 
1412*c87b03e5Sespie 	  /* Put the labels into the "variables" of the
1413*c87b03e5Sespie 	     top-level block, so debugger can see them.  */
1414*c87b03e5Sespie 	  TREE_CHAIN (label) = BLOCK_VARS (block);
1415*c87b03e5Sespie 	  BLOCK_VARS (block) = label;
1416*c87b03e5Sespie 	}
1417*c87b03e5Sespie #endif
1418*c87b03e5Sespie     }
1419*c87b03e5Sespie 
1420*c87b03e5Sespie   /* Pop the current level, and free the structure for reuse.  */
1421*c87b03e5Sespie 
1422*c87b03e5Sespie   {
1423*c87b03e5Sespie     register struct binding_level *level = current_binding_level;
1424*c87b03e5Sespie     current_binding_level = current_binding_level->level_chain;
1425*c87b03e5Sespie 
1426*c87b03e5Sespie     level->level_chain = free_binding_level;
1427*c87b03e5Sespie     free_binding_level = level;
1428*c87b03e5Sespie   }
1429*c87b03e5Sespie 
1430*c87b03e5Sespie   /* Dispose of the block that we just made inside some higher level.  */
1431*c87b03e5Sespie   if (functionbody)
1432*c87b03e5Sespie     DECL_INITIAL (current_function_decl) = block;
1433*c87b03e5Sespie   else if (block)
1434*c87b03e5Sespie     {
1435*c87b03e5Sespie       if (!block_previously_created)
1436*c87b03e5Sespie         current_binding_level->blocks
1437*c87b03e5Sespie           = chainon (current_binding_level->blocks, block);
1438*c87b03e5Sespie     }
1439*c87b03e5Sespie   /* If we did not make a block for the level just exited,
1440*c87b03e5Sespie      any blocks made for inner levels
1441*c87b03e5Sespie      (since they cannot be recorded as subblocks in that level)
1442*c87b03e5Sespie      must be carried forward so they will later become subblocks
1443*c87b03e5Sespie      of something else.  */
1444*c87b03e5Sespie   else if (subblocks)
1445*c87b03e5Sespie     current_binding_level->blocks
1446*c87b03e5Sespie       = chainon (current_binding_level->blocks, subblocks);
1447*c87b03e5Sespie 
1448*c87b03e5Sespie   /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1449*c87b03e5Sespie      binding contour so that they point to the appropriate construct, i.e.
1450*c87b03e5Sespie      either to the current FUNCTION_DECL node, or else to the BLOCK node
1451*c87b03e5Sespie      we just constructed.
1452*c87b03e5Sespie 
1453*c87b03e5Sespie      Note that for tagged types whose scope is just the formal parameter
1454*c87b03e5Sespie      list for some function type specification, we can't properly set
1455*c87b03e5Sespie      their TYPE_CONTEXTs here, because we don't have a pointer to the
1456*c87b03e5Sespie      appropriate FUNCTION_TYPE node readily available to us.  For those
1457*c87b03e5Sespie      cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1458*c87b03e5Sespie      in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1459*c87b03e5Sespie      node which will represent the "scope" for these "parameter list local"
1460*c87b03e5Sespie      tagged types.
1461*c87b03e5Sespie   */
1462*c87b03e5Sespie 
1463*c87b03e5Sespie   if (block)
1464*c87b03e5Sespie     TREE_USED (block) = 1;
1465*c87b03e5Sespie   return block;
1466*c87b03e5Sespie }
1467*c87b03e5Sespie 
1468*c87b03e5Sespie void
maybe_pushlevels(pc)1469*c87b03e5Sespie maybe_pushlevels (pc)
1470*c87b03e5Sespie      int pc;
1471*c87b03e5Sespie {
1472*c87b03e5Sespie #if defined(DEBUG_JAVA_BINDING_LEVELS)
1473*c87b03e5Sespie   current_pc = pc;
1474*c87b03e5Sespie #endif
1475*c87b03e5Sespie 
1476*c87b03e5Sespie   while (pending_local_decls != NULL_TREE &&
1477*c87b03e5Sespie 	 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1478*c87b03e5Sespie     {
1479*c87b03e5Sespie       tree *ptr = &pending_local_decls;
1480*c87b03e5Sespie       tree decl = *ptr;
1481*c87b03e5Sespie       int end_pc = DECL_LOCAL_END_PC (decl);
1482*c87b03e5Sespie 
1483*c87b03e5Sespie       while (*ptr != NULL_TREE
1484*c87b03e5Sespie 	     && DECL_LOCAL_START_PC (*ptr) <= pc
1485*c87b03e5Sespie 	     && DECL_LOCAL_END_PC (*ptr) == end_pc)
1486*c87b03e5Sespie 	ptr = &TREE_CHAIN (*ptr);
1487*c87b03e5Sespie       pending_local_decls = *ptr;
1488*c87b03e5Sespie       *ptr = NULL_TREE;
1489*c87b03e5Sespie 
1490*c87b03e5Sespie       /* Force non-nested range to be nested in current range. */
1491*c87b03e5Sespie       if (end_pc > current_binding_level->end_pc)
1492*c87b03e5Sespie 	end_pc = current_binding_level->end_pc;
1493*c87b03e5Sespie 
1494*c87b03e5Sespie       maybe_start_try (pc, end_pc);
1495*c87b03e5Sespie 
1496*c87b03e5Sespie       pushlevel (1);
1497*c87b03e5Sespie       expand_start_bindings (0);
1498*c87b03e5Sespie 
1499*c87b03e5Sespie       current_binding_level->end_pc = end_pc;
1500*c87b03e5Sespie       current_binding_level->start_pc = pc;
1501*c87b03e5Sespie       current_binding_level->names = decl;
1502*c87b03e5Sespie       for ( ; decl != NULL_TREE;  decl = TREE_CHAIN (decl))
1503*c87b03e5Sespie 	{
1504*c87b03e5Sespie 	  push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1505*c87b03e5Sespie 	}
1506*c87b03e5Sespie     }
1507*c87b03e5Sespie 
1508*c87b03e5Sespie   maybe_start_try (pc, 0);
1509*c87b03e5Sespie }
1510*c87b03e5Sespie 
1511*c87b03e5Sespie void
maybe_poplevels(pc)1512*c87b03e5Sespie maybe_poplevels (pc)
1513*c87b03e5Sespie      int pc;
1514*c87b03e5Sespie {
1515*c87b03e5Sespie #if defined(DEBUG_JAVA_BINDING_LEVELS)
1516*c87b03e5Sespie   current_pc = pc;
1517*c87b03e5Sespie #endif
1518*c87b03e5Sespie 
1519*c87b03e5Sespie   while (current_binding_level->end_pc <= pc)
1520*c87b03e5Sespie     {
1521*c87b03e5Sespie       expand_end_bindings (getdecls (), 1, 0);
1522*c87b03e5Sespie       maybe_end_try (current_binding_level->start_pc, pc);
1523*c87b03e5Sespie       poplevel (1, 0, 0);
1524*c87b03e5Sespie     }
1525*c87b03e5Sespie   maybe_end_try (0, pc);
1526*c87b03e5Sespie }
1527*c87b03e5Sespie 
1528*c87b03e5Sespie /* Terminate any binding which began during the range beginning at
1529*c87b03e5Sespie    start_pc.  This tidies up improperly nested local variable ranges
1530*c87b03e5Sespie    and exception handlers; a variable declared within an exception
1531*c87b03e5Sespie    range is forcibly terminated when that exception ends. */
1532*c87b03e5Sespie 
1533*c87b03e5Sespie void
force_poplevels(start_pc)1534*c87b03e5Sespie force_poplevels (start_pc)
1535*c87b03e5Sespie      int start_pc;
1536*c87b03e5Sespie {
1537*c87b03e5Sespie   while (current_binding_level->start_pc > start_pc)
1538*c87b03e5Sespie     {
1539*c87b03e5Sespie       if (pedantic && current_binding_level->start_pc > start_pc)
1540*c87b03e5Sespie 	warning_with_decl (current_function_decl,
1541*c87b03e5Sespie 			   "In %s: overlapped variable and exception ranges at %d",
1542*c87b03e5Sespie 			   current_binding_level->start_pc);
1543*c87b03e5Sespie       expand_end_bindings (getdecls (), 1, 0);
1544*c87b03e5Sespie       poplevel (1, 0, 0);
1545*c87b03e5Sespie     }
1546*c87b03e5Sespie }
1547*c87b03e5Sespie 
1548*c87b03e5Sespie /* Insert BLOCK at the end of the list of subblocks of the
1549*c87b03e5Sespie    current binding level.  This is used when a BIND_EXPR is expanded,
1550*c87b03e5Sespie    to handle the BLOCK node inside the BIND_EXPR.  */
1551*c87b03e5Sespie 
1552*c87b03e5Sespie void
insert_block(block)1553*c87b03e5Sespie insert_block (block)
1554*c87b03e5Sespie      tree block;
1555*c87b03e5Sespie {
1556*c87b03e5Sespie   TREE_USED (block) = 1;
1557*c87b03e5Sespie   current_binding_level->blocks
1558*c87b03e5Sespie     = chainon (current_binding_level->blocks, block);
1559*c87b03e5Sespie }
1560*c87b03e5Sespie 
1561*c87b03e5Sespie /* Set the BLOCK node for the innermost scope
1562*c87b03e5Sespie    (the one we are currently in).  */
1563*c87b03e5Sespie 
1564*c87b03e5Sespie void
set_block(block)1565*c87b03e5Sespie set_block (block)
1566*c87b03e5Sespie      register tree block;
1567*c87b03e5Sespie {
1568*c87b03e5Sespie   current_binding_level->this_block = block;
1569*c87b03e5Sespie   current_binding_level->names = chainon (current_binding_level->names,
1570*c87b03e5Sespie 					  BLOCK_VARS (block));
1571*c87b03e5Sespie   current_binding_level->blocks = chainon (current_binding_level->blocks,
1572*c87b03e5Sespie 					   BLOCK_SUBBLOCKS (block));
1573*c87b03e5Sespie }
1574*c87b03e5Sespie 
1575*c87b03e5Sespie /* integrate_decl_tree calls this function. */
1576*c87b03e5Sespie 
1577*c87b03e5Sespie void
java_dup_lang_specific_decl(node)1578*c87b03e5Sespie java_dup_lang_specific_decl (node)
1579*c87b03e5Sespie      tree node;
1580*c87b03e5Sespie {
1581*c87b03e5Sespie   int lang_decl_size;
1582*c87b03e5Sespie   struct lang_decl *x;
1583*c87b03e5Sespie 
1584*c87b03e5Sespie   if (!DECL_LANG_SPECIFIC (node))
1585*c87b03e5Sespie     return;
1586*c87b03e5Sespie 
1587*c87b03e5Sespie   lang_decl_size = sizeof (struct lang_decl);
1588*c87b03e5Sespie   x = (struct lang_decl *) ggc_alloc (lang_decl_size);
1589*c87b03e5Sespie   memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1590*c87b03e5Sespie   DECL_LANG_SPECIFIC (node) = x;
1591*c87b03e5Sespie }
1592*c87b03e5Sespie 
1593*c87b03e5Sespie void
give_name_to_locals(jcf)1594*c87b03e5Sespie give_name_to_locals (jcf)
1595*c87b03e5Sespie      JCF *jcf;
1596*c87b03e5Sespie {
1597*c87b03e5Sespie   int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1598*c87b03e5Sespie   int code_offset = DECL_CODE_OFFSET (current_function_decl);
1599*c87b03e5Sespie   tree parm;
1600*c87b03e5Sespie   pending_local_decls = NULL_TREE;
1601*c87b03e5Sespie   if (n == 0)
1602*c87b03e5Sespie     return;
1603*c87b03e5Sespie   JCF_SEEK (jcf, n);
1604*c87b03e5Sespie   n = JCF_readu2 (jcf);
1605*c87b03e5Sespie   for (i = 0; i < n; i++)
1606*c87b03e5Sespie     {
1607*c87b03e5Sespie       int start_pc = JCF_readu2 (jcf);
1608*c87b03e5Sespie       int length = JCF_readu2 (jcf);
1609*c87b03e5Sespie       int name_index = JCF_readu2 (jcf);
1610*c87b03e5Sespie       int signature_index = JCF_readu2 (jcf);
1611*c87b03e5Sespie       int slot = JCF_readu2 (jcf);
1612*c87b03e5Sespie       tree name = get_name_constant (jcf, name_index);
1613*c87b03e5Sespie       tree type = parse_signature (jcf, signature_index);
1614*c87b03e5Sespie       if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1615*c87b03e5Sespie 	  && start_pc == 0
1616*c87b03e5Sespie 	  && length == DECL_CODE_LENGTH (current_function_decl))
1617*c87b03e5Sespie 	{
1618*c87b03e5Sespie 	  tree decl = TREE_VEC_ELT (decl_map, slot);
1619*c87b03e5Sespie 	  DECL_NAME (decl) = name;
1620*c87b03e5Sespie 	  SET_DECL_ASSEMBLER_NAME (decl, name);
1621*c87b03e5Sespie 	  if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1622*c87b03e5Sespie 	    warning ("bad type in parameter debug info");
1623*c87b03e5Sespie 	}
1624*c87b03e5Sespie       else
1625*c87b03e5Sespie 	{
1626*c87b03e5Sespie 	  tree *ptr;
1627*c87b03e5Sespie 	  int end_pc = start_pc + length;
1628*c87b03e5Sespie 	  tree decl = build_decl (VAR_DECL, name, type);
1629*c87b03e5Sespie 	  if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1630*c87b03e5Sespie 	    {
1631*c87b03e5Sespie 	      warning_with_decl (decl,
1632*c87b03e5Sespie 			 "bad PC range for debug info for local `%s'");
1633*c87b03e5Sespie 	      end_pc = DECL_CODE_LENGTH (current_function_decl);
1634*c87b03e5Sespie 	    }
1635*c87b03e5Sespie 
1636*c87b03e5Sespie 	  /* Adjust start_pc if necessary so that the local's first
1637*c87b03e5Sespie 	     store operation will use the relevant DECL as a
1638*c87b03e5Sespie 	     destination. Fore more information, read the leading
1639*c87b03e5Sespie 	     comments for expr.c:maybe_adjust_start_pc. */
1640*c87b03e5Sespie 	  start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1641*c87b03e5Sespie 
1642*c87b03e5Sespie 	  MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1643*c87b03e5Sespie 	  DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1644*c87b03e5Sespie 	  DECL_LOCAL_START_PC (decl) = start_pc;
1645*c87b03e5Sespie #if 0
1646*c87b03e5Sespie 	  /* FIXME: The range used internally for exceptions and local
1647*c87b03e5Sespie 	     variable ranges, is a half-open interval:
1648*c87b03e5Sespie 	     start_pc <= pc < end_pc.  However, the range used in the
1649*c87b03e5Sespie 	     Java VM spec is inclusive at both ends:
1650*c87b03e5Sespie 	     start_pc <= pc <= end_pc. */
1651*c87b03e5Sespie 	  end_pc++;
1652*c87b03e5Sespie #endif
1653*c87b03e5Sespie 	  DECL_LOCAL_END_PC (decl) = end_pc;
1654*c87b03e5Sespie 
1655*c87b03e5Sespie 	  /* Now insert the new decl in the proper place in
1656*c87b03e5Sespie 	     pending_local_decls.  We are essentially doing an insertion sort,
1657*c87b03e5Sespie 	     which works fine, since the list input will normally already
1658*c87b03e5Sespie 	     be sorted. */
1659*c87b03e5Sespie 	  ptr = &pending_local_decls;
1660*c87b03e5Sespie 	  while (*ptr != NULL_TREE
1661*c87b03e5Sespie 		 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1662*c87b03e5Sespie 		     || (DECL_LOCAL_START_PC (*ptr) == start_pc
1663*c87b03e5Sespie 			 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1664*c87b03e5Sespie 	    ptr = &TREE_CHAIN (*ptr);
1665*c87b03e5Sespie 	  TREE_CHAIN (decl) = *ptr;
1666*c87b03e5Sespie 	  *ptr = decl;
1667*c87b03e5Sespie 	}
1668*c87b03e5Sespie     }
1669*c87b03e5Sespie 
1670*c87b03e5Sespie   pending_local_decls = nreverse (pending_local_decls);
1671*c87b03e5Sespie 
1672*c87b03e5Sespie   /* Fill in default names for the parameters. */
1673*c87b03e5Sespie   for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1674*c87b03e5Sespie        parm != NULL_TREE;  parm = TREE_CHAIN (parm), i++)
1675*c87b03e5Sespie     {
1676*c87b03e5Sespie       if (DECL_NAME (parm) == NULL_TREE)
1677*c87b03e5Sespie 	{
1678*c87b03e5Sespie 	  int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1679*c87b03e5Sespie 	  if (arg_i == 0)
1680*c87b03e5Sespie 	    DECL_NAME (parm) = get_identifier ("this");
1681*c87b03e5Sespie 	  else
1682*c87b03e5Sespie 	    {
1683*c87b03e5Sespie 	      char buffer[12];
1684*c87b03e5Sespie 	      sprintf (buffer, "ARG_%d", arg_i);
1685*c87b03e5Sespie 	      DECL_NAME (parm) = get_identifier (buffer);
1686*c87b03e5Sespie 	    }
1687*c87b03e5Sespie 	  SET_DECL_ASSEMBLER_NAME (parm, DECL_NAME (parm));
1688*c87b03e5Sespie 	}
1689*c87b03e5Sespie     }
1690*c87b03e5Sespie }
1691*c87b03e5Sespie 
1692*c87b03e5Sespie tree
build_result_decl(fndecl)1693*c87b03e5Sespie build_result_decl (fndecl)
1694*c87b03e5Sespie   tree fndecl;
1695*c87b03e5Sespie {
1696*c87b03e5Sespie   tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1697*c87b03e5Sespie   tree result = DECL_RESULT (fndecl);
1698*c87b03e5Sespie   if (! result)
1699*c87b03e5Sespie     {
1700*c87b03e5Sespie       /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1701*c87b03e5Sespie       if (INTEGRAL_TYPE_P (restype)
1702*c87b03e5Sespie 	  && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1703*c87b03e5Sespie 	restype = integer_type_node;
1704*c87b03e5Sespie       result = build_decl (RESULT_DECL, NULL_TREE, restype);
1705*c87b03e5Sespie       DECL_CONTEXT (result) = fndecl;
1706*c87b03e5Sespie       DECL_RESULT (fndecl) = result;
1707*c87b03e5Sespie     }
1708*c87b03e5Sespie   return result;
1709*c87b03e5Sespie }
1710*c87b03e5Sespie 
1711*c87b03e5Sespie void
complete_start_java_method(fndecl)1712*c87b03e5Sespie complete_start_java_method (fndecl)
1713*c87b03e5Sespie   tree fndecl;
1714*c87b03e5Sespie {
1715*c87b03e5Sespie   if (! flag_emit_class_files)
1716*c87b03e5Sespie     {
1717*c87b03e5Sespie       /* Initialize the RTL code for the function.  */
1718*c87b03e5Sespie       init_function_start (fndecl, input_filename, lineno);
1719*c87b03e5Sespie 
1720*c87b03e5Sespie       /* Set up parameters and prepare for return, for the function.  */
1721*c87b03e5Sespie       expand_function_start (fndecl, 0);
1722*c87b03e5Sespie     }
1723*c87b03e5Sespie 
1724*c87b03e5Sespie #if 0
1725*c87b03e5Sespie       /* If this fcn was already referenced via a block-scope `extern' decl (or
1726*c87b03e5Sespie          an implicit decl), propagate certain information about the usage. */
1727*c87b03e5Sespie       if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1728*c87b03e5Sespie         TREE_ADDRESSABLE (current_function_decl) = 1;
1729*c87b03e5Sespie 
1730*c87b03e5Sespie #endif
1731*c87b03e5Sespie 
1732*c87b03e5Sespie   if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1733*c87b03e5Sespie       && ! flag_emit_class_files
1734*c87b03e5Sespie       && ! DECL_CLINIT_P (fndecl)
1735*c87b03e5Sespie       && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1736*c87b03e5Sespie     {
1737*c87b03e5Sespie       tree clas = DECL_CONTEXT (fndecl);
1738*c87b03e5Sespie       tree init = build (CALL_EXPR, void_type_node,
1739*c87b03e5Sespie 			 build_address_of (soft_initclass_node),
1740*c87b03e5Sespie 			 build_tree_list (NULL_TREE, build_class_ref (clas)),
1741*c87b03e5Sespie 			 NULL_TREE);
1742*c87b03e5Sespie       TREE_SIDE_EFFECTS (init) = 1;
1743*c87b03e5Sespie       expand_expr_stmt (init);
1744*c87b03e5Sespie     }
1745*c87b03e5Sespie 
1746*c87b03e5Sespie   /* Push local variables. Function compiled from source code are
1747*c87b03e5Sespie      using a different local variables management, and for them,
1748*c87b03e5Sespie      pushlevel shouldn't be called from here.  */
1749*c87b03e5Sespie   if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1750*c87b03e5Sespie     {
1751*c87b03e5Sespie       pushlevel (2);
1752*c87b03e5Sespie       if (! flag_emit_class_files)
1753*c87b03e5Sespie 	expand_start_bindings (1);
1754*c87b03e5Sespie     }
1755*c87b03e5Sespie 
1756*c87b03e5Sespie   if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1757*c87b03e5Sespie     {
1758*c87b03e5Sespie       /* Wrap function body with a monitorenter plus monitorexit cleanup. */
1759*c87b03e5Sespie       tree enter, exit, lock;
1760*c87b03e5Sespie       if (METHOD_STATIC (fndecl))
1761*c87b03e5Sespie 	lock = build_class_ref (DECL_CONTEXT (fndecl));
1762*c87b03e5Sespie       else
1763*c87b03e5Sespie 	lock = DECL_ARGUMENTS (fndecl);
1764*c87b03e5Sespie       BUILD_MONITOR_ENTER (enter, lock);
1765*c87b03e5Sespie       BUILD_MONITOR_EXIT (exit, lock);
1766*c87b03e5Sespie       if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1767*c87b03e5Sespie 	{
1768*c87b03e5Sespie 	  expand_expr_stmt (enter);
1769*c87b03e5Sespie 	  expand_decl_cleanup (NULL_TREE, exit);
1770*c87b03e5Sespie 	}
1771*c87b03e5Sespie       else
1772*c87b03e5Sespie 	{
1773*c87b03e5Sespie 	  tree function_body = DECL_FUNCTION_BODY (fndecl);
1774*c87b03e5Sespie 	  tree body = BLOCK_EXPR_BODY (function_body);
1775*c87b03e5Sespie 	  lock = build (COMPOUND_EXPR, void_type_node,
1776*c87b03e5Sespie 			enter,
1777*c87b03e5Sespie 			build (TRY_FINALLY_EXPR, void_type_node, body, exit));
1778*c87b03e5Sespie 	  TREE_SIDE_EFFECTS (lock) = 1;
1779*c87b03e5Sespie 	  BLOCK_EXPR_BODY (function_body) = lock;
1780*c87b03e5Sespie 	}
1781*c87b03e5Sespie     }
1782*c87b03e5Sespie }
1783*c87b03e5Sespie 
1784*c87b03e5Sespie void
start_java_method(fndecl)1785*c87b03e5Sespie start_java_method (fndecl)
1786*c87b03e5Sespie      tree fndecl;
1787*c87b03e5Sespie {
1788*c87b03e5Sespie   tree tem, *ptr;
1789*c87b03e5Sespie   int i;
1790*c87b03e5Sespie 
1791*c87b03e5Sespie   current_function_decl = fndecl;
1792*c87b03e5Sespie   announce_function (fndecl);
1793*c87b03e5Sespie 
1794*c87b03e5Sespie   i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1795*c87b03e5Sespie   decl_map = make_tree_vec (i);
1796*c87b03e5Sespie   type_map = xrealloc (type_map, i * sizeof (tree));
1797*c87b03e5Sespie 
1798*c87b03e5Sespie #if defined(DEBUG_JAVA_BINDING_LEVELS)
1799*c87b03e5Sespie   fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1800*c87b03e5Sespie   current_pc = 0;
1801*c87b03e5Sespie #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1802*c87b03e5Sespie   pushlevel (1);  /* Push parameters. */
1803*c87b03e5Sespie 
1804*c87b03e5Sespie   ptr = &DECL_ARGUMENTS (fndecl);
1805*c87b03e5Sespie   for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1806*c87b03e5Sespie        tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1807*c87b03e5Sespie     {
1808*c87b03e5Sespie       tree parm_name = NULL_TREE, parm_decl;
1809*c87b03e5Sespie       tree parm_type = TREE_VALUE (tem);
1810*c87b03e5Sespie       if (i >= DECL_MAX_LOCALS (fndecl))
1811*c87b03e5Sespie 	abort ();
1812*c87b03e5Sespie 
1813*c87b03e5Sespie       parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1814*c87b03e5Sespie       DECL_CONTEXT (parm_decl) = fndecl;
1815*c87b03e5Sespie       if (PROMOTE_PROTOTYPES
1816*c87b03e5Sespie 	  && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1817*c87b03e5Sespie 	  && INTEGRAL_TYPE_P (parm_type))
1818*c87b03e5Sespie 	parm_type = integer_type_node;
1819*c87b03e5Sespie       DECL_ARG_TYPE (parm_decl) = parm_type;
1820*c87b03e5Sespie 
1821*c87b03e5Sespie       *ptr = parm_decl;
1822*c87b03e5Sespie       ptr = &TREE_CHAIN (parm_decl);
1823*c87b03e5Sespie 
1824*c87b03e5Sespie       /* Add parm_decl to the decl_map. */
1825*c87b03e5Sespie       push_jvm_slot (i, parm_decl);
1826*c87b03e5Sespie 
1827*c87b03e5Sespie       type_map[i] = TREE_TYPE (parm_decl);
1828*c87b03e5Sespie       if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1829*c87b03e5Sespie 	{
1830*c87b03e5Sespie 	  i++;
1831*c87b03e5Sespie 	  type_map[i] = void_type_node;
1832*c87b03e5Sespie 	}
1833*c87b03e5Sespie     }
1834*c87b03e5Sespie   *ptr = NULL_TREE;
1835*c87b03e5Sespie   DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1836*c87b03e5Sespie 
1837*c87b03e5Sespie   while (i < DECL_MAX_LOCALS(fndecl))
1838*c87b03e5Sespie     type_map[i++] = NULL_TREE;
1839*c87b03e5Sespie 
1840*c87b03e5Sespie   build_result_decl (fndecl);
1841*c87b03e5Sespie   complete_start_java_method (fndecl);
1842*c87b03e5Sespie }
1843*c87b03e5Sespie 
1844*c87b03e5Sespie void
end_java_method()1845*c87b03e5Sespie end_java_method ()
1846*c87b03e5Sespie {
1847*c87b03e5Sespie   tree fndecl = current_function_decl;
1848*c87b03e5Sespie 
1849*c87b03e5Sespie   expand_end_bindings (getdecls (), 1, 0);
1850*c87b03e5Sespie   /* pop out of function */
1851*c87b03e5Sespie   poplevel (1, 1, 0);
1852*c87b03e5Sespie 
1853*c87b03e5Sespie   /* pop out of its parameters */
1854*c87b03e5Sespie   poplevel (1, 0, 1);
1855*c87b03e5Sespie 
1856*c87b03e5Sespie   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1857*c87b03e5Sespie 
1858*c87b03e5Sespie   /* Generate rtl for function exit.  */
1859*c87b03e5Sespie   expand_function_end (input_filename, lineno, 0);
1860*c87b03e5Sespie 
1861*c87b03e5Sespie   /* Run the optimizers and output assembler code for this function. */
1862*c87b03e5Sespie   rest_of_compilation (fndecl);
1863*c87b03e5Sespie 
1864*c87b03e5Sespie   current_function_decl = NULL_TREE;
1865*c87b03e5Sespie }
1866*c87b03e5Sespie 
1867*c87b03e5Sespie /* Dump FUNCTION_DECL FN as tree dump PHASE. */
1868*c87b03e5Sespie 
1869*c87b03e5Sespie static void
dump_function(phase,fn)1870*c87b03e5Sespie dump_function (phase, fn)
1871*c87b03e5Sespie      enum tree_dump_index phase;
1872*c87b03e5Sespie      tree fn;
1873*c87b03e5Sespie {
1874*c87b03e5Sespie   FILE *stream;
1875*c87b03e5Sespie   int flags;
1876*c87b03e5Sespie 
1877*c87b03e5Sespie   stream = dump_begin (phase, &flags);
1878*c87b03e5Sespie   if (stream)
1879*c87b03e5Sespie     {
1880*c87b03e5Sespie       dump_node (fn, TDF_SLIM | flags, stream);
1881*c87b03e5Sespie       dump_end (phase, stream);
1882*c87b03e5Sespie     }
1883*c87b03e5Sespie }
1884*c87b03e5Sespie 
java_optimize_inline(fndecl)1885*c87b03e5Sespie void java_optimize_inline (fndecl)
1886*c87b03e5Sespie      tree fndecl;
1887*c87b03e5Sespie {
1888*c87b03e5Sespie   if (flag_inline_trees)
1889*c87b03e5Sespie     {
1890*c87b03e5Sespie       timevar_push (TV_INTEGRATION);
1891*c87b03e5Sespie       optimize_inline_calls (fndecl);
1892*c87b03e5Sespie       timevar_pop (TV_INTEGRATION);
1893*c87b03e5Sespie       dump_function (TDI_inlined, fndecl);
1894*c87b03e5Sespie     }
1895*c87b03e5Sespie }
1896*c87b03e5Sespie 
1897*c87b03e5Sespie #include "gt-java-decl.h"
1898