1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
4 2005, 2006, 2007, 2008 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 3, 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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
30 #include "coretypes.h"
37 #include "java-tree.h"
43 #include "java-except.h"
47 #include "tree-inline.h"
50 #include "tree-iterator.h"
51 #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 (input_location
, 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 (input_location
, 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 genericization 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
);
344 /* Helper for java_genericize. */
347 java_replace_references (tree
*tp
, int *walk_subtrees
,
348 void *data ATTRIBUTE_UNUSED
)
350 if (TREE_CODE (*tp
) == MODIFY_EXPR
)
352 source_location loc
= EXPR_LOCATION (*tp
);
353 tree lhs
= TREE_OPERAND (*tp
, 0);
354 /* This is specific to the bytecode compiler. If a variable has
355 LOCAL_SLOT_P set, replace an assignment to it with an assignment
356 to the corresponding variable that holds all its aliases. */
357 if (TREE_CODE (lhs
) == VAR_DECL
358 && DECL_LANG_SPECIFIC (lhs
)
359 && LOCAL_SLOT_P (lhs
)
360 && TREE_CODE (TREE_TYPE (lhs
)) == POINTER_TYPE
)
362 tree new_lhs
= java_replace_reference (lhs
, /* want_lvalue */ true);
363 tree new_rhs
= build1 (NOP_EXPR
, TREE_TYPE (new_lhs
),
364 TREE_OPERAND (*tp
, 1));
365 tree tem
= build2 (MODIFY_EXPR
, TREE_TYPE (new_lhs
),
367 *tp
= build1 (NOP_EXPR
, TREE_TYPE (lhs
), tem
);
368 SET_EXPR_LOCATION (tem
, loc
);
369 SET_EXPR_LOCATION (new_rhs
, loc
);
370 SET_EXPR_LOCATION (*tp
, loc
);
373 if (TREE_CODE (*tp
) == VAR_DECL
)
375 *tp
= java_replace_reference (*tp
, /* want_lvalue */ false);
382 /* Same as find_local_index, except that INDEX is a stack index. */
385 find_stack_slot (int index
, tree type
)
387 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
393 /* A chain of _DECL nodes for all variables, constants, functions,
394 * and typedef types. These are in the reverse of the order supplied.
398 /* For each level, a list of shadowed outer-level local definitions
399 to be restored when this level is popped.
400 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
401 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
404 /* For each level (except not the global one),
405 a chain of BLOCK nodes for all the levels
406 that were entered and exited one level down. */
409 /* The binding level which this one is contained in (inherits from). */
410 struct binding_level
*level_chain
;
412 /* The bytecode PC that marks the end of this level. */
414 /* The bytecode PC that marks the start of this level. */
417 /* The statements in this binding level. */
420 /* An exception range associated with this binding level. */
421 struct eh_range
* GTY((skip (""))) exception_range
;
423 /* Binding depth at which this level began. Used only for debugging. */
424 unsigned binding_depth
;
426 /* The location at which this level began. */
430 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
432 /* The binding level currently in effect. */
434 static GTY(()) struct binding_level
*current_binding_level
;
436 /* A chain of binding_level structures awaiting reuse. */
438 static GTY(()) struct binding_level
*free_binding_level
;
440 /* The outermost binding level, for names of file scope.
441 This is created when the compiler is started and exists
442 through the entire run. */
444 static GTY(()) struct binding_level
*global_binding_level
;
446 /* The binding level that holds variables declared at the outermost
447 level within a function body. */
449 static struct binding_level
*function_binding_level
;
451 /* A PC value bigger than any PC value we may ever may encounter. */
453 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
455 /* Binding level structures are initialized by copying this one. */
457 static const struct binding_level clear_binding_level
459 NULL_TREE
, /* names */
460 NULL_TREE
, /* shadowed */
461 NULL_TREE
, /* blocks */
462 NULL_BINDING_LEVEL
, /* level_chain */
463 LARGEST_PC
, /* end_pc */
466 NULL
, /* exception_range */
467 0, /* binding_depth */
471 tree java_global_trees
[JTI_MAX
];
473 /* Build (and pushdecl) a "promoted type" for all standard
474 types shorter than int. */
477 push_promoted_type (const char *name
, tree actual_type
)
479 tree type
= make_node (TREE_CODE (actual_type
));
481 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
482 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
484 tree in_min
= TYPE_MIN_VALUE (actual_type
);
485 tree in_max
= TYPE_MAX_VALUE (actual_type
);
487 TYPE_MIN_VALUE (type
) = copy_node (in_min
);
488 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
489 TYPE_MAX_VALUE (type
) = copy_node (in_max
);
490 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
491 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
492 TYPE_STRING_FLAG (type
) = TYPE_STRING_FLAG (actual_type
);
494 pushdecl (build_decl (input_location
,
495 TYPE_DECL
, get_identifier (name
), type
));
499 /* Return tree that represents a vtable for a primitive array. */
501 create_primitive_vtable (const char *name
)
506 sprintf (buf
, "_Jv_%sVTable", name
);
507 r
= build_decl (input_location
,
508 VAR_DECL
, get_identifier (buf
), ptr_type_node
);
509 DECL_EXTERNAL (r
) = 1;
513 /* Parse the version string and compute the ABI version number. */
517 const char *p
= version_string
;
518 unsigned int major
= 0, minor
= 0;
519 unsigned int abi_version
;
521 /* Skip leading junk. */
522 while (*p
&& !ISDIGIT (*p
))
526 /* Extract major version. */
529 major
= major
* 10 + *p
- '0';
533 gcc_assert (*p
== '.' && ISDIGIT (p
[1]));
536 /* Extract minor version. */
539 minor
= minor
* 10 + *p
- '0';
543 if (flag_indirect_dispatch
)
545 abi_version
= GCJ_CURRENT_BC_ABI_VERSION
;
546 abi_version
|= FLAG_BINARYCOMPAT_ABI
;
550 /* Implicit in this computation is the idea that we won't break the
551 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
553 abi_version
= 100000 * major
+ 1000 * minor
;
555 if (flag_bootstrap_classes
)
556 abi_version
|= FLAG_BOOTSTRAP_LOADER
;
558 gcj_abi_version
= build_int_cstu (ptr_type_node
, abi_version
);
562 java_init_decl_processing (void)
565 tree field
= NULL_TREE
;
568 init_class_processing ();
570 current_function_decl
= NULL
;
571 current_binding_level
= NULL_BINDING_LEVEL
;
572 free_binding_level
= NULL_BINDING_LEVEL
;
573 pushlevel (0); /* make the binding_level structure for global names */
574 global_binding_level
= current_binding_level
;
576 /* The code here must be similar to build_common_tree_nodes{,_2} in
577 tree.c, especially as to the order of initializing common nodes. */
578 error_mark_node
= make_node (ERROR_MARK
);
579 TREE_TYPE (error_mark_node
) = error_mark_node
;
581 /* Create sizetype first - needed for other types. */
582 initialize_sizetypes (false);
584 byte_type_node
= make_signed_type (8);
585 pushdecl (build_decl (BUILTINS_LOCATION
,
586 TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
587 short_type_node
= make_signed_type (16);
588 pushdecl (build_decl (BUILTINS_LOCATION
,
589 TYPE_DECL
, get_identifier ("short"), short_type_node
));
590 int_type_node
= make_signed_type (32);
591 pushdecl (build_decl (BUILTINS_LOCATION
,
592 TYPE_DECL
, get_identifier ("int"), int_type_node
));
593 long_type_node
= make_signed_type (64);
594 pushdecl (build_decl (BUILTINS_LOCATION
,
595 TYPE_DECL
, get_identifier ("long"), long_type_node
));
597 unsigned_byte_type_node
= make_unsigned_type (8);
598 pushdecl (build_decl (BUILTINS_LOCATION
,
599 TYPE_DECL
, get_identifier ("unsigned byte"),
600 unsigned_byte_type_node
));
601 unsigned_short_type_node
= make_unsigned_type (16);
602 pushdecl (build_decl (BUILTINS_LOCATION
,
603 TYPE_DECL
, get_identifier ("unsigned short"),
604 unsigned_short_type_node
));
605 unsigned_int_type_node
= make_unsigned_type (32);
606 pushdecl (build_decl (BUILTINS_LOCATION
,
607 TYPE_DECL
, get_identifier ("unsigned int"),
608 unsigned_int_type_node
));
609 unsigned_long_type_node
= make_unsigned_type (64);
610 pushdecl (build_decl (BUILTINS_LOCATION
,
611 TYPE_DECL
, get_identifier ("unsigned long"),
612 unsigned_long_type_node
));
614 /* This is not a java type, however tree-dfa requires a definition for
616 size_type_node
= make_unsigned_type (POINTER_SIZE
);
617 set_sizetype (size_type_node
);
619 /* Define these next since types below may used them. */
620 integer_type_node
= java_type_for_size (INT_TYPE_SIZE
, 0);
621 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
622 integer_one_node
= build_int_cst (NULL_TREE
, 1);
623 integer_two_node
= build_int_cst (NULL_TREE
, 2);
624 integer_four_node
= build_int_cst (NULL_TREE
, 4);
625 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
627 /* A few values used for range checking in the lexer. */
628 decimal_int_max
= build_int_cstu (unsigned_int_type_node
, 0x80000000);
629 #if HOST_BITS_PER_WIDE_INT == 64
630 decimal_long_max
= build_int_cstu (unsigned_long_type_node
,
631 0x8000000000000000LL
);
632 #elif HOST_BITS_PER_WIDE_INT == 32
633 decimal_long_max
= build_int_cst_wide (unsigned_long_type_node
,
636 #error "unsupported size"
639 size_zero_node
= size_int (0);
640 size_one_node
= size_int (1);
641 bitsize_zero_node
= bitsize_int (0);
642 bitsize_one_node
= bitsize_int (1);
643 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
645 long_zero_node
= build_int_cst (long_type_node
, 0);
647 void_type_node
= make_node (VOID_TYPE
);
648 pushdecl (build_decl (BUILTINS_LOCATION
,
649 TYPE_DECL
, get_identifier ("void"), void_type_node
));
650 layout_type (void_type_node
); /* Uses size_zero_node */
652 ptr_type_node
= build_pointer_type (void_type_node
);
654 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
656 t
= make_node (VOID_TYPE
);
657 layout_type (t
); /* Uses size_zero_node */
658 return_address_type_node
= build_pointer_type (t
);
660 null_pointer_node
= build_int_cst (ptr_type_node
, 0);
662 char_type_node
= make_node (INTEGER_TYPE
);
663 TYPE_STRING_FLAG (char_type_node
) = 1;
664 TYPE_PRECISION (char_type_node
) = 16;
665 fixup_unsigned_type (char_type_node
);
666 pushdecl (build_decl (BUILTINS_LOCATION
,
667 TYPE_DECL
, get_identifier ("char"), char_type_node
));
669 boolean_type_node
= make_node (BOOLEAN_TYPE
);
670 TYPE_PRECISION (boolean_type_node
) = 1;
671 fixup_unsigned_type (boolean_type_node
);
672 pushdecl (build_decl (BUILTINS_LOCATION
,
673 TYPE_DECL
, get_identifier ("boolean"),
675 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
676 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
678 promoted_byte_type_node
679 = push_promoted_type ("promoted_byte", byte_type_node
);
680 promoted_short_type_node
681 = push_promoted_type ("promoted_short", short_type_node
);
682 promoted_char_type_node
683 = push_promoted_type ("promoted_char", char_type_node
);
684 promoted_boolean_type_node
685 = push_promoted_type ("promoted_boolean", boolean_type_node
);
687 float_type_node
= make_node (REAL_TYPE
);
688 TYPE_PRECISION (float_type_node
) = 32;
689 pushdecl (build_decl (BUILTINS_LOCATION
,
690 TYPE_DECL
, get_identifier ("float"),
692 layout_type (float_type_node
);
694 double_type_node
= make_node (REAL_TYPE
);
695 TYPE_PRECISION (double_type_node
) = 64;
696 pushdecl (build_decl (BUILTINS_LOCATION
,
697 TYPE_DECL
, get_identifier ("double"),
699 layout_type (double_type_node
);
701 float_zero_node
= build_real (float_type_node
, dconst0
);
702 double_zero_node
= build_real (double_type_node
, dconst0
);
704 /* These are the vtables for arrays of primitives. */
705 boolean_array_vtable
= create_primitive_vtable ("boolean");
706 byte_array_vtable
= create_primitive_vtable ("byte");
707 char_array_vtable
= create_primitive_vtable ("char");
708 short_array_vtable
= create_primitive_vtable ("short");
709 int_array_vtable
= create_primitive_vtable ("int");
710 long_array_vtable
= create_primitive_vtable ("long");
711 float_array_vtable
= create_primitive_vtable ("float");
712 double_array_vtable
= create_primitive_vtable ("double");
714 one_elt_array_domain_type
= build_index_type (integer_one_node
);
715 utf8const_type
= make_node (RECORD_TYPE
);
716 PUSH_FIELD (input_location
,
717 utf8const_type
, field
, "hash", unsigned_short_type_node
);
718 PUSH_FIELD (input_location
,
719 utf8const_type
, field
, "length", unsigned_short_type_node
);
720 FINISH_RECORD (utf8const_type
);
721 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
723 atable_type
= build_array_type (ptr_type_node
,
724 one_elt_array_domain_type
);
725 TYPE_NONALIASED_COMPONENT (atable_type
) = 1;
726 atable_ptr_type
= build_pointer_type (atable_type
);
728 itable_type
= build_array_type (ptr_type_node
,
729 one_elt_array_domain_type
);
730 TYPE_NONALIASED_COMPONENT (itable_type
) = 1;
731 itable_ptr_type
= build_pointer_type (itable_type
);
733 symbol_type
= make_node (RECORD_TYPE
);
734 PUSH_FIELD (input_location
,
735 symbol_type
, field
, "clname", utf8const_ptr_type
);
736 PUSH_FIELD (input_location
, symbol_type
, field
, "name", utf8const_ptr_type
);
737 PUSH_FIELD (input_location
,
738 symbol_type
, field
, "signature", utf8const_ptr_type
);
739 FINISH_RECORD (symbol_type
);
741 symbols_array_type
= build_array_type (symbol_type
,
742 one_elt_array_domain_type
);
743 symbols_array_ptr_type
= build_pointer_type (symbols_array_type
);
745 assertion_entry_type
= make_node (RECORD_TYPE
);
746 PUSH_FIELD (input_location
,
747 assertion_entry_type
, field
, "assertion_code", integer_type_node
);
748 PUSH_FIELD (input_location
,
749 assertion_entry_type
, field
, "op1", utf8const_ptr_type
);
750 PUSH_FIELD (input_location
,
751 assertion_entry_type
, field
, "op2", utf8const_ptr_type
);
752 FINISH_RECORD (assertion_entry_type
);
754 assertion_table_type
= build_array_type (assertion_entry_type
,
755 one_elt_array_domain_type
);
757 /* As you're adding items here, please update the code right after
758 this section, so that the filename containing the source code of
759 the pre-defined class gets registered correctly. */
760 unqualified_object_id_node
= get_identifier ("Object");
761 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
762 object_ptr_type_node
= promote_type (object_type_node
);
763 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
764 string_ptr_type_node
= promote_type (string_type_node
);
765 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
766 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
767 exception_type_node
= lookup_class (get_identifier ("java.lang.Exception"));
768 runtime_exception_type_node
=
769 lookup_class (get_identifier ("java.lang.RuntimeException"));
770 error_exception_type_node
=
771 lookup_class (get_identifier ("java.lang.Error"));
773 rawdata_ptr_type_node
774 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
776 add_predefined_file (get_identifier ("java/lang/Class.java"));
777 add_predefined_file (get_identifier ("java/lang/Error.java"));
778 add_predefined_file (get_identifier ("java/lang/Object.java"));
779 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
780 add_predefined_file (get_identifier ("java/lang/String.java"));
781 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
782 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
783 add_predefined_file (get_identifier ("java/lang/Exception.java"));
784 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
785 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
787 methodtable_type
= make_node (RECORD_TYPE
);
788 layout_type (methodtable_type
);
789 build_decl (BUILTINS_LOCATION
,
790 TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
791 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
793 TYPE_identifier_node
= get_identifier ("TYPE");
794 init_identifier_node
= get_identifier ("<init>");
795 clinit_identifier_node
= get_identifier ("<clinit>");
796 void_signature_node
= get_identifier ("()V");
797 finalize_identifier_node
= get_identifier ("finalize");
798 this_identifier_node
= get_identifier ("this");
800 java_lang_cloneable_identifier_node
= get_identifier ("java.lang.Cloneable");
801 java_io_serializable_identifier_node
=
802 get_identifier ("java.io.Serializable");
804 /* for lack of a better place to put this stub call */
805 init_expr_processing();
807 constants_type_node
= make_node (RECORD_TYPE
);
808 PUSH_FIELD (input_location
,
809 constants_type_node
, field
, "size", unsigned_int_type_node
);
810 PUSH_FIELD (input_location
,
811 constants_type_node
, field
, "tags", ptr_type_node
);
812 PUSH_FIELD (input_location
,
813 constants_type_node
, field
, "data", ptr_type_node
);
814 constants_data_field_decl_node
= field
;
815 FINISH_RECORD (constants_type_node
);
816 build_decl (BUILTINS_LOCATION
,
817 TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
819 access_flags_type_node
= unsigned_short_type_node
;
821 dtable_type
= make_node (RECORD_TYPE
);
822 dtable_ptr_type
= build_pointer_type (dtable_type
);
824 otable_type
= build_array_type (integer_type_node
,
825 one_elt_array_domain_type
);
826 TYPE_NONALIASED_COMPONENT (otable_type
) = 1;
827 otable_ptr_type
= build_pointer_type (otable_type
);
829 PUSH_FIELD (input_location
,
830 object_type_node
, field
, "vtable", dtable_ptr_type
);
831 DECL_FCONTEXT (field
) = object_type_node
;
832 TYPE_VFIELD (object_type_node
) = field
;
834 /* This isn't exactly true, but it is what we have in the source.
835 There is an unresolved issue here, which is whether the vtable
836 should be marked by the GC. */
837 if (! flag_hash_synchronization
)
838 PUSH_FIELD (input_location
, object_type_node
, field
, "sync_info",
839 build_pointer_type (object_type_node
));
840 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
841 FIELD_PRIVATE (t
) = 1;
842 FINISH_RECORD (object_type_node
);
844 field_type_node
= make_node (RECORD_TYPE
);
845 field_ptr_type_node
= build_pointer_type (field_type_node
);
846 method_type_node
= make_node (RECORD_TYPE
);
847 method_ptr_type_node
= build_pointer_type (method_type_node
);
849 set_super_info (0, class_type_node
, object_type_node
, 0);
850 set_super_info (0, string_type_node
, object_type_node
, 0);
851 class_ptr_type
= build_pointer_type (class_type_node
);
853 PUSH_FIELD (input_location
,
854 class_type_node
, field
, "next_or_version", class_ptr_type
);
855 PUSH_FIELD (input_location
,
856 class_type_node
, field
, "name", utf8const_ptr_type
);
857 PUSH_FIELD (input_location
,
858 class_type_node
, field
, "accflags", access_flags_type_node
);
859 PUSH_FIELD (input_location
,
860 class_type_node
, field
, "superclass", class_ptr_type
);
861 PUSH_FIELD (input_location
,
862 class_type_node
, field
, "constants", constants_type_node
);
863 constants_field_decl_node
= field
;
864 PUSH_FIELD (input_location
,
865 class_type_node
, field
, "methods", method_ptr_type_node
);
866 PUSH_FIELD (input_location
,
867 class_type_node
, field
, "method_count", short_type_node
);
868 PUSH_FIELD (input_location
,
869 class_type_node
, field
, "vtable_method_count", short_type_node
);
870 PUSH_FIELD (input_location
,
871 class_type_node
, field
, "fields", field_ptr_type_node
);
872 PUSH_FIELD (input_location
,
873 class_type_node
, field
, "size_in_bytes", int_type_node
);
874 PUSH_FIELD (input_location
,
875 class_type_node
, field
, "field_count", short_type_node
);
876 PUSH_FIELD (input_location
,
877 class_type_node
, field
, "static_field_count", short_type_node
);
878 PUSH_FIELD (input_location
,
879 class_type_node
, field
, "vtable", dtable_ptr_type
);
880 PUSH_FIELD (input_location
,
881 class_type_node
, field
, "otable", otable_ptr_type
);
882 PUSH_FIELD (input_location
,
883 class_type_node
, field
, "otable_syms",
884 symbols_array_ptr_type
);
885 PUSH_FIELD (input_location
,
886 class_type_node
, field
, "atable", atable_ptr_type
);
887 PUSH_FIELD (input_location
,
888 class_type_node
, field
, "atable_syms",
889 symbols_array_ptr_type
);
890 PUSH_FIELD (input_location
,
891 class_type_node
, field
, "itable", itable_ptr_type
);
892 PUSH_FIELD (input_location
, class_type_node
, field
, "itable_syms",
893 symbols_array_ptr_type
);
894 PUSH_FIELD (input_location
,
895 class_type_node
, field
, "catch_classes", ptr_type_node
);
896 PUSH_FIELD (input_location
, class_type_node
, field
, "interfaces",
897 build_pointer_type (class_ptr_type
));
898 PUSH_FIELD (input_location
, class_type_node
, field
, "loader", ptr_type_node
);
899 PUSH_FIELD (input_location
,
900 class_type_node
, field
, "interface_count", short_type_node
);
901 PUSH_FIELD (input_location
, class_type_node
, field
, "state", byte_type_node
);
902 PUSH_FIELD (input_location
, class_type_node
, field
, "thread", ptr_type_node
);
903 PUSH_FIELD (input_location
,
904 class_type_node
, field
, "depth", short_type_node
);
905 PUSH_FIELD (input_location
,
906 class_type_node
, field
, "ancestors", ptr_type_node
);
907 PUSH_FIELD (input_location
, class_type_node
, field
, "idt", ptr_type_node
);
908 PUSH_FIELD (input_location
,
909 class_type_node
, field
, "arrayclass", ptr_type_node
);
910 PUSH_FIELD (input_location
,
911 class_type_node
, field
, "protectionDomain", ptr_type_node
);
912 PUSH_FIELD (input_location
,
913 class_type_node
, field
, "assertion_table", ptr_type_node
);
914 PUSH_FIELD (input_location
,
915 class_type_node
, field
, "hack_signers", ptr_type_node
);
916 PUSH_FIELD (input_location
, class_type_node
, field
, "chain", ptr_type_node
);
917 PUSH_FIELD (input_location
,
918 class_type_node
, field
, "aux_info", ptr_type_node
);
919 PUSH_FIELD (input_location
, class_type_node
, field
, "engine", ptr_type_node
);
920 PUSH_FIELD (input_location
,
921 class_type_node
, field
, "reflection_data", ptr_type_node
);
922 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
923 FIELD_PRIVATE (t
) = 1;
924 push_super_field (class_type_node
, object_type_node
);
926 FINISH_RECORD (class_type_node
);
927 build_decl (BUILTINS_LOCATION
,
928 TYPE_DECL
, get_identifier ("Class"), class_type_node
);
930 field_info_union_node
= make_node (UNION_TYPE
);
931 PUSH_FIELD (input_location
,
932 field_info_union_node
, field
, "boffset", int_type_node
);
933 PUSH_FIELD (input_location
,
934 field_info_union_node
, field
, "addr", ptr_type_node
);
935 layout_type (field_info_union_node
);
937 PUSH_FIELD (input_location
,
938 field_type_node
, field
, "name", utf8const_ptr_type
);
939 PUSH_FIELD (input_location
, field_type_node
, field
, "type", class_ptr_type
);
940 PUSH_FIELD (input_location
,
941 field_type_node
, field
, "accflags", access_flags_type_node
);
942 PUSH_FIELD (input_location
,
943 field_type_node
, field
, "bsize", unsigned_short_type_node
);
944 PUSH_FIELD (input_location
,
945 field_type_node
, field
, "info", field_info_union_node
);
946 FINISH_RECORD (field_type_node
);
947 build_decl (BUILTINS_LOCATION
,
948 TYPE_DECL
, get_identifier ("Field"), field_type_node
);
950 nativecode_ptr_array_type_node
951 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
953 PUSH_FIELD (input_location
,
954 dtable_type
, field
, "class", class_ptr_type
);
955 PUSH_FIELD (input_location
,
956 dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
957 FINISH_RECORD (dtable_type
);
958 build_decl (BUILTINS_LOCATION
,
959 TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
961 jexception_type
= make_node (RECORD_TYPE
);
962 PUSH_FIELD (input_location
,
963 jexception_type
, field
, "start_pc", ptr_type_node
);
964 PUSH_FIELD (input_location
, jexception_type
, field
, "end_pc", ptr_type_node
);
965 PUSH_FIELD (input_location
,
966 jexception_type
, field
, "handler_pc", ptr_type_node
);
967 PUSH_FIELD (input_location
,
968 jexception_type
, field
, "catch_type", class_ptr_type
);
969 FINISH_RECORD (jexception_type
);
970 build_decl (BUILTINS_LOCATION
,
971 TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
972 jexception_ptr_type
= build_pointer_type (jexception_type
);
974 lineNumberEntry_type
= make_node (RECORD_TYPE
);
975 PUSH_FIELD (input_location
,
976 lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
977 PUSH_FIELD (input_location
,
978 lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
979 FINISH_RECORD (lineNumberEntry_type
);
981 lineNumbers_type
= make_node (RECORD_TYPE
);
982 PUSH_FIELD (input_location
,
983 lineNumbers_type
, field
, "length", unsigned_int_type_node
);
984 FINISH_RECORD (lineNumbers_type
);
986 PUSH_FIELD (input_location
,
987 method_type_node
, field
, "name", utf8const_ptr_type
);
988 PUSH_FIELD (input_location
,
989 method_type_node
, field
, "signature", utf8const_ptr_type
);
990 PUSH_FIELD (input_location
,
991 method_type_node
, field
, "accflags", access_flags_type_node
);
992 PUSH_FIELD (input_location
,
993 method_type_node
, field
, "index", unsigned_short_type_node
);
994 PUSH_FIELD (input_location
,
995 method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
996 PUSH_FIELD (input_location
,
997 method_type_node
, field
, "throws", ptr_type_node
);
998 FINISH_RECORD (method_type_node
);
999 build_decl (BUILTINS_LOCATION
,
1000 TYPE_DECL
, get_identifier ("Method"), method_type_node
);
1002 endlink
= end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
1004 t
= tree_cons (NULL_TREE
, class_ptr_type
, endlink
);
1005 alloc_object_node
= add_builtin_function ("_Jv_AllocObject",
1006 build_function_type (ptr_type_node
, t
),
1007 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1008 DECL_IS_MALLOC (alloc_object_node
) = 1;
1009 alloc_no_finalizer_node
=
1010 add_builtin_function ("_Jv_AllocObjectNoFinalizer",
1011 build_function_type (ptr_type_node
, t
),
1012 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1013 DECL_IS_MALLOC (alloc_no_finalizer_node
) = 1;
1015 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
1016 soft_initclass_node
= add_builtin_function ("_Jv_InitClass",
1017 build_function_type (void_type_node
,
1019 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1020 t
= tree_cons (NULL_TREE
, class_ptr_type
,
1021 tree_cons (NULL_TREE
, int_type_node
, endlink
));
1022 soft_resolvepoolentry_node
1023 = add_builtin_function ("_Jv_ResolvePoolEntry",
1024 build_function_type (ptr_type_node
, t
),
1025 0,NOT_BUILT_IN
, NULL
, NULL_TREE
);
1026 DECL_PURE_P (soft_resolvepoolentry_node
) = 1;
1027 throw_node
= add_builtin_function ("_Jv_Throw",
1028 build_function_type (void_type_node
, t
),
1029 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1030 /* Mark throw_nodes as `noreturn' functions with side effects. */
1031 TREE_THIS_VOLATILE (throw_node
) = 1;
1032 TREE_SIDE_EFFECTS (throw_node
) = 1;
1034 t
= build_function_type (void_type_node
, tree_cons (NULL_TREE
, ptr_type_node
,
1036 soft_monitorenter_node
1037 = add_builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
1039 soft_monitorexit_node
1040 = add_builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
1043 t
= tree_cons (NULL_TREE
, ptr_type_node
,
1044 tree_cons (NULL_TREE
, int_type_node
, endlink
));
1046 = add_builtin_function ("_Jv_NewPrimArray",
1047 build_function_type (ptr_type_node
, t
),
1048 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1049 DECL_IS_MALLOC (soft_newarray_node
) = 1;
1051 t
= tree_cons (NULL_TREE
, int_type_node
,
1052 tree_cons (NULL_TREE
, class_ptr_type
,
1053 tree_cons (NULL_TREE
, object_ptr_type_node
,
1056 = add_builtin_function ("_Jv_NewObjectArray",
1057 build_function_type (ptr_type_node
, t
),
1058 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1059 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
1061 /* There is no endlink here because _Jv_NewMultiArray is a varargs
1063 t
= tree_cons (NULL_TREE
, ptr_type_node
,
1064 tree_cons (NULL_TREE
, int_type_node
, NULL_TREE
));
1065 soft_multianewarray_node
1066 = add_builtin_function ("_Jv_NewMultiArray",
1067 build_function_type (ptr_type_node
, t
),
1068 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1069 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
1071 t
= build_function_type (void_type_node
,
1072 tree_cons (NULL_TREE
, int_type_node
, endlink
));
1073 soft_badarrayindex_node
1074 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t
,
1075 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1076 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1078 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
1079 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
1081 soft_nullpointer_node
1082 = add_builtin_function ("_Jv_ThrowNullPointerException",
1083 build_function_type (void_type_node
, endlink
),
1084 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1085 /* Mark soft_nullpointer_node as a `noreturn' function with side
1087 TREE_THIS_VOLATILE (soft_nullpointer_node
) = 1;
1088 TREE_SIDE_EFFECTS (soft_nullpointer_node
) = 1;
1090 soft_abstractmethod_node
1091 = add_builtin_function ("_Jv_ThrowAbstractMethodError",
1092 build_function_type (void_type_node
, endlink
),
1093 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1094 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1096 TREE_THIS_VOLATILE (soft_abstractmethod_node
) = 1;
1097 TREE_SIDE_EFFECTS (soft_abstractmethod_node
) = 1;
1099 soft_nosuchfield_node
1100 = add_builtin_function ("_Jv_ThrowNoSuchFieldError",
1101 build_function_type (void_type_node
, endlink
),
1102 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1103 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1105 TREE_THIS_VOLATILE (soft_nosuchfield_node
) = 1;
1106 TREE_SIDE_EFFECTS (soft_nosuchfield_node
) = 1;
1108 t
= tree_cons (NULL_TREE
, class_ptr_type
,
1109 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
1111 = add_builtin_function ("_Jv_CheckCast",
1112 build_function_type (ptr_type_node
, t
),
1113 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1114 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
1115 tree_cons (NULL_TREE
, class_ptr_type
, endlink
));
1116 soft_instanceof_node
1117 = add_builtin_function ("_Jv_IsInstanceOf",
1118 build_function_type (boolean_type_node
, t
),
1119 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1120 DECL_PURE_P (soft_instanceof_node
) = 1;
1121 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
1122 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
1123 soft_checkarraystore_node
1124 = add_builtin_function ("_Jv_CheckArrayStore",
1125 build_function_type (void_type_node
, t
),
1126 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1127 t
= tree_cons (NULL_TREE
, ptr_type_node
,
1128 tree_cons (NULL_TREE
, ptr_type_node
,
1129 tree_cons (NULL_TREE
, int_type_node
, endlink
)));
1130 soft_lookupinterfacemethod_node
1131 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx",
1132 build_function_type (ptr_type_node
, t
),
1133 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1134 DECL_PURE_P (soft_lookupinterfacemethod_node
) = 1;
1135 t
= tree_cons (NULL_TREE
, ptr_type_node
,
1136 tree_cons (NULL_TREE
, ptr_type_node
,
1137 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)));
1138 soft_lookupinterfacemethodbyname_node
1139 = add_builtin_function ("_Jv_LookupInterfaceMethod",
1140 build_function_type (ptr_type_node
, t
),
1141 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1142 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
1143 tree_cons (NULL_TREE
, ptr_type_node
,
1144 tree_cons (NULL_TREE
, ptr_type_node
,
1145 tree_cons (NULL_TREE
, int_type_node
,
1147 soft_lookupjnimethod_node
1148 = add_builtin_function ("_Jv_LookupJNIMethod",
1149 build_function_type (ptr_type_node
, t
),
1150 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1151 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
1152 soft_getjnienvnewframe_node
1153 = add_builtin_function ("_Jv_GetJNIEnvNewFrame",
1154 build_function_type (ptr_type_node
, t
),
1155 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1156 soft_jnipopsystemframe_node
1157 = add_builtin_function ("_Jv_JNI_PopSystemFrame",
1158 build_function_type (void_type_node
, t
),
1159 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1161 t
= tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
);
1163 = add_builtin_function ("_Jv_UnwrapJNIweakReference",
1164 build_function_type (object_ptr_type_node
, t
),
1165 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1167 t
= tree_cons (NULL_TREE
, int_type_node
,
1168 tree_cons (NULL_TREE
, int_type_node
, endlink
));
1170 = add_builtin_function ("_Jv_divI",
1171 build_function_type (int_type_node
, t
),
1172 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1175 = add_builtin_function ("_Jv_remI",
1176 build_function_type (int_type_node
, t
),
1177 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1179 t
= tree_cons (NULL_TREE
, long_type_node
,
1180 tree_cons (NULL_TREE
, long_type_node
, endlink
));
1182 = add_builtin_function ("_Jv_divJ",
1183 build_function_type (long_type_node
, t
),
1184 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1187 = add_builtin_function ("_Jv_remJ",
1188 build_function_type (long_type_node
, t
),
1189 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1191 /* Initialize variables for except.c. */
1193 if (targetm
.arm_eabi_unwinder
)
1194 unwind_resume_libfunc
= init_one_libfunc ("__cxa_end_cleanup");
1196 default_init_unwind_resume_libfunc ();
1198 initialize_builtins ();
1199 soft_fmod_node
= built_in_decls
[BUILT_IN_FMOD
];
1205 /* Look up NAME in the current binding level and its superiors
1206 in the namespace of variables, functions and typedefs.
1207 Return a ..._DECL node of some kind representing its definition,
1208 or return 0 if it is undefined. */
1211 lookup_name (tree name
)
1214 if (current_binding_level
!= global_binding_level
1215 && IDENTIFIER_LOCAL_VALUE (name
))
1216 val
= IDENTIFIER_LOCAL_VALUE (name
);
1218 val
= IDENTIFIER_GLOBAL_VALUE (name
);
1222 /* Similar to `lookup_name' but look only at current binding level and
1223 the previous one if it's the parameter level. */
1226 lookup_name_current_level (tree name
)
1230 if (current_binding_level
== global_binding_level
)
1231 return IDENTIFIER_GLOBAL_VALUE (name
);
1233 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
1236 for (t
= current_binding_level
->names
; t
; t
= TREE_CHAIN (t
))
1237 if (DECL_NAME (t
) == name
)
1243 /* Record a decl-node X as belonging to the current lexical scope.
1244 Check for errors (such as an incompatible declaration for the same
1245 name already seen in the same scope).
1247 Returns either X or an old decl for the same name.
1248 If an old decl is returned, it may have been smashed
1249 to agree with what X says. */
1255 tree name
= DECL_NAME (x
);
1256 struct binding_level
*b
= current_binding_level
;
1258 if (TREE_CODE (x
) != TYPE_DECL
)
1259 DECL_CONTEXT (x
) = current_function_decl
;
1262 t
= lookup_name_current_level (name
);
1263 if (t
!= 0 && t
== error_mark_node
)
1264 /* error_mark_node is 0 for a while during initialization! */
1267 error ("%q+D used prior to declaration", x
);
1270 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1271 to point to the TYPE_DECL.
1272 Since Java does not have typedefs, a type can only have
1273 one (true) name, given by a class, interface, or builtin. */
1274 if (TREE_CODE (x
) == TYPE_DECL
1275 && TYPE_NAME (TREE_TYPE (x
)) == 0
1276 && TREE_TYPE (x
) != error_mark_node
)
1278 TYPE_NAME (TREE_TYPE (x
)) = x
;
1279 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1282 /* This name is new in its binding level.
1283 Install the new declaration and return it. */
1284 if (b
== global_binding_level
)
1286 /* Install a global value. */
1288 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1292 /* Here to install a non-global value. */
1293 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1294 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1296 /* If storing a local value, there may already be one (inherited).
1297 If so, record it for restoration when this binding level ends. */
1299 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1303 /* Put decls on list in reverse order.
1304 We will reverse them later if necessary. */
1305 TREE_CHAIN (x
) = b
->names
;
1312 pushdecl_force_head (tree x
)
1314 current_binding_level
->names
= x
;
1317 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1320 pushdecl_top_level (tree x
)
1323 struct binding_level
*b
= current_binding_level
;
1325 current_binding_level
= global_binding_level
;
1327 current_binding_level
= b
;
1331 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1334 pushdecl_function_level (tree x
)
1337 struct binding_level
*b
= current_binding_level
;
1339 current_binding_level
= function_binding_level
;
1341 current_binding_level
= b
;
1345 /* Nonzero if we are currently in the global binding level. */
1348 global_bindings_p (void)
1350 return current_binding_level
== global_binding_level
;
1353 /* Return the list of declarations of the current level.
1354 Note that this list is in reverse order unless/until
1355 you nreverse it; and when you do nreverse it, you must
1356 store the result back using `storedecls' or you will lose. */
1361 return current_binding_level
->names
;
1364 /* Create a new `struct binding_level'. */
1366 static struct binding_level
*
1367 make_binding_level (void)
1370 return GGC_CNEW (struct binding_level
);
1374 pushlevel (int unused ATTRIBUTE_UNUSED
)
1376 struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1378 /* Reuse or create a struct for this binding level. */
1380 if (free_binding_level
)
1382 newlevel
= free_binding_level
;
1383 free_binding_level
= free_binding_level
->level_chain
;
1387 newlevel
= make_binding_level ();
1390 /* Add this level to the front of the chain (stack) of levels that
1393 *newlevel
= clear_binding_level
;
1394 newlevel
->level_chain
= current_binding_level
;
1395 newlevel
->loc
= input_location
;
1396 current_binding_level
= newlevel
;
1397 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1398 newlevel
->binding_depth
= binding_depth
;
1400 fprintf (stderr
, "push %s level %p pc %d\n",
1401 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1404 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1407 /* Exit a binding level.
1408 Pop the level off, and restore the state of the identifier-decl mappings
1409 that were in effect when this level was entered.
1411 If KEEP is nonzero, this level had explicit declarations, so
1412 and create a "block" (a BLOCK node) for the level
1413 to record its declarations and subblocks for symbol table output.
1415 If FUNCTIONBODY is nonzero, this level is the body of a function,
1416 so create a block as if KEEP were set and also clear out all
1419 If REVERSE is nonzero, reverse the order of decls before putting
1420 them into the BLOCK. */
1423 poplevel (int keep
, int reverse
, int functionbody
)
1426 /* The chain of decls was accumulated in reverse order.
1427 Put it into forward order, just for cleanliness. */
1429 tree subblocks
= current_binding_level
->blocks
;
1434 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1437 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1438 fprintf (stderr
, "pop %s level %p pc %d (end pc %d)\n",
1439 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1440 current_binding_level
->end_pc
);
1442 fprintf (stderr
, "pop %s level %p pc %d\n",
1443 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1444 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1446 /* Get the decls in the order they were written.
1447 Usually current_binding_level->names is in reverse order.
1448 But parameter decls were previously put in forward order. */
1451 current_binding_level
->names
1452 = decls
= nreverse (current_binding_level
->names
);
1454 decls
= current_binding_level
->names
;
1456 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1457 if (TREE_CODE (decl
) == VAR_DECL
1458 && DECL_LANG_SPECIFIC (decl
) != NULL
1459 && DECL_LOCAL_SLOT_NUMBER (decl
))
1460 LOCAL_VAR_OUT_OF_SCOPE_P (decl
) = 1;
1462 /* If there were any declarations in that level,
1463 or if this level is a function body,
1464 create a BLOCK to record them for the life of this function. */
1467 if (keep
|| functionbody
)
1469 block
= make_node (BLOCK
);
1470 TREE_TYPE (block
) = void_type_node
;
1473 if (current_binding_level
->exception_range
)
1474 expand_end_java_handler (current_binding_level
->exception_range
);
1478 /* If any statements have been generated at this level, create a
1479 BIND_EXPR to hold them and copy the variables to it. This
1480 only applies to the bytecode compiler. */
1481 if (current_binding_level
->stmts
)
1484 tree
*var
= &BLOCK_VARS (block
);
1486 /* Copy decls from names list, ignoring labels. */
1489 tree next
= TREE_CHAIN (decl
);
1490 if (TREE_CODE (decl
) != LABEL_DECL
)
1493 var
= &TREE_CHAIN (decl
);
1499 bind
= build3 (BIND_EXPR
, TREE_TYPE (block
), BLOCK_VARS (block
),
1500 BLOCK_EXPR_BODY (block
), block
);
1501 BIND_EXPR_BODY (bind
) = current_binding_level
->stmts
;
1503 if (BIND_EXPR_BODY (bind
)
1504 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind
)))
1505 TREE_SIDE_EFFECTS (bind
) = 1;
1507 /* FIXME: gimplifier brain damage. */
1508 if (BIND_EXPR_BODY (bind
) == NULL
)
1509 BIND_EXPR_BODY (bind
) = build_java_empty_stmt ();
1511 SET_EXPR_LOCATION (bind
, current_binding_level
->loc
);
1513 current_binding_level
->stmts
= NULL
;
1517 BLOCK_VARS (block
) = decls
;
1519 BLOCK_SUBBLOCKS (block
) = subblocks
;
1522 /* In each subblock, record that this is its superior. */
1524 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1525 BLOCK_SUPERCONTEXT (link
) = block
;
1527 /* Clear out the meanings of the local variables of this level. */
1529 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1531 tree name
= DECL_NAME (link
);
1532 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1534 /* If the ident. was used or addressed via a local extern decl,
1535 don't forget that fact. */
1536 if (DECL_EXTERNAL (link
))
1538 if (TREE_USED (link
))
1539 TREE_USED (name
) = 1;
1540 if (TREE_ADDRESSABLE (link
))
1541 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1543 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1547 /* Restore all name-meanings of the outer levels
1548 that were shadowed by this level. */
1550 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1551 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1553 /* If the level being exited is the top level of a function,
1554 check over all the labels, and clear out the current
1555 (function local) meanings of their names. */
1559 /* If this is the top level block of a function,
1560 the vars are the function's parameters.
1561 Don't leave them in the BLOCK because they are
1562 found in the FUNCTION_DECL instead. */
1564 BLOCK_VARS (block
) = 0;
1567 /* Pop the current level, and free the structure for reuse. */
1570 struct binding_level
*level
= current_binding_level
;
1571 current_binding_level
= current_binding_level
->level_chain
;
1573 level
->level_chain
= free_binding_level
;
1574 free_binding_level
= level
;
1577 /* Dispose of the block that we just made inside some higher level. */
1580 DECL_INITIAL (current_function_decl
) = block
;
1581 DECL_SAVED_TREE (current_function_decl
) = bind
;
1587 current_binding_level
->blocks
1588 = chainon (current_binding_level
->blocks
, block
);
1590 /* If we did not make a block for the level just exited,
1591 any blocks made for inner levels
1592 (since they cannot be recorded as subblocks in that level)
1593 must be carried forward so they will later become subblocks
1594 of something else. */
1596 current_binding_level
->blocks
1597 = chainon (current_binding_level
->blocks
, subblocks
);
1600 java_add_stmt (bind
);
1604 TREE_USED (block
) = 1;
1609 maybe_pushlevels (int pc
)
1611 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1615 while (pending_local_decls
!= NULL_TREE
&&
1616 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1618 tree
*ptr
= &pending_local_decls
;
1619 tree decl
= *ptr
, next
;
1620 int end_pc
= DECL_LOCAL_END_PC (decl
);
1622 while (*ptr
!= NULL_TREE
1623 && DECL_LOCAL_START_PC (*ptr
) <= pc
1624 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1625 ptr
= &TREE_CHAIN (*ptr
);
1626 pending_local_decls
= *ptr
;
1629 /* Force non-nested range to be nested in current range by
1630 truncating variable lifetimes. */
1631 if (end_pc
> current_binding_level
->end_pc
)
1634 end_pc
= current_binding_level
->end_pc
;
1635 for (t
= decl
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1636 DECL_LOCAL_END_PC (t
) = end_pc
;
1639 maybe_start_try (pc
, end_pc
);
1643 current_binding_level
->end_pc
= end_pc
;
1644 current_binding_level
->start_pc
= pc
;
1645 current_binding_level
->names
= NULL
;
1646 for ( ; decl
!= NULL_TREE
; decl
= next
)
1648 int index
= DECL_LOCAL_SLOT_NUMBER (decl
);
1650 next
= TREE_CHAIN (decl
);
1651 push_jvm_slot (index
, decl
);
1654 = find_local_variable (index
, TREE_TYPE (decl
), pc
);
1655 if (TREE_CODE (TREE_TYPE (base_decl
)) == POINTER_TYPE
)
1656 base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
1657 SET_DECL_VALUE_EXPR (decl
, base_decl
);
1658 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1662 maybe_start_try (pc
, 0);
1666 maybe_poplevels (int pc
)
1668 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1672 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1673 inclusive, so a variable is live if pc == end_pc. Here, we
1674 terminate a range if the current pc is equal to the end of the
1675 range, and this is *before* we have generated code for the
1676 instruction at end_pc. We're closing a binding level one
1677 instruction too early.*/
1678 while (current_binding_level
->end_pc
<= pc
)
1682 /* Terminate any binding which began during the range beginning at
1683 start_pc. This tidies up improperly nested local variable ranges
1684 and exception handlers; a variable declared within an exception
1685 range is forcibly terminated when that exception ends. */
1688 force_poplevels (int start_pc
)
1690 while (current_binding_level
->start_pc
> start_pc
)
1692 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1693 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1694 current_function_decl
,
1695 current_binding_level
->start_pc
);
1700 /* integrate_decl_tree calls this function. */
1703 java_dup_lang_specific_decl (tree node
)
1706 struct lang_decl
*x
;
1708 if (!DECL_LANG_SPECIFIC (node
))
1711 lang_decl_size
= sizeof (struct lang_decl
);
1712 x
= GGC_NEW (struct lang_decl
);
1713 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1714 DECL_LANG_SPECIFIC (node
) = x
;
1718 give_name_to_locals (JCF
*jcf
)
1720 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1721 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1723 pending_local_decls
= NULL_TREE
;
1727 n
= JCF_readu2 (jcf
);
1728 for (i
= 0; i
< n
; i
++)
1730 int start_pc
= JCF_readu2 (jcf
);
1731 int length
= JCF_readu2 (jcf
);
1732 int name_index
= JCF_readu2 (jcf
);
1733 int signature_index
= JCF_readu2 (jcf
);
1734 int slot
= JCF_readu2 (jcf
);
1735 tree name
= get_name_constant (jcf
, name_index
);
1736 tree type
= parse_signature (jcf
, signature_index
);
1737 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1739 && length
== DECL_CODE_LENGTH (current_function_decl
))
1741 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1742 DECL_NAME (decl
) = name
;
1743 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1744 warning (0, "bad type in parameter debug info");
1749 int end_pc
= start_pc
+ length
;
1750 tree decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
1751 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1753 warning (0, "bad PC range for debug info for local %q+D",
1755 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1758 /* Adjust start_pc if necessary so that the local's first
1759 store operation will use the relevant DECL as a
1760 destination. Fore more information, read the leading
1761 comments for expr.c:maybe_adjust_start_pc. */
1762 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1764 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1765 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1766 DECL_LOCAL_START_PC (decl
) = start_pc
;
1767 DECL_LOCAL_END_PC (decl
) = end_pc
;
1769 /* Now insert the new decl in the proper place in
1770 pending_local_decls. We are essentially doing an insertion sort,
1771 which works fine, since the list input will normally already
1773 ptr
= &pending_local_decls
;
1774 while (*ptr
!= NULL_TREE
1775 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1776 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1777 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1778 ptr
= &TREE_CHAIN (*ptr
);
1779 TREE_CHAIN (decl
) = *ptr
;
1784 pending_local_decls
= nreverse (pending_local_decls
);
1786 /* Fill in default names for the parameters. */
1787 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1788 parm
!= NULL_TREE
; parm
= TREE_CHAIN (parm
), i
++)
1790 if (DECL_NAME (parm
) == NULL_TREE
)
1792 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1794 DECL_NAME (parm
) = get_identifier ("this");
1798 sprintf (buffer
, "ARG_%d", arg_i
);
1799 DECL_NAME (parm
) = get_identifier (buffer
);
1806 build_result_decl (tree fndecl
)
1808 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1809 tree result
= DECL_RESULT (fndecl
);
1812 result
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
1813 RESULT_DECL
, NULL_TREE
, restype
);
1814 DECL_ARTIFICIAL (result
) = 1;
1815 DECL_IGNORED_P (result
) = 1;
1816 DECL_CONTEXT (result
) = fndecl
;
1817 DECL_RESULT (fndecl
) = result
;
1823 start_java_method (tree fndecl
)
1830 current_function_decl
= fndecl
;
1831 announce_function (fndecl
);
1833 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1834 decl_map
= make_tree_vec (i
);
1835 base_decl_map
= make_tree_vec (i
);
1836 type_map
= XRESIZEVEC (tree
, type_map
, i
);
1838 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1839 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1841 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1842 pushlevel (1); /* Push parameters. */
1844 ptr
= &DECL_ARGUMENTS (fndecl
);
1845 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1846 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1848 tree parm_name
= NULL_TREE
, parm_decl
;
1849 tree parm_type
= TREE_VALUE (tem
);
1850 gcc_assert (i
< DECL_MAX_LOCALS (fndecl
));
1852 parm_decl
= build_decl (input_location
, PARM_DECL
, parm_name
, parm_type
);
1853 DECL_CONTEXT (parm_decl
) = fndecl
;
1854 if (targetm
.calls
.promote_prototypes (parm_type
)
1855 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1856 && INTEGRAL_TYPE_P (parm_type
))
1857 parm_type
= integer_type_node
;
1858 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1861 ptr
= &TREE_CHAIN (parm_decl
);
1863 /* Add parm_decl to the decl_map. */
1864 push_jvm_slot (i
, parm_decl
);
1866 type_map
[i
] = TREE_TYPE (parm_decl
);
1867 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1870 type_map
[i
] = void_type_node
;
1874 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1876 while (i
< DECL_MAX_LOCALS(fndecl
))
1877 type_map
[i
++] = NULL_TREE
;
1879 build_result_decl (fndecl
);
1880 DECL_SOURCE_LOCATION (fndecl
) = input_location
;
1882 /* Push local variables. */
1885 function_binding_level
= current_binding_level
;
1889 end_java_method (void)
1891 tree fndecl
= current_function_decl
;
1893 /* pop out of function */
1896 /* pop out of its parameters */
1899 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1901 if (DECL_SAVED_TREE (fndecl
))
1903 tree fbody
, block_body
;
1904 /* Before we check initialization, attached all class initialization
1905 variable to the block_body */
1906 fbody
= DECL_SAVED_TREE (fndecl
);
1907 block_body
= BIND_EXPR_BODY (fbody
);
1908 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl
),
1909 attach_init_test_initialization_flags
, block_body
);
1912 finish_method (fndecl
);
1914 current_function_decl
= NULL_TREE
;
1915 base_decl_map
= NULL_TREE
;
1918 /* Prepare a method for expansion. */
1921 finish_method (tree fndecl
)
1923 tree
*tp
= &DECL_SAVED_TREE (fndecl
);
1925 /* Wrap body of synchronized methods in a monitorenter,
1926 plus monitorexit cleanup. */
1927 if (METHOD_SYNCHRONIZED (fndecl
))
1929 tree enter
, exit
, lock
;
1930 if (METHOD_STATIC (fndecl
))
1931 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1933 lock
= DECL_ARGUMENTS (fndecl
);
1934 BUILD_MONITOR_ENTER (enter
, lock
);
1935 BUILD_MONITOR_EXIT (exit
, lock
);
1936 *tp
= build2 (COMPOUND_EXPR
, void_type_node
, enter
,
1937 build2 (TRY_FINALLY_EXPR
, void_type_node
, *tp
, exit
));
1940 /* Convert function tree to GENERIC prior to inlining. */
1941 java_genericize (fndecl
);
1943 /* Store the end of the function, so that we get good line number
1944 info for the epilogue. */
1945 if (DECL_STRUCT_FUNCTION (fndecl
))
1946 set_cfun (DECL_STRUCT_FUNCTION (fndecl
));
1948 allocate_struct_function (fndecl
, false);
1949 cfun
->function_end_locus
= DECL_FUNCTION_LAST_LINE (fndecl
);
1951 /* Defer inlining and expansion to the cgraph optimizers. */
1952 cgraph_finalize_function (fndecl
, false);
1955 /* We pessimistically marked all methods and fields external until we
1956 knew what set of classes we were planning to compile. Now mark those
1957 associated with CLASS to be generated locally as not external. */
1960 java_mark_decl_local (tree decl
)
1962 DECL_EXTERNAL (decl
) = 0;
1964 #ifdef ENABLE_CHECKING
1965 /* Double check that we didn't pass the function to the callgraph early. */
1966 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1967 gcc_assert (!cgraph_node (decl
)->local
.finalized
);
1969 gcc_assert (!DECL_RTL_SET_P (decl
));
1972 /* Given appropriate target support, G++ will emit hidden aliases for native
1973 methods. Using this hidden name is required for proper operation of
1974 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1975 proper target support, then mark the method for aliasing. */
1978 java_mark_cni_decl_local (tree decl
)
1980 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1984 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
1985 DECL_LOCAL_CNI_METHOD_P (decl
) = 1;
1987 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1988 mangler. We might have already referenced this native method and
1989 therefore created its name, but even if we have it won't hurt.
1990 We'll just go via its externally visible name, rather than its
1991 hidden alias. However, we must force things so that the correct
1992 mangling is done. */
1994 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
1995 java_mangle_decl (decl
);
1996 if (DECL_RTL_SET_P (decl
))
1998 SET_DECL_RTL (decl
, 0);
1999 make_decl_rtl (decl
);
2003 /* Use the preceding two functions and mark all members of the class. */
2006 java_mark_class_local (tree klass
)
2010 for (t
= TYPE_FIELDS (klass
); t
; t
= TREE_CHAIN (t
))
2011 if (FIELD_STATIC (t
))
2012 java_mark_decl_local (t
);
2014 for (t
= TYPE_METHODS (klass
); t
; t
= TREE_CHAIN (t
))
2015 if (!METHOD_ABSTRACT (t
))
2017 if (METHOD_NATIVE (t
) && !flag_jni
)
2018 java_mark_cni_decl_local (t
);
2020 java_mark_decl_local (t
);
2024 /* Add a statement to a compound_expr. */
2027 add_stmt_to_compound (tree existing
, tree type
, tree stmt
)
2033 tree expr
= build2 (COMPOUND_EXPR
, type
, existing
, stmt
);
2034 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (existing
)
2035 | TREE_SIDE_EFFECTS (stmt
);
2042 /* If this node is an expr, mark its input location. Called from
2046 set_input_location (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
2047 void *data ATTRIBUTE_UNUSED
)
2051 if (CAN_HAVE_LOCATION_P (t
))
2053 if (EXPR_HAS_LOCATION(t
))
2054 return t
; /* Don't walk any further into this expr. */
2056 SET_EXPR_LOCATION (t
, input_location
);
2059 return NULL_TREE
; /* Continue walking this expr. */
2062 /* Add a statement to the statement_list currently being constructed.
2063 If the statement_list is null, we don't create a singleton list.
2064 This is necessary because poplevel() assumes that adding a
2065 statement to a null statement_list returns the statement. */
2068 java_add_stmt (tree new_stmt
)
2070 tree stmts
= current_binding_level
->stmts
;
2071 tree_stmt_iterator i
;
2074 walk_tree (&new_stmt
, set_input_location
, NULL
, NULL
);
2077 return current_binding_level
->stmts
= new_stmt
;
2079 /* Force STMTS to be a statement_list. */
2080 if (TREE_CODE (stmts
) != STATEMENT_LIST
)
2082 tree t
= make_node (STATEMENT_LIST
);
2084 tsi_link_after (&i
, stmts
, TSI_CONTINUE_LINKING
);
2088 i
= tsi_last (stmts
);
2089 tsi_link_after (&i
, new_stmt
, TSI_CONTINUE_LINKING
);
2090 TREE_TYPE (stmts
) = void_type_node
;
2092 return current_binding_level
->stmts
= stmts
;
2095 /* Add a variable to the current scope. */
2098 java_add_local_var (tree decl
)
2100 tree
*vars
= ¤t_binding_level
->names
;
2102 TREE_CHAIN (decl
) = next
;
2104 DECL_CONTEXT (decl
) = current_function_decl
;
2105 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
2109 /* Return a pointer to the compound_expr currently being
2115 return ¤t_binding_level
->stmts
;
2118 /* Register an exception range as belonging to the current binding
2119 level. There may only be one: if there are more, we'll create more
2120 binding levels. However, each range can have multiple handlers,
2121 and these are expanded when we call expand_end_java_handler(). */
2124 register_exception_range (struct eh_range
*range
, int pc
, int end_pc
)
2126 gcc_assert (! current_binding_level
->exception_range
);
2127 current_binding_level
->exception_range
= range
;
2128 current_binding_level
->end_pc
= end_pc
;
2129 current_binding_level
->start_pc
= pc
;
2132 #include "gt-java-decl.h"