1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
4 2005, 2006, 2007, 2008, 2009, 2010 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"
34 #include "java-tree.h"
37 #include "java-except.h"
40 #include "tree-inline.h"
43 #include "tree-iterator.h"
44 #include "langhooks.h"
47 #if defined (DEBUG_JAVA_BINDING_LEVELS)
48 extern void indent (void);
51 static tree push_jvm_slot (int, tree);
52 static tree lookup_name_current_level (tree);
53 static tree push_promoted_type (const char *, tree);
54 static struct binding_level *make_binding_level (void);
55 static tree create_primitive_vtable (const char *);
56 static tree check_local_unnamed_variable (tree, tree, tree);
57 static void parse_version (void);
60 /* The following ABI flags are used in the high-order bits of the version
61 ID field. The version ID number itself should never be larger than
62 0xfffff, so it should be safe to use top 12 bits for these flags. */
64 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
66 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
67 should be loaded by the bootstrap
70 /* If an ABI change is made within a GCC release series, rendering current
71 binaries incompatible with the old runtimes, this number must be set to
72 enforce the compatibility rules. */
73 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
75 /* The runtime may recognize a variety of BC ABIs (objects generated by
76 different version of gcj), but will probably always require strict
77 matching for the ordinary (C++) ABI. */
79 /* The version ID of the BC ABI that we generate. This must be kept in
80 sync with parse_version(), libgcj, and reality (if the BC format changes,
82 #define GCJ_CURRENT_BC_ABI_VERSION \
83 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
85 /* The ABI version number. */
88 /* Name of the Cloneable class. */
89 tree java_lang_cloneable_identifier_node;
91 /* Name of the Serializable class. */
92 tree java_io_serializable_identifier_node;
94 /* The DECL_MAP is a mapping from (index, type) to a decl node.
95 If index < max_locals, it is the index of a local variable.
96 if index >= max_locals, then index-max_locals is a stack slot.
97 The DECL_MAP mapping is represented as a TREE_VEC whose elements
98 are a list of decls (VAR_DECL or PARM_DECL) chained by
99 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
100 we search the chain for a decl with a matching TREE_TYPE. */
102 static GTY(()) tree decl_map;
104 /* The base_decl_map is contains one variable of ptr_type: this is
105 used to contain every variable of reference type that is ever
106 stored in a local variable slot. */
108 static GTY(()) tree base_decl_map;
110 /* An index used to make temporary identifiers unique. */
113 /* A list of local variables VAR_DECLs for this method that we have seen
114 debug information, but we have not reached their starting (byte) PC yet. */
116 static GTY(()) tree pending_local_decls;
118 /* The decl for "_Jv_ResolvePoolEntry". */
119 tree soft_resolvepoolentry_node;
121 /* The decl for the .constants field of an instance of Class. */
122 tree constants_field_decl_node;
124 /* The decl for the .data field of an instance of Class. */
125 tree constants_data_field_decl_node;
127 #if defined(DEBUG_JAVA_BINDING_LEVELS)
128 int binding_depth = 0;
129 int is_class_level = 0;
137 for (i = 0; i < binding_depth*2; i++)
140 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
142 /* True if decl is a named local variable, i.e. if it is an alias
143 that's used only for debugging purposes. */
146 debug_variable_p (tree decl)
148 if (TREE_CODE (decl) == PARM_DECL)
151 if (LOCAL_SLOT_P (decl))
158 push_jvm_slot (int index, tree decl)
160 DECL_CONTEXT (decl) = current_function_decl;
161 layout_decl (decl, 0);
163 /* Now link the decl into the decl_map. */
164 if (DECL_LANG_SPECIFIC (decl) == NULL)
166 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
167 DECL_LOCAL_START_PC (decl) = 0;
168 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
169 DECL_LOCAL_SLOT_NUMBER (decl) = index;
171 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
172 TREE_VEC_ELT (decl_map, index) = decl;
177 /* Find the best declaration based upon type. If 'decl' fits 'type' better
178 than 'best', return 'decl'. Otherwise return 'best'. */
181 check_local_unnamed_variable (tree best, tree decl, tree type)
183 tree decl_type = TREE_TYPE (decl);
185 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
187 /* Use the same decl for all integer types <= 32 bits. This is
188 necessary because sometimes a value is stored as (for example)
189 boolean but loaded as int. */
190 if (decl_type == type
191 || (INTEGRAL_TYPE_P (decl_type)
192 && INTEGRAL_TYPE_P (type)
193 && TYPE_PRECISION (decl_type) <= 32
194 && TYPE_PRECISION (type) <= 32
195 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
196 /* ptr_type_node is used for null pointers, which are
197 assignment compatible with everything. */
198 || (TREE_CODE (decl_type) == POINTER_TYPE
199 && type == ptr_type_node)
200 /* Whenever anyone wants to use a slot that is initially
201 occupied by a PARM_DECL of pointer type they must get that
202 decl, even if they asked for a pointer to a different type.
203 However, if someone wants a scalar variable in a slot that
204 initially held a pointer arg -- or vice versa -- we create a
207 ???: As long as verification is correct, this will be a
208 compatible type. But maybe we should create a dummy variable
209 and replace all references to it with the DECL and a
212 || (TREE_CODE (decl_type) == POINTER_TYPE
213 && TREE_CODE (decl) == PARM_DECL
214 && TREE_CODE (type) == POINTER_TYPE))
216 if (best == NULL_TREE
217 || (decl_type == type && TREE_TYPE (best) != type))
225 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
226 that is valid at PC (or -1 if any pc).
227 If there is no existing matching decl, allocate one. */
230 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
232 tree tmp = TREE_VEC_ELT (decl_map, index);
233 tree decl = NULL_TREE;
235 /* Scan through every declaration that has been created in this
236 slot. We're only looking for variables that correspond to local
237 index declarations and PARM_DECLs, not named variables: such
238 local variables are used only for debugging information. */
239 while (tmp != NULL_TREE)
241 if (! debug_variable_p (tmp))
242 decl = check_local_unnamed_variable (decl, tmp, type);
243 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
246 /* gcj has a function called promote_type(), which is used by both
247 the bytecode compiler and the source compiler. Unfortunately,
248 the type systems for the Java VM and the Java language are not
249 the same: a boolean in the VM promotes to an int, not to a wide
250 boolean. If our caller wants something to hold a boolean, that
251 had better be an int, because that slot might be re-used
252 later in integer context. */
253 if (TREE_CODE (type) == BOOLEAN_TYPE)
254 type = integer_type_node;
256 /* If we don't find a match, create one with the type passed in.
257 The name of the variable is #n#m, which n is the variable index
258 in the local variable area and m is a dummy identifier for
259 uniqueness -- multiple variables may share the same local
260 variable index. We don't call pushdecl() to push pointer types
261 into a binding expr because they'll all be replaced by a single
262 variable that is used for every reference in that local variable
268 sprintf (buf, "#slot#%d#%d", index, uniq++);
269 name = get_identifier (buf);
270 decl = build_decl (input_location, VAR_DECL, name, type);
271 DECL_IGNORED_P (decl) = 1;
272 DECL_ARTIFICIAL (decl) = 1;
273 decl = push_jvm_slot (index, decl);
274 LOCAL_SLOT_P (decl) = 1;
276 if (TREE_CODE (type) != POINTER_TYPE)
277 pushdecl_function_level (decl);
280 /* As well as creating a local variable that matches the type, we
281 also create a base variable (of ptr_type) that will hold all its
283 if (TREE_CODE (type) == POINTER_TYPE
284 && ! TREE_VEC_ELT (base_decl_map, index))
289 sprintf (buf, "#ref#%d#%d", index, uniq++);
290 name = get_identifier (buf);
292 = TREE_VEC_ELT (base_decl_map, index)
293 = build_decl (input_location, VAR_DECL, name, ptr_type_node);
294 pushdecl_function_level (base_decl);
295 DECL_IGNORED_P (base_decl) = 1;
296 DECL_ARTIFICIAL (base_decl) = 1;
302 /* Called during genericization for every variable. If the variable
303 is a temporary of pointer type, replace it with a common variable
304 thath is used to hold all pointer types that are ever stored in
305 that slot. Set WANT_LVALUE if you want a variable that is to be
309 java_replace_reference (tree var_decl, bool want_lvalue)
316 decl_type = TREE_TYPE (var_decl);
318 if (TREE_CODE (decl_type) == POINTER_TYPE)
320 if (DECL_LANG_SPECIFIC (var_decl)
321 && LOCAL_SLOT_P (var_decl))
323 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
324 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
326 gcc_assert (base_decl);
328 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
337 /* Helper for java_genericize. */
340 java_replace_references (tree *tp, int *walk_subtrees,
341 void *data ATTRIBUTE_UNUSED)
343 if (TREE_CODE (*tp) == MODIFY_EXPR)
345 source_location loc = EXPR_LOCATION (*tp);
346 tree lhs = TREE_OPERAND (*tp, 0);
347 /* This is specific to the bytecode compiler. If a variable has
348 LOCAL_SLOT_P set, replace an assignment to it with an assignment
349 to the corresponding variable that holds all its aliases. */
350 if (TREE_CODE (lhs) == VAR_DECL
351 && DECL_LANG_SPECIFIC (lhs)
352 && LOCAL_SLOT_P (lhs)
353 && TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE)
355 tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
356 tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs),
357 TREE_OPERAND (*tp, 1));
358 tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
360 *tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem);
361 SET_EXPR_LOCATION (tem, loc);
362 SET_EXPR_LOCATION (new_rhs, loc);
363 SET_EXPR_LOCATION (*tp, loc);
366 if (TREE_CODE (*tp) == VAR_DECL)
368 *tp = java_replace_reference (*tp, /* want_lvalue */ false);
375 /* Same as find_local_index, except that INDEX is a stack index. */
378 find_stack_slot (int index, tree type)
380 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
386 /* A chain of _DECL nodes for all variables, constants, functions,
387 * and typedef types. These are in the reverse of the order supplied.
391 /* For each level, a list of shadowed outer-level local definitions
392 to be restored when this level is popped.
393 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
394 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
397 /* For each level (except not the global one),
398 a chain of BLOCK nodes for all the levels
399 that were entered and exited one level down. */
402 /* The binding level which this one is contained in (inherits from). */
403 struct binding_level *level_chain;
405 /* The bytecode PC that marks the end of this level. */
407 /* The bytecode PC that marks the start of this level. */
410 /* The statements in this binding level. */
413 /* An exception range associated with this binding level. */
414 struct eh_range * GTY((skip (""))) exception_range;
416 /* Binding depth at which this level began. Used only for debugging. */
417 unsigned binding_depth;
419 /* The location at which this level began. */
423 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
425 /* The binding level currently in effect. */
427 static GTY(()) struct binding_level *current_binding_level;
429 /* A chain of binding_level structures awaiting reuse. */
431 static GTY(()) struct binding_level *free_binding_level;
433 /* The outermost binding level, for names of file scope.
434 This is created when the compiler is started and exists
435 through the entire run. */
437 static GTY(()) struct binding_level *global_binding_level;
439 /* The binding level that holds variables declared at the outermost
440 level within a function body. */
442 static struct binding_level *function_binding_level;
444 /* A PC value bigger than any PC value we may ever may encounter. */
446 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
448 /* Binding level structures are initialized by copying this one. */
450 static const struct binding_level clear_binding_level
452 NULL_TREE, /* names */
453 NULL_TREE, /* shadowed */
454 NULL_TREE, /* blocks */
455 NULL_BINDING_LEVEL, /* level_chain */
456 LARGEST_PC, /* end_pc */
459 NULL, /* exception_range */
460 0, /* binding_depth */
464 tree java_global_trees[JTI_MAX];
466 /* Build (and pushdecl) a "promoted type" for all standard
467 types shorter than int. */
470 push_promoted_type (const char *name, tree actual_type)
472 tree type = make_node (TREE_CODE (actual_type));
474 tree in_min = TYPE_MIN_VALUE (int_type_node);
475 tree in_max = TYPE_MAX_VALUE (int_type_node);
477 tree in_min = TYPE_MIN_VALUE (actual_type);
478 tree in_max = TYPE_MAX_VALUE (actual_type);
480 TYPE_MIN_VALUE (type) = copy_node (in_min);
481 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
482 TYPE_MAX_VALUE (type) = copy_node (in_max);
483 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
484 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
485 TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
487 pushdecl (build_decl (input_location,
488 TYPE_DECL, get_identifier (name), type));
492 /* Return tree that represents a vtable for a primitive array. */
494 create_primitive_vtable (const char *name)
499 sprintf (buf, "_Jv_%sVTable", name);
500 r = build_decl (input_location,
501 VAR_DECL, get_identifier (buf), ptr_type_node);
502 DECL_EXTERNAL (r) = 1;
506 /* Parse the version string and compute the ABI version number. */
510 const char *p = version_string;
511 unsigned int major = 0, minor = 0;
512 unsigned int abi_version;
514 /* Skip leading junk. */
515 while (*p && !ISDIGIT (*p))
519 /* Extract major version. */
522 major = major * 10 + *p - '0';
526 gcc_assert (*p == '.' && ISDIGIT (p[1]));
529 /* Extract minor version. */
532 minor = minor * 10 + *p - '0';
536 if (flag_indirect_dispatch)
538 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
539 abi_version |= FLAG_BINARYCOMPAT_ABI;
543 /* Implicit in this computation is the idea that we won't break the
544 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
546 abi_version = 100000 * major + 1000 * minor;
548 if (flag_bootstrap_classes)
549 abi_version |= FLAG_BOOTSTRAP_LOADER;
551 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
555 java_init_decl_processing (void)
558 tree field = NULL_TREE;
561 init_class_processing ();
563 current_function_decl = NULL;
564 current_binding_level = NULL_BINDING_LEVEL;
565 free_binding_level = NULL_BINDING_LEVEL;
566 pushlevel (0); /* make the binding_level structure for global names */
567 global_binding_level = current_binding_level;
569 /* The code here must be similar to build_common_tree_nodes{,_2} in
570 tree.c, especially as to the order of initializing common nodes. */
571 error_mark_node = make_node (ERROR_MARK);
572 TREE_TYPE (error_mark_node) = error_mark_node;
574 /* Create sizetype first - needed for other types. */
575 initialize_sizetypes ();
577 byte_type_node = make_signed_type (8);
578 pushdecl (build_decl (BUILTINS_LOCATION,
579 TYPE_DECL, get_identifier ("byte"), byte_type_node));
580 short_type_node = make_signed_type (16);
581 pushdecl (build_decl (BUILTINS_LOCATION,
582 TYPE_DECL, get_identifier ("short"), short_type_node));
583 int_type_node = make_signed_type (32);
584 pushdecl (build_decl (BUILTINS_LOCATION,
585 TYPE_DECL, get_identifier ("int"), int_type_node));
586 long_type_node = make_signed_type (64);
587 pushdecl (build_decl (BUILTINS_LOCATION,
588 TYPE_DECL, get_identifier ("long"), long_type_node));
590 unsigned_byte_type_node = make_unsigned_type (8);
591 pushdecl (build_decl (BUILTINS_LOCATION,
592 TYPE_DECL, get_identifier ("unsigned byte"),
593 unsigned_byte_type_node));
594 unsigned_short_type_node = make_unsigned_type (16);
595 pushdecl (build_decl (BUILTINS_LOCATION,
596 TYPE_DECL, get_identifier ("unsigned short"),
597 unsigned_short_type_node));
598 unsigned_int_type_node = make_unsigned_type (32);
599 pushdecl (build_decl (BUILTINS_LOCATION,
600 TYPE_DECL, get_identifier ("unsigned int"),
601 unsigned_int_type_node));
602 unsigned_long_type_node = make_unsigned_type (64);
603 pushdecl (build_decl (BUILTINS_LOCATION,
604 TYPE_DECL, get_identifier ("unsigned long"),
605 unsigned_long_type_node));
607 /* This is not a java type, however tree-dfa requires a definition for
609 size_type_node = make_unsigned_type (POINTER_SIZE);
610 set_sizetype (size_type_node);
612 /* Define these next since types below may used them. */
613 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
614 integer_zero_node = build_int_cst (NULL_TREE, 0);
615 integer_one_node = build_int_cst (NULL_TREE, 1);
616 integer_two_node = build_int_cst (NULL_TREE, 2);
617 integer_four_node = build_int_cst (NULL_TREE, 4);
618 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
620 /* A few values used for range checking in the lexer. */
621 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
623 = double_int_to_tree (unsigned_long_type_node,
624 double_int_setbit (double_int_zero, 64));
626 size_zero_node = size_int (0);
627 size_one_node = size_int (1);
628 bitsize_zero_node = bitsize_int (0);
629 bitsize_one_node = bitsize_int (1);
630 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
632 long_zero_node = build_int_cst (long_type_node, 0);
634 void_type_node = make_node (VOID_TYPE);
635 pushdecl (build_decl (BUILTINS_LOCATION,
636 TYPE_DECL, get_identifier ("void"), void_type_node));
637 layout_type (void_type_node); /* Uses size_zero_node */
639 ptr_type_node = build_pointer_type (void_type_node);
641 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
643 t = make_node (VOID_TYPE);
644 layout_type (t); /* Uses size_zero_node */
645 return_address_type_node = build_pointer_type (t);
647 null_pointer_node = build_int_cst (ptr_type_node, 0);
649 char_type_node = make_node (INTEGER_TYPE);
650 TYPE_STRING_FLAG (char_type_node) = 1;
651 TYPE_PRECISION (char_type_node) = 16;
652 fixup_unsigned_type (char_type_node);
653 pushdecl (build_decl (BUILTINS_LOCATION,
654 TYPE_DECL, get_identifier ("char"), char_type_node));
656 boolean_type_node = make_node (BOOLEAN_TYPE);
657 TYPE_PRECISION (boolean_type_node) = 1;
658 fixup_unsigned_type (boolean_type_node);
659 pushdecl (build_decl (BUILTINS_LOCATION,
660 TYPE_DECL, get_identifier ("boolean"),
662 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
663 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
665 promoted_byte_type_node
666 = push_promoted_type ("promoted_byte", byte_type_node);
667 promoted_short_type_node
668 = push_promoted_type ("promoted_short", short_type_node);
669 promoted_char_type_node
670 = push_promoted_type ("promoted_char", char_type_node);
671 promoted_boolean_type_node
672 = push_promoted_type ("promoted_boolean", boolean_type_node);
674 float_type_node = make_node (REAL_TYPE);
675 TYPE_PRECISION (float_type_node) = 32;
676 pushdecl (build_decl (BUILTINS_LOCATION,
677 TYPE_DECL, get_identifier ("float"),
679 layout_type (float_type_node);
681 double_type_node = make_node (REAL_TYPE);
682 TYPE_PRECISION (double_type_node) = 64;
683 pushdecl (build_decl (BUILTINS_LOCATION,
684 TYPE_DECL, get_identifier ("double"),
686 layout_type (double_type_node);
688 float_zero_node = build_real (float_type_node, dconst0);
689 double_zero_node = build_real (double_type_node, dconst0);
691 /* These are the vtables for arrays of primitives. */
692 boolean_array_vtable = create_primitive_vtable ("boolean");
693 byte_array_vtable = create_primitive_vtable ("byte");
694 char_array_vtable = create_primitive_vtable ("char");
695 short_array_vtable = create_primitive_vtable ("short");
696 int_array_vtable = create_primitive_vtable ("int");
697 long_array_vtable = create_primitive_vtable ("long");
698 float_array_vtable = create_primitive_vtable ("float");
699 double_array_vtable = create_primitive_vtable ("double");
701 one_elt_array_domain_type = build_index_type (integer_one_node);
702 utf8const_type = make_node (RECORD_TYPE);
703 PUSH_FIELD (input_location,
704 utf8const_type, field, "hash", unsigned_short_type_node);
705 PUSH_FIELD (input_location,
706 utf8const_type, field, "length", unsigned_short_type_node);
707 FINISH_RECORD (utf8const_type);
708 utf8const_ptr_type = build_pointer_type (utf8const_type);
710 atable_type = build_array_type (ptr_type_node,
711 one_elt_array_domain_type);
712 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
713 atable_ptr_type = build_pointer_type (atable_type);
715 itable_type = build_array_type (ptr_type_node,
716 one_elt_array_domain_type);
717 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
718 itable_ptr_type = build_pointer_type (itable_type);
720 symbol_type = make_node (RECORD_TYPE);
721 PUSH_FIELD (input_location,
722 symbol_type, field, "clname", utf8const_ptr_type);
723 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
724 PUSH_FIELD (input_location,
725 symbol_type, field, "signature", utf8const_ptr_type);
726 FINISH_RECORD (symbol_type);
728 symbols_array_type = build_array_type (symbol_type,
729 one_elt_array_domain_type);
730 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
732 assertion_entry_type = make_node (RECORD_TYPE);
733 PUSH_FIELD (input_location,
734 assertion_entry_type, field, "assertion_code", integer_type_node);
735 PUSH_FIELD (input_location,
736 assertion_entry_type, field, "op1", utf8const_ptr_type);
737 PUSH_FIELD (input_location,
738 assertion_entry_type, field, "op2", utf8const_ptr_type);
739 FINISH_RECORD (assertion_entry_type);
741 assertion_table_type = build_array_type (assertion_entry_type,
742 one_elt_array_domain_type);
744 /* As you're adding items here, please update the code right after
745 this section, so that the filename containing the source code of
746 the pre-defined class gets registered correctly. */
747 unqualified_object_id_node = get_identifier ("Object");
748 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
749 object_ptr_type_node = promote_type (object_type_node);
750 string_type_node = lookup_class (get_identifier ("java.lang.String"));
751 string_ptr_type_node = promote_type (string_type_node);
752 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
753 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
754 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
755 runtime_exception_type_node =
756 lookup_class (get_identifier ("java.lang.RuntimeException"));
757 error_exception_type_node =
758 lookup_class (get_identifier ("java.lang.Error"));
760 rawdata_ptr_type_node
761 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
763 add_predefined_file (get_identifier ("java/lang/Class.java"));
764 add_predefined_file (get_identifier ("java/lang/Error.java"));
765 add_predefined_file (get_identifier ("java/lang/Object.java"));
766 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
767 add_predefined_file (get_identifier ("java/lang/String.java"));
768 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
769 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
770 add_predefined_file (get_identifier ("java/lang/Exception.java"));
771 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
772 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
774 methodtable_type = make_node (RECORD_TYPE);
775 layout_type (methodtable_type);
776 build_decl (BUILTINS_LOCATION,
777 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
778 methodtable_ptr_type = build_pointer_type (methodtable_type);
780 TYPE_identifier_node = get_identifier ("TYPE");
781 init_identifier_node = get_identifier ("<init>");
782 clinit_identifier_node = get_identifier ("<clinit>");
783 void_signature_node = get_identifier ("()V");
784 finalize_identifier_node = get_identifier ("finalize");
785 this_identifier_node = get_identifier ("this");
787 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
788 java_io_serializable_identifier_node =
789 get_identifier ("java.io.Serializable");
791 /* for lack of a better place to put this stub call */
792 init_expr_processing();
794 constants_type_node = make_node (RECORD_TYPE);
795 PUSH_FIELD (input_location,
796 constants_type_node, field, "size", unsigned_int_type_node);
797 PUSH_FIELD (input_location,
798 constants_type_node, field, "tags", ptr_type_node);
799 PUSH_FIELD (input_location,
800 constants_type_node, field, "data", ptr_type_node);
801 constants_data_field_decl_node = field;
802 FINISH_RECORD (constants_type_node);
803 build_decl (BUILTINS_LOCATION,
804 TYPE_DECL, get_identifier ("constants"), constants_type_node);
806 access_flags_type_node = unsigned_short_type_node;
808 dtable_type = make_node (RECORD_TYPE);
809 dtable_ptr_type = build_pointer_type (dtable_type);
811 otable_type = build_array_type (integer_type_node,
812 one_elt_array_domain_type);
813 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
814 otable_ptr_type = build_pointer_type (otable_type);
816 PUSH_FIELD (input_location,
817 object_type_node, field, "vtable", dtable_ptr_type);
818 DECL_FCONTEXT (field) = object_type_node;
819 TYPE_VFIELD (object_type_node) = field;
821 /* This isn't exactly true, but it is what we have in the source.
822 There is an unresolved issue here, which is whether the vtable
823 should be marked by the GC. */
824 if (! flag_hash_synchronization)
825 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
826 build_pointer_type (object_type_node));
827 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
828 FIELD_PRIVATE (t) = 1;
829 FINISH_RECORD (object_type_node);
831 field_type_node = make_node (RECORD_TYPE);
832 field_ptr_type_node = build_pointer_type (field_type_node);
833 method_type_node = make_node (RECORD_TYPE);
834 method_ptr_type_node = build_pointer_type (method_type_node);
836 set_super_info (0, class_type_node, object_type_node, 0);
837 set_super_info (0, string_type_node, object_type_node, 0);
838 class_ptr_type = build_pointer_type (class_type_node);
840 PUSH_FIELD (input_location,
841 class_type_node, field, "next_or_version", class_ptr_type);
842 PUSH_FIELD (input_location,
843 class_type_node, field, "name", utf8const_ptr_type);
844 PUSH_FIELD (input_location,
845 class_type_node, field, "accflags", access_flags_type_node);
846 PUSH_FIELD (input_location,
847 class_type_node, field, "superclass", class_ptr_type);
848 PUSH_FIELD (input_location,
849 class_type_node, field, "constants", constants_type_node);
850 constants_field_decl_node = field;
851 PUSH_FIELD (input_location,
852 class_type_node, field, "methods", method_ptr_type_node);
853 PUSH_FIELD (input_location,
854 class_type_node, field, "method_count", short_type_node);
855 PUSH_FIELD (input_location,
856 class_type_node, field, "vtable_method_count", short_type_node);
857 PUSH_FIELD (input_location,
858 class_type_node, field, "fields", field_ptr_type_node);
859 PUSH_FIELD (input_location,
860 class_type_node, field, "size_in_bytes", int_type_node);
861 PUSH_FIELD (input_location,
862 class_type_node, field, "field_count", short_type_node);
863 PUSH_FIELD (input_location,
864 class_type_node, field, "static_field_count", short_type_node);
865 PUSH_FIELD (input_location,
866 class_type_node, field, "vtable", dtable_ptr_type);
867 PUSH_FIELD (input_location,
868 class_type_node, field, "otable", otable_ptr_type);
869 PUSH_FIELD (input_location,
870 class_type_node, field, "otable_syms",
871 symbols_array_ptr_type);
872 PUSH_FIELD (input_location,
873 class_type_node, field, "atable", atable_ptr_type);
874 PUSH_FIELD (input_location,
875 class_type_node, field, "atable_syms",
876 symbols_array_ptr_type);
877 PUSH_FIELD (input_location,
878 class_type_node, field, "itable", itable_ptr_type);
879 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
880 symbols_array_ptr_type);
881 PUSH_FIELD (input_location,
882 class_type_node, field, "catch_classes", ptr_type_node);
883 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
884 build_pointer_type (class_ptr_type));
885 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
886 PUSH_FIELD (input_location,
887 class_type_node, field, "interface_count", short_type_node);
888 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
889 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
890 PUSH_FIELD (input_location,
891 class_type_node, field, "depth", short_type_node);
892 PUSH_FIELD (input_location,
893 class_type_node, field, "ancestors", ptr_type_node);
894 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
895 PUSH_FIELD (input_location,
896 class_type_node, field, "arrayclass", ptr_type_node);
897 PUSH_FIELD (input_location,
898 class_type_node, field, "protectionDomain", ptr_type_node);
899 PUSH_FIELD (input_location,
900 class_type_node, field, "assertion_table", ptr_type_node);
901 PUSH_FIELD (input_location,
902 class_type_node, field, "hack_signers", ptr_type_node);
903 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
904 PUSH_FIELD (input_location,
905 class_type_node, field, "aux_info", ptr_type_node);
906 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
907 PUSH_FIELD (input_location,
908 class_type_node, field, "reflection_data", ptr_type_node);
909 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
910 FIELD_PRIVATE (t) = 1;
911 push_super_field (class_type_node, object_type_node);
913 FINISH_RECORD (class_type_node);
914 build_decl (BUILTINS_LOCATION,
915 TYPE_DECL, get_identifier ("Class"), class_type_node);
917 field_info_union_node = make_node (UNION_TYPE);
918 PUSH_FIELD (input_location,
919 field_info_union_node, field, "boffset", int_type_node);
920 PUSH_FIELD (input_location,
921 field_info_union_node, field, "addr", ptr_type_node);
922 layout_type (field_info_union_node);
924 PUSH_FIELD (input_location,
925 field_type_node, field, "name", utf8const_ptr_type);
926 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
927 PUSH_FIELD (input_location,
928 field_type_node, field, "accflags", access_flags_type_node);
929 PUSH_FIELD (input_location,
930 field_type_node, field, "bsize", unsigned_short_type_node);
931 PUSH_FIELD (input_location,
932 field_type_node, field, "info", field_info_union_node);
933 FINISH_RECORD (field_type_node);
934 build_decl (BUILTINS_LOCATION,
935 TYPE_DECL, get_identifier ("Field"), field_type_node);
937 nativecode_ptr_array_type_node
938 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
940 PUSH_FIELD (input_location,
941 dtable_type, field, "class", class_ptr_type);
942 PUSH_FIELD (input_location,
943 dtable_type, field, "methods", nativecode_ptr_array_type_node);
944 FINISH_RECORD (dtable_type);
945 build_decl (BUILTINS_LOCATION,
946 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
948 jexception_type = make_node (RECORD_TYPE);
949 PUSH_FIELD (input_location,
950 jexception_type, field, "start_pc", ptr_type_node);
951 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
952 PUSH_FIELD (input_location,
953 jexception_type, field, "handler_pc", ptr_type_node);
954 PUSH_FIELD (input_location,
955 jexception_type, field, "catch_type", class_ptr_type);
956 FINISH_RECORD (jexception_type);
957 build_decl (BUILTINS_LOCATION,
958 TYPE_DECL, get_identifier ("jexception"), field_type_node);
959 jexception_ptr_type = build_pointer_type (jexception_type);
961 lineNumberEntry_type = make_node (RECORD_TYPE);
962 PUSH_FIELD (input_location,
963 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
964 PUSH_FIELD (input_location,
965 lineNumberEntry_type, field, "start_pc", ptr_type_node);
966 FINISH_RECORD (lineNumberEntry_type);
968 lineNumbers_type = make_node (RECORD_TYPE);
969 PUSH_FIELD (input_location,
970 lineNumbers_type, field, "length", unsigned_int_type_node);
971 FINISH_RECORD (lineNumbers_type);
973 PUSH_FIELD (input_location,
974 method_type_node, field, "name", utf8const_ptr_type);
975 PUSH_FIELD (input_location,
976 method_type_node, field, "signature", utf8const_ptr_type);
977 PUSH_FIELD (input_location,
978 method_type_node, field, "accflags", access_flags_type_node);
979 PUSH_FIELD (input_location,
980 method_type_node, field, "index", unsigned_short_type_node);
981 PUSH_FIELD (input_location,
982 method_type_node, field, "ncode", nativecode_ptr_type_node);
983 PUSH_FIELD (input_location,
984 method_type_node, field, "throws", ptr_type_node);
985 FINISH_RECORD (method_type_node);
986 build_decl (BUILTINS_LOCATION,
987 TYPE_DECL, get_identifier ("Method"), method_type_node);
989 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
991 t = tree_cons (NULL_TREE, class_ptr_type, endlink);
992 alloc_object_node = add_builtin_function ("_Jv_AllocObject",
993 build_function_type (ptr_type_node, t),
994 0, NOT_BUILT_IN, NULL, NULL_TREE);
995 DECL_IS_MALLOC (alloc_object_node) = 1;
996 alloc_no_finalizer_node =
997 add_builtin_function ("_Jv_AllocObjectNoFinalizer",
998 build_function_type (ptr_type_node, t),
999 0, NOT_BUILT_IN, NULL, NULL_TREE);
1000 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
1002 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1003 soft_initclass_node = add_builtin_function ("_Jv_InitClass",
1004 build_function_type (void_type_node,
1006 0, NOT_BUILT_IN, NULL, NULL_TREE);
1007 t = tree_cons (NULL_TREE, class_ptr_type,
1008 tree_cons (NULL_TREE, int_type_node, endlink));
1009 soft_resolvepoolentry_node
1010 = add_builtin_function ("_Jv_ResolvePoolEntry",
1011 build_function_type (ptr_type_node, t),
1012 0,NOT_BUILT_IN, NULL, NULL_TREE);
1013 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
1014 throw_node = add_builtin_function ("_Jv_Throw",
1015 build_function_type (void_type_node, t),
1016 0, NOT_BUILT_IN, NULL, NULL_TREE);
1017 /* Mark throw_nodes as `noreturn' functions with side effects. */
1018 TREE_THIS_VOLATILE (throw_node) = 1;
1019 TREE_SIDE_EFFECTS (throw_node) = 1;
1021 t = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node,
1023 soft_monitorenter_node
1024 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1026 soft_monitorexit_node
1027 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1030 t = tree_cons (NULL_TREE, ptr_type_node,
1031 tree_cons (NULL_TREE, int_type_node, endlink));
1033 = add_builtin_function ("_Jv_NewPrimArray",
1034 build_function_type (ptr_type_node, t),
1035 0, NOT_BUILT_IN, NULL, NULL_TREE);
1036 DECL_IS_MALLOC (soft_newarray_node) = 1;
1038 t = tree_cons (NULL_TREE, int_type_node,
1039 tree_cons (NULL_TREE, class_ptr_type,
1040 tree_cons (NULL_TREE, object_ptr_type_node,
1043 = add_builtin_function ("_Jv_NewObjectArray",
1044 build_function_type (ptr_type_node, t),
1045 0, NOT_BUILT_IN, NULL, NULL_TREE);
1046 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1048 /* There is no endlink here because _Jv_NewMultiArray is a varargs
1050 t = tree_cons (NULL_TREE, ptr_type_node,
1051 tree_cons (NULL_TREE, int_type_node, NULL_TREE));
1052 soft_multianewarray_node
1053 = add_builtin_function ("_Jv_NewMultiArray",
1054 build_function_type (ptr_type_node, t),
1055 0, NOT_BUILT_IN, NULL, NULL_TREE);
1056 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1058 t = build_function_type (void_type_node,
1059 tree_cons (NULL_TREE, int_type_node, endlink));
1060 soft_badarrayindex_node
1061 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1062 0, NOT_BUILT_IN, NULL, NULL_TREE);
1063 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1065 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1066 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1068 soft_nullpointer_node
1069 = add_builtin_function ("_Jv_ThrowNullPointerException",
1070 build_function_type (void_type_node, endlink),
1071 0, NOT_BUILT_IN, NULL, NULL_TREE);
1072 /* Mark soft_nullpointer_node as a `noreturn' function with side
1074 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1075 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1077 soft_abstractmethod_node
1078 = add_builtin_function ("_Jv_ThrowAbstractMethodError",
1079 build_function_type (void_type_node, endlink),
1080 0, NOT_BUILT_IN, NULL, NULL_TREE);
1081 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1083 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1084 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1086 soft_nosuchfield_node
1087 = add_builtin_function ("_Jv_ThrowNoSuchFieldError",
1088 build_function_type (void_type_node, endlink),
1089 0, NOT_BUILT_IN, NULL, NULL_TREE);
1090 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1092 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1093 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1095 t = tree_cons (NULL_TREE, class_ptr_type,
1096 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1098 = add_builtin_function ("_Jv_CheckCast",
1099 build_function_type (ptr_type_node, t),
1100 0, NOT_BUILT_IN, NULL, NULL_TREE);
1101 t = tree_cons (NULL_TREE, object_ptr_type_node,
1102 tree_cons (NULL_TREE, class_ptr_type, endlink));
1103 soft_instanceof_node
1104 = add_builtin_function ("_Jv_IsInstanceOf",
1105 build_function_type (boolean_type_node, t),
1106 0, NOT_BUILT_IN, NULL, NULL_TREE);
1107 DECL_PURE_P (soft_instanceof_node) = 1;
1108 t = tree_cons (NULL_TREE, object_ptr_type_node,
1109 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1110 soft_checkarraystore_node
1111 = add_builtin_function ("_Jv_CheckArrayStore",
1112 build_function_type (void_type_node, t),
1113 0, NOT_BUILT_IN, NULL, NULL_TREE);
1114 t = tree_cons (NULL_TREE, ptr_type_node,
1115 tree_cons (NULL_TREE, ptr_type_node,
1116 tree_cons (NULL_TREE, int_type_node, endlink)));
1117 soft_lookupinterfacemethod_node
1118 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx",
1119 build_function_type (ptr_type_node, t),
1120 0, NOT_BUILT_IN, NULL, NULL_TREE);
1121 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1122 t = tree_cons (NULL_TREE, ptr_type_node,
1123 tree_cons (NULL_TREE, ptr_type_node,
1124 tree_cons (NULL_TREE, ptr_type_node, endlink)));
1125 soft_lookupinterfacemethodbyname_node
1126 = add_builtin_function ("_Jv_LookupInterfaceMethod",
1127 build_function_type (ptr_type_node, t),
1128 0, NOT_BUILT_IN, NULL, NULL_TREE);
1129 t = tree_cons (NULL_TREE, object_ptr_type_node,
1130 tree_cons (NULL_TREE, ptr_type_node,
1131 tree_cons (NULL_TREE, ptr_type_node,
1132 tree_cons (NULL_TREE, int_type_node,
1134 soft_lookupjnimethod_node
1135 = add_builtin_function ("_Jv_LookupJNIMethod",
1136 build_function_type (ptr_type_node, t),
1137 0, NOT_BUILT_IN, NULL, NULL_TREE);
1138 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1139 soft_getjnienvnewframe_node
1140 = add_builtin_function ("_Jv_GetJNIEnvNewFrame",
1141 build_function_type (ptr_type_node, t),
1142 0, NOT_BUILT_IN, NULL, NULL_TREE);
1143 soft_jnipopsystemframe_node
1144 = add_builtin_function ("_Jv_JNI_PopSystemFrame",
1145 build_function_type (void_type_node, t),
1146 0, NOT_BUILT_IN, NULL, NULL_TREE);
1148 t = tree_cons (NULL_TREE, object_ptr_type_node, endlink);
1150 = add_builtin_function ("_Jv_UnwrapJNIweakReference",
1151 build_function_type (object_ptr_type_node, t),
1152 0, NOT_BUILT_IN, NULL, NULL_TREE);
1154 t = tree_cons (NULL_TREE, int_type_node,
1155 tree_cons (NULL_TREE, int_type_node, endlink));
1157 = add_builtin_function ("_Jv_divI",
1158 build_function_type (int_type_node, t),
1159 0, NOT_BUILT_IN, NULL, NULL_TREE);
1162 = add_builtin_function ("_Jv_remI",
1163 build_function_type (int_type_node, t),
1164 0, NOT_BUILT_IN, NULL, NULL_TREE);
1166 t = tree_cons (NULL_TREE, long_type_node,
1167 tree_cons (NULL_TREE, long_type_node, endlink));
1169 = add_builtin_function ("_Jv_divJ",
1170 build_function_type (long_type_node, t),
1171 0, NOT_BUILT_IN, NULL, NULL_TREE);
1174 = add_builtin_function ("_Jv_remJ",
1175 build_function_type (long_type_node, t),
1176 0, NOT_BUILT_IN, NULL, NULL_TREE);
1178 initialize_builtins ();
1180 soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1186 /* Look up NAME in the current binding level and its superiors
1187 in the namespace of variables, functions and typedefs.
1188 Return a ..._DECL node of some kind representing its definition,
1189 or return 0 if it is undefined. */
1192 lookup_name (tree name)
1195 if (current_binding_level != global_binding_level
1196 && IDENTIFIER_LOCAL_VALUE (name))
1197 val = IDENTIFIER_LOCAL_VALUE (name);
1199 val = IDENTIFIER_GLOBAL_VALUE (name);
1203 /* Similar to `lookup_name' but look only at current binding level and
1204 the previous one if it's the parameter level. */
1207 lookup_name_current_level (tree name)
1211 if (current_binding_level == global_binding_level)
1212 return IDENTIFIER_GLOBAL_VALUE (name);
1214 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1217 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
1218 if (DECL_NAME (t) == name)
1224 /* Record a decl-node X as belonging to the current lexical scope.
1225 Check for errors (such as an incompatible declaration for the same
1226 name already seen in the same scope).
1228 Returns either X or an old decl for the same name.
1229 If an old decl is returned, it may have been smashed
1230 to agree with what X says. */
1236 tree name = DECL_NAME (x);
1237 struct binding_level *b = current_binding_level;
1239 if (TREE_CODE (x) != TYPE_DECL)
1240 DECL_CONTEXT (x) = current_function_decl;
1243 t = lookup_name_current_level (name);
1244 if (t != 0 && t == error_mark_node)
1245 /* error_mark_node is 0 for a while during initialization! */
1248 error ("%q+D used prior to declaration", x);
1251 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1252 to point to the TYPE_DECL.
1253 Since Java does not have typedefs, a type can only have
1254 one (true) name, given by a class, interface, or builtin. */
1255 if (TREE_CODE (x) == TYPE_DECL
1256 && TYPE_NAME (TREE_TYPE (x)) == 0
1257 && TREE_TYPE (x) != error_mark_node)
1259 TYPE_NAME (TREE_TYPE (x)) = x;
1260 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1263 /* This name is new in its binding level.
1264 Install the new declaration and return it. */
1265 if (b == global_binding_level)
1267 /* Install a global value. */
1269 IDENTIFIER_GLOBAL_VALUE (name) = x;
1273 /* Here to install a non-global value. */
1274 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1275 IDENTIFIER_LOCAL_VALUE (name) = x;
1277 /* If storing a local value, there may already be one (inherited).
1278 If so, record it for restoration when this binding level ends. */
1280 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1284 /* Put decls on list in reverse order.
1285 We will reverse them later if necessary. */
1286 TREE_CHAIN (x) = b->names;
1293 pushdecl_force_head (tree x)
1295 current_binding_level->names = x;
1298 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1301 pushdecl_top_level (tree x)
1304 struct binding_level *b = current_binding_level;
1306 current_binding_level = global_binding_level;
1308 current_binding_level = b;
1312 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1315 pushdecl_function_level (tree x)
1318 struct binding_level *b = current_binding_level;
1320 current_binding_level = function_binding_level;
1322 current_binding_level = b;
1326 /* Nonzero if we are currently in the global binding level. */
1329 global_bindings_p (void)
1331 return current_binding_level == global_binding_level;
1334 /* Return the list of declarations of the current level.
1335 Note that this list is in reverse order unless/until
1336 you nreverse it; and when you do nreverse it, you must
1337 store the result back using `storedecls' or you will lose. */
1342 return current_binding_level->names;
1345 /* Create a new `struct binding_level'. */
1347 static struct binding_level *
1348 make_binding_level (void)
1351 return ggc_alloc_cleared_binding_level ();
1355 pushlevel (int unused ATTRIBUTE_UNUSED)
1357 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1359 /* Reuse or create a struct for this binding level. */
1361 if (free_binding_level)
1363 newlevel = free_binding_level;
1364 free_binding_level = free_binding_level->level_chain;
1368 newlevel = make_binding_level ();
1371 /* Add this level to the front of the chain (stack) of levels that
1374 *newlevel = clear_binding_level;
1375 newlevel->level_chain = current_binding_level;
1376 newlevel->loc = input_location;
1377 current_binding_level = newlevel;
1378 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1379 newlevel->binding_depth = binding_depth;
1381 fprintf (stderr, "push %s level %p pc %d\n",
1382 (is_class_level) ? "class" : "block", newlevel, current_pc);
1385 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1388 /* Exit a binding level.
1389 Pop the level off, and restore the state of the identifier-decl mappings
1390 that were in effect when this level was entered.
1392 If KEEP is nonzero, this level had explicit declarations, so
1393 and create a "block" (a BLOCK node) for the level
1394 to record its declarations and subblocks for symbol table output.
1396 If FUNCTIONBODY is nonzero, this level is the body of a function,
1397 so create a block as if KEEP were set and also clear out all
1400 If REVERSE is nonzero, reverse the order of decls before putting
1401 them into the BLOCK. */
1404 poplevel (int keep, int reverse, int functionbody)
1407 /* The chain of decls was accumulated in reverse order.
1408 Put it into forward order, just for cleanliness. */
1410 tree subblocks = current_binding_level->blocks;
1415 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1418 if (current_binding_level->end_pc != LARGEST_PC)
1419 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1420 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1421 current_binding_level->end_pc);
1423 fprintf (stderr, "pop %s level %p pc %d\n",
1424 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1425 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1427 /* Get the decls in the order they were written.
1428 Usually current_binding_level->names is in reverse order.
1429 But parameter decls were previously put in forward order. */
1432 current_binding_level->names
1433 = decls = nreverse (current_binding_level->names);
1435 decls = current_binding_level->names;
1437 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1438 if (TREE_CODE (decl) == VAR_DECL
1439 && DECL_LANG_SPECIFIC (decl) != NULL
1440 && DECL_LOCAL_SLOT_NUMBER (decl))
1441 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1443 /* If there were any declarations in that level,
1444 or if this level is a function body,
1445 create a BLOCK to record them for the life of this function. */
1448 if (keep || functionbody)
1450 block = make_node (BLOCK);
1451 TREE_TYPE (block) = void_type_node;
1454 if (current_binding_level->exception_range)
1455 expand_end_java_handler (current_binding_level->exception_range);
1459 /* If any statements have been generated at this level, create a
1460 BIND_EXPR to hold them and copy the variables to it. This
1461 only applies to the bytecode compiler. */
1462 if (current_binding_level->stmts)
1465 tree *var = &BLOCK_VARS (block);
1467 /* Copy decls from names list, ignoring labels. */
1470 tree next = TREE_CHAIN (decl);
1471 if (TREE_CODE (decl) != LABEL_DECL)
1474 var = &TREE_CHAIN (decl);
1480 bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
1481 BLOCK_EXPR_BODY (block), block);
1482 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1484 if (BIND_EXPR_BODY (bind)
1485 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1486 TREE_SIDE_EFFECTS (bind) = 1;
1488 /* FIXME: gimplifier brain damage. */
1489 if (BIND_EXPR_BODY (bind) == NULL)
1490 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1492 SET_EXPR_LOCATION (bind, current_binding_level->loc);
1494 current_binding_level->stmts = NULL;
1498 BLOCK_VARS (block) = decls;
1500 BLOCK_SUBBLOCKS (block) = subblocks;
1503 /* In each subblock, record that this is its superior. */
1505 for (link = subblocks; link; link = TREE_CHAIN (link))
1506 BLOCK_SUPERCONTEXT (link) = block;
1508 /* Clear out the meanings of the local variables of this level. */
1510 for (link = decls; link; link = TREE_CHAIN (link))
1512 tree name = DECL_NAME (link);
1513 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1515 /* If the ident. was used or addressed via a local extern decl,
1516 don't forget that fact. */
1517 if (DECL_EXTERNAL (link))
1519 if (TREE_USED (link))
1520 TREE_USED (name) = 1;
1521 if (TREE_ADDRESSABLE (link))
1522 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1524 IDENTIFIER_LOCAL_VALUE (name) = 0;
1528 /* Restore all name-meanings of the outer levels
1529 that were shadowed by this level. */
1531 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1532 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1534 /* If the level being exited is the top level of a function,
1535 check over all the labels, and clear out the current
1536 (function local) meanings of their names. */
1540 /* If this is the top level block of a function,
1541 the vars are the function's parameters.
1542 Don't leave them in the BLOCK because they are
1543 found in the FUNCTION_DECL instead. */
1545 BLOCK_VARS (block) = 0;
1548 /* Pop the current level, and free the structure for reuse. */
1551 struct binding_level *level = current_binding_level;
1552 current_binding_level = current_binding_level->level_chain;
1554 level->level_chain = free_binding_level;
1555 free_binding_level = level;
1558 /* Dispose of the block that we just made inside some higher level. */
1561 DECL_INITIAL (current_function_decl) = block;
1562 DECL_SAVED_TREE (current_function_decl) = bind;
1568 current_binding_level->blocks
1569 = chainon (current_binding_level->blocks, block);
1571 /* If we did not make a block for the level just exited,
1572 any blocks made for inner levels
1573 (since they cannot be recorded as subblocks in that level)
1574 must be carried forward so they will later become subblocks
1575 of something else. */
1577 current_binding_level->blocks
1578 = chainon (current_binding_level->blocks, subblocks);
1581 java_add_stmt (bind);
1585 TREE_USED (block) = 1;
1590 maybe_pushlevels (int pc)
1592 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1596 while (pending_local_decls != NULL_TREE &&
1597 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1599 tree *ptr = &pending_local_decls;
1600 tree decl = *ptr, next;
1601 int end_pc = DECL_LOCAL_END_PC (decl);
1603 while (*ptr != NULL_TREE
1604 && DECL_LOCAL_START_PC (*ptr) <= pc
1605 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1606 ptr = &TREE_CHAIN (*ptr);
1607 pending_local_decls = *ptr;
1610 /* Force non-nested range to be nested in current range by
1611 truncating variable lifetimes. */
1612 if (end_pc > current_binding_level->end_pc)
1615 end_pc = current_binding_level->end_pc;
1616 for (t = decl; t != NULL_TREE; t = TREE_CHAIN (t))
1617 DECL_LOCAL_END_PC (t) = end_pc;
1620 maybe_start_try (pc, end_pc);
1624 current_binding_level->end_pc = end_pc;
1625 current_binding_level->start_pc = pc;
1626 current_binding_level->names = NULL;
1627 for ( ; decl != NULL_TREE; decl = next)
1629 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1631 next = TREE_CHAIN (decl);
1632 push_jvm_slot (index, decl);
1635 = find_local_variable (index, TREE_TYPE (decl), pc);
1636 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1637 base_decl = TREE_VEC_ELT (base_decl_map, index);
1638 SET_DECL_VALUE_EXPR (decl, base_decl);
1639 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1643 maybe_start_try (pc, 0);
1647 maybe_poplevels (int pc)
1649 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1653 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1654 inclusive, so a variable is live if pc == end_pc. Here, we
1655 terminate a range if the current pc is equal to the end of the
1656 range, and this is *before* we have generated code for the
1657 instruction at end_pc. We're closing a binding level one
1658 instruction too early.*/
1659 while (current_binding_level->end_pc <= pc)
1663 /* Terminate any binding which began during the range beginning at
1664 start_pc. This tidies up improperly nested local variable ranges
1665 and exception handlers; a variable declared within an exception
1666 range is forcibly terminated when that exception ends. */
1669 force_poplevels (int start_pc)
1671 while (current_binding_level->start_pc > start_pc)
1673 if (pedantic && current_binding_level->start_pc > start_pc)
1674 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1675 current_function_decl,
1676 current_binding_level->start_pc);
1681 /* integrate_decl_tree calls this function. */
1684 java_dup_lang_specific_decl (tree node)
1687 struct lang_decl *x;
1689 if (!DECL_LANG_SPECIFIC (node))
1692 lang_decl_size = sizeof (struct lang_decl);
1693 x = ggc_alloc_lang_decl (lang_decl_size);
1694 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1695 DECL_LANG_SPECIFIC (node) = x;
1699 give_name_to_locals (JCF *jcf)
1701 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1702 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1704 pending_local_decls = NULL_TREE;
1708 n = JCF_readu2 (jcf);
1709 for (i = 0; i < n; i++)
1711 int start_pc = JCF_readu2 (jcf);
1712 int length = JCF_readu2 (jcf);
1713 int name_index = JCF_readu2 (jcf);
1714 int signature_index = JCF_readu2 (jcf);
1715 int slot = JCF_readu2 (jcf);
1716 tree name = get_name_constant (jcf, name_index);
1717 tree type = parse_signature (jcf, signature_index);
1718 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1720 && length == DECL_CODE_LENGTH (current_function_decl))
1722 tree decl = TREE_VEC_ELT (decl_map, slot);
1723 DECL_NAME (decl) = name;
1724 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1725 warning (0, "bad type in parameter debug info");
1730 int end_pc = start_pc + length;
1731 tree decl = build_decl (input_location, VAR_DECL, name, type);
1732 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1734 warning (0, "bad PC range for debug info for local %q+D",
1736 end_pc = DECL_CODE_LENGTH (current_function_decl);
1739 /* Adjust start_pc if necessary so that the local's first
1740 store operation will use the relevant DECL as a
1741 destination. Fore more information, read the leading
1742 comments for expr.c:maybe_adjust_start_pc. */
1743 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1745 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1746 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1747 DECL_LOCAL_START_PC (decl) = start_pc;
1748 DECL_LOCAL_END_PC (decl) = end_pc;
1750 /* Now insert the new decl in the proper place in
1751 pending_local_decls. We are essentially doing an insertion sort,
1752 which works fine, since the list input will normally already
1754 ptr = &pending_local_decls;
1755 while (*ptr != NULL_TREE
1756 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1757 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1758 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1759 ptr = &TREE_CHAIN (*ptr);
1760 TREE_CHAIN (decl) = *ptr;
1765 pending_local_decls = nreverse (pending_local_decls);
1767 /* Fill in default names for the parameters. */
1768 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1769 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1771 if (DECL_NAME (parm) == NULL_TREE)
1773 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1775 DECL_NAME (parm) = get_identifier ("this");
1779 sprintf (buffer, "ARG_%d", arg_i);
1780 DECL_NAME (parm) = get_identifier (buffer);
1787 build_result_decl (tree fndecl)
1789 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1790 tree result = DECL_RESULT (fndecl);
1793 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1794 RESULT_DECL, NULL_TREE, restype);
1795 DECL_ARTIFICIAL (result) = 1;
1796 DECL_IGNORED_P (result) = 1;
1797 DECL_CONTEXT (result) = fndecl;
1798 DECL_RESULT (fndecl) = result;
1804 start_java_method (tree fndecl)
1811 current_function_decl = fndecl;
1812 announce_function (fndecl);
1814 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1815 decl_map = make_tree_vec (i);
1816 base_decl_map = make_tree_vec (i);
1817 type_map = XRESIZEVEC (tree, type_map, i);
1819 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1820 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1822 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1823 pushlevel (1); /* Push parameters. */
1825 ptr = &DECL_ARGUMENTS (fndecl);
1826 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1827 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1829 tree parm_name = NULL_TREE, parm_decl;
1830 tree parm_type = TREE_VALUE (tem);
1831 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1833 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1834 DECL_CONTEXT (parm_decl) = fndecl;
1835 if (targetm.calls.promote_prototypes (parm_type)
1836 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1837 && INTEGRAL_TYPE_P (parm_type))
1838 parm_type = integer_type_node;
1839 DECL_ARG_TYPE (parm_decl) = parm_type;
1842 ptr = &TREE_CHAIN (parm_decl);
1844 /* Add parm_decl to the decl_map. */
1845 push_jvm_slot (i, parm_decl);
1847 /* The this parameter of methods is artificial. */
1848 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE && i == 0)
1849 DECL_ARTIFICIAL (parm_decl) = 1;
1851 type_map[i] = TREE_TYPE (parm_decl);
1852 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1855 type_map[i] = void_type_node;
1859 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1861 while (i < DECL_MAX_LOCALS(fndecl))
1862 type_map[i++] = NULL_TREE;
1864 build_result_decl (fndecl);
1865 DECL_SOURCE_LOCATION (fndecl) = input_location;
1867 /* Push local variables. */
1870 function_binding_level = current_binding_level;
1874 end_java_method (void)
1876 tree fndecl = current_function_decl;
1878 /* pop out of function */
1881 /* pop out of its parameters */
1884 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1886 if (DECL_SAVED_TREE (fndecl))
1888 tree fbody, block_body;
1889 /* Before we check initialization, attached all class initialization
1890 variable to the block_body */
1891 fbody = DECL_SAVED_TREE (fndecl);
1892 block_body = BIND_EXPR_BODY (fbody);
1893 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1894 attach_init_test_initialization_flags, block_body);
1897 finish_method (fndecl);
1899 current_function_decl = NULL_TREE;
1900 base_decl_map = NULL_TREE;
1903 /* Prepare a method for expansion. */
1906 finish_method (tree fndecl)
1908 tree *tp = &DECL_SAVED_TREE (fndecl);
1910 /* Wrap body of synchronized methods in a monitorenter,
1911 plus monitorexit cleanup. */
1912 if (METHOD_SYNCHRONIZED (fndecl))
1914 tree enter, exit, lock;
1915 if (METHOD_STATIC (fndecl))
1916 lock = build_class_ref (DECL_CONTEXT (fndecl));
1918 lock = DECL_ARGUMENTS (fndecl);
1919 BUILD_MONITOR_ENTER (enter, lock);
1920 BUILD_MONITOR_EXIT (exit, lock);
1921 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1922 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1925 /* Convert function tree to GENERIC prior to inlining. */
1926 java_genericize (fndecl);
1928 /* Store the end of the function, so that we get good line number
1929 info for the epilogue. */
1930 if (DECL_STRUCT_FUNCTION (fndecl))
1931 set_cfun (DECL_STRUCT_FUNCTION (fndecl));
1933 allocate_struct_function (fndecl, false);
1934 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1936 /* Defer inlining and expansion to the cgraph optimizers. */
1937 cgraph_finalize_function (fndecl, false);
1940 /* We pessimistically marked all methods and fields external until we
1941 knew what set of classes we were planning to compile. Now mark those
1942 associated with CLASS to be generated locally as not external. */
1945 java_mark_decl_local (tree decl)
1947 DECL_EXTERNAL (decl) = 0;
1949 #ifdef ENABLE_CHECKING
1950 /* Double check that we didn't pass the function to the callgraph early. */
1951 if (TREE_CODE (decl) == FUNCTION_DECL)
1952 gcc_assert (!cgraph_node (decl)->local.finalized);
1954 gcc_assert (!DECL_RTL_SET_P (decl));
1957 /* Given appropriate target support, G++ will emit hidden aliases for native
1958 methods. Using this hidden name is required for proper operation of
1959 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1960 proper target support, then mark the method for aliasing. */
1963 java_mark_cni_decl_local (tree decl)
1965 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1969 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1970 DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1972 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1973 mangler. We might have already referenced this native method and
1974 therefore created its name, but even if we have it won't hurt.
1975 We'll just go via its externally visible name, rather than its
1976 hidden alias. However, we must force things so that the correct
1977 mangling is done. */
1979 if (DECL_ASSEMBLER_NAME_SET_P (decl))
1980 java_mangle_decl (decl);
1981 if (DECL_RTL_SET_P (decl))
1983 SET_DECL_RTL (decl, 0);
1984 make_decl_rtl (decl);
1988 /* Use the preceding two functions and mark all members of the class. */
1991 java_mark_class_local (tree klass)
1995 for (t = TYPE_FIELDS (klass); t ; t = TREE_CHAIN (t))
1996 if (FIELD_STATIC (t))
1998 if (DECL_EXTERNAL (t))
1999 VEC_safe_push (tree, gc, pending_static_fields, t);
2000 java_mark_decl_local (t);
2003 for (t = TYPE_METHODS (klass); t ; t = TREE_CHAIN (t))
2004 if (!METHOD_ABSTRACT (t))
2006 if (METHOD_NATIVE (t) && !flag_jni)
2007 java_mark_cni_decl_local (t);
2009 java_mark_decl_local (t);
2013 /* Add a statement to a compound_expr. */
2016 add_stmt_to_compound (tree existing, tree type, tree stmt)
2022 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
2023 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
2024 | TREE_SIDE_EFFECTS (stmt);
2031 /* If this node is an expr, mark its input location. Called from
2035 set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
2036 void *data ATTRIBUTE_UNUSED)
2040 if (CAN_HAVE_LOCATION_P (t))
2042 if (EXPR_HAS_LOCATION(t))
2043 return t; /* Don't walk any further into this expr. */
2045 SET_EXPR_LOCATION (t, input_location);
2048 return NULL_TREE; /* Continue walking this expr. */
2051 /* Add a statement to the statement_list currently being constructed.
2052 If the statement_list is null, we don't create a singleton list.
2053 This is necessary because poplevel() assumes that adding a
2054 statement to a null statement_list returns the statement. */
2057 java_add_stmt (tree new_stmt)
2059 tree stmts = current_binding_level->stmts;
2060 tree_stmt_iterator i;
2063 walk_tree (&new_stmt, set_input_location, NULL, NULL);
2066 return current_binding_level->stmts = new_stmt;
2068 /* Force STMTS to be a statement_list. */
2069 if (TREE_CODE (stmts) != STATEMENT_LIST)
2071 tree t = make_node (STATEMENT_LIST);
2073 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2077 i = tsi_last (stmts);
2078 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2079 TREE_TYPE (stmts) = void_type_node;
2081 return current_binding_level->stmts = stmts;
2084 /* Add a variable to the current scope. */
2087 java_add_local_var (tree decl)
2089 tree *vars = ¤t_binding_level->names;
2091 TREE_CHAIN (decl) = next;
2093 DECL_CONTEXT (decl) = current_function_decl;
2094 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2098 /* Return a pointer to the compound_expr currently being
2104 return ¤t_binding_level->stmts;
2107 /* Register an exception range as belonging to the current binding
2108 level. There may only be one: if there are more, we'll create more
2109 binding levels. However, each range can have multiple handlers,
2110 and these are expanded when we call expand_end_java_handler(). */
2113 register_exception_range (struct eh_range *range, int pc, int end_pc)
2115 gcc_assert (! current_binding_level->exception_range);
2116 current_binding_level->exception_range = range;
2117 current_binding_level->end_pc = end_pc;
2118 current_binding_level->start_pc = pc;
2121 #include "gt-java-decl.h"