1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc. */
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
31 #include "coretypes.h"
38 #include "java-tree.h"
44 #include "java-except.h"
48 #include "tree-inline.h"
52 #if defined (DEBUG_JAVA_BINDING_LEVELS)
53 extern void indent (void);
56 static tree push_jvm_slot (int, tree);
57 static tree lookup_name_current_level (tree);
58 static tree push_promoted_type (const char *, tree);
59 static struct binding_level *make_binding_level (void);
60 static tree create_primitive_vtable (const char *);
61 static tree check_local_unnamed_variable (tree, tree, tree);
62 static void parse_version (void);
64 /* Used when computing the ABI version. */
65 #define GCJ_BINARYCOMPAT_ADDITION 5
67 /* The version of the BC ABI that we generate. At the moment we are
68 compatible with what shipped in GCC 4.0. This must be kept in sync
69 with parse_version(), libgcj, and reality (if the BC format
70 changes, this must change. */
71 #define GCJ_CURRENT_BC_ABI_VERSION \
72 (4 * 10000 + 0 * 10 + GCJ_BINARYCOMPAT_ADDITION)
74 /* The ABI version number. */
77 /* Name of the Cloneable class. */
78 tree java_lang_cloneable_identifier_node;
80 /* Name of the Serializable class. */
81 tree java_io_serializable_identifier_node;
83 /* The DECL_MAP is a mapping from (index, type) to a decl node.
84 If index < max_locals, it is the index of a local variable.
85 if index >= max_locals, then index-max_locals is a stack slot.
86 The DECL_MAP mapping is represented as a TREE_VEC whose elements
87 are a list of decls (VAR_DECL or PARM_DECL) chained by
88 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
89 we search the chain for a decl with a matching TREE_TYPE. */
91 static GTY(()) tree decl_map;
93 /* The base_decl_map is contains one variable of ptr_type: this is
94 used to contain every variable of reference type that is ever
95 stored in a local variable slot. */
97 static GTY(()) tree base_decl_map;
99 /* An index used to make temporary identifiers unique. */
102 /* A list of local variables VAR_DECLs for this method that we have seen
103 debug information, but we have not reached their starting (byte) PC yet. */
105 static GTY(()) tree pending_local_decls;
107 #if defined(DEBUG_JAVA_BINDING_LEVELS)
108 int binding_depth = 0;
109 int is_class_level = 0;
117 for (i = 0; i < binding_depth*2; i++)
120 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
122 /* True if decl is a named local variable, i.e. if it is an alias
123 that's used only for debugging purposes. */
126 debug_variable_p (tree decl)
128 if (TREE_CODE (decl) == PARM_DECL)
131 if (LOCAL_SLOT_P (decl))
137 /* Copy the value in decl into every live alias in the same local
138 variable slot. Some of these will be dead stores removed by the
142 update_aliases (tree decl, int index, int pc)
144 tree decl_type = TREE_TYPE (decl);
147 if (debug_variable_p (decl))
150 for (tmp = TREE_VEC_ELT (decl_map, index);
152 tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
154 tree tmp_type = TREE_TYPE (tmp);
156 && LOCAL_SLOT_P (tmp) == 0
158 || (pc >= DECL_LOCAL_START_PC (tmp)
159 && pc < DECL_LOCAL_END_PC (tmp)))
160 /* This test is < (rather than <=) because there's no point
161 updating an alias that's about to die at the end of this
163 && (tmp_type == decl_type
164 || (INTEGRAL_TYPE_P (tmp_type)
165 && INTEGRAL_TYPE_P (decl_type)
166 && TYPE_PRECISION (decl_type) <= 32
167 && TYPE_PRECISION (tmp_type) <= 32)
168 || (TREE_CODE (tmp_type) == POINTER_TYPE
169 && TREE_CODE (decl_type) == POINTER_TYPE)))
171 tree src = build1 (NOP_EXPR, tmp_type, decl);
172 if (LOCAL_VAR_OUT_OF_SCOPE_P (tmp))
174 java_add_stmt (build2 (MODIFY_EXPR, tmp_type, tmp, src));
180 push_jvm_slot (int index, tree decl)
182 DECL_CONTEXT (decl) = current_function_decl;
183 layout_decl (decl, 0);
185 /* Now link the decl into the decl_map. */
186 if (DECL_LANG_SPECIFIC (decl) == NULL)
188 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
189 DECL_LOCAL_START_PC (decl) = 0;
190 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
191 DECL_LOCAL_SLOT_NUMBER (decl) = index;
193 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
194 TREE_VEC_ELT (decl_map, index) = decl;
199 /* At the point of its creation a local variable decl inherits
200 whatever is already in the same slot. In the case of a local
201 variable that is declared but unused, we won't find anything. */
204 initialize_local_variable (tree decl, int index)
206 tree decl_type = TREE_TYPE (decl);
207 if (TREE_CODE (decl_type) == POINTER_TYPE)
209 tree tmp = TREE_VEC_ELT (base_decl_map, index);
213 /* At the point of its creation this decl inherits whatever
215 tree src = build1 (NOP_EXPR, decl_type, tmp);
216 java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, src));
223 for (tmp = TREE_VEC_ELT (decl_map, index);
225 tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
227 tree tmp_type = TREE_TYPE (tmp);
229 && ! debug_variable_p (tmp)
230 && (tmp_type == decl_type
231 || (INTEGRAL_TYPE_P (tmp_type)
232 && INTEGRAL_TYPE_P (decl_type)
233 && TYPE_PRECISION (decl_type) <= 32
234 && TYPE_PRECISION (tmp_type) <= 32
235 && TYPE_PRECISION (tmp_type)
236 >= TYPE_PRECISION (decl_type))))
238 java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, tmp));
245 /* Find the best declaration based upon type. If 'decl' fits 'type' better
246 than 'best', return 'decl'. Otherwise return 'best'. */
249 check_local_unnamed_variable (tree best, tree decl, tree type)
251 tree decl_type = TREE_TYPE (decl);
253 if (LOCAL_VAR_OUT_OF_SCOPE_P (decl))
256 /* Use the same decl for all integer types <= 32 bits. This is
257 necessary because sometimes a value is stored as (for example)
258 boolean but loaded as int. */
259 if (decl_type == type
260 || (INTEGRAL_TYPE_P (decl_type)
261 && INTEGRAL_TYPE_P (type)
262 && TYPE_PRECISION (decl_type) <= 32
263 && TYPE_PRECISION (type) <= 32
264 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
265 /* ptr_type_node is used for null pointers, which are
266 assignment compatible with everything. */
267 || (TREE_CODE (decl_type) == POINTER_TYPE
268 && type == ptr_type_node)
269 /* Whenever anyone wants to use a slot that is initially
270 occupied by a PARM_DECL of pointer type they must get that
271 decl, even if they asked for a pointer to a different type.
272 However, if someone wants a scalar variable in a slot that
273 initially held a pointer arg -- or vice versa -- we create a
276 ???: As long as verification is correct, this will be a
277 compatible type. But maybe we should create a dummy variable
278 and replace all references to it with the DECL and a
281 || (TREE_CODE (decl_type) == POINTER_TYPE
282 && TREE_CODE (decl) == PARM_DECL
283 && TREE_CODE (type) == POINTER_TYPE))
285 if (best == NULL_TREE
286 || (decl_type == type && TREE_TYPE (best) != type))
294 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
295 that is valid at PC (or -1 if any pc).
296 If there is no existing matching decl, allocate one. */
299 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
301 tree tmp = TREE_VEC_ELT (decl_map, index);
302 tree decl = NULL_TREE;
304 /* Scan through every declaration that has been created in this
305 slot. We're only looking for variables that correspond to local
306 index declarations and PARM_DECLs, not named variables: such
307 local variables are used only for debugging information. */
308 while (tmp != NULL_TREE)
310 if (! debug_variable_p (tmp))
311 decl = check_local_unnamed_variable (decl, tmp, type);
312 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
315 /* gcj has a function called promote_type(), which is used by both
316 the bytecode compiler and the source compiler. Unfortunately,
317 the type systems for the Java VM and the Java language are not
318 the same: a boolean in the VM promotes to an int, not to a wide
319 boolean. If our caller wants something to hold a boolean, that
320 had better be an int, because that slot might be re-used
321 later in integer context. */
322 if (TREE_CODE (type) == BOOLEAN_TYPE)
323 type = integer_type_node;
325 /* If we don't find a match, create one with the type passed in.
326 The name of the variable is #n#m, which n is the variable index
327 in the local variable area and m is a dummy identifier for
328 uniqueness -- multiple variables may share the same local
329 variable index. We don't call pushdecl() to push pointer types
330 into a binding expr because they'll all be replaced by a single
331 variable that is used for every reference in that local variable
337 sprintf (buf, "#slot#%d#%d", index, uniq++);
338 name = get_identifier (buf);
339 decl = build_decl (VAR_DECL, name, type);
340 DECL_IGNORED_P (decl) = 1;
341 DECL_ARTIFICIAL (decl) = 1;
342 decl = push_jvm_slot (index, decl);
343 LOCAL_SLOT_P (decl) = 1;
345 if (TREE_CODE (type) != POINTER_TYPE)
346 pushdecl_function_level (decl);
349 /* As well as creating a local variable that matches the type, we
350 also create a base variable (of ptr_type) that will hold all its
352 if (TREE_CODE (type) == POINTER_TYPE
353 && ! TREE_VEC_ELT (base_decl_map, index))
358 sprintf (buf, "#ref#%d#%d", index, uniq++);
359 name = get_identifier (buf);
361 = TREE_VEC_ELT (base_decl_map, index)
362 = build_decl (VAR_DECL, name, ptr_type_node);
363 pushdecl_function_level (base_decl);
364 DECL_IGNORED_P (base_decl) = 1;
365 DECL_ARTIFICIAL (base_decl) = 1;
371 /* Called during gimplification for every variable. If the variable
372 is a temporary of pointer type, replace it with a common variable
373 thath is used to hold all pointer types that are ever stored in
374 that slot. Set WANT_LVALUE if you want a variable that is to be
378 java_replace_reference (tree var_decl, bool want_lvalue)
385 decl_type = TREE_TYPE (var_decl);
387 if (TREE_CODE (decl_type) == POINTER_TYPE)
389 if (DECL_LANG_SPECIFIC (var_decl)
390 && LOCAL_SLOT_P (var_decl))
392 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
393 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
399 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
409 /* Same as find_local_index, except that INDEX is a stack index. */
412 find_stack_slot (int index, tree type)
414 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
418 struct binding_level GTY(())
420 /* A chain of _DECL nodes for all variables, constants, functions,
421 * and typedef types. These are in the reverse of the order supplied.
425 /* For each level, a list of shadowed outer-level local definitions
426 to be restored when this level is popped.
427 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
428 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
431 /* For each level (except not the global one),
432 a chain of BLOCK nodes for all the levels
433 that were entered and exited one level down. */
436 /* The binding level which this one is contained in (inherits from). */
437 struct binding_level *level_chain;
439 /* The bytecode PC that marks the end of this level. */
441 /* The bytecode PC that marks the start of this level. */
444 /* The statements in this binding level. */
447 /* An exception range associated with this binding level. */
448 struct eh_range * GTY((skip (""))) exception_range;
450 /* Binding depth at which this level began. Used only for debugging. */
451 unsigned binding_depth;
454 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
456 /* The binding level currently in effect. */
458 static GTY(()) struct binding_level *current_binding_level;
460 /* A chain of binding_level structures awaiting reuse. */
462 static GTY(()) struct binding_level *free_binding_level;
464 /* The outermost binding level, for names of file scope.
465 This is created when the compiler is started and exists
466 through the entire run. */
468 static GTY(()) struct binding_level *global_binding_level;
470 /* The binding level that holds variables declared at the outermost
471 level within a function body. */
473 static struct binding_level *function_binding_level;
475 /* A PC value bigger than any PC value we may ever may encounter. */
477 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
479 /* Binding level structures are initialized by copying this one. */
481 static const struct binding_level clear_binding_level
483 NULL_TREE, /* names */
484 NULL_TREE, /* shadowed */
485 NULL_TREE, /* blocks */
486 NULL_BINDING_LEVEL, /* level_chain */
487 LARGEST_PC, /* end_pc */
490 NULL, /* exception_range */
491 0, /* binding_depth */
495 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
496 that have names. Here so we can clear out their names' definitions
497 at the end of the function. */
499 static tree named_labels;
501 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
503 static tree shadowed_labels;
506 tree java_global_trees[JTI_MAX];
508 /* Build (and pushdecl) a "promoted type" for all standard
509 types shorter than int. */
512 push_promoted_type (const char *name, tree actual_type)
514 tree type = make_node (TREE_CODE (actual_type));
516 tree in_min = TYPE_MIN_VALUE (int_type_node);
517 tree in_max = TYPE_MAX_VALUE (int_type_node);
519 tree in_min = TYPE_MIN_VALUE (actual_type);
520 tree in_max = TYPE_MAX_VALUE (actual_type);
522 TYPE_MIN_VALUE (type) = copy_node (in_min);
523 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
524 TYPE_MAX_VALUE (type) = copy_node (in_max);
525 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
526 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
528 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
532 /* Return a definition for a builtin function named NAME and whose data type
533 is TYPE. TYPE should be a function type with argument types.
534 FUNCTION_CODE tells later passes how to compile calls to this function.
535 See tree.h for its possible values.
537 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
538 the name to be called if we can't opencode the function. If
539 ATTRS is nonzero, use that for the function's attribute list. */
542 builtin_function (const char *name,
545 enum built_in_class cl,
546 const char *library_name,
547 tree ARG_UNUSED (attrs))
549 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
550 DECL_EXTERNAL (decl) = 1;
551 TREE_PUBLIC (decl) = 1;
553 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
554 make_decl_rtl (decl);
556 DECL_BUILT_IN_CLASS (decl) = cl;
557 DECL_FUNCTION_CODE (decl) = function_code;
561 /* Return tree that represents a vtable for a primitive array. */
563 create_primitive_vtable (const char *name)
568 sprintf (buf, "_Jv_%sVTable", name);
569 r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
570 DECL_EXTERNAL (r) = 1;
580 /* Parse the version string and compute the ABI version number. */
584 const char *p = version_string;
585 unsigned int major = 0, minor = 0;
586 unsigned int abi_version;
588 /* Skip leading junk. */
589 while (*p && !ISDIGIT (*p))
593 /* Extract major version. */
596 major = major * 10 + *p - '0';
600 gcc_assert (*p == '.' && ISDIGIT (p[1]));
603 /* Extract minor version. */
606 minor = minor * 10 + *p - '0';
610 /* Implicit in this computation is the idea that we won't break the
611 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
613 abi_version = 10000 * major + 10 * minor;
614 /* It is helpful to distinguish BC ABI from ordinary ABI at this
615 level, since at some point we will recognize a variety of BC ABIs
616 (objects generated by different version of gcj), but will
617 probably always require strict matching for ordinary ABI. */
618 if (flag_indirect_dispatch)
619 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
621 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
625 java_init_decl_processing (void)
628 tree field = NULL_TREE;
631 init_class_processing ();
633 current_function_decl = NULL;
634 current_binding_level = NULL_BINDING_LEVEL;
635 free_binding_level = NULL_BINDING_LEVEL;
636 pushlevel (0); /* make the binding_level structure for global names */
637 global_binding_level = current_binding_level;
639 /* The code here must be similar to build_common_tree_nodes{,_2} in
640 tree.c, especially as to the order of initializing common nodes. */
641 error_mark_node = make_node (ERROR_MARK);
642 TREE_TYPE (error_mark_node) = error_mark_node;
644 /* Create sizetype first - needed for other types. */
645 initialize_sizetypes (false);
647 byte_type_node = make_signed_type (8);
648 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
649 short_type_node = make_signed_type (16);
650 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
651 int_type_node = make_signed_type (32);
652 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
653 long_type_node = make_signed_type (64);
654 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
656 unsigned_byte_type_node = make_unsigned_type (8);
657 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
658 unsigned_byte_type_node));
659 unsigned_short_type_node = make_unsigned_type (16);
660 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
661 unsigned_short_type_node));
662 unsigned_int_type_node = make_unsigned_type (32);
663 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
664 unsigned_int_type_node));
665 unsigned_long_type_node = make_unsigned_type (64);
666 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
667 unsigned_long_type_node));
669 /* This is not a java type, however tree-dfa requires a definition for
671 size_type_node = make_unsigned_type (POINTER_SIZE);
672 set_sizetype (size_type_node);
674 /* Define these next since types below may used them. */
675 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
676 integer_zero_node = build_int_cst (NULL_TREE, 0);
677 integer_one_node = build_int_cst (NULL_TREE, 1);
678 integer_two_node = build_int_cst (NULL_TREE, 2);
679 integer_four_node = build_int_cst (NULL_TREE, 4);
680 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
682 /* A few values used for range checking in the lexer. */
683 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
684 #if HOST_BITS_PER_WIDE_INT == 64
685 decimal_long_max = build_int_cstu (unsigned_long_type_node,
686 0x8000000000000000LL);
687 #elif HOST_BITS_PER_WIDE_INT == 32
688 decimal_long_max = build_int_cst_wide (unsigned_long_type_node,
691 #error "unsupported size"
694 size_zero_node = size_int (0);
695 size_one_node = size_int (1);
696 bitsize_zero_node = bitsize_int (0);
697 bitsize_one_node = bitsize_int (1);
698 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
700 long_zero_node = build_int_cst (long_type_node, 0);
702 void_type_node = make_node (VOID_TYPE);
703 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
704 layout_type (void_type_node); /* Uses size_zero_node */
706 ptr_type_node = build_pointer_type (void_type_node);
708 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
710 t = make_node (VOID_TYPE);
711 layout_type (t); /* Uses size_zero_node */
712 return_address_type_node = build_pointer_type (t);
714 null_pointer_node = build_int_cst (ptr_type_node, 0);
717 /* Make a type to be the domain of a few array types
718 whose domains don't really matter.
719 200 is small enough that it always fits in size_t
720 and large enough that it can hold most function names for the
721 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
722 short_array_type_node = build_prim_array_type (short_type_node, 200);
724 char_type_node = make_node (CHAR_TYPE);
725 TYPE_PRECISION (char_type_node) = 16;
726 fixup_unsigned_type (char_type_node);
727 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
729 boolean_type_node = make_node (BOOLEAN_TYPE);
730 TYPE_PRECISION (boolean_type_node) = 1;
731 fixup_unsigned_type (boolean_type_node);
732 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
734 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
735 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
737 promoted_byte_type_node
738 = push_promoted_type ("promoted_byte", byte_type_node);
739 promoted_short_type_node
740 = push_promoted_type ("promoted_short", short_type_node);
741 promoted_char_type_node
742 = push_promoted_type ("promoted_char", char_type_node);
743 promoted_boolean_type_node
744 = push_promoted_type ("promoted_boolean", boolean_type_node);
746 float_type_node = make_node (REAL_TYPE);
747 TYPE_PRECISION (float_type_node) = 32;
748 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
750 layout_type (float_type_node);
752 double_type_node = make_node (REAL_TYPE);
753 TYPE_PRECISION (double_type_node) = 64;
754 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
756 layout_type (double_type_node);
758 float_zero_node = build_real (float_type_node, dconst0);
759 double_zero_node = build_real (double_type_node, dconst0);
761 /* These are the vtables for arrays of primitives. */
762 boolean_array_vtable = create_primitive_vtable ("boolean");
763 byte_array_vtable = create_primitive_vtable ("byte");
764 char_array_vtable = create_primitive_vtable ("char");
765 short_array_vtable = create_primitive_vtable ("short");
766 int_array_vtable = create_primitive_vtable ("int");
767 long_array_vtable = create_primitive_vtable ("long");
768 float_array_vtable = create_primitive_vtable ("float");
769 double_array_vtable = create_primitive_vtable ("double");
771 one_elt_array_domain_type = build_index_type (integer_one_node);
772 utf8const_type = make_node (RECORD_TYPE);
773 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
774 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
775 FINISH_RECORD (utf8const_type);
776 utf8const_ptr_type = build_pointer_type (utf8const_type);
778 atable_type = build_array_type (ptr_type_node,
779 one_elt_array_domain_type);
780 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
781 atable_ptr_type = build_pointer_type (atable_type);
783 itable_type = build_array_type (ptr_type_node,
784 one_elt_array_domain_type);
785 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
786 itable_ptr_type = build_pointer_type (itable_type);
788 symbol_type = make_node (RECORD_TYPE);
789 PUSH_FIELD (symbol_type, field, "clname", utf8const_ptr_type);
790 PUSH_FIELD (symbol_type, field, "name", utf8const_ptr_type);
791 PUSH_FIELD (symbol_type, field, "signature", utf8const_ptr_type);
792 FINISH_RECORD (symbol_type);
794 symbols_array_type = build_array_type (symbol_type,
795 one_elt_array_domain_type);
796 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
798 assertion_entry_type = make_node (RECORD_TYPE);
799 PUSH_FIELD (assertion_entry_type, field, "assertion_code", integer_type_node);
800 PUSH_FIELD (assertion_entry_type, field, "op1", utf8const_ptr_type);
801 PUSH_FIELD (assertion_entry_type, field, "op2", utf8const_ptr_type);
802 FINISH_RECORD (assertion_entry_type);
804 assertion_table_type = build_array_type (assertion_entry_type,
805 one_elt_array_domain_type);
807 /* As you're adding items here, please update the code right after
808 this section, so that the filename containing the source code of
809 the pre-defined class gets registered correctly. */
810 unqualified_object_id_node = get_identifier ("Object");
811 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
812 object_ptr_type_node = promote_type (object_type_node);
813 string_type_node = lookup_class (get_identifier ("java.lang.String"));
814 string_ptr_type_node = promote_type (string_type_node);
815 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
816 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
817 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
818 runtime_exception_type_node =
819 lookup_class (get_identifier ("java.lang.RuntimeException"));
820 error_exception_type_node =
821 lookup_class (get_identifier ("java.lang.Error"));
823 rawdata_ptr_type_node
824 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
826 add_predefined_file (get_identifier ("java/lang/Class.java"));
827 add_predefined_file (get_identifier ("java/lang/Error.java"));
828 add_predefined_file (get_identifier ("java/lang/Object.java"));
829 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
830 add_predefined_file (get_identifier ("java/lang/String.java"));
831 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
832 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
833 add_predefined_file (get_identifier ("java/lang/Exception.java"));
834 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
835 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
837 methodtable_type = make_node (RECORD_TYPE);
838 layout_type (methodtable_type);
839 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
840 methodtable_ptr_type = build_pointer_type (methodtable_type);
842 TYPE_identifier_node = get_identifier ("TYPE");
843 init_identifier_node = get_identifier ("<init>");
844 clinit_identifier_node = get_identifier ("<clinit>");
845 finit_identifier_node = get_identifier ("finit$");
846 instinit_identifier_node = get_identifier ("instinit$");
847 void_signature_node = get_identifier ("()V");
848 length_identifier_node = get_identifier ("length");
849 finalize_identifier_node = get_identifier ("finalize");
850 this_identifier_node = get_identifier ("this");
851 super_identifier_node = get_identifier ("super");
852 continue_identifier_node = get_identifier ("continue");
853 access0_identifier_node = get_identifier ("access$0");
854 classdollar_identifier_node = get_identifier ("class$");
856 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
857 java_io_serializable_identifier_node =
858 get_identifier ("java.io.Serializable");
860 /* for lack of a better place to put this stub call */
861 init_expr_processing();
863 constants_type_node = make_node (RECORD_TYPE);
864 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
865 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
866 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
867 FINISH_RECORD (constants_type_node);
868 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
870 access_flags_type_node = unsigned_short_type_node;
872 dtable_type = make_node (RECORD_TYPE);
873 dtable_ptr_type = build_pointer_type (dtable_type);
875 otable_type = build_array_type (integer_type_node,
876 one_elt_array_domain_type);
877 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
878 otable_ptr_type = build_pointer_type (otable_type);
880 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
881 DECL_FCONTEXT (field) = object_type_node;
882 TYPE_VFIELD (object_type_node) = field;
884 /* This isn't exactly true, but it is what we have in the source.
885 There is an unresolved issue here, which is whether the vtable
886 should be marked by the GC. */
887 if (! flag_hash_synchronization)
888 PUSH_FIELD (object_type_node, field, "sync_info",
889 build_pointer_type (object_type_node));
890 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
891 FIELD_PRIVATE (t) = 1;
892 FINISH_RECORD (object_type_node);
894 field_type_node = make_node (RECORD_TYPE);
895 field_ptr_type_node = build_pointer_type (field_type_node);
896 method_type_node = make_node (RECORD_TYPE);
897 method_ptr_type_node = build_pointer_type (method_type_node);
899 set_super_info (0, class_type_node, object_type_node, 0);
900 set_super_info (0, string_type_node, object_type_node, 0);
901 class_ptr_type = build_pointer_type (class_type_node);
903 PUSH_FIELD (class_type_node, field, "next_or_version", class_ptr_type);
904 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
905 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
906 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
907 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
908 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
909 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
910 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
911 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
912 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
913 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
914 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
915 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
916 PUSH_FIELD (class_type_node, field, "otable", otable_ptr_type);
917 PUSH_FIELD (class_type_node, field, "otable_syms",
918 symbols_array_ptr_type);
919 PUSH_FIELD (class_type_node, field, "atable", atable_ptr_type);
920 PUSH_FIELD (class_type_node, field, "atable_syms",
921 symbols_array_ptr_type);
922 PUSH_FIELD (class_type_node, field, "itable", itable_ptr_type);
923 PUSH_FIELD (class_type_node, field, "itable_syms",
924 symbols_array_ptr_type);
925 PUSH_FIELD (class_type_node, field, "catch_classes", ptr_type_node);
926 PUSH_FIELD (class_type_node, field, "interfaces",
927 build_pointer_type (class_ptr_type));
928 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
929 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
930 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
931 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
932 PUSH_FIELD (class_type_node, field, "depth", short_type_node);
933 PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
934 PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
935 PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);
936 PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
937 PUSH_FIELD (class_type_node, field, "assertion_table", ptr_type_node);
938 PUSH_FIELD (class_type_node, field, "hack_signers", ptr_type_node);
939 PUSH_FIELD (class_type_node, field, "chain", ptr_type_node);
940 PUSH_FIELD (class_type_node, field, "aux_info", ptr_type_node);
941 PUSH_FIELD (class_type_node, field, "engine", ptr_type_node);
942 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
943 FIELD_PRIVATE (t) = 1;
944 push_super_field (class_type_node, object_type_node);
946 FINISH_RECORD (class_type_node);
947 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
949 field_info_union_node = make_node (UNION_TYPE);
950 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
951 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
953 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
955 layout_type (field_info_union_node);
957 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
958 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
959 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
960 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
961 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
962 FINISH_RECORD (field_type_node);
963 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
965 nativecode_ptr_array_type_node
966 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
968 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
969 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
970 FINISH_RECORD (dtable_type);
971 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
973 jexception_type = make_node (RECORD_TYPE);
974 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
975 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
976 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
977 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
978 FINISH_RECORD (jexception_type);
979 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
980 jexception_ptr_type = build_pointer_type (jexception_type);
982 lineNumberEntry_type = make_node (RECORD_TYPE);
983 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
984 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
985 FINISH_RECORD (lineNumberEntry_type);
987 lineNumbers_type = make_node (RECORD_TYPE);
988 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
989 FINISH_RECORD (lineNumbers_type);
991 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
992 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
993 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
994 PUSH_FIELD (method_type_node, field, "index", unsigned_short_type_node);
995 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
996 PUSH_FIELD (method_type_node, field, "throws", ptr_type_node);
997 FINISH_RECORD (method_type_node);
998 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
1000 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
1002 t = tree_cons (NULL_TREE, class_ptr_type, endlink);
1003 alloc_object_node = builtin_function ("_Jv_AllocObject",
1004 build_function_type (ptr_type_node, t),
1005 0, NOT_BUILT_IN, NULL, NULL_TREE);
1006 DECL_IS_MALLOC (alloc_object_node) = 1;
1007 alloc_no_finalizer_node =
1008 builtin_function ("_Jv_AllocObjectNoFinalizer",
1009 build_function_type (ptr_type_node, t),
1010 0, NOT_BUILT_IN, NULL, NULL_TREE);
1011 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
1013 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1014 soft_initclass_node = builtin_function ("_Jv_InitClass",
1015 build_function_type (void_type_node,
1017 0, NOT_BUILT_IN, NULL, NULL_TREE);
1019 throw_node = builtin_function ("_Jv_Throw",
1020 build_function_type (void_type_node, t),
1021 0, NOT_BUILT_IN, NULL, NULL_TREE);
1022 /* Mark throw_nodes as `noreturn' functions with side effects. */
1023 TREE_THIS_VOLATILE (throw_node) = 1;
1024 TREE_SIDE_EFFECTS (throw_node) = 1;
1026 t = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node,
1028 soft_monitorenter_node
1029 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1031 soft_monitorexit_node
1032 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1035 t = tree_cons (NULL_TREE, ptr_type_node,
1036 tree_cons (NULL_TREE, int_type_node, endlink));
1038 = builtin_function ("_Jv_NewPrimArray",
1039 build_function_type (ptr_type_node, t),
1040 0, NOT_BUILT_IN, NULL, NULL_TREE);
1041 DECL_IS_MALLOC (soft_newarray_node) = 1;
1043 t = tree_cons (NULL_TREE, int_type_node,
1044 tree_cons (NULL_TREE, class_ptr_type,
1045 tree_cons (NULL_TREE, object_ptr_type_node,
1048 = builtin_function ("_Jv_NewObjectArray",
1049 build_function_type (ptr_type_node, t),
1050 0, NOT_BUILT_IN, NULL, NULL_TREE);
1051 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1053 /* There is no endlink here because _Jv_NewMultiArray is a varargs
1055 t = tree_cons (NULL_TREE, ptr_type_node,
1056 tree_cons (NULL_TREE, int_type_node, NULL_TREE));
1057 soft_multianewarray_node
1058 = builtin_function ("_Jv_NewMultiArray",
1059 build_function_type (ptr_type_node, t),
1060 0, NOT_BUILT_IN, NULL, NULL_TREE);
1061 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1063 t = build_function_type (void_type_node,
1064 tree_cons (NULL_TREE, int_type_node, endlink));
1065 soft_badarrayindex_node
1066 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
1067 0, NOT_BUILT_IN, NULL, NULL_TREE);
1068 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1070 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1071 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1073 soft_nullpointer_node
1074 = builtin_function ("_Jv_ThrowNullPointerException",
1075 build_function_type (void_type_node, endlink),
1076 0, NOT_BUILT_IN, NULL, NULL_TREE);
1077 /* Mark soft_nullpointer_node as a `noreturn' function with side
1079 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1080 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1082 t = tree_cons (NULL_TREE, class_ptr_type,
1083 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1085 = builtin_function ("_Jv_CheckCast",
1086 build_function_type (ptr_type_node, t),
1087 0, NOT_BUILT_IN, NULL, NULL_TREE);
1088 t = tree_cons (NULL_TREE, object_ptr_type_node,
1089 tree_cons (NULL_TREE, class_ptr_type, endlink));
1090 soft_instanceof_node
1091 = builtin_function ("_Jv_IsInstanceOf",
1092 build_function_type (boolean_type_node, t),
1093 0, NOT_BUILT_IN, NULL, NULL_TREE);
1094 DECL_IS_PURE (soft_instanceof_node) = 1;
1095 t = tree_cons (NULL_TREE, object_ptr_type_node,
1096 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1097 soft_checkarraystore_node
1098 = builtin_function ("_Jv_CheckArrayStore",
1099 build_function_type (void_type_node, t),
1100 0, NOT_BUILT_IN, NULL, NULL_TREE);
1101 t = tree_cons (NULL_TREE, ptr_type_node,
1102 tree_cons (NULL_TREE, ptr_type_node,
1103 tree_cons (NULL_TREE, int_type_node, endlink)));
1104 soft_lookupinterfacemethod_node
1105 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
1106 build_function_type (ptr_type_node, t),
1107 0, NOT_BUILT_IN, NULL, NULL_TREE);
1108 DECL_IS_PURE (soft_lookupinterfacemethod_node) = 1;
1109 t = tree_cons (NULL_TREE, ptr_type_node,
1110 tree_cons (NULL_TREE, ptr_type_node,
1111 tree_cons (NULL_TREE, ptr_type_node, endlink)));
1112 soft_lookupinterfacemethodbyname_node
1113 = builtin_function ("_Jv_LookupInterfaceMethod",
1114 build_function_type (ptr_type_node, t),
1115 0, NOT_BUILT_IN, NULL, NULL_TREE);
1116 t = tree_cons (NULL_TREE, object_ptr_type_node,
1117 tree_cons (NULL_TREE, ptr_type_node,
1118 tree_cons (NULL_TREE, ptr_type_node,
1119 tree_cons (NULL_TREE, int_type_node,
1121 soft_lookupjnimethod_node
1122 = builtin_function ("_Jv_LookupJNIMethod",
1123 build_function_type (ptr_type_node, t),
1124 0, NOT_BUILT_IN, NULL, NULL_TREE);
1125 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1126 soft_getjnienvnewframe_node
1127 = builtin_function ("_Jv_GetJNIEnvNewFrame",
1128 build_function_type (ptr_type_node, t),
1129 0, NOT_BUILT_IN, NULL, NULL_TREE);
1130 soft_jnipopsystemframe_node
1131 = builtin_function ("_Jv_JNI_PopSystemFrame",
1132 build_function_type (void_type_node, t),
1133 0, NOT_BUILT_IN, NULL, NULL_TREE);
1135 t = tree_cons (NULL_TREE, int_type_node,
1136 tree_cons (NULL_TREE, int_type_node, endlink));
1138 = builtin_function ("_Jv_divI",
1139 build_function_type (int_type_node, t),
1140 0, NOT_BUILT_IN, NULL, NULL_TREE);
1143 = builtin_function ("_Jv_remI",
1144 build_function_type (int_type_node, t),
1145 0, NOT_BUILT_IN, NULL, NULL_TREE);
1147 t = tree_cons (NULL_TREE, long_type_node,
1148 tree_cons (NULL_TREE, long_type_node, endlink));
1150 = builtin_function ("_Jv_divJ",
1151 build_function_type (long_type_node, t),
1152 0, NOT_BUILT_IN, NULL, NULL_TREE);
1155 = builtin_function ("_Jv_remJ",
1156 build_function_type (long_type_node, t),
1157 0, NOT_BUILT_IN, NULL, NULL_TREE);
1159 /* Initialize variables for except.c. */
1160 eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
1161 ? "__gcj_personality_sj0"
1162 : "__gcj_personality_v0");
1164 lang_eh_runtime_type = do_nothing;
1168 initialize_builtins ();
1169 soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1171 soft_fmodf_node = built_in_decls[BUILT_IN_FMODF];
1178 /* Look up NAME in the current binding level and its superiors
1179 in the namespace of variables, functions and typedefs.
1180 Return a ..._DECL node of some kind representing its definition,
1181 or return 0 if it is undefined. */
1184 lookup_name (tree name)
1187 if (current_binding_level != global_binding_level
1188 && IDENTIFIER_LOCAL_VALUE (name))
1189 val = IDENTIFIER_LOCAL_VALUE (name);
1191 val = IDENTIFIER_GLOBAL_VALUE (name);
1195 /* Similar to `lookup_name' but look only at current binding level and
1196 the previous one if its the parameter level. */
1199 lookup_name_current_level (tree name)
1203 if (current_binding_level == global_binding_level)
1204 return IDENTIFIER_GLOBAL_VALUE (name);
1206 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1209 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
1210 if (DECL_NAME (t) == name)
1216 /* Use a binding level to record a labeled block declaration */
1219 push_labeled_block (tree lb)
1221 tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
1222 struct binding_level *b = current_binding_level;
1223 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1225 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1226 TREE_CHAIN (lb) = b->names;
1228 IDENTIFIER_LOCAL_VALUE (name) = lb;
1231 /* Pop the current binding level, reinstalling values for the previous
1235 pop_labeled_block (void)
1237 struct binding_level *b = current_binding_level;
1238 tree label = b->names;
1239 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
1242 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
1243 TREE_VALUE (b->shadowed);
1245 /* Pop the current level, and free the structure for reuse. */
1246 current_binding_level = current_binding_level->level_chain;
1247 b->level_chain = free_binding_level;
1248 free_binding_level = b;
1251 /* Record a decl-node X as belonging to the current lexical scope.
1252 Check for errors (such as an incompatible declaration for the same
1253 name already seen in the same scope).
1255 Returns either X or an old decl for the same name.
1256 If an old decl is returned, it may have been smashed
1257 to agree with what X says. */
1263 tree name = DECL_NAME (x);
1264 struct binding_level *b = current_binding_level;
1266 if (TREE_CODE (x) != TYPE_DECL)
1267 DECL_CONTEXT (x) = current_function_decl;
1270 t = lookup_name_current_level (name);
1271 if (t != 0 && t == error_mark_node)
1272 /* error_mark_node is 0 for a while during initialization! */
1275 error ("%J'%D' used prior to declaration", x, x);
1278 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1279 to point to the TYPE_DECL.
1280 Since Java does not have typedefs, a type can only have
1281 one (true) name, given by a class, interface, or builtin. */
1282 if (TREE_CODE (x) == TYPE_DECL
1283 && TYPE_NAME (TREE_TYPE (x)) == 0
1284 && TREE_TYPE (x) != error_mark_node)
1286 TYPE_NAME (TREE_TYPE (x)) = x;
1287 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1290 /* This name is new in its binding level.
1291 Install the new declaration and return it. */
1292 if (b == global_binding_level)
1294 /* Install a global value. */
1296 IDENTIFIER_GLOBAL_VALUE (name) = x;
1300 /* Here to install a non-global value. */
1301 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1302 IDENTIFIER_LOCAL_VALUE (name) = x;
1305 /* Warn if shadowing an argument at the top level of the body. */
1306 if (oldlocal != 0 && !DECL_EXTERNAL (x)
1307 /* This warning doesn't apply to the parms of a nested fcn. */
1308 && ! current_binding_level->parm_flag
1309 /* Check that this is one level down from the parms. */
1310 && current_binding_level->level_chain->parm_flag
1311 /* Check that the decl being shadowed
1312 comes from the parm level, one level up. */
1313 && chain_member (oldlocal, current_binding_level->level_chain->names))
1315 if (TREE_CODE (oldlocal) == PARM_DECL)
1316 pedwarn ("declaration of %qs shadows a parameter",
1317 IDENTIFIER_POINTER (name));
1319 pedwarn ("declaration of %qs shadows a symbol from the parameter list",
1320 IDENTIFIER_POINTER (name));
1323 /* Maybe warn if shadowing something else. */
1324 else if (warn_shadow && !DECL_EXTERNAL (x)
1325 /* No shadow warnings for internally generated vars. */
1326 && DECL_SOURCE_LINE (x) != 0
1327 /* No shadow warnings for vars made for inlining. */
1328 && ! DECL_FROM_INLINE (x))
1330 const char *warnstring = 0;
1332 if (TREE_CODE (x) == PARM_DECL
1333 && current_binding_level->level_chain->parm_flag)
1334 /* Don't warn about the parm names in function declarator
1335 within a function declarator.
1336 It would be nice to avoid warning in any function
1337 declarator in a declaration, as opposed to a definition,
1338 but there is no way to tell it's not a definition. */
1340 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1341 warnstring = "declaration of %qs shadows a parameter";
1342 else if (oldlocal != 0)
1343 warnstring = "declaration of %qs shadows previous local";
1344 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1345 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1346 warnstring = "declaration of %qs shadows global declaration";
1349 warning (warnstring, IDENTIFIER_POINTER (name));
1353 /* If storing a local value, there may already be one (inherited).
1354 If so, record it for restoration when this binding level ends. */
1356 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1360 /* Put decls on list in reverse order.
1361 We will reverse them later if necessary. */
1362 TREE_CHAIN (x) = b->names;
1369 pushdecl_force_head (tree x)
1371 current_binding_level->names = x;
1374 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1377 pushdecl_top_level (tree x)
1380 struct binding_level *b = current_binding_level;
1382 current_binding_level = global_binding_level;
1384 current_binding_level = b;
1388 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1391 pushdecl_function_level (tree x)
1394 struct binding_level *b = current_binding_level;
1396 current_binding_level = function_binding_level;
1398 current_binding_level = b;
1402 /* Nonzero if we are currently in the global binding level. */
1405 global_bindings_p (void)
1407 return current_binding_level == global_binding_level;
1410 /* Return the list of declarations of the current level.
1411 Note that this list is in reverse order unless/until
1412 you nreverse it; and when you do nreverse it, you must
1413 store the result back using `storedecls' or you will lose. */
1418 return current_binding_level->names;
1421 /* Create a new `struct binding_level'. */
1423 static struct binding_level *
1424 make_binding_level (void)
1427 return ggc_alloc_cleared (sizeof (struct binding_level));
1431 pushlevel (int unused ATTRIBUTE_UNUSED)
1433 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1436 /* If this is the top level of a function,
1437 just make sure that NAMED_LABELS is 0. */
1439 if (current_binding_level == global_binding_level)
1443 /* Reuse or create a struct for this binding level. */
1445 if (free_binding_level)
1447 newlevel = free_binding_level;
1448 free_binding_level = free_binding_level->level_chain;
1452 newlevel = make_binding_level ();
1455 /* Add this level to the front of the chain (stack) of levels that
1458 *newlevel = clear_binding_level;
1459 newlevel->level_chain = current_binding_level;
1460 current_binding_level = newlevel;
1461 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1462 newlevel->binding_depth = binding_depth;
1464 fprintf (stderr, "push %s level %p pc %d\n",
1465 (is_class_level) ? "class" : "block", newlevel, current_pc);
1468 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1471 /* Exit a binding level.
1472 Pop the level off, and restore the state of the identifier-decl mappings
1473 that were in effect when this level was entered.
1475 If KEEP is nonzero, this level had explicit declarations, so
1476 and create a "block" (a BLOCK node) for the level
1477 to record its declarations and subblocks for symbol table output.
1479 If FUNCTIONBODY is nonzero, this level is the body of a function,
1480 so create a block as if KEEP were set and also clear out all
1483 If REVERSE is nonzero, reverse the order of decls before putting
1484 them into the BLOCK. */
1487 poplevel (int keep, int reverse, int functionbody)
1490 /* The chain of decls was accumulated in reverse order.
1491 Put it into forward order, just for cleanliness. */
1493 tree subblocks = current_binding_level->blocks;
1498 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1501 if (current_binding_level->end_pc != LARGEST_PC)
1502 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1503 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1504 current_binding_level->end_pc);
1506 fprintf (stderr, "pop %s level %p pc %d\n",
1507 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1509 if (is_class_level != (current_binding_level == class_binding_level))
1512 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1516 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1518 /* Get the decls in the order they were written.
1519 Usually current_binding_level->names is in reverse order.
1520 But parameter decls were previously put in forward order. */
1523 current_binding_level->names
1524 = decls = nreverse (current_binding_level->names);
1526 decls = current_binding_level->names;
1528 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1529 if (TREE_CODE (decl) == VAR_DECL
1530 && DECL_LANG_SPECIFIC (decl) != NULL
1531 && DECL_LOCAL_SLOT_NUMBER (decl))
1532 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1534 /* If there were any declarations in that level,
1535 or if this level is a function body,
1536 create a BLOCK to record them for the life of this function. */
1539 if (keep || functionbody)
1541 block = make_node (BLOCK);
1542 TREE_TYPE (block) = void_type_node;
1545 if (current_binding_level->exception_range)
1546 expand_end_java_handler (current_binding_level->exception_range);
1550 /* If any statements have been generated at this level, create a
1551 BIND_EXPR to hold them and copy the variables to it. This
1552 only applies to the bytecode compiler. */
1553 if (current_binding_level->stmts)
1556 tree *var = &BLOCK_VARS (block);
1558 /* Copy decls from names list, ignoring labels. */
1561 tree next = TREE_CHAIN (decl);
1562 if (TREE_CODE (decl) != LABEL_DECL)
1565 var = &TREE_CHAIN (decl);
1571 bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
1572 BLOCK_EXPR_BODY (block), block);
1573 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1575 if (BIND_EXPR_BODY (bind)
1576 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1577 TREE_SIDE_EFFECTS (bind) = 1;
1579 /* FIXME: gimplifier brain damage. */
1580 if (BIND_EXPR_BODY (bind) == NULL)
1581 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1583 current_binding_level->stmts = NULL;
1587 BLOCK_VARS (block) = decls;
1589 BLOCK_SUBBLOCKS (block) = subblocks;
1592 /* In each subblock, record that this is its superior. */
1594 for (link = subblocks; link; link = TREE_CHAIN (link))
1595 BLOCK_SUPERCONTEXT (link) = block;
1597 /* Clear out the meanings of the local variables of this level. */
1599 for (link = decls; link; link = TREE_CHAIN (link))
1601 tree name = DECL_NAME (link);
1602 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1604 /* If the ident. was used or addressed via a local extern decl,
1605 don't forget that fact. */
1606 if (DECL_EXTERNAL (link))
1608 if (TREE_USED (link))
1609 TREE_USED (name) = 1;
1610 if (TREE_ADDRESSABLE (link))
1611 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1613 IDENTIFIER_LOCAL_VALUE (name) = 0;
1617 /* Restore all name-meanings of the outer levels
1618 that were shadowed by this level. */
1620 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1621 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1623 /* If the level being exited is the top level of a function,
1624 check over all the labels, and clear out the current
1625 (function local) meanings of their names. */
1629 /* If this is the top level block of a function,
1630 the vars are the function's parameters.
1631 Don't leave them in the BLOCK because they are
1632 found in the FUNCTION_DECL instead. */
1634 BLOCK_VARS (block) = 0;
1636 /* Clear out the definitions of all label names,
1637 since their scopes end here,
1638 and add them to BLOCK_VARS. */
1641 for (link = named_labels; link; link = TREE_CHAIN (link))
1643 tree label = TREE_VALUE (link);
1645 if (DECL_INITIAL (label) == 0)
1647 error ("%Jlabel '%D' used but not defined", label, label);
1648 /* Avoid crashing later. */
1649 define_label (input_location, DECL_NAME (label));
1651 else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
1652 warning ("%Jlabel '%D' defined but not used", label, label);
1653 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1655 /* Put the labels into the "variables" of the
1656 top-level block, so debugger can see them. */
1657 TREE_CHAIN (label) = BLOCK_VARS (block);
1658 BLOCK_VARS (block) = label;
1663 /* Pop the current level, and free the structure for reuse. */
1666 struct binding_level *level = current_binding_level;
1667 current_binding_level = current_binding_level->level_chain;
1669 level->level_chain = free_binding_level;
1670 free_binding_level = level;
1673 /* Dispose of the block that we just made inside some higher level. */
1676 DECL_INITIAL (current_function_decl) = block;
1677 DECL_SAVED_TREE (current_function_decl) = bind;
1683 current_binding_level->blocks
1684 = chainon (current_binding_level->blocks, block);
1686 /* If we did not make a block for the level just exited,
1687 any blocks made for inner levels
1688 (since they cannot be recorded as subblocks in that level)
1689 must be carried forward so they will later become subblocks
1690 of something else. */
1692 current_binding_level->blocks
1693 = chainon (current_binding_level->blocks, subblocks);
1696 java_add_stmt (bind);
1700 TREE_USED (block) = 1;
1705 maybe_pushlevels (int pc)
1707 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1711 while (pending_local_decls != NULL_TREE &&
1712 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1714 tree *ptr = &pending_local_decls;
1715 tree decl = *ptr, next;
1716 int end_pc = DECL_LOCAL_END_PC (decl);
1718 while (*ptr != NULL_TREE
1719 && DECL_LOCAL_START_PC (*ptr) <= pc
1720 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1721 ptr = &TREE_CHAIN (*ptr);
1722 pending_local_decls = *ptr;
1725 /* Force non-nested range to be nested in current range by
1726 truncating variable lifetimes. */
1727 if (end_pc > current_binding_level->end_pc)
1729 end_pc = current_binding_level->end_pc;
1730 DECL_LOCAL_END_PC (decl) = end_pc;
1733 maybe_start_try (pc, end_pc);
1737 current_binding_level->end_pc = end_pc;
1738 current_binding_level->start_pc = pc;
1739 current_binding_level->names = NULL;
1740 for ( ; decl != NULL_TREE; decl = next)
1742 next = TREE_CHAIN (decl);
1743 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1745 initialize_local_variable (decl, DECL_LOCAL_SLOT_NUMBER (decl));
1749 maybe_start_try (pc, 0);
1753 maybe_poplevels (int pc)
1755 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1759 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1760 inclusive, so a variable is live if pc == end_pc. Here, we
1761 terminate a range if the current pc is equal to the end of the
1762 range, and this is *before* we have generated code for the
1763 instruction at end_pc. We're closing a binding level one
1764 instruction too early.*/
1765 while (current_binding_level->end_pc <= pc)
1769 /* Terminate any binding which began during the range beginning at
1770 start_pc. This tidies up improperly nested local variable ranges
1771 and exception handlers; a variable declared within an exception
1772 range is forcibly terminated when that exception ends. */
1775 force_poplevels (int start_pc)
1777 while (current_binding_level->start_pc > start_pc)
1779 if (pedantic && current_binding_level->start_pc > start_pc)
1780 warning ("%JIn %D: overlapped variable and exception ranges at %d",
1781 current_function_decl, current_function_decl,
1782 current_binding_level->start_pc);
1787 /* Insert BLOCK at the end of the list of subblocks of the
1788 current binding level. This is used when a BIND_EXPR is expanded,
1789 to handle the BLOCK node inside the BIND_EXPR. */
1792 insert_block (tree block)
1794 TREE_USED (block) = 1;
1795 current_binding_level->blocks
1796 = chainon (current_binding_level->blocks, block);
1799 /* integrate_decl_tree calls this function. */
1802 java_dup_lang_specific_decl (tree node)
1805 struct lang_decl *x;
1807 if (!DECL_LANG_SPECIFIC (node))
1810 lang_decl_size = sizeof (struct lang_decl);
1811 x = ggc_alloc (lang_decl_size);
1812 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1813 DECL_LANG_SPECIFIC (node) = x;
1817 give_name_to_locals (JCF *jcf)
1819 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1820 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1822 pending_local_decls = NULL_TREE;
1826 n = JCF_readu2 (jcf);
1827 for (i = 0; i < n; i++)
1829 int start_pc = JCF_readu2 (jcf);
1830 int length = JCF_readu2 (jcf);
1831 int name_index = JCF_readu2 (jcf);
1832 int signature_index = JCF_readu2 (jcf);
1833 int slot = JCF_readu2 (jcf);
1834 tree name = get_name_constant (jcf, name_index);
1835 tree type = parse_signature (jcf, signature_index);
1836 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1838 && length == DECL_CODE_LENGTH (current_function_decl))
1840 tree decl = TREE_VEC_ELT (decl_map, slot);
1841 DECL_NAME (decl) = name;
1842 SET_DECL_ASSEMBLER_NAME (decl, name);
1843 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1844 warning ("bad type in parameter debug info");
1849 int end_pc = start_pc + length;
1850 tree decl = build_decl (VAR_DECL, name, type);
1851 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1853 warning ("%Jbad PC range for debug info for local '%D'",
1855 end_pc = DECL_CODE_LENGTH (current_function_decl);
1858 /* Adjust start_pc if necessary so that the local's first
1859 store operation will use the relevant DECL as a
1860 destination. Fore more information, read the leading
1861 comments for expr.c:maybe_adjust_start_pc. */
1862 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1864 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1865 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1866 DECL_LOCAL_START_PC (decl) = start_pc;
1868 /* FIXME: The range used internally for exceptions and local
1869 variable ranges, is a half-open interval:
1870 start_pc <= pc < end_pc. However, the range used in the
1871 Java VM spec is inclusive at both ends:
1872 start_pc <= pc <= end_pc. */
1875 DECL_LOCAL_END_PC (decl) = end_pc;
1877 /* Now insert the new decl in the proper place in
1878 pending_local_decls. We are essentially doing an insertion sort,
1879 which works fine, since the list input will normally already
1881 ptr = &pending_local_decls;
1882 while (*ptr != NULL_TREE
1883 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1884 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1885 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1886 ptr = &TREE_CHAIN (*ptr);
1887 TREE_CHAIN (decl) = *ptr;
1892 pending_local_decls = nreverse (pending_local_decls);
1894 /* Fill in default names for the parameters. */
1895 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1896 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1898 if (DECL_NAME (parm) == NULL_TREE)
1900 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1902 DECL_NAME (parm) = get_identifier ("this");
1906 sprintf (buffer, "ARG_%d", arg_i);
1907 DECL_NAME (parm) = get_identifier (buffer);
1909 SET_DECL_ASSEMBLER_NAME (parm, DECL_NAME (parm));
1915 build_result_decl (tree fndecl)
1917 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1918 tree result = DECL_RESULT (fndecl);
1921 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1922 if (INTEGRAL_TYPE_P (restype)
1923 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1924 restype = integer_type_node;
1925 result = build_decl (RESULT_DECL, NULL_TREE, restype);
1926 DECL_ARTIFICIAL (result) = 1;
1927 DECL_IGNORED_P (result) = 1;
1928 DECL_CONTEXT (result) = fndecl;
1929 DECL_RESULT (fndecl) = result;
1935 start_java_method (tree fndecl)
1942 current_function_decl = fndecl;
1943 announce_function (fndecl);
1945 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1946 decl_map = make_tree_vec (i);
1947 base_decl_map = make_tree_vec (i);
1948 type_map = xrealloc (type_map, i * sizeof (tree));
1950 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1951 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1953 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1954 pushlevel (1); /* Push parameters. */
1956 ptr = &DECL_ARGUMENTS (fndecl);
1957 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1958 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1960 tree parm_name = NULL_TREE, parm_decl;
1961 tree parm_type = TREE_VALUE (tem);
1962 if (i >= DECL_MAX_LOCALS (fndecl))
1965 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1966 DECL_CONTEXT (parm_decl) = fndecl;
1967 if (targetm.calls.promote_prototypes (parm_type)
1968 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1969 && INTEGRAL_TYPE_P (parm_type))
1970 parm_type = integer_type_node;
1971 DECL_ARG_TYPE (parm_decl) = parm_type;
1974 ptr = &TREE_CHAIN (parm_decl);
1976 /* Add parm_decl to the decl_map. */
1977 push_jvm_slot (i, parm_decl);
1979 type_map[i] = TREE_TYPE (parm_decl);
1980 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1983 type_map[i] = void_type_node;
1987 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1989 while (i < DECL_MAX_LOCALS(fndecl))
1990 type_map[i++] = NULL_TREE;
1992 build_result_decl (fndecl);
1994 /* Push local variables. */
1997 function_binding_level = current_binding_level;
2001 end_java_method (void)
2003 tree fndecl = current_function_decl;
2005 /* pop out of function */
2008 /* pop out of its parameters */
2011 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
2013 if (DECL_SAVED_TREE (fndecl))
2015 tree fbody, block_body;
2016 /* Before we check initialization, attached all class initialization
2017 variable to the block_body */
2018 fbody = DECL_SAVED_TREE (fndecl);
2019 block_body = BIND_EXPR_BODY (fbody);
2020 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
2021 attach_init_test_initialization_flags, block_body);
2024 flag_unit_at_a_time = 0;
2025 finish_method (fndecl);
2027 if (! flag_unit_at_a_time)
2029 /* Nulling these fields when we no longer need them saves
2031 DECL_SAVED_TREE (fndecl) = NULL;
2032 DECL_STRUCT_FUNCTION (fndecl) = NULL;
2033 DECL_INITIAL (fndecl) = NULL_TREE;
2035 current_function_decl = NULL_TREE;
2038 /* Prepare a method for expansion. */
2041 finish_method (tree fndecl)
2043 tree *tp = &DECL_SAVED_TREE (fndecl);
2045 /* Wrap body of synchronized methods in a monitorenter,
2046 plus monitorexit cleanup. */
2047 if (METHOD_SYNCHRONIZED (fndecl))
2049 tree enter, exit, lock;
2050 if (METHOD_STATIC (fndecl))
2051 lock = build_class_ref (DECL_CONTEXT (fndecl));
2053 lock = DECL_ARGUMENTS (fndecl);
2054 BUILD_MONITOR_ENTER (enter, lock);
2055 BUILD_MONITOR_EXIT (exit, lock);
2056 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
2057 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
2060 /* Ensure non-abstract non-static non-private members are defined only once
2061 when linking. This is an issue when using CNI to interface with C++ object
2063 if (! METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
2064 && ! METHOD_ABSTRACT (fndecl) && ! METHOD_FINAL (fndecl))
2065 make_decl_one_only (fndecl);
2067 /* Prepend class initialization for static methods reachable from
2069 if (METHOD_STATIC (fndecl)
2070 && (! METHOD_PRIVATE (fndecl)
2071 || INNER_CLASS_P (DECL_CONTEXT (fndecl)))
2072 && ! DECL_CLINIT_P (fndecl)
2073 && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl))))
2075 tree clas = DECL_CONTEXT (fndecl);
2076 tree init = build3 (CALL_EXPR, void_type_node,
2077 build_address_of (soft_initclass_node),
2078 build_tree_list (NULL_TREE, build_class_ref (clas)),
2080 *tp = build2 (COMPOUND_EXPR, TREE_TYPE (*tp), init, *tp);
2083 /* Convert function tree to GENERIC prior to inlining. */
2084 java_genericize (fndecl);
2086 /* Store the end of the function, so that we get good line number
2087 info for the epilogue. */
2088 if (DECL_STRUCT_FUNCTION (fndecl))
2089 cfun = DECL_STRUCT_FUNCTION (fndecl);
2091 allocate_struct_function (fndecl);
2092 #ifdef USE_MAPPED_LOCATION
2093 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
2095 cfun->function_end_locus.file = DECL_SOURCE_FILE (fndecl);
2096 cfun->function_end_locus.line = DECL_FUNCTION_LAST_LINE (fndecl);
2099 /* Defer inlining and expansion to the cgraph optimizers. */
2100 cgraph_finalize_function (fndecl, false);
2103 /* Optimize and expand a function's entire body. */
2106 java_expand_body (tree fndecl)
2108 tree_rest_of_compilation (fndecl);
2111 /* We pessimistically marked all methods and fields external until we
2112 knew what set of classes we were planning to compile. Now mark those
2113 associated with CLASS to be generated locally as not external. */
2116 java_mark_decl_local (tree decl)
2118 DECL_EXTERNAL (decl) = 0;
2120 /* If we've already constructed DECL_RTL, give encode_section_info
2121 a second chance, now that we've changed the flags. */
2122 if (DECL_RTL_SET_P (decl))
2123 make_decl_rtl (decl);
2127 java_mark_class_local (tree class)
2131 for (t = TYPE_FIELDS (class); t ; t = TREE_CHAIN (t))
2132 if (FIELD_STATIC (t))
2133 java_mark_decl_local (t);
2135 for (t = TYPE_METHODS (class); t ; t = TREE_CHAIN (t))
2136 if (!METHOD_ABSTRACT (t) && (!METHOD_NATIVE (t) || flag_jni))
2137 java_mark_decl_local (t);
2140 /* Add a statement to a compound_expr. */
2143 add_stmt_to_compound (tree existing, tree type, tree stmt)
2149 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
2150 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
2151 | TREE_SIDE_EFFECTS (stmt);
2158 /* Add a statement to the compound_expr currently being
2162 java_add_stmt (tree stmt)
2165 SET_EXPR_LOCATION (stmt, input_location);
2167 return current_binding_level->stmts
2168 = add_stmt_to_compound (current_binding_level->stmts,
2169 TREE_TYPE (stmt), stmt);
2172 /* Add a variable to the current scope. */
2175 java_add_local_var (tree decl)
2177 tree *vars = ¤t_binding_level->names;
2179 TREE_CHAIN (decl) = next;
2181 DECL_CONTEXT (decl) = current_function_decl;
2182 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2186 /* Return a pointer to the compound_expr currently being
2192 return ¤t_binding_level->stmts;
2195 /* Register an exception range as belonging to the current binding
2196 level. There may only be one: if there are more, we'll create more
2197 binding levels. However, each range can have multiple handlers,
2198 and these are expanded when we call expand_end_java_handler(). */
2201 register_exception_range (struct eh_range *range, int pc, int end_pc)
2203 if (current_binding_level->exception_range)
2205 current_binding_level->exception_range = range;
2206 current_binding_level->end_pc = end_pc;
2207 current_binding_level->start_pc = pc;
2210 #include "gt-java-decl.h"