OSDN Git Service

48430ed8acd54360dc72d925110c8aa22a39d989
[pf3gnuchains/gcc-fork.git] / gcc / java / decl.c
1 /* Process declarations and variables for the GNU compiler for the
2    Java(TM) language.
3
4    Copyright (C) 1996, 1998 Free Software Foundation, Inc.
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
22
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc.  */
26
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
28
29 #include "config.h"
30 #include "system.h"
31 #include "tree.h"
32 #include "java-tree.h"
33 #include "jcf.h"
34 #include "toplev.h"
35
36 #ifndef INT_TYPE_SIZE
37 #define INT_TYPE_SIZE BITS_PER_WORD
38 #endif
39
40 /* The DECL_MAP is a mapping from (index, type) to a decl node.
41    If index < max_locals, it is the index of a local variable.
42    if index >= max_locals, then index-max_locals is a stack slot.
43    The DECL_MAP mapping is represented as a TREE_VEC whose elements
44    are a list of decls (VAR_DECL or PARM_DECL) chained by
45    DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
46    we search the chain for a decl with a matching TREE_TYPE. */
47
48 tree decl_map;
49
50 /* A list of local variables VAR_DECLs for this method that we have seen
51    debug information, but we have not reached their starting (byte) PC yet. */
52
53 tree pending_local_decls = NULL_TREE;
54
55 /* Push a local variable or stack slot into the decl_map,
56    and assign it an rtl. */
57
58 tree
59 push_jvm_slot (index, decl)
60      int index;
61      tree decl;
62 {
63   struct rtx_def *rtl = NULL;
64   tree type = TREE_TYPE (decl);
65   tree tmp;
66
67   DECL_CONTEXT (decl) = current_function_decl;
68   layout_decl (decl, 0);
69
70   /* See if we have an appropriate rtl (i.e. same mode) at this index.
71      If so, we must use it. */ 
72   tmp = TREE_VEC_ELT (decl_map, index);
73   while (tmp != NULL_TREE)
74     {
75       if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
76         rtl = DECL_RTL (tmp);
77       if (rtl != NULL)
78         break;
79      tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
80     }
81   if (rtl != NULL)
82     DECL_RTL (decl) = rtl;
83   else
84     {
85       if (index >= DECL_MAX_LOCALS (current_function_decl))
86         DECL_REGISTER (decl) = 1;
87       expand_decl (decl);
88     }
89
90   /* Now link the decl into the decl_map. */
91   if (DECL_LANG_SPECIFIC (decl) == NULL)
92     {
93       DECL_LANG_SPECIFIC (decl)
94         = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
95       DECL_LOCAL_START_PC (decl) = 0;
96       DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
97       DECL_LOCAL_SLOT_NUMBER (decl) = index;
98     }
99   DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
100   TREE_VEC_ELT (decl_map, index) = decl;
101   return decl;
102 }
103
104 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
105    that is valid at PC (or -1 if any pc).
106    If there is no existing matching decl, allocate one.
107    If we find a decl with matching modes but different types,
108    we re-use the rtl, but create a new decl. */
109
110 tree
111 find_local_variable (index, type, pc)
112      int index;
113      tree type;
114      int pc;
115 {
116   tree decl = TREE_VEC_ELT (decl_map, index);
117   tree best = NULL_TREE;
118   while (decl != NULL_TREE)
119     {
120       int in_range;
121       in_range = pc < 0
122         || (pc >= DECL_LOCAL_START_PC (decl)
123             && pc < DECL_LOCAL_END_PC (decl));
124
125       if ((TREE_TYPE (decl) == type
126            || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
127                && type == ptr_type_node))
128            && in_range)
129         {
130           if (best == NULL_TREE
131               || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
132               || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
133               || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
134             best = decl;
135         }
136       decl = DECL_LOCAL_SLOT_CHAIN (decl);
137     }
138   if (best != NULL_TREE)
139     return best;
140   return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
141 }
142
143
144 /* Same as find_local_index, except that INDEX is a stack index. */
145
146 tree
147 find_stack_slot (index, type)
148      int index;
149      tree type;
150 {
151   return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
152                               type, -1);
153 }
154
155 struct binding_level
156   {
157     /* A chain of _DECL nodes for all variables, constants, functions,
158      * and typedef types.  These are in the reverse of the order supplied.
159      */
160     tree names;
161
162     /* For each level, a list of shadowed outer-level local definitions
163        to be restored when this level is popped.
164        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
165        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
166     tree shadowed;
167
168     /* For each level (except not the global one),
169        a chain of BLOCK nodes for all the levels
170        that were entered and exited one level down.  */
171     tree blocks;
172
173     /* The BLOCK node for this level, if one has been preallocated.
174        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
175     tree this_block;
176
177     /* The binding level which this one is contained in (inherits from).  */
178     struct binding_level *level_chain;
179
180     /* 1 means make a BLOCK for this level regardless of all else.
181        2 for temporary binding contours created by the compiler.  */
182     char keep;
183
184     /* Nonzero means make a BLOCK if this level has any subblocks.  */
185     char keep_if_subblocks;
186
187     /* Nonzero if this level can safely have additional
188        cleanup-needing variables added to it.  */
189     char more_cleanups_ok;
190     char have_cleanups;
191
192     /* The bytecode PC that marks the end of this level. */
193     int end_pc;
194   };
195
196 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
197
198 /* The binding level currently in effect.  */
199
200 static struct binding_level *current_binding_level;
201
202 /* A chain of binding_level structures awaiting reuse.  */
203
204 static struct binding_level *free_binding_level;
205
206 /* The outermost binding level, for names of file scope.
207    This is created when the compiler is started and exists
208    through the entire run.  */
209
210 static struct binding_level *global_binding_level;
211
212 /* Binding level structures are initialized by copying this one.  */
213
214 static struct binding_level clear_binding_level
215   = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
216        NULL_BINDING_LEVEL, 0, 0, 0, 0, 1000000000};
217
218 #if 0
219 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
220    that have names.  Here so we can clear out their names' definitions
221    at the end of the function.  */
222
223 static tree named_labels;
224
225 /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
226
227 static tree shadowed_labels;
228 #endif
229
230 int flag_traditional;
231
232 /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
233
234 static int keep_next_level_flag;
235
236 /* Nonzero means make a BLOCK for the next level pushed
237    if it has subblocks.  */
238
239 static int keep_next_if_subblocks;
240   
241 /* The FUNCTION_DECL for the function currently being compiled,
242    or 0 if between functions.  */
243 tree current_function_decl;
244
245 /* The type node for the ordinary character type.  */
246 tree char_type_node;
247
248 tree object_type_node;
249 tree unqualified_object_id_node;
250 tree object_ptr_type_node;
251 tree string_type_node;
252 tree throwable_type_node;
253 tree runtime_exception_type_node;
254 tree error_exception_type_node;
255
256 tree boolean_type_node;
257
258 tree float_type_node;
259 tree double_type_node;
260
261 /* a VOID_TYPE node.  */
262
263 tree void_type_node;
264 tree ptr_type_node;
265 tree return_address_type_node;
266
267 tree integer_type_node;
268
269 tree byte_type_node;
270 tree short_type_node;
271 tree int_type_node;
272 tree long_type_node;
273
274 tree promoted_byte_type_node;
275 tree promoted_short_type_node;
276 tree promoted_char_type_node;
277 tree promoted_boolean_type_node;
278
279 tree unsigned_byte_type_node;
280 tree unsigned_short_type_node;
281 tree unsigned_int_type_node;
282 tree unsigned_long_type_node;
283
284 /* The type for struct methodtable. */
285 tree methodtable_type;
286 tree methodtable_ptr_type;
287
288 tree utf8const_type;
289 tree utf8const_ptr_type;
290 tree class_type_node;
291 tree class_ptr_type;
292 tree field_type_node;
293 tree field_ptr_type_node;
294 tree field_info_union_node;
295 tree jexception_type;
296 tree jexception_ptr_type;
297 tree lineNumberEntry_type;
298 tree lineNumbers_type;
299 tree constants_type_node;
300 tree dtable_type;
301 tree dtable_ptr_type;
302 tree method_type_node;
303 tree method_ptr_type_node;
304 tree nativecode_ptr_array_type_node;
305 tree one_elt_array_domain_type;
306 tree access_flags_type_node;
307 tree class_dtable_decl;
308
309 /* a node which has tree code ERROR_MARK, and whose type is itself.
310    All erroneous expressions are replaced with this node.  All functions
311    that accept nodes as arguments should avoid generating error messages
312    if this node is one of the arguments, since it is undesirable to get
313    multiple error messages from one error in the input.  */
314
315 tree error_mark_node;
316
317 /* Two expressions that are constants with value zero.
318    The first is of type `int', the second of type `void *'.
319    Other of type `long', `float' and `double' follow.  */
320 tree integer_zero_node;
321 tree null_pointer_node;
322 tree long_zero_node;
323 tree float_zero_node;
324 tree double_zero_node;
325
326 tree empty_stmt_node;
327
328 /* Nodes for boolean constants TRUE and FALSE. */
329 tree boolean_true_node, boolean_false_node;
330
331 tree TYPE_identifier_node;
332 tree init_identifier_node;
333 tree clinit_identifier_node;
334 tree finit_identifier_node;
335 tree void_signature_node;
336 tree length_identifier_node;
337 tree this_identifier_node;
338 tree super_identifier_node;
339
340 tree end_params_node;
341
342 /* References to internal libjava functions we use. */
343 tree alloc_object_node;
344 tree soft_instanceof_node;
345 tree soft_checkcast_node;
346 tree soft_initclass_node;
347 tree soft_newarray_node;
348 tree soft_anewarray_node;
349 tree soft_multianewarray_node;
350 tree soft_badarrayindex_node;
351 tree throw_node;
352 tree soft_checkarraystore_node;
353 tree soft_monitorenter_node;
354 tree soft_monitorexit_node;
355 tree soft_lookupinterfacemethod_node;
356 tree soft_fmod_node;
357 tree soft_exceptioninfo_call_node;
358
359 /* Build (and pushdecl) a "promoted type" for all standard
360    types shorter than int.  */
361
362 static tree
363 push_promoted_type (name, actual_type)
364      char *name;
365      tree actual_type;
366 {
367   tree type = make_node (TREE_CODE (actual_type));
368 #if 1
369   tree in_min = TYPE_MIN_VALUE (int_type_node);
370   tree in_max = TYPE_MAX_VALUE (int_type_node);
371 #else
372   tree in_min = TYPE_MIN_VALUE (actual_type);
373   tree in_max = TYPE_MAX_VALUE (actual_type);
374 #endif
375   TYPE_MIN_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_min),
376                                        TREE_INT_CST_HIGH (in_min));
377   TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
378   TYPE_MAX_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_max),
379                                        TREE_INT_CST_HIGH (in_max));
380   TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
381   TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
382   layout_type (type);
383   pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
384   return type;
385 }
386
387 /* Nodes for integer constants.  */
388 tree integer_one_node, integer_two_node, integer_four_node;
389 tree integer_negative_one_node;
390
391 /* Return a definition for a builtin function named NAME and whose data type
392    is TYPE.  TYPE should be a function type with argument types.
393    FUNCTION_CODE tells later passes how to compile calls to this function.
394    See tree.h for its possible values.
395
396    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
397    the name to be called if we can't opencode the function.  */
398
399 tree
400 builtin_function (name, type, function_code, library_name)
401      char *name;
402      tree type;
403      enum built_in_function function_code;
404      char *library_name;
405 {
406   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
407   DECL_EXTERNAL (decl) = 1;
408   TREE_PUBLIC (decl) = 1;
409   if (library_name)
410     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
411   make_decl_rtl (decl, NULL_PTR, 1);
412   pushdecl (decl);
413   if (function_code != NOT_BUILT_IN)
414     {
415       DECL_BUILT_IN (decl) = 1;
416       DECL_FUNCTION_CODE (decl) = function_code;
417     }
418   return decl;
419 }
420
421 void
422 init_decl_processing ()
423 {
424   register tree endlink;
425   tree field;
426   tree t;
427
428   current_function_decl = NULL;
429   current_binding_level = NULL_BINDING_LEVEL;
430   free_binding_level = NULL_BINDING_LEVEL;
431   pushlevel (0);        /* make the binding_level structure for global names */
432   global_binding_level = current_binding_level;
433
434   error_mark_node = make_node (ERROR_MARK);
435   TREE_TYPE (error_mark_node) = error_mark_node;
436
437   /* Create sizetype first - needed for other types. */
438   sizetype = make_unsigned_type (POINTER_SIZE);
439   size_zero_node = build_int_2 (0, 0);
440   TREE_TYPE (size_zero_node) = sizetype;
441   size_one_node = build_int_2 (1, 0);
442   TREE_TYPE (size_one_node) = sizetype;
443
444   byte_type_node = make_signed_type (8);
445   pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
446   short_type_node = make_signed_type (16);
447   pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
448   int_type_node = make_signed_type (32);
449   pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
450   long_type_node = make_signed_type (64);
451   pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
452
453   unsigned_byte_type_node = make_unsigned_type (8);
454   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
455                         unsigned_byte_type_node));
456   unsigned_short_type_node = make_unsigned_type (16);
457   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
458                         unsigned_short_type_node));
459   unsigned_int_type_node = make_unsigned_type (32);
460   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
461                         unsigned_int_type_node));
462   unsigned_long_type_node = make_unsigned_type (64);
463   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
464                         unsigned_long_type_node));
465
466   integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
467
468   integer_zero_node = build_int_2 (0, 0);
469   integer_one_node = build_int_2 (1, 0);
470   integer_two_node = build_int_2 (2, 0);
471   integer_four_node = build_int_2 (4, 0);
472   integer_negative_one_node = build_int_2 (-1, 0);
473
474   long_zero_node = build_int_2 (0, 0);
475   TREE_TYPE (long_zero_node) = long_type_node;
476
477   void_type_node = make_node (VOID_TYPE);
478   pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
479   layout_type (void_type_node); /* Uses size_zero_node */
480   ptr_type_node = build_pointer_type (void_type_node);
481   t = make_node (VOID_TYPE);
482   layout_type (t); /* Uses size_zero_node */
483   return_address_type_node = build_pointer_type (t);
484
485   null_pointer_node = build_int_2 (0, 0);
486   TREE_TYPE (null_pointer_node) = ptr_type_node;
487
488   /* Used by the parser to represent empty statements and blocks. */
489   empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
490   CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
491
492 #if 0
493   /* Make a type to be the domain of a few array types
494      whose domains don't really matter.
495      200 is small enough that it always fits in size_t
496      and large enough that it can hold most function names for the
497      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
498   short_array_type_node = build_prim_array_type (short_type_node, 200);
499 #endif
500   char_type_node = make_node (CHAR_TYPE);
501   TYPE_PRECISION (char_type_node) = 16;
502   fixup_unsigned_type (char_type_node);
503   pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
504
505   boolean_type_node = make_node (BOOLEAN_TYPE);
506   TYPE_PRECISION (boolean_type_node) = 1;
507   fixup_unsigned_type (boolean_type_node);
508   pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
509                         boolean_type_node));
510   boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
511   boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
512
513   promoted_byte_type_node
514     = push_promoted_type ("promoted_byte", byte_type_node);
515   promoted_short_type_node
516     = push_promoted_type ("promoted_short", short_type_node);
517   promoted_char_type_node
518     = push_promoted_type ("promoted_char", char_type_node);
519   promoted_boolean_type_node
520     = push_promoted_type ("promoted_boolean", boolean_type_node);
521
522   float_type_node = make_node (REAL_TYPE);
523   TYPE_PRECISION (float_type_node) = 32;
524   pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
525                         float_type_node));
526   layout_type (float_type_node);
527
528   double_type_node = make_node (REAL_TYPE);
529   TYPE_PRECISION (double_type_node) = 64;
530   pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
531                         double_type_node));
532   layout_type (double_type_node);
533
534   float_zero_node = build_real (float_type_node, dconst0);
535   double_zero_node = build_real (double_type_node, dconst0);
536
537   unqualified_object_id_node = get_identifier ("Object");
538   object_type_node = lookup_class (get_identifier ("java.lang.Object"));
539   object_ptr_type_node = promote_type (object_type_node);
540   string_type_node = lookup_class (get_identifier ("java.lang.String"));
541   class_type_node = lookup_class (get_identifier ("java.lang.Class"));
542   throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
543   runtime_exception_type_node = 
544     lookup_class (get_identifier ("java.lang.RuntimeException"));
545   error_exception_type_node = 
546     lookup_class (get_identifier ("java.lang.Error"));
547
548   methodtable_type = make_node (RECORD_TYPE);
549   layout_type (methodtable_type);
550   build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
551   methodtable_ptr_type = build_pointer_type (methodtable_type);
552
553   TYPE_identifier_node = get_identifier ("TYPE");
554   init_identifier_node = get_identifier ("<init>");
555   clinit_identifier_node = get_identifier ("<clinit>");
556   finit_identifier_node = get_identifier ("$finit$");
557   void_signature_node = get_identifier ("()V");
558   length_identifier_node = get_identifier ("length");
559   this_identifier_node = get_identifier ("this");
560   super_identifier_node = get_identifier ("super");
561
562   /* for lack of a better place to put this stub call */
563   init_expr_processing();
564
565   utf8const_type = make_node (RECORD_TYPE);
566   PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
567   PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
568   FINISH_RECORD (utf8const_type);
569   utf8const_ptr_type = build_pointer_type (utf8const_type);
570
571   constants_type_node = make_node (RECORD_TYPE);
572   PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
573   PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
574   PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
575   FINISH_RECORD (constants_type_node);
576   build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
577
578   access_flags_type_node = unsigned_short_type_node;
579
580   dtable_type = make_node (RECORD_TYPE);
581   dtable_ptr_type = build_pointer_type (dtable_type);
582
583   PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
584   PUSH_FIELD (object_type_node, field, "sync_info", ptr_type_node);
585   for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
586     FIELD_PRIVATE (t) = 1;
587   FINISH_RECORD (object_type_node);
588
589   class_dtable_decl = build_dtable_decl (class_type_node);
590   TREE_STATIC (class_dtable_decl) = 1;
591   DECL_ARTIFICIAL (class_dtable_decl) = 1;
592   DECL_IGNORED_P (class_dtable_decl) = 1;
593   rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
594
595   field_type_node = make_node (RECORD_TYPE);
596   field_ptr_type_node = build_pointer_type (field_type_node);
597   method_type_node = make_node (RECORD_TYPE);
598   method_ptr_type_node = build_pointer_type (method_type_node);
599
600   set_super_info (0, class_type_node, object_type_node, 0);
601   set_super_info (0, string_type_node, object_type_node, 0);
602   class_ptr_type = build_pointer_type (class_type_node);
603
604   PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
605   PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
606   PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
607   PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
608   PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
609   PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
610   PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
611   PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
612   PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
613   PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
614   PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
615   PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
616   PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
617   PUSH_FIELD (class_type_node, field, "interfaces",
618               build_pointer_type (class_ptr_type));
619   PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
620   PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
621   PUSH_FIELD (class_type_node, field, "state", byte_type_node);
622   PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
623   for (t = TYPE_FIELDS (class_type_node);  t != NULL_TREE;  t = TREE_CHAIN (t))
624     FIELD_PRIVATE (t) = 1;
625   push_super_field (class_type_node, object_type_node);
626   FINISH_RECORD (class_type_node);
627   build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
628
629   field_info_union_node = make_node (UNION_TYPE);
630   PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
631   PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
632 #if 0
633   PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
634 #endif
635   layout_type (field_info_union_node);
636
637   PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
638   PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
639   PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
640   PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
641   PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
642   FINISH_RECORD (field_type_node);
643   CLASS_LOADED_P (field_type_node) = 1;
644   build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
645
646   one_elt_array_domain_type = build_index_type (integer_one_node);
647   nativecode_ptr_array_type_node
648     = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
649
650   PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
651   PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
652   FINISH_RECORD (dtable_type);
653   build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
654
655 #define jint_type int_type_node
656 #define jint_ptr_type ptr_type_node
657
658   jexception_type = make_node (RECORD_TYPE);
659   PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
660   PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
661   PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
662   PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
663   FINISH_RECORD (jexception_type);
664   build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
665   jexception_ptr_type = build_pointer_type (jexception_type);
666
667   lineNumberEntry_type = make_node (RECORD_TYPE);
668   PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
669   PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
670   FINISH_RECORD (lineNumberEntry_type);
671
672   lineNumbers_type = make_node (RECORD_TYPE);
673   PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
674   FINISH_RECORD (lineNumbers_type);
675
676 #define instn_ptr_type_node ptr_type_node       /* XXX JH */
677
678 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
679
680   PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
681   PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
682   PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
683   PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
684   FINISH_RECORD (method_type_node);
685   CLASS_LOADED_P (method_type_node) = 1;
686   build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
687
688   endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
689
690   t = tree_cons (NULL_TREE, class_ptr_type,
691                  tree_cons (NULL_TREE, int_type_node, endlink));
692   alloc_object_node = builtin_function ("_Jv_AllocObject",
693                                         build_function_type (ptr_type_node, t),
694                                         NOT_BUILT_IN, NULL_PTR);
695   soft_initclass_node = builtin_function ("_Jv_InitClass",
696                                           build_function_type (void_type_node,
697                                                                t),
698                                           NOT_BUILT_IN, NULL_PTR);
699   t = tree_cons (NULL_TREE, ptr_type_node, endlink);
700   throw_node = builtin_function ("_Jv_Throw",
701                                  build_function_type (ptr_type_node, t),
702                                  NOT_BUILT_IN, NULL_PTR);
703   t = build_function_type (int_type_node, endlink);
704   soft_monitorenter_node 
705       = builtin_function ("_Jv_MonitorEnter", t, NOT_BUILT_IN, NULL_PTR);
706   soft_monitorexit_node 
707       = builtin_function ("_Jv_MonitorExit", t, NOT_BUILT_IN, NULL_PTR);
708   
709   t = tree_cons (NULL_TREE, int_type_node, 
710                  tree_cons (NULL_TREE, int_type_node, endlink));
711   soft_newarray_node
712       = builtin_function ("_Jv_NewArray",
713                           build_function_type(ptr_type_node, t),
714                           NOT_BUILT_IN, NULL_PTR );
715
716   t = tree_cons (NULL_TREE, int_type_node,
717                  tree_cons (NULL_TREE, class_ptr_type,
718                             tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
719   soft_anewarray_node
720       = builtin_function ("_Jv_NewObjectArray",
721                           build_function_type (ptr_type_node, t),
722                           NOT_BUILT_IN, NULL_PTR );
723
724   t = tree_cons (NULL_TREE, ptr_type_node,
725                  tree_cons (NULL_TREE, int_type_node, endlink));
726   soft_multianewarray_node
727       = builtin_function ("_Jv_NewMultiArray",
728                           build_function_type (ptr_type_node, t),
729                           NOT_BUILT_IN, NULL_PTR );
730
731   t = build_function_type (void_type_node, 
732                            tree_cons (NULL_TREE, int_type_node, endlink));
733   soft_badarrayindex_node
734       = builtin_function ("_Jv_ThrowBadArrayIndex", t, 
735                           NOT_BUILT_IN, NULL_PTR);
736   TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
737   TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
738
739   t = tree_cons (NULL_TREE, class_ptr_type,
740                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
741   soft_checkcast_node
742     = builtin_function ("_Jv_CheckCast",
743                         build_function_type (ptr_type_node, t),
744                         NOT_BUILT_IN, NULL_PTR);
745   t = tree_cons (NULL_TREE, object_ptr_type_node,
746                  tree_cons (NULL_TREE, class_ptr_type, endlink));
747   soft_instanceof_node
748     = builtin_function ("_Jv_IsInstanceOf",
749                         build_function_type (promoted_boolean_type_node, t),
750                         NOT_BUILT_IN, NULL_PTR);
751   t = tree_cons (NULL_TREE, object_ptr_type_node,
752                  tree_cons (NULL_TREE, object_ptr_type_node, endlink));
753   soft_checkarraystore_node
754     = builtin_function ("_Jv_CheckArrayStore",
755                         build_function_type (void_type_node, t),
756                         NOT_BUILT_IN, NULL_PTR);
757   t = tree_cons (NULL_TREE, ptr_type_node,
758                  tree_cons (NULL_TREE, ptr_type_node,
759                             tree_cons (NULL_TREE, ptr_type_node, endlink)));
760   soft_lookupinterfacemethod_node 
761     = builtin_function ("_Jv_LookupInterfaceMethod",
762                         build_function_type (ptr_type_node, t),
763                         NOT_BUILT_IN, NULL_PTR);
764   t = tree_cons (NULL_TREE, double_type_node,
765                  tree_cons (NULL_TREE, double_type_node, endlink));
766   soft_fmod_node
767     = builtin_function ("__builtin_fmod",
768                         build_function_type (double_type_node, t),
769                         BUILT_IN_FMOD, "fmod");
770
771   soft_exceptioninfo_call_node
772     = build (CALL_EXPR, 
773              ptr_type_node,
774              build_address_of 
775                (builtin_function ("_Jv_exception_info", 
776                                   build_function_type (ptr_type_node, endlink),
777                                   NOT_BUILT_IN, NULL_PTR)),
778              NULL_TREE, NULL_TREE);
779   TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
780 #if 0
781   t = tree_cons (NULL_TREE, float_type_node,
782                  tree_cons (NULL_TREE, float_type_node, endlink));
783   soft_fmodf_node
784     = builtin_function ("__builtin_fmodf",
785                         build_function_type (float_type_node, t),
786                         BUILT_IN_FMOD, "fmodf");
787 #endif
788     
789   init_class_processing ();
790 }
791
792
793 /* Look up NAME in the current binding level and its superiors
794    in the namespace of variables, functions and typedefs.
795    Return a ..._DECL node of some kind representing its definition,
796    or return 0 if it is undefined.  */
797
798 tree
799 lookup_name (name)
800      tree name;
801 {
802   register tree val;
803   if (current_binding_level != global_binding_level
804       && IDENTIFIER_LOCAL_VALUE (name))
805     val = IDENTIFIER_LOCAL_VALUE (name);
806   else
807     val = IDENTIFIER_GLOBAL_VALUE (name);
808   return val;
809 }
810
811 /* Similar to `lookup_name' but look only at current binding level and
812    the previous one if its the parameter level.  */
813
814 tree
815 lookup_name_current_level (name)
816      tree name;
817 {
818   register tree t;
819
820   if (current_binding_level == global_binding_level)
821     return IDENTIFIER_GLOBAL_VALUE (name);
822
823   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
824     return 0;
825
826   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
827     if (DECL_NAME (t) == name)
828       break;
829
830   return t;
831 }
832
833 /* Use a binding level to record a labeled block declaration */
834
835 void
836 push_labeled_block (lb)
837     tree lb;
838 {
839   register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
840   register struct binding_level *b = current_binding_level;
841   tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
842   if (oldlocal != 0)
843       b->shadowed = tree_cons (name, oldlocal, b->shadowed);
844   TREE_CHAIN (lb) = b->names;
845   b->names = lb;
846   IDENTIFIER_LOCAL_VALUE (name) = lb;
847 }
848
849 /* Pop the current binding level, reinstalling values for the previous
850    labeled block */
851
852 void
853 pop_labeled_block ()
854 {
855   struct binding_level *b = current_binding_level;
856   tree label =  b->names;
857   IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) = 
858     NULL_TREE;
859   if (b->shadowed)
860     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) = 
861       TREE_VALUE (b->shadowed);
862
863   /* Pop the current level, and free the structure for reuse.  */
864   current_binding_level = current_binding_level->level_chain;
865   b->level_chain = free_binding_level;
866   free_binding_level = b;
867 }
868
869 /* Record a decl-node X as belonging to the current lexical scope.
870    Check for errors (such as an incompatible declaration for the same
871    name already seen in the same scope).
872
873    Returns either X or an old decl for the same name.
874    If an old decl is returned, it may have been smashed
875    to agree with what X says.  */
876
877 tree
878 pushdecl (x)
879      tree x;
880 {
881   register tree t;
882   register tree name = DECL_NAME (x);
883   register struct binding_level *b = current_binding_level;
884
885   DECL_CONTEXT (x) = current_function_decl;
886   if (name)
887     {
888       char *file;
889       int line;
890
891       t = lookup_name_current_level (name);
892       if (t != 0 && t == error_mark_node)
893         /* error_mark_node is 0 for a while during initialization!  */
894         {
895           t = 0;
896           error_with_decl (x, "`%s' used prior to declaration");
897         }
898
899       if (t != 0)
900         {
901           file = DECL_SOURCE_FILE (t);
902           line = DECL_SOURCE_LINE (t);
903         }
904
905       /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
906          to point to the TYPE_DECL.
907          Since Java does not have typedefs, a type can only have
908          one (true) name, given by a class, interface, or builtin. */
909       if (TREE_CODE (x) == TYPE_DECL
910           && TYPE_NAME (TREE_TYPE (x)) == 0
911           && TREE_TYPE (x) != error_mark_node)
912         {
913           TYPE_NAME (TREE_TYPE (x)) = x;
914           TYPE_STUB_DECL (TREE_TYPE (x)) = x;
915         }
916
917       /* This name is new in its binding level.
918          Install the new declaration and return it.  */
919       if (b == global_binding_level)
920         {
921           /* Install a global value.  */
922           
923           IDENTIFIER_GLOBAL_VALUE (name) = x;
924         }
925       else
926         {
927           /* Here to install a non-global value.  */
928           tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
929           IDENTIFIER_LOCAL_VALUE (name) = x;
930
931 #if 0
932           /* Warn if shadowing an argument at the top level of the body.  */
933           if (oldlocal != 0 && !DECL_EXTERNAL (x)
934               /* This warning doesn't apply to the parms of a nested fcn.  */
935               && ! current_binding_level->parm_flag
936               /* Check that this is one level down from the parms.  */
937               && current_binding_level->level_chain->parm_flag
938               /* Check that the decl being shadowed
939                  comes from the parm level, one level up.  */
940               && chain_member (oldlocal, current_binding_level->level_chain->names))
941             {
942               if (TREE_CODE (oldlocal) == PARM_DECL)
943                 pedwarn ("declaration of `%s' shadows a parameter",
944                          IDENTIFIER_POINTER (name));
945               else
946                 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
947                          IDENTIFIER_POINTER (name));
948             }
949
950           /* Maybe warn if shadowing something else.  */
951           else if (warn_shadow && !DECL_EXTERNAL (x)
952                    /* No shadow warnings for internally generated vars.  */
953                    && DECL_SOURCE_LINE (x) != 0
954                    /* No shadow warnings for vars made for inlining.  */
955                    && ! DECL_FROM_INLINE (x))
956             {
957               char *warnstring = 0;
958
959               if (TREE_CODE (x) == PARM_DECL
960                   && current_binding_level->level_chain->parm_flag)
961                 /* Don't warn about the parm names in function declarator
962                    within a function declarator.
963                    It would be nice to avoid warning in any function
964                    declarator in a declaration, as opposed to a definition,
965                    but there is no way to tell it's not a definition.  */
966                 ;
967               else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
968                 warnstring = "declaration of `%s' shadows a parameter";
969               else if (oldlocal != 0)
970                 warnstring = "declaration of `%s' shadows previous local";
971               else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
972                        && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
973                 warnstring = "declaration of `%s' shadows global declaration";
974
975               if (warnstring)
976                 warning (warnstring, IDENTIFIER_POINTER (name));
977             }
978 #endif
979
980           /* If storing a local value, there may already be one (inherited).
981              If so, record it for restoration when this binding level ends.  */
982           if (oldlocal != 0)
983             b->shadowed = tree_cons (name, oldlocal, b->shadowed);
984         }
985     }
986
987   /* Put decls on list in reverse order.
988      We will reverse them later if necessary.  */
989   TREE_CHAIN (x) = b->names;
990   b->names = x;
991
992   return x;
993 }
994 void
995 pushdecl_force_head (x)
996      tree x;
997 {
998   current_binding_level->names = x;
999 }
1000
1001 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate.  */
1002
1003 tree
1004 pushdecl_top_level (x)
1005      tree x;
1006 {
1007   register tree t;
1008   register struct binding_level *b = current_binding_level;
1009
1010   current_binding_level = global_binding_level;
1011   t = pushdecl (x);
1012   current_binding_level = b;
1013   return t;
1014 }
1015
1016 /* Nonzero if we are currently in the global binding level.  */
1017
1018 int
1019 global_bindings_p ()
1020 {
1021   return current_binding_level == global_binding_level;
1022 }
1023
1024 /* Return the list of declarations of the current level.
1025    Note that this list is in reverse order unless/until
1026    you nreverse it; and when you do nreverse it, you must
1027    store the result back using `storedecls' or you will lose.  */
1028
1029 tree
1030 getdecls ()
1031 {
1032   return current_binding_level->names;
1033 }
1034
1035 /* Create a new `struct binding_level'.  */
1036
1037 static
1038 struct binding_level *
1039 make_binding_level ()
1040 {
1041   /* NOSTRICT */
1042   return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1043 }
1044
1045 void
1046 pushlevel (unused)
1047   int unused ATTRIBUTE_UNUSED;
1048 {
1049   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1050
1051 #if 0
1052   /* If this is the top level of a function,
1053      just make sure that NAMED_LABELS is 0.  */
1054
1055   if (current_binding_level == global_binding_level)
1056     named_labels = 0;
1057 #endif
1058
1059   /* Reuse or create a struct for this binding level.  */
1060
1061   if (free_binding_level)
1062     {
1063       newlevel = free_binding_level;
1064       free_binding_level = free_binding_level->level_chain;
1065     }
1066   else
1067     {
1068       newlevel = make_binding_level ();
1069     }
1070
1071   /* Add this level to the front of the chain (stack) of levels that
1072      are active.  */
1073
1074   *newlevel = clear_binding_level;
1075   newlevel->level_chain = current_binding_level;
1076   current_binding_level = newlevel;
1077   newlevel->keep = keep_next_level_flag;
1078   keep_next_level_flag = 0;
1079   newlevel->keep_if_subblocks = keep_next_if_subblocks;
1080   keep_next_if_subblocks = 0;
1081 }
1082
1083 /* Exit a binding level.
1084    Pop the level off, and restore the state of the identifier-decl mappings
1085    that were in effect when this level was entered.
1086
1087    If KEEP is nonzero, this level had explicit declarations, so
1088    and create a "block" (a BLOCK node) for the level
1089    to record its declarations and subblocks for symbol table output.
1090
1091    If FUNCTIONBODY is nonzero, this level is the body of a function,
1092    so create a block as if KEEP were set and also clear out all
1093    label names.
1094
1095    If REVERSE is nonzero, reverse the order of decls before putting
1096    them into the BLOCK.  */
1097
1098 tree
1099 poplevel (keep, reverse, functionbody)
1100      int keep;
1101      int reverse;
1102      int functionbody;
1103 {
1104   register tree link;
1105   /* The chain of decls was accumulated in reverse order.
1106      Put it into forward order, just for cleanliness.  */
1107   tree decls;
1108   tree subblocks = current_binding_level->blocks;
1109   tree block = 0;
1110   tree decl;
1111   int block_previously_created;
1112
1113   keep |= current_binding_level->keep;
1114
1115   /* Get the decls in the order they were written.
1116      Usually current_binding_level->names is in reverse order.
1117      But parameter decls were previously put in forward order.  */
1118
1119   if (reverse)
1120     current_binding_level->names
1121       = decls = nreverse (current_binding_level->names);
1122   else
1123     decls = current_binding_level->names;
1124
1125   /* Output any nested inline functions within this block
1126      if they weren't already output.  */
1127
1128   for (decl = decls; decl; decl = TREE_CHAIN (decl))
1129     if (TREE_CODE (decl) == FUNCTION_DECL
1130         && ! TREE_ASM_WRITTEN (decl)
1131         && DECL_INITIAL (decl) != 0
1132         && TREE_ADDRESSABLE (decl))
1133       {
1134         /* If this decl was copied from a file-scope decl
1135            on account of a block-scope extern decl,
1136            propagate TREE_ADDRESSABLE to the file-scope decl.
1137
1138            DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1139            true, since then the decl goes through save_for_inline_copying.  */
1140         if (DECL_ABSTRACT_ORIGIN (decl) != 0
1141             && DECL_ABSTRACT_ORIGIN (decl) != decl)
1142           TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1143         else
1144           {
1145             push_function_context ();
1146             output_inline_function (decl);
1147             pop_function_context ();
1148           }
1149       }
1150
1151   /* If there were any declarations in that level,
1152      or if this level is a function body,
1153      create a BLOCK to record them for the life of this function.  */
1154
1155   block = 0;
1156   block_previously_created = (current_binding_level->this_block != 0);
1157   if (block_previously_created)
1158     block = current_binding_level->this_block;
1159   else if (keep || functionbody
1160            || (current_binding_level->keep_if_subblocks && subblocks != 0))
1161     block = make_node (BLOCK);
1162   if (block != 0)
1163     {
1164       BLOCK_VARS (block) = decls;
1165       BLOCK_TYPE_TAGS (block) = NULL_TREE;
1166       BLOCK_SUBBLOCKS (block) = subblocks;
1167       remember_end_note (block);
1168     }
1169
1170   /* In each subblock, record that this is its superior.  */
1171
1172   for (link = subblocks; link; link = TREE_CHAIN (link))
1173     BLOCK_SUPERCONTEXT (link) = block;
1174
1175   /* Clear out the meanings of the local variables of this level.  */
1176
1177   for (link = decls; link; link = TREE_CHAIN (link))
1178     {
1179       tree name = DECL_NAME (link);
1180       if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1181         {
1182           /* If the ident. was used or addressed via a local extern decl,
1183              don't forget that fact.  */
1184           if (DECL_EXTERNAL (link))
1185             {
1186               if (TREE_USED (link))
1187                 TREE_USED (name) = 1;
1188               if (TREE_ADDRESSABLE (link))
1189                 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1190             }
1191           IDENTIFIER_LOCAL_VALUE (name) = 0;
1192         }
1193     }
1194
1195   /* Restore all name-meanings of the outer levels
1196      that were shadowed by this level.  */
1197
1198   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1199     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1200
1201   /* If the level being exited is the top level of a function,
1202      check over all the labels, and clear out the current
1203      (function local) meanings of their names.  */
1204
1205   if (functionbody)
1206     {
1207       /* If this is the top level block of a function,
1208          the vars are the function's parameters.
1209          Don't leave them in the BLOCK because they are
1210          found in the FUNCTION_DECL instead.  */
1211
1212       BLOCK_VARS (block) = 0;
1213
1214       /* Clear out the definitions of all label names,
1215          since their scopes end here,
1216          and add them to BLOCK_VARS.  */
1217
1218 #if 0
1219       for (link = named_labels; link; link = TREE_CHAIN (link))
1220         {
1221           register tree label = TREE_VALUE (link);
1222
1223           if (DECL_INITIAL (label) == 0)
1224             {
1225               error_with_decl (label, "label `%s' used but not defined");
1226               /* Avoid crashing later.  */
1227               define_label (input_filename, lineno,
1228                             DECL_NAME (label));
1229             }
1230           else if (warn_unused && !TREE_USED (label))
1231             warning_with_decl (label, "label `%s' defined but not used");
1232           IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1233
1234           /* Put the labels into the "variables" of the
1235              top-level block, so debugger can see them.  */
1236           TREE_CHAIN (label) = BLOCK_VARS (block);
1237           BLOCK_VARS (block) = label;
1238         }
1239 #endif
1240     }
1241
1242   /* Pop the current level, and free the structure for reuse.  */
1243
1244   {
1245     register struct binding_level *level = current_binding_level;
1246     current_binding_level = current_binding_level->level_chain;
1247
1248     level->level_chain = free_binding_level;
1249     free_binding_level = level;
1250   }
1251
1252   /* Dispose of the block that we just made inside some higher level.  */
1253   if (functionbody)
1254     DECL_INITIAL (current_function_decl) = block;
1255   else if (block)
1256     {
1257       if (!block_previously_created)
1258         current_binding_level->blocks
1259           = chainon (current_binding_level->blocks, block);
1260     }
1261   /* If we did not make a block for the level just exited,
1262      any blocks made for inner levels
1263      (since they cannot be recorded as subblocks in that level)
1264      must be carried forward so they will later become subblocks
1265      of something else.  */
1266   else if (subblocks)
1267     current_binding_level->blocks
1268       = chainon (current_binding_level->blocks, subblocks);
1269
1270   /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1271      binding contour so that they point to the appropriate construct, i.e.
1272      either to the current FUNCTION_DECL node, or else to the BLOCK node
1273      we just constructed.
1274
1275      Note that for tagged types whose scope is just the formal parameter
1276      list for some function type specification, we can't properly set
1277      their TYPE_CONTEXTs here, because we don't have a pointer to the
1278      appropriate FUNCTION_TYPE node readily available to us.  For those
1279      cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1280      in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1281      node which will represent the "scope" for these "parameter list local"
1282      tagged types.
1283   */
1284
1285   if (block)
1286     TREE_USED (block) = 1;
1287   return block;
1288 }
1289
1290 void
1291 maybe_pushlevels (pc)
1292      int pc;
1293 {
1294   while (pending_local_decls != NULL_TREE &&
1295          DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1296     {
1297       tree *ptr = &pending_local_decls;
1298       tree decl = *ptr;
1299       int end_pc = DECL_LOCAL_END_PC (decl);
1300
1301       while (*ptr != NULL_TREE
1302              && DECL_LOCAL_START_PC (*ptr) <= pc
1303              && DECL_LOCAL_END_PC (*ptr) == end_pc)
1304         ptr = &TREE_CHAIN (*ptr);
1305       pending_local_decls = *ptr;
1306       *ptr = NULL_TREE;
1307
1308       /* Force non-nested range to be nested in current range. */
1309       if (end_pc > current_binding_level->end_pc)
1310         end_pc = current_binding_level->end_pc;
1311
1312       pushlevel (1);
1313       expand_start_bindings (0);
1314       current_binding_level->end_pc = end_pc;
1315       
1316       current_binding_level->names = decl;
1317       for ( ; decl != NULL_TREE;  decl = TREE_CHAIN (decl))
1318         {
1319           push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1320         }
1321     }
1322 }
1323
1324 void
1325 maybe_poplevels (pc)
1326      int pc;
1327 {
1328   while (current_binding_level->end_pc <= pc)
1329     {
1330       expand_end_bindings (getdecls (), 1, 0);
1331       poplevel (1, 0, 0);
1332     }
1333 }
1334
1335 /* Insert BLOCK at the end of the list of subblocks of the
1336    current binding level.  This is used when a BIND_EXPR is expanded,
1337    to handle the BLOCK node inside the BIND_EXPR.  */
1338
1339 void
1340 insert_block (block)
1341      tree block;
1342 {
1343   TREE_USED (block) = 1;
1344   abort ();
1345   current_binding_level->blocks
1346     = chainon (current_binding_level->blocks, block);
1347 }
1348
1349 /* Set the BLOCK node for the innermost scope
1350    (the one we are currently in).  */
1351
1352 void
1353 set_block (block)
1354      register tree block;
1355 {
1356   current_binding_level->this_block = block;
1357 }
1358
1359 /* integrate_decl_tree calls this function. */
1360
1361 void
1362 copy_lang_decl (node)
1363      tree node;
1364 {
1365   int lang_decl_size
1366     = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1367     : sizeof (struct lang_decl);
1368   struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1369   bcopy (DECL_LANG_SPECIFIC (node), x, lang_decl_size);
1370   DECL_LANG_SPECIFIC (node) = x;
1371 }
1372
1373 /* If DECL has a cleanup, build and return that cleanup here.
1374    This is a callback called by expand_expr.  */
1375
1376 tree
1377 maybe_build_cleanup (decl)
1378   tree decl ATTRIBUTE_UNUSED;
1379 {
1380   /* There are no cleanups in Java (I think).  */
1381   return NULL_TREE;
1382 }
1383
1384 void
1385 give_name_to_locals (jcf)
1386      JCF *jcf;
1387 {
1388   int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1389   tree parm;
1390   pending_local_decls = NULL_TREE;
1391   if (n == 0)
1392     return;
1393   JCF_SEEK (jcf, n);
1394   n = JCF_readu2 (jcf);
1395   for (i = 0; i < n; i++)
1396     {
1397       int start_pc = JCF_readu2 (jcf);
1398       int length = JCF_readu2 (jcf);
1399       int name_index = JCF_readu2 (jcf);
1400       int signature_index = JCF_readu2 (jcf);
1401       int slot = JCF_readu2 (jcf);
1402       tree name = get_name_constant (jcf, name_index);
1403       tree type = parse_signature (jcf, signature_index);
1404       if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1405           && start_pc == 0
1406           && length == DECL_CODE_LENGTH (current_function_decl))
1407         {
1408           tree decl = TREE_VEC_ELT (decl_map, slot);
1409           DECL_NAME (decl) = name;
1410           DECL_ASSEMBLER_NAME (decl) = name;
1411           if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1412             warning ("bad type in parameter debug info");
1413         }
1414       else
1415         {
1416           tree *ptr;
1417           int end_pc = start_pc + length;
1418           tree decl = build_decl (VAR_DECL, name, type);
1419           if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1420             {
1421               warning_with_decl (decl,
1422                          "bad PC range for debug info for local `%s'");
1423               end_pc = DECL_CODE_LENGTH (current_function_decl);
1424             }
1425           DECL_LANG_SPECIFIC (decl)
1426             = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1427           DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1428           DECL_LOCAL_START_PC (decl) = start_pc;
1429           DECL_LOCAL_END_PC (decl) = end_pc;
1430
1431           /* Now insert the new decl in the proper place in
1432              pending_local_decls.  We are essentially doing an insertion sort,
1433              which works fine, since the list input will normally already
1434              be sorted. */
1435           ptr = &pending_local_decls;
1436           while (*ptr != NULL_TREE
1437                  && (DECL_LOCAL_START_PC (*ptr) > start_pc
1438                      || (DECL_LOCAL_START_PC (*ptr) == start_pc
1439                          && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1440             ptr = &TREE_CHAIN (*ptr);
1441           TREE_CHAIN (decl) = *ptr;
1442           *ptr = decl;
1443         }
1444     }
1445
1446   pending_local_decls = nreverse (pending_local_decls);
1447
1448   /* Fill in default names for the parameters. */ 
1449   for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1450        parm != NULL_TREE;  parm = TREE_CHAIN (parm), i++)
1451     {
1452       if (DECL_NAME (parm) == NULL_TREE)
1453         {
1454           int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1455           if (arg_i == 0)
1456             DECL_NAME (parm) = get_identifier ("this");
1457           else
1458             {
1459               char buffer[12];
1460               sprintf (buffer, "ARG_%d", arg_i);
1461               DECL_NAME (parm) = get_identifier (buffer);
1462             }
1463           DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1464         }
1465     }
1466 }
1467
1468 void
1469 complete_start_java_method (fndecl)
1470   tree fndecl;
1471 {
1472   tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1473   /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1474   if (INTEGRAL_TYPE_P (restype)
1475       && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1476     restype = integer_type_node;
1477   DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype);
1478
1479   if (! flag_emit_class_files)
1480     {
1481       /* Initialize the RTL code for the function.  */
1482       init_function_start (fndecl, input_filename, lineno);
1483
1484       /* Set up parameters and prepare for return, for the function.  */
1485       expand_function_start (fndecl, 0);
1486     }
1487
1488   /* Allocate further tree nodes temporarily during compilation
1489      of this function only.  */
1490   temporary_allocation ();
1491
1492 #if 0
1493       /* If this fcn was already referenced via a block-scope `extern' decl (or
1494          an implicit decl), propagate certain information about the usage. */
1495       if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1496         TREE_ADDRESSABLE (current_function_decl) = 1;
1497
1498 #endif
1499
1500   if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1501       && ! flag_emit_class_files)
1502     {
1503       tree clas = DECL_CONTEXT (fndecl);
1504       tree init = build (CALL_EXPR, void_type_node,
1505                          build_address_of (soft_initclass_node),
1506                          build_tree_list (NULL_TREE, build_class_ref (clas)),
1507                          NULL_TREE);
1508       TREE_SIDE_EFFECTS (init) = 1;
1509       expand_expr_stmt (init);
1510     }
1511
1512   if (METHOD_SYNCHRONIZED (fndecl))
1513     {
1514       /* FIXME: surround the function body by a try/finally set.  */
1515     }
1516
1517   /* Push local variables. Function compiled from source code are
1518      using a different local variables management, and for them,
1519      pushlevel shouldn't be called from here.  */
1520   if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1521     {
1522       pushlevel (2);
1523       if (! flag_emit_class_files)
1524         expand_start_bindings (1);
1525     }
1526 }
1527
1528 void
1529 start_java_method (fndecl)
1530      tree fndecl;
1531 {
1532   tree tem, *ptr;
1533   int i;
1534
1535   current_function_decl = fndecl;
1536   announce_function (fndecl);
1537
1538   i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1539   decl_map = make_tree_vec (i);
1540   type_map = (tree *) oballoc (i * sizeof (tree));
1541
1542   pushlevel (1);  /* Push parameters. */
1543
1544   ptr = &DECL_ARGUMENTS (fndecl);
1545   for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1546        tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1547     {
1548       tree parm_name = NULL_TREE, parm_decl;
1549       tree parm_type = TREE_VALUE (tem);
1550       if (i >= DECL_MAX_LOCALS(fndecl))
1551         fatal ("function has more parameters than local slots");
1552
1553       parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1554       DECL_CONTEXT (parm_decl) = fndecl;
1555 #ifdef PROMOTE_PROTOTYPES
1556       if (TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1557           && INTEGRAL_TYPE_P (parm_type))
1558         parm_type = integer_type_node;
1559 #endif
1560       DECL_ARG_TYPE (parm_decl) = parm_type;
1561
1562       *ptr = parm_decl;
1563       ptr = &TREE_CHAIN (parm_decl);
1564
1565       /* Add parm_decl to the decl_map. */
1566       push_jvm_slot (i, parm_decl);
1567
1568       type_map[i] = TREE_TYPE (parm_decl);
1569       if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1570         {
1571           i++;
1572           type_map[i] = void_type_node;
1573         }
1574     }
1575   *ptr = NULL_TREE;
1576   DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1577
1578   while (i < DECL_MAX_LOCALS(fndecl))
1579     type_map[i++] = NULL_TREE;
1580
1581   complete_start_java_method (fndecl);
1582 }
1583
1584 void
1585 end_java_method ()
1586 {
1587   tree fndecl = current_function_decl;
1588
1589   expand_end_bindings (getdecls (), 1, 0);
1590   /* pop out of function */
1591   poplevel (1, 1, 0);
1592
1593   /* pop out of its parameters */
1594   poplevel (1, 0, 1);
1595
1596   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1597
1598   emit_handlers ();
1599
1600   /* Generate rtl for function exit.  */
1601   expand_function_end (input_filename, lineno, 0);
1602
1603   /* Run the optimizers and output assembler code for this function. */
1604   rest_of_compilation (fndecl);
1605
1606   current_function_decl = NULL_TREE;
1607   permanent_allocation (1);
1608 }