1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
33 #include "java-tree.h"
39 #include "java-except.h"
41 #if defined (DEBUG_JAVA_BINDING_LEVELS)
42 extern void indent PROTO((void));
45 static tree push_jvm_slot PARAMS ((int, tree));
46 static tree lookup_name_current_level PARAMS ((tree));
47 static tree push_promoted_type PARAMS ((const char *, tree));
48 static struct binding_level *make_binding_level PARAMS ((void));
50 /* Set to non-zero value in order to emit class initilization code
51 before static field references. */
52 extern int always_initialize_class_p;
55 #define INT_TYPE_SIZE BITS_PER_WORD
58 /* The DECL_MAP is a mapping from (index, type) to a decl node.
59 If index < max_locals, it is the index of a local variable.
60 if index >= max_locals, then index-max_locals is a stack slot.
61 The DECL_MAP mapping is represented as a TREE_VEC whose elements
62 are a list of decls (VAR_DECL or PARM_DECL) chained by
63 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
64 we search the chain for a decl with a matching TREE_TYPE. */
68 /* A list of local variables VAR_DECLs for this method that we have seen
69 debug information, but we have not reached their starting (byte) PC yet. */
71 tree pending_local_decls = NULL_TREE;
73 /* Push a local variable or stack slot into the decl_map,
74 and assign it an rtl. */
76 #if defined(DEBUG_JAVA_BINDING_LEVELS)
77 int binding_depth = 0;
78 int is_class_level = 0;
86 for (i = 0; i < binding_depth*2; i++)
89 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
92 push_jvm_slot (index, decl)
96 struct rtx_def *rtl = NULL;
97 tree type = TREE_TYPE (decl);
100 DECL_CONTEXT (decl) = current_function_decl;
101 layout_decl (decl, 0);
103 /* See if we have an appropriate rtl (i.e. same mode) at this index.
104 If so, we must use it. */
105 tmp = TREE_VEC_ELT (decl_map, index);
106 while (tmp != NULL_TREE)
108 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
109 rtl = DECL_RTL (tmp);
112 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
115 DECL_RTL (decl) = rtl;
118 if (index >= DECL_MAX_LOCALS (current_function_decl))
119 DECL_REGISTER (decl) = 1;
123 /* Now link the decl into the decl_map. */
124 if (DECL_LANG_SPECIFIC (decl) == NULL)
126 DECL_LANG_SPECIFIC (decl)
127 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
128 DECL_LOCAL_START_PC (decl) = 0;
129 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
130 DECL_LOCAL_SLOT_NUMBER (decl) = index;
132 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
133 TREE_VEC_ELT (decl_map, index) = decl;
137 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
138 that is valid at PC (or -1 if any pc).
139 If there is no existing matching decl, allocate one. */
142 find_local_variable (index, type, pc)
147 tree decl = TREE_VEC_ELT (decl_map, index);
148 tree best = NULL_TREE;
150 while (decl != NULL_TREE)
154 || (pc >= DECL_LOCAL_START_PC (decl)
155 && pc < DECL_LOCAL_END_PC (decl));
157 if ((TREE_TYPE (decl) == type
158 || (TREE_CODE (TREE_TYPE (decl)) == TREE_CODE (type)
159 && TYPE_PRECISION (TREE_TYPE (decl)) <= 32
160 && TYPE_PRECISION (type) <= 32
161 && TREE_CODE (type) != POINTER_TYPE)
162 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
163 && type == ptr_type_node))
166 if (best == NULL_TREE
167 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
168 || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
169 || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
172 decl = DECL_LOCAL_SLOT_CHAIN (decl);
174 if (best != NULL_TREE)
176 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
180 /* Same as find_local_index, except that INDEX is a stack index. */
183 find_stack_slot (index, type)
187 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
193 /* A chain of _DECL nodes for all variables, constants, functions,
194 * and typedef types. These are in the reverse of the order supplied.
198 /* For each level, a list of shadowed outer-level local definitions
199 to be restored when this level is popped.
200 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
201 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
204 /* For each level (except not the global one),
205 a chain of BLOCK nodes for all the levels
206 that were entered and exited one level down. */
209 /* The BLOCK node for this level, if one has been preallocated.
210 If 0, the BLOCK is allocated (if needed) when the level is popped. */
213 /* The binding level which this one is contained in (inherits from). */
214 struct binding_level *level_chain;
216 /* 1 means make a BLOCK for this level regardless of all else.
217 2 for temporary binding contours created by the compiler. */
220 /* Nonzero means make a BLOCK if this level has any subblocks. */
221 char keep_if_subblocks;
223 /* Nonzero if this level can safely have additional
224 cleanup-needing variables added to it. */
225 char more_cleanups_ok;
228 /* The bytecode PC that marks the end of this level. */
230 /* The bytecode PC that marks the start of this level. */
233 #if defined(DEBUG_JAVA_BINDING_LEVELS)
234 /* Binding depth at which this level began. */
235 unsigned binding_depth;
236 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
239 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
241 /* The binding level currently in effect. */
243 static struct binding_level *current_binding_level;
245 /* A chain of binding_level structures awaiting reuse. */
247 static struct binding_level *free_binding_level;
249 /* The outermost binding level, for names of file scope.
250 This is created when the compiler is started and exists
251 through the entire run. */
253 static struct binding_level *global_binding_level;
255 /* A PC value bigger than any PC value we may ever may encounter. */
257 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
259 /* Binding level structures are initialized by copying this one. */
261 static struct binding_level clear_binding_level
262 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
263 NULL_BINDING_LEVEL, 0, 0, 0, 0, LARGEST_PC, 0};
266 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
267 that have names. Here so we can clear out their names' definitions
268 at the end of the function. */
270 static tree named_labels;
272 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
274 static tree shadowed_labels;
277 int flag_traditional;
279 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
281 static int keep_next_level_flag;
283 /* Nonzero means make a BLOCK for the next level pushed
284 if it has subblocks. */
286 static int keep_next_if_subblocks;
288 tree object_type_node;
289 tree unqualified_object_id_node;
290 tree object_ptr_type_node;
291 tree string_type_node;
292 tree string_ptr_type_node;
293 tree throwable_type_node;
294 tree runtime_exception_type_node;
295 tree error_exception_type_node;
296 tree *predef_filenames;
297 int predef_filenames_size;
299 tree boolean_type_node;
301 tree return_address_type_node;
304 tree short_type_node;
308 tree promoted_byte_type_node;
309 tree promoted_short_type_node;
310 tree promoted_char_type_node;
311 tree promoted_boolean_type_node;
313 tree unsigned_byte_type_node;
314 tree unsigned_short_type_node;
315 tree unsigned_int_type_node;
316 tree unsigned_long_type_node;
318 /* The type for struct methodtable. */
319 tree methodtable_type;
320 tree methodtable_ptr_type;
323 tree utf8const_ptr_type;
324 tree class_type_node;
326 tree field_type_node;
327 tree field_ptr_type_node;
328 tree field_info_union_node;
329 tree jexception_type;
330 tree jexception_ptr_type;
331 tree lineNumberEntry_type;
332 tree lineNumbers_type;
333 tree constants_type_node;
335 tree dtable_ptr_type;
336 tree method_type_node;
337 tree method_ptr_type_node;
338 tree nativecode_ptr_array_type_node;
339 tree one_elt_array_domain_type;
340 tree access_flags_type_node;
341 tree class_dtable_decl;
343 /* Expressions that are constants with value zero, of types
344 `long', `float' and `double'. */
346 tree float_zero_node;
347 tree double_zero_node;
349 tree empty_stmt_node;
351 /* Nodes for boolean constants TRUE and FALSE. */
352 tree boolean_true_node, boolean_false_node;
354 tree TYPE_identifier_node;
355 tree init_identifier_node;
356 tree clinit_identifier_node;
357 tree finit_identifier_node;
358 tree void_signature_node;
359 tree length_identifier_node;
360 tree this_identifier_node;
361 tree super_identifier_node;
362 tree continue_identifier_node;
363 tree access0_identifier_node; /* 1.1 */
364 tree end_params_node;
366 /* References to internal libjava functions we use. */
367 tree alloc_object_node;
368 tree soft_instanceof_node;
369 tree soft_checkcast_node;
370 tree soft_initclass_node;
371 tree soft_newarray_node;
372 tree soft_anewarray_node;
373 tree soft_multianewarray_node;
374 tree soft_badarrayindex_node;
376 tree soft_checkarraystore_node;
377 tree soft_monitorenter_node;
378 tree soft_monitorexit_node;
379 tree soft_lookupinterfacemethod_node;
381 tree soft_exceptioninfo_call_node;
387 /* Build (and pushdecl) a "promoted type" for all standard
388 types shorter than int. */
391 push_promoted_type (name, actual_type)
395 tree type = make_node (TREE_CODE (actual_type));
397 tree in_min = TYPE_MIN_VALUE (int_type_node);
398 tree in_max = TYPE_MAX_VALUE (int_type_node);
400 tree in_min = TYPE_MIN_VALUE (actual_type);
401 tree in_max = TYPE_MAX_VALUE (actual_type);
403 TYPE_MIN_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_min),
404 TREE_INT_CST_HIGH (in_min));
405 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
406 TYPE_MAX_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_max),
407 TREE_INT_CST_HIGH (in_max));
408 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
409 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
411 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
415 /* Nodes for integer constants. */
416 tree integer_two_node, integer_four_node;
417 tree integer_negative_one_node;
419 /* Return a definition for a builtin function named NAME and whose data type
420 is TYPE. TYPE should be a function type with argument types.
421 FUNCTION_CODE tells later passes how to compile calls to this function.
422 See tree.h for its possible values.
424 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
425 the name to be called if we can't opencode the function. */
428 builtin_function (name, type, function_code, class, library_name)
432 enum built_in_class class;
433 const char *library_name;
435 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
436 DECL_EXTERNAL (decl) = 1;
437 TREE_PUBLIC (decl) = 1;
439 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
440 make_decl_rtl (decl, NULL_PTR, 1);
442 DECL_BUILT_IN_CLASS (decl) = class;
443 DECL_FUNCTION_CODE (decl) = function_code;
448 init_decl_processing ()
450 register tree endlink;
451 tree field = NULL_TREE;
454 current_function_decl = NULL;
455 current_binding_level = NULL_BINDING_LEVEL;
456 free_binding_level = NULL_BINDING_LEVEL;
457 pushlevel (0); /* make the binding_level structure for global names */
458 global_binding_level = current_binding_level;
460 error_mark_node = make_node (ERROR_MARK);
461 TREE_TYPE (error_mark_node) = error_mark_node;
463 initialize_sizetypes ();
464 /* Create sizetype first - needed for other types. */
465 initialize_sizetypes ();
466 set_sizetype (make_unsigned_type (POINTER_SIZE));
467 size_zero_node = build_int_2 (0, 0);
468 TREE_TYPE (size_zero_node) = sizetype;
469 size_one_node = build_int_2 (1, 0);
470 TREE_TYPE (size_one_node) = sizetype;
472 byte_type_node = make_signed_type (8);
473 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
474 short_type_node = make_signed_type (16);
475 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
476 int_type_node = make_signed_type (32);
477 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
478 long_type_node = make_signed_type (64);
479 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
481 unsigned_byte_type_node = make_unsigned_type (8);
482 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
483 unsigned_byte_type_node));
484 unsigned_short_type_node = make_unsigned_type (16);
485 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
486 unsigned_short_type_node));
487 unsigned_int_type_node = make_unsigned_type (32);
488 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
489 unsigned_int_type_node));
490 unsigned_long_type_node = make_unsigned_type (64);
491 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
492 unsigned_long_type_node));
494 integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
496 integer_zero_node = build_int_2 (0, 0);
497 integer_one_node = build_int_2 (1, 0);
498 integer_two_node = build_int_2 (2, 0);
499 integer_four_node = build_int_2 (4, 0);
500 integer_negative_one_node = build_int_2 (-1, 0);
502 long_zero_node = build_int_2 (0, 0);
503 TREE_TYPE (long_zero_node) = long_type_node;
505 void_type_node = make_node (VOID_TYPE);
506 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
507 layout_type (void_type_node); /* Uses size_zero_node */
508 ptr_type_node = build_pointer_type (void_type_node);
509 t = make_node (VOID_TYPE);
510 layout_type (t); /* Uses size_zero_node */
511 return_address_type_node = build_pointer_type (t);
513 null_pointer_node = build_int_2 (0, 0);
514 TREE_TYPE (null_pointer_node) = ptr_type_node;
516 /* Used by the parser to represent empty statements and blocks. */
517 empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
518 CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
521 /* Make a type to be the domain of a few array types
522 whose domains don't really matter.
523 200 is small enough that it always fits in size_t
524 and large enough that it can hold most function names for the
525 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
526 short_array_type_node = build_prim_array_type (short_type_node, 200);
528 char_type_node = make_node (CHAR_TYPE);
529 TYPE_PRECISION (char_type_node) = 16;
530 fixup_unsigned_type (char_type_node);
531 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
533 boolean_type_node = make_node (BOOLEAN_TYPE);
534 TYPE_PRECISION (boolean_type_node) = 1;
535 fixup_unsigned_type (boolean_type_node);
536 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
538 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
539 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
541 promoted_byte_type_node
542 = push_promoted_type ("promoted_byte", byte_type_node);
543 promoted_short_type_node
544 = push_promoted_type ("promoted_short", short_type_node);
545 promoted_char_type_node
546 = push_promoted_type ("promoted_char", char_type_node);
547 promoted_boolean_type_node
548 = push_promoted_type ("promoted_boolean", boolean_type_node);
550 float_type_node = make_node (REAL_TYPE);
551 TYPE_PRECISION (float_type_node) = 32;
552 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
554 layout_type (float_type_node);
556 double_type_node = make_node (REAL_TYPE);
557 TYPE_PRECISION (double_type_node) = 64;
558 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
560 layout_type (double_type_node);
562 float_zero_node = build_real (float_type_node, dconst0);
563 double_zero_node = build_real (double_type_node, dconst0);
565 /* As your adding items here, please update the code right after
566 this section, so that the filename containing the source code of
567 the pre-defined class gets registered correctly. */
568 unqualified_object_id_node = get_identifier ("Object");
569 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
570 object_ptr_type_node = promote_type (object_type_node);
571 string_type_node = lookup_class (get_identifier ("java.lang.String"));
572 string_ptr_type_node = promote_type (string_type_node);
573 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
574 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
575 runtime_exception_type_node =
576 lookup_class (get_identifier ("java.lang.RuntimeException"));
577 error_exception_type_node =
578 lookup_class (get_identifier ("java.lang.Error"));
580 /* This section has to be updated as items are added to the previous
582 predef_filenames_size = 6;
583 predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
584 predef_filenames [0] = get_identifier ("java/lang/Class.java");
585 predef_filenames [1] = get_identifier ("java/lang/Error.java");
586 predef_filenames [2] = get_identifier ("java/lang/Object.java");
587 predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
588 predef_filenames [4] = get_identifier ("java/lang/String.java");
589 predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
591 methodtable_type = make_node (RECORD_TYPE);
592 layout_type (methodtable_type);
593 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
594 methodtable_ptr_type = build_pointer_type (methodtable_type);
596 TYPE_identifier_node = get_identifier ("TYPE");
597 init_identifier_node = get_identifier ("<init>");
598 clinit_identifier_node = get_identifier ("<clinit>");
599 finit_identifier_node = get_identifier ("$finit$");
600 void_signature_node = get_identifier ("()V");
601 length_identifier_node = get_identifier ("length");
602 this_identifier_node = get_identifier ("this");
603 super_identifier_node = get_identifier ("super");
604 continue_identifier_node = get_identifier ("continue");
605 access0_identifier_node = get_identifier ("access$0");
607 /* for lack of a better place to put this stub call */
608 init_expr_processing();
610 utf8const_type = make_node (RECORD_TYPE);
611 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
612 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
613 FINISH_RECORD (utf8const_type);
614 utf8const_ptr_type = build_pointer_type (utf8const_type);
616 constants_type_node = make_node (RECORD_TYPE);
617 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
618 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
619 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
620 FINISH_RECORD (constants_type_node);
621 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
623 access_flags_type_node = unsigned_short_type_node;
625 dtable_type = make_node (RECORD_TYPE);
626 dtable_ptr_type = build_pointer_type (dtable_type);
628 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
629 /* This isn't exactly true, but it is what we have in the source.
630 There is an unresolved issue here, which is whether the vtable
631 should be marked by the GC. */
632 PUSH_FIELD (object_type_node, field, "sync_info",
633 build_pointer_type (object_type_node));
634 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
635 FIELD_PRIVATE (t) = 1;
636 FINISH_RECORD (object_type_node);
638 class_dtable_decl = build_dtable_decl (class_type_node);
639 TREE_STATIC (class_dtable_decl) = 1;
640 DECL_ARTIFICIAL (class_dtable_decl) = 1;
641 DECL_IGNORED_P (class_dtable_decl) = 1;
642 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
644 field_type_node = make_node (RECORD_TYPE);
645 field_ptr_type_node = build_pointer_type (field_type_node);
646 method_type_node = make_node (RECORD_TYPE);
647 method_ptr_type_node = build_pointer_type (method_type_node);
649 set_super_info (0, class_type_node, object_type_node, 0);
650 set_super_info (0, string_type_node, object_type_node, 0);
651 class_ptr_type = build_pointer_type (class_type_node);
653 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
654 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
655 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
656 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
657 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
658 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
659 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
660 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
661 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
662 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
663 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
664 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
665 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
666 PUSH_FIELD (class_type_node, field, "interfaces",
667 build_pointer_type (class_ptr_type));
668 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
669 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
670 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
671 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
672 PUSH_FIELD (class_type_node, field, "depth", short_type_node);
673 PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
674 PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
675 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
676 FIELD_PRIVATE (t) = 1;
677 push_super_field (class_type_node, object_type_node);
678 FINISH_RECORD (class_type_node);
679 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
681 field_info_union_node = make_node (UNION_TYPE);
682 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
683 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
685 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
687 layout_type (field_info_union_node);
689 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
690 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
691 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
692 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
693 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
694 FINISH_RECORD (field_type_node);
695 CLASS_LOADED_P (field_type_node) = 1;
696 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
698 one_elt_array_domain_type = build_index_type (integer_one_node);
699 nativecode_ptr_array_type_node
700 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
702 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
703 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
704 FINISH_RECORD (dtable_type);
705 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
707 #define jint_type int_type_node
708 #define jint_ptr_type ptr_type_node
710 jexception_type = make_node (RECORD_TYPE);
711 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
712 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
713 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
714 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
715 FINISH_RECORD (jexception_type);
716 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
717 jexception_ptr_type = build_pointer_type (jexception_type);
719 lineNumberEntry_type = make_node (RECORD_TYPE);
720 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
721 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
722 FINISH_RECORD (lineNumberEntry_type);
724 lineNumbers_type = make_node (RECORD_TYPE);
725 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
726 FINISH_RECORD (lineNumbers_type);
728 #define instn_ptr_type_node ptr_type_node /* XXX JH */
730 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
732 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
733 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
734 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
735 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
736 FINISH_RECORD (method_type_node);
737 CLASS_LOADED_P (method_type_node) = 1;
738 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
740 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
742 t = tree_cons (NULL_TREE, class_ptr_type,
743 tree_cons (NULL_TREE, int_type_node, endlink));
744 alloc_object_node = builtin_function ("_Jv_AllocObject",
745 build_function_type (ptr_type_node, t),
746 0, NOT_BUILT_IN, NULL_PTR);
747 DECL_IS_MALLOC (alloc_object_node) = 1;
748 soft_initclass_node = builtin_function ("_Jv_InitClass",
749 build_function_type (void_type_node,
753 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
754 throw_node[0] = builtin_function ("_Jv_Throw",
755 build_function_type (ptr_type_node, t),
756 0, NOT_BUILT_IN, NULL_PTR);
757 /* Mark throw_nodes as `noreturn' functions with side effects. */
758 TREE_THIS_VOLATILE (throw_node[0]) = 1;
759 TREE_SIDE_EFFECTS (throw_node[0]) = 1;
760 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
761 throw_node[1] = builtin_function ("_Jv_Sjlj_Throw",
762 build_function_type (ptr_type_node, t),
763 0, NOT_BUILT_IN, NULL_PTR);
764 TREE_THIS_VOLATILE (throw_node[1]) = 1;
765 TREE_SIDE_EFFECTS (throw_node[1]) = 1;
766 t = build_function_type (int_type_node, endlink);
767 soft_monitorenter_node
768 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
770 soft_monitorexit_node
771 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
774 t = tree_cons (NULL_TREE, int_type_node,
775 tree_cons (NULL_TREE, int_type_node, endlink));
777 = builtin_function ("_Jv_NewArray",
778 build_function_type(ptr_type_node, t),
779 0, NOT_BUILT_IN, NULL_PTR);
780 DECL_IS_MALLOC (soft_newarray_node) = 1;
782 t = tree_cons (NULL_TREE, int_type_node,
783 tree_cons (NULL_TREE, class_ptr_type,
784 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
786 = builtin_function ("_Jv_NewObjectArray",
787 build_function_type (ptr_type_node, t),
788 0, NOT_BUILT_IN, NULL_PTR);
789 DECL_IS_MALLOC (soft_anewarray_node) = 1;
791 t = tree_cons (NULL_TREE, ptr_type_node,
792 tree_cons (NULL_TREE, int_type_node, endlink));
793 soft_multianewarray_node
794 = builtin_function ("_Jv_NewMultiArray",
795 build_function_type (ptr_type_node, t),
796 0, NOT_BUILT_IN, NULL_PTR);
797 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
799 t = build_function_type (void_type_node,
800 tree_cons (NULL_TREE, int_type_node, endlink));
801 soft_badarrayindex_node
802 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
803 0, NOT_BUILT_IN, NULL_PTR);
804 /* Mark soft_badarrayindex_node as a `noreturn' function with side
806 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
807 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
809 t = tree_cons (NULL_TREE, class_ptr_type,
810 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
812 = builtin_function ("_Jv_CheckCast",
813 build_function_type (ptr_type_node, t),
814 0, NOT_BUILT_IN, NULL_PTR);
815 t = tree_cons (NULL_TREE, object_ptr_type_node,
816 tree_cons (NULL_TREE, class_ptr_type, endlink));
818 = builtin_function ("_Jv_IsInstanceOf",
819 build_function_type (boolean_type_node, t),
820 0, NOT_BUILT_IN, NULL_PTR);
821 t = tree_cons (NULL_TREE, object_ptr_type_node,
822 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
823 soft_checkarraystore_node
824 = builtin_function ("_Jv_CheckArrayStore",
825 build_function_type (void_type_node, t),
826 0, NOT_BUILT_IN, NULL_PTR);
827 t = tree_cons (NULL_TREE, ptr_type_node,
828 tree_cons (NULL_TREE, ptr_type_node,
829 tree_cons (NULL_TREE, int_type_node, endlink)));
830 soft_lookupinterfacemethod_node
831 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
832 build_function_type (ptr_type_node, t),
833 0, NOT_BUILT_IN, NULL_PTR);
834 t = tree_cons (NULL_TREE, double_type_node,
835 tree_cons (NULL_TREE, double_type_node, endlink));
837 = builtin_function ("__builtin_fmod",
838 build_function_type (double_type_node, t),
839 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod");
841 soft_exceptioninfo_call_node
845 (builtin_function ("_Jv_exception_info",
846 build_function_type (ptr_type_node, endlink),
847 0, NOT_BUILT_IN, NULL_PTR)),
848 NULL_TREE, NULL_TREE);
849 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
851 t = tree_cons (NULL_TREE, float_type_node,
852 tree_cons (NULL_TREE, float_type_node, endlink));
854 = builtin_function ("__builtin_fmodf",
855 build_function_type (float_type_node, t),
856 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf");
860 = builtin_function ("_Jv_divI",
861 build_function_type (int_type_node, t),
862 0, NOT_BUILT_IN, NULL_PTR);
865 = builtin_function ("_Jv_remI",
866 build_function_type (int_type_node, t),
867 0, NOT_BUILT_IN, NULL_PTR);
870 = builtin_function ("_Jv_divJ",
871 build_function_type (long_type_node, t),
872 0, NOT_BUILT_IN, NULL_PTR);
875 = builtin_function ("_Jv_remJ",
876 build_function_type (long_type_node, t),
877 0, NOT_BUILT_IN, NULL_PTR);
879 init_class_processing ();
883 /* Look up NAME in the current binding level and its superiors
884 in the namespace of variables, functions and typedefs.
885 Return a ..._DECL node of some kind representing its definition,
886 or return 0 if it is undefined. */
893 if (current_binding_level != global_binding_level
894 && IDENTIFIER_LOCAL_VALUE (name))
895 val = IDENTIFIER_LOCAL_VALUE (name);
897 val = IDENTIFIER_GLOBAL_VALUE (name);
901 /* Similar to `lookup_name' but look only at current binding level and
902 the previous one if its the parameter level. */
905 lookup_name_current_level (name)
910 if (current_binding_level == global_binding_level)
911 return IDENTIFIER_GLOBAL_VALUE (name);
913 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
916 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
917 if (DECL_NAME (t) == name)
923 /* Use a binding level to record a labeled block declaration */
926 push_labeled_block (lb)
929 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
930 register struct binding_level *b = current_binding_level;
931 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
933 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
934 TREE_CHAIN (lb) = b->names;
936 IDENTIFIER_LOCAL_VALUE (name) = lb;
939 /* Pop the current binding level, reinstalling values for the previous
945 struct binding_level *b = current_binding_level;
946 tree label = b->names;
947 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
950 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
951 TREE_VALUE (b->shadowed);
953 /* Pop the current level, and free the structure for reuse. */
954 current_binding_level = current_binding_level->level_chain;
955 b->level_chain = free_binding_level;
956 free_binding_level = b;
959 /* Record a decl-node X as belonging to the current lexical scope.
960 Check for errors (such as an incompatible declaration for the same
961 name already seen in the same scope).
963 Returns either X or an old decl for the same name.
964 If an old decl is returned, it may have been smashed
965 to agree with what X says. */
972 register tree name = DECL_NAME (x);
973 register struct binding_level *b = current_binding_level;
975 if (TREE_CODE (x) != TYPE_DECL)
976 DECL_CONTEXT (x) = current_function_decl;
982 t = lookup_name_current_level (name);
983 if (t != 0 && t == error_mark_node)
984 /* error_mark_node is 0 for a while during initialization! */
987 error_with_decl (x, "`%s' used prior to declaration");
992 file = DECL_SOURCE_FILE (t);
993 line = DECL_SOURCE_LINE (t);
996 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
997 to point to the TYPE_DECL.
998 Since Java does not have typedefs, a type can only have
999 one (true) name, given by a class, interface, or builtin. */
1000 if (TREE_CODE (x) == TYPE_DECL
1001 && TYPE_NAME (TREE_TYPE (x)) == 0
1002 && TREE_TYPE (x) != error_mark_node)
1004 TYPE_NAME (TREE_TYPE (x)) = x;
1005 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1008 /* This name is new in its binding level.
1009 Install the new declaration and return it. */
1010 if (b == global_binding_level)
1012 /* Install a global value. */
1014 IDENTIFIER_GLOBAL_VALUE (name) = x;
1018 /* Here to install a non-global value. */
1019 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1020 IDENTIFIER_LOCAL_VALUE (name) = x;
1023 /* Warn if shadowing an argument at the top level of the body. */
1024 if (oldlocal != 0 && !DECL_EXTERNAL (x)
1025 /* This warning doesn't apply to the parms of a nested fcn. */
1026 && ! current_binding_level->parm_flag
1027 /* Check that this is one level down from the parms. */
1028 && current_binding_level->level_chain->parm_flag
1029 /* Check that the decl being shadowed
1030 comes from the parm level, one level up. */
1031 && chain_member (oldlocal, current_binding_level->level_chain->names))
1033 if (TREE_CODE (oldlocal) == PARM_DECL)
1034 pedwarn ("declaration of `%s' shadows a parameter",
1035 IDENTIFIER_POINTER (name));
1037 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1038 IDENTIFIER_POINTER (name));
1041 /* Maybe warn if shadowing something else. */
1042 else if (warn_shadow && !DECL_EXTERNAL (x)
1043 /* No shadow warnings for internally generated vars. */
1044 && DECL_SOURCE_LINE (x) != 0
1045 /* No shadow warnings for vars made for inlining. */
1046 && ! DECL_FROM_INLINE (x))
1048 const char *warnstring = 0;
1050 if (TREE_CODE (x) == PARM_DECL
1051 && current_binding_level->level_chain->parm_flag)
1052 /* Don't warn about the parm names in function declarator
1053 within a function declarator.
1054 It would be nice to avoid warning in any function
1055 declarator in a declaration, as opposed to a definition,
1056 but there is no way to tell it's not a definition. */
1058 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1059 warnstring = "declaration of `%s' shadows a parameter";
1060 else if (oldlocal != 0)
1061 warnstring = "declaration of `%s' shadows previous local";
1062 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1063 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1064 warnstring = "declaration of `%s' shadows global declaration";
1067 warning (warnstring, IDENTIFIER_POINTER (name));
1071 /* If storing a local value, there may already be one (inherited).
1072 If so, record it for restoration when this binding level ends. */
1074 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1078 /* Put decls on list in reverse order.
1079 We will reverse them later if necessary. */
1080 TREE_CHAIN (x) = b->names;
1086 pushdecl_force_head (x)
1089 current_binding_level->names = x;
1092 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1095 pushdecl_top_level (x)
1099 register struct binding_level *b = current_binding_level;
1101 current_binding_level = global_binding_level;
1103 current_binding_level = b;
1107 /* Nonzero if we are currently in the global binding level. */
1110 global_bindings_p ()
1112 return current_binding_level == global_binding_level;
1115 /* Return the list of declarations of the current level.
1116 Note that this list is in reverse order unless/until
1117 you nreverse it; and when you do nreverse it, you must
1118 store the result back using `storedecls' or you will lose. */
1123 return current_binding_level->names;
1126 /* Create a new `struct binding_level'. */
1129 struct binding_level *
1130 make_binding_level ()
1133 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1138 int unused ATTRIBUTE_UNUSED;
1140 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1143 /* If this is the top level of a function,
1144 just make sure that NAMED_LABELS is 0. */
1146 if (current_binding_level == global_binding_level)
1150 /* Reuse or create a struct for this binding level. */
1152 if (free_binding_level)
1154 newlevel = free_binding_level;
1155 free_binding_level = free_binding_level->level_chain;
1159 newlevel = make_binding_level ();
1162 /* Add this level to the front of the chain (stack) of levels that
1165 *newlevel = clear_binding_level;
1166 newlevel->level_chain = current_binding_level;
1167 current_binding_level = newlevel;
1168 newlevel->keep = keep_next_level_flag;
1169 keep_next_level_flag = 0;
1170 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1171 keep_next_if_subblocks = 0;
1172 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1173 newlevel->binding_depth = binding_depth;
1175 fprintf (stderr, "push %s level 0x%08x pc %d\n",
1176 (is_class_level) ? "class" : "block", newlevel, current_pc);
1179 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1182 /* Exit a binding level.
1183 Pop the level off, and restore the state of the identifier-decl mappings
1184 that were in effect when this level was entered.
1186 If KEEP is nonzero, this level had explicit declarations, so
1187 and create a "block" (a BLOCK node) for the level
1188 to record its declarations and subblocks for symbol table output.
1190 If FUNCTIONBODY is nonzero, this level is the body of a function,
1191 so create a block as if KEEP were set and also clear out all
1194 If REVERSE is nonzero, reverse the order of decls before putting
1195 them into the BLOCK. */
1198 poplevel (keep, reverse, functionbody)
1204 /* The chain of decls was accumulated in reverse order.
1205 Put it into forward order, just for cleanliness. */
1207 tree subblocks = current_binding_level->blocks;
1210 int block_previously_created;
1212 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1215 if (current_binding_level->end_pc != LARGEST_PC)
1216 fprintf (stderr, "pop %s level 0x%08x pc %d (end pc %d)\n",
1217 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1218 current_binding_level->end_pc);
1220 fprintf (stderr, "pop %s level 0x%08x pc %d\n",
1221 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1223 if (is_class_level != (current_binding_level == class_binding_level))
1226 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1230 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1232 keep |= current_binding_level->keep;
1234 /* Get the decls in the order they were written.
1235 Usually current_binding_level->names is in reverse order.
1236 But parameter decls were previously put in forward order. */
1239 current_binding_level->names
1240 = decls = nreverse (current_binding_level->names);
1242 decls = current_binding_level->names;
1244 /* Output any nested inline functions within this block
1245 if they weren't already output. */
1247 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1248 if (TREE_CODE (decl) == FUNCTION_DECL
1249 && ! TREE_ASM_WRITTEN (decl)
1250 && DECL_INITIAL (decl) != 0
1251 && TREE_ADDRESSABLE (decl))
1253 /* If this decl was copied from a file-scope decl
1254 on account of a block-scope extern decl,
1255 propagate TREE_ADDRESSABLE to the file-scope decl.
1257 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1258 true, since then the decl goes through save_for_inline_copying. */
1259 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1260 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1261 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1264 push_function_context ();
1265 output_inline_function (decl);
1266 pop_function_context ();
1270 /* If there were any declarations in that level,
1271 or if this level is a function body,
1272 create a BLOCK to record them for the life of this function. */
1275 block_previously_created = (current_binding_level->this_block != 0);
1276 if (block_previously_created)
1277 block = current_binding_level->this_block;
1278 else if (keep || functionbody
1279 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1280 block = make_node (BLOCK);
1283 BLOCK_VARS (block) = decls;
1284 BLOCK_SUBBLOCKS (block) = subblocks;
1287 /* In each subblock, record that this is its superior. */
1289 for (link = subblocks; link; link = TREE_CHAIN (link))
1290 BLOCK_SUPERCONTEXT (link) = block;
1292 /* Clear out the meanings of the local variables of this level. */
1294 for (link = decls; link; link = TREE_CHAIN (link))
1296 tree name = DECL_NAME (link);
1297 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1299 /* If the ident. was used or addressed via a local extern decl,
1300 don't forget that fact. */
1301 if (DECL_EXTERNAL (link))
1303 if (TREE_USED (link))
1304 TREE_USED (name) = 1;
1305 if (TREE_ADDRESSABLE (link))
1306 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1308 IDENTIFIER_LOCAL_VALUE (name) = 0;
1312 /* Restore all name-meanings of the outer levels
1313 that were shadowed by this level. */
1315 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1316 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1318 /* If the level being exited is the top level of a function,
1319 check over all the labels, and clear out the current
1320 (function local) meanings of their names. */
1324 /* If this is the top level block of a function,
1325 the vars are the function's parameters.
1326 Don't leave them in the BLOCK because they are
1327 found in the FUNCTION_DECL instead. */
1329 BLOCK_VARS (block) = 0;
1331 /* Clear out the definitions of all label names,
1332 since their scopes end here,
1333 and add them to BLOCK_VARS. */
1336 for (link = named_labels; link; link = TREE_CHAIN (link))
1338 register tree label = TREE_VALUE (link);
1340 if (DECL_INITIAL (label) == 0)
1342 error_with_decl (label, "label `%s' used but not defined");
1343 /* Avoid crashing later. */
1344 define_label (input_filename, lineno,
1347 else if (warn_unused && !TREE_USED (label))
1348 warning_with_decl (label, "label `%s' defined but not used");
1349 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1351 /* Put the labels into the "variables" of the
1352 top-level block, so debugger can see them. */
1353 TREE_CHAIN (label) = BLOCK_VARS (block);
1354 BLOCK_VARS (block) = label;
1359 /* Pop the current level, and free the structure for reuse. */
1362 register struct binding_level *level = current_binding_level;
1363 current_binding_level = current_binding_level->level_chain;
1365 level->level_chain = free_binding_level;
1366 free_binding_level = level;
1369 /* Dispose of the block that we just made inside some higher level. */
1371 DECL_INITIAL (current_function_decl) = block;
1374 if (!block_previously_created)
1375 current_binding_level->blocks
1376 = chainon (current_binding_level->blocks, block);
1378 /* If we did not make a block for the level just exited,
1379 any blocks made for inner levels
1380 (since they cannot be recorded as subblocks in that level)
1381 must be carried forward so they will later become subblocks
1382 of something else. */
1384 current_binding_level->blocks
1385 = chainon (current_binding_level->blocks, subblocks);
1387 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1388 binding contour so that they point to the appropriate construct, i.e.
1389 either to the current FUNCTION_DECL node, or else to the BLOCK node
1390 we just constructed.
1392 Note that for tagged types whose scope is just the formal parameter
1393 list for some function type specification, we can't properly set
1394 their TYPE_CONTEXTs here, because we don't have a pointer to the
1395 appropriate FUNCTION_TYPE node readily available to us. For those
1396 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1397 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1398 node which will represent the "scope" for these "parameter list local"
1403 TREE_USED (block) = 1;
1408 maybe_pushlevels (pc)
1411 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1415 while (pending_local_decls != NULL_TREE &&
1416 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1418 tree *ptr = &pending_local_decls;
1420 int end_pc = DECL_LOCAL_END_PC (decl);
1422 while (*ptr != NULL_TREE
1423 && DECL_LOCAL_START_PC (*ptr) <= pc
1424 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1425 ptr = &TREE_CHAIN (*ptr);
1426 pending_local_decls = *ptr;
1429 /* Force non-nested range to be nested in current range. */
1430 if (end_pc > current_binding_level->end_pc)
1431 end_pc = current_binding_level->end_pc;
1433 maybe_start_try (pc, end_pc);
1436 expand_start_bindings (0);
1438 current_binding_level->end_pc = end_pc;
1439 current_binding_level->start_pc = pc;
1440 current_binding_level->names = decl;
1441 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1443 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1447 maybe_start_try (pc, 0);
1451 maybe_poplevels (pc)
1454 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1458 while (current_binding_level->end_pc <= pc)
1460 expand_end_bindings (getdecls (), 1, 0);
1461 maybe_end_try (current_binding_level->start_pc, pc);
1464 maybe_end_try (0, pc);
1467 /* Terminate any binding which began during the range beginning at
1468 start_pc. This tidies up improperly nested local variable ranges
1469 and exception handlers; a variable declared within an exception
1470 range is forcibly terminated when that exception ends. */
1473 force_poplevels (start_pc)
1476 while (current_binding_level->start_pc > start_pc)
1478 if (pedantic && current_binding_level->start_pc > start_pc)
1479 warning_with_decl (current_function_decl,
1480 "In %s: overlapped variable and exception ranges at %d",
1481 current_binding_level->start_pc);
1482 expand_end_bindings (getdecls (), 1, 0);
1487 /* Insert BLOCK at the end of the list of subblocks of the
1488 current binding level. This is used when a BIND_EXPR is expanded,
1489 to handle the BLOCK node inside the BIND_EXPR. */
1492 insert_block (block)
1495 TREE_USED (block) = 1;
1496 current_binding_level->blocks
1497 = chainon (current_binding_level->blocks, block);
1500 /* Set the BLOCK node for the innermost scope
1501 (the one we are currently in). */
1505 register tree block;
1507 current_binding_level->this_block = block;
1510 /* integrate_decl_tree calls this function. */
1513 copy_lang_decl (node)
1517 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1518 : sizeof (struct lang_decl);
1519 struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1520 bcopy ((PTR) DECL_LANG_SPECIFIC (node), (PTR) x, lang_decl_size);
1521 DECL_LANG_SPECIFIC (node) = x;
1524 /* If DECL has a cleanup, build and return that cleanup here.
1525 This is a callback called by expand_expr. */
1528 maybe_build_cleanup (decl)
1529 tree decl ATTRIBUTE_UNUSED;
1531 /* There are no cleanups in Java (I think). */
1536 give_name_to_locals (jcf)
1539 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1541 pending_local_decls = NULL_TREE;
1545 n = JCF_readu2 (jcf);
1546 for (i = 0; i < n; i++)
1548 int start_pc = JCF_readu2 (jcf);
1549 int length = JCF_readu2 (jcf);
1550 int name_index = JCF_readu2 (jcf);
1551 int signature_index = JCF_readu2 (jcf);
1552 int slot = JCF_readu2 (jcf);
1553 tree name = get_name_constant (jcf, name_index);
1554 tree type = parse_signature (jcf, signature_index);
1555 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1557 && length == DECL_CODE_LENGTH (current_function_decl))
1559 tree decl = TREE_VEC_ELT (decl_map, slot);
1560 DECL_NAME (decl) = name;
1561 DECL_ASSEMBLER_NAME (decl) = name;
1562 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1563 warning ("bad type in parameter debug info");
1568 int end_pc = start_pc + length;
1569 tree decl = build_decl (VAR_DECL, name, type);
1570 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1572 warning_with_decl (decl,
1573 "bad PC range for debug info for local `%s'");
1574 end_pc = DECL_CODE_LENGTH (current_function_decl);
1576 DECL_LANG_SPECIFIC (decl)
1577 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1578 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1579 DECL_LOCAL_START_PC (decl) = start_pc;
1581 /* FIXME: The range used internally for exceptions and local
1582 variable ranges, is a half-open interval:
1583 start_pc <= pc < end_pc. However, the range used in the
1584 Java VM spec is inclusive at both ends:
1585 start_pc <= pc <= end_pc. */
1588 DECL_LOCAL_END_PC (decl) = end_pc;
1590 /* Now insert the new decl in the proper place in
1591 pending_local_decls. We are essentially doing an insertion sort,
1592 which works fine, since the list input will normally already
1594 ptr = &pending_local_decls;
1595 while (*ptr != NULL_TREE
1596 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1597 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1598 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1599 ptr = &TREE_CHAIN (*ptr);
1600 TREE_CHAIN (decl) = *ptr;
1605 pending_local_decls = nreverse (pending_local_decls);
1607 /* Fill in default names for the parameters. */
1608 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1609 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1611 if (DECL_NAME (parm) == NULL_TREE)
1613 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1615 DECL_NAME (parm) = get_identifier ("this");
1619 sprintf (buffer, "ARG_%d", arg_i);
1620 DECL_NAME (parm) = get_identifier (buffer);
1622 DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1628 build_result_decl (fndecl)
1631 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1632 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1633 if (INTEGRAL_TYPE_P (restype)
1634 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1635 restype = integer_type_node;
1636 return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
1639 /* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
1640 to emit initialization code for each test flag. */
1643 emit_init_test_initialization (entry, key)
1644 struct hash_entry *entry;
1645 hash_table_key key ATTRIBUTE_UNUSED;
1647 struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
1648 expand_decl (ite->init_test_decl);
1650 expand_expr_stmt (build (MODIFY_EXPR, boolean_type_node,
1651 ite->init_test_decl, boolean_false_node));
1657 complete_start_java_method (fndecl)
1660 if (! flag_emit_class_files)
1662 /* Initialize the RTL code for the function. */
1663 init_function_start (fndecl, input_filename, lineno);
1665 /* Set up parameters and prepare for return, for the function. */
1666 expand_function_start (fndecl, 0);
1668 /* Emit initialization code for test flags. */
1669 if (! always_initialize_class_p)
1670 hash_traverse (&DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1671 emit_init_test_initialization, 0);
1674 /* Allocate further tree nodes temporarily during compilation
1675 of this function only. */
1676 temporary_allocation ();
1679 /* If this fcn was already referenced via a block-scope `extern' decl (or
1680 an implicit decl), propagate certain information about the usage. */
1681 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1682 TREE_ADDRESSABLE (current_function_decl) = 1;
1686 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1687 && ! flag_emit_class_files
1688 && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1690 tree clas = DECL_CONTEXT (fndecl);
1691 tree init = build (CALL_EXPR, void_type_node,
1692 build_address_of (soft_initclass_node),
1693 build_tree_list (NULL_TREE, build_class_ref (clas)),
1695 TREE_SIDE_EFFECTS (init) = 1;
1696 expand_expr_stmt (init);
1699 /* Push local variables. Function compiled from source code are
1700 using a different local variables management, and for them,
1701 pushlevel shouldn't be called from here. */
1702 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1705 if (! flag_emit_class_files)
1706 expand_start_bindings (1);
1709 if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1711 /* Warp function body with a monitorenter plus monitorexit cleanup. */
1712 tree enter, exit, lock;
1713 if (METHOD_STATIC (fndecl))
1714 lock = build_class_ref (DECL_CONTEXT (fndecl));
1716 lock = DECL_ARGUMENTS (fndecl);
1717 BUILD_MONITOR_ENTER (enter, lock);
1718 BUILD_MONITOR_EXIT (exit, lock);
1719 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1721 expand_expr_stmt (enter);
1722 expand_decl_cleanup (NULL_TREE, exit);
1726 tree function_body = DECL_FUNCTION_BODY (fndecl);
1727 tree body = BLOCK_EXPR_BODY (function_body);
1728 lock = build (WITH_CLEANUP_EXPR, void_type_node,
1729 enter, NULL_TREE, exit);
1730 TREE_SIDE_EFFECTS (lock) = 1;
1731 lock = build (COMPOUND_EXPR, TREE_TYPE (body), lock, body);
1732 TREE_SIDE_EFFECTS (lock) = 1;
1733 lock = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (body), lock);
1734 TREE_SIDE_EFFECTS (lock) = 1;
1735 BLOCK_EXPR_BODY (function_body) = lock;
1741 start_java_method (fndecl)
1747 current_function_decl = fndecl;
1748 announce_function (fndecl);
1750 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1751 decl_map = make_tree_vec (i);
1752 type_map = (tree *) oballoc (i * sizeof (tree));
1754 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1755 fprintf (stderr, "%s:\n", (*decl_printable_name) (fndecl, 2));
1757 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1758 pushlevel (1); /* Push parameters. */
1760 ptr = &DECL_ARGUMENTS (fndecl);
1761 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1762 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1764 tree parm_name = NULL_TREE, parm_decl;
1765 tree parm_type = TREE_VALUE (tem);
1766 if (i >= DECL_MAX_LOCALS(fndecl))
1767 fatal ("function has more parameters than local slots");
1769 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1770 DECL_CONTEXT (parm_decl) = fndecl;
1771 if (PROMOTE_PROTOTYPES
1772 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1773 && INTEGRAL_TYPE_P (parm_type))
1774 parm_type = integer_type_node;
1775 DECL_ARG_TYPE (parm_decl) = parm_type;
1778 ptr = &TREE_CHAIN (parm_decl);
1780 /* Add parm_decl to the decl_map. */
1781 push_jvm_slot (i, parm_decl);
1783 type_map[i] = TREE_TYPE (parm_decl);
1784 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1787 type_map[i] = void_type_node;
1791 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1793 while (i < DECL_MAX_LOCALS(fndecl))
1794 type_map[i++] = NULL_TREE;
1796 build_result_decl (fndecl);
1797 complete_start_java_method (fndecl);
1803 tree fndecl = current_function_decl;
1804 int flag_asynchronous_exceptions = asynchronous_exceptions;
1806 expand_end_bindings (getdecls (), 1, 0);
1807 /* pop out of function */
1810 /* pop out of its parameters */
1813 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1817 /* Generate rtl for function exit. */
1818 expand_function_end (input_filename, lineno, 0);
1820 /* FIXME: If the current method contains any exception handlers,
1821 force asynchronous_exceptions: this is necessary because signal
1822 handlers in libjava may throw exceptions. This is far from being
1823 a perfect solution, but it's better than doing nothing at all.*/
1825 asynchronous_exceptions = 1;
1827 /* Run the optimizers and output assembler code for this function. */
1828 rest_of_compilation (fndecl);
1830 current_function_decl = NULL_TREE;
1831 permanent_allocation (1);
1832 asynchronous_exceptions = flag_asynchronous_exceptions;