* tree-ssa-loop-ivopts.c (get_computation_cost_at): Check inv
[official-gcc.git] / gcc / java / decl.c
blob36989d380abcb6be6fe53a1f872e4b21f73206b8
1 /* Process declarations and variables for the GNU compiler for the
2 Java(TM) language.
3 Copyright (C) 1996-2016 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)
10 any later version.
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. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "target.h"
31 #include "function.h"
32 #include "tree.h"
33 #include "stringpool.h"
34 #include "cgraph.h"
35 #include "diagnostic-core.h"
36 #include "stor-layout.h"
37 #include "varasm.h"
38 #include "toplev.h"
39 #include "java-tree.h"
40 #include "jcf.h"
41 #include "java-except.h"
42 #include "version.h"
43 #include "tree-iterator.h"
44 #include "langhooks.h"
46 #if defined (DEBUG_JAVA_BINDING_LEVELS)
47 extern void indent (void);
48 #endif
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
67 loader. */
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,
80 this must change). */
81 #define GCJ_CURRENT_BC_ABI_VERSION \
82 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
84 /* The ABI version number. */
85 tree gcj_abi_version;
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. */
110 static int uniq;
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;
129 int current_pc;
131 void
132 indent (void)
134 int i;
136 for (i = 0; i < binding_depth*2; i++)
137 putc (' ', stderr);
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. */
144 static bool
145 debug_variable_p (tree decl)
147 if (TREE_CODE (decl) == PARM_DECL)
148 return false;
150 if (LOCAL_SLOT_P (decl))
151 return false;
153 return true;
156 static tree
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;
173 return decl;
176 /* Find the best declaration based upon type. If 'decl' fits 'type' better
177 than 'best', return 'decl'. Otherwise return 'best'. */
179 static tree
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
204 new VAR_DECL.
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
209 NOP_EXPR.
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))
217 return decl;
220 return best;
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. */
228 tree
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
262 slot. */
263 if (! decl)
265 char buf[64];
266 tree name;
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
281 aliases. */
282 if (TREE_CODE (type) == POINTER_TYPE
283 && ! TREE_VEC_ELT (base_decl_map, index))
285 char buf[64];
286 tree name;
287 tree base_decl;
288 sprintf (buf, "#ref#%d#%d", index, uniq++);
289 name = get_identifier (buf);
290 base_decl
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;
298 return decl;
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
305 written to. */
307 static tree
308 java_replace_reference (tree var_decl, bool want_lvalue)
310 tree decl_type;
312 if (! base_decl_map)
313 return var_decl;
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);
326 if (! want_lvalue)
327 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
329 return base_decl;
333 return var_decl;
336 /* Helper for java_genericize. */
338 tree
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),
358 new_lhs, new_rhs);
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);
368 *walk_subtrees = 0;
371 return NULL_TREE;
374 /* Same as find_local_index, except that INDEX is a stack index. */
376 tree
377 find_stack_slot (int index, tree type)
379 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
380 type, -1);
383 struct GTY(())
384 binding_level {
385 /* A chain of _DECL nodes for all variables, constants, functions,
386 * and typedef types. These are in the reverse of the order supplied.
388 tree names;
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). */
394 tree shadowed;
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. */
399 tree blocks;
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. */
405 int end_pc;
406 /* The bytecode PC that marks the start of this level. */
407 int start_pc;
409 /* The statements in this binding level. */
410 tree stmts;
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. */
419 source_location loc;
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 */
456 0, /* start_pc */
457 NULL, /* stmts */
458 NULL, /* exception_range */
459 0, /* binding_depth */
460 0, /* loc */
463 tree java_global_trees[JTI_MAX];
465 /* Build (and pushdecl) a "promoted type" for all standard
466 types shorter than int. */
468 static tree
469 push_promoted_type (const char *name, tree actual_type)
471 tree type = make_node (TREE_CODE (actual_type));
472 #if 1
473 tree in_min = TYPE_MIN_VALUE (int_type_node);
474 tree in_max = TYPE_MAX_VALUE (int_type_node);
475 #else
476 tree in_min = TYPE_MIN_VALUE (actual_type);
477 tree in_max = TYPE_MAX_VALUE (actual_type);
478 #endif
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);
485 layout_type (type);
486 pushdecl (build_decl (input_location,
487 TYPE_DECL, get_identifier (name), type));
488 return type;
491 /* Return tree that represents a vtable for a primitive array. */
492 static tree
493 create_primitive_vtable (const char *name)
495 tree r;
496 char buf[50];
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;
502 return r;
505 /* Parse the version string and compute the ABI version number. */
506 static void
507 parse_version (void)
509 const char *p = version_string;
510 unsigned int major = 0;
511 unsigned int abi_version;
513 /* Skip leading junk. */
514 while (*p && !ISDIGIT (*p))
515 ++p;
516 gcc_assert (*p);
518 /* Extract major version. */
519 while (ISDIGIT (*p))
521 major = major * 10 + *p - '0';
522 ++p;
525 gcc_assert (*p == '.' && ISDIGIT (p[1]));
526 ++p;
528 if (flag_indirect_dispatch)
530 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
531 abi_version |= FLAG_BINARYCOMPAT_ABI;
533 else /* C++ ABI */
535 /* Implicit in this computation is the idea that we won't break the
536 old-style binary ABI in a minor release (e.g., from 6.1.0 to
537 6.2.0). */
538 abi_version = 100000 * major;
540 if (flag_bootstrap_classes)
541 abi_version |= FLAG_BOOTSTRAP_LOADER;
543 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
546 void
547 java_init_decl_processing (void)
549 tree field = NULL_TREE;
550 tree t;
552 init_class_processing ();
554 current_function_decl = NULL;
555 current_binding_level = NULL_BINDING_LEVEL;
556 free_binding_level = NULL_BINDING_LEVEL;
557 pushlevel (0); /* make the binding_level structure for global names */
558 global_binding_level = current_binding_level;
560 /* Build common tree nodes, Java has an unsigned char. */
561 build_common_tree_nodes (false);
563 /* ??? Now we continue and override some of the built types again
564 with Java specific types. As the above generated types are
565 supposed to match the targets C ABI this isn't really the way
566 to go and any Java specifics should _not_ use those global types
567 if the Java ABI does not match the C one. */
569 byte_type_node = make_signed_type (8);
570 pushdecl (build_decl (BUILTINS_LOCATION,
571 TYPE_DECL, get_identifier ("byte"), byte_type_node));
572 short_type_node = make_signed_type (16);
573 pushdecl (build_decl (BUILTINS_LOCATION,
574 TYPE_DECL, get_identifier ("short"), short_type_node));
575 int_type_node = make_signed_type (32);
576 pushdecl (build_decl (BUILTINS_LOCATION,
577 TYPE_DECL, get_identifier ("int"), int_type_node));
578 long_type_node = make_signed_type (64);
579 pushdecl (build_decl (BUILTINS_LOCATION,
580 TYPE_DECL, get_identifier ("long"), long_type_node));
582 unsigned_byte_type_node = make_unsigned_type (8);
583 pushdecl (build_decl (BUILTINS_LOCATION,
584 TYPE_DECL, get_identifier ("unsigned byte"),
585 unsigned_byte_type_node));
586 unsigned_short_type_node = make_unsigned_type (16);
587 pushdecl (build_decl (BUILTINS_LOCATION,
588 TYPE_DECL, get_identifier ("unsigned short"),
589 unsigned_short_type_node));
590 unsigned_int_type_node = make_unsigned_type (32);
591 pushdecl (build_decl (BUILTINS_LOCATION,
592 TYPE_DECL, get_identifier ("unsigned int"),
593 unsigned_int_type_node));
594 unsigned_long_type_node = make_unsigned_type (64);
595 pushdecl (build_decl (BUILTINS_LOCATION,
596 TYPE_DECL, get_identifier ("unsigned long"),
597 unsigned_long_type_node));
599 /* Define these next since types below may used them. */
600 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
601 integer_zero_node = build_int_cst (NULL_TREE, 0);
602 integer_one_node = build_int_cst (NULL_TREE, 1);
603 integer_two_node = build_int_cst (NULL_TREE, 2);
604 integer_three_node = build_int_cst (NULL_TREE, 3);
605 integer_four_node = build_int_cst (NULL_TREE, 4);
606 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
608 /* A few values used for range checking in the lexer. */
609 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
610 decimal_long_max
611 = double_int_to_tree (unsigned_long_type_node,
612 double_int_zero.set_bit (64));
614 long_zero_node = build_int_cst (long_type_node, 0);
616 pushdecl (build_decl (BUILTINS_LOCATION,
617 TYPE_DECL, get_identifier ("void"), void_type_node));
619 t = make_node (VOID_TYPE);
620 layout_type (t); /* Uses size_zero_node */
621 return_address_type_node = build_pointer_type (t);
623 char_type_node = make_unsigned_type (16);
624 TYPE_STRING_FLAG (char_type_node) = 1;
625 pushdecl (build_decl (BUILTINS_LOCATION,
626 TYPE_DECL, get_identifier ("char"), char_type_node));
628 boolean_type_node = make_unsigned_type (1);
629 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
630 pushdecl (build_decl (BUILTINS_LOCATION,
631 TYPE_DECL, get_identifier ("boolean"),
632 boolean_type_node));
633 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
634 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
636 promoted_byte_type_node
637 = push_promoted_type ("promoted_byte", byte_type_node);
638 promoted_short_type_node
639 = push_promoted_type ("promoted_short", short_type_node);
640 promoted_char_type_node
641 = push_promoted_type ("promoted_char", char_type_node);
642 promoted_boolean_type_node
643 = push_promoted_type ("promoted_boolean", boolean_type_node);
645 float_type_node = make_node (REAL_TYPE);
646 TYPE_PRECISION (float_type_node) = 32;
647 pushdecl (build_decl (BUILTINS_LOCATION,
648 TYPE_DECL, get_identifier ("float"),
649 float_type_node));
650 layout_type (float_type_node);
652 double_type_node = make_node (REAL_TYPE);
653 TYPE_PRECISION (double_type_node) = 64;
654 pushdecl (build_decl (BUILTINS_LOCATION,
655 TYPE_DECL, get_identifier ("double"),
656 double_type_node));
657 layout_type (double_type_node);
659 float_zero_node = build_real (float_type_node, dconst0);
660 double_zero_node = build_real (double_type_node, dconst0);
662 /* These are the vtables for arrays of primitives. */
663 boolean_array_vtable = create_primitive_vtable ("boolean");
664 byte_array_vtable = create_primitive_vtable ("byte");
665 char_array_vtable = create_primitive_vtable ("char");
666 short_array_vtable = create_primitive_vtable ("short");
667 int_array_vtable = create_primitive_vtable ("int");
668 long_array_vtable = create_primitive_vtable ("long");
669 float_array_vtable = create_primitive_vtable ("float");
670 double_array_vtable = create_primitive_vtable ("double");
672 one_elt_array_domain_type = build_index_type (integer_one_node);
673 utf8const_type = make_node (RECORD_TYPE);
674 PUSH_FIELD (input_location,
675 utf8const_type, field, "hash", unsigned_short_type_node);
676 PUSH_FIELD (input_location,
677 utf8const_type, field, "length", unsigned_short_type_node);
678 FINISH_RECORD (utf8const_type);
679 utf8const_ptr_type = build_pointer_type (utf8const_type);
681 atable_type = build_array_type (ptr_type_node,
682 one_elt_array_domain_type);
683 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
684 atable_ptr_type = build_pointer_type (atable_type);
686 itable_type = build_array_type (ptr_type_node,
687 one_elt_array_domain_type);
688 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
689 itable_ptr_type = build_pointer_type (itable_type);
691 symbol_type = make_node (RECORD_TYPE);
692 PUSH_FIELD (input_location,
693 symbol_type, field, "clname", utf8const_ptr_type);
694 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
695 PUSH_FIELD (input_location,
696 symbol_type, field, "signature", utf8const_ptr_type);
697 FINISH_RECORD (symbol_type);
699 symbols_array_type = build_array_type (symbol_type,
700 one_elt_array_domain_type);
701 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
703 assertion_entry_type = make_node (RECORD_TYPE);
704 PUSH_FIELD (input_location,
705 assertion_entry_type, field, "assertion_code", integer_type_node);
706 PUSH_FIELD (input_location,
707 assertion_entry_type, field, "op1", utf8const_ptr_type);
708 PUSH_FIELD (input_location,
709 assertion_entry_type, field, "op2", utf8const_ptr_type);
710 FINISH_RECORD (assertion_entry_type);
712 assertion_table_type = build_array_type (assertion_entry_type,
713 one_elt_array_domain_type);
715 /* As you're adding items here, please update the code right after
716 this section, so that the filename containing the source code of
717 the pre-defined class gets registered correctly. */
718 unqualified_object_id_node = get_identifier ("Object");
719 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
720 object_ptr_type_node = promote_type (object_type_node);
721 string_type_node = lookup_class (get_identifier ("java.lang.String"));
722 string_ptr_type_node = promote_type (string_type_node);
723 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
724 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
725 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
726 runtime_exception_type_node =
727 lookup_class (get_identifier ("java.lang.RuntimeException"));
728 error_exception_type_node =
729 lookup_class (get_identifier ("java.lang.Error"));
731 rawdata_ptr_type_node
732 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
734 add_predefined_file (get_identifier ("java/lang/Class.java"));
735 add_predefined_file (get_identifier ("java/lang/Error.java"));
736 add_predefined_file (get_identifier ("java/lang/Object.java"));
737 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
738 add_predefined_file (get_identifier ("java/lang/String.java"));
739 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
740 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
741 add_predefined_file (get_identifier ("java/lang/Exception.java"));
742 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
743 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
745 methodtable_type = make_node (RECORD_TYPE);
746 layout_type (methodtable_type);
747 build_decl (BUILTINS_LOCATION,
748 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
749 methodtable_ptr_type = build_pointer_type (methodtable_type);
751 TYPE_identifier_node = get_identifier ("TYPE");
752 init_identifier_node = get_identifier ("<init>");
753 clinit_identifier_node = get_identifier ("<clinit>");
754 void_signature_node = get_identifier ("()V");
755 finalize_identifier_node = get_identifier ("finalize");
756 this_identifier_node = get_identifier ("this");
758 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
759 java_io_serializable_identifier_node =
760 get_identifier ("java.io.Serializable");
762 /* for lack of a better place to put this stub call */
763 init_expr_processing();
765 constants_type_node = make_node (RECORD_TYPE);
766 PUSH_FIELD (input_location,
767 constants_type_node, field, "size", unsigned_int_type_node);
768 PUSH_FIELD (input_location,
769 constants_type_node, field, "tags", ptr_type_node);
770 PUSH_FIELD (input_location,
771 constants_type_node, field, "data", ptr_type_node);
772 constants_data_field_decl_node = field;
773 FINISH_RECORD (constants_type_node);
774 build_decl (BUILTINS_LOCATION,
775 TYPE_DECL, get_identifier ("constants"), constants_type_node);
777 access_flags_type_node = unsigned_short_type_node;
779 dtable_type = make_node (RECORD_TYPE);
780 dtable_ptr_type = build_pointer_type (dtable_type);
782 otable_type = build_array_type (integer_type_node,
783 one_elt_array_domain_type);
784 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
785 otable_ptr_type = build_pointer_type (otable_type);
787 PUSH_FIELD (input_location,
788 object_type_node, field, "vtable", dtable_ptr_type);
789 DECL_FCONTEXT (field) = object_type_node;
790 TYPE_VFIELD (object_type_node) = field;
792 /* This isn't exactly true, but it is what we have in the source.
793 There is an unresolved issue here, which is whether the vtable
794 should be marked by the GC. */
795 if (! flag_hash_synchronization)
796 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
797 build_pointer_type (object_type_node));
798 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
799 FIELD_PRIVATE (t) = 1;
800 FINISH_RECORD (object_type_node);
802 field_type_node = make_node (RECORD_TYPE);
803 field_ptr_type_node = build_pointer_type (field_type_node);
804 method_type_node = make_node (RECORD_TYPE);
805 method_ptr_type_node = build_pointer_type (method_type_node);
807 set_super_info (0, class_type_node, object_type_node, 0);
808 set_super_info (0, string_type_node, object_type_node, 0);
809 class_ptr_type = build_pointer_type (class_type_node);
811 PUSH_FIELD (input_location,
812 class_type_node, field, "next_or_version", class_ptr_type);
813 PUSH_FIELD (input_location,
814 class_type_node, field, "name", utf8const_ptr_type);
815 PUSH_FIELD (input_location,
816 class_type_node, field, "accflags", access_flags_type_node);
817 PUSH_FIELD (input_location,
818 class_type_node, field, "superclass", class_ptr_type);
819 PUSH_FIELD (input_location,
820 class_type_node, field, "constants", constants_type_node);
821 constants_field_decl_node = field;
822 PUSH_FIELD (input_location,
823 class_type_node, field, "methods", method_ptr_type_node);
824 PUSH_FIELD (input_location,
825 class_type_node, field, "method_count", short_type_node);
826 PUSH_FIELD (input_location,
827 class_type_node, field, "vtable_method_count", short_type_node);
828 PUSH_FIELD (input_location,
829 class_type_node, field, "fields", field_ptr_type_node);
830 PUSH_FIELD (input_location,
831 class_type_node, field, "size_in_bytes", int_type_node);
832 PUSH_FIELD (input_location,
833 class_type_node, field, "field_count", short_type_node);
834 PUSH_FIELD (input_location,
835 class_type_node, field, "static_field_count", short_type_node);
836 PUSH_FIELD (input_location,
837 class_type_node, field, "vtable", dtable_ptr_type);
838 PUSH_FIELD (input_location,
839 class_type_node, field, "otable", otable_ptr_type);
840 PUSH_FIELD (input_location,
841 class_type_node, field, "otable_syms",
842 symbols_array_ptr_type);
843 PUSH_FIELD (input_location,
844 class_type_node, field, "atable", atable_ptr_type);
845 PUSH_FIELD (input_location,
846 class_type_node, field, "atable_syms",
847 symbols_array_ptr_type);
848 PUSH_FIELD (input_location,
849 class_type_node, field, "itable", itable_ptr_type);
850 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
851 symbols_array_ptr_type);
852 PUSH_FIELD (input_location,
853 class_type_node, field, "catch_classes", ptr_type_node);
854 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
855 build_pointer_type (class_ptr_type));
856 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
857 PUSH_FIELD (input_location,
858 class_type_node, field, "interface_count", short_type_node);
859 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
860 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
861 PUSH_FIELD (input_location,
862 class_type_node, field, "depth", short_type_node);
863 PUSH_FIELD (input_location,
864 class_type_node, field, "ancestors", ptr_type_node);
865 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
866 PUSH_FIELD (input_location,
867 class_type_node, field, "arrayclass", ptr_type_node);
868 PUSH_FIELD (input_location,
869 class_type_node, field, "protectionDomain", ptr_type_node);
870 PUSH_FIELD (input_location,
871 class_type_node, field, "assertion_table", ptr_type_node);
872 PUSH_FIELD (input_location,
873 class_type_node, field, "hack_signers", ptr_type_node);
874 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
875 PUSH_FIELD (input_location,
876 class_type_node, field, "aux_info", ptr_type_node);
877 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
878 PUSH_FIELD (input_location,
879 class_type_node, field, "reflection_data", ptr_type_node);
880 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
881 FIELD_PRIVATE (t) = 1;
882 push_super_field (class_type_node, object_type_node);
884 FINISH_RECORD (class_type_node);
885 build_decl (BUILTINS_LOCATION,
886 TYPE_DECL, get_identifier ("Class"), class_type_node);
888 field_info_union_node = make_node (UNION_TYPE);
889 PUSH_FIELD (input_location,
890 field_info_union_node, field, "boffset", int_type_node);
891 PUSH_FIELD (input_location,
892 field_info_union_node, field, "addr", ptr_type_node);
893 layout_type (field_info_union_node);
895 PUSH_FIELD (input_location,
896 field_type_node, field, "name", utf8const_ptr_type);
897 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
898 PUSH_FIELD (input_location,
899 field_type_node, field, "accflags", access_flags_type_node);
900 PUSH_FIELD (input_location,
901 field_type_node, field, "bsize", unsigned_short_type_node);
902 PUSH_FIELD (input_location,
903 field_type_node, field, "info", field_info_union_node);
904 FINISH_RECORD (field_type_node);
905 build_decl (BUILTINS_LOCATION,
906 TYPE_DECL, get_identifier ("Field"), field_type_node);
908 nativecode_ptr_array_type_node
909 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
911 PUSH_FIELD (input_location,
912 dtable_type, field, "class", class_ptr_type);
913 PUSH_FIELD (input_location,
914 dtable_type, field, "methods", nativecode_ptr_array_type_node);
915 FINISH_RECORD (dtable_type);
916 build_decl (BUILTINS_LOCATION,
917 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
919 jexception_type = make_node (RECORD_TYPE);
920 PUSH_FIELD (input_location,
921 jexception_type, field, "start_pc", ptr_type_node);
922 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
923 PUSH_FIELD (input_location,
924 jexception_type, field, "handler_pc", ptr_type_node);
925 PUSH_FIELD (input_location,
926 jexception_type, field, "catch_type", class_ptr_type);
927 FINISH_RECORD (jexception_type);
928 build_decl (BUILTINS_LOCATION,
929 TYPE_DECL, get_identifier ("jexception"), field_type_node);
930 jexception_ptr_type = build_pointer_type (jexception_type);
932 lineNumberEntry_type = make_node (RECORD_TYPE);
933 PUSH_FIELD (input_location,
934 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
935 PUSH_FIELD (input_location,
936 lineNumberEntry_type, field, "start_pc", ptr_type_node);
937 FINISH_RECORD (lineNumberEntry_type);
939 lineNumbers_type = make_node (RECORD_TYPE);
940 PUSH_FIELD (input_location,
941 lineNumbers_type, field, "length", unsigned_int_type_node);
942 FINISH_RECORD (lineNumbers_type);
944 PUSH_FIELD (input_location,
945 method_type_node, field, "name", utf8const_ptr_type);
946 PUSH_FIELD (input_location,
947 method_type_node, field, "signature", utf8const_ptr_type);
948 PUSH_FIELD (input_location,
949 method_type_node, field, "accflags", access_flags_type_node);
950 PUSH_FIELD (input_location,
951 method_type_node, field, "index", unsigned_short_type_node);
952 PUSH_FIELD (input_location,
953 method_type_node, field, "ncode", nativecode_ptr_type_node);
954 PUSH_FIELD (input_location,
955 method_type_node, field, "throws", ptr_type_node);
956 FINISH_RECORD (method_type_node);
957 build_decl (BUILTINS_LOCATION,
958 TYPE_DECL, get_identifier ("Method"), method_type_node);
960 end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
962 t = build_function_type_list (ptr_type_node, class_ptr_type, NULL_TREE);
963 alloc_object_node = add_builtin_function ("_Jv_AllocObject", t,
964 0, NOT_BUILT_IN, NULL, NULL_TREE);
965 DECL_IS_MALLOC (alloc_object_node) = 1;
966 alloc_no_finalizer_node =
967 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t,
968 0, NOT_BUILT_IN, NULL, NULL_TREE);
969 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
971 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
972 soft_initclass_node = add_builtin_function ("_Jv_InitClass", t,
973 0, NOT_BUILT_IN, NULL, NULL_TREE);
974 t = build_function_type_list (ptr_type_node,
975 class_ptr_type, int_type_node, NULL_TREE);
976 soft_resolvepoolentry_node
977 = add_builtin_function ("_Jv_ResolvePoolEntry", t,
978 0,NOT_BUILT_IN, NULL, NULL_TREE);
979 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
980 t = build_function_type_list (void_type_node,
981 class_ptr_type, int_type_node, NULL_TREE);
982 throw_node = add_builtin_function ("_Jv_Throw", t,
983 0, NOT_BUILT_IN, NULL, NULL_TREE);
984 /* Mark throw_nodes as `noreturn' functions with side effects. */
985 TREE_THIS_VOLATILE (throw_node) = 1;
986 TREE_SIDE_EFFECTS (throw_node) = 1;
988 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
989 soft_monitorenter_node
990 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
991 NULL, NULL_TREE);
992 soft_monitorexit_node
993 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
994 NULL, NULL_TREE);
996 t = build_function_type_list (ptr_type_node,
997 ptr_type_node, int_type_node, NULL_TREE);
998 soft_newarray_node
999 = add_builtin_function ("_Jv_NewPrimArray", t,
1000 0, NOT_BUILT_IN, NULL, NULL_TREE);
1001 DECL_IS_MALLOC (soft_newarray_node) = 1;
1003 t = build_function_type_list (ptr_type_node,
1004 int_type_node, class_ptr_type,
1005 object_ptr_type_node, NULL_TREE);
1006 soft_anewarray_node
1007 = add_builtin_function ("_Jv_NewObjectArray", t,
1008 0, NOT_BUILT_IN, NULL, NULL_TREE);
1009 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1011 t = build_varargs_function_type_list (ptr_type_node,
1012 ptr_type_node, int_type_node,
1013 NULL_TREE);
1014 soft_multianewarray_node
1015 = add_builtin_function ("_Jv_NewMultiArray", t,
1016 0, NOT_BUILT_IN, NULL, NULL_TREE);
1017 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1019 t = build_function_type_list (void_type_node, int_type_node, NULL_TREE);
1020 soft_badarrayindex_node
1021 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1022 0, NOT_BUILT_IN, NULL, NULL_TREE);
1023 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1024 effects. */
1025 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1026 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1028 t = build_function_type_list (void_type_node, NULL_TREE);
1029 soft_nullpointer_node
1030 = add_builtin_function ("_Jv_ThrowNullPointerException", t,
1031 0, NOT_BUILT_IN, NULL, NULL_TREE);
1032 /* Mark soft_nullpointer_node as a `noreturn' function with side
1033 effects. */
1034 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1035 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1037 soft_abstractmethod_node
1038 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t,
1039 0, NOT_BUILT_IN, NULL, NULL_TREE);
1040 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1041 effects. */
1042 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1043 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1045 soft_nosuchfield_node
1046 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t,
1047 0, NOT_BUILT_IN, NULL, NULL_TREE);
1048 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1049 effects. */
1050 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1051 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1053 t = build_function_type_list (ptr_type_node,
1054 class_ptr_type, object_ptr_type_node,
1055 NULL_TREE);
1056 soft_checkcast_node
1057 = add_builtin_function ("_Jv_CheckCast", t,
1058 0, NOT_BUILT_IN, NULL, NULL_TREE);
1059 t = build_function_type_list (boolean_type_node,
1060 object_ptr_type_node, class_ptr_type,
1061 NULL_TREE);
1062 soft_instanceof_node
1063 = add_builtin_function ("_Jv_IsInstanceOf", t,
1064 0, NOT_BUILT_IN, NULL, NULL_TREE);
1065 DECL_PURE_P (soft_instanceof_node) = 1;
1066 t = build_function_type_list (void_type_node,
1067 object_ptr_type_node, object_ptr_type_node,
1068 NULL_TREE);
1069 soft_checkarraystore_node
1070 = add_builtin_function ("_Jv_CheckArrayStore", t,
1071 0, NOT_BUILT_IN, NULL, NULL_TREE);
1072 t = build_function_type_list (ptr_type_node,
1073 ptr_type_node, ptr_type_node, int_type_node,
1074 NULL_TREE);
1075 soft_lookupinterfacemethod_node
1076 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t,
1077 0, NOT_BUILT_IN, NULL, NULL_TREE);
1078 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1080 t = build_function_type_list (ptr_type_node,
1081 ptr_type_node, ptr_type_node, ptr_type_node,
1082 NULL_TREE);
1083 soft_lookupinterfacemethodbyname_node
1084 = add_builtin_function ("_Jv_LookupInterfaceMethod", t,
1085 0, NOT_BUILT_IN, NULL, NULL_TREE);
1086 t = build_function_type_list (ptr_type_node,
1087 object_ptr_type_node, ptr_type_node,
1088 ptr_type_node, int_type_node, NULL_TREE);
1089 soft_lookupjnimethod_node
1090 = add_builtin_function ("_Jv_LookupJNIMethod", t,
1091 0, NOT_BUILT_IN, NULL, NULL_TREE);
1092 t = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
1093 soft_getjnienvnewframe_node
1094 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t,
1095 0, NOT_BUILT_IN, NULL, NULL_TREE);
1096 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1097 soft_jnipopsystemframe_node
1098 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t,
1099 0, NOT_BUILT_IN, NULL, NULL_TREE);
1101 t = build_function_type_list (object_ptr_type_node,
1102 object_ptr_type_node, NULL_TREE);
1103 soft_unwrapjni_node
1104 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t,
1105 0, NOT_BUILT_IN, NULL, NULL_TREE);
1107 t = build_function_type_list (int_type_node,
1108 int_type_node, int_type_node, NULL_TREE);
1109 soft_idiv_node
1110 = add_builtin_function ("_Jv_divI", t,
1111 0, NOT_BUILT_IN, NULL, NULL_TREE);
1113 soft_irem_node
1114 = add_builtin_function ("_Jv_remI", t,
1115 0, NOT_BUILT_IN, NULL, NULL_TREE);
1117 t = build_function_type_list (long_type_node,
1118 long_type_node, long_type_node, NULL_TREE);
1119 soft_ldiv_node
1120 = add_builtin_function ("_Jv_divJ", t,
1121 0, NOT_BUILT_IN, NULL, NULL_TREE);
1123 soft_lrem_node
1124 = add_builtin_function ("_Jv_remJ", t,
1125 0, NOT_BUILT_IN, NULL, NULL_TREE);
1127 initialize_builtins ();
1129 soft_fmod_node = builtin_decl_explicit (BUILT_IN_FMOD);
1131 parse_version ();
1135 /* Look up NAME in the current binding level and its superiors
1136 in the namespace of variables, functions and typedefs.
1137 Return a ..._DECL node of some kind representing its definition,
1138 or return 0 if it is undefined. */
1140 tree
1141 lookup_name (tree name)
1143 tree val;
1144 if (current_binding_level != global_binding_level
1145 && IDENTIFIER_LOCAL_VALUE (name))
1146 val = IDENTIFIER_LOCAL_VALUE (name);
1147 else
1148 val = IDENTIFIER_GLOBAL_VALUE (name);
1149 return val;
1152 /* Similar to `lookup_name' but look only at current binding level and
1153 the previous one if it's the parameter level. */
1155 static tree
1156 lookup_name_current_level (tree name)
1158 tree t;
1160 if (current_binding_level == global_binding_level)
1161 return IDENTIFIER_GLOBAL_VALUE (name);
1163 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1164 return 0;
1166 for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
1167 if (DECL_NAME (t) == name)
1168 break;
1170 return t;
1173 /* Record a decl-node X as belonging to the current lexical scope.
1174 Check for errors (such as an incompatible declaration for the same
1175 name already seen in the same scope).
1177 Returns either X or an old decl for the same name.
1178 If an old decl is returned, it may have been smashed
1179 to agree with what X says. */
1181 tree
1182 pushdecl (tree x)
1184 tree t;
1185 tree name = DECL_NAME (x);
1186 struct binding_level *b = current_binding_level;
1188 if (TREE_CODE (x) != TYPE_DECL)
1189 DECL_CONTEXT (x) = current_function_decl;
1190 if (name)
1192 t = lookup_name_current_level (name);
1193 if (t != 0 && t == error_mark_node)
1194 /* error_mark_node is 0 for a while during initialization! */
1196 t = 0;
1197 error ("%q+D used prior to declaration", x);
1200 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1201 to point to the TYPE_DECL.
1202 Since Java does not have typedefs, a type can only have
1203 one (true) name, given by a class, interface, or builtin. */
1204 if (TREE_CODE (x) == TYPE_DECL
1205 && TYPE_NAME (TREE_TYPE (x)) == 0
1206 && TREE_TYPE (x) != error_mark_node)
1208 TYPE_NAME (TREE_TYPE (x)) = x;
1209 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1212 /* This name is new in its binding level.
1213 Install the new declaration and return it. */
1214 if (b == global_binding_level)
1216 /* Install a global value. */
1218 IDENTIFIER_GLOBAL_VALUE (name) = x;
1220 else
1222 /* Here to install a non-global value. */
1223 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1224 IDENTIFIER_LOCAL_VALUE (name) = x;
1226 /* If storing a local value, there may already be one (inherited).
1227 If so, record it for restoration when this binding level ends. */
1228 if (oldlocal != 0)
1229 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1233 /* Put decls on list in reverse order.
1234 We will reverse them later if necessary. */
1235 DECL_CHAIN (x) = b->names;
1236 b->names = x;
1238 return x;
1241 void
1242 pushdecl_force_head (tree x)
1244 current_binding_level->names = x;
1247 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1249 tree
1250 pushdecl_top_level (tree x)
1252 tree t;
1253 struct binding_level *b = current_binding_level;
1255 current_binding_level = global_binding_level;
1256 t = pushdecl (x);
1257 current_binding_level = b;
1258 return t;
1261 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1263 tree
1264 pushdecl_function_level (tree x)
1266 tree t;
1267 struct binding_level *b = current_binding_level;
1269 current_binding_level = function_binding_level;
1270 t = pushdecl (x);
1271 current_binding_level = b;
1272 return t;
1275 /* Return true if we are in the global binding level. */
1277 bool
1278 global_bindings_p (void)
1280 return current_binding_level == global_binding_level;
1283 /* Return the list of declarations of the current level.
1284 Note that this list is in reverse order unless/until
1285 you nreverse it; and when you do nreverse it, you must
1286 store the result back using `storedecls' or you will lose. */
1288 tree
1289 getdecls (void)
1291 return current_binding_level->names;
1294 /* Create a new `struct binding_level'. */
1296 static struct binding_level *
1297 make_binding_level (void)
1299 /* NOSTRICT */
1300 return ggc_cleared_alloc<binding_level> ();
1303 void
1304 pushlevel (int unused ATTRIBUTE_UNUSED)
1306 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1308 /* Reuse or create a struct for this binding level. */
1310 if (free_binding_level)
1312 newlevel = free_binding_level;
1313 free_binding_level = free_binding_level->level_chain;
1315 else
1317 newlevel = make_binding_level ();
1320 /* Add this level to the front of the chain (stack) of levels that
1321 are active. */
1323 *newlevel = clear_binding_level;
1324 newlevel->level_chain = current_binding_level;
1325 newlevel->loc = input_location;
1326 current_binding_level = newlevel;
1327 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1328 newlevel->binding_depth = binding_depth;
1329 indent ();
1330 fprintf (stderr, "push %s level %p pc %d\n",
1331 (is_class_level) ? "class" : "block", newlevel, current_pc);
1332 is_class_level = 0;
1333 binding_depth++;
1334 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1337 /* Exit a binding level.
1338 Pop the level off, and restore the state of the identifier-decl mappings
1339 that were in effect when this level was entered.
1341 If KEEP is nonzero, this level had explicit declarations, so
1342 and create a "block" (a BLOCK node) for the level
1343 to record its declarations and subblocks for symbol table output.
1345 If FUNCTIONBODY is nonzero, this level is the body of a function,
1346 so create a block as if KEEP were set and also clear out all
1347 label names.
1349 If REVERSE is nonzero, reverse the order of decls before putting
1350 them into the BLOCK. */
1352 tree
1353 poplevel (int keep, int reverse, int functionbody)
1355 tree link;
1356 /* The chain of decls was accumulated in reverse order.
1357 Put it into forward order, just for cleanliness. */
1358 tree decls;
1359 tree subblocks = current_binding_level->blocks;
1360 tree block = 0;
1361 tree decl;
1362 tree bind = 0;
1364 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1365 binding_depth--;
1366 indent ();
1367 if (current_binding_level->end_pc != LARGEST_PC)
1368 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1369 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1370 current_binding_level->end_pc);
1371 else
1372 fprintf (stderr, "pop %s level %p pc %d\n",
1373 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1374 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1376 /* Get the decls in the order they were written.
1377 Usually current_binding_level->names is in reverse order.
1378 But parameter decls were previously put in forward order. */
1380 if (reverse)
1381 current_binding_level->names
1382 = decls = nreverse (current_binding_level->names);
1383 else
1384 decls = current_binding_level->names;
1386 for (decl = decls; decl; decl = DECL_CHAIN (decl))
1387 if (TREE_CODE (decl) == VAR_DECL
1388 && DECL_LANG_SPECIFIC (decl) != NULL
1389 && DECL_LOCAL_SLOT_NUMBER (decl))
1390 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1392 /* If there were any declarations in that level,
1393 or if this level is a function body,
1394 create a BLOCK to record them for the life of this function. */
1396 block = 0;
1397 if (keep || functionbody)
1398 block = make_node (BLOCK);
1400 if (current_binding_level->exception_range)
1401 expand_end_java_handler (current_binding_level->exception_range);
1403 if (block != 0)
1405 /* If any statements have been generated at this level, create a
1406 BIND_EXPR to hold them and copy the variables to it. This
1407 only applies to the bytecode compiler. */
1408 if (current_binding_level->stmts)
1410 tree decl = decls;
1411 tree *var = &BLOCK_VARS (block);
1413 /* Copy decls from names list, ignoring labels. */
1414 while (decl)
1416 tree next = DECL_CHAIN (decl);
1417 if (TREE_CODE (decl) != LABEL_DECL)
1419 *var = decl;
1420 var = &DECL_CHAIN (decl);
1422 decl = next;
1424 *var = NULL;
1426 bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block),
1427 BLOCK_EXPR_BODY (block), block);
1428 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1430 if (BIND_EXPR_BODY (bind)
1431 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1432 TREE_SIDE_EFFECTS (bind) = 1;
1434 /* FIXME: gimplifier brain damage. */
1435 if (BIND_EXPR_BODY (bind) == NULL)
1436 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1438 SET_EXPR_LOCATION (bind, current_binding_level->loc);
1440 current_binding_level->stmts = NULL;
1442 else
1444 BLOCK_VARS (block) = decls;
1446 BLOCK_SUBBLOCKS (block) = subblocks;
1449 /* In each subblock, record that this is its superior. */
1451 for (link = subblocks; link; link = BLOCK_CHAIN (link))
1452 BLOCK_SUPERCONTEXT (link) = block;
1454 /* Clear out the meanings of the local variables of this level. */
1456 for (link = decls; link; link = DECL_CHAIN (link))
1458 tree name = DECL_NAME (link);
1459 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1461 /* If the ident. was used or addressed via a local extern decl,
1462 don't forget that fact. */
1463 if (DECL_EXTERNAL (link))
1465 if (TREE_USED (link))
1466 TREE_USED (name) = 1;
1467 if (TREE_ADDRESSABLE (link))
1468 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1470 IDENTIFIER_LOCAL_VALUE (name) = 0;
1474 /* Restore all name-meanings of the outer levels
1475 that were shadowed by this level. */
1477 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1478 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1480 /* If the level being exited is the top level of a function,
1481 check over all the labels, and clear out the current
1482 (function local) meanings of their names. */
1484 if (functionbody)
1486 /* If this is the top level block of a function,
1487 the vars are the function's parameters.
1488 Don't leave them in the BLOCK because they are
1489 found in the FUNCTION_DECL instead. */
1491 BLOCK_VARS (block) = 0;
1494 /* Pop the current level, and free the structure for reuse. */
1497 struct binding_level *level = current_binding_level;
1498 current_binding_level = current_binding_level->level_chain;
1500 level->level_chain = free_binding_level;
1501 free_binding_level = level;
1504 /* Dispose of the block that we just made inside some higher level. */
1505 if (functionbody)
1507 DECL_INITIAL (current_function_decl) = block;
1508 DECL_SAVED_TREE (current_function_decl) = bind;
1510 else
1512 if (block)
1514 current_binding_level->blocks
1515 = block_chainon (current_binding_level->blocks, block);
1517 /* If we did not make a block for the level just exited,
1518 any blocks made for inner levels
1519 (since they cannot be recorded as subblocks in that level)
1520 must be carried forward so they will later become subblocks
1521 of something else. */
1522 else if (subblocks)
1523 current_binding_level->blocks
1524 = block_chainon (current_binding_level->blocks, subblocks);
1526 if (bind)
1527 java_add_stmt (bind);
1530 if (block)
1531 TREE_USED (block) = 1;
1532 return block;
1535 void
1536 maybe_pushlevels (int pc)
1538 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1539 current_pc = pc;
1540 #endif
1542 while (pending_local_decls != NULL_TREE &&
1543 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1545 tree *ptr = &pending_local_decls;
1546 tree decl = *ptr, next;
1547 int end_pc = DECL_LOCAL_END_PC (decl);
1549 while (*ptr != NULL_TREE
1550 && DECL_LOCAL_START_PC (*ptr) <= pc
1551 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1552 ptr = &DECL_CHAIN (*ptr);
1553 pending_local_decls = *ptr;
1554 *ptr = NULL_TREE;
1556 /* Force non-nested range to be nested in current range by
1557 truncating variable lifetimes. */
1558 if (end_pc > current_binding_level->end_pc)
1560 tree t;
1561 end_pc = current_binding_level->end_pc;
1562 for (t = decl; t != NULL_TREE; t = DECL_CHAIN (t))
1563 DECL_LOCAL_END_PC (t) = end_pc;
1566 maybe_start_try (pc, end_pc);
1568 pushlevel (1);
1570 current_binding_level->end_pc = end_pc;
1571 current_binding_level->start_pc = pc;
1572 current_binding_level->names = NULL;
1573 for ( ; decl != NULL_TREE; decl = next)
1575 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1576 tree base_decl;
1577 next = DECL_CHAIN (decl);
1578 push_jvm_slot (index, decl);
1579 pushdecl (decl);
1580 base_decl
1581 = find_local_variable (index, TREE_TYPE (decl), pc);
1582 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1583 base_decl = TREE_VEC_ELT (base_decl_map, index);
1584 SET_DECL_VALUE_EXPR (decl, base_decl);
1585 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1589 maybe_start_try (pc, 0);
1592 void
1593 maybe_poplevels (int pc)
1595 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1596 current_pc = pc;
1597 #endif
1599 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1600 inclusive, so a variable is live if pc == end_pc. Here, we
1601 terminate a range if the current pc is equal to the end of the
1602 range, and this is *before* we have generated code for the
1603 instruction at end_pc. We're closing a binding level one
1604 instruction too early.*/
1605 while (current_binding_level->end_pc <= pc)
1606 poplevel (1, 0, 0);
1609 /* Terminate any binding which began during the range beginning at
1610 start_pc. This tidies up improperly nested local variable ranges
1611 and exception handlers; a variable declared within an exception
1612 range is forcibly terminated when that exception ends. */
1614 void
1615 force_poplevels (int start_pc)
1617 while (current_binding_level->start_pc > start_pc)
1619 if (pedantic && current_binding_level->start_pc > start_pc)
1620 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1621 current_function_decl,
1622 current_binding_level->start_pc);
1623 poplevel (1, 0, 0);
1627 /* integrate_decl_tree calls this function. */
1629 void
1630 java_dup_lang_specific_decl (tree node)
1632 int lang_decl_size;
1633 struct lang_decl *x;
1635 if (!DECL_LANG_SPECIFIC (node))
1636 return;
1638 lang_decl_size = sizeof (struct lang_decl);
1639 x = ggc_alloc<struct lang_decl> ();
1640 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1641 DECL_LANG_SPECIFIC (node) = x;
1644 void
1645 give_name_to_locals (JCF *jcf)
1647 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1648 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1649 tree parm;
1650 pending_local_decls = NULL_TREE;
1651 if (n == 0)
1652 return;
1653 JCF_SEEK (jcf, n);
1654 n = JCF_readu2 (jcf);
1655 for (i = 0; i < n; i++)
1657 int start_pc = JCF_readu2 (jcf);
1658 int length = JCF_readu2 (jcf);
1659 int name_index = JCF_readu2 (jcf);
1660 int signature_index = JCF_readu2 (jcf);
1661 int slot = JCF_readu2 (jcf);
1662 tree name = get_name_constant (jcf, name_index);
1663 tree type = parse_signature (jcf, signature_index);
1664 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1665 && start_pc == 0
1666 && length == DECL_CODE_LENGTH (current_function_decl))
1668 tree decl = TREE_VEC_ELT (decl_map, slot);
1669 DECL_NAME (decl) = name;
1670 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1671 warning (0, "bad type in parameter debug info");
1673 else
1675 tree *ptr;
1676 int end_pc = start_pc + length;
1677 tree decl = build_decl (input_location, VAR_DECL, name, type);
1678 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1680 warning (0, "bad PC range for debug info for local %q+D",
1681 decl);
1682 end_pc = DECL_CODE_LENGTH (current_function_decl);
1685 /* Adjust start_pc if necessary so that the local's first
1686 store operation will use the relevant DECL as a
1687 destination. Fore more information, read the leading
1688 comments for expr.c:maybe_adjust_start_pc. */
1689 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1691 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1692 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1693 DECL_LOCAL_START_PC (decl) = start_pc;
1694 DECL_LOCAL_END_PC (decl) = end_pc;
1696 /* Now insert the new decl in the proper place in
1697 pending_local_decls. We are essentially doing an insertion sort,
1698 which works fine, since the list input will normally already
1699 be sorted. */
1700 ptr = &pending_local_decls;
1701 while (*ptr != NULL_TREE
1702 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1703 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1704 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1705 ptr = &DECL_CHAIN (*ptr);
1706 DECL_CHAIN (decl) = *ptr;
1707 *ptr = decl;
1711 pending_local_decls = nreverse (pending_local_decls);
1713 /* Fill in default names for the parameters. */
1714 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1715 parm != NULL_TREE; parm = DECL_CHAIN (parm), i++)
1717 if (DECL_NAME (parm) == NULL_TREE)
1719 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1720 if (arg_i == 0)
1721 DECL_NAME (parm) = get_identifier ("this");
1722 else
1724 char buffer[12];
1725 sprintf (buffer, "ARG_%d", arg_i);
1726 DECL_NAME (parm) = get_identifier (buffer);
1732 tree
1733 build_result_decl (tree fndecl)
1735 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1736 tree result = DECL_RESULT (fndecl);
1737 if (! result)
1739 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1740 RESULT_DECL, NULL_TREE, restype);
1741 DECL_ARTIFICIAL (result) = 1;
1742 DECL_IGNORED_P (result) = 1;
1743 DECL_CONTEXT (result) = fndecl;
1744 DECL_RESULT (fndecl) = result;
1746 return result;
1749 void
1750 start_java_method (tree fndecl)
1752 tree tem, *ptr;
1753 int i;
1755 uniq = 0;
1757 current_function_decl = fndecl;
1758 announce_function (fndecl);
1760 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1761 decl_map = make_tree_vec (i);
1762 base_decl_map = make_tree_vec (i);
1763 type_map = XRESIZEVEC (tree, type_map, i);
1765 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1766 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1767 current_pc = 0;
1768 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1769 pushlevel (1); /* Push parameters. */
1771 ptr = &DECL_ARGUMENTS (fndecl);
1772 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1773 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1775 tree parm_name = NULL_TREE, parm_decl;
1776 tree parm_type = TREE_VALUE (tem);
1777 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1779 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1780 DECL_CONTEXT (parm_decl) = fndecl;
1781 if (targetm.calls.promote_prototypes (parm_type)
1782 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1783 && INTEGRAL_TYPE_P (parm_type))
1784 parm_type = integer_type_node;
1785 DECL_ARG_TYPE (parm_decl) = parm_type;
1787 *ptr = parm_decl;
1788 ptr = &DECL_CHAIN (parm_decl);
1790 /* Add parm_decl to the decl_map. */
1791 push_jvm_slot (i, parm_decl);
1793 /* The this parameter of methods is artificial. */
1794 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE && i == 0)
1795 DECL_ARTIFICIAL (parm_decl) = 1;
1797 type_map[i] = TREE_TYPE (parm_decl);
1798 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1800 i++;
1801 type_map[i] = void_type_node;
1804 *ptr = NULL_TREE;
1805 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1807 while (i < DECL_MAX_LOCALS(fndecl))
1808 type_map[i++] = NULL_TREE;
1810 build_result_decl (fndecl);
1811 DECL_SOURCE_LOCATION (fndecl) = input_location;
1813 /* Push local variables. */
1814 pushlevel (2);
1816 function_binding_level = current_binding_level;
1819 void
1820 end_java_method (void)
1822 tree fndecl = current_function_decl;
1824 /* pop out of function */
1825 poplevel (1, 1, 0);
1827 /* pop out of its parameters */
1828 poplevel (1, 0, 1);
1830 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1832 if (DECL_SAVED_TREE (fndecl))
1834 tree fbody, block_body;
1835 /* Before we check initialization, attached all class initialization
1836 variable to the block_body */
1837 fbody = DECL_SAVED_TREE (fndecl);
1838 block_body = BIND_EXPR_BODY (fbody);
1839 hash_table<treetreehasher> *ht = DECL_FUNCTION_INIT_TEST_TABLE (fndecl);
1840 ht->traverse<tree, attach_init_test_initialization_flags> (block_body);
1843 finish_method (fndecl);
1845 current_function_decl = NULL_TREE;
1846 base_decl_map = NULL_TREE;
1849 /* Prepare a method for expansion. */
1851 void
1852 finish_method (tree fndecl)
1854 tree *tp = &DECL_SAVED_TREE (fndecl);
1856 /* Wrap body of synchronized methods in a monitorenter,
1857 plus monitorexit cleanup. */
1858 if (METHOD_SYNCHRONIZED (fndecl))
1860 tree enter, exit, lock;
1861 if (METHOD_STATIC (fndecl))
1862 lock = build_class_ref (DECL_CONTEXT (fndecl));
1863 else
1864 lock = DECL_ARGUMENTS (fndecl);
1865 BUILD_MONITOR_ENTER (enter, lock);
1866 BUILD_MONITOR_EXIT (exit, lock);
1867 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1868 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1871 /* Convert function tree to GENERIC prior to inlining. */
1872 java_genericize (fndecl);
1874 /* Store the end of the function, so that we get good line number
1875 info for the epilogue. */
1876 if (DECL_STRUCT_FUNCTION (fndecl))
1877 set_cfun (DECL_STRUCT_FUNCTION (fndecl));
1878 else
1879 allocate_struct_function (fndecl, false);
1880 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1882 /* Defer inlining and expansion to the cgraph optimizers. */
1883 cgraph_node::finalize_function (fndecl, false);
1886 /* We pessimistically marked all methods and fields external until we
1887 knew what set of classes we were planning to compile. Now mark those
1888 associated with CLASS to be generated locally as not external. */
1890 static void
1891 java_mark_decl_local (tree decl)
1893 DECL_EXTERNAL (decl) = 0;
1895 /* Double check that we didn't pass the function to the callgraph early. */
1896 if (flag_checking && TREE_CODE (decl) == FUNCTION_DECL)
1898 struct cgraph_node *node = cgraph_node::get (decl);
1899 gcc_assert (!node || !node->definition);
1901 gcc_assert (!DECL_RTL_SET_P (decl));
1904 /* Given appropriate target support, G++ will emit hidden aliases for native
1905 methods. Using this hidden name is required for proper operation of
1906 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1907 proper target support, then mark the method for aliasing. */
1909 static void
1910 java_mark_cni_decl_local (tree decl)
1912 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1913 return;
1914 #endif
1916 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1917 DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1919 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1920 mangler. We might have already referenced this native method and
1921 therefore created its name, but even if we have it won't hurt.
1922 We'll just go via its externally visible name, rather than its
1923 hidden alias. However, we must force things so that the correct
1924 mangling is done. */
1926 if (DECL_ASSEMBLER_NAME_SET_P (decl))
1927 java_mangle_decl (decl);
1928 if (DECL_RTL_SET_P (decl))
1930 SET_DECL_RTL (decl, 0);
1931 make_decl_rtl (decl);
1935 /* Use the preceding two functions and mark all members of the class. */
1937 void
1938 java_mark_class_local (tree klass)
1940 tree t;
1942 for (t = TYPE_FIELDS (klass); t ; t = DECL_CHAIN (t))
1943 if (FIELD_STATIC (t))
1944 java_mark_decl_local (t);
1946 for (t = TYPE_METHODS (klass); t ; t = DECL_CHAIN (t))
1947 if (!METHOD_ABSTRACT (t))
1949 if (METHOD_NATIVE (t) && !flag_jni)
1950 java_mark_cni_decl_local (t);
1951 else
1952 java_mark_decl_local (t);
1956 /* Add a statement to a compound_expr. */
1958 tree
1959 add_stmt_to_compound (tree existing, tree type, tree stmt)
1961 if (!stmt)
1962 return existing;
1963 else if (existing)
1965 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
1966 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
1967 | TREE_SIDE_EFFECTS (stmt);
1968 return expr;
1970 else
1971 return stmt;
1974 /* If this node is an expr, mark its input location. Called from
1975 walk_tree(). */
1977 static tree
1978 set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
1979 void *data ATTRIBUTE_UNUSED)
1981 tree t = *tp;
1983 if (CAN_HAVE_LOCATION_P (t))
1985 if (EXPR_HAS_LOCATION(t))
1986 return t; /* Don't walk any further into this expr. */
1987 else
1988 SET_EXPR_LOCATION (t, input_location);
1991 return NULL_TREE; /* Continue walking this expr. */
1994 /* Add a statement to the statement_list currently being constructed.
1995 If the statement_list is null, we don't create a singleton list.
1996 This is necessary because poplevel() assumes that adding a
1997 statement to a null statement_list returns the statement. */
1999 tree
2000 java_add_stmt (tree new_stmt)
2002 tree stmts = current_binding_level->stmts;
2003 tree_stmt_iterator i;
2005 if (LOCATION_FILE (input_location))
2006 walk_tree (&new_stmt, set_input_location, NULL, NULL);
2008 if (stmts == NULL)
2009 return current_binding_level->stmts = new_stmt;
2011 /* Force STMTS to be a statement_list. */
2012 if (TREE_CODE (stmts) != STATEMENT_LIST)
2014 tree t = make_node (STATEMENT_LIST);
2015 i = tsi_last (t);
2016 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2017 stmts = t;
2020 i = tsi_last (stmts);
2021 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2022 TREE_TYPE (stmts) = void_type_node;
2024 return current_binding_level->stmts = stmts;
2027 /* Add a variable to the current scope. */
2029 tree
2030 java_add_local_var (tree decl)
2032 tree *vars = &current_binding_level->names;
2033 tree next = *vars;
2034 DECL_CHAIN (decl) = next;
2035 *vars = decl;
2036 DECL_CONTEXT (decl) = current_function_decl;
2037 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2038 return decl;
2041 /* Return a pointer to the compound_expr currently being
2042 constructed. */
2044 tree *
2045 get_stmts (void)
2047 return &current_binding_level->stmts;
2050 /* Register an exception range as belonging to the current binding
2051 level. There may only be one: if there are more, we'll create more
2052 binding levels. However, each range can have multiple handlers,
2053 and these are expanded when we call expand_end_java_handler(). */
2055 void
2056 register_exception_range (struct eh_range *range, int pc, int end_pc)
2058 gcc_assert (! current_binding_level->exception_range);
2059 current_binding_level->exception_range = range;
2060 current_binding_level->end_pc = end_pc;
2061 current_binding_level->start_pc = pc;
2064 #include "gt-java-decl.h"