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 "diagnostic-core.h"
34 #include "java-tree.h"
36 #include "java-except.h"
39 #include "tree-inline.h"
42 #include "tree-iterator.h"
43 #include "langhooks.h"
46 #if defined (DEBUG_JAVA_BINDING_LEVELS)
47 extern void indent (void);
50 static tree
push_jvm_slot (int, tree
);
51 static tree
lookup_name_current_level (tree
);
52 static tree
push_promoted_type (const char *, tree
);
53 static struct binding_level
*make_binding_level (void);
54 static tree
create_primitive_vtable (const char *);
55 static tree
check_local_unnamed_variable (tree
, tree
, tree
);
56 static void parse_version (void);
59 /* The following ABI flags are used in the high-order bits of the version
60 ID field. The version ID number itself should never be larger than
61 0xfffff, so it should be safe to use top 12 bits for these flags. */
63 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
65 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
66 should be loaded by the bootstrap
69 /* If an ABI change is made within a GCC release series, rendering current
70 binaries incompatible with the old runtimes, this number must be set to
71 enforce the compatibility rules. */
72 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
74 /* The runtime may recognize a variety of BC ABIs (objects generated by
75 different version of gcj), but will probably always require strict
76 matching for the ordinary (C++) ABI. */
78 /* The version ID of the BC ABI that we generate. This must be kept in
79 sync with parse_version(), libgcj, and reality (if the BC format changes,
81 #define GCJ_CURRENT_BC_ABI_VERSION \
82 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
84 /* The ABI version number. */
87 /* Name of the Cloneable class. */
88 tree java_lang_cloneable_identifier_node
;
90 /* Name of the Serializable class. */
91 tree java_io_serializable_identifier_node
;
93 /* The DECL_MAP is a mapping from (index, type) to a decl node.
94 If index < max_locals, it is the index of a local variable.
95 if index >= max_locals, then index-max_locals is a stack slot.
96 The DECL_MAP mapping is represented as a TREE_VEC whose elements
97 are a list of decls (VAR_DECL or PARM_DECL) chained by
98 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
99 we search the chain for a decl with a matching TREE_TYPE. */
101 static GTY(()) tree decl_map
;
103 /* The base_decl_map is contains one variable of ptr_type: this is
104 used to contain every variable of reference type that is ever
105 stored in a local variable slot. */
107 static GTY(()) tree base_decl_map
;
109 /* An index used to make temporary identifiers unique. */
112 /* A list of local variables VAR_DECLs for this method that we have seen
113 debug information, but we have not reached their starting (byte) PC yet. */
115 static GTY(()) tree pending_local_decls
;
117 /* The decl for "_Jv_ResolvePoolEntry". */
118 tree soft_resolvepoolentry_node
;
120 /* The decl for the .constants field of an instance of Class. */
121 tree constants_field_decl_node
;
123 /* The decl for the .data field of an instance of Class. */
124 tree constants_data_field_decl_node
;
126 #if defined(DEBUG_JAVA_BINDING_LEVELS)
127 int binding_depth
= 0;
128 int is_class_level
= 0;
136 for (i
= 0; i
< binding_depth
*2; i
++)
139 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
141 /* True if decl is a named local variable, i.e. if it is an alias
142 that's used only for debugging purposes. */
145 debug_variable_p (tree decl
)
147 if (TREE_CODE (decl
) == PARM_DECL
)
150 if (LOCAL_SLOT_P (decl
))
157 push_jvm_slot (int index
, tree decl
)
159 DECL_CONTEXT (decl
) = current_function_decl
;
160 layout_decl (decl
, 0);
162 /* Now link the decl into the decl_map. */
163 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
165 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
166 DECL_LOCAL_START_PC (decl
) = 0;
167 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
168 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
170 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
171 TREE_VEC_ELT (decl_map
, index
) = decl
;
176 /* Find the best declaration based upon type. If 'decl' fits 'type' better
177 than 'best', return 'decl'. Otherwise return 'best'. */
180 check_local_unnamed_variable (tree best
, tree decl
, tree type
)
182 tree decl_type
= TREE_TYPE (decl
);
184 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl
));
186 /* Use the same decl for all integer types <= 32 bits. This is
187 necessary because sometimes a value is stored as (for example)
188 boolean but loaded as int. */
189 if (decl_type
== type
190 || (INTEGRAL_TYPE_P (decl_type
)
191 && INTEGRAL_TYPE_P (type
)
192 && TYPE_PRECISION (decl_type
) <= 32
193 && TYPE_PRECISION (type
) <= 32
194 && TYPE_PRECISION (decl_type
) >= TYPE_PRECISION (type
))
195 /* ptr_type_node is used for null pointers, which are
196 assignment compatible with everything. */
197 || (TREE_CODE (decl_type
) == POINTER_TYPE
198 && type
== ptr_type_node
)
199 /* Whenever anyone wants to use a slot that is initially
200 occupied by a PARM_DECL of pointer type they must get that
201 decl, even if they asked for a pointer to a different type.
202 However, if someone wants a scalar variable in a slot that
203 initially held a pointer arg -- or vice versa -- we create a
206 ???: As long as verification is correct, this will be a
207 compatible type. But maybe we should create a dummy variable
208 and replace all references to it with the DECL and a
211 || (TREE_CODE (decl_type
) == POINTER_TYPE
212 && TREE_CODE (decl
) == PARM_DECL
213 && TREE_CODE (type
) == POINTER_TYPE
))
215 if (best
== NULL_TREE
216 || (decl_type
== type
&& TREE_TYPE (best
) != type
))
224 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
225 that is valid at PC (or -1 if any pc).
226 If there is no existing matching decl, allocate one. */
229 find_local_variable (int index
, tree type
, int pc ATTRIBUTE_UNUSED
)
231 tree tmp
= TREE_VEC_ELT (decl_map
, index
);
232 tree decl
= NULL_TREE
;
234 /* Scan through every declaration that has been created in this
235 slot. We're only looking for variables that correspond to local
236 index declarations and PARM_DECLs, not named variables: such
237 local variables are used only for debugging information. */
238 while (tmp
!= NULL_TREE
)
240 if (! debug_variable_p (tmp
))
241 decl
= check_local_unnamed_variable (decl
, tmp
, type
);
242 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
245 /* gcj has a function called promote_type(), which is used by both
246 the bytecode compiler and the source compiler. Unfortunately,
247 the type systems for the Java VM and the Java language are not
248 the same: a boolean in the VM promotes to an int, not to a wide
249 boolean. If our caller wants something to hold a boolean, that
250 had better be an int, because that slot might be re-used
251 later in integer context. */
252 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
253 type
= integer_type_node
;
255 /* If we don't find a match, create one with the type passed in.
256 The name of the variable is #n#m, which n is the variable index
257 in the local variable area and m is a dummy identifier for
258 uniqueness -- multiple variables may share the same local
259 variable index. We don't call pushdecl() to push pointer types
260 into a binding expr because they'll all be replaced by a single
261 variable that is used for every reference in that local variable
267 sprintf (buf
, "#slot#%d#%d", index
, uniq
++);
268 name
= get_identifier (buf
);
269 decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
270 DECL_IGNORED_P (decl
) = 1;
271 DECL_ARTIFICIAL (decl
) = 1;
272 decl
= push_jvm_slot (index
, decl
);
273 LOCAL_SLOT_P (decl
) = 1;
275 if (TREE_CODE (type
) != POINTER_TYPE
)
276 pushdecl_function_level (decl
);
279 /* As well as creating a local variable that matches the type, we
280 also create a base variable (of ptr_type) that will hold all its
282 if (TREE_CODE (type
) == POINTER_TYPE
283 && ! TREE_VEC_ELT (base_decl_map
, index
))
288 sprintf (buf
, "#ref#%d#%d", index
, uniq
++);
289 name
= get_identifier (buf
);
291 = TREE_VEC_ELT (base_decl_map
, index
)
292 = build_decl (input_location
, VAR_DECL
, name
, ptr_type_node
);
293 pushdecl_function_level (base_decl
);
294 DECL_IGNORED_P (base_decl
) = 1;
295 DECL_ARTIFICIAL (base_decl
) = 1;
301 /* Called during genericization for every variable. If the variable
302 is a temporary of pointer type, replace it with a common variable
303 thath is used to hold all pointer types that are ever stored in
304 that slot. Set WANT_LVALUE if you want a variable that is to be
308 java_replace_reference (tree var_decl
, bool want_lvalue
)
315 decl_type
= TREE_TYPE (var_decl
);
317 if (TREE_CODE (decl_type
) == POINTER_TYPE
)
319 if (DECL_LANG_SPECIFIC (var_decl
)
320 && LOCAL_SLOT_P (var_decl
))
322 int index
= DECL_LOCAL_SLOT_NUMBER (var_decl
);
323 tree base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
325 gcc_assert (base_decl
);
327 base_decl
= build1 (NOP_EXPR
, decl_type
, base_decl
);
336 /* Helper for java_genericize. */
339 java_replace_references (tree
*tp
, int *walk_subtrees
,
340 void *data ATTRIBUTE_UNUSED
)
342 if (TREE_CODE (*tp
) == MODIFY_EXPR
)
344 source_location loc
= EXPR_LOCATION (*tp
);
345 tree lhs
= TREE_OPERAND (*tp
, 0);
346 /* This is specific to the bytecode compiler. If a variable has
347 LOCAL_SLOT_P set, replace an assignment to it with an assignment
348 to the corresponding variable that holds all its aliases. */
349 if (TREE_CODE (lhs
) == VAR_DECL
350 && DECL_LANG_SPECIFIC (lhs
)
351 && LOCAL_SLOT_P (lhs
)
352 && TREE_CODE (TREE_TYPE (lhs
)) == POINTER_TYPE
)
354 tree new_lhs
= java_replace_reference (lhs
, /* want_lvalue */ true);
355 tree new_rhs
= build1 (NOP_EXPR
, TREE_TYPE (new_lhs
),
356 TREE_OPERAND (*tp
, 1));
357 tree tem
= build2 (MODIFY_EXPR
, TREE_TYPE (new_lhs
),
359 *tp
= build1 (NOP_EXPR
, TREE_TYPE (lhs
), tem
);
360 SET_EXPR_LOCATION (tem
, loc
);
361 SET_EXPR_LOCATION (new_rhs
, loc
);
362 SET_EXPR_LOCATION (*tp
, loc
);
365 if (TREE_CODE (*tp
) == VAR_DECL
)
367 *tp
= java_replace_reference (*tp
, /* want_lvalue */ false);
374 /* Same as find_local_index, except that INDEX is a stack index. */
377 find_stack_slot (int index
, tree type
)
379 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
385 /* A chain of _DECL nodes for all variables, constants, functions,
386 * and typedef types. These are in the reverse of the order supplied.
390 /* For each level, a list of shadowed outer-level local definitions
391 to be restored when this level is popped.
392 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
393 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
396 /* For each level (except not the global one),
397 a chain of BLOCK nodes for all the levels
398 that were entered and exited one level down. */
401 /* The binding level which this one is contained in (inherits from). */
402 struct binding_level
*level_chain
;
404 /* The bytecode PC that marks the end of this level. */
406 /* The bytecode PC that marks the start of this level. */
409 /* The statements in this binding level. */
412 /* An exception range associated with this binding level. */
413 struct eh_range
* GTY((skip (""))) exception_range
;
415 /* Binding depth at which this level began. Used only for debugging. */
416 unsigned binding_depth
;
418 /* The location at which this level began. */
422 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
424 /* The binding level currently in effect. */
426 static GTY(()) struct binding_level
*current_binding_level
;
428 /* A chain of binding_level structures awaiting reuse. */
430 static GTY(()) struct binding_level
*free_binding_level
;
432 /* The outermost binding level, for names of file scope.
433 This is created when the compiler is started and exists
434 through the entire run. */
436 static GTY(()) struct binding_level
*global_binding_level
;
438 /* The binding level that holds variables declared at the outermost
439 level within a function body. */
441 static struct binding_level
*function_binding_level
;
443 /* A PC value bigger than any PC value we may ever may encounter. */
445 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
447 /* Binding level structures are initialized by copying this one. */
449 static const struct binding_level clear_binding_level
451 NULL_TREE
, /* names */
452 NULL_TREE
, /* shadowed */
453 NULL_TREE
, /* blocks */
454 NULL_BINDING_LEVEL
, /* level_chain */
455 LARGEST_PC
, /* end_pc */
458 NULL
, /* exception_range */
459 0, /* binding_depth */
463 tree java_global_trees
[JTI_MAX
];
465 /* Build (and pushdecl) a "promoted type" for all standard
466 types shorter than int. */
469 push_promoted_type (const char *name
, tree actual_type
)
471 tree type
= make_node (TREE_CODE (actual_type
));
473 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
474 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
476 tree in_min
= TYPE_MIN_VALUE (actual_type
);
477 tree in_max
= TYPE_MAX_VALUE (actual_type
);
479 TYPE_MIN_VALUE (type
) = copy_node (in_min
);
480 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
481 TYPE_MAX_VALUE (type
) = copy_node (in_max
);
482 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
483 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
484 TYPE_STRING_FLAG (type
) = TYPE_STRING_FLAG (actual_type
);
486 pushdecl (build_decl (input_location
,
487 TYPE_DECL
, get_identifier (name
), type
));
491 /* Return tree that represents a vtable for a primitive array. */
493 create_primitive_vtable (const char *name
)
498 sprintf (buf
, "_Jv_%sVTable", name
);
499 r
= build_decl (input_location
,
500 VAR_DECL
, get_identifier (buf
), ptr_type_node
);
501 DECL_EXTERNAL (r
) = 1;
505 /* Parse the version string and compute the ABI version number. */
509 const char *p
= version_string
;
510 unsigned int major
= 0, minor
= 0;
511 unsigned int abi_version
;
513 /* Skip leading junk. */
514 while (*p
&& !ISDIGIT (*p
))
518 /* Extract major version. */
521 major
= major
* 10 + *p
- '0';
525 gcc_assert (*p
== '.' && ISDIGIT (p
[1]));
528 /* Extract minor version. */
531 minor
= minor
* 10 + *p
- '0';
535 if (flag_indirect_dispatch
)
537 abi_version
= GCJ_CURRENT_BC_ABI_VERSION
;
538 abi_version
|= FLAG_BINARYCOMPAT_ABI
;
542 /* Implicit in this computation is the idea that we won't break the
543 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
545 abi_version
= 100000 * major
+ 1000 * minor
;
547 if (flag_bootstrap_classes
)
548 abi_version
|= FLAG_BOOTSTRAP_LOADER
;
550 gcj_abi_version
= build_int_cstu (ptr_type_node
, abi_version
);
554 java_init_decl_processing (void)
556 tree field
= NULL_TREE
;
559 init_class_processing ();
561 current_function_decl
= NULL
;
562 current_binding_level
= NULL_BINDING_LEVEL
;
563 free_binding_level
= NULL_BINDING_LEVEL
;
564 pushlevel (0); /* make the binding_level structure for global names */
565 global_binding_level
= current_binding_level
;
567 /* Build common tree nodes, Java has an unsigned char. */
568 build_common_tree_nodes (false, false);
570 /* ??? Now we continue and override some of the built types again
571 with Java specific types. As the above generated types are
572 supposed to match the targets C ABI this isn't really the way
573 to go and any Java specifics should _not_ use those global types
574 if the Java ABI does not match the C one. */
576 byte_type_node
= make_signed_type (8);
577 pushdecl (build_decl (BUILTINS_LOCATION
,
578 TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
579 short_type_node
= make_signed_type (16);
580 pushdecl (build_decl (BUILTINS_LOCATION
,
581 TYPE_DECL
, get_identifier ("short"), short_type_node
));
582 int_type_node
= make_signed_type (32);
583 pushdecl (build_decl (BUILTINS_LOCATION
,
584 TYPE_DECL
, get_identifier ("int"), int_type_node
));
585 long_type_node
= make_signed_type (64);
586 pushdecl (build_decl (BUILTINS_LOCATION
,
587 TYPE_DECL
, get_identifier ("long"), long_type_node
));
589 unsigned_byte_type_node
= make_unsigned_type (8);
590 pushdecl (build_decl (BUILTINS_LOCATION
,
591 TYPE_DECL
, get_identifier ("unsigned byte"),
592 unsigned_byte_type_node
));
593 unsigned_short_type_node
= make_unsigned_type (16);
594 pushdecl (build_decl (BUILTINS_LOCATION
,
595 TYPE_DECL
, get_identifier ("unsigned short"),
596 unsigned_short_type_node
));
597 unsigned_int_type_node
= make_unsigned_type (32);
598 pushdecl (build_decl (BUILTINS_LOCATION
,
599 TYPE_DECL
, get_identifier ("unsigned int"),
600 unsigned_int_type_node
));
601 unsigned_long_type_node
= make_unsigned_type (64);
602 pushdecl (build_decl (BUILTINS_LOCATION
,
603 TYPE_DECL
, get_identifier ("unsigned long"),
604 unsigned_long_type_node
));
606 /* Define these next since types below may used them. */
607 integer_type_node
= java_type_for_size (INT_TYPE_SIZE
, 0);
608 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
609 integer_one_node
= build_int_cst (NULL_TREE
, 1);
610 integer_two_node
= build_int_cst (NULL_TREE
, 2);
611 integer_three_node
= build_int_cst (NULL_TREE
, 3);
612 integer_four_node
= build_int_cst (NULL_TREE
, 4);
613 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
615 /* A few values used for range checking in the lexer. */
616 decimal_int_max
= build_int_cstu (unsigned_int_type_node
, 0x80000000);
618 = double_int_to_tree (unsigned_long_type_node
,
619 double_int_zero
.set_bit (64));
621 long_zero_node
= build_int_cst (long_type_node
, 0);
623 pushdecl (build_decl (BUILTINS_LOCATION
,
624 TYPE_DECL
, get_identifier ("void"), void_type_node
));
626 t
= make_node (VOID_TYPE
);
627 layout_type (t
); /* Uses size_zero_node */
628 return_address_type_node
= build_pointer_type (t
);
630 char_type_node
= make_unsigned_type (16);
631 TYPE_STRING_FLAG (char_type_node
) = 1;
632 pushdecl (build_decl (BUILTINS_LOCATION
,
633 TYPE_DECL
, get_identifier ("char"), char_type_node
));
635 boolean_type_node
= make_unsigned_type (1);
636 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
637 pushdecl (build_decl (BUILTINS_LOCATION
,
638 TYPE_DECL
, get_identifier ("boolean"),
640 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
641 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
643 promoted_byte_type_node
644 = push_promoted_type ("promoted_byte", byte_type_node
);
645 promoted_short_type_node
646 = push_promoted_type ("promoted_short", short_type_node
);
647 promoted_char_type_node
648 = push_promoted_type ("promoted_char", char_type_node
);
649 promoted_boolean_type_node
650 = push_promoted_type ("promoted_boolean", boolean_type_node
);
652 float_type_node
= make_node (REAL_TYPE
);
653 TYPE_PRECISION (float_type_node
) = 32;
654 pushdecl (build_decl (BUILTINS_LOCATION
,
655 TYPE_DECL
, get_identifier ("float"),
657 layout_type (float_type_node
);
659 double_type_node
= make_node (REAL_TYPE
);
660 TYPE_PRECISION (double_type_node
) = 64;
661 pushdecl (build_decl (BUILTINS_LOCATION
,
662 TYPE_DECL
, get_identifier ("double"),
664 layout_type (double_type_node
);
666 float_zero_node
= build_real (float_type_node
, dconst0
);
667 double_zero_node
= build_real (double_type_node
, dconst0
);
669 /* These are the vtables for arrays of primitives. */
670 boolean_array_vtable
= create_primitive_vtable ("boolean");
671 byte_array_vtable
= create_primitive_vtable ("byte");
672 char_array_vtable
= create_primitive_vtable ("char");
673 short_array_vtable
= create_primitive_vtable ("short");
674 int_array_vtable
= create_primitive_vtable ("int");
675 long_array_vtable
= create_primitive_vtable ("long");
676 float_array_vtable
= create_primitive_vtable ("float");
677 double_array_vtable
= create_primitive_vtable ("double");
679 one_elt_array_domain_type
= build_index_type (integer_one_node
);
680 utf8const_type
= make_node (RECORD_TYPE
);
681 PUSH_FIELD (input_location
,
682 utf8const_type
, field
, "hash", unsigned_short_type_node
);
683 PUSH_FIELD (input_location
,
684 utf8const_type
, field
, "length", unsigned_short_type_node
);
685 FINISH_RECORD (utf8const_type
);
686 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
688 atable_type
= build_array_type (ptr_type_node
,
689 one_elt_array_domain_type
);
690 TYPE_NONALIASED_COMPONENT (atable_type
) = 1;
691 atable_ptr_type
= build_pointer_type (atable_type
);
693 itable_type
= build_array_type (ptr_type_node
,
694 one_elt_array_domain_type
);
695 TYPE_NONALIASED_COMPONENT (itable_type
) = 1;
696 itable_ptr_type
= build_pointer_type (itable_type
);
698 symbol_type
= make_node (RECORD_TYPE
);
699 PUSH_FIELD (input_location
,
700 symbol_type
, field
, "clname", utf8const_ptr_type
);
701 PUSH_FIELD (input_location
, symbol_type
, field
, "name", utf8const_ptr_type
);
702 PUSH_FIELD (input_location
,
703 symbol_type
, field
, "signature", utf8const_ptr_type
);
704 FINISH_RECORD (symbol_type
);
706 symbols_array_type
= build_array_type (symbol_type
,
707 one_elt_array_domain_type
);
708 symbols_array_ptr_type
= build_pointer_type (symbols_array_type
);
710 assertion_entry_type
= make_node (RECORD_TYPE
);
711 PUSH_FIELD (input_location
,
712 assertion_entry_type
, field
, "assertion_code", integer_type_node
);
713 PUSH_FIELD (input_location
,
714 assertion_entry_type
, field
, "op1", utf8const_ptr_type
);
715 PUSH_FIELD (input_location
,
716 assertion_entry_type
, field
, "op2", utf8const_ptr_type
);
717 FINISH_RECORD (assertion_entry_type
);
719 assertion_table_type
= build_array_type (assertion_entry_type
,
720 one_elt_array_domain_type
);
722 /* As you're adding items here, please update the code right after
723 this section, so that the filename containing the source code of
724 the pre-defined class gets registered correctly. */
725 unqualified_object_id_node
= get_identifier ("Object");
726 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
727 object_ptr_type_node
= promote_type (object_type_node
);
728 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
729 string_ptr_type_node
= promote_type (string_type_node
);
730 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
731 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
732 exception_type_node
= lookup_class (get_identifier ("java.lang.Exception"));
733 runtime_exception_type_node
=
734 lookup_class (get_identifier ("java.lang.RuntimeException"));
735 error_exception_type_node
=
736 lookup_class (get_identifier ("java.lang.Error"));
738 rawdata_ptr_type_node
739 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
741 add_predefined_file (get_identifier ("java/lang/Class.java"));
742 add_predefined_file (get_identifier ("java/lang/Error.java"));
743 add_predefined_file (get_identifier ("java/lang/Object.java"));
744 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
745 add_predefined_file (get_identifier ("java/lang/String.java"));
746 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
747 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
748 add_predefined_file (get_identifier ("java/lang/Exception.java"));
749 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
750 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
752 methodtable_type
= make_node (RECORD_TYPE
);
753 layout_type (methodtable_type
);
754 build_decl (BUILTINS_LOCATION
,
755 TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
756 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
758 TYPE_identifier_node
= get_identifier ("TYPE");
759 init_identifier_node
= get_identifier ("<init>");
760 clinit_identifier_node
= get_identifier ("<clinit>");
761 void_signature_node
= get_identifier ("()V");
762 finalize_identifier_node
= get_identifier ("finalize");
763 this_identifier_node
= get_identifier ("this");
765 java_lang_cloneable_identifier_node
= get_identifier ("java.lang.Cloneable");
766 java_io_serializable_identifier_node
=
767 get_identifier ("java.io.Serializable");
769 /* for lack of a better place to put this stub call */
770 init_expr_processing();
772 constants_type_node
= make_node (RECORD_TYPE
);
773 PUSH_FIELD (input_location
,
774 constants_type_node
, field
, "size", unsigned_int_type_node
);
775 PUSH_FIELD (input_location
,
776 constants_type_node
, field
, "tags", ptr_type_node
);
777 PUSH_FIELD (input_location
,
778 constants_type_node
, field
, "data", ptr_type_node
);
779 constants_data_field_decl_node
= field
;
780 FINISH_RECORD (constants_type_node
);
781 build_decl (BUILTINS_LOCATION
,
782 TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
784 access_flags_type_node
= unsigned_short_type_node
;
786 dtable_type
= make_node (RECORD_TYPE
);
787 dtable_ptr_type
= build_pointer_type (dtable_type
);
789 otable_type
= build_array_type (integer_type_node
,
790 one_elt_array_domain_type
);
791 TYPE_NONALIASED_COMPONENT (otable_type
) = 1;
792 otable_ptr_type
= build_pointer_type (otable_type
);
794 PUSH_FIELD (input_location
,
795 object_type_node
, field
, "vtable", dtable_ptr_type
);
796 DECL_FCONTEXT (field
) = object_type_node
;
797 TYPE_VFIELD (object_type_node
) = field
;
799 /* This isn't exactly true, but it is what we have in the source.
800 There is an unresolved issue here, which is whether the vtable
801 should be marked by the GC. */
802 if (! flag_hash_synchronization
)
803 PUSH_FIELD (input_location
, object_type_node
, field
, "sync_info",
804 build_pointer_type (object_type_node
));
805 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
806 FIELD_PRIVATE (t
) = 1;
807 FINISH_RECORD (object_type_node
);
809 field_type_node
= make_node (RECORD_TYPE
);
810 field_ptr_type_node
= build_pointer_type (field_type_node
);
811 method_type_node
= make_node (RECORD_TYPE
);
812 method_ptr_type_node
= build_pointer_type (method_type_node
);
814 set_super_info (0, class_type_node
, object_type_node
, 0);
815 set_super_info (0, string_type_node
, object_type_node
, 0);
816 class_ptr_type
= build_pointer_type (class_type_node
);
818 PUSH_FIELD (input_location
,
819 class_type_node
, field
, "next_or_version", class_ptr_type
);
820 PUSH_FIELD (input_location
,
821 class_type_node
, field
, "name", utf8const_ptr_type
);
822 PUSH_FIELD (input_location
,
823 class_type_node
, field
, "accflags", access_flags_type_node
);
824 PUSH_FIELD (input_location
,
825 class_type_node
, field
, "superclass", class_ptr_type
);
826 PUSH_FIELD (input_location
,
827 class_type_node
, field
, "constants", constants_type_node
);
828 constants_field_decl_node
= field
;
829 PUSH_FIELD (input_location
,
830 class_type_node
, field
, "methods", method_ptr_type_node
);
831 PUSH_FIELD (input_location
,
832 class_type_node
, field
, "method_count", short_type_node
);
833 PUSH_FIELD (input_location
,
834 class_type_node
, field
, "vtable_method_count", short_type_node
);
835 PUSH_FIELD (input_location
,
836 class_type_node
, field
, "fields", field_ptr_type_node
);
837 PUSH_FIELD (input_location
,
838 class_type_node
, field
, "size_in_bytes", int_type_node
);
839 PUSH_FIELD (input_location
,
840 class_type_node
, field
, "field_count", short_type_node
);
841 PUSH_FIELD (input_location
,
842 class_type_node
, field
, "static_field_count", short_type_node
);
843 PUSH_FIELD (input_location
,
844 class_type_node
, field
, "vtable", dtable_ptr_type
);
845 PUSH_FIELD (input_location
,
846 class_type_node
, field
, "otable", otable_ptr_type
);
847 PUSH_FIELD (input_location
,
848 class_type_node
, field
, "otable_syms",
849 symbols_array_ptr_type
);
850 PUSH_FIELD (input_location
,
851 class_type_node
, field
, "atable", atable_ptr_type
);
852 PUSH_FIELD (input_location
,
853 class_type_node
, field
, "atable_syms",
854 symbols_array_ptr_type
);
855 PUSH_FIELD (input_location
,
856 class_type_node
, field
, "itable", itable_ptr_type
);
857 PUSH_FIELD (input_location
, class_type_node
, field
, "itable_syms",
858 symbols_array_ptr_type
);
859 PUSH_FIELD (input_location
,
860 class_type_node
, field
, "catch_classes", ptr_type_node
);
861 PUSH_FIELD (input_location
, class_type_node
, field
, "interfaces",
862 build_pointer_type (class_ptr_type
));
863 PUSH_FIELD (input_location
, class_type_node
, field
, "loader", ptr_type_node
);
864 PUSH_FIELD (input_location
,
865 class_type_node
, field
, "interface_count", short_type_node
);
866 PUSH_FIELD (input_location
, class_type_node
, field
, "state", byte_type_node
);
867 PUSH_FIELD (input_location
, class_type_node
, field
, "thread", ptr_type_node
);
868 PUSH_FIELD (input_location
,
869 class_type_node
, field
, "depth", short_type_node
);
870 PUSH_FIELD (input_location
,
871 class_type_node
, field
, "ancestors", ptr_type_node
);
872 PUSH_FIELD (input_location
, class_type_node
, field
, "idt", ptr_type_node
);
873 PUSH_FIELD (input_location
,
874 class_type_node
, field
, "arrayclass", ptr_type_node
);
875 PUSH_FIELD (input_location
,
876 class_type_node
, field
, "protectionDomain", ptr_type_node
);
877 PUSH_FIELD (input_location
,
878 class_type_node
, field
, "assertion_table", ptr_type_node
);
879 PUSH_FIELD (input_location
,
880 class_type_node
, field
, "hack_signers", ptr_type_node
);
881 PUSH_FIELD (input_location
, class_type_node
, field
, "chain", ptr_type_node
);
882 PUSH_FIELD (input_location
,
883 class_type_node
, field
, "aux_info", ptr_type_node
);
884 PUSH_FIELD (input_location
, class_type_node
, field
, "engine", ptr_type_node
);
885 PUSH_FIELD (input_location
,
886 class_type_node
, field
, "reflection_data", ptr_type_node
);
887 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
888 FIELD_PRIVATE (t
) = 1;
889 push_super_field (class_type_node
, object_type_node
);
891 FINISH_RECORD (class_type_node
);
892 build_decl (BUILTINS_LOCATION
,
893 TYPE_DECL
, get_identifier ("Class"), class_type_node
);
895 field_info_union_node
= make_node (UNION_TYPE
);
896 PUSH_FIELD (input_location
,
897 field_info_union_node
, field
, "boffset", int_type_node
);
898 PUSH_FIELD (input_location
,
899 field_info_union_node
, field
, "addr", ptr_type_node
);
900 layout_type (field_info_union_node
);
902 PUSH_FIELD (input_location
,
903 field_type_node
, field
, "name", utf8const_ptr_type
);
904 PUSH_FIELD (input_location
, field_type_node
, field
, "type", class_ptr_type
);
905 PUSH_FIELD (input_location
,
906 field_type_node
, field
, "accflags", access_flags_type_node
);
907 PUSH_FIELD (input_location
,
908 field_type_node
, field
, "bsize", unsigned_short_type_node
);
909 PUSH_FIELD (input_location
,
910 field_type_node
, field
, "info", field_info_union_node
);
911 FINISH_RECORD (field_type_node
);
912 build_decl (BUILTINS_LOCATION
,
913 TYPE_DECL
, get_identifier ("Field"), field_type_node
);
915 nativecode_ptr_array_type_node
916 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
918 PUSH_FIELD (input_location
,
919 dtable_type
, field
, "class", class_ptr_type
);
920 PUSH_FIELD (input_location
,
921 dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
922 FINISH_RECORD (dtable_type
);
923 build_decl (BUILTINS_LOCATION
,
924 TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
926 jexception_type
= make_node (RECORD_TYPE
);
927 PUSH_FIELD (input_location
,
928 jexception_type
, field
, "start_pc", ptr_type_node
);
929 PUSH_FIELD (input_location
, jexception_type
, field
, "end_pc", ptr_type_node
);
930 PUSH_FIELD (input_location
,
931 jexception_type
, field
, "handler_pc", ptr_type_node
);
932 PUSH_FIELD (input_location
,
933 jexception_type
, field
, "catch_type", class_ptr_type
);
934 FINISH_RECORD (jexception_type
);
935 build_decl (BUILTINS_LOCATION
,
936 TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
937 jexception_ptr_type
= build_pointer_type (jexception_type
);
939 lineNumberEntry_type
= make_node (RECORD_TYPE
);
940 PUSH_FIELD (input_location
,
941 lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
942 PUSH_FIELD (input_location
,
943 lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
944 FINISH_RECORD (lineNumberEntry_type
);
946 lineNumbers_type
= make_node (RECORD_TYPE
);
947 PUSH_FIELD (input_location
,
948 lineNumbers_type
, field
, "length", unsigned_int_type_node
);
949 FINISH_RECORD (lineNumbers_type
);
951 PUSH_FIELD (input_location
,
952 method_type_node
, field
, "name", utf8const_ptr_type
);
953 PUSH_FIELD (input_location
,
954 method_type_node
, field
, "signature", utf8const_ptr_type
);
955 PUSH_FIELD (input_location
,
956 method_type_node
, field
, "accflags", access_flags_type_node
);
957 PUSH_FIELD (input_location
,
958 method_type_node
, field
, "index", unsigned_short_type_node
);
959 PUSH_FIELD (input_location
,
960 method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
961 PUSH_FIELD (input_location
,
962 method_type_node
, field
, "throws", ptr_type_node
);
963 FINISH_RECORD (method_type_node
);
964 build_decl (BUILTINS_LOCATION
,
965 TYPE_DECL
, get_identifier ("Method"), method_type_node
);
967 end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
969 t
= build_function_type_list (ptr_type_node
, class_ptr_type
, NULL_TREE
);
970 alloc_object_node
= add_builtin_function ("_Jv_AllocObject", t
,
971 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
972 DECL_IS_MALLOC (alloc_object_node
) = 1;
973 alloc_no_finalizer_node
=
974 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t
,
975 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
976 DECL_IS_MALLOC (alloc_no_finalizer_node
) = 1;
978 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
979 soft_initclass_node
= add_builtin_function ("_Jv_InitClass", t
,
980 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
981 t
= build_function_type_list (ptr_type_node
,
982 class_ptr_type
, int_type_node
, NULL_TREE
);
983 soft_resolvepoolentry_node
984 = add_builtin_function ("_Jv_ResolvePoolEntry", t
,
985 0,NOT_BUILT_IN
, NULL
, NULL_TREE
);
986 DECL_PURE_P (soft_resolvepoolentry_node
) = 1;
987 t
= build_function_type_list (void_type_node
,
988 class_ptr_type
, int_type_node
, NULL_TREE
);
989 throw_node
= add_builtin_function ("_Jv_Throw", t
,
990 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
991 /* Mark throw_nodes as `noreturn' functions with side effects. */
992 TREE_THIS_VOLATILE (throw_node
) = 1;
993 TREE_SIDE_EFFECTS (throw_node
) = 1;
995 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
996 soft_monitorenter_node
997 = add_builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
999 soft_monitorexit_node
1000 = add_builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
1003 t
= build_function_type_list (ptr_type_node
,
1004 ptr_type_node
, int_type_node
, NULL_TREE
);
1006 = add_builtin_function ("_Jv_NewPrimArray", t
,
1007 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1008 DECL_IS_MALLOC (soft_newarray_node
) = 1;
1010 t
= build_function_type_list (ptr_type_node
,
1011 int_type_node
, class_ptr_type
,
1012 object_ptr_type_node
, NULL_TREE
);
1014 = add_builtin_function ("_Jv_NewObjectArray", t
,
1015 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1016 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
1018 t
= build_varargs_function_type_list (ptr_type_node
,
1019 ptr_type_node
, int_type_node
,
1021 soft_multianewarray_node
1022 = add_builtin_function ("_Jv_NewMultiArray", t
,
1023 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1024 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
1026 t
= build_function_type_list (void_type_node
, int_type_node
, NULL_TREE
);
1027 soft_badarrayindex_node
1028 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t
,
1029 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1030 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1032 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
1033 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
1035 t
= build_function_type_list (void_type_node
, NULL_TREE
);
1036 soft_nullpointer_node
1037 = add_builtin_function ("_Jv_ThrowNullPointerException", t
,
1038 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1039 /* Mark soft_nullpointer_node as a `noreturn' function with side
1041 TREE_THIS_VOLATILE (soft_nullpointer_node
) = 1;
1042 TREE_SIDE_EFFECTS (soft_nullpointer_node
) = 1;
1044 soft_abstractmethod_node
1045 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t
,
1046 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1047 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1049 TREE_THIS_VOLATILE (soft_abstractmethod_node
) = 1;
1050 TREE_SIDE_EFFECTS (soft_abstractmethod_node
) = 1;
1052 soft_nosuchfield_node
1053 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t
,
1054 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1055 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1057 TREE_THIS_VOLATILE (soft_nosuchfield_node
) = 1;
1058 TREE_SIDE_EFFECTS (soft_nosuchfield_node
) = 1;
1060 t
= build_function_type_list (ptr_type_node
,
1061 class_ptr_type
, object_ptr_type_node
,
1064 = add_builtin_function ("_Jv_CheckCast", t
,
1065 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1066 t
= build_function_type_list (boolean_type_node
,
1067 object_ptr_type_node
, class_ptr_type
,
1069 soft_instanceof_node
1070 = add_builtin_function ("_Jv_IsInstanceOf", t
,
1071 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1072 DECL_PURE_P (soft_instanceof_node
) = 1;
1073 t
= build_function_type_list (void_type_node
,
1074 object_ptr_type_node
, object_ptr_type_node
,
1076 soft_checkarraystore_node
1077 = add_builtin_function ("_Jv_CheckArrayStore", t
,
1078 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1079 t
= build_function_type_list (ptr_type_node
,
1080 ptr_type_node
, ptr_type_node
, int_type_node
,
1082 soft_lookupinterfacemethod_node
1083 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t
,
1084 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1085 DECL_PURE_P (soft_lookupinterfacemethod_node
) = 1;
1087 t
= build_function_type_list (ptr_type_node
,
1088 ptr_type_node
, ptr_type_node
, ptr_type_node
,
1090 soft_lookupinterfacemethodbyname_node
1091 = add_builtin_function ("_Jv_LookupInterfaceMethod", t
,
1092 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1093 t
= build_function_type_list (ptr_type_node
,
1094 object_ptr_type_node
, ptr_type_node
,
1095 ptr_type_node
, int_type_node
, NULL_TREE
);
1096 soft_lookupjnimethod_node
1097 = add_builtin_function ("_Jv_LookupJNIMethod", t
,
1098 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1099 t
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
1100 soft_getjnienvnewframe_node
1101 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t
,
1102 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1103 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
1104 soft_jnipopsystemframe_node
1105 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t
,
1106 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1108 t
= build_function_type_list (object_ptr_type_node
,
1109 object_ptr_type_node
, NULL_TREE
);
1111 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t
,
1112 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1114 t
= build_function_type_list (int_type_node
,
1115 int_type_node
, int_type_node
, NULL_TREE
);
1117 = add_builtin_function ("_Jv_divI", t
,
1118 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1121 = add_builtin_function ("_Jv_remI", t
,
1122 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1124 t
= build_function_type_list (long_type_node
,
1125 long_type_node
, long_type_node
, NULL_TREE
);
1127 = add_builtin_function ("_Jv_divJ", t
,
1128 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1131 = add_builtin_function ("_Jv_remJ", t
,
1132 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1134 initialize_builtins ();
1136 soft_fmod_node
= builtin_decl_explicit (BUILT_IN_FMOD
);
1142 /* Look up NAME in the current binding level and its superiors
1143 in the namespace of variables, functions and typedefs.
1144 Return a ..._DECL node of some kind representing its definition,
1145 or return 0 if it is undefined. */
1148 lookup_name (tree name
)
1151 if (current_binding_level
!= global_binding_level
1152 && IDENTIFIER_LOCAL_VALUE (name
))
1153 val
= IDENTIFIER_LOCAL_VALUE (name
);
1155 val
= IDENTIFIER_GLOBAL_VALUE (name
);
1159 /* Similar to `lookup_name' but look only at current binding level and
1160 the previous one if it's the parameter level. */
1163 lookup_name_current_level (tree name
)
1167 if (current_binding_level
== global_binding_level
)
1168 return IDENTIFIER_GLOBAL_VALUE (name
);
1170 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
1173 for (t
= current_binding_level
->names
; t
; t
= DECL_CHAIN (t
))
1174 if (DECL_NAME (t
) == name
)
1180 /* Record a decl-node X as belonging to the current lexical scope.
1181 Check for errors (such as an incompatible declaration for the same
1182 name already seen in the same scope).
1184 Returns either X or an old decl for the same name.
1185 If an old decl is returned, it may have been smashed
1186 to agree with what X says. */
1192 tree name
= DECL_NAME (x
);
1193 struct binding_level
*b
= current_binding_level
;
1195 if (TREE_CODE (x
) != TYPE_DECL
)
1196 DECL_CONTEXT (x
) = current_function_decl
;
1199 t
= lookup_name_current_level (name
);
1200 if (t
!= 0 && t
== error_mark_node
)
1201 /* error_mark_node is 0 for a while during initialization! */
1204 error ("%q+D used prior to declaration", x
);
1207 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1208 to point to the TYPE_DECL.
1209 Since Java does not have typedefs, a type can only have
1210 one (true) name, given by a class, interface, or builtin. */
1211 if (TREE_CODE (x
) == TYPE_DECL
1212 && TYPE_NAME (TREE_TYPE (x
)) == 0
1213 && TREE_TYPE (x
) != error_mark_node
)
1215 TYPE_NAME (TREE_TYPE (x
)) = x
;
1216 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1219 /* This name is new in its binding level.
1220 Install the new declaration and return it. */
1221 if (b
== global_binding_level
)
1223 /* Install a global value. */
1225 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1229 /* Here to install a non-global value. */
1230 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1231 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1233 /* If storing a local value, there may already be one (inherited).
1234 If so, record it for restoration when this binding level ends. */
1236 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1240 /* Put decls on list in reverse order.
1241 We will reverse them later if necessary. */
1242 DECL_CHAIN (x
) = b
->names
;
1249 pushdecl_force_head (tree x
)
1251 current_binding_level
->names
= x
;
1254 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1257 pushdecl_top_level (tree x
)
1260 struct binding_level
*b
= current_binding_level
;
1262 current_binding_level
= global_binding_level
;
1264 current_binding_level
= b
;
1268 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1271 pushdecl_function_level (tree x
)
1274 struct binding_level
*b
= current_binding_level
;
1276 current_binding_level
= function_binding_level
;
1278 current_binding_level
= b
;
1282 /* Return true if we are in the global binding level. */
1285 global_bindings_p (void)
1287 return current_binding_level
== global_binding_level
;
1290 /* Return the list of declarations of the current level.
1291 Note that this list is in reverse order unless/until
1292 you nreverse it; and when you do nreverse it, you must
1293 store the result back using `storedecls' or you will lose. */
1298 return current_binding_level
->names
;
1301 /* Create a new `struct binding_level'. */
1303 static struct binding_level
*
1304 make_binding_level (void)
1307 return ggc_alloc_cleared_binding_level ();
1311 pushlevel (int unused ATTRIBUTE_UNUSED
)
1313 struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1315 /* Reuse or create a struct for this binding level. */
1317 if (free_binding_level
)
1319 newlevel
= free_binding_level
;
1320 free_binding_level
= free_binding_level
->level_chain
;
1324 newlevel
= make_binding_level ();
1327 /* Add this level to the front of the chain (stack) of levels that
1330 *newlevel
= clear_binding_level
;
1331 newlevel
->level_chain
= current_binding_level
;
1332 newlevel
->loc
= input_location
;
1333 current_binding_level
= newlevel
;
1334 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1335 newlevel
->binding_depth
= binding_depth
;
1337 fprintf (stderr
, "push %s level %p pc %d\n",
1338 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1341 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1344 /* Exit a binding level.
1345 Pop the level off, and restore the state of the identifier-decl mappings
1346 that were in effect when this level was entered.
1348 If KEEP is nonzero, this level had explicit declarations, so
1349 and create a "block" (a BLOCK node) for the level
1350 to record its declarations and subblocks for symbol table output.
1352 If FUNCTIONBODY is nonzero, this level is the body of a function,
1353 so create a block as if KEEP were set and also clear out all
1356 If REVERSE is nonzero, reverse the order of decls before putting
1357 them into the BLOCK. */
1360 poplevel (int keep
, int reverse
, int functionbody
)
1363 /* The chain of decls was accumulated in reverse order.
1364 Put it into forward order, just for cleanliness. */
1366 tree subblocks
= current_binding_level
->blocks
;
1371 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1374 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1375 fprintf (stderr
, "pop %s level %p pc %d (end pc %d)\n",
1376 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1377 current_binding_level
->end_pc
);
1379 fprintf (stderr
, "pop %s level %p pc %d\n",
1380 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1381 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1383 /* Get the decls in the order they were written.
1384 Usually current_binding_level->names is in reverse order.
1385 But parameter decls were previously put in forward order. */
1388 current_binding_level
->names
1389 = decls
= nreverse (current_binding_level
->names
);
1391 decls
= current_binding_level
->names
;
1393 for (decl
= decls
; decl
; decl
= DECL_CHAIN (decl
))
1394 if (TREE_CODE (decl
) == VAR_DECL
1395 && DECL_LANG_SPECIFIC (decl
) != NULL
1396 && DECL_LOCAL_SLOT_NUMBER (decl
))
1397 LOCAL_VAR_OUT_OF_SCOPE_P (decl
) = 1;
1399 /* If there were any declarations in that level,
1400 or if this level is a function body,
1401 create a BLOCK to record them for the life of this function. */
1404 if (keep
|| functionbody
)
1405 block
= make_node (BLOCK
);
1407 if (current_binding_level
->exception_range
)
1408 expand_end_java_handler (current_binding_level
->exception_range
);
1412 /* If any statements have been generated at this level, create a
1413 BIND_EXPR to hold them and copy the variables to it. This
1414 only applies to the bytecode compiler. */
1415 if (current_binding_level
->stmts
)
1418 tree
*var
= &BLOCK_VARS (block
);
1420 /* Copy decls from names list, ignoring labels. */
1423 tree next
= DECL_CHAIN (decl
);
1424 if (TREE_CODE (decl
) != LABEL_DECL
)
1427 var
= &DECL_CHAIN (decl
);
1433 bind
= build3 (BIND_EXPR
, void_type_node
, BLOCK_VARS (block
),
1434 BLOCK_EXPR_BODY (block
), block
);
1435 BIND_EXPR_BODY (bind
) = current_binding_level
->stmts
;
1437 if (BIND_EXPR_BODY (bind
)
1438 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind
)))
1439 TREE_SIDE_EFFECTS (bind
) = 1;
1441 /* FIXME: gimplifier brain damage. */
1442 if (BIND_EXPR_BODY (bind
) == NULL
)
1443 BIND_EXPR_BODY (bind
) = build_java_empty_stmt ();
1445 SET_EXPR_LOCATION (bind
, current_binding_level
->loc
);
1447 current_binding_level
->stmts
= NULL
;
1451 BLOCK_VARS (block
) = decls
;
1453 BLOCK_SUBBLOCKS (block
) = subblocks
;
1456 /* In each subblock, record that this is its superior. */
1458 for (link
= subblocks
; link
; link
= BLOCK_CHAIN (link
))
1459 BLOCK_SUPERCONTEXT (link
) = block
;
1461 /* Clear out the meanings of the local variables of this level. */
1463 for (link
= decls
; link
; link
= DECL_CHAIN (link
))
1465 tree name
= DECL_NAME (link
);
1466 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1468 /* If the ident. was used or addressed via a local extern decl,
1469 don't forget that fact. */
1470 if (DECL_EXTERNAL (link
))
1472 if (TREE_USED (link
))
1473 TREE_USED (name
) = 1;
1474 if (TREE_ADDRESSABLE (link
))
1475 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1477 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1481 /* Restore all name-meanings of the outer levels
1482 that were shadowed by this level. */
1484 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1485 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1487 /* If the level being exited is the top level of a function,
1488 check over all the labels, and clear out the current
1489 (function local) meanings of their names. */
1493 /* If this is the top level block of a function,
1494 the vars are the function's parameters.
1495 Don't leave them in the BLOCK because they are
1496 found in the FUNCTION_DECL instead. */
1498 BLOCK_VARS (block
) = 0;
1501 /* Pop the current level, and free the structure for reuse. */
1504 struct binding_level
*level
= current_binding_level
;
1505 current_binding_level
= current_binding_level
->level_chain
;
1507 level
->level_chain
= free_binding_level
;
1508 free_binding_level
= level
;
1511 /* Dispose of the block that we just made inside some higher level. */
1514 DECL_INITIAL (current_function_decl
) = block
;
1515 DECL_SAVED_TREE (current_function_decl
) = bind
;
1521 current_binding_level
->blocks
1522 = block_chainon (current_binding_level
->blocks
, block
);
1524 /* If we did not make a block for the level just exited,
1525 any blocks made for inner levels
1526 (since they cannot be recorded as subblocks in that level)
1527 must be carried forward so they will later become subblocks
1528 of something else. */
1530 current_binding_level
->blocks
1531 = block_chainon (current_binding_level
->blocks
, subblocks
);
1534 java_add_stmt (bind
);
1538 TREE_USED (block
) = 1;
1543 maybe_pushlevels (int pc
)
1545 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1549 while (pending_local_decls
!= NULL_TREE
&&
1550 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1552 tree
*ptr
= &pending_local_decls
;
1553 tree decl
= *ptr
, next
;
1554 int end_pc
= DECL_LOCAL_END_PC (decl
);
1556 while (*ptr
!= NULL_TREE
1557 && DECL_LOCAL_START_PC (*ptr
) <= pc
1558 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1559 ptr
= &DECL_CHAIN (*ptr
);
1560 pending_local_decls
= *ptr
;
1563 /* Force non-nested range to be nested in current range by
1564 truncating variable lifetimes. */
1565 if (end_pc
> current_binding_level
->end_pc
)
1568 end_pc
= current_binding_level
->end_pc
;
1569 for (t
= decl
; t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
1570 DECL_LOCAL_END_PC (t
) = end_pc
;
1573 maybe_start_try (pc
, end_pc
);
1577 current_binding_level
->end_pc
= end_pc
;
1578 current_binding_level
->start_pc
= pc
;
1579 current_binding_level
->names
= NULL
;
1580 for ( ; decl
!= NULL_TREE
; decl
= next
)
1582 int index
= DECL_LOCAL_SLOT_NUMBER (decl
);
1584 next
= DECL_CHAIN (decl
);
1585 push_jvm_slot (index
, decl
);
1588 = find_local_variable (index
, TREE_TYPE (decl
), pc
);
1589 if (TREE_CODE (TREE_TYPE (base_decl
)) == POINTER_TYPE
)
1590 base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
1591 SET_DECL_VALUE_EXPR (decl
, base_decl
);
1592 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1596 maybe_start_try (pc
, 0);
1600 maybe_poplevels (int pc
)
1602 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1606 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1607 inclusive, so a variable is live if pc == end_pc. Here, we
1608 terminate a range if the current pc is equal to the end of the
1609 range, and this is *before* we have generated code for the
1610 instruction at end_pc. We're closing a binding level one
1611 instruction too early.*/
1612 while (current_binding_level
->end_pc
<= pc
)
1616 /* Terminate any binding which began during the range beginning at
1617 start_pc. This tidies up improperly nested local variable ranges
1618 and exception handlers; a variable declared within an exception
1619 range is forcibly terminated when that exception ends. */
1622 force_poplevels (int start_pc
)
1624 while (current_binding_level
->start_pc
> start_pc
)
1626 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1627 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1628 current_function_decl
,
1629 current_binding_level
->start_pc
);
1634 /* integrate_decl_tree calls this function. */
1637 java_dup_lang_specific_decl (tree node
)
1640 struct lang_decl
*x
;
1642 if (!DECL_LANG_SPECIFIC (node
))
1645 lang_decl_size
= sizeof (struct lang_decl
);
1646 x
= ggc_alloc_lang_decl (lang_decl_size
);
1647 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1648 DECL_LANG_SPECIFIC (node
) = x
;
1652 give_name_to_locals (JCF
*jcf
)
1654 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1655 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1657 pending_local_decls
= NULL_TREE
;
1661 n
= JCF_readu2 (jcf
);
1662 for (i
= 0; i
< n
; i
++)
1664 int start_pc
= JCF_readu2 (jcf
);
1665 int length
= JCF_readu2 (jcf
);
1666 int name_index
= JCF_readu2 (jcf
);
1667 int signature_index
= JCF_readu2 (jcf
);
1668 int slot
= JCF_readu2 (jcf
);
1669 tree name
= get_name_constant (jcf
, name_index
);
1670 tree type
= parse_signature (jcf
, signature_index
);
1671 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1673 && length
== DECL_CODE_LENGTH (current_function_decl
))
1675 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1676 DECL_NAME (decl
) = name
;
1677 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1678 warning (0, "bad type in parameter debug info");
1683 int end_pc
= start_pc
+ length
;
1684 tree decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
1685 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1687 warning (0, "bad PC range for debug info for local %q+D",
1689 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1692 /* Adjust start_pc if necessary so that the local's first
1693 store operation will use the relevant DECL as a
1694 destination. Fore more information, read the leading
1695 comments for expr.c:maybe_adjust_start_pc. */
1696 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1698 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1699 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1700 DECL_LOCAL_START_PC (decl
) = start_pc
;
1701 DECL_LOCAL_END_PC (decl
) = end_pc
;
1703 /* Now insert the new decl in the proper place in
1704 pending_local_decls. We are essentially doing an insertion sort,
1705 which works fine, since the list input will normally already
1707 ptr
= &pending_local_decls
;
1708 while (*ptr
!= NULL_TREE
1709 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1710 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1711 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1712 ptr
= &DECL_CHAIN (*ptr
);
1713 DECL_CHAIN (decl
) = *ptr
;
1718 pending_local_decls
= nreverse (pending_local_decls
);
1720 /* Fill in default names for the parameters. */
1721 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1722 parm
!= NULL_TREE
; parm
= DECL_CHAIN (parm
), i
++)
1724 if (DECL_NAME (parm
) == NULL_TREE
)
1726 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1728 DECL_NAME (parm
) = get_identifier ("this");
1732 sprintf (buffer
, "ARG_%d", arg_i
);
1733 DECL_NAME (parm
) = get_identifier (buffer
);
1740 build_result_decl (tree fndecl
)
1742 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1743 tree result
= DECL_RESULT (fndecl
);
1746 result
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
1747 RESULT_DECL
, NULL_TREE
, restype
);
1748 DECL_ARTIFICIAL (result
) = 1;
1749 DECL_IGNORED_P (result
) = 1;
1750 DECL_CONTEXT (result
) = fndecl
;
1751 DECL_RESULT (fndecl
) = result
;
1757 start_java_method (tree fndecl
)
1764 current_function_decl
= fndecl
;
1765 announce_function (fndecl
);
1767 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1768 decl_map
= make_tree_vec (i
);
1769 base_decl_map
= make_tree_vec (i
);
1770 type_map
= XRESIZEVEC (tree
, type_map
, i
);
1772 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1773 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1775 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1776 pushlevel (1); /* Push parameters. */
1778 ptr
= &DECL_ARGUMENTS (fndecl
);
1779 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1780 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1782 tree parm_name
= NULL_TREE
, parm_decl
;
1783 tree parm_type
= TREE_VALUE (tem
);
1784 gcc_assert (i
< DECL_MAX_LOCALS (fndecl
));
1786 parm_decl
= build_decl (input_location
, PARM_DECL
, parm_name
, parm_type
);
1787 DECL_CONTEXT (parm_decl
) = fndecl
;
1788 if (targetm
.calls
.promote_prototypes (parm_type
)
1789 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1790 && INTEGRAL_TYPE_P (parm_type
))
1791 parm_type
= integer_type_node
;
1792 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1795 ptr
= &DECL_CHAIN (parm_decl
);
1797 /* Add parm_decl to the decl_map. */
1798 push_jvm_slot (i
, parm_decl
);
1800 /* The this parameter of methods is artificial. */
1801 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
&& i
== 0)
1802 DECL_ARTIFICIAL (parm_decl
) = 1;
1804 type_map
[i
] = TREE_TYPE (parm_decl
);
1805 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1808 type_map
[i
] = void_type_node
;
1812 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1814 while (i
< DECL_MAX_LOCALS(fndecl
))
1815 type_map
[i
++] = NULL_TREE
;
1817 build_result_decl (fndecl
);
1818 DECL_SOURCE_LOCATION (fndecl
) = input_location
;
1820 /* Push local variables. */
1823 function_binding_level
= current_binding_level
;
1827 end_java_method (void)
1829 tree fndecl
= current_function_decl
;
1831 /* pop out of function */
1834 /* pop out of its parameters */
1837 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1839 if (DECL_SAVED_TREE (fndecl
))
1841 tree fbody
, block_body
;
1842 /* Before we check initialization, attached all class initialization
1843 variable to the block_body */
1844 fbody
= DECL_SAVED_TREE (fndecl
);
1845 block_body
= BIND_EXPR_BODY (fbody
);
1846 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl
),
1847 attach_init_test_initialization_flags
, block_body
);
1850 finish_method (fndecl
);
1852 current_function_decl
= NULL_TREE
;
1853 base_decl_map
= NULL_TREE
;
1856 /* Prepare a method for expansion. */
1859 finish_method (tree fndecl
)
1861 tree
*tp
= &DECL_SAVED_TREE (fndecl
);
1863 /* Wrap body of synchronized methods in a monitorenter,
1864 plus monitorexit cleanup. */
1865 if (METHOD_SYNCHRONIZED (fndecl
))
1867 tree enter
, exit
, lock
;
1868 if (METHOD_STATIC (fndecl
))
1869 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1871 lock
= DECL_ARGUMENTS (fndecl
);
1872 BUILD_MONITOR_ENTER (enter
, lock
);
1873 BUILD_MONITOR_EXIT (exit
, lock
);
1874 *tp
= build2 (COMPOUND_EXPR
, void_type_node
, enter
,
1875 build2 (TRY_FINALLY_EXPR
, void_type_node
, *tp
, exit
));
1878 /* Convert function tree to GENERIC prior to inlining. */
1879 java_genericize (fndecl
);
1881 /* Store the end of the function, so that we get good line number
1882 info for the epilogue. */
1883 if (DECL_STRUCT_FUNCTION (fndecl
))
1884 set_cfun (DECL_STRUCT_FUNCTION (fndecl
));
1886 allocate_struct_function (fndecl
, false);
1887 cfun
->function_end_locus
= DECL_FUNCTION_LAST_LINE (fndecl
);
1889 /* Defer inlining and expansion to the cgraph optimizers. */
1890 cgraph_finalize_function (fndecl
, false);
1893 /* We pessimistically marked all methods and fields external until we
1894 knew what set of classes we were planning to compile. Now mark those
1895 associated with CLASS to be generated locally as not external. */
1898 java_mark_decl_local (tree decl
)
1900 DECL_EXTERNAL (decl
) = 0;
1902 #ifdef ENABLE_CHECKING
1903 /* Double check that we didn't pass the function to the callgraph early. */
1904 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1906 struct cgraph_node
*node
= cgraph_get_node (decl
);
1907 gcc_assert (!node
|| !node
->local
.finalized
);
1910 gcc_assert (!DECL_RTL_SET_P (decl
));
1913 /* Given appropriate target support, G++ will emit hidden aliases for native
1914 methods. Using this hidden name is required for proper operation of
1915 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1916 proper target support, then mark the method for aliasing. */
1919 java_mark_cni_decl_local (tree decl
)
1921 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1925 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
1926 DECL_LOCAL_CNI_METHOD_P (decl
) = 1;
1928 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1929 mangler. We might have already referenced this native method and
1930 therefore created its name, but even if we have it won't hurt.
1931 We'll just go via its externally visible name, rather than its
1932 hidden alias. However, we must force things so that the correct
1933 mangling is done. */
1935 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
1936 java_mangle_decl (decl
);
1937 if (DECL_RTL_SET_P (decl
))
1939 SET_DECL_RTL (decl
, 0);
1940 make_decl_rtl (decl
);
1944 /* Use the preceding two functions and mark all members of the class. */
1947 java_mark_class_local (tree klass
)
1951 for (t
= TYPE_FIELDS (klass
); t
; t
= DECL_CHAIN (t
))
1952 if (FIELD_STATIC (t
))
1954 if (DECL_EXTERNAL (t
))
1955 vec_safe_push (pending_static_fields
, t
);
1956 java_mark_decl_local (t
);
1959 for (t
= TYPE_METHODS (klass
); t
; t
= DECL_CHAIN (t
))
1960 if (!METHOD_ABSTRACT (t
))
1962 if (METHOD_NATIVE (t
) && !flag_jni
)
1963 java_mark_cni_decl_local (t
);
1965 java_mark_decl_local (t
);
1969 /* Add a statement to a compound_expr. */
1972 add_stmt_to_compound (tree existing
, tree type
, tree stmt
)
1978 tree expr
= build2 (COMPOUND_EXPR
, type
, existing
, stmt
);
1979 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (existing
)
1980 | TREE_SIDE_EFFECTS (stmt
);
1987 /* If this node is an expr, mark its input location. Called from
1991 set_input_location (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
1992 void *data ATTRIBUTE_UNUSED
)
1996 if (CAN_HAVE_LOCATION_P (t
))
1998 if (EXPR_HAS_LOCATION(t
))
1999 return t
; /* Don't walk any further into this expr. */
2001 SET_EXPR_LOCATION (t
, input_location
);
2004 return NULL_TREE
; /* Continue walking this expr. */
2007 /* Add a statement to the statement_list currently being constructed.
2008 If the statement_list is null, we don't create a singleton list.
2009 This is necessary because poplevel() assumes that adding a
2010 statement to a null statement_list returns the statement. */
2013 java_add_stmt (tree new_stmt
)
2015 tree stmts
= current_binding_level
->stmts
;
2016 tree_stmt_iterator i
;
2019 walk_tree (&new_stmt
, set_input_location
, NULL
, NULL
);
2022 return current_binding_level
->stmts
= new_stmt
;
2024 /* Force STMTS to be a statement_list. */
2025 if (TREE_CODE (stmts
) != STATEMENT_LIST
)
2027 tree t
= make_node (STATEMENT_LIST
);
2029 tsi_link_after (&i
, stmts
, TSI_CONTINUE_LINKING
);
2033 i
= tsi_last (stmts
);
2034 tsi_link_after (&i
, new_stmt
, TSI_CONTINUE_LINKING
);
2035 TREE_TYPE (stmts
) = void_type_node
;
2037 return current_binding_level
->stmts
= stmts
;
2040 /* Add a variable to the current scope. */
2043 java_add_local_var (tree decl
)
2045 tree
*vars
= ¤t_binding_level
->names
;
2047 DECL_CHAIN (decl
) = next
;
2049 DECL_CONTEXT (decl
) = current_function_decl
;
2050 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
2054 /* Return a pointer to the compound_expr currently being
2060 return ¤t_binding_level
->stmts
;
2063 /* Register an exception range as belonging to the current binding
2064 level. There may only be one: if there are more, we'll create more
2065 binding levels. However, each range can have multiple handlers,
2066 and these are expanded when we call expand_end_java_handler(). */
2069 register_exception_range (struct eh_range
*range
, int pc
, int end_pc
)
2071 gcc_assert (! current_binding_level
->exception_range
);
2072 current_binding_level
->exception_range
= range
;
2073 current_binding_level
->end_pc
= end_pc
;
2074 current_binding_level
->start_pc
= pc
;
2077 #include "gt-java-decl.h"