1 /* Process declarations and variables for the GNU compiler for the
4 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc. */
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
34 #include "java-tree.h"
40 #include "java-except.h"
42 #if defined (DEBUG_JAVA_BINDING_LEVELS)
43 extern void indent
PROTO((void));
46 static tree push_jvm_slot
PARAMS ((int, tree
));
47 static tree lookup_name_current_level
PARAMS ((tree
));
48 static tree push_promoted_type
PARAMS ((const char *, tree
));
49 static struct binding_level
*make_binding_level
PARAMS ((void));
51 /* Set to non-zero value in order to emit class initilization code
52 before static field references. */
53 extern int always_initialize_class_p
;
56 #define INT_TYPE_SIZE BITS_PER_WORD
59 /* The DECL_MAP is a mapping from (index, type) to a decl node.
60 If index < max_locals, it is the index of a local variable.
61 if index >= max_locals, then index-max_locals is a stack slot.
62 The DECL_MAP mapping is represented as a TREE_VEC whose elements
63 are a list of decls (VAR_DECL or PARM_DECL) chained by
64 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
65 we search the chain for a decl with a matching TREE_TYPE. */
69 /* A list of local variables VAR_DECLs for this method that we have seen
70 debug information, but we have not reached their starting (byte) PC yet. */
72 tree pending_local_decls
= NULL_TREE
;
74 /* Push a local variable or stack slot into the decl_map,
75 and assign it an rtl. */
77 #if defined(DEBUG_JAVA_BINDING_LEVELS)
78 int binding_depth
= 0;
79 int is_class_level
= 0;
87 for (i
= 0; i
< binding_depth
*2; i
++)
90 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
93 push_jvm_slot (index
, decl
)
97 struct rtx_def
*rtl
= NULL
;
98 tree type
= TREE_TYPE (decl
);
101 DECL_CONTEXT (decl
) = current_function_decl
;
102 layout_decl (decl
, 0);
104 /* See if we have an appropriate rtl (i.e. same mode) at this index.
105 If so, we must use it. */
106 tmp
= TREE_VEC_ELT (decl_map
, index
);
107 while (tmp
!= NULL_TREE
)
109 if (TYPE_MODE (type
) == TYPE_MODE (TREE_TYPE (tmp
)))
110 rtl
= DECL_RTL (tmp
);
113 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
116 DECL_RTL (decl
) = rtl
;
119 if (index
>= DECL_MAX_LOCALS (current_function_decl
))
120 DECL_REGISTER (decl
) = 1;
124 /* Now link the decl into the decl_map. */
125 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
127 DECL_LANG_SPECIFIC (decl
)
128 = (struct lang_decl
*) permalloc (sizeof (struct lang_decl_var
));
129 DECL_LOCAL_START_PC (decl
) = 0;
130 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
131 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
133 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
134 TREE_VEC_ELT (decl_map
, index
) = decl
;
138 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
139 that is valid at PC (or -1 if any pc).
140 If there is no existing matching decl, allocate one.
141 If we find a decl with matching modes but different types,
142 we re-use the rtl, but create a new decl. */
145 find_local_variable (index
, type
, pc
)
150 tree decl
= TREE_VEC_ELT (decl_map
, index
);
151 tree best
= NULL_TREE
;
152 while (decl
!= NULL_TREE
)
156 || (pc
>= DECL_LOCAL_START_PC (decl
)
157 && pc
< DECL_LOCAL_END_PC (decl
));
159 if ((TREE_TYPE (decl
) == type
160 || (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
161 && type
== ptr_type_node
))
164 if (best
== NULL_TREE
165 || (TREE_TYPE (decl
) == type
&& TREE_TYPE (best
) != type
)
166 || DECL_LOCAL_START_PC (decl
) > DECL_LOCAL_START_PC (best
)
167 || DECL_LOCAL_END_PC (decl
) < DECL_LOCAL_START_PC (decl
))
170 decl
= DECL_LOCAL_SLOT_CHAIN (decl
);
172 if (best
!= NULL_TREE
)
174 return push_jvm_slot (index
, build_decl (VAR_DECL
, NULL_TREE
, type
));
178 /* Same as find_local_index, except that INDEX is a stack index. */
181 find_stack_slot (index
, type
)
185 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
191 /* A chain of _DECL nodes for all variables, constants, functions,
192 * and typedef types. These are in the reverse of the order supplied.
196 /* For each level, a list of shadowed outer-level local definitions
197 to be restored when this level is popped.
198 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
199 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
202 /* For each level (except not the global one),
203 a chain of BLOCK nodes for all the levels
204 that were entered and exited one level down. */
207 /* The BLOCK node for this level, if one has been preallocated.
208 If 0, the BLOCK is allocated (if needed) when the level is popped. */
211 /* The binding level which this one is contained in (inherits from). */
212 struct binding_level
*level_chain
;
214 /* 1 means make a BLOCK for this level regardless of all else.
215 2 for temporary binding contours created by the compiler. */
218 /* Nonzero means make a BLOCK if this level has any subblocks. */
219 char keep_if_subblocks
;
221 /* Nonzero if this level can safely have additional
222 cleanup-needing variables added to it. */
223 char more_cleanups_ok
;
226 /* The bytecode PC that marks the end of this level. */
228 /* The bytecode PC that marks the start of this level. */
231 #if defined(DEBUG_JAVA_BINDING_LEVELS)
232 /* Binding depth at which this level began. */
233 unsigned binding_depth
;
234 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
237 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
239 /* The binding level currently in effect. */
241 static struct binding_level
*current_binding_level
;
243 /* A chain of binding_level structures awaiting reuse. */
245 static struct binding_level
*free_binding_level
;
247 /* The outermost binding level, for names of file scope.
248 This is created when the compiler is started and exists
249 through the entire run. */
251 static struct binding_level
*global_binding_level
;
253 /* A PC value bigger than any PC value we may ever may encounter. */
255 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
257 /* Binding level structures are initialized by copying this one. */
259 static struct binding_level clear_binding_level
260 = {NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
,
261 NULL_BINDING_LEVEL
, 0, 0, 0, 0, LARGEST_PC
, 0};
264 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
265 that have names. Here so we can clear out their names' definitions
266 at the end of the function. */
268 static tree named_labels
;
270 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
272 static tree shadowed_labels
;
275 int flag_traditional
;
277 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
279 static int keep_next_level_flag
;
281 /* Nonzero means make a BLOCK for the next level pushed
282 if it has subblocks. */
284 static int keep_next_if_subblocks
;
286 tree object_type_node
;
287 tree unqualified_object_id_node
;
288 tree object_ptr_type_node
;
289 tree string_type_node
;
290 tree string_ptr_type_node
;
291 tree throwable_type_node
;
292 tree runtime_exception_type_node
;
293 tree error_exception_type_node
;
294 tree
*predef_filenames
;
295 int predef_filenames_size
;
297 tree boolean_type_node
;
299 tree return_address_type_node
;
302 tree short_type_node
;
306 tree promoted_byte_type_node
;
307 tree promoted_short_type_node
;
308 tree promoted_char_type_node
;
309 tree promoted_boolean_type_node
;
311 tree unsigned_byte_type_node
;
312 tree unsigned_short_type_node
;
313 tree unsigned_int_type_node
;
314 tree unsigned_long_type_node
;
316 /* The type for struct methodtable. */
317 tree methodtable_type
;
318 tree methodtable_ptr_type
;
321 tree utf8const_ptr_type
;
322 tree class_type_node
;
324 tree field_type_node
;
325 tree field_ptr_type_node
;
326 tree field_info_union_node
;
327 tree jexception_type
;
328 tree jexception_ptr_type
;
329 tree lineNumberEntry_type
;
330 tree lineNumbers_type
;
331 tree constants_type_node
;
333 tree dtable_ptr_type
;
334 tree method_type_node
;
335 tree method_ptr_type_node
;
336 tree nativecode_ptr_array_type_node
;
337 tree one_elt_array_domain_type
;
338 tree access_flags_type_node
;
339 tree class_dtable_decl
;
341 /* Expressions that are constants with value zero, of types
342 `long', `float' and `double'. */
344 tree float_zero_node
;
345 tree double_zero_node
;
347 tree empty_stmt_node
;
349 /* Nodes for boolean constants TRUE and FALSE. */
350 tree boolean_true_node
, boolean_false_node
;
352 tree TYPE_identifier_node
;
353 tree init_identifier_node
;
354 tree clinit_identifier_node
;
355 tree finit_identifier_node
;
356 tree void_signature_node
;
357 tree length_identifier_node
;
358 tree this_identifier_node
;
359 tree super_identifier_node
;
360 tree continue_identifier_node
;
362 tree end_params_node
;
364 /* References to internal libjava functions we use. */
365 tree alloc_object_node
;
366 tree soft_instanceof_node
;
367 tree soft_checkcast_node
;
368 tree soft_initclass_node
;
369 tree soft_newarray_node
;
370 tree soft_anewarray_node
;
371 tree soft_multianewarray_node
;
372 tree soft_badarrayindex_node
;
374 tree soft_checkarraystore_node
;
375 tree soft_monitorenter_node
;
376 tree soft_monitorexit_node
;
377 tree soft_lookupinterfacemethod_node
;
379 tree soft_exceptioninfo_call_node
;
385 /* Build (and pushdecl) a "promoted type" for all standard
386 types shorter than int. */
389 push_promoted_type (name
, actual_type
)
393 tree type
= make_node (TREE_CODE (actual_type
));
395 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
396 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
398 tree in_min
= TYPE_MIN_VALUE (actual_type
);
399 tree in_max
= TYPE_MAX_VALUE (actual_type
);
401 TYPE_MIN_VALUE (type
) = build_int_2 (TREE_INT_CST_LOW (in_min
),
402 TREE_INT_CST_HIGH (in_min
));
403 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
404 TYPE_MAX_VALUE (type
) = build_int_2 (TREE_INT_CST_LOW (in_max
),
405 TREE_INT_CST_HIGH (in_max
));
406 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
407 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
409 pushdecl (build_decl (TYPE_DECL
, get_identifier (name
), type
));
413 /* Nodes for integer constants. */
414 tree integer_two_node
, integer_four_node
;
415 tree integer_negative_one_node
;
417 /* Return a definition for a builtin function named NAME and whose data type
418 is TYPE. TYPE should be a function type with argument types.
419 FUNCTION_CODE tells later passes how to compile calls to this function.
420 See tree.h for its possible values.
422 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
423 the name to be called if we can't opencode the function. */
426 builtin_function (name
, type
, function_code
, class, library_name
)
430 enum built_in_class
class;
431 const char *library_name
;
433 tree decl
= build_decl (FUNCTION_DECL
, get_identifier (name
), type
);
434 DECL_EXTERNAL (decl
) = 1;
435 TREE_PUBLIC (decl
) = 1;
437 DECL_ASSEMBLER_NAME (decl
) = get_identifier (library_name
);
438 make_decl_rtl (decl
, NULL_PTR
, 1);
440 DECL_BUILT_IN_CLASS (decl
) = class;
441 DECL_FUNCTION_CODE (decl
) = function_code
;
446 init_decl_processing ()
448 register tree endlink
;
449 tree field
= NULL_TREE
;
452 current_function_decl
= NULL
;
453 current_binding_level
= NULL_BINDING_LEVEL
;
454 free_binding_level
= NULL_BINDING_LEVEL
;
455 pushlevel (0); /* make the binding_level structure for global names */
456 global_binding_level
= current_binding_level
;
458 error_mark_node
= make_node (ERROR_MARK
);
459 TREE_TYPE (error_mark_node
) = error_mark_node
;
461 /* Create sizetype first - needed for other types. */
462 initialize_sizetypes ();
463 set_sizetype (make_unsigned_type (POINTER_SIZE
));
464 size_zero_node
= build_int_2 (0, 0);
465 TREE_TYPE (size_zero_node
) = sizetype
;
466 size_one_node
= build_int_2 (1, 0);
467 TREE_TYPE (size_one_node
) = sizetype
;
469 byte_type_node
= make_signed_type (8);
470 pushdecl (build_decl (TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
471 short_type_node
= make_signed_type (16);
472 pushdecl (build_decl (TYPE_DECL
, get_identifier ("short"), short_type_node
));
473 int_type_node
= make_signed_type (32);
474 pushdecl (build_decl (TYPE_DECL
, get_identifier ("int"), int_type_node
));
475 long_type_node
= make_signed_type (64);
476 pushdecl (build_decl (TYPE_DECL
, get_identifier ("long"), long_type_node
));
478 unsigned_byte_type_node
= make_unsigned_type (8);
479 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned byte"),
480 unsigned_byte_type_node
));
481 unsigned_short_type_node
= make_unsigned_type (16);
482 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned short"),
483 unsigned_short_type_node
));
484 unsigned_int_type_node
= make_unsigned_type (32);
485 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned int"),
486 unsigned_int_type_node
));
487 unsigned_long_type_node
= make_unsigned_type (64);
488 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned long"),
489 unsigned_long_type_node
));
491 integer_type_node
= type_for_size (INT_TYPE_SIZE
, 0);
493 integer_zero_node
= build_int_2 (0, 0);
494 integer_one_node
= build_int_2 (1, 0);
495 integer_two_node
= build_int_2 (2, 0);
496 integer_four_node
= build_int_2 (4, 0);
497 integer_negative_one_node
= build_int_2 (-1, 0);
499 long_zero_node
= build_int_2 (0, 0);
500 TREE_TYPE (long_zero_node
) = long_type_node
;
502 void_type_node
= make_node (VOID_TYPE
);
503 pushdecl (build_decl (TYPE_DECL
, get_identifier ("void"), void_type_node
));
504 layout_type (void_type_node
); /* Uses size_zero_node */
505 ptr_type_node
= build_pointer_type (void_type_node
);
506 t
= make_node (VOID_TYPE
);
507 layout_type (t
); /* Uses size_zero_node */
508 return_address_type_node
= build_pointer_type (t
);
510 null_pointer_node
= build_int_2 (0, 0);
511 TREE_TYPE (null_pointer_node
) = ptr_type_node
;
513 /* Used by the parser to represent empty statements and blocks. */
514 empty_stmt_node
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
515 CAN_COMPLETE_NORMALLY (empty_stmt_node
) = 1;
518 /* Make a type to be the domain of a few array types
519 whose domains don't really matter.
520 200 is small enough that it always fits in size_t
521 and large enough that it can hold most function names for the
522 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
523 short_array_type_node
= build_prim_array_type (short_type_node
, 200);
525 char_type_node
= make_node (CHAR_TYPE
);
526 TYPE_PRECISION (char_type_node
) = 16;
527 fixup_unsigned_type (char_type_node
);
528 pushdecl (build_decl (TYPE_DECL
, get_identifier ("char"), char_type_node
));
530 boolean_type_node
= make_node (BOOLEAN_TYPE
);
531 TYPE_PRECISION (boolean_type_node
) = 1;
532 fixup_unsigned_type (boolean_type_node
);
533 pushdecl (build_decl (TYPE_DECL
, get_identifier ("boolean"),
535 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
536 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
538 promoted_byte_type_node
539 = push_promoted_type ("promoted_byte", byte_type_node
);
540 promoted_short_type_node
541 = push_promoted_type ("promoted_short", short_type_node
);
542 promoted_char_type_node
543 = push_promoted_type ("promoted_char", char_type_node
);
544 promoted_boolean_type_node
545 = push_promoted_type ("promoted_boolean", boolean_type_node
);
547 float_type_node
= make_node (REAL_TYPE
);
548 TYPE_PRECISION (float_type_node
) = 32;
549 pushdecl (build_decl (TYPE_DECL
, get_identifier ("float"),
551 layout_type (float_type_node
);
553 double_type_node
= make_node (REAL_TYPE
);
554 TYPE_PRECISION (double_type_node
) = 64;
555 pushdecl (build_decl (TYPE_DECL
, get_identifier ("double"),
557 layout_type (double_type_node
);
559 float_zero_node
= build_real (float_type_node
, dconst0
);
560 double_zero_node
= build_real (double_type_node
, dconst0
);
562 /* As your adding items here, please update the code right after
563 this section, so that the filename containing the source code of
564 the pre-defined class gets registered correctly. */
565 unqualified_object_id_node
= get_identifier ("Object");
566 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
567 object_ptr_type_node
= promote_type (object_type_node
);
568 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
569 string_ptr_type_node
= promote_type (string_type_node
);
570 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
571 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
572 runtime_exception_type_node
=
573 lookup_class (get_identifier ("java.lang.RuntimeException"));
574 error_exception_type_node
=
575 lookup_class (get_identifier ("java.lang.Error"));
577 /* This section has to be updated as items are added to the previous
579 predef_filenames_size
= 6;
580 predef_filenames
= (tree
*)xmalloc (predef_filenames_size
* sizeof (tree
));
581 predef_filenames
[0] = get_identifier ("java/lang/Class.java");
582 predef_filenames
[1] = get_identifier ("java/lang/Error.java");
583 predef_filenames
[2] = get_identifier ("java/lang/Object.java");
584 predef_filenames
[3] = get_identifier ("java/lang/RuntimeException.java");
585 predef_filenames
[4] = get_identifier ("java/lang/String.java");
586 predef_filenames
[5] = get_identifier ("java/lang/Throwable.java");
588 methodtable_type
= make_node (RECORD_TYPE
);
589 layout_type (methodtable_type
);
590 build_decl (TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
591 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
593 TYPE_identifier_node
= get_identifier ("TYPE");
594 init_identifier_node
= get_identifier ("<init>");
595 clinit_identifier_node
= get_identifier ("<clinit>");
596 finit_identifier_node
= get_identifier ("$finit$");
597 void_signature_node
= get_identifier ("()V");
598 length_identifier_node
= get_identifier ("length");
599 this_identifier_node
= get_identifier ("this");
600 super_identifier_node
= get_identifier ("super");
601 continue_identifier_node
= get_identifier ("continue");
603 /* for lack of a better place to put this stub call */
604 init_expr_processing();
606 utf8const_type
= make_node (RECORD_TYPE
);
607 PUSH_FIELD (utf8const_type
, field
, "hash", unsigned_short_type_node
);
608 PUSH_FIELD (utf8const_type
, field
, "length", unsigned_short_type_node
);
609 FINISH_RECORD (utf8const_type
);
610 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
612 constants_type_node
= make_node (RECORD_TYPE
);
613 PUSH_FIELD (constants_type_node
, field
, "size", unsigned_int_type_node
);
614 PUSH_FIELD (constants_type_node
, field
, "tags", ptr_type_node
);
615 PUSH_FIELD (constants_type_node
, field
, "data", ptr_type_node
);
616 FINISH_RECORD (constants_type_node
);
617 build_decl (TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
619 access_flags_type_node
= unsigned_short_type_node
;
621 dtable_type
= make_node (RECORD_TYPE
);
622 dtable_ptr_type
= build_pointer_type (dtable_type
);
624 PUSH_FIELD (object_type_node
, field
, "vtable", dtable_ptr_type
);
625 PUSH_FIELD (object_type_node
, field
, "sync_info", ptr_type_node
);
626 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
627 FIELD_PRIVATE (t
) = 1;
628 FINISH_RECORD (object_type_node
);
630 class_dtable_decl
= build_dtable_decl (class_type_node
);
631 TREE_STATIC (class_dtable_decl
) = 1;
632 DECL_ARTIFICIAL (class_dtable_decl
) = 1;
633 DECL_IGNORED_P (class_dtable_decl
) = 1;
634 rest_of_decl_compilation (class_dtable_decl
, (char*) 0, 1, 0);
636 field_type_node
= make_node (RECORD_TYPE
);
637 field_ptr_type_node
= build_pointer_type (field_type_node
);
638 method_type_node
= make_node (RECORD_TYPE
);
639 method_ptr_type_node
= build_pointer_type (method_type_node
);
641 set_super_info (0, class_type_node
, object_type_node
, 0);
642 set_super_info (0, string_type_node
, object_type_node
, 0);
643 class_ptr_type
= build_pointer_type (class_type_node
);
645 PUSH_FIELD (class_type_node
, field
, "next", class_ptr_type
);
646 PUSH_FIELD (class_type_node
, field
, "name", utf8const_ptr_type
);
647 PUSH_FIELD (class_type_node
, field
, "accflags", access_flags_type_node
);
648 PUSH_FIELD (class_type_node
, field
, "superclass", class_ptr_type
);
649 PUSH_FIELD (class_type_node
, field
, "constants", constants_type_node
);
650 PUSH_FIELD (class_type_node
, field
, "methods", method_ptr_type_node
);
651 PUSH_FIELD (class_type_node
, field
, "method_count", short_type_node
);
652 PUSH_FIELD (class_type_node
, field
, "vtable_method_count", short_type_node
);
653 PUSH_FIELD (class_type_node
, field
, "fields", field_ptr_type_node
);
654 PUSH_FIELD (class_type_node
, field
, "size_in_bytes", int_type_node
);
655 PUSH_FIELD (class_type_node
, field
, "field_count", short_type_node
);
656 PUSH_FIELD (class_type_node
, field
, "static_field_count", short_type_node
);
657 PUSH_FIELD (class_type_node
, field
, "vtable", dtable_ptr_type
);
658 PUSH_FIELD (class_type_node
, field
, "interfaces",
659 build_pointer_type (class_ptr_type
));
660 PUSH_FIELD (class_type_node
, field
, "loader", ptr_type_node
);
661 PUSH_FIELD (class_type_node
, field
, "interface_count", short_type_node
);
662 PUSH_FIELD (class_type_node
, field
, "state", byte_type_node
);
663 PUSH_FIELD (class_type_node
, field
, "thread", ptr_type_node
);
664 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
665 FIELD_PRIVATE (t
) = 1;
666 push_super_field (class_type_node
, object_type_node
);
667 FINISH_RECORD (class_type_node
);
668 build_decl (TYPE_DECL
, get_identifier ("Class"), class_type_node
);
670 field_info_union_node
= make_node (UNION_TYPE
);
671 PUSH_FIELD (field_info_union_node
, field
, "boffset", int_type_node
);
672 PUSH_FIELD (field_info_union_node
, field
, "addr", ptr_type_node
);
674 PUSH_FIELD (field_info_union_node
, field
, "idx", unsigned_short_type_node
);
676 layout_type (field_info_union_node
);
678 PUSH_FIELD (field_type_node
, field
, "name", utf8const_ptr_type
);
679 PUSH_FIELD (field_type_node
, field
, "type", class_ptr_type
);
680 PUSH_FIELD (field_type_node
, field
, "accflags", access_flags_type_node
);
681 PUSH_FIELD (field_type_node
, field
, "bsize", unsigned_short_type_node
);
682 PUSH_FIELD (field_type_node
, field
, "info", field_info_union_node
);
683 FINISH_RECORD (field_type_node
);
684 CLASS_LOADED_P (field_type_node
) = 1;
685 build_decl (TYPE_DECL
, get_identifier ("Field"), field_type_node
);
687 one_elt_array_domain_type
= build_index_type (integer_one_node
);
688 nativecode_ptr_array_type_node
689 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
691 PUSH_FIELD (dtable_type
, field
, "class", class_ptr_type
);
692 PUSH_FIELD (dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
693 FINISH_RECORD (dtable_type
);
694 build_decl (TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
696 #define jint_type int_type_node
697 #define jint_ptr_type ptr_type_node
699 jexception_type
= make_node (RECORD_TYPE
);
700 PUSH_FIELD (jexception_type
, field
, "start_pc", ptr_type_node
);
701 PUSH_FIELD (jexception_type
, field
, "end_pc", ptr_type_node
);
702 PUSH_FIELD (jexception_type
, field
, "handler_pc", ptr_type_node
);
703 PUSH_FIELD (jexception_type
, field
, "catch_type", class_ptr_type
);
704 FINISH_RECORD (jexception_type
);
705 build_decl (TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
706 jexception_ptr_type
= build_pointer_type (jexception_type
);
708 lineNumberEntry_type
= make_node (RECORD_TYPE
);
709 PUSH_FIELD (lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
710 PUSH_FIELD (lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
711 FINISH_RECORD (lineNumberEntry_type
);
713 lineNumbers_type
= make_node (RECORD_TYPE
);
714 PUSH_FIELD (lineNumbers_type
, field
, "length", unsigned_int_type_node
);
715 FINISH_RECORD (lineNumbers_type
);
717 #define instn_ptr_type_node ptr_type_node /* XXX JH */
719 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
721 PUSH_FIELD (method_type_node
, field
, "name", utf8const_ptr_type
);
722 PUSH_FIELD (method_type_node
, field
, "signature", utf8const_ptr_type
);
723 PUSH_FIELD (method_type_node
, field
, "accflags", access_flags_type_node
);
724 PUSH_FIELD (method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
725 FINISH_RECORD (method_type_node
);
726 CLASS_LOADED_P (method_type_node
) = 1;
727 build_decl (TYPE_DECL
, get_identifier ("Method"), method_type_node
);
729 endlink
= end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
731 t
= tree_cons (NULL_TREE
, class_ptr_type
,
732 tree_cons (NULL_TREE
, int_type_node
, endlink
));
733 alloc_object_node
= builtin_function ("_Jv_AllocObject",
734 build_function_type (ptr_type_node
, t
),
735 0, NOT_BUILT_IN
, NULL_PTR
);
736 DECL_IS_MALLOC (alloc_object_node
) = 1;
737 soft_initclass_node
= builtin_function ("_Jv_InitClass",
738 build_function_type (void_type_node
,
742 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
743 throw_node
[0] = builtin_function ("_Jv_Throw",
744 build_function_type (ptr_type_node
, t
),
745 0, NOT_BUILT_IN
, NULL_PTR
);
746 /* Mark throw_nodes as `noreturn' functions with side effects. */
747 TREE_THIS_VOLATILE (throw_node
[0]) = 1;
748 TREE_SIDE_EFFECTS (throw_node
[0]) = 1;
749 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
750 throw_node
[1] = builtin_function ("_Jv_Sjlj_Throw",
751 build_function_type (ptr_type_node
, t
),
752 0, NOT_BUILT_IN
, NULL_PTR
);
753 TREE_THIS_VOLATILE (throw_node
[1]) = 1;
754 TREE_SIDE_EFFECTS (throw_node
[1]) = 1;
755 t
= build_function_type (int_type_node
, endlink
);
756 soft_monitorenter_node
757 = builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
759 soft_monitorexit_node
760 = builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
763 t
= tree_cons (NULL_TREE
, int_type_node
,
764 tree_cons (NULL_TREE
, int_type_node
, endlink
));
766 = builtin_function ("_Jv_NewArray",
767 build_function_type(ptr_type_node
, t
),
768 0, NOT_BUILT_IN
, NULL_PTR
);
769 DECL_IS_MALLOC (soft_newarray_node
) = 1;
771 t
= tree_cons (NULL_TREE
, int_type_node
,
772 tree_cons (NULL_TREE
, class_ptr_type
,
773 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
)));
775 = builtin_function ("_Jv_NewObjectArray",
776 build_function_type (ptr_type_node
, t
),
777 0, NOT_BUILT_IN
, NULL_PTR
);
778 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
780 t
= tree_cons (NULL_TREE
, ptr_type_node
,
781 tree_cons (NULL_TREE
, int_type_node
, endlink
));
782 soft_multianewarray_node
783 = builtin_function ("_Jv_NewMultiArray",
784 build_function_type (ptr_type_node
, t
),
785 0, NOT_BUILT_IN
, NULL_PTR
);
786 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
788 t
= build_function_type (void_type_node
,
789 tree_cons (NULL_TREE
, int_type_node
, endlink
));
790 soft_badarrayindex_node
791 = builtin_function ("_Jv_ThrowBadArrayIndex", t
,
792 0, NOT_BUILT_IN
, NULL_PTR
);
793 /* Mark soft_badarrayindex_node as a `noreturn' function with side
795 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
796 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
798 t
= tree_cons (NULL_TREE
, class_ptr_type
,
799 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
801 = builtin_function ("_Jv_CheckCast",
802 build_function_type (ptr_type_node
, t
),
803 0, NOT_BUILT_IN
, NULL_PTR
);
804 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
805 tree_cons (NULL_TREE
, class_ptr_type
, endlink
));
807 = builtin_function ("_Jv_IsInstanceOf",
808 build_function_type (boolean_type_node
, t
),
809 0, NOT_BUILT_IN
, NULL_PTR
);
810 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
811 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
812 soft_checkarraystore_node
813 = builtin_function ("_Jv_CheckArrayStore",
814 build_function_type (void_type_node
, t
),
815 0, NOT_BUILT_IN
, NULL_PTR
);
816 t
= tree_cons (NULL_TREE
, ptr_type_node
,
817 tree_cons (NULL_TREE
, ptr_type_node
,
818 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)));
819 soft_lookupinterfacemethod_node
820 = builtin_function ("_Jv_LookupInterfaceMethod",
821 build_function_type (ptr_type_node
, t
),
822 0, NOT_BUILT_IN
, NULL_PTR
);
823 t
= tree_cons (NULL_TREE
, double_type_node
,
824 tree_cons (NULL_TREE
, double_type_node
, endlink
));
826 = builtin_function ("__builtin_fmod",
827 build_function_type (double_type_node
, t
),
828 BUILT_IN_FMOD
, BUILT_IN_NORMAL
, "fmod");
830 soft_exceptioninfo_call_node
834 (builtin_function ("_Jv_exception_info",
835 build_function_type (ptr_type_node
, endlink
),
836 0, NOT_BUILT_IN
, NULL_PTR
)),
837 NULL_TREE
, NULL_TREE
);
838 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node
) = 1;
840 t
= tree_cons (NULL_TREE
, float_type_node
,
841 tree_cons (NULL_TREE
, float_type_node
, endlink
));
843 = builtin_function ("__builtin_fmodf",
844 build_function_type (float_type_node
, t
),
845 BUILT_IN_FMOD
, BUILT_IN_NORMAL
, "fmodf");
849 = builtin_function ("_Jv_divI",
850 build_function_type (int_type_node
, t
),
851 0, NOT_BUILT_IN
, NULL_PTR
);
854 = builtin_function ("_Jv_remI",
855 build_function_type (int_type_node
, t
),
856 0, NOT_BUILT_IN
, NULL_PTR
);
859 = builtin_function ("_Jv_divJ",
860 build_function_type (long_type_node
, t
),
861 0, NOT_BUILT_IN
, NULL_PTR
);
864 = builtin_function ("_Jv_remJ",
865 build_function_type (long_type_node
, t
),
866 0, NOT_BUILT_IN
, NULL_PTR
);
868 init_class_processing ();
872 /* Look up NAME in the current binding level and its superiors
873 in the namespace of variables, functions and typedefs.
874 Return a ..._DECL node of some kind representing its definition,
875 or return 0 if it is undefined. */
882 if (current_binding_level
!= global_binding_level
883 && IDENTIFIER_LOCAL_VALUE (name
))
884 val
= IDENTIFIER_LOCAL_VALUE (name
);
886 val
= IDENTIFIER_GLOBAL_VALUE (name
);
890 /* Similar to `lookup_name' but look only at current binding level and
891 the previous one if its the parameter level. */
894 lookup_name_current_level (name
)
899 if (current_binding_level
== global_binding_level
)
900 return IDENTIFIER_GLOBAL_VALUE (name
);
902 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
905 for (t
= current_binding_level
->names
; t
; t
= TREE_CHAIN (t
))
906 if (DECL_NAME (t
) == name
)
912 /* Use a binding level to record a labeled block declaration */
915 push_labeled_block (lb
)
918 register tree name
= DECL_NAME (LABELED_BLOCK_LABEL (lb
));
919 register struct binding_level
*b
= current_binding_level
;
920 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
922 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
923 TREE_CHAIN (lb
) = b
->names
;
925 IDENTIFIER_LOCAL_VALUE (name
) = lb
;
928 /* Pop the current binding level, reinstalling values for the previous
934 struct binding_level
*b
= current_binding_level
;
935 tree label
= b
->names
;
936 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label
))) =
939 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b
->shadowed
)) =
940 TREE_VALUE (b
->shadowed
);
942 /* Pop the current level, and free the structure for reuse. */
943 current_binding_level
= current_binding_level
->level_chain
;
944 b
->level_chain
= free_binding_level
;
945 free_binding_level
= b
;
948 /* Record a decl-node X as belonging to the current lexical scope.
949 Check for errors (such as an incompatible declaration for the same
950 name already seen in the same scope).
952 Returns either X or an old decl for the same name.
953 If an old decl is returned, it may have been smashed
954 to agree with what X says. */
961 register tree name
= DECL_NAME (x
);
962 register struct binding_level
*b
= current_binding_level
;
964 DECL_CONTEXT (x
) = current_function_decl
;
970 t
= lookup_name_current_level (name
);
971 if (t
!= 0 && t
== error_mark_node
)
972 /* error_mark_node is 0 for a while during initialization! */
975 error_with_decl (x
, "`%s' used prior to declaration");
980 file
= DECL_SOURCE_FILE (t
);
981 line
= DECL_SOURCE_LINE (t
);
984 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
985 to point to the TYPE_DECL.
986 Since Java does not have typedefs, a type can only have
987 one (true) name, given by a class, interface, or builtin. */
988 if (TREE_CODE (x
) == TYPE_DECL
989 && TYPE_NAME (TREE_TYPE (x
)) == 0
990 && TREE_TYPE (x
) != error_mark_node
)
992 TYPE_NAME (TREE_TYPE (x
)) = x
;
993 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
996 /* This name is new in its binding level.
997 Install the new declaration and return it. */
998 if (b
== global_binding_level
)
1000 /* Install a global value. */
1002 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1006 /* Here to install a non-global value. */
1007 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1008 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1011 /* Warn if shadowing an argument at the top level of the body. */
1012 if (oldlocal
!= 0 && !DECL_EXTERNAL (x
)
1013 /* This warning doesn't apply to the parms of a nested fcn. */
1014 && ! current_binding_level
->parm_flag
1015 /* Check that this is one level down from the parms. */
1016 && current_binding_level
->level_chain
->parm_flag
1017 /* Check that the decl being shadowed
1018 comes from the parm level, one level up. */
1019 && chain_member (oldlocal
, current_binding_level
->level_chain
->names
))
1021 if (TREE_CODE (oldlocal
) == PARM_DECL
)
1022 pedwarn ("declaration of `%s' shadows a parameter",
1023 IDENTIFIER_POINTER (name
));
1025 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1026 IDENTIFIER_POINTER (name
));
1029 /* Maybe warn if shadowing something else. */
1030 else if (warn_shadow
&& !DECL_EXTERNAL (x
)
1031 /* No shadow warnings for internally generated vars. */
1032 && DECL_SOURCE_LINE (x
) != 0
1033 /* No shadow warnings for vars made for inlining. */
1034 && ! DECL_FROM_INLINE (x
))
1036 const char *warnstring
= 0;
1038 if (TREE_CODE (x
) == PARM_DECL
1039 && current_binding_level
->level_chain
->parm_flag
)
1040 /* Don't warn about the parm names in function declarator
1041 within a function declarator.
1042 It would be nice to avoid warning in any function
1043 declarator in a declaration, as opposed to a definition,
1044 but there is no way to tell it's not a definition. */
1046 else if (oldlocal
!= 0 && TREE_CODE (oldlocal
) == PARM_DECL
)
1047 warnstring
= "declaration of `%s' shadows a parameter";
1048 else if (oldlocal
!= 0)
1049 warnstring
= "declaration of `%s' shadows previous local";
1050 else if (IDENTIFIER_GLOBAL_VALUE (name
) != 0
1051 && IDENTIFIER_GLOBAL_VALUE (name
) != error_mark_node
)
1052 warnstring
= "declaration of `%s' shadows global declaration";
1055 warning (warnstring
, IDENTIFIER_POINTER (name
));
1059 /* If storing a local value, there may already be one (inherited).
1060 If so, record it for restoration when this binding level ends. */
1062 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1066 /* Put decls on list in reverse order.
1067 We will reverse them later if necessary. */
1068 TREE_CHAIN (x
) = b
->names
;
1074 pushdecl_force_head (x
)
1077 current_binding_level
->names
= x
;
1080 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1083 pushdecl_top_level (x
)
1087 register struct binding_level
*b
= current_binding_level
;
1089 current_binding_level
= global_binding_level
;
1091 current_binding_level
= b
;
1095 /* Nonzero if we are currently in the global binding level. */
1098 global_bindings_p ()
1100 return current_binding_level
== global_binding_level
;
1103 /* Return the list of declarations of the current level.
1104 Note that this list is in reverse order unless/until
1105 you nreverse it; and when you do nreverse it, you must
1106 store the result back using `storedecls' or you will lose. */
1111 return current_binding_level
->names
;
1114 /* Create a new `struct binding_level'. */
1117 struct binding_level
*
1118 make_binding_level ()
1121 return (struct binding_level
*) xmalloc (sizeof (struct binding_level
));
1126 int unused ATTRIBUTE_UNUSED
;
1128 register struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1131 /* If this is the top level of a function,
1132 just make sure that NAMED_LABELS is 0. */
1134 if (current_binding_level
== global_binding_level
)
1138 /* Reuse or create a struct for this binding level. */
1140 if (free_binding_level
)
1142 newlevel
= free_binding_level
;
1143 free_binding_level
= free_binding_level
->level_chain
;
1147 newlevel
= make_binding_level ();
1150 /* Add this level to the front of the chain (stack) of levels that
1153 *newlevel
= clear_binding_level
;
1154 newlevel
->level_chain
= current_binding_level
;
1155 current_binding_level
= newlevel
;
1156 newlevel
->keep
= keep_next_level_flag
;
1157 keep_next_level_flag
= 0;
1158 newlevel
->keep_if_subblocks
= keep_next_if_subblocks
;
1159 keep_next_if_subblocks
= 0;
1160 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1161 newlevel
->binding_depth
= binding_depth
;
1163 fprintf (stderr
, "push %s level 0x%08x pc %d\n",
1164 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1167 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1170 /* Exit a binding level.
1171 Pop the level off, and restore the state of the identifier-decl mappings
1172 that were in effect when this level was entered.
1174 If KEEP is nonzero, this level had explicit declarations, so
1175 and create a "block" (a BLOCK node) for the level
1176 to record its declarations and subblocks for symbol table output.
1178 If FUNCTIONBODY is nonzero, this level is the body of a function,
1179 so create a block as if KEEP were set and also clear out all
1182 If REVERSE is nonzero, reverse the order of decls before putting
1183 them into the BLOCK. */
1186 poplevel (keep
, reverse
, functionbody
)
1192 /* The chain of decls was accumulated in reverse order.
1193 Put it into forward order, just for cleanliness. */
1195 tree subblocks
= current_binding_level
->blocks
;
1198 int block_previously_created
;
1200 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1203 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1204 fprintf (stderr
, "pop %s level 0x%08x pc %d (end pc %d)\n",
1205 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1206 current_binding_level
->end_pc
);
1208 fprintf (stderr
, "pop %s level 0x%08x pc %d\n",
1209 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1211 if (is_class_level
!= (current_binding_level
== class_binding_level
))
1214 fprintf (stderr
, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1218 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1220 keep
|= current_binding_level
->keep
;
1222 /* Get the decls in the order they were written.
1223 Usually current_binding_level->names is in reverse order.
1224 But parameter decls were previously put in forward order. */
1227 current_binding_level
->names
1228 = decls
= nreverse (current_binding_level
->names
);
1230 decls
= current_binding_level
->names
;
1232 /* Output any nested inline functions within this block
1233 if they weren't already output. */
1235 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1236 if (TREE_CODE (decl
) == FUNCTION_DECL
1237 && ! TREE_ASM_WRITTEN (decl
)
1238 && DECL_INITIAL (decl
) != 0
1239 && TREE_ADDRESSABLE (decl
))
1241 /* If this decl was copied from a file-scope decl
1242 on account of a block-scope extern decl,
1243 propagate TREE_ADDRESSABLE to the file-scope decl.
1245 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1246 true, since then the decl goes through save_for_inline_copying. */
1247 if (DECL_ABSTRACT_ORIGIN (decl
) != 0
1248 && DECL_ABSTRACT_ORIGIN (decl
) != decl
)
1249 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl
)) = 1;
1252 push_function_context ();
1253 output_inline_function (decl
);
1254 pop_function_context ();
1258 /* If there were any declarations in that level,
1259 or if this level is a function body,
1260 create a BLOCK to record them for the life of this function. */
1263 block_previously_created
= (current_binding_level
->this_block
!= 0);
1264 if (block_previously_created
)
1265 block
= current_binding_level
->this_block
;
1266 else if (keep
|| functionbody
1267 || (current_binding_level
->keep_if_subblocks
&& subblocks
!= 0))
1268 block
= make_node (BLOCK
);
1271 BLOCK_VARS (block
) = decls
;
1272 BLOCK_SUBBLOCKS (block
) = subblocks
;
1275 /* In each subblock, record that this is its superior. */
1277 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1278 BLOCK_SUPERCONTEXT (link
) = block
;
1280 /* Clear out the meanings of the local variables of this level. */
1282 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1284 tree name
= DECL_NAME (link
);
1285 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1287 /* If the ident. was used or addressed via a local extern decl,
1288 don't forget that fact. */
1289 if (DECL_EXTERNAL (link
))
1291 if (TREE_USED (link
))
1292 TREE_USED (name
) = 1;
1293 if (TREE_ADDRESSABLE (link
))
1294 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1296 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1300 /* Restore all name-meanings of the outer levels
1301 that were shadowed by this level. */
1303 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1304 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1306 /* If the level being exited is the top level of a function,
1307 check over all the labels, and clear out the current
1308 (function local) meanings of their names. */
1312 /* If this is the top level block of a function,
1313 the vars are the function's parameters.
1314 Don't leave them in the BLOCK because they are
1315 found in the FUNCTION_DECL instead. */
1317 BLOCK_VARS (block
) = 0;
1319 /* Clear out the definitions of all label names,
1320 since their scopes end here,
1321 and add them to BLOCK_VARS. */
1324 for (link
= named_labels
; link
; link
= TREE_CHAIN (link
))
1326 register tree label
= TREE_VALUE (link
);
1328 if (DECL_INITIAL (label
) == 0)
1330 error_with_decl (label
, "label `%s' used but not defined");
1331 /* Avoid crashing later. */
1332 define_label (input_filename
, lineno
,
1335 else if (warn_unused
&& !TREE_USED (label
))
1336 warning_with_decl (label
, "label `%s' defined but not used");
1337 IDENTIFIER_LABEL_VALUE (DECL_NAME (label
)) = 0;
1339 /* Put the labels into the "variables" of the
1340 top-level block, so debugger can see them. */
1341 TREE_CHAIN (label
) = BLOCK_VARS (block
);
1342 BLOCK_VARS (block
) = label
;
1347 /* Pop the current level, and free the structure for reuse. */
1350 register struct binding_level
*level
= current_binding_level
;
1351 current_binding_level
= current_binding_level
->level_chain
;
1353 level
->level_chain
= free_binding_level
;
1354 free_binding_level
= level
;
1357 /* Dispose of the block that we just made inside some higher level. */
1359 DECL_INITIAL (current_function_decl
) = block
;
1362 if (!block_previously_created
)
1363 current_binding_level
->blocks
1364 = chainon (current_binding_level
->blocks
, block
);
1366 /* If we did not make a block for the level just exited,
1367 any blocks made for inner levels
1368 (since they cannot be recorded as subblocks in that level)
1369 must be carried forward so they will later become subblocks
1370 of something else. */
1372 current_binding_level
->blocks
1373 = chainon (current_binding_level
->blocks
, subblocks
);
1375 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1376 binding contour so that they point to the appropriate construct, i.e.
1377 either to the current FUNCTION_DECL node, or else to the BLOCK node
1378 we just constructed.
1380 Note that for tagged types whose scope is just the formal parameter
1381 list for some function type specification, we can't properly set
1382 their TYPE_CONTEXTs here, because we don't have a pointer to the
1383 appropriate FUNCTION_TYPE node readily available to us. For those
1384 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1385 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1386 node which will represent the "scope" for these "parameter list local"
1391 TREE_USED (block
) = 1;
1396 maybe_pushlevels (pc
)
1399 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1403 while (pending_local_decls
!= NULL_TREE
&&
1404 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1406 tree
*ptr
= &pending_local_decls
;
1408 int end_pc
= DECL_LOCAL_END_PC (decl
);
1410 while (*ptr
!= NULL_TREE
1411 && DECL_LOCAL_START_PC (*ptr
) <= pc
1412 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1413 ptr
= &TREE_CHAIN (*ptr
);
1414 pending_local_decls
= *ptr
;
1417 /* Force non-nested range to be nested in current range. */
1418 if (end_pc
> current_binding_level
->end_pc
)
1419 end_pc
= current_binding_level
->end_pc
;
1421 maybe_start_try (pc
, end_pc
);
1424 expand_start_bindings (0);
1426 current_binding_level
->end_pc
= end_pc
;
1427 current_binding_level
->start_pc
= pc
;
1428 current_binding_level
->names
= decl
;
1429 for ( ; decl
!= NULL_TREE
; decl
= TREE_CHAIN (decl
))
1431 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl
), decl
);
1435 maybe_start_try (pc
, 0);
1439 maybe_poplevels (pc
)
1442 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1446 while (current_binding_level
->end_pc
<= pc
)
1448 expand_end_bindings (getdecls (), 1, 0);
1449 maybe_end_try (current_binding_level
->start_pc
, pc
);
1452 maybe_end_try (0, pc
);
1455 /* Terminate any binding which began during the range beginning at
1456 start_pc. This tidies up improperly nested local variable ranges
1457 and exception handlers; a variable declared within an exception
1458 range is forcibly terminated when that exception ends. */
1461 force_poplevels (start_pc
)
1464 while (current_binding_level
->start_pc
> start_pc
)
1466 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1467 warning_with_decl (current_function_decl
,
1468 "In %s: overlapped variable and exception ranges at %d",
1469 current_binding_level
->start_pc
);
1470 expand_end_bindings (getdecls (), 1, 0);
1475 /* Insert BLOCK at the end of the list of subblocks of the
1476 current binding level. This is used when a BIND_EXPR is expanded,
1477 to handle the BLOCK node inside the BIND_EXPR. */
1480 insert_block (block
)
1483 TREE_USED (block
) = 1;
1484 current_binding_level
->blocks
1485 = chainon (current_binding_level
->blocks
, block
);
1488 /* Set the BLOCK node for the innermost scope
1489 (the one we are currently in). */
1493 register tree block
;
1495 current_binding_level
->this_block
= block
;
1498 /* integrate_decl_tree calls this function. */
1501 copy_lang_decl (node
)
1505 = TREE_CODE (node
) == VAR_DECL
? sizeof (struct lang_decl_var
)
1506 : sizeof (struct lang_decl
);
1507 struct lang_decl
*x
= (struct lang_decl
*) oballoc (lang_decl_size
);
1508 bcopy ((PTR
) DECL_LANG_SPECIFIC (node
), (PTR
) x
, lang_decl_size
);
1509 DECL_LANG_SPECIFIC (node
) = x
;
1512 /* If DECL has a cleanup, build and return that cleanup here.
1513 This is a callback called by expand_expr. */
1516 maybe_build_cleanup (decl
)
1517 tree decl ATTRIBUTE_UNUSED
;
1519 /* There are no cleanups in Java (I think). */
1524 give_name_to_locals (jcf
)
1527 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1529 pending_local_decls
= NULL_TREE
;
1533 n
= JCF_readu2 (jcf
);
1534 for (i
= 0; i
< n
; i
++)
1536 int start_pc
= JCF_readu2 (jcf
);
1537 int length
= JCF_readu2 (jcf
);
1538 int name_index
= JCF_readu2 (jcf
);
1539 int signature_index
= JCF_readu2 (jcf
);
1540 int slot
= JCF_readu2 (jcf
);
1541 tree name
= get_name_constant (jcf
, name_index
);
1542 tree type
= parse_signature (jcf
, signature_index
);
1543 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1545 && length
== DECL_CODE_LENGTH (current_function_decl
))
1547 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1548 DECL_NAME (decl
) = name
;
1549 DECL_ASSEMBLER_NAME (decl
) = name
;
1550 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1551 warning ("bad type in parameter debug info");
1556 int end_pc
= start_pc
+ length
;
1557 tree decl
= build_decl (VAR_DECL
, name
, type
);
1558 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1560 warning_with_decl (decl
,
1561 "bad PC range for debug info for local `%s'");
1562 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1564 DECL_LANG_SPECIFIC (decl
)
1565 = (struct lang_decl
*) permalloc (sizeof (struct lang_decl_var
));
1566 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1567 DECL_LOCAL_START_PC (decl
) = start_pc
;
1569 /* FIXME: The range used internally for exceptions and local
1570 variable ranges, is a half-open interval:
1571 start_pc <= pc < end_pc. However, the range used in the
1572 Java VM spec is inclusive at both ends:
1573 start_pc <= pc <= end_pc. */
1576 DECL_LOCAL_END_PC (decl
) = end_pc
;
1578 /* Now insert the new decl in the proper place in
1579 pending_local_decls. We are essentially doing an insertion sort,
1580 which works fine, since the list input will normally already
1582 ptr
= &pending_local_decls
;
1583 while (*ptr
!= NULL_TREE
1584 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1585 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1586 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1587 ptr
= &TREE_CHAIN (*ptr
);
1588 TREE_CHAIN (decl
) = *ptr
;
1593 pending_local_decls
= nreverse (pending_local_decls
);
1595 /* Fill in default names for the parameters. */
1596 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1597 parm
!= NULL_TREE
; parm
= TREE_CHAIN (parm
), i
++)
1599 if (DECL_NAME (parm
) == NULL_TREE
)
1601 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1603 DECL_NAME (parm
) = get_identifier ("this");
1607 sprintf (buffer
, "ARG_%d", arg_i
);
1608 DECL_NAME (parm
) = get_identifier (buffer
);
1610 DECL_ASSEMBLER_NAME (parm
) = DECL_NAME (parm
);
1616 build_result_decl (fndecl
)
1619 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1620 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1621 if (INTEGRAL_TYPE_P (restype
)
1622 && TYPE_PRECISION (restype
) < TYPE_PRECISION (integer_type_node
))
1623 restype
= integer_type_node
;
1624 return (DECL_RESULT (fndecl
) = build_decl (RESULT_DECL
, NULL_TREE
, restype
));
1628 /* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
1629 to emit initialization code for each test flag. */
1632 emit_init_test_initialization (entry
, key
)
1633 struct hash_entry
*entry
;
1636 struct init_test_hash_entry
*ite
= (struct init_test_hash_entry
*) entry
;
1637 expand_decl (ite
->init_test_decl
);
1639 expand_expr_stmt (build (MODIFY_EXPR
, boolean_type_node
,
1640 ite
->init_test_decl
, boolean_false_node
));
1646 complete_start_java_method (fndecl
)
1649 if (! flag_emit_class_files
)
1651 /* Initialize the RTL code for the function. */
1652 init_function_start (fndecl
, input_filename
, lineno
);
1654 /* Set up parameters and prepare for return, for the function. */
1655 expand_function_start (fndecl
, 0);
1657 /* Emit initialization code for test flags. */
1658 if (! always_initialize_class_p
)
1659 hash_traverse (&DECL_FUNCTION_INIT_TEST_TABLE (fndecl
),
1660 emit_init_test_initialization
, 0);
1663 /* Allocate further tree nodes temporarily during compilation
1664 of this function only. */
1665 temporary_allocation ();
1668 /* If this fcn was already referenced via a block-scope `extern' decl (or
1669 an implicit decl), propagate certain information about the usage. */
1670 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl
)))
1671 TREE_ADDRESSABLE (current_function_decl
) = 1;
1675 if (METHOD_STATIC (fndecl
) && ! METHOD_PRIVATE (fndecl
)
1676 && ! flag_emit_class_files
1677 && ! CLASS_INTERFACE (TYPE_NAME (current_class
)))
1679 tree clas
= DECL_CONTEXT (fndecl
);
1680 tree init
= build (CALL_EXPR
, void_type_node
,
1681 build_address_of (soft_initclass_node
),
1682 build_tree_list (NULL_TREE
, build_class_ref (clas
)),
1684 TREE_SIDE_EFFECTS (init
) = 1;
1685 expand_expr_stmt (init
);
1688 /* Push local variables. Function compiled from source code are
1689 using a different local variables management, and for them,
1690 pushlevel shouldn't be called from here. */
1691 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl
)))
1694 if (! flag_emit_class_files
)
1695 expand_start_bindings (1);
1698 if (METHOD_SYNCHRONIZED (fndecl
) && ! flag_emit_class_files
)
1700 /* Warp function body with a monitorenter plus monitorexit cleanup. */
1701 tree enter
, exit
, lock
;
1702 if (METHOD_STATIC (fndecl
))
1703 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1705 lock
= DECL_ARGUMENTS (fndecl
);
1706 BUILD_MONITOR_ENTER (enter
, lock
);
1707 BUILD_MONITOR_EXIT (exit
, lock
);
1708 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl
)))
1710 expand_expr_stmt (enter
);
1711 expand_decl_cleanup (NULL_TREE
, exit
);
1715 tree function_body
= DECL_FUNCTION_BODY (fndecl
);
1716 tree body
= BLOCK_EXPR_BODY (function_body
);
1717 lock
= build (WITH_CLEANUP_EXPR
, void_type_node
,
1718 enter
, NULL_TREE
, exit
);
1719 TREE_SIDE_EFFECTS (lock
) = 1;
1720 lock
= build (COMPOUND_EXPR
, TREE_TYPE (body
), lock
, body
);
1721 TREE_SIDE_EFFECTS (lock
) = 1;
1722 lock
= build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (body
), lock
);
1723 TREE_SIDE_EFFECTS (lock
) = 1;
1724 BLOCK_EXPR_BODY (function_body
) = lock
;
1730 start_java_method (fndecl
)
1736 current_function_decl
= fndecl
;
1737 announce_function (fndecl
);
1739 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1740 decl_map
= make_tree_vec (i
);
1741 type_map
= (tree
*) oballoc (i
* sizeof (tree
));
1743 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1744 fprintf (stderr
, "%s:\n", (*decl_printable_name
) (fndecl
, 2));
1746 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1747 pushlevel (1); /* Push parameters. */
1749 ptr
= &DECL_ARGUMENTS (fndecl
);
1750 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1751 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1753 tree parm_name
= NULL_TREE
, parm_decl
;
1754 tree parm_type
= TREE_VALUE (tem
);
1755 if (i
>= DECL_MAX_LOCALS(fndecl
))
1756 fatal ("function has more parameters than local slots");
1758 parm_decl
= build_decl (PARM_DECL
, parm_name
, parm_type
);
1759 DECL_CONTEXT (parm_decl
) = fndecl
;
1760 if (PROMOTE_PROTOTYPES
1761 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1762 && INTEGRAL_TYPE_P (parm_type
))
1763 parm_type
= integer_type_node
;
1764 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1767 ptr
= &TREE_CHAIN (parm_decl
);
1769 /* Add parm_decl to the decl_map. */
1770 push_jvm_slot (i
, parm_decl
);
1772 type_map
[i
] = TREE_TYPE (parm_decl
);
1773 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1776 type_map
[i
] = void_type_node
;
1780 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1782 while (i
< DECL_MAX_LOCALS(fndecl
))
1783 type_map
[i
++] = NULL_TREE
;
1785 build_result_decl (fndecl
);
1786 complete_start_java_method (fndecl
);
1792 tree fndecl
= current_function_decl
;
1793 int flag_asynchronous_exceptions
= asynchronous_exceptions
;
1795 expand_end_bindings (getdecls (), 1, 0);
1796 /* pop out of function */
1799 /* pop out of its parameters */
1802 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1806 /* Generate rtl for function exit. */
1807 expand_function_end (input_filename
, lineno
, 0);
1809 /* FIXME: If the current method contains any exception handlers,
1810 force asynchronous_exceptions: this is necessary because signal
1811 handlers in libjava may throw exceptions. This is far from being
1812 a perfect solution, but it's better than doing nothing at all.*/
1814 asynchronous_exceptions
= 1;
1816 /* Run the optimizers and output assembler code for this function. */
1817 rest_of_compilation (fndecl
);
1819 current_function_decl
= NULL_TREE
;
1820 permanent_allocation (1);
1821 asynchronous_exceptions
= flag_asynchronous_exceptions
;