1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC 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 GCC 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 GCC; 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. */
31 #include "coretypes.h"
38 #include "java-tree.h"
44 #include "java-except.h"
47 #include "tree-inline.h"
49 #if defined (DEBUG_JAVA_BINDING_LEVELS)
50 extern void indent
PARAMS ((void));
53 static tree push_jvm_slot
PARAMS ((int, tree
));
54 static tree lookup_name_current_level
PARAMS ((tree
));
55 static tree push_promoted_type
PARAMS ((const char *, tree
));
56 static struct binding_level
*make_binding_level
PARAMS ((void));
57 static tree create_primitive_vtable
PARAMS ((const char *));
58 static tree check_local_named_variable
PARAMS ((tree
, tree
, int, int *));
59 static tree check_local_unnamed_variable
PARAMS ((tree
, tree
, tree
));
60 static void dump_function
PARAMS ((enum tree_dump_index
, tree
));
62 /* Name of the Cloneable class. */
63 tree java_lang_cloneable_identifier_node
;
65 /* Name of the Serializable class. */
66 tree java_io_serializable_identifier_node
;
68 /* Set to nonzero value in order to emit class initilization code
69 before static field references. */
70 extern int always_initialize_class_p
;
72 /* The DECL_MAP is a mapping from (index, type) to a decl node.
73 If index < max_locals, it is the index of a local variable.
74 if index >= max_locals, then index-max_locals is a stack slot.
75 The DECL_MAP mapping is represented as a TREE_VEC whose elements
76 are a list of decls (VAR_DECL or PARM_DECL) chained by
77 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
78 we search the chain for a decl with a matching TREE_TYPE. */
80 static GTY(()) tree decl_map
;
82 /* A list of local variables VAR_DECLs for this method that we have seen
83 debug information, but we have not reached their starting (byte) PC yet. */
85 static GTY(()) tree pending_local_decls
;
87 /* Push a local variable or stack slot into the decl_map,
88 and assign it an rtl. */
90 #if defined(DEBUG_JAVA_BINDING_LEVELS)
91 int binding_depth
= 0;
92 int is_class_level
= 0;
100 for (i
= 0; i
< binding_depth
*2; i
++)
103 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
106 push_jvm_slot (index
, decl
)
110 struct rtx_def
*rtl
= NULL
;
111 tree type
= TREE_TYPE (decl
);
114 DECL_CONTEXT (decl
) = current_function_decl
;
115 layout_decl (decl
, 0);
117 /* See if we have an appropriate rtl (i.e. same mode) at this index.
118 If so, we must use it. */
119 tmp
= TREE_VEC_ELT (decl_map
, index
);
120 while (tmp
!= NULL_TREE
)
122 if (TYPE_MODE (type
) == TYPE_MODE (TREE_TYPE (tmp
)))
123 rtl
= DECL_RTL_IF_SET (tmp
);
126 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
129 SET_DECL_RTL (decl
, rtl
);
132 if (index
>= DECL_MAX_LOCALS (current_function_decl
))
133 DECL_REGISTER (decl
) = 1;
137 /* Now link the decl into the decl_map. */
138 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
140 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
141 DECL_LOCAL_START_PC (decl
) = 0;
142 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
143 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
145 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
146 TREE_VEC_ELT (decl_map
, index
) = decl
;
150 /* Find out if 'decl' passed in fits the defined PC location better than
151 'best'. Return decl if it does, return best if it doesn't. If decl
152 is returned, then updated is set to true. */
155 check_local_named_variable (best
, decl
, pc
, updated
)
161 if (pc
>= DECL_LOCAL_START_PC (decl
)
162 && pc
< DECL_LOCAL_END_PC (decl
))
164 if (best
== NULL_TREE
165 || (DECL_LOCAL_START_PC (decl
) > DECL_LOCAL_START_PC (best
)
166 && DECL_LOCAL_END_PC (decl
) < DECL_LOCAL_END_PC (best
)))
176 /* Find the best declaration based upon type. If 'decl' fits 'type' better
177 than 'best', return 'decl'. Otherwise return 'best'. */
180 check_local_unnamed_variable (best
, decl
, type
)
185 if (TREE_TYPE (decl
) == type
186 || (TREE_CODE (TREE_TYPE (decl
)) == TREE_CODE (type
)
187 && TYPE_PRECISION (TREE_TYPE (decl
)) <= 32
188 && TYPE_PRECISION (type
) <= 32
189 && TREE_CODE (type
) != POINTER_TYPE
)
190 || (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
191 && type
== ptr_type_node
))
193 if (best
== NULL_TREE
194 || (TREE_TYPE (decl
) == type
&& TREE_TYPE (best
) != type
))
202 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
203 that is valid at PC (or -1 if any pc).
204 If there is no existing matching decl, allocate one. */
207 find_local_variable (index
, type
, pc
)
212 tree decl
= TREE_VEC_ELT (decl_map
, index
);
213 tree best
= NULL_TREE
;
214 int found_scoped_var
= 0;
216 /* Scan through every declaration that has been created in this slot. */
217 while (decl
!= NULL_TREE
)
219 /* Variables created in give_name_to_locals() have a name and have
220 a specified scope, so we can handle them specifically. We want
221 to use the specific decls created for those so they are assigned
222 the right variables in the debugging information. */
223 if (DECL_NAME (decl
) != NULL_TREE
)
225 /* This is a variable we have a name for, so it has a scope
226 supplied in the class file. But it only matters when we
227 actually have a PC to use. If pc<0, then we are asking
228 for a stack slot and this decl won't be one of those. */
230 best
= check_local_named_variable (best
, decl
, pc
,
233 /* We scan for type information unless we found a variable in the
234 proper scope already. */
235 else if (!found_scoped_var
)
237 /* If we don't have scoping information for a variable, we use
238 a different method to look it up. */
239 best
= check_local_unnamed_variable (best
, decl
, type
);
242 decl
= DECL_LOCAL_SLOT_CHAIN (decl
);
245 if (best
!= NULL_TREE
)
248 /* If we don't find a match, create one with the type passed in. */
249 return push_jvm_slot (index
, build_decl (VAR_DECL
, NULL_TREE
, type
));
253 /* Same as find_local_index, except that INDEX is a stack index. */
256 find_stack_slot (index
, type
)
260 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
266 /* A chain of _DECL nodes for all variables, constants, functions,
267 * and typedef types. These are in the reverse of the order supplied.
271 /* For each level, a list of shadowed outer-level local definitions
272 to be restored when this level is popped.
273 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
274 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
277 /* For each level (except not the global one),
278 a chain of BLOCK nodes for all the levels
279 that were entered and exited one level down. */
282 /* The BLOCK node for this level, if one has been preallocated.
283 If 0, the BLOCK is allocated (if needed) when the level is popped. */
286 /* The binding level which this one is contained in (inherits from). */
287 struct binding_level
*level_chain
;
289 /* The bytecode PC that marks the end of this level. */
291 /* The bytecode PC that marks the start of this level. */
294 #if defined(DEBUG_JAVA_BINDING_LEVELS)
295 /* Binding depth at which this level began. */
296 unsigned binding_depth
;
297 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
300 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
302 /* The binding level currently in effect. */
304 static struct binding_level
*current_binding_level
;
306 /* A chain of binding_level structures awaiting reuse. */
308 static struct binding_level
*free_binding_level
;
310 /* The outermost binding level, for names of file scope.
311 This is created when the compiler is started and exists
312 through the entire run. */
314 static struct binding_level
*global_binding_level
;
316 /* A PC value bigger than any PC value we may ever may encounter. */
318 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
320 /* Binding level structures are initialized by copying this one. */
322 static const struct binding_level clear_binding_level
323 = {NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
,
324 NULL_BINDING_LEVEL
, LARGEST_PC
, 0};
327 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
328 that have names. Here so we can clear out their names' definitions
329 at the end of the function. */
331 static tree named_labels
;
333 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
335 static tree shadowed_labels
;
338 tree java_global_trees
[JTI_MAX
];
340 /* Build (and pushdecl) a "promoted type" for all standard
341 types shorter than int. */
344 push_promoted_type (name
, actual_type
)
348 tree type
= make_node (TREE_CODE (actual_type
));
350 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
351 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
353 tree in_min
= TYPE_MIN_VALUE (actual_type
);
354 tree in_max
= TYPE_MAX_VALUE (actual_type
);
356 TYPE_MIN_VALUE (type
) = copy_node (in_min
);
357 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
358 TYPE_MAX_VALUE (type
) = copy_node (in_max
);
359 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
360 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
362 pushdecl (build_decl (TYPE_DECL
, get_identifier (name
), type
));
366 /* Return a definition for a builtin function named NAME and whose data type
367 is TYPE. TYPE should be a function type with argument types.
368 FUNCTION_CODE tells later passes how to compile calls to this function.
369 See tree.h for its possible values.
371 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
372 the name to be called if we can't opencode the function. If
373 ATTRS is nonzero, use that for the function's attribute list. */
376 builtin_function (name
, type
, function_code
, class, library_name
, attrs
)
380 enum built_in_class
class;
381 const char *library_name
;
382 tree attrs ATTRIBUTE_UNUSED
;
384 tree decl
= build_decl (FUNCTION_DECL
, get_identifier (name
), type
);
385 DECL_EXTERNAL (decl
) = 1;
386 TREE_PUBLIC (decl
) = 1;
388 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (library_name
));
389 make_decl_rtl (decl
, NULL
);
391 DECL_BUILT_IN_CLASS (decl
) = class;
392 DECL_FUNCTION_CODE (decl
) = function_code
;
396 /* Return tree that represents a vtable for a primitive array. */
398 create_primitive_vtable (name
)
404 sprintf (buf
, "_Jv_%sVTable", name
);
405 r
= build_decl (VAR_DECL
, get_identifier (buf
), ptr_type_node
);
406 DECL_EXTERNAL (r
) = 1;
411 java_init_decl_processing ()
413 register tree endlink
;
414 tree field
= NULL_TREE
;
417 init_class_processing ();
419 current_function_decl
= NULL
;
420 current_binding_level
= NULL_BINDING_LEVEL
;
421 free_binding_level
= NULL_BINDING_LEVEL
;
422 pushlevel (0); /* make the binding_level structure for global names */
423 global_binding_level
= current_binding_level
;
425 /* The code here must be similar to build_common_tree_nodes{,_2} in
426 tree.c, especially as to the order of initializing common nodes. */
427 error_mark_node
= make_node (ERROR_MARK
);
428 TREE_TYPE (error_mark_node
) = error_mark_node
;
430 /* Create sizetype first - needed for other types. */
431 initialize_sizetypes ();
433 byte_type_node
= make_signed_type (8);
434 pushdecl (build_decl (TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
435 short_type_node
= make_signed_type (16);
436 pushdecl (build_decl (TYPE_DECL
, get_identifier ("short"), short_type_node
));
437 int_type_node
= make_signed_type (32);
438 pushdecl (build_decl (TYPE_DECL
, get_identifier ("int"), int_type_node
));
439 long_type_node
= make_signed_type (64);
440 pushdecl (build_decl (TYPE_DECL
, get_identifier ("long"), long_type_node
));
442 unsigned_byte_type_node
= make_unsigned_type (8);
443 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned byte"),
444 unsigned_byte_type_node
));
445 unsigned_short_type_node
= make_unsigned_type (16);
446 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned short"),
447 unsigned_short_type_node
));
448 unsigned_int_type_node
= make_unsigned_type (32);
449 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned int"),
450 unsigned_int_type_node
));
451 unsigned_long_type_node
= make_unsigned_type (64);
452 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned long"),
453 unsigned_long_type_node
));
455 set_sizetype (make_unsigned_type (POINTER_SIZE
));
457 /* Define these next since types below may used them. */
458 integer_type_node
= java_type_for_size (INT_TYPE_SIZE
, 0);
459 integer_zero_node
= build_int_2 (0, 0);
460 integer_one_node
= build_int_2 (1, 0);
461 integer_two_node
= build_int_2 (2, 0);
462 integer_four_node
= build_int_2 (4, 0);
463 integer_minus_one_node
= build_int_2 (-1, -1);
465 /* A few values used for range checking in the lexer. */
466 decimal_int_max
= build_int_2 (0x80000000, 0);
467 TREE_TYPE (decimal_int_max
) = unsigned_int_type_node
;
468 #if HOST_BITS_PER_WIDE_INT == 64
469 decimal_long_max
= build_int_2 (0x8000000000000000LL
, 0);
471 #if HOST_BITS_PER_WIDE_INT == 32
472 decimal_long_max
= build_int_2 (0, 0x80000000);
474 #error "unsupported size"
477 TREE_TYPE (decimal_long_max
) = unsigned_long_type_node
;
479 size_zero_node
= size_int (0);
480 size_one_node
= size_int (1);
481 bitsize_zero_node
= bitsize_int (0);
482 bitsize_one_node
= bitsize_int (1);
483 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
485 long_zero_node
= build_int_2 (0, 0);
486 TREE_TYPE (long_zero_node
) = long_type_node
;
488 void_type_node
= make_node (VOID_TYPE
);
489 pushdecl (build_decl (TYPE_DECL
, get_identifier ("void"), void_type_node
));
490 layout_type (void_type_node
); /* Uses size_zero_node */
491 ptr_type_node
= build_pointer_type (void_type_node
);
492 t
= make_node (VOID_TYPE
);
493 layout_type (t
); /* Uses size_zero_node */
494 return_address_type_node
= build_pointer_type (t
);
496 null_pointer_node
= build_int_2 (0, 0);
497 TREE_TYPE (null_pointer_node
) = ptr_type_node
;
499 /* Used by the parser to represent empty statements and blocks. */
500 empty_stmt_node
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
501 CAN_COMPLETE_NORMALLY (empty_stmt_node
) = 1;
504 /* Make a type to be the domain of a few array types
505 whose domains don't really matter.
506 200 is small enough that it always fits in size_t
507 and large enough that it can hold most function names for the
508 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
509 short_array_type_node
= build_prim_array_type (short_type_node
, 200);
511 char_type_node
= make_node (CHAR_TYPE
);
512 TYPE_PRECISION (char_type_node
) = 16;
513 fixup_unsigned_type (char_type_node
);
514 pushdecl (build_decl (TYPE_DECL
, get_identifier ("char"), char_type_node
));
516 boolean_type_node
= make_node (BOOLEAN_TYPE
);
517 TYPE_PRECISION (boolean_type_node
) = 1;
518 fixup_unsigned_type (boolean_type_node
);
519 pushdecl (build_decl (TYPE_DECL
, get_identifier ("boolean"),
521 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
522 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
524 promoted_byte_type_node
525 = push_promoted_type ("promoted_byte", byte_type_node
);
526 promoted_short_type_node
527 = push_promoted_type ("promoted_short", short_type_node
);
528 promoted_char_type_node
529 = push_promoted_type ("promoted_char", char_type_node
);
530 promoted_boolean_type_node
531 = push_promoted_type ("promoted_boolean", boolean_type_node
);
533 float_type_node
= make_node (REAL_TYPE
);
534 TYPE_PRECISION (float_type_node
) = 32;
535 pushdecl (build_decl (TYPE_DECL
, get_identifier ("float"),
537 layout_type (float_type_node
);
539 double_type_node
= make_node (REAL_TYPE
);
540 TYPE_PRECISION (double_type_node
) = 64;
541 pushdecl (build_decl (TYPE_DECL
, get_identifier ("double"),
543 layout_type (double_type_node
);
545 float_zero_node
= build_real (float_type_node
, dconst0
);
546 double_zero_node
= build_real (double_type_node
, dconst0
);
548 /* These are the vtables for arrays of primitives. */
549 boolean_array_vtable
= create_primitive_vtable ("boolean");
550 byte_array_vtable
= create_primitive_vtable ("byte");
551 char_array_vtable
= create_primitive_vtable ("char");
552 short_array_vtable
= create_primitive_vtable ("short");
553 int_array_vtable
= create_primitive_vtable ("int");
554 long_array_vtable
= create_primitive_vtable ("long");
555 float_array_vtable
= create_primitive_vtable ("float");
556 double_array_vtable
= create_primitive_vtable ("double");
558 /* As you're adding items here, please update the code right after
559 this section, so that the filename containing the source code of
560 the pre-defined class gets registered correctly. */
561 unqualified_object_id_node
= get_identifier ("Object");
562 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
563 object_ptr_type_node
= promote_type (object_type_node
);
564 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
565 string_ptr_type_node
= promote_type (string_type_node
);
566 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
567 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
568 exception_type_node
= lookup_class (get_identifier ("java.lang.Exception"));
569 runtime_exception_type_node
=
570 lookup_class (get_identifier ("java.lang.RuntimeException"));
571 error_exception_type_node
=
572 lookup_class (get_identifier ("java.lang.Error"));
573 class_not_found_type_node
=
574 lookup_class (get_identifier ("java.lang.ClassNotFoundException"));
575 no_class_def_found_type_node
=
576 lookup_class (get_identifier ("java.lang.NoClassDefFoundError"));
578 rawdata_ptr_type_node
579 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
581 add_predefined_file (get_identifier ("java/lang/Class.java"));
582 add_predefined_file (get_identifier ("java/lang/Error.java"));
583 add_predefined_file (get_identifier ("java/lang/Object.java"));
584 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
585 add_predefined_file (get_identifier ("java/lang/String.java"));
586 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
587 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
588 add_predefined_file (get_identifier ("java/lang/Exception.java"));
589 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
590 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
591 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
593 methodtable_type
= make_node (RECORD_TYPE
);
594 layout_type (methodtable_type
);
595 build_decl (TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
596 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
598 TYPE_identifier_node
= get_identifier ("TYPE");
599 init_identifier_node
= get_identifier ("<init>");
600 clinit_identifier_node
= get_identifier ("<clinit>");
601 finit_identifier_node
= get_identifier ("finit$");
602 instinit_identifier_node
= get_identifier ("instinit$");
603 void_signature_node
= get_identifier ("()V");
604 length_identifier_node
= get_identifier ("length");
605 finalize_identifier_node
= get_identifier ("finalize");
606 this_identifier_node
= get_identifier ("this");
607 super_identifier_node
= get_identifier ("super");
608 continue_identifier_node
= get_identifier ("continue");
609 access0_identifier_node
= get_identifier ("access$0");
610 classdollar_identifier_node
= get_identifier ("class$");
612 java_lang_cloneable_identifier_node
= get_identifier ("java.lang.Cloneable");
613 java_io_serializable_identifier_node
=
614 get_identifier ("java.io.Serializable");
616 /* for lack of a better place to put this stub call */
617 init_expr_processing();
619 utf8const_type
= make_node (RECORD_TYPE
);
620 PUSH_FIELD (utf8const_type
, field
, "hash", unsigned_short_type_node
);
621 PUSH_FIELD (utf8const_type
, field
, "length", unsigned_short_type_node
);
622 FINISH_RECORD (utf8const_type
);
623 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
625 constants_type_node
= make_node (RECORD_TYPE
);
626 PUSH_FIELD (constants_type_node
, field
, "size", unsigned_int_type_node
);
627 PUSH_FIELD (constants_type_node
, field
, "tags", ptr_type_node
);
628 PUSH_FIELD (constants_type_node
, field
, "data", ptr_type_node
);
629 FINISH_RECORD (constants_type_node
);
630 build_decl (TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
632 access_flags_type_node
= unsigned_short_type_node
;
634 dtable_type
= make_node (RECORD_TYPE
);
635 dtable_ptr_type
= build_pointer_type (dtable_type
);
637 one_elt_array_domain_type
= build_index_type (integer_one_node
);
638 otable_type
= build_array_type (integer_type_node
,
639 one_elt_array_domain_type
);
640 TYPE_NONALIASED_COMPONENT (otable_type
) = 1;
641 otable_ptr_type
= build_pointer_type (otable_type
);
643 method_symbol_type
= make_node (RECORD_TYPE
);
644 PUSH_FIELD (method_symbol_type
, field
, "clname", utf8const_ptr_type
);
645 PUSH_FIELD (method_symbol_type
, field
, "name", utf8const_ptr_type
);
646 PUSH_FIELD (method_symbol_type
, field
, "signature", utf8const_ptr_type
);
647 FINISH_RECORD (method_symbol_type
);
649 method_symbols_array_type
= build_array_type (method_symbol_type
,
650 one_elt_array_domain_type
);
651 method_symbols_array_ptr_type
= build_pointer_type
652 (method_symbols_array_type
);
654 otable_decl
= build_decl (VAR_DECL
, get_identifier ("otable"), otable_type
);
655 DECL_EXTERNAL (otable_decl
) = 1;
656 TREE_STATIC (otable_decl
) = 1;
657 TREE_READONLY (otable_decl
) = 1;
658 pushdecl (otable_decl
);
660 otable_syms_decl
= build_decl (VAR_DECL
, get_identifier ("otable_syms"),
661 method_symbols_array_type
);
662 TREE_STATIC (otable_syms_decl
) = 1;
663 TREE_CONSTANT (otable_syms_decl
) = 1;
664 pushdecl (otable_syms_decl
);
666 PUSH_FIELD (object_type_node
, field
, "vtable", dtable_ptr_type
);
667 /* This isn't exactly true, but it is what we have in the source.
668 There is an unresolved issue here, which is whether the vtable
669 should be marked by the GC. */
670 if (! flag_hash_synchronization
)
671 PUSH_FIELD (object_type_node
, field
, "sync_info",
672 build_pointer_type (object_type_node
));
673 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
674 FIELD_PRIVATE (t
) = 1;
675 FINISH_RECORD (object_type_node
);
677 field_type_node
= make_node (RECORD_TYPE
);
678 field_ptr_type_node
= build_pointer_type (field_type_node
);
679 method_type_node
= make_node (RECORD_TYPE
);
680 method_ptr_type_node
= build_pointer_type (method_type_node
);
682 set_super_info (0, class_type_node
, object_type_node
, 0);
683 set_super_info (0, string_type_node
, object_type_node
, 0);
684 class_ptr_type
= build_pointer_type (class_type_node
);
686 PUSH_FIELD (class_type_node
, field
, "next", class_ptr_type
);
687 PUSH_FIELD (class_type_node
, field
, "name", utf8const_ptr_type
);
688 PUSH_FIELD (class_type_node
, field
, "accflags", access_flags_type_node
);
689 PUSH_FIELD (class_type_node
, field
, "superclass", class_ptr_type
);
690 PUSH_FIELD (class_type_node
, field
, "constants", constants_type_node
);
691 PUSH_FIELD (class_type_node
, field
, "methods", method_ptr_type_node
);
692 PUSH_FIELD (class_type_node
, field
, "method_count", short_type_node
);
693 PUSH_FIELD (class_type_node
, field
, "vtable_method_count", short_type_node
);
694 PUSH_FIELD (class_type_node
, field
, "fields", field_ptr_type_node
);
695 PUSH_FIELD (class_type_node
, field
, "size_in_bytes", int_type_node
);
696 PUSH_FIELD (class_type_node
, field
, "field_count", short_type_node
);
697 PUSH_FIELD (class_type_node
, field
, "static_field_count", short_type_node
);
698 PUSH_FIELD (class_type_node
, field
, "vtable", dtable_ptr_type
);
699 PUSH_FIELD (class_type_node
, field
, "otable", otable_ptr_type
);
700 PUSH_FIELD (class_type_node
, field
, "otable_syms",
701 method_symbols_array_ptr_type
);
702 PUSH_FIELD (class_type_node
, field
, "interfaces",
703 build_pointer_type (class_ptr_type
));
704 PUSH_FIELD (class_type_node
, field
, "loader", ptr_type_node
);
705 PUSH_FIELD (class_type_node
, field
, "interface_count", short_type_node
);
706 PUSH_FIELD (class_type_node
, field
, "state", byte_type_node
);
707 PUSH_FIELD (class_type_node
, field
, "thread", ptr_type_node
);
708 PUSH_FIELD (class_type_node
, field
, "depth", short_type_node
);
709 PUSH_FIELD (class_type_node
, field
, "ancestors", ptr_type_node
);
710 PUSH_FIELD (class_type_node
, field
, "idt", ptr_type_node
);
711 PUSH_FIELD (class_type_node
, field
, "arrayclass", ptr_type_node
);
712 PUSH_FIELD (class_type_node
, field
, "protectionDomain", ptr_type_node
);
713 PUSH_FIELD (class_type_node
, field
, "chain", ptr_type_node
);
714 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
715 FIELD_PRIVATE (t
) = 1;
716 push_super_field (class_type_node
, object_type_node
);
718 FINISH_RECORD (class_type_node
);
719 build_decl (TYPE_DECL
, get_identifier ("Class"), class_type_node
);
721 field_info_union_node
= make_node (UNION_TYPE
);
722 PUSH_FIELD (field_info_union_node
, field
, "boffset", int_type_node
);
723 PUSH_FIELD (field_info_union_node
, field
, "addr", ptr_type_node
);
725 PUSH_FIELD (field_info_union_node
, field
, "idx", unsigned_short_type_node
);
727 layout_type (field_info_union_node
);
729 PUSH_FIELD (field_type_node
, field
, "name", utf8const_ptr_type
);
730 PUSH_FIELD (field_type_node
, field
, "type", class_ptr_type
);
731 PUSH_FIELD (field_type_node
, field
, "accflags", access_flags_type_node
);
732 PUSH_FIELD (field_type_node
, field
, "bsize", unsigned_short_type_node
);
733 PUSH_FIELD (field_type_node
, field
, "info", field_info_union_node
);
734 FINISH_RECORD (field_type_node
);
735 build_decl (TYPE_DECL
, get_identifier ("Field"), field_type_node
);
737 nativecode_ptr_array_type_node
738 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
740 PUSH_FIELD (dtable_type
, field
, "class", class_ptr_type
);
741 PUSH_FIELD (dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
742 FINISH_RECORD (dtable_type
);
743 build_decl (TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
745 #define jint_type int_type_node
746 #define jint_ptr_type ptr_type_node
748 jexception_type
= make_node (RECORD_TYPE
);
749 PUSH_FIELD (jexception_type
, field
, "start_pc", ptr_type_node
);
750 PUSH_FIELD (jexception_type
, field
, "end_pc", ptr_type_node
);
751 PUSH_FIELD (jexception_type
, field
, "handler_pc", ptr_type_node
);
752 PUSH_FIELD (jexception_type
, field
, "catch_type", class_ptr_type
);
753 FINISH_RECORD (jexception_type
);
754 build_decl (TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
755 jexception_ptr_type
= build_pointer_type (jexception_type
);
757 lineNumberEntry_type
= make_node (RECORD_TYPE
);
758 PUSH_FIELD (lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
759 PUSH_FIELD (lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
760 FINISH_RECORD (lineNumberEntry_type
);
762 lineNumbers_type
= make_node (RECORD_TYPE
);
763 PUSH_FIELD (lineNumbers_type
, field
, "length", unsigned_int_type_node
);
764 FINISH_RECORD (lineNumbers_type
);
766 #define instn_ptr_type_node ptr_type_node /* XXX JH */
768 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
770 PUSH_FIELD (method_type_node
, field
, "name", utf8const_ptr_type
);
771 PUSH_FIELD (method_type_node
, field
, "signature", utf8const_ptr_type
);
772 PUSH_FIELD (method_type_node
, field
, "accflags", access_flags_type_node
);
773 PUSH_FIELD (method_type_node
, field
, "index", unsigned_short_type_node
);
774 PUSH_FIELD (method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
775 PUSH_FIELD (method_type_node
, field
, "throws", ptr_type_node
);
776 FINISH_RECORD (method_type_node
);
777 build_decl (TYPE_DECL
, get_identifier ("Method"), method_type_node
);
779 endlink
= end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
781 t
= tree_cons (NULL_TREE
, class_ptr_type
,
782 tree_cons (NULL_TREE
, int_type_node
, endlink
));
783 alloc_object_node
= builtin_function ("_Jv_AllocObject",
784 build_function_type (ptr_type_node
, t
),
785 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
786 DECL_IS_MALLOC (alloc_object_node
) = 1;
787 alloc_no_finalizer_node
=
788 builtin_function ("_Jv_AllocObjectNoFinalizer",
789 build_function_type (ptr_type_node
, t
),
790 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
791 DECL_IS_MALLOC (alloc_no_finalizer_node
) = 1;
793 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
794 soft_initclass_node
= builtin_function ("_Jv_InitClass",
795 build_function_type (void_type_node
,
797 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
799 throw_node
= builtin_function ("_Jv_Throw",
800 build_function_type (ptr_type_node
, t
),
801 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
802 /* Mark throw_nodes as `noreturn' functions with side effects. */
803 TREE_THIS_VOLATILE (throw_node
) = 1;
804 TREE_SIDE_EFFECTS (throw_node
) = 1;
806 t
= build_function_type (int_type_node
, endlink
);
807 soft_monitorenter_node
808 = builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
810 soft_monitorexit_node
811 = builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
814 t
= tree_cons (NULL_TREE
, int_type_node
,
815 tree_cons (NULL_TREE
, int_type_node
, endlink
));
817 = builtin_function ("_Jv_NewPrimArray",
818 build_function_type(ptr_type_node
, t
),
819 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
820 DECL_IS_MALLOC (soft_newarray_node
) = 1;
822 t
= tree_cons (NULL_TREE
, int_type_node
,
823 tree_cons (NULL_TREE
, class_ptr_type
,
824 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
)));
826 = builtin_function ("_Jv_NewObjectArray",
827 build_function_type (ptr_type_node
, t
),
828 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
829 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
831 t
= tree_cons (NULL_TREE
, ptr_type_node
,
832 tree_cons (NULL_TREE
, int_type_node
, endlink
));
833 soft_multianewarray_node
834 = builtin_function ("_Jv_NewMultiArray",
835 build_function_type (ptr_type_node
, t
),
836 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
837 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
839 t
= build_function_type (void_type_node
,
840 tree_cons (NULL_TREE
, int_type_node
, endlink
));
841 soft_badarrayindex_node
842 = builtin_function ("_Jv_ThrowBadArrayIndex", t
,
843 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
844 /* Mark soft_badarrayindex_node as a `noreturn' function with side
846 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
847 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
849 soft_nullpointer_node
850 = builtin_function ("_Jv_ThrowNullPointerException",
851 build_function_type (void_type_node
, endlink
),
852 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
853 /* Mark soft_nullpointer_node as a `noreturn' function with side
855 TREE_THIS_VOLATILE (soft_nullpointer_node
) = 1;
856 TREE_SIDE_EFFECTS (soft_nullpointer_node
) = 1;
858 t
= tree_cons (NULL_TREE
, class_ptr_type
,
859 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
861 = builtin_function ("_Jv_CheckCast",
862 build_function_type (ptr_type_node
, t
),
863 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
864 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
865 tree_cons (NULL_TREE
, class_ptr_type
, endlink
));
867 = builtin_function ("_Jv_IsInstanceOf",
868 build_function_type (boolean_type_node
, t
),
869 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
870 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
871 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
872 soft_checkarraystore_node
873 = builtin_function ("_Jv_CheckArrayStore",
874 build_function_type (void_type_node
, t
),
875 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
876 t
= tree_cons (NULL_TREE
, ptr_type_node
,
877 tree_cons (NULL_TREE
, ptr_type_node
,
878 tree_cons (NULL_TREE
, int_type_node
, endlink
)));
879 soft_lookupinterfacemethod_node
880 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
881 build_function_type (ptr_type_node
, t
),
882 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
884 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
885 tree_cons (NULL_TREE
, ptr_type_node
,
886 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)));
887 soft_lookupjnimethod_node
888 = builtin_function ("_Jv_LookupJNIMethod",
889 build_function_type (ptr_type_node
, t
),
890 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
891 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
892 soft_getjnienvnewframe_node
893 = builtin_function ("_Jv_GetJNIEnvNewFrame",
894 build_function_type (ptr_type_node
, t
),
895 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
896 soft_jnipopsystemframe_node
897 = builtin_function ("_Jv_JNI_PopSystemFrame",
898 build_function_type (ptr_type_node
, t
),
899 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
901 t
= tree_cons (NULL_TREE
, double_type_node
,
902 tree_cons (NULL_TREE
, double_type_node
, endlink
));
904 = builtin_function ("__builtin_fmod",
905 build_function_type (double_type_node
, t
),
906 BUILT_IN_FMOD
, BUILT_IN_NORMAL
, "fmod", NULL_TREE
);
909 t
= tree_cons (NULL_TREE
, float_type_node
,
910 tree_cons (NULL_TREE
, float_type_node
, endlink
));
912 = builtin_function ("__builtin_fmodf",
913 build_function_type (float_type_node
, t
),
914 BUILT_IN_FMOD
, BUILT_IN_NORMAL
, "fmodf", NULL_TREE
);
918 = builtin_function ("_Jv_divI",
919 build_function_type (int_type_node
, t
),
920 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
923 = builtin_function ("_Jv_remI",
924 build_function_type (int_type_node
, t
),
925 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
928 = builtin_function ("_Jv_divJ",
929 build_function_type (long_type_node
, t
),
930 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
933 = builtin_function ("_Jv_remJ",
934 build_function_type (long_type_node
, t
),
935 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
937 /* Initialize variables for except.c. */
938 eh_personality_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
939 ? "__gcj_personality_sj0"
940 : "__gcj_personality_v0");
941 lang_eh_runtime_type
= prepare_eh_table_type
;
945 initialize_builtins ();
949 /* Look up NAME in the current binding level and its superiors
950 in the namespace of variables, functions and typedefs.
951 Return a ..._DECL node of some kind representing its definition,
952 or return 0 if it is undefined. */
959 if (current_binding_level
!= global_binding_level
960 && IDENTIFIER_LOCAL_VALUE (name
))
961 val
= IDENTIFIER_LOCAL_VALUE (name
);
963 val
= IDENTIFIER_GLOBAL_VALUE (name
);
967 /* Similar to `lookup_name' but look only at current binding level and
968 the previous one if its the parameter level. */
971 lookup_name_current_level (name
)
976 if (current_binding_level
== global_binding_level
)
977 return IDENTIFIER_GLOBAL_VALUE (name
);
979 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
982 for (t
= current_binding_level
->names
; t
; t
= TREE_CHAIN (t
))
983 if (DECL_NAME (t
) == name
)
989 /* Use a binding level to record a labeled block declaration */
992 push_labeled_block (lb
)
995 register tree name
= DECL_NAME (LABELED_BLOCK_LABEL (lb
));
996 register struct binding_level
*b
= current_binding_level
;
997 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
999 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1000 TREE_CHAIN (lb
) = b
->names
;
1002 IDENTIFIER_LOCAL_VALUE (name
) = lb
;
1005 /* Pop the current binding level, reinstalling values for the previous
1009 pop_labeled_block ()
1011 struct binding_level
*b
= current_binding_level
;
1012 tree label
= b
->names
;
1013 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label
))) =
1016 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b
->shadowed
)) =
1017 TREE_VALUE (b
->shadowed
);
1019 /* Pop the current level, and free the structure for reuse. */
1020 current_binding_level
= current_binding_level
->level_chain
;
1021 b
->level_chain
= free_binding_level
;
1022 free_binding_level
= b
;
1025 /* Record a decl-node X as belonging to the current lexical scope.
1026 Check for errors (such as an incompatible declaration for the same
1027 name already seen in the same scope).
1029 Returns either X or an old decl for the same name.
1030 If an old decl is returned, it may have been smashed
1031 to agree with what X says. */
1038 register tree name
= DECL_NAME (x
);
1039 register struct binding_level
*b
= current_binding_level
;
1041 if (TREE_CODE (x
) != TYPE_DECL
)
1042 DECL_CONTEXT (x
) = current_function_decl
;
1048 t
= lookup_name_current_level (name
);
1049 if (t
!= 0 && t
== error_mark_node
)
1050 /* error_mark_node is 0 for a while during initialization! */
1053 error_with_decl (x
, "`%s' used prior to declaration");
1058 file
= DECL_SOURCE_FILE (t
);
1059 line
= DECL_SOURCE_LINE (t
);
1062 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1063 to point to the TYPE_DECL.
1064 Since Java does not have typedefs, a type can only have
1065 one (true) name, given by a class, interface, or builtin. */
1066 if (TREE_CODE (x
) == TYPE_DECL
1067 && TYPE_NAME (TREE_TYPE (x
)) == 0
1068 && TREE_TYPE (x
) != error_mark_node
)
1070 TYPE_NAME (TREE_TYPE (x
)) = x
;
1071 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1074 /* This name is new in its binding level.
1075 Install the new declaration and return it. */
1076 if (b
== global_binding_level
)
1078 /* Install a global value. */
1080 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1084 /* Here to install a non-global value. */
1085 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1086 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1089 /* Warn if shadowing an argument at the top level of the body. */
1090 if (oldlocal
!= 0 && !DECL_EXTERNAL (x
)
1091 /* This warning doesn't apply to the parms of a nested fcn. */
1092 && ! current_binding_level
->parm_flag
1093 /* Check that this is one level down from the parms. */
1094 && current_binding_level
->level_chain
->parm_flag
1095 /* Check that the decl being shadowed
1096 comes from the parm level, one level up. */
1097 && chain_member (oldlocal
, current_binding_level
->level_chain
->names
))
1099 if (TREE_CODE (oldlocal
) == PARM_DECL
)
1100 pedwarn ("declaration of `%s' shadows a parameter",
1101 IDENTIFIER_POINTER (name
));
1103 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1104 IDENTIFIER_POINTER (name
));
1107 /* Maybe warn if shadowing something else. */
1108 else if (warn_shadow
&& !DECL_EXTERNAL (x
)
1109 /* No shadow warnings for internally generated vars. */
1110 && DECL_SOURCE_LINE (x
) != 0
1111 /* No shadow warnings for vars made for inlining. */
1112 && ! DECL_FROM_INLINE (x
))
1114 const char *warnstring
= 0;
1116 if (TREE_CODE (x
) == PARM_DECL
1117 && current_binding_level
->level_chain
->parm_flag
)
1118 /* Don't warn about the parm names in function declarator
1119 within a function declarator.
1120 It would be nice to avoid warning in any function
1121 declarator in a declaration, as opposed to a definition,
1122 but there is no way to tell it's not a definition. */
1124 else if (oldlocal
!= 0 && TREE_CODE (oldlocal
) == PARM_DECL
)
1125 warnstring
= "declaration of `%s' shadows a parameter";
1126 else if (oldlocal
!= 0)
1127 warnstring
= "declaration of `%s' shadows previous local";
1128 else if (IDENTIFIER_GLOBAL_VALUE (name
) != 0
1129 && IDENTIFIER_GLOBAL_VALUE (name
) != error_mark_node
)
1130 warnstring
= "declaration of `%s' shadows global declaration";
1133 warning (warnstring
, IDENTIFIER_POINTER (name
));
1137 /* If storing a local value, there may already be one (inherited).
1138 If so, record it for restoration when this binding level ends. */
1140 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1144 /* Put decls on list in reverse order.
1145 We will reverse them later if necessary. */
1146 TREE_CHAIN (x
) = b
->names
;
1153 pushdecl_force_head (x
)
1156 current_binding_level
->names
= x
;
1159 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1162 pushdecl_top_level (x
)
1166 register struct binding_level
*b
= current_binding_level
;
1168 current_binding_level
= global_binding_level
;
1170 current_binding_level
= b
;
1174 /* Nonzero if we are currently in the global binding level. */
1177 global_bindings_p ()
1179 return current_binding_level
== global_binding_level
;
1182 /* Return the list of declarations of the current level.
1183 Note that this list is in reverse order unless/until
1184 you nreverse it; and when you do nreverse it, you must
1185 store the result back using `storedecls' or you will lose. */
1190 return current_binding_level
->names
;
1193 /* Create a new `struct binding_level'. */
1195 static struct binding_level
*
1196 make_binding_level ()
1199 return xmalloc (sizeof (struct binding_level
));
1204 int unused ATTRIBUTE_UNUSED
;
1206 register struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1209 /* If this is the top level of a function,
1210 just make sure that NAMED_LABELS is 0. */
1212 if (current_binding_level
== global_binding_level
)
1216 /* Reuse or create a struct for this binding level. */
1218 if (free_binding_level
)
1220 newlevel
= free_binding_level
;
1221 free_binding_level
= free_binding_level
->level_chain
;
1225 newlevel
= make_binding_level ();
1228 /* Add this level to the front of the chain (stack) of levels that
1231 *newlevel
= clear_binding_level
;
1232 newlevel
->level_chain
= current_binding_level
;
1233 current_binding_level
= newlevel
;
1234 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1235 newlevel
->binding_depth
= binding_depth
;
1237 fprintf (stderr
, "push %s level 0x%08x pc %d\n",
1238 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1241 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1244 /* Exit a binding level.
1245 Pop the level off, and restore the state of the identifier-decl mappings
1246 that were in effect when this level was entered.
1248 If KEEP is nonzero, this level had explicit declarations, so
1249 and create a "block" (a BLOCK node) for the level
1250 to record its declarations and subblocks for symbol table output.
1252 If FUNCTIONBODY is nonzero, this level is the body of a function,
1253 so create a block as if KEEP were set and also clear out all
1256 If REVERSE is nonzero, reverse the order of decls before putting
1257 them into the BLOCK. */
1260 poplevel (keep
, reverse
, functionbody
)
1266 /* The chain of decls was accumulated in reverse order.
1267 Put it into forward order, just for cleanliness. */
1269 tree subblocks
= current_binding_level
->blocks
;
1272 int block_previously_created
;
1274 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1277 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1278 fprintf (stderr
, "pop %s level 0x%08x pc %d (end pc %d)\n",
1279 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1280 current_binding_level
->end_pc
);
1282 fprintf (stderr
, "pop %s level 0x%08x pc %d\n",
1283 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1285 if (is_class_level
!= (current_binding_level
== class_binding_level
))
1288 fprintf (stderr
, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1292 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1294 /* Get the decls in the order they were written.
1295 Usually current_binding_level->names is in reverse order.
1296 But parameter decls were previously put in forward order. */
1299 current_binding_level
->names
1300 = decls
= nreverse (current_binding_level
->names
);
1302 decls
= current_binding_level
->names
;
1304 /* Output any nested inline functions within this block
1305 if they weren't already output. */
1307 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1308 if (TREE_CODE (decl
) == FUNCTION_DECL
1309 && ! TREE_ASM_WRITTEN (decl
)
1310 && DECL_INITIAL (decl
) != 0
1311 && TREE_ADDRESSABLE (decl
))
1313 /* If this decl was copied from a file-scope decl
1314 on account of a block-scope extern decl,
1315 propagate TREE_ADDRESSABLE to the file-scope decl.
1317 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1318 true, since then the decl goes through save_for_inline_copying. */
1319 if (DECL_ABSTRACT_ORIGIN (decl
) != 0
1320 && DECL_ABSTRACT_ORIGIN (decl
) != decl
)
1321 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl
)) = 1;
1324 push_function_context ();
1325 output_inline_function (decl
);
1326 pop_function_context ();
1330 /* If there were any declarations in that level,
1331 or if this level is a function body,
1332 create a BLOCK to record them for the life of this function. */
1335 block_previously_created
= (current_binding_level
->this_block
!= 0);
1336 if (block_previously_created
)
1337 block
= current_binding_level
->this_block
;
1338 else if (keep
|| functionbody
)
1339 block
= make_node (BLOCK
);
1342 BLOCK_VARS (block
) = decls
;
1343 BLOCK_SUBBLOCKS (block
) = subblocks
;
1346 /* In each subblock, record that this is its superior. */
1348 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1349 BLOCK_SUPERCONTEXT (link
) = block
;
1351 /* Clear out the meanings of the local variables of this level. */
1353 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1355 tree name
= DECL_NAME (link
);
1356 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1358 /* If the ident. was used or addressed via a local extern decl,
1359 don't forget that fact. */
1360 if (DECL_EXTERNAL (link
))
1362 if (TREE_USED (link
))
1363 TREE_USED (name
) = 1;
1364 if (TREE_ADDRESSABLE (link
))
1365 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1367 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1371 /* Restore all name-meanings of the outer levels
1372 that were shadowed by this level. */
1374 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1375 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1377 /* If the level being exited is the top level of a function,
1378 check over all the labels, and clear out the current
1379 (function local) meanings of their names. */
1383 /* If this is the top level block of a function,
1384 the vars are the function's parameters.
1385 Don't leave them in the BLOCK because they are
1386 found in the FUNCTION_DECL instead. */
1388 BLOCK_VARS (block
) = 0;
1390 /* Clear out the definitions of all label names,
1391 since their scopes end here,
1392 and add them to BLOCK_VARS. */
1395 for (link
= named_labels
; link
; link
= TREE_CHAIN (link
))
1397 register tree label
= TREE_VALUE (link
);
1399 if (DECL_INITIAL (label
) == 0)
1401 error_with_decl (label
, "label `%s' used but not defined");
1402 /* Avoid crashing later. */
1403 define_label (input_filename
, lineno
,
1406 else if (warn_unused
[UNUSED_LABEL
] && !TREE_USED (label
))
1407 warning_with_decl (label
, "label `%s' defined but not used");
1408 IDENTIFIER_LABEL_VALUE (DECL_NAME (label
)) = 0;
1410 /* Put the labels into the "variables" of the
1411 top-level block, so debugger can see them. */
1412 TREE_CHAIN (label
) = BLOCK_VARS (block
);
1413 BLOCK_VARS (block
) = label
;
1418 /* Pop the current level, and free the structure for reuse. */
1421 register struct binding_level
*level
= current_binding_level
;
1422 current_binding_level
= current_binding_level
->level_chain
;
1424 level
->level_chain
= free_binding_level
;
1425 free_binding_level
= level
;
1428 /* Dispose of the block that we just made inside some higher level. */
1430 DECL_INITIAL (current_function_decl
) = block
;
1433 if (!block_previously_created
)
1434 current_binding_level
->blocks
1435 = chainon (current_binding_level
->blocks
, block
);
1437 /* If we did not make a block for the level just exited,
1438 any blocks made for inner levels
1439 (since they cannot be recorded as subblocks in that level)
1440 must be carried forward so they will later become subblocks
1441 of something else. */
1443 current_binding_level
->blocks
1444 = chainon (current_binding_level
->blocks
, subblocks
);
1446 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1447 binding contour so that they point to the appropriate construct, i.e.
1448 either to the current FUNCTION_DECL node, or else to the BLOCK node
1449 we just constructed.
1451 Note that for tagged types whose scope is just the formal parameter
1452 list for some function type specification, we can't properly set
1453 their TYPE_CONTEXTs here, because we don't have a pointer to the
1454 appropriate FUNCTION_TYPE node readily available to us. For those
1455 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1456 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1457 node which will represent the "scope" for these "parameter list local"
1462 TREE_USED (block
) = 1;
1467 maybe_pushlevels (pc
)
1470 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1474 while (pending_local_decls
!= NULL_TREE
&&
1475 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1477 tree
*ptr
= &pending_local_decls
;
1479 int end_pc
= DECL_LOCAL_END_PC (decl
);
1481 while (*ptr
!= NULL_TREE
1482 && DECL_LOCAL_START_PC (*ptr
) <= pc
1483 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1484 ptr
= &TREE_CHAIN (*ptr
);
1485 pending_local_decls
= *ptr
;
1488 /* Force non-nested range to be nested in current range. */
1489 if (end_pc
> current_binding_level
->end_pc
)
1490 end_pc
= current_binding_level
->end_pc
;
1492 maybe_start_try (pc
, end_pc
);
1495 expand_start_bindings (0);
1497 current_binding_level
->end_pc
= end_pc
;
1498 current_binding_level
->start_pc
= pc
;
1499 current_binding_level
->names
= decl
;
1500 for ( ; decl
!= NULL_TREE
; decl
= TREE_CHAIN (decl
))
1502 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl
), decl
);
1506 maybe_start_try (pc
, 0);
1510 maybe_poplevels (pc
)
1513 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1517 while (current_binding_level
->end_pc
<= pc
)
1519 expand_end_bindings (getdecls (), 1, 0);
1520 maybe_end_try (current_binding_level
->start_pc
, pc
);
1523 maybe_end_try (0, pc
);
1526 /* Terminate any binding which began during the range beginning at
1527 start_pc. This tidies up improperly nested local variable ranges
1528 and exception handlers; a variable declared within an exception
1529 range is forcibly terminated when that exception ends. */
1532 force_poplevels (start_pc
)
1535 while (current_binding_level
->start_pc
> start_pc
)
1537 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1538 warning_with_decl (current_function_decl
,
1539 "In %s: overlapped variable and exception ranges at %d",
1540 current_binding_level
->start_pc
);
1541 expand_end_bindings (getdecls (), 1, 0);
1546 /* Insert BLOCK at the end of the list of subblocks of the
1547 current binding level. This is used when a BIND_EXPR is expanded,
1548 to handle the BLOCK node inside the BIND_EXPR. */
1551 insert_block (block
)
1554 TREE_USED (block
) = 1;
1555 current_binding_level
->blocks
1556 = chainon (current_binding_level
->blocks
, block
);
1559 /* Set the BLOCK node for the innermost scope
1560 (the one we are currently in). */
1564 register tree block
;
1566 current_binding_level
->this_block
= block
;
1567 current_binding_level
->names
= chainon (current_binding_level
->names
,
1568 BLOCK_VARS (block
));
1569 current_binding_level
->blocks
= chainon (current_binding_level
->blocks
,
1570 BLOCK_SUBBLOCKS (block
));
1573 /* integrate_decl_tree calls this function. */
1576 java_dup_lang_specific_decl (node
)
1580 struct lang_decl
*x
;
1582 if (!DECL_LANG_SPECIFIC (node
))
1585 lang_decl_size
= sizeof (struct lang_decl
);
1586 x
= (struct lang_decl
*) ggc_alloc (lang_decl_size
);
1587 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1588 DECL_LANG_SPECIFIC (node
) = x
;
1592 give_name_to_locals (jcf
)
1595 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1596 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1598 pending_local_decls
= NULL_TREE
;
1602 n
= JCF_readu2 (jcf
);
1603 for (i
= 0; i
< n
; i
++)
1605 int start_pc
= JCF_readu2 (jcf
);
1606 int length
= JCF_readu2 (jcf
);
1607 int name_index
= JCF_readu2 (jcf
);
1608 int signature_index
= JCF_readu2 (jcf
);
1609 int slot
= JCF_readu2 (jcf
);
1610 tree name
= get_name_constant (jcf
, name_index
);
1611 tree type
= parse_signature (jcf
, signature_index
);
1612 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1614 && length
== DECL_CODE_LENGTH (current_function_decl
))
1616 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1617 DECL_NAME (decl
) = name
;
1618 SET_DECL_ASSEMBLER_NAME (decl
, name
);
1619 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1620 warning ("bad type in parameter debug info");
1625 int end_pc
= start_pc
+ length
;
1626 tree decl
= build_decl (VAR_DECL
, name
, type
);
1627 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1629 warning_with_decl (decl
,
1630 "bad PC range for debug info for local `%s'");
1631 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1634 /* Adjust start_pc if necessary so that the local's first
1635 store operation will use the relevant DECL as a
1636 destination. Fore more information, read the leading
1637 comments for expr.c:maybe_adjust_start_pc. */
1638 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1640 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1641 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1642 DECL_LOCAL_START_PC (decl
) = start_pc
;
1644 /* FIXME: The range used internally for exceptions and local
1645 variable ranges, is a half-open interval:
1646 start_pc <= pc < end_pc. However, the range used in the
1647 Java VM spec is inclusive at both ends:
1648 start_pc <= pc <= end_pc. */
1651 DECL_LOCAL_END_PC (decl
) = end_pc
;
1653 /* Now insert the new decl in the proper place in
1654 pending_local_decls. We are essentially doing an insertion sort,
1655 which works fine, since the list input will normally already
1657 ptr
= &pending_local_decls
;
1658 while (*ptr
!= NULL_TREE
1659 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1660 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1661 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1662 ptr
= &TREE_CHAIN (*ptr
);
1663 TREE_CHAIN (decl
) = *ptr
;
1668 pending_local_decls
= nreverse (pending_local_decls
);
1670 /* Fill in default names for the parameters. */
1671 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1672 parm
!= NULL_TREE
; parm
= TREE_CHAIN (parm
), i
++)
1674 if (DECL_NAME (parm
) == NULL_TREE
)
1676 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1678 DECL_NAME (parm
) = get_identifier ("this");
1682 sprintf (buffer
, "ARG_%d", arg_i
);
1683 DECL_NAME (parm
) = get_identifier (buffer
);
1685 SET_DECL_ASSEMBLER_NAME (parm
, DECL_NAME (parm
));
1691 build_result_decl (fndecl
)
1694 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1695 tree result
= DECL_RESULT (fndecl
);
1698 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1699 if (INTEGRAL_TYPE_P (restype
)
1700 && TYPE_PRECISION (restype
) < TYPE_PRECISION (integer_type_node
))
1701 restype
= integer_type_node
;
1702 result
= build_decl (RESULT_DECL
, NULL_TREE
, restype
);
1703 DECL_CONTEXT (result
) = fndecl
;
1704 DECL_RESULT (fndecl
) = result
;
1710 complete_start_java_method (fndecl
)
1713 if (! flag_emit_class_files
)
1715 /* Initialize the RTL code for the function. */
1716 init_function_start (fndecl
, input_filename
, lineno
);
1718 /* Set up parameters and prepare for return, for the function. */
1719 expand_function_start (fndecl
, 0);
1723 /* If this fcn was already referenced via a block-scope `extern' decl (or
1724 an implicit decl), propagate certain information about the usage. */
1725 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl
)))
1726 TREE_ADDRESSABLE (current_function_decl
) = 1;
1730 if (METHOD_STATIC (fndecl
) && ! METHOD_PRIVATE (fndecl
)
1731 && ! flag_emit_class_files
1732 && ! DECL_CLINIT_P (fndecl
)
1733 && ! CLASS_INTERFACE (TYPE_NAME (current_class
)))
1735 tree clas
= DECL_CONTEXT (fndecl
);
1736 tree init
= build (CALL_EXPR
, void_type_node
,
1737 build_address_of (soft_initclass_node
),
1738 build_tree_list (NULL_TREE
, build_class_ref (clas
)),
1740 TREE_SIDE_EFFECTS (init
) = 1;
1741 expand_expr_stmt (init
);
1744 /* Push local variables. Function compiled from source code are
1745 using a different local variables management, and for them,
1746 pushlevel shouldn't be called from here. */
1747 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl
)))
1750 if (! flag_emit_class_files
)
1751 expand_start_bindings (1);
1754 if (METHOD_SYNCHRONIZED (fndecl
) && ! flag_emit_class_files
)
1756 /* Wrap function body with a monitorenter plus monitorexit cleanup. */
1757 tree enter
, exit
, lock
;
1758 if (METHOD_STATIC (fndecl
))
1759 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1761 lock
= DECL_ARGUMENTS (fndecl
);
1762 BUILD_MONITOR_ENTER (enter
, lock
);
1763 BUILD_MONITOR_EXIT (exit
, lock
);
1764 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl
)))
1766 expand_expr_stmt (enter
);
1767 expand_decl_cleanup (NULL_TREE
, exit
);
1771 tree function_body
= DECL_FUNCTION_BODY (fndecl
);
1772 tree body
= BLOCK_EXPR_BODY (function_body
);
1773 lock
= build (COMPOUND_EXPR
, void_type_node
,
1775 build (TRY_FINALLY_EXPR
, void_type_node
, body
, exit
));
1776 TREE_SIDE_EFFECTS (lock
) = 1;
1777 BLOCK_EXPR_BODY (function_body
) = lock
;
1783 start_java_method (fndecl
)
1789 current_function_decl
= fndecl
;
1790 announce_function (fndecl
);
1792 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1793 decl_map
= make_tree_vec (i
);
1794 type_map
= xrealloc (type_map
, i
* sizeof (tree
));
1796 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1797 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1799 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1800 pushlevel (1); /* Push parameters. */
1802 ptr
= &DECL_ARGUMENTS (fndecl
);
1803 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1804 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1806 tree parm_name
= NULL_TREE
, parm_decl
;
1807 tree parm_type
= TREE_VALUE (tem
);
1808 if (i
>= DECL_MAX_LOCALS (fndecl
))
1811 parm_decl
= build_decl (PARM_DECL
, parm_name
, parm_type
);
1812 DECL_CONTEXT (parm_decl
) = fndecl
;
1813 if (PROMOTE_PROTOTYPES
1814 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1815 && INTEGRAL_TYPE_P (parm_type
))
1816 parm_type
= integer_type_node
;
1817 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1820 ptr
= &TREE_CHAIN (parm_decl
);
1822 /* Add parm_decl to the decl_map. */
1823 push_jvm_slot (i
, parm_decl
);
1825 type_map
[i
] = TREE_TYPE (parm_decl
);
1826 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1829 type_map
[i
] = void_type_node
;
1833 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1835 while (i
< DECL_MAX_LOCALS(fndecl
))
1836 type_map
[i
++] = NULL_TREE
;
1838 build_result_decl (fndecl
);
1839 complete_start_java_method (fndecl
);
1845 tree fndecl
= current_function_decl
;
1847 expand_end_bindings (getdecls (), 1, 0);
1848 /* pop out of function */
1851 /* pop out of its parameters */
1854 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1856 /* Generate rtl for function exit. */
1857 expand_function_end (input_filename
, lineno
, 0);
1859 /* Run the optimizers and output assembler code for this function. */
1860 rest_of_compilation (fndecl
);
1862 current_function_decl
= NULL_TREE
;
1865 /* Dump FUNCTION_DECL FN as tree dump PHASE. */
1868 dump_function (phase
, fn
)
1869 enum tree_dump_index phase
;
1875 stream
= dump_begin (phase
, &flags
);
1878 dump_node (fn
, TDF_SLIM
| flags
, stream
);
1879 dump_end (phase
, stream
);
1883 void java_optimize_inline (fndecl
)
1886 if (flag_inline_trees
)
1888 timevar_push (TV_INTEGRATION
);
1889 optimize_inline_calls (fndecl
);
1890 timevar_pop (TV_INTEGRATION
);
1891 dump_function (TDI_inlined
, fndecl
);
1895 #include "gt-java-decl.h"