1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996-2013 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
29 #include "coretypes.h"
31 #include "stor-layout.h"
32 #include "stringpool.h"
34 #include "diagnostic-core.h"
37 #include "java-tree.h"
39 #include "java-except.h"
42 #include "tree-inline.h"
45 #include "tree-iterator.h"
46 #include "langhooks.h"
49 #if defined (DEBUG_JAVA_BINDING_LEVELS)
50 extern void indent (void);
53 static tree
push_jvm_slot (int, tree
);
54 static tree
lookup_name_current_level (tree
);
55 static tree
push_promoted_type (const char *, tree
);
56 static struct binding_level
*make_binding_level (void);
57 static tree
create_primitive_vtable (const char *);
58 static tree
check_local_unnamed_variable (tree
, tree
, tree
);
59 static void parse_version (void);
62 /* The following ABI flags are used in the high-order bits of the version
63 ID field. The version ID number itself should never be larger than
64 0xfffff, so it should be safe to use top 12 bits for these flags. */
66 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
68 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
69 should be loaded by the bootstrap
72 /* If an ABI change is made within a GCC release series, rendering current
73 binaries incompatible with the old runtimes, this number must be set to
74 enforce the compatibility rules. */
75 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
77 /* The runtime may recognize a variety of BC ABIs (objects generated by
78 different version of gcj), but will probably always require strict
79 matching for the ordinary (C++) ABI. */
81 /* The version ID of the BC ABI that we generate. This must be kept in
82 sync with parse_version(), libgcj, and reality (if the BC format changes,
84 #define GCJ_CURRENT_BC_ABI_VERSION \
85 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
87 /* The ABI version number. */
90 /* Name of the Cloneable class. */
91 tree java_lang_cloneable_identifier_node
;
93 /* Name of the Serializable class. */
94 tree java_io_serializable_identifier_node
;
96 /* The DECL_MAP is a mapping from (index, type) to a decl node.
97 If index < max_locals, it is the index of a local variable.
98 if index >= max_locals, then index-max_locals is a stack slot.
99 The DECL_MAP mapping is represented as a TREE_VEC whose elements
100 are a list of decls (VAR_DECL or PARM_DECL) chained by
101 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
102 we search the chain for a decl with a matching TREE_TYPE. */
104 static GTY(()) tree decl_map
;
106 /* The base_decl_map is contains one variable of ptr_type: this is
107 used to contain every variable of reference type that is ever
108 stored in a local variable slot. */
110 static GTY(()) tree base_decl_map
;
112 /* An index used to make temporary identifiers unique. */
115 /* A list of local variables VAR_DECLs for this method that we have seen
116 debug information, but we have not reached their starting (byte) PC yet. */
118 static GTY(()) tree pending_local_decls
;
120 /* The decl for "_Jv_ResolvePoolEntry". */
121 tree soft_resolvepoolentry_node
;
123 /* The decl for the .constants field of an instance of Class. */
124 tree constants_field_decl_node
;
126 /* The decl for the .data field of an instance of Class. */
127 tree constants_data_field_decl_node
;
129 #if defined(DEBUG_JAVA_BINDING_LEVELS)
130 int binding_depth
= 0;
131 int is_class_level
= 0;
139 for (i
= 0; i
< binding_depth
*2; i
++)
142 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
144 /* True if decl is a named local variable, i.e. if it is an alias
145 that's used only for debugging purposes. */
148 debug_variable_p (tree decl
)
150 if (TREE_CODE (decl
) == PARM_DECL
)
153 if (LOCAL_SLOT_P (decl
))
160 push_jvm_slot (int index
, tree decl
)
162 DECL_CONTEXT (decl
) = current_function_decl
;
163 layout_decl (decl
, 0);
165 /* Now link the decl into the decl_map. */
166 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
168 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
169 DECL_LOCAL_START_PC (decl
) = 0;
170 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
171 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
173 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
174 TREE_VEC_ELT (decl_map
, index
) = decl
;
179 /* Find the best declaration based upon type. If 'decl' fits 'type' better
180 than 'best', return 'decl'. Otherwise return 'best'. */
183 check_local_unnamed_variable (tree best
, tree decl
, tree type
)
185 tree decl_type
= TREE_TYPE (decl
);
187 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl
));
189 /* Use the same decl for all integer types <= 32 bits. This is
190 necessary because sometimes a value is stored as (for example)
191 boolean but loaded as int. */
192 if (decl_type
== type
193 || (INTEGRAL_TYPE_P (decl_type
)
194 && INTEGRAL_TYPE_P (type
)
195 && TYPE_PRECISION (decl_type
) <= 32
196 && TYPE_PRECISION (type
) <= 32
197 && TYPE_PRECISION (decl_type
) >= TYPE_PRECISION (type
))
198 /* ptr_type_node is used for null pointers, which are
199 assignment compatible with everything. */
200 || (TREE_CODE (decl_type
) == POINTER_TYPE
201 && type
== ptr_type_node
)
202 /* Whenever anyone wants to use a slot that is initially
203 occupied by a PARM_DECL of pointer type they must get that
204 decl, even if they asked for a pointer to a different type.
205 However, if someone wants a scalar variable in a slot that
206 initially held a pointer arg -- or vice versa -- we create a
209 ???: As long as verification is correct, this will be a
210 compatible type. But maybe we should create a dummy variable
211 and replace all references to it with the DECL and a
214 || (TREE_CODE (decl_type
) == POINTER_TYPE
215 && TREE_CODE (decl
) == PARM_DECL
216 && TREE_CODE (type
) == POINTER_TYPE
))
218 if (best
== NULL_TREE
219 || (decl_type
== type
&& TREE_TYPE (best
) != type
))
227 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
228 that is valid at PC (or -1 if any pc).
229 If there is no existing matching decl, allocate one. */
232 find_local_variable (int index
, tree type
, int pc ATTRIBUTE_UNUSED
)
234 tree tmp
= TREE_VEC_ELT (decl_map
, index
);
235 tree decl
= NULL_TREE
;
237 /* Scan through every declaration that has been created in this
238 slot. We're only looking for variables that correspond to local
239 index declarations and PARM_DECLs, not named variables: such
240 local variables are used only for debugging information. */
241 while (tmp
!= NULL_TREE
)
243 if (! debug_variable_p (tmp
))
244 decl
= check_local_unnamed_variable (decl
, tmp
, type
);
245 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
248 /* gcj has a function called promote_type(), which is used by both
249 the bytecode compiler and the source compiler. Unfortunately,
250 the type systems for the Java VM and the Java language are not
251 the same: a boolean in the VM promotes to an int, not to a wide
252 boolean. If our caller wants something to hold a boolean, that
253 had better be an int, because that slot might be re-used
254 later in integer context. */
255 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
256 type
= integer_type_node
;
258 /* If we don't find a match, create one with the type passed in.
259 The name of the variable is #n#m, which n is the variable index
260 in the local variable area and m is a dummy identifier for
261 uniqueness -- multiple variables may share the same local
262 variable index. We don't call pushdecl() to push pointer types
263 into a binding expr because they'll all be replaced by a single
264 variable that is used for every reference in that local variable
270 sprintf (buf
, "#slot#%d#%d", index
, uniq
++);
271 name
= get_identifier (buf
);
272 decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
273 DECL_IGNORED_P (decl
) = 1;
274 DECL_ARTIFICIAL (decl
) = 1;
275 decl
= push_jvm_slot (index
, decl
);
276 LOCAL_SLOT_P (decl
) = 1;
278 if (TREE_CODE (type
) != POINTER_TYPE
)
279 pushdecl_function_level (decl
);
282 /* As well as creating a local variable that matches the type, we
283 also create a base variable (of ptr_type) that will hold all its
285 if (TREE_CODE (type
) == POINTER_TYPE
286 && ! TREE_VEC_ELT (base_decl_map
, index
))
291 sprintf (buf
, "#ref#%d#%d", index
, uniq
++);
292 name
= get_identifier (buf
);
294 = TREE_VEC_ELT (base_decl_map
, index
)
295 = build_decl (input_location
, VAR_DECL
, name
, ptr_type_node
);
296 pushdecl_function_level (base_decl
);
297 DECL_IGNORED_P (base_decl
) = 1;
298 DECL_ARTIFICIAL (base_decl
) = 1;
304 /* Called during genericization for every variable. If the variable
305 is a temporary of pointer type, replace it with a common variable
306 thath is used to hold all pointer types that are ever stored in
307 that slot. Set WANT_LVALUE if you want a variable that is to be
311 java_replace_reference (tree var_decl
, bool want_lvalue
)
318 decl_type
= TREE_TYPE (var_decl
);
320 if (TREE_CODE (decl_type
) == POINTER_TYPE
)
322 if (DECL_LANG_SPECIFIC (var_decl
)
323 && LOCAL_SLOT_P (var_decl
))
325 int index
= DECL_LOCAL_SLOT_NUMBER (var_decl
);
326 tree base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
328 gcc_assert (base_decl
);
330 base_decl
= build1 (NOP_EXPR
, decl_type
, base_decl
);
339 /* Helper for java_genericize. */
342 java_replace_references (tree
*tp
, int *walk_subtrees
,
343 void *data ATTRIBUTE_UNUSED
)
345 if (TREE_CODE (*tp
) == MODIFY_EXPR
)
347 source_location loc
= EXPR_LOCATION (*tp
);
348 tree lhs
= TREE_OPERAND (*tp
, 0);
349 /* This is specific to the bytecode compiler. If a variable has
350 LOCAL_SLOT_P set, replace an assignment to it with an assignment
351 to the corresponding variable that holds all its aliases. */
352 if (TREE_CODE (lhs
) == VAR_DECL
353 && DECL_LANG_SPECIFIC (lhs
)
354 && LOCAL_SLOT_P (lhs
)
355 && TREE_CODE (TREE_TYPE (lhs
)) == POINTER_TYPE
)
357 tree new_lhs
= java_replace_reference (lhs
, /* want_lvalue */ true);
358 tree new_rhs
= build1 (NOP_EXPR
, TREE_TYPE (new_lhs
),
359 TREE_OPERAND (*tp
, 1));
360 tree tem
= build2 (MODIFY_EXPR
, TREE_TYPE (new_lhs
),
362 *tp
= build1 (NOP_EXPR
, TREE_TYPE (lhs
), tem
);
363 SET_EXPR_LOCATION (tem
, loc
);
364 SET_EXPR_LOCATION (new_rhs
, loc
);
365 SET_EXPR_LOCATION (*tp
, loc
);
368 if (TREE_CODE (*tp
) == VAR_DECL
)
370 *tp
= java_replace_reference (*tp
, /* want_lvalue */ false);
377 /* Same as find_local_index, except that INDEX is a stack index. */
380 find_stack_slot (int index
, tree type
)
382 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
388 /* A chain of _DECL nodes for all variables, constants, functions,
389 * and typedef types. These are in the reverse of the order supplied.
393 /* For each level, a list of shadowed outer-level local definitions
394 to be restored when this level is popped.
395 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
396 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
399 /* For each level (except not the global one),
400 a chain of BLOCK nodes for all the levels
401 that were entered and exited one level down. */
404 /* The binding level which this one is contained in (inherits from). */
405 struct binding_level
*level_chain
;
407 /* The bytecode PC that marks the end of this level. */
409 /* The bytecode PC that marks the start of this level. */
412 /* The statements in this binding level. */
415 /* An exception range associated with this binding level. */
416 struct eh_range
* GTY((skip (""))) exception_range
;
418 /* Binding depth at which this level began. Used only for debugging. */
419 unsigned binding_depth
;
421 /* The location at which this level began. */
425 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
427 /* The binding level currently in effect. */
429 static GTY(()) struct binding_level
*current_binding_level
;
431 /* A chain of binding_level structures awaiting reuse. */
433 static GTY(()) struct binding_level
*free_binding_level
;
435 /* The outermost binding level, for names of file scope.
436 This is created when the compiler is started and exists
437 through the entire run. */
439 static GTY(()) struct binding_level
*global_binding_level
;
441 /* The binding level that holds variables declared at the outermost
442 level within a function body. */
444 static struct binding_level
*function_binding_level
;
446 /* A PC value bigger than any PC value we may ever may encounter. */
448 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
450 /* Binding level structures are initialized by copying this one. */
452 static const struct binding_level clear_binding_level
454 NULL_TREE
, /* names */
455 NULL_TREE
, /* shadowed */
456 NULL_TREE
, /* blocks */
457 NULL_BINDING_LEVEL
, /* level_chain */
458 LARGEST_PC
, /* end_pc */
461 NULL
, /* exception_range */
462 0, /* binding_depth */
466 tree java_global_trees
[JTI_MAX
];
468 /* Build (and pushdecl) a "promoted type" for all standard
469 types shorter than int. */
472 push_promoted_type (const char *name
, tree actual_type
)
474 tree type
= make_node (TREE_CODE (actual_type
));
476 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
477 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
479 tree in_min
= TYPE_MIN_VALUE (actual_type
);
480 tree in_max
= TYPE_MAX_VALUE (actual_type
);
482 TYPE_MIN_VALUE (type
) = copy_node (in_min
);
483 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
484 TYPE_MAX_VALUE (type
) = copy_node (in_max
);
485 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
486 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
487 TYPE_STRING_FLAG (type
) = TYPE_STRING_FLAG (actual_type
);
489 pushdecl (build_decl (input_location
,
490 TYPE_DECL
, get_identifier (name
), type
));
494 /* Return tree that represents a vtable for a primitive array. */
496 create_primitive_vtable (const char *name
)
501 sprintf (buf
, "_Jv_%sVTable", name
);
502 r
= build_decl (input_location
,
503 VAR_DECL
, get_identifier (buf
), ptr_type_node
);
504 DECL_EXTERNAL (r
) = 1;
508 /* Parse the version string and compute the ABI version number. */
512 const char *p
= version_string
;
513 unsigned int major
= 0, minor
= 0;
514 unsigned int abi_version
;
516 /* Skip leading junk. */
517 while (*p
&& !ISDIGIT (*p
))
521 /* Extract major version. */
524 major
= major
* 10 + *p
- '0';
528 gcc_assert (*p
== '.' && ISDIGIT (p
[1]));
531 /* Extract minor version. */
534 minor
= minor
* 10 + *p
- '0';
538 if (flag_indirect_dispatch
)
540 abi_version
= GCJ_CURRENT_BC_ABI_VERSION
;
541 abi_version
|= FLAG_BINARYCOMPAT_ABI
;
545 /* Implicit in this computation is the idea that we won't break the
546 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
548 abi_version
= 100000 * major
+ 1000 * minor
;
550 if (flag_bootstrap_classes
)
551 abi_version
|= FLAG_BOOTSTRAP_LOADER
;
553 gcj_abi_version
= build_int_cstu (ptr_type_node
, abi_version
);
557 java_init_decl_processing (void)
559 tree field
= NULL_TREE
;
562 init_class_processing ();
564 current_function_decl
= NULL
;
565 current_binding_level
= NULL_BINDING_LEVEL
;
566 free_binding_level
= NULL_BINDING_LEVEL
;
567 pushlevel (0); /* make the binding_level structure for global names */
568 global_binding_level
= current_binding_level
;
570 /* Build common tree nodes, Java has an unsigned char. */
571 build_common_tree_nodes (false, false);
573 /* ??? Now we continue and override some of the built types again
574 with Java specific types. As the above generated types are
575 supposed to match the targets C ABI this isn't really the way
576 to go and any Java specifics should _not_ use those global types
577 if the Java ABI does not match the C one. */
579 byte_type_node
= make_signed_type (8);
580 pushdecl (build_decl (BUILTINS_LOCATION
,
581 TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
582 short_type_node
= make_signed_type (16);
583 pushdecl (build_decl (BUILTINS_LOCATION
,
584 TYPE_DECL
, get_identifier ("short"), short_type_node
));
585 int_type_node
= make_signed_type (32);
586 pushdecl (build_decl (BUILTINS_LOCATION
,
587 TYPE_DECL
, get_identifier ("int"), int_type_node
));
588 long_type_node
= make_signed_type (64);
589 pushdecl (build_decl (BUILTINS_LOCATION
,
590 TYPE_DECL
, get_identifier ("long"), long_type_node
));
592 unsigned_byte_type_node
= make_unsigned_type (8);
593 pushdecl (build_decl (BUILTINS_LOCATION
,
594 TYPE_DECL
, get_identifier ("unsigned byte"),
595 unsigned_byte_type_node
));
596 unsigned_short_type_node
= make_unsigned_type (16);
597 pushdecl (build_decl (BUILTINS_LOCATION
,
598 TYPE_DECL
, get_identifier ("unsigned short"),
599 unsigned_short_type_node
));
600 unsigned_int_type_node
= make_unsigned_type (32);
601 pushdecl (build_decl (BUILTINS_LOCATION
,
602 TYPE_DECL
, get_identifier ("unsigned int"),
603 unsigned_int_type_node
));
604 unsigned_long_type_node
= make_unsigned_type (64);
605 pushdecl (build_decl (BUILTINS_LOCATION
,
606 TYPE_DECL
, get_identifier ("unsigned long"),
607 unsigned_long_type_node
));
609 /* Define these next since types below may used them. */
610 integer_type_node
= java_type_for_size (INT_TYPE_SIZE
, 0);
611 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
612 integer_one_node
= build_int_cst (NULL_TREE
, 1);
613 integer_two_node
= build_int_cst (NULL_TREE
, 2);
614 integer_three_node
= build_int_cst (NULL_TREE
, 3);
615 integer_four_node
= build_int_cst (NULL_TREE
, 4);
616 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
618 /* A few values used for range checking in the lexer. */
619 decimal_int_max
= build_int_cstu (unsigned_int_type_node
, 0x80000000);
621 = double_int_to_tree (unsigned_long_type_node
,
622 double_int_zero
.set_bit (64));
624 long_zero_node
= build_int_cst (long_type_node
, 0);
626 pushdecl (build_decl (BUILTINS_LOCATION
,
627 TYPE_DECL
, get_identifier ("void"), void_type_node
));
629 t
= make_node (VOID_TYPE
);
630 layout_type (t
); /* Uses size_zero_node */
631 return_address_type_node
= build_pointer_type (t
);
633 char_type_node
= make_unsigned_type (16);
634 TYPE_STRING_FLAG (char_type_node
) = 1;
635 pushdecl (build_decl (BUILTINS_LOCATION
,
636 TYPE_DECL
, get_identifier ("char"), char_type_node
));
638 boolean_type_node
= make_unsigned_type (1);
639 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
640 pushdecl (build_decl (BUILTINS_LOCATION
,
641 TYPE_DECL
, get_identifier ("boolean"),
643 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
644 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
646 promoted_byte_type_node
647 = push_promoted_type ("promoted_byte", byte_type_node
);
648 promoted_short_type_node
649 = push_promoted_type ("promoted_short", short_type_node
);
650 promoted_char_type_node
651 = push_promoted_type ("promoted_char", char_type_node
);
652 promoted_boolean_type_node
653 = push_promoted_type ("promoted_boolean", boolean_type_node
);
655 float_type_node
= make_node (REAL_TYPE
);
656 TYPE_PRECISION (float_type_node
) = 32;
657 pushdecl (build_decl (BUILTINS_LOCATION
,
658 TYPE_DECL
, get_identifier ("float"),
660 layout_type (float_type_node
);
662 double_type_node
= make_node (REAL_TYPE
);
663 TYPE_PRECISION (double_type_node
) = 64;
664 pushdecl (build_decl (BUILTINS_LOCATION
,
665 TYPE_DECL
, get_identifier ("double"),
667 layout_type (double_type_node
);
669 float_zero_node
= build_real (float_type_node
, dconst0
);
670 double_zero_node
= build_real (double_type_node
, dconst0
);
672 /* These are the vtables for arrays of primitives. */
673 boolean_array_vtable
= create_primitive_vtable ("boolean");
674 byte_array_vtable
= create_primitive_vtable ("byte");
675 char_array_vtable
= create_primitive_vtable ("char");
676 short_array_vtable
= create_primitive_vtable ("short");
677 int_array_vtable
= create_primitive_vtable ("int");
678 long_array_vtable
= create_primitive_vtable ("long");
679 float_array_vtable
= create_primitive_vtable ("float");
680 double_array_vtable
= create_primitive_vtable ("double");
682 one_elt_array_domain_type
= build_index_type (integer_one_node
);
683 utf8const_type
= make_node (RECORD_TYPE
);
684 PUSH_FIELD (input_location
,
685 utf8const_type
, field
, "hash", unsigned_short_type_node
);
686 PUSH_FIELD (input_location
,
687 utf8const_type
, field
, "length", unsigned_short_type_node
);
688 FINISH_RECORD (utf8const_type
);
689 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
691 atable_type
= build_array_type (ptr_type_node
,
692 one_elt_array_domain_type
);
693 TYPE_NONALIASED_COMPONENT (atable_type
) = 1;
694 atable_ptr_type
= build_pointer_type (atable_type
);
696 itable_type
= build_array_type (ptr_type_node
,
697 one_elt_array_domain_type
);
698 TYPE_NONALIASED_COMPONENT (itable_type
) = 1;
699 itable_ptr_type
= build_pointer_type (itable_type
);
701 symbol_type
= make_node (RECORD_TYPE
);
702 PUSH_FIELD (input_location
,
703 symbol_type
, field
, "clname", utf8const_ptr_type
);
704 PUSH_FIELD (input_location
, symbol_type
, field
, "name", utf8const_ptr_type
);
705 PUSH_FIELD (input_location
,
706 symbol_type
, field
, "signature", utf8const_ptr_type
);
707 FINISH_RECORD (symbol_type
);
709 symbols_array_type
= build_array_type (symbol_type
,
710 one_elt_array_domain_type
);
711 symbols_array_ptr_type
= build_pointer_type (symbols_array_type
);
713 assertion_entry_type
= make_node (RECORD_TYPE
);
714 PUSH_FIELD (input_location
,
715 assertion_entry_type
, field
, "assertion_code", integer_type_node
);
716 PUSH_FIELD (input_location
,
717 assertion_entry_type
, field
, "op1", utf8const_ptr_type
);
718 PUSH_FIELD (input_location
,
719 assertion_entry_type
, field
, "op2", utf8const_ptr_type
);
720 FINISH_RECORD (assertion_entry_type
);
722 assertion_table_type
= build_array_type (assertion_entry_type
,
723 one_elt_array_domain_type
);
725 /* As you're adding items here, please update the code right after
726 this section, so that the filename containing the source code of
727 the pre-defined class gets registered correctly. */
728 unqualified_object_id_node
= get_identifier ("Object");
729 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
730 object_ptr_type_node
= promote_type (object_type_node
);
731 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
732 string_ptr_type_node
= promote_type (string_type_node
);
733 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
734 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
735 exception_type_node
= lookup_class (get_identifier ("java.lang.Exception"));
736 runtime_exception_type_node
=
737 lookup_class (get_identifier ("java.lang.RuntimeException"));
738 error_exception_type_node
=
739 lookup_class (get_identifier ("java.lang.Error"));
741 rawdata_ptr_type_node
742 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
744 add_predefined_file (get_identifier ("java/lang/Class.java"));
745 add_predefined_file (get_identifier ("java/lang/Error.java"));
746 add_predefined_file (get_identifier ("java/lang/Object.java"));
747 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
748 add_predefined_file (get_identifier ("java/lang/String.java"));
749 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
750 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
751 add_predefined_file (get_identifier ("java/lang/Exception.java"));
752 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
753 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
755 methodtable_type
= make_node (RECORD_TYPE
);
756 layout_type (methodtable_type
);
757 build_decl (BUILTINS_LOCATION
,
758 TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
759 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
761 TYPE_identifier_node
= get_identifier ("TYPE");
762 init_identifier_node
= get_identifier ("<init>");
763 clinit_identifier_node
= get_identifier ("<clinit>");
764 void_signature_node
= get_identifier ("()V");
765 finalize_identifier_node
= get_identifier ("finalize");
766 this_identifier_node
= get_identifier ("this");
768 java_lang_cloneable_identifier_node
= get_identifier ("java.lang.Cloneable");
769 java_io_serializable_identifier_node
=
770 get_identifier ("java.io.Serializable");
772 /* for lack of a better place to put this stub call */
773 init_expr_processing();
775 constants_type_node
= make_node (RECORD_TYPE
);
776 PUSH_FIELD (input_location
,
777 constants_type_node
, field
, "size", unsigned_int_type_node
);
778 PUSH_FIELD (input_location
,
779 constants_type_node
, field
, "tags", ptr_type_node
);
780 PUSH_FIELD (input_location
,
781 constants_type_node
, field
, "data", ptr_type_node
);
782 constants_data_field_decl_node
= field
;
783 FINISH_RECORD (constants_type_node
);
784 build_decl (BUILTINS_LOCATION
,
785 TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
787 access_flags_type_node
= unsigned_short_type_node
;
789 dtable_type
= make_node (RECORD_TYPE
);
790 dtable_ptr_type
= build_pointer_type (dtable_type
);
792 otable_type
= build_array_type (integer_type_node
,
793 one_elt_array_domain_type
);
794 TYPE_NONALIASED_COMPONENT (otable_type
) = 1;
795 otable_ptr_type
= build_pointer_type (otable_type
);
797 PUSH_FIELD (input_location
,
798 object_type_node
, field
, "vtable", dtable_ptr_type
);
799 DECL_FCONTEXT (field
) = object_type_node
;
800 TYPE_VFIELD (object_type_node
) = field
;
802 /* This isn't exactly true, but it is what we have in the source.
803 There is an unresolved issue here, which is whether the vtable
804 should be marked by the GC. */
805 if (! flag_hash_synchronization
)
806 PUSH_FIELD (input_location
, object_type_node
, field
, "sync_info",
807 build_pointer_type (object_type_node
));
808 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
809 FIELD_PRIVATE (t
) = 1;
810 FINISH_RECORD (object_type_node
);
812 field_type_node
= make_node (RECORD_TYPE
);
813 field_ptr_type_node
= build_pointer_type (field_type_node
);
814 method_type_node
= make_node (RECORD_TYPE
);
815 method_ptr_type_node
= build_pointer_type (method_type_node
);
817 set_super_info (0, class_type_node
, object_type_node
, 0);
818 set_super_info (0, string_type_node
, object_type_node
, 0);
819 class_ptr_type
= build_pointer_type (class_type_node
);
821 PUSH_FIELD (input_location
,
822 class_type_node
, field
, "next_or_version", class_ptr_type
);
823 PUSH_FIELD (input_location
,
824 class_type_node
, field
, "name", utf8const_ptr_type
);
825 PUSH_FIELD (input_location
,
826 class_type_node
, field
, "accflags", access_flags_type_node
);
827 PUSH_FIELD (input_location
,
828 class_type_node
, field
, "superclass", class_ptr_type
);
829 PUSH_FIELD (input_location
,
830 class_type_node
, field
, "constants", constants_type_node
);
831 constants_field_decl_node
= field
;
832 PUSH_FIELD (input_location
,
833 class_type_node
, field
, "methods", method_ptr_type_node
);
834 PUSH_FIELD (input_location
,
835 class_type_node
, field
, "method_count", short_type_node
);
836 PUSH_FIELD (input_location
,
837 class_type_node
, field
, "vtable_method_count", short_type_node
);
838 PUSH_FIELD (input_location
,
839 class_type_node
, field
, "fields", field_ptr_type_node
);
840 PUSH_FIELD (input_location
,
841 class_type_node
, field
, "size_in_bytes", int_type_node
);
842 PUSH_FIELD (input_location
,
843 class_type_node
, field
, "field_count", short_type_node
);
844 PUSH_FIELD (input_location
,
845 class_type_node
, field
, "static_field_count", short_type_node
);
846 PUSH_FIELD (input_location
,
847 class_type_node
, field
, "vtable", dtable_ptr_type
);
848 PUSH_FIELD (input_location
,
849 class_type_node
, field
, "otable", otable_ptr_type
);
850 PUSH_FIELD (input_location
,
851 class_type_node
, field
, "otable_syms",
852 symbols_array_ptr_type
);
853 PUSH_FIELD (input_location
,
854 class_type_node
, field
, "atable", atable_ptr_type
);
855 PUSH_FIELD (input_location
,
856 class_type_node
, field
, "atable_syms",
857 symbols_array_ptr_type
);
858 PUSH_FIELD (input_location
,
859 class_type_node
, field
, "itable", itable_ptr_type
);
860 PUSH_FIELD (input_location
, class_type_node
, field
, "itable_syms",
861 symbols_array_ptr_type
);
862 PUSH_FIELD (input_location
,
863 class_type_node
, field
, "catch_classes", ptr_type_node
);
864 PUSH_FIELD (input_location
, class_type_node
, field
, "interfaces",
865 build_pointer_type (class_ptr_type
));
866 PUSH_FIELD (input_location
, class_type_node
, field
, "loader", ptr_type_node
);
867 PUSH_FIELD (input_location
,
868 class_type_node
, field
, "interface_count", short_type_node
);
869 PUSH_FIELD (input_location
, class_type_node
, field
, "state", byte_type_node
);
870 PUSH_FIELD (input_location
, class_type_node
, field
, "thread", ptr_type_node
);
871 PUSH_FIELD (input_location
,
872 class_type_node
, field
, "depth", short_type_node
);
873 PUSH_FIELD (input_location
,
874 class_type_node
, field
, "ancestors", ptr_type_node
);
875 PUSH_FIELD (input_location
, class_type_node
, field
, "idt", ptr_type_node
);
876 PUSH_FIELD (input_location
,
877 class_type_node
, field
, "arrayclass", ptr_type_node
);
878 PUSH_FIELD (input_location
,
879 class_type_node
, field
, "protectionDomain", ptr_type_node
);
880 PUSH_FIELD (input_location
,
881 class_type_node
, field
, "assertion_table", ptr_type_node
);
882 PUSH_FIELD (input_location
,
883 class_type_node
, field
, "hack_signers", ptr_type_node
);
884 PUSH_FIELD (input_location
, class_type_node
, field
, "chain", ptr_type_node
);
885 PUSH_FIELD (input_location
,
886 class_type_node
, field
, "aux_info", ptr_type_node
);
887 PUSH_FIELD (input_location
, class_type_node
, field
, "engine", ptr_type_node
);
888 PUSH_FIELD (input_location
,
889 class_type_node
, field
, "reflection_data", ptr_type_node
);
890 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
891 FIELD_PRIVATE (t
) = 1;
892 push_super_field (class_type_node
, object_type_node
);
894 FINISH_RECORD (class_type_node
);
895 build_decl (BUILTINS_LOCATION
,
896 TYPE_DECL
, get_identifier ("Class"), class_type_node
);
898 field_info_union_node
= make_node (UNION_TYPE
);
899 PUSH_FIELD (input_location
,
900 field_info_union_node
, field
, "boffset", int_type_node
);
901 PUSH_FIELD (input_location
,
902 field_info_union_node
, field
, "addr", ptr_type_node
);
903 layout_type (field_info_union_node
);
905 PUSH_FIELD (input_location
,
906 field_type_node
, field
, "name", utf8const_ptr_type
);
907 PUSH_FIELD (input_location
, field_type_node
, field
, "type", class_ptr_type
);
908 PUSH_FIELD (input_location
,
909 field_type_node
, field
, "accflags", access_flags_type_node
);
910 PUSH_FIELD (input_location
,
911 field_type_node
, field
, "bsize", unsigned_short_type_node
);
912 PUSH_FIELD (input_location
,
913 field_type_node
, field
, "info", field_info_union_node
);
914 FINISH_RECORD (field_type_node
);
915 build_decl (BUILTINS_LOCATION
,
916 TYPE_DECL
, get_identifier ("Field"), field_type_node
);
918 nativecode_ptr_array_type_node
919 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
921 PUSH_FIELD (input_location
,
922 dtable_type
, field
, "class", class_ptr_type
);
923 PUSH_FIELD (input_location
,
924 dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
925 FINISH_RECORD (dtable_type
);
926 build_decl (BUILTINS_LOCATION
,
927 TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
929 jexception_type
= make_node (RECORD_TYPE
);
930 PUSH_FIELD (input_location
,
931 jexception_type
, field
, "start_pc", ptr_type_node
);
932 PUSH_FIELD (input_location
, jexception_type
, field
, "end_pc", ptr_type_node
);
933 PUSH_FIELD (input_location
,
934 jexception_type
, field
, "handler_pc", ptr_type_node
);
935 PUSH_FIELD (input_location
,
936 jexception_type
, field
, "catch_type", class_ptr_type
);
937 FINISH_RECORD (jexception_type
);
938 build_decl (BUILTINS_LOCATION
,
939 TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
940 jexception_ptr_type
= build_pointer_type (jexception_type
);
942 lineNumberEntry_type
= make_node (RECORD_TYPE
);
943 PUSH_FIELD (input_location
,
944 lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
945 PUSH_FIELD (input_location
,
946 lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
947 FINISH_RECORD (lineNumberEntry_type
);
949 lineNumbers_type
= make_node (RECORD_TYPE
);
950 PUSH_FIELD (input_location
,
951 lineNumbers_type
, field
, "length", unsigned_int_type_node
);
952 FINISH_RECORD (lineNumbers_type
);
954 PUSH_FIELD (input_location
,
955 method_type_node
, field
, "name", utf8const_ptr_type
);
956 PUSH_FIELD (input_location
,
957 method_type_node
, field
, "signature", utf8const_ptr_type
);
958 PUSH_FIELD (input_location
,
959 method_type_node
, field
, "accflags", access_flags_type_node
);
960 PUSH_FIELD (input_location
,
961 method_type_node
, field
, "index", unsigned_short_type_node
);
962 PUSH_FIELD (input_location
,
963 method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
964 PUSH_FIELD (input_location
,
965 method_type_node
, field
, "throws", ptr_type_node
);
966 FINISH_RECORD (method_type_node
);
967 build_decl (BUILTINS_LOCATION
,
968 TYPE_DECL
, get_identifier ("Method"), method_type_node
);
970 end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
972 t
= build_function_type_list (ptr_type_node
, class_ptr_type
, NULL_TREE
);
973 alloc_object_node
= add_builtin_function ("_Jv_AllocObject", t
,
974 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
975 DECL_IS_MALLOC (alloc_object_node
) = 1;
976 alloc_no_finalizer_node
=
977 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t
,
978 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
979 DECL_IS_MALLOC (alloc_no_finalizer_node
) = 1;
981 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
982 soft_initclass_node
= add_builtin_function ("_Jv_InitClass", t
,
983 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
984 t
= build_function_type_list (ptr_type_node
,
985 class_ptr_type
, int_type_node
, NULL_TREE
);
986 soft_resolvepoolentry_node
987 = add_builtin_function ("_Jv_ResolvePoolEntry", t
,
988 0,NOT_BUILT_IN
, NULL
, NULL_TREE
);
989 DECL_PURE_P (soft_resolvepoolentry_node
) = 1;
990 t
= build_function_type_list (void_type_node
,
991 class_ptr_type
, int_type_node
, NULL_TREE
);
992 throw_node
= add_builtin_function ("_Jv_Throw", t
,
993 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
994 /* Mark throw_nodes as `noreturn' functions with side effects. */
995 TREE_THIS_VOLATILE (throw_node
) = 1;
996 TREE_SIDE_EFFECTS (throw_node
) = 1;
998 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
999 soft_monitorenter_node
1000 = add_builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
1002 soft_monitorexit_node
1003 = add_builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
1006 t
= build_function_type_list (ptr_type_node
,
1007 ptr_type_node
, int_type_node
, NULL_TREE
);
1009 = add_builtin_function ("_Jv_NewPrimArray", t
,
1010 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1011 DECL_IS_MALLOC (soft_newarray_node
) = 1;
1013 t
= build_function_type_list (ptr_type_node
,
1014 int_type_node
, class_ptr_type
,
1015 object_ptr_type_node
, NULL_TREE
);
1017 = add_builtin_function ("_Jv_NewObjectArray", t
,
1018 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1019 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
1021 t
= build_varargs_function_type_list (ptr_type_node
,
1022 ptr_type_node
, int_type_node
,
1024 soft_multianewarray_node
1025 = add_builtin_function ("_Jv_NewMultiArray", t
,
1026 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1027 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
1029 t
= build_function_type_list (void_type_node
, int_type_node
, NULL_TREE
);
1030 soft_badarrayindex_node
1031 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t
,
1032 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1033 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1035 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
1036 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
1038 t
= build_function_type_list (void_type_node
, NULL_TREE
);
1039 soft_nullpointer_node
1040 = add_builtin_function ("_Jv_ThrowNullPointerException", t
,
1041 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1042 /* Mark soft_nullpointer_node as a `noreturn' function with side
1044 TREE_THIS_VOLATILE (soft_nullpointer_node
) = 1;
1045 TREE_SIDE_EFFECTS (soft_nullpointer_node
) = 1;
1047 soft_abstractmethod_node
1048 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t
,
1049 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1050 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1052 TREE_THIS_VOLATILE (soft_abstractmethod_node
) = 1;
1053 TREE_SIDE_EFFECTS (soft_abstractmethod_node
) = 1;
1055 soft_nosuchfield_node
1056 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t
,
1057 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1058 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1060 TREE_THIS_VOLATILE (soft_nosuchfield_node
) = 1;
1061 TREE_SIDE_EFFECTS (soft_nosuchfield_node
) = 1;
1063 t
= build_function_type_list (ptr_type_node
,
1064 class_ptr_type
, object_ptr_type_node
,
1067 = add_builtin_function ("_Jv_CheckCast", t
,
1068 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1069 t
= build_function_type_list (boolean_type_node
,
1070 object_ptr_type_node
, class_ptr_type
,
1072 soft_instanceof_node
1073 = add_builtin_function ("_Jv_IsInstanceOf", t
,
1074 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1075 DECL_PURE_P (soft_instanceof_node
) = 1;
1076 t
= build_function_type_list (void_type_node
,
1077 object_ptr_type_node
, object_ptr_type_node
,
1079 soft_checkarraystore_node
1080 = add_builtin_function ("_Jv_CheckArrayStore", t
,
1081 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1082 t
= build_function_type_list (ptr_type_node
,
1083 ptr_type_node
, ptr_type_node
, int_type_node
,
1085 soft_lookupinterfacemethod_node
1086 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t
,
1087 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1088 DECL_PURE_P (soft_lookupinterfacemethod_node
) = 1;
1090 t
= build_function_type_list (ptr_type_node
,
1091 ptr_type_node
, ptr_type_node
, ptr_type_node
,
1093 soft_lookupinterfacemethodbyname_node
1094 = add_builtin_function ("_Jv_LookupInterfaceMethod", t
,
1095 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1096 t
= build_function_type_list (ptr_type_node
,
1097 object_ptr_type_node
, ptr_type_node
,
1098 ptr_type_node
, int_type_node
, NULL_TREE
);
1099 soft_lookupjnimethod_node
1100 = add_builtin_function ("_Jv_LookupJNIMethod", t
,
1101 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1102 t
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
1103 soft_getjnienvnewframe_node
1104 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t
,
1105 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1106 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
1107 soft_jnipopsystemframe_node
1108 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t
,
1109 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1111 t
= build_function_type_list (object_ptr_type_node
,
1112 object_ptr_type_node
, NULL_TREE
);
1114 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t
,
1115 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1117 t
= build_function_type_list (int_type_node
,
1118 int_type_node
, int_type_node
, NULL_TREE
);
1120 = add_builtin_function ("_Jv_divI", t
,
1121 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1124 = add_builtin_function ("_Jv_remI", t
,
1125 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1127 t
= build_function_type_list (long_type_node
,
1128 long_type_node
, long_type_node
, NULL_TREE
);
1130 = add_builtin_function ("_Jv_divJ", t
,
1131 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1134 = add_builtin_function ("_Jv_remJ", t
,
1135 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1137 initialize_builtins ();
1139 soft_fmod_node
= builtin_decl_explicit (BUILT_IN_FMOD
);
1145 /* Look up NAME in the current binding level and its superiors
1146 in the namespace of variables, functions and typedefs.
1147 Return a ..._DECL node of some kind representing its definition,
1148 or return 0 if it is undefined. */
1151 lookup_name (tree name
)
1154 if (current_binding_level
!= global_binding_level
1155 && IDENTIFIER_LOCAL_VALUE (name
))
1156 val
= IDENTIFIER_LOCAL_VALUE (name
);
1158 val
= IDENTIFIER_GLOBAL_VALUE (name
);
1162 /* Similar to `lookup_name' but look only at current binding level and
1163 the previous one if it's the parameter level. */
1166 lookup_name_current_level (tree name
)
1170 if (current_binding_level
== global_binding_level
)
1171 return IDENTIFIER_GLOBAL_VALUE (name
);
1173 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
1176 for (t
= current_binding_level
->names
; t
; t
= DECL_CHAIN (t
))
1177 if (DECL_NAME (t
) == name
)
1183 /* Record a decl-node X as belonging to the current lexical scope.
1184 Check for errors (such as an incompatible declaration for the same
1185 name already seen in the same scope).
1187 Returns either X or an old decl for the same name.
1188 If an old decl is returned, it may have been smashed
1189 to agree with what X says. */
1195 tree name
= DECL_NAME (x
);
1196 struct binding_level
*b
= current_binding_level
;
1198 if (TREE_CODE (x
) != TYPE_DECL
)
1199 DECL_CONTEXT (x
) = current_function_decl
;
1202 t
= lookup_name_current_level (name
);
1203 if (t
!= 0 && t
== error_mark_node
)
1204 /* error_mark_node is 0 for a while during initialization! */
1207 error ("%q+D used prior to declaration", x
);
1210 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1211 to point to the TYPE_DECL.
1212 Since Java does not have typedefs, a type can only have
1213 one (true) name, given by a class, interface, or builtin. */
1214 if (TREE_CODE (x
) == TYPE_DECL
1215 && TYPE_NAME (TREE_TYPE (x
)) == 0
1216 && TREE_TYPE (x
) != error_mark_node
)
1218 TYPE_NAME (TREE_TYPE (x
)) = x
;
1219 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1222 /* This name is new in its binding level.
1223 Install the new declaration and return it. */
1224 if (b
== global_binding_level
)
1226 /* Install a global value. */
1228 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1232 /* Here to install a non-global value. */
1233 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1234 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1236 /* If storing a local value, there may already be one (inherited).
1237 If so, record it for restoration when this binding level ends. */
1239 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1243 /* Put decls on list in reverse order.
1244 We will reverse them later if necessary. */
1245 DECL_CHAIN (x
) = b
->names
;
1252 pushdecl_force_head (tree x
)
1254 current_binding_level
->names
= x
;
1257 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1260 pushdecl_top_level (tree x
)
1263 struct binding_level
*b
= current_binding_level
;
1265 current_binding_level
= global_binding_level
;
1267 current_binding_level
= b
;
1271 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1274 pushdecl_function_level (tree x
)
1277 struct binding_level
*b
= current_binding_level
;
1279 current_binding_level
= function_binding_level
;
1281 current_binding_level
= b
;
1285 /* Return true if we are in the global binding level. */
1288 global_bindings_p (void)
1290 return current_binding_level
== global_binding_level
;
1293 /* Return the list of declarations of the current level.
1294 Note that this list is in reverse order unless/until
1295 you nreverse it; and when you do nreverse it, you must
1296 store the result back using `storedecls' or you will lose. */
1301 return current_binding_level
->names
;
1304 /* Create a new `struct binding_level'. */
1306 static struct binding_level
*
1307 make_binding_level (void)
1310 return ggc_alloc_cleared_binding_level ();
1314 pushlevel (int unused ATTRIBUTE_UNUSED
)
1316 struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1318 /* Reuse or create a struct for this binding level. */
1320 if (free_binding_level
)
1322 newlevel
= free_binding_level
;
1323 free_binding_level
= free_binding_level
->level_chain
;
1327 newlevel
= make_binding_level ();
1330 /* Add this level to the front of the chain (stack) of levels that
1333 *newlevel
= clear_binding_level
;
1334 newlevel
->level_chain
= current_binding_level
;
1335 newlevel
->loc
= input_location
;
1336 current_binding_level
= newlevel
;
1337 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1338 newlevel
->binding_depth
= binding_depth
;
1340 fprintf (stderr
, "push %s level %p pc %d\n",
1341 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1344 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1347 /* Exit a binding level.
1348 Pop the level off, and restore the state of the identifier-decl mappings
1349 that were in effect when this level was entered.
1351 If KEEP is nonzero, this level had explicit declarations, so
1352 and create a "block" (a BLOCK node) for the level
1353 to record its declarations and subblocks for symbol table output.
1355 If FUNCTIONBODY is nonzero, this level is the body of a function,
1356 so create a block as if KEEP were set and also clear out all
1359 If REVERSE is nonzero, reverse the order of decls before putting
1360 them into the BLOCK. */
1363 poplevel (int keep
, int reverse
, int functionbody
)
1366 /* The chain of decls was accumulated in reverse order.
1367 Put it into forward order, just for cleanliness. */
1369 tree subblocks
= current_binding_level
->blocks
;
1374 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1377 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1378 fprintf (stderr
, "pop %s level %p pc %d (end pc %d)\n",
1379 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1380 current_binding_level
->end_pc
);
1382 fprintf (stderr
, "pop %s level %p pc %d\n",
1383 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1384 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1386 /* Get the decls in the order they were written.
1387 Usually current_binding_level->names is in reverse order.
1388 But parameter decls were previously put in forward order. */
1391 current_binding_level
->names
1392 = decls
= nreverse (current_binding_level
->names
);
1394 decls
= current_binding_level
->names
;
1396 for (decl
= decls
; decl
; decl
= DECL_CHAIN (decl
))
1397 if (TREE_CODE (decl
) == VAR_DECL
1398 && DECL_LANG_SPECIFIC (decl
) != NULL
1399 && DECL_LOCAL_SLOT_NUMBER (decl
))
1400 LOCAL_VAR_OUT_OF_SCOPE_P (decl
) = 1;
1402 /* If there were any declarations in that level,
1403 or if this level is a function body,
1404 create a BLOCK to record them for the life of this function. */
1407 if (keep
|| functionbody
)
1408 block
= make_node (BLOCK
);
1410 if (current_binding_level
->exception_range
)
1411 expand_end_java_handler (current_binding_level
->exception_range
);
1415 /* If any statements have been generated at this level, create a
1416 BIND_EXPR to hold them and copy the variables to it. This
1417 only applies to the bytecode compiler. */
1418 if (current_binding_level
->stmts
)
1421 tree
*var
= &BLOCK_VARS (block
);
1423 /* Copy decls from names list, ignoring labels. */
1426 tree next
= DECL_CHAIN (decl
);
1427 if (TREE_CODE (decl
) != LABEL_DECL
)
1430 var
= &DECL_CHAIN (decl
);
1436 bind
= build3 (BIND_EXPR
, void_type_node
, BLOCK_VARS (block
),
1437 BLOCK_EXPR_BODY (block
), block
);
1438 BIND_EXPR_BODY (bind
) = current_binding_level
->stmts
;
1440 if (BIND_EXPR_BODY (bind
)
1441 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind
)))
1442 TREE_SIDE_EFFECTS (bind
) = 1;
1444 /* FIXME: gimplifier brain damage. */
1445 if (BIND_EXPR_BODY (bind
) == NULL
)
1446 BIND_EXPR_BODY (bind
) = build_java_empty_stmt ();
1448 SET_EXPR_LOCATION (bind
, current_binding_level
->loc
);
1450 current_binding_level
->stmts
= NULL
;
1454 BLOCK_VARS (block
) = decls
;
1456 BLOCK_SUBBLOCKS (block
) = subblocks
;
1459 /* In each subblock, record that this is its superior. */
1461 for (link
= subblocks
; link
; link
= BLOCK_CHAIN (link
))
1462 BLOCK_SUPERCONTEXT (link
) = block
;
1464 /* Clear out the meanings of the local variables of this level. */
1466 for (link
= decls
; link
; link
= DECL_CHAIN (link
))
1468 tree name
= DECL_NAME (link
);
1469 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1471 /* If the ident. was used or addressed via a local extern decl,
1472 don't forget that fact. */
1473 if (DECL_EXTERNAL (link
))
1475 if (TREE_USED (link
))
1476 TREE_USED (name
) = 1;
1477 if (TREE_ADDRESSABLE (link
))
1478 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1480 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1484 /* Restore all name-meanings of the outer levels
1485 that were shadowed by this level. */
1487 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1488 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1490 /* If the level being exited is the top level of a function,
1491 check over all the labels, and clear out the current
1492 (function local) meanings of their names. */
1496 /* If this is the top level block of a function,
1497 the vars are the function's parameters.
1498 Don't leave them in the BLOCK because they are
1499 found in the FUNCTION_DECL instead. */
1501 BLOCK_VARS (block
) = 0;
1504 /* Pop the current level, and free the structure for reuse. */
1507 struct binding_level
*level
= current_binding_level
;
1508 current_binding_level
= current_binding_level
->level_chain
;
1510 level
->level_chain
= free_binding_level
;
1511 free_binding_level
= level
;
1514 /* Dispose of the block that we just made inside some higher level. */
1517 DECL_INITIAL (current_function_decl
) = block
;
1518 DECL_SAVED_TREE (current_function_decl
) = bind
;
1524 current_binding_level
->blocks
1525 = block_chainon (current_binding_level
->blocks
, block
);
1527 /* If we did not make a block for the level just exited,
1528 any blocks made for inner levels
1529 (since they cannot be recorded as subblocks in that level)
1530 must be carried forward so they will later become subblocks
1531 of something else. */
1533 current_binding_level
->blocks
1534 = block_chainon (current_binding_level
->blocks
, subblocks
);
1537 java_add_stmt (bind
);
1541 TREE_USED (block
) = 1;
1546 maybe_pushlevels (int pc
)
1548 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1552 while (pending_local_decls
!= NULL_TREE
&&
1553 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1555 tree
*ptr
= &pending_local_decls
;
1556 tree decl
= *ptr
, next
;
1557 int end_pc
= DECL_LOCAL_END_PC (decl
);
1559 while (*ptr
!= NULL_TREE
1560 && DECL_LOCAL_START_PC (*ptr
) <= pc
1561 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1562 ptr
= &DECL_CHAIN (*ptr
);
1563 pending_local_decls
= *ptr
;
1566 /* Force non-nested range to be nested in current range by
1567 truncating variable lifetimes. */
1568 if (end_pc
> current_binding_level
->end_pc
)
1571 end_pc
= current_binding_level
->end_pc
;
1572 for (t
= decl
; t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
1573 DECL_LOCAL_END_PC (t
) = end_pc
;
1576 maybe_start_try (pc
, end_pc
);
1580 current_binding_level
->end_pc
= end_pc
;
1581 current_binding_level
->start_pc
= pc
;
1582 current_binding_level
->names
= NULL
;
1583 for ( ; decl
!= NULL_TREE
; decl
= next
)
1585 int index
= DECL_LOCAL_SLOT_NUMBER (decl
);
1587 next
= DECL_CHAIN (decl
);
1588 push_jvm_slot (index
, decl
);
1591 = find_local_variable (index
, TREE_TYPE (decl
), pc
);
1592 if (TREE_CODE (TREE_TYPE (base_decl
)) == POINTER_TYPE
)
1593 base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
1594 SET_DECL_VALUE_EXPR (decl
, base_decl
);
1595 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1599 maybe_start_try (pc
, 0);
1603 maybe_poplevels (int pc
)
1605 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1609 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1610 inclusive, so a variable is live if pc == end_pc. Here, we
1611 terminate a range if the current pc is equal to the end of the
1612 range, and this is *before* we have generated code for the
1613 instruction at end_pc. We're closing a binding level one
1614 instruction too early.*/
1615 while (current_binding_level
->end_pc
<= pc
)
1619 /* Terminate any binding which began during the range beginning at
1620 start_pc. This tidies up improperly nested local variable ranges
1621 and exception handlers; a variable declared within an exception
1622 range is forcibly terminated when that exception ends. */
1625 force_poplevels (int start_pc
)
1627 while (current_binding_level
->start_pc
> start_pc
)
1629 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1630 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1631 current_function_decl
,
1632 current_binding_level
->start_pc
);
1637 /* integrate_decl_tree calls this function. */
1640 java_dup_lang_specific_decl (tree node
)
1643 struct lang_decl
*x
;
1645 if (!DECL_LANG_SPECIFIC (node
))
1648 lang_decl_size
= sizeof (struct lang_decl
);
1649 x
= ggc_alloc_lang_decl (lang_decl_size
);
1650 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1651 DECL_LANG_SPECIFIC (node
) = x
;
1655 give_name_to_locals (JCF
*jcf
)
1657 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1658 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1660 pending_local_decls
= NULL_TREE
;
1664 n
= JCF_readu2 (jcf
);
1665 for (i
= 0; i
< n
; i
++)
1667 int start_pc
= JCF_readu2 (jcf
);
1668 int length
= JCF_readu2 (jcf
);
1669 int name_index
= JCF_readu2 (jcf
);
1670 int signature_index
= JCF_readu2 (jcf
);
1671 int slot
= JCF_readu2 (jcf
);
1672 tree name
= get_name_constant (jcf
, name_index
);
1673 tree type
= parse_signature (jcf
, signature_index
);
1674 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1676 && length
== DECL_CODE_LENGTH (current_function_decl
))
1678 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1679 DECL_NAME (decl
) = name
;
1680 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1681 warning (0, "bad type in parameter debug info");
1686 int end_pc
= start_pc
+ length
;
1687 tree decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
1688 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1690 warning (0, "bad PC range for debug info for local %q+D",
1692 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1695 /* Adjust start_pc if necessary so that the local's first
1696 store operation will use the relevant DECL as a
1697 destination. Fore more information, read the leading
1698 comments for expr.c:maybe_adjust_start_pc. */
1699 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1701 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1702 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1703 DECL_LOCAL_START_PC (decl
) = start_pc
;
1704 DECL_LOCAL_END_PC (decl
) = end_pc
;
1706 /* Now insert the new decl in the proper place in
1707 pending_local_decls. We are essentially doing an insertion sort,
1708 which works fine, since the list input will normally already
1710 ptr
= &pending_local_decls
;
1711 while (*ptr
!= NULL_TREE
1712 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1713 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1714 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1715 ptr
= &DECL_CHAIN (*ptr
);
1716 DECL_CHAIN (decl
) = *ptr
;
1721 pending_local_decls
= nreverse (pending_local_decls
);
1723 /* Fill in default names for the parameters. */
1724 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1725 parm
!= NULL_TREE
; parm
= DECL_CHAIN (parm
), i
++)
1727 if (DECL_NAME (parm
) == NULL_TREE
)
1729 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1731 DECL_NAME (parm
) = get_identifier ("this");
1735 sprintf (buffer
, "ARG_%d", arg_i
);
1736 DECL_NAME (parm
) = get_identifier (buffer
);
1743 build_result_decl (tree fndecl
)
1745 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1746 tree result
= DECL_RESULT (fndecl
);
1749 result
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
1750 RESULT_DECL
, NULL_TREE
, restype
);
1751 DECL_ARTIFICIAL (result
) = 1;
1752 DECL_IGNORED_P (result
) = 1;
1753 DECL_CONTEXT (result
) = fndecl
;
1754 DECL_RESULT (fndecl
) = result
;
1760 start_java_method (tree fndecl
)
1767 current_function_decl
= fndecl
;
1768 announce_function (fndecl
);
1770 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1771 decl_map
= make_tree_vec (i
);
1772 base_decl_map
= make_tree_vec (i
);
1773 type_map
= XRESIZEVEC (tree
, type_map
, i
);
1775 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1776 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1778 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1779 pushlevel (1); /* Push parameters. */
1781 ptr
= &DECL_ARGUMENTS (fndecl
);
1782 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1783 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1785 tree parm_name
= NULL_TREE
, parm_decl
;
1786 tree parm_type
= TREE_VALUE (tem
);
1787 gcc_assert (i
< DECL_MAX_LOCALS (fndecl
));
1789 parm_decl
= build_decl (input_location
, PARM_DECL
, parm_name
, parm_type
);
1790 DECL_CONTEXT (parm_decl
) = fndecl
;
1791 if (targetm
.calls
.promote_prototypes (parm_type
)
1792 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1793 && INTEGRAL_TYPE_P (parm_type
))
1794 parm_type
= integer_type_node
;
1795 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1798 ptr
= &DECL_CHAIN (parm_decl
);
1800 /* Add parm_decl to the decl_map. */
1801 push_jvm_slot (i
, parm_decl
);
1803 /* The this parameter of methods is artificial. */
1804 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
&& i
== 0)
1805 DECL_ARTIFICIAL (parm_decl
) = 1;
1807 type_map
[i
] = TREE_TYPE (parm_decl
);
1808 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1811 type_map
[i
] = void_type_node
;
1815 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1817 while (i
< DECL_MAX_LOCALS(fndecl
))
1818 type_map
[i
++] = NULL_TREE
;
1820 build_result_decl (fndecl
);
1821 DECL_SOURCE_LOCATION (fndecl
) = input_location
;
1823 /* Push local variables. */
1826 function_binding_level
= current_binding_level
;
1830 end_java_method (void)
1832 tree fndecl
= current_function_decl
;
1834 /* pop out of function */
1837 /* pop out of its parameters */
1840 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1842 if (DECL_SAVED_TREE (fndecl
))
1844 tree fbody
, block_body
;
1845 /* Before we check initialization, attached all class initialization
1846 variable to the block_body */
1847 fbody
= DECL_SAVED_TREE (fndecl
);
1848 block_body
= BIND_EXPR_BODY (fbody
);
1849 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl
),
1850 attach_init_test_initialization_flags
, block_body
);
1853 finish_method (fndecl
);
1855 current_function_decl
= NULL_TREE
;
1856 base_decl_map
= NULL_TREE
;
1859 /* Prepare a method for expansion. */
1862 finish_method (tree fndecl
)
1864 tree
*tp
= &DECL_SAVED_TREE (fndecl
);
1866 /* Wrap body of synchronized methods in a monitorenter,
1867 plus monitorexit cleanup. */
1868 if (METHOD_SYNCHRONIZED (fndecl
))
1870 tree enter
, exit
, lock
;
1871 if (METHOD_STATIC (fndecl
))
1872 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1874 lock
= DECL_ARGUMENTS (fndecl
);
1875 BUILD_MONITOR_ENTER (enter
, lock
);
1876 BUILD_MONITOR_EXIT (exit
, lock
);
1877 *tp
= build2 (COMPOUND_EXPR
, void_type_node
, enter
,
1878 build2 (TRY_FINALLY_EXPR
, void_type_node
, *tp
, exit
));
1881 /* Convert function tree to GENERIC prior to inlining. */
1882 java_genericize (fndecl
);
1884 /* Store the end of the function, so that we get good line number
1885 info for the epilogue. */
1886 if (DECL_STRUCT_FUNCTION (fndecl
))
1887 set_cfun (DECL_STRUCT_FUNCTION (fndecl
));
1889 allocate_struct_function (fndecl
, false);
1890 cfun
->function_end_locus
= DECL_FUNCTION_LAST_LINE (fndecl
);
1892 /* Defer inlining and expansion to the cgraph optimizers. */
1893 cgraph_finalize_function (fndecl
, false);
1896 /* We pessimistically marked all methods and fields external until we
1897 knew what set of classes we were planning to compile. Now mark those
1898 associated with CLASS to be generated locally as not external. */
1901 java_mark_decl_local (tree decl
)
1903 DECL_EXTERNAL (decl
) = 0;
1905 #ifdef ENABLE_CHECKING
1906 /* Double check that we didn't pass the function to the callgraph early. */
1907 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1909 struct cgraph_node
*node
= cgraph_get_node (decl
);
1910 gcc_assert (!node
|| !node
->definition
);
1913 gcc_assert (!DECL_RTL_SET_P (decl
));
1916 /* Given appropriate target support, G++ will emit hidden aliases for native
1917 methods. Using this hidden name is required for proper operation of
1918 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1919 proper target support, then mark the method for aliasing. */
1922 java_mark_cni_decl_local (tree decl
)
1924 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1928 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
1929 DECL_LOCAL_CNI_METHOD_P (decl
) = 1;
1931 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1932 mangler. We might have already referenced this native method and
1933 therefore created its name, but even if we have it won't hurt.
1934 We'll just go via its externally visible name, rather than its
1935 hidden alias. However, we must force things so that the correct
1936 mangling is done. */
1938 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
1939 java_mangle_decl (decl
);
1940 if (DECL_RTL_SET_P (decl
))
1942 SET_DECL_RTL (decl
, 0);
1943 make_decl_rtl (decl
);
1947 /* Use the preceding two functions and mark all members of the class. */
1950 java_mark_class_local (tree klass
)
1954 for (t
= TYPE_FIELDS (klass
); t
; t
= DECL_CHAIN (t
))
1955 if (FIELD_STATIC (t
))
1957 if (DECL_EXTERNAL (t
))
1958 vec_safe_push (pending_static_fields
, t
);
1959 java_mark_decl_local (t
);
1962 for (t
= TYPE_METHODS (klass
); t
; t
= DECL_CHAIN (t
))
1963 if (!METHOD_ABSTRACT (t
))
1965 if (METHOD_NATIVE (t
) && !flag_jni
)
1966 java_mark_cni_decl_local (t
);
1968 java_mark_decl_local (t
);
1972 /* Add a statement to a compound_expr. */
1975 add_stmt_to_compound (tree existing
, tree type
, tree stmt
)
1981 tree expr
= build2 (COMPOUND_EXPR
, type
, existing
, stmt
);
1982 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (existing
)
1983 | TREE_SIDE_EFFECTS (stmt
);
1990 /* If this node is an expr, mark its input location. Called from
1994 set_input_location (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
1995 void *data ATTRIBUTE_UNUSED
)
1999 if (CAN_HAVE_LOCATION_P (t
))
2001 if (EXPR_HAS_LOCATION(t
))
2002 return t
; /* Don't walk any further into this expr. */
2004 SET_EXPR_LOCATION (t
, input_location
);
2007 return NULL_TREE
; /* Continue walking this expr. */
2010 /* Add a statement to the statement_list currently being constructed.
2011 If the statement_list is null, we don't create a singleton list.
2012 This is necessary because poplevel() assumes that adding a
2013 statement to a null statement_list returns the statement. */
2016 java_add_stmt (tree new_stmt
)
2018 tree stmts
= current_binding_level
->stmts
;
2019 tree_stmt_iterator i
;
2022 walk_tree (&new_stmt
, set_input_location
, NULL
, NULL
);
2025 return current_binding_level
->stmts
= new_stmt
;
2027 /* Force STMTS to be a statement_list. */
2028 if (TREE_CODE (stmts
) != STATEMENT_LIST
)
2030 tree t
= make_node (STATEMENT_LIST
);
2032 tsi_link_after (&i
, stmts
, TSI_CONTINUE_LINKING
);
2036 i
= tsi_last (stmts
);
2037 tsi_link_after (&i
, new_stmt
, TSI_CONTINUE_LINKING
);
2038 TREE_TYPE (stmts
) = void_type_node
;
2040 return current_binding_level
->stmts
= stmts
;
2043 /* Add a variable to the current scope. */
2046 java_add_local_var (tree decl
)
2048 tree
*vars
= ¤t_binding_level
->names
;
2050 DECL_CHAIN (decl
) = next
;
2052 DECL_CONTEXT (decl
) = current_function_decl
;
2053 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
2057 /* Return a pointer to the compound_expr currently being
2063 return ¤t_binding_level
->stmts
;
2066 /* Register an exception range as belonging to the current binding
2067 level. There may only be one: if there are more, we'll create more
2068 binding levels. However, each range can have multiple handlers,
2069 and these are expanded when we call expand_end_java_handler(). */
2072 register_exception_range (struct eh_range
*range
, int pc
, int end_pc
)
2074 gcc_assert (! current_binding_level
->exception_range
);
2075 current_binding_level
->exception_range
= range
;
2076 current_binding_level
->end_pc
= end_pc
;
2077 current_binding_level
->start_pc
= pc
;
2080 #include "gt-java-decl.h"