Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / java / decl.c
bloba17b826696b165ec094b1804788d8ef1c0b31ba8
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, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
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 "tree.h"
32 #include "diagnostic-core.h"
33 #include "toplev.h"
34 #include "flags.h"
35 #include "java-tree.h"
36 #include "jcf.h"
37 #include "libfuncs.h"
38 #include "java-except.h"
39 #include "ggc.h"
40 #include "cgraph.h"
41 #include "tree-inline.h"
42 #include "target.h"
43 #include "version.h"
44 #include "tree-iterator.h"
45 #include "langhooks.h"
46 #include "cgraph.h"
48 #if defined (DEBUG_JAVA_BINDING_LEVELS)
49 extern void indent (void);
50 #endif
52 static tree push_jvm_slot (int, tree);
53 static tree lookup_name_current_level (tree);
54 static tree push_promoted_type (const char *, tree);
55 static struct binding_level *make_binding_level (void);
56 static tree create_primitive_vtable (const char *);
57 static tree check_local_unnamed_variable (tree, tree, tree);
58 static void parse_version (void);
61 /* The following ABI flags are used in the high-order bits of the version
62 ID field. The version ID number itself should never be larger than
63 0xfffff, so it should be safe to use top 12 bits for these flags. */
65 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
67 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
68 should be loaded by the bootstrap
69 loader. */
71 /* If an ABI change is made within a GCC release series, rendering current
72 binaries incompatible with the old runtimes, this number must be set to
73 enforce the compatibility rules. */
74 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
76 /* The runtime may recognize a variety of BC ABIs (objects generated by
77 different version of gcj), but will probably always require strict
78 matching for the ordinary (C++) ABI. */
80 /* The version ID of the BC ABI that we generate. This must be kept in
81 sync with parse_version(), libgcj, and reality (if the BC format changes,
82 this must change). */
83 #define GCJ_CURRENT_BC_ABI_VERSION \
84 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
86 /* The ABI version number. */
87 tree gcj_abi_version;
89 /* Name of the Cloneable class. */
90 tree java_lang_cloneable_identifier_node;
92 /* Name of the Serializable class. */
93 tree java_io_serializable_identifier_node;
95 /* The DECL_MAP is a mapping from (index, type) to a decl node.
96 If index < max_locals, it is the index of a local variable.
97 if index >= max_locals, then index-max_locals is a stack slot.
98 The DECL_MAP mapping is represented as a TREE_VEC whose elements
99 are a list of decls (VAR_DECL or PARM_DECL) chained by
100 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
101 we search the chain for a decl with a matching TREE_TYPE. */
103 static GTY(()) tree decl_map;
105 /* The base_decl_map is contains one variable of ptr_type: this is
106 used to contain every variable of reference type that is ever
107 stored in a local variable slot. */
109 static GTY(()) tree base_decl_map;
111 /* An index used to make temporary identifiers unique. */
112 static int uniq;
114 /* A list of local variables VAR_DECLs for this method that we have seen
115 debug information, but we have not reached their starting (byte) PC yet. */
117 static GTY(()) tree pending_local_decls;
119 /* The decl for "_Jv_ResolvePoolEntry". */
120 tree soft_resolvepoolentry_node;
122 /* The decl for the .constants field of an instance of Class. */
123 tree constants_field_decl_node;
125 /* The decl for the .data field of an instance of Class. */
126 tree constants_data_field_decl_node;
128 #if defined(DEBUG_JAVA_BINDING_LEVELS)
129 int binding_depth = 0;
130 int is_class_level = 0;
131 int current_pc;
133 void
134 indent (void)
136 int i;
138 for (i = 0; i < binding_depth*2; i++)
139 putc (' ', stderr);
141 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
143 /* True if decl is a named local variable, i.e. if it is an alias
144 that's used only for debugging purposes. */
146 static bool
147 debug_variable_p (tree decl)
149 if (TREE_CODE (decl) == PARM_DECL)
150 return false;
152 if (LOCAL_SLOT_P (decl))
153 return false;
155 return true;
158 static tree
159 push_jvm_slot (int index, tree decl)
161 DECL_CONTEXT (decl) = current_function_decl;
162 layout_decl (decl, 0);
164 /* Now link the decl into the decl_map. */
165 if (DECL_LANG_SPECIFIC (decl) == NULL)
167 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
168 DECL_LOCAL_START_PC (decl) = 0;
169 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
170 DECL_LOCAL_SLOT_NUMBER (decl) = index;
172 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
173 TREE_VEC_ELT (decl_map, index) = decl;
175 return decl;
178 /* Find the best declaration based upon type. If 'decl' fits 'type' better
179 than 'best', return 'decl'. Otherwise return 'best'. */
181 static tree
182 check_local_unnamed_variable (tree best, tree decl, tree type)
184 tree decl_type = TREE_TYPE (decl);
186 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
188 /* Use the same decl for all integer types <= 32 bits. This is
189 necessary because sometimes a value is stored as (for example)
190 boolean but loaded as int. */
191 if (decl_type == type
192 || (INTEGRAL_TYPE_P (decl_type)
193 && INTEGRAL_TYPE_P (type)
194 && TYPE_PRECISION (decl_type) <= 32
195 && TYPE_PRECISION (type) <= 32
196 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
197 /* ptr_type_node is used for null pointers, which are
198 assignment compatible with everything. */
199 || (TREE_CODE (decl_type) == POINTER_TYPE
200 && type == ptr_type_node)
201 /* Whenever anyone wants to use a slot that is initially
202 occupied by a PARM_DECL of pointer type they must get that
203 decl, even if they asked for a pointer to a different type.
204 However, if someone wants a scalar variable in a slot that
205 initially held a pointer arg -- or vice versa -- we create a
206 new VAR_DECL.
208 ???: As long as verification is correct, this will be a
209 compatible type. But maybe we should create a dummy variable
210 and replace all references to it with the DECL and a
211 NOP_EXPR.
213 || (TREE_CODE (decl_type) == POINTER_TYPE
214 && TREE_CODE (decl) == PARM_DECL
215 && TREE_CODE (type) == POINTER_TYPE))
217 if (best == NULL_TREE
218 || (decl_type == type && TREE_TYPE (best) != type))
219 return decl;
222 return best;
226 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
227 that is valid at PC (or -1 if any pc).
228 If there is no existing matching decl, allocate one. */
230 tree
231 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
233 tree tmp = TREE_VEC_ELT (decl_map, index);
234 tree decl = NULL_TREE;
236 /* Scan through every declaration that has been created in this
237 slot. We're only looking for variables that correspond to local
238 index declarations and PARM_DECLs, not named variables: such
239 local variables are used only for debugging information. */
240 while (tmp != NULL_TREE)
242 if (! debug_variable_p (tmp))
243 decl = check_local_unnamed_variable (decl, tmp, type);
244 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
247 /* gcj has a function called promote_type(), which is used by both
248 the bytecode compiler and the source compiler. Unfortunately,
249 the type systems for the Java VM and the Java language are not
250 the same: a boolean in the VM promotes to an int, not to a wide
251 boolean. If our caller wants something to hold a boolean, that
252 had better be an int, because that slot might be re-used
253 later in integer context. */
254 if (TREE_CODE (type) == BOOLEAN_TYPE)
255 type = integer_type_node;
257 /* If we don't find a match, create one with the type passed in.
258 The name of the variable is #n#m, which n is the variable index
259 in the local variable area and m is a dummy identifier for
260 uniqueness -- multiple variables may share the same local
261 variable index. We don't call pushdecl() to push pointer types
262 into a binding expr because they'll all be replaced by a single
263 variable that is used for every reference in that local variable
264 slot. */
265 if (! decl)
267 char buf[64];
268 tree name;
269 sprintf (buf, "#slot#%d#%d", index, uniq++);
270 name = get_identifier (buf);
271 decl = build_decl (input_location, VAR_DECL, name, type);
272 DECL_IGNORED_P (decl) = 1;
273 DECL_ARTIFICIAL (decl) = 1;
274 decl = push_jvm_slot (index, decl);
275 LOCAL_SLOT_P (decl) = 1;
277 if (TREE_CODE (type) != POINTER_TYPE)
278 pushdecl_function_level (decl);
281 /* As well as creating a local variable that matches the type, we
282 also create a base variable (of ptr_type) that will hold all its
283 aliases. */
284 if (TREE_CODE (type) == POINTER_TYPE
285 && ! TREE_VEC_ELT (base_decl_map, index))
287 char buf[64];
288 tree name;
289 tree base_decl;
290 sprintf (buf, "#ref#%d#%d", index, uniq++);
291 name = get_identifier (buf);
292 base_decl
293 = TREE_VEC_ELT (base_decl_map, index)
294 = build_decl (input_location, VAR_DECL, name, ptr_type_node);
295 pushdecl_function_level (base_decl);
296 DECL_IGNORED_P (base_decl) = 1;
297 DECL_ARTIFICIAL (base_decl) = 1;
300 return decl;
303 /* Called during genericization for every variable. If the variable
304 is a temporary of pointer type, replace it with a common variable
305 thath is used to hold all pointer types that are ever stored in
306 that slot. Set WANT_LVALUE if you want a variable that is to be
307 written to. */
309 static tree
310 java_replace_reference (tree var_decl, bool want_lvalue)
312 tree decl_type;
314 if (! base_decl_map)
315 return var_decl;
317 decl_type = TREE_TYPE (var_decl);
319 if (TREE_CODE (decl_type) == POINTER_TYPE)
321 if (DECL_LANG_SPECIFIC (var_decl)
322 && LOCAL_SLOT_P (var_decl))
324 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
325 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
327 gcc_assert (base_decl);
328 if (! want_lvalue)
329 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
331 return base_decl;
335 return var_decl;
338 /* Helper for java_genericize. */
340 tree
341 java_replace_references (tree *tp, int *walk_subtrees,
342 void *data ATTRIBUTE_UNUSED)
344 if (TREE_CODE (*tp) == MODIFY_EXPR)
346 source_location loc = EXPR_LOCATION (*tp);
347 tree lhs = TREE_OPERAND (*tp, 0);
348 /* This is specific to the bytecode compiler. If a variable has
349 LOCAL_SLOT_P set, replace an assignment to it with an assignment
350 to the corresponding variable that holds all its aliases. */
351 if (TREE_CODE (lhs) == VAR_DECL
352 && DECL_LANG_SPECIFIC (lhs)
353 && LOCAL_SLOT_P (lhs)
354 && TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE)
356 tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
357 tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs),
358 TREE_OPERAND (*tp, 1));
359 tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
360 new_lhs, new_rhs);
361 *tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem);
362 SET_EXPR_LOCATION (tem, loc);
363 SET_EXPR_LOCATION (new_rhs, loc);
364 SET_EXPR_LOCATION (*tp, loc);
367 if (TREE_CODE (*tp) == VAR_DECL)
369 *tp = java_replace_reference (*tp, /* want_lvalue */ false);
370 *walk_subtrees = 0;
373 return NULL_TREE;
376 /* Same as find_local_index, except that INDEX is a stack index. */
378 tree
379 find_stack_slot (int index, tree type)
381 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
382 type, -1);
385 struct GTY(())
386 binding_level {
387 /* A chain of _DECL nodes for all variables, constants, functions,
388 * and typedef types. These are in the reverse of the order supplied.
390 tree names;
392 /* For each level, a list of shadowed outer-level local definitions
393 to be restored when this level is popped.
394 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
395 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
396 tree shadowed;
398 /* For each level (except not the global one),
399 a chain of BLOCK nodes for all the levels
400 that were entered and exited one level down. */
401 tree blocks;
403 /* The binding level which this one is contained in (inherits from). */
404 struct binding_level *level_chain;
406 /* The bytecode PC that marks the end of this level. */
407 int end_pc;
408 /* The bytecode PC that marks the start of this level. */
409 int start_pc;
411 /* The statements in this binding level. */
412 tree stmts;
414 /* An exception range associated with this binding level. */
415 struct eh_range * GTY((skip (""))) exception_range;
417 /* Binding depth at which this level began. Used only for debugging. */
418 unsigned binding_depth;
420 /* The location at which this level began. */
421 source_location loc;
424 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
426 /* The binding level currently in effect. */
428 static GTY(()) struct binding_level *current_binding_level;
430 /* A chain of binding_level structures awaiting reuse. */
432 static GTY(()) struct binding_level *free_binding_level;
434 /* The outermost binding level, for names of file scope.
435 This is created when the compiler is started and exists
436 through the entire run. */
438 static GTY(()) struct binding_level *global_binding_level;
440 /* The binding level that holds variables declared at the outermost
441 level within a function body. */
443 static struct binding_level *function_binding_level;
445 /* A PC value bigger than any PC value we may ever may encounter. */
447 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
449 /* Binding level structures are initialized by copying this one. */
451 static const struct binding_level clear_binding_level
453 NULL_TREE, /* names */
454 NULL_TREE, /* shadowed */
455 NULL_TREE, /* blocks */
456 NULL_BINDING_LEVEL, /* level_chain */
457 LARGEST_PC, /* end_pc */
458 0, /* start_pc */
459 NULL, /* stmts */
460 NULL, /* exception_range */
461 0, /* binding_depth */
462 0, /* loc */
465 tree java_global_trees[JTI_MAX];
467 /* Build (and pushdecl) a "promoted type" for all standard
468 types shorter than int. */
470 static tree
471 push_promoted_type (const char *name, tree actual_type)
473 tree type = make_node (TREE_CODE (actual_type));
474 #if 1
475 tree in_min = TYPE_MIN_VALUE (int_type_node);
476 tree in_max = TYPE_MAX_VALUE (int_type_node);
477 #else
478 tree in_min = TYPE_MIN_VALUE (actual_type);
479 tree in_max = TYPE_MAX_VALUE (actual_type);
480 #endif
481 TYPE_MIN_VALUE (type) = copy_node (in_min);
482 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
483 TYPE_MAX_VALUE (type) = copy_node (in_max);
484 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
485 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
486 TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
487 layout_type (type);
488 pushdecl (build_decl (input_location,
489 TYPE_DECL, get_identifier (name), type));
490 return type;
493 /* Return tree that represents a vtable for a primitive array. */
494 static tree
495 create_primitive_vtable (const char *name)
497 tree r;
498 char buf[50];
500 sprintf (buf, "_Jv_%sVTable", name);
501 r = build_decl (input_location,
502 VAR_DECL, get_identifier (buf), ptr_type_node);
503 DECL_EXTERNAL (r) = 1;
504 return r;
507 /* Parse the version string and compute the ABI version number. */
508 static void
509 parse_version (void)
511 const char *p = version_string;
512 unsigned int major = 0, minor = 0;
513 unsigned int abi_version;
515 /* Skip leading junk. */
516 while (*p && !ISDIGIT (*p))
517 ++p;
518 gcc_assert (*p);
520 /* Extract major version. */
521 while (ISDIGIT (*p))
523 major = major * 10 + *p - '0';
524 ++p;
527 gcc_assert (*p == '.' && ISDIGIT (p[1]));
528 ++p;
530 /* Extract minor version. */
531 while (ISDIGIT (*p))
533 minor = minor * 10 + *p - '0';
534 ++p;
537 if (flag_indirect_dispatch)
539 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
540 abi_version |= FLAG_BINARYCOMPAT_ABI;
542 else /* C++ ABI */
544 /* Implicit in this computation is the idea that we won't break the
545 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
546 4.0.1). */
547 abi_version = 100000 * major + 1000 * minor;
549 if (flag_bootstrap_classes)
550 abi_version |= FLAG_BOOTSTRAP_LOADER;
552 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
555 void
556 java_init_decl_processing (void)
558 tree field = NULL_TREE;
559 tree t;
561 init_class_processing ();
563 current_function_decl = NULL;
564 current_binding_level = NULL_BINDING_LEVEL;
565 free_binding_level = NULL_BINDING_LEVEL;
566 pushlevel (0); /* make the binding_level structure for global names */
567 global_binding_level = current_binding_level;
569 /* The code here must be similar to build_common_tree_nodes{,_2} in
570 tree.c, especially as to the order of initializing common nodes. */
571 error_mark_node = make_node (ERROR_MARK);
572 TREE_TYPE (error_mark_node) = error_mark_node;
574 /* Create sizetype first - needed for other types. */
575 initialize_sizetypes ();
577 byte_type_node = make_signed_type (8);
578 pushdecl (build_decl (BUILTINS_LOCATION,
579 TYPE_DECL, get_identifier ("byte"), byte_type_node));
580 short_type_node = make_signed_type (16);
581 pushdecl (build_decl (BUILTINS_LOCATION,
582 TYPE_DECL, get_identifier ("short"), short_type_node));
583 int_type_node = make_signed_type (32);
584 pushdecl (build_decl (BUILTINS_LOCATION,
585 TYPE_DECL, get_identifier ("int"), int_type_node));
586 long_type_node = make_signed_type (64);
587 pushdecl (build_decl (BUILTINS_LOCATION,
588 TYPE_DECL, get_identifier ("long"), long_type_node));
590 unsigned_byte_type_node = make_unsigned_type (8);
591 pushdecl (build_decl (BUILTINS_LOCATION,
592 TYPE_DECL, get_identifier ("unsigned byte"),
593 unsigned_byte_type_node));
594 unsigned_short_type_node = make_unsigned_type (16);
595 pushdecl (build_decl (BUILTINS_LOCATION,
596 TYPE_DECL, get_identifier ("unsigned short"),
597 unsigned_short_type_node));
598 unsigned_int_type_node = make_unsigned_type (32);
599 pushdecl (build_decl (BUILTINS_LOCATION,
600 TYPE_DECL, get_identifier ("unsigned int"),
601 unsigned_int_type_node));
602 unsigned_long_type_node = make_unsigned_type (64);
603 pushdecl (build_decl (BUILTINS_LOCATION,
604 TYPE_DECL, get_identifier ("unsigned long"),
605 unsigned_long_type_node));
607 /* This is not a java type, however tree-dfa requires a definition for
608 size_type_node. */
609 size_type_node = make_unsigned_type (POINTER_SIZE);
610 set_sizetype (size_type_node);
612 /* Define these next since types below may used them. */
613 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
614 integer_zero_node = build_int_cst (NULL_TREE, 0);
615 integer_one_node = build_int_cst (NULL_TREE, 1);
616 integer_two_node = build_int_cst (NULL_TREE, 2);
617 integer_three_node = build_int_cst (NULL_TREE, 3);
618 integer_four_node = build_int_cst (NULL_TREE, 4);
619 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
621 /* A few values used for range checking in the lexer. */
622 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
623 decimal_long_max
624 = double_int_to_tree (unsigned_long_type_node,
625 double_int_setbit (double_int_zero, 64));
627 size_zero_node = size_int (0);
628 size_one_node = size_int (1);
629 bitsize_zero_node = bitsize_int (0);
630 bitsize_one_node = bitsize_int (1);
631 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
633 long_zero_node = build_int_cst (long_type_node, 0);
635 void_type_node = make_node (VOID_TYPE);
636 pushdecl (build_decl (BUILTINS_LOCATION,
637 TYPE_DECL, get_identifier ("void"), void_type_node));
638 layout_type (void_type_node); /* Uses size_zero_node */
640 ptr_type_node = build_pointer_type (void_type_node);
641 const_ptr_type_node
642 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
644 t = make_node (VOID_TYPE);
645 layout_type (t); /* Uses size_zero_node */
646 return_address_type_node = build_pointer_type (t);
648 null_pointer_node = build_int_cst (ptr_type_node, 0);
650 char_type_node = make_node (INTEGER_TYPE);
651 TYPE_STRING_FLAG (char_type_node) = 1;
652 TYPE_PRECISION (char_type_node) = 16;
653 fixup_unsigned_type (char_type_node);
654 pushdecl (build_decl (BUILTINS_LOCATION,
655 TYPE_DECL, get_identifier ("char"), char_type_node));
657 boolean_type_node = make_node (BOOLEAN_TYPE);
658 TYPE_PRECISION (boolean_type_node) = 1;
659 fixup_unsigned_type (boolean_type_node);
660 pushdecl (build_decl (BUILTINS_LOCATION,
661 TYPE_DECL, get_identifier ("boolean"),
662 boolean_type_node));
663 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
664 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
666 promoted_byte_type_node
667 = push_promoted_type ("promoted_byte", byte_type_node);
668 promoted_short_type_node
669 = push_promoted_type ("promoted_short", short_type_node);
670 promoted_char_type_node
671 = push_promoted_type ("promoted_char", char_type_node);
672 promoted_boolean_type_node
673 = push_promoted_type ("promoted_boolean", boolean_type_node);
675 float_type_node = make_node (REAL_TYPE);
676 TYPE_PRECISION (float_type_node) = 32;
677 pushdecl (build_decl (BUILTINS_LOCATION,
678 TYPE_DECL, get_identifier ("float"),
679 float_type_node));
680 layout_type (float_type_node);
682 double_type_node = make_node (REAL_TYPE);
683 TYPE_PRECISION (double_type_node) = 64;
684 pushdecl (build_decl (BUILTINS_LOCATION,
685 TYPE_DECL, get_identifier ("double"),
686 double_type_node));
687 layout_type (double_type_node);
689 float_zero_node = build_real (float_type_node, dconst0);
690 double_zero_node = build_real (double_type_node, dconst0);
692 /* These are the vtables for arrays of primitives. */
693 boolean_array_vtable = create_primitive_vtable ("boolean");
694 byte_array_vtable = create_primitive_vtable ("byte");
695 char_array_vtable = create_primitive_vtable ("char");
696 short_array_vtable = create_primitive_vtable ("short");
697 int_array_vtable = create_primitive_vtable ("int");
698 long_array_vtable = create_primitive_vtable ("long");
699 float_array_vtable = create_primitive_vtable ("float");
700 double_array_vtable = create_primitive_vtable ("double");
702 one_elt_array_domain_type = build_index_type (integer_one_node);
703 utf8const_type = make_node (RECORD_TYPE);
704 PUSH_FIELD (input_location,
705 utf8const_type, field, "hash", unsigned_short_type_node);
706 PUSH_FIELD (input_location,
707 utf8const_type, field, "length", unsigned_short_type_node);
708 FINISH_RECORD (utf8const_type);
709 utf8const_ptr_type = build_pointer_type (utf8const_type);
711 atable_type = build_array_type (ptr_type_node,
712 one_elt_array_domain_type);
713 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
714 atable_ptr_type = build_pointer_type (atable_type);
716 itable_type = build_array_type (ptr_type_node,
717 one_elt_array_domain_type);
718 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
719 itable_ptr_type = build_pointer_type (itable_type);
721 symbol_type = make_node (RECORD_TYPE);
722 PUSH_FIELD (input_location,
723 symbol_type, field, "clname", utf8const_ptr_type);
724 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
725 PUSH_FIELD (input_location,
726 symbol_type, field, "signature", utf8const_ptr_type);
727 FINISH_RECORD (symbol_type);
729 symbols_array_type = build_array_type (symbol_type,
730 one_elt_array_domain_type);
731 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
733 assertion_entry_type = make_node (RECORD_TYPE);
734 PUSH_FIELD (input_location,
735 assertion_entry_type, field, "assertion_code", integer_type_node);
736 PUSH_FIELD (input_location,
737 assertion_entry_type, field, "op1", utf8const_ptr_type);
738 PUSH_FIELD (input_location,
739 assertion_entry_type, field, "op2", utf8const_ptr_type);
740 FINISH_RECORD (assertion_entry_type);
742 assertion_table_type = build_array_type (assertion_entry_type,
743 one_elt_array_domain_type);
745 /* As you're adding items here, please update the code right after
746 this section, so that the filename containing the source code of
747 the pre-defined class gets registered correctly. */
748 unqualified_object_id_node = get_identifier ("Object");
749 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
750 object_ptr_type_node = promote_type (object_type_node);
751 string_type_node = lookup_class (get_identifier ("java.lang.String"));
752 string_ptr_type_node = promote_type (string_type_node);
753 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
754 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
755 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
756 runtime_exception_type_node =
757 lookup_class (get_identifier ("java.lang.RuntimeException"));
758 error_exception_type_node =
759 lookup_class (get_identifier ("java.lang.Error"));
761 rawdata_ptr_type_node
762 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
764 add_predefined_file (get_identifier ("java/lang/Class.java"));
765 add_predefined_file (get_identifier ("java/lang/Error.java"));
766 add_predefined_file (get_identifier ("java/lang/Object.java"));
767 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
768 add_predefined_file (get_identifier ("java/lang/String.java"));
769 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
770 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
771 add_predefined_file (get_identifier ("java/lang/Exception.java"));
772 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
773 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
775 methodtable_type = make_node (RECORD_TYPE);
776 layout_type (methodtable_type);
777 build_decl (BUILTINS_LOCATION,
778 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
779 methodtable_ptr_type = build_pointer_type (methodtable_type);
781 TYPE_identifier_node = get_identifier ("TYPE");
782 init_identifier_node = get_identifier ("<init>");
783 clinit_identifier_node = get_identifier ("<clinit>");
784 void_signature_node = get_identifier ("()V");
785 finalize_identifier_node = get_identifier ("finalize");
786 this_identifier_node = get_identifier ("this");
788 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
789 java_io_serializable_identifier_node =
790 get_identifier ("java.io.Serializable");
792 /* for lack of a better place to put this stub call */
793 init_expr_processing();
795 constants_type_node = make_node (RECORD_TYPE);
796 PUSH_FIELD (input_location,
797 constants_type_node, field, "size", unsigned_int_type_node);
798 PUSH_FIELD (input_location,
799 constants_type_node, field, "tags", ptr_type_node);
800 PUSH_FIELD (input_location,
801 constants_type_node, field, "data", ptr_type_node);
802 constants_data_field_decl_node = field;
803 FINISH_RECORD (constants_type_node);
804 build_decl (BUILTINS_LOCATION,
805 TYPE_DECL, get_identifier ("constants"), constants_type_node);
807 access_flags_type_node = unsigned_short_type_node;
809 dtable_type = make_node (RECORD_TYPE);
810 dtable_ptr_type = build_pointer_type (dtable_type);
812 otable_type = build_array_type (integer_type_node,
813 one_elt_array_domain_type);
814 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
815 otable_ptr_type = build_pointer_type (otable_type);
817 PUSH_FIELD (input_location,
818 object_type_node, field, "vtable", dtable_ptr_type);
819 DECL_FCONTEXT (field) = object_type_node;
820 TYPE_VFIELD (object_type_node) = field;
822 /* This isn't exactly true, but it is what we have in the source.
823 There is an unresolved issue here, which is whether the vtable
824 should be marked by the GC. */
825 if (! flag_hash_synchronization)
826 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
827 build_pointer_type (object_type_node));
828 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
829 FIELD_PRIVATE (t) = 1;
830 FINISH_RECORD (object_type_node);
832 field_type_node = make_node (RECORD_TYPE);
833 field_ptr_type_node = build_pointer_type (field_type_node);
834 method_type_node = make_node (RECORD_TYPE);
835 method_ptr_type_node = build_pointer_type (method_type_node);
837 set_super_info (0, class_type_node, object_type_node, 0);
838 set_super_info (0, string_type_node, object_type_node, 0);
839 class_ptr_type = build_pointer_type (class_type_node);
841 PUSH_FIELD (input_location,
842 class_type_node, field, "next_or_version", class_ptr_type);
843 PUSH_FIELD (input_location,
844 class_type_node, field, "name", utf8const_ptr_type);
845 PUSH_FIELD (input_location,
846 class_type_node, field, "accflags", access_flags_type_node);
847 PUSH_FIELD (input_location,
848 class_type_node, field, "superclass", class_ptr_type);
849 PUSH_FIELD (input_location,
850 class_type_node, field, "constants", constants_type_node);
851 constants_field_decl_node = field;
852 PUSH_FIELD (input_location,
853 class_type_node, field, "methods", method_ptr_type_node);
854 PUSH_FIELD (input_location,
855 class_type_node, field, "method_count", short_type_node);
856 PUSH_FIELD (input_location,
857 class_type_node, field, "vtable_method_count", short_type_node);
858 PUSH_FIELD (input_location,
859 class_type_node, field, "fields", field_ptr_type_node);
860 PUSH_FIELD (input_location,
861 class_type_node, field, "size_in_bytes", int_type_node);
862 PUSH_FIELD (input_location,
863 class_type_node, field, "field_count", short_type_node);
864 PUSH_FIELD (input_location,
865 class_type_node, field, "static_field_count", short_type_node);
866 PUSH_FIELD (input_location,
867 class_type_node, field, "vtable", dtable_ptr_type);
868 PUSH_FIELD (input_location,
869 class_type_node, field, "otable", otable_ptr_type);
870 PUSH_FIELD (input_location,
871 class_type_node, field, "otable_syms",
872 symbols_array_ptr_type);
873 PUSH_FIELD (input_location,
874 class_type_node, field, "atable", atable_ptr_type);
875 PUSH_FIELD (input_location,
876 class_type_node, field, "atable_syms",
877 symbols_array_ptr_type);
878 PUSH_FIELD (input_location,
879 class_type_node, field, "itable", itable_ptr_type);
880 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
881 symbols_array_ptr_type);
882 PUSH_FIELD (input_location,
883 class_type_node, field, "catch_classes", ptr_type_node);
884 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
885 build_pointer_type (class_ptr_type));
886 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
887 PUSH_FIELD (input_location,
888 class_type_node, field, "interface_count", short_type_node);
889 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
890 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
891 PUSH_FIELD (input_location,
892 class_type_node, field, "depth", short_type_node);
893 PUSH_FIELD (input_location,
894 class_type_node, field, "ancestors", ptr_type_node);
895 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
896 PUSH_FIELD (input_location,
897 class_type_node, field, "arrayclass", ptr_type_node);
898 PUSH_FIELD (input_location,
899 class_type_node, field, "protectionDomain", ptr_type_node);
900 PUSH_FIELD (input_location,
901 class_type_node, field, "assertion_table", ptr_type_node);
902 PUSH_FIELD (input_location,
903 class_type_node, field, "hack_signers", ptr_type_node);
904 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
905 PUSH_FIELD (input_location,
906 class_type_node, field, "aux_info", ptr_type_node);
907 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
908 PUSH_FIELD (input_location,
909 class_type_node, field, "reflection_data", ptr_type_node);
910 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
911 FIELD_PRIVATE (t) = 1;
912 push_super_field (class_type_node, object_type_node);
914 FINISH_RECORD (class_type_node);
915 build_decl (BUILTINS_LOCATION,
916 TYPE_DECL, get_identifier ("Class"), class_type_node);
918 field_info_union_node = make_node (UNION_TYPE);
919 PUSH_FIELD (input_location,
920 field_info_union_node, field, "boffset", int_type_node);
921 PUSH_FIELD (input_location,
922 field_info_union_node, field, "addr", ptr_type_node);
923 layout_type (field_info_union_node);
925 PUSH_FIELD (input_location,
926 field_type_node, field, "name", utf8const_ptr_type);
927 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
928 PUSH_FIELD (input_location,
929 field_type_node, field, "accflags", access_flags_type_node);
930 PUSH_FIELD (input_location,
931 field_type_node, field, "bsize", unsigned_short_type_node);
932 PUSH_FIELD (input_location,
933 field_type_node, field, "info", field_info_union_node);
934 FINISH_RECORD (field_type_node);
935 build_decl (BUILTINS_LOCATION,
936 TYPE_DECL, get_identifier ("Field"), field_type_node);
938 nativecode_ptr_array_type_node
939 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
941 PUSH_FIELD (input_location,
942 dtable_type, field, "class", class_ptr_type);
943 PUSH_FIELD (input_location,
944 dtable_type, field, "methods", nativecode_ptr_array_type_node);
945 FINISH_RECORD (dtable_type);
946 build_decl (BUILTINS_LOCATION,
947 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
949 jexception_type = make_node (RECORD_TYPE);
950 PUSH_FIELD (input_location,
951 jexception_type, field, "start_pc", ptr_type_node);
952 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
953 PUSH_FIELD (input_location,
954 jexception_type, field, "handler_pc", ptr_type_node);
955 PUSH_FIELD (input_location,
956 jexception_type, field, "catch_type", class_ptr_type);
957 FINISH_RECORD (jexception_type);
958 build_decl (BUILTINS_LOCATION,
959 TYPE_DECL, get_identifier ("jexception"), field_type_node);
960 jexception_ptr_type = build_pointer_type (jexception_type);
962 lineNumberEntry_type = make_node (RECORD_TYPE);
963 PUSH_FIELD (input_location,
964 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
965 PUSH_FIELD (input_location,
966 lineNumberEntry_type, field, "start_pc", ptr_type_node);
967 FINISH_RECORD (lineNumberEntry_type);
969 lineNumbers_type = make_node (RECORD_TYPE);
970 PUSH_FIELD (input_location,
971 lineNumbers_type, field, "length", unsigned_int_type_node);
972 FINISH_RECORD (lineNumbers_type);
974 PUSH_FIELD (input_location,
975 method_type_node, field, "name", utf8const_ptr_type);
976 PUSH_FIELD (input_location,
977 method_type_node, field, "signature", utf8const_ptr_type);
978 PUSH_FIELD (input_location,
979 method_type_node, field, "accflags", access_flags_type_node);
980 PUSH_FIELD (input_location,
981 method_type_node, field, "index", unsigned_short_type_node);
982 PUSH_FIELD (input_location,
983 method_type_node, field, "ncode", nativecode_ptr_type_node);
984 PUSH_FIELD (input_location,
985 method_type_node, field, "throws", ptr_type_node);
986 FINISH_RECORD (method_type_node);
987 build_decl (BUILTINS_LOCATION,
988 TYPE_DECL, get_identifier ("Method"), method_type_node);
990 end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
992 t = build_function_type_list (ptr_type_node, class_ptr_type, NULL_TREE);
993 alloc_object_node = add_builtin_function ("_Jv_AllocObject", t,
994 0, NOT_BUILT_IN, NULL, NULL_TREE);
995 DECL_IS_MALLOC (alloc_object_node) = 1;
996 alloc_no_finalizer_node =
997 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t,
998 0, NOT_BUILT_IN, NULL, NULL_TREE);
999 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
1001 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1002 soft_initclass_node = add_builtin_function ("_Jv_InitClass", t,
1003 0, NOT_BUILT_IN, NULL, NULL_TREE);
1004 t = build_function_type_list (ptr_type_node,
1005 class_ptr_type, int_type_node, NULL_TREE);
1006 soft_resolvepoolentry_node
1007 = add_builtin_function ("_Jv_ResolvePoolEntry", t,
1008 0,NOT_BUILT_IN, NULL, NULL_TREE);
1009 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
1010 t = build_function_type_list (void_type_node,
1011 class_ptr_type, int_type_node, NULL_TREE);
1012 throw_node = add_builtin_function ("_Jv_Throw", t,
1013 0, NOT_BUILT_IN, NULL, NULL_TREE);
1014 /* Mark throw_nodes as `noreturn' functions with side effects. */
1015 TREE_THIS_VOLATILE (throw_node) = 1;
1016 TREE_SIDE_EFFECTS (throw_node) = 1;
1018 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1019 soft_monitorenter_node
1020 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1021 NULL, NULL_TREE);
1022 soft_monitorexit_node
1023 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1024 NULL, NULL_TREE);
1026 t = build_function_type_list (ptr_type_node,
1027 ptr_type_node, int_type_node, NULL_TREE);
1028 soft_newarray_node
1029 = add_builtin_function ("_Jv_NewPrimArray", t,
1030 0, NOT_BUILT_IN, NULL, NULL_TREE);
1031 DECL_IS_MALLOC (soft_newarray_node) = 1;
1033 t = build_function_type_list (ptr_type_node,
1034 int_type_node, class_ptr_type,
1035 object_ptr_type_node, NULL_TREE);
1036 soft_anewarray_node
1037 = add_builtin_function ("_Jv_NewObjectArray", t,
1038 0, NOT_BUILT_IN, NULL, NULL_TREE);
1039 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1041 t = build_varargs_function_type_list (ptr_type_node,
1042 ptr_type_node, int_type_node,
1043 NULL_TREE);
1044 soft_multianewarray_node
1045 = add_builtin_function ("_Jv_NewMultiArray", t,
1046 0, NOT_BUILT_IN, NULL, NULL_TREE);
1047 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1049 t = build_function_type_list (void_type_node, int_type_node, NULL_TREE);
1050 soft_badarrayindex_node
1051 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1052 0, NOT_BUILT_IN, NULL, NULL_TREE);
1053 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1054 effects. */
1055 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1056 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1058 t = build_function_type_list (void_type_node, NULL_TREE);
1059 soft_nullpointer_node
1060 = add_builtin_function ("_Jv_ThrowNullPointerException", t,
1061 0, NOT_BUILT_IN, NULL, NULL_TREE);
1062 /* Mark soft_nullpointer_node as a `noreturn' function with side
1063 effects. */
1064 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1065 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1067 soft_abstractmethod_node
1068 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t,
1069 0, NOT_BUILT_IN, NULL, NULL_TREE);
1070 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1071 effects. */
1072 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1073 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1075 soft_nosuchfield_node
1076 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t,
1077 0, NOT_BUILT_IN, NULL, NULL_TREE);
1078 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1079 effects. */
1080 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1081 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1083 t = build_function_type_list (ptr_type_node,
1084 class_ptr_type, object_ptr_type_node,
1085 NULL_TREE);
1086 soft_checkcast_node
1087 = add_builtin_function ("_Jv_CheckCast", t,
1088 0, NOT_BUILT_IN, NULL, NULL_TREE);
1089 t = build_function_type_list (boolean_type_node,
1090 object_ptr_type_node, class_ptr_type,
1091 NULL_TREE);
1092 soft_instanceof_node
1093 = add_builtin_function ("_Jv_IsInstanceOf", t,
1094 0, NOT_BUILT_IN, NULL, NULL_TREE);
1095 DECL_PURE_P (soft_instanceof_node) = 1;
1096 t = build_function_type_list (void_type_node,
1097 object_ptr_type_node, object_ptr_type_node,
1098 NULL_TREE);
1099 soft_checkarraystore_node
1100 = add_builtin_function ("_Jv_CheckArrayStore", t,
1101 0, NOT_BUILT_IN, NULL, NULL_TREE);
1102 t = build_function_type_list (ptr_type_node,
1103 ptr_type_node, ptr_type_node, int_type_node,
1104 NULL_TREE);
1105 soft_lookupinterfacemethod_node
1106 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t,
1107 0, NOT_BUILT_IN, NULL, NULL_TREE);
1108 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1110 t = build_function_type_list (ptr_type_node,
1111 ptr_type_node, ptr_type_node, ptr_type_node,
1112 NULL_TREE);
1113 soft_lookupinterfacemethodbyname_node
1114 = add_builtin_function ("_Jv_LookupInterfaceMethod", t,
1115 0, NOT_BUILT_IN, NULL, NULL_TREE);
1116 t = build_function_type_list (ptr_type_node,
1117 object_ptr_type_node, ptr_type_node,
1118 ptr_type_node, int_type_node, NULL_TREE);
1119 soft_lookupjnimethod_node
1120 = add_builtin_function ("_Jv_LookupJNIMethod", t,
1121 0, NOT_BUILT_IN, NULL, NULL_TREE);
1122 t = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
1123 soft_getjnienvnewframe_node
1124 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t,
1125 0, NOT_BUILT_IN, NULL, NULL_TREE);
1126 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1127 soft_jnipopsystemframe_node
1128 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t,
1129 0, NOT_BUILT_IN, NULL, NULL_TREE);
1131 t = build_function_type_list (object_ptr_type_node,
1132 object_ptr_type_node, NULL_TREE);
1133 soft_unwrapjni_node
1134 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t,
1135 0, NOT_BUILT_IN, NULL, NULL_TREE);
1137 t = build_function_type_list (int_type_node,
1138 int_type_node, int_type_node, NULL_TREE);
1139 soft_idiv_node
1140 = add_builtin_function ("_Jv_divI", t,
1141 0, NOT_BUILT_IN, NULL, NULL_TREE);
1143 soft_irem_node
1144 = add_builtin_function ("_Jv_remI", t,
1145 0, NOT_BUILT_IN, NULL, NULL_TREE);
1147 t = build_function_type_list (long_type_node,
1148 long_type_node, long_type_node, NULL_TREE);
1149 soft_ldiv_node
1150 = add_builtin_function ("_Jv_divJ", t,
1151 0, NOT_BUILT_IN, NULL, NULL_TREE);
1153 soft_lrem_node
1154 = add_builtin_function ("_Jv_remJ", t,
1155 0, NOT_BUILT_IN, NULL, NULL_TREE);
1157 initialize_builtins ();
1159 soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1161 parse_version ();
1165 /* Look up NAME in the current binding level and its superiors
1166 in the namespace of variables, functions and typedefs.
1167 Return a ..._DECL node of some kind representing its definition,
1168 or return 0 if it is undefined. */
1170 tree
1171 lookup_name (tree name)
1173 tree val;
1174 if (current_binding_level != global_binding_level
1175 && IDENTIFIER_LOCAL_VALUE (name))
1176 val = IDENTIFIER_LOCAL_VALUE (name);
1177 else
1178 val = IDENTIFIER_GLOBAL_VALUE (name);
1179 return val;
1182 /* Similar to `lookup_name' but look only at current binding level and
1183 the previous one if it's the parameter level. */
1185 static tree
1186 lookup_name_current_level (tree name)
1188 tree t;
1190 if (current_binding_level == global_binding_level)
1191 return IDENTIFIER_GLOBAL_VALUE (name);
1193 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1194 return 0;
1196 for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
1197 if (DECL_NAME (t) == name)
1198 break;
1200 return t;
1203 /* Record a decl-node X as belonging to the current lexical scope.
1204 Check for errors (such as an incompatible declaration for the same
1205 name already seen in the same scope).
1207 Returns either X or an old decl for the same name.
1208 If an old decl is returned, it may have been smashed
1209 to agree with what X says. */
1211 tree
1212 pushdecl (tree x)
1214 tree t;
1215 tree name = DECL_NAME (x);
1216 struct binding_level *b = current_binding_level;
1218 if (TREE_CODE (x) != TYPE_DECL)
1219 DECL_CONTEXT (x) = current_function_decl;
1220 if (name)
1222 t = lookup_name_current_level (name);
1223 if (t != 0 && t == error_mark_node)
1224 /* error_mark_node is 0 for a while during initialization! */
1226 t = 0;
1227 error ("%q+D used prior to declaration", x);
1230 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1231 to point to the TYPE_DECL.
1232 Since Java does not have typedefs, a type can only have
1233 one (true) name, given by a class, interface, or builtin. */
1234 if (TREE_CODE (x) == TYPE_DECL
1235 && TYPE_NAME (TREE_TYPE (x)) == 0
1236 && TREE_TYPE (x) != error_mark_node)
1238 TYPE_NAME (TREE_TYPE (x)) = x;
1239 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1242 /* This name is new in its binding level.
1243 Install the new declaration and return it. */
1244 if (b == global_binding_level)
1246 /* Install a global value. */
1248 IDENTIFIER_GLOBAL_VALUE (name) = x;
1250 else
1252 /* Here to install a non-global value. */
1253 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1254 IDENTIFIER_LOCAL_VALUE (name) = x;
1256 /* If storing a local value, there may already be one (inherited).
1257 If so, record it for restoration when this binding level ends. */
1258 if (oldlocal != 0)
1259 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1263 /* Put decls on list in reverse order.
1264 We will reverse them later if necessary. */
1265 DECL_CHAIN (x) = b->names;
1266 b->names = x;
1268 return x;
1271 void
1272 pushdecl_force_head (tree x)
1274 current_binding_level->names = x;
1277 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1279 tree
1280 pushdecl_top_level (tree x)
1282 tree t;
1283 struct binding_level *b = current_binding_level;
1285 current_binding_level = global_binding_level;
1286 t = pushdecl (x);
1287 current_binding_level = b;
1288 return t;
1291 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1293 tree
1294 pushdecl_function_level (tree x)
1296 tree t;
1297 struct binding_level *b = current_binding_level;
1299 current_binding_level = function_binding_level;
1300 t = pushdecl (x);
1301 current_binding_level = b;
1302 return t;
1305 /* Nonzero if we are currently in the global binding level. */
1308 global_bindings_p (void)
1310 return current_binding_level == global_binding_level;
1313 /* Return the list of declarations of the current level.
1314 Note that this list is in reverse order unless/until
1315 you nreverse it; and when you do nreverse it, you must
1316 store the result back using `storedecls' or you will lose. */
1318 tree
1319 getdecls (void)
1321 return current_binding_level->names;
1324 /* Create a new `struct binding_level'. */
1326 static struct binding_level *
1327 make_binding_level (void)
1329 /* NOSTRICT */
1330 return ggc_alloc_cleared_binding_level ();
1333 void
1334 pushlevel (int unused ATTRIBUTE_UNUSED)
1336 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1338 /* Reuse or create a struct for this binding level. */
1340 if (free_binding_level)
1342 newlevel = free_binding_level;
1343 free_binding_level = free_binding_level->level_chain;
1345 else
1347 newlevel = make_binding_level ();
1350 /* Add this level to the front of the chain (stack) of levels that
1351 are active. */
1353 *newlevel = clear_binding_level;
1354 newlevel->level_chain = current_binding_level;
1355 newlevel->loc = input_location;
1356 current_binding_level = newlevel;
1357 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1358 newlevel->binding_depth = binding_depth;
1359 indent ();
1360 fprintf (stderr, "push %s level %p pc %d\n",
1361 (is_class_level) ? "class" : "block", newlevel, current_pc);
1362 is_class_level = 0;
1363 binding_depth++;
1364 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1367 /* Exit a binding level.
1368 Pop the level off, and restore the state of the identifier-decl mappings
1369 that were in effect when this level was entered.
1371 If KEEP is nonzero, this level had explicit declarations, so
1372 and create a "block" (a BLOCK node) for the level
1373 to record its declarations and subblocks for symbol table output.
1375 If FUNCTIONBODY is nonzero, this level is the body of a function,
1376 so create a block as if KEEP were set and also clear out all
1377 label names.
1379 If REVERSE is nonzero, reverse the order of decls before putting
1380 them into the BLOCK. */
1382 tree
1383 poplevel (int keep, int reverse, int functionbody)
1385 tree link;
1386 /* The chain of decls was accumulated in reverse order.
1387 Put it into forward order, just for cleanliness. */
1388 tree decls;
1389 tree subblocks = current_binding_level->blocks;
1390 tree block = 0;
1391 tree decl;
1392 tree bind = 0;
1394 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1395 binding_depth--;
1396 indent ();
1397 if (current_binding_level->end_pc != LARGEST_PC)
1398 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1399 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1400 current_binding_level->end_pc);
1401 else
1402 fprintf (stderr, "pop %s level %p pc %d\n",
1403 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1404 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1406 /* Get the decls in the order they were written.
1407 Usually current_binding_level->names is in reverse order.
1408 But parameter decls were previously put in forward order. */
1410 if (reverse)
1411 current_binding_level->names
1412 = decls = nreverse (current_binding_level->names);
1413 else
1414 decls = current_binding_level->names;
1416 for (decl = decls; decl; decl = DECL_CHAIN (decl))
1417 if (TREE_CODE (decl) == VAR_DECL
1418 && DECL_LANG_SPECIFIC (decl) != NULL
1419 && DECL_LOCAL_SLOT_NUMBER (decl))
1420 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1422 /* If there were any declarations in that level,
1423 or if this level is a function body,
1424 create a BLOCK to record them for the life of this function. */
1426 block = 0;
1427 if (keep || functionbody)
1429 block = make_node (BLOCK);
1430 TREE_TYPE (block) = void_type_node;
1433 if (current_binding_level->exception_range)
1434 expand_end_java_handler (current_binding_level->exception_range);
1436 if (block != 0)
1438 /* If any statements have been generated at this level, create a
1439 BIND_EXPR to hold them and copy the variables to it. This
1440 only applies to the bytecode compiler. */
1441 if (current_binding_level->stmts)
1443 tree decl = decls;
1444 tree *var = &BLOCK_VARS (block);
1446 /* Copy decls from names list, ignoring labels. */
1447 while (decl)
1449 tree next = DECL_CHAIN (decl);
1450 if (TREE_CODE (decl) != LABEL_DECL)
1452 *var = decl;
1453 var = &DECL_CHAIN (decl);
1455 decl = next;
1457 *var = NULL;
1459 bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
1460 BLOCK_EXPR_BODY (block), block);
1461 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1463 if (BIND_EXPR_BODY (bind)
1464 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1465 TREE_SIDE_EFFECTS (bind) = 1;
1467 /* FIXME: gimplifier brain damage. */
1468 if (BIND_EXPR_BODY (bind) == NULL)
1469 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1471 SET_EXPR_LOCATION (bind, current_binding_level->loc);
1473 current_binding_level->stmts = NULL;
1475 else
1477 BLOCK_VARS (block) = decls;
1479 BLOCK_SUBBLOCKS (block) = subblocks;
1482 /* In each subblock, record that this is its superior. */
1484 for (link = subblocks; link; link = TREE_CHAIN (link))
1485 BLOCK_SUPERCONTEXT (link) = block;
1487 /* Clear out the meanings of the local variables of this level. */
1489 for (link = decls; link; link = DECL_CHAIN (link))
1491 tree name = DECL_NAME (link);
1492 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1494 /* If the ident. was used or addressed via a local extern decl,
1495 don't forget that fact. */
1496 if (DECL_EXTERNAL (link))
1498 if (TREE_USED (link))
1499 TREE_USED (name) = 1;
1500 if (TREE_ADDRESSABLE (link))
1501 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1503 IDENTIFIER_LOCAL_VALUE (name) = 0;
1507 /* Restore all name-meanings of the outer levels
1508 that were shadowed by this level. */
1510 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1511 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1513 /* If the level being exited is the top level of a function,
1514 check over all the labels, and clear out the current
1515 (function local) meanings of their names. */
1517 if (functionbody)
1519 /* If this is the top level block of a function,
1520 the vars are the function's parameters.
1521 Don't leave them in the BLOCK because they are
1522 found in the FUNCTION_DECL instead. */
1524 BLOCK_VARS (block) = 0;
1527 /* Pop the current level, and free the structure for reuse. */
1530 struct binding_level *level = current_binding_level;
1531 current_binding_level = current_binding_level->level_chain;
1533 level->level_chain = free_binding_level;
1534 free_binding_level = level;
1537 /* Dispose of the block that we just made inside some higher level. */
1538 if (functionbody)
1540 DECL_INITIAL (current_function_decl) = block;
1541 DECL_SAVED_TREE (current_function_decl) = bind;
1543 else
1545 if (block)
1547 current_binding_level->blocks
1548 = chainon (current_binding_level->blocks, block);
1550 /* If we did not make a block for the level just exited,
1551 any blocks made for inner levels
1552 (since they cannot be recorded as subblocks in that level)
1553 must be carried forward so they will later become subblocks
1554 of something else. */
1555 else if (subblocks)
1556 current_binding_level->blocks
1557 = chainon (current_binding_level->blocks, subblocks);
1559 if (bind)
1560 java_add_stmt (bind);
1563 if (block)
1564 TREE_USED (block) = 1;
1565 return block;
1568 void
1569 maybe_pushlevels (int pc)
1571 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1572 current_pc = pc;
1573 #endif
1575 while (pending_local_decls != NULL_TREE &&
1576 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1578 tree *ptr = &pending_local_decls;
1579 tree decl = *ptr, next;
1580 int end_pc = DECL_LOCAL_END_PC (decl);
1582 while (*ptr != NULL_TREE
1583 && DECL_LOCAL_START_PC (*ptr) <= pc
1584 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1585 ptr = &DECL_CHAIN (*ptr);
1586 pending_local_decls = *ptr;
1587 *ptr = NULL_TREE;
1589 /* Force non-nested range to be nested in current range by
1590 truncating variable lifetimes. */
1591 if (end_pc > current_binding_level->end_pc)
1593 tree t;
1594 end_pc = current_binding_level->end_pc;
1595 for (t = decl; t != NULL_TREE; t = DECL_CHAIN (t))
1596 DECL_LOCAL_END_PC (t) = end_pc;
1599 maybe_start_try (pc, end_pc);
1601 pushlevel (1);
1603 current_binding_level->end_pc = end_pc;
1604 current_binding_level->start_pc = pc;
1605 current_binding_level->names = NULL;
1606 for ( ; decl != NULL_TREE; decl = next)
1608 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1609 tree base_decl;
1610 next = DECL_CHAIN (decl);
1611 push_jvm_slot (index, decl);
1612 pushdecl (decl);
1613 base_decl
1614 = find_local_variable (index, TREE_TYPE (decl), pc);
1615 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1616 base_decl = TREE_VEC_ELT (base_decl_map, index);
1617 SET_DECL_VALUE_EXPR (decl, base_decl);
1618 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1622 maybe_start_try (pc, 0);
1625 void
1626 maybe_poplevels (int pc)
1628 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1629 current_pc = pc;
1630 #endif
1632 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1633 inclusive, so a variable is live if pc == end_pc. Here, we
1634 terminate a range if the current pc is equal to the end of the
1635 range, and this is *before* we have generated code for the
1636 instruction at end_pc. We're closing a binding level one
1637 instruction too early.*/
1638 while (current_binding_level->end_pc <= pc)
1639 poplevel (1, 0, 0);
1642 /* Terminate any binding which began during the range beginning at
1643 start_pc. This tidies up improperly nested local variable ranges
1644 and exception handlers; a variable declared within an exception
1645 range is forcibly terminated when that exception ends. */
1647 void
1648 force_poplevels (int start_pc)
1650 while (current_binding_level->start_pc > start_pc)
1652 if (pedantic && current_binding_level->start_pc > start_pc)
1653 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1654 current_function_decl,
1655 current_binding_level->start_pc);
1656 poplevel (1, 0, 0);
1660 /* integrate_decl_tree calls this function. */
1662 void
1663 java_dup_lang_specific_decl (tree node)
1665 int lang_decl_size;
1666 struct lang_decl *x;
1668 if (!DECL_LANG_SPECIFIC (node))
1669 return;
1671 lang_decl_size = sizeof (struct lang_decl);
1672 x = ggc_alloc_lang_decl (lang_decl_size);
1673 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1674 DECL_LANG_SPECIFIC (node) = x;
1677 void
1678 give_name_to_locals (JCF *jcf)
1680 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1681 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1682 tree parm;
1683 pending_local_decls = NULL_TREE;
1684 if (n == 0)
1685 return;
1686 JCF_SEEK (jcf, n);
1687 n = JCF_readu2 (jcf);
1688 for (i = 0; i < n; i++)
1690 int start_pc = JCF_readu2 (jcf);
1691 int length = JCF_readu2 (jcf);
1692 int name_index = JCF_readu2 (jcf);
1693 int signature_index = JCF_readu2 (jcf);
1694 int slot = JCF_readu2 (jcf);
1695 tree name = get_name_constant (jcf, name_index);
1696 tree type = parse_signature (jcf, signature_index);
1697 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1698 && start_pc == 0
1699 && length == DECL_CODE_LENGTH (current_function_decl))
1701 tree decl = TREE_VEC_ELT (decl_map, slot);
1702 DECL_NAME (decl) = name;
1703 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1704 warning (0, "bad type in parameter debug info");
1706 else
1708 tree *ptr;
1709 int end_pc = start_pc + length;
1710 tree decl = build_decl (input_location, VAR_DECL, name, type);
1711 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1713 warning (0, "bad PC range for debug info for local %q+D",
1714 decl);
1715 end_pc = DECL_CODE_LENGTH (current_function_decl);
1718 /* Adjust start_pc if necessary so that the local's first
1719 store operation will use the relevant DECL as a
1720 destination. Fore more information, read the leading
1721 comments for expr.c:maybe_adjust_start_pc. */
1722 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1724 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1725 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1726 DECL_LOCAL_START_PC (decl) = start_pc;
1727 DECL_LOCAL_END_PC (decl) = end_pc;
1729 /* Now insert the new decl in the proper place in
1730 pending_local_decls. We are essentially doing an insertion sort,
1731 which works fine, since the list input will normally already
1732 be sorted. */
1733 ptr = &pending_local_decls;
1734 while (*ptr != NULL_TREE
1735 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1736 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1737 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1738 ptr = &DECL_CHAIN (*ptr);
1739 DECL_CHAIN (decl) = *ptr;
1740 *ptr = decl;
1744 pending_local_decls = nreverse (pending_local_decls);
1746 /* Fill in default names for the parameters. */
1747 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1748 parm != NULL_TREE; parm = DECL_CHAIN (parm), i++)
1750 if (DECL_NAME (parm) == NULL_TREE)
1752 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1753 if (arg_i == 0)
1754 DECL_NAME (parm) = get_identifier ("this");
1755 else
1757 char buffer[12];
1758 sprintf (buffer, "ARG_%d", arg_i);
1759 DECL_NAME (parm) = get_identifier (buffer);
1765 tree
1766 build_result_decl (tree fndecl)
1768 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1769 tree result = DECL_RESULT (fndecl);
1770 if (! result)
1772 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1773 RESULT_DECL, NULL_TREE, restype);
1774 DECL_ARTIFICIAL (result) = 1;
1775 DECL_IGNORED_P (result) = 1;
1776 DECL_CONTEXT (result) = fndecl;
1777 DECL_RESULT (fndecl) = result;
1779 return result;
1782 void
1783 start_java_method (tree fndecl)
1785 tree tem, *ptr;
1786 int i;
1788 uniq = 0;
1790 current_function_decl = fndecl;
1791 announce_function (fndecl);
1793 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1794 decl_map = make_tree_vec (i);
1795 base_decl_map = make_tree_vec (i);
1796 type_map = XRESIZEVEC (tree, type_map, i);
1798 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1799 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1800 current_pc = 0;
1801 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1802 pushlevel (1); /* Push parameters. */
1804 ptr = &DECL_ARGUMENTS (fndecl);
1805 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1806 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1808 tree parm_name = NULL_TREE, parm_decl;
1809 tree parm_type = TREE_VALUE (tem);
1810 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1812 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1813 DECL_CONTEXT (parm_decl) = fndecl;
1814 if (targetm.calls.promote_prototypes (parm_type)
1815 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1816 && INTEGRAL_TYPE_P (parm_type))
1817 parm_type = integer_type_node;
1818 DECL_ARG_TYPE (parm_decl) = parm_type;
1820 *ptr = parm_decl;
1821 ptr = &DECL_CHAIN (parm_decl);
1823 /* Add parm_decl to the decl_map. */
1824 push_jvm_slot (i, parm_decl);
1826 /* The this parameter of methods is artificial. */
1827 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE && i == 0)
1828 DECL_ARTIFICIAL (parm_decl) = 1;
1830 type_map[i] = TREE_TYPE (parm_decl);
1831 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1833 i++;
1834 type_map[i] = void_type_node;
1837 *ptr = NULL_TREE;
1838 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1840 while (i < DECL_MAX_LOCALS(fndecl))
1841 type_map[i++] = NULL_TREE;
1843 build_result_decl (fndecl);
1844 DECL_SOURCE_LOCATION (fndecl) = input_location;
1846 /* Push local variables. */
1847 pushlevel (2);
1849 function_binding_level = current_binding_level;
1852 void
1853 end_java_method (void)
1855 tree fndecl = current_function_decl;
1857 /* pop out of function */
1858 poplevel (1, 1, 0);
1860 /* pop out of its parameters */
1861 poplevel (1, 0, 1);
1863 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1865 if (DECL_SAVED_TREE (fndecl))
1867 tree fbody, block_body;
1868 /* Before we check initialization, attached all class initialization
1869 variable to the block_body */
1870 fbody = DECL_SAVED_TREE (fndecl);
1871 block_body = BIND_EXPR_BODY (fbody);
1872 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1873 attach_init_test_initialization_flags, block_body);
1876 finish_method (fndecl);
1878 current_function_decl = NULL_TREE;
1879 base_decl_map = 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 = DECL_CHAIN (t))
1975 if (FIELD_STATIC (t))
1977 if (DECL_EXTERNAL (t))
1978 VEC_safe_push (tree, gc, pending_static_fields, t);
1979 java_mark_decl_local (t);
1982 for (t = TYPE_METHODS (klass); t ; t = DECL_CHAIN (t))
1983 if (!METHOD_ABSTRACT (t))
1985 if (METHOD_NATIVE (t) && !flag_jni)
1986 java_mark_cni_decl_local (t);
1987 else
1988 java_mark_decl_local (t);
1992 /* Add a statement to a compound_expr. */
1994 tree
1995 add_stmt_to_compound (tree existing, tree type, tree stmt)
1997 if (!stmt)
1998 return existing;
1999 else if (existing)
2001 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
2002 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
2003 | TREE_SIDE_EFFECTS (stmt);
2004 return expr;
2006 else
2007 return stmt;
2010 /* If this node is an expr, mark its input location. Called from
2011 walk_tree(). */
2013 static tree
2014 set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
2015 void *data ATTRIBUTE_UNUSED)
2017 tree t = *tp;
2019 if (CAN_HAVE_LOCATION_P (t))
2021 if (EXPR_HAS_LOCATION(t))
2022 return t; /* Don't walk any further into this expr. */
2023 else
2024 SET_EXPR_LOCATION (t, input_location);
2027 return NULL_TREE; /* Continue walking this expr. */
2030 /* Add a statement to the statement_list currently being constructed.
2031 If the statement_list is null, we don't create a singleton list.
2032 This is necessary because poplevel() assumes that adding a
2033 statement to a null statement_list returns the statement. */
2035 tree
2036 java_add_stmt (tree new_stmt)
2038 tree stmts = current_binding_level->stmts;
2039 tree_stmt_iterator i;
2041 if (input_filename)
2042 walk_tree (&new_stmt, set_input_location, NULL, NULL);
2044 if (stmts == NULL)
2045 return current_binding_level->stmts = new_stmt;
2047 /* Force STMTS to be a statement_list. */
2048 if (TREE_CODE (stmts) != STATEMENT_LIST)
2050 tree t = make_node (STATEMENT_LIST);
2051 i = tsi_last (t);
2052 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2053 stmts = t;
2056 i = tsi_last (stmts);
2057 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2058 TREE_TYPE (stmts) = void_type_node;
2060 return current_binding_level->stmts = stmts;
2063 /* Add a variable to the current scope. */
2065 tree
2066 java_add_local_var (tree decl)
2068 tree *vars = &current_binding_level->names;
2069 tree next = *vars;
2070 DECL_CHAIN (decl) = next;
2071 *vars = decl;
2072 DECL_CONTEXT (decl) = current_function_decl;
2073 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2074 return decl;
2077 /* Return a pointer to the compound_expr currently being
2078 constructed. */
2080 tree *
2081 get_stmts (void)
2083 return &current_binding_level->stmts;
2086 /* Register an exception range as belonging to the current binding
2087 level. There may only be one: if there are more, we'll create more
2088 binding levels. However, each range can have multiple handlers,
2089 and these are expanded when we call expand_end_java_handler(). */
2091 void
2092 register_exception_range (struct eh_range *range, int pc, int end_pc)
2094 gcc_assert (! current_binding_level->exception_range);
2095 current_binding_level->exception_range = range;
2096 current_binding_level->end_pc = end_pc;
2097 current_binding_level->start_pc = pc;
2100 #include "gt-java-decl.h"