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, 2009 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_builtins ();
1193 soft_fmod_node
= built_in_decls
[BUILT_IN_FMOD
];
1199 /* Look up NAME in the current binding level and its superiors
1200 in the namespace of variables, functions and typedefs.
1201 Return a ..._DECL node of some kind representing its definition,
1202 or return 0 if it is undefined. */
1205 lookup_name (tree name
)
1208 if (current_binding_level
!= global_binding_level
1209 && IDENTIFIER_LOCAL_VALUE (name
))
1210 val
= IDENTIFIER_LOCAL_VALUE (name
);
1212 val
= IDENTIFIER_GLOBAL_VALUE (name
);
1216 /* Similar to `lookup_name' but look only at current binding level and
1217 the previous one if it's the parameter level. */
1220 lookup_name_current_level (tree name
)
1224 if (current_binding_level
== global_binding_level
)
1225 return IDENTIFIER_GLOBAL_VALUE (name
);
1227 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
1230 for (t
= current_binding_level
->names
; t
; t
= TREE_CHAIN (t
))
1231 if (DECL_NAME (t
) == name
)
1237 /* Record a decl-node X as belonging to the current lexical scope.
1238 Check for errors (such as an incompatible declaration for the same
1239 name already seen in the same scope).
1241 Returns either X or an old decl for the same name.
1242 If an old decl is returned, it may have been smashed
1243 to agree with what X says. */
1249 tree name
= DECL_NAME (x
);
1250 struct binding_level
*b
= current_binding_level
;
1252 if (TREE_CODE (x
) != TYPE_DECL
)
1253 DECL_CONTEXT (x
) = current_function_decl
;
1256 t
= lookup_name_current_level (name
);
1257 if (t
!= 0 && t
== error_mark_node
)
1258 /* error_mark_node is 0 for a while during initialization! */
1261 error ("%q+D used prior to declaration", x
);
1264 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1265 to point to the TYPE_DECL.
1266 Since Java does not have typedefs, a type can only have
1267 one (true) name, given by a class, interface, or builtin. */
1268 if (TREE_CODE (x
) == TYPE_DECL
1269 && TYPE_NAME (TREE_TYPE (x
)) == 0
1270 && TREE_TYPE (x
) != error_mark_node
)
1272 TYPE_NAME (TREE_TYPE (x
)) = x
;
1273 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1276 /* This name is new in its binding level.
1277 Install the new declaration and return it. */
1278 if (b
== global_binding_level
)
1280 /* Install a global value. */
1282 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1286 /* Here to install a non-global value. */
1287 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1288 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1290 /* If storing a local value, there may already be one (inherited).
1291 If so, record it for restoration when this binding level ends. */
1293 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1297 /* Put decls on list in reverse order.
1298 We will reverse them later if necessary. */
1299 TREE_CHAIN (x
) = b
->names
;
1306 pushdecl_force_head (tree x
)
1308 current_binding_level
->names
= x
;
1311 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1314 pushdecl_top_level (tree x
)
1317 struct binding_level
*b
= current_binding_level
;
1319 current_binding_level
= global_binding_level
;
1321 current_binding_level
= b
;
1325 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1328 pushdecl_function_level (tree x
)
1331 struct binding_level
*b
= current_binding_level
;
1333 current_binding_level
= function_binding_level
;
1335 current_binding_level
= b
;
1339 /* Nonzero if we are currently in the global binding level. */
1342 global_bindings_p (void)
1344 return current_binding_level
== global_binding_level
;
1347 /* Return the list of declarations of the current level.
1348 Note that this list is in reverse order unless/until
1349 you nreverse it; and when you do nreverse it, you must
1350 store the result back using `storedecls' or you will lose. */
1355 return current_binding_level
->names
;
1358 /* Create a new `struct binding_level'. */
1360 static struct binding_level
*
1361 make_binding_level (void)
1364 return GGC_CNEW (struct binding_level
);
1368 pushlevel (int unused ATTRIBUTE_UNUSED
)
1370 struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1372 /* Reuse or create a struct for this binding level. */
1374 if (free_binding_level
)
1376 newlevel
= free_binding_level
;
1377 free_binding_level
= free_binding_level
->level_chain
;
1381 newlevel
= make_binding_level ();
1384 /* Add this level to the front of the chain (stack) of levels that
1387 *newlevel
= clear_binding_level
;
1388 newlevel
->level_chain
= current_binding_level
;
1389 newlevel
->loc
= input_location
;
1390 current_binding_level
= newlevel
;
1391 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1392 newlevel
->binding_depth
= binding_depth
;
1394 fprintf (stderr
, "push %s level %p pc %d\n",
1395 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1398 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1401 /* Exit a binding level.
1402 Pop the level off, and restore the state of the identifier-decl mappings
1403 that were in effect when this level was entered.
1405 If KEEP is nonzero, this level had explicit declarations, so
1406 and create a "block" (a BLOCK node) for the level
1407 to record its declarations and subblocks for symbol table output.
1409 If FUNCTIONBODY is nonzero, this level is the body of a function,
1410 so create a block as if KEEP were set and also clear out all
1413 If REVERSE is nonzero, reverse the order of decls before putting
1414 them into the BLOCK. */
1417 poplevel (int keep
, int reverse
, int functionbody
)
1420 /* The chain of decls was accumulated in reverse order.
1421 Put it into forward order, just for cleanliness. */
1423 tree subblocks
= current_binding_level
->blocks
;
1428 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1431 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1432 fprintf (stderr
, "pop %s level %p pc %d (end pc %d)\n",
1433 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1434 current_binding_level
->end_pc
);
1436 fprintf (stderr
, "pop %s level %p pc %d\n",
1437 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1438 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1440 /* Get the decls in the order they were written.
1441 Usually current_binding_level->names is in reverse order.
1442 But parameter decls were previously put in forward order. */
1445 current_binding_level
->names
1446 = decls
= nreverse (current_binding_level
->names
);
1448 decls
= current_binding_level
->names
;
1450 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1451 if (TREE_CODE (decl
) == VAR_DECL
1452 && DECL_LANG_SPECIFIC (decl
) != NULL
1453 && DECL_LOCAL_SLOT_NUMBER (decl
))
1454 LOCAL_VAR_OUT_OF_SCOPE_P (decl
) = 1;
1456 /* If there were any declarations in that level,
1457 or if this level is a function body,
1458 create a BLOCK to record them for the life of this function. */
1461 if (keep
|| functionbody
)
1463 block
= make_node (BLOCK
);
1464 TREE_TYPE (block
) = void_type_node
;
1467 if (current_binding_level
->exception_range
)
1468 expand_end_java_handler (current_binding_level
->exception_range
);
1472 /* If any statements have been generated at this level, create a
1473 BIND_EXPR to hold them and copy the variables to it. This
1474 only applies to the bytecode compiler. */
1475 if (current_binding_level
->stmts
)
1478 tree
*var
= &BLOCK_VARS (block
);
1480 /* Copy decls from names list, ignoring labels. */
1483 tree next
= TREE_CHAIN (decl
);
1484 if (TREE_CODE (decl
) != LABEL_DECL
)
1487 var
= &TREE_CHAIN (decl
);
1493 bind
= build3 (BIND_EXPR
, TREE_TYPE (block
), BLOCK_VARS (block
),
1494 BLOCK_EXPR_BODY (block
), block
);
1495 BIND_EXPR_BODY (bind
) = current_binding_level
->stmts
;
1497 if (BIND_EXPR_BODY (bind
)
1498 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind
)))
1499 TREE_SIDE_EFFECTS (bind
) = 1;
1501 /* FIXME: gimplifier brain damage. */
1502 if (BIND_EXPR_BODY (bind
) == NULL
)
1503 BIND_EXPR_BODY (bind
) = build_java_empty_stmt ();
1505 SET_EXPR_LOCATION (bind
, current_binding_level
->loc
);
1507 current_binding_level
->stmts
= NULL
;
1511 BLOCK_VARS (block
) = decls
;
1513 BLOCK_SUBBLOCKS (block
) = subblocks
;
1516 /* In each subblock, record that this is its superior. */
1518 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1519 BLOCK_SUPERCONTEXT (link
) = block
;
1521 /* Clear out the meanings of the local variables of this level. */
1523 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1525 tree name
= DECL_NAME (link
);
1526 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1528 /* If the ident. was used or addressed via a local extern decl,
1529 don't forget that fact. */
1530 if (DECL_EXTERNAL (link
))
1532 if (TREE_USED (link
))
1533 TREE_USED (name
) = 1;
1534 if (TREE_ADDRESSABLE (link
))
1535 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1537 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1541 /* Restore all name-meanings of the outer levels
1542 that were shadowed by this level. */
1544 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1545 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1547 /* If the level being exited is the top level of a function,
1548 check over all the labels, and clear out the current
1549 (function local) meanings of their names. */
1553 /* If this is the top level block of a function,
1554 the vars are the function's parameters.
1555 Don't leave them in the BLOCK because they are
1556 found in the FUNCTION_DECL instead. */
1558 BLOCK_VARS (block
) = 0;
1561 /* Pop the current level, and free the structure for reuse. */
1564 struct binding_level
*level
= current_binding_level
;
1565 current_binding_level
= current_binding_level
->level_chain
;
1567 level
->level_chain
= free_binding_level
;
1568 free_binding_level
= level
;
1571 /* Dispose of the block that we just made inside some higher level. */
1574 DECL_INITIAL (current_function_decl
) = block
;
1575 DECL_SAVED_TREE (current_function_decl
) = bind
;
1581 current_binding_level
->blocks
1582 = chainon (current_binding_level
->blocks
, block
);
1584 /* If we did not make a block for the level just exited,
1585 any blocks made for inner levels
1586 (since they cannot be recorded as subblocks in that level)
1587 must be carried forward so they will later become subblocks
1588 of something else. */
1590 current_binding_level
->blocks
1591 = chainon (current_binding_level
->blocks
, subblocks
);
1594 java_add_stmt (bind
);
1598 TREE_USED (block
) = 1;
1603 maybe_pushlevels (int pc
)
1605 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1609 while (pending_local_decls
!= NULL_TREE
&&
1610 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1612 tree
*ptr
= &pending_local_decls
;
1613 tree decl
= *ptr
, next
;
1614 int end_pc
= DECL_LOCAL_END_PC (decl
);
1616 while (*ptr
!= NULL_TREE
1617 && DECL_LOCAL_START_PC (*ptr
) <= pc
1618 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1619 ptr
= &TREE_CHAIN (*ptr
);
1620 pending_local_decls
= *ptr
;
1623 /* Force non-nested range to be nested in current range by
1624 truncating variable lifetimes. */
1625 if (end_pc
> current_binding_level
->end_pc
)
1628 end_pc
= current_binding_level
->end_pc
;
1629 for (t
= decl
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
1630 DECL_LOCAL_END_PC (t
) = end_pc
;
1633 maybe_start_try (pc
, end_pc
);
1637 current_binding_level
->end_pc
= end_pc
;
1638 current_binding_level
->start_pc
= pc
;
1639 current_binding_level
->names
= NULL
;
1640 for ( ; decl
!= NULL_TREE
; decl
= next
)
1642 int index
= DECL_LOCAL_SLOT_NUMBER (decl
);
1644 next
= TREE_CHAIN (decl
);
1645 push_jvm_slot (index
, decl
);
1648 = find_local_variable (index
, TREE_TYPE (decl
), pc
);
1649 if (TREE_CODE (TREE_TYPE (base_decl
)) == POINTER_TYPE
)
1650 base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
1651 SET_DECL_VALUE_EXPR (decl
, base_decl
);
1652 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1656 maybe_start_try (pc
, 0);
1660 maybe_poplevels (int pc
)
1662 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1666 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1667 inclusive, so a variable is live if pc == end_pc. Here, we
1668 terminate a range if the current pc is equal to the end of the
1669 range, and this is *before* we have generated code for the
1670 instruction at end_pc. We're closing a binding level one
1671 instruction too early.*/
1672 while (current_binding_level
->end_pc
<= pc
)
1676 /* Terminate any binding which began during the range beginning at
1677 start_pc. This tidies up improperly nested local variable ranges
1678 and exception handlers; a variable declared within an exception
1679 range is forcibly terminated when that exception ends. */
1682 force_poplevels (int start_pc
)
1684 while (current_binding_level
->start_pc
> start_pc
)
1686 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1687 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1688 current_function_decl
,
1689 current_binding_level
->start_pc
);
1694 /* integrate_decl_tree calls this function. */
1697 java_dup_lang_specific_decl (tree node
)
1700 struct lang_decl
*x
;
1702 if (!DECL_LANG_SPECIFIC (node
))
1705 lang_decl_size
= sizeof (struct lang_decl
);
1706 x
= GGC_NEW (struct lang_decl
);
1707 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1708 DECL_LANG_SPECIFIC (node
) = x
;
1712 give_name_to_locals (JCF
*jcf
)
1714 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1715 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1717 pending_local_decls
= NULL_TREE
;
1721 n
= JCF_readu2 (jcf
);
1722 for (i
= 0; i
< n
; i
++)
1724 int start_pc
= JCF_readu2 (jcf
);
1725 int length
= JCF_readu2 (jcf
);
1726 int name_index
= JCF_readu2 (jcf
);
1727 int signature_index
= JCF_readu2 (jcf
);
1728 int slot
= JCF_readu2 (jcf
);
1729 tree name
= get_name_constant (jcf
, name_index
);
1730 tree type
= parse_signature (jcf
, signature_index
);
1731 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1733 && length
== DECL_CODE_LENGTH (current_function_decl
))
1735 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1736 DECL_NAME (decl
) = name
;
1737 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1738 warning (0, "bad type in parameter debug info");
1743 int end_pc
= start_pc
+ length
;
1744 tree decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
1745 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1747 warning (0, "bad PC range for debug info for local %q+D",
1749 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1752 /* Adjust start_pc if necessary so that the local's first
1753 store operation will use the relevant DECL as a
1754 destination. Fore more information, read the leading
1755 comments for expr.c:maybe_adjust_start_pc. */
1756 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1758 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1759 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1760 DECL_LOCAL_START_PC (decl
) = start_pc
;
1761 DECL_LOCAL_END_PC (decl
) = end_pc
;
1763 /* Now insert the new decl in the proper place in
1764 pending_local_decls. We are essentially doing an insertion sort,
1765 which works fine, since the list input will normally already
1767 ptr
= &pending_local_decls
;
1768 while (*ptr
!= NULL_TREE
1769 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1770 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1771 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1772 ptr
= &TREE_CHAIN (*ptr
);
1773 TREE_CHAIN (decl
) = *ptr
;
1778 pending_local_decls
= nreverse (pending_local_decls
);
1780 /* Fill in default names for the parameters. */
1781 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1782 parm
!= NULL_TREE
; parm
= TREE_CHAIN (parm
), i
++)
1784 if (DECL_NAME (parm
) == NULL_TREE
)
1786 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1788 DECL_NAME (parm
) = get_identifier ("this");
1792 sprintf (buffer
, "ARG_%d", arg_i
);
1793 DECL_NAME (parm
) = get_identifier (buffer
);
1800 build_result_decl (tree fndecl
)
1802 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1803 tree result
= DECL_RESULT (fndecl
);
1806 result
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
1807 RESULT_DECL
, NULL_TREE
, restype
);
1808 DECL_ARTIFICIAL (result
) = 1;
1809 DECL_IGNORED_P (result
) = 1;
1810 DECL_CONTEXT (result
) = fndecl
;
1811 DECL_RESULT (fndecl
) = result
;
1817 start_java_method (tree fndecl
)
1824 current_function_decl
= fndecl
;
1825 announce_function (fndecl
);
1827 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1828 decl_map
= make_tree_vec (i
);
1829 base_decl_map
= make_tree_vec (i
);
1830 type_map
= XRESIZEVEC (tree
, type_map
, i
);
1832 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1833 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1835 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1836 pushlevel (1); /* Push parameters. */
1838 ptr
= &DECL_ARGUMENTS (fndecl
);
1839 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1840 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1842 tree parm_name
= NULL_TREE
, parm_decl
;
1843 tree parm_type
= TREE_VALUE (tem
);
1844 gcc_assert (i
< DECL_MAX_LOCALS (fndecl
));
1846 parm_decl
= build_decl (input_location
, PARM_DECL
, parm_name
, parm_type
);
1847 DECL_CONTEXT (parm_decl
) = fndecl
;
1848 if (targetm
.calls
.promote_prototypes (parm_type
)
1849 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1850 && INTEGRAL_TYPE_P (parm_type
))
1851 parm_type
= integer_type_node
;
1852 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1855 ptr
= &TREE_CHAIN (parm_decl
);
1857 /* Add parm_decl to the decl_map. */
1858 push_jvm_slot (i
, parm_decl
);
1860 type_map
[i
] = TREE_TYPE (parm_decl
);
1861 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1864 type_map
[i
] = void_type_node
;
1868 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1870 while (i
< DECL_MAX_LOCALS(fndecl
))
1871 type_map
[i
++] = NULL_TREE
;
1873 build_result_decl (fndecl
);
1874 DECL_SOURCE_LOCATION (fndecl
) = input_location
;
1876 /* Push local variables. */
1879 function_binding_level
= current_binding_level
;
1883 end_java_method (void)
1885 tree fndecl
= current_function_decl
;
1887 /* pop out of function */
1890 /* pop out of its parameters */
1893 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1895 if (DECL_SAVED_TREE (fndecl
))
1897 tree fbody
, block_body
;
1898 /* Before we check initialization, attached all class initialization
1899 variable to the block_body */
1900 fbody
= DECL_SAVED_TREE (fndecl
);
1901 block_body
= BIND_EXPR_BODY (fbody
);
1902 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl
),
1903 attach_init_test_initialization_flags
, block_body
);
1906 finish_method (fndecl
);
1908 current_function_decl
= NULL_TREE
;
1909 base_decl_map
= NULL_TREE
;
1912 /* Prepare a method for expansion. */
1915 finish_method (tree fndecl
)
1917 tree
*tp
= &DECL_SAVED_TREE (fndecl
);
1919 /* Wrap body of synchronized methods in a monitorenter,
1920 plus monitorexit cleanup. */
1921 if (METHOD_SYNCHRONIZED (fndecl
))
1923 tree enter
, exit
, lock
;
1924 if (METHOD_STATIC (fndecl
))
1925 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1927 lock
= DECL_ARGUMENTS (fndecl
);
1928 BUILD_MONITOR_ENTER (enter
, lock
);
1929 BUILD_MONITOR_EXIT (exit
, lock
);
1930 *tp
= build2 (COMPOUND_EXPR
, void_type_node
, enter
,
1931 build2 (TRY_FINALLY_EXPR
, void_type_node
, *tp
, exit
));
1934 /* Convert function tree to GENERIC prior to inlining. */
1935 java_genericize (fndecl
);
1937 /* Store the end of the function, so that we get good line number
1938 info for the epilogue. */
1939 if (DECL_STRUCT_FUNCTION (fndecl
))
1940 set_cfun (DECL_STRUCT_FUNCTION (fndecl
));
1942 allocate_struct_function (fndecl
, false);
1943 cfun
->function_end_locus
= DECL_FUNCTION_LAST_LINE (fndecl
);
1945 /* Defer inlining and expansion to the cgraph optimizers. */
1946 cgraph_finalize_function (fndecl
, false);
1949 /* We pessimistically marked all methods and fields external until we
1950 knew what set of classes we were planning to compile. Now mark those
1951 associated with CLASS to be generated locally as not external. */
1954 java_mark_decl_local (tree decl
)
1956 DECL_EXTERNAL (decl
) = 0;
1958 #ifdef ENABLE_CHECKING
1959 /* Double check that we didn't pass the function to the callgraph early. */
1960 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1961 gcc_assert (!cgraph_node (decl
)->local
.finalized
);
1963 gcc_assert (!DECL_RTL_SET_P (decl
));
1966 /* Given appropriate target support, G++ will emit hidden aliases for native
1967 methods. Using this hidden name is required for proper operation of
1968 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1969 proper target support, then mark the method for aliasing. */
1972 java_mark_cni_decl_local (tree decl
)
1974 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1978 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
1979 DECL_LOCAL_CNI_METHOD_P (decl
) = 1;
1981 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1982 mangler. We might have already referenced this native method and
1983 therefore created its name, but even if we have it won't hurt.
1984 We'll just go via its externally visible name, rather than its
1985 hidden alias. However, we must force things so that the correct
1986 mangling is done. */
1988 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
1989 java_mangle_decl (decl
);
1990 if (DECL_RTL_SET_P (decl
))
1992 SET_DECL_RTL (decl
, 0);
1993 make_decl_rtl (decl
);
1997 /* Use the preceding two functions and mark all members of the class. */
2000 java_mark_class_local (tree klass
)
2004 for (t
= TYPE_FIELDS (klass
); t
; t
= TREE_CHAIN (t
))
2005 if (FIELD_STATIC (t
))
2006 java_mark_decl_local (t
);
2008 for (t
= TYPE_METHODS (klass
); t
; t
= TREE_CHAIN (t
))
2009 if (!METHOD_ABSTRACT (t
))
2011 if (METHOD_NATIVE (t
) && !flag_jni
)
2012 java_mark_cni_decl_local (t
);
2014 java_mark_decl_local (t
);
2018 /* Add a statement to a compound_expr. */
2021 add_stmt_to_compound (tree existing
, tree type
, tree stmt
)
2027 tree expr
= build2 (COMPOUND_EXPR
, type
, existing
, stmt
);
2028 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (existing
)
2029 | TREE_SIDE_EFFECTS (stmt
);
2036 /* If this node is an expr, mark its input location. Called from
2040 set_input_location (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
2041 void *data ATTRIBUTE_UNUSED
)
2045 if (CAN_HAVE_LOCATION_P (t
))
2047 if (EXPR_HAS_LOCATION(t
))
2048 return t
; /* Don't walk any further into this expr. */
2050 SET_EXPR_LOCATION (t
, input_location
);
2053 return NULL_TREE
; /* Continue walking this expr. */
2056 /* Add a statement to the statement_list currently being constructed.
2057 If the statement_list is null, we don't create a singleton list.
2058 This is necessary because poplevel() assumes that adding a
2059 statement to a null statement_list returns the statement. */
2062 java_add_stmt (tree new_stmt
)
2064 tree stmts
= current_binding_level
->stmts
;
2065 tree_stmt_iterator i
;
2068 walk_tree (&new_stmt
, set_input_location
, NULL
, NULL
);
2071 return current_binding_level
->stmts
= new_stmt
;
2073 /* Force STMTS to be a statement_list. */
2074 if (TREE_CODE (stmts
) != STATEMENT_LIST
)
2076 tree t
= make_node (STATEMENT_LIST
);
2078 tsi_link_after (&i
, stmts
, TSI_CONTINUE_LINKING
);
2082 i
= tsi_last (stmts
);
2083 tsi_link_after (&i
, new_stmt
, TSI_CONTINUE_LINKING
);
2084 TREE_TYPE (stmts
) = void_type_node
;
2086 return current_binding_level
->stmts
= stmts
;
2089 /* Add a variable to the current scope. */
2092 java_add_local_var (tree decl
)
2094 tree
*vars
= ¤t_binding_level
->names
;
2096 TREE_CHAIN (decl
) = next
;
2098 DECL_CONTEXT (decl
) = current_function_decl
;
2099 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
2103 /* Return a pointer to the compound_expr currently being
2109 return ¤t_binding_level
->stmts
;
2112 /* Register an exception range as belonging to the current binding
2113 level. There may only be one: if there are more, we'll create more
2114 binding levels. However, each range can have multiple handlers,
2115 and these are expanded when we call expand_end_java_handler(). */
2118 register_exception_range (struct eh_range
*range
, int pc
, int end_pc
)
2120 gcc_assert (! current_binding_level
->exception_range
);
2121 current_binding_level
->exception_range
= range
;
2122 current_binding_level
->end_pc
= end_pc
;
2123 current_binding_level
->start_pc
= pc
;
2126 #include "gt-java-decl.h"