* cgraph.h: Flatten. Remove all include files.
[official-gcc.git] / gcc / java / decl.c
blobfbd09a3d08946cf7cf2bd16d211e9c8a0ca9ef33
1 /* Process declarations and variables for the GNU compiler for the
2 Java(TM) language.
3 Copyright (C) 1996-2014 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 "tree.h"
31 #include "stor-layout.h"
32 #include "stringpool.h"
33 #include "varasm.h"
34 #include "diagnostic-core.h"
35 #include "toplev.h"
36 #include "flags.h"
37 #include "java-tree.h"
38 #include "jcf.h"
39 #include "java-except.h"
40 #include "ggc.h"
41 #include "hash-map.h"
42 #include "is-a.h"
43 #include "plugin-api.h"
44 #include "vec.h"
45 #include "hashtab.h"
46 #include "hash-set.h"
47 #include "machmode.h"
48 #include "tm.h"
49 #include "hard-reg-set.h"
50 #include "input.h"
51 #include "function.h"
52 #include "ipa-ref.h"
53 #include "cgraph.h"
54 #include "tree-inline.h"
55 #include "target.h"
56 #include "version.h"
57 #include "tree-iterator.h"
58 #include "langhooks.h"
60 #if defined (DEBUG_JAVA_BINDING_LEVELS)
61 extern void indent (void);
62 #endif
64 static tree push_jvm_slot (int, tree);
65 static tree lookup_name_current_level (tree);
66 static tree push_promoted_type (const char *, tree);
67 static struct binding_level *make_binding_level (void);
68 static tree create_primitive_vtable (const char *);
69 static tree check_local_unnamed_variable (tree, tree, tree);
70 static void parse_version (void);
73 /* The following ABI flags are used in the high-order bits of the version
74 ID field. The version ID number itself should never be larger than
75 0xfffff, so it should be safe to use top 12 bits for these flags. */
77 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
79 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
80 should be loaded by the bootstrap
81 loader. */
83 /* If an ABI change is made within a GCC release series, rendering current
84 binaries incompatible with the old runtimes, this number must be set to
85 enforce the compatibility rules. */
86 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
88 /* The runtime may recognize a variety of BC ABIs (objects generated by
89 different version of gcj), but will probably always require strict
90 matching for the ordinary (C++) ABI. */
92 /* The version ID of the BC ABI that we generate. This must be kept in
93 sync with parse_version(), libgcj, and reality (if the BC format changes,
94 this must change). */
95 #define GCJ_CURRENT_BC_ABI_VERSION \
96 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
98 /* The ABI version number. */
99 tree gcj_abi_version;
101 /* Name of the Cloneable class. */
102 tree java_lang_cloneable_identifier_node;
104 /* Name of the Serializable class. */
105 tree java_io_serializable_identifier_node;
107 /* The DECL_MAP is a mapping from (index, type) to a decl node.
108 If index < max_locals, it is the index of a local variable.
109 if index >= max_locals, then index-max_locals is a stack slot.
110 The DECL_MAP mapping is represented as a TREE_VEC whose elements
111 are a list of decls (VAR_DECL or PARM_DECL) chained by
112 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
113 we search the chain for a decl with a matching TREE_TYPE. */
115 static GTY(()) tree decl_map;
117 /* The base_decl_map is contains one variable of ptr_type: this is
118 used to contain every variable of reference type that is ever
119 stored in a local variable slot. */
121 static GTY(()) tree base_decl_map;
123 /* An index used to make temporary identifiers unique. */
124 static int uniq;
126 /* A list of local variables VAR_DECLs for this method that we have seen
127 debug information, but we have not reached their starting (byte) PC yet. */
129 static GTY(()) tree pending_local_decls;
131 /* The decl for "_Jv_ResolvePoolEntry". */
132 tree soft_resolvepoolentry_node;
134 /* The decl for the .constants field of an instance of Class. */
135 tree constants_field_decl_node;
137 /* The decl for the .data field of an instance of Class. */
138 tree constants_data_field_decl_node;
140 #if defined(DEBUG_JAVA_BINDING_LEVELS)
141 int binding_depth = 0;
142 int is_class_level = 0;
143 int current_pc;
145 void
146 indent (void)
148 int i;
150 for (i = 0; i < binding_depth*2; i++)
151 putc (' ', stderr);
153 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
155 /* True if decl is a named local variable, i.e. if it is an alias
156 that's used only for debugging purposes. */
158 static bool
159 debug_variable_p (tree decl)
161 if (TREE_CODE (decl) == PARM_DECL)
162 return false;
164 if (LOCAL_SLOT_P (decl))
165 return false;
167 return true;
170 static tree
171 push_jvm_slot (int index, tree decl)
173 DECL_CONTEXT (decl) = current_function_decl;
174 layout_decl (decl, 0);
176 /* Now link the decl into the decl_map. */
177 if (DECL_LANG_SPECIFIC (decl) == NULL)
179 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
180 DECL_LOCAL_START_PC (decl) = 0;
181 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
182 DECL_LOCAL_SLOT_NUMBER (decl) = index;
184 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
185 TREE_VEC_ELT (decl_map, index) = decl;
187 return decl;
190 /* Find the best declaration based upon type. If 'decl' fits 'type' better
191 than 'best', return 'decl'. Otherwise return 'best'. */
193 static tree
194 check_local_unnamed_variable (tree best, tree decl, tree type)
196 tree decl_type = TREE_TYPE (decl);
198 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
200 /* Use the same decl for all integer types <= 32 bits. This is
201 necessary because sometimes a value is stored as (for example)
202 boolean but loaded as int. */
203 if (decl_type == type
204 || (INTEGRAL_TYPE_P (decl_type)
205 && INTEGRAL_TYPE_P (type)
206 && TYPE_PRECISION (decl_type) <= 32
207 && TYPE_PRECISION (type) <= 32
208 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
209 /* ptr_type_node is used for null pointers, which are
210 assignment compatible with everything. */
211 || (TREE_CODE (decl_type) == POINTER_TYPE
212 && type == ptr_type_node)
213 /* Whenever anyone wants to use a slot that is initially
214 occupied by a PARM_DECL of pointer type they must get that
215 decl, even if they asked for a pointer to a different type.
216 However, if someone wants a scalar variable in a slot that
217 initially held a pointer arg -- or vice versa -- we create a
218 new VAR_DECL.
220 ???: As long as verification is correct, this will be a
221 compatible type. But maybe we should create a dummy variable
222 and replace all references to it with the DECL and a
223 NOP_EXPR.
225 || (TREE_CODE (decl_type) == POINTER_TYPE
226 && TREE_CODE (decl) == PARM_DECL
227 && TREE_CODE (type) == POINTER_TYPE))
229 if (best == NULL_TREE
230 || (decl_type == type && TREE_TYPE (best) != type))
231 return decl;
234 return best;
238 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
239 that is valid at PC (or -1 if any pc).
240 If there is no existing matching decl, allocate one. */
242 tree
243 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
245 tree tmp = TREE_VEC_ELT (decl_map, index);
246 tree decl = NULL_TREE;
248 /* Scan through every declaration that has been created in this
249 slot. We're only looking for variables that correspond to local
250 index declarations and PARM_DECLs, not named variables: such
251 local variables are used only for debugging information. */
252 while (tmp != NULL_TREE)
254 if (! debug_variable_p (tmp))
255 decl = check_local_unnamed_variable (decl, tmp, type);
256 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
259 /* gcj has a function called promote_type(), which is used by both
260 the bytecode compiler and the source compiler. Unfortunately,
261 the type systems for the Java VM and the Java language are not
262 the same: a boolean in the VM promotes to an int, not to a wide
263 boolean. If our caller wants something to hold a boolean, that
264 had better be an int, because that slot might be re-used
265 later in integer context. */
266 if (TREE_CODE (type) == BOOLEAN_TYPE)
267 type = integer_type_node;
269 /* If we don't find a match, create one with the type passed in.
270 The name of the variable is #n#m, which n is the variable index
271 in the local variable area and m is a dummy identifier for
272 uniqueness -- multiple variables may share the same local
273 variable index. We don't call pushdecl() to push pointer types
274 into a binding expr because they'll all be replaced by a single
275 variable that is used for every reference in that local variable
276 slot. */
277 if (! decl)
279 char buf[64];
280 tree name;
281 sprintf (buf, "#slot#%d#%d", index, uniq++);
282 name = get_identifier (buf);
283 decl = build_decl (input_location, VAR_DECL, name, type);
284 DECL_IGNORED_P (decl) = 1;
285 DECL_ARTIFICIAL (decl) = 1;
286 decl = push_jvm_slot (index, decl);
287 LOCAL_SLOT_P (decl) = 1;
289 if (TREE_CODE (type) != POINTER_TYPE)
290 pushdecl_function_level (decl);
293 /* As well as creating a local variable that matches the type, we
294 also create a base variable (of ptr_type) that will hold all its
295 aliases. */
296 if (TREE_CODE (type) == POINTER_TYPE
297 && ! TREE_VEC_ELT (base_decl_map, index))
299 char buf[64];
300 tree name;
301 tree base_decl;
302 sprintf (buf, "#ref#%d#%d", index, uniq++);
303 name = get_identifier (buf);
304 base_decl
305 = TREE_VEC_ELT (base_decl_map, index)
306 = build_decl (input_location, VAR_DECL, name, ptr_type_node);
307 pushdecl_function_level (base_decl);
308 DECL_IGNORED_P (base_decl) = 1;
309 DECL_ARTIFICIAL (base_decl) = 1;
312 return decl;
315 /* Called during genericization for every variable. If the variable
316 is a temporary of pointer type, replace it with a common variable
317 thath is used to hold all pointer types that are ever stored in
318 that slot. Set WANT_LVALUE if you want a variable that is to be
319 written to. */
321 static tree
322 java_replace_reference (tree var_decl, bool want_lvalue)
324 tree decl_type;
326 if (! base_decl_map)
327 return var_decl;
329 decl_type = TREE_TYPE (var_decl);
331 if (TREE_CODE (decl_type) == POINTER_TYPE)
333 if (DECL_LANG_SPECIFIC (var_decl)
334 && LOCAL_SLOT_P (var_decl))
336 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
337 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
339 gcc_assert (base_decl);
340 if (! want_lvalue)
341 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
343 return base_decl;
347 return var_decl;
350 /* Helper for java_genericize. */
352 tree
353 java_replace_references (tree *tp, int *walk_subtrees,
354 void *data ATTRIBUTE_UNUSED)
356 if (TREE_CODE (*tp) == MODIFY_EXPR)
358 source_location loc = EXPR_LOCATION (*tp);
359 tree lhs = TREE_OPERAND (*tp, 0);
360 /* This is specific to the bytecode compiler. If a variable has
361 LOCAL_SLOT_P set, replace an assignment to it with an assignment
362 to the corresponding variable that holds all its aliases. */
363 if (TREE_CODE (lhs) == VAR_DECL
364 && DECL_LANG_SPECIFIC (lhs)
365 && LOCAL_SLOT_P (lhs)
366 && TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE)
368 tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
369 tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs),
370 TREE_OPERAND (*tp, 1));
371 tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
372 new_lhs, new_rhs);
373 *tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem);
374 SET_EXPR_LOCATION (tem, loc);
375 SET_EXPR_LOCATION (new_rhs, loc);
376 SET_EXPR_LOCATION (*tp, loc);
379 if (TREE_CODE (*tp) == VAR_DECL)
381 *tp = java_replace_reference (*tp, /* want_lvalue */ false);
382 *walk_subtrees = 0;
385 return NULL_TREE;
388 /* Same as find_local_index, except that INDEX is a stack index. */
390 tree
391 find_stack_slot (int index, tree type)
393 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
394 type, -1);
397 struct GTY(())
398 binding_level {
399 /* A chain of _DECL nodes for all variables, constants, functions,
400 * and typedef types. These are in the reverse of the order supplied.
402 tree names;
404 /* For each level, a list of shadowed outer-level local definitions
405 to be restored when this level is popped.
406 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
407 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
408 tree shadowed;
410 /* For each level (except not the global one),
411 a chain of BLOCK nodes for all the levels
412 that were entered and exited one level down. */
413 tree blocks;
415 /* The binding level which this one is contained in (inherits from). */
416 struct binding_level *level_chain;
418 /* The bytecode PC that marks the end of this level. */
419 int end_pc;
420 /* The bytecode PC that marks the start of this level. */
421 int start_pc;
423 /* The statements in this binding level. */
424 tree stmts;
426 /* An exception range associated with this binding level. */
427 struct eh_range * GTY((skip (""))) exception_range;
429 /* Binding depth at which this level began. Used only for debugging. */
430 unsigned binding_depth;
432 /* The location at which this level began. */
433 source_location loc;
436 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
438 /* The binding level currently in effect. */
440 static GTY(()) struct binding_level *current_binding_level;
442 /* A chain of binding_level structures awaiting reuse. */
444 static GTY(()) struct binding_level *free_binding_level;
446 /* The outermost binding level, for names of file scope.
447 This is created when the compiler is started and exists
448 through the entire run. */
450 static GTY(()) struct binding_level *global_binding_level;
452 /* The binding level that holds variables declared at the outermost
453 level within a function body. */
455 static struct binding_level *function_binding_level;
457 /* A PC value bigger than any PC value we may ever may encounter. */
459 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
461 /* Binding level structures are initialized by copying this one. */
463 static const struct binding_level clear_binding_level
465 NULL_TREE, /* names */
466 NULL_TREE, /* shadowed */
467 NULL_TREE, /* blocks */
468 NULL_BINDING_LEVEL, /* level_chain */
469 LARGEST_PC, /* end_pc */
470 0, /* start_pc */
471 NULL, /* stmts */
472 NULL, /* exception_range */
473 0, /* binding_depth */
474 0, /* loc */
477 tree java_global_trees[JTI_MAX];
479 /* Build (and pushdecl) a "promoted type" for all standard
480 types shorter than int. */
482 static tree
483 push_promoted_type (const char *name, tree actual_type)
485 tree type = make_node (TREE_CODE (actual_type));
486 #if 1
487 tree in_min = TYPE_MIN_VALUE (int_type_node);
488 tree in_max = TYPE_MAX_VALUE (int_type_node);
489 #else
490 tree in_min = TYPE_MIN_VALUE (actual_type);
491 tree in_max = TYPE_MAX_VALUE (actual_type);
492 #endif
493 TYPE_MIN_VALUE (type) = copy_node (in_min);
494 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
495 TYPE_MAX_VALUE (type) = copy_node (in_max);
496 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
497 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
498 TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
499 layout_type (type);
500 pushdecl (build_decl (input_location,
501 TYPE_DECL, get_identifier (name), type));
502 return type;
505 /* Return tree that represents a vtable for a primitive array. */
506 static tree
507 create_primitive_vtable (const char *name)
509 tree r;
510 char buf[50];
512 sprintf (buf, "_Jv_%sVTable", name);
513 r = build_decl (input_location,
514 VAR_DECL, get_identifier (buf), ptr_type_node);
515 DECL_EXTERNAL (r) = 1;
516 return r;
519 /* Parse the version string and compute the ABI version number. */
520 static void
521 parse_version (void)
523 const char *p = version_string;
524 unsigned int major = 0, minor = 0;
525 unsigned int abi_version;
527 /* Skip leading junk. */
528 while (*p && !ISDIGIT (*p))
529 ++p;
530 gcc_assert (*p);
532 /* Extract major version. */
533 while (ISDIGIT (*p))
535 major = major * 10 + *p - '0';
536 ++p;
539 gcc_assert (*p == '.' && ISDIGIT (p[1]));
540 ++p;
542 /* Extract minor version. */
543 while (ISDIGIT (*p))
545 minor = minor * 10 + *p - '0';
546 ++p;
549 if (flag_indirect_dispatch)
551 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
552 abi_version |= FLAG_BINARYCOMPAT_ABI;
554 else /* C++ ABI */
556 /* Implicit in this computation is the idea that we won't break the
557 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
558 4.0.1). */
559 abi_version = 100000 * major + 1000 * minor;
561 if (flag_bootstrap_classes)
562 abi_version |= FLAG_BOOTSTRAP_LOADER;
564 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
567 void
568 java_init_decl_processing (void)
570 tree field = NULL_TREE;
571 tree t;
573 init_class_processing ();
575 current_function_decl = NULL;
576 current_binding_level = NULL_BINDING_LEVEL;
577 free_binding_level = NULL_BINDING_LEVEL;
578 pushlevel (0); /* make the binding_level structure for global names */
579 global_binding_level = current_binding_level;
581 /* Build common tree nodes, Java has an unsigned char. */
582 build_common_tree_nodes (false, false);
584 /* ??? Now we continue and override some of the built types again
585 with Java specific types. As the above generated types are
586 supposed to match the targets C ABI this isn't really the way
587 to go and any Java specifics should _not_ use those global types
588 if the Java ABI does not match the C one. */
590 byte_type_node = make_signed_type (8);
591 pushdecl (build_decl (BUILTINS_LOCATION,
592 TYPE_DECL, get_identifier ("byte"), byte_type_node));
593 short_type_node = make_signed_type (16);
594 pushdecl (build_decl (BUILTINS_LOCATION,
595 TYPE_DECL, get_identifier ("short"), short_type_node));
596 int_type_node = make_signed_type (32);
597 pushdecl (build_decl (BUILTINS_LOCATION,
598 TYPE_DECL, get_identifier ("int"), int_type_node));
599 long_type_node = make_signed_type (64);
600 pushdecl (build_decl (BUILTINS_LOCATION,
601 TYPE_DECL, get_identifier ("long"), long_type_node));
603 unsigned_byte_type_node = make_unsigned_type (8);
604 pushdecl (build_decl (BUILTINS_LOCATION,
605 TYPE_DECL, get_identifier ("unsigned byte"),
606 unsigned_byte_type_node));
607 unsigned_short_type_node = make_unsigned_type (16);
608 pushdecl (build_decl (BUILTINS_LOCATION,
609 TYPE_DECL, get_identifier ("unsigned short"),
610 unsigned_short_type_node));
611 unsigned_int_type_node = make_unsigned_type (32);
612 pushdecl (build_decl (BUILTINS_LOCATION,
613 TYPE_DECL, get_identifier ("unsigned int"),
614 unsigned_int_type_node));
615 unsigned_long_type_node = make_unsigned_type (64);
616 pushdecl (build_decl (BUILTINS_LOCATION,
617 TYPE_DECL, get_identifier ("unsigned long"),
618 unsigned_long_type_node));
620 /* Define these next since types below may used them. */
621 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
622 integer_zero_node = build_int_cst (NULL_TREE, 0);
623 integer_one_node = build_int_cst (NULL_TREE, 1);
624 integer_two_node = build_int_cst (NULL_TREE, 2);
625 integer_three_node = build_int_cst (NULL_TREE, 3);
626 integer_four_node = build_int_cst (NULL_TREE, 4);
627 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
629 /* A few values used for range checking in the lexer. */
630 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
631 decimal_long_max
632 = double_int_to_tree (unsigned_long_type_node,
633 double_int_zero.set_bit (64));
635 long_zero_node = build_int_cst (long_type_node, 0);
637 pushdecl (build_decl (BUILTINS_LOCATION,
638 TYPE_DECL, get_identifier ("void"), void_type_node));
640 t = make_node (VOID_TYPE);
641 layout_type (t); /* Uses size_zero_node */
642 return_address_type_node = build_pointer_type (t);
644 char_type_node = make_unsigned_type (16);
645 TYPE_STRING_FLAG (char_type_node) = 1;
646 pushdecl (build_decl (BUILTINS_LOCATION,
647 TYPE_DECL, get_identifier ("char"), char_type_node));
649 boolean_type_node = make_unsigned_type (1);
650 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
651 pushdecl (build_decl (BUILTINS_LOCATION,
652 TYPE_DECL, get_identifier ("boolean"),
653 boolean_type_node));
654 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
655 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
657 promoted_byte_type_node
658 = push_promoted_type ("promoted_byte", byte_type_node);
659 promoted_short_type_node
660 = push_promoted_type ("promoted_short", short_type_node);
661 promoted_char_type_node
662 = push_promoted_type ("promoted_char", char_type_node);
663 promoted_boolean_type_node
664 = push_promoted_type ("promoted_boolean", boolean_type_node);
666 float_type_node = make_node (REAL_TYPE);
667 TYPE_PRECISION (float_type_node) = 32;
668 pushdecl (build_decl (BUILTINS_LOCATION,
669 TYPE_DECL, get_identifier ("float"),
670 float_type_node));
671 layout_type (float_type_node);
673 double_type_node = make_node (REAL_TYPE);
674 TYPE_PRECISION (double_type_node) = 64;
675 pushdecl (build_decl (BUILTINS_LOCATION,
676 TYPE_DECL, get_identifier ("double"),
677 double_type_node));
678 layout_type (double_type_node);
680 float_zero_node = build_real (float_type_node, dconst0);
681 double_zero_node = build_real (double_type_node, dconst0);
683 /* These are the vtables for arrays of primitives. */
684 boolean_array_vtable = create_primitive_vtable ("boolean");
685 byte_array_vtable = create_primitive_vtable ("byte");
686 char_array_vtable = create_primitive_vtable ("char");
687 short_array_vtable = create_primitive_vtable ("short");
688 int_array_vtable = create_primitive_vtable ("int");
689 long_array_vtable = create_primitive_vtable ("long");
690 float_array_vtable = create_primitive_vtable ("float");
691 double_array_vtable = create_primitive_vtable ("double");
693 one_elt_array_domain_type = build_index_type (integer_one_node);
694 utf8const_type = make_node (RECORD_TYPE);
695 PUSH_FIELD (input_location,
696 utf8const_type, field, "hash", unsigned_short_type_node);
697 PUSH_FIELD (input_location,
698 utf8const_type, field, "length", unsigned_short_type_node);
699 FINISH_RECORD (utf8const_type);
700 utf8const_ptr_type = build_pointer_type (utf8const_type);
702 atable_type = build_array_type (ptr_type_node,
703 one_elt_array_domain_type);
704 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
705 atable_ptr_type = build_pointer_type (atable_type);
707 itable_type = build_array_type (ptr_type_node,
708 one_elt_array_domain_type);
709 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
710 itable_ptr_type = build_pointer_type (itable_type);
712 symbol_type = make_node (RECORD_TYPE);
713 PUSH_FIELD (input_location,
714 symbol_type, field, "clname", utf8const_ptr_type);
715 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
716 PUSH_FIELD (input_location,
717 symbol_type, field, "signature", utf8const_ptr_type);
718 FINISH_RECORD (symbol_type);
720 symbols_array_type = build_array_type (symbol_type,
721 one_elt_array_domain_type);
722 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
724 assertion_entry_type = make_node (RECORD_TYPE);
725 PUSH_FIELD (input_location,
726 assertion_entry_type, field, "assertion_code", integer_type_node);
727 PUSH_FIELD (input_location,
728 assertion_entry_type, field, "op1", utf8const_ptr_type);
729 PUSH_FIELD (input_location,
730 assertion_entry_type, field, "op2", utf8const_ptr_type);
731 FINISH_RECORD (assertion_entry_type);
733 assertion_table_type = build_array_type (assertion_entry_type,
734 one_elt_array_domain_type);
736 /* As you're adding items here, please update the code right after
737 this section, so that the filename containing the source code of
738 the pre-defined class gets registered correctly. */
739 unqualified_object_id_node = get_identifier ("Object");
740 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
741 object_ptr_type_node = promote_type (object_type_node);
742 string_type_node = lookup_class (get_identifier ("java.lang.String"));
743 string_ptr_type_node = promote_type (string_type_node);
744 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
745 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
746 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
747 runtime_exception_type_node =
748 lookup_class (get_identifier ("java.lang.RuntimeException"));
749 error_exception_type_node =
750 lookup_class (get_identifier ("java.lang.Error"));
752 rawdata_ptr_type_node
753 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
755 add_predefined_file (get_identifier ("java/lang/Class.java"));
756 add_predefined_file (get_identifier ("java/lang/Error.java"));
757 add_predefined_file (get_identifier ("java/lang/Object.java"));
758 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
759 add_predefined_file (get_identifier ("java/lang/String.java"));
760 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
761 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
762 add_predefined_file (get_identifier ("java/lang/Exception.java"));
763 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
764 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
766 methodtable_type = make_node (RECORD_TYPE);
767 layout_type (methodtable_type);
768 build_decl (BUILTINS_LOCATION,
769 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
770 methodtable_ptr_type = build_pointer_type (methodtable_type);
772 TYPE_identifier_node = get_identifier ("TYPE");
773 init_identifier_node = get_identifier ("<init>");
774 clinit_identifier_node = get_identifier ("<clinit>");
775 void_signature_node = get_identifier ("()V");
776 finalize_identifier_node = get_identifier ("finalize");
777 this_identifier_node = get_identifier ("this");
779 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
780 java_io_serializable_identifier_node =
781 get_identifier ("java.io.Serializable");
783 /* for lack of a better place to put this stub call */
784 init_expr_processing();
786 constants_type_node = make_node (RECORD_TYPE);
787 PUSH_FIELD (input_location,
788 constants_type_node, field, "size", unsigned_int_type_node);
789 PUSH_FIELD (input_location,
790 constants_type_node, field, "tags", ptr_type_node);
791 PUSH_FIELD (input_location,
792 constants_type_node, field, "data", ptr_type_node);
793 constants_data_field_decl_node = field;
794 FINISH_RECORD (constants_type_node);
795 build_decl (BUILTINS_LOCATION,
796 TYPE_DECL, get_identifier ("constants"), constants_type_node);
798 access_flags_type_node = unsigned_short_type_node;
800 dtable_type = make_node (RECORD_TYPE);
801 dtable_ptr_type = build_pointer_type (dtable_type);
803 otable_type = build_array_type (integer_type_node,
804 one_elt_array_domain_type);
805 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
806 otable_ptr_type = build_pointer_type (otable_type);
808 PUSH_FIELD (input_location,
809 object_type_node, field, "vtable", dtable_ptr_type);
810 DECL_FCONTEXT (field) = object_type_node;
811 TYPE_VFIELD (object_type_node) = field;
813 /* This isn't exactly true, but it is what we have in the source.
814 There is an unresolved issue here, which is whether the vtable
815 should be marked by the GC. */
816 if (! flag_hash_synchronization)
817 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
818 build_pointer_type (object_type_node));
819 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
820 FIELD_PRIVATE (t) = 1;
821 FINISH_RECORD (object_type_node);
823 field_type_node = make_node (RECORD_TYPE);
824 field_ptr_type_node = build_pointer_type (field_type_node);
825 method_type_node = make_node (RECORD_TYPE);
826 method_ptr_type_node = build_pointer_type (method_type_node);
828 set_super_info (0, class_type_node, object_type_node, 0);
829 set_super_info (0, string_type_node, object_type_node, 0);
830 class_ptr_type = build_pointer_type (class_type_node);
832 PUSH_FIELD (input_location,
833 class_type_node, field, "next_or_version", class_ptr_type);
834 PUSH_FIELD (input_location,
835 class_type_node, field, "name", utf8const_ptr_type);
836 PUSH_FIELD (input_location,
837 class_type_node, field, "accflags", access_flags_type_node);
838 PUSH_FIELD (input_location,
839 class_type_node, field, "superclass", class_ptr_type);
840 PUSH_FIELD (input_location,
841 class_type_node, field, "constants", constants_type_node);
842 constants_field_decl_node = field;
843 PUSH_FIELD (input_location,
844 class_type_node, field, "methods", method_ptr_type_node);
845 PUSH_FIELD (input_location,
846 class_type_node, field, "method_count", short_type_node);
847 PUSH_FIELD (input_location,
848 class_type_node, field, "vtable_method_count", short_type_node);
849 PUSH_FIELD (input_location,
850 class_type_node, field, "fields", field_ptr_type_node);
851 PUSH_FIELD (input_location,
852 class_type_node, field, "size_in_bytes", int_type_node);
853 PUSH_FIELD (input_location,
854 class_type_node, field, "field_count", short_type_node);
855 PUSH_FIELD (input_location,
856 class_type_node, field, "static_field_count", short_type_node);
857 PUSH_FIELD (input_location,
858 class_type_node, field, "vtable", dtable_ptr_type);
859 PUSH_FIELD (input_location,
860 class_type_node, field, "otable", otable_ptr_type);
861 PUSH_FIELD (input_location,
862 class_type_node, field, "otable_syms",
863 symbols_array_ptr_type);
864 PUSH_FIELD (input_location,
865 class_type_node, field, "atable", atable_ptr_type);
866 PUSH_FIELD (input_location,
867 class_type_node, field, "atable_syms",
868 symbols_array_ptr_type);
869 PUSH_FIELD (input_location,
870 class_type_node, field, "itable", itable_ptr_type);
871 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
872 symbols_array_ptr_type);
873 PUSH_FIELD (input_location,
874 class_type_node, field, "catch_classes", ptr_type_node);
875 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
876 build_pointer_type (class_ptr_type));
877 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
878 PUSH_FIELD (input_location,
879 class_type_node, field, "interface_count", short_type_node);
880 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
881 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
882 PUSH_FIELD (input_location,
883 class_type_node, field, "depth", short_type_node);
884 PUSH_FIELD (input_location,
885 class_type_node, field, "ancestors", ptr_type_node);
886 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
887 PUSH_FIELD (input_location,
888 class_type_node, field, "arrayclass", ptr_type_node);
889 PUSH_FIELD (input_location,
890 class_type_node, field, "protectionDomain", ptr_type_node);
891 PUSH_FIELD (input_location,
892 class_type_node, field, "assertion_table", ptr_type_node);
893 PUSH_FIELD (input_location,
894 class_type_node, field, "hack_signers", ptr_type_node);
895 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
896 PUSH_FIELD (input_location,
897 class_type_node, field, "aux_info", ptr_type_node);
898 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
899 PUSH_FIELD (input_location,
900 class_type_node, field, "reflection_data", ptr_type_node);
901 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
902 FIELD_PRIVATE (t) = 1;
903 push_super_field (class_type_node, object_type_node);
905 FINISH_RECORD (class_type_node);
906 build_decl (BUILTINS_LOCATION,
907 TYPE_DECL, get_identifier ("Class"), class_type_node);
909 field_info_union_node = make_node (UNION_TYPE);
910 PUSH_FIELD (input_location,
911 field_info_union_node, field, "boffset", int_type_node);
912 PUSH_FIELD (input_location,
913 field_info_union_node, field, "addr", ptr_type_node);
914 layout_type (field_info_union_node);
916 PUSH_FIELD (input_location,
917 field_type_node, field, "name", utf8const_ptr_type);
918 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
919 PUSH_FIELD (input_location,
920 field_type_node, field, "accflags", access_flags_type_node);
921 PUSH_FIELD (input_location,
922 field_type_node, field, "bsize", unsigned_short_type_node);
923 PUSH_FIELD (input_location,
924 field_type_node, field, "info", field_info_union_node);
925 FINISH_RECORD (field_type_node);
926 build_decl (BUILTINS_LOCATION,
927 TYPE_DECL, get_identifier ("Field"), field_type_node);
929 nativecode_ptr_array_type_node
930 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
932 PUSH_FIELD (input_location,
933 dtable_type, field, "class", class_ptr_type);
934 PUSH_FIELD (input_location,
935 dtable_type, field, "methods", nativecode_ptr_array_type_node);
936 FINISH_RECORD (dtable_type);
937 build_decl (BUILTINS_LOCATION,
938 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
940 jexception_type = make_node (RECORD_TYPE);
941 PUSH_FIELD (input_location,
942 jexception_type, field, "start_pc", ptr_type_node);
943 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
944 PUSH_FIELD (input_location,
945 jexception_type, field, "handler_pc", ptr_type_node);
946 PUSH_FIELD (input_location,
947 jexception_type, field, "catch_type", class_ptr_type);
948 FINISH_RECORD (jexception_type);
949 build_decl (BUILTINS_LOCATION,
950 TYPE_DECL, get_identifier ("jexception"), field_type_node);
951 jexception_ptr_type = build_pointer_type (jexception_type);
953 lineNumberEntry_type = make_node (RECORD_TYPE);
954 PUSH_FIELD (input_location,
955 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
956 PUSH_FIELD (input_location,
957 lineNumberEntry_type, field, "start_pc", ptr_type_node);
958 FINISH_RECORD (lineNumberEntry_type);
960 lineNumbers_type = make_node (RECORD_TYPE);
961 PUSH_FIELD (input_location,
962 lineNumbers_type, field, "length", unsigned_int_type_node);
963 FINISH_RECORD (lineNumbers_type);
965 PUSH_FIELD (input_location,
966 method_type_node, field, "name", utf8const_ptr_type);
967 PUSH_FIELD (input_location,
968 method_type_node, field, "signature", utf8const_ptr_type);
969 PUSH_FIELD (input_location,
970 method_type_node, field, "accflags", access_flags_type_node);
971 PUSH_FIELD (input_location,
972 method_type_node, field, "index", unsigned_short_type_node);
973 PUSH_FIELD (input_location,
974 method_type_node, field, "ncode", nativecode_ptr_type_node);
975 PUSH_FIELD (input_location,
976 method_type_node, field, "throws", ptr_type_node);
977 FINISH_RECORD (method_type_node);
978 build_decl (BUILTINS_LOCATION,
979 TYPE_DECL, get_identifier ("Method"), method_type_node);
981 end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
983 t = build_function_type_list (ptr_type_node, class_ptr_type, NULL_TREE);
984 alloc_object_node = add_builtin_function ("_Jv_AllocObject", t,
985 0, NOT_BUILT_IN, NULL, NULL_TREE);
986 DECL_IS_MALLOC (alloc_object_node) = 1;
987 alloc_no_finalizer_node =
988 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t,
989 0, NOT_BUILT_IN, NULL, NULL_TREE);
990 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
992 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
993 soft_initclass_node = add_builtin_function ("_Jv_InitClass", t,
994 0, NOT_BUILT_IN, NULL, NULL_TREE);
995 t = build_function_type_list (ptr_type_node,
996 class_ptr_type, int_type_node, NULL_TREE);
997 soft_resolvepoolentry_node
998 = add_builtin_function ("_Jv_ResolvePoolEntry", t,
999 0,NOT_BUILT_IN, NULL, NULL_TREE);
1000 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
1001 t = build_function_type_list (void_type_node,
1002 class_ptr_type, int_type_node, NULL_TREE);
1003 throw_node = add_builtin_function ("_Jv_Throw", t,
1004 0, NOT_BUILT_IN, NULL, NULL_TREE);
1005 /* Mark throw_nodes as `noreturn' functions with side effects. */
1006 TREE_THIS_VOLATILE (throw_node) = 1;
1007 TREE_SIDE_EFFECTS (throw_node) = 1;
1009 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1010 soft_monitorenter_node
1011 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1012 NULL, NULL_TREE);
1013 soft_monitorexit_node
1014 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1015 NULL, NULL_TREE);
1017 t = build_function_type_list (ptr_type_node,
1018 ptr_type_node, int_type_node, NULL_TREE);
1019 soft_newarray_node
1020 = add_builtin_function ("_Jv_NewPrimArray", t,
1021 0, NOT_BUILT_IN, NULL, NULL_TREE);
1022 DECL_IS_MALLOC (soft_newarray_node) = 1;
1024 t = build_function_type_list (ptr_type_node,
1025 int_type_node, class_ptr_type,
1026 object_ptr_type_node, NULL_TREE);
1027 soft_anewarray_node
1028 = add_builtin_function ("_Jv_NewObjectArray", t,
1029 0, NOT_BUILT_IN, NULL, NULL_TREE);
1030 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1032 t = build_varargs_function_type_list (ptr_type_node,
1033 ptr_type_node, int_type_node,
1034 NULL_TREE);
1035 soft_multianewarray_node
1036 = add_builtin_function ("_Jv_NewMultiArray", t,
1037 0, NOT_BUILT_IN, NULL, NULL_TREE);
1038 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1040 t = build_function_type_list (void_type_node, int_type_node, NULL_TREE);
1041 soft_badarrayindex_node
1042 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1043 0, NOT_BUILT_IN, NULL, NULL_TREE);
1044 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1045 effects. */
1046 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1047 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1049 t = build_function_type_list (void_type_node, NULL_TREE);
1050 soft_nullpointer_node
1051 = add_builtin_function ("_Jv_ThrowNullPointerException", t,
1052 0, NOT_BUILT_IN, NULL, NULL_TREE);
1053 /* Mark soft_nullpointer_node as a `noreturn' function with side
1054 effects. */
1055 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1056 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1058 soft_abstractmethod_node
1059 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t,
1060 0, NOT_BUILT_IN, NULL, NULL_TREE);
1061 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1062 effects. */
1063 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1064 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1066 soft_nosuchfield_node
1067 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t,
1068 0, NOT_BUILT_IN, NULL, NULL_TREE);
1069 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1070 effects. */
1071 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1072 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1074 t = build_function_type_list (ptr_type_node,
1075 class_ptr_type, object_ptr_type_node,
1076 NULL_TREE);
1077 soft_checkcast_node
1078 = add_builtin_function ("_Jv_CheckCast", t,
1079 0, NOT_BUILT_IN, NULL, NULL_TREE);
1080 t = build_function_type_list (boolean_type_node,
1081 object_ptr_type_node, class_ptr_type,
1082 NULL_TREE);
1083 soft_instanceof_node
1084 = add_builtin_function ("_Jv_IsInstanceOf", t,
1085 0, NOT_BUILT_IN, NULL, NULL_TREE);
1086 DECL_PURE_P (soft_instanceof_node) = 1;
1087 t = build_function_type_list (void_type_node,
1088 object_ptr_type_node, object_ptr_type_node,
1089 NULL_TREE);
1090 soft_checkarraystore_node
1091 = add_builtin_function ("_Jv_CheckArrayStore", t,
1092 0, NOT_BUILT_IN, NULL, NULL_TREE);
1093 t = build_function_type_list (ptr_type_node,
1094 ptr_type_node, ptr_type_node, int_type_node,
1095 NULL_TREE);
1096 soft_lookupinterfacemethod_node
1097 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t,
1098 0, NOT_BUILT_IN, NULL, NULL_TREE);
1099 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1101 t = build_function_type_list (ptr_type_node,
1102 ptr_type_node, ptr_type_node, ptr_type_node,
1103 NULL_TREE);
1104 soft_lookupinterfacemethodbyname_node
1105 = add_builtin_function ("_Jv_LookupInterfaceMethod", t,
1106 0, NOT_BUILT_IN, NULL, NULL_TREE);
1107 t = build_function_type_list (ptr_type_node,
1108 object_ptr_type_node, ptr_type_node,
1109 ptr_type_node, int_type_node, NULL_TREE);
1110 soft_lookupjnimethod_node
1111 = add_builtin_function ("_Jv_LookupJNIMethod", t,
1112 0, NOT_BUILT_IN, NULL, NULL_TREE);
1113 t = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
1114 soft_getjnienvnewframe_node
1115 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t,
1116 0, NOT_BUILT_IN, NULL, NULL_TREE);
1117 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1118 soft_jnipopsystemframe_node
1119 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t,
1120 0, NOT_BUILT_IN, NULL, NULL_TREE);
1122 t = build_function_type_list (object_ptr_type_node,
1123 object_ptr_type_node, NULL_TREE);
1124 soft_unwrapjni_node
1125 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t,
1126 0, NOT_BUILT_IN, NULL, NULL_TREE);
1128 t = build_function_type_list (int_type_node,
1129 int_type_node, int_type_node, NULL_TREE);
1130 soft_idiv_node
1131 = add_builtin_function ("_Jv_divI", t,
1132 0, NOT_BUILT_IN, NULL, NULL_TREE);
1134 soft_irem_node
1135 = add_builtin_function ("_Jv_remI", t,
1136 0, NOT_BUILT_IN, NULL, NULL_TREE);
1138 t = build_function_type_list (long_type_node,
1139 long_type_node, long_type_node, NULL_TREE);
1140 soft_ldiv_node
1141 = add_builtin_function ("_Jv_divJ", t,
1142 0, NOT_BUILT_IN, NULL, NULL_TREE);
1144 soft_lrem_node
1145 = add_builtin_function ("_Jv_remJ", t,
1146 0, NOT_BUILT_IN, NULL, NULL_TREE);
1148 initialize_builtins ();
1150 soft_fmod_node = builtin_decl_explicit (BUILT_IN_FMOD);
1152 parse_version ();
1156 /* Look up NAME in the current binding level and its superiors
1157 in the namespace of variables, functions and typedefs.
1158 Return a ..._DECL node of some kind representing its definition,
1159 or return 0 if it is undefined. */
1161 tree
1162 lookup_name (tree name)
1164 tree val;
1165 if (current_binding_level != global_binding_level
1166 && IDENTIFIER_LOCAL_VALUE (name))
1167 val = IDENTIFIER_LOCAL_VALUE (name);
1168 else
1169 val = IDENTIFIER_GLOBAL_VALUE (name);
1170 return val;
1173 /* Similar to `lookup_name' but look only at current binding level and
1174 the previous one if it's the parameter level. */
1176 static tree
1177 lookup_name_current_level (tree name)
1179 tree t;
1181 if (current_binding_level == global_binding_level)
1182 return IDENTIFIER_GLOBAL_VALUE (name);
1184 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1185 return 0;
1187 for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
1188 if (DECL_NAME (t) == name)
1189 break;
1191 return t;
1194 /* Record a decl-node X as belonging to the current lexical scope.
1195 Check for errors (such as an incompatible declaration for the same
1196 name already seen in the same scope).
1198 Returns either X or an old decl for the same name.
1199 If an old decl is returned, it may have been smashed
1200 to agree with what X says. */
1202 tree
1203 pushdecl (tree x)
1205 tree t;
1206 tree name = DECL_NAME (x);
1207 struct binding_level *b = current_binding_level;
1209 if (TREE_CODE (x) != TYPE_DECL)
1210 DECL_CONTEXT (x) = current_function_decl;
1211 if (name)
1213 t = lookup_name_current_level (name);
1214 if (t != 0 && t == error_mark_node)
1215 /* error_mark_node is 0 for a while during initialization! */
1217 t = 0;
1218 error ("%q+D used prior to declaration", x);
1221 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1222 to point to the TYPE_DECL.
1223 Since Java does not have typedefs, a type can only have
1224 one (true) name, given by a class, interface, or builtin. */
1225 if (TREE_CODE (x) == TYPE_DECL
1226 && TYPE_NAME (TREE_TYPE (x)) == 0
1227 && TREE_TYPE (x) != error_mark_node)
1229 TYPE_NAME (TREE_TYPE (x)) = x;
1230 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1233 /* This name is new in its binding level.
1234 Install the new declaration and return it. */
1235 if (b == global_binding_level)
1237 /* Install a global value. */
1239 IDENTIFIER_GLOBAL_VALUE (name) = x;
1241 else
1243 /* Here to install a non-global value. */
1244 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1245 IDENTIFIER_LOCAL_VALUE (name) = x;
1247 /* If storing a local value, there may already be one (inherited).
1248 If so, record it for restoration when this binding level ends. */
1249 if (oldlocal != 0)
1250 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1254 /* Put decls on list in reverse order.
1255 We will reverse them later if necessary. */
1256 DECL_CHAIN (x) = b->names;
1257 b->names = x;
1259 return x;
1262 void
1263 pushdecl_force_head (tree x)
1265 current_binding_level->names = x;
1268 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1270 tree
1271 pushdecl_top_level (tree x)
1273 tree t;
1274 struct binding_level *b = current_binding_level;
1276 current_binding_level = global_binding_level;
1277 t = pushdecl (x);
1278 current_binding_level = b;
1279 return t;
1282 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1284 tree
1285 pushdecl_function_level (tree x)
1287 tree t;
1288 struct binding_level *b = current_binding_level;
1290 current_binding_level = function_binding_level;
1291 t = pushdecl (x);
1292 current_binding_level = b;
1293 return t;
1296 /* Return true if we are in the global binding level. */
1298 bool
1299 global_bindings_p (void)
1301 return current_binding_level == global_binding_level;
1304 /* Return the list of declarations of the current level.
1305 Note that this list is in reverse order unless/until
1306 you nreverse it; and when you do nreverse it, you must
1307 store the result back using `storedecls' or you will lose. */
1309 tree
1310 getdecls (void)
1312 return current_binding_level->names;
1315 /* Create a new `struct binding_level'. */
1317 static struct binding_level *
1318 make_binding_level (void)
1320 /* NOSTRICT */
1321 return ggc_cleared_alloc<binding_level> ();
1324 void
1325 pushlevel (int unused ATTRIBUTE_UNUSED)
1327 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1329 /* Reuse or create a struct for this binding level. */
1331 if (free_binding_level)
1333 newlevel = free_binding_level;
1334 free_binding_level = free_binding_level->level_chain;
1336 else
1338 newlevel = make_binding_level ();
1341 /* Add this level to the front of the chain (stack) of levels that
1342 are active. */
1344 *newlevel = clear_binding_level;
1345 newlevel->level_chain = current_binding_level;
1346 newlevel->loc = input_location;
1347 current_binding_level = newlevel;
1348 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1349 newlevel->binding_depth = binding_depth;
1350 indent ();
1351 fprintf (stderr, "push %s level %p pc %d\n",
1352 (is_class_level) ? "class" : "block", newlevel, current_pc);
1353 is_class_level = 0;
1354 binding_depth++;
1355 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1358 /* Exit a binding level.
1359 Pop the level off, and restore the state of the identifier-decl mappings
1360 that were in effect when this level was entered.
1362 If KEEP is nonzero, this level had explicit declarations, so
1363 and create a "block" (a BLOCK node) for the level
1364 to record its declarations and subblocks for symbol table output.
1366 If FUNCTIONBODY is nonzero, this level is the body of a function,
1367 so create a block as if KEEP were set and also clear out all
1368 label names.
1370 If REVERSE is nonzero, reverse the order of decls before putting
1371 them into the BLOCK. */
1373 tree
1374 poplevel (int keep, int reverse, int functionbody)
1376 tree link;
1377 /* The chain of decls was accumulated in reverse order.
1378 Put it into forward order, just for cleanliness. */
1379 tree decls;
1380 tree subblocks = current_binding_level->blocks;
1381 tree block = 0;
1382 tree decl;
1383 tree bind = 0;
1385 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1386 binding_depth--;
1387 indent ();
1388 if (current_binding_level->end_pc != LARGEST_PC)
1389 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1390 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1391 current_binding_level->end_pc);
1392 else
1393 fprintf (stderr, "pop %s level %p pc %d\n",
1394 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1395 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1397 /* Get the decls in the order they were written.
1398 Usually current_binding_level->names is in reverse order.
1399 But parameter decls were previously put in forward order. */
1401 if (reverse)
1402 current_binding_level->names
1403 = decls = nreverse (current_binding_level->names);
1404 else
1405 decls = current_binding_level->names;
1407 for (decl = decls; decl; decl = DECL_CHAIN (decl))
1408 if (TREE_CODE (decl) == VAR_DECL
1409 && DECL_LANG_SPECIFIC (decl) != NULL
1410 && DECL_LOCAL_SLOT_NUMBER (decl))
1411 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1413 /* If there were any declarations in that level,
1414 or if this level is a function body,
1415 create a BLOCK to record them for the life of this function. */
1417 block = 0;
1418 if (keep || functionbody)
1419 block = make_node (BLOCK);
1421 if (current_binding_level->exception_range)
1422 expand_end_java_handler (current_binding_level->exception_range);
1424 if (block != 0)
1426 /* If any statements have been generated at this level, create a
1427 BIND_EXPR to hold them and copy the variables to it. This
1428 only applies to the bytecode compiler. */
1429 if (current_binding_level->stmts)
1431 tree decl = decls;
1432 tree *var = &BLOCK_VARS (block);
1434 /* Copy decls from names list, ignoring labels. */
1435 while (decl)
1437 tree next = DECL_CHAIN (decl);
1438 if (TREE_CODE (decl) != LABEL_DECL)
1440 *var = decl;
1441 var = &DECL_CHAIN (decl);
1443 decl = next;
1445 *var = NULL;
1447 bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block),
1448 BLOCK_EXPR_BODY (block), block);
1449 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1451 if (BIND_EXPR_BODY (bind)
1452 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1453 TREE_SIDE_EFFECTS (bind) = 1;
1455 /* FIXME: gimplifier brain damage. */
1456 if (BIND_EXPR_BODY (bind) == NULL)
1457 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1459 SET_EXPR_LOCATION (bind, current_binding_level->loc);
1461 current_binding_level->stmts = NULL;
1463 else
1465 BLOCK_VARS (block) = decls;
1467 BLOCK_SUBBLOCKS (block) = subblocks;
1470 /* In each subblock, record that this is its superior. */
1472 for (link = subblocks; link; link = BLOCK_CHAIN (link))
1473 BLOCK_SUPERCONTEXT (link) = block;
1475 /* Clear out the meanings of the local variables of this level. */
1477 for (link = decls; link; link = DECL_CHAIN (link))
1479 tree name = DECL_NAME (link);
1480 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1482 /* If the ident. was used or addressed via a local extern decl,
1483 don't forget that fact. */
1484 if (DECL_EXTERNAL (link))
1486 if (TREE_USED (link))
1487 TREE_USED (name) = 1;
1488 if (TREE_ADDRESSABLE (link))
1489 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1491 IDENTIFIER_LOCAL_VALUE (name) = 0;
1495 /* Restore all name-meanings of the outer levels
1496 that were shadowed by this level. */
1498 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1499 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1501 /* If the level being exited is the top level of a function,
1502 check over all the labels, and clear out the current
1503 (function local) meanings of their names. */
1505 if (functionbody)
1507 /* If this is the top level block of a function,
1508 the vars are the function's parameters.
1509 Don't leave them in the BLOCK because they are
1510 found in the FUNCTION_DECL instead. */
1512 BLOCK_VARS (block) = 0;
1515 /* Pop the current level, and free the structure for reuse. */
1518 struct binding_level *level = current_binding_level;
1519 current_binding_level = current_binding_level->level_chain;
1521 level->level_chain = free_binding_level;
1522 free_binding_level = level;
1525 /* Dispose of the block that we just made inside some higher level. */
1526 if (functionbody)
1528 DECL_INITIAL (current_function_decl) = block;
1529 DECL_SAVED_TREE (current_function_decl) = bind;
1531 else
1533 if (block)
1535 current_binding_level->blocks
1536 = block_chainon (current_binding_level->blocks, block);
1538 /* If we did not make a block for the level just exited,
1539 any blocks made for inner levels
1540 (since they cannot be recorded as subblocks in that level)
1541 must be carried forward so they will later become subblocks
1542 of something else. */
1543 else if (subblocks)
1544 current_binding_level->blocks
1545 = block_chainon (current_binding_level->blocks, subblocks);
1547 if (bind)
1548 java_add_stmt (bind);
1551 if (block)
1552 TREE_USED (block) = 1;
1553 return block;
1556 void
1557 maybe_pushlevels (int pc)
1559 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1560 current_pc = pc;
1561 #endif
1563 while (pending_local_decls != NULL_TREE &&
1564 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1566 tree *ptr = &pending_local_decls;
1567 tree decl = *ptr, next;
1568 int end_pc = DECL_LOCAL_END_PC (decl);
1570 while (*ptr != NULL_TREE
1571 && DECL_LOCAL_START_PC (*ptr) <= pc
1572 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1573 ptr = &DECL_CHAIN (*ptr);
1574 pending_local_decls = *ptr;
1575 *ptr = NULL_TREE;
1577 /* Force non-nested range to be nested in current range by
1578 truncating variable lifetimes. */
1579 if (end_pc > current_binding_level->end_pc)
1581 tree t;
1582 end_pc = current_binding_level->end_pc;
1583 for (t = decl; t != NULL_TREE; t = DECL_CHAIN (t))
1584 DECL_LOCAL_END_PC (t) = end_pc;
1587 maybe_start_try (pc, end_pc);
1589 pushlevel (1);
1591 current_binding_level->end_pc = end_pc;
1592 current_binding_level->start_pc = pc;
1593 current_binding_level->names = NULL;
1594 for ( ; decl != NULL_TREE; decl = next)
1596 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1597 tree base_decl;
1598 next = DECL_CHAIN (decl);
1599 push_jvm_slot (index, decl);
1600 pushdecl (decl);
1601 base_decl
1602 = find_local_variable (index, TREE_TYPE (decl), pc);
1603 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1604 base_decl = TREE_VEC_ELT (base_decl_map, index);
1605 SET_DECL_VALUE_EXPR (decl, base_decl);
1606 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1610 maybe_start_try (pc, 0);
1613 void
1614 maybe_poplevels (int pc)
1616 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1617 current_pc = pc;
1618 #endif
1620 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1621 inclusive, so a variable is live if pc == end_pc. Here, we
1622 terminate a range if the current pc is equal to the end of the
1623 range, and this is *before* we have generated code for the
1624 instruction at end_pc. We're closing a binding level one
1625 instruction too early.*/
1626 while (current_binding_level->end_pc <= pc)
1627 poplevel (1, 0, 0);
1630 /* Terminate any binding which began during the range beginning at
1631 start_pc. This tidies up improperly nested local variable ranges
1632 and exception handlers; a variable declared within an exception
1633 range is forcibly terminated when that exception ends. */
1635 void
1636 force_poplevels (int start_pc)
1638 while (current_binding_level->start_pc > start_pc)
1640 if (pedantic && current_binding_level->start_pc > start_pc)
1641 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1642 current_function_decl,
1643 current_binding_level->start_pc);
1644 poplevel (1, 0, 0);
1648 /* integrate_decl_tree calls this function. */
1650 void
1651 java_dup_lang_specific_decl (tree node)
1653 int lang_decl_size;
1654 struct lang_decl *x;
1656 if (!DECL_LANG_SPECIFIC (node))
1657 return;
1659 lang_decl_size = sizeof (struct lang_decl);
1660 x = ggc_alloc<struct lang_decl> ();
1661 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1662 DECL_LANG_SPECIFIC (node) = x;
1665 void
1666 give_name_to_locals (JCF *jcf)
1668 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1669 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1670 tree parm;
1671 pending_local_decls = NULL_TREE;
1672 if (n == 0)
1673 return;
1674 JCF_SEEK (jcf, n);
1675 n = JCF_readu2 (jcf);
1676 for (i = 0; i < n; i++)
1678 int start_pc = JCF_readu2 (jcf);
1679 int length = JCF_readu2 (jcf);
1680 int name_index = JCF_readu2 (jcf);
1681 int signature_index = JCF_readu2 (jcf);
1682 int slot = JCF_readu2 (jcf);
1683 tree name = get_name_constant (jcf, name_index);
1684 tree type = parse_signature (jcf, signature_index);
1685 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1686 && start_pc == 0
1687 && length == DECL_CODE_LENGTH (current_function_decl))
1689 tree decl = TREE_VEC_ELT (decl_map, slot);
1690 DECL_NAME (decl) = name;
1691 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1692 warning (0, "bad type in parameter debug info");
1694 else
1696 tree *ptr;
1697 int end_pc = start_pc + length;
1698 tree decl = build_decl (input_location, VAR_DECL, name, type);
1699 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1701 warning (0, "bad PC range for debug info for local %q+D",
1702 decl);
1703 end_pc = DECL_CODE_LENGTH (current_function_decl);
1706 /* Adjust start_pc if necessary so that the local's first
1707 store operation will use the relevant DECL as a
1708 destination. Fore more information, read the leading
1709 comments for expr.c:maybe_adjust_start_pc. */
1710 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1712 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1713 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1714 DECL_LOCAL_START_PC (decl) = start_pc;
1715 DECL_LOCAL_END_PC (decl) = end_pc;
1717 /* Now insert the new decl in the proper place in
1718 pending_local_decls. We are essentially doing an insertion sort,
1719 which works fine, since the list input will normally already
1720 be sorted. */
1721 ptr = &pending_local_decls;
1722 while (*ptr != NULL_TREE
1723 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1724 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1725 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1726 ptr = &DECL_CHAIN (*ptr);
1727 DECL_CHAIN (decl) = *ptr;
1728 *ptr = decl;
1732 pending_local_decls = nreverse (pending_local_decls);
1734 /* Fill in default names for the parameters. */
1735 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1736 parm != NULL_TREE; parm = DECL_CHAIN (parm), i++)
1738 if (DECL_NAME (parm) == NULL_TREE)
1740 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1741 if (arg_i == 0)
1742 DECL_NAME (parm) = get_identifier ("this");
1743 else
1745 char buffer[12];
1746 sprintf (buffer, "ARG_%d", arg_i);
1747 DECL_NAME (parm) = get_identifier (buffer);
1753 tree
1754 build_result_decl (tree fndecl)
1756 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1757 tree result = DECL_RESULT (fndecl);
1758 if (! result)
1760 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1761 RESULT_DECL, NULL_TREE, restype);
1762 DECL_ARTIFICIAL (result) = 1;
1763 DECL_IGNORED_P (result) = 1;
1764 DECL_CONTEXT (result) = fndecl;
1765 DECL_RESULT (fndecl) = result;
1767 return result;
1770 void
1771 start_java_method (tree fndecl)
1773 tree tem, *ptr;
1774 int i;
1776 uniq = 0;
1778 current_function_decl = fndecl;
1779 announce_function (fndecl);
1781 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1782 decl_map = make_tree_vec (i);
1783 base_decl_map = make_tree_vec (i);
1784 type_map = XRESIZEVEC (tree, type_map, i);
1786 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1787 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1788 current_pc = 0;
1789 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1790 pushlevel (1); /* Push parameters. */
1792 ptr = &DECL_ARGUMENTS (fndecl);
1793 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1794 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1796 tree parm_name = NULL_TREE, parm_decl;
1797 tree parm_type = TREE_VALUE (tem);
1798 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1800 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1801 DECL_CONTEXT (parm_decl) = fndecl;
1802 if (targetm.calls.promote_prototypes (parm_type)
1803 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1804 && INTEGRAL_TYPE_P (parm_type))
1805 parm_type = integer_type_node;
1806 DECL_ARG_TYPE (parm_decl) = parm_type;
1808 *ptr = parm_decl;
1809 ptr = &DECL_CHAIN (parm_decl);
1811 /* Add parm_decl to the decl_map. */
1812 push_jvm_slot (i, parm_decl);
1814 /* The this parameter of methods is artificial. */
1815 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE && i == 0)
1816 DECL_ARTIFICIAL (parm_decl) = 1;
1818 type_map[i] = TREE_TYPE (parm_decl);
1819 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1821 i++;
1822 type_map[i] = void_type_node;
1825 *ptr = NULL_TREE;
1826 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1828 while (i < DECL_MAX_LOCALS(fndecl))
1829 type_map[i++] = NULL_TREE;
1831 build_result_decl (fndecl);
1832 DECL_SOURCE_LOCATION (fndecl) = input_location;
1834 /* Push local variables. */
1835 pushlevel (2);
1837 function_binding_level = current_binding_level;
1840 void
1841 end_java_method (void)
1843 tree fndecl = current_function_decl;
1845 /* pop out of function */
1846 poplevel (1, 1, 0);
1848 /* pop out of its parameters */
1849 poplevel (1, 0, 1);
1851 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1853 if (DECL_SAVED_TREE (fndecl))
1855 tree fbody, block_body;
1856 /* Before we check initialization, attached all class initialization
1857 variable to the block_body */
1858 fbody = DECL_SAVED_TREE (fndecl);
1859 block_body = BIND_EXPR_BODY (fbody);
1860 hash_table<treetreehasher> *ht = DECL_FUNCTION_INIT_TEST_TABLE (fndecl);
1861 ht->traverse<tree, attach_init_test_initialization_flags> (block_body);
1864 finish_method (fndecl);
1866 current_function_decl = NULL_TREE;
1867 base_decl_map = NULL_TREE;
1870 /* Prepare a method for expansion. */
1872 void
1873 finish_method (tree fndecl)
1875 tree *tp = &DECL_SAVED_TREE (fndecl);
1877 /* Wrap body of synchronized methods in a monitorenter,
1878 plus monitorexit cleanup. */
1879 if (METHOD_SYNCHRONIZED (fndecl))
1881 tree enter, exit, lock;
1882 if (METHOD_STATIC (fndecl))
1883 lock = build_class_ref (DECL_CONTEXT (fndecl));
1884 else
1885 lock = DECL_ARGUMENTS (fndecl);
1886 BUILD_MONITOR_ENTER (enter, lock);
1887 BUILD_MONITOR_EXIT (exit, lock);
1888 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1889 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1892 /* Convert function tree to GENERIC prior to inlining. */
1893 java_genericize (fndecl);
1895 /* Store the end of the function, so that we get good line number
1896 info for the epilogue. */
1897 if (DECL_STRUCT_FUNCTION (fndecl))
1898 set_cfun (DECL_STRUCT_FUNCTION (fndecl));
1899 else
1900 allocate_struct_function (fndecl, false);
1901 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1903 /* Defer inlining and expansion to the cgraph optimizers. */
1904 cgraph_node::finalize_function (fndecl, false);
1907 /* We pessimistically marked all methods and fields external until we
1908 knew what set of classes we were planning to compile. Now mark those
1909 associated with CLASS to be generated locally as not external. */
1911 static void
1912 java_mark_decl_local (tree decl)
1914 DECL_EXTERNAL (decl) = 0;
1916 #ifdef ENABLE_CHECKING
1917 /* Double check that we didn't pass the function to the callgraph early. */
1918 if (TREE_CODE (decl) == FUNCTION_DECL)
1920 struct cgraph_node *node = cgraph_node::get (decl);
1921 gcc_assert (!node || !node->definition);
1923 #endif
1924 gcc_assert (!DECL_RTL_SET_P (decl));
1927 /* Given appropriate target support, G++ will emit hidden aliases for native
1928 methods. Using this hidden name is required for proper operation of
1929 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1930 proper target support, then mark the method for aliasing. */
1932 static void
1933 java_mark_cni_decl_local (tree decl)
1935 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1936 return;
1937 #endif
1939 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1940 DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1942 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1943 mangler. We might have already referenced this native method and
1944 therefore created its name, but even if we have it won't hurt.
1945 We'll just go via its externally visible name, rather than its
1946 hidden alias. However, we must force things so that the correct
1947 mangling is done. */
1949 if (DECL_ASSEMBLER_NAME_SET_P (decl))
1950 java_mangle_decl (decl);
1951 if (DECL_RTL_SET_P (decl))
1953 SET_DECL_RTL (decl, 0);
1954 make_decl_rtl (decl);
1958 /* Use the preceding two functions and mark all members of the class. */
1960 void
1961 java_mark_class_local (tree klass)
1963 tree t;
1965 for (t = TYPE_FIELDS (klass); t ; t = DECL_CHAIN (t))
1966 if (FIELD_STATIC (t))
1968 if (DECL_EXTERNAL (t))
1969 vec_safe_push (pending_static_fields, t);
1970 java_mark_decl_local (t);
1973 for (t = TYPE_METHODS (klass); t ; t = DECL_CHAIN (t))
1974 if (!METHOD_ABSTRACT (t))
1976 if (METHOD_NATIVE (t) && !flag_jni)
1977 java_mark_cni_decl_local (t);
1978 else
1979 java_mark_decl_local (t);
1983 /* Add a statement to a compound_expr. */
1985 tree
1986 add_stmt_to_compound (tree existing, tree type, tree stmt)
1988 if (!stmt)
1989 return existing;
1990 else if (existing)
1992 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
1993 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
1994 | TREE_SIDE_EFFECTS (stmt);
1995 return expr;
1997 else
1998 return stmt;
2001 /* If this node is an expr, mark its input location. Called from
2002 walk_tree(). */
2004 static tree
2005 set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
2006 void *data ATTRIBUTE_UNUSED)
2008 tree t = *tp;
2010 if (CAN_HAVE_LOCATION_P (t))
2012 if (EXPR_HAS_LOCATION(t))
2013 return t; /* Don't walk any further into this expr. */
2014 else
2015 SET_EXPR_LOCATION (t, input_location);
2018 return NULL_TREE; /* Continue walking this expr. */
2021 /* Add a statement to the statement_list currently being constructed.
2022 If the statement_list is null, we don't create a singleton list.
2023 This is necessary because poplevel() assumes that adding a
2024 statement to a null statement_list returns the statement. */
2026 tree
2027 java_add_stmt (tree new_stmt)
2029 tree stmts = current_binding_level->stmts;
2030 tree_stmt_iterator i;
2032 if (LOCATION_FILE (input_location))
2033 walk_tree (&new_stmt, set_input_location, NULL, NULL);
2035 if (stmts == NULL)
2036 return current_binding_level->stmts = new_stmt;
2038 /* Force STMTS to be a statement_list. */
2039 if (TREE_CODE (stmts) != STATEMENT_LIST)
2041 tree t = make_node (STATEMENT_LIST);
2042 i = tsi_last (t);
2043 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2044 stmts = t;
2047 i = tsi_last (stmts);
2048 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2049 TREE_TYPE (stmts) = void_type_node;
2051 return current_binding_level->stmts = stmts;
2054 /* Add a variable to the current scope. */
2056 tree
2057 java_add_local_var (tree decl)
2059 tree *vars = &current_binding_level->names;
2060 tree next = *vars;
2061 DECL_CHAIN (decl) = next;
2062 *vars = decl;
2063 DECL_CONTEXT (decl) = current_function_decl;
2064 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2065 return decl;
2068 /* Return a pointer to the compound_expr currently being
2069 constructed. */
2071 tree *
2072 get_stmts (void)
2074 return &current_binding_level->stmts;
2077 /* Register an exception range as belonging to the current binding
2078 level. There may only be one: if there are more, we'll create more
2079 binding levels. However, each range can have multiple handlers,
2080 and these are expanded when we call expand_end_java_handler(). */
2082 void
2083 register_exception_range (struct eh_range *range, int pc, int end_pc)
2085 gcc_assert (! current_binding_level->exception_range);
2086 current_binding_level->exception_range = range;
2087 current_binding_level->end_pc = end_pc;
2088 current_binding_level->start_pc = pc;
2091 #include "gt-java-decl.h"