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));
49 static boolean emit_init_test_initialization PARAMS ((struct hash_entry *,
51 static tree create_primitive_vtable PARAMS ((const char *));
53 /* Set to non-zero value in order to emit class initilization code
54 before static field references. */
55 extern int always_initialize_class_p;
58 #define INT_TYPE_SIZE BITS_PER_WORD
61 /* The DECL_MAP is a mapping from (index, type) to a decl node.
62 If index < max_locals, it is the index of a local variable.
63 if index >= max_locals, then index-max_locals is a stack slot.
64 The DECL_MAP mapping is represented as a TREE_VEC whose elements
65 are a list of decls (VAR_DECL or PARM_DECL) chained by
66 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
67 we search the chain for a decl with a matching TREE_TYPE. */
71 /* A list of local variables VAR_DECLs for this method that we have seen
72 debug information, but we have not reached their starting (byte) PC yet. */
74 tree pending_local_decls = NULL_TREE;
76 /* Push a local variable or stack slot into the decl_map,
77 and assign it an rtl. */
79 #if defined(DEBUG_JAVA_BINDING_LEVELS)
80 int binding_depth = 0;
81 int is_class_level = 0;
89 for (i = 0; i < binding_depth*2; i++)
92 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
95 push_jvm_slot (index, decl)
99 struct rtx_def *rtl = NULL;
100 tree type = TREE_TYPE (decl);
103 DECL_CONTEXT (decl) = current_function_decl;
104 layout_decl (decl, 0);
106 /* See if we have an appropriate rtl (i.e. same mode) at this index.
107 If so, we must use it. */
108 tmp = TREE_VEC_ELT (decl_map, index);
109 while (tmp != NULL_TREE)
111 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
112 rtl = DECL_RTL (tmp);
115 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
118 DECL_RTL (decl) = rtl;
121 if (index >= DECL_MAX_LOCALS (current_function_decl))
122 DECL_REGISTER (decl) = 1;
126 /* Now link the decl into the decl_map. */
127 if (DECL_LANG_SPECIFIC (decl) == NULL)
129 DECL_LANG_SPECIFIC (decl)
130 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
131 DECL_LOCAL_START_PC (decl) = 0;
132 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
133 DECL_LOCAL_SLOT_NUMBER (decl) = index;
135 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
136 TREE_VEC_ELT (decl_map, index) = decl;
140 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
141 that is valid at PC (or -1 if any pc).
142 If there is no existing matching decl, allocate one. */
145 find_local_variable (index, type, pc)
150 tree decl = TREE_VEC_ELT (decl_map, index);
151 tree best = NULL_TREE;
153 while (decl != NULL_TREE)
157 || (pc >= DECL_LOCAL_START_PC (decl)
158 && pc < DECL_LOCAL_END_PC (decl));
160 if ((TREE_TYPE (decl) == type
161 || (TREE_CODE (TREE_TYPE (decl)) == TREE_CODE (type)
162 && TYPE_PRECISION (TREE_TYPE (decl)) <= 32
163 && TYPE_PRECISION (type) <= 32
164 && TREE_CODE (type) != POINTER_TYPE)
165 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
166 && type == ptr_type_node))
169 if (best == NULL_TREE
170 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
171 || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
172 || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
175 decl = DECL_LOCAL_SLOT_CHAIN (decl);
177 if (best != NULL_TREE)
179 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
183 /* Same as find_local_index, except that INDEX is a stack index. */
186 find_stack_slot (index, type)
190 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
196 /* A chain of _DECL nodes for all variables, constants, functions,
197 * and typedef types. These are in the reverse of the order supplied.
201 /* For each level, a list of shadowed outer-level local definitions
202 to be restored when this level is popped.
203 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
204 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
207 /* For each level (except not the global one),
208 a chain of BLOCK nodes for all the levels
209 that were entered and exited one level down. */
212 /* The BLOCK node for this level, if one has been preallocated.
213 If 0, the BLOCK is allocated (if needed) when the level is popped. */
216 /* The binding level which this one is contained in (inherits from). */
217 struct binding_level *level_chain;
219 /* 1 means make a BLOCK for this level regardless of all else.
220 2 for temporary binding contours created by the compiler. */
223 /* Nonzero means make a BLOCK if this level has any subblocks. */
224 char keep_if_subblocks;
226 /* Nonzero if this level can safely have additional
227 cleanup-needing variables added to it. */
228 char more_cleanups_ok;
231 /* The bytecode PC that marks the end of this level. */
233 /* The bytecode PC that marks the start of this level. */
236 #if defined(DEBUG_JAVA_BINDING_LEVELS)
237 /* Binding depth at which this level began. */
238 unsigned binding_depth;
239 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
242 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
244 /* The binding level currently in effect. */
246 static struct binding_level *current_binding_level;
248 /* A chain of binding_level structures awaiting reuse. */
250 static struct binding_level *free_binding_level;
252 /* The outermost binding level, for names of file scope.
253 This is created when the compiler is started and exists
254 through the entire run. */
256 static struct binding_level *global_binding_level;
258 /* A PC value bigger than any PC value we may ever may encounter. */
260 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
262 /* Binding level structures are initialized by copying this one. */
264 static struct binding_level clear_binding_level
265 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
266 NULL_BINDING_LEVEL, 0, 0, 0, 0, LARGEST_PC, 0};
269 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
270 that have names. Here so we can clear out their names' definitions
271 at the end of the function. */
273 static tree named_labels;
275 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
277 static tree shadowed_labels;
280 int flag_traditional;
282 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
284 static int keep_next_level_flag;
286 /* Nonzero means make a BLOCK for the next level pushed
287 if it has subblocks. */
289 static int keep_next_if_subblocks;
291 tree object_type_node;
292 tree unqualified_object_id_node;
293 tree object_ptr_type_node;
294 tree string_type_node;
295 tree string_ptr_type_node;
296 tree throwable_type_node;
297 tree runtime_exception_type_node;
298 tree error_exception_type_node;
299 tree rawdata_ptr_type_node;
300 tree *predef_filenames;
301 int predef_filenames_size;
303 tree boolean_type_node;
305 tree return_address_type_node;
308 tree short_type_node;
312 tree promoted_byte_type_node;
313 tree promoted_short_type_node;
314 tree promoted_char_type_node;
315 tree promoted_boolean_type_node;
317 tree unsigned_byte_type_node;
318 tree unsigned_short_type_node;
319 tree unsigned_int_type_node;
320 tree unsigned_long_type_node;
322 /* The type for struct methodtable. */
323 tree methodtable_type;
324 tree methodtable_ptr_type;
327 tree utf8const_ptr_type;
328 tree class_type_node;
330 tree field_type_node;
331 tree field_ptr_type_node;
332 tree field_info_union_node;
333 tree jexception_type;
334 tree jexception_ptr_type;
335 tree lineNumberEntry_type;
336 tree lineNumbers_type;
337 tree constants_type_node;
339 tree dtable_ptr_type;
340 tree method_type_node;
341 tree method_ptr_type_node;
342 tree nativecode_ptr_array_type_node;
343 tree one_elt_array_domain_type;
344 tree access_flags_type_node;
345 tree class_dtable_decl;
347 /* Expressions that are constants with value zero, of types
348 `long', `float' and `double'. */
350 tree float_zero_node;
351 tree double_zero_node;
353 tree empty_stmt_node;
355 /* Nodes for boolean constants TRUE and FALSE. */
356 tree boolean_true_node;
357 tree boolean_false_node;
359 tree TYPE_identifier_node;
360 tree init_identifier_node;
361 tree clinit_identifier_node;
362 tree finit_identifier_node;
363 tree void_signature_node;
364 tree length_identifier_node;
365 tree this_identifier_node;
366 tree super_identifier_node;
367 tree continue_identifier_node;
368 tree access0_identifier_node; /* 1.1 */
369 tree end_params_node;
371 /* References to internal libjava functions we use. */
372 tree alloc_object_node;
373 tree soft_instanceof_node;
374 tree soft_checkcast_node;
375 tree soft_initclass_node;
376 tree soft_newarray_node;
377 tree soft_anewarray_node;
378 tree soft_multianewarray_node;
379 tree soft_badarrayindex_node;
380 tree soft_nullpointer_node;
382 tree soft_checkarraystore_node;
383 tree soft_monitorenter_node;
384 tree soft_monitorexit_node;
385 tree soft_lookupinterfacemethod_node;
386 tree soft_lookupjnimethod_node;
387 tree soft_getjnienvnewframe_node;
388 tree soft_jnipopsystemframe_node;
390 tree soft_exceptioninfo_call_node;
396 /* Declarations for vtables for primitive arrays. */
397 tree boolean_array_vtable;
398 tree byte_array_vtable;
399 tree char_array_vtable;
400 tree short_array_vtable;
401 tree int_array_vtable;
402 tree long_array_vtable;
403 tree float_array_vtable;
404 tree double_array_vtable;
406 /* Build (and pushdecl) a "promoted type" for all standard
407 types shorter than int. */
410 push_promoted_type (name, actual_type)
414 tree type = make_node (TREE_CODE (actual_type));
416 tree in_min = TYPE_MIN_VALUE (int_type_node);
417 tree in_max = TYPE_MAX_VALUE (int_type_node);
419 tree in_min = TYPE_MIN_VALUE (actual_type);
420 tree in_max = TYPE_MAX_VALUE (actual_type);
422 TYPE_MIN_VALUE (type) = copy_node (in_min);
423 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
424 TYPE_MAX_VALUE (type) = copy_node (in_max);
425 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
426 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
428 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
432 /* Nodes for integer constants. */
433 tree integer_two_node;
434 tree integer_four_node;
435 tree integer_negative_one_node;
437 /* Return a definition for a builtin function named NAME and whose data type
438 is TYPE. TYPE should be a function type with argument types.
439 FUNCTION_CODE tells later passes how to compile calls to this function.
440 See tree.h for its possible values.
442 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
443 the name to be called if we can't opencode the function. */
446 builtin_function (name, type, function_code, class, library_name)
450 enum built_in_class class;
451 const char *library_name;
453 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
454 DECL_EXTERNAL (decl) = 1;
455 TREE_PUBLIC (decl) = 1;
457 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
458 make_decl_rtl (decl, NULL_PTR, 1);
460 DECL_BUILT_IN_CLASS (decl) = class;
461 DECL_FUNCTION_CODE (decl) = function_code;
465 /* Return tree that represents a vtable for a primitive array. */
467 create_primitive_vtable (name)
473 sprintf (buf, "_Jv_%sVTable", name);
474 r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
475 DECL_EXTERNAL (r) = 1;
476 make_decl_rtl (r, buf, 1);
481 init_decl_processing ()
483 register tree endlink;
484 tree field = NULL_TREE;
487 current_function_decl = NULL;
488 current_binding_level = NULL_BINDING_LEVEL;
489 free_binding_level = NULL_BINDING_LEVEL;
490 pushlevel (0); /* make the binding_level structure for global names */
491 global_binding_level = current_binding_level;
493 /* The code here must be similar to build_common_tree_nodes{,_2} in
494 tree.c, especially as to the order of initializing common nodes. */
495 error_mark_node = make_node (ERROR_MARK);
496 TREE_TYPE (error_mark_node) = error_mark_node;
498 /* Create sizetype first - needed for other types. */
499 initialize_sizetypes ();
501 byte_type_node = make_signed_type (8);
502 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
503 short_type_node = make_signed_type (16);
504 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
505 int_type_node = make_signed_type (32);
506 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
507 long_type_node = make_signed_type (64);
508 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
510 unsigned_byte_type_node = make_unsigned_type (8);
511 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
512 unsigned_byte_type_node));
513 unsigned_short_type_node = make_unsigned_type (16);
514 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
515 unsigned_short_type_node));
516 unsigned_int_type_node = make_unsigned_type (32);
517 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
518 unsigned_int_type_node));
519 unsigned_long_type_node = make_unsigned_type (64);
520 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
521 unsigned_long_type_node));
523 set_sizetype (make_unsigned_type (POINTER_SIZE));
525 /* Define these next since types below may used them. */
526 integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
527 integer_zero_node = build_int_2 (0, 0);
528 integer_one_node = build_int_2 (1, 0);
529 integer_two_node = build_int_2 (2, 0);
530 integer_four_node = build_int_2 (4, 0);
531 integer_negative_one_node = build_int_2 (-1, 0);
533 size_zero_node = size_int (0);
534 size_one_node = size_int (1);
535 bitsize_zero_node = bitsize_int (0);
536 bitsize_one_node = bitsize_int (1);
537 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
539 long_zero_node = build_int_2 (0, 0);
540 TREE_TYPE (long_zero_node) = long_type_node;
542 void_type_node = make_node (VOID_TYPE);
543 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
544 layout_type (void_type_node); /* Uses size_zero_node */
545 ptr_type_node = build_pointer_type (void_type_node);
546 t = make_node (VOID_TYPE);
547 layout_type (t); /* Uses size_zero_node */
548 return_address_type_node = build_pointer_type (t);
550 null_pointer_node = build_int_2 (0, 0);
551 TREE_TYPE (null_pointer_node) = ptr_type_node;
553 /* Used by the parser to represent empty statements and blocks. */
554 empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
555 CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
558 /* Make a type to be the domain of a few array types
559 whose domains don't really matter.
560 200 is small enough that it always fits in size_t
561 and large enough that it can hold most function names for the
562 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
563 short_array_type_node = build_prim_array_type (short_type_node, 200);
565 char_type_node = make_node (CHAR_TYPE);
566 TYPE_PRECISION (char_type_node) = 16;
567 fixup_unsigned_type (char_type_node);
568 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
570 boolean_type_node = make_node (BOOLEAN_TYPE);
571 TYPE_PRECISION (boolean_type_node) = 1;
572 fixup_unsigned_type (boolean_type_node);
573 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
575 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
576 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
578 promoted_byte_type_node
579 = push_promoted_type ("promoted_byte", byte_type_node);
580 promoted_short_type_node
581 = push_promoted_type ("promoted_short", short_type_node);
582 promoted_char_type_node
583 = push_promoted_type ("promoted_char", char_type_node);
584 promoted_boolean_type_node
585 = push_promoted_type ("promoted_boolean", boolean_type_node);
587 float_type_node = make_node (REAL_TYPE);
588 TYPE_PRECISION (float_type_node) = 32;
589 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
591 layout_type (float_type_node);
593 double_type_node = make_node (REAL_TYPE);
594 TYPE_PRECISION (double_type_node) = 64;
595 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
597 layout_type (double_type_node);
599 float_zero_node = build_real (float_type_node, dconst0);
600 double_zero_node = build_real (double_type_node, dconst0);
602 /* These are the vtables for arrays of primitives. */
603 boolean_array_vtable = create_primitive_vtable ("boolean");
604 byte_array_vtable = create_primitive_vtable ("byte");
605 char_array_vtable = create_primitive_vtable ("char");
606 short_array_vtable = create_primitive_vtable ("short");
607 int_array_vtable = create_primitive_vtable ("int");
608 long_array_vtable = create_primitive_vtable ("long");
609 float_array_vtable = create_primitive_vtable ("float");
610 double_array_vtable = create_primitive_vtable ("double");
612 /* As you're adding items here, please update the code right after
613 this section, so that the filename containing the source code of
614 the pre-defined class gets registered correctly. */
615 unqualified_object_id_node = get_identifier ("Object");
616 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
617 object_ptr_type_node = promote_type (object_type_node);
618 string_type_node = lookup_class (get_identifier ("java.lang.String"));
619 string_ptr_type_node = promote_type (string_type_node);
620 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
621 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
622 runtime_exception_type_node =
623 lookup_class (get_identifier ("java.lang.RuntimeException"));
624 error_exception_type_node =
625 lookup_class (get_identifier ("java.lang.Error"));
626 rawdata_ptr_type_node
627 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
629 /* This section has to be updated as items are added to the previous
631 predef_filenames_size = 7;
632 predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
633 predef_filenames [0] = get_identifier ("java/lang/Class.java");
634 predef_filenames [1] = get_identifier ("java/lang/Error.java");
635 predef_filenames [2] = get_identifier ("java/lang/Object.java");
636 predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
637 predef_filenames [4] = get_identifier ("java/lang/String.java");
638 predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
639 predef_filenames [6] = get_identifier ("gnu/gcj/RawData.java");
641 methodtable_type = make_node (RECORD_TYPE);
642 layout_type (methodtable_type);
643 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
644 methodtable_ptr_type = build_pointer_type (methodtable_type);
646 TYPE_identifier_node = get_identifier ("TYPE");
647 init_identifier_node = get_identifier ("<init>");
648 clinit_identifier_node = get_identifier ("<clinit>");
649 finit_identifier_node = get_identifier ("$finit$");
650 void_signature_node = get_identifier ("()V");
651 length_identifier_node = get_identifier ("length");
652 this_identifier_node = get_identifier ("this");
653 super_identifier_node = get_identifier ("super");
654 continue_identifier_node = get_identifier ("continue");
655 access0_identifier_node = get_identifier ("access$0");
657 /* for lack of a better place to put this stub call */
658 init_expr_processing();
660 utf8const_type = make_node (RECORD_TYPE);
661 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
662 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
663 FINISH_RECORD (utf8const_type);
664 utf8const_ptr_type = build_pointer_type (utf8const_type);
666 constants_type_node = make_node (RECORD_TYPE);
667 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
668 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
669 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
670 FINISH_RECORD (constants_type_node);
671 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
673 access_flags_type_node = unsigned_short_type_node;
675 dtable_type = make_node (RECORD_TYPE);
676 dtable_ptr_type = build_pointer_type (dtable_type);
678 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
679 /* This isn't exactly true, but it is what we have in the source.
680 There is an unresolved issue here, which is whether the vtable
681 should be marked by the GC. */
682 if (! flag_hash_synchronization)
683 PUSH_FIELD (object_type_node, field, "sync_info",
684 build_pointer_type (object_type_node));
685 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
686 FIELD_PRIVATE (t) = 1;
687 FINISH_RECORD (object_type_node);
689 class_dtable_decl = build_dtable_decl (class_type_node);
690 TREE_STATIC (class_dtable_decl) = 1;
691 DECL_ARTIFICIAL (class_dtable_decl) = 1;
692 DECL_IGNORED_P (class_dtable_decl) = 1;
693 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
695 field_type_node = make_node (RECORD_TYPE);
696 field_ptr_type_node = build_pointer_type (field_type_node);
697 method_type_node = make_node (RECORD_TYPE);
698 method_ptr_type_node = build_pointer_type (method_type_node);
700 set_super_info (0, class_type_node, object_type_node, 0);
701 set_super_info (0, string_type_node, object_type_node, 0);
702 class_ptr_type = build_pointer_type (class_type_node);
704 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
705 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
706 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
707 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
708 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
709 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
710 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
711 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
712 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
713 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
714 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
715 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
716 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
717 PUSH_FIELD (class_type_node, field, "interfaces",
718 build_pointer_type (class_ptr_type));
719 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
720 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
721 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
722 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
723 PUSH_FIELD (class_type_node, field, "depth", short_type_node);
724 PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
725 PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
726 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
727 FIELD_PRIVATE (t) = 1;
728 push_super_field (class_type_node, object_type_node);
729 FINISH_RECORD (class_type_node);
730 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
732 field_info_union_node = make_node (UNION_TYPE);
733 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
734 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
736 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
738 layout_type (field_info_union_node);
740 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
741 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
742 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
743 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
744 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
745 FINISH_RECORD (field_type_node);
746 CLASS_LOADED_P (field_type_node) = 1;
747 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
749 one_elt_array_domain_type = build_index_type (integer_one_node);
750 nativecode_ptr_array_type_node
751 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
753 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
754 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
755 FINISH_RECORD (dtable_type);
756 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
758 #define jint_type int_type_node
759 #define jint_ptr_type ptr_type_node
761 jexception_type = make_node (RECORD_TYPE);
762 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
763 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
764 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
765 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
766 FINISH_RECORD (jexception_type);
767 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
768 jexception_ptr_type = build_pointer_type (jexception_type);
770 lineNumberEntry_type = make_node (RECORD_TYPE);
771 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
772 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
773 FINISH_RECORD (lineNumberEntry_type);
775 lineNumbers_type = make_node (RECORD_TYPE);
776 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
777 FINISH_RECORD (lineNumbers_type);
779 #define instn_ptr_type_node ptr_type_node /* XXX JH */
781 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
783 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
784 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
785 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
786 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
787 FINISH_RECORD (method_type_node);
788 CLASS_LOADED_P (method_type_node) = 1;
789 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
791 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
793 t = tree_cons (NULL_TREE, class_ptr_type,
794 tree_cons (NULL_TREE, int_type_node, endlink));
795 alloc_object_node = builtin_function ("_Jv_AllocObject",
796 build_function_type (ptr_type_node, t),
797 0, NOT_BUILT_IN, NULL_PTR);
798 DECL_IS_MALLOC (alloc_object_node) = 1;
800 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
801 soft_initclass_node = builtin_function ("_Jv_InitClass",
802 build_function_type (void_type_node,
806 throw_node[0] = builtin_function ("_Jv_Throw",
807 build_function_type (ptr_type_node, t),
808 0, NOT_BUILT_IN, NULL_PTR);
809 /* Mark throw_nodes as `noreturn' functions with side effects. */
810 TREE_THIS_VOLATILE (throw_node[0]) = 1;
811 TREE_SIDE_EFFECTS (throw_node[0]) = 1;
812 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
813 throw_node[1] = builtin_function ("_Jv_Sjlj_Throw",
814 build_function_type (ptr_type_node, t),
815 0, NOT_BUILT_IN, NULL_PTR);
816 TREE_THIS_VOLATILE (throw_node[1]) = 1;
817 TREE_SIDE_EFFECTS (throw_node[1]) = 1;
818 t = build_function_type (int_type_node, endlink);
819 soft_monitorenter_node
820 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
822 soft_monitorexit_node
823 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
826 t = tree_cons (NULL_TREE, int_type_node,
827 tree_cons (NULL_TREE, int_type_node, endlink));
829 = builtin_function ("_Jv_NewArray",
830 build_function_type(ptr_type_node, t),
831 0, NOT_BUILT_IN, NULL_PTR);
832 DECL_IS_MALLOC (soft_newarray_node) = 1;
834 t = tree_cons (NULL_TREE, int_type_node,
835 tree_cons (NULL_TREE, class_ptr_type,
836 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
838 = builtin_function ("_Jv_NewObjectArray",
839 build_function_type (ptr_type_node, t),
840 0, NOT_BUILT_IN, NULL_PTR);
841 DECL_IS_MALLOC (soft_anewarray_node) = 1;
843 t = tree_cons (NULL_TREE, ptr_type_node,
844 tree_cons (NULL_TREE, int_type_node, endlink));
845 soft_multianewarray_node
846 = builtin_function ("_Jv_NewMultiArray",
847 build_function_type (ptr_type_node, t),
848 0, NOT_BUILT_IN, NULL_PTR);
849 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
851 t = build_function_type (void_type_node,
852 tree_cons (NULL_TREE, int_type_node, endlink));
853 soft_badarrayindex_node
854 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
855 0, NOT_BUILT_IN, NULL_PTR);
856 /* Mark soft_badarrayindex_node as a `noreturn' function with side
858 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
859 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
861 soft_nullpointer_node
862 = builtin_function ("_Jv_ThrowNullPointerException",
863 build_function_type (void_type_node, endlink),
864 0, NOT_BUILT_IN, NULL_PTR);
865 /* Mark soft_nullpointer_node as a `noreturn' function with side
867 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
868 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
870 t = tree_cons (NULL_TREE, class_ptr_type,
871 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
873 = builtin_function ("_Jv_CheckCast",
874 build_function_type (ptr_type_node, t),
875 0, NOT_BUILT_IN, NULL_PTR);
876 t = tree_cons (NULL_TREE, object_ptr_type_node,
877 tree_cons (NULL_TREE, class_ptr_type, endlink));
879 = builtin_function ("_Jv_IsInstanceOf",
880 build_function_type (boolean_type_node, t),
881 0, NOT_BUILT_IN, NULL_PTR);
882 t = tree_cons (NULL_TREE, object_ptr_type_node,
883 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
884 soft_checkarraystore_node
885 = builtin_function ("_Jv_CheckArrayStore",
886 build_function_type (void_type_node, t),
887 0, NOT_BUILT_IN, NULL_PTR);
888 t = tree_cons (NULL_TREE, ptr_type_node,
889 tree_cons (NULL_TREE, ptr_type_node,
890 tree_cons (NULL_TREE, int_type_node, endlink)));
891 soft_lookupinterfacemethod_node
892 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
893 build_function_type (ptr_type_node, t),
894 0, NOT_BUILT_IN, NULL_PTR);
896 t = tree_cons (NULL_TREE, object_ptr_type_node,
897 tree_cons (NULL_TREE, ptr_type_node,
898 tree_cons (NULL_TREE, ptr_type_node, endlink)));
899 soft_lookupjnimethod_node
900 = builtin_function ("_Jv_LookupJNIMethod",
901 build_function_type (ptr_type_node, t),
902 0, NOT_BUILT_IN, NULL_PTR);
903 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
904 soft_getjnienvnewframe_node
905 = builtin_function ("_Jv_GetJNIEnvNewFrame",
906 build_function_type (ptr_type_node, t),
907 0, NOT_BUILT_IN, NULL_PTR);
908 soft_jnipopsystemframe_node
909 = builtin_function ("_Jv_JNI_PopSystemFrame",
910 build_function_type (ptr_type_node, t),
911 0, NOT_BUILT_IN, NULL_PTR);
913 t = tree_cons (NULL_TREE, double_type_node,
914 tree_cons (NULL_TREE, double_type_node, endlink));
916 = builtin_function ("__builtin_fmod",
917 build_function_type (double_type_node, t),
918 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod");
920 soft_exceptioninfo_call_node
924 (builtin_function ("_Jv_exception_info",
925 build_function_type (ptr_type_node, endlink),
926 0, NOT_BUILT_IN, NULL_PTR)),
927 NULL_TREE, NULL_TREE);
928 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
930 t = tree_cons (NULL_TREE, float_type_node,
931 tree_cons (NULL_TREE, float_type_node, endlink));
933 = builtin_function ("__builtin_fmodf",
934 build_function_type (float_type_node, t),
935 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf");
939 = builtin_function ("_Jv_divI",
940 build_function_type (int_type_node, t),
941 0, NOT_BUILT_IN, NULL_PTR);
944 = builtin_function ("_Jv_remI",
945 build_function_type (int_type_node, t),
946 0, NOT_BUILT_IN, NULL_PTR);
949 = builtin_function ("_Jv_divJ",
950 build_function_type (long_type_node, t),
951 0, NOT_BUILT_IN, NULL_PTR);
954 = builtin_function ("_Jv_remJ",
955 build_function_type (long_type_node, t),
956 0, NOT_BUILT_IN, NULL_PTR);
958 init_class_processing ();
962 /* Look up NAME in the current binding level and its superiors
963 in the namespace of variables, functions and typedefs.
964 Return a ..._DECL node of some kind representing its definition,
965 or return 0 if it is undefined. */
972 if (current_binding_level != global_binding_level
973 && IDENTIFIER_LOCAL_VALUE (name))
974 val = IDENTIFIER_LOCAL_VALUE (name);
976 val = IDENTIFIER_GLOBAL_VALUE (name);
980 /* Similar to `lookup_name' but look only at current binding level and
981 the previous one if its the parameter level. */
984 lookup_name_current_level (name)
989 if (current_binding_level == global_binding_level)
990 return IDENTIFIER_GLOBAL_VALUE (name);
992 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
995 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
996 if (DECL_NAME (t) == name)
1002 /* Use a binding level to record a labeled block declaration */
1005 push_labeled_block (lb)
1008 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
1009 register struct binding_level *b = current_binding_level;
1010 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1012 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1013 TREE_CHAIN (lb) = b->names;
1015 IDENTIFIER_LOCAL_VALUE (name) = lb;
1018 /* Pop the current binding level, reinstalling values for the previous
1022 pop_labeled_block ()
1024 struct binding_level *b = current_binding_level;
1025 tree label = b->names;
1026 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
1029 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
1030 TREE_VALUE (b->shadowed);
1032 /* Pop the current level, and free the structure for reuse. */
1033 current_binding_level = current_binding_level->level_chain;
1034 b->level_chain = free_binding_level;
1035 free_binding_level = b;
1038 /* Record a decl-node X as belonging to the current lexical scope.
1039 Check for errors (such as an incompatible declaration for the same
1040 name already seen in the same scope).
1042 Returns either X or an old decl for the same name.
1043 If an old decl is returned, it may have been smashed
1044 to agree with what X says. */
1051 register tree name = DECL_NAME (x);
1052 register struct binding_level *b = current_binding_level;
1054 if (TREE_CODE (x) != TYPE_DECL)
1055 DECL_CONTEXT (x) = current_function_decl;
1061 t = lookup_name_current_level (name);
1062 if (t != 0 && t == error_mark_node)
1063 /* error_mark_node is 0 for a while during initialization! */
1066 error_with_decl (x, "`%s' used prior to declaration");
1071 file = DECL_SOURCE_FILE (t);
1072 line = DECL_SOURCE_LINE (t);
1075 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1076 to point to the TYPE_DECL.
1077 Since Java does not have typedefs, a type can only have
1078 one (true) name, given by a class, interface, or builtin. */
1079 if (TREE_CODE (x) == TYPE_DECL
1080 && TYPE_NAME (TREE_TYPE (x)) == 0
1081 && TREE_TYPE (x) != error_mark_node)
1083 TYPE_NAME (TREE_TYPE (x)) = x;
1084 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1087 /* This name is new in its binding level.
1088 Install the new declaration and return it. */
1089 if (b == global_binding_level)
1091 /* Install a global value. */
1093 IDENTIFIER_GLOBAL_VALUE (name) = x;
1097 /* Here to install a non-global value. */
1098 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1099 IDENTIFIER_LOCAL_VALUE (name) = x;
1102 /* Warn if shadowing an argument at the top level of the body. */
1103 if (oldlocal != 0 && !DECL_EXTERNAL (x)
1104 /* This warning doesn't apply to the parms of a nested fcn. */
1105 && ! current_binding_level->parm_flag
1106 /* Check that this is one level down from the parms. */
1107 && current_binding_level->level_chain->parm_flag
1108 /* Check that the decl being shadowed
1109 comes from the parm level, one level up. */
1110 && chain_member (oldlocal, current_binding_level->level_chain->names))
1112 if (TREE_CODE (oldlocal) == PARM_DECL)
1113 pedwarn ("declaration of `%s' shadows a parameter",
1114 IDENTIFIER_POINTER (name));
1116 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1117 IDENTIFIER_POINTER (name));
1120 /* Maybe warn if shadowing something else. */
1121 else if (warn_shadow && !DECL_EXTERNAL (x)
1122 /* No shadow warnings for internally generated vars. */
1123 && DECL_SOURCE_LINE (x) != 0
1124 /* No shadow warnings for vars made for inlining. */
1125 && ! DECL_FROM_INLINE (x))
1127 const char *warnstring = 0;
1129 if (TREE_CODE (x) == PARM_DECL
1130 && current_binding_level->level_chain->parm_flag)
1131 /* Don't warn about the parm names in function declarator
1132 within a function declarator.
1133 It would be nice to avoid warning in any function
1134 declarator in a declaration, as opposed to a definition,
1135 but there is no way to tell it's not a definition. */
1137 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1138 warnstring = "declaration of `%s' shadows a parameter";
1139 else if (oldlocal != 0)
1140 warnstring = "declaration of `%s' shadows previous local";
1141 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1142 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1143 warnstring = "declaration of `%s' shadows global declaration";
1146 warning (warnstring, IDENTIFIER_POINTER (name));
1150 /* If storing a local value, there may already be one (inherited).
1151 If so, record it for restoration when this binding level ends. */
1153 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1157 /* Put decls on list in reverse order.
1158 We will reverse them later if necessary. */
1159 TREE_CHAIN (x) = b->names;
1166 pushdecl_force_head (x)
1169 current_binding_level->names = x;
1172 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1175 pushdecl_top_level (x)
1179 register struct binding_level *b = current_binding_level;
1181 current_binding_level = global_binding_level;
1183 current_binding_level = b;
1187 /* Nonzero if we are currently in the global binding level. */
1190 global_bindings_p ()
1192 return current_binding_level == global_binding_level;
1195 /* Return the list of declarations of the current level.
1196 Note that this list is in reverse order unless/until
1197 you nreverse it; and when you do nreverse it, you must
1198 store the result back using `storedecls' or you will lose. */
1203 return current_binding_level->names;
1206 /* Create a new `struct binding_level'. */
1208 static struct binding_level *
1209 make_binding_level ()
1212 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1217 int unused ATTRIBUTE_UNUSED;
1219 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1222 /* If this is the top level of a function,
1223 just make sure that NAMED_LABELS is 0. */
1225 if (current_binding_level == global_binding_level)
1229 /* Reuse or create a struct for this binding level. */
1231 if (free_binding_level)
1233 newlevel = free_binding_level;
1234 free_binding_level = free_binding_level->level_chain;
1238 newlevel = make_binding_level ();
1241 /* Add this level to the front of the chain (stack) of levels that
1244 *newlevel = clear_binding_level;
1245 newlevel->level_chain = current_binding_level;
1246 current_binding_level = newlevel;
1247 newlevel->keep = keep_next_level_flag;
1248 keep_next_level_flag = 0;
1249 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1250 keep_next_if_subblocks = 0;
1251 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1252 newlevel->binding_depth = binding_depth;
1254 fprintf (stderr, "push %s level 0x%08x pc %d\n",
1255 (is_class_level) ? "class" : "block", newlevel, current_pc);
1258 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1261 /* Exit a binding level.
1262 Pop the level off, and restore the state of the identifier-decl mappings
1263 that were in effect when this level was entered.
1265 If KEEP is nonzero, this level had explicit declarations, so
1266 and create a "block" (a BLOCK node) for the level
1267 to record its declarations and subblocks for symbol table output.
1269 If FUNCTIONBODY is nonzero, this level is the body of a function,
1270 so create a block as if KEEP were set and also clear out all
1273 If REVERSE is nonzero, reverse the order of decls before putting
1274 them into the BLOCK. */
1277 poplevel (keep, reverse, functionbody)
1283 /* The chain of decls was accumulated in reverse order.
1284 Put it into forward order, just for cleanliness. */
1286 tree subblocks = current_binding_level->blocks;
1289 int block_previously_created;
1291 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1294 if (current_binding_level->end_pc != LARGEST_PC)
1295 fprintf (stderr, "pop %s level 0x%08x pc %d (end pc %d)\n",
1296 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1297 current_binding_level->end_pc);
1299 fprintf (stderr, "pop %s level 0x%08x pc %d\n",
1300 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1302 if (is_class_level != (current_binding_level == class_binding_level))
1305 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1309 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1311 keep |= current_binding_level->keep;
1313 /* Get the decls in the order they were written.
1314 Usually current_binding_level->names is in reverse order.
1315 But parameter decls were previously put in forward order. */
1318 current_binding_level->names
1319 = decls = nreverse (current_binding_level->names);
1321 decls = current_binding_level->names;
1323 /* Output any nested inline functions within this block
1324 if they weren't already output. */
1326 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1327 if (TREE_CODE (decl) == FUNCTION_DECL
1328 && ! TREE_ASM_WRITTEN (decl)
1329 && DECL_INITIAL (decl) != 0
1330 && TREE_ADDRESSABLE (decl))
1332 /* If this decl was copied from a file-scope decl
1333 on account of a block-scope extern decl,
1334 propagate TREE_ADDRESSABLE to the file-scope decl.
1336 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1337 true, since then the decl goes through save_for_inline_copying. */
1338 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1339 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1340 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1343 push_function_context ();
1344 output_inline_function (decl);
1345 pop_function_context ();
1349 /* If there were any declarations in that level,
1350 or if this level is a function body,
1351 create a BLOCK to record them for the life of this function. */
1354 block_previously_created = (current_binding_level->this_block != 0);
1355 if (block_previously_created)
1356 block = current_binding_level->this_block;
1357 else if (keep || functionbody
1358 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1359 block = make_node (BLOCK);
1362 BLOCK_VARS (block) = decls;
1363 BLOCK_SUBBLOCKS (block) = subblocks;
1366 /* In each subblock, record that this is its superior. */
1368 for (link = subblocks; link; link = TREE_CHAIN (link))
1369 BLOCK_SUPERCONTEXT (link) = block;
1371 /* Clear out the meanings of the local variables of this level. */
1373 for (link = decls; link; link = TREE_CHAIN (link))
1375 tree name = DECL_NAME (link);
1376 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1378 /* If the ident. was used or addressed via a local extern decl,
1379 don't forget that fact. */
1380 if (DECL_EXTERNAL (link))
1382 if (TREE_USED (link))
1383 TREE_USED (name) = 1;
1384 if (TREE_ADDRESSABLE (link))
1385 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1387 IDENTIFIER_LOCAL_VALUE (name) = 0;
1391 /* Restore all name-meanings of the outer levels
1392 that were shadowed by this level. */
1394 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1395 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1397 /* If the level being exited is the top level of a function,
1398 check over all the labels, and clear out the current
1399 (function local) meanings of their names. */
1403 /* If this is the top level block of a function,
1404 the vars are the function's parameters.
1405 Don't leave them in the BLOCK because they are
1406 found in the FUNCTION_DECL instead. */
1408 BLOCK_VARS (block) = 0;
1410 /* Clear out the definitions of all label names,
1411 since their scopes end here,
1412 and add them to BLOCK_VARS. */
1415 for (link = named_labels; link; link = TREE_CHAIN (link))
1417 register tree label = TREE_VALUE (link);
1419 if (DECL_INITIAL (label) == 0)
1421 error_with_decl (label, "label `%s' used but not defined");
1422 /* Avoid crashing later. */
1423 define_label (input_filename, lineno,
1426 else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
1427 warning_with_decl (label, "label `%s' defined but not used");
1428 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1430 /* Put the labels into the "variables" of the
1431 top-level block, so debugger can see them. */
1432 TREE_CHAIN (label) = BLOCK_VARS (block);
1433 BLOCK_VARS (block) = label;
1438 /* Pop the current level, and free the structure for reuse. */
1441 register struct binding_level *level = current_binding_level;
1442 current_binding_level = current_binding_level->level_chain;
1444 level->level_chain = free_binding_level;
1445 free_binding_level = level;
1448 /* Dispose of the block that we just made inside some higher level. */
1450 DECL_INITIAL (current_function_decl) = block;
1453 if (!block_previously_created)
1454 current_binding_level->blocks
1455 = chainon (current_binding_level->blocks, block);
1457 /* If we did not make a block for the level just exited,
1458 any blocks made for inner levels
1459 (since they cannot be recorded as subblocks in that level)
1460 must be carried forward so they will later become subblocks
1461 of something else. */
1463 current_binding_level->blocks
1464 = chainon (current_binding_level->blocks, subblocks);
1466 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1467 binding contour so that they point to the appropriate construct, i.e.
1468 either to the current FUNCTION_DECL node, or else to the BLOCK node
1469 we just constructed.
1471 Note that for tagged types whose scope is just the formal parameter
1472 list for some function type specification, we can't properly set
1473 their TYPE_CONTEXTs here, because we don't have a pointer to the
1474 appropriate FUNCTION_TYPE node readily available to us. For those
1475 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1476 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1477 node which will represent the "scope" for these "parameter list local"
1482 TREE_USED (block) = 1;
1487 maybe_pushlevels (pc)
1490 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1494 while (pending_local_decls != NULL_TREE &&
1495 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1497 tree *ptr = &pending_local_decls;
1499 int end_pc = DECL_LOCAL_END_PC (decl);
1501 while (*ptr != NULL_TREE
1502 && DECL_LOCAL_START_PC (*ptr) <= pc
1503 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1504 ptr = &TREE_CHAIN (*ptr);
1505 pending_local_decls = *ptr;
1508 /* Force non-nested range to be nested in current range. */
1509 if (end_pc > current_binding_level->end_pc)
1510 end_pc = current_binding_level->end_pc;
1512 maybe_start_try (pc, end_pc);
1515 expand_start_bindings (0);
1517 current_binding_level->end_pc = end_pc;
1518 current_binding_level->start_pc = pc;
1519 current_binding_level->names = decl;
1520 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1522 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1526 maybe_start_try (pc, 0);
1530 maybe_poplevels (pc)
1533 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1537 while (current_binding_level->end_pc <= pc)
1539 expand_end_bindings (getdecls (), 1, 0);
1540 maybe_end_try (current_binding_level->start_pc, pc);
1543 maybe_end_try (0, pc);
1546 /* Terminate any binding which began during the range beginning at
1547 start_pc. This tidies up improperly nested local variable ranges
1548 and exception handlers; a variable declared within an exception
1549 range is forcibly terminated when that exception ends. */
1552 force_poplevels (start_pc)
1555 while (current_binding_level->start_pc > start_pc)
1557 if (pedantic && current_binding_level->start_pc > start_pc)
1558 warning_with_decl (current_function_decl,
1559 "In %s: overlapped variable and exception ranges at %d",
1560 current_binding_level->start_pc);
1561 expand_end_bindings (getdecls (), 1, 0);
1566 /* Insert BLOCK at the end of the list of subblocks of the
1567 current binding level. This is used when a BIND_EXPR is expanded,
1568 to handle the BLOCK node inside the BIND_EXPR. */
1571 insert_block (block)
1574 TREE_USED (block) = 1;
1575 current_binding_level->blocks
1576 = chainon (current_binding_level->blocks, block);
1579 /* Set the BLOCK node for the innermost scope
1580 (the one we are currently in). */
1584 register tree block;
1586 current_binding_level->this_block = block;
1589 /* integrate_decl_tree calls this function. */
1592 copy_lang_decl (node)
1596 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1597 : sizeof (struct lang_decl);
1598 struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1599 bcopy ((PTR) DECL_LANG_SPECIFIC (node), (PTR) x, lang_decl_size);
1600 DECL_LANG_SPECIFIC (node) = x;
1603 /* If DECL has a cleanup, build and return that cleanup here.
1604 This is a callback called by expand_expr. */
1607 maybe_build_cleanup (decl)
1608 tree decl ATTRIBUTE_UNUSED;
1610 /* There are no cleanups in Java (I think). */
1615 give_name_to_locals (jcf)
1618 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1620 pending_local_decls = NULL_TREE;
1624 n = JCF_readu2 (jcf);
1625 for (i = 0; i < n; i++)
1627 int start_pc = JCF_readu2 (jcf);
1628 int length = JCF_readu2 (jcf);
1629 int name_index = JCF_readu2 (jcf);
1630 int signature_index = JCF_readu2 (jcf);
1631 int slot = JCF_readu2 (jcf);
1632 tree name = get_name_constant (jcf, name_index);
1633 tree type = parse_signature (jcf, signature_index);
1634 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1636 && length == DECL_CODE_LENGTH (current_function_decl))
1638 tree decl = TREE_VEC_ELT (decl_map, slot);
1639 DECL_NAME (decl) = name;
1640 DECL_ASSEMBLER_NAME (decl) = name;
1641 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1642 warning ("bad type in parameter debug info");
1647 int end_pc = start_pc + length;
1648 tree decl = build_decl (VAR_DECL, name, type);
1649 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1651 warning_with_decl (decl,
1652 "bad PC range for debug info for local `%s'");
1653 end_pc = DECL_CODE_LENGTH (current_function_decl);
1655 DECL_LANG_SPECIFIC (decl)
1656 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1657 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1658 DECL_LOCAL_START_PC (decl) = start_pc;
1660 /* FIXME: The range used internally for exceptions and local
1661 variable ranges, is a half-open interval:
1662 start_pc <= pc < end_pc. However, the range used in the
1663 Java VM spec is inclusive at both ends:
1664 start_pc <= pc <= end_pc. */
1667 DECL_LOCAL_END_PC (decl) = end_pc;
1669 /* Now insert the new decl in the proper place in
1670 pending_local_decls. We are essentially doing an insertion sort,
1671 which works fine, since the list input will normally already
1673 ptr = &pending_local_decls;
1674 while (*ptr != NULL_TREE
1675 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1676 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1677 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1678 ptr = &TREE_CHAIN (*ptr);
1679 TREE_CHAIN (decl) = *ptr;
1684 pending_local_decls = nreverse (pending_local_decls);
1686 /* Fill in default names for the parameters. */
1687 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1688 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1690 if (DECL_NAME (parm) == NULL_TREE)
1692 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1694 DECL_NAME (parm) = get_identifier ("this");
1698 sprintf (buffer, "ARG_%d", arg_i);
1699 DECL_NAME (parm) = get_identifier (buffer);
1701 DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1707 build_result_decl (fndecl)
1710 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1711 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1712 if (INTEGRAL_TYPE_P (restype)
1713 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1714 restype = integer_type_node;
1715 return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
1718 /* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
1719 to emit initialization code for each test flag. */
1722 emit_init_test_initialization (entry, key)
1723 struct hash_entry *entry;
1724 hash_table_key key ATTRIBUTE_UNUSED;
1726 struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
1727 tree klass = build_class_ref ((tree) entry->key);
1728 expand_decl (ite->init_test_decl);
1730 /* We initialize the class init check variable by looking at the
1731 `state' field of the class to see if it is already initialized.
1732 This makes things a bit faster if the class is already
1733 initialized, which should be the common case. */
1735 (build (MODIFY_EXPR, boolean_type_node,
1736 ite->init_test_decl,
1737 build (GE_EXPR, boolean_type_node,
1738 build (COMPONENT_REF, byte_type_node,
1739 build1 (INDIRECT_REF, class_type_node, klass),
1740 lookup_field (&class_type_node,
1741 get_identifier ("state"))),
1742 build_int_2 (JV_STATE_DONE, 0))));
1748 complete_start_java_method (fndecl)
1751 if (! flag_emit_class_files)
1753 /* Initialize the RTL code for the function. */
1754 init_function_start (fndecl, input_filename, lineno);
1756 /* Set up parameters and prepare for return, for the function. */
1757 expand_function_start (fndecl, 0);
1759 /* Emit initialization code for test flags. */
1760 if (! always_initialize_class_p)
1761 hash_traverse (&DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1762 emit_init_test_initialization, 0);
1765 /* Allocate further tree nodes temporarily during compilation
1766 of this function only. */
1767 temporary_allocation ();
1770 /* If this fcn was already referenced via a block-scope `extern' decl (or
1771 an implicit decl), propagate certain information about the usage. */
1772 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1773 TREE_ADDRESSABLE (current_function_decl) = 1;
1777 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1778 && ! flag_emit_class_files
1779 && ! DECL_CLINIT_P (fndecl)
1780 && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1782 tree clas = DECL_CONTEXT (fndecl);
1783 tree init = build (CALL_EXPR, void_type_node,
1784 build_address_of (soft_initclass_node),
1785 build_tree_list (NULL_TREE, build_class_ref (clas)),
1787 TREE_SIDE_EFFECTS (init) = 1;
1788 expand_expr_stmt (init);
1791 /* Push local variables. Function compiled from source code are
1792 using a different local variables management, and for them,
1793 pushlevel shouldn't be called from here. */
1794 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1797 if (! flag_emit_class_files)
1798 expand_start_bindings (1);
1801 if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1803 /* Wrap function body with a monitorenter plus monitorexit cleanup. */
1804 tree enter, exit, lock;
1805 if (METHOD_STATIC (fndecl))
1806 lock = build_class_ref (DECL_CONTEXT (fndecl));
1808 lock = DECL_ARGUMENTS (fndecl);
1809 BUILD_MONITOR_ENTER (enter, lock);
1810 BUILD_MONITOR_EXIT (exit, lock);
1811 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1813 expand_expr_stmt (enter);
1814 expand_decl_cleanup (NULL_TREE, exit);
1818 tree function_body = DECL_FUNCTION_BODY (fndecl);
1819 tree body = BLOCK_EXPR_BODY (function_body);
1820 lock = build (WITH_CLEANUP_EXPR, void_type_node,
1821 enter, NULL_TREE, exit);
1822 TREE_SIDE_EFFECTS (lock) = 1;
1823 lock = build (COMPOUND_EXPR, TREE_TYPE (body), lock, body);
1824 TREE_SIDE_EFFECTS (lock) = 1;
1825 lock = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (body), lock);
1826 TREE_SIDE_EFFECTS (lock) = 1;
1827 BLOCK_EXPR_BODY (function_body) = lock;
1833 start_java_method (fndecl)
1839 current_function_decl = fndecl;
1840 announce_function (fndecl);
1842 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1843 decl_map = make_tree_vec (i);
1844 type_map = (tree *) oballoc (i * sizeof (tree));
1846 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1847 fprintf (stderr, "%s:\n", (*decl_printable_name) (fndecl, 2));
1849 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1850 pushlevel (1); /* Push parameters. */
1852 ptr = &DECL_ARGUMENTS (fndecl);
1853 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1854 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1856 tree parm_name = NULL_TREE, parm_decl;
1857 tree parm_type = TREE_VALUE (tem);
1858 if (i >= DECL_MAX_LOCALS(fndecl))
1859 fatal ("function has more parameters than local slots");
1861 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1862 DECL_CONTEXT (parm_decl) = fndecl;
1863 if (PROMOTE_PROTOTYPES
1864 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1865 && INTEGRAL_TYPE_P (parm_type))
1866 parm_type = integer_type_node;
1867 DECL_ARG_TYPE (parm_decl) = parm_type;
1870 ptr = &TREE_CHAIN (parm_decl);
1872 /* Add parm_decl to the decl_map. */
1873 push_jvm_slot (i, parm_decl);
1875 type_map[i] = TREE_TYPE (parm_decl);
1876 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1879 type_map[i] = void_type_node;
1883 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1885 while (i < DECL_MAX_LOCALS(fndecl))
1886 type_map[i++] = NULL_TREE;
1888 build_result_decl (fndecl);
1889 complete_start_java_method (fndecl);
1895 tree fndecl = current_function_decl;
1896 int flag_asynchronous_exceptions = asynchronous_exceptions;
1898 expand_end_bindings (getdecls (), 1, 0);
1899 /* pop out of function */
1902 /* pop out of its parameters */
1905 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1909 /* Generate rtl for function exit. */
1910 expand_function_end (input_filename, lineno, 0);
1912 /* FIXME: If the current method contains any exception handlers,
1913 force asynchronous_exceptions: this is necessary because signal
1914 handlers in libjava may throw exceptions. This is far from being
1915 a perfect solution, but it's better than doing nothing at all.*/
1917 asynchronous_exceptions = 1;
1919 /* Run the optimizers and output assembler code for this function. */
1920 rest_of_compilation (fndecl);
1922 current_function_decl = NULL_TREE;
1923 permanent_allocation (1);
1924 asynchronous_exceptions = flag_asynchronous_exceptions;