1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
4 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
30 #include "coretypes.h"
37 #include "java-tree.h"
43 #include "java-except.h"
47 #include "tree-inline.h"
50 #include "tree-iterator.h"
51 #include "langhooks.h"
54 #if defined (DEBUG_JAVA_BINDING_LEVELS)
55 extern void indent (void);
58 static tree push_jvm_slot (int, tree);
59 static tree lookup_name_current_level (tree);
60 static tree push_promoted_type (const char *, tree);
61 static struct binding_level *make_binding_level (void);
62 static tree create_primitive_vtable (const char *);
63 static tree check_local_unnamed_variable (tree, tree, tree);
64 static void parse_version (void);
67 /* The following ABI flags are used in the high-order bits of the version
68 ID field. The version ID number itself should never be larger than
69 0xfffff, so it should be safe to use top 12 bits for these flags. */
71 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
73 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
74 should be loaded by the bootstrap
77 /* If an ABI change is made within a GCC release series, rendering current
78 binaries incompatible with the old runtimes, this number must be set to
79 enforce the compatibility rules. */
80 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
82 /* The runtime may recognize a variety of BC ABIs (objects generated by
83 different version of gcj), but will probably always require strict
84 matching for the ordinary (C++) ABI. */
86 /* The version ID of the BC ABI that we generate. This must be kept in
87 sync with parse_version(), libgcj, and reality (if the BC format changes,
89 #define GCJ_CURRENT_BC_ABI_VERSION \
90 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
92 /* The ABI version number. */
95 /* Name of the Cloneable class. */
96 tree java_lang_cloneable_identifier_node;
98 /* Name of the Serializable class. */
99 tree java_io_serializable_identifier_node;
101 /* The DECL_MAP is a mapping from (index, type) to a decl node.
102 If index < max_locals, it is the index of a local variable.
103 if index >= max_locals, then index-max_locals is a stack slot.
104 The DECL_MAP mapping is represented as a TREE_VEC whose elements
105 are a list of decls (VAR_DECL or PARM_DECL) chained by
106 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
107 we search the chain for a decl with a matching TREE_TYPE. */
109 static GTY(()) tree decl_map;
111 /* The base_decl_map is contains one variable of ptr_type: this is
112 used to contain every variable of reference type that is ever
113 stored in a local variable slot. */
115 static GTY(()) tree base_decl_map;
117 /* An index used to make temporary identifiers unique. */
120 /* A list of local variables VAR_DECLs for this method that we have seen
121 debug information, but we have not reached their starting (byte) PC yet. */
123 static GTY(()) tree pending_local_decls;
125 /* The decl for "_Jv_ResolvePoolEntry". */
126 tree soft_resolvepoolentry_node;
128 /* The decl for the .constants field of an instance of Class. */
129 tree constants_field_decl_node;
131 /* The decl for the .data field of an instance of Class. */
132 tree constants_data_field_decl_node;
134 #if defined(DEBUG_JAVA_BINDING_LEVELS)
135 int binding_depth = 0;
136 int is_class_level = 0;
144 for (i = 0; i < binding_depth*2; i++)
147 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
149 /* True if decl is a named local variable, i.e. if it is an alias
150 that's used only for debugging purposes. */
153 debug_variable_p (tree decl)
155 if (TREE_CODE (decl) == PARM_DECL)
158 if (LOCAL_SLOT_P (decl))
165 push_jvm_slot (int index, tree decl)
167 DECL_CONTEXT (decl) = current_function_decl;
168 layout_decl (decl, 0);
170 /* Now link the decl into the decl_map. */
171 if (DECL_LANG_SPECIFIC (decl) == NULL)
173 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
174 DECL_LOCAL_START_PC (decl) = 0;
175 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
176 DECL_LOCAL_SLOT_NUMBER (decl) = index;
178 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
179 TREE_VEC_ELT (decl_map, index) = decl;
184 /* Find the best declaration based upon type. If 'decl' fits 'type' better
185 than 'best', return 'decl'. Otherwise return 'best'. */
188 check_local_unnamed_variable (tree best, tree decl, tree type)
190 tree decl_type = TREE_TYPE (decl);
192 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
194 /* Use the same decl for all integer types <= 32 bits. This is
195 necessary because sometimes a value is stored as (for example)
196 boolean but loaded as int. */
197 if (decl_type == type
198 || (INTEGRAL_TYPE_P (decl_type)
199 && INTEGRAL_TYPE_P (type)
200 && TYPE_PRECISION (decl_type) <= 32
201 && TYPE_PRECISION (type) <= 32
202 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
203 /* ptr_type_node is used for null pointers, which are
204 assignment compatible with everything. */
205 || (TREE_CODE (decl_type) == POINTER_TYPE
206 && type == ptr_type_node)
207 /* Whenever anyone wants to use a slot that is initially
208 occupied by a PARM_DECL of pointer type they must get that
209 decl, even if they asked for a pointer to a different type.
210 However, if someone wants a scalar variable in a slot that
211 initially held a pointer arg -- or vice versa -- we create a
214 ???: As long as verification is correct, this will be a
215 compatible type. But maybe we should create a dummy variable
216 and replace all references to it with the DECL and a
219 || (TREE_CODE (decl_type) == POINTER_TYPE
220 && TREE_CODE (decl) == PARM_DECL
221 && TREE_CODE (type) == POINTER_TYPE))
223 if (best == NULL_TREE
224 || (decl_type == type && TREE_TYPE (best) != type))
232 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
233 that is valid at PC (or -1 if any pc).
234 If there is no existing matching decl, allocate one. */
237 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
239 tree tmp = TREE_VEC_ELT (decl_map, index);
240 tree decl = NULL_TREE;
242 /* Scan through every declaration that has been created in this
243 slot. We're only looking for variables that correspond to local
244 index declarations and PARM_DECLs, not named variables: such
245 local variables are used only for debugging information. */
246 while (tmp != NULL_TREE)
248 if (! debug_variable_p (tmp))
249 decl = check_local_unnamed_variable (decl, tmp, type);
250 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
253 /* gcj has a function called promote_type(), which is used by both
254 the bytecode compiler and the source compiler. Unfortunately,
255 the type systems for the Java VM and the Java language are not
256 the same: a boolean in the VM promotes to an int, not to a wide
257 boolean. If our caller wants something to hold a boolean, that
258 had better be an int, because that slot might be re-used
259 later in integer context. */
260 if (TREE_CODE (type) == BOOLEAN_TYPE)
261 type = integer_type_node;
263 /* If we don't find a match, create one with the type passed in.
264 The name of the variable is #n#m, which n is the variable index
265 in the local variable area and m is a dummy identifier for
266 uniqueness -- multiple variables may share the same local
267 variable index. We don't call pushdecl() to push pointer types
268 into a binding expr because they'll all be replaced by a single
269 variable that is used for every reference in that local variable
275 sprintf (buf, "#slot#%d#%d", index, uniq++);
276 name = get_identifier (buf);
277 decl = build_decl (input_location, VAR_DECL, name, type);
278 DECL_IGNORED_P (decl) = 1;
279 DECL_ARTIFICIAL (decl) = 1;
280 decl = push_jvm_slot (index, decl);
281 LOCAL_SLOT_P (decl) = 1;
283 if (TREE_CODE (type) != POINTER_TYPE)
284 pushdecl_function_level (decl);
287 /* As well as creating a local variable that matches the type, we
288 also create a base variable (of ptr_type) that will hold all its
290 if (TREE_CODE (type) == POINTER_TYPE
291 && ! TREE_VEC_ELT (base_decl_map, index))
296 sprintf (buf, "#ref#%d#%d", index, uniq++);
297 name = get_identifier (buf);
299 = TREE_VEC_ELT (base_decl_map, index)
300 = build_decl (input_location, VAR_DECL, name, ptr_type_node);
301 pushdecl_function_level (base_decl);
302 DECL_IGNORED_P (base_decl) = 1;
303 DECL_ARTIFICIAL (base_decl) = 1;
309 /* Called during genericization for every variable. If the variable
310 is a temporary of pointer type, replace it with a common variable
311 thath is used to hold all pointer types that are ever stored in
312 that slot. Set WANT_LVALUE if you want a variable that is to be
316 java_replace_reference (tree var_decl, bool want_lvalue)
323 decl_type = TREE_TYPE (var_decl);
325 if (TREE_CODE (decl_type) == POINTER_TYPE)
327 if (DECL_LANG_SPECIFIC (var_decl)
328 && LOCAL_SLOT_P (var_decl))
330 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
331 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
333 gcc_assert (base_decl);
335 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
344 /* Helper for java_genericize. */
347 java_replace_references (tree *tp, int *walk_subtrees,
348 void *data ATTRIBUTE_UNUSED)
350 if (TREE_CODE (*tp) == MODIFY_EXPR)
352 source_location loc = EXPR_LOCATION (*tp);
353 tree lhs = TREE_OPERAND (*tp, 0);
354 /* This is specific to the bytecode compiler. If a variable has
355 LOCAL_SLOT_P set, replace an assignment to it with an assignment
356 to the corresponding variable that holds all its aliases. */
357 if (TREE_CODE (lhs) == VAR_DECL
358 && DECL_LANG_SPECIFIC (lhs)
359 && LOCAL_SLOT_P (lhs)
360 && TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE)
362 tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
363 tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs),
364 TREE_OPERAND (*tp, 1));
365 tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
367 *tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem);
368 SET_EXPR_LOCATION (tem, loc);
369 SET_EXPR_LOCATION (new_rhs, loc);
370 SET_EXPR_LOCATION (*tp, loc);
373 if (TREE_CODE (*tp) == VAR_DECL)
375 *tp = java_replace_reference (*tp, /* want_lvalue */ false);
382 /* Same as find_local_index, except that INDEX is a stack index. */
385 find_stack_slot (int index, tree type)
387 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
393 /* A chain of _DECL nodes for all variables, constants, functions,
394 * and typedef types. These are in the reverse of the order supplied.
398 /* For each level, a list of shadowed outer-level local definitions
399 to be restored when this level is popped.
400 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
401 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
404 /* For each level (except not the global one),
405 a chain of BLOCK nodes for all the levels
406 that were entered and exited one level down. */
409 /* The binding level which this one is contained in (inherits from). */
410 struct binding_level *level_chain;
412 /* The bytecode PC that marks the end of this level. */
414 /* The bytecode PC that marks the start of this level. */
417 /* The statements in this binding level. */
420 /* An exception range associated with this binding level. */
421 struct eh_range * GTY((skip (""))) exception_range;
423 /* Binding depth at which this level began. Used only for debugging. */
424 unsigned binding_depth;
426 /* The location at which this level began. */
430 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
432 /* The binding level currently in effect. */
434 static GTY(()) struct binding_level *current_binding_level;
436 /* A chain of binding_level structures awaiting reuse. */
438 static GTY(()) struct binding_level *free_binding_level;
440 /* The outermost binding level, for names of file scope.
441 This is created when the compiler is started and exists
442 through the entire run. */
444 static GTY(()) struct binding_level *global_binding_level;
446 /* The binding level that holds variables declared at the outermost
447 level within a function body. */
449 static struct binding_level *function_binding_level;
451 /* A PC value bigger than any PC value we may ever may encounter. */
453 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
455 /* Binding level structures are initialized by copying this one. */
457 static const struct binding_level clear_binding_level
459 NULL_TREE, /* names */
460 NULL_TREE, /* shadowed */
461 NULL_TREE, /* blocks */
462 NULL_BINDING_LEVEL, /* level_chain */
463 LARGEST_PC, /* end_pc */
466 NULL, /* exception_range */
467 0, /* binding_depth */
471 tree java_global_trees[JTI_MAX];
473 /* Build (and pushdecl) a "promoted type" for all standard
474 types shorter than int. */
477 push_promoted_type (const char *name, tree actual_type)
479 tree type = make_node (TREE_CODE (actual_type));
481 tree in_min = TYPE_MIN_VALUE (int_type_node);
482 tree in_max = TYPE_MAX_VALUE (int_type_node);
484 tree in_min = TYPE_MIN_VALUE (actual_type);
485 tree in_max = TYPE_MAX_VALUE (actual_type);
487 TYPE_MIN_VALUE (type) = copy_node (in_min);
488 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
489 TYPE_MAX_VALUE (type) = copy_node (in_max);
490 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
491 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
492 TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
494 pushdecl (build_decl (input_location,
495 TYPE_DECL, get_identifier (name), type));
499 /* Return tree that represents a vtable for a primitive array. */
501 create_primitive_vtable (const char *name)
506 sprintf (buf, "_Jv_%sVTable", name);
507 r = build_decl (input_location,
508 VAR_DECL, get_identifier (buf), ptr_type_node);
509 DECL_EXTERNAL (r) = 1;
519 /* Parse the version string and compute the ABI version number. */
523 const char *p = version_string;
524 unsigned int major = 0, minor = 0;
525 unsigned int abi_version;
527 /* Skip leading junk. */
528 while (*p && !ISDIGIT (*p))
532 /* Extract major version. */
535 major = major * 10 + *p - '0';
539 gcc_assert (*p == '.' && ISDIGIT (p[1]));
542 /* Extract minor version. */
545 minor = minor * 10 + *p - '0';
549 if (flag_indirect_dispatch)
551 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
552 abi_version |= FLAG_BINARYCOMPAT_ABI;
556 /* Implicit in this computation is the idea that we won't break the
557 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
559 abi_version = 100000 * major + 1000 * minor;
561 if (flag_bootstrap_classes)
562 abi_version |= FLAG_BOOTSTRAP_LOADER;
564 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
568 java_init_decl_processing (void)
571 tree field = NULL_TREE;
574 init_class_processing ();
576 current_function_decl = NULL;
577 current_binding_level = NULL_BINDING_LEVEL;
578 free_binding_level = NULL_BINDING_LEVEL;
579 pushlevel (0); /* make the binding_level structure for global names */
580 global_binding_level = current_binding_level;
582 /* The code here must be similar to build_common_tree_nodes{,_2} in
583 tree.c, especially as to the order of initializing common nodes. */
584 error_mark_node = make_node (ERROR_MARK);
585 TREE_TYPE (error_mark_node) = error_mark_node;
587 /* Create sizetype first - needed for other types. */
588 initialize_sizetypes (false);
590 byte_type_node = make_signed_type (8);
591 pushdecl (build_decl (BUILTINS_LOCATION,
592 TYPE_DECL, get_identifier ("byte"), byte_type_node));
593 short_type_node = make_signed_type (16);
594 pushdecl (build_decl (BUILTINS_LOCATION,
595 TYPE_DECL, get_identifier ("short"), short_type_node));
596 int_type_node = make_signed_type (32);
597 pushdecl (build_decl (BUILTINS_LOCATION,
598 TYPE_DECL, get_identifier ("int"), int_type_node));
599 long_type_node = make_signed_type (64);
600 pushdecl (build_decl (BUILTINS_LOCATION,
601 TYPE_DECL, get_identifier ("long"), long_type_node));
603 unsigned_byte_type_node = make_unsigned_type (8);
604 pushdecl (build_decl (BUILTINS_LOCATION,
605 TYPE_DECL, get_identifier ("unsigned byte"),
606 unsigned_byte_type_node));
607 unsigned_short_type_node = make_unsigned_type (16);
608 pushdecl (build_decl (BUILTINS_LOCATION,
609 TYPE_DECL, get_identifier ("unsigned short"),
610 unsigned_short_type_node));
611 unsigned_int_type_node = make_unsigned_type (32);
612 pushdecl (build_decl (BUILTINS_LOCATION,
613 TYPE_DECL, get_identifier ("unsigned int"),
614 unsigned_int_type_node));
615 unsigned_long_type_node = make_unsigned_type (64);
616 pushdecl (build_decl (BUILTINS_LOCATION,
617 TYPE_DECL, get_identifier ("unsigned long"),
618 unsigned_long_type_node));
620 /* This is not a java type, however tree-dfa requires a definition for
622 size_type_node = make_unsigned_type (POINTER_SIZE);
623 set_sizetype (size_type_node);
625 /* Define these next since types below may used them. */
626 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
627 integer_zero_node = build_int_cst (NULL_TREE, 0);
628 integer_one_node = build_int_cst (NULL_TREE, 1);
629 integer_two_node = build_int_cst (NULL_TREE, 2);
630 integer_four_node = build_int_cst (NULL_TREE, 4);
631 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
633 /* A few values used for range checking in the lexer. */
634 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
635 #if HOST_BITS_PER_WIDE_INT == 64
636 decimal_long_max = build_int_cstu (unsigned_long_type_node,
637 0x8000000000000000LL);
638 #elif HOST_BITS_PER_WIDE_INT == 32
639 decimal_long_max = build_int_cst_wide (unsigned_long_type_node,
642 #error "unsupported size"
645 size_zero_node = size_int (0);
646 size_one_node = size_int (1);
647 bitsize_zero_node = bitsize_int (0);
648 bitsize_one_node = bitsize_int (1);
649 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
651 long_zero_node = build_int_cst (long_type_node, 0);
653 void_type_node = make_node (VOID_TYPE);
654 pushdecl (build_decl (BUILTINS_LOCATION,
655 TYPE_DECL, get_identifier ("void"), void_type_node));
656 layout_type (void_type_node); /* Uses size_zero_node */
658 ptr_type_node = build_pointer_type (void_type_node);
660 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
662 t = make_node (VOID_TYPE);
663 layout_type (t); /* Uses size_zero_node */
664 return_address_type_node = build_pointer_type (t);
666 null_pointer_node = build_int_cst (ptr_type_node, 0);
668 char_type_node = make_node (INTEGER_TYPE);
669 TYPE_STRING_FLAG (char_type_node) = 1;
670 TYPE_PRECISION (char_type_node) = 16;
671 fixup_unsigned_type (char_type_node);
672 pushdecl (build_decl (BUILTINS_LOCATION,
673 TYPE_DECL, get_identifier ("char"), char_type_node));
675 boolean_type_node = make_node (BOOLEAN_TYPE);
676 TYPE_PRECISION (boolean_type_node) = 1;
677 fixup_unsigned_type (boolean_type_node);
678 pushdecl (build_decl (BUILTINS_LOCATION,
679 TYPE_DECL, get_identifier ("boolean"),
681 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
682 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
684 promoted_byte_type_node
685 = push_promoted_type ("promoted_byte", byte_type_node);
686 promoted_short_type_node
687 = push_promoted_type ("promoted_short", short_type_node);
688 promoted_char_type_node
689 = push_promoted_type ("promoted_char", char_type_node);
690 promoted_boolean_type_node
691 = push_promoted_type ("promoted_boolean", boolean_type_node);
693 float_type_node = make_node (REAL_TYPE);
694 TYPE_PRECISION (float_type_node) = 32;
695 pushdecl (build_decl (BUILTINS_LOCATION,
696 TYPE_DECL, get_identifier ("float"),
698 layout_type (float_type_node);
700 double_type_node = make_node (REAL_TYPE);
701 TYPE_PRECISION (double_type_node) = 64;
702 pushdecl (build_decl (BUILTINS_LOCATION,
703 TYPE_DECL, get_identifier ("double"),
705 layout_type (double_type_node);
707 float_zero_node = build_real (float_type_node, dconst0);
708 double_zero_node = build_real (double_type_node, dconst0);
710 /* These are the vtables for arrays of primitives. */
711 boolean_array_vtable = create_primitive_vtable ("boolean");
712 byte_array_vtable = create_primitive_vtable ("byte");
713 char_array_vtable = create_primitive_vtable ("char");
714 short_array_vtable = create_primitive_vtable ("short");
715 int_array_vtable = create_primitive_vtable ("int");
716 long_array_vtable = create_primitive_vtable ("long");
717 float_array_vtable = create_primitive_vtable ("float");
718 double_array_vtable = create_primitive_vtable ("double");
720 one_elt_array_domain_type = build_index_type (integer_one_node);
721 utf8const_type = make_node (RECORD_TYPE);
722 PUSH_FIELD (input_location,
723 utf8const_type, field, "hash", unsigned_short_type_node);
724 PUSH_FIELD (input_location,
725 utf8const_type, field, "length", unsigned_short_type_node);
726 FINISH_RECORD (utf8const_type);
727 utf8const_ptr_type = build_pointer_type (utf8const_type);
729 atable_type = build_array_type (ptr_type_node,
730 one_elt_array_domain_type);
731 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
732 atable_ptr_type = build_pointer_type (atable_type);
734 itable_type = build_array_type (ptr_type_node,
735 one_elt_array_domain_type);
736 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
737 itable_ptr_type = build_pointer_type (itable_type);
739 symbol_type = make_node (RECORD_TYPE);
740 PUSH_FIELD (input_location,
741 symbol_type, field, "clname", utf8const_ptr_type);
742 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
743 PUSH_FIELD (input_location,
744 symbol_type, field, "signature", utf8const_ptr_type);
745 FINISH_RECORD (symbol_type);
747 symbols_array_type = build_array_type (symbol_type,
748 one_elt_array_domain_type);
749 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
751 assertion_entry_type = make_node (RECORD_TYPE);
752 PUSH_FIELD (input_location,
753 assertion_entry_type, field, "assertion_code", integer_type_node);
754 PUSH_FIELD (input_location,
755 assertion_entry_type, field, "op1", utf8const_ptr_type);
756 PUSH_FIELD (input_location,
757 assertion_entry_type, field, "op2", utf8const_ptr_type);
758 FINISH_RECORD (assertion_entry_type);
760 assertion_table_type = build_array_type (assertion_entry_type,
761 one_elt_array_domain_type);
763 /* As you're adding items here, please update the code right after
764 this section, so that the filename containing the source code of
765 the pre-defined class gets registered correctly. */
766 unqualified_object_id_node = get_identifier ("Object");
767 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
768 object_ptr_type_node = promote_type (object_type_node);
769 string_type_node = lookup_class (get_identifier ("java.lang.String"));
770 string_ptr_type_node = promote_type (string_type_node);
771 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
772 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
773 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
774 runtime_exception_type_node =
775 lookup_class (get_identifier ("java.lang.RuntimeException"));
776 error_exception_type_node =
777 lookup_class (get_identifier ("java.lang.Error"));
779 rawdata_ptr_type_node
780 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
782 add_predefined_file (get_identifier ("java/lang/Class.java"));
783 add_predefined_file (get_identifier ("java/lang/Error.java"));
784 add_predefined_file (get_identifier ("java/lang/Object.java"));
785 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
786 add_predefined_file (get_identifier ("java/lang/String.java"));
787 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
788 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
789 add_predefined_file (get_identifier ("java/lang/Exception.java"));
790 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
791 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
793 methodtable_type = make_node (RECORD_TYPE);
794 layout_type (methodtable_type);
795 build_decl (BUILTINS_LOCATION,
796 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
797 methodtable_ptr_type = build_pointer_type (methodtable_type);
799 TYPE_identifier_node = get_identifier ("TYPE");
800 init_identifier_node = get_identifier ("<init>");
801 clinit_identifier_node = get_identifier ("<clinit>");
802 void_signature_node = get_identifier ("()V");
803 finalize_identifier_node = get_identifier ("finalize");
804 this_identifier_node = get_identifier ("this");
806 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
807 java_io_serializable_identifier_node =
808 get_identifier ("java.io.Serializable");
810 /* for lack of a better place to put this stub call */
811 init_expr_processing();
813 constants_type_node = make_node (RECORD_TYPE);
814 PUSH_FIELD (input_location,
815 constants_type_node, field, "size", unsigned_int_type_node);
816 PUSH_FIELD (input_location,
817 constants_type_node, field, "tags", ptr_type_node);
818 PUSH_FIELD (input_location,
819 constants_type_node, field, "data", ptr_type_node);
820 constants_data_field_decl_node = field;
821 FINISH_RECORD (constants_type_node);
822 build_decl (BUILTINS_LOCATION,
823 TYPE_DECL, get_identifier ("constants"), constants_type_node);
825 access_flags_type_node = unsigned_short_type_node;
827 dtable_type = make_node (RECORD_TYPE);
828 dtable_ptr_type = build_pointer_type (dtable_type);
830 otable_type = build_array_type (integer_type_node,
831 one_elt_array_domain_type);
832 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
833 otable_ptr_type = build_pointer_type (otable_type);
835 PUSH_FIELD (input_location,
836 object_type_node, field, "vtable", dtable_ptr_type);
837 DECL_FCONTEXT (field) = object_type_node;
838 TYPE_VFIELD (object_type_node) = field;
840 /* This isn't exactly true, but it is what we have in the source.
841 There is an unresolved issue here, which is whether the vtable
842 should be marked by the GC. */
843 if (! flag_hash_synchronization)
844 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
845 build_pointer_type (object_type_node));
846 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
847 FIELD_PRIVATE (t) = 1;
848 FINISH_RECORD (object_type_node);
850 field_type_node = make_node (RECORD_TYPE);
851 field_ptr_type_node = build_pointer_type (field_type_node);
852 method_type_node = make_node (RECORD_TYPE);
853 method_ptr_type_node = build_pointer_type (method_type_node);
855 set_super_info (0, class_type_node, object_type_node, 0);
856 set_super_info (0, string_type_node, object_type_node, 0);
857 class_ptr_type = build_pointer_type (class_type_node);
859 PUSH_FIELD (input_location,
860 class_type_node, field, "next_or_version", class_ptr_type);
861 PUSH_FIELD (input_location,
862 class_type_node, field, "name", utf8const_ptr_type);
863 PUSH_FIELD (input_location,
864 class_type_node, field, "accflags", access_flags_type_node);
865 PUSH_FIELD (input_location,
866 class_type_node, field, "superclass", class_ptr_type);
867 PUSH_FIELD (input_location,
868 class_type_node, field, "constants", constants_type_node);
869 constants_field_decl_node = field;
870 PUSH_FIELD (input_location,
871 class_type_node, field, "methods", method_ptr_type_node);
872 PUSH_FIELD (input_location,
873 class_type_node, field, "method_count", short_type_node);
874 PUSH_FIELD (input_location,
875 class_type_node, field, "vtable_method_count", short_type_node);
876 PUSH_FIELD (input_location,
877 class_type_node, field, "fields", field_ptr_type_node);
878 PUSH_FIELD (input_location,
879 class_type_node, field, "size_in_bytes", int_type_node);
880 PUSH_FIELD (input_location,
881 class_type_node, field, "field_count", short_type_node);
882 PUSH_FIELD (input_location,
883 class_type_node, field, "static_field_count", short_type_node);
884 PUSH_FIELD (input_location,
885 class_type_node, field, "vtable", dtable_ptr_type);
886 PUSH_FIELD (input_location,
887 class_type_node, field, "otable", otable_ptr_type);
888 PUSH_FIELD (input_location,
889 class_type_node, field, "otable_syms",
890 symbols_array_ptr_type);
891 PUSH_FIELD (input_location,
892 class_type_node, field, "atable", atable_ptr_type);
893 PUSH_FIELD (input_location,
894 class_type_node, field, "atable_syms",
895 symbols_array_ptr_type);
896 PUSH_FIELD (input_location,
897 class_type_node, field, "itable", itable_ptr_type);
898 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
899 symbols_array_ptr_type);
900 PUSH_FIELD (input_location,
901 class_type_node, field, "catch_classes", ptr_type_node);
902 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
903 build_pointer_type (class_ptr_type));
904 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
905 PUSH_FIELD (input_location,
906 class_type_node, field, "interface_count", short_type_node);
907 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
908 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
909 PUSH_FIELD (input_location,
910 class_type_node, field, "depth", short_type_node);
911 PUSH_FIELD (input_location,
912 class_type_node, field, "ancestors", ptr_type_node);
913 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
914 PUSH_FIELD (input_location,
915 class_type_node, field, "arrayclass", ptr_type_node);
916 PUSH_FIELD (input_location,
917 class_type_node, field, "protectionDomain", ptr_type_node);
918 PUSH_FIELD (input_location,
919 class_type_node, field, "assertion_table", ptr_type_node);
920 PUSH_FIELD (input_location,
921 class_type_node, field, "hack_signers", ptr_type_node);
922 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
923 PUSH_FIELD (input_location,
924 class_type_node, field, "aux_info", ptr_type_node);
925 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
926 PUSH_FIELD (input_location,
927 class_type_node, field, "reflection_data", ptr_type_node);
928 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
929 FIELD_PRIVATE (t) = 1;
930 push_super_field (class_type_node, object_type_node);
932 FINISH_RECORD (class_type_node);
933 build_decl (BUILTINS_LOCATION,
934 TYPE_DECL, get_identifier ("Class"), class_type_node);
936 field_info_union_node = make_node (UNION_TYPE);
937 PUSH_FIELD (input_location,
938 field_info_union_node, field, "boffset", int_type_node);
939 PUSH_FIELD (input_location,
940 field_info_union_node, field, "addr", ptr_type_node);
941 layout_type (field_info_union_node);
943 PUSH_FIELD (input_location,
944 field_type_node, field, "name", utf8const_ptr_type);
945 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
946 PUSH_FIELD (input_location,
947 field_type_node, field, "accflags", access_flags_type_node);
948 PUSH_FIELD (input_location,
949 field_type_node, field, "bsize", unsigned_short_type_node);
950 PUSH_FIELD (input_location,
951 field_type_node, field, "info", field_info_union_node);
952 FINISH_RECORD (field_type_node);
953 build_decl (BUILTINS_LOCATION,
954 TYPE_DECL, get_identifier ("Field"), field_type_node);
956 nativecode_ptr_array_type_node
957 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
959 PUSH_FIELD (input_location,
960 dtable_type, field, "class", class_ptr_type);
961 PUSH_FIELD (input_location,
962 dtable_type, field, "methods", nativecode_ptr_array_type_node);
963 FINISH_RECORD (dtable_type);
964 build_decl (BUILTINS_LOCATION,
965 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
967 jexception_type = make_node (RECORD_TYPE);
968 PUSH_FIELD (input_location,
969 jexception_type, field, "start_pc", ptr_type_node);
970 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
971 PUSH_FIELD (input_location,
972 jexception_type, field, "handler_pc", ptr_type_node);
973 PUSH_FIELD (input_location,
974 jexception_type, field, "catch_type", class_ptr_type);
975 FINISH_RECORD (jexception_type);
976 build_decl (BUILTINS_LOCATION,
977 TYPE_DECL, get_identifier ("jexception"), field_type_node);
978 jexception_ptr_type = build_pointer_type (jexception_type);
980 lineNumberEntry_type = make_node (RECORD_TYPE);
981 PUSH_FIELD (input_location,
982 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
983 PUSH_FIELD (input_location,
984 lineNumberEntry_type, field, "start_pc", ptr_type_node);
985 FINISH_RECORD (lineNumberEntry_type);
987 lineNumbers_type = make_node (RECORD_TYPE);
988 PUSH_FIELD (input_location,
989 lineNumbers_type, field, "length", unsigned_int_type_node);
990 FINISH_RECORD (lineNumbers_type);
992 PUSH_FIELD (input_location,
993 method_type_node, field, "name", utf8const_ptr_type);
994 PUSH_FIELD (input_location,
995 method_type_node, field, "signature", utf8const_ptr_type);
996 PUSH_FIELD (input_location,
997 method_type_node, field, "accflags", access_flags_type_node);
998 PUSH_FIELD (input_location,
999 method_type_node, field, "index", unsigned_short_type_node);
1000 PUSH_FIELD (input_location,
1001 method_type_node, field, "ncode", nativecode_ptr_type_node);
1002 PUSH_FIELD (input_location,
1003 method_type_node, field, "throws", ptr_type_node);
1004 FINISH_RECORD (method_type_node);
1005 build_decl (BUILTINS_LOCATION,
1006 TYPE_DECL, get_identifier ("Method"), method_type_node);
1008 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
1010 t = tree_cons (NULL_TREE, class_ptr_type, endlink);
1011 alloc_object_node = add_builtin_function ("_Jv_AllocObject",
1012 build_function_type (ptr_type_node, t),
1013 0, NOT_BUILT_IN, NULL, NULL_TREE);
1014 DECL_IS_MALLOC (alloc_object_node) = 1;
1015 alloc_no_finalizer_node =
1016 add_builtin_function ("_Jv_AllocObjectNoFinalizer",
1017 build_function_type (ptr_type_node, t),
1018 0, NOT_BUILT_IN, NULL, NULL_TREE);
1019 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
1021 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1022 soft_initclass_node = add_builtin_function ("_Jv_InitClass",
1023 build_function_type (void_type_node,
1025 0, NOT_BUILT_IN, NULL, NULL_TREE);
1026 t = tree_cons (NULL_TREE, class_ptr_type,
1027 tree_cons (NULL_TREE, int_type_node, endlink));
1028 soft_resolvepoolentry_node
1029 = add_builtin_function ("_Jv_ResolvePoolEntry",
1030 build_function_type (ptr_type_node, t),
1031 0,NOT_BUILT_IN, NULL, NULL_TREE);
1032 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
1033 throw_node = add_builtin_function ("_Jv_Throw",
1034 build_function_type (void_type_node, t),
1035 0, NOT_BUILT_IN, NULL, NULL_TREE);
1036 /* Mark throw_nodes as `noreturn' functions with side effects. */
1037 TREE_THIS_VOLATILE (throw_node) = 1;
1038 TREE_SIDE_EFFECTS (throw_node) = 1;
1040 t = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node,
1042 soft_monitorenter_node
1043 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1045 soft_monitorexit_node
1046 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1049 t = tree_cons (NULL_TREE, ptr_type_node,
1050 tree_cons (NULL_TREE, int_type_node, endlink));
1052 = add_builtin_function ("_Jv_NewPrimArray",
1053 build_function_type (ptr_type_node, t),
1054 0, NOT_BUILT_IN, NULL, NULL_TREE);
1055 DECL_IS_MALLOC (soft_newarray_node) = 1;
1057 t = tree_cons (NULL_TREE, int_type_node,
1058 tree_cons (NULL_TREE, class_ptr_type,
1059 tree_cons (NULL_TREE, object_ptr_type_node,
1062 = add_builtin_function ("_Jv_NewObjectArray",
1063 build_function_type (ptr_type_node, t),
1064 0, NOT_BUILT_IN, NULL, NULL_TREE);
1065 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1067 /* There is no endlink here because _Jv_NewMultiArray is a varargs
1069 t = tree_cons (NULL_TREE, ptr_type_node,
1070 tree_cons (NULL_TREE, int_type_node, NULL_TREE));
1071 soft_multianewarray_node
1072 = add_builtin_function ("_Jv_NewMultiArray",
1073 build_function_type (ptr_type_node, t),
1074 0, NOT_BUILT_IN, NULL, NULL_TREE);
1075 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1077 t = build_function_type (void_type_node,
1078 tree_cons (NULL_TREE, int_type_node, endlink));
1079 soft_badarrayindex_node
1080 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1081 0, NOT_BUILT_IN, NULL, NULL_TREE);
1082 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1084 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1085 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1087 soft_nullpointer_node
1088 = add_builtin_function ("_Jv_ThrowNullPointerException",
1089 build_function_type (void_type_node, endlink),
1090 0, NOT_BUILT_IN, NULL, NULL_TREE);
1091 /* Mark soft_nullpointer_node as a `noreturn' function with side
1093 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1094 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1096 soft_abstractmethod_node
1097 = add_builtin_function ("_Jv_ThrowAbstractMethodError",
1098 build_function_type (void_type_node, endlink),
1099 0, NOT_BUILT_IN, NULL, NULL_TREE);
1100 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1102 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1103 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1105 soft_nosuchfield_node
1106 = add_builtin_function ("_Jv_ThrowNoSuchFieldError",
1107 build_function_type (void_type_node, endlink),
1108 0, NOT_BUILT_IN, NULL, NULL_TREE);
1109 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1111 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1112 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1114 t = tree_cons (NULL_TREE, class_ptr_type,
1115 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1117 = add_builtin_function ("_Jv_CheckCast",
1118 build_function_type (ptr_type_node, t),
1119 0, NOT_BUILT_IN, NULL, NULL_TREE);
1120 t = tree_cons (NULL_TREE, object_ptr_type_node,
1121 tree_cons (NULL_TREE, class_ptr_type, endlink));
1122 soft_instanceof_node
1123 = add_builtin_function ("_Jv_IsInstanceOf",
1124 build_function_type (boolean_type_node, t),
1125 0, NOT_BUILT_IN, NULL, NULL_TREE);
1126 DECL_PURE_P (soft_instanceof_node) = 1;
1127 t = tree_cons (NULL_TREE, object_ptr_type_node,
1128 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1129 soft_checkarraystore_node
1130 = add_builtin_function ("_Jv_CheckArrayStore",
1131 build_function_type (void_type_node, t),
1132 0, NOT_BUILT_IN, NULL, NULL_TREE);
1133 t = tree_cons (NULL_TREE, ptr_type_node,
1134 tree_cons (NULL_TREE, ptr_type_node,
1135 tree_cons (NULL_TREE, int_type_node, endlink)));
1136 soft_lookupinterfacemethod_node
1137 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx",
1138 build_function_type (ptr_type_node, t),
1139 0, NOT_BUILT_IN, NULL, NULL_TREE);
1140 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1141 t = tree_cons (NULL_TREE, ptr_type_node,
1142 tree_cons (NULL_TREE, ptr_type_node,
1143 tree_cons (NULL_TREE, ptr_type_node, endlink)));
1144 soft_lookupinterfacemethodbyname_node
1145 = add_builtin_function ("_Jv_LookupInterfaceMethod",
1146 build_function_type (ptr_type_node, t),
1147 0, NOT_BUILT_IN, NULL, NULL_TREE);
1148 t = tree_cons (NULL_TREE, object_ptr_type_node,
1149 tree_cons (NULL_TREE, ptr_type_node,
1150 tree_cons (NULL_TREE, ptr_type_node,
1151 tree_cons (NULL_TREE, int_type_node,
1153 soft_lookupjnimethod_node
1154 = add_builtin_function ("_Jv_LookupJNIMethod",
1155 build_function_type (ptr_type_node, t),
1156 0, NOT_BUILT_IN, NULL, NULL_TREE);
1157 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1158 soft_getjnienvnewframe_node
1159 = add_builtin_function ("_Jv_GetJNIEnvNewFrame",
1160 build_function_type (ptr_type_node, t),
1161 0, NOT_BUILT_IN, NULL, NULL_TREE);
1162 soft_jnipopsystemframe_node
1163 = add_builtin_function ("_Jv_JNI_PopSystemFrame",
1164 build_function_type (void_type_node, t),
1165 0, NOT_BUILT_IN, NULL, NULL_TREE);
1167 t = tree_cons (NULL_TREE, object_ptr_type_node, endlink);
1169 = add_builtin_function ("_Jv_UnwrapJNIweakReference",
1170 build_function_type (object_ptr_type_node, t),
1171 0, NOT_BUILT_IN, NULL, NULL_TREE);
1173 t = tree_cons (NULL_TREE, int_type_node,
1174 tree_cons (NULL_TREE, int_type_node, endlink));
1176 = add_builtin_function ("_Jv_divI",
1177 build_function_type (int_type_node, t),
1178 0, NOT_BUILT_IN, NULL, NULL_TREE);
1181 = add_builtin_function ("_Jv_remI",
1182 build_function_type (int_type_node, t),
1183 0, NOT_BUILT_IN, NULL, NULL_TREE);
1185 t = tree_cons (NULL_TREE, long_type_node,
1186 tree_cons (NULL_TREE, long_type_node, endlink));
1188 = add_builtin_function ("_Jv_divJ",
1189 build_function_type (long_type_node, t),
1190 0, NOT_BUILT_IN, NULL, NULL_TREE);
1193 = add_builtin_function ("_Jv_remJ",
1194 build_function_type (long_type_node, t),
1195 0, NOT_BUILT_IN, NULL, NULL_TREE);
1197 /* Initialize variables for except.c. */
1198 eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
1199 ? "__gcj_personality_sj0"
1200 : "__gcj_personality_v0");
1201 if (targetm.arm_eabi_unwinder)
1202 unwind_resume_libfunc = init_one_libfunc ("__cxa_end_cleanup");
1204 default_init_unwind_resume_libfunc ();
1206 lang_eh_runtime_type = do_nothing;
1208 initialize_builtins ();
1209 soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1215 /* Look up NAME in the current binding level and its superiors
1216 in the namespace of variables, functions and typedefs.
1217 Return a ..._DECL node of some kind representing its definition,
1218 or return 0 if it is undefined. */
1221 lookup_name (tree name)
1224 if (current_binding_level != global_binding_level
1225 && IDENTIFIER_LOCAL_VALUE (name))
1226 val = IDENTIFIER_LOCAL_VALUE (name);
1228 val = IDENTIFIER_GLOBAL_VALUE (name);
1232 /* Similar to `lookup_name' but look only at current binding level and
1233 the previous one if it's the parameter level. */
1236 lookup_name_current_level (tree name)
1240 if (current_binding_level == global_binding_level)
1241 return IDENTIFIER_GLOBAL_VALUE (name);
1243 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1246 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
1247 if (DECL_NAME (t) == name)
1253 /* Record a decl-node X as belonging to the current lexical scope.
1254 Check for errors (such as an incompatible declaration for the same
1255 name already seen in the same scope).
1257 Returns either X or an old decl for the same name.
1258 If an old decl is returned, it may have been smashed
1259 to agree with what X says. */
1265 tree name = DECL_NAME (x);
1266 struct binding_level *b = current_binding_level;
1268 if (TREE_CODE (x) != TYPE_DECL)
1269 DECL_CONTEXT (x) = current_function_decl;
1272 t = lookup_name_current_level (name);
1273 if (t != 0 && t == error_mark_node)
1274 /* error_mark_node is 0 for a while during initialization! */
1277 error ("%q+D used prior to declaration", x);
1280 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1281 to point to the TYPE_DECL.
1282 Since Java does not have typedefs, a type can only have
1283 one (true) name, given by a class, interface, or builtin. */
1284 if (TREE_CODE (x) == TYPE_DECL
1285 && TYPE_NAME (TREE_TYPE (x)) == 0
1286 && TREE_TYPE (x) != error_mark_node)
1288 TYPE_NAME (TREE_TYPE (x)) = x;
1289 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1292 /* This name is new in its binding level.
1293 Install the new declaration and return it. */
1294 if (b == global_binding_level)
1296 /* Install a global value. */
1298 IDENTIFIER_GLOBAL_VALUE (name) = x;
1302 /* Here to install a non-global value. */
1303 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1304 IDENTIFIER_LOCAL_VALUE (name) = x;
1306 /* If storing a local value, there may already be one (inherited).
1307 If so, record it for restoration when this binding level ends. */
1309 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1313 /* Put decls on list in reverse order.
1314 We will reverse them later if necessary. */
1315 TREE_CHAIN (x) = b->names;
1322 pushdecl_force_head (tree x)
1324 current_binding_level->names = x;
1327 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1330 pushdecl_top_level (tree x)
1333 struct binding_level *b = current_binding_level;
1335 current_binding_level = global_binding_level;
1337 current_binding_level = b;
1341 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1344 pushdecl_function_level (tree x)
1347 struct binding_level *b = current_binding_level;
1349 current_binding_level = function_binding_level;
1351 current_binding_level = b;
1355 /* Nonzero if we are currently in the global binding level. */
1358 global_bindings_p (void)
1360 return current_binding_level == global_binding_level;
1363 /* Return the list of declarations of the current level.
1364 Note that this list is in reverse order unless/until
1365 you nreverse it; and when you do nreverse it, you must
1366 store the result back using `storedecls' or you will lose. */
1371 return current_binding_level->names;
1374 /* Create a new `struct binding_level'. */
1376 static struct binding_level *
1377 make_binding_level (void)
1380 return GGC_CNEW (struct binding_level);
1384 pushlevel (int unused ATTRIBUTE_UNUSED)
1386 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1388 /* Reuse or create a struct for this binding level. */
1390 if (free_binding_level)
1392 newlevel = free_binding_level;
1393 free_binding_level = free_binding_level->level_chain;
1397 newlevel = make_binding_level ();
1400 /* Add this level to the front of the chain (stack) of levels that
1403 *newlevel = clear_binding_level;
1404 newlevel->level_chain = current_binding_level;
1405 newlevel->loc = input_location;
1406 current_binding_level = newlevel;
1407 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1408 newlevel->binding_depth = binding_depth;
1410 fprintf (stderr, "push %s level %p pc %d\n",
1411 (is_class_level) ? "class" : "block", newlevel, current_pc);
1414 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1417 /* Exit a binding level.
1418 Pop the level off, and restore the state of the identifier-decl mappings
1419 that were in effect when this level was entered.
1421 If KEEP is nonzero, this level had explicit declarations, so
1422 and create a "block" (a BLOCK node) for the level
1423 to record its declarations and subblocks for symbol table output.
1425 If FUNCTIONBODY is nonzero, this level is the body of a function,
1426 so create a block as if KEEP were set and also clear out all
1429 If REVERSE is nonzero, reverse the order of decls before putting
1430 them into the BLOCK. */
1433 poplevel (int keep, int reverse, int functionbody)
1436 /* The chain of decls was accumulated in reverse order.
1437 Put it into forward order, just for cleanliness. */
1439 tree subblocks = current_binding_level->blocks;
1444 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1447 if (current_binding_level->end_pc != LARGEST_PC)
1448 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1449 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1450 current_binding_level->end_pc);
1452 fprintf (stderr, "pop %s level %p pc %d\n",
1453 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1454 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1456 /* Get the decls in the order they were written.
1457 Usually current_binding_level->names is in reverse order.
1458 But parameter decls were previously put in forward order. */
1461 current_binding_level->names
1462 = decls = nreverse (current_binding_level->names);
1464 decls = current_binding_level->names;
1466 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1467 if (TREE_CODE (decl) == VAR_DECL
1468 && DECL_LANG_SPECIFIC (decl) != NULL
1469 && DECL_LOCAL_SLOT_NUMBER (decl))
1470 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1472 /* If there were any declarations in that level,
1473 or if this level is a function body,
1474 create a BLOCK to record them for the life of this function. */
1477 if (keep || functionbody)
1479 block = make_node (BLOCK);
1480 TREE_TYPE (block) = void_type_node;
1483 if (current_binding_level->exception_range)
1484 expand_end_java_handler (current_binding_level->exception_range);
1488 /* If any statements have been generated at this level, create a
1489 BIND_EXPR to hold them and copy the variables to it. This
1490 only applies to the bytecode compiler. */
1491 if (current_binding_level->stmts)
1494 tree *var = &BLOCK_VARS (block);
1496 /* Copy decls from names list, ignoring labels. */
1499 tree next = TREE_CHAIN (decl);
1500 if (TREE_CODE (decl) != LABEL_DECL)
1503 var = &TREE_CHAIN (decl);
1509 bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
1510 BLOCK_EXPR_BODY (block), block);
1511 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1513 if (BIND_EXPR_BODY (bind)
1514 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1515 TREE_SIDE_EFFECTS (bind) = 1;
1517 /* FIXME: gimplifier brain damage. */
1518 if (BIND_EXPR_BODY (bind) == NULL)
1519 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1521 SET_EXPR_LOCATION (bind, current_binding_level->loc);
1523 current_binding_level->stmts = NULL;
1527 BLOCK_VARS (block) = decls;
1529 BLOCK_SUBBLOCKS (block) = subblocks;
1532 /* In each subblock, record that this is its superior. */
1534 for (link = subblocks; link; link = TREE_CHAIN (link))
1535 BLOCK_SUPERCONTEXT (link) = block;
1537 /* Clear out the meanings of the local variables of this level. */
1539 for (link = decls; link; link = TREE_CHAIN (link))
1541 tree name = DECL_NAME (link);
1542 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1544 /* If the ident. was used or addressed via a local extern decl,
1545 don't forget that fact. */
1546 if (DECL_EXTERNAL (link))
1548 if (TREE_USED (link))
1549 TREE_USED (name) = 1;
1550 if (TREE_ADDRESSABLE (link))
1551 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1553 IDENTIFIER_LOCAL_VALUE (name) = 0;
1557 /* Restore all name-meanings of the outer levels
1558 that were shadowed by this level. */
1560 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1561 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1563 /* If the level being exited is the top level of a function,
1564 check over all the labels, and clear out the current
1565 (function local) meanings of their names. */
1569 /* If this is the top level block of a function,
1570 the vars are the function's parameters.
1571 Don't leave them in the BLOCK because they are
1572 found in the FUNCTION_DECL instead. */
1574 BLOCK_VARS (block) = 0;
1577 /* Pop the current level, and free the structure for reuse. */
1580 struct binding_level *level = current_binding_level;
1581 current_binding_level = current_binding_level->level_chain;
1583 level->level_chain = free_binding_level;
1584 free_binding_level = level;
1587 /* Dispose of the block that we just made inside some higher level. */
1590 DECL_INITIAL (current_function_decl) = block;
1591 DECL_SAVED_TREE (current_function_decl) = bind;
1597 current_binding_level->blocks
1598 = chainon (current_binding_level->blocks, block);
1600 /* If we did not make a block for the level just exited,
1601 any blocks made for inner levels
1602 (since they cannot be recorded as subblocks in that level)
1603 must be carried forward so they will later become subblocks
1604 of something else. */
1606 current_binding_level->blocks
1607 = chainon (current_binding_level->blocks, subblocks);
1610 java_add_stmt (bind);
1614 TREE_USED (block) = 1;
1619 maybe_pushlevels (int pc)
1621 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1625 while (pending_local_decls != NULL_TREE &&
1626 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1628 tree *ptr = &pending_local_decls;
1629 tree decl = *ptr, next;
1630 int end_pc = DECL_LOCAL_END_PC (decl);
1632 while (*ptr != NULL_TREE
1633 && DECL_LOCAL_START_PC (*ptr) <= pc
1634 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1635 ptr = &TREE_CHAIN (*ptr);
1636 pending_local_decls = *ptr;
1639 /* Force non-nested range to be nested in current range by
1640 truncating variable lifetimes. */
1641 if (end_pc > current_binding_level->end_pc)
1644 end_pc = current_binding_level->end_pc;
1645 for (t = decl; t != NULL_TREE; t = TREE_CHAIN (t))
1646 DECL_LOCAL_END_PC (t) = end_pc;
1649 maybe_start_try (pc, end_pc);
1653 current_binding_level->end_pc = end_pc;
1654 current_binding_level->start_pc = pc;
1655 current_binding_level->names = NULL;
1656 for ( ; decl != NULL_TREE; decl = next)
1658 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1660 next = TREE_CHAIN (decl);
1661 push_jvm_slot (index, decl);
1664 = find_local_variable (index, TREE_TYPE (decl), pc);
1665 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1666 base_decl = TREE_VEC_ELT (base_decl_map, index);
1667 SET_DECL_VALUE_EXPR (decl, base_decl);
1668 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1672 maybe_start_try (pc, 0);
1676 maybe_poplevels (int pc)
1678 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1682 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1683 inclusive, so a variable is live if pc == end_pc. Here, we
1684 terminate a range if the current pc is equal to the end of the
1685 range, and this is *before* we have generated code for the
1686 instruction at end_pc. We're closing a binding level one
1687 instruction too early.*/
1688 while (current_binding_level->end_pc <= pc)
1692 /* Terminate any binding which began during the range beginning at
1693 start_pc. This tidies up improperly nested local variable ranges
1694 and exception handlers; a variable declared within an exception
1695 range is forcibly terminated when that exception ends. */
1698 force_poplevels (int start_pc)
1700 while (current_binding_level->start_pc > start_pc)
1702 if (pedantic && current_binding_level->start_pc > start_pc)
1703 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1704 current_function_decl,
1705 current_binding_level->start_pc);
1710 /* integrate_decl_tree calls this function. */
1713 java_dup_lang_specific_decl (tree node)
1716 struct lang_decl *x;
1718 if (!DECL_LANG_SPECIFIC (node))
1721 lang_decl_size = sizeof (struct lang_decl);
1722 x = GGC_NEW (struct lang_decl);
1723 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1724 DECL_LANG_SPECIFIC (node) = x;
1728 give_name_to_locals (JCF *jcf)
1730 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1731 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1733 pending_local_decls = NULL_TREE;
1737 n = JCF_readu2 (jcf);
1738 for (i = 0; i < n; i++)
1740 int start_pc = JCF_readu2 (jcf);
1741 int length = JCF_readu2 (jcf);
1742 int name_index = JCF_readu2 (jcf);
1743 int signature_index = JCF_readu2 (jcf);
1744 int slot = JCF_readu2 (jcf);
1745 tree name = get_name_constant (jcf, name_index);
1746 tree type = parse_signature (jcf, signature_index);
1747 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1749 && length == DECL_CODE_LENGTH (current_function_decl))
1751 tree decl = TREE_VEC_ELT (decl_map, slot);
1752 DECL_NAME (decl) = name;
1753 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1754 warning (0, "bad type in parameter debug info");
1759 int end_pc = start_pc + length;
1760 tree decl = build_decl (input_location, VAR_DECL, name, type);
1761 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1763 warning (0, "bad PC range for debug info for local %q+D",
1765 end_pc = DECL_CODE_LENGTH (current_function_decl);
1768 /* Adjust start_pc if necessary so that the local's first
1769 store operation will use the relevant DECL as a
1770 destination. Fore more information, read the leading
1771 comments for expr.c:maybe_adjust_start_pc. */
1772 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1774 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1775 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1776 DECL_LOCAL_START_PC (decl) = start_pc;
1777 DECL_LOCAL_END_PC (decl) = end_pc;
1779 /* Now insert the new decl in the proper place in
1780 pending_local_decls. We are essentially doing an insertion sort,
1781 which works fine, since the list input will normally already
1783 ptr = &pending_local_decls;
1784 while (*ptr != NULL_TREE
1785 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1786 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1787 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1788 ptr = &TREE_CHAIN (*ptr);
1789 TREE_CHAIN (decl) = *ptr;
1794 pending_local_decls = nreverse (pending_local_decls);
1796 /* Fill in default names for the parameters. */
1797 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1798 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1800 if (DECL_NAME (parm) == NULL_TREE)
1802 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1804 DECL_NAME (parm) = get_identifier ("this");
1808 sprintf (buffer, "ARG_%d", arg_i);
1809 DECL_NAME (parm) = get_identifier (buffer);
1816 build_result_decl (tree fndecl)
1818 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1819 tree result = DECL_RESULT (fndecl);
1822 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1823 RESULT_DECL, NULL_TREE, restype);
1824 DECL_ARTIFICIAL (result) = 1;
1825 DECL_IGNORED_P (result) = 1;
1826 DECL_CONTEXT (result) = fndecl;
1827 DECL_RESULT (fndecl) = result;
1833 start_java_method (tree fndecl)
1840 current_function_decl = fndecl;
1841 announce_function (fndecl);
1843 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1844 decl_map = make_tree_vec (i);
1845 base_decl_map = make_tree_vec (i);
1846 type_map = XRESIZEVEC (tree, type_map, i);
1848 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1849 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1851 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1852 pushlevel (1); /* Push parameters. */
1854 ptr = &DECL_ARGUMENTS (fndecl);
1855 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1856 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1858 tree parm_name = NULL_TREE, parm_decl;
1859 tree parm_type = TREE_VALUE (tem);
1860 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1862 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1863 DECL_CONTEXT (parm_decl) = fndecl;
1864 if (targetm.calls.promote_prototypes (parm_type)
1865 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1866 && INTEGRAL_TYPE_P (parm_type))
1867 parm_type = integer_type_node;
1868 DECL_ARG_TYPE (parm_decl) = parm_type;
1871 ptr = &TREE_CHAIN (parm_decl);
1873 /* Add parm_decl to the decl_map. */
1874 push_jvm_slot (i, parm_decl);
1876 type_map[i] = TREE_TYPE (parm_decl);
1877 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1880 type_map[i] = void_type_node;
1884 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1886 while (i < DECL_MAX_LOCALS(fndecl))
1887 type_map[i++] = NULL_TREE;
1889 build_result_decl (fndecl);
1890 DECL_SOURCE_LOCATION (fndecl) = input_location;
1892 /* Push local variables. */
1895 function_binding_level = current_binding_level;
1899 end_java_method (void)
1901 tree fndecl = current_function_decl;
1903 /* pop out of function */
1906 /* pop out of its parameters */
1909 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1911 if (DECL_SAVED_TREE (fndecl))
1913 tree fbody, block_body;
1914 /* Before we check initialization, attached all class initialization
1915 variable to the block_body */
1916 fbody = DECL_SAVED_TREE (fndecl);
1917 block_body = BIND_EXPR_BODY (fbody);
1918 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1919 attach_init_test_initialization_flags, block_body);
1922 finish_method (fndecl);
1924 current_function_decl = NULL_TREE;
1925 base_decl_map = NULL_TREE;
1928 /* Prepare a method for expansion. */
1931 finish_method (tree fndecl)
1933 tree *tp = &DECL_SAVED_TREE (fndecl);
1935 /* Wrap body of synchronized methods in a monitorenter,
1936 plus monitorexit cleanup. */
1937 if (METHOD_SYNCHRONIZED (fndecl))
1939 tree enter, exit, lock;
1940 if (METHOD_STATIC (fndecl))
1941 lock = build_class_ref (DECL_CONTEXT (fndecl));
1943 lock = DECL_ARGUMENTS (fndecl);
1944 BUILD_MONITOR_ENTER (enter, lock);
1945 BUILD_MONITOR_EXIT (exit, lock);
1946 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1947 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1950 /* Convert function tree to GENERIC prior to inlining. */
1951 java_genericize (fndecl);
1953 /* Store the end of the function, so that we get good line number
1954 info for the epilogue. */
1955 if (DECL_STRUCT_FUNCTION (fndecl))
1956 set_cfun (DECL_STRUCT_FUNCTION (fndecl));
1958 allocate_struct_function (fndecl, false);
1959 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1961 /* Defer inlining and expansion to the cgraph optimizers. */
1962 cgraph_finalize_function (fndecl, false);
1965 /* We pessimistically marked all methods and fields external until we
1966 knew what set of classes we were planning to compile. Now mark those
1967 associated with CLASS to be generated locally as not external. */
1970 java_mark_decl_local (tree decl)
1972 DECL_EXTERNAL (decl) = 0;
1974 #ifdef ENABLE_CHECKING
1975 /* Double check that we didn't pass the function to the callgraph early. */
1976 if (TREE_CODE (decl) == FUNCTION_DECL)
1977 gcc_assert (!cgraph_node (decl)->local.finalized);
1979 gcc_assert (!DECL_RTL_SET_P (decl));
1982 /* Given appropriate target support, G++ will emit hidden aliases for native
1983 methods. Using this hidden name is required for proper operation of
1984 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1985 proper target support, then mark the method for aliasing. */
1988 java_mark_cni_decl_local (tree decl)
1990 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1994 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1995 DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1997 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1998 mangler. We might have already referenced this native method and
1999 therefore created its name, but even if we have it won't hurt.
2000 We'll just go via its externally visible name, rather than its
2001 hidden alias. However, we must force things so that the correct
2002 mangling is done. */
2004 if (DECL_ASSEMBLER_NAME_SET_P (decl))
2005 java_mangle_decl (decl);
2006 if (DECL_RTL_SET_P (decl))
2008 SET_DECL_RTL (decl, 0);
2009 make_decl_rtl (decl);
2013 /* Use the preceding two functions and mark all members of the class. */
2016 java_mark_class_local (tree klass)
2020 for (t = TYPE_FIELDS (klass); t ; t = TREE_CHAIN (t))
2021 if (FIELD_STATIC (t))
2022 java_mark_decl_local (t);
2024 for (t = TYPE_METHODS (klass); t ; t = TREE_CHAIN (t))
2025 if (!METHOD_ABSTRACT (t))
2027 if (METHOD_NATIVE (t) && !flag_jni)
2028 java_mark_cni_decl_local (t);
2030 java_mark_decl_local (t);
2034 /* Add a statement to a compound_expr. */
2037 add_stmt_to_compound (tree existing, tree type, tree stmt)
2043 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
2044 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
2045 | TREE_SIDE_EFFECTS (stmt);
2052 /* If this node is an expr, mark its input location. Called from
2056 set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
2057 void *data ATTRIBUTE_UNUSED)
2061 if (CAN_HAVE_LOCATION_P (t))
2063 if (EXPR_HAS_LOCATION(t))
2064 return t; /* Don't walk any further into this expr. */
2066 SET_EXPR_LOCATION (t, input_location);
2069 return NULL_TREE; /* Continue walking this expr. */
2072 /* Add a statement to the statement_list currently being constructed.
2073 If the statement_list is null, we don't create a singleton list.
2074 This is necessary because poplevel() assumes that adding a
2075 statement to a null statement_list returns the statement. */
2078 java_add_stmt (tree new_stmt)
2080 tree stmts = current_binding_level->stmts;
2081 tree_stmt_iterator i;
2084 walk_tree (&new_stmt, set_input_location, NULL, NULL);
2087 return current_binding_level->stmts = new_stmt;
2089 /* Force STMTS to be a statement_list. */
2090 if (TREE_CODE (stmts) != STATEMENT_LIST)
2092 tree t = make_node (STATEMENT_LIST);
2094 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2098 i = tsi_last (stmts);
2099 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2100 TREE_TYPE (stmts) = void_type_node;
2102 return current_binding_level->stmts = stmts;
2105 /* Add a variable to the current scope. */
2108 java_add_local_var (tree decl)
2110 tree *vars = ¤t_binding_level->names;
2112 TREE_CHAIN (decl) = next;
2114 DECL_CONTEXT (decl) = current_function_decl;
2115 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2119 /* Return a pointer to the compound_expr currently being
2125 return ¤t_binding_level->stmts;
2128 /* Register an exception range as belonging to the current binding
2129 level. There may only be one: if there are more, we'll create more
2130 binding levels. However, each range can have multiple handlers,
2131 and these are expanded when we call expand_end_java_handler(). */
2134 register_exception_range (struct eh_range *range, int pc, int end_pc)
2136 gcc_assert (! current_binding_level->exception_range);
2137 current_binding_level->exception_range = range;
2138 current_binding_level->end_pc = end_pc;
2139 current_binding_level->start_pc = pc;
2142 #include "gt-java-decl.h"