1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
4 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
30 #include "coretypes.h"
32 #include "diagnostic-core.h"
35 #include "java-tree.h"
37 #include "java-except.h"
40 #include "tree-inline.h"
43 #include "tree-iterator.h"
44 #include "langhooks.h"
47 #if defined (DEBUG_JAVA_BINDING_LEVELS)
48 extern void indent (void);
51 static tree
push_jvm_slot (int, tree
);
52 static tree
lookup_name_current_level (tree
);
53 static tree
push_promoted_type (const char *, tree
);
54 static struct binding_level
*make_binding_level (void);
55 static tree
create_primitive_vtable (const char *);
56 static tree
check_local_unnamed_variable (tree
, tree
, tree
);
57 static void parse_version (void);
60 /* The following ABI flags are used in the high-order bits of the version
61 ID field. The version ID number itself should never be larger than
62 0xfffff, so it should be safe to use top 12 bits for these flags. */
64 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
66 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
67 should be loaded by the bootstrap
70 /* If an ABI change is made within a GCC release series, rendering current
71 binaries incompatible with the old runtimes, this number must be set to
72 enforce the compatibility rules. */
73 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
75 /* The runtime may recognize a variety of BC ABIs (objects generated by
76 different version of gcj), but will probably always require strict
77 matching for the ordinary (C++) ABI. */
79 /* The version ID of the BC ABI that we generate. This must be kept in
80 sync with parse_version(), libgcj, and reality (if the BC format changes,
82 #define GCJ_CURRENT_BC_ABI_VERSION \
83 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
85 /* The ABI version number. */
88 /* Name of the Cloneable class. */
89 tree java_lang_cloneable_identifier_node
;
91 /* Name of the Serializable class. */
92 tree java_io_serializable_identifier_node
;
94 /* The DECL_MAP is a mapping from (index, type) to a decl node.
95 If index < max_locals, it is the index of a local variable.
96 if index >= max_locals, then index-max_locals is a stack slot.
97 The DECL_MAP mapping is represented as a TREE_VEC whose elements
98 are a list of decls (VAR_DECL or PARM_DECL) chained by
99 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
100 we search the chain for a decl with a matching TREE_TYPE. */
102 static GTY(()) tree decl_map
;
104 /* The base_decl_map is contains one variable of ptr_type: this is
105 used to contain every variable of reference type that is ever
106 stored in a local variable slot. */
108 static GTY(()) tree base_decl_map
;
110 /* An index used to make temporary identifiers unique. */
113 /* A list of local variables VAR_DECLs for this method that we have seen
114 debug information, but we have not reached their starting (byte) PC yet. */
116 static GTY(()) tree pending_local_decls
;
118 /* The decl for "_Jv_ResolvePoolEntry". */
119 tree soft_resolvepoolentry_node
;
121 /* The decl for the .constants field of an instance of Class. */
122 tree constants_field_decl_node
;
124 /* The decl for the .data field of an instance of Class. */
125 tree constants_data_field_decl_node
;
127 #if defined(DEBUG_JAVA_BINDING_LEVELS)
128 int binding_depth
= 0;
129 int is_class_level
= 0;
137 for (i
= 0; i
< binding_depth
*2; i
++)
140 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
142 /* True if decl is a named local variable, i.e. if it is an alias
143 that's used only for debugging purposes. */
146 debug_variable_p (tree decl
)
148 if (TREE_CODE (decl
) == PARM_DECL
)
151 if (LOCAL_SLOT_P (decl
))
158 push_jvm_slot (int index
, tree decl
)
160 DECL_CONTEXT (decl
) = current_function_decl
;
161 layout_decl (decl
, 0);
163 /* Now link the decl into the decl_map. */
164 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
166 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
167 DECL_LOCAL_START_PC (decl
) = 0;
168 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
169 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
171 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
172 TREE_VEC_ELT (decl_map
, index
) = decl
;
177 /* Find the best declaration based upon type. If 'decl' fits 'type' better
178 than 'best', return 'decl'. Otherwise return 'best'. */
181 check_local_unnamed_variable (tree best
, tree decl
, tree type
)
183 tree decl_type
= TREE_TYPE (decl
);
185 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl
));
187 /* Use the same decl for all integer types <= 32 bits. This is
188 necessary because sometimes a value is stored as (for example)
189 boolean but loaded as int. */
190 if (decl_type
== type
191 || (INTEGRAL_TYPE_P (decl_type
)
192 && INTEGRAL_TYPE_P (type
)
193 && TYPE_PRECISION (decl_type
) <= 32
194 && TYPE_PRECISION (type
) <= 32
195 && TYPE_PRECISION (decl_type
) >= TYPE_PRECISION (type
))
196 /* ptr_type_node is used for null pointers, which are
197 assignment compatible with everything. */
198 || (TREE_CODE (decl_type
) == POINTER_TYPE
199 && type
== ptr_type_node
)
200 /* Whenever anyone wants to use a slot that is initially
201 occupied by a PARM_DECL of pointer type they must get that
202 decl, even if they asked for a pointer to a different type.
203 However, if someone wants a scalar variable in a slot that
204 initially held a pointer arg -- or vice versa -- we create a
207 ???: As long as verification is correct, this will be a
208 compatible type. But maybe we should create a dummy variable
209 and replace all references to it with the DECL and a
212 || (TREE_CODE (decl_type
) == POINTER_TYPE
213 && TREE_CODE (decl
) == PARM_DECL
214 && TREE_CODE (type
) == POINTER_TYPE
))
216 if (best
== NULL_TREE
217 || (decl_type
== type
&& TREE_TYPE (best
) != type
))
225 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
226 that is valid at PC (or -1 if any pc).
227 If there is no existing matching decl, allocate one. */
230 find_local_variable (int index
, tree type
, int pc ATTRIBUTE_UNUSED
)
232 tree tmp
= TREE_VEC_ELT (decl_map
, index
);
233 tree decl
= NULL_TREE
;
235 /* Scan through every declaration that has been created in this
236 slot. We're only looking for variables that correspond to local
237 index declarations and PARM_DECLs, not named variables: such
238 local variables are used only for debugging information. */
239 while (tmp
!= NULL_TREE
)
241 if (! debug_variable_p (tmp
))
242 decl
= check_local_unnamed_variable (decl
, tmp
, type
);
243 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
246 /* gcj has a function called promote_type(), which is used by both
247 the bytecode compiler and the source compiler. Unfortunately,
248 the type systems for the Java VM and the Java language are not
249 the same: a boolean in the VM promotes to an int, not to a wide
250 boolean. If our caller wants something to hold a boolean, that
251 had better be an int, because that slot might be re-used
252 later in integer context. */
253 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
254 type
= integer_type_node
;
256 /* If we don't find a match, create one with the type passed in.
257 The name of the variable is #n#m, which n is the variable index
258 in the local variable area and m is a dummy identifier for
259 uniqueness -- multiple variables may share the same local
260 variable index. We don't call pushdecl() to push pointer types
261 into a binding expr because they'll all be replaced by a single
262 variable that is used for every reference in that local variable
268 sprintf (buf
, "#slot#%d#%d", index
, uniq
++);
269 name
= get_identifier (buf
);
270 decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
271 DECL_IGNORED_P (decl
) = 1;
272 DECL_ARTIFICIAL (decl
) = 1;
273 decl
= push_jvm_slot (index
, decl
);
274 LOCAL_SLOT_P (decl
) = 1;
276 if (TREE_CODE (type
) != POINTER_TYPE
)
277 pushdecl_function_level (decl
);
280 /* As well as creating a local variable that matches the type, we
281 also create a base variable (of ptr_type) that will hold all its
283 if (TREE_CODE (type
) == POINTER_TYPE
284 && ! TREE_VEC_ELT (base_decl_map
, index
))
289 sprintf (buf
, "#ref#%d#%d", index
, uniq
++);
290 name
= get_identifier (buf
);
292 = TREE_VEC_ELT (base_decl_map
, index
)
293 = build_decl (input_location
, VAR_DECL
, name
, ptr_type_node
);
294 pushdecl_function_level (base_decl
);
295 DECL_IGNORED_P (base_decl
) = 1;
296 DECL_ARTIFICIAL (base_decl
) = 1;
302 /* Called during genericization for every variable. If the variable
303 is a temporary of pointer type, replace it with a common variable
304 thath is used to hold all pointer types that are ever stored in
305 that slot. Set WANT_LVALUE if you want a variable that is to be
309 java_replace_reference (tree var_decl
, bool want_lvalue
)
316 decl_type
= TREE_TYPE (var_decl
);
318 if (TREE_CODE (decl_type
) == POINTER_TYPE
)
320 if (DECL_LANG_SPECIFIC (var_decl
)
321 && LOCAL_SLOT_P (var_decl
))
323 int index
= DECL_LOCAL_SLOT_NUMBER (var_decl
);
324 tree base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
326 gcc_assert (base_decl
);
328 base_decl
= build1 (NOP_EXPR
, decl_type
, base_decl
);
337 /* Helper for java_genericize. */
340 java_replace_references (tree
*tp
, int *walk_subtrees
,
341 void *data ATTRIBUTE_UNUSED
)
343 if (TREE_CODE (*tp
) == MODIFY_EXPR
)
345 source_location loc
= EXPR_LOCATION (*tp
);
346 tree lhs
= TREE_OPERAND (*tp
, 0);
347 /* This is specific to the bytecode compiler. If a variable has
348 LOCAL_SLOT_P set, replace an assignment to it with an assignment
349 to the corresponding variable that holds all its aliases. */
350 if (TREE_CODE (lhs
) == VAR_DECL
351 && DECL_LANG_SPECIFIC (lhs
)
352 && LOCAL_SLOT_P (lhs
)
353 && TREE_CODE (TREE_TYPE (lhs
)) == POINTER_TYPE
)
355 tree new_lhs
= java_replace_reference (lhs
, /* want_lvalue */ true);
356 tree new_rhs
= build1 (NOP_EXPR
, TREE_TYPE (new_lhs
),
357 TREE_OPERAND (*tp
, 1));
358 tree tem
= build2 (MODIFY_EXPR
, TREE_TYPE (new_lhs
),
360 *tp
= build1 (NOP_EXPR
, TREE_TYPE (lhs
), tem
);
361 SET_EXPR_LOCATION (tem
, loc
);
362 SET_EXPR_LOCATION (new_rhs
, loc
);
363 SET_EXPR_LOCATION (*tp
, loc
);
366 if (TREE_CODE (*tp
) == VAR_DECL
)
368 *tp
= java_replace_reference (*tp
, /* want_lvalue */ false);
375 /* Same as find_local_index, except that INDEX is a stack index. */
378 find_stack_slot (int index
, tree type
)
380 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
386 /* A chain of _DECL nodes for all variables, constants, functions,
387 * and typedef types. These are in the reverse of the order supplied.
391 /* For each level, a list of shadowed outer-level local definitions
392 to be restored when this level is popped.
393 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
394 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
397 /* For each level (except not the global one),
398 a chain of BLOCK nodes for all the levels
399 that were entered and exited one level down. */
402 /* The binding level which this one is contained in (inherits from). */
403 struct binding_level
*level_chain
;
405 /* The bytecode PC that marks the end of this level. */
407 /* The bytecode PC that marks the start of this level. */
410 /* The statements in this binding level. */
413 /* An exception range associated with this binding level. */
414 struct eh_range
* GTY((skip (""))) exception_range
;
416 /* Binding depth at which this level began. Used only for debugging. */
417 unsigned binding_depth
;
419 /* The location at which this level began. */
423 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
425 /* The binding level currently in effect. */
427 static GTY(()) struct binding_level
*current_binding_level
;
429 /* A chain of binding_level structures awaiting reuse. */
431 static GTY(()) struct binding_level
*free_binding_level
;
433 /* The outermost binding level, for names of file scope.
434 This is created when the compiler is started and exists
435 through the entire run. */
437 static GTY(()) struct binding_level
*global_binding_level
;
439 /* The binding level that holds variables declared at the outermost
440 level within a function body. */
442 static struct binding_level
*function_binding_level
;
444 /* A PC value bigger than any PC value we may ever may encounter. */
446 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
448 /* Binding level structures are initialized by copying this one. */
450 static const struct binding_level clear_binding_level
452 NULL_TREE
, /* names */
453 NULL_TREE
, /* shadowed */
454 NULL_TREE
, /* blocks */
455 NULL_BINDING_LEVEL
, /* level_chain */
456 LARGEST_PC
, /* end_pc */
459 NULL
, /* exception_range */
460 0, /* binding_depth */
464 tree java_global_trees
[JTI_MAX
];
466 /* Build (and pushdecl) a "promoted type" for all standard
467 types shorter than int. */
470 push_promoted_type (const char *name
, tree actual_type
)
472 tree type
= make_node (TREE_CODE (actual_type
));
474 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
475 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
477 tree in_min
= TYPE_MIN_VALUE (actual_type
);
478 tree in_max
= TYPE_MAX_VALUE (actual_type
);
480 TYPE_MIN_VALUE (type
) = copy_node (in_min
);
481 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
482 TYPE_MAX_VALUE (type
) = copy_node (in_max
);
483 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
484 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
485 TYPE_STRING_FLAG (type
) = TYPE_STRING_FLAG (actual_type
);
487 pushdecl (build_decl (input_location
,
488 TYPE_DECL
, get_identifier (name
), type
));
492 /* Return tree that represents a vtable for a primitive array. */
494 create_primitive_vtable (const char *name
)
499 sprintf (buf
, "_Jv_%sVTable", name
);
500 r
= build_decl (input_location
,
501 VAR_DECL
, get_identifier (buf
), ptr_type_node
);
502 DECL_EXTERNAL (r
) = 1;
506 /* Parse the version string and compute the ABI version number. */
510 const char *p
= version_string
;
511 unsigned int major
= 0, minor
= 0;
512 unsigned int abi_version
;
514 /* Skip leading junk. */
515 while (*p
&& !ISDIGIT (*p
))
519 /* Extract major version. */
522 major
= major
* 10 + *p
- '0';
526 gcc_assert (*p
== '.' && ISDIGIT (p
[1]));
529 /* Extract minor version. */
532 minor
= minor
* 10 + *p
- '0';
536 if (flag_indirect_dispatch
)
538 abi_version
= GCJ_CURRENT_BC_ABI_VERSION
;
539 abi_version
|= FLAG_BINARYCOMPAT_ABI
;
543 /* Implicit in this computation is the idea that we won't break the
544 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
546 abi_version
= 100000 * major
+ 1000 * minor
;
548 if (flag_bootstrap_classes
)
549 abi_version
|= FLAG_BOOTSTRAP_LOADER
;
551 gcj_abi_version
= build_int_cstu (ptr_type_node
, abi_version
);
555 java_init_decl_processing (void)
557 tree field
= NULL_TREE
;
560 init_class_processing ();
562 current_function_decl
= NULL
;
563 current_binding_level
= NULL_BINDING_LEVEL
;
564 free_binding_level
= NULL_BINDING_LEVEL
;
565 pushlevel (0); /* make the binding_level structure for global names */
566 global_binding_level
= current_binding_level
;
568 /* Build common tree nodes, Java has an unsigned char. */
569 build_common_tree_nodes (false, false);
571 /* ??? Now we continue and override some of the built types again
572 with Java specific types. As the above generated types are
573 supposed to match the targets C ABI this isn't really the way
574 to go and any Java specifics should _not_ use those global types
575 if the Java ABI does not match the C one. */
577 byte_type_node
= make_signed_type (8);
578 pushdecl (build_decl (BUILTINS_LOCATION
,
579 TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
580 short_type_node
= make_signed_type (16);
581 pushdecl (build_decl (BUILTINS_LOCATION
,
582 TYPE_DECL
, get_identifier ("short"), short_type_node
));
583 int_type_node
= make_signed_type (32);
584 pushdecl (build_decl (BUILTINS_LOCATION
,
585 TYPE_DECL
, get_identifier ("int"), int_type_node
));
586 long_type_node
= make_signed_type (64);
587 pushdecl (build_decl (BUILTINS_LOCATION
,
588 TYPE_DECL
, get_identifier ("long"), long_type_node
));
590 unsigned_byte_type_node
= make_unsigned_type (8);
591 pushdecl (build_decl (BUILTINS_LOCATION
,
592 TYPE_DECL
, get_identifier ("unsigned byte"),
593 unsigned_byte_type_node
));
594 unsigned_short_type_node
= make_unsigned_type (16);
595 pushdecl (build_decl (BUILTINS_LOCATION
,
596 TYPE_DECL
, get_identifier ("unsigned short"),
597 unsigned_short_type_node
));
598 unsigned_int_type_node
= make_unsigned_type (32);
599 pushdecl (build_decl (BUILTINS_LOCATION
,
600 TYPE_DECL
, get_identifier ("unsigned int"),
601 unsigned_int_type_node
));
602 unsigned_long_type_node
= make_unsigned_type (64);
603 pushdecl (build_decl (BUILTINS_LOCATION
,
604 TYPE_DECL
, get_identifier ("unsigned long"),
605 unsigned_long_type_node
));
607 /* Define these next since types below may used them. */
608 integer_type_node
= java_type_for_size (INT_TYPE_SIZE
, 0);
609 integer_zero_node
= build_int_cst (NULL_TREE
, 0);
610 integer_one_node
= build_int_cst (NULL_TREE
, 1);
611 integer_two_node
= build_int_cst (NULL_TREE
, 2);
612 integer_three_node
= build_int_cst (NULL_TREE
, 3);
613 integer_four_node
= build_int_cst (NULL_TREE
, 4);
614 integer_minus_one_node
= build_int_cst (NULL_TREE
, -1);
616 /* A few values used for range checking in the lexer. */
617 decimal_int_max
= build_int_cstu (unsigned_int_type_node
, 0x80000000);
619 = double_int_to_tree (unsigned_long_type_node
,
620 double_int_zero
.set_bit (64));
622 long_zero_node
= build_int_cst (long_type_node
, 0);
624 pushdecl (build_decl (BUILTINS_LOCATION
,
625 TYPE_DECL
, get_identifier ("void"), void_type_node
));
627 t
= make_node (VOID_TYPE
);
628 layout_type (t
); /* Uses size_zero_node */
629 return_address_type_node
= build_pointer_type (t
);
631 char_type_node
= make_unsigned_type (16);
632 TYPE_STRING_FLAG (char_type_node
) = 1;
633 pushdecl (build_decl (BUILTINS_LOCATION
,
634 TYPE_DECL
, get_identifier ("char"), char_type_node
));
636 boolean_type_node
= make_unsigned_type (1);
637 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
638 pushdecl (build_decl (BUILTINS_LOCATION
,
639 TYPE_DECL
, get_identifier ("boolean"),
641 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
642 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
644 promoted_byte_type_node
645 = push_promoted_type ("promoted_byte", byte_type_node
);
646 promoted_short_type_node
647 = push_promoted_type ("promoted_short", short_type_node
);
648 promoted_char_type_node
649 = push_promoted_type ("promoted_char", char_type_node
);
650 promoted_boolean_type_node
651 = push_promoted_type ("promoted_boolean", boolean_type_node
);
653 float_type_node
= make_node (REAL_TYPE
);
654 TYPE_PRECISION (float_type_node
) = 32;
655 pushdecl (build_decl (BUILTINS_LOCATION
,
656 TYPE_DECL
, get_identifier ("float"),
658 layout_type (float_type_node
);
660 double_type_node
= make_node (REAL_TYPE
);
661 TYPE_PRECISION (double_type_node
) = 64;
662 pushdecl (build_decl (BUILTINS_LOCATION
,
663 TYPE_DECL
, get_identifier ("double"),
665 layout_type (double_type_node
);
667 float_zero_node
= build_real (float_type_node
, dconst0
);
668 double_zero_node
= build_real (double_type_node
, dconst0
);
670 /* These are the vtables for arrays of primitives. */
671 boolean_array_vtable
= create_primitive_vtable ("boolean");
672 byte_array_vtable
= create_primitive_vtable ("byte");
673 char_array_vtable
= create_primitive_vtable ("char");
674 short_array_vtable
= create_primitive_vtable ("short");
675 int_array_vtable
= create_primitive_vtable ("int");
676 long_array_vtable
= create_primitive_vtable ("long");
677 float_array_vtable
= create_primitive_vtable ("float");
678 double_array_vtable
= create_primitive_vtable ("double");
680 one_elt_array_domain_type
= build_index_type (integer_one_node
);
681 utf8const_type
= make_node (RECORD_TYPE
);
682 PUSH_FIELD (input_location
,
683 utf8const_type
, field
, "hash", unsigned_short_type_node
);
684 PUSH_FIELD (input_location
,
685 utf8const_type
, field
, "length", unsigned_short_type_node
);
686 FINISH_RECORD (utf8const_type
);
687 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
689 atable_type
= build_array_type (ptr_type_node
,
690 one_elt_array_domain_type
);
691 TYPE_NONALIASED_COMPONENT (atable_type
) = 1;
692 atable_ptr_type
= build_pointer_type (atable_type
);
694 itable_type
= build_array_type (ptr_type_node
,
695 one_elt_array_domain_type
);
696 TYPE_NONALIASED_COMPONENT (itable_type
) = 1;
697 itable_ptr_type
= build_pointer_type (itable_type
);
699 symbol_type
= make_node (RECORD_TYPE
);
700 PUSH_FIELD (input_location
,
701 symbol_type
, field
, "clname", utf8const_ptr_type
);
702 PUSH_FIELD (input_location
, symbol_type
, field
, "name", utf8const_ptr_type
);
703 PUSH_FIELD (input_location
,
704 symbol_type
, field
, "signature", utf8const_ptr_type
);
705 FINISH_RECORD (symbol_type
);
707 symbols_array_type
= build_array_type (symbol_type
,
708 one_elt_array_domain_type
);
709 symbols_array_ptr_type
= build_pointer_type (symbols_array_type
);
711 assertion_entry_type
= make_node (RECORD_TYPE
);
712 PUSH_FIELD (input_location
,
713 assertion_entry_type
, field
, "assertion_code", integer_type_node
);
714 PUSH_FIELD (input_location
,
715 assertion_entry_type
, field
, "op1", utf8const_ptr_type
);
716 PUSH_FIELD (input_location
,
717 assertion_entry_type
, field
, "op2", utf8const_ptr_type
);
718 FINISH_RECORD (assertion_entry_type
);
720 assertion_table_type
= build_array_type (assertion_entry_type
,
721 one_elt_array_domain_type
);
723 /* As you're adding items here, please update the code right after
724 this section, so that the filename containing the source code of
725 the pre-defined class gets registered correctly. */
726 unqualified_object_id_node
= get_identifier ("Object");
727 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
728 object_ptr_type_node
= promote_type (object_type_node
);
729 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
730 string_ptr_type_node
= promote_type (string_type_node
);
731 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
732 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
733 exception_type_node
= lookup_class (get_identifier ("java.lang.Exception"));
734 runtime_exception_type_node
=
735 lookup_class (get_identifier ("java.lang.RuntimeException"));
736 error_exception_type_node
=
737 lookup_class (get_identifier ("java.lang.Error"));
739 rawdata_ptr_type_node
740 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
742 add_predefined_file (get_identifier ("java/lang/Class.java"));
743 add_predefined_file (get_identifier ("java/lang/Error.java"));
744 add_predefined_file (get_identifier ("java/lang/Object.java"));
745 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
746 add_predefined_file (get_identifier ("java/lang/String.java"));
747 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
748 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
749 add_predefined_file (get_identifier ("java/lang/Exception.java"));
750 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
751 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
753 methodtable_type
= make_node (RECORD_TYPE
);
754 layout_type (methodtable_type
);
755 build_decl (BUILTINS_LOCATION
,
756 TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
757 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
759 TYPE_identifier_node
= get_identifier ("TYPE");
760 init_identifier_node
= get_identifier ("<init>");
761 clinit_identifier_node
= get_identifier ("<clinit>");
762 void_signature_node
= get_identifier ("()V");
763 finalize_identifier_node
= get_identifier ("finalize");
764 this_identifier_node
= get_identifier ("this");
766 java_lang_cloneable_identifier_node
= get_identifier ("java.lang.Cloneable");
767 java_io_serializable_identifier_node
=
768 get_identifier ("java.io.Serializable");
770 /* for lack of a better place to put this stub call */
771 init_expr_processing();
773 constants_type_node
= make_node (RECORD_TYPE
);
774 PUSH_FIELD (input_location
,
775 constants_type_node
, field
, "size", unsigned_int_type_node
);
776 PUSH_FIELD (input_location
,
777 constants_type_node
, field
, "tags", ptr_type_node
);
778 PUSH_FIELD (input_location
,
779 constants_type_node
, field
, "data", ptr_type_node
);
780 constants_data_field_decl_node
= field
;
781 FINISH_RECORD (constants_type_node
);
782 build_decl (BUILTINS_LOCATION
,
783 TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
785 access_flags_type_node
= unsigned_short_type_node
;
787 dtable_type
= make_node (RECORD_TYPE
);
788 dtable_ptr_type
= build_pointer_type (dtable_type
);
790 otable_type
= build_array_type (integer_type_node
,
791 one_elt_array_domain_type
);
792 TYPE_NONALIASED_COMPONENT (otable_type
) = 1;
793 otable_ptr_type
= build_pointer_type (otable_type
);
795 PUSH_FIELD (input_location
,
796 object_type_node
, field
, "vtable", dtable_ptr_type
);
797 DECL_FCONTEXT (field
) = object_type_node
;
798 TYPE_VFIELD (object_type_node
) = field
;
800 /* This isn't exactly true, but it is what we have in the source.
801 There is an unresolved issue here, which is whether the vtable
802 should be marked by the GC. */
803 if (! flag_hash_synchronization
)
804 PUSH_FIELD (input_location
, object_type_node
, field
, "sync_info",
805 build_pointer_type (object_type_node
));
806 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
807 FIELD_PRIVATE (t
) = 1;
808 FINISH_RECORD (object_type_node
);
810 field_type_node
= make_node (RECORD_TYPE
);
811 field_ptr_type_node
= build_pointer_type (field_type_node
);
812 method_type_node
= make_node (RECORD_TYPE
);
813 method_ptr_type_node
= build_pointer_type (method_type_node
);
815 set_super_info (0, class_type_node
, object_type_node
, 0);
816 set_super_info (0, string_type_node
, object_type_node
, 0);
817 class_ptr_type
= build_pointer_type (class_type_node
);
819 PUSH_FIELD (input_location
,
820 class_type_node
, field
, "next_or_version", class_ptr_type
);
821 PUSH_FIELD (input_location
,
822 class_type_node
, field
, "name", utf8const_ptr_type
);
823 PUSH_FIELD (input_location
,
824 class_type_node
, field
, "accflags", access_flags_type_node
);
825 PUSH_FIELD (input_location
,
826 class_type_node
, field
, "superclass", class_ptr_type
);
827 PUSH_FIELD (input_location
,
828 class_type_node
, field
, "constants", constants_type_node
);
829 constants_field_decl_node
= field
;
830 PUSH_FIELD (input_location
,
831 class_type_node
, field
, "methods", method_ptr_type_node
);
832 PUSH_FIELD (input_location
,
833 class_type_node
, field
, "method_count", short_type_node
);
834 PUSH_FIELD (input_location
,
835 class_type_node
, field
, "vtable_method_count", short_type_node
);
836 PUSH_FIELD (input_location
,
837 class_type_node
, field
, "fields", field_ptr_type_node
);
838 PUSH_FIELD (input_location
,
839 class_type_node
, field
, "size_in_bytes", int_type_node
);
840 PUSH_FIELD (input_location
,
841 class_type_node
, field
, "field_count", short_type_node
);
842 PUSH_FIELD (input_location
,
843 class_type_node
, field
, "static_field_count", short_type_node
);
844 PUSH_FIELD (input_location
,
845 class_type_node
, field
, "vtable", dtable_ptr_type
);
846 PUSH_FIELD (input_location
,
847 class_type_node
, field
, "otable", otable_ptr_type
);
848 PUSH_FIELD (input_location
,
849 class_type_node
, field
, "otable_syms",
850 symbols_array_ptr_type
);
851 PUSH_FIELD (input_location
,
852 class_type_node
, field
, "atable", atable_ptr_type
);
853 PUSH_FIELD (input_location
,
854 class_type_node
, field
, "atable_syms",
855 symbols_array_ptr_type
);
856 PUSH_FIELD (input_location
,
857 class_type_node
, field
, "itable", itable_ptr_type
);
858 PUSH_FIELD (input_location
, class_type_node
, field
, "itable_syms",
859 symbols_array_ptr_type
);
860 PUSH_FIELD (input_location
,
861 class_type_node
, field
, "catch_classes", ptr_type_node
);
862 PUSH_FIELD (input_location
, class_type_node
, field
, "interfaces",
863 build_pointer_type (class_ptr_type
));
864 PUSH_FIELD (input_location
, class_type_node
, field
, "loader", ptr_type_node
);
865 PUSH_FIELD (input_location
,
866 class_type_node
, field
, "interface_count", short_type_node
);
867 PUSH_FIELD (input_location
, class_type_node
, field
, "state", byte_type_node
);
868 PUSH_FIELD (input_location
, class_type_node
, field
, "thread", ptr_type_node
);
869 PUSH_FIELD (input_location
,
870 class_type_node
, field
, "depth", short_type_node
);
871 PUSH_FIELD (input_location
,
872 class_type_node
, field
, "ancestors", ptr_type_node
);
873 PUSH_FIELD (input_location
, class_type_node
, field
, "idt", ptr_type_node
);
874 PUSH_FIELD (input_location
,
875 class_type_node
, field
, "arrayclass", ptr_type_node
);
876 PUSH_FIELD (input_location
,
877 class_type_node
, field
, "protectionDomain", ptr_type_node
);
878 PUSH_FIELD (input_location
,
879 class_type_node
, field
, "assertion_table", ptr_type_node
);
880 PUSH_FIELD (input_location
,
881 class_type_node
, field
, "hack_signers", ptr_type_node
);
882 PUSH_FIELD (input_location
, class_type_node
, field
, "chain", ptr_type_node
);
883 PUSH_FIELD (input_location
,
884 class_type_node
, field
, "aux_info", ptr_type_node
);
885 PUSH_FIELD (input_location
, class_type_node
, field
, "engine", ptr_type_node
);
886 PUSH_FIELD (input_location
,
887 class_type_node
, field
, "reflection_data", ptr_type_node
);
888 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
889 FIELD_PRIVATE (t
) = 1;
890 push_super_field (class_type_node
, object_type_node
);
892 FINISH_RECORD (class_type_node
);
893 build_decl (BUILTINS_LOCATION
,
894 TYPE_DECL
, get_identifier ("Class"), class_type_node
);
896 field_info_union_node
= make_node (UNION_TYPE
);
897 PUSH_FIELD (input_location
,
898 field_info_union_node
, field
, "boffset", int_type_node
);
899 PUSH_FIELD (input_location
,
900 field_info_union_node
, field
, "addr", ptr_type_node
);
901 layout_type (field_info_union_node
);
903 PUSH_FIELD (input_location
,
904 field_type_node
, field
, "name", utf8const_ptr_type
);
905 PUSH_FIELD (input_location
, field_type_node
, field
, "type", class_ptr_type
);
906 PUSH_FIELD (input_location
,
907 field_type_node
, field
, "accflags", access_flags_type_node
);
908 PUSH_FIELD (input_location
,
909 field_type_node
, field
, "bsize", unsigned_short_type_node
);
910 PUSH_FIELD (input_location
,
911 field_type_node
, field
, "info", field_info_union_node
);
912 FINISH_RECORD (field_type_node
);
913 build_decl (BUILTINS_LOCATION
,
914 TYPE_DECL
, get_identifier ("Field"), field_type_node
);
916 nativecode_ptr_array_type_node
917 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
919 PUSH_FIELD (input_location
,
920 dtable_type
, field
, "class", class_ptr_type
);
921 PUSH_FIELD (input_location
,
922 dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
923 FINISH_RECORD (dtable_type
);
924 build_decl (BUILTINS_LOCATION
,
925 TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
927 jexception_type
= make_node (RECORD_TYPE
);
928 PUSH_FIELD (input_location
,
929 jexception_type
, field
, "start_pc", ptr_type_node
);
930 PUSH_FIELD (input_location
, jexception_type
, field
, "end_pc", ptr_type_node
);
931 PUSH_FIELD (input_location
,
932 jexception_type
, field
, "handler_pc", ptr_type_node
);
933 PUSH_FIELD (input_location
,
934 jexception_type
, field
, "catch_type", class_ptr_type
);
935 FINISH_RECORD (jexception_type
);
936 build_decl (BUILTINS_LOCATION
,
937 TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
938 jexception_ptr_type
= build_pointer_type (jexception_type
);
940 lineNumberEntry_type
= make_node (RECORD_TYPE
);
941 PUSH_FIELD (input_location
,
942 lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
943 PUSH_FIELD (input_location
,
944 lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
945 FINISH_RECORD (lineNumberEntry_type
);
947 lineNumbers_type
= make_node (RECORD_TYPE
);
948 PUSH_FIELD (input_location
,
949 lineNumbers_type
, field
, "length", unsigned_int_type_node
);
950 FINISH_RECORD (lineNumbers_type
);
952 PUSH_FIELD (input_location
,
953 method_type_node
, field
, "name", utf8const_ptr_type
);
954 PUSH_FIELD (input_location
,
955 method_type_node
, field
, "signature", utf8const_ptr_type
);
956 PUSH_FIELD (input_location
,
957 method_type_node
, field
, "accflags", access_flags_type_node
);
958 PUSH_FIELD (input_location
,
959 method_type_node
, field
, "index", unsigned_short_type_node
);
960 PUSH_FIELD (input_location
,
961 method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
962 PUSH_FIELD (input_location
,
963 method_type_node
, field
, "throws", ptr_type_node
);
964 FINISH_RECORD (method_type_node
);
965 build_decl (BUILTINS_LOCATION
,
966 TYPE_DECL
, get_identifier ("Method"), method_type_node
);
968 end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
970 t
= build_function_type_list (ptr_type_node
, class_ptr_type
, NULL_TREE
);
971 alloc_object_node
= add_builtin_function ("_Jv_AllocObject", t
,
972 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
973 DECL_IS_MALLOC (alloc_object_node
) = 1;
974 alloc_no_finalizer_node
=
975 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t
,
976 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
977 DECL_IS_MALLOC (alloc_no_finalizer_node
) = 1;
979 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
980 soft_initclass_node
= add_builtin_function ("_Jv_InitClass", t
,
981 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
982 t
= build_function_type_list (ptr_type_node
,
983 class_ptr_type
, int_type_node
, NULL_TREE
);
984 soft_resolvepoolentry_node
985 = add_builtin_function ("_Jv_ResolvePoolEntry", t
,
986 0,NOT_BUILT_IN
, NULL
, NULL_TREE
);
987 DECL_PURE_P (soft_resolvepoolentry_node
) = 1;
988 t
= build_function_type_list (void_type_node
,
989 class_ptr_type
, int_type_node
, NULL_TREE
);
990 throw_node
= add_builtin_function ("_Jv_Throw", t
,
991 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
992 /* Mark throw_nodes as `noreturn' functions with side effects. */
993 TREE_THIS_VOLATILE (throw_node
) = 1;
994 TREE_SIDE_EFFECTS (throw_node
) = 1;
996 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
997 soft_monitorenter_node
998 = add_builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
1000 soft_monitorexit_node
1001 = add_builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
1004 t
= build_function_type_list (ptr_type_node
,
1005 ptr_type_node
, int_type_node
, NULL_TREE
);
1007 = add_builtin_function ("_Jv_NewPrimArray", t
,
1008 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1009 DECL_IS_MALLOC (soft_newarray_node
) = 1;
1011 t
= build_function_type_list (ptr_type_node
,
1012 int_type_node
, class_ptr_type
,
1013 object_ptr_type_node
, NULL_TREE
);
1015 = add_builtin_function ("_Jv_NewObjectArray", t
,
1016 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1017 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
1019 t
= build_varargs_function_type_list (ptr_type_node
,
1020 ptr_type_node
, int_type_node
,
1022 soft_multianewarray_node
1023 = add_builtin_function ("_Jv_NewMultiArray", t
,
1024 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1025 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
1027 t
= build_function_type_list (void_type_node
, int_type_node
, NULL_TREE
);
1028 soft_badarrayindex_node
1029 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t
,
1030 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1031 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1033 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
1034 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
1036 t
= build_function_type_list (void_type_node
, NULL_TREE
);
1037 soft_nullpointer_node
1038 = add_builtin_function ("_Jv_ThrowNullPointerException", t
,
1039 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1040 /* Mark soft_nullpointer_node as a `noreturn' function with side
1042 TREE_THIS_VOLATILE (soft_nullpointer_node
) = 1;
1043 TREE_SIDE_EFFECTS (soft_nullpointer_node
) = 1;
1045 soft_abstractmethod_node
1046 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t
,
1047 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1048 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1050 TREE_THIS_VOLATILE (soft_abstractmethod_node
) = 1;
1051 TREE_SIDE_EFFECTS (soft_abstractmethod_node
) = 1;
1053 soft_nosuchfield_node
1054 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t
,
1055 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1056 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1058 TREE_THIS_VOLATILE (soft_nosuchfield_node
) = 1;
1059 TREE_SIDE_EFFECTS (soft_nosuchfield_node
) = 1;
1061 t
= build_function_type_list (ptr_type_node
,
1062 class_ptr_type
, object_ptr_type_node
,
1065 = add_builtin_function ("_Jv_CheckCast", t
,
1066 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1067 t
= build_function_type_list (boolean_type_node
,
1068 object_ptr_type_node
, class_ptr_type
,
1070 soft_instanceof_node
1071 = add_builtin_function ("_Jv_IsInstanceOf", t
,
1072 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1073 DECL_PURE_P (soft_instanceof_node
) = 1;
1074 t
= build_function_type_list (void_type_node
,
1075 object_ptr_type_node
, object_ptr_type_node
,
1077 soft_checkarraystore_node
1078 = add_builtin_function ("_Jv_CheckArrayStore", t
,
1079 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1080 t
= build_function_type_list (ptr_type_node
,
1081 ptr_type_node
, ptr_type_node
, int_type_node
,
1083 soft_lookupinterfacemethod_node
1084 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t
,
1085 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1086 DECL_PURE_P (soft_lookupinterfacemethod_node
) = 1;
1088 t
= build_function_type_list (ptr_type_node
,
1089 ptr_type_node
, ptr_type_node
, ptr_type_node
,
1091 soft_lookupinterfacemethodbyname_node
1092 = add_builtin_function ("_Jv_LookupInterfaceMethod", t
,
1093 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1094 t
= build_function_type_list (ptr_type_node
,
1095 object_ptr_type_node
, ptr_type_node
,
1096 ptr_type_node
, int_type_node
, NULL_TREE
);
1097 soft_lookupjnimethod_node
1098 = add_builtin_function ("_Jv_LookupJNIMethod", t
,
1099 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1100 t
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
1101 soft_getjnienvnewframe_node
1102 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t
,
1103 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1104 t
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
1105 soft_jnipopsystemframe_node
1106 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t
,
1107 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1109 t
= build_function_type_list (object_ptr_type_node
,
1110 object_ptr_type_node
, NULL_TREE
);
1112 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t
,
1113 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1115 t
= build_function_type_list (int_type_node
,
1116 int_type_node
, int_type_node
, NULL_TREE
);
1118 = add_builtin_function ("_Jv_divI", t
,
1119 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1122 = add_builtin_function ("_Jv_remI", t
,
1123 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1125 t
= build_function_type_list (long_type_node
,
1126 long_type_node
, long_type_node
, NULL_TREE
);
1128 = add_builtin_function ("_Jv_divJ", t
,
1129 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1132 = add_builtin_function ("_Jv_remJ", t
,
1133 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
1135 initialize_builtins ();
1137 soft_fmod_node
= builtin_decl_explicit (BUILT_IN_FMOD
);
1143 /* Look up NAME in the current binding level and its superiors
1144 in the namespace of variables, functions and typedefs.
1145 Return a ..._DECL node of some kind representing its definition,
1146 or return 0 if it is undefined. */
1149 lookup_name (tree name
)
1152 if (current_binding_level
!= global_binding_level
1153 && IDENTIFIER_LOCAL_VALUE (name
))
1154 val
= IDENTIFIER_LOCAL_VALUE (name
);
1156 val
= IDENTIFIER_GLOBAL_VALUE (name
);
1160 /* Similar to `lookup_name' but look only at current binding level and
1161 the previous one if it's the parameter level. */
1164 lookup_name_current_level (tree name
)
1168 if (current_binding_level
== global_binding_level
)
1169 return IDENTIFIER_GLOBAL_VALUE (name
);
1171 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
1174 for (t
= current_binding_level
->names
; t
; t
= DECL_CHAIN (t
))
1175 if (DECL_NAME (t
) == name
)
1181 /* Record a decl-node X as belonging to the current lexical scope.
1182 Check for errors (such as an incompatible declaration for the same
1183 name already seen in the same scope).
1185 Returns either X or an old decl for the same name.
1186 If an old decl is returned, it may have been smashed
1187 to agree with what X says. */
1193 tree name
= DECL_NAME (x
);
1194 struct binding_level
*b
= current_binding_level
;
1196 if (TREE_CODE (x
) != TYPE_DECL
)
1197 DECL_CONTEXT (x
) = current_function_decl
;
1200 t
= lookup_name_current_level (name
);
1201 if (t
!= 0 && t
== error_mark_node
)
1202 /* error_mark_node is 0 for a while during initialization! */
1205 error ("%q+D used prior to declaration", x
);
1208 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1209 to point to the TYPE_DECL.
1210 Since Java does not have typedefs, a type can only have
1211 one (true) name, given by a class, interface, or builtin. */
1212 if (TREE_CODE (x
) == TYPE_DECL
1213 && TYPE_NAME (TREE_TYPE (x
)) == 0
1214 && TREE_TYPE (x
) != error_mark_node
)
1216 TYPE_NAME (TREE_TYPE (x
)) = x
;
1217 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1220 /* This name is new in its binding level.
1221 Install the new declaration and return it. */
1222 if (b
== global_binding_level
)
1224 /* Install a global value. */
1226 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1230 /* Here to install a non-global value. */
1231 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1232 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1234 /* If storing a local value, there may already be one (inherited).
1235 If so, record it for restoration when this binding level ends. */
1237 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1241 /* Put decls on list in reverse order.
1242 We will reverse them later if necessary. */
1243 DECL_CHAIN (x
) = b
->names
;
1250 pushdecl_force_head (tree x
)
1252 current_binding_level
->names
= x
;
1255 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1258 pushdecl_top_level (tree x
)
1261 struct binding_level
*b
= current_binding_level
;
1263 current_binding_level
= global_binding_level
;
1265 current_binding_level
= b
;
1269 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1272 pushdecl_function_level (tree x
)
1275 struct binding_level
*b
= current_binding_level
;
1277 current_binding_level
= function_binding_level
;
1279 current_binding_level
= b
;
1283 /* Return true if we are in the global binding level. */
1286 global_bindings_p (void)
1288 return current_binding_level
== global_binding_level
;
1291 /* Return the list of declarations of the current level.
1292 Note that this list is in reverse order unless/until
1293 you nreverse it; and when you do nreverse it, you must
1294 store the result back using `storedecls' or you will lose. */
1299 return current_binding_level
->names
;
1302 /* Create a new `struct binding_level'. */
1304 static struct binding_level
*
1305 make_binding_level (void)
1308 return ggc_alloc_cleared_binding_level ();
1312 pushlevel (int unused ATTRIBUTE_UNUSED
)
1314 struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1316 /* Reuse or create a struct for this binding level. */
1318 if (free_binding_level
)
1320 newlevel
= free_binding_level
;
1321 free_binding_level
= free_binding_level
->level_chain
;
1325 newlevel
= make_binding_level ();
1328 /* Add this level to the front of the chain (stack) of levels that
1331 *newlevel
= clear_binding_level
;
1332 newlevel
->level_chain
= current_binding_level
;
1333 newlevel
->loc
= input_location
;
1334 current_binding_level
= newlevel
;
1335 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1336 newlevel
->binding_depth
= binding_depth
;
1338 fprintf (stderr
, "push %s level %p pc %d\n",
1339 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1342 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1345 /* Exit a binding level.
1346 Pop the level off, and restore the state of the identifier-decl mappings
1347 that were in effect when this level was entered.
1349 If KEEP is nonzero, this level had explicit declarations, so
1350 and create a "block" (a BLOCK node) for the level
1351 to record its declarations and subblocks for symbol table output.
1353 If FUNCTIONBODY is nonzero, this level is the body of a function,
1354 so create a block as if KEEP were set and also clear out all
1357 If REVERSE is nonzero, reverse the order of decls before putting
1358 them into the BLOCK. */
1361 poplevel (int keep
, int reverse
, int functionbody
)
1364 /* The chain of decls was accumulated in reverse order.
1365 Put it into forward order, just for cleanliness. */
1367 tree subblocks
= current_binding_level
->blocks
;
1372 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1375 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1376 fprintf (stderr
, "pop %s level %p pc %d (end pc %d)\n",
1377 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1378 current_binding_level
->end_pc
);
1380 fprintf (stderr
, "pop %s level %p pc %d\n",
1381 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1382 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1384 /* Get the decls in the order they were written.
1385 Usually current_binding_level->names is in reverse order.
1386 But parameter decls were previously put in forward order. */
1389 current_binding_level
->names
1390 = decls
= nreverse (current_binding_level
->names
);
1392 decls
= current_binding_level
->names
;
1394 for (decl
= decls
; decl
; decl
= DECL_CHAIN (decl
))
1395 if (TREE_CODE (decl
) == VAR_DECL
1396 && DECL_LANG_SPECIFIC (decl
) != NULL
1397 && DECL_LOCAL_SLOT_NUMBER (decl
))
1398 LOCAL_VAR_OUT_OF_SCOPE_P (decl
) = 1;
1400 /* If there were any declarations in that level,
1401 or if this level is a function body,
1402 create a BLOCK to record them for the life of this function. */
1405 if (keep
|| functionbody
)
1406 block
= make_node (BLOCK
);
1408 if (current_binding_level
->exception_range
)
1409 expand_end_java_handler (current_binding_level
->exception_range
);
1413 /* If any statements have been generated at this level, create a
1414 BIND_EXPR to hold them and copy the variables to it. This
1415 only applies to the bytecode compiler. */
1416 if (current_binding_level
->stmts
)
1419 tree
*var
= &BLOCK_VARS (block
);
1421 /* Copy decls from names list, ignoring labels. */
1424 tree next
= DECL_CHAIN (decl
);
1425 if (TREE_CODE (decl
) != LABEL_DECL
)
1428 var
= &DECL_CHAIN (decl
);
1434 bind
= build3 (BIND_EXPR
, void_type_node
, BLOCK_VARS (block
),
1435 BLOCK_EXPR_BODY (block
), block
);
1436 BIND_EXPR_BODY (bind
) = current_binding_level
->stmts
;
1438 if (BIND_EXPR_BODY (bind
)
1439 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind
)))
1440 TREE_SIDE_EFFECTS (bind
) = 1;
1442 /* FIXME: gimplifier brain damage. */
1443 if (BIND_EXPR_BODY (bind
) == NULL
)
1444 BIND_EXPR_BODY (bind
) = build_java_empty_stmt ();
1446 SET_EXPR_LOCATION (bind
, current_binding_level
->loc
);
1448 current_binding_level
->stmts
= NULL
;
1452 BLOCK_VARS (block
) = decls
;
1454 BLOCK_SUBBLOCKS (block
) = subblocks
;
1457 /* In each subblock, record that this is its superior. */
1459 for (link
= subblocks
; link
; link
= BLOCK_CHAIN (link
))
1460 BLOCK_SUPERCONTEXT (link
) = block
;
1462 /* Clear out the meanings of the local variables of this level. */
1464 for (link
= decls
; link
; link
= DECL_CHAIN (link
))
1466 tree name
= DECL_NAME (link
);
1467 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1469 /* If the ident. was used or addressed via a local extern decl,
1470 don't forget that fact. */
1471 if (DECL_EXTERNAL (link
))
1473 if (TREE_USED (link
))
1474 TREE_USED (name
) = 1;
1475 if (TREE_ADDRESSABLE (link
))
1476 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1478 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1482 /* Restore all name-meanings of the outer levels
1483 that were shadowed by this level. */
1485 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1486 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1488 /* If the level being exited is the top level of a function,
1489 check over all the labels, and clear out the current
1490 (function local) meanings of their names. */
1494 /* If this is the top level block of a function,
1495 the vars are the function's parameters.
1496 Don't leave them in the BLOCK because they are
1497 found in the FUNCTION_DECL instead. */
1499 BLOCK_VARS (block
) = 0;
1502 /* Pop the current level, and free the structure for reuse. */
1505 struct binding_level
*level
= current_binding_level
;
1506 current_binding_level
= current_binding_level
->level_chain
;
1508 level
->level_chain
= free_binding_level
;
1509 free_binding_level
= level
;
1512 /* Dispose of the block that we just made inside some higher level. */
1515 DECL_INITIAL (current_function_decl
) = block
;
1516 DECL_SAVED_TREE (current_function_decl
) = bind
;
1522 current_binding_level
->blocks
1523 = block_chainon (current_binding_level
->blocks
, block
);
1525 /* If we did not make a block for the level just exited,
1526 any blocks made for inner levels
1527 (since they cannot be recorded as subblocks in that level)
1528 must be carried forward so they will later become subblocks
1529 of something else. */
1531 current_binding_level
->blocks
1532 = block_chainon (current_binding_level
->blocks
, subblocks
);
1535 java_add_stmt (bind
);
1539 TREE_USED (block
) = 1;
1544 maybe_pushlevels (int pc
)
1546 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1550 while (pending_local_decls
!= NULL_TREE
&&
1551 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1553 tree
*ptr
= &pending_local_decls
;
1554 tree decl
= *ptr
, next
;
1555 int end_pc
= DECL_LOCAL_END_PC (decl
);
1557 while (*ptr
!= NULL_TREE
1558 && DECL_LOCAL_START_PC (*ptr
) <= pc
1559 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1560 ptr
= &DECL_CHAIN (*ptr
);
1561 pending_local_decls
= *ptr
;
1564 /* Force non-nested range to be nested in current range by
1565 truncating variable lifetimes. */
1566 if (end_pc
> current_binding_level
->end_pc
)
1569 end_pc
= current_binding_level
->end_pc
;
1570 for (t
= decl
; t
!= NULL_TREE
; t
= DECL_CHAIN (t
))
1571 DECL_LOCAL_END_PC (t
) = end_pc
;
1574 maybe_start_try (pc
, end_pc
);
1578 current_binding_level
->end_pc
= end_pc
;
1579 current_binding_level
->start_pc
= pc
;
1580 current_binding_level
->names
= NULL
;
1581 for ( ; decl
!= NULL_TREE
; decl
= next
)
1583 int index
= DECL_LOCAL_SLOT_NUMBER (decl
);
1585 next
= DECL_CHAIN (decl
);
1586 push_jvm_slot (index
, decl
);
1589 = find_local_variable (index
, TREE_TYPE (decl
), pc
);
1590 if (TREE_CODE (TREE_TYPE (base_decl
)) == POINTER_TYPE
)
1591 base_decl
= TREE_VEC_ELT (base_decl_map
, index
);
1592 SET_DECL_VALUE_EXPR (decl
, base_decl
);
1593 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1597 maybe_start_try (pc
, 0);
1601 maybe_poplevels (int pc
)
1603 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1607 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1608 inclusive, so a variable is live if pc == end_pc. Here, we
1609 terminate a range if the current pc is equal to the end of the
1610 range, and this is *before* we have generated code for the
1611 instruction at end_pc. We're closing a binding level one
1612 instruction too early.*/
1613 while (current_binding_level
->end_pc
<= pc
)
1617 /* Terminate any binding which began during the range beginning at
1618 start_pc. This tidies up improperly nested local variable ranges
1619 and exception handlers; a variable declared within an exception
1620 range is forcibly terminated when that exception ends. */
1623 force_poplevels (int start_pc
)
1625 while (current_binding_level
->start_pc
> start_pc
)
1627 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1628 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1629 current_function_decl
,
1630 current_binding_level
->start_pc
);
1635 /* integrate_decl_tree calls this function. */
1638 java_dup_lang_specific_decl (tree node
)
1641 struct lang_decl
*x
;
1643 if (!DECL_LANG_SPECIFIC (node
))
1646 lang_decl_size
= sizeof (struct lang_decl
);
1647 x
= ggc_alloc_lang_decl (lang_decl_size
);
1648 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1649 DECL_LANG_SPECIFIC (node
) = x
;
1653 give_name_to_locals (JCF
*jcf
)
1655 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1656 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1658 pending_local_decls
= NULL_TREE
;
1662 n
= JCF_readu2 (jcf
);
1663 for (i
= 0; i
< n
; i
++)
1665 int start_pc
= JCF_readu2 (jcf
);
1666 int length
= JCF_readu2 (jcf
);
1667 int name_index
= JCF_readu2 (jcf
);
1668 int signature_index
= JCF_readu2 (jcf
);
1669 int slot
= JCF_readu2 (jcf
);
1670 tree name
= get_name_constant (jcf
, name_index
);
1671 tree type
= parse_signature (jcf
, signature_index
);
1672 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1674 && length
== DECL_CODE_LENGTH (current_function_decl
))
1676 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1677 DECL_NAME (decl
) = name
;
1678 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1679 warning (0, "bad type in parameter debug info");
1684 int end_pc
= start_pc
+ length
;
1685 tree decl
= build_decl (input_location
, VAR_DECL
, name
, type
);
1686 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1688 warning (0, "bad PC range for debug info for local %q+D",
1690 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1693 /* Adjust start_pc if necessary so that the local's first
1694 store operation will use the relevant DECL as a
1695 destination. Fore more information, read the leading
1696 comments for expr.c:maybe_adjust_start_pc. */
1697 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1699 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1700 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1701 DECL_LOCAL_START_PC (decl
) = start_pc
;
1702 DECL_LOCAL_END_PC (decl
) = end_pc
;
1704 /* Now insert the new decl in the proper place in
1705 pending_local_decls. We are essentially doing an insertion sort,
1706 which works fine, since the list input will normally already
1708 ptr
= &pending_local_decls
;
1709 while (*ptr
!= NULL_TREE
1710 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1711 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1712 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1713 ptr
= &DECL_CHAIN (*ptr
);
1714 DECL_CHAIN (decl
) = *ptr
;
1719 pending_local_decls
= nreverse (pending_local_decls
);
1721 /* Fill in default names for the parameters. */
1722 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1723 parm
!= NULL_TREE
; parm
= DECL_CHAIN (parm
), i
++)
1725 if (DECL_NAME (parm
) == NULL_TREE
)
1727 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1729 DECL_NAME (parm
) = get_identifier ("this");
1733 sprintf (buffer
, "ARG_%d", arg_i
);
1734 DECL_NAME (parm
) = get_identifier (buffer
);
1741 build_result_decl (tree fndecl
)
1743 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1744 tree result
= DECL_RESULT (fndecl
);
1747 result
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
1748 RESULT_DECL
, NULL_TREE
, restype
);
1749 DECL_ARTIFICIAL (result
) = 1;
1750 DECL_IGNORED_P (result
) = 1;
1751 DECL_CONTEXT (result
) = fndecl
;
1752 DECL_RESULT (fndecl
) = result
;
1758 start_java_method (tree fndecl
)
1765 current_function_decl
= fndecl
;
1766 announce_function (fndecl
);
1768 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1769 decl_map
= make_tree_vec (i
);
1770 base_decl_map
= make_tree_vec (i
);
1771 type_map
= XRESIZEVEC (tree
, type_map
, i
);
1773 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1774 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1776 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1777 pushlevel (1); /* Push parameters. */
1779 ptr
= &DECL_ARGUMENTS (fndecl
);
1780 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1781 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1783 tree parm_name
= NULL_TREE
, parm_decl
;
1784 tree parm_type
= TREE_VALUE (tem
);
1785 gcc_assert (i
< DECL_MAX_LOCALS (fndecl
));
1787 parm_decl
= build_decl (input_location
, PARM_DECL
, parm_name
, parm_type
);
1788 DECL_CONTEXT (parm_decl
) = fndecl
;
1789 if (targetm
.calls
.promote_prototypes (parm_type
)
1790 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1791 && INTEGRAL_TYPE_P (parm_type
))
1792 parm_type
= integer_type_node
;
1793 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1796 ptr
= &DECL_CHAIN (parm_decl
);
1798 /* Add parm_decl to the decl_map. */
1799 push_jvm_slot (i
, parm_decl
);
1801 /* The this parameter of methods is artificial. */
1802 if (TREE_CODE (TREE_TYPE (fndecl
)) == METHOD_TYPE
&& i
== 0)
1803 DECL_ARTIFICIAL (parm_decl
) = 1;
1805 type_map
[i
] = TREE_TYPE (parm_decl
);
1806 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1809 type_map
[i
] = void_type_node
;
1813 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1815 while (i
< DECL_MAX_LOCALS(fndecl
))
1816 type_map
[i
++] = NULL_TREE
;
1818 build_result_decl (fndecl
);
1819 DECL_SOURCE_LOCATION (fndecl
) = input_location
;
1821 /* Push local variables. */
1824 function_binding_level
= current_binding_level
;
1828 end_java_method (void)
1830 tree fndecl
= current_function_decl
;
1832 /* pop out of function */
1835 /* pop out of its parameters */
1838 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1840 if (DECL_SAVED_TREE (fndecl
))
1842 tree fbody
, block_body
;
1843 /* Before we check initialization, attached all class initialization
1844 variable to the block_body */
1845 fbody
= DECL_SAVED_TREE (fndecl
);
1846 block_body
= BIND_EXPR_BODY (fbody
);
1847 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl
),
1848 attach_init_test_initialization_flags
, block_body
);
1851 finish_method (fndecl
);
1853 current_function_decl
= NULL_TREE
;
1854 base_decl_map
= NULL_TREE
;
1857 /* Prepare a method for expansion. */
1860 finish_method (tree fndecl
)
1862 tree
*tp
= &DECL_SAVED_TREE (fndecl
);
1864 /* Wrap body of synchronized methods in a monitorenter,
1865 plus monitorexit cleanup. */
1866 if (METHOD_SYNCHRONIZED (fndecl
))
1868 tree enter
, exit
, lock
;
1869 if (METHOD_STATIC (fndecl
))
1870 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1872 lock
= DECL_ARGUMENTS (fndecl
);
1873 BUILD_MONITOR_ENTER (enter
, lock
);
1874 BUILD_MONITOR_EXIT (exit
, lock
);
1875 *tp
= build2 (COMPOUND_EXPR
, void_type_node
, enter
,
1876 build2 (TRY_FINALLY_EXPR
, void_type_node
, *tp
, exit
));
1879 /* Convert function tree to GENERIC prior to inlining. */
1880 java_genericize (fndecl
);
1882 /* Store the end of the function, so that we get good line number
1883 info for the epilogue. */
1884 if (DECL_STRUCT_FUNCTION (fndecl
))
1885 set_cfun (DECL_STRUCT_FUNCTION (fndecl
));
1887 allocate_struct_function (fndecl
, false);
1888 cfun
->function_end_locus
= DECL_FUNCTION_LAST_LINE (fndecl
);
1890 /* Defer inlining and expansion to the cgraph optimizers. */
1891 cgraph_finalize_function (fndecl
, false);
1894 /* We pessimistically marked all methods and fields external until we
1895 knew what set of classes we were planning to compile. Now mark those
1896 associated with CLASS to be generated locally as not external. */
1899 java_mark_decl_local (tree decl
)
1901 DECL_EXTERNAL (decl
) = 0;
1903 #ifdef ENABLE_CHECKING
1904 /* Double check that we didn't pass the function to the callgraph early. */
1905 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1907 struct cgraph_node
*node
= cgraph_get_node (decl
);
1908 gcc_assert (!node
|| !node
->local
.finalized
);
1911 gcc_assert (!DECL_RTL_SET_P (decl
));
1914 /* Given appropriate target support, G++ will emit hidden aliases for native
1915 methods. Using this hidden name is required for proper operation of
1916 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1917 proper target support, then mark the method for aliasing. */
1920 java_mark_cni_decl_local (tree decl
)
1922 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1926 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
1927 DECL_LOCAL_CNI_METHOD_P (decl
) = 1;
1929 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1930 mangler. We might have already referenced this native method and
1931 therefore created its name, but even if we have it won't hurt.
1932 We'll just go via its externally visible name, rather than its
1933 hidden alias. However, we must force things so that the correct
1934 mangling is done. */
1936 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
1937 java_mangle_decl (decl
);
1938 if (DECL_RTL_SET_P (decl
))
1940 SET_DECL_RTL (decl
, 0);
1941 make_decl_rtl (decl
);
1945 /* Use the preceding two functions and mark all members of the class. */
1948 java_mark_class_local (tree klass
)
1952 for (t
= TYPE_FIELDS (klass
); t
; t
= DECL_CHAIN (t
))
1953 if (FIELD_STATIC (t
))
1955 if (DECL_EXTERNAL (t
))
1956 vec_safe_push (pending_static_fields
, t
);
1957 java_mark_decl_local (t
);
1960 for (t
= TYPE_METHODS (klass
); t
; t
= DECL_CHAIN (t
))
1961 if (!METHOD_ABSTRACT (t
))
1963 if (METHOD_NATIVE (t
) && !flag_jni
)
1964 java_mark_cni_decl_local (t
);
1966 java_mark_decl_local (t
);
1970 /* Add a statement to a compound_expr. */
1973 add_stmt_to_compound (tree existing
, tree type
, tree stmt
)
1979 tree expr
= build2 (COMPOUND_EXPR
, type
, existing
, stmt
);
1980 TREE_SIDE_EFFECTS (expr
) = TREE_SIDE_EFFECTS (existing
)
1981 | TREE_SIDE_EFFECTS (stmt
);
1988 /* If this node is an expr, mark its input location. Called from
1992 set_input_location (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
,
1993 void *data ATTRIBUTE_UNUSED
)
1997 if (CAN_HAVE_LOCATION_P (t
))
1999 if (EXPR_HAS_LOCATION(t
))
2000 return t
; /* Don't walk any further into this expr. */
2002 SET_EXPR_LOCATION (t
, input_location
);
2005 return NULL_TREE
; /* Continue walking this expr. */
2008 /* Add a statement to the statement_list currently being constructed.
2009 If the statement_list is null, we don't create a singleton list.
2010 This is necessary because poplevel() assumes that adding a
2011 statement to a null statement_list returns the statement. */
2014 java_add_stmt (tree new_stmt
)
2016 tree stmts
= current_binding_level
->stmts
;
2017 tree_stmt_iterator i
;
2020 walk_tree (&new_stmt
, set_input_location
, NULL
, NULL
);
2023 return current_binding_level
->stmts
= new_stmt
;
2025 /* Force STMTS to be a statement_list. */
2026 if (TREE_CODE (stmts
) != STATEMENT_LIST
)
2028 tree t
= make_node (STATEMENT_LIST
);
2030 tsi_link_after (&i
, stmts
, TSI_CONTINUE_LINKING
);
2034 i
= tsi_last (stmts
);
2035 tsi_link_after (&i
, new_stmt
, TSI_CONTINUE_LINKING
);
2036 TREE_TYPE (stmts
) = void_type_node
;
2038 return current_binding_level
->stmts
= stmts
;
2041 /* Add a variable to the current scope. */
2044 java_add_local_var (tree decl
)
2046 tree
*vars
= ¤t_binding_level
->names
;
2048 DECL_CHAIN (decl
) = next
;
2050 DECL_CONTEXT (decl
) = current_function_decl
;
2051 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
2055 /* Return a pointer to the compound_expr currently being
2061 return ¤t_binding_level
->stmts
;
2064 /* Register an exception range as belonging to the current binding
2065 level. There may only be one: if there are more, we'll create more
2066 binding levels. However, each range can have multiple handlers,
2067 and these are expanded when we call expand_end_java_handler(). */
2070 register_exception_range (struct eh_range
*range
, int pc
, int end_pc
)
2072 gcc_assert (! current_binding_level
->exception_range
);
2073 current_binding_level
->exception_range
= range
;
2074 current_binding_level
->end_pc
= end_pc
;
2075 current_binding_level
->start_pc
= pc
;
2078 #include "gt-java-decl.h"