/cp
[official-gcc.git] / gcc / java / decl.c
blobb855fcaa3c90b48a6c0fcdc72c56e46ee1390c9f
1 /* Process declarations and variables for the GNU compiler for the
2 Java(TM) language.
3 Copyright (C) 1996-2015 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>.
21 Java and all Java-based marks are trademarks or registered trademarks
22 of Sun Microsystems, Inc. in the United States and other countries.
23 The Free Software Foundation is independent of Sun Microsystems, Inc. */
25 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "options.h"
33 #include "tree.h"
34 #include "stor-layout.h"
35 #include "stringpool.h"
36 #include "varasm.h"
37 #include "diagnostic-core.h"
38 #include "toplev.h"
39 #include "flags.h"
40 #include "java-tree.h"
41 #include "jcf.h"
42 #include "java-except.h"
43 #include "tm.h"
44 #include "hard-reg-set.h"
45 #include "function.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"
53 #if defined (DEBUG_JAVA_BINDING_LEVELS)
54 extern void indent (void);
55 #endif
57 static tree push_jvm_slot (int, tree);
58 static tree lookup_name_current_level (tree);
59 static tree push_promoted_type (const char *, tree);
60 static struct binding_level *make_binding_level (void);
61 static tree create_primitive_vtable (const char *);
62 static tree check_local_unnamed_variable (tree, tree, tree);
63 static void parse_version (void);
66 /* The following ABI flags are used in the high-order bits of the version
67 ID field. The version ID number itself should never be larger than
68 0xfffff, so it should be safe to use top 12 bits for these flags. */
70 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
72 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
73 should be loaded by the bootstrap
74 loader. */
76 /* If an ABI change is made within a GCC release series, rendering current
77 binaries incompatible with the old runtimes, this number must be set to
78 enforce the compatibility rules. */
79 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
81 /* The runtime may recognize a variety of BC ABIs (objects generated by
82 different version of gcj), but will probably always require strict
83 matching for the ordinary (C++) ABI. */
85 /* The version ID of the BC ABI that we generate. This must be kept in
86 sync with parse_version(), libgcj, and reality (if the BC format changes,
87 this must change). */
88 #define GCJ_CURRENT_BC_ABI_VERSION \
89 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
91 /* The ABI version number. */
92 tree gcj_abi_version;
94 /* Name of the Cloneable class. */
95 tree java_lang_cloneable_identifier_node;
97 /* Name of the Serializable class. */
98 tree java_io_serializable_identifier_node;
100 /* The DECL_MAP is a mapping from (index, type) to a decl node.
101 If index < max_locals, it is the index of a local variable.
102 if index >= max_locals, then index-max_locals is a stack slot.
103 The DECL_MAP mapping is represented as a TREE_VEC whose elements
104 are a list of decls (VAR_DECL or PARM_DECL) chained by
105 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
106 we search the chain for a decl with a matching TREE_TYPE. */
108 static GTY(()) tree decl_map;
110 /* The base_decl_map is contains one variable of ptr_type: this is
111 used to contain every variable of reference type that is ever
112 stored in a local variable slot. */
114 static GTY(()) tree base_decl_map;
116 /* An index used to make temporary identifiers unique. */
117 static int uniq;
119 /* A list of local variables VAR_DECLs for this method that we have seen
120 debug information, but we have not reached their starting (byte) PC yet. */
122 static GTY(()) tree pending_local_decls;
124 /* The decl for "_Jv_ResolvePoolEntry". */
125 tree soft_resolvepoolentry_node;
127 /* The decl for the .constants field of an instance of Class. */
128 tree constants_field_decl_node;
130 /* The decl for the .data field of an instance of Class. */
131 tree constants_data_field_decl_node;
133 #if defined(DEBUG_JAVA_BINDING_LEVELS)
134 int binding_depth = 0;
135 int is_class_level = 0;
136 int current_pc;
138 void
139 indent (void)
141 int i;
143 for (i = 0; i < binding_depth*2; i++)
144 putc (' ', stderr);
146 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
148 /* True if decl is a named local variable, i.e. if it is an alias
149 that's used only for debugging purposes. */
151 static bool
152 debug_variable_p (tree decl)
154 if (TREE_CODE (decl) == PARM_DECL)
155 return false;
157 if (LOCAL_SLOT_P (decl))
158 return false;
160 return true;
163 static tree
164 push_jvm_slot (int index, tree decl)
166 DECL_CONTEXT (decl) = current_function_decl;
167 layout_decl (decl, 0);
169 /* Now link the decl into the decl_map. */
170 if (DECL_LANG_SPECIFIC (decl) == NULL)
172 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
173 DECL_LOCAL_START_PC (decl) = 0;
174 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
175 DECL_LOCAL_SLOT_NUMBER (decl) = index;
177 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
178 TREE_VEC_ELT (decl_map, index) = decl;
180 return decl;
183 /* Find the best declaration based upon type. If 'decl' fits 'type' better
184 than 'best', return 'decl'. Otherwise return 'best'. */
186 static tree
187 check_local_unnamed_variable (tree best, tree decl, tree type)
189 tree decl_type = TREE_TYPE (decl);
191 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
193 /* Use the same decl for all integer types <= 32 bits. This is
194 necessary because sometimes a value is stored as (for example)
195 boolean but loaded as int. */
196 if (decl_type == type
197 || (INTEGRAL_TYPE_P (decl_type)
198 && INTEGRAL_TYPE_P (type)
199 && TYPE_PRECISION (decl_type) <= 32
200 && TYPE_PRECISION (type) <= 32
201 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
202 /* ptr_type_node is used for null pointers, which are
203 assignment compatible with everything. */
204 || (TREE_CODE (decl_type) == POINTER_TYPE
205 && type == ptr_type_node)
206 /* Whenever anyone wants to use a slot that is initially
207 occupied by a PARM_DECL of pointer type they must get that
208 decl, even if they asked for a pointer to a different type.
209 However, if someone wants a scalar variable in a slot that
210 initially held a pointer arg -- or vice versa -- we create a
211 new VAR_DECL.
213 ???: As long as verification is correct, this will be a
214 compatible type. But maybe we should create a dummy variable
215 and replace all references to it with the DECL and a
216 NOP_EXPR.
218 || (TREE_CODE (decl_type) == POINTER_TYPE
219 && TREE_CODE (decl) == PARM_DECL
220 && TREE_CODE (type) == POINTER_TYPE))
222 if (best == NULL_TREE
223 || (decl_type == type && TREE_TYPE (best) != type))
224 return decl;
227 return best;
231 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
232 that is valid at PC (or -1 if any pc).
233 If there is no existing matching decl, allocate one. */
235 tree
236 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
238 tree tmp = TREE_VEC_ELT (decl_map, index);
239 tree decl = NULL_TREE;
241 /* Scan through every declaration that has been created in this
242 slot. We're only looking for variables that correspond to local
243 index declarations and PARM_DECLs, not named variables: such
244 local variables are used only for debugging information. */
245 while (tmp != NULL_TREE)
247 if (! debug_variable_p (tmp))
248 decl = check_local_unnamed_variable (decl, tmp, type);
249 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
252 /* gcj has a function called promote_type(), which is used by both
253 the bytecode compiler and the source compiler. Unfortunately,
254 the type systems for the Java VM and the Java language are not
255 the same: a boolean in the VM promotes to an int, not to a wide
256 boolean. If our caller wants something to hold a boolean, that
257 had better be an int, because that slot might be re-used
258 later in integer context. */
259 if (TREE_CODE (type) == BOOLEAN_TYPE)
260 type = integer_type_node;
262 /* If we don't find a match, create one with the type passed in.
263 The name of the variable is #n#m, which n is the variable index
264 in the local variable area and m is a dummy identifier for
265 uniqueness -- multiple variables may share the same local
266 variable index. We don't call pushdecl() to push pointer types
267 into a binding expr because they'll all be replaced by a single
268 variable that is used for every reference in that local variable
269 slot. */
270 if (! decl)
272 char buf[64];
273 tree name;
274 sprintf (buf, "#slot#%d#%d", index, uniq++);
275 name = get_identifier (buf);
276 decl = build_decl (input_location, VAR_DECL, name, type);
277 DECL_IGNORED_P (decl) = 1;
278 DECL_ARTIFICIAL (decl) = 1;
279 decl = push_jvm_slot (index, decl);
280 LOCAL_SLOT_P (decl) = 1;
282 if (TREE_CODE (type) != POINTER_TYPE)
283 pushdecl_function_level (decl);
286 /* As well as creating a local variable that matches the type, we
287 also create a base variable (of ptr_type) that will hold all its
288 aliases. */
289 if (TREE_CODE (type) == POINTER_TYPE
290 && ! TREE_VEC_ELT (base_decl_map, index))
292 char buf[64];
293 tree name;
294 tree base_decl;
295 sprintf (buf, "#ref#%d#%d", index, uniq++);
296 name = get_identifier (buf);
297 base_decl
298 = TREE_VEC_ELT (base_decl_map, index)
299 = build_decl (input_location, VAR_DECL, name, ptr_type_node);
300 pushdecl_function_level (base_decl);
301 DECL_IGNORED_P (base_decl) = 1;
302 DECL_ARTIFICIAL (base_decl) = 1;
305 return decl;
308 /* Called during genericization for every variable. If the variable
309 is a temporary of pointer type, replace it with a common variable
310 thath is used to hold all pointer types that are ever stored in
311 that slot. Set WANT_LVALUE if you want a variable that is to be
312 written to. */
314 static tree
315 java_replace_reference (tree var_decl, bool want_lvalue)
317 tree decl_type;
319 if (! base_decl_map)
320 return var_decl;
322 decl_type = TREE_TYPE (var_decl);
324 if (TREE_CODE (decl_type) == POINTER_TYPE)
326 if (DECL_LANG_SPECIFIC (var_decl)
327 && LOCAL_SLOT_P (var_decl))
329 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
330 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
332 gcc_assert (base_decl);
333 if (! want_lvalue)
334 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
336 return base_decl;
340 return var_decl;
343 /* Helper for java_genericize. */
345 tree
346 java_replace_references (tree *tp, int *walk_subtrees,
347 void *data ATTRIBUTE_UNUSED)
349 if (TREE_CODE (*tp) == MODIFY_EXPR)
351 source_location loc = EXPR_LOCATION (*tp);
352 tree lhs = TREE_OPERAND (*tp, 0);
353 /* This is specific to the bytecode compiler. If a variable has
354 LOCAL_SLOT_P set, replace an assignment to it with an assignment
355 to the corresponding variable that holds all its aliases. */
356 if (TREE_CODE (lhs) == VAR_DECL
357 && DECL_LANG_SPECIFIC (lhs)
358 && LOCAL_SLOT_P (lhs)
359 && TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE)
361 tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
362 tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs),
363 TREE_OPERAND (*tp, 1));
364 tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
365 new_lhs, new_rhs);
366 *tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem);
367 SET_EXPR_LOCATION (tem, loc);
368 SET_EXPR_LOCATION (new_rhs, loc);
369 SET_EXPR_LOCATION (*tp, loc);
372 if (TREE_CODE (*tp) == VAR_DECL)
374 *tp = java_replace_reference (*tp, /* want_lvalue */ false);
375 *walk_subtrees = 0;
378 return NULL_TREE;
381 /* Same as find_local_index, except that INDEX is a stack index. */
383 tree
384 find_stack_slot (int index, tree type)
386 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
387 type, -1);
390 struct GTY(())
391 binding_level {
392 /* A chain of _DECL nodes for all variables, constants, functions,
393 * and typedef types. These are in the reverse of the order supplied.
395 tree names;
397 /* For each level, a list of shadowed outer-level local definitions
398 to be restored when this level is popped.
399 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
400 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
401 tree shadowed;
403 /* For each level (except not the global one),
404 a chain of BLOCK nodes for all the levels
405 that were entered and exited one level down. */
406 tree blocks;
408 /* The binding level which this one is contained in (inherits from). */
409 struct binding_level *level_chain;
411 /* The bytecode PC that marks the end of this level. */
412 int end_pc;
413 /* The bytecode PC that marks the start of this level. */
414 int start_pc;
416 /* The statements in this binding level. */
417 tree stmts;
419 /* An exception range associated with this binding level. */
420 struct eh_range * GTY((skip (""))) exception_range;
422 /* Binding depth at which this level began. Used only for debugging. */
423 unsigned binding_depth;
425 /* The location at which this level began. */
426 source_location loc;
429 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
431 /* The binding level currently in effect. */
433 static GTY(()) struct binding_level *current_binding_level;
435 /* A chain of binding_level structures awaiting reuse. */
437 static GTY(()) struct binding_level *free_binding_level;
439 /* The outermost binding level, for names of file scope.
440 This is created when the compiler is started and exists
441 through the entire run. */
443 static GTY(()) struct binding_level *global_binding_level;
445 /* The binding level that holds variables declared at the outermost
446 level within a function body. */
448 static struct binding_level *function_binding_level;
450 /* A PC value bigger than any PC value we may ever may encounter. */
452 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
454 /* Binding level structures are initialized by copying this one. */
456 static const struct binding_level clear_binding_level
458 NULL_TREE, /* names */
459 NULL_TREE, /* shadowed */
460 NULL_TREE, /* blocks */
461 NULL_BINDING_LEVEL, /* level_chain */
462 LARGEST_PC, /* end_pc */
463 0, /* start_pc */
464 NULL, /* stmts */
465 NULL, /* exception_range */
466 0, /* binding_depth */
467 0, /* loc */
470 tree java_global_trees[JTI_MAX];
472 /* Build (and pushdecl) a "promoted type" for all standard
473 types shorter than int. */
475 static tree
476 push_promoted_type (const char *name, tree actual_type)
478 tree type = make_node (TREE_CODE (actual_type));
479 #if 1
480 tree in_min = TYPE_MIN_VALUE (int_type_node);
481 tree in_max = TYPE_MAX_VALUE (int_type_node);
482 #else
483 tree in_min = TYPE_MIN_VALUE (actual_type);
484 tree in_max = TYPE_MAX_VALUE (actual_type);
485 #endif
486 TYPE_MIN_VALUE (type) = copy_node (in_min);
487 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
488 TYPE_MAX_VALUE (type) = copy_node (in_max);
489 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
490 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
491 TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
492 layout_type (type);
493 pushdecl (build_decl (input_location,
494 TYPE_DECL, get_identifier (name), type));
495 return type;
498 /* Return tree that represents a vtable for a primitive array. */
499 static tree
500 create_primitive_vtable (const char *name)
502 tree r;
503 char buf[50];
505 sprintf (buf, "_Jv_%sVTable", name);
506 r = build_decl (input_location,
507 VAR_DECL, get_identifier (buf), ptr_type_node);
508 DECL_EXTERNAL (r) = 1;
509 return r;
512 /* Parse the version string and compute the ABI version number. */
513 static void
514 parse_version (void)
516 const char *p = version_string;
517 unsigned int major = 0, minor = 0;
518 unsigned int abi_version;
520 /* Skip leading junk. */
521 while (*p && !ISDIGIT (*p))
522 ++p;
523 gcc_assert (*p);
525 /* Extract major version. */
526 while (ISDIGIT (*p))
528 major = major * 10 + *p - '0';
529 ++p;
532 gcc_assert (*p == '.' && ISDIGIT (p[1]));
533 ++p;
535 /* Extract minor version. */
536 while (ISDIGIT (*p))
538 minor = minor * 10 + *p - '0';
539 ++p;
542 if (flag_indirect_dispatch)
544 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
545 abi_version |= FLAG_BINARYCOMPAT_ABI;
547 else /* C++ ABI */
549 /* Implicit in this computation is the idea that we won't break the
550 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
551 4.0.1). */
552 abi_version = 100000 * major + 1000 * minor;
554 if (flag_bootstrap_classes)
555 abi_version |= FLAG_BOOTSTRAP_LOADER;
557 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
560 void
561 java_init_decl_processing (void)
563 tree field = NULL_TREE;
564 tree t;
566 init_class_processing ();
568 current_function_decl = NULL;
569 current_binding_level = NULL_BINDING_LEVEL;
570 free_binding_level = NULL_BINDING_LEVEL;
571 pushlevel (0); /* make the binding_level structure for global names */
572 global_binding_level = current_binding_level;
574 /* Build common tree nodes, Java has an unsigned char. */
575 build_common_tree_nodes (false, false);
577 /* ??? Now we continue and override some of the built types again
578 with Java specific types. As the above generated types are
579 supposed to match the targets C ABI this isn't really the way
580 to go and any Java specifics should _not_ use those global types
581 if the Java ABI does not match the C one. */
583 byte_type_node = make_signed_type (8);
584 pushdecl (build_decl (BUILTINS_LOCATION,
585 TYPE_DECL, get_identifier ("byte"), byte_type_node));
586 short_type_node = make_signed_type (16);
587 pushdecl (build_decl (BUILTINS_LOCATION,
588 TYPE_DECL, get_identifier ("short"), short_type_node));
589 int_type_node = make_signed_type (32);
590 pushdecl (build_decl (BUILTINS_LOCATION,
591 TYPE_DECL, get_identifier ("int"), int_type_node));
592 long_type_node = make_signed_type (64);
593 pushdecl (build_decl (BUILTINS_LOCATION,
594 TYPE_DECL, get_identifier ("long"), long_type_node));
596 unsigned_byte_type_node = make_unsigned_type (8);
597 pushdecl (build_decl (BUILTINS_LOCATION,
598 TYPE_DECL, get_identifier ("unsigned byte"),
599 unsigned_byte_type_node));
600 unsigned_short_type_node = make_unsigned_type (16);
601 pushdecl (build_decl (BUILTINS_LOCATION,
602 TYPE_DECL, get_identifier ("unsigned short"),
603 unsigned_short_type_node));
604 unsigned_int_type_node = make_unsigned_type (32);
605 pushdecl (build_decl (BUILTINS_LOCATION,
606 TYPE_DECL, get_identifier ("unsigned int"),
607 unsigned_int_type_node));
608 unsigned_long_type_node = make_unsigned_type (64);
609 pushdecl (build_decl (BUILTINS_LOCATION,
610 TYPE_DECL, get_identifier ("unsigned long"),
611 unsigned_long_type_node));
613 /* Define these next since types below may used them. */
614 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
615 integer_zero_node = build_int_cst (NULL_TREE, 0);
616 integer_one_node = build_int_cst (NULL_TREE, 1);
617 integer_two_node = build_int_cst (NULL_TREE, 2);
618 integer_three_node = build_int_cst (NULL_TREE, 3);
619 integer_four_node = build_int_cst (NULL_TREE, 4);
620 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
622 /* A few values used for range checking in the lexer. */
623 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
624 decimal_long_max
625 = double_int_to_tree (unsigned_long_type_node,
626 double_int_zero.set_bit (64));
628 long_zero_node = build_int_cst (long_type_node, 0);
630 pushdecl (build_decl (BUILTINS_LOCATION,
631 TYPE_DECL, get_identifier ("void"), void_type_node));
633 t = make_node (VOID_TYPE);
634 layout_type (t); /* Uses size_zero_node */
635 return_address_type_node = build_pointer_type (t);
637 char_type_node = make_unsigned_type (16);
638 TYPE_STRING_FLAG (char_type_node) = 1;
639 pushdecl (build_decl (BUILTINS_LOCATION,
640 TYPE_DECL, get_identifier ("char"), char_type_node));
642 boolean_type_node = make_unsigned_type (1);
643 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
644 pushdecl (build_decl (BUILTINS_LOCATION,
645 TYPE_DECL, get_identifier ("boolean"),
646 boolean_type_node));
647 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
648 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
650 promoted_byte_type_node
651 = push_promoted_type ("promoted_byte", byte_type_node);
652 promoted_short_type_node
653 = push_promoted_type ("promoted_short", short_type_node);
654 promoted_char_type_node
655 = push_promoted_type ("promoted_char", char_type_node);
656 promoted_boolean_type_node
657 = push_promoted_type ("promoted_boolean", boolean_type_node);
659 float_type_node = make_node (REAL_TYPE);
660 TYPE_PRECISION (float_type_node) = 32;
661 pushdecl (build_decl (BUILTINS_LOCATION,
662 TYPE_DECL, get_identifier ("float"),
663 float_type_node));
664 layout_type (float_type_node);
666 double_type_node = make_node (REAL_TYPE);
667 TYPE_PRECISION (double_type_node) = 64;
668 pushdecl (build_decl (BUILTINS_LOCATION,
669 TYPE_DECL, get_identifier ("double"),
670 double_type_node));
671 layout_type (double_type_node);
673 float_zero_node = build_real (float_type_node, dconst0);
674 double_zero_node = build_real (double_type_node, dconst0);
676 /* These are the vtables for arrays of primitives. */
677 boolean_array_vtable = create_primitive_vtable ("boolean");
678 byte_array_vtable = create_primitive_vtable ("byte");
679 char_array_vtable = create_primitive_vtable ("char");
680 short_array_vtable = create_primitive_vtable ("short");
681 int_array_vtable = create_primitive_vtable ("int");
682 long_array_vtable = create_primitive_vtable ("long");
683 float_array_vtable = create_primitive_vtable ("float");
684 double_array_vtable = create_primitive_vtable ("double");
686 one_elt_array_domain_type = build_index_type (integer_one_node);
687 utf8const_type = make_node (RECORD_TYPE);
688 PUSH_FIELD (input_location,
689 utf8const_type, field, "hash", unsigned_short_type_node);
690 PUSH_FIELD (input_location,
691 utf8const_type, field, "length", unsigned_short_type_node);
692 FINISH_RECORD (utf8const_type);
693 utf8const_ptr_type = build_pointer_type (utf8const_type);
695 atable_type = build_array_type (ptr_type_node,
696 one_elt_array_domain_type);
697 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
698 atable_ptr_type = build_pointer_type (atable_type);
700 itable_type = build_array_type (ptr_type_node,
701 one_elt_array_domain_type);
702 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
703 itable_ptr_type = build_pointer_type (itable_type);
705 symbol_type = make_node (RECORD_TYPE);
706 PUSH_FIELD (input_location,
707 symbol_type, field, "clname", utf8const_ptr_type);
708 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
709 PUSH_FIELD (input_location,
710 symbol_type, field, "signature", utf8const_ptr_type);
711 FINISH_RECORD (symbol_type);
713 symbols_array_type = build_array_type (symbol_type,
714 one_elt_array_domain_type);
715 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
717 assertion_entry_type = make_node (RECORD_TYPE);
718 PUSH_FIELD (input_location,
719 assertion_entry_type, field, "assertion_code", integer_type_node);
720 PUSH_FIELD (input_location,
721 assertion_entry_type, field, "op1", utf8const_ptr_type);
722 PUSH_FIELD (input_location,
723 assertion_entry_type, field, "op2", utf8const_ptr_type);
724 FINISH_RECORD (assertion_entry_type);
726 assertion_table_type = build_array_type (assertion_entry_type,
727 one_elt_array_domain_type);
729 /* As you're adding items here, please update the code right after
730 this section, so that the filename containing the source code of
731 the pre-defined class gets registered correctly. */
732 unqualified_object_id_node = get_identifier ("Object");
733 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
734 object_ptr_type_node = promote_type (object_type_node);
735 string_type_node = lookup_class (get_identifier ("java.lang.String"));
736 string_ptr_type_node = promote_type (string_type_node);
737 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
738 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
739 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
740 runtime_exception_type_node =
741 lookup_class (get_identifier ("java.lang.RuntimeException"));
742 error_exception_type_node =
743 lookup_class (get_identifier ("java.lang.Error"));
745 rawdata_ptr_type_node
746 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
748 add_predefined_file (get_identifier ("java/lang/Class.java"));
749 add_predefined_file (get_identifier ("java/lang/Error.java"));
750 add_predefined_file (get_identifier ("java/lang/Object.java"));
751 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
752 add_predefined_file (get_identifier ("java/lang/String.java"));
753 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
754 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
755 add_predefined_file (get_identifier ("java/lang/Exception.java"));
756 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
757 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
759 methodtable_type = make_node (RECORD_TYPE);
760 layout_type (methodtable_type);
761 build_decl (BUILTINS_LOCATION,
762 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
763 methodtable_ptr_type = build_pointer_type (methodtable_type);
765 TYPE_identifier_node = get_identifier ("TYPE");
766 init_identifier_node = get_identifier ("<init>");
767 clinit_identifier_node = get_identifier ("<clinit>");
768 void_signature_node = get_identifier ("()V");
769 finalize_identifier_node = get_identifier ("finalize");
770 this_identifier_node = get_identifier ("this");
772 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
773 java_io_serializable_identifier_node =
774 get_identifier ("java.io.Serializable");
776 /* for lack of a better place to put this stub call */
777 init_expr_processing();
779 constants_type_node = make_node (RECORD_TYPE);
780 PUSH_FIELD (input_location,
781 constants_type_node, field, "size", unsigned_int_type_node);
782 PUSH_FIELD (input_location,
783 constants_type_node, field, "tags", ptr_type_node);
784 PUSH_FIELD (input_location,
785 constants_type_node, field, "data", ptr_type_node);
786 constants_data_field_decl_node = field;
787 FINISH_RECORD (constants_type_node);
788 build_decl (BUILTINS_LOCATION,
789 TYPE_DECL, get_identifier ("constants"), constants_type_node);
791 access_flags_type_node = unsigned_short_type_node;
793 dtable_type = make_node (RECORD_TYPE);
794 dtable_ptr_type = build_pointer_type (dtable_type);
796 otable_type = build_array_type (integer_type_node,
797 one_elt_array_domain_type);
798 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
799 otable_ptr_type = build_pointer_type (otable_type);
801 PUSH_FIELD (input_location,
802 object_type_node, field, "vtable", dtable_ptr_type);
803 DECL_FCONTEXT (field) = object_type_node;
804 TYPE_VFIELD (object_type_node) = field;
806 /* This isn't exactly true, but it is what we have in the source.
807 There is an unresolved issue here, which is whether the vtable
808 should be marked by the GC. */
809 if (! flag_hash_synchronization)
810 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
811 build_pointer_type (object_type_node));
812 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
813 FIELD_PRIVATE (t) = 1;
814 FINISH_RECORD (object_type_node);
816 field_type_node = make_node (RECORD_TYPE);
817 field_ptr_type_node = build_pointer_type (field_type_node);
818 method_type_node = make_node (RECORD_TYPE);
819 method_ptr_type_node = build_pointer_type (method_type_node);
821 set_super_info (0, class_type_node, object_type_node, 0);
822 set_super_info (0, string_type_node, object_type_node, 0);
823 class_ptr_type = build_pointer_type (class_type_node);
825 PUSH_FIELD (input_location,
826 class_type_node, field, "next_or_version", class_ptr_type);
827 PUSH_FIELD (input_location,
828 class_type_node, field, "name", utf8const_ptr_type);
829 PUSH_FIELD (input_location,
830 class_type_node, field, "accflags", access_flags_type_node);
831 PUSH_FIELD (input_location,
832 class_type_node, field, "superclass", class_ptr_type);
833 PUSH_FIELD (input_location,
834 class_type_node, field, "constants", constants_type_node);
835 constants_field_decl_node = field;
836 PUSH_FIELD (input_location,
837 class_type_node, field, "methods", method_ptr_type_node);
838 PUSH_FIELD (input_location,
839 class_type_node, field, "method_count", short_type_node);
840 PUSH_FIELD (input_location,
841 class_type_node, field, "vtable_method_count", short_type_node);
842 PUSH_FIELD (input_location,
843 class_type_node, field, "fields", field_ptr_type_node);
844 PUSH_FIELD (input_location,
845 class_type_node, field, "size_in_bytes", int_type_node);
846 PUSH_FIELD (input_location,
847 class_type_node, field, "field_count", short_type_node);
848 PUSH_FIELD (input_location,
849 class_type_node, field, "static_field_count", short_type_node);
850 PUSH_FIELD (input_location,
851 class_type_node, field, "vtable", dtable_ptr_type);
852 PUSH_FIELD (input_location,
853 class_type_node, field, "otable", otable_ptr_type);
854 PUSH_FIELD (input_location,
855 class_type_node, field, "otable_syms",
856 symbols_array_ptr_type);
857 PUSH_FIELD (input_location,
858 class_type_node, field, "atable", atable_ptr_type);
859 PUSH_FIELD (input_location,
860 class_type_node, field, "atable_syms",
861 symbols_array_ptr_type);
862 PUSH_FIELD (input_location,
863 class_type_node, field, "itable", itable_ptr_type);
864 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
865 symbols_array_ptr_type);
866 PUSH_FIELD (input_location,
867 class_type_node, field, "catch_classes", ptr_type_node);
868 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
869 build_pointer_type (class_ptr_type));
870 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
871 PUSH_FIELD (input_location,
872 class_type_node, field, "interface_count", short_type_node);
873 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
874 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
875 PUSH_FIELD (input_location,
876 class_type_node, field, "depth", short_type_node);
877 PUSH_FIELD (input_location,
878 class_type_node, field, "ancestors", ptr_type_node);
879 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
880 PUSH_FIELD (input_location,
881 class_type_node, field, "arrayclass", ptr_type_node);
882 PUSH_FIELD (input_location,
883 class_type_node, field, "protectionDomain", ptr_type_node);
884 PUSH_FIELD (input_location,
885 class_type_node, field, "assertion_table", ptr_type_node);
886 PUSH_FIELD (input_location,
887 class_type_node, field, "hack_signers", ptr_type_node);
888 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
889 PUSH_FIELD (input_location,
890 class_type_node, field, "aux_info", ptr_type_node);
891 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
892 PUSH_FIELD (input_location,
893 class_type_node, field, "reflection_data", ptr_type_node);
894 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
895 FIELD_PRIVATE (t) = 1;
896 push_super_field (class_type_node, object_type_node);
898 FINISH_RECORD (class_type_node);
899 build_decl (BUILTINS_LOCATION,
900 TYPE_DECL, get_identifier ("Class"), class_type_node);
902 field_info_union_node = make_node (UNION_TYPE);
903 PUSH_FIELD (input_location,
904 field_info_union_node, field, "boffset", int_type_node);
905 PUSH_FIELD (input_location,
906 field_info_union_node, field, "addr", ptr_type_node);
907 layout_type (field_info_union_node);
909 PUSH_FIELD (input_location,
910 field_type_node, field, "name", utf8const_ptr_type);
911 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
912 PUSH_FIELD (input_location,
913 field_type_node, field, "accflags", access_flags_type_node);
914 PUSH_FIELD (input_location,
915 field_type_node, field, "bsize", unsigned_short_type_node);
916 PUSH_FIELD (input_location,
917 field_type_node, field, "info", field_info_union_node);
918 FINISH_RECORD (field_type_node);
919 build_decl (BUILTINS_LOCATION,
920 TYPE_DECL, get_identifier ("Field"), field_type_node);
922 nativecode_ptr_array_type_node
923 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
925 PUSH_FIELD (input_location,
926 dtable_type, field, "class", class_ptr_type);
927 PUSH_FIELD (input_location,
928 dtable_type, field, "methods", nativecode_ptr_array_type_node);
929 FINISH_RECORD (dtable_type);
930 build_decl (BUILTINS_LOCATION,
931 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
933 jexception_type = make_node (RECORD_TYPE);
934 PUSH_FIELD (input_location,
935 jexception_type, field, "start_pc", ptr_type_node);
936 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
937 PUSH_FIELD (input_location,
938 jexception_type, field, "handler_pc", ptr_type_node);
939 PUSH_FIELD (input_location,
940 jexception_type, field, "catch_type", class_ptr_type);
941 FINISH_RECORD (jexception_type);
942 build_decl (BUILTINS_LOCATION,
943 TYPE_DECL, get_identifier ("jexception"), field_type_node);
944 jexception_ptr_type = build_pointer_type (jexception_type);
946 lineNumberEntry_type = make_node (RECORD_TYPE);
947 PUSH_FIELD (input_location,
948 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
949 PUSH_FIELD (input_location,
950 lineNumberEntry_type, field, "start_pc", ptr_type_node);
951 FINISH_RECORD (lineNumberEntry_type);
953 lineNumbers_type = make_node (RECORD_TYPE);
954 PUSH_FIELD (input_location,
955 lineNumbers_type, field, "length", unsigned_int_type_node);
956 FINISH_RECORD (lineNumbers_type);
958 PUSH_FIELD (input_location,
959 method_type_node, field, "name", utf8const_ptr_type);
960 PUSH_FIELD (input_location,
961 method_type_node, field, "signature", utf8const_ptr_type);
962 PUSH_FIELD (input_location,
963 method_type_node, field, "accflags", access_flags_type_node);
964 PUSH_FIELD (input_location,
965 method_type_node, field, "index", unsigned_short_type_node);
966 PUSH_FIELD (input_location,
967 method_type_node, field, "ncode", nativecode_ptr_type_node);
968 PUSH_FIELD (input_location,
969 method_type_node, field, "throws", ptr_type_node);
970 FINISH_RECORD (method_type_node);
971 build_decl (BUILTINS_LOCATION,
972 TYPE_DECL, get_identifier ("Method"), method_type_node);
974 end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
976 t = build_function_type_list (ptr_type_node, class_ptr_type, NULL_TREE);
977 alloc_object_node = add_builtin_function ("_Jv_AllocObject", t,
978 0, NOT_BUILT_IN, NULL, NULL_TREE);
979 DECL_IS_MALLOC (alloc_object_node) = 1;
980 alloc_no_finalizer_node =
981 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t,
982 0, NOT_BUILT_IN, NULL, NULL_TREE);
983 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
985 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
986 soft_initclass_node = add_builtin_function ("_Jv_InitClass", t,
987 0, NOT_BUILT_IN, NULL, NULL_TREE);
988 t = build_function_type_list (ptr_type_node,
989 class_ptr_type, int_type_node, NULL_TREE);
990 soft_resolvepoolentry_node
991 = add_builtin_function ("_Jv_ResolvePoolEntry", t,
992 0,NOT_BUILT_IN, NULL, NULL_TREE);
993 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
994 t = build_function_type_list (void_type_node,
995 class_ptr_type, int_type_node, NULL_TREE);
996 throw_node = add_builtin_function ("_Jv_Throw", t,
997 0, NOT_BUILT_IN, NULL, NULL_TREE);
998 /* Mark throw_nodes as `noreturn' functions with side effects. */
999 TREE_THIS_VOLATILE (throw_node) = 1;
1000 TREE_SIDE_EFFECTS (throw_node) = 1;
1002 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1003 soft_monitorenter_node
1004 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1005 NULL, NULL_TREE);
1006 soft_monitorexit_node
1007 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1008 NULL, NULL_TREE);
1010 t = build_function_type_list (ptr_type_node,
1011 ptr_type_node, int_type_node, NULL_TREE);
1012 soft_newarray_node
1013 = add_builtin_function ("_Jv_NewPrimArray", t,
1014 0, NOT_BUILT_IN, NULL, NULL_TREE);
1015 DECL_IS_MALLOC (soft_newarray_node) = 1;
1017 t = build_function_type_list (ptr_type_node,
1018 int_type_node, class_ptr_type,
1019 object_ptr_type_node, NULL_TREE);
1020 soft_anewarray_node
1021 = add_builtin_function ("_Jv_NewObjectArray", t,
1022 0, NOT_BUILT_IN, NULL, NULL_TREE);
1023 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1025 t = build_varargs_function_type_list (ptr_type_node,
1026 ptr_type_node, int_type_node,
1027 NULL_TREE);
1028 soft_multianewarray_node
1029 = add_builtin_function ("_Jv_NewMultiArray", t,
1030 0, NOT_BUILT_IN, NULL, NULL_TREE);
1031 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1033 t = build_function_type_list (void_type_node, int_type_node, NULL_TREE);
1034 soft_badarrayindex_node
1035 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1036 0, NOT_BUILT_IN, NULL, NULL_TREE);
1037 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1038 effects. */
1039 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1040 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1042 t = build_function_type_list (void_type_node, NULL_TREE);
1043 soft_nullpointer_node
1044 = add_builtin_function ("_Jv_ThrowNullPointerException", t,
1045 0, NOT_BUILT_IN, NULL, NULL_TREE);
1046 /* Mark soft_nullpointer_node as a `noreturn' function with side
1047 effects. */
1048 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1049 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1051 soft_abstractmethod_node
1052 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t,
1053 0, NOT_BUILT_IN, NULL, NULL_TREE);
1054 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1055 effects. */
1056 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1057 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1059 soft_nosuchfield_node
1060 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t,
1061 0, NOT_BUILT_IN, NULL, NULL_TREE);
1062 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1063 effects. */
1064 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1065 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1067 t = build_function_type_list (ptr_type_node,
1068 class_ptr_type, object_ptr_type_node,
1069 NULL_TREE);
1070 soft_checkcast_node
1071 = add_builtin_function ("_Jv_CheckCast", t,
1072 0, NOT_BUILT_IN, NULL, NULL_TREE);
1073 t = build_function_type_list (boolean_type_node,
1074 object_ptr_type_node, class_ptr_type,
1075 NULL_TREE);
1076 soft_instanceof_node
1077 = add_builtin_function ("_Jv_IsInstanceOf", t,
1078 0, NOT_BUILT_IN, NULL, NULL_TREE);
1079 DECL_PURE_P (soft_instanceof_node) = 1;
1080 t = build_function_type_list (void_type_node,
1081 object_ptr_type_node, object_ptr_type_node,
1082 NULL_TREE);
1083 soft_checkarraystore_node
1084 = add_builtin_function ("_Jv_CheckArrayStore", t,
1085 0, NOT_BUILT_IN, NULL, NULL_TREE);
1086 t = build_function_type_list (ptr_type_node,
1087 ptr_type_node, ptr_type_node, int_type_node,
1088 NULL_TREE);
1089 soft_lookupinterfacemethod_node
1090 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t,
1091 0, NOT_BUILT_IN, NULL, NULL_TREE);
1092 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1094 t = build_function_type_list (ptr_type_node,
1095 ptr_type_node, ptr_type_node, ptr_type_node,
1096 NULL_TREE);
1097 soft_lookupinterfacemethodbyname_node
1098 = add_builtin_function ("_Jv_LookupInterfaceMethod", t,
1099 0, NOT_BUILT_IN, NULL, NULL_TREE);
1100 t = build_function_type_list (ptr_type_node,
1101 object_ptr_type_node, ptr_type_node,
1102 ptr_type_node, int_type_node, NULL_TREE);
1103 soft_lookupjnimethod_node
1104 = add_builtin_function ("_Jv_LookupJNIMethod", t,
1105 0, NOT_BUILT_IN, NULL, NULL_TREE);
1106 t = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
1107 soft_getjnienvnewframe_node
1108 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t,
1109 0, NOT_BUILT_IN, NULL, NULL_TREE);
1110 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1111 soft_jnipopsystemframe_node
1112 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t,
1113 0, NOT_BUILT_IN, NULL, NULL_TREE);
1115 t = build_function_type_list (object_ptr_type_node,
1116 object_ptr_type_node, NULL_TREE);
1117 soft_unwrapjni_node
1118 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t,
1119 0, NOT_BUILT_IN, NULL, NULL_TREE);
1121 t = build_function_type_list (int_type_node,
1122 int_type_node, int_type_node, NULL_TREE);
1123 soft_idiv_node
1124 = add_builtin_function ("_Jv_divI", t,
1125 0, NOT_BUILT_IN, NULL, NULL_TREE);
1127 soft_irem_node
1128 = add_builtin_function ("_Jv_remI", t,
1129 0, NOT_BUILT_IN, NULL, NULL_TREE);
1131 t = build_function_type_list (long_type_node,
1132 long_type_node, long_type_node, NULL_TREE);
1133 soft_ldiv_node
1134 = add_builtin_function ("_Jv_divJ", t,
1135 0, NOT_BUILT_IN, NULL, NULL_TREE);
1137 soft_lrem_node
1138 = add_builtin_function ("_Jv_remJ", t,
1139 0, NOT_BUILT_IN, NULL, NULL_TREE);
1141 initialize_builtins ();
1143 soft_fmod_node = builtin_decl_explicit (BUILT_IN_FMOD);
1145 parse_version ();
1149 /* Look up NAME in the current binding level and its superiors
1150 in the namespace of variables, functions and typedefs.
1151 Return a ..._DECL node of some kind representing its definition,
1152 or return 0 if it is undefined. */
1154 tree
1155 lookup_name (tree name)
1157 tree val;
1158 if (current_binding_level != global_binding_level
1159 && IDENTIFIER_LOCAL_VALUE (name))
1160 val = IDENTIFIER_LOCAL_VALUE (name);
1161 else
1162 val = IDENTIFIER_GLOBAL_VALUE (name);
1163 return val;
1166 /* Similar to `lookup_name' but look only at current binding level and
1167 the previous one if it's the parameter level. */
1169 static tree
1170 lookup_name_current_level (tree name)
1172 tree t;
1174 if (current_binding_level == global_binding_level)
1175 return IDENTIFIER_GLOBAL_VALUE (name);
1177 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1178 return 0;
1180 for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
1181 if (DECL_NAME (t) == name)
1182 break;
1184 return t;
1187 /* Record a decl-node X as belonging to the current lexical scope.
1188 Check for errors (such as an incompatible declaration for the same
1189 name already seen in the same scope).
1191 Returns either X or an old decl for the same name.
1192 If an old decl is returned, it may have been smashed
1193 to agree with what X says. */
1195 tree
1196 pushdecl (tree x)
1198 tree t;
1199 tree name = DECL_NAME (x);
1200 struct binding_level *b = current_binding_level;
1202 if (TREE_CODE (x) != TYPE_DECL)
1203 DECL_CONTEXT (x) = current_function_decl;
1204 if (name)
1206 t = lookup_name_current_level (name);
1207 if (t != 0 && t == error_mark_node)
1208 /* error_mark_node is 0 for a while during initialization! */
1210 t = 0;
1211 error ("%q+D used prior to declaration", x);
1214 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1215 to point to the TYPE_DECL.
1216 Since Java does not have typedefs, a type can only have
1217 one (true) name, given by a class, interface, or builtin. */
1218 if (TREE_CODE (x) == TYPE_DECL
1219 && TYPE_NAME (TREE_TYPE (x)) == 0
1220 && TREE_TYPE (x) != error_mark_node)
1222 TYPE_NAME (TREE_TYPE (x)) = x;
1223 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1226 /* This name is new in its binding level.
1227 Install the new declaration and return it. */
1228 if (b == global_binding_level)
1230 /* Install a global value. */
1232 IDENTIFIER_GLOBAL_VALUE (name) = x;
1234 else
1236 /* Here to install a non-global value. */
1237 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1238 IDENTIFIER_LOCAL_VALUE (name) = x;
1240 /* If storing a local value, there may already be one (inherited).
1241 If so, record it for restoration when this binding level ends. */
1242 if (oldlocal != 0)
1243 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1247 /* Put decls on list in reverse order.
1248 We will reverse them later if necessary. */
1249 DECL_CHAIN (x) = b->names;
1250 b->names = x;
1252 return x;
1255 void
1256 pushdecl_force_head (tree x)
1258 current_binding_level->names = x;
1261 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1263 tree
1264 pushdecl_top_level (tree x)
1266 tree t;
1267 struct binding_level *b = current_binding_level;
1269 current_binding_level = global_binding_level;
1270 t = pushdecl (x);
1271 current_binding_level = b;
1272 return t;
1275 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1277 tree
1278 pushdecl_function_level (tree x)
1280 tree t;
1281 struct binding_level *b = current_binding_level;
1283 current_binding_level = function_binding_level;
1284 t = pushdecl (x);
1285 current_binding_level = b;
1286 return t;
1289 /* Return true if we are in the global binding level. */
1291 bool
1292 global_bindings_p (void)
1294 return current_binding_level == global_binding_level;
1297 /* Return the list of declarations of the current level.
1298 Note that this list is in reverse order unless/until
1299 you nreverse it; and when you do nreverse it, you must
1300 store the result back using `storedecls' or you will lose. */
1302 tree
1303 getdecls (void)
1305 return current_binding_level->names;
1308 /* Create a new `struct binding_level'. */
1310 static struct binding_level *
1311 make_binding_level (void)
1313 /* NOSTRICT */
1314 return ggc_cleared_alloc<binding_level> ();
1317 void
1318 pushlevel (int unused ATTRIBUTE_UNUSED)
1320 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1322 /* Reuse or create a struct for this binding level. */
1324 if (free_binding_level)
1326 newlevel = free_binding_level;
1327 free_binding_level = free_binding_level->level_chain;
1329 else
1331 newlevel = make_binding_level ();
1334 /* Add this level to the front of the chain (stack) of levels that
1335 are active. */
1337 *newlevel = clear_binding_level;
1338 newlevel->level_chain = current_binding_level;
1339 newlevel->loc = input_location;
1340 current_binding_level = newlevel;
1341 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1342 newlevel->binding_depth = binding_depth;
1343 indent ();
1344 fprintf (stderr, "push %s level %p pc %d\n",
1345 (is_class_level) ? "class" : "block", newlevel, current_pc);
1346 is_class_level = 0;
1347 binding_depth++;
1348 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1351 /* Exit a binding level.
1352 Pop the level off, and restore the state of the identifier-decl mappings
1353 that were in effect when this level was entered.
1355 If KEEP is nonzero, this level had explicit declarations, so
1356 and create a "block" (a BLOCK node) for the level
1357 to record its declarations and subblocks for symbol table output.
1359 If FUNCTIONBODY is nonzero, this level is the body of a function,
1360 so create a block as if KEEP were set and also clear out all
1361 label names.
1363 If REVERSE is nonzero, reverse the order of decls before putting
1364 them into the BLOCK. */
1366 tree
1367 poplevel (int keep, int reverse, int functionbody)
1369 tree link;
1370 /* The chain of decls was accumulated in reverse order.
1371 Put it into forward order, just for cleanliness. */
1372 tree decls;
1373 tree subblocks = current_binding_level->blocks;
1374 tree block = 0;
1375 tree decl;
1376 tree bind = 0;
1378 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1379 binding_depth--;
1380 indent ();
1381 if (current_binding_level->end_pc != LARGEST_PC)
1382 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1383 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1384 current_binding_level->end_pc);
1385 else
1386 fprintf (stderr, "pop %s level %p pc %d\n",
1387 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1388 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1390 /* Get the decls in the order they were written.
1391 Usually current_binding_level->names is in reverse order.
1392 But parameter decls were previously put in forward order. */
1394 if (reverse)
1395 current_binding_level->names
1396 = decls = nreverse (current_binding_level->names);
1397 else
1398 decls = current_binding_level->names;
1400 for (decl = decls; decl; decl = DECL_CHAIN (decl))
1401 if (TREE_CODE (decl) == VAR_DECL
1402 && DECL_LANG_SPECIFIC (decl) != NULL
1403 && DECL_LOCAL_SLOT_NUMBER (decl))
1404 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1406 /* If there were any declarations in that level,
1407 or if this level is a function body,
1408 create a BLOCK to record them for the life of this function. */
1410 block = 0;
1411 if (keep || functionbody)
1412 block = make_node (BLOCK);
1414 if (current_binding_level->exception_range)
1415 expand_end_java_handler (current_binding_level->exception_range);
1417 if (block != 0)
1419 /* If any statements have been generated at this level, create a
1420 BIND_EXPR to hold them and copy the variables to it. This
1421 only applies to the bytecode compiler. */
1422 if (current_binding_level->stmts)
1424 tree decl = decls;
1425 tree *var = &BLOCK_VARS (block);
1427 /* Copy decls from names list, ignoring labels. */
1428 while (decl)
1430 tree next = DECL_CHAIN (decl);
1431 if (TREE_CODE (decl) != LABEL_DECL)
1433 *var = decl;
1434 var = &DECL_CHAIN (decl);
1436 decl = next;
1438 *var = NULL;
1440 bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block),
1441 BLOCK_EXPR_BODY (block), block);
1442 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1444 if (BIND_EXPR_BODY (bind)
1445 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1446 TREE_SIDE_EFFECTS (bind) = 1;
1448 /* FIXME: gimplifier brain damage. */
1449 if (BIND_EXPR_BODY (bind) == NULL)
1450 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1452 SET_EXPR_LOCATION (bind, current_binding_level->loc);
1454 current_binding_level->stmts = NULL;
1456 else
1458 BLOCK_VARS (block) = decls;
1460 BLOCK_SUBBLOCKS (block) = subblocks;
1463 /* In each subblock, record that this is its superior. */
1465 for (link = subblocks; link; link = BLOCK_CHAIN (link))
1466 BLOCK_SUPERCONTEXT (link) = block;
1468 /* Clear out the meanings of the local variables of this level. */
1470 for (link = decls; link; link = DECL_CHAIN (link))
1472 tree name = DECL_NAME (link);
1473 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1475 /* If the ident. was used or addressed via a local extern decl,
1476 don't forget that fact. */
1477 if (DECL_EXTERNAL (link))
1479 if (TREE_USED (link))
1480 TREE_USED (name) = 1;
1481 if (TREE_ADDRESSABLE (link))
1482 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1484 IDENTIFIER_LOCAL_VALUE (name) = 0;
1488 /* Restore all name-meanings of the outer levels
1489 that were shadowed by this level. */
1491 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1492 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1494 /* If the level being exited is the top level of a function,
1495 check over all the labels, and clear out the current
1496 (function local) meanings of their names. */
1498 if (functionbody)
1500 /* If this is the top level block of a function,
1501 the vars are the function's parameters.
1502 Don't leave them in the BLOCK because they are
1503 found in the FUNCTION_DECL instead. */
1505 BLOCK_VARS (block) = 0;
1508 /* Pop the current level, and free the structure for reuse. */
1511 struct binding_level *level = current_binding_level;
1512 current_binding_level = current_binding_level->level_chain;
1514 level->level_chain = free_binding_level;
1515 free_binding_level = level;
1518 /* Dispose of the block that we just made inside some higher level. */
1519 if (functionbody)
1521 DECL_INITIAL (current_function_decl) = block;
1522 DECL_SAVED_TREE (current_function_decl) = bind;
1524 else
1526 if (block)
1528 current_binding_level->blocks
1529 = block_chainon (current_binding_level->blocks, block);
1531 /* If we did not make a block for the level just exited,
1532 any blocks made for inner levels
1533 (since they cannot be recorded as subblocks in that level)
1534 must be carried forward so they will later become subblocks
1535 of something else. */
1536 else if (subblocks)
1537 current_binding_level->blocks
1538 = block_chainon (current_binding_level->blocks, subblocks);
1540 if (bind)
1541 java_add_stmt (bind);
1544 if (block)
1545 TREE_USED (block) = 1;
1546 return block;
1549 void
1550 maybe_pushlevels (int pc)
1552 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1553 current_pc = pc;
1554 #endif
1556 while (pending_local_decls != NULL_TREE &&
1557 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1559 tree *ptr = &pending_local_decls;
1560 tree decl = *ptr, next;
1561 int end_pc = DECL_LOCAL_END_PC (decl);
1563 while (*ptr != NULL_TREE
1564 && DECL_LOCAL_START_PC (*ptr) <= pc
1565 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1566 ptr = &DECL_CHAIN (*ptr);
1567 pending_local_decls = *ptr;
1568 *ptr = NULL_TREE;
1570 /* Force non-nested range to be nested in current range by
1571 truncating variable lifetimes. */
1572 if (end_pc > current_binding_level->end_pc)
1574 tree t;
1575 end_pc = current_binding_level->end_pc;
1576 for (t = decl; t != NULL_TREE; t = DECL_CHAIN (t))
1577 DECL_LOCAL_END_PC (t) = end_pc;
1580 maybe_start_try (pc, end_pc);
1582 pushlevel (1);
1584 current_binding_level->end_pc = end_pc;
1585 current_binding_level->start_pc = pc;
1586 current_binding_level->names = NULL;
1587 for ( ; decl != NULL_TREE; decl = next)
1589 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1590 tree base_decl;
1591 next = DECL_CHAIN (decl);
1592 push_jvm_slot (index, decl);
1593 pushdecl (decl);
1594 base_decl
1595 = find_local_variable (index, TREE_TYPE (decl), pc);
1596 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1597 base_decl = TREE_VEC_ELT (base_decl_map, index);
1598 SET_DECL_VALUE_EXPR (decl, base_decl);
1599 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1603 maybe_start_try (pc, 0);
1606 void
1607 maybe_poplevels (int pc)
1609 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1610 current_pc = pc;
1611 #endif
1613 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1614 inclusive, so a variable is live if pc == end_pc. Here, we
1615 terminate a range if the current pc is equal to the end of the
1616 range, and this is *before* we have generated code for the
1617 instruction at end_pc. We're closing a binding level one
1618 instruction too early.*/
1619 while (current_binding_level->end_pc <= pc)
1620 poplevel (1, 0, 0);
1623 /* Terminate any binding which began during the range beginning at
1624 start_pc. This tidies up improperly nested local variable ranges
1625 and exception handlers; a variable declared within an exception
1626 range is forcibly terminated when that exception ends. */
1628 void
1629 force_poplevels (int start_pc)
1631 while (current_binding_level->start_pc > start_pc)
1633 if (pedantic && current_binding_level->start_pc > start_pc)
1634 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1635 current_function_decl,
1636 current_binding_level->start_pc);
1637 poplevel (1, 0, 0);
1641 /* integrate_decl_tree calls this function. */
1643 void
1644 java_dup_lang_specific_decl (tree node)
1646 int lang_decl_size;
1647 struct lang_decl *x;
1649 if (!DECL_LANG_SPECIFIC (node))
1650 return;
1652 lang_decl_size = sizeof (struct lang_decl);
1653 x = ggc_alloc<struct lang_decl> ();
1654 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1655 DECL_LANG_SPECIFIC (node) = x;
1658 void
1659 give_name_to_locals (JCF *jcf)
1661 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1662 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1663 tree parm;
1664 pending_local_decls = NULL_TREE;
1665 if (n == 0)
1666 return;
1667 JCF_SEEK (jcf, n);
1668 n = JCF_readu2 (jcf);
1669 for (i = 0; i < n; i++)
1671 int start_pc = JCF_readu2 (jcf);
1672 int length = JCF_readu2 (jcf);
1673 int name_index = JCF_readu2 (jcf);
1674 int signature_index = JCF_readu2 (jcf);
1675 int slot = JCF_readu2 (jcf);
1676 tree name = get_name_constant (jcf, name_index);
1677 tree type = parse_signature (jcf, signature_index);
1678 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1679 && start_pc == 0
1680 && length == DECL_CODE_LENGTH (current_function_decl))
1682 tree decl = TREE_VEC_ELT (decl_map, slot);
1683 DECL_NAME (decl) = name;
1684 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1685 warning (0, "bad type in parameter debug info");
1687 else
1689 tree *ptr;
1690 int end_pc = start_pc + length;
1691 tree decl = build_decl (input_location, VAR_DECL, name, type);
1692 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1694 warning (0, "bad PC range for debug info for local %q+D",
1695 decl);
1696 end_pc = DECL_CODE_LENGTH (current_function_decl);
1699 /* Adjust start_pc if necessary so that the local's first
1700 store operation will use the relevant DECL as a
1701 destination. Fore more information, read the leading
1702 comments for expr.c:maybe_adjust_start_pc. */
1703 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1705 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1706 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1707 DECL_LOCAL_START_PC (decl) = start_pc;
1708 DECL_LOCAL_END_PC (decl) = end_pc;
1710 /* Now insert the new decl in the proper place in
1711 pending_local_decls. We are essentially doing an insertion sort,
1712 which works fine, since the list input will normally already
1713 be sorted. */
1714 ptr = &pending_local_decls;
1715 while (*ptr != NULL_TREE
1716 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1717 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1718 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1719 ptr = &DECL_CHAIN (*ptr);
1720 DECL_CHAIN (decl) = *ptr;
1721 *ptr = decl;
1725 pending_local_decls = nreverse (pending_local_decls);
1727 /* Fill in default names for the parameters. */
1728 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1729 parm != NULL_TREE; parm = DECL_CHAIN (parm), i++)
1731 if (DECL_NAME (parm) == NULL_TREE)
1733 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1734 if (arg_i == 0)
1735 DECL_NAME (parm) = get_identifier ("this");
1736 else
1738 char buffer[12];
1739 sprintf (buffer, "ARG_%d", arg_i);
1740 DECL_NAME (parm) = get_identifier (buffer);
1746 tree
1747 build_result_decl (tree fndecl)
1749 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1750 tree result = DECL_RESULT (fndecl);
1751 if (! result)
1753 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1754 RESULT_DECL, NULL_TREE, restype);
1755 DECL_ARTIFICIAL (result) = 1;
1756 DECL_IGNORED_P (result) = 1;
1757 DECL_CONTEXT (result) = fndecl;
1758 DECL_RESULT (fndecl) = result;
1760 return result;
1763 void
1764 start_java_method (tree fndecl)
1766 tree tem, *ptr;
1767 int i;
1769 uniq = 0;
1771 current_function_decl = fndecl;
1772 announce_function (fndecl);
1774 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1775 decl_map = make_tree_vec (i);
1776 base_decl_map = make_tree_vec (i);
1777 type_map = XRESIZEVEC (tree, type_map, i);
1779 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1780 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1781 current_pc = 0;
1782 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1783 pushlevel (1); /* Push parameters. */
1785 ptr = &DECL_ARGUMENTS (fndecl);
1786 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1787 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1789 tree parm_name = NULL_TREE, parm_decl;
1790 tree parm_type = TREE_VALUE (tem);
1791 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1793 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1794 DECL_CONTEXT (parm_decl) = fndecl;
1795 if (targetm.calls.promote_prototypes (parm_type)
1796 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1797 && INTEGRAL_TYPE_P (parm_type))
1798 parm_type = integer_type_node;
1799 DECL_ARG_TYPE (parm_decl) = parm_type;
1801 *ptr = parm_decl;
1802 ptr = &DECL_CHAIN (parm_decl);
1804 /* Add parm_decl to the decl_map. */
1805 push_jvm_slot (i, parm_decl);
1807 /* The this parameter of methods is artificial. */
1808 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE && i == 0)
1809 DECL_ARTIFICIAL (parm_decl) = 1;
1811 type_map[i] = TREE_TYPE (parm_decl);
1812 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1814 i++;
1815 type_map[i] = void_type_node;
1818 *ptr = NULL_TREE;
1819 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1821 while (i < DECL_MAX_LOCALS(fndecl))
1822 type_map[i++] = NULL_TREE;
1824 build_result_decl (fndecl);
1825 DECL_SOURCE_LOCATION (fndecl) = input_location;
1827 /* Push local variables. */
1828 pushlevel (2);
1830 function_binding_level = current_binding_level;
1833 void
1834 end_java_method (void)
1836 tree fndecl = current_function_decl;
1838 /* pop out of function */
1839 poplevel (1, 1, 0);
1841 /* pop out of its parameters */
1842 poplevel (1, 0, 1);
1844 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1846 if (DECL_SAVED_TREE (fndecl))
1848 tree fbody, block_body;
1849 /* Before we check initialization, attached all class initialization
1850 variable to the block_body */
1851 fbody = DECL_SAVED_TREE (fndecl);
1852 block_body = BIND_EXPR_BODY (fbody);
1853 hash_table<treetreehasher> *ht = DECL_FUNCTION_INIT_TEST_TABLE (fndecl);
1854 ht->traverse<tree, attach_init_test_initialization_flags> (block_body);
1857 finish_method (fndecl);
1859 current_function_decl = NULL_TREE;
1860 base_decl_map = NULL_TREE;
1863 /* Prepare a method for expansion. */
1865 void
1866 finish_method (tree fndecl)
1868 tree *tp = &DECL_SAVED_TREE (fndecl);
1870 /* Wrap body of synchronized methods in a monitorenter,
1871 plus monitorexit cleanup. */
1872 if (METHOD_SYNCHRONIZED (fndecl))
1874 tree enter, exit, lock;
1875 if (METHOD_STATIC (fndecl))
1876 lock = build_class_ref (DECL_CONTEXT (fndecl));
1877 else
1878 lock = DECL_ARGUMENTS (fndecl);
1879 BUILD_MONITOR_ENTER (enter, lock);
1880 BUILD_MONITOR_EXIT (exit, lock);
1881 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1882 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1885 /* Convert function tree to GENERIC prior to inlining. */
1886 java_genericize (fndecl);
1888 /* Store the end of the function, so that we get good line number
1889 info for the epilogue. */
1890 if (DECL_STRUCT_FUNCTION (fndecl))
1891 set_cfun (DECL_STRUCT_FUNCTION (fndecl));
1892 else
1893 allocate_struct_function (fndecl, false);
1894 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1896 /* Defer inlining and expansion to the cgraph optimizers. */
1897 cgraph_node::finalize_function (fndecl, false);
1900 /* We pessimistically marked all methods and fields external until we
1901 knew what set of classes we were planning to compile. Now mark those
1902 associated with CLASS to be generated locally as not external. */
1904 static void
1905 java_mark_decl_local (tree decl)
1907 DECL_EXTERNAL (decl) = 0;
1909 #ifdef ENABLE_CHECKING
1910 /* Double check that we didn't pass the function to the callgraph early. */
1911 if (TREE_CODE (decl) == FUNCTION_DECL)
1913 struct cgraph_node *node = cgraph_node::get (decl);
1914 gcc_assert (!node || !node->definition);
1916 #endif
1917 gcc_assert (!DECL_RTL_SET_P (decl));
1920 /* Given appropriate target support, G++ will emit hidden aliases for native
1921 methods. Using this hidden name is required for proper operation of
1922 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1923 proper target support, then mark the method for aliasing. */
1925 static void
1926 java_mark_cni_decl_local (tree decl)
1928 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1929 return;
1930 #endif
1932 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1933 DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1935 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1936 mangler. We might have already referenced this native method and
1937 therefore created its name, but even if we have it won't hurt.
1938 We'll just go via its externally visible name, rather than its
1939 hidden alias. However, we must force things so that the correct
1940 mangling is done. */
1942 if (DECL_ASSEMBLER_NAME_SET_P (decl))
1943 java_mangle_decl (decl);
1944 if (DECL_RTL_SET_P (decl))
1946 SET_DECL_RTL (decl, 0);
1947 make_decl_rtl (decl);
1951 /* Use the preceding two functions and mark all members of the class. */
1953 void
1954 java_mark_class_local (tree klass)
1956 tree t;
1958 for (t = TYPE_FIELDS (klass); t ; t = DECL_CHAIN (t))
1959 if (FIELD_STATIC (t))
1960 java_mark_decl_local (t);
1962 for (t = TYPE_METHODS (klass); t ; t = DECL_CHAIN (t))
1963 if (!METHOD_ABSTRACT (t))
1965 if (METHOD_NATIVE (t) && !flag_jni)
1966 java_mark_cni_decl_local (t);
1967 else
1968 java_mark_decl_local (t);
1972 /* Add a statement to a compound_expr. */
1974 tree
1975 add_stmt_to_compound (tree existing, tree type, tree stmt)
1977 if (!stmt)
1978 return existing;
1979 else if (existing)
1981 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
1982 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
1983 | TREE_SIDE_EFFECTS (stmt);
1984 return expr;
1986 else
1987 return stmt;
1990 /* If this node is an expr, mark its input location. Called from
1991 walk_tree(). */
1993 static tree
1994 set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
1995 void *data ATTRIBUTE_UNUSED)
1997 tree t = *tp;
1999 if (CAN_HAVE_LOCATION_P (t))
2001 if (EXPR_HAS_LOCATION(t))
2002 return t; /* Don't walk any further into this expr. */
2003 else
2004 SET_EXPR_LOCATION (t, input_location);
2007 return NULL_TREE; /* Continue walking this expr. */
2010 /* Add a statement to the statement_list currently being constructed.
2011 If the statement_list is null, we don't create a singleton list.
2012 This is necessary because poplevel() assumes that adding a
2013 statement to a null statement_list returns the statement. */
2015 tree
2016 java_add_stmt (tree new_stmt)
2018 tree stmts = current_binding_level->stmts;
2019 tree_stmt_iterator i;
2021 if (LOCATION_FILE (input_location))
2022 walk_tree (&new_stmt, set_input_location, NULL, NULL);
2024 if (stmts == NULL)
2025 return current_binding_level->stmts = new_stmt;
2027 /* Force STMTS to be a statement_list. */
2028 if (TREE_CODE (stmts) != STATEMENT_LIST)
2030 tree t = make_node (STATEMENT_LIST);
2031 i = tsi_last (t);
2032 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2033 stmts = t;
2036 i = tsi_last (stmts);
2037 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2038 TREE_TYPE (stmts) = void_type_node;
2040 return current_binding_level->stmts = stmts;
2043 /* Add a variable to the current scope. */
2045 tree
2046 java_add_local_var (tree decl)
2048 tree *vars = &current_binding_level->names;
2049 tree next = *vars;
2050 DECL_CHAIN (decl) = next;
2051 *vars = decl;
2052 DECL_CONTEXT (decl) = current_function_decl;
2053 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2054 return decl;
2057 /* Return a pointer to the compound_expr currently being
2058 constructed. */
2060 tree *
2061 get_stmts (void)
2063 return &current_binding_level->stmts;
2066 /* Register an exception range as belonging to the current binding
2067 level. There may only be one: if there are more, we'll create more
2068 binding levels. However, each range can have multiple handlers,
2069 and these are expanded when we call expand_end_java_handler(). */
2071 void
2072 register_exception_range (struct eh_range *range, int pc, int end_pc)
2074 gcc_assert (! current_binding_level->exception_range);
2075 current_binding_level->exception_range = range;
2076 current_binding_level->end_pc = end_pc;
2077 current_binding_level->start_pc = pc;
2080 #include "gt-java-decl.h"