OSDN Git Service

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