gcc/java/
[official-gcc.git] / gcc / java / decl.c
blob3c1e7eaef9cd62907043c56689694f2302da7efe
1 /* Process declarations and variables for the GNU compiler for the
2 Java(TM) language.
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007,
4 2005, 2006, 2007, 2008 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)
11 any later version.
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. */
28 #include "config.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "tm.h"
32 #include "tree.h"
33 #include "rtl.h"
34 #include "real.h"
35 #include "toplev.h"
36 #include "flags.h"
37 #include "java-tree.h"
38 #include "jcf.h"
39 #include "function.h"
40 #include "expr.h"
41 #include "libfuncs.h"
42 #include "except.h"
43 #include "java-except.h"
44 #include "ggc.h"
45 #include "timevar.h"
46 #include "cgraph.h"
47 #include "tree-inline.h"
48 #include "target.h"
49 #include "version.h"
50 #include "tree-iterator.h"
51 #include "langhooks.h"
52 #include "cgraph.h"
54 #if defined (DEBUG_JAVA_BINDING_LEVELS)
55 extern void indent (void);
56 #endif
58 static tree push_jvm_slot (int, tree);
59 static tree lookup_name_current_level (tree);
60 static tree push_promoted_type (const char *, tree);
61 static struct binding_level *make_binding_level (void);
62 static tree create_primitive_vtable (const char *);
63 static tree check_local_unnamed_variable (tree, tree, tree);
64 static void parse_version (void);
67 /* The following ABI flags are used in the high-order bits of the version
68 ID field. The version ID number itself should never be larger than
69 0xfffff, so it should be safe to use top 12 bits for these flags. */
71 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
73 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
74 should be loaded by the bootstrap
75 loader. */
77 /* If an ABI change is made within a GCC release series, rendering current
78 binaries incompatible with the old runtimes, this number must be set to
79 enforce the compatibility rules. */
80 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
82 /* The runtime may recognize a variety of BC ABIs (objects generated by
83 different version of gcj), but will probably always require strict
84 matching for the ordinary (C++) ABI. */
86 /* The version ID of the BC ABI that we generate. This must be kept in
87 sync with parse_version(), libgcj, and reality (if the BC format changes,
88 this must change). */
89 #define GCJ_CURRENT_BC_ABI_VERSION \
90 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
92 /* The ABI version number. */
93 tree gcj_abi_version;
95 /* Name of the Cloneable class. */
96 tree java_lang_cloneable_identifier_node;
98 /* Name of the Serializable class. */
99 tree java_io_serializable_identifier_node;
101 /* The DECL_MAP is a mapping from (index, type) to a decl node.
102 If index < max_locals, it is the index of a local variable.
103 if index >= max_locals, then index-max_locals is a stack slot.
104 The DECL_MAP mapping is represented as a TREE_VEC whose elements
105 are a list of decls (VAR_DECL or PARM_DECL) chained by
106 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
107 we search the chain for a decl with a matching TREE_TYPE. */
109 static GTY(()) tree decl_map;
111 /* The base_decl_map is contains one variable of ptr_type: this is
112 used to contain every variable of reference type that is ever
113 stored in a local variable slot. */
115 static GTY(()) tree base_decl_map;
117 /* An index used to make temporary identifiers unique. */
118 static int uniq;
120 /* A list of local variables VAR_DECLs for this method that we have seen
121 debug information, but we have not reached their starting (byte) PC yet. */
123 static GTY(()) tree pending_local_decls;
125 /* The decl for "_Jv_ResolvePoolEntry". */
126 tree soft_resolvepoolentry_node;
128 /* The decl for the .constants field of an instance of Class. */
129 tree constants_field_decl_node;
131 /* The decl for the .data field of an instance of Class. */
132 tree constants_data_field_decl_node;
134 #if defined(DEBUG_JAVA_BINDING_LEVELS)
135 int binding_depth = 0;
136 int is_class_level = 0;
137 int current_pc;
139 void
140 indent (void)
142 int i;
144 for (i = 0; i < binding_depth*2; i++)
145 putc (' ', stderr);
147 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
149 /* True if decl is a named local variable, i.e. if it is an alias
150 that's used only for debugging purposes. */
152 static bool
153 debug_variable_p (tree decl)
155 if (TREE_CODE (decl) == PARM_DECL)
156 return false;
158 if (LOCAL_SLOT_P (decl))
159 return false;
161 return true;
164 static tree
165 push_jvm_slot (int index, tree decl)
167 DECL_CONTEXT (decl) = current_function_decl;
168 layout_decl (decl, 0);
170 /* Now link the decl into the decl_map. */
171 if (DECL_LANG_SPECIFIC (decl) == NULL)
173 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
174 DECL_LOCAL_START_PC (decl) = 0;
175 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
176 DECL_LOCAL_SLOT_NUMBER (decl) = index;
178 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
179 TREE_VEC_ELT (decl_map, index) = decl;
181 return decl;
184 /* Find the best declaration based upon type. If 'decl' fits 'type' better
185 than 'best', return 'decl'. Otherwise return 'best'. */
187 static tree
188 check_local_unnamed_variable (tree best, tree decl, tree type)
190 tree decl_type = TREE_TYPE (decl);
192 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
194 /* Use the same decl for all integer types <= 32 bits. This is
195 necessary because sometimes a value is stored as (for example)
196 boolean but loaded as int. */
197 if (decl_type == type
198 || (INTEGRAL_TYPE_P (decl_type)
199 && INTEGRAL_TYPE_P (type)
200 && TYPE_PRECISION (decl_type) <= 32
201 && TYPE_PRECISION (type) <= 32
202 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
203 /* ptr_type_node is used for null pointers, which are
204 assignment compatible with everything. */
205 || (TREE_CODE (decl_type) == POINTER_TYPE
206 && type == ptr_type_node)
207 /* Whenever anyone wants to use a slot that is initially
208 occupied by a PARM_DECL of pointer type they must get that
209 decl, even if they asked for a pointer to a different type.
210 However, if someone wants a scalar variable in a slot that
211 initially held a pointer arg -- or vice versa -- we create a
212 new VAR_DECL.
214 ???: As long as verification is correct, this will be a
215 compatible type. But maybe we should create a dummy variable
216 and replace all references to it with the DECL and a
217 NOP_EXPR.
219 || (TREE_CODE (decl_type) == POINTER_TYPE
220 && TREE_CODE (decl) == PARM_DECL
221 && TREE_CODE (type) == POINTER_TYPE))
223 if (best == NULL_TREE
224 || (decl_type == type && TREE_TYPE (best) != type))
225 return decl;
228 return best;
232 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
233 that is valid at PC (or -1 if any pc).
234 If there is no existing matching decl, allocate one. */
236 tree
237 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
239 tree tmp = TREE_VEC_ELT (decl_map, index);
240 tree decl = NULL_TREE;
242 /* Scan through every declaration that has been created in this
243 slot. We're only looking for variables that correspond to local
244 index declarations and PARM_DECLs, not named variables: such
245 local variables are used only for debugging information. */
246 while (tmp != NULL_TREE)
248 if (! debug_variable_p (tmp))
249 decl = check_local_unnamed_variable (decl, tmp, type);
250 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
253 /* gcj has a function called promote_type(), which is used by both
254 the bytecode compiler and the source compiler. Unfortunately,
255 the type systems for the Java VM and the Java language are not
256 the same: a boolean in the VM promotes to an int, not to a wide
257 boolean. If our caller wants something to hold a boolean, that
258 had better be an int, because that slot might be re-used
259 later in integer context. */
260 if (TREE_CODE (type) == BOOLEAN_TYPE)
261 type = integer_type_node;
263 /* If we don't find a match, create one with the type passed in.
264 The name of the variable is #n#m, which n is the variable index
265 in the local variable area and m is a dummy identifier for
266 uniqueness -- multiple variables may share the same local
267 variable index. We don't call pushdecl() to push pointer types
268 into a binding expr because they'll all be replaced by a single
269 variable that is used for every reference in that local variable
270 slot. */
271 if (! decl)
273 char buf[64];
274 tree name;
275 sprintf (buf, "#slot#%d#%d", index, uniq++);
276 name = get_identifier (buf);
277 decl = build_decl (input_location, VAR_DECL, name, type);
278 DECL_IGNORED_P (decl) = 1;
279 DECL_ARTIFICIAL (decl) = 1;
280 decl = push_jvm_slot (index, decl);
281 LOCAL_SLOT_P (decl) = 1;
283 if (TREE_CODE (type) != POINTER_TYPE)
284 pushdecl_function_level (decl);
287 /* As well as creating a local variable that matches the type, we
288 also create a base variable (of ptr_type) that will hold all its
289 aliases. */
290 if (TREE_CODE (type) == POINTER_TYPE
291 && ! TREE_VEC_ELT (base_decl_map, index))
293 char buf[64];
294 tree name;
295 tree base_decl;
296 sprintf (buf, "#ref#%d#%d", index, uniq++);
297 name = get_identifier (buf);
298 base_decl
299 = TREE_VEC_ELT (base_decl_map, index)
300 = build_decl (input_location, VAR_DECL, name, ptr_type_node);
301 pushdecl_function_level (base_decl);
302 DECL_IGNORED_P (base_decl) = 1;
303 DECL_ARTIFICIAL (base_decl) = 1;
306 return decl;
309 /* Called during gimplification for every variable. If the variable
310 is a temporary of pointer type, replace it with a common variable
311 thath is used to hold all pointer types that are ever stored in
312 that slot. Set WANT_LVALUE if you want a variable that is to be
313 written to. */
315 tree
316 java_replace_reference (tree var_decl, bool want_lvalue)
318 tree decl_type;
320 if (! base_decl_map)
321 return var_decl;
323 decl_type = TREE_TYPE (var_decl);
325 if (TREE_CODE (decl_type) == POINTER_TYPE)
327 if (DECL_LANG_SPECIFIC (var_decl)
328 && LOCAL_SLOT_P (var_decl))
330 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
331 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
333 gcc_assert (base_decl);
334 if (! want_lvalue)
335 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
337 return base_decl;
341 return var_decl;
345 /* Same as find_local_index, except that INDEX is a stack index. */
347 tree
348 find_stack_slot (int index, tree type)
350 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
351 type, -1);
354 struct GTY(())
355 binding_level {
356 /* A chain of _DECL nodes for all variables, constants, functions,
357 * and typedef types. These are in the reverse of the order supplied.
359 tree names;
361 /* For each level, a list of shadowed outer-level local definitions
362 to be restored when this level is popped.
363 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
364 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
365 tree shadowed;
367 /* For each level (except not the global one),
368 a chain of BLOCK nodes for all the levels
369 that were entered and exited one level down. */
370 tree blocks;
372 /* The binding level which this one is contained in (inherits from). */
373 struct binding_level *level_chain;
375 /* The bytecode PC that marks the end of this level. */
376 int end_pc;
377 /* The bytecode PC that marks the start of this level. */
378 int start_pc;
380 /* The statements in this binding level. */
381 tree stmts;
383 /* An exception range associated with this binding level. */
384 struct eh_range * GTY((skip (""))) exception_range;
386 /* Binding depth at which this level began. Used only for debugging. */
387 unsigned binding_depth;
390 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
392 /* The binding level currently in effect. */
394 static GTY(()) struct binding_level *current_binding_level;
396 /* A chain of binding_level structures awaiting reuse. */
398 static GTY(()) struct binding_level *free_binding_level;
400 /* The outermost binding level, for names of file scope.
401 This is created when the compiler is started and exists
402 through the entire run. */
404 static GTY(()) struct binding_level *global_binding_level;
406 /* The binding level that holds variables declared at the outermost
407 level within a function body. */
409 static struct binding_level *function_binding_level;
411 /* A PC value bigger than any PC value we may ever may encounter. */
413 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
415 /* Binding level structures are initialized by copying this one. */
417 static const struct binding_level clear_binding_level
419 NULL_TREE, /* names */
420 NULL_TREE, /* shadowed */
421 NULL_TREE, /* blocks */
422 NULL_BINDING_LEVEL, /* level_chain */
423 LARGEST_PC, /* end_pc */
424 0, /* start_pc */
425 NULL, /* stmts */
426 NULL, /* exception_range */
427 0, /* binding_depth */
430 tree java_global_trees[JTI_MAX];
432 /* Build (and pushdecl) a "promoted type" for all standard
433 types shorter than int. */
435 static tree
436 push_promoted_type (const char *name, tree actual_type)
438 tree type = make_node (TREE_CODE (actual_type));
439 #if 1
440 tree in_min = TYPE_MIN_VALUE (int_type_node);
441 tree in_max = TYPE_MAX_VALUE (int_type_node);
442 #else
443 tree in_min = TYPE_MIN_VALUE (actual_type);
444 tree in_max = TYPE_MAX_VALUE (actual_type);
445 #endif
446 TYPE_MIN_VALUE (type) = copy_node (in_min);
447 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
448 TYPE_MAX_VALUE (type) = copy_node (in_max);
449 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
450 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
451 TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
452 layout_type (type);
453 pushdecl (build_decl (input_location,
454 TYPE_DECL, get_identifier (name), type));
455 return type;
458 /* Return tree that represents a vtable for a primitive array. */
459 static tree
460 create_primitive_vtable (const char *name)
462 tree r;
463 char buf[50];
465 sprintf (buf, "_Jv_%sVTable", name);
466 r = build_decl (input_location,
467 VAR_DECL, get_identifier (buf), ptr_type_node);
468 DECL_EXTERNAL (r) = 1;
469 return r;
472 static tree
473 do_nothing (tree t)
475 return t;
478 /* Parse the version string and compute the ABI version number. */
479 static void
480 parse_version (void)
482 const char *p = version_string;
483 unsigned int major = 0, minor = 0;
484 unsigned int abi_version;
486 /* Skip leading junk. */
487 while (*p && !ISDIGIT (*p))
488 ++p;
489 gcc_assert (*p);
491 /* Extract major version. */
492 while (ISDIGIT (*p))
494 major = major * 10 + *p - '0';
495 ++p;
498 gcc_assert (*p == '.' && ISDIGIT (p[1]));
499 ++p;
501 /* Extract minor version. */
502 while (ISDIGIT (*p))
504 minor = minor * 10 + *p - '0';
505 ++p;
508 if (flag_indirect_dispatch)
510 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
511 abi_version |= FLAG_BINARYCOMPAT_ABI;
513 else /* C++ ABI */
515 /* Implicit in this computation is the idea that we won't break the
516 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
517 4.0.1). */
518 abi_version = 100000 * major + 1000 * minor;
520 if (flag_bootstrap_classes)
521 abi_version |= FLAG_BOOTSTRAP_LOADER;
523 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
526 void
527 java_init_decl_processing (void)
529 tree endlink;
530 tree field = NULL_TREE;
531 tree t;
533 init_class_processing ();
535 current_function_decl = NULL;
536 current_binding_level = NULL_BINDING_LEVEL;
537 free_binding_level = NULL_BINDING_LEVEL;
538 pushlevel (0); /* make the binding_level structure for global names */
539 global_binding_level = current_binding_level;
541 /* The code here must be similar to build_common_tree_nodes{,_2} in
542 tree.c, especially as to the order of initializing common nodes. */
543 error_mark_node = make_node (ERROR_MARK);
544 TREE_TYPE (error_mark_node) = error_mark_node;
546 /* Create sizetype first - needed for other types. */
547 initialize_sizetypes (false);
549 byte_type_node = make_signed_type (8);
550 pushdecl (build_decl (BUILTINS_LOCATION,
551 TYPE_DECL, get_identifier ("byte"), byte_type_node));
552 short_type_node = make_signed_type (16);
553 pushdecl (build_decl (BUILTINS_LOCATION,
554 TYPE_DECL, get_identifier ("short"), short_type_node));
555 int_type_node = make_signed_type (32);
556 pushdecl (build_decl (BUILTINS_LOCATION,
557 TYPE_DECL, get_identifier ("int"), int_type_node));
558 long_type_node = make_signed_type (64);
559 pushdecl (build_decl (BUILTINS_LOCATION,
560 TYPE_DECL, get_identifier ("long"), long_type_node));
562 unsigned_byte_type_node = make_unsigned_type (8);
563 pushdecl (build_decl (BUILTINS_LOCATION,
564 TYPE_DECL, get_identifier ("unsigned byte"),
565 unsigned_byte_type_node));
566 unsigned_short_type_node = make_unsigned_type (16);
567 pushdecl (build_decl (BUILTINS_LOCATION,
568 TYPE_DECL, get_identifier ("unsigned short"),
569 unsigned_short_type_node));
570 unsigned_int_type_node = make_unsigned_type (32);
571 pushdecl (build_decl (BUILTINS_LOCATION,
572 TYPE_DECL, get_identifier ("unsigned int"),
573 unsigned_int_type_node));
574 unsigned_long_type_node = make_unsigned_type (64);
575 pushdecl (build_decl (BUILTINS_LOCATION,
576 TYPE_DECL, get_identifier ("unsigned long"),
577 unsigned_long_type_node));
579 /* This is not a java type, however tree-dfa requires a definition for
580 size_type_node. */
581 size_type_node = make_unsigned_type (POINTER_SIZE);
582 set_sizetype (size_type_node);
584 /* Define these next since types below may used them. */
585 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
586 integer_zero_node = build_int_cst (NULL_TREE, 0);
587 integer_one_node = build_int_cst (NULL_TREE, 1);
588 integer_two_node = build_int_cst (NULL_TREE, 2);
589 integer_four_node = build_int_cst (NULL_TREE, 4);
590 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
592 /* A few values used for range checking in the lexer. */
593 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
594 #if HOST_BITS_PER_WIDE_INT == 64
595 decimal_long_max = build_int_cstu (unsigned_long_type_node,
596 0x8000000000000000LL);
597 #elif HOST_BITS_PER_WIDE_INT == 32
598 decimal_long_max = build_int_cst_wide (unsigned_long_type_node,
599 0, 0x80000000);
600 #else
601 #error "unsupported size"
602 #endif
604 size_zero_node = size_int (0);
605 size_one_node = size_int (1);
606 bitsize_zero_node = bitsize_int (0);
607 bitsize_one_node = bitsize_int (1);
608 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
610 long_zero_node = build_int_cst (long_type_node, 0);
612 void_type_node = make_node (VOID_TYPE);
613 pushdecl (build_decl (BUILTINS_LOCATION,
614 TYPE_DECL, get_identifier ("void"), void_type_node));
615 layout_type (void_type_node); /* Uses size_zero_node */
617 ptr_type_node = build_pointer_type (void_type_node);
618 const_ptr_type_node
619 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
621 t = make_node (VOID_TYPE);
622 layout_type (t); /* Uses size_zero_node */
623 return_address_type_node = build_pointer_type (t);
625 null_pointer_node = build_int_cst (ptr_type_node, 0);
627 char_type_node = make_node (INTEGER_TYPE);
628 TYPE_STRING_FLAG (char_type_node) = 1;
629 TYPE_PRECISION (char_type_node) = 16;
630 fixup_unsigned_type (char_type_node);
631 pushdecl (build_decl (BUILTINS_LOCATION,
632 TYPE_DECL, get_identifier ("char"), char_type_node));
634 boolean_type_node = make_node (BOOLEAN_TYPE);
635 TYPE_PRECISION (boolean_type_node) = 1;
636 fixup_unsigned_type (boolean_type_node);
637 pushdecl (build_decl (BUILTINS_LOCATION,
638 TYPE_DECL, get_identifier ("boolean"),
639 boolean_type_node));
640 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
641 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
643 promoted_byte_type_node
644 = push_promoted_type ("promoted_byte", byte_type_node);
645 promoted_short_type_node
646 = push_promoted_type ("promoted_short", short_type_node);
647 promoted_char_type_node
648 = push_promoted_type ("promoted_char", char_type_node);
649 promoted_boolean_type_node
650 = push_promoted_type ("promoted_boolean", boolean_type_node);
652 float_type_node = make_node (REAL_TYPE);
653 TYPE_PRECISION (float_type_node) = 32;
654 pushdecl (build_decl (BUILTINS_LOCATION,
655 TYPE_DECL, get_identifier ("float"),
656 float_type_node));
657 layout_type (float_type_node);
659 double_type_node = make_node (REAL_TYPE);
660 TYPE_PRECISION (double_type_node) = 64;
661 pushdecl (build_decl (BUILTINS_LOCATION,
662 TYPE_DECL, get_identifier ("double"),
663 double_type_node));
664 layout_type (double_type_node);
666 float_zero_node = build_real (float_type_node, dconst0);
667 double_zero_node = build_real (double_type_node, dconst0);
669 /* These are the vtables for arrays of primitives. */
670 boolean_array_vtable = create_primitive_vtable ("boolean");
671 byte_array_vtable = create_primitive_vtable ("byte");
672 char_array_vtable = create_primitive_vtable ("char");
673 short_array_vtable = create_primitive_vtable ("short");
674 int_array_vtable = create_primitive_vtable ("int");
675 long_array_vtable = create_primitive_vtable ("long");
676 float_array_vtable = create_primitive_vtable ("float");
677 double_array_vtable = create_primitive_vtable ("double");
679 one_elt_array_domain_type = build_index_type (integer_one_node);
680 utf8const_type = make_node (RECORD_TYPE);
681 PUSH_FIELD (input_location,
682 utf8const_type, field, "hash", unsigned_short_type_node);
683 PUSH_FIELD (input_location,
684 utf8const_type, field, "length", unsigned_short_type_node);
685 FINISH_RECORD (utf8const_type);
686 utf8const_ptr_type = build_pointer_type (utf8const_type);
688 atable_type = build_array_type (ptr_type_node,
689 one_elt_array_domain_type);
690 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
691 atable_ptr_type = build_pointer_type (atable_type);
693 itable_type = build_array_type (ptr_type_node,
694 one_elt_array_domain_type);
695 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
696 itable_ptr_type = build_pointer_type (itable_type);
698 symbol_type = make_node (RECORD_TYPE);
699 PUSH_FIELD (input_location,
700 symbol_type, field, "clname", utf8const_ptr_type);
701 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
702 PUSH_FIELD (input_location,
703 symbol_type, field, "signature", utf8const_ptr_type);
704 FINISH_RECORD (symbol_type);
706 symbols_array_type = build_array_type (symbol_type,
707 one_elt_array_domain_type);
708 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
710 assertion_entry_type = make_node (RECORD_TYPE);
711 PUSH_FIELD (input_location,
712 assertion_entry_type, field, "assertion_code", integer_type_node);
713 PUSH_FIELD (input_location,
714 assertion_entry_type, field, "op1", utf8const_ptr_type);
715 PUSH_FIELD (input_location,
716 assertion_entry_type, field, "op2", utf8const_ptr_type);
717 FINISH_RECORD (assertion_entry_type);
719 assertion_table_type = build_array_type (assertion_entry_type,
720 one_elt_array_domain_type);
722 /* As you're adding items here, please update the code right after
723 this section, so that the filename containing the source code of
724 the pre-defined class gets registered correctly. */
725 unqualified_object_id_node = get_identifier ("Object");
726 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
727 object_ptr_type_node = promote_type (object_type_node);
728 string_type_node = lookup_class (get_identifier ("java.lang.String"));
729 string_ptr_type_node = promote_type (string_type_node);
730 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
731 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
732 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
733 runtime_exception_type_node =
734 lookup_class (get_identifier ("java.lang.RuntimeException"));
735 error_exception_type_node =
736 lookup_class (get_identifier ("java.lang.Error"));
738 rawdata_ptr_type_node
739 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
741 add_predefined_file (get_identifier ("java/lang/Class.java"));
742 add_predefined_file (get_identifier ("java/lang/Error.java"));
743 add_predefined_file (get_identifier ("java/lang/Object.java"));
744 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
745 add_predefined_file (get_identifier ("java/lang/String.java"));
746 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
747 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
748 add_predefined_file (get_identifier ("java/lang/Exception.java"));
749 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
750 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
752 methodtable_type = make_node (RECORD_TYPE);
753 layout_type (methodtable_type);
754 build_decl (BUILTINS_LOCATION,
755 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
756 methodtable_ptr_type = build_pointer_type (methodtable_type);
758 TYPE_identifier_node = get_identifier ("TYPE");
759 init_identifier_node = get_identifier ("<init>");
760 clinit_identifier_node = get_identifier ("<clinit>");
761 void_signature_node = get_identifier ("()V");
762 finalize_identifier_node = get_identifier ("finalize");
763 this_identifier_node = get_identifier ("this");
765 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
766 java_io_serializable_identifier_node =
767 get_identifier ("java.io.Serializable");
769 /* for lack of a better place to put this stub call */
770 init_expr_processing();
772 constants_type_node = make_node (RECORD_TYPE);
773 PUSH_FIELD (input_location,
774 constants_type_node, field, "size", unsigned_int_type_node);
775 PUSH_FIELD (input_location,
776 constants_type_node, field, "tags", ptr_type_node);
777 PUSH_FIELD (input_location,
778 constants_type_node, field, "data", ptr_type_node);
779 constants_data_field_decl_node = field;
780 FINISH_RECORD (constants_type_node);
781 build_decl (BUILTINS_LOCATION,
782 TYPE_DECL, get_identifier ("constants"), constants_type_node);
784 access_flags_type_node = unsigned_short_type_node;
786 dtable_type = make_node (RECORD_TYPE);
787 dtable_ptr_type = build_pointer_type (dtable_type);
789 otable_type = build_array_type (integer_type_node,
790 one_elt_array_domain_type);
791 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
792 otable_ptr_type = build_pointer_type (otable_type);
794 PUSH_FIELD (input_location,
795 object_type_node, field, "vtable", dtable_ptr_type);
796 DECL_FCONTEXT (field) = object_type_node;
797 TYPE_VFIELD (object_type_node) = field;
799 /* This isn't exactly true, but it is what we have in the source.
800 There is an unresolved issue here, which is whether the vtable
801 should be marked by the GC. */
802 if (! flag_hash_synchronization)
803 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
804 build_pointer_type (object_type_node));
805 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
806 FIELD_PRIVATE (t) = 1;
807 FINISH_RECORD (object_type_node);
809 field_type_node = make_node (RECORD_TYPE);
810 field_ptr_type_node = build_pointer_type (field_type_node);
811 method_type_node = make_node (RECORD_TYPE);
812 method_ptr_type_node = build_pointer_type (method_type_node);
814 set_super_info (0, class_type_node, object_type_node, 0);
815 set_super_info (0, string_type_node, object_type_node, 0);
816 class_ptr_type = build_pointer_type (class_type_node);
818 PUSH_FIELD (input_location,
819 class_type_node, field, "next_or_version", class_ptr_type);
820 PUSH_FIELD (input_location,
821 class_type_node, field, "name", utf8const_ptr_type);
822 PUSH_FIELD (input_location,
823 class_type_node, field, "accflags", access_flags_type_node);
824 PUSH_FIELD (input_location,
825 class_type_node, field, "superclass", class_ptr_type);
826 PUSH_FIELD (input_location,
827 class_type_node, field, "constants", constants_type_node);
828 constants_field_decl_node = field;
829 PUSH_FIELD (input_location,
830 class_type_node, field, "methods", method_ptr_type_node);
831 PUSH_FIELD (input_location,
832 class_type_node, field, "method_count", short_type_node);
833 PUSH_FIELD (input_location,
834 class_type_node, field, "vtable_method_count", short_type_node);
835 PUSH_FIELD (input_location,
836 class_type_node, field, "fields", field_ptr_type_node);
837 PUSH_FIELD (input_location,
838 class_type_node, field, "size_in_bytes", int_type_node);
839 PUSH_FIELD (input_location,
840 class_type_node, field, "field_count", short_type_node);
841 PUSH_FIELD (input_location,
842 class_type_node, field, "static_field_count", short_type_node);
843 PUSH_FIELD (input_location,
844 class_type_node, field, "vtable", dtable_ptr_type);
845 PUSH_FIELD (input_location,
846 class_type_node, field, "otable", otable_ptr_type);
847 PUSH_FIELD (input_location,
848 class_type_node, field, "otable_syms",
849 symbols_array_ptr_type);
850 PUSH_FIELD (input_location,
851 class_type_node, field, "atable", atable_ptr_type);
852 PUSH_FIELD (input_location,
853 class_type_node, field, "atable_syms",
854 symbols_array_ptr_type);
855 PUSH_FIELD (input_location,
856 class_type_node, field, "itable", itable_ptr_type);
857 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
858 symbols_array_ptr_type);
859 PUSH_FIELD (input_location,
860 class_type_node, field, "catch_classes", ptr_type_node);
861 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
862 build_pointer_type (class_ptr_type));
863 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
864 PUSH_FIELD (input_location,
865 class_type_node, field, "interface_count", short_type_node);
866 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
867 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
868 PUSH_FIELD (input_location,
869 class_type_node, field, "depth", short_type_node);
870 PUSH_FIELD (input_location,
871 class_type_node, field, "ancestors", ptr_type_node);
872 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
873 PUSH_FIELD (input_location,
874 class_type_node, field, "arrayclass", ptr_type_node);
875 PUSH_FIELD (input_location,
876 class_type_node, field, "protectionDomain", ptr_type_node);
877 PUSH_FIELD (input_location,
878 class_type_node, field, "assertion_table", ptr_type_node);
879 PUSH_FIELD (input_location,
880 class_type_node, field, "hack_signers", ptr_type_node);
881 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
882 PUSH_FIELD (input_location,
883 class_type_node, field, "aux_info", ptr_type_node);
884 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
885 PUSH_FIELD (input_location,
886 class_type_node, field, "reflection_data", ptr_type_node);
887 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
888 FIELD_PRIVATE (t) = 1;
889 push_super_field (class_type_node, object_type_node);
891 FINISH_RECORD (class_type_node);
892 build_decl (BUILTINS_LOCATION,
893 TYPE_DECL, get_identifier ("Class"), class_type_node);
895 field_info_union_node = make_node (UNION_TYPE);
896 PUSH_FIELD (input_location,
897 field_info_union_node, field, "boffset", int_type_node);
898 PUSH_FIELD (input_location,
899 field_info_union_node, field, "addr", ptr_type_node);
900 layout_type (field_info_union_node);
902 PUSH_FIELD (input_location,
903 field_type_node, field, "name", utf8const_ptr_type);
904 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
905 PUSH_FIELD (input_location,
906 field_type_node, field, "accflags", access_flags_type_node);
907 PUSH_FIELD (input_location,
908 field_type_node, field, "bsize", unsigned_short_type_node);
909 PUSH_FIELD (input_location,
910 field_type_node, field, "info", field_info_union_node);
911 FINISH_RECORD (field_type_node);
912 build_decl (BUILTINS_LOCATION,
913 TYPE_DECL, get_identifier ("Field"), field_type_node);
915 nativecode_ptr_array_type_node
916 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
918 PUSH_FIELD (input_location,
919 dtable_type, field, "class", class_ptr_type);
920 PUSH_FIELD (input_location,
921 dtable_type, field, "methods", nativecode_ptr_array_type_node);
922 FINISH_RECORD (dtable_type);
923 build_decl (BUILTINS_LOCATION,
924 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
926 jexception_type = make_node (RECORD_TYPE);
927 PUSH_FIELD (input_location,
928 jexception_type, field, "start_pc", ptr_type_node);
929 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
930 PUSH_FIELD (input_location,
931 jexception_type, field, "handler_pc", ptr_type_node);
932 PUSH_FIELD (input_location,
933 jexception_type, field, "catch_type", class_ptr_type);
934 FINISH_RECORD (jexception_type);
935 build_decl (BUILTINS_LOCATION,
936 TYPE_DECL, get_identifier ("jexception"), field_type_node);
937 jexception_ptr_type = build_pointer_type (jexception_type);
939 lineNumberEntry_type = make_node (RECORD_TYPE);
940 PUSH_FIELD (input_location,
941 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
942 PUSH_FIELD (input_location,
943 lineNumberEntry_type, field, "start_pc", ptr_type_node);
944 FINISH_RECORD (lineNumberEntry_type);
946 lineNumbers_type = make_node (RECORD_TYPE);
947 PUSH_FIELD (input_location,
948 lineNumbers_type, field, "length", unsigned_int_type_node);
949 FINISH_RECORD (lineNumbers_type);
951 PUSH_FIELD (input_location,
952 method_type_node, field, "name", utf8const_ptr_type);
953 PUSH_FIELD (input_location,
954 method_type_node, field, "signature", utf8const_ptr_type);
955 PUSH_FIELD (input_location,
956 method_type_node, field, "accflags", access_flags_type_node);
957 PUSH_FIELD (input_location,
958 method_type_node, field, "index", unsigned_short_type_node);
959 PUSH_FIELD (input_location,
960 method_type_node, field, "ncode", nativecode_ptr_type_node);
961 PUSH_FIELD (input_location,
962 method_type_node, field, "throws", ptr_type_node);
963 FINISH_RECORD (method_type_node);
964 build_decl (BUILTINS_LOCATION,
965 TYPE_DECL, get_identifier ("Method"), method_type_node);
967 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
969 t = tree_cons (NULL_TREE, class_ptr_type, endlink);
970 alloc_object_node = add_builtin_function ("_Jv_AllocObject",
971 build_function_type (ptr_type_node, 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",
976 build_function_type (ptr_type_node, t),
977 0, NOT_BUILT_IN, NULL, NULL_TREE);
978 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
980 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
981 soft_initclass_node = add_builtin_function ("_Jv_InitClass",
982 build_function_type (void_type_node,
984 0, NOT_BUILT_IN, NULL, NULL_TREE);
985 t = tree_cons (NULL_TREE, class_ptr_type,
986 tree_cons (NULL_TREE, int_type_node, endlink));
987 soft_resolvepoolentry_node
988 = add_builtin_function ("_Jv_ResolvePoolEntry",
989 build_function_type (ptr_type_node, t),
990 0,NOT_BUILT_IN, NULL, NULL_TREE);
991 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
992 throw_node = add_builtin_function ("_Jv_Throw",
993 build_function_type (void_type_node, t),
994 0, NOT_BUILT_IN, NULL, NULL_TREE);
995 /* Mark throw_nodes as `noreturn' functions with side effects. */
996 TREE_THIS_VOLATILE (throw_node) = 1;
997 TREE_SIDE_EFFECTS (throw_node) = 1;
999 t = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node,
1000 endlink));
1001 soft_monitorenter_node
1002 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1003 NULL, NULL_TREE);
1004 soft_monitorexit_node
1005 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1006 NULL, NULL_TREE);
1008 t = tree_cons (NULL_TREE, ptr_type_node,
1009 tree_cons (NULL_TREE, int_type_node, endlink));
1010 soft_newarray_node
1011 = add_builtin_function ("_Jv_NewPrimArray",
1012 build_function_type (ptr_type_node, t),
1013 0, NOT_BUILT_IN, NULL, NULL_TREE);
1014 DECL_IS_MALLOC (soft_newarray_node) = 1;
1016 t = tree_cons (NULL_TREE, int_type_node,
1017 tree_cons (NULL_TREE, class_ptr_type,
1018 tree_cons (NULL_TREE, object_ptr_type_node,
1019 endlink)));
1020 soft_anewarray_node
1021 = add_builtin_function ("_Jv_NewObjectArray",
1022 build_function_type (ptr_type_node, t),
1023 0, NOT_BUILT_IN, NULL, NULL_TREE);
1024 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1026 /* There is no endlink here because _Jv_NewMultiArray is a varargs
1027 function. */
1028 t = tree_cons (NULL_TREE, ptr_type_node,
1029 tree_cons (NULL_TREE, int_type_node, NULL_TREE));
1030 soft_multianewarray_node
1031 = add_builtin_function ("_Jv_NewMultiArray",
1032 build_function_type (ptr_type_node, t),
1033 0, NOT_BUILT_IN, NULL, NULL_TREE);
1034 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1036 t = build_function_type (void_type_node,
1037 tree_cons (NULL_TREE, int_type_node, endlink));
1038 soft_badarrayindex_node
1039 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1040 0, NOT_BUILT_IN, NULL, NULL_TREE);
1041 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1042 effects. */
1043 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1044 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1046 soft_nullpointer_node
1047 = add_builtin_function ("_Jv_ThrowNullPointerException",
1048 build_function_type (void_type_node, endlink),
1049 0, NOT_BUILT_IN, NULL, NULL_TREE);
1050 /* Mark soft_nullpointer_node as a `noreturn' function with side
1051 effects. */
1052 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1053 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1055 soft_abstractmethod_node
1056 = add_builtin_function ("_Jv_ThrowAbstractMethodError",
1057 build_function_type (void_type_node, endlink),
1058 0, NOT_BUILT_IN, NULL, NULL_TREE);
1059 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1060 effects. */
1061 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1062 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1064 soft_nosuchfield_node
1065 = add_builtin_function ("_Jv_ThrowNoSuchFieldError",
1066 build_function_type (void_type_node, endlink),
1067 0, NOT_BUILT_IN, NULL, NULL_TREE);
1068 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1069 effects. */
1070 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1071 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1073 t = tree_cons (NULL_TREE, class_ptr_type,
1074 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1075 soft_checkcast_node
1076 = add_builtin_function ("_Jv_CheckCast",
1077 build_function_type (ptr_type_node, t),
1078 0, NOT_BUILT_IN, NULL, NULL_TREE);
1079 t = tree_cons (NULL_TREE, object_ptr_type_node,
1080 tree_cons (NULL_TREE, class_ptr_type, endlink));
1081 soft_instanceof_node
1082 = add_builtin_function ("_Jv_IsInstanceOf",
1083 build_function_type (boolean_type_node, t),
1084 0, NOT_BUILT_IN, NULL, NULL_TREE);
1085 DECL_PURE_P (soft_instanceof_node) = 1;
1086 t = tree_cons (NULL_TREE, object_ptr_type_node,
1087 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1088 soft_checkarraystore_node
1089 = add_builtin_function ("_Jv_CheckArrayStore",
1090 build_function_type (void_type_node, t),
1091 0, NOT_BUILT_IN, NULL, NULL_TREE);
1092 t = tree_cons (NULL_TREE, ptr_type_node,
1093 tree_cons (NULL_TREE, ptr_type_node,
1094 tree_cons (NULL_TREE, int_type_node, endlink)));
1095 soft_lookupinterfacemethod_node
1096 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx",
1097 build_function_type (ptr_type_node, t),
1098 0, NOT_BUILT_IN, NULL, NULL_TREE);
1099 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1100 t = tree_cons (NULL_TREE, ptr_type_node,
1101 tree_cons (NULL_TREE, ptr_type_node,
1102 tree_cons (NULL_TREE, ptr_type_node, endlink)));
1103 soft_lookupinterfacemethodbyname_node
1104 = add_builtin_function ("_Jv_LookupInterfaceMethod",
1105 build_function_type (ptr_type_node, t),
1106 0, NOT_BUILT_IN, NULL, NULL_TREE);
1107 t = tree_cons (NULL_TREE, object_ptr_type_node,
1108 tree_cons (NULL_TREE, ptr_type_node,
1109 tree_cons (NULL_TREE, ptr_type_node,
1110 tree_cons (NULL_TREE, int_type_node,
1111 endlink))));
1112 soft_lookupjnimethod_node
1113 = add_builtin_function ("_Jv_LookupJNIMethod",
1114 build_function_type (ptr_type_node, t),
1115 0, NOT_BUILT_IN, NULL, NULL_TREE);
1116 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1117 soft_getjnienvnewframe_node
1118 = add_builtin_function ("_Jv_GetJNIEnvNewFrame",
1119 build_function_type (ptr_type_node, t),
1120 0, NOT_BUILT_IN, NULL, NULL_TREE);
1121 soft_jnipopsystemframe_node
1122 = add_builtin_function ("_Jv_JNI_PopSystemFrame",
1123 build_function_type (void_type_node, t),
1124 0, NOT_BUILT_IN, NULL, NULL_TREE);
1126 t = tree_cons (NULL_TREE, object_ptr_type_node, endlink);
1127 soft_unwrapjni_node
1128 = add_builtin_function ("_Jv_UnwrapJNIweakReference",
1129 build_function_type (object_ptr_type_node, t),
1130 0, NOT_BUILT_IN, NULL, NULL_TREE);
1132 t = tree_cons (NULL_TREE, int_type_node,
1133 tree_cons (NULL_TREE, int_type_node, endlink));
1134 soft_idiv_node
1135 = add_builtin_function ("_Jv_divI",
1136 build_function_type (int_type_node, t),
1137 0, NOT_BUILT_IN, NULL, NULL_TREE);
1139 soft_irem_node
1140 = add_builtin_function ("_Jv_remI",
1141 build_function_type (int_type_node, t),
1142 0, NOT_BUILT_IN, NULL, NULL_TREE);
1144 t = tree_cons (NULL_TREE, long_type_node,
1145 tree_cons (NULL_TREE, long_type_node, endlink));
1146 soft_ldiv_node
1147 = add_builtin_function ("_Jv_divJ",
1148 build_function_type (long_type_node, t),
1149 0, NOT_BUILT_IN, NULL, NULL_TREE);
1151 soft_lrem_node
1152 = add_builtin_function ("_Jv_remJ",
1153 build_function_type (long_type_node, t),
1154 0, NOT_BUILT_IN, NULL, NULL_TREE);
1156 /* Initialize variables for except.c. */
1157 eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
1158 ? "__gcj_personality_sj0"
1159 : "__gcj_personality_v0");
1160 if (targetm.arm_eabi_unwinder)
1161 unwind_resume_libfunc = init_one_libfunc ("__cxa_end_cleanup");
1162 else
1163 default_init_unwind_resume_libfunc ();
1165 lang_eh_runtime_type = do_nothing;
1167 initialize_builtins ();
1168 soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1170 parse_version ();
1174 /* Look up NAME in the current binding level and its superiors
1175 in the namespace of variables, functions and typedefs.
1176 Return a ..._DECL node of some kind representing its definition,
1177 or return 0 if it is undefined. */
1179 tree
1180 lookup_name (tree name)
1182 tree val;
1183 if (current_binding_level != global_binding_level
1184 && IDENTIFIER_LOCAL_VALUE (name))
1185 val = IDENTIFIER_LOCAL_VALUE (name);
1186 else
1187 val = IDENTIFIER_GLOBAL_VALUE (name);
1188 return val;
1191 /* Similar to `lookup_name' but look only at current binding level and
1192 the previous one if it's the parameter level. */
1194 static tree
1195 lookup_name_current_level (tree name)
1197 tree t;
1199 if (current_binding_level == global_binding_level)
1200 return IDENTIFIER_GLOBAL_VALUE (name);
1202 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1203 return 0;
1205 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
1206 if (DECL_NAME (t) == name)
1207 break;
1209 return t;
1212 /* Record a decl-node X as belonging to the current lexical scope.
1213 Check for errors (such as an incompatible declaration for the same
1214 name already seen in the same scope).
1216 Returns either X or an old decl for the same name.
1217 If an old decl is returned, it may have been smashed
1218 to agree with what X says. */
1220 tree
1221 pushdecl (tree x)
1223 tree t;
1224 tree name = DECL_NAME (x);
1225 struct binding_level *b = current_binding_level;
1227 if (TREE_CODE (x) != TYPE_DECL)
1228 DECL_CONTEXT (x) = current_function_decl;
1229 if (name)
1231 t = lookup_name_current_level (name);
1232 if (t != 0 && t == error_mark_node)
1233 /* error_mark_node is 0 for a while during initialization! */
1235 t = 0;
1236 error ("%q+D used prior to declaration", x);
1239 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1240 to point to the TYPE_DECL.
1241 Since Java does not have typedefs, a type can only have
1242 one (true) name, given by a class, interface, or builtin. */
1243 if (TREE_CODE (x) == TYPE_DECL
1244 && TYPE_NAME (TREE_TYPE (x)) == 0
1245 && TREE_TYPE (x) != error_mark_node)
1247 TYPE_NAME (TREE_TYPE (x)) = x;
1248 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1251 /* This name is new in its binding level.
1252 Install the new declaration and return it. */
1253 if (b == global_binding_level)
1255 /* Install a global value. */
1257 IDENTIFIER_GLOBAL_VALUE (name) = x;
1259 else
1261 /* Here to install a non-global value. */
1262 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1263 IDENTIFIER_LOCAL_VALUE (name) = x;
1265 /* If storing a local value, there may already be one (inherited).
1266 If so, record it for restoration when this binding level ends. */
1267 if (oldlocal != 0)
1268 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1272 /* Put decls on list in reverse order.
1273 We will reverse them later if necessary. */
1274 TREE_CHAIN (x) = b->names;
1275 b->names = x;
1277 return x;
1280 void
1281 pushdecl_force_head (tree x)
1283 current_binding_level->names = x;
1286 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1288 tree
1289 pushdecl_top_level (tree x)
1291 tree t;
1292 struct binding_level *b = current_binding_level;
1294 current_binding_level = global_binding_level;
1295 t = pushdecl (x);
1296 current_binding_level = b;
1297 return t;
1300 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1302 tree
1303 pushdecl_function_level (tree x)
1305 tree t;
1306 struct binding_level *b = current_binding_level;
1308 current_binding_level = function_binding_level;
1309 t = pushdecl (x);
1310 current_binding_level = b;
1311 return t;
1314 /* Nonzero if we are currently in the global binding level. */
1317 global_bindings_p (void)
1319 return current_binding_level == global_binding_level;
1322 /* Return the list of declarations of the current level.
1323 Note that this list is in reverse order unless/until
1324 you nreverse it; and when you do nreverse it, you must
1325 store the result back using `storedecls' or you will lose. */
1327 tree
1328 getdecls (void)
1330 return current_binding_level->names;
1333 /* Create a new `struct binding_level'. */
1335 static struct binding_level *
1336 make_binding_level (void)
1338 /* NOSTRICT */
1339 return GGC_CNEW (struct binding_level);
1342 void
1343 pushlevel (int unused ATTRIBUTE_UNUSED)
1345 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1347 /* Reuse or create a struct for this binding level. */
1349 if (free_binding_level)
1351 newlevel = free_binding_level;
1352 free_binding_level = free_binding_level->level_chain;
1354 else
1356 newlevel = make_binding_level ();
1359 /* Add this level to the front of the chain (stack) of levels that
1360 are active. */
1362 *newlevel = clear_binding_level;
1363 newlevel->level_chain = current_binding_level;
1364 current_binding_level = newlevel;
1365 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1366 newlevel->binding_depth = binding_depth;
1367 indent ();
1368 fprintf (stderr, "push %s level %p pc %d\n",
1369 (is_class_level) ? "class" : "block", newlevel, current_pc);
1370 is_class_level = 0;
1371 binding_depth++;
1372 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1375 /* Exit a binding level.
1376 Pop the level off, and restore the state of the identifier-decl mappings
1377 that were in effect when this level was entered.
1379 If KEEP is nonzero, this level had explicit declarations, so
1380 and create a "block" (a BLOCK node) for the level
1381 to record its declarations and subblocks for symbol table output.
1383 If FUNCTIONBODY is nonzero, this level is the body of a function,
1384 so create a block as if KEEP were set and also clear out all
1385 label names.
1387 If REVERSE is nonzero, reverse the order of decls before putting
1388 them into the BLOCK. */
1390 tree
1391 poplevel (int keep, int reverse, int functionbody)
1393 tree link;
1394 /* The chain of decls was accumulated in reverse order.
1395 Put it into forward order, just for cleanliness. */
1396 tree decls;
1397 tree subblocks = current_binding_level->blocks;
1398 tree block = 0;
1399 tree decl;
1400 tree bind = 0;
1402 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1403 binding_depth--;
1404 indent ();
1405 if (current_binding_level->end_pc != LARGEST_PC)
1406 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1407 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1408 current_binding_level->end_pc);
1409 else
1410 fprintf (stderr, "pop %s level %p pc %d\n",
1411 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1412 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1414 /* Get the decls in the order they were written.
1415 Usually current_binding_level->names is in reverse order.
1416 But parameter decls were previously put in forward order. */
1418 if (reverse)
1419 current_binding_level->names
1420 = decls = nreverse (current_binding_level->names);
1421 else
1422 decls = current_binding_level->names;
1424 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1425 if (TREE_CODE (decl) == VAR_DECL
1426 && DECL_LANG_SPECIFIC (decl) != NULL
1427 && DECL_LOCAL_SLOT_NUMBER (decl))
1428 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1430 /* If there were any declarations in that level,
1431 or if this level is a function body,
1432 create a BLOCK to record them for the life of this function. */
1434 block = 0;
1435 if (keep || functionbody)
1437 block = make_node (BLOCK);
1438 TREE_TYPE (block) = void_type_node;
1441 if (current_binding_level->exception_range)
1442 expand_end_java_handler (current_binding_level->exception_range);
1444 if (block != 0)
1446 /* If any statements have been generated at this level, create a
1447 BIND_EXPR to hold them and copy the variables to it. This
1448 only applies to the bytecode compiler. */
1449 if (current_binding_level->stmts)
1451 tree decl = decls;
1452 tree *var = &BLOCK_VARS (block);
1454 /* Copy decls from names list, ignoring labels. */
1455 while (decl)
1457 tree next = TREE_CHAIN (decl);
1458 if (TREE_CODE (decl) != LABEL_DECL)
1460 *var = decl;
1461 var = &TREE_CHAIN (decl);
1463 decl = next;
1465 *var = NULL;
1467 bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
1468 BLOCK_EXPR_BODY (block), block);
1469 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1471 if (BIND_EXPR_BODY (bind)
1472 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1473 TREE_SIDE_EFFECTS (bind) = 1;
1475 /* FIXME: gimplifier brain damage. */
1476 if (BIND_EXPR_BODY (bind) == NULL)
1477 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1479 current_binding_level->stmts = NULL;
1481 else
1483 BLOCK_VARS (block) = decls;
1485 BLOCK_SUBBLOCKS (block) = subblocks;
1488 /* In each subblock, record that this is its superior. */
1490 for (link = subblocks; link; link = TREE_CHAIN (link))
1491 BLOCK_SUPERCONTEXT (link) = block;
1493 /* Clear out the meanings of the local variables of this level. */
1495 for (link = decls; link; link = TREE_CHAIN (link))
1497 tree name = DECL_NAME (link);
1498 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1500 /* If the ident. was used or addressed via a local extern decl,
1501 don't forget that fact. */
1502 if (DECL_EXTERNAL (link))
1504 if (TREE_USED (link))
1505 TREE_USED (name) = 1;
1506 if (TREE_ADDRESSABLE (link))
1507 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1509 IDENTIFIER_LOCAL_VALUE (name) = 0;
1513 /* Restore all name-meanings of the outer levels
1514 that were shadowed by this level. */
1516 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1517 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1519 /* If the level being exited is the top level of a function,
1520 check over all the labels, and clear out the current
1521 (function local) meanings of their names. */
1523 if (functionbody)
1525 /* If this is the top level block of a function,
1526 the vars are the function's parameters.
1527 Don't leave them in the BLOCK because they are
1528 found in the FUNCTION_DECL instead. */
1530 BLOCK_VARS (block) = 0;
1533 /* Pop the current level, and free the structure for reuse. */
1536 struct binding_level *level = current_binding_level;
1537 current_binding_level = current_binding_level->level_chain;
1539 level->level_chain = free_binding_level;
1540 free_binding_level = level;
1543 /* Dispose of the block that we just made inside some higher level. */
1544 if (functionbody)
1546 DECL_INITIAL (current_function_decl) = block;
1547 DECL_SAVED_TREE (current_function_decl) = bind;
1549 else
1551 if (block)
1553 current_binding_level->blocks
1554 = chainon (current_binding_level->blocks, block);
1556 /* If we did not make a block for the level just exited,
1557 any blocks made for inner levels
1558 (since they cannot be recorded as subblocks in that level)
1559 must be carried forward so they will later become subblocks
1560 of something else. */
1561 else if (subblocks)
1562 current_binding_level->blocks
1563 = chainon (current_binding_level->blocks, subblocks);
1565 if (bind)
1566 java_add_stmt (bind);
1569 if (block)
1570 TREE_USED (block) = 1;
1571 return block;
1574 void
1575 maybe_pushlevels (int pc)
1577 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1578 current_pc = pc;
1579 #endif
1581 while (pending_local_decls != NULL_TREE &&
1582 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1584 tree *ptr = &pending_local_decls;
1585 tree decl = *ptr, next;
1586 int end_pc = DECL_LOCAL_END_PC (decl);
1588 while (*ptr != NULL_TREE
1589 && DECL_LOCAL_START_PC (*ptr) <= pc
1590 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1591 ptr = &TREE_CHAIN (*ptr);
1592 pending_local_decls = *ptr;
1593 *ptr = NULL_TREE;
1595 /* Force non-nested range to be nested in current range by
1596 truncating variable lifetimes. */
1597 if (end_pc > current_binding_level->end_pc)
1599 tree t;
1600 end_pc = current_binding_level->end_pc;
1601 for (t = decl; t != NULL_TREE; t = TREE_CHAIN (t))
1602 DECL_LOCAL_END_PC (t) = end_pc;
1605 maybe_start_try (pc, end_pc);
1607 pushlevel (1);
1609 current_binding_level->end_pc = end_pc;
1610 current_binding_level->start_pc = pc;
1611 current_binding_level->names = NULL;
1612 for ( ; decl != NULL_TREE; decl = next)
1614 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1615 tree base_decl;
1616 next = TREE_CHAIN (decl);
1617 push_jvm_slot (index, decl);
1618 pushdecl (decl);
1619 base_decl
1620 = find_local_variable (index, TREE_TYPE (decl), pc);
1621 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1622 base_decl = TREE_VEC_ELT (base_decl_map, index);
1623 SET_DECL_VALUE_EXPR (decl, base_decl);
1624 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1628 maybe_start_try (pc, 0);
1631 void
1632 maybe_poplevels (int pc)
1634 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1635 current_pc = pc;
1636 #endif
1638 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1639 inclusive, so a variable is live if pc == end_pc. Here, we
1640 terminate a range if the current pc is equal to the end of the
1641 range, and this is *before* we have generated code for the
1642 instruction at end_pc. We're closing a binding level one
1643 instruction too early.*/
1644 while (current_binding_level->end_pc <= pc)
1645 poplevel (1, 0, 0);
1648 /* Terminate any binding which began during the range beginning at
1649 start_pc. This tidies up improperly nested local variable ranges
1650 and exception handlers; a variable declared within an exception
1651 range is forcibly terminated when that exception ends. */
1653 void
1654 force_poplevels (int start_pc)
1656 while (current_binding_level->start_pc > start_pc)
1658 if (pedantic && current_binding_level->start_pc > start_pc)
1659 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1660 current_function_decl,
1661 current_binding_level->start_pc);
1662 poplevel (1, 0, 0);
1666 /* integrate_decl_tree calls this function. */
1668 void
1669 java_dup_lang_specific_decl (tree node)
1671 int lang_decl_size;
1672 struct lang_decl *x;
1674 if (!DECL_LANG_SPECIFIC (node))
1675 return;
1677 lang_decl_size = sizeof (struct lang_decl);
1678 x = GGC_NEW (struct lang_decl);
1679 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1680 DECL_LANG_SPECIFIC (node) = x;
1683 void
1684 give_name_to_locals (JCF *jcf)
1686 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1687 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1688 tree parm;
1689 pending_local_decls = NULL_TREE;
1690 if (n == 0)
1691 return;
1692 JCF_SEEK (jcf, n);
1693 n = JCF_readu2 (jcf);
1694 for (i = 0; i < n; i++)
1696 int start_pc = JCF_readu2 (jcf);
1697 int length = JCF_readu2 (jcf);
1698 int name_index = JCF_readu2 (jcf);
1699 int signature_index = JCF_readu2 (jcf);
1700 int slot = JCF_readu2 (jcf);
1701 tree name = get_name_constant (jcf, name_index);
1702 tree type = parse_signature (jcf, signature_index);
1703 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1704 && start_pc == 0
1705 && length == DECL_CODE_LENGTH (current_function_decl))
1707 tree decl = TREE_VEC_ELT (decl_map, slot);
1708 DECL_NAME (decl) = name;
1709 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1710 warning (0, "bad type in parameter debug info");
1712 else
1714 tree *ptr;
1715 int end_pc = start_pc + length;
1716 tree decl = build_decl (input_location, VAR_DECL, name, type);
1717 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1719 warning (0, "bad PC range for debug info for local %q+D",
1720 decl);
1721 end_pc = DECL_CODE_LENGTH (current_function_decl);
1724 /* Adjust start_pc if necessary so that the local's first
1725 store operation will use the relevant DECL as a
1726 destination. Fore more information, read the leading
1727 comments for expr.c:maybe_adjust_start_pc. */
1728 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1730 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1731 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1732 DECL_LOCAL_START_PC (decl) = start_pc;
1733 DECL_LOCAL_END_PC (decl) = end_pc;
1735 /* Now insert the new decl in the proper place in
1736 pending_local_decls. We are essentially doing an insertion sort,
1737 which works fine, since the list input will normally already
1738 be sorted. */
1739 ptr = &pending_local_decls;
1740 while (*ptr != NULL_TREE
1741 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1742 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1743 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1744 ptr = &TREE_CHAIN (*ptr);
1745 TREE_CHAIN (decl) = *ptr;
1746 *ptr = decl;
1750 pending_local_decls = nreverse (pending_local_decls);
1752 /* Fill in default names for the parameters. */
1753 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1754 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1756 if (DECL_NAME (parm) == NULL_TREE)
1758 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1759 if (arg_i == 0)
1760 DECL_NAME (parm) = get_identifier ("this");
1761 else
1763 char buffer[12];
1764 sprintf (buffer, "ARG_%d", arg_i);
1765 DECL_NAME (parm) = get_identifier (buffer);
1771 tree
1772 build_result_decl (tree fndecl)
1774 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1775 tree result = DECL_RESULT (fndecl);
1776 if (! result)
1778 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1779 RESULT_DECL, NULL_TREE, restype);
1780 DECL_ARTIFICIAL (result) = 1;
1781 DECL_IGNORED_P (result) = 1;
1782 DECL_CONTEXT (result) = fndecl;
1783 DECL_RESULT (fndecl) = result;
1785 return result;
1788 void
1789 start_java_method (tree fndecl)
1791 tree tem, *ptr;
1792 int i;
1794 uniq = 0;
1796 current_function_decl = fndecl;
1797 announce_function (fndecl);
1799 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1800 decl_map = make_tree_vec (i);
1801 base_decl_map = make_tree_vec (i);
1802 type_map = XRESIZEVEC (tree, type_map, i);
1804 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1805 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1806 current_pc = 0;
1807 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1808 pushlevel (1); /* Push parameters. */
1810 ptr = &DECL_ARGUMENTS (fndecl);
1811 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1812 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1814 tree parm_name = NULL_TREE, parm_decl;
1815 tree parm_type = TREE_VALUE (tem);
1816 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1818 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1819 DECL_CONTEXT (parm_decl) = fndecl;
1820 if (targetm.calls.promote_prototypes (parm_type)
1821 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1822 && INTEGRAL_TYPE_P (parm_type))
1823 parm_type = integer_type_node;
1824 DECL_ARG_TYPE (parm_decl) = parm_type;
1826 *ptr = parm_decl;
1827 ptr = &TREE_CHAIN (parm_decl);
1829 /* Add parm_decl to the decl_map. */
1830 push_jvm_slot (i, parm_decl);
1832 type_map[i] = TREE_TYPE (parm_decl);
1833 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1835 i++;
1836 type_map[i] = void_type_node;
1839 *ptr = NULL_TREE;
1840 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1842 while (i < DECL_MAX_LOCALS(fndecl))
1843 type_map[i++] = NULL_TREE;
1845 build_result_decl (fndecl);
1847 /* Push local variables. */
1848 pushlevel (2);
1850 function_binding_level = current_binding_level;
1853 void
1854 end_java_method (void)
1856 tree fndecl = current_function_decl;
1858 /* pop out of function */
1859 poplevel (1, 1, 0);
1861 /* pop out of its parameters */
1862 poplevel (1, 0, 1);
1864 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1866 if (DECL_SAVED_TREE (fndecl))
1868 tree fbody, block_body;
1869 /* Before we check initialization, attached all class initialization
1870 variable to the block_body */
1871 fbody = DECL_SAVED_TREE (fndecl);
1872 block_body = BIND_EXPR_BODY (fbody);
1873 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1874 attach_init_test_initialization_flags, block_body);
1877 finish_method (fndecl);
1879 current_function_decl = NULL_TREE;
1882 /* Prepare a method for expansion. */
1884 void
1885 finish_method (tree fndecl)
1887 tree *tp = &DECL_SAVED_TREE (fndecl);
1889 /* Wrap body of synchronized methods in a monitorenter,
1890 plus monitorexit cleanup. */
1891 if (METHOD_SYNCHRONIZED (fndecl))
1893 tree enter, exit, lock;
1894 if (METHOD_STATIC (fndecl))
1895 lock = build_class_ref (DECL_CONTEXT (fndecl));
1896 else
1897 lock = DECL_ARGUMENTS (fndecl);
1898 BUILD_MONITOR_ENTER (enter, lock);
1899 BUILD_MONITOR_EXIT (exit, lock);
1900 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1901 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1904 /* Convert function tree to GENERIC prior to inlining. */
1905 java_genericize (fndecl);
1907 /* Store the end of the function, so that we get good line number
1908 info for the epilogue. */
1909 if (DECL_STRUCT_FUNCTION (fndecl))
1910 set_cfun (DECL_STRUCT_FUNCTION (fndecl));
1911 else
1912 allocate_struct_function (fndecl, false);
1913 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1915 /* Defer inlining and expansion to the cgraph optimizers. */
1916 cgraph_finalize_function (fndecl, false);
1919 /* We pessimistically marked all methods and fields external until we
1920 knew what set of classes we were planning to compile. Now mark those
1921 associated with CLASS to be generated locally as not external. */
1923 static void
1924 java_mark_decl_local (tree decl)
1926 DECL_EXTERNAL (decl) = 0;
1928 #ifdef ENABLE_CHECKING
1929 /* Double check that we didn't pass the function to the callgraph early. */
1930 if (TREE_CODE (decl) == FUNCTION_DECL)
1931 gcc_assert (!cgraph_node (decl)->local.finalized);
1932 #endif
1933 gcc_assert (!DECL_RTL_SET_P (decl));
1936 /* Given appropriate target support, G++ will emit hidden aliases for native
1937 methods. Using this hidden name is required for proper operation of
1938 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1939 proper target support, then mark the method for aliasing. */
1941 static void
1942 java_mark_cni_decl_local (tree decl)
1944 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1945 return;
1946 #endif
1948 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1949 DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1951 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1952 mangler. We might have already referenced this native method and
1953 therefore created its name, but even if we have it won't hurt.
1954 We'll just go via its externally visible name, rather than its
1955 hidden alias. However, we must force things so that the correct
1956 mangling is done. */
1958 if (DECL_ASSEMBLER_NAME_SET_P (decl))
1959 java_mangle_decl (decl);
1960 if (DECL_RTL_SET_P (decl))
1962 SET_DECL_RTL (decl, 0);
1963 make_decl_rtl (decl);
1967 /* Use the preceding two functions and mark all members of the class. */
1969 void
1970 java_mark_class_local (tree klass)
1972 tree t;
1974 for (t = TYPE_FIELDS (klass); t ; t = TREE_CHAIN (t))
1975 if (FIELD_STATIC (t))
1976 java_mark_decl_local (t);
1978 for (t = TYPE_METHODS (klass); t ; t = TREE_CHAIN (t))
1979 if (!METHOD_ABSTRACT (t))
1981 if (METHOD_NATIVE (t) && !flag_jni)
1982 java_mark_cni_decl_local (t);
1983 else
1984 java_mark_decl_local (t);
1988 /* Add a statement to a compound_expr. */
1990 tree
1991 add_stmt_to_compound (tree existing, tree type, tree stmt)
1993 if (!stmt)
1994 return existing;
1995 else if (existing)
1997 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
1998 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
1999 | TREE_SIDE_EFFECTS (stmt);
2000 return expr;
2002 else
2003 return stmt;
2006 /* Add a statement to the statement_list currently being constructed.
2007 If the statement_list is null, we don't create a singleton list.
2008 This is necessary because poplevel() assumes that adding a
2009 statement to a null statement_list returns the statement. */
2011 tree
2012 java_add_stmt (tree new_stmt)
2014 tree stmts = current_binding_level->stmts;
2015 tree_stmt_iterator i;
2017 if (input_filename)
2018 SET_EXPR_LOCATION (new_stmt, input_location);
2020 if (stmts == NULL)
2021 return current_binding_level->stmts = new_stmt;
2023 /* Force STMTS to be a statement_list. */
2024 if (TREE_CODE (stmts) != STATEMENT_LIST)
2026 tree t = make_node (STATEMENT_LIST);
2027 i = tsi_last (t);
2028 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2029 stmts = t;
2032 i = tsi_last (stmts);
2033 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2034 TREE_TYPE (stmts) = void_type_node;
2036 return current_binding_level->stmts = stmts;
2039 /* Add a variable to the current scope. */
2041 tree
2042 java_add_local_var (tree decl)
2044 tree *vars = &current_binding_level->names;
2045 tree next = *vars;
2046 TREE_CHAIN (decl) = next;
2047 *vars = decl;
2048 DECL_CONTEXT (decl) = current_function_decl;
2049 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2050 return decl;
2053 /* Return a pointer to the compound_expr currently being
2054 constructed. */
2056 tree *
2057 get_stmts (void)
2059 return &current_binding_level->stmts;
2062 /* Register an exception range as belonging to the current binding
2063 level. There may only be one: if there are more, we'll create more
2064 binding levels. However, each range can have multiple handlers,
2065 and these are expanded when we call expand_end_java_handler(). */
2067 void
2068 register_exception_range (struct eh_range *range, int pc, int end_pc)
2070 gcc_assert (! current_binding_level->exception_range);
2071 current_binding_level->exception_range = range;
2072 current_binding_level->end_pc = end_pc;
2073 current_binding_level->start_pc = pc;
2076 #include "gt-java-decl.h"