This commit was manufactured by cvs2svn to create branch 'egcs'.
[official-gcc.git] / gcc / java / decl.c
bloba12931fe1bab5f729e8a7b0617e8d5776d7151e6
1 /* Process declarations and variables for the GNU compiler for the
2 Java(TM) language.
4 Copyright (C) 1996, 1998 Free Software Foundation, Inc.
6 This file is part of GNU CC.
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.
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.
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.
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. */
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
29 #include "config.h"
30 #include "tree.h"
31 #include "java-tree.h"
32 #include "jcf.h"
33 #include "system.h"
35 /* The DECL_MAP is a mapping from (index, type) to a decl node.
36 If index < max_locals, it is the index of a local variable.
37 if index >= max_locals, then index-max_locals is a stack slot.
38 The DECL_MAP mapping is represented as a TREE_VEC whose elements
39 are a list of decls (VAR_DECL or PARM_DECL) chained by
40 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
41 we search the chain for a decl with a matching TREE_TYPE. */
43 tree decl_map;
45 /* A list of local variables VAR_DECLs for this method that we have seen
46 debug information, but we have not reached their starting (byte) PC yet. */
48 tree pending_local_decls = NULL_TREE;
50 /* Push a local variable or stack slot into the decl_map,
51 and assign it an rtl. */
53 tree
54 push_jvm_slot (index, decl)
55 int index;
56 tree decl;
58 struct rtx_def *rtl = NULL;
59 tree type = TREE_TYPE (decl);
60 tree tmp;
62 DECL_CONTEXT (decl) = current_function_decl;
63 layout_decl (decl, 0);
65 /* See if we have an appropriate rtl (i.e. same mode) at this index.
66 If so, we must use it. */
67 tmp = TREE_VEC_ELT (decl_map, index);
68 while (tmp != NULL_TREE)
70 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
71 rtl = DECL_RTL (tmp);
72 if (rtl != NULL)
73 break;
74 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
76 if (rtl != NULL)
77 DECL_RTL (decl) = rtl;
78 else
80 if (index >= DECL_MAX_LOCALS (current_function_decl))
81 DECL_REGISTER (decl) = 1;
82 expand_decl (decl);
85 /* Now link the decl into the decl_map. */
86 if (DECL_LANG_SPECIFIC (decl) == NULL)
88 DECL_LANG_SPECIFIC (decl)
89 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
90 DECL_LOCAL_START_PC (decl) = 0;
91 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
92 DECL_LOCAL_SLOT_NUMBER (decl) = index;
94 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
95 TREE_VEC_ELT (decl_map, index) = decl;
96 return decl;
99 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
100 that is valid at PC (or -1 if any pc).
101 If there is no existing matching decl, allocate one.
102 If we find a decl with matching modes but different types,
103 we re-use the rtl, but create a new decl. */
105 tree
106 find_local_variable (index, type, pc)
107 int index;
108 tree type;
109 int pc;
111 struct rtx_def *rtl = NULL;
112 tree decl = TREE_VEC_ELT (decl_map, index);
113 tree best = NULL_TREE;
114 while (decl != NULL_TREE)
116 int in_range;
117 in_range = pc < 0
118 || (pc >= DECL_LOCAL_START_PC (decl)
119 && pc < DECL_LOCAL_END_PC (decl));
121 if ((TREE_TYPE (decl) == type
122 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
123 && type == ptr_type_node))
124 && in_range)
126 if (best == NULL_TREE
127 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
128 || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
129 || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
130 best = decl;
132 decl = DECL_LOCAL_SLOT_CHAIN (decl);
134 if (best != NULL_TREE)
135 return best;
136 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
140 /* Same as find_local_index, except that INDEX is a stack index. */
142 tree
143 find_stack_slot (index, type)
144 int index;
145 tree type;
147 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
148 type, -1);
151 struct binding_level
153 /* A chain of _DECL nodes for all variables, constants, functions,
154 * and typedef types. These are in the reverse of the order supplied.
156 tree names;
158 /* For each level, a list of shadowed outer-level local definitions
159 to be restored when this level is popped.
160 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
161 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
162 tree shadowed;
164 /* For each level (except not the global one),
165 a chain of BLOCK nodes for all the levels
166 that were entered and exited one level down. */
167 tree blocks;
169 /* The BLOCK node for this level, if one has been preallocated.
170 If 0, the BLOCK is allocated (if needed) when the level is popped. */
171 tree this_block;
173 /* The binding level which this one is contained in (inherits from). */
174 struct binding_level *level_chain;
176 /* 1 means make a BLOCK for this level regardless of all else.
177 2 for temporary binding contours created by the compiler. */
178 char keep;
180 /* Nonzero means make a BLOCK if this level has any subblocks. */
181 char keep_if_subblocks;
183 /* Nonzero if this level can safely have additional
184 cleanup-needing variables added to it. */
185 char more_cleanups_ok;
186 char have_cleanups;
188 /* The bytecode PC that marks the end of this level. */
189 int end_pc;
192 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
194 /* The binding level currently in effect. */
196 static struct binding_level *current_binding_level;
198 /* A chain of binding_level structures awaiting reuse. */
200 static struct binding_level *free_binding_level;
202 /* The outermost binding level, for names of file scope.
203 This is created when the compiler is started and exists
204 through the entire run. */
206 static struct binding_level *global_binding_level;
208 /* Binding level structures are initialized by copying this one. */
210 static struct binding_level clear_binding_level
211 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
212 NULL_BINDING_LEVEL, 0, 0, 0, 0, 1000000000};
214 #if 0
215 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
216 that have names. Here so we can clear out their names' definitions
217 at the end of the function. */
219 static tree named_labels;
221 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
223 static tree shadowed_labels;
224 #endif
226 int flag_traditional;
228 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
230 static int keep_next_level_flag;
232 /* Nonzero means make a BLOCK for the next level pushed
233 if it has subblocks. */
235 static int keep_next_if_subblocks;
237 /* The FUNCTION_DECL for the function currently being compiled,
238 or 0 if between functions. */
239 tree current_function_decl;
241 /* The type node for the ordinary character type. */
242 tree char_type_node;
244 tree object_type_node;
245 tree object_ptr_type_node;
246 tree string_type_node;
247 tree throwable_type_node;
249 tree boolean_type_node;
251 tree float_type_node;
252 tree double_type_node;
254 /* a VOID_TYPE node. */
256 tree void_type_node;
257 tree ptr_type_node;
258 tree return_address_type_node;
260 tree integer_type_node;
262 tree byte_type_node;
263 tree short_type_node;
264 tree int_type_node;
265 tree long_type_node;
267 tree promoted_byte_type_node;
268 tree promoted_short_type_node;
269 tree promoted_char_type_node;
270 tree promoted_boolean_type_node;
272 tree unsigned_byte_type_node;
273 tree unsigned_short_type_node;
274 tree unsigned_int_type_node;
275 tree unsigned_long_type_node;
277 /* The type for struct methodtable. */
278 tree methodtable_type;
279 tree methodtable_ptr_type;
281 tree utf8const_type;
282 tree utf8const_ptr_type;
283 tree class_type_node;
284 tree class_ptr_type;
285 tree field_type_node;
286 tree field_ptr_type_node;
287 tree field_info_union_node;
288 tree jexception_type;
289 tree jexception_ptr_type;
290 tree lineNumberEntry_type;
291 tree lineNumbers_type;
292 tree constants_type_node;
293 tree dtable_type;
294 tree dtable_ptr_type;
295 tree method_type_node;
296 tree method_ptr_type_node;
297 tree nativecode_ptr_array_type_node;
298 tree one_elt_array_domain_type;
299 tree access_flags_type_node;
300 tree class_dtable_decl;
302 /* a node which has tree code ERROR_MARK, and whose type is itself.
303 All erroneous expressions are replaced with this node. All functions
304 that accept nodes as arguments should avoid generating error messages
305 if this node is one of the arguments, since it is undesirable to get
306 multiple error messages from one error in the input. */
308 tree error_mark_node;
310 /* Two expressions that are constants with value zero.
311 The first is of type `int', the second of type `void *'. */
312 tree integer_zero_node;
313 tree null_pointer_node;
315 /* Nodes for boolean constants TRUE and FALSE. */
316 tree boolean_true_node, boolean_false_node;
318 tree TYPE_identifier_node;
319 tree init_identifier_node;
320 tree clinit_identifier_node;
321 tree finalize_identifier_node;
322 tree void_signature_node;
323 tree length_identifier_node;
324 tree this_identifier_node;
325 tree super_identifier_node;
327 /* References to internal libjava functions we use. */
328 tree alloc_object_node;
329 tree soft_instanceof_node;
330 tree soft_checkcast_node;
331 tree soft_initclass_node;
332 tree soft_newarray_node;
333 tree soft_anewarray_node;
334 tree soft_multianewarray_node;
335 tree soft_badarrayindex_node;
336 tree throw_node;
337 tree soft_checkarraystore_node;
338 tree soft_monitorenter_node;
339 tree soft_monitorexit_node;
340 tree soft_lookupinterfacemethod_node;
341 tree soft_fmod_node;
343 /* Build (and pushdecl) a "promoted type" for all standard
344 types shorter than int. */
346 static tree
347 push_promoted_type (name, actual_type)
348 char *name;
349 tree actual_type;
351 tree type = make_node (TREE_CODE (actual_type));
352 #if 1
353 tree in_min = TYPE_MIN_VALUE (int_type_node);
354 tree in_max = TYPE_MAX_VALUE (int_type_node);
355 #else
356 tree in_min = TYPE_MIN_VALUE (actual_type);
357 tree in_max = TYPE_MAX_VALUE (actual_type);
358 #endif
359 TYPE_MIN_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_min),
360 TREE_INT_CST_HIGH (in_min));
361 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
362 TYPE_MAX_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_max),
363 TREE_INT_CST_HIGH (in_max));
364 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
365 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
366 layout_type (type);
367 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
368 return type;
371 /* Nodes for integer constants. */
372 tree integer_one_node, integer_two_node, integer_four_node;
373 tree integer_negative_one_node;
375 /* Return a definition for a builtin function named NAME and whose data type
376 is TYPE. TYPE should be a function type with argument types.
377 FUNCTION_CODE tells later passes how to compile calls to this function.
378 See tree.h for its possible values.
380 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
381 the name to be called if we can't opencode the function. */
383 tree
384 builtin_function (name, type, function_code, library_name)
385 char *name;
386 tree type;
387 enum built_in_function function_code;
388 char *library_name;
390 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
391 DECL_EXTERNAL (decl) = 1;
392 TREE_PUBLIC (decl) = 1;
393 if (library_name)
394 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
395 make_decl_rtl (decl, NULL_PTR, 1);
396 pushdecl (decl);
397 if (function_code != NOT_BUILT_IN)
399 DECL_BUILT_IN (decl) = 1;
400 DECL_FUNCTION_CODE (decl) = function_code;
402 return decl;
405 void
406 init_decl_processing ()
408 tree field;
409 tree t;
411 current_function_decl = NULL;
412 current_binding_level = NULL_BINDING_LEVEL;
413 free_binding_level = NULL_BINDING_LEVEL;
414 pushlevel (0); /* make the binding_level structure for global names */
415 global_binding_level = current_binding_level;
417 error_mark_node = make_node (ERROR_MARK);
418 TREE_TYPE (error_mark_node) = error_mark_node;
420 /* Create sizetype first - needed for other types. */
421 sizetype = make_unsigned_type (POINTER_SIZE);
422 size_zero_node = build_int_2 (0, 0);
423 TREE_TYPE (size_zero_node) = sizetype;
424 size_one_node = build_int_2 (1, 0);
425 TREE_TYPE (size_one_node) = sizetype;
427 byte_type_node = make_signed_type (8);
428 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
429 short_type_node = make_signed_type (16);
430 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
431 int_type_node = make_signed_type (32);
432 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
433 long_type_node = make_signed_type (64);
434 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
436 unsigned_byte_type_node = make_unsigned_type (8);
437 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
438 unsigned_byte_type_node));
439 unsigned_short_type_node = make_unsigned_type (16);
440 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
441 unsigned_short_type_node));
442 unsigned_int_type_node = make_unsigned_type (32);
443 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
444 unsigned_int_type_node));
445 unsigned_long_type_node = make_unsigned_type (64);
446 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
447 unsigned_long_type_node));
449 integer_type_node = int_type_node;
451 integer_zero_node = build_int_2 (0, 0);
452 integer_one_node = build_int_2 (1, 0);
453 integer_two_node = build_int_2 (2, 0);
454 integer_four_node = build_int_2 (4, 0);
455 integer_negative_one_node = build_int_2 (-1, 0);
457 void_type_node = make_node (VOID_TYPE);
458 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
459 layout_type (void_type_node); /* Uses size_zero_node */
460 ptr_type_node = build_pointer_type (void_type_node);
461 t = make_node (VOID_TYPE);
462 layout_type (t); /* Uses size_zero_node */
463 return_address_type_node = build_pointer_type (t);
465 null_pointer_node = build_int_2 (0, 0);
466 TREE_TYPE (null_pointer_node) = ptr_type_node;
468 #if 0
469 /* Make a type to be the domain of a few array types
470 whose domains don't really matter.
471 200 is small enough that it always fits in size_t
472 and large enough that it can hold most function names for the
473 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
474 short_array_type_node = build_prim_array_type (short_type_node, 200);
475 #endif
476 char_type_node = make_node (CHAR_TYPE);
477 TYPE_PRECISION (char_type_node) = 16;
478 fixup_unsigned_type (char_type_node);
479 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
481 boolean_type_node = make_node (BOOLEAN_TYPE);
482 TYPE_PRECISION (boolean_type_node) = 1;
483 fixup_unsigned_type (boolean_type_node);
484 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
485 boolean_type_node));
486 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
487 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
489 promoted_byte_type_node
490 = push_promoted_type ("promoted_byte", byte_type_node);
491 promoted_short_type_node
492 = push_promoted_type ("promoted_short", short_type_node);
493 promoted_char_type_node
494 = push_promoted_type ("promoted_char", char_type_node);
495 promoted_boolean_type_node
496 = push_promoted_type ("promoted_boolean", boolean_type_node);
498 float_type_node = make_node (REAL_TYPE);
499 TYPE_PRECISION (float_type_node) = 32;
500 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
501 float_type_node));
502 layout_type (float_type_node);
504 double_type_node = make_node (REAL_TYPE);
505 TYPE_PRECISION (double_type_node) = 64;
506 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
507 double_type_node));
508 layout_type (double_type_node);
510 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
511 object_ptr_type_node = promote_type (object_type_node);
512 string_type_node = lookup_class (get_identifier ("java.lang.String"));
513 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
514 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
516 methodtable_type = make_node (RECORD_TYPE);
517 layout_type (methodtable_type);
518 pushdecl (build_decl (TYPE_DECL, get_identifier ("methodtable"),
519 methodtable_type));
520 methodtable_ptr_type = build_pointer_type (methodtable_type);
522 TYPE_identifier_node = get_identifier ("TYPE");
523 init_identifier_node = get_identifier ("<init>");
524 clinit_identifier_node = get_identifier ("<clinit>");
525 finalize_identifier_node = get_identifier ("finalize");
526 void_signature_node = get_identifier ("()V");
527 length_identifier_node = get_identifier ("length");
528 this_identifier_node = get_identifier ("this");
529 super_identifier_node = get_identifier ("super");
531 /* for lack of a better place to put this stub call */
532 init_expr_processing();
534 utf8const_type = make_node (RECORD_TYPE);
535 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
536 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
537 FINISH_RECORD (utf8const_type);
538 utf8const_ptr_type = build_pointer_type (utf8const_type);
540 constants_type_node = make_node (RECORD_TYPE);
541 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
542 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
543 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
544 FINISH_RECORD (constants_type_node);
545 pushdecl (build_decl (TYPE_DECL, get_identifier ("constants"),
546 constants_type_node));
548 access_flags_type_node = unsigned_short_type_node;
550 dtable_type = make_node (RECORD_TYPE);
551 dtable_ptr_type = build_pointer_type (dtable_type);
553 PUSH_FIELD (object_type_node, field, "dtable", dtable_ptr_type);
554 PUSH_FIELD (object_type_node, field, "sync_info", ptr_type_node);
555 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
556 FIELD_PRIVATE (t) = 1;
557 FINISH_RECORD (object_type_node);
559 class_dtable_decl = build_dtable_decl (class_type_node);
560 TREE_STATIC (class_dtable_decl) = 1;
561 DECL_ARTIFICIAL (class_dtable_decl) = 1;
562 DECL_IGNORED_P (class_dtable_decl) = 1;
563 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
565 field_type_node = make_node (RECORD_TYPE);
566 field_ptr_type_node = build_pointer_type (field_type_node);
567 method_type_node = make_node (RECORD_TYPE);
568 method_ptr_type_node = build_pointer_type (method_type_node);
570 set_super_info (0, class_type_node, object_type_node, 0);
571 set_super_info (0, string_type_node, object_type_node, 0);
572 class_ptr_type = build_pointer_type (class_type_node);
574 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
575 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
576 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
577 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
578 PUSH_FIELD (class_type_node, field, "subclass_head", class_ptr_type);
579 PUSH_FIELD (class_type_node, field, "subclass_next", class_ptr_type);
580 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
581 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
582 PUSH_FIELD (class_type_node, field, "nmethods", short_type_node);
583 PUSH_FIELD (class_type_node, field, "msize", short_type_node);
584 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
585 PUSH_FIELD (class_type_node, field, "bfsize", int_type_node);
586 PUSH_FIELD (class_type_node, field, "nfields", short_type_node);
587 PUSH_FIELD (class_type_node, field, "nsfields", short_type_node);
588 PUSH_FIELD (class_type_node, field, "dtable", dtable_ptr_type);
589 PUSH_FIELD (class_type_node, field, "interfaces",
590 build_pointer_type (class_ptr_type));
591 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
592 PUSH_FIELD (class_type_node, field, "interface_len", short_type_node);
593 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
594 PUSH_FIELD (class_type_node, field, "final", byte_type_node);
595 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
596 FIELD_PRIVATE (t) = 1;
597 push_super_field (class_type_node, object_type_node);
598 FINISH_RECORD (class_type_node);
599 pushdecl (build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node));
601 field_info_union_node = make_node (UNION_TYPE);
602 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
603 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
604 #if 0
605 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
606 #endif
607 layout_type (field_info_union_node);
609 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
610 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
611 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
612 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
613 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
614 FINISH_RECORD (field_type_node);
615 CLASS_LOADED_P (field_type_node) = 1;
616 pushdecl (build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node));
618 one_elt_array_domain_type = build_index_type (integer_one_node);
619 nativecode_ptr_array_type_node
620 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
622 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
623 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
624 FINISH_RECORD (dtable_type);
625 pushdecl (build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type));
627 #define jint_type int_type_node
628 #define jint_ptr_type ptr_type_node
630 jexception_type = make_node (RECORD_TYPE);
631 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
632 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
633 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
634 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
635 FINISH_RECORD (jexception_type);
636 pushdecl (build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node));
637 jexception_ptr_type = build_pointer_type (jexception_type);
639 lineNumberEntry_type = make_node (RECORD_TYPE);
640 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
641 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
642 FINISH_RECORD (lineNumberEntry_type);
644 lineNumbers_type = make_node (RECORD_TYPE);
645 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
646 FINISH_RECORD (lineNumbers_type);
648 #define instn_ptr_type_node ptr_type_node /* XXX JH */
650 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
652 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
653 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
654 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
655 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
656 FINISH_RECORD (method_type_node);
657 CLASS_LOADED_P (method_type_node) = 1;
658 pushdecl (build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node));
660 t = tree_cons (NULL_TREE, class_ptr_type,
661 build_tree_list (NULL_TREE, int_type_node));
662 alloc_object_node = builtin_function ("_Jv_AllocObject",
663 build_function_type (ptr_type_node, t),
664 NOT_BUILT_IN, NULL_PTR);
665 soft_initclass_node = builtin_function ("_Jv_InitClass",
666 build_function_type (void_type_node,
668 NOT_BUILT_IN, NULL_PTR);
669 t = build_tree_list (NULL_TREE, void_type_node);
670 throw_node = builtin_function ("_Jv_Throw",
671 build_function_type (ptr_type_node, t),
672 NOT_BUILT_IN, NULL_PTR);
673 soft_monitorenter_node
674 = builtin_function ("_Jv_MonitorEnter",
675 build_function_type (int_type_node, t),
676 NOT_BUILT_IN, NULL_PTR);
677 soft_monitorexit_node
678 = builtin_function ("_Jv_MonitorExit",
679 build_function_type (int_type_node, t),
680 NOT_BUILT_IN, NULL_PTR);
682 t = tree_cons (NULL_TREE, int_type_node,
683 build_tree_list (NULL_TREE, int_type_node));
684 soft_newarray_node
685 = builtin_function ("_Jv_NewArray",
686 build_function_type(ptr_type_node, t),
687 NOT_BUILT_IN, NULL_PTR );
689 t = tree_cons (NULL_TREE, int_type_node,
690 tree_cons (NULL_TREE, class_ptr_type,
691 build_tree_list (NULL_TREE, object_ptr_type_node)));
692 soft_anewarray_node
693 = builtin_function ("_Jv_NewObjectArray",
694 build_function_type (ptr_type_node, t),
695 NOT_BUILT_IN, NULL_PTR );
697 t = tree_cons (NULL_TREE, ptr_type_node,
698 build_tree_list (NULL_TREE, int_type_node));
699 soft_multianewarray_node
700 = builtin_function ("_Jv_NewMultiArray",
701 build_function_type (ptr_type_node, t),
702 NOT_BUILT_IN, NULL_PTR );
704 t = build_function_type (void_type_node, NULL_TREE);
705 soft_badarrayindex_node
706 = builtin_function ("_Jv_ThrowBadArrayIndex", t, NOT_BUILT_IN, NULL_PTR );
707 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
708 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
710 t = tree_cons (NULL_TREE, class_ptr_type,
711 build_tree_list (NULL_TREE, object_ptr_type_node));
712 soft_checkcast_node
713 = builtin_function ("_Jv_CheckCast",
714 build_function_type (ptr_type_node, t),
715 NOT_BUILT_IN, NULL_PTR);
716 t = tree_cons (NULL_TREE, object_ptr_type_node,
717 build_tree_list (NULL_TREE, class_ptr_type));
718 soft_instanceof_node
719 = builtin_function ("_Jv_IsInstanceOf",
720 build_function_type (promoted_boolean_type_node, t),
721 NOT_BUILT_IN, NULL_PTR);
722 t = tree_cons (NULL_TREE, object_ptr_type_node,
723 build_tree_list (NULL_TREE, object_ptr_type_node));
724 soft_checkarraystore_node
725 = builtin_function ("_Jv_CheckArrayStore",
726 build_function_type (void_type_node, t),
727 NOT_BUILT_IN, NULL_PTR);
728 t = tree_cons (NULL_TREE, ptr_type_node,
729 tree_cons (NULL_TREE, ptr_type_node,
730 build_tree_list (NULL_TREE, ptr_type_node)));
731 soft_lookupinterfacemethod_node
732 = builtin_function ("_Jv_LookupInterfaceMethod",
733 build_function_type(ptr_type_node, t),
734 NOT_BUILT_IN, NULL_PTR);
735 t = tree_cons (NULL_TREE, double_type_node,
736 build_tree_list (NULL_TREE, double_type_node));
737 soft_fmod_node
738 = builtin_function ("__builtin_fmod",
739 build_function_type (double_type_node, t),
740 BUILT_IN_FMOD, "fmod");
741 #if 0
742 t = tree_cons (NULL_TREE, float_type_node,
743 build_tree_list (NULL_TREE, float_type_node));
744 soft_fmodf_node
745 = builtin_function ("__builtin_fmodf",
746 build_function_type (float_type_node, t),
747 BUILT_IN_FMOD, "fmodf");
748 #endif
750 init_class_processing ();
754 /* Look up NAME in the current binding level and its superiors
755 in the namespace of variables, functions and typedefs.
756 Return a ..._DECL node of some kind representing its definition,
757 or return 0 if it is undefined. */
759 tree
760 lookup_name (name)
761 tree name;
763 register tree val;
764 if (current_binding_level != global_binding_level
765 && IDENTIFIER_LOCAL_VALUE (name))
766 val = IDENTIFIER_LOCAL_VALUE (name);
767 else
768 val = IDENTIFIER_GLOBAL_VALUE (name);
769 return val;
772 /* Similar to `lookup_name' but look only at current binding level and
773 the previous one if its the parameter level. */
775 tree
776 lookup_name_current_level (name)
777 tree name;
779 register tree t;
781 if (current_binding_level == global_binding_level)
782 return IDENTIFIER_GLOBAL_VALUE (name);
784 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
785 return 0;
787 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
788 if (DECL_NAME (t) == name)
789 break;
791 return t;
794 /* Use a binding level to record a labeled block declaration */
796 void
797 push_labeled_block (lb)
798 tree lb;
800 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
801 register struct binding_level *b = current_binding_level;
802 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
803 if (oldlocal != 0)
804 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
805 TREE_CHAIN (lb) = b->names;
806 b->names = lb;
807 IDENTIFIER_LOCAL_VALUE (name) = lb;
810 /* Pop the current binding level, reinstalling values for the previous
811 labeled block */
813 void
814 pop_labeled_block ()
816 struct binding_level *b = current_binding_level;
817 tree label = b->names;
818 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
819 NULL_TREE;
820 if (b->shadowed)
821 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
822 TREE_VALUE (b->shadowed);
824 /* Pop the current level, and free the structure for reuse. */
825 current_binding_level = current_binding_level->level_chain;
826 b->level_chain = free_binding_level;
827 free_binding_level = b;
830 /* Record a decl-node X as belonging to the current lexical scope.
831 Check for errors (such as an incompatible declaration for the same
832 name already seen in the same scope).
834 Returns either X or an old decl for the same name.
835 If an old decl is returned, it may have been smashed
836 to agree with what X says. */
838 tree
839 pushdecl (x)
840 tree x;
842 register tree t;
843 register tree name = DECL_NAME (x);
844 register struct binding_level *b = current_binding_level;
846 DECL_CONTEXT (x) = current_function_decl;
847 if (name)
849 char *file;
850 int line;
851 int different_binding_level = 0;
853 t = lookup_name_current_level (name);
854 if (t != 0 && t == error_mark_node)
855 /* error_mark_node is 0 for a while during initialization! */
857 t = 0;
858 error_with_decl (x, "`%s' used prior to declaration");
861 if (t != 0)
863 file = DECL_SOURCE_FILE (t);
864 line = DECL_SOURCE_LINE (t);
867 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
868 to point to the TYPE_DECL.
869 Since Java does not have typedefs, a type can only have
870 one (true) name, given by a class, interface, or builtin. */
871 if (TREE_CODE (x) == TYPE_DECL
872 && TYPE_NAME (TREE_TYPE (x)) == 0
873 && TREE_TYPE (x) != error_mark_node)
875 TYPE_NAME (TREE_TYPE (x)) = x;
876 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
879 /* This name is new in its binding level.
880 Install the new declaration and return it. */
881 if (b == global_binding_level)
883 /* Install a global value. */
885 IDENTIFIER_GLOBAL_VALUE (name) = x;
887 else
889 /* Here to install a non-global value. */
890 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
891 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
892 IDENTIFIER_LOCAL_VALUE (name) = x;
894 #if 0
895 /* Warn if shadowing an argument at the top level of the body. */
896 if (oldlocal != 0 && !DECL_EXTERNAL (x)
897 /* This warning doesn't apply to the parms of a nested fcn. */
898 && ! current_binding_level->parm_flag
899 /* Check that this is one level down from the parms. */
900 && current_binding_level->level_chain->parm_flag
901 /* Check that the decl being shadowed
902 comes from the parm level, one level up. */
903 && chain_member (oldlocal, current_binding_level->level_chain->names))
905 if (TREE_CODE (oldlocal) == PARM_DECL)
906 pedwarn ("declaration of `%s' shadows a parameter",
907 IDENTIFIER_POINTER (name));
908 else
909 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
910 IDENTIFIER_POINTER (name));
913 /* Maybe warn if shadowing something else. */
914 else if (warn_shadow && !DECL_EXTERNAL (x)
915 /* No shadow warnings for internally generated vars. */
916 && DECL_SOURCE_LINE (x) != 0
917 /* No shadow warnings for vars made for inlining. */
918 && ! DECL_FROM_INLINE (x))
920 char *warnstring = 0;
922 if (TREE_CODE (x) == PARM_DECL
923 && current_binding_level->level_chain->parm_flag)
924 /* Don't warn about the parm names in function declarator
925 within a function declarator.
926 It would be nice to avoid warning in any function
927 declarator in a declaration, as opposed to a definition,
928 but there is no way to tell it's not a definition. */
930 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
931 warnstring = "declaration of `%s' shadows a parameter";
932 else if (oldlocal != 0)
933 warnstring = "declaration of `%s' shadows previous local";
934 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
935 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
936 warnstring = "declaration of `%s' shadows global declaration";
938 if (warnstring)
939 warning (warnstring, IDENTIFIER_POINTER (name));
941 #endif
943 /* If storing a local value, there may already be one (inherited).
944 If so, record it for restoration when this binding level ends. */
945 if (oldlocal != 0)
946 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
950 /* Put decls on list in reverse order.
951 We will reverse them later if necessary. */
952 TREE_CHAIN (x) = b->names;
953 b->names = x;
955 return x;
957 void
958 pushdecl_force_head (x)
959 tree x;
961 current_binding_level->names = x;
964 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
966 tree
967 pushdecl_top_level (x)
968 tree x;
970 register tree t;
971 register struct binding_level *b = current_binding_level;
973 current_binding_level = global_binding_level;
974 t = pushdecl (x);
975 current_binding_level = b;
976 return t;
979 /* Nonzero if we are currently in the global binding level. */
982 global_bindings_p ()
984 return current_binding_level == global_binding_level;
987 /* Return the list of declarations of the current level.
988 Note that this list is in reverse order unless/until
989 you nreverse it; and when you do nreverse it, you must
990 store the result back using `storedecls' or you will lose. */
992 tree
993 getdecls ()
995 return current_binding_level->names;
998 /* Create a new `struct binding_level'. */
1000 static
1001 struct binding_level *
1002 make_binding_level ()
1004 /* NOSTRICT */
1005 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1008 void
1009 pushlevel (unused)
1010 int unused;
1012 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1014 #if 0
1015 /* If this is the top level of a function,
1016 just make sure that NAMED_LABELS is 0. */
1018 if (current_binding_level == global_binding_level)
1019 named_labels = 0;
1020 #endif
1022 /* Reuse or create a struct for this binding level. */
1024 if (free_binding_level)
1026 newlevel = free_binding_level;
1027 free_binding_level = free_binding_level->level_chain;
1029 else
1031 newlevel = make_binding_level ();
1034 /* Add this level to the front of the chain (stack) of levels that
1035 are active. */
1037 *newlevel = clear_binding_level;
1038 newlevel->level_chain = current_binding_level;
1039 current_binding_level = newlevel;
1040 newlevel->keep = keep_next_level_flag;
1041 keep_next_level_flag = 0;
1042 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1043 keep_next_if_subblocks = 0;
1046 /* Exit a binding level.
1047 Pop the level off, and restore the state of the identifier-decl mappings
1048 that were in effect when this level was entered.
1050 If KEEP is nonzero, this level had explicit declarations, so
1051 and create a "block" (a BLOCK node) for the level
1052 to record its declarations and subblocks for symbol table output.
1054 If FUNCTIONBODY is nonzero, this level is the body of a function,
1055 so create a block as if KEEP were set and also clear out all
1056 label names.
1058 If REVERSE is nonzero, reverse the order of decls before putting
1059 them into the BLOCK. */
1061 tree
1062 poplevel (keep, reverse, functionbody)
1063 int keep;
1064 int reverse;
1065 int functionbody;
1067 register tree link;
1068 /* The chain of decls was accumulated in reverse order.
1069 Put it into forward order, just for cleanliness. */
1070 tree decls;
1071 tree subblocks = current_binding_level->blocks;
1072 tree block = 0;
1073 tree decl;
1074 int block_previously_created;
1076 keep |= current_binding_level->keep;
1078 /* Get the decls in the order they were written.
1079 Usually current_binding_level->names is in reverse order.
1080 But parameter decls were previously put in forward order. */
1082 if (reverse)
1083 current_binding_level->names
1084 = decls = nreverse (current_binding_level->names);
1085 else
1086 decls = current_binding_level->names;
1088 /* Output any nested inline functions within this block
1089 if they weren't already output. */
1091 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1092 if (TREE_CODE (decl) == FUNCTION_DECL
1093 && ! TREE_ASM_WRITTEN (decl)
1094 && DECL_INITIAL (decl) != 0
1095 && TREE_ADDRESSABLE (decl))
1097 /* If this decl was copied from a file-scope decl
1098 on account of a block-scope extern decl,
1099 propagate TREE_ADDRESSABLE to the file-scope decl.
1101 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1102 true, since then the decl goes through save_for_inline_copying. */
1103 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1104 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1105 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1106 else
1108 push_function_context ();
1109 output_inline_function (decl);
1110 pop_function_context ();
1114 /* If there were any declarations in that level,
1115 or if this level is a function body,
1116 create a BLOCK to record them for the life of this function. */
1118 block = 0;
1119 block_previously_created = (current_binding_level->this_block != 0);
1120 if (block_previously_created)
1121 block = current_binding_level->this_block;
1122 else if (keep || functionbody
1123 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1124 block = make_node (BLOCK);
1125 if (block != 0)
1127 BLOCK_VARS (block) = decls;
1128 BLOCK_TYPE_TAGS (block) = NULL_TREE;
1129 BLOCK_SUBBLOCKS (block) = subblocks;
1130 remember_end_note (block);
1133 /* In each subblock, record that this is its superior. */
1135 for (link = subblocks; link; link = TREE_CHAIN (link))
1136 BLOCK_SUPERCONTEXT (link) = block;
1138 /* Clear out the meanings of the local variables of this level. */
1140 for (link = decls; link; link = TREE_CHAIN (link))
1142 tree name = DECL_NAME (link);
1143 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1145 /* If the ident. was used or addressed via a local extern decl,
1146 don't forget that fact. */
1147 if (DECL_EXTERNAL (link))
1149 if (TREE_USED (link))
1150 TREE_USED (name) = 1;
1151 if (TREE_ADDRESSABLE (link))
1152 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1154 IDENTIFIER_LOCAL_VALUE (name) = 0;
1158 /* Restore all name-meanings of the outer levels
1159 that were shadowed by this level. */
1161 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1162 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1164 /* If the level being exited is the top level of a function,
1165 check over all the labels, and clear out the current
1166 (function local) meanings of their names. */
1168 if (functionbody)
1170 /* If this is the top level block of a function,
1171 the vars are the function's parameters.
1172 Don't leave them in the BLOCK because they are
1173 found in the FUNCTION_DECL instead. */
1175 BLOCK_VARS (block) = 0;
1177 /* Clear out the definitions of all label names,
1178 since their scopes end here,
1179 and add them to BLOCK_VARS. */
1181 #if 0
1182 for (link = named_labels; link; link = TREE_CHAIN (link))
1184 register tree label = TREE_VALUE (link);
1186 if (DECL_INITIAL (label) == 0)
1188 error_with_decl (label, "label `%s' used but not defined");
1189 /* Avoid crashing later. */
1190 define_label (input_filename, lineno,
1191 DECL_NAME (label));
1193 else if (warn_unused && !TREE_USED (label))
1194 warning_with_decl (label, "label `%s' defined but not used");
1195 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1197 /* Put the labels into the "variables" of the
1198 top-level block, so debugger can see them. */
1199 TREE_CHAIN (label) = BLOCK_VARS (block);
1200 BLOCK_VARS (block) = label;
1202 #endif
1205 /* Pop the current level, and free the structure for reuse. */
1208 register struct binding_level *level = current_binding_level;
1209 current_binding_level = current_binding_level->level_chain;
1211 level->level_chain = free_binding_level;
1212 free_binding_level = level;
1215 /* Dispose of the block that we just made inside some higher level. */
1216 if (functionbody)
1217 DECL_INITIAL (current_function_decl) = block;
1218 else if (block)
1220 if (!block_previously_created)
1221 current_binding_level->blocks
1222 = chainon (current_binding_level->blocks, block);
1224 /* If we did not make a block for the level just exited,
1225 any blocks made for inner levels
1226 (since they cannot be recorded as subblocks in that level)
1227 must be carried forward so they will later become subblocks
1228 of something else. */
1229 else if (subblocks)
1230 current_binding_level->blocks
1231 = chainon (current_binding_level->blocks, subblocks);
1233 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1234 binding contour so that they point to the appropriate construct, i.e.
1235 either to the current FUNCTION_DECL node, or else to the BLOCK node
1236 we just constructed.
1238 Note that for tagged types whose scope is just the formal parameter
1239 list for some function type specification, we can't properly set
1240 their TYPE_CONTEXTs here, because we don't have a pointer to the
1241 appropriate FUNCTION_TYPE node readily available to us. For those
1242 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1243 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1244 node which will represent the "scope" for these "parameter list local"
1245 tagged types.
1248 if (block)
1249 TREE_USED (block) = 1;
1250 return block;
1253 void
1254 maybe_pushlevels (pc)
1255 int pc;
1257 while (pending_local_decls != NULL_TREE &&
1258 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1260 tree *ptr = &pending_local_decls;
1261 tree decl = *ptr;
1262 int end_pc = DECL_LOCAL_END_PC (decl);
1264 while (*ptr != NULL_TREE
1265 && DECL_LOCAL_START_PC (*ptr) <= pc
1266 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1267 ptr = &TREE_CHAIN (*ptr);
1268 pending_local_decls = *ptr;
1269 *ptr = NULL_TREE;
1271 /* Force non-nested range to be nested in current range. */
1272 if (end_pc > current_binding_level->end_pc)
1273 end_pc = current_binding_level->end_pc;
1275 pushlevel (1);
1276 expand_start_bindings (0);
1277 current_binding_level->end_pc = end_pc;
1279 current_binding_level->names = decl;
1280 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1282 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1287 void
1288 maybe_poplevels (pc)
1289 int pc;
1291 while (current_binding_level->end_pc <= pc)
1293 expand_end_bindings (getdecls (), 1, 0);
1294 poplevel (1, 0, 0);
1298 /* Insert BLOCK at the end of the list of subblocks of the
1299 current binding level. This is used when a BIND_EXPR is expanded,
1300 to handle the BLOCK node inside the BIND_EXPR. */
1302 void
1303 insert_block (block)
1304 tree block;
1306 TREE_USED (block) = 1;
1307 abort ();
1308 current_binding_level->blocks
1309 = chainon (current_binding_level->blocks, block);
1312 /* Set the BLOCK node for the innermost scope
1313 (the one we are currently in). */
1315 void
1316 set_block (block)
1317 register tree block;
1319 current_binding_level->this_block = block;
1322 /* integrate_decl_tree calls this function. */
1324 void
1325 copy_lang_decl (node)
1326 tree node;
1328 int lang_decl_size
1329 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1330 : sizeof (struct lang_decl);
1331 struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1332 bcopy (DECL_LANG_SPECIFIC (node), x, lang_decl_size);
1333 DECL_LANG_SPECIFIC (node) = x;
1336 /* If DECL has a cleanup, build and return that cleanup here.
1337 This is a callback called by expand_expr. */
1339 tree
1340 maybe_build_cleanup (decl)
1341 tree decl;
1343 /* There are no cleanups in Java (I think). */
1344 return NULL_TREE;
1347 void
1348 give_name_to_locals (jcf)
1349 JCF *jcf;
1351 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1352 tree parm;
1353 pending_local_decls = NULL_TREE;
1354 if (n == 0)
1355 return;
1356 JCF_SEEK (jcf, n);
1357 n = JCF_readu2 (jcf);
1358 for (i = 0; i < n; i++)
1360 int start_pc = JCF_readu2 (jcf);
1361 int length = JCF_readu2 (jcf);
1362 int name_index = JCF_readu2 (jcf);
1363 int signature_index = JCF_readu2 (jcf);
1364 int slot = JCF_readu2 (jcf);
1365 tree name = get_name_constant (jcf, name_index);
1366 tree type = promote_type (parse_signature (jcf, signature_index));
1367 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1368 && start_pc == 0
1369 && length == DECL_CODE_LENGTH (current_function_decl))
1371 tree decl = TREE_VEC_ELT (decl_map, slot);
1372 DECL_NAME (decl) = name;
1373 DECL_ASSEMBLER_NAME (decl) = name;
1374 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1375 warning ("bad type in parameter debug info");
1377 else
1379 tree *ptr;
1380 int end_pc = start_pc + length;
1381 tree decl = build_decl (VAR_DECL, name, type);
1382 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1384 warning_with_decl (decl,
1385 "bad PC range for debug info for local `%s'");
1386 end_pc = DECL_CODE_LENGTH (current_function_decl);
1388 DECL_LANG_SPECIFIC (decl)
1389 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1390 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1391 DECL_LOCAL_START_PC (decl) = start_pc;
1392 DECL_LOCAL_END_PC (decl) = end_pc;
1394 /* Now insert the new decl in the proper place in
1395 pending_local_decls. We are essentially doing an insertion sort,
1396 which works fine, since the list input will normally already
1397 be sorted. */
1398 ptr = &pending_local_decls;
1399 while (*ptr != NULL_TREE
1400 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1401 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1402 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1403 ptr = &TREE_CHAIN (*ptr);
1404 TREE_CHAIN (decl) = *ptr;
1405 *ptr = decl;
1409 pending_local_decls = nreverse (pending_local_decls);
1411 /* Fill in default names for the parameters. */
1412 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1413 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1415 if (DECL_NAME (parm) == NULL_TREE)
1417 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1418 if (arg_i == 0)
1419 DECL_NAME (parm) = get_identifier ("this");
1420 else
1422 char buffer[12];
1423 sprintf (buffer, "ARG_%d", arg_i);
1424 DECL_NAME (parm) = get_identifier (buffer);
1426 DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1431 void
1432 complete_start_java_method (fndecl)
1433 tree fndecl;
1436 DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE,
1437 TREE_TYPE (TREE_TYPE (fndecl)));
1439 if (! flag_emit_class_files)
1441 /* Initialize the RTL code for the function. */
1442 init_function_start (fndecl, input_filename, lineno);
1444 /* Set up parameters and prepare for return, for the function. */
1445 expand_function_start (fndecl, 0);
1448 /* Allocate further tree nodes temporarily during compilation
1449 of this function only. */
1450 temporary_allocation ();
1452 #if 0
1453 /* If this fcn was already referenced via a block-scope `extern' decl (or
1454 an implicit decl), propagate certain information about the usage. */
1455 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1456 TREE_ADDRESSABLE (current_function_decl) = 1;
1458 #endif
1460 if (METHOD_SYNCHRONIZED (fndecl))
1462 /* FIXME: surround the function body by a try/finally set. */
1465 /* Push local variables. Function compiled from source code are
1466 using a different local variables management, and for them,
1467 pushlevel shouldn't be called from here. */
1468 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1471 pushlevel (2);
1472 if (! flag_emit_class_files)
1473 expand_start_bindings (1);
1477 void
1478 start_java_method (fndecl)
1479 tree fndecl;
1481 tree tem, *ptr;
1482 int i;
1484 current_function_decl = fndecl;
1485 announce_function (fndecl);
1487 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1488 decl_map = make_tree_vec (i);
1489 type_map = (tree *) oballoc (i * sizeof (tree));
1491 pushlevel (1); /* Push parameters. */
1493 ptr = &DECL_ARGUMENTS (fndecl);
1494 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1495 tem != NULL_TREE; tem = TREE_CHAIN (tem), i++)
1497 tree parm_name = NULL_TREE, parm_decl;
1498 if (i >= DECL_MAX_LOCALS(fndecl))
1499 fatal ("function has more parameters than local slots");
1501 parm_decl = build_decl (PARM_DECL, parm_name, TREE_VALUE (tem));
1502 DECL_CONTEXT (parm_decl) = fndecl;
1503 DECL_ARG_TYPE (parm_decl) = TREE_TYPE (parm_decl);
1505 *ptr = parm_decl;
1506 ptr = &TREE_CHAIN (parm_decl);
1508 /* Add parm_decl to the decl_map. */
1509 push_jvm_slot (i, parm_decl);
1511 type_map[i] = TREE_TYPE (parm_decl);
1512 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1514 i++;
1515 type_map[i] = void_type_node;
1518 *ptr = NULL_TREE;
1519 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1521 while (i < DECL_MAX_LOCALS(fndecl))
1522 type_map[i++] = NULL_TREE;
1524 complete_start_java_method (fndecl);
1527 void
1528 end_java_method ()
1530 tree fndecl = current_function_decl;
1532 expand_end_bindings (getdecls (), 1, 0);
1533 /* pop out of function */
1534 poplevel (1, 1, 0);
1536 /* pop out of its parameters */
1537 poplevel (1, 0, 1);
1539 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1541 emit_handlers ();
1543 /* Generate rtl for function exit. */
1544 expand_function_end (input_filename, lineno, 0);
1546 /* Run the optimizers and output assembler code for this function. */
1547 rest_of_compilation (fndecl);
1549 current_function_decl = NULL_TREE;
1550 permanent_allocation (1);
1553 tree
1554 build_decl_no_layout (code, name, type)
1555 enum tree_code code;
1556 tree name, type;
1558 tree decl = build_decl (TYPE_DECL, name, type);
1559 TREE_SET_CODE (decl, code);
1560 return decl;