1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007 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, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, 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"
48 #include "tree-inline.h"
51 #include "tree-iterator.h"
52 #include "langhooks.h"
54 #if defined (DEBUG_JAVA_BINDING_LEVELS)
55 extern void indent (void);
58 static tree
push_jvm_slot (int, tree
);
59 static tree
lookup_name_current_level (tree
);
60 static tree
push_promoted_type (const char *, tree
);
61 static struct binding_level
*make_binding_level (void);
62 static tree
create_primitive_vtable (const char *);
63 static tree
check_local_unnamed_variable (tree
, tree
, tree
);
64 static void parse_version (void);
67 /* The following ABI flags are used in the high-order bits of the version
68 ID field. The version ID number itself should never be larger than
69 0xfffff, so it should be safe to use top 12 bits for these flags. */
71 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
73 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
74 should be loaded by the bootstrap
77 /* If an ABI change is made within a GCC release series, rendering current
78 binaries incompatible with the old runtimes, this number must be set to
79 enforce the compatibility rules. */
80 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
82 /* The runtime may recognize a variety of BC ABIs (objects generated by
83 different version of gcj), but will probably always require strict
84 matching for the ordinary (C++) ABI. */
86 /* The version ID of the BC ABI that we generate. This must be kept in
87 sync with parse_version(), libgcj, and reality (if the BC format changes,
89 #define GCJ_CURRENT_BC_ABI_VERSION \
90 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
92 /* The ABI version number. */
95 /* Name of the Cloneable class. */
96 tree java_lang_cloneable_identifier_node
;
98 /* Name of the Serializable class. */
99 tree java_io_serializable_identifier_node
;
101 /* The DECL_MAP is a mapping from (index, type) to a decl node.
102 If index < max_locals, it is the index of a local variable.
103 if index >= max_locals, then index-max_locals is a stack slot.
104 The DECL_MAP mapping is represented as a TREE_VEC whose elements
105 are a list of decls (VAR_DECL or PARM_DECL) chained by
106 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
107 we search the chain for a decl with a matching TREE_TYPE. */
109 static GTY(()) tree decl_map
;
111 /* The base_decl_map is contains one variable of ptr_type: this is
112 used to contain every variable of reference type that is ever
113 stored in a local variable slot. */
115 static GTY(()) tree base_decl_map
;
117 /* An index used to make temporary identifiers unique. */
120 /* A list of local variables VAR_DECLs for this method that we have seen
121 debug information, but we have not reached their starting (byte) PC yet. */
123 static GTY(()) tree pending_local_decls
;
125 /* The decl for "_Jv_ResolvePoolEntry". */
126 tree soft_resolvepoolentry_node
;
128 /* The decl for the .constants field of an instance of Class. */
129 tree constants_field_decl_node
;
131 /* The decl for the .data field of an instance of Class. */
132 tree constants_data_field_decl_node
;
134 #if defined(DEBUG_JAVA_BINDING_LEVELS)
135 int binding_depth
= 0;
136 int is_class_level
= 0;
144 for (i
= 0; i
< binding_depth
*2; i
++)
147 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
149 /* True if decl is a named local variable, i.e. if it is an alias
150 that's used only for debugging purposes. */
153 debug_variable_p (tree decl
)
155 if (TREE_CODE (decl
) == PARM_DECL
)
158 if (LOCAL_SLOT_P (decl
))
165 push_jvm_slot (int index
, tree decl
)
167 DECL_CONTEXT (decl
) = current_function_decl
;
168 layout_decl (decl
, 0);
170 /* Now link the decl into the decl_map. */
171 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
173 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
174 DECL_LOCAL_START_PC (decl
) = 0;
175 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
176 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
178 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
179 TREE_VEC_ELT (decl_map
, index
) = decl
;
184 /* Find the best declaration based upon type. If 'decl' fits 'type' better
185 than 'best', return 'decl'. Otherwise return 'best'. */
188 check_local_unnamed_variable (tree best
, tree decl
, tree type
)
190 tree decl_type
= TREE_TYPE (decl
);
192 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl
));
194 /* Use the same decl for all integer types <= 32 bits. This is
195 necessary because sometimes a value is stored as (for example)
196 boolean but loaded as int. */
197 if (decl_type
== type
198 || (INTEGRAL_TYPE_P (decl_type
)
199 && INTEGRAL_TYPE_P (type
)
200 && TYPE_PRECISION (decl_type
) <= 32
201 && TYPE_PRECISION (type
) <= 32
202 && TYPE_PRECISION (decl_type
) >= TYPE_PRECISION (type
))
203 /* ptr_type_node is used for null pointers, which are
204 assignment compatible with everything. */
205 || (TREE_CODE (decl_type
) == POINTER_TYPE
206 && type
== ptr_type_node
)
207 /* Whenever anyone wants to use a slot that is initially
208 occupied by a PARM_DECL of pointer type they must get that
209 decl, even if they asked for a pointer to a different type.
210 However, if someone wants a scalar variable in a slot that
211 initially held a pointer arg -- or vice versa -- we create a
214 ???: As long as verification is correct, this will be a
215 compatible type. But maybe we should create a dummy variable
216 and replace all references to it with the DECL and a
219 || (TREE_CODE (decl_type
) == POINTER_TYPE
220 && TREE_CODE (decl
) == PARM_DECL
221 && TREE_CODE (type
) == POINTER_TYPE
))
223 if (best
== NULL_TREE
224 || (decl_type
== type
&& TREE_TYPE (best
) != type
))
232 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
233 that is valid at PC (or -1 if any pc).
234 If there is no existing matching decl, allocate one. */
237 find_local_variable (int index
, tree type
, int pc ATTRIBUTE_UNUSED
)
239 tree tmp
= TREE_VEC_ELT (decl_map
, index
);
240 tree decl
= NULL_TREE
;
242 /* Scan through every declaration that has been created in this
243 slot. We're only looking for variables that correspond to local
244 index declarations and PARM_DECLs, not named variables: such
245 local variables are used only for debugging information. */
246 while (tmp
!= NULL_TREE
)
248 if (! debug_variable_p (tmp
))
249 decl
= check_local_unnamed_variable (decl
, tmp
, type
);
250 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
253 /* gcj has a function called promote_type(), which is used by both
254 the bytecode compiler and the source compiler. Unfortunately,
255 the type systems for the Java VM and the Java language are not
256 the same: a boolean in the VM promotes to an int, not to a wide
257 boolean. If our caller wants something to hold a boolean, that
258 had better be an int, because that slot might be re-used
259 later in integer context. */
260 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
261 type
= integer_type_node
;
263 /* If we don't find a match, create one with the type passed in.
264 The name of the variable is #n#m, which n is the variable index
265 in the local variable area and m is a dummy identifier for
266 uniqueness -- multiple variables may share the same local
267 variable index. We don't call pushdecl() to push pointer types
268 into a binding expr because they'll all be replaced by a single
269 variable that is used for every reference in that local variable
275 sprintf (buf
, "#slot#%d#%d", index
, uniq
++);
276 name
= get_identifier (buf
);
277 decl
= build_decl (VAR_DECL
, name
, type
);
278 DECL_IGNORED_P (decl
) = 1;
279 DECL_ARTIFICIAL (decl
) = 1;
280 decl
= push_jvm_slot (index
, decl
);
281 LOCAL_SLOT_P (decl
) = 1;
283 if (TREE_CODE (type
) != POINTER_TYPE
)
284 pushdecl_function_level (decl
);
287 /* As well as creating a local variable that matches the type, we
288 also create a base variable (of ptr_type) that will hold all its
290 if (TREE_CODE (type
) == POINTER_TYPE
291 && ! TREE_VEC_ELT (base_decl_map
, index
))
296 sprintf (buf
, "#ref#%d#%d", index
, uniq
++);
297 name
= get_identifier (buf
);
299 = TREE_VEC_ELT (base_decl_map
, index
)
300 = build_decl (VAR_DECL
, name
, ptr_type_node
);
301 pushdecl_function_level (base_decl
);
302 DECL_IGNORED_P (base_decl
) = 1;
303 DECL_ARTIFICIAL (base_decl
) = 1;
309 /* Called during gimplification for every variable. If the variable
310 is a temporary of pointer type, replace it with a common variable
311 thath is used to hold all pointer types that are ever stored in
312 that slot. Set WANT_LVALUE if you want a variable that is to be
316 java_replace_reference (tree var_decl
, bool want_lvalue
)
323 decl_type
= TREE_TYPE (var_decl
);
325 if (TREE_CODE (decl_type
) == POINTER_TYPE
)
327 if (DECL_LANG_SPECIFIC (var_decl
)
328 && LOCAL_SLOT_P (var_decl
))
330 int index
= DECL_LOCAL_SLOT_NUMBER (var_decl
);
331 tree base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
333 gcc_assert (base_decl
);
335 base_decl
= build1 (NOP_EXPR
, decl_type
, base_decl
);
345 /* Same as find_local_index, except that INDEX is a stack index. */
348 find_stack_slot (int index
, tree type
)
350 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
354 struct binding_level
GTY(())
356 /* A chain of _DECL nodes for all variables, constants, functions,
357 * and typedef types. These are in the reverse of the order supplied.
361 /* For each level, a list of shadowed outer-level local definitions
362 to be restored when this level is popped.
363 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
364 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
367 /* For each level (except not the global one),
368 a chain of BLOCK nodes for all the levels
369 that were entered and exited one level down. */
372 /* The binding level which this one is contained in (inherits from). */
373 struct binding_level
*level_chain
;
375 /* The bytecode PC that marks the end of this level. */
377 /* The bytecode PC that marks the start of this level. */
380 /* The statements in this binding level. */
383 /* An exception range associated with this binding level. */
384 struct eh_range
* GTY((skip (""))) exception_range
;
386 /* Binding depth at which this level began. Used only for debugging. */
387 unsigned binding_depth
;
390 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
392 /* The binding level currently in effect. */
394 static GTY(()) struct binding_level
*current_binding_level
;
396 /* A chain of binding_level structures awaiting reuse. */
398 static GTY(()) struct binding_level
*free_binding_level
;
400 /* The outermost binding level, for names of file scope.
401 This is created when the compiler is started and exists
402 through the entire run. */
404 static GTY(()) struct binding_level
*global_binding_level
;
406 /* The binding level that holds variables declared at the outermost
407 level within a function body. */
409 static struct binding_level
*function_binding_level
;
411 /* A PC value bigger than any PC value we may ever may encounter. */
413 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
415 /* Binding level structures are initialized by copying this one. */
417 static const struct binding_level clear_binding_level
419 NULL_TREE
, /* names */
420 NULL_TREE
, /* shadowed */
421 NULL_TREE
, /* blocks */
422 NULL_BINDING_LEVEL
, /* level_chain */
423 LARGEST_PC
, /* end_pc */
426 NULL
, /* exception_range */
427 0, /* binding_depth */
431 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
432 that have names. Here so we can clear out their names' definitions
433 at the end of the function. */
435 static tree named_labels
;
437 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
439 static tree shadowed_labels
;
442 tree java_global_trees
[JTI_MAX
];
444 /* Build (and pushdecl) a "promoted type" for all standard
445 types shorter than int. */
448 push_promoted_type (const char *name
, tree actual_type
)
450 tree type
= make_node (TREE_CODE (actual_type
));
452 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
453 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
455 tree in_min
= TYPE_MIN_VALUE (actual_type
);
456 tree in_max
= TYPE_MAX_VALUE (actual_type
);
458 TYPE_MIN_VALUE (type
) = copy_node (in_min
);
459 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
460 TYPE_MAX_VALUE (type
) = copy_node (in_max
);
461 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
462 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
463 TYPE_STRING_FLAG (type
) = TYPE_STRING_FLAG (actual_type
);
465 pushdecl (build_decl (TYPE_DECL
, get_identifier (name
), type
));
469 /* Return tree that represents a vtable for a primitive array. */
471 create_primitive_vtable (const char *name
)
476 sprintf (buf
, "_Jv_%sVTable", name
);
477 r
= build_decl (VAR_DECL
, get_identifier (buf
), ptr_type_node
);
478 DECL_EXTERNAL (r
) = 1;
488 /* Parse the version string and compute the ABI version number. */
492 const char *p
= version_string
;
493 unsigned int major
= 0, minor
= 0;
494 unsigned int abi_version
;
496 /* Skip leading junk. */
497 while (*p
&& !ISDIGIT (*p
))
501 /* Extract major version. */
504 major
= major
* 10 + *p
- '0';
508 gcc_assert (*p
== '.' && ISDIGIT (p
[1]));
511 /* Extract minor version. */
514 minor
= minor
* 10 + *p
- '0';
518 if (flag_indirect_dispatch
)
520 abi_version
= GCJ_CURRENT_BC_ABI_VERSION
;
521 abi_version
|= FLAG_BINARYCOMPAT_ABI
;
525 /* Implicit in this computation is the idea that we won't break the
526 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
528 abi_version
= 100000 * major
+ 1000 * minor
;
530 if (flag_bootstrap_classes
)
531 abi_version
|= FLAG_BOOTSTRAP_LOADER
;
533 gcj_abi_version
= build_int_cstu (ptr_type_node
, abi_version
);
537 java_init_decl_processing (void)
540 tree field
= NULL_TREE
;
543 init_class_processing ();
545 current_function_decl
= NULL
;
546 current_binding_level
= NULL_BINDING_LEVEL
;
547 free_binding_level
= NULL_BINDING_LEVEL
;
548 pushlevel (0); /* make the binding_level structure for global names */
549 global_binding_level
= current_binding_level
;
551 /* The code here must be similar to build_common_tree_nodes{,_2} in
552 tree.c, especially as to the order of initializing common nodes. */
553 error_mark_node
= make_node (ERROR_MARK
);
554 TREE_TYPE (error_mark_node
) = error_mark_node
;
556 /* Create sizetype first - needed for other types. */
557 initialize_sizetypes (false);
559 byte_type_node
= make_signed_type (8);
560 pushdecl (build_decl (TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
561 short_type_node
= make_signed_type (16);
562 pushdecl (build_decl (TYPE_DECL
, get_identifier ("short"), short_type_node
));
563 int_type_node
= make_signed_type (32);
564 pushdecl (build_decl (TYPE_DECL
, get_identifier ("int"), int_type_node
));
565 long_type_node
= make_signed_type (64);
566 pushdecl (build_decl (TYPE_DECL
, get_identifier ("long"), long_type_node
));
568 unsigned_byte_type_node
= make_unsigned_type (8);
569 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned byte"),
570 unsigned_byte_type_node
));
571 unsigned_short_type_node
= make_unsigned_type (16);
572 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned short"),
573 unsigned_short_type_node
));
574 unsigned_int_type_node
= make_unsigned_type (32);
575 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned int"),
576 unsigned_int_type_node
));
577 unsigned_long_type_node
= make_unsigned_type (64);
578 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned long"),
579 unsigned_long_type_node
));
581 /* This is not a java type, however tree-dfa requires a definition for
583 size_type_node
= make_unsigned_type (POINTER_SIZE
);
584 set_sizetype (size_type_node
);
586 /* Define these next since types below may used them. */
587 integer_type_node
= java_type_for_size (INT_TYPE_SIZE
, 0);
588 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
589 integer_one_node
= build_int_cst (NULL_TREE
, 1);
590 integer_two_node
= build_int_cst (NULL_TREE
, 2);
591 integer_four_node
= build_int_cst (NULL_TREE
, 4);
592 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
594 /* A few values used for range checking in the lexer. */
595 decimal_int_max
= build_int_cstu (unsigned_int_type_node
, 0x80000000);
596 #if HOST_BITS_PER_WIDE_INT == 64
597 decimal_long_max
= build_int_cstu (unsigned_long_type_node
,
598 0x8000000000000000LL
);
599 #elif HOST_BITS_PER_WIDE_INT == 32
600 decimal_long_max
= build_int_cst_wide (unsigned_long_type_node
,
603 #error "unsupported size"
606 size_zero_node
= size_int (0);
607 size_one_node
= size_int (1);
608 bitsize_zero_node
= bitsize_int (0);
609 bitsize_one_node
= bitsize_int (1);
610 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
612 long_zero_node
= build_int_cst (long_type_node
, 0);
614 void_type_node
= make_node (VOID_TYPE
);
615 pushdecl (build_decl (TYPE_DECL
, get_identifier ("void"), void_type_node
));
616 layout_type (void_type_node
); /* Uses size_zero_node */
618 ptr_type_node
= build_pointer_type (void_type_node
);
620 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
622 t
= make_node (VOID_TYPE
);
623 layout_type (t
); /* Uses size_zero_node */
624 return_address_type_node
= build_pointer_type (t
);
626 null_pointer_node
= build_int_cst (ptr_type_node
, 0);
629 /* Make a type to be the domain of a few array types
630 whose domains don't really matter.
631 200 is small enough that it always fits in size_t
632 and large enough that it can hold most function names for the
633 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
634 short_array_type_node
= build_prim_array_type (short_type_node
, 200);
636 char_type_node
= make_node (INTEGER_TYPE
);
637 TYPE_STRING_FLAG (char_type_node
) = 1;
638 TYPE_PRECISION (char_type_node
) = 16;
639 fixup_unsigned_type (char_type_node
);
640 pushdecl (build_decl (TYPE_DECL
, get_identifier ("char"), char_type_node
));
642 boolean_type_node
= make_node (BOOLEAN_TYPE
);
643 TYPE_PRECISION (boolean_type_node
) = 1;
644 fixup_unsigned_type (boolean_type_node
);
645 pushdecl (build_decl (TYPE_DECL
, get_identifier ("boolean"),
647 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
648 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
650 promoted_byte_type_node
651 = push_promoted_type ("promoted_byte", byte_type_node
);
652 promoted_short_type_node
653 = push_promoted_type ("promoted_short", short_type_node
);
654 promoted_char_type_node
655 = push_promoted_type ("promoted_char", char_type_node
);
656 promoted_boolean_type_node
657 = push_promoted_type ("promoted_boolean", boolean_type_node
);
659 float_type_node
= make_node (REAL_TYPE
);
660 TYPE_PRECISION (float_type_node
) = 32;
661 pushdecl (build_decl (TYPE_DECL
, get_identifier ("float"),
663 layout_type (float_type_node
);
665 double_type_node
= make_node (REAL_TYPE
);
666 TYPE_PRECISION (double_type_node
) = 64;
667 pushdecl (build_decl (TYPE_DECL
, get_identifier ("double"),
669 layout_type (double_type_node
);
671 float_zero_node
= build_real (float_type_node
, dconst0
);
672 double_zero_node
= build_real (double_type_node
, dconst0
);
674 /* These are the vtables for arrays of primitives. */
675 boolean_array_vtable
= create_primitive_vtable ("boolean");
676 byte_array_vtable
= create_primitive_vtable ("byte");
677 char_array_vtable
= create_primitive_vtable ("char");
678 short_array_vtable
= create_primitive_vtable ("short");
679 int_array_vtable
= create_primitive_vtable ("int");
680 long_array_vtable
= create_primitive_vtable ("long");
681 float_array_vtable
= create_primitive_vtable ("float");
682 double_array_vtable
= create_primitive_vtable ("double");
684 one_elt_array_domain_type
= build_index_type (integer_one_node
);
685 utf8const_type
= make_node (RECORD_TYPE
);
686 PUSH_FIELD (utf8const_type
, field
, "hash", unsigned_short_type_node
);
687 PUSH_FIELD (utf8const_type
, field
, "length", unsigned_short_type_node
);
688 FINISH_RECORD (utf8const_type
);
689 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
691 atable_type
= build_array_type (ptr_type_node
,
692 one_elt_array_domain_type
);
693 TYPE_NONALIASED_COMPONENT (atable_type
) = 1;
694 atable_ptr_type
= build_pointer_type (atable_type
);
696 itable_type
= build_array_type (ptr_type_node
,
697 one_elt_array_domain_type
);
698 TYPE_NONALIASED_COMPONENT (itable_type
) = 1;
699 itable_ptr_type
= build_pointer_type (itable_type
);
701 symbol_type
= make_node (RECORD_TYPE
);
702 PUSH_FIELD (symbol_type
, field
, "clname", utf8const_ptr_type
);
703 PUSH_FIELD (symbol_type
, field
, "name", utf8const_ptr_type
);
704 PUSH_FIELD (symbol_type
, field
, "signature", utf8const_ptr_type
);
705 FINISH_RECORD (symbol_type
);
707 symbols_array_type
= build_array_type (symbol_type
,
708 one_elt_array_domain_type
);
709 symbols_array_ptr_type
= build_pointer_type (symbols_array_type
);
711 assertion_entry_type
= make_node (RECORD_TYPE
);
712 PUSH_FIELD (assertion_entry_type
, field
, "assertion_code", integer_type_node
);
713 PUSH_FIELD (assertion_entry_type
, field
, "op1", utf8const_ptr_type
);
714 PUSH_FIELD (assertion_entry_type
, field
, "op2", utf8const_ptr_type
);
715 FINISH_RECORD (assertion_entry_type
);
717 assertion_table_type
= build_array_type (assertion_entry_type
,
718 one_elt_array_domain_type
);
720 /* As you're adding items here, please update the code right after
721 this section, so that the filename containing the source code of
722 the pre-defined class gets registered correctly. */
723 unqualified_object_id_node
= get_identifier ("Object");
724 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
725 object_ptr_type_node
= promote_type (object_type_node
);
726 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
727 string_ptr_type_node
= promote_type (string_type_node
);
728 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
729 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
730 exception_type_node
= lookup_class (get_identifier ("java.lang.Exception"));
731 runtime_exception_type_node
=
732 lookup_class (get_identifier ("java.lang.RuntimeException"));
733 error_exception_type_node
=
734 lookup_class (get_identifier ("java.lang.Error"));
736 rawdata_ptr_type_node
737 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
739 add_predefined_file (get_identifier ("java/lang/Class.java"));
740 add_predefined_file (get_identifier ("java/lang/Error.java"));
741 add_predefined_file (get_identifier ("java/lang/Object.java"));
742 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
743 add_predefined_file (get_identifier ("java/lang/String.java"));
744 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
745 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
746 add_predefined_file (get_identifier ("java/lang/Exception.java"));
747 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
748 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
750 methodtable_type
= make_node (RECORD_TYPE
);
751 layout_type (methodtable_type
);
752 build_decl (TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
753 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
755 TYPE_identifier_node
= get_identifier ("TYPE");
756 init_identifier_node
= get_identifier ("<init>");
757 clinit_identifier_node
= get_identifier ("<clinit>");
758 void_signature_node
= get_identifier ("()V");
759 finalize_identifier_node
= get_identifier ("finalize");
760 this_identifier_node
= get_identifier ("this");
761 classdollar_identifier_node
= get_identifier ("class$");
763 java_lang_cloneable_identifier_node
= get_identifier ("java.lang.Cloneable");
764 java_io_serializable_identifier_node
=
765 get_identifier ("java.io.Serializable");
767 /* for lack of a better place to put this stub call */
768 init_expr_processing();
770 constants_type_node
= make_node (RECORD_TYPE
);
771 PUSH_FIELD (constants_type_node
, field
, "size", unsigned_int_type_node
);
772 PUSH_FIELD (constants_type_node
, field
, "tags", ptr_type_node
);
773 PUSH_FIELD (constants_type_node
, field
, "data", ptr_type_node
);
774 constants_data_field_decl_node
= field
;
775 FINISH_RECORD (constants_type_node
);
776 build_decl (TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
778 access_flags_type_node
= unsigned_short_type_node
;
780 dtable_type
= make_node (RECORD_TYPE
);
781 dtable_ptr_type
= build_pointer_type (dtable_type
);
783 otable_type
= build_array_type (integer_type_node
,
784 one_elt_array_domain_type
);
785 TYPE_NONALIASED_COMPONENT (otable_type
) = 1;
786 otable_ptr_type
= build_pointer_type (otable_type
);
788 PUSH_FIELD (object_type_node
, field
, "vtable", dtable_ptr_type
);
789 DECL_FCONTEXT (field
) = object_type_node
;
790 TYPE_VFIELD (object_type_node
) = field
;
792 /* This isn't exactly true, but it is what we have in the source.
793 There is an unresolved issue here, which is whether the vtable
794 should be marked by the GC. */
795 if (! flag_hash_synchronization
)
796 PUSH_FIELD (object_type_node
, field
, "sync_info",
797 build_pointer_type (object_type_node
));
798 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
799 FIELD_PRIVATE (t
) = 1;
800 FINISH_RECORD (object_type_node
);
802 field_type_node
= make_node (RECORD_TYPE
);
803 field_ptr_type_node
= build_pointer_type (field_type_node
);
804 method_type_node
= make_node (RECORD_TYPE
);
805 method_ptr_type_node
= build_pointer_type (method_type_node
);
807 set_super_info (0, class_type_node
, object_type_node
, 0);
808 set_super_info (0, string_type_node
, object_type_node
, 0);
809 class_ptr_type
= build_pointer_type (class_type_node
);
811 PUSH_FIELD (class_type_node
, field
, "next_or_version", class_ptr_type
);
812 PUSH_FIELD (class_type_node
, field
, "name", utf8const_ptr_type
);
813 PUSH_FIELD (class_type_node
, field
, "accflags", access_flags_type_node
);
814 PUSH_FIELD (class_type_node
, field
, "superclass", class_ptr_type
);
815 PUSH_FIELD (class_type_node
, field
, "constants", constants_type_node
);
816 constants_field_decl_node
= field
;
817 PUSH_FIELD (class_type_node
, field
, "methods", method_ptr_type_node
);
818 PUSH_FIELD (class_type_node
, field
, "method_count", short_type_node
);
819 PUSH_FIELD (class_type_node
, field
, "vtable_method_count", short_type_node
);
820 PUSH_FIELD (class_type_node
, field
, "fields", field_ptr_type_node
);
821 PUSH_FIELD (class_type_node
, field
, "size_in_bytes", int_type_node
);
822 PUSH_FIELD (class_type_node
, field
, "field_count", short_type_node
);
823 PUSH_FIELD (class_type_node
, field
, "static_field_count", short_type_node
);
824 PUSH_FIELD (class_type_node
, field
, "vtable", dtable_ptr_type
);
825 PUSH_FIELD (class_type_node
, field
, "otable", otable_ptr_type
);
826 PUSH_FIELD (class_type_node
, field
, "otable_syms",
827 symbols_array_ptr_type
);
828 PUSH_FIELD (class_type_node
, field
, "atable", atable_ptr_type
);
829 PUSH_FIELD (class_type_node
, field
, "atable_syms",
830 symbols_array_ptr_type
);
831 PUSH_FIELD (class_type_node
, field
, "itable", itable_ptr_type
);
832 PUSH_FIELD (class_type_node
, field
, "itable_syms",
833 symbols_array_ptr_type
);
834 PUSH_FIELD (class_type_node
, field
, "catch_classes", ptr_type_node
);
835 PUSH_FIELD (class_type_node
, field
, "interfaces",
836 build_pointer_type (class_ptr_type
));
837 PUSH_FIELD (class_type_node
, field
, "loader", ptr_type_node
);
838 PUSH_FIELD (class_type_node
, field
, "interface_count", short_type_node
);
839 PUSH_FIELD (class_type_node
, field
, "state", byte_type_node
);
840 PUSH_FIELD (class_type_node
, field
, "thread", ptr_type_node
);
841 PUSH_FIELD (class_type_node
, field
, "depth", short_type_node
);
842 PUSH_FIELD (class_type_node
, field
, "ancestors", ptr_type_node
);
843 PUSH_FIELD (class_type_node
, field
, "idt", ptr_type_node
);
844 PUSH_FIELD (class_type_node
, field
, "arrayclass", ptr_type_node
);
845 PUSH_FIELD (class_type_node
, field
, "protectionDomain", ptr_type_node
);
846 PUSH_FIELD (class_type_node
, field
, "assertion_table", ptr_type_node
);
847 PUSH_FIELD (class_type_node
, field
, "hack_signers", ptr_type_node
);
848 PUSH_FIELD (class_type_node
, field
, "chain", ptr_type_node
);
849 PUSH_FIELD (class_type_node
, field
, "aux_info", ptr_type_node
);
850 PUSH_FIELD (class_type_node
, field
, "engine", ptr_type_node
);
851 PUSH_FIELD (class_type_node
, field
, "reflection_data", ptr_type_node
);
852 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
853 FIELD_PRIVATE (t
) = 1;
854 push_super_field (class_type_node
, object_type_node
);
856 FINISH_RECORD (class_type_node
);
857 build_decl (TYPE_DECL
, get_identifier ("Class"), class_type_node
);
859 field_info_union_node
= make_node (UNION_TYPE
);
860 PUSH_FIELD (field_info_union_node
, field
, "boffset", int_type_node
);
861 PUSH_FIELD (field_info_union_node
, field
, "addr", ptr_type_node
);
863 PUSH_FIELD (field_info_union_node
, field
, "idx", unsigned_short_type_node
);
865 layout_type (field_info_union_node
);
867 PUSH_FIELD (field_type_node
, field
, "name", utf8const_ptr_type
);
868 PUSH_FIELD (field_type_node
, field
, "type", class_ptr_type
);
869 PUSH_FIELD (field_type_node
, field
, "accflags", access_flags_type_node
);
870 PUSH_FIELD (field_type_node
, field
, "bsize", unsigned_short_type_node
);
871 PUSH_FIELD (field_type_node
, field
, "info", field_info_union_node
);
872 FINISH_RECORD (field_type_node
);
873 build_decl (TYPE_DECL
, get_identifier ("Field"), field_type_node
);
875 nativecode_ptr_array_type_node
876 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
878 PUSH_FIELD (dtable_type
, field
, "class", class_ptr_type
);
879 PUSH_FIELD (dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
880 FINISH_RECORD (dtable_type
);
881 build_decl (TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
883 jexception_type
= make_node (RECORD_TYPE
);
884 PUSH_FIELD (jexception_type
, field
, "start_pc", ptr_type_node
);
885 PUSH_FIELD (jexception_type
, field
, "end_pc", ptr_type_node
);
886 PUSH_FIELD (jexception_type
, field
, "handler_pc", ptr_type_node
);
887 PUSH_FIELD (jexception_type
, field
, "catch_type", class_ptr_type
);
888 FINISH_RECORD (jexception_type
);
889 build_decl (TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
890 jexception_ptr_type
= build_pointer_type (jexception_type
);
892 lineNumberEntry_type
= make_node (RECORD_TYPE
);
893 PUSH_FIELD (lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
894 PUSH_FIELD (lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
895 FINISH_RECORD (lineNumberEntry_type
);
897 lineNumbers_type
= make_node (RECORD_TYPE
);
898 PUSH_FIELD (lineNumbers_type
, field
, "length", unsigned_int_type_node
);
899 FINISH_RECORD (lineNumbers_type
);
901 PUSH_FIELD (method_type_node
, field
, "name", utf8const_ptr_type
);
902 PUSH_FIELD (method_type_node
, field
, "signature", utf8const_ptr_type
);
903 PUSH_FIELD (method_type_node
, field
, "accflags", access_flags_type_node
);
904 PUSH_FIELD (method_type_node
, field
, "index", unsigned_short_type_node
);
905 PUSH_FIELD (method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
906 PUSH_FIELD (method_type_node
, field
, "throws", ptr_type_node
);
907 FINISH_RECORD (method_type_node
);
908 build_decl (TYPE_DECL
, get_identifier ("Method"), method_type_node
);
910 endlink
= end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
912 t
= tree_cons (NULL_TREE
, class_ptr_type
, endlink
);
913 alloc_object_node
= add_builtin_function ("_Jv_AllocObject",
914 build_function_type (ptr_type_node
, t
),
915 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
916 DECL_IS_MALLOC (alloc_object_node
) = 1;
917 alloc_no_finalizer_node
=
918 add_builtin_function ("_Jv_AllocObjectNoFinalizer",
919 build_function_type (ptr_type_node
, t
),
920 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
921 DECL_IS_MALLOC (alloc_no_finalizer_node
) = 1;
923 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
924 soft_initclass_node
= add_builtin_function ("_Jv_InitClass",
925 build_function_type (void_type_node
,
927 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
928 t
= tree_cons (NULL_TREE
, class_ptr_type
,
929 tree_cons (NULL_TREE
, int_type_node
, endlink
));
930 soft_resolvepoolentry_node
931 = add_builtin_function ("_Jv_ResolvePoolEntry",
932 build_function_type (ptr_type_node
, t
),
933 0,NOT_BUILT_IN
, NULL
, NULL_TREE
);
934 DECL_IS_PURE (soft_resolvepoolentry_node
) = 1;
935 throw_node
= add_builtin_function ("_Jv_Throw",
936 build_function_type (void_type_node
, t
),
937 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
938 /* Mark throw_nodes as `noreturn' functions with side effects. */
939 TREE_THIS_VOLATILE (throw_node
) = 1;
940 TREE_SIDE_EFFECTS (throw_node
) = 1;
942 t
= build_function_type (void_type_node
, tree_cons (NULL_TREE
, ptr_type_node
,
944 soft_monitorenter_node
945 = add_builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
947 soft_monitorexit_node
948 = add_builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
951 t
= tree_cons (NULL_TREE
, ptr_type_node
,
952 tree_cons (NULL_TREE
, int_type_node
, endlink
));
954 = add_builtin_function ("_Jv_NewPrimArray",
955 build_function_type (ptr_type_node
, t
),
956 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
957 DECL_IS_MALLOC (soft_newarray_node
) = 1;
959 t
= tree_cons (NULL_TREE
, int_type_node
,
960 tree_cons (NULL_TREE
, class_ptr_type
,
961 tree_cons (NULL_TREE
, object_ptr_type_node
,
964 = add_builtin_function ("_Jv_NewObjectArray",
965 build_function_type (ptr_type_node
, t
),
966 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
967 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
969 /* There is no endlink here because _Jv_NewMultiArray is a varargs
971 t
= tree_cons (NULL_TREE
, ptr_type_node
,
972 tree_cons (NULL_TREE
, int_type_node
, NULL_TREE
));
973 soft_multianewarray_node
974 = add_builtin_function ("_Jv_NewMultiArray",
975 build_function_type (ptr_type_node
, t
),
976 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
977 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
979 t
= build_function_type (void_type_node
,
980 tree_cons (NULL_TREE
, int_type_node
, endlink
));
981 soft_badarrayindex_node
982 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t
,
983 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
984 /* Mark soft_badarrayindex_node as a `noreturn' function with side
986 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
987 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
989 soft_nullpointer_node
990 = add_builtin_function ("_Jv_ThrowNullPointerException",
991 build_function_type (void_type_node
, endlink
),
992 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
993 /* Mark soft_nullpointer_node as a `noreturn' function with side
995 TREE_THIS_VOLATILE (soft_nullpointer_node
) = 1;
996 TREE_SIDE_EFFECTS (soft_nullpointer_node
) = 1;
998 soft_abstractmethod_node
999 = add_builtin_function ("_Jv_ThrowAbstractMethodError",
1000 build_function_type (void_type_node
, endlink
),
1001 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1002 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1004 TREE_THIS_VOLATILE (soft_abstractmethod_node
) = 1;
1005 TREE_SIDE_EFFECTS (soft_abstractmethod_node
) = 1;
1007 soft_nosuchfield_node
1008 = add_builtin_function ("_Jv_ThrowNoSuchFieldError",
1009 build_function_type (void_type_node
, endlink
),
1010 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1011 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1013 TREE_THIS_VOLATILE (soft_nosuchfield_node
) = 1;
1014 TREE_SIDE_EFFECTS (soft_nosuchfield_node
) = 1;
1016 t
= tree_cons (NULL_TREE
, class_ptr_type
,
1017 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
1019 = add_builtin_function ("_Jv_CheckCast",
1020 build_function_type (ptr_type_node
, t
),
1021 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1022 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
1023 tree_cons (NULL_TREE
, class_ptr_type
, endlink
));
1024 soft_instanceof_node
1025 = add_builtin_function ("_Jv_IsInstanceOf",
1026 build_function_type (boolean_type_node
, t
),
1027 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1028 DECL_IS_PURE (soft_instanceof_node
) = 1;
1029 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
1030 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
1031 soft_checkarraystore_node
1032 = add_builtin_function ("_Jv_CheckArrayStore",
1033 build_function_type (void_type_node
, t
),
1034 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1035 t
= tree_cons (NULL_TREE
, ptr_type_node
,
1036 tree_cons (NULL_TREE
, ptr_type_node
,
1037 tree_cons (NULL_TREE
, int_type_node
, endlink
)));
1038 soft_lookupinterfacemethod_node
1039 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx",
1040 build_function_type (ptr_type_node
, t
),
1041 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1042 DECL_IS_PURE (soft_lookupinterfacemethod_node
) = 1;
1043 t
= tree_cons (NULL_TREE
, ptr_type_node
,
1044 tree_cons (NULL_TREE
, ptr_type_node
,
1045 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)));
1046 soft_lookupinterfacemethodbyname_node
1047 = add_builtin_function ("_Jv_LookupInterfaceMethod",
1048 build_function_type (ptr_type_node
, t
),
1049 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1050 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
1051 tree_cons (NULL_TREE
, ptr_type_node
,
1052 tree_cons (NULL_TREE
, ptr_type_node
,
1053 tree_cons (NULL_TREE
, int_type_node
,
1055 soft_lookupjnimethod_node
1056 = add_builtin_function ("_Jv_LookupJNIMethod",
1057 build_function_type (ptr_type_node
, t
),
1058 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1059 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
1060 soft_getjnienvnewframe_node
1061 = add_builtin_function ("_Jv_GetJNIEnvNewFrame",
1062 build_function_type (ptr_type_node
, t
),
1063 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1064 soft_jnipopsystemframe_node
1065 = add_builtin_function ("_Jv_JNI_PopSystemFrame",
1066 build_function_type (void_type_node
, t
),
1067 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1069 t
= tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
);
1071 = add_builtin_function ("_Jv_UnwrapJNIweakReference",
1072 build_function_type (object_ptr_type_node
, t
),
1073 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1075 t
= tree_cons (NULL_TREE
, int_type_node
,
1076 tree_cons (NULL_TREE
, int_type_node
, endlink
));
1078 = add_builtin_function ("_Jv_divI",
1079 build_function_type (int_type_node
, t
),
1080 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1083 = add_builtin_function ("_Jv_remI",
1084 build_function_type (int_type_node
, t
),
1085 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1087 t
= tree_cons (NULL_TREE
, long_type_node
,
1088 tree_cons (NULL_TREE
, long_type_node
, endlink
));
1090 = add_builtin_function ("_Jv_divJ",
1091 build_function_type (long_type_node
, t
),
1092 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1095 = add_builtin_function ("_Jv_remJ",
1096 build_function_type (long_type_node
, t
),
1097 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1099 /* Initialize variables for except.c. */
1100 eh_personality_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
1101 ? "__gcj_personality_sj0"
1102 : "__gcj_personality_v0");
1103 default_init_unwind_resume_libfunc ();
1105 lang_eh_runtime_type
= do_nothing
;
1107 initialize_builtins ();
1108 soft_fmod_node
= built_in_decls
[BUILT_IN_FMOD
];
1110 soft_fmodf_node
= built_in_decls
[BUILT_IN_FMODF
];
1117 /* Look up NAME in the current binding level and its superiors
1118 in the namespace of variables, functions and typedefs.
1119 Return a ..._DECL node of some kind representing its definition,
1120 or return 0 if it is undefined. */
1123 lookup_name (tree name
)
1126 if (current_binding_level
!= global_binding_level
1127 && IDENTIFIER_LOCAL_VALUE (name
))
1128 val
= IDENTIFIER_LOCAL_VALUE (name
);
1130 val
= IDENTIFIER_GLOBAL_VALUE (name
);
1134 /* Similar to `lookup_name' but look only at current binding level and
1135 the previous one if it's the parameter level. */
1138 lookup_name_current_level (tree name
)
1142 if (current_binding_level
== global_binding_level
)
1143 return IDENTIFIER_GLOBAL_VALUE (name
);
1145 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
1148 for (t
= current_binding_level
->names
; t
; t
= TREE_CHAIN (t
))
1149 if (DECL_NAME (t
) == name
)
1155 /* Use a binding level to record a labeled block declaration */
1158 push_labeled_block (tree lb
)
1160 tree name
= DECL_NAME (LABELED_BLOCK_LABEL (lb
));
1161 struct binding_level
*b
= current_binding_level
;
1162 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1164 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1165 TREE_CHAIN (lb
) = b
->names
;
1167 IDENTIFIER_LOCAL_VALUE (name
) = lb
;
1170 /* Pop the current binding level, reinstalling values for the previous
1174 pop_labeled_block (void)
1176 struct binding_level
*b
= current_binding_level
;
1177 tree label
= b
->names
;
1178 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label
))) =
1181 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b
->shadowed
)) =
1182 TREE_VALUE (b
->shadowed
);
1184 /* Pop the current level, and free the structure for reuse. */
1185 current_binding_level
= current_binding_level
->level_chain
;
1186 b
->level_chain
= free_binding_level
;
1187 free_binding_level
= b
;
1190 /* Record a decl-node X as belonging to the current lexical scope.
1191 Check for errors (such as an incompatible declaration for the same
1192 name already seen in the same scope).
1194 Returns either X or an old decl for the same name.
1195 If an old decl is returned, it may have been smashed
1196 to agree with what X says. */
1202 tree name
= DECL_NAME (x
);
1203 struct binding_level
*b
= current_binding_level
;
1205 if (TREE_CODE (x
) != TYPE_DECL
)
1206 DECL_CONTEXT (x
) = current_function_decl
;
1209 t
= lookup_name_current_level (name
);
1210 if (t
!= 0 && t
== error_mark_node
)
1211 /* error_mark_node is 0 for a while during initialization! */
1214 error ("%q+D used prior to declaration", x
);
1217 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1218 to point to the TYPE_DECL.
1219 Since Java does not have typedefs, a type can only have
1220 one (true) name, given by a class, interface, or builtin. */
1221 if (TREE_CODE (x
) == TYPE_DECL
1222 && TYPE_NAME (TREE_TYPE (x
)) == 0
1223 && TREE_TYPE (x
) != error_mark_node
)
1225 TYPE_NAME (TREE_TYPE (x
)) = x
;
1226 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1229 /* This name is new in its binding level.
1230 Install the new declaration and return it. */
1231 if (b
== global_binding_level
)
1233 /* Install a global value. */
1235 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1239 /* Here to install a non-global value. */
1240 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1241 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1244 /* Warn if shadowing an argument at the top level of the body. */
1245 if (oldlocal
!= 0 && !DECL_EXTERNAL (x
)
1246 /* This warning doesn't apply to the parms of a nested fcn. */
1247 && ! current_binding_level
->parm_flag
1248 /* Check that this is one level down from the parms. */
1249 && current_binding_level
->level_chain
->parm_flag
1250 /* Check that the decl being shadowed
1251 comes from the parm level, one level up. */
1252 && chain_member (oldlocal
, current_binding_level
->level_chain
->names
))
1254 if (TREE_CODE (oldlocal
) == PARM_DECL
)
1255 pedwarn ("declaration of %qs shadows a parameter",
1256 IDENTIFIER_POINTER (name
));
1258 pedwarn ("declaration of %qs shadows a symbol from the parameter list",
1259 IDENTIFIER_POINTER (name
));
1262 /* Maybe warn if shadowing something else. */
1263 else if (warn_shadow
&& !DECL_EXTERNAL (x
)
1264 /* No shadow warnings for internally generated vars. */
1265 && DECL_SOURCE_LINE (x
) != 0
1266 /* No shadow warnings for vars made for inlining. */
1267 && ! DECL_FROM_INLINE (x
))
1269 const char *warnstring
= 0;
1271 if (TREE_CODE (x
) == PARM_DECL
1272 && current_binding_level
->level_chain
->parm_flag
)
1273 /* Don't warn about the parm names in function declarator
1274 within a function declarator.
1275 It would be nice to avoid warning in any function
1276 declarator in a declaration, as opposed to a definition,
1277 but there is no way to tell it's not a definition. */
1279 else if (oldlocal
!= 0 && TREE_CODE (oldlocal
) == PARM_DECL
)
1280 warnstring
= "declaration of %qs shadows a parameter";
1281 else if (oldlocal
!= 0)
1282 warnstring
= "declaration of %qs shadows previous local";
1283 else if (IDENTIFIER_GLOBAL_VALUE (name
) != 0
1284 && IDENTIFIER_GLOBAL_VALUE (name
) != error_mark_node
)
1285 warnstring
= "declaration of %qs shadows global declaration";
1288 warning (0, warnstring
, IDENTIFIER_POINTER (name
));
1292 /* If storing a local value, there may already be one (inherited).
1293 If so, record it for restoration when this binding level ends. */
1295 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1299 /* Put decls on list in reverse order.
1300 We will reverse them later if necessary. */
1301 TREE_CHAIN (x
) = b
->names
;
1308 pushdecl_force_head (tree x
)
1310 current_binding_level
->names
= x
;
1313 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1316 pushdecl_top_level (tree x
)
1319 struct binding_level
*b
= current_binding_level
;
1321 current_binding_level
= global_binding_level
;
1323 current_binding_level
= b
;
1327 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1330 pushdecl_function_level (tree x
)
1333 struct binding_level
*b
= current_binding_level
;
1335 current_binding_level
= function_binding_level
;
1337 current_binding_level
= b
;
1341 /* Nonzero if we are currently in the global binding level. */
1344 global_bindings_p (void)
1346 return current_binding_level
== global_binding_level
;
1349 /* Return the list of declarations of the current level.
1350 Note that this list is in reverse order unless/until
1351 you nreverse it; and when you do nreverse it, you must
1352 store the result back using `storedecls' or you will lose. */
1357 return current_binding_level
->names
;
1360 /* Create a new `struct binding_level'. */
1362 static struct binding_level
*
1363 make_binding_level (void)
1366 return ggc_alloc_cleared (sizeof (struct binding_level
));
1370 pushlevel (int unused ATTRIBUTE_UNUSED
)
1372 struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1375 /* If this is the top level of a function,
1376 just make sure that NAMED_LABELS is 0. */
1378 if (current_binding_level
== global_binding_level
)
1382 /* Reuse or create a struct for this binding level. */
1384 if (free_binding_level
)
1386 newlevel
= free_binding_level
;
1387 free_binding_level
= free_binding_level
->level_chain
;
1391 newlevel
= make_binding_level ();
1394 /* Add this level to the front of the chain (stack) of levels that
1397 *newlevel
= clear_binding_level
;
1398 newlevel
->level_chain
= current_binding_level
;
1399 current_binding_level
= newlevel
;
1400 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1401 newlevel
->binding_depth
= binding_depth
;
1403 fprintf (stderr
, "push %s level %p pc %d\n",
1404 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1407 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1410 /* Exit a binding level.
1411 Pop the level off, and restore the state of the identifier-decl mappings
1412 that were in effect when this level was entered.
1414 If KEEP is nonzero, this level had explicit declarations, so
1415 and create a "block" (a BLOCK node) for the level
1416 to record its declarations and subblocks for symbol table output.
1418 If FUNCTIONBODY is nonzero, this level is the body of a function,
1419 so create a block as if KEEP were set and also clear out all
1422 If REVERSE is nonzero, reverse the order of decls before putting
1423 them into the BLOCK. */
1426 poplevel (int keep
, int reverse
, int functionbody
)
1429 /* The chain of decls was accumulated in reverse order.
1430 Put it into forward order, just for cleanliness. */
1432 tree subblocks
= current_binding_level
->blocks
;
1437 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1440 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1441 fprintf (stderr
, "pop %s level %p pc %d (end pc %d)\n",
1442 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1443 current_binding_level
->end_pc
);
1445 fprintf (stderr
, "pop %s level %p pc %d\n",
1446 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1448 if (is_class_level
!= (current_binding_level
== class_binding_level
))
1451 fprintf (stderr
, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1455 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1457 /* Get the decls in the order they were written.
1458 Usually current_binding_level->names is in reverse order.
1459 But parameter decls were previously put in forward order. */
1462 current_binding_level
->names
1463 = decls
= nreverse (current_binding_level
->names
);
1465 decls
= current_binding_level
->names
;
1467 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1468 if (TREE_CODE (decl
) == VAR_DECL
1469 && DECL_LANG_SPECIFIC (decl
) != NULL
1470 && DECL_LOCAL_SLOT_NUMBER (decl
))
1471 LOCAL_VAR_OUT_OF_SCOPE_P (decl
) = 1;
1473 /* If there were any declarations in that level,
1474 or if this level is a function body,
1475 create a BLOCK to record them for the life of this function. */
1478 if (keep
|| functionbody
)
1480 block
= make_node (BLOCK
);
1481 TREE_TYPE (block
) = void_type_node
;
1484 if (current_binding_level
->exception_range
)
1485 expand_end_java_handler (current_binding_level
->exception_range
);
1489 /* If any statements have been generated at this level, create a
1490 BIND_EXPR to hold them and copy the variables to it. This
1491 only applies to the bytecode compiler. */
1492 if (current_binding_level
->stmts
)
1495 tree
*var
= &BLOCK_VARS (block
);
1497 /* Copy decls from names list, ignoring labels. */
1500 tree next
= TREE_CHAIN (decl
);
1501 if (TREE_CODE (decl
) != LABEL_DECL
)
1504 var
= &TREE_CHAIN (decl
);
1510 bind
= build3 (BIND_EXPR
, TREE_TYPE (block
), BLOCK_VARS (block
),
1511 BLOCK_EXPR_BODY (block
), block
);
1512 BIND_EXPR_BODY (bind
) = current_binding_level
->stmts
;
1514 if (BIND_EXPR_BODY (bind
)
1515 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind
)))
1516 TREE_SIDE_EFFECTS (bind
) = 1;
1518 /* FIXME: gimplifier brain damage. */
1519 if (BIND_EXPR_BODY (bind
) == NULL
)
1520 BIND_EXPR_BODY (bind
) = build_java_empty_stmt ();
1522 current_binding_level
->stmts
= NULL
;
1526 BLOCK_VARS (block
) = decls
;
1528 BLOCK_SUBBLOCKS (block
) = subblocks
;
1531 /* In each subblock, record that this is its superior. */
1533 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1534 BLOCK_SUPERCONTEXT (link
) = block
;
1536 /* Clear out the meanings of the local variables of this level. */
1538 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1540 tree name
= DECL_NAME (link
);
1541 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1543 /* If the ident. was used or addressed via a local extern decl,
1544 don't forget that fact. */
1545 if (DECL_EXTERNAL (link
))
1547 if (TREE_USED (link
))
1548 TREE_USED (name
) = 1;
1549 if (TREE_ADDRESSABLE (link
))
1550 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1552 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1556 /* Restore all name-meanings of the outer levels
1557 that were shadowed by this level. */
1559 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1560 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1562 /* If the level being exited is the top level of a function,
1563 check over all the labels, and clear out the current
1564 (function local) meanings of their names. */
1568 /* If this is the top level block of a function,
1569 the vars are the function's parameters.
1570 Don't leave them in the BLOCK because they are
1571 found in the FUNCTION_DECL instead. */
1573 BLOCK_VARS (block
) = 0;
1575 /* Clear out the definitions of all label names,
1576 since their scopes end here,
1577 and add them to BLOCK_VARS. */
1580 for (link
= named_labels
; link
; link
= TREE_CHAIN (link
))
1582 tree label
= TREE_VALUE (link
);
1584 if (DECL_INITIAL (label
) == 0)
1586 error ("label %q+D used but not defined", label
);
1587 /* Avoid crashing later. */
1588 define_label (input_location
, DECL_NAME (label
));
1590 else if (warn_unused
[UNUSED_LABEL
] && !TREE_USED (label
))
1591 warning (0, "label %q+D defined but not used", label
);
1592 IDENTIFIER_LABEL_VALUE (DECL_NAME (label
)) = 0;
1594 /* Put the labels into the "variables" of the
1595 top-level block, so debugger can see them. */
1596 TREE_CHAIN (label
) = BLOCK_VARS (block
);
1597 BLOCK_VARS (block
) = label
;
1602 /* Pop the current level, and free the structure for reuse. */
1605 struct binding_level
*level
= current_binding_level
;
1606 current_binding_level
= current_binding_level
->level_chain
;
1608 level
->level_chain
= free_binding_level
;
1609 free_binding_level
= level
;
1612 /* Dispose of the block that we just made inside some higher level. */
1615 DECL_INITIAL (current_function_decl
) = block
;
1616 DECL_SAVED_TREE (current_function_decl
) = bind
;
1622 current_binding_level
->blocks
1623 = chainon (current_binding_level
->blocks
, block
);
1625 /* If we did not make a block for the level just exited,
1626 any blocks made for inner levels
1627 (since they cannot be recorded as subblocks in that level)
1628 must be carried forward so they will later become subblocks
1629 of something else. */
1631 current_binding_level
->blocks
1632 = chainon (current_binding_level
->blocks
, subblocks
);
1635 java_add_stmt (bind
);
1639 TREE_USED (block
) = 1;
1644 maybe_pushlevels (int pc
)
1646 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1650 while (pending_local_decls
!= NULL_TREE
&&
1651 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1653 tree
*ptr
= &pending_local_decls
;
1654 tree decl
= *ptr
, next
;
1655 int end_pc
= DECL_LOCAL_END_PC (decl
);
1657 while (*ptr
!= NULL_TREE
1658 && DECL_LOCAL_START_PC (*ptr
) <= pc
1659 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1660 ptr
= &TREE_CHAIN (*ptr
);
1661 pending_local_decls
= *ptr
;
1664 /* Force non-nested range to be nested in current range by
1665 truncating variable lifetimes. */
1666 if (end_pc
> current_binding_level
->end_pc
)
1669 end_pc
= current_binding_level
->end_pc
;
1670 for (t
= decl
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1671 DECL_LOCAL_END_PC (t
) = end_pc
;
1674 maybe_start_try (pc
, end_pc
);
1678 current_binding_level
->end_pc
= end_pc
;
1679 current_binding_level
->start_pc
= pc
;
1680 current_binding_level
->names
= NULL
;
1681 for ( ; decl
!= NULL_TREE
; decl
= next
)
1683 int index
= DECL_LOCAL_SLOT_NUMBER (decl
);
1685 next
= TREE_CHAIN (decl
);
1686 push_jvm_slot (index
, decl
);
1689 = find_local_variable (index
, TREE_TYPE (decl
), pc
);
1690 if (TREE_CODE (TREE_TYPE (base_decl
)) == POINTER_TYPE
)
1691 base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
1692 SET_DECL_VALUE_EXPR (decl
, base_decl
);
1693 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1697 maybe_start_try (pc
, 0);
1701 maybe_poplevels (int pc
)
1703 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1707 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1708 inclusive, so a variable is live if pc == end_pc. Here, we
1709 terminate a range if the current pc is equal to the end of the
1710 range, and this is *before* we have generated code for the
1711 instruction at end_pc. We're closing a binding level one
1712 instruction too early.*/
1713 while (current_binding_level
->end_pc
<= pc
)
1717 /* Terminate any binding which began during the range beginning at
1718 start_pc. This tidies up improperly nested local variable ranges
1719 and exception handlers; a variable declared within an exception
1720 range is forcibly terminated when that exception ends. */
1723 force_poplevels (int start_pc
)
1725 while (current_binding_level
->start_pc
> start_pc
)
1727 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1728 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1729 current_function_decl
,
1730 current_binding_level
->start_pc
);
1735 /* Insert BLOCK at the end of the list of subblocks of the
1736 current binding level. This is used when a BIND_EXPR is expanded,
1737 to handle the BLOCK node inside the BIND_EXPR. */
1740 insert_block (tree block
)
1742 TREE_USED (block
) = 1;
1743 current_binding_level
->blocks
1744 = chainon (current_binding_level
->blocks
, block
);
1747 /* integrate_decl_tree calls this function. */
1750 java_dup_lang_specific_decl (tree node
)
1753 struct lang_decl
*x
;
1755 if (!DECL_LANG_SPECIFIC (node
))
1758 lang_decl_size
= sizeof (struct lang_decl
);
1759 x
= ggc_alloc (lang_decl_size
);
1760 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1761 DECL_LANG_SPECIFIC (node
) = x
;
1765 give_name_to_locals (JCF
*jcf
)
1767 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1768 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1770 pending_local_decls
= NULL_TREE
;
1774 n
= JCF_readu2 (jcf
);
1775 for (i
= 0; i
< n
; i
++)
1777 int start_pc
= JCF_readu2 (jcf
);
1778 int length
= JCF_readu2 (jcf
);
1779 int name_index
= JCF_readu2 (jcf
);
1780 int signature_index
= JCF_readu2 (jcf
);
1781 int slot
= JCF_readu2 (jcf
);
1782 tree name
= get_name_constant (jcf
, name_index
);
1783 tree type
= parse_signature (jcf
, signature_index
);
1784 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1786 && length
== DECL_CODE_LENGTH (current_function_decl
))
1788 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1789 DECL_NAME (decl
) = name
;
1790 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1791 warning (0, "bad type in parameter debug info");
1796 int end_pc
= start_pc
+ length
;
1797 tree decl
= build_decl (VAR_DECL
, name
, type
);
1798 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1800 warning (0, "bad PC range for debug info for local %q+D",
1802 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1805 /* Adjust start_pc if necessary so that the local's first
1806 store operation will use the relevant DECL as a
1807 destination. Fore more information, read the leading
1808 comments for expr.c:maybe_adjust_start_pc. */
1809 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1811 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1812 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1813 DECL_LOCAL_START_PC (decl
) = start_pc
;
1815 /* FIXME: The range used internally for exceptions and local
1816 variable ranges, is a half-open interval:
1817 start_pc <= pc < end_pc. However, the range used in the
1818 Java VM spec is inclusive at both ends:
1819 start_pc <= pc <= end_pc. */
1822 DECL_LOCAL_END_PC (decl
) = end_pc
;
1824 /* Now insert the new decl in the proper place in
1825 pending_local_decls. We are essentially doing an insertion sort,
1826 which works fine, since the list input will normally already
1828 ptr
= &pending_local_decls
;
1829 while (*ptr
!= NULL_TREE
1830 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1831 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1832 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1833 ptr
= &TREE_CHAIN (*ptr
);
1834 TREE_CHAIN (decl
) = *ptr
;
1839 pending_local_decls
= nreverse (pending_local_decls
);
1841 /* Fill in default names for the parameters. */
1842 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1843 parm
!= NULL_TREE
; parm
= TREE_CHAIN (parm
), i
++)
1845 if (DECL_NAME (parm
) == NULL_TREE
)
1847 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1849 DECL_NAME (parm
) = get_identifier ("this");
1853 sprintf (buffer
, "ARG_%d", arg_i
);
1854 DECL_NAME (parm
) = get_identifier (buffer
);
1861 build_result_decl (tree fndecl
)
1863 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1864 tree result
= DECL_RESULT (fndecl
);
1867 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1868 if (INTEGRAL_TYPE_P (restype
)
1869 && TYPE_PRECISION (restype
) < TYPE_PRECISION (integer_type_node
))
1870 restype
= integer_type_node
;
1871 result
= build_decl (RESULT_DECL
, NULL_TREE
, restype
);
1872 DECL_ARTIFICIAL (result
) = 1;
1873 DECL_IGNORED_P (result
) = 1;
1874 DECL_CONTEXT (result
) = fndecl
;
1875 DECL_RESULT (fndecl
) = result
;
1881 start_java_method (tree fndecl
)
1888 current_function_decl
= fndecl
;
1889 announce_function (fndecl
);
1891 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1892 decl_map
= make_tree_vec (i
);
1893 base_decl_map
= make_tree_vec (i
);
1894 type_map
= xrealloc (type_map
, i
* sizeof (tree
));
1896 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1897 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1899 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1900 pushlevel (1); /* Push parameters. */
1902 ptr
= &DECL_ARGUMENTS (fndecl
);
1903 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1904 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1906 tree parm_name
= NULL_TREE
, parm_decl
;
1907 tree parm_type
= TREE_VALUE (tem
);
1908 gcc_assert (i
< DECL_MAX_LOCALS (fndecl
));
1910 parm_decl
= build_decl (PARM_DECL
, parm_name
, parm_type
);
1911 DECL_CONTEXT (parm_decl
) = fndecl
;
1912 if (targetm
.calls
.promote_prototypes (parm_type
)
1913 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1914 && INTEGRAL_TYPE_P (parm_type
))
1915 parm_type
= integer_type_node
;
1916 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1919 ptr
= &TREE_CHAIN (parm_decl
);
1921 /* Add parm_decl to the decl_map. */
1922 push_jvm_slot (i
, parm_decl
);
1924 type_map
[i
] = TREE_TYPE (parm_decl
);
1925 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1928 type_map
[i
] = void_type_node
;
1932 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1934 while (i
< DECL_MAX_LOCALS(fndecl
))
1935 type_map
[i
++] = NULL_TREE
;
1937 build_result_decl (fndecl
);
1939 /* Push local variables. */
1942 function_binding_level
= current_binding_level
;
1946 end_java_method (void)
1948 tree fndecl
= current_function_decl
;
1950 /* pop out of function */
1953 /* pop out of its parameters */
1956 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1958 if (DECL_SAVED_TREE (fndecl
))
1960 tree fbody
, block_body
;
1961 /* Before we check initialization, attached all class initialization
1962 variable to the block_body */
1963 fbody
= DECL_SAVED_TREE (fndecl
);
1964 block_body
= BIND_EXPR_BODY (fbody
);
1965 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl
),
1966 attach_init_test_initialization_flags
, block_body
);
1969 finish_method (fndecl
);
1971 if (! flag_unit_at_a_time
)
1973 /* Nulling these fields when we no longer need them saves
1975 DECL_SAVED_TREE (fndecl
) = NULL
;
1976 DECL_STRUCT_FUNCTION (fndecl
) = NULL
;
1977 DECL_INITIAL (fndecl
) = NULL_TREE
;
1979 current_function_decl
= NULL_TREE
;
1982 /* Prepare a method for expansion. */
1985 finish_method (tree fndecl
)
1987 tree
*tp
= &DECL_SAVED_TREE (fndecl
);
1989 /* Wrap body of synchronized methods in a monitorenter,
1990 plus monitorexit cleanup. */
1991 if (METHOD_SYNCHRONIZED (fndecl
))
1993 tree enter
, exit
, lock
;
1994 if (METHOD_STATIC (fndecl
))
1995 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1997 lock
= DECL_ARGUMENTS (fndecl
);
1998 BUILD_MONITOR_ENTER (enter
, lock
);
1999 BUILD_MONITOR_EXIT (exit
, lock
);
2000 *tp
= build2 (COMPOUND_EXPR
, void_type_node
, enter
,
2001 build2 (TRY_FINALLY_EXPR
, void_type_node
, *tp
, exit
));
2004 /* Prepend class initialization for static methods reachable from
2006 if (METHOD_STATIC (fndecl
)
2007 && (! METHOD_PRIVATE (fndecl
)
2008 || INNER_CLASS_P (DECL_CONTEXT (fndecl
)))
2009 && ! DECL_CLINIT_P (fndecl
)
2010 && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl
))))
2012 tree clas
= DECL_CONTEXT (fndecl
);
2013 tree init
= build3 (CALL_EXPR
, void_type_node
,
2014 build_address_of (soft_initclass_node
),
2015 build_tree_list (NULL_TREE
, build_class_ref (clas
)),
2017 *tp
= build2 (COMPOUND_EXPR
, TREE_TYPE (*tp
), init
, *tp
);
2020 /* Convert function tree to GENERIC prior to inlining. */
2021 java_genericize (fndecl
);
2023 /* Store the end of the function, so that we get good line number
2024 info for the epilogue. */
2025 if (DECL_STRUCT_FUNCTION (fndecl
))
2026 cfun
= DECL_STRUCT_FUNCTION (fndecl
);
2028 allocate_struct_function (fndecl
);
2029 #ifdef USE_MAPPED_LOCATION
2030 cfun
->function_end_locus
= DECL_FUNCTION_LAST_LINE (fndecl
);
2032 cfun
->function_end_locus
.file
= DECL_SOURCE_FILE (fndecl
);
2033 cfun
->function_end_locus
.line
= DECL_FUNCTION_LAST_LINE (fndecl
);
2036 /* Defer inlining and expansion to the cgraph optimizers. */
2037 cgraph_finalize_function (fndecl
, false);
2040 /* Optimize and expand a function's entire body. */
2043 java_expand_body (tree fndecl
)
2045 tree_rest_of_compilation (fndecl
);
2048 /* We pessimistically marked all methods and fields external until we
2049 knew what set of classes we were planning to compile. Now mark those
2050 associated with CLASS to be generated locally as not external. */
2053 java_mark_decl_local (tree decl
)
2055 DECL_EXTERNAL (decl
) = 0;
2057 /* If we've already constructed DECL_RTL, give encode_section_info
2058 a second chance, now that we've changed the flags. */
2059 /* ??? Ideally, we'd have flag_unit_at_a_time set, and not have done
2060 anything that would have referenced DECL_RTL so far. But at the
2061 moment we force flag_unit_at_a_time off due to excessive memory
2062 consumption when compiling large jar files. Which probably means
2063 that we need to re-order how we process jar files... */
2064 if (DECL_RTL_SET_P (decl
))
2065 make_decl_rtl (decl
);
2068 /* Given appropriate target support, G++ will emit hidden aliases for native
2069 methods. Using this hidden name is required for proper operation of
2070 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
2071 proper target support, then mark the method for aliasing. */
2074 java_mark_cni_decl_local (tree decl
)
2076 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the mangler.
2077 We expect that we should not yet have referenced this decl in a
2078 context that requires it. Check this invariant even if we don't have
2079 support for hidden aliases. */
2080 gcc_assert (!DECL_ASSEMBLER_NAME_SET_P (decl
));
2082 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
2086 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
2087 DECL_LOCAL_CNI_METHOD_P (decl
) = 1;
2090 /* Use the preceding two functions and mark all members of the class. */
2093 java_mark_class_local (tree
class)
2097 for (t
= TYPE_FIELDS (class); t
; t
= TREE_CHAIN (t
))
2098 if (FIELD_STATIC (t
))
2099 java_mark_decl_local (t
);
2101 for (t
= TYPE_METHODS (class); t
; t
= TREE_CHAIN (t
))
2102 if (!METHOD_ABSTRACT (t
))
2104 if (METHOD_NATIVE (t
) && !flag_jni
)
2105 java_mark_cni_decl_local (t
);
2107 java_mark_decl_local (t
);
2111 /* Add a statement to a compound_expr. */
2114 add_stmt_to_compound (tree existing
, tree type
, tree stmt
)
2120 tree expr
= build2 (COMPOUND_EXPR
, type
, existing
, stmt
);
2121 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (existing
)
2122 | TREE_SIDE_EFFECTS (stmt
);
2129 /* Add a statement to the statement_list currently being constructed.
2130 If the statement_list is null, we don't create a singleton list.
2131 This is necessary because poplevel() assumes that adding a
2132 statement to a null statement_list returns the statement. */
2135 java_add_stmt (tree new_stmt
)
2137 tree stmts
= current_binding_level
->stmts
;
2138 tree_stmt_iterator i
;
2141 SET_EXPR_LOCATION (new_stmt
, input_location
);
2144 return current_binding_level
->stmts
= new_stmt
;
2146 /* Force STMTS to be a statement_list. */
2147 if (TREE_CODE (stmts
) != STATEMENT_LIST
)
2149 tree t
= make_node (STATEMENT_LIST
);
2151 tsi_link_after (&i
, stmts
, TSI_CONTINUE_LINKING
);
2155 i
= tsi_last (stmts
);
2156 tsi_link_after (&i
, new_stmt
, TSI_CONTINUE_LINKING
);
2157 TREE_TYPE (stmts
) = void_type_node
;
2159 return current_binding_level
->stmts
= stmts
;
2162 /* Add a variable to the current scope. */
2165 java_add_local_var (tree decl
)
2167 tree
*vars
= ¤t_binding_level
->names
;
2169 TREE_CHAIN (decl
) = next
;
2171 DECL_CONTEXT (decl
) = current_function_decl
;
2172 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
2176 /* Return a pointer to the compound_expr currently being
2182 return ¤t_binding_level
->stmts
;
2185 /* Register an exception range as belonging to the current binding
2186 level. There may only be one: if there are more, we'll create more
2187 binding levels. However, each range can have multiple handlers,
2188 and these are expanded when we call expand_end_java_handler(). */
2191 register_exception_range (struct eh_range
*range
, int pc
, int end_pc
)
2193 gcc_assert (! current_binding_level
->exception_range
);
2194 current_binding_level
->exception_range
= range
;
2195 current_binding_level
->end_pc
= end_pc
;
2196 current_binding_level
->start_pc
= pc
;
2199 #include "gt-java-decl.h"