1 /* Process declarations and variables for the GNU compiler for the
4 Copyright (C) 1996, 97-99, 2000 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)
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. */
34 #include "java-tree.h"
40 #include "java-except.h"
42 #if defined (DEBUG_JAVA_BINDING_LEVELS)
43 extern void indent PROTO((void));
46 static tree push_jvm_slot PARAMS ((int, tree));
47 static tree lookup_name_current_level PARAMS ((tree));
48 static tree push_promoted_type PARAMS ((const char *, tree));
49 static struct binding_level *make_binding_level PARAMS ((void));
52 #define INT_TYPE_SIZE BITS_PER_WORD
55 /* The DECL_MAP is a mapping from (index, type) to a decl node.
56 If index < max_locals, it is the index of a local variable.
57 if index >= max_locals, then index-max_locals is a stack slot.
58 The DECL_MAP mapping is represented as a TREE_VEC whose elements
59 are a list of decls (VAR_DECL or PARM_DECL) chained by
60 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
61 we search the chain for a decl with a matching TREE_TYPE. */
65 /* A list of local variables VAR_DECLs for this method that we have seen
66 debug information, but we have not reached their starting (byte) PC yet. */
68 tree pending_local_decls = NULL_TREE;
70 /* Push a local variable or stack slot into the decl_map,
71 and assign it an rtl. */
73 #if defined(DEBUG_JAVA_BINDING_LEVELS)
74 int binding_depth = 0;
75 int is_class_level = 0;
83 for (i = 0; i < binding_depth*2; i++)
86 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
89 push_jvm_slot (index, decl)
93 struct rtx_def *rtl = NULL;
94 tree type = TREE_TYPE (decl);
97 DECL_CONTEXT (decl) = current_function_decl;
98 layout_decl (decl, 0);
100 /* See if we have an appropriate rtl (i.e. same mode) at this index.
101 If so, we must use it. */
102 tmp = TREE_VEC_ELT (decl_map, index);
103 while (tmp != NULL_TREE)
105 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
106 rtl = DECL_RTL (tmp);
109 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
112 DECL_RTL (decl) = rtl;
115 if (index >= DECL_MAX_LOCALS (current_function_decl))
116 DECL_REGISTER (decl) = 1;
120 /* Now link the decl into the decl_map. */
121 if (DECL_LANG_SPECIFIC (decl) == NULL)
123 DECL_LANG_SPECIFIC (decl)
124 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
125 DECL_LOCAL_START_PC (decl) = 0;
126 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
127 DECL_LOCAL_SLOT_NUMBER (decl) = index;
129 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
130 TREE_VEC_ELT (decl_map, index) = decl;
134 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
135 that is valid at PC (or -1 if any pc).
136 If there is no existing matching decl, allocate one.
137 If we find a decl with matching modes but different types,
138 we re-use the rtl, but create a new decl. */
141 find_local_variable (index, type, pc)
146 tree decl = TREE_VEC_ELT (decl_map, index);
147 tree best = NULL_TREE;
148 while (decl != NULL_TREE)
152 || (pc >= DECL_LOCAL_START_PC (decl)
153 && pc < DECL_LOCAL_END_PC (decl));
155 if ((TREE_TYPE (decl) == type
156 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
157 && type == ptr_type_node))
160 if (best == NULL_TREE
161 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
162 || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
163 || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
166 decl = DECL_LOCAL_SLOT_CHAIN (decl);
168 if (best != NULL_TREE)
170 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
174 /* Same as find_local_index, except that INDEX is a stack index. */
177 find_stack_slot (index, type)
181 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
187 /* A chain of _DECL nodes for all variables, constants, functions,
188 * and typedef types. These are in the reverse of the order supplied.
192 /* For each level, a list of shadowed outer-level local definitions
193 to be restored when this level is popped.
194 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
195 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
198 /* For each level (except not the global one),
199 a chain of BLOCK nodes for all the levels
200 that were entered and exited one level down. */
203 /* The BLOCK node for this level, if one has been preallocated.
204 If 0, the BLOCK is allocated (if needed) when the level is popped. */
207 /* The binding level which this one is contained in (inherits from). */
208 struct binding_level *level_chain;
210 /* 1 means make a BLOCK for this level regardless of all else.
211 2 for temporary binding contours created by the compiler. */
214 /* Nonzero means make a BLOCK if this level has any subblocks. */
215 char keep_if_subblocks;
217 /* Nonzero if this level can safely have additional
218 cleanup-needing variables added to it. */
219 char more_cleanups_ok;
222 /* The bytecode PC that marks the end of this level. */
224 /* The bytecode PC that marks the start of this level. */
227 #if defined(DEBUG_JAVA_BINDING_LEVELS)
228 /* Binding depth at which this level began. */
229 unsigned binding_depth;
230 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
233 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
235 /* The binding level currently in effect. */
237 static struct binding_level *current_binding_level;
239 /* A chain of binding_level structures awaiting reuse. */
241 static struct binding_level *free_binding_level;
243 /* The outermost binding level, for names of file scope.
244 This is created when the compiler is started and exists
245 through the entire run. */
247 static struct binding_level *global_binding_level;
249 /* A PC value bigger than any PC value we may ever may encounter. */
251 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
253 /* Binding level structures are initialized by copying this one. */
255 static struct binding_level clear_binding_level
256 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
257 NULL_BINDING_LEVEL, 0, 0, 0, 0, LARGEST_PC, 0};
260 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
261 that have names. Here so we can clear out their names' definitions
262 at the end of the function. */
264 static tree named_labels;
266 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
268 static tree shadowed_labels;
271 int flag_traditional;
273 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
275 static int keep_next_level_flag;
277 /* Nonzero means make a BLOCK for the next level pushed
278 if it has subblocks. */
280 static int keep_next_if_subblocks;
282 /* The FUNCTION_DECL for the function currently being compiled,
283 or 0 if between functions. */
284 tree current_function_decl;
286 tree object_type_node;
287 tree unqualified_object_id_node;
288 tree object_ptr_type_node;
289 tree string_type_node;
290 tree string_ptr_type_node;
291 tree throwable_type_node;
292 tree runtime_exception_type_node;
293 tree error_exception_type_node;
294 tree *predef_filenames;
295 int predef_filenames_size;
297 tree boolean_type_node;
299 tree return_address_type_node;
302 tree short_type_node;
306 tree promoted_byte_type_node;
307 tree promoted_short_type_node;
308 tree promoted_char_type_node;
309 tree promoted_boolean_type_node;
311 tree unsigned_byte_type_node;
312 tree unsigned_short_type_node;
313 tree unsigned_int_type_node;
314 tree unsigned_long_type_node;
316 /* The type for struct methodtable. */
317 tree methodtable_type;
318 tree methodtable_ptr_type;
321 tree utf8const_ptr_type;
322 tree class_type_node;
324 tree field_type_node;
325 tree field_ptr_type_node;
326 tree field_info_union_node;
327 tree jexception_type;
328 tree jexception_ptr_type;
329 tree lineNumberEntry_type;
330 tree lineNumbers_type;
331 tree constants_type_node;
333 tree dtable_ptr_type;
334 tree method_type_node;
335 tree method_ptr_type_node;
336 tree nativecode_ptr_array_type_node;
337 tree one_elt_array_domain_type;
338 tree access_flags_type_node;
339 tree class_dtable_decl;
341 /* Expressions that are constants with value zero, of types
342 `long', `float' and `double'. */
344 tree float_zero_node;
345 tree double_zero_node;
347 tree empty_stmt_node;
349 /* Nodes for boolean constants TRUE and FALSE. */
350 tree boolean_true_node, boolean_false_node;
352 tree TYPE_identifier_node;
353 tree init_identifier_node;
354 tree clinit_identifier_node;
355 tree finit_identifier_node;
356 tree void_signature_node;
357 tree length_identifier_node;
358 tree this_identifier_node;
359 tree super_identifier_node;
360 tree continue_identifier_node;
362 tree end_params_node;
364 /* References to internal libjava functions we use. */
365 tree alloc_object_node;
366 tree soft_instanceof_node;
367 tree soft_checkcast_node;
368 tree soft_initclass_node;
369 tree soft_newarray_node;
370 tree soft_anewarray_node;
371 tree soft_multianewarray_node;
372 tree soft_badarrayindex_node;
374 tree soft_checkarraystore_node;
375 tree soft_monitorenter_node;
376 tree soft_monitorexit_node;
377 tree soft_lookupinterfacemethod_node;
379 tree soft_exceptioninfo_call_node;
385 /* Build (and pushdecl) a "promoted type" for all standard
386 types shorter than int. */
389 push_promoted_type (name, actual_type)
393 tree type = make_node (TREE_CODE (actual_type));
395 tree in_min = TYPE_MIN_VALUE (int_type_node);
396 tree in_max = TYPE_MAX_VALUE (int_type_node);
398 tree in_min = TYPE_MIN_VALUE (actual_type);
399 tree in_max = TYPE_MAX_VALUE (actual_type);
401 TYPE_MIN_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_min),
402 TREE_INT_CST_HIGH (in_min));
403 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
404 TYPE_MAX_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_max),
405 TREE_INT_CST_HIGH (in_max));
406 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
407 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
409 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
413 /* Nodes for integer constants. */
414 tree integer_two_node, integer_four_node;
415 tree integer_negative_one_node;
417 /* Return a definition for a builtin function named NAME and whose data type
418 is TYPE. TYPE should be a function type with argument types.
419 FUNCTION_CODE tells later passes how to compile calls to this function.
420 See tree.h for its possible values.
422 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
423 the name to be called if we can't opencode the function. */
426 builtin_function (name, type, function_code, class, library_name)
430 enum built_in_class class;
431 const char *library_name;
433 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
434 DECL_EXTERNAL (decl) = 1;
435 TREE_PUBLIC (decl) = 1;
437 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
438 make_decl_rtl (decl, NULL_PTR, 1);
440 DECL_BUILT_IN_CLASS (decl) = class;
441 DECL_FUNCTION_CODE (decl) = function_code;
446 init_decl_processing ()
448 register tree endlink;
449 tree field = NULL_TREE;
452 current_function_decl = NULL;
453 current_binding_level = NULL_BINDING_LEVEL;
454 free_binding_level = NULL_BINDING_LEVEL;
455 pushlevel (0); /* make the binding_level structure for global names */
456 global_binding_level = current_binding_level;
458 error_mark_node = make_node (ERROR_MARK);
459 TREE_TYPE (error_mark_node) = error_mark_node;
461 /* Create sizetype first - needed for other types. */
462 sizetype = make_unsigned_type (POINTER_SIZE);
463 size_zero_node = build_int_2 (0, 0);
464 TREE_TYPE (size_zero_node) = sizetype;
465 size_one_node = build_int_2 (1, 0);
466 TREE_TYPE (size_one_node) = sizetype;
468 byte_type_node = make_signed_type (8);
469 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
470 short_type_node = make_signed_type (16);
471 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
472 int_type_node = make_signed_type (32);
473 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
474 long_type_node = make_signed_type (64);
475 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
477 unsigned_byte_type_node = make_unsigned_type (8);
478 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
479 unsigned_byte_type_node));
480 unsigned_short_type_node = make_unsigned_type (16);
481 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
482 unsigned_short_type_node));
483 unsigned_int_type_node = make_unsigned_type (32);
484 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
485 unsigned_int_type_node));
486 unsigned_long_type_node = make_unsigned_type (64);
487 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
488 unsigned_long_type_node));
490 integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
492 integer_zero_node = build_int_2 (0, 0);
493 integer_one_node = build_int_2 (1, 0);
494 integer_two_node = build_int_2 (2, 0);
495 integer_four_node = build_int_2 (4, 0);
496 integer_negative_one_node = build_int_2 (-1, 0);
498 long_zero_node = build_int_2 (0, 0);
499 TREE_TYPE (long_zero_node) = long_type_node;
501 void_type_node = make_node (VOID_TYPE);
502 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
503 layout_type (void_type_node); /* Uses size_zero_node */
504 ptr_type_node = build_pointer_type (void_type_node);
505 t = make_node (VOID_TYPE);
506 layout_type (t); /* Uses size_zero_node */
507 return_address_type_node = build_pointer_type (t);
509 null_pointer_node = build_int_2 (0, 0);
510 TREE_TYPE (null_pointer_node) = ptr_type_node;
512 /* Used by the parser to represent empty statements and blocks. */
513 empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
514 CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
517 /* Make a type to be the domain of a few array types
518 whose domains don't really matter.
519 200 is small enough that it always fits in size_t
520 and large enough that it can hold most function names for the
521 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
522 short_array_type_node = build_prim_array_type (short_type_node, 200);
524 char_type_node = make_node (CHAR_TYPE);
525 TYPE_PRECISION (char_type_node) = 16;
526 fixup_unsigned_type (char_type_node);
527 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
529 boolean_type_node = make_node (BOOLEAN_TYPE);
530 TYPE_PRECISION (boolean_type_node) = 1;
531 fixup_unsigned_type (boolean_type_node);
532 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
534 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
535 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
537 promoted_byte_type_node
538 = push_promoted_type ("promoted_byte", byte_type_node);
539 promoted_short_type_node
540 = push_promoted_type ("promoted_short", short_type_node);
541 promoted_char_type_node
542 = push_promoted_type ("promoted_char", char_type_node);
543 promoted_boolean_type_node
544 = push_promoted_type ("promoted_boolean", boolean_type_node);
546 float_type_node = make_node (REAL_TYPE);
547 TYPE_PRECISION (float_type_node) = 32;
548 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
550 layout_type (float_type_node);
552 double_type_node = make_node (REAL_TYPE);
553 TYPE_PRECISION (double_type_node) = 64;
554 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
556 layout_type (double_type_node);
558 float_zero_node = build_real (float_type_node, dconst0);
559 double_zero_node = build_real (double_type_node, dconst0);
561 /* As your adding items here, please update the code right after
562 this section, so that the filename containing the source code of
563 the pre-defined class gets registered correctly. */
564 unqualified_object_id_node = get_identifier ("Object");
565 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
566 object_ptr_type_node = promote_type (object_type_node);
567 string_type_node = lookup_class (get_identifier ("java.lang.String"));
568 string_ptr_type_node = promote_type (string_type_node);
569 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
570 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
571 runtime_exception_type_node =
572 lookup_class (get_identifier ("java.lang.RuntimeException"));
573 error_exception_type_node =
574 lookup_class (get_identifier ("java.lang.Error"));
576 /* This section has to be updated as items are added to the previous
578 predef_filenames_size = 6;
579 predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
580 predef_filenames [0] = get_identifier ("java/lang/Class.java");
581 predef_filenames [1] = get_identifier ("java/lang/Error.java");
582 predef_filenames [2] = get_identifier ("java/lang/Object.java");
583 predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
584 predef_filenames [4] = get_identifier ("java/lang/String.java");
585 predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
587 methodtable_type = make_node (RECORD_TYPE);
588 layout_type (methodtable_type);
589 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
590 methodtable_ptr_type = build_pointer_type (methodtable_type);
592 TYPE_identifier_node = get_identifier ("TYPE");
593 init_identifier_node = get_identifier ("<init>");
594 clinit_identifier_node = get_identifier ("<clinit>");
595 finit_identifier_node = get_identifier ("$finit$");
596 void_signature_node = get_identifier ("()V");
597 length_identifier_node = get_identifier ("length");
598 this_identifier_node = get_identifier ("this");
599 super_identifier_node = get_identifier ("super");
600 continue_identifier_node = get_identifier ("continue");
602 /* for lack of a better place to put this stub call */
603 init_expr_processing();
605 utf8const_type = make_node (RECORD_TYPE);
606 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
607 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
608 FINISH_RECORD (utf8const_type);
609 utf8const_ptr_type = build_pointer_type (utf8const_type);
611 constants_type_node = make_node (RECORD_TYPE);
612 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
613 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
614 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
615 FINISH_RECORD (constants_type_node);
616 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
618 access_flags_type_node = unsigned_short_type_node;
620 dtable_type = make_node (RECORD_TYPE);
621 dtable_ptr_type = build_pointer_type (dtable_type);
623 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
624 PUSH_FIELD (object_type_node, field, "sync_info", ptr_type_node);
625 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
626 FIELD_PRIVATE (t) = 1;
627 FINISH_RECORD (object_type_node);
629 class_dtable_decl = build_dtable_decl (class_type_node);
630 TREE_STATIC (class_dtable_decl) = 1;
631 DECL_ARTIFICIAL (class_dtable_decl) = 1;
632 DECL_IGNORED_P (class_dtable_decl) = 1;
633 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
635 field_type_node = make_node (RECORD_TYPE);
636 field_ptr_type_node = build_pointer_type (field_type_node);
637 method_type_node = make_node (RECORD_TYPE);
638 method_ptr_type_node = build_pointer_type (method_type_node);
640 set_super_info (0, class_type_node, object_type_node, 0);
641 set_super_info (0, string_type_node, object_type_node, 0);
642 class_ptr_type = build_pointer_type (class_type_node);
644 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
645 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
646 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
647 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
648 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
649 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
650 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
651 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
652 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
653 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
654 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
655 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
656 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
657 PUSH_FIELD (class_type_node, field, "interfaces",
658 build_pointer_type (class_ptr_type));
659 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
660 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
661 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
662 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
663 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
664 FIELD_PRIVATE (t) = 1;
665 push_super_field (class_type_node, object_type_node);
666 FINISH_RECORD (class_type_node);
667 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
669 field_info_union_node = make_node (UNION_TYPE);
670 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
671 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
673 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
675 layout_type (field_info_union_node);
677 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
678 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
679 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
680 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
681 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
682 FINISH_RECORD (field_type_node);
683 CLASS_LOADED_P (field_type_node) = 1;
684 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
686 one_elt_array_domain_type = build_index_type (integer_one_node);
687 nativecode_ptr_array_type_node
688 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
690 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
691 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
692 FINISH_RECORD (dtable_type);
693 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
695 #define jint_type int_type_node
696 #define jint_ptr_type ptr_type_node
698 jexception_type = make_node (RECORD_TYPE);
699 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
700 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
701 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
702 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
703 FINISH_RECORD (jexception_type);
704 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
705 jexception_ptr_type = build_pointer_type (jexception_type);
707 lineNumberEntry_type = make_node (RECORD_TYPE);
708 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
709 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
710 FINISH_RECORD (lineNumberEntry_type);
712 lineNumbers_type = make_node (RECORD_TYPE);
713 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
714 FINISH_RECORD (lineNumbers_type);
716 #define instn_ptr_type_node ptr_type_node /* XXX JH */
718 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
720 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
721 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
722 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
723 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
724 FINISH_RECORD (method_type_node);
725 CLASS_LOADED_P (method_type_node) = 1;
726 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
728 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
730 t = tree_cons (NULL_TREE, class_ptr_type,
731 tree_cons (NULL_TREE, int_type_node, endlink));
732 alloc_object_node = builtin_function ("_Jv_AllocObject",
733 build_function_type (ptr_type_node, t),
734 0, NOT_BUILT_IN, NULL_PTR);
735 DECL_IS_MALLOC (alloc_object_node) = 1;
736 soft_initclass_node = builtin_function ("_Jv_InitClass",
737 build_function_type (void_type_node,
741 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
742 throw_node[0] = builtin_function ("_Jv_Throw",
743 build_function_type (ptr_type_node, t),
744 0, NOT_BUILT_IN, NULL_PTR);
745 /* Mark throw_nodes as `noreturn' functions with side effects. */
746 TREE_THIS_VOLATILE (throw_node[0]) = 1;
747 TREE_SIDE_EFFECTS (throw_node[0]) = 1;
748 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
749 throw_node[1] = builtin_function ("_Jv_Sjlj_Throw",
750 build_function_type (ptr_type_node, t),
751 0, NOT_BUILT_IN, NULL_PTR);
752 TREE_THIS_VOLATILE (throw_node[1]) = 1;
753 TREE_SIDE_EFFECTS (throw_node[1]) = 1;
754 t = build_function_type (int_type_node, endlink);
755 soft_monitorenter_node
756 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
758 soft_monitorexit_node
759 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
762 t = tree_cons (NULL_TREE, int_type_node,
763 tree_cons (NULL_TREE, int_type_node, endlink));
765 = builtin_function ("_Jv_NewArray",
766 build_function_type(ptr_type_node, t),
767 0, NOT_BUILT_IN, NULL_PTR);
768 DECL_IS_MALLOC (soft_newarray_node) = 1;
770 t = tree_cons (NULL_TREE, int_type_node,
771 tree_cons (NULL_TREE, class_ptr_type,
772 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
774 = builtin_function ("_Jv_NewObjectArray",
775 build_function_type (ptr_type_node, t),
776 0, NOT_BUILT_IN, NULL_PTR);
777 DECL_IS_MALLOC (soft_anewarray_node) = 1;
779 t = tree_cons (NULL_TREE, ptr_type_node,
780 tree_cons (NULL_TREE, int_type_node, endlink));
781 soft_multianewarray_node
782 = builtin_function ("_Jv_NewMultiArray",
783 build_function_type (ptr_type_node, t),
784 0, NOT_BUILT_IN, NULL_PTR);
785 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
787 t = build_function_type (void_type_node,
788 tree_cons (NULL_TREE, int_type_node, endlink));
789 soft_badarrayindex_node
790 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
791 0, NOT_BUILT_IN, NULL_PTR);
792 /* Mark soft_badarrayindex_node as a `noreturn' function with side
794 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
795 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
797 t = tree_cons (NULL_TREE, class_ptr_type,
798 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
800 = builtin_function ("_Jv_CheckCast",
801 build_function_type (ptr_type_node, t),
802 0, NOT_BUILT_IN, NULL_PTR);
803 t = tree_cons (NULL_TREE, object_ptr_type_node,
804 tree_cons (NULL_TREE, class_ptr_type, endlink));
806 = builtin_function ("_Jv_IsInstanceOf",
807 build_function_type (boolean_type_node, t),
808 0, NOT_BUILT_IN, NULL_PTR);
809 t = tree_cons (NULL_TREE, object_ptr_type_node,
810 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
811 soft_checkarraystore_node
812 = builtin_function ("_Jv_CheckArrayStore",
813 build_function_type (void_type_node, t),
814 0, NOT_BUILT_IN, NULL_PTR);
815 t = tree_cons (NULL_TREE, ptr_type_node,
816 tree_cons (NULL_TREE, ptr_type_node,
817 tree_cons (NULL_TREE, ptr_type_node, endlink)));
818 soft_lookupinterfacemethod_node
819 = builtin_function ("_Jv_LookupInterfaceMethod",
820 build_function_type (ptr_type_node, t),
821 0, NOT_BUILT_IN, NULL_PTR);
822 t = tree_cons (NULL_TREE, double_type_node,
823 tree_cons (NULL_TREE, double_type_node, endlink));
825 = builtin_function ("__builtin_fmod",
826 build_function_type (double_type_node, t),
827 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod");
829 soft_exceptioninfo_call_node
833 (builtin_function ("_Jv_exception_info",
834 build_function_type (ptr_type_node, endlink),
835 0, NOT_BUILT_IN, NULL_PTR)),
836 NULL_TREE, NULL_TREE);
837 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
839 t = tree_cons (NULL_TREE, float_type_node,
840 tree_cons (NULL_TREE, float_type_node, endlink));
842 = builtin_function ("__builtin_fmodf",
843 build_function_type (float_type_node, t),
844 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf");
848 = builtin_function ("_Jv_divI",
849 build_function_type (int_type_node, t),
850 0, NOT_BUILT_IN, NULL_PTR);
853 = builtin_function ("_Jv_remI",
854 build_function_type (int_type_node, t),
855 0, NOT_BUILT_IN, NULL_PTR);
858 = builtin_function ("_Jv_divJ",
859 build_function_type (long_type_node, t),
860 0, NOT_BUILT_IN, NULL_PTR);
863 = builtin_function ("_Jv_remJ",
864 build_function_type (long_type_node, t),
865 0, NOT_BUILT_IN, NULL_PTR);
867 init_class_processing ();
871 /* Look up NAME in the current binding level and its superiors
872 in the namespace of variables, functions and typedefs.
873 Return a ..._DECL node of some kind representing its definition,
874 or return 0 if it is undefined. */
881 if (current_binding_level != global_binding_level
882 && IDENTIFIER_LOCAL_VALUE (name))
883 val = IDENTIFIER_LOCAL_VALUE (name);
885 val = IDENTIFIER_GLOBAL_VALUE (name);
889 /* Similar to `lookup_name' but look only at current binding level and
890 the previous one if its the parameter level. */
893 lookup_name_current_level (name)
898 if (current_binding_level == global_binding_level)
899 return IDENTIFIER_GLOBAL_VALUE (name);
901 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
904 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
905 if (DECL_NAME (t) == name)
911 /* Use a binding level to record a labeled block declaration */
914 push_labeled_block (lb)
917 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
918 register struct binding_level *b = current_binding_level;
919 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
921 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
922 TREE_CHAIN (lb) = b->names;
924 IDENTIFIER_LOCAL_VALUE (name) = lb;
927 /* Pop the current binding level, reinstalling values for the previous
933 struct binding_level *b = current_binding_level;
934 tree label = b->names;
935 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
938 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
939 TREE_VALUE (b->shadowed);
941 /* Pop the current level, and free the structure for reuse. */
942 current_binding_level = current_binding_level->level_chain;
943 b->level_chain = free_binding_level;
944 free_binding_level = b;
947 /* Record a decl-node X as belonging to the current lexical scope.
948 Check for errors (such as an incompatible declaration for the same
949 name already seen in the same scope).
951 Returns either X or an old decl for the same name.
952 If an old decl is returned, it may have been smashed
953 to agree with what X says. */
960 register tree name = DECL_NAME (x);
961 register struct binding_level *b = current_binding_level;
963 DECL_CONTEXT (x) = current_function_decl;
969 t = lookup_name_current_level (name);
970 if (t != 0 && t == error_mark_node)
971 /* error_mark_node is 0 for a while during initialization! */
974 error_with_decl (x, "`%s' used prior to declaration");
979 file = DECL_SOURCE_FILE (t);
980 line = DECL_SOURCE_LINE (t);
983 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
984 to point to the TYPE_DECL.
985 Since Java does not have typedefs, a type can only have
986 one (true) name, given by a class, interface, or builtin. */
987 if (TREE_CODE (x) == TYPE_DECL
988 && TYPE_NAME (TREE_TYPE (x)) == 0
989 && TREE_TYPE (x) != error_mark_node)
991 TYPE_NAME (TREE_TYPE (x)) = x;
992 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
995 /* This name is new in its binding level.
996 Install the new declaration and return it. */
997 if (b == global_binding_level)
999 /* Install a global value. */
1001 IDENTIFIER_GLOBAL_VALUE (name) = x;
1005 /* Here to install a non-global value. */
1006 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1007 IDENTIFIER_LOCAL_VALUE (name) = x;
1010 /* Warn if shadowing an argument at the top level of the body. */
1011 if (oldlocal != 0 && !DECL_EXTERNAL (x)
1012 /* This warning doesn't apply to the parms of a nested fcn. */
1013 && ! current_binding_level->parm_flag
1014 /* Check that this is one level down from the parms. */
1015 && current_binding_level->level_chain->parm_flag
1016 /* Check that the decl being shadowed
1017 comes from the parm level, one level up. */
1018 && chain_member (oldlocal, current_binding_level->level_chain->names))
1020 if (TREE_CODE (oldlocal) == PARM_DECL)
1021 pedwarn ("declaration of `%s' shadows a parameter",
1022 IDENTIFIER_POINTER (name));
1024 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1025 IDENTIFIER_POINTER (name));
1028 /* Maybe warn if shadowing something else. */
1029 else if (warn_shadow && !DECL_EXTERNAL (x)
1030 /* No shadow warnings for internally generated vars. */
1031 && DECL_SOURCE_LINE (x) != 0
1032 /* No shadow warnings for vars made for inlining. */
1033 && ! DECL_FROM_INLINE (x))
1035 const char *warnstring = 0;
1037 if (TREE_CODE (x) == PARM_DECL
1038 && current_binding_level->level_chain->parm_flag)
1039 /* Don't warn about the parm names in function declarator
1040 within a function declarator.
1041 It would be nice to avoid warning in any function
1042 declarator in a declaration, as opposed to a definition,
1043 but there is no way to tell it's not a definition. */
1045 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1046 warnstring = "declaration of `%s' shadows a parameter";
1047 else if (oldlocal != 0)
1048 warnstring = "declaration of `%s' shadows previous local";
1049 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1050 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1051 warnstring = "declaration of `%s' shadows global declaration";
1054 warning (warnstring, IDENTIFIER_POINTER (name));
1058 /* If storing a local value, there may already be one (inherited).
1059 If so, record it for restoration when this binding level ends. */
1061 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1065 /* Put decls on list in reverse order.
1066 We will reverse them later if necessary. */
1067 TREE_CHAIN (x) = b->names;
1073 pushdecl_force_head (x)
1076 current_binding_level->names = x;
1079 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1082 pushdecl_top_level (x)
1086 register struct binding_level *b = current_binding_level;
1088 current_binding_level = global_binding_level;
1090 current_binding_level = b;
1094 /* Nonzero if we are currently in the global binding level. */
1097 global_bindings_p ()
1099 return current_binding_level == global_binding_level;
1102 /* Return the list of declarations of the current level.
1103 Note that this list is in reverse order unless/until
1104 you nreverse it; and when you do nreverse it, you must
1105 store the result back using `storedecls' or you will lose. */
1110 return current_binding_level->names;
1113 /* Create a new `struct binding_level'. */
1116 struct binding_level *
1117 make_binding_level ()
1120 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1125 int unused ATTRIBUTE_UNUSED;
1127 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1130 /* If this is the top level of a function,
1131 just make sure that NAMED_LABELS is 0. */
1133 if (current_binding_level == global_binding_level)
1137 /* Reuse or create a struct for this binding level. */
1139 if (free_binding_level)
1141 newlevel = free_binding_level;
1142 free_binding_level = free_binding_level->level_chain;
1146 newlevel = make_binding_level ();
1149 /* Add this level to the front of the chain (stack) of levels that
1152 *newlevel = clear_binding_level;
1153 newlevel->level_chain = current_binding_level;
1154 current_binding_level = newlevel;
1155 newlevel->keep = keep_next_level_flag;
1156 keep_next_level_flag = 0;
1157 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1158 keep_next_if_subblocks = 0;
1159 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1160 newlevel->binding_depth = binding_depth;
1162 fprintf (stderr, "push %s level 0x%08x pc %d\n",
1163 (is_class_level) ? "class" : "block", newlevel, current_pc);
1166 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1169 /* Exit a binding level.
1170 Pop the level off, and restore the state of the identifier-decl mappings
1171 that were in effect when this level was entered.
1173 If KEEP is nonzero, this level had explicit declarations, so
1174 and create a "block" (a BLOCK node) for the level
1175 to record its declarations and subblocks for symbol table output.
1177 If FUNCTIONBODY is nonzero, this level is the body of a function,
1178 so create a block as if KEEP were set and also clear out all
1181 If REVERSE is nonzero, reverse the order of decls before putting
1182 them into the BLOCK. */
1185 poplevel (keep, reverse, functionbody)
1191 /* The chain of decls was accumulated in reverse order.
1192 Put it into forward order, just for cleanliness. */
1194 tree subblocks = current_binding_level->blocks;
1197 int block_previously_created;
1199 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1202 if (current_binding_level->end_pc != LARGEST_PC)
1203 fprintf (stderr, "pop %s level 0x%08x pc %d (end pc %d)\n",
1204 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1205 current_binding_level->end_pc);
1207 fprintf (stderr, "pop %s level 0x%08x pc %d\n",
1208 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1210 if (is_class_level != (current_binding_level == class_binding_level))
1213 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1217 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1219 keep |= current_binding_level->keep;
1221 /* Get the decls in the order they were written.
1222 Usually current_binding_level->names is in reverse order.
1223 But parameter decls were previously put in forward order. */
1226 current_binding_level->names
1227 = decls = nreverse (current_binding_level->names);
1229 decls = current_binding_level->names;
1231 /* Output any nested inline functions within this block
1232 if they weren't already output. */
1234 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1235 if (TREE_CODE (decl) == FUNCTION_DECL
1236 && ! TREE_ASM_WRITTEN (decl)
1237 && DECL_INITIAL (decl) != 0
1238 && TREE_ADDRESSABLE (decl))
1240 /* If this decl was copied from a file-scope decl
1241 on account of a block-scope extern decl,
1242 propagate TREE_ADDRESSABLE to the file-scope decl.
1244 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1245 true, since then the decl goes through save_for_inline_copying. */
1246 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1247 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1248 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1251 push_function_context ();
1252 output_inline_function (decl);
1253 pop_function_context ();
1257 /* If there were any declarations in that level,
1258 or if this level is a function body,
1259 create a BLOCK to record them for the life of this function. */
1262 block_previously_created = (current_binding_level->this_block != 0);
1263 if (block_previously_created)
1264 block = current_binding_level->this_block;
1265 else if (keep || functionbody
1266 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1267 block = make_node (BLOCK);
1270 BLOCK_VARS (block) = decls;
1271 BLOCK_SUBBLOCKS (block) = subblocks;
1274 /* In each subblock, record that this is its superior. */
1276 for (link = subblocks; link; link = TREE_CHAIN (link))
1277 BLOCK_SUPERCONTEXT (link) = block;
1279 /* Clear out the meanings of the local variables of this level. */
1281 for (link = decls; link; link = TREE_CHAIN (link))
1283 tree name = DECL_NAME (link);
1284 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1286 /* If the ident. was used or addressed via a local extern decl,
1287 don't forget that fact. */
1288 if (DECL_EXTERNAL (link))
1290 if (TREE_USED (link))
1291 TREE_USED (name) = 1;
1292 if (TREE_ADDRESSABLE (link))
1293 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1295 IDENTIFIER_LOCAL_VALUE (name) = 0;
1299 /* Restore all name-meanings of the outer levels
1300 that were shadowed by this level. */
1302 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1303 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1305 /* If the level being exited is the top level of a function,
1306 check over all the labels, and clear out the current
1307 (function local) meanings of their names. */
1311 /* If this is the top level block of a function,
1312 the vars are the function's parameters.
1313 Don't leave them in the BLOCK because they are
1314 found in the FUNCTION_DECL instead. */
1316 BLOCK_VARS (block) = 0;
1318 /* Clear out the definitions of all label names,
1319 since their scopes end here,
1320 and add them to BLOCK_VARS. */
1323 for (link = named_labels; link; link = TREE_CHAIN (link))
1325 register tree label = TREE_VALUE (link);
1327 if (DECL_INITIAL (label) == 0)
1329 error_with_decl (label, "label `%s' used but not defined");
1330 /* Avoid crashing later. */
1331 define_label (input_filename, lineno,
1334 else if (warn_unused && !TREE_USED (label))
1335 warning_with_decl (label, "label `%s' defined but not used");
1336 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1338 /* Put the labels into the "variables" of the
1339 top-level block, so debugger can see them. */
1340 TREE_CHAIN (label) = BLOCK_VARS (block);
1341 BLOCK_VARS (block) = label;
1346 /* Pop the current level, and free the structure for reuse. */
1349 register struct binding_level *level = current_binding_level;
1350 current_binding_level = current_binding_level->level_chain;
1352 level->level_chain = free_binding_level;
1353 free_binding_level = level;
1356 /* Dispose of the block that we just made inside some higher level. */
1358 DECL_INITIAL (current_function_decl) = block;
1361 if (!block_previously_created)
1362 current_binding_level->blocks
1363 = chainon (current_binding_level->blocks, block);
1365 /* If we did not make a block for the level just exited,
1366 any blocks made for inner levels
1367 (since they cannot be recorded as subblocks in that level)
1368 must be carried forward so they will later become subblocks
1369 of something else. */
1371 current_binding_level->blocks
1372 = chainon (current_binding_level->blocks, subblocks);
1374 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1375 binding contour so that they point to the appropriate construct, i.e.
1376 either to the current FUNCTION_DECL node, or else to the BLOCK node
1377 we just constructed.
1379 Note that for tagged types whose scope is just the formal parameter
1380 list for some function type specification, we can't properly set
1381 their TYPE_CONTEXTs here, because we don't have a pointer to the
1382 appropriate FUNCTION_TYPE node readily available to us. For those
1383 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1384 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1385 node which will represent the "scope" for these "parameter list local"
1390 TREE_USED (block) = 1;
1395 maybe_pushlevels (pc)
1398 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1402 while (pending_local_decls != NULL_TREE &&
1403 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1405 tree *ptr = &pending_local_decls;
1407 int end_pc = DECL_LOCAL_END_PC (decl);
1409 while (*ptr != NULL_TREE
1410 && DECL_LOCAL_START_PC (*ptr) <= pc
1411 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1412 ptr = &TREE_CHAIN (*ptr);
1413 pending_local_decls = *ptr;
1416 /* Force non-nested range to be nested in current range. */
1417 if (end_pc > current_binding_level->end_pc)
1418 end_pc = current_binding_level->end_pc;
1420 maybe_start_try (pc, end_pc);
1423 expand_start_bindings (0);
1425 current_binding_level->end_pc = end_pc;
1426 current_binding_level->start_pc = pc;
1427 current_binding_level->names = decl;
1428 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1430 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1434 maybe_start_try (pc, 0);
1438 maybe_poplevels (pc)
1441 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1445 while (current_binding_level->end_pc <= pc)
1447 expand_end_bindings (getdecls (), 1, 0);
1448 maybe_end_try (current_binding_level->start_pc, pc);
1451 maybe_end_try (0, pc);
1454 /* Terminate any binding which began during the range beginning at
1455 start_pc. This tidies up improperly nested local variable ranges
1456 and exception handlers; a variable declared within an exception
1457 range is forcibly terminated when that exception ends. */
1460 force_poplevels (start_pc)
1463 while (current_binding_level->start_pc > start_pc)
1465 if (pedantic && current_binding_level->start_pc > start_pc)
1466 warning_with_decl (current_function_decl,
1467 "In %s: overlapped variable and exception ranges at %d",
1468 current_binding_level->start_pc);
1469 expand_end_bindings (getdecls (), 1, 0);
1474 /* Insert BLOCK at the end of the list of subblocks of the
1475 current binding level. This is used when a BIND_EXPR is expanded,
1476 to handle the BLOCK node inside the BIND_EXPR. */
1479 insert_block (block)
1482 TREE_USED (block) = 1;
1483 current_binding_level->blocks
1484 = chainon (current_binding_level->blocks, block);
1487 /* Set the BLOCK node for the innermost scope
1488 (the one we are currently in). */
1492 register tree block;
1494 current_binding_level->this_block = block;
1497 /* integrate_decl_tree calls this function. */
1500 copy_lang_decl (node)
1504 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1505 : sizeof (struct lang_decl);
1506 struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1507 bcopy ((PTR) DECL_LANG_SPECIFIC (node), (PTR) x, lang_decl_size);
1508 DECL_LANG_SPECIFIC (node) = x;
1511 /* If DECL has a cleanup, build and return that cleanup here.
1512 This is a callback called by expand_expr. */
1515 maybe_build_cleanup (decl)
1516 tree decl ATTRIBUTE_UNUSED;
1518 /* There are no cleanups in Java (I think). */
1523 give_name_to_locals (jcf)
1526 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1528 pending_local_decls = NULL_TREE;
1532 n = JCF_readu2 (jcf);
1533 for (i = 0; i < n; i++)
1535 int start_pc = JCF_readu2 (jcf);
1536 int length = JCF_readu2 (jcf);
1537 int name_index = JCF_readu2 (jcf);
1538 int signature_index = JCF_readu2 (jcf);
1539 int slot = JCF_readu2 (jcf);
1540 tree name = get_name_constant (jcf, name_index);
1541 tree type = parse_signature (jcf, signature_index);
1542 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1544 && length == DECL_CODE_LENGTH (current_function_decl))
1546 tree decl = TREE_VEC_ELT (decl_map, slot);
1547 DECL_NAME (decl) = name;
1548 DECL_ASSEMBLER_NAME (decl) = name;
1549 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1550 warning ("bad type in parameter debug info");
1555 int end_pc = start_pc + length;
1556 tree decl = build_decl (VAR_DECL, name, type);
1557 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1559 warning_with_decl (decl,
1560 "bad PC range for debug info for local `%s'");
1561 end_pc = DECL_CODE_LENGTH (current_function_decl);
1563 DECL_LANG_SPECIFIC (decl)
1564 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1565 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1566 DECL_LOCAL_START_PC (decl) = start_pc;
1568 /* FIXME: The range used internally for exceptions and local
1569 variable ranges, is a half-open interval:
1570 start_pc <= pc < end_pc. However, the range used in the
1571 Java VM spec is inclusive at both ends:
1572 start_pc <= pc <= end_pc. */
1575 DECL_LOCAL_END_PC (decl) = end_pc;
1577 /* Now insert the new decl in the proper place in
1578 pending_local_decls. We are essentially doing an insertion sort,
1579 which works fine, since the list input will normally already
1581 ptr = &pending_local_decls;
1582 while (*ptr != NULL_TREE
1583 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1584 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1585 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1586 ptr = &TREE_CHAIN (*ptr);
1587 TREE_CHAIN (decl) = *ptr;
1592 pending_local_decls = nreverse (pending_local_decls);
1594 /* Fill in default names for the parameters. */
1595 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1596 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1598 if (DECL_NAME (parm) == NULL_TREE)
1600 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1602 DECL_NAME (parm) = get_identifier ("this");
1606 sprintf (buffer, "ARG_%d", arg_i);
1607 DECL_NAME (parm) = get_identifier (buffer);
1609 DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1615 build_result_decl (fndecl)
1618 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1619 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1620 if (INTEGRAL_TYPE_P (restype)
1621 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1622 restype = integer_type_node;
1623 return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
1627 complete_start_java_method (fndecl)
1630 if (! flag_emit_class_files)
1632 /* Initialize the RTL code for the function. */
1633 init_function_start (fndecl, input_filename, lineno);
1635 /* Set up parameters and prepare for return, for the function. */
1636 expand_function_start (fndecl, 0);
1639 /* Allocate further tree nodes temporarily during compilation
1640 of this function only. */
1641 temporary_allocation ();
1644 /* If this fcn was already referenced via a block-scope `extern' decl (or
1645 an implicit decl), propagate certain information about the usage. */
1646 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1647 TREE_ADDRESSABLE (current_function_decl) = 1;
1651 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1652 && ! flag_emit_class_files
1653 && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1655 tree clas = DECL_CONTEXT (fndecl);
1656 tree init = build (CALL_EXPR, void_type_node,
1657 build_address_of (soft_initclass_node),
1658 build_tree_list (NULL_TREE, build_class_ref (clas)),
1660 TREE_SIDE_EFFECTS (init) = 1;
1661 expand_expr_stmt (init);
1664 /* Push local variables. Function compiled from source code are
1665 using a different local variables management, and for them,
1666 pushlevel shouldn't be called from here. */
1667 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1670 if (! flag_emit_class_files)
1671 expand_start_bindings (1);
1674 if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1676 /* Warp function body with a monitorenter plus monitorexit cleanup. */
1677 tree enter, exit, lock;
1678 if (METHOD_STATIC (fndecl))
1679 lock = build_class_ref (DECL_CONTEXT (fndecl));
1681 lock = DECL_ARGUMENTS (fndecl);
1682 BUILD_MONITOR_ENTER (enter, lock);
1683 BUILD_MONITOR_EXIT (exit, lock);
1684 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1686 expand_expr_stmt (enter);
1687 expand_decl_cleanup (NULL_TREE, exit);
1691 tree function_body = DECL_FUNCTION_BODY (fndecl);
1692 tree body = BLOCK_EXPR_BODY (function_body);
1693 lock = build (WITH_CLEANUP_EXPR, void_type_node,
1694 enter, NULL_TREE, exit);
1695 TREE_SIDE_EFFECTS (lock) = 1;
1696 lock = build (COMPOUND_EXPR, TREE_TYPE (body), lock, body);
1697 TREE_SIDE_EFFECTS (lock) = 1;
1698 lock = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (body), lock);
1699 TREE_SIDE_EFFECTS (lock) = 1;
1700 BLOCK_EXPR_BODY (function_body) = lock;
1706 start_java_method (fndecl)
1712 current_function_decl = fndecl;
1713 announce_function (fndecl);
1715 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1716 decl_map = make_tree_vec (i);
1717 type_map = (tree *) oballoc (i * sizeof (tree));
1719 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1720 fprintf (stderr, "%s:\n", (*decl_printable_name) (fndecl, 2));
1722 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1723 pushlevel (1); /* Push parameters. */
1725 ptr = &DECL_ARGUMENTS (fndecl);
1726 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1727 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1729 tree parm_name = NULL_TREE, parm_decl;
1730 tree parm_type = TREE_VALUE (tem);
1731 if (i >= DECL_MAX_LOCALS(fndecl))
1732 fatal ("function has more parameters than local slots");
1734 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1735 DECL_CONTEXT (parm_decl) = fndecl;
1736 if (PROMOTE_PROTOTYPES
1737 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1738 && INTEGRAL_TYPE_P (parm_type))
1739 parm_type = integer_type_node;
1740 DECL_ARG_TYPE (parm_decl) = parm_type;
1743 ptr = &TREE_CHAIN (parm_decl);
1745 /* Add parm_decl to the decl_map. */
1746 push_jvm_slot (i, parm_decl);
1748 type_map[i] = TREE_TYPE (parm_decl);
1749 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1752 type_map[i] = void_type_node;
1756 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1758 while (i < DECL_MAX_LOCALS(fndecl))
1759 type_map[i++] = NULL_TREE;
1761 build_result_decl (fndecl);
1762 complete_start_java_method (fndecl);
1768 tree fndecl = current_function_decl;
1769 int flag_asynchronous_exceptions = asynchronous_exceptions;
1771 expand_end_bindings (getdecls (), 1, 0);
1772 /* pop out of function */
1775 /* pop out of its parameters */
1778 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1782 /* Generate rtl for function exit. */
1783 expand_function_end (input_filename, lineno, 0);
1785 /* FIXME: If the current method contains any exception handlers,
1786 force asynchronous_exceptions: this is necessary because signal
1787 handlers in libjava may throw exceptions. This is far from being
1788 a perfect solution, but it's better than doing nothing at all.*/
1790 asynchronous_exceptions = 1;
1792 /* Run the optimizers and output assembler code for this function. */
1793 rest_of_compilation (fndecl);
1795 current_function_decl = NULL_TREE;
1796 permanent_allocation (1);
1797 asynchronous_exceptions = flag_asynchronous_exceptions;