Fix type in the changelog entry,
[official-gcc.git] / gcc / java / decl.c
blobc035fe058964f568e416242de4b0563fcd9089d7
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 "tree.h"
32 #include "options.h"
33 #include "stor-layout.h"
34 #include "stringpool.h"
35 #include "varasm.h"
36 #include "diagnostic-core.h"
37 #include "toplev.h"
38 #include "flags.h"
39 #include "java-tree.h"
40 #include "jcf.h"
41 #include "java-except.h"
42 #include "tm.h"
43 #include "hard-reg-set.h"
44 #include "function.h"
45 #include "cgraph.h"
46 #include "tree-inline.h"
47 #include "target.h"
48 #include "version.h"
49 #include "tree-iterator.h"
50 #include "langhooks.h"
52 #if defined (DEBUG_JAVA_BINDING_LEVELS)
53 extern void indent (void);
54 #endif
56 static tree push_jvm_slot (int, tree);
57 static tree lookup_name_current_level (tree);
58 static tree push_promoted_type (const char *, tree);
59 static struct binding_level *make_binding_level (void);
60 static tree create_primitive_vtable (const char *);
61 static tree check_local_unnamed_variable (tree, tree, tree);
62 static void parse_version (void);
65 /* The following ABI flags are used in the high-order bits of the version
66 ID field. The version ID number itself should never be larger than
67 0xfffff, so it should be safe to use top 12 bits for these flags. */
69 #define FLAG_BINARYCOMPAT_ABI (1<<31) /* Class is built with the BC-ABI. */
71 #define FLAG_BOOTSTRAP_LOADER (1<<30) /* Used when defining a class that
72 should be loaded by the bootstrap
73 loader. */
75 /* If an ABI change is made within a GCC release series, rendering current
76 binaries incompatible with the old runtimes, this number must be set to
77 enforce the compatibility rules. */
78 #define MINOR_BINARYCOMPAT_ABI_VERSION 1
80 /* The runtime may recognize a variety of BC ABIs (objects generated by
81 different version of gcj), but will probably always require strict
82 matching for the ordinary (C++) ABI. */
84 /* The version ID of the BC ABI that we generate. This must be kept in
85 sync with parse_version(), libgcj, and reality (if the BC format changes,
86 this must change). */
87 #define GCJ_CURRENT_BC_ABI_VERSION \
88 (4 * 100000 + 0 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
90 /* The ABI version number. */
91 tree gcj_abi_version;
93 /* Name of the Cloneable class. */
94 tree java_lang_cloneable_identifier_node;
96 /* Name of the Serializable class. */
97 tree java_io_serializable_identifier_node;
99 /* The DECL_MAP is a mapping from (index, type) to a decl node.
100 If index < max_locals, it is the index of a local variable.
101 if index >= max_locals, then index-max_locals is a stack slot.
102 The DECL_MAP mapping is represented as a TREE_VEC whose elements
103 are a list of decls (VAR_DECL or PARM_DECL) chained by
104 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
105 we search the chain for a decl with a matching TREE_TYPE. */
107 static GTY(()) tree decl_map;
109 /* The base_decl_map is contains one variable of ptr_type: this is
110 used to contain every variable of reference type that is ever
111 stored in a local variable slot. */
113 static GTY(()) tree base_decl_map;
115 /* An index used to make temporary identifiers unique. */
116 static int uniq;
118 /* A list of local variables VAR_DECLs for this method that we have seen
119 debug information, but we have not reached their starting (byte) PC yet. */
121 static GTY(()) tree pending_local_decls;
123 /* The decl for "_Jv_ResolvePoolEntry". */
124 tree soft_resolvepoolentry_node;
126 /* The decl for the .constants field of an instance of Class. */
127 tree constants_field_decl_node;
129 /* The decl for the .data field of an instance of Class. */
130 tree constants_data_field_decl_node;
132 #if defined(DEBUG_JAVA_BINDING_LEVELS)
133 int binding_depth = 0;
134 int is_class_level = 0;
135 int current_pc;
137 void
138 indent (void)
140 int i;
142 for (i = 0; i < binding_depth*2; i++)
143 putc (' ', stderr);
145 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
147 /* True if decl is a named local variable, i.e. if it is an alias
148 that's used only for debugging purposes. */
150 static bool
151 debug_variable_p (tree decl)
153 if (TREE_CODE (decl) == PARM_DECL)
154 return false;
156 if (LOCAL_SLOT_P (decl))
157 return false;
159 return true;
162 static tree
163 push_jvm_slot (int index, tree decl)
165 DECL_CONTEXT (decl) = current_function_decl;
166 layout_decl (decl, 0);
168 /* Now link the decl into the decl_map. */
169 if (DECL_LANG_SPECIFIC (decl) == NULL)
171 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
172 DECL_LOCAL_START_PC (decl) = 0;
173 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
174 DECL_LOCAL_SLOT_NUMBER (decl) = index;
176 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
177 TREE_VEC_ELT (decl_map, index) = decl;
179 return decl;
182 /* Find the best declaration based upon type. If 'decl' fits 'type' better
183 than 'best', return 'decl'. Otherwise return 'best'. */
185 static tree
186 check_local_unnamed_variable (tree best, tree decl, tree type)
188 tree decl_type = TREE_TYPE (decl);
190 gcc_assert (! LOCAL_VAR_OUT_OF_SCOPE_P (decl));
192 /* Use the same decl for all integer types <= 32 bits. This is
193 necessary because sometimes a value is stored as (for example)
194 boolean but loaded as int. */
195 if (decl_type == type
196 || (INTEGRAL_TYPE_P (decl_type)
197 && INTEGRAL_TYPE_P (type)
198 && TYPE_PRECISION (decl_type) <= 32
199 && TYPE_PRECISION (type) <= 32
200 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
201 /* ptr_type_node is used for null pointers, which are
202 assignment compatible with everything. */
203 || (TREE_CODE (decl_type) == POINTER_TYPE
204 && type == ptr_type_node)
205 /* Whenever anyone wants to use a slot that is initially
206 occupied by a PARM_DECL of pointer type they must get that
207 decl, even if they asked for a pointer to a different type.
208 However, if someone wants a scalar variable in a slot that
209 initially held a pointer arg -- or vice versa -- we create a
210 new VAR_DECL.
212 ???: As long as verification is correct, this will be a
213 compatible type. But maybe we should create a dummy variable
214 and replace all references to it with the DECL and a
215 NOP_EXPR.
217 || (TREE_CODE (decl_type) == POINTER_TYPE
218 && TREE_CODE (decl) == PARM_DECL
219 && TREE_CODE (type) == POINTER_TYPE))
221 if (best == NULL_TREE
222 || (decl_type == type && TREE_TYPE (best) != type))
223 return decl;
226 return best;
230 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
231 that is valid at PC (or -1 if any pc).
232 If there is no existing matching decl, allocate one. */
234 tree
235 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
237 tree tmp = TREE_VEC_ELT (decl_map, index);
238 tree decl = NULL_TREE;
240 /* Scan through every declaration that has been created in this
241 slot. We're only looking for variables that correspond to local
242 index declarations and PARM_DECLs, not named variables: such
243 local variables are used only for debugging information. */
244 while (tmp != NULL_TREE)
246 if (! debug_variable_p (tmp))
247 decl = check_local_unnamed_variable (decl, tmp, type);
248 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
251 /* gcj has a function called promote_type(), which is used by both
252 the bytecode compiler and the source compiler. Unfortunately,
253 the type systems for the Java VM and the Java language are not
254 the same: a boolean in the VM promotes to an int, not to a wide
255 boolean. If our caller wants something to hold a boolean, that
256 had better be an int, because that slot might be re-used
257 later in integer context. */
258 if (TREE_CODE (type) == BOOLEAN_TYPE)
259 type = integer_type_node;
261 /* If we don't find a match, create one with the type passed in.
262 The name of the variable is #n#m, which n is the variable index
263 in the local variable area and m is a dummy identifier for
264 uniqueness -- multiple variables may share the same local
265 variable index. We don't call pushdecl() to push pointer types
266 into a binding expr because they'll all be replaced by a single
267 variable that is used for every reference in that local variable
268 slot. */
269 if (! decl)
271 char buf[64];
272 tree name;
273 sprintf (buf, "#slot#%d#%d", index, uniq++);
274 name = get_identifier (buf);
275 decl = build_decl (input_location, VAR_DECL, name, type);
276 DECL_IGNORED_P (decl) = 1;
277 DECL_ARTIFICIAL (decl) = 1;
278 decl = push_jvm_slot (index, decl);
279 LOCAL_SLOT_P (decl) = 1;
281 if (TREE_CODE (type) != POINTER_TYPE)
282 pushdecl_function_level (decl);
285 /* As well as creating a local variable that matches the type, we
286 also create a base variable (of ptr_type) that will hold all its
287 aliases. */
288 if (TREE_CODE (type) == POINTER_TYPE
289 && ! TREE_VEC_ELT (base_decl_map, index))
291 char buf[64];
292 tree name;
293 tree base_decl;
294 sprintf (buf, "#ref#%d#%d", index, uniq++);
295 name = get_identifier (buf);
296 base_decl
297 = TREE_VEC_ELT (base_decl_map, index)
298 = build_decl (input_location, VAR_DECL, name, ptr_type_node);
299 pushdecl_function_level (base_decl);
300 DECL_IGNORED_P (base_decl) = 1;
301 DECL_ARTIFICIAL (base_decl) = 1;
304 return decl;
307 /* Called during genericization for every variable. If the variable
308 is a temporary of pointer type, replace it with a common variable
309 thath is used to hold all pointer types that are ever stored in
310 that slot. Set WANT_LVALUE if you want a variable that is to be
311 written to. */
313 static tree
314 java_replace_reference (tree var_decl, bool want_lvalue)
316 tree decl_type;
318 if (! base_decl_map)
319 return var_decl;
321 decl_type = TREE_TYPE (var_decl);
323 if (TREE_CODE (decl_type) == POINTER_TYPE)
325 if (DECL_LANG_SPECIFIC (var_decl)
326 && LOCAL_SLOT_P (var_decl))
328 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
329 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
331 gcc_assert (base_decl);
332 if (! want_lvalue)
333 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
335 return base_decl;
339 return var_decl;
342 /* Helper for java_genericize. */
344 tree
345 java_replace_references (tree *tp, int *walk_subtrees,
346 void *data ATTRIBUTE_UNUSED)
348 if (TREE_CODE (*tp) == MODIFY_EXPR)
350 source_location loc = EXPR_LOCATION (*tp);
351 tree lhs = TREE_OPERAND (*tp, 0);
352 /* This is specific to the bytecode compiler. If a variable has
353 LOCAL_SLOT_P set, replace an assignment to it with an assignment
354 to the corresponding variable that holds all its aliases. */
355 if (TREE_CODE (lhs) == VAR_DECL
356 && DECL_LANG_SPECIFIC (lhs)
357 && LOCAL_SLOT_P (lhs)
358 && TREE_CODE (TREE_TYPE (lhs)) == POINTER_TYPE)
360 tree new_lhs = java_replace_reference (lhs, /* want_lvalue */ true);
361 tree new_rhs = build1 (NOP_EXPR, TREE_TYPE (new_lhs),
362 TREE_OPERAND (*tp, 1));
363 tree tem = build2 (MODIFY_EXPR, TREE_TYPE (new_lhs),
364 new_lhs, new_rhs);
365 *tp = build1 (NOP_EXPR, TREE_TYPE (lhs), tem);
366 SET_EXPR_LOCATION (tem, loc);
367 SET_EXPR_LOCATION (new_rhs, loc);
368 SET_EXPR_LOCATION (*tp, loc);
371 if (TREE_CODE (*tp) == VAR_DECL)
373 *tp = java_replace_reference (*tp, /* want_lvalue */ false);
374 *walk_subtrees = 0;
377 return NULL_TREE;
380 /* Same as find_local_index, except that INDEX is a stack index. */
382 tree
383 find_stack_slot (int index, tree type)
385 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
386 type, -1);
389 struct GTY(())
390 binding_level {
391 /* A chain of _DECL nodes for all variables, constants, functions,
392 * and typedef types. These are in the reverse of the order supplied.
394 tree names;
396 /* For each level, a list of shadowed outer-level local definitions
397 to be restored when this level is popped.
398 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
399 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
400 tree shadowed;
402 /* For each level (except not the global one),
403 a chain of BLOCK nodes for all the levels
404 that were entered and exited one level down. */
405 tree blocks;
407 /* The binding level which this one is contained in (inherits from). */
408 struct binding_level *level_chain;
410 /* The bytecode PC that marks the end of this level. */
411 int end_pc;
412 /* The bytecode PC that marks the start of this level. */
413 int start_pc;
415 /* The statements in this binding level. */
416 tree stmts;
418 /* An exception range associated with this binding level. */
419 struct eh_range * GTY((skip (""))) exception_range;
421 /* Binding depth at which this level began. Used only for debugging. */
422 unsigned binding_depth;
424 /* The location at which this level began. */
425 source_location loc;
428 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
430 /* The binding level currently in effect. */
432 static GTY(()) struct binding_level *current_binding_level;
434 /* A chain of binding_level structures awaiting reuse. */
436 static GTY(()) struct binding_level *free_binding_level;
438 /* The outermost binding level, for names of file scope.
439 This is created when the compiler is started and exists
440 through the entire run. */
442 static GTY(()) struct binding_level *global_binding_level;
444 /* The binding level that holds variables declared at the outermost
445 level within a function body. */
447 static struct binding_level *function_binding_level;
449 /* A PC value bigger than any PC value we may ever may encounter. */
451 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
453 /* Binding level structures are initialized by copying this one. */
455 static const struct binding_level clear_binding_level
457 NULL_TREE, /* names */
458 NULL_TREE, /* shadowed */
459 NULL_TREE, /* blocks */
460 NULL_BINDING_LEVEL, /* level_chain */
461 LARGEST_PC, /* end_pc */
462 0, /* start_pc */
463 NULL, /* stmts */
464 NULL, /* exception_range */
465 0, /* binding_depth */
466 0, /* loc */
469 tree java_global_trees[JTI_MAX];
471 /* Build (and pushdecl) a "promoted type" for all standard
472 types shorter than int. */
474 static tree
475 push_promoted_type (const char *name, tree actual_type)
477 tree type = make_node (TREE_CODE (actual_type));
478 #if 1
479 tree in_min = TYPE_MIN_VALUE (int_type_node);
480 tree in_max = TYPE_MAX_VALUE (int_type_node);
481 #else
482 tree in_min = TYPE_MIN_VALUE (actual_type);
483 tree in_max = TYPE_MAX_VALUE (actual_type);
484 #endif
485 TYPE_MIN_VALUE (type) = copy_node (in_min);
486 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
487 TYPE_MAX_VALUE (type) = copy_node (in_max);
488 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
489 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
490 TYPE_STRING_FLAG (type) = TYPE_STRING_FLAG (actual_type);
491 layout_type (type);
492 pushdecl (build_decl (input_location,
493 TYPE_DECL, get_identifier (name), type));
494 return type;
497 /* Return tree that represents a vtable for a primitive array. */
498 static tree
499 create_primitive_vtable (const char *name)
501 tree r;
502 char buf[50];
504 sprintf (buf, "_Jv_%sVTable", name);
505 r = build_decl (input_location,
506 VAR_DECL, get_identifier (buf), ptr_type_node);
507 DECL_EXTERNAL (r) = 1;
508 return r;
511 /* Parse the version string and compute the ABI version number. */
512 static void
513 parse_version (void)
515 const char *p = version_string;
516 unsigned int major = 0, minor = 0;
517 unsigned int abi_version;
519 /* Skip leading junk. */
520 while (*p && !ISDIGIT (*p))
521 ++p;
522 gcc_assert (*p);
524 /* Extract major version. */
525 while (ISDIGIT (*p))
527 major = major * 10 + *p - '0';
528 ++p;
531 gcc_assert (*p == '.' && ISDIGIT (p[1]));
532 ++p;
534 /* Extract minor version. */
535 while (ISDIGIT (*p))
537 minor = minor * 10 + *p - '0';
538 ++p;
541 if (flag_indirect_dispatch)
543 abi_version = GCJ_CURRENT_BC_ABI_VERSION;
544 abi_version |= FLAG_BINARYCOMPAT_ABI;
546 else /* C++ ABI */
548 /* Implicit in this computation is the idea that we won't break the
549 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
550 4.0.1). */
551 abi_version = 100000 * major + 1000 * minor;
553 if (flag_bootstrap_classes)
554 abi_version |= FLAG_BOOTSTRAP_LOADER;
556 gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
559 void
560 java_init_decl_processing (void)
562 tree field = NULL_TREE;
563 tree t;
565 init_class_processing ();
567 current_function_decl = NULL;
568 current_binding_level = NULL_BINDING_LEVEL;
569 free_binding_level = NULL_BINDING_LEVEL;
570 pushlevel (0); /* make the binding_level structure for global names */
571 global_binding_level = current_binding_level;
573 /* Build common tree nodes, Java has an unsigned char. */
574 build_common_tree_nodes (false, false);
576 /* ??? Now we continue and override some of the built types again
577 with Java specific types. As the above generated types are
578 supposed to match the targets C ABI this isn't really the way
579 to go and any Java specifics should _not_ use those global types
580 if the Java ABI does not match the C one. */
582 byte_type_node = make_signed_type (8);
583 pushdecl (build_decl (BUILTINS_LOCATION,
584 TYPE_DECL, get_identifier ("byte"), byte_type_node));
585 short_type_node = make_signed_type (16);
586 pushdecl (build_decl (BUILTINS_LOCATION,
587 TYPE_DECL, get_identifier ("short"), short_type_node));
588 int_type_node = make_signed_type (32);
589 pushdecl (build_decl (BUILTINS_LOCATION,
590 TYPE_DECL, get_identifier ("int"), int_type_node));
591 long_type_node = make_signed_type (64);
592 pushdecl (build_decl (BUILTINS_LOCATION,
593 TYPE_DECL, get_identifier ("long"), long_type_node));
595 unsigned_byte_type_node = make_unsigned_type (8);
596 pushdecl (build_decl (BUILTINS_LOCATION,
597 TYPE_DECL, get_identifier ("unsigned byte"),
598 unsigned_byte_type_node));
599 unsigned_short_type_node = make_unsigned_type (16);
600 pushdecl (build_decl (BUILTINS_LOCATION,
601 TYPE_DECL, get_identifier ("unsigned short"),
602 unsigned_short_type_node));
603 unsigned_int_type_node = make_unsigned_type (32);
604 pushdecl (build_decl (BUILTINS_LOCATION,
605 TYPE_DECL, get_identifier ("unsigned int"),
606 unsigned_int_type_node));
607 unsigned_long_type_node = make_unsigned_type (64);
608 pushdecl (build_decl (BUILTINS_LOCATION,
609 TYPE_DECL, get_identifier ("unsigned long"),
610 unsigned_long_type_node));
612 /* Define these next since types below may used them. */
613 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
614 integer_zero_node = build_int_cst (NULL_TREE, 0);
615 integer_one_node = build_int_cst (NULL_TREE, 1);
616 integer_two_node = build_int_cst (NULL_TREE, 2);
617 integer_three_node = build_int_cst (NULL_TREE, 3);
618 integer_four_node = build_int_cst (NULL_TREE, 4);
619 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
621 /* A few values used for range checking in the lexer. */
622 decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
623 decimal_long_max
624 = double_int_to_tree (unsigned_long_type_node,
625 double_int_zero.set_bit (64));
627 long_zero_node = build_int_cst (long_type_node, 0);
629 pushdecl (build_decl (BUILTINS_LOCATION,
630 TYPE_DECL, get_identifier ("void"), void_type_node));
632 t = make_node (VOID_TYPE);
633 layout_type (t); /* Uses size_zero_node */
634 return_address_type_node = build_pointer_type (t);
636 char_type_node = make_unsigned_type (16);
637 TYPE_STRING_FLAG (char_type_node) = 1;
638 pushdecl (build_decl (BUILTINS_LOCATION,
639 TYPE_DECL, get_identifier ("char"), char_type_node));
641 boolean_type_node = make_unsigned_type (1);
642 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
643 pushdecl (build_decl (BUILTINS_LOCATION,
644 TYPE_DECL, get_identifier ("boolean"),
645 boolean_type_node));
646 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
647 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
649 promoted_byte_type_node
650 = push_promoted_type ("promoted_byte", byte_type_node);
651 promoted_short_type_node
652 = push_promoted_type ("promoted_short", short_type_node);
653 promoted_char_type_node
654 = push_promoted_type ("promoted_char", char_type_node);
655 promoted_boolean_type_node
656 = push_promoted_type ("promoted_boolean", boolean_type_node);
658 float_type_node = make_node (REAL_TYPE);
659 TYPE_PRECISION (float_type_node) = 32;
660 pushdecl (build_decl (BUILTINS_LOCATION,
661 TYPE_DECL, get_identifier ("float"),
662 float_type_node));
663 layout_type (float_type_node);
665 double_type_node = make_node (REAL_TYPE);
666 TYPE_PRECISION (double_type_node) = 64;
667 pushdecl (build_decl (BUILTINS_LOCATION,
668 TYPE_DECL, get_identifier ("double"),
669 double_type_node));
670 layout_type (double_type_node);
672 float_zero_node = build_real (float_type_node, dconst0);
673 double_zero_node = build_real (double_type_node, dconst0);
675 /* These are the vtables for arrays of primitives. */
676 boolean_array_vtable = create_primitive_vtable ("boolean");
677 byte_array_vtable = create_primitive_vtable ("byte");
678 char_array_vtable = create_primitive_vtable ("char");
679 short_array_vtable = create_primitive_vtable ("short");
680 int_array_vtable = create_primitive_vtable ("int");
681 long_array_vtable = create_primitive_vtable ("long");
682 float_array_vtable = create_primitive_vtable ("float");
683 double_array_vtable = create_primitive_vtable ("double");
685 one_elt_array_domain_type = build_index_type (integer_one_node);
686 utf8const_type = make_node (RECORD_TYPE);
687 PUSH_FIELD (input_location,
688 utf8const_type, field, "hash", unsigned_short_type_node);
689 PUSH_FIELD (input_location,
690 utf8const_type, field, "length", unsigned_short_type_node);
691 FINISH_RECORD (utf8const_type);
692 utf8const_ptr_type = build_pointer_type (utf8const_type);
694 atable_type = build_array_type (ptr_type_node,
695 one_elt_array_domain_type);
696 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
697 atable_ptr_type = build_pointer_type (atable_type);
699 itable_type = build_array_type (ptr_type_node,
700 one_elt_array_domain_type);
701 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
702 itable_ptr_type = build_pointer_type (itable_type);
704 symbol_type = make_node (RECORD_TYPE);
705 PUSH_FIELD (input_location,
706 symbol_type, field, "clname", utf8const_ptr_type);
707 PUSH_FIELD (input_location, symbol_type, field, "name", utf8const_ptr_type);
708 PUSH_FIELD (input_location,
709 symbol_type, field, "signature", utf8const_ptr_type);
710 FINISH_RECORD (symbol_type);
712 symbols_array_type = build_array_type (symbol_type,
713 one_elt_array_domain_type);
714 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
716 assertion_entry_type = make_node (RECORD_TYPE);
717 PUSH_FIELD (input_location,
718 assertion_entry_type, field, "assertion_code", integer_type_node);
719 PUSH_FIELD (input_location,
720 assertion_entry_type, field, "op1", utf8const_ptr_type);
721 PUSH_FIELD (input_location,
722 assertion_entry_type, field, "op2", utf8const_ptr_type);
723 FINISH_RECORD (assertion_entry_type);
725 assertion_table_type = build_array_type (assertion_entry_type,
726 one_elt_array_domain_type);
728 /* As you're adding items here, please update the code right after
729 this section, so that the filename containing the source code of
730 the pre-defined class gets registered correctly. */
731 unqualified_object_id_node = get_identifier ("Object");
732 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
733 object_ptr_type_node = promote_type (object_type_node);
734 string_type_node = lookup_class (get_identifier ("java.lang.String"));
735 string_ptr_type_node = promote_type (string_type_node);
736 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
737 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
738 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
739 runtime_exception_type_node =
740 lookup_class (get_identifier ("java.lang.RuntimeException"));
741 error_exception_type_node =
742 lookup_class (get_identifier ("java.lang.Error"));
744 rawdata_ptr_type_node
745 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
747 add_predefined_file (get_identifier ("java/lang/Class.java"));
748 add_predefined_file (get_identifier ("java/lang/Error.java"));
749 add_predefined_file (get_identifier ("java/lang/Object.java"));
750 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
751 add_predefined_file (get_identifier ("java/lang/String.java"));
752 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
753 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
754 add_predefined_file (get_identifier ("java/lang/Exception.java"));
755 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
756 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
758 methodtable_type = make_node (RECORD_TYPE);
759 layout_type (methodtable_type);
760 build_decl (BUILTINS_LOCATION,
761 TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
762 methodtable_ptr_type = build_pointer_type (methodtable_type);
764 TYPE_identifier_node = get_identifier ("TYPE");
765 init_identifier_node = get_identifier ("<init>");
766 clinit_identifier_node = get_identifier ("<clinit>");
767 void_signature_node = get_identifier ("()V");
768 finalize_identifier_node = get_identifier ("finalize");
769 this_identifier_node = get_identifier ("this");
771 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
772 java_io_serializable_identifier_node =
773 get_identifier ("java.io.Serializable");
775 /* for lack of a better place to put this stub call */
776 init_expr_processing();
778 constants_type_node = make_node (RECORD_TYPE);
779 PUSH_FIELD (input_location,
780 constants_type_node, field, "size", unsigned_int_type_node);
781 PUSH_FIELD (input_location,
782 constants_type_node, field, "tags", ptr_type_node);
783 PUSH_FIELD (input_location,
784 constants_type_node, field, "data", ptr_type_node);
785 constants_data_field_decl_node = field;
786 FINISH_RECORD (constants_type_node);
787 build_decl (BUILTINS_LOCATION,
788 TYPE_DECL, get_identifier ("constants"), constants_type_node);
790 access_flags_type_node = unsigned_short_type_node;
792 dtable_type = make_node (RECORD_TYPE);
793 dtable_ptr_type = build_pointer_type (dtable_type);
795 otable_type = build_array_type (integer_type_node,
796 one_elt_array_domain_type);
797 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
798 otable_ptr_type = build_pointer_type (otable_type);
800 PUSH_FIELD (input_location,
801 object_type_node, field, "vtable", dtable_ptr_type);
802 DECL_FCONTEXT (field) = object_type_node;
803 TYPE_VFIELD (object_type_node) = field;
805 /* This isn't exactly true, but it is what we have in the source.
806 There is an unresolved issue here, which is whether the vtable
807 should be marked by the GC. */
808 if (! flag_hash_synchronization)
809 PUSH_FIELD (input_location, object_type_node, field, "sync_info",
810 build_pointer_type (object_type_node));
811 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
812 FIELD_PRIVATE (t) = 1;
813 FINISH_RECORD (object_type_node);
815 field_type_node = make_node (RECORD_TYPE);
816 field_ptr_type_node = build_pointer_type (field_type_node);
817 method_type_node = make_node (RECORD_TYPE);
818 method_ptr_type_node = build_pointer_type (method_type_node);
820 set_super_info (0, class_type_node, object_type_node, 0);
821 set_super_info (0, string_type_node, object_type_node, 0);
822 class_ptr_type = build_pointer_type (class_type_node);
824 PUSH_FIELD (input_location,
825 class_type_node, field, "next_or_version", class_ptr_type);
826 PUSH_FIELD (input_location,
827 class_type_node, field, "name", utf8const_ptr_type);
828 PUSH_FIELD (input_location,
829 class_type_node, field, "accflags", access_flags_type_node);
830 PUSH_FIELD (input_location,
831 class_type_node, field, "superclass", class_ptr_type);
832 PUSH_FIELD (input_location,
833 class_type_node, field, "constants", constants_type_node);
834 constants_field_decl_node = field;
835 PUSH_FIELD (input_location,
836 class_type_node, field, "methods", method_ptr_type_node);
837 PUSH_FIELD (input_location,
838 class_type_node, field, "method_count", short_type_node);
839 PUSH_FIELD (input_location,
840 class_type_node, field, "vtable_method_count", short_type_node);
841 PUSH_FIELD (input_location,
842 class_type_node, field, "fields", field_ptr_type_node);
843 PUSH_FIELD (input_location,
844 class_type_node, field, "size_in_bytes", int_type_node);
845 PUSH_FIELD (input_location,
846 class_type_node, field, "field_count", short_type_node);
847 PUSH_FIELD (input_location,
848 class_type_node, field, "static_field_count", short_type_node);
849 PUSH_FIELD (input_location,
850 class_type_node, field, "vtable", dtable_ptr_type);
851 PUSH_FIELD (input_location,
852 class_type_node, field, "otable", otable_ptr_type);
853 PUSH_FIELD (input_location,
854 class_type_node, field, "otable_syms",
855 symbols_array_ptr_type);
856 PUSH_FIELD (input_location,
857 class_type_node, field, "atable", atable_ptr_type);
858 PUSH_FIELD (input_location,
859 class_type_node, field, "atable_syms",
860 symbols_array_ptr_type);
861 PUSH_FIELD (input_location,
862 class_type_node, field, "itable", itable_ptr_type);
863 PUSH_FIELD (input_location, class_type_node, field, "itable_syms",
864 symbols_array_ptr_type);
865 PUSH_FIELD (input_location,
866 class_type_node, field, "catch_classes", ptr_type_node);
867 PUSH_FIELD (input_location, class_type_node, field, "interfaces",
868 build_pointer_type (class_ptr_type));
869 PUSH_FIELD (input_location, class_type_node, field, "loader", ptr_type_node);
870 PUSH_FIELD (input_location,
871 class_type_node, field, "interface_count", short_type_node);
872 PUSH_FIELD (input_location, class_type_node, field, "state", byte_type_node);
873 PUSH_FIELD (input_location, class_type_node, field, "thread", ptr_type_node);
874 PUSH_FIELD (input_location,
875 class_type_node, field, "depth", short_type_node);
876 PUSH_FIELD (input_location,
877 class_type_node, field, "ancestors", ptr_type_node);
878 PUSH_FIELD (input_location, class_type_node, field, "idt", ptr_type_node);
879 PUSH_FIELD (input_location,
880 class_type_node, field, "arrayclass", ptr_type_node);
881 PUSH_FIELD (input_location,
882 class_type_node, field, "protectionDomain", ptr_type_node);
883 PUSH_FIELD (input_location,
884 class_type_node, field, "assertion_table", ptr_type_node);
885 PUSH_FIELD (input_location,
886 class_type_node, field, "hack_signers", ptr_type_node);
887 PUSH_FIELD (input_location, class_type_node, field, "chain", ptr_type_node);
888 PUSH_FIELD (input_location,
889 class_type_node, field, "aux_info", ptr_type_node);
890 PUSH_FIELD (input_location, class_type_node, field, "engine", ptr_type_node);
891 PUSH_FIELD (input_location,
892 class_type_node, field, "reflection_data", ptr_type_node);
893 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = DECL_CHAIN (t))
894 FIELD_PRIVATE (t) = 1;
895 push_super_field (class_type_node, object_type_node);
897 FINISH_RECORD (class_type_node);
898 build_decl (BUILTINS_LOCATION,
899 TYPE_DECL, get_identifier ("Class"), class_type_node);
901 field_info_union_node = make_node (UNION_TYPE);
902 PUSH_FIELD (input_location,
903 field_info_union_node, field, "boffset", int_type_node);
904 PUSH_FIELD (input_location,
905 field_info_union_node, field, "addr", ptr_type_node);
906 layout_type (field_info_union_node);
908 PUSH_FIELD (input_location,
909 field_type_node, field, "name", utf8const_ptr_type);
910 PUSH_FIELD (input_location, field_type_node, field, "type", class_ptr_type);
911 PUSH_FIELD (input_location,
912 field_type_node, field, "accflags", access_flags_type_node);
913 PUSH_FIELD (input_location,
914 field_type_node, field, "bsize", unsigned_short_type_node);
915 PUSH_FIELD (input_location,
916 field_type_node, field, "info", field_info_union_node);
917 FINISH_RECORD (field_type_node);
918 build_decl (BUILTINS_LOCATION,
919 TYPE_DECL, get_identifier ("Field"), field_type_node);
921 nativecode_ptr_array_type_node
922 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
924 PUSH_FIELD (input_location,
925 dtable_type, field, "class", class_ptr_type);
926 PUSH_FIELD (input_location,
927 dtable_type, field, "methods", nativecode_ptr_array_type_node);
928 FINISH_RECORD (dtable_type);
929 build_decl (BUILTINS_LOCATION,
930 TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
932 jexception_type = make_node (RECORD_TYPE);
933 PUSH_FIELD (input_location,
934 jexception_type, field, "start_pc", ptr_type_node);
935 PUSH_FIELD (input_location, jexception_type, field, "end_pc", ptr_type_node);
936 PUSH_FIELD (input_location,
937 jexception_type, field, "handler_pc", ptr_type_node);
938 PUSH_FIELD (input_location,
939 jexception_type, field, "catch_type", class_ptr_type);
940 FINISH_RECORD (jexception_type);
941 build_decl (BUILTINS_LOCATION,
942 TYPE_DECL, get_identifier ("jexception"), field_type_node);
943 jexception_ptr_type = build_pointer_type (jexception_type);
945 lineNumberEntry_type = make_node (RECORD_TYPE);
946 PUSH_FIELD (input_location,
947 lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
948 PUSH_FIELD (input_location,
949 lineNumberEntry_type, field, "start_pc", ptr_type_node);
950 FINISH_RECORD (lineNumberEntry_type);
952 lineNumbers_type = make_node (RECORD_TYPE);
953 PUSH_FIELD (input_location,
954 lineNumbers_type, field, "length", unsigned_int_type_node);
955 FINISH_RECORD (lineNumbers_type);
957 PUSH_FIELD (input_location,
958 method_type_node, field, "name", utf8const_ptr_type);
959 PUSH_FIELD (input_location,
960 method_type_node, field, "signature", utf8const_ptr_type);
961 PUSH_FIELD (input_location,
962 method_type_node, field, "accflags", access_flags_type_node);
963 PUSH_FIELD (input_location,
964 method_type_node, field, "index", unsigned_short_type_node);
965 PUSH_FIELD (input_location,
966 method_type_node, field, "ncode", nativecode_ptr_type_node);
967 PUSH_FIELD (input_location,
968 method_type_node, field, "throws", ptr_type_node);
969 FINISH_RECORD (method_type_node);
970 build_decl (BUILTINS_LOCATION,
971 TYPE_DECL, get_identifier ("Method"), method_type_node);
973 end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
975 t = build_function_type_list (ptr_type_node, class_ptr_type, NULL_TREE);
976 alloc_object_node = add_builtin_function ("_Jv_AllocObject", t,
977 0, NOT_BUILT_IN, NULL, NULL_TREE);
978 DECL_IS_MALLOC (alloc_object_node) = 1;
979 alloc_no_finalizer_node =
980 add_builtin_function ("_Jv_AllocObjectNoFinalizer", t,
981 0, NOT_BUILT_IN, NULL, NULL_TREE);
982 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
984 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
985 soft_initclass_node = add_builtin_function ("_Jv_InitClass", t,
986 0, NOT_BUILT_IN, NULL, NULL_TREE);
987 t = build_function_type_list (ptr_type_node,
988 class_ptr_type, int_type_node, NULL_TREE);
989 soft_resolvepoolentry_node
990 = add_builtin_function ("_Jv_ResolvePoolEntry", t,
991 0,NOT_BUILT_IN, NULL, NULL_TREE);
992 DECL_PURE_P (soft_resolvepoolentry_node) = 1;
993 t = build_function_type_list (void_type_node,
994 class_ptr_type, int_type_node, NULL_TREE);
995 throw_node = add_builtin_function ("_Jv_Throw", t,
996 0, NOT_BUILT_IN, NULL, NULL_TREE);
997 /* Mark throw_nodes as `noreturn' functions with side effects. */
998 TREE_THIS_VOLATILE (throw_node) = 1;
999 TREE_SIDE_EFFECTS (throw_node) = 1;
1001 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1002 soft_monitorenter_node
1003 = add_builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
1004 NULL, NULL_TREE);
1005 soft_monitorexit_node
1006 = add_builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
1007 NULL, NULL_TREE);
1009 t = build_function_type_list (ptr_type_node,
1010 ptr_type_node, int_type_node, NULL_TREE);
1011 soft_newarray_node
1012 = add_builtin_function ("_Jv_NewPrimArray", t,
1013 0, NOT_BUILT_IN, NULL, NULL_TREE);
1014 DECL_IS_MALLOC (soft_newarray_node) = 1;
1016 t = build_function_type_list (ptr_type_node,
1017 int_type_node, class_ptr_type,
1018 object_ptr_type_node, NULL_TREE);
1019 soft_anewarray_node
1020 = add_builtin_function ("_Jv_NewObjectArray", t,
1021 0, NOT_BUILT_IN, NULL, NULL_TREE);
1022 DECL_IS_MALLOC (soft_anewarray_node) = 1;
1024 t = build_varargs_function_type_list (ptr_type_node,
1025 ptr_type_node, int_type_node,
1026 NULL_TREE);
1027 soft_multianewarray_node
1028 = add_builtin_function ("_Jv_NewMultiArray", t,
1029 0, NOT_BUILT_IN, NULL, NULL_TREE);
1030 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
1032 t = build_function_type_list (void_type_node, int_type_node, NULL_TREE);
1033 soft_badarrayindex_node
1034 = add_builtin_function ("_Jv_ThrowBadArrayIndex", t,
1035 0, NOT_BUILT_IN, NULL, NULL_TREE);
1036 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1037 effects. */
1038 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1039 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1041 t = build_function_type_list (void_type_node, NULL_TREE);
1042 soft_nullpointer_node
1043 = add_builtin_function ("_Jv_ThrowNullPointerException", t,
1044 0, NOT_BUILT_IN, NULL, NULL_TREE);
1045 /* Mark soft_nullpointer_node as a `noreturn' function with side
1046 effects. */
1047 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1048 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1050 soft_abstractmethod_node
1051 = add_builtin_function ("_Jv_ThrowAbstractMethodError", t,
1052 0, NOT_BUILT_IN, NULL, NULL_TREE);
1053 /* Mark soft_abstractmethod_node as a `noreturn' function with side
1054 effects. */
1055 TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
1056 TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
1058 soft_nosuchfield_node
1059 = add_builtin_function ("_Jv_ThrowNoSuchFieldError", t,
1060 0, NOT_BUILT_IN, NULL, NULL_TREE);
1061 /* Mark soft_nosuchfield_node as a `noreturn' function with side
1062 effects. */
1063 TREE_THIS_VOLATILE (soft_nosuchfield_node) = 1;
1064 TREE_SIDE_EFFECTS (soft_nosuchfield_node) = 1;
1066 t = build_function_type_list (ptr_type_node,
1067 class_ptr_type, object_ptr_type_node,
1068 NULL_TREE);
1069 soft_checkcast_node
1070 = add_builtin_function ("_Jv_CheckCast", t,
1071 0, NOT_BUILT_IN, NULL, NULL_TREE);
1072 t = build_function_type_list (boolean_type_node,
1073 object_ptr_type_node, class_ptr_type,
1074 NULL_TREE);
1075 soft_instanceof_node
1076 = add_builtin_function ("_Jv_IsInstanceOf", t,
1077 0, NOT_BUILT_IN, NULL, NULL_TREE);
1078 DECL_PURE_P (soft_instanceof_node) = 1;
1079 t = build_function_type_list (void_type_node,
1080 object_ptr_type_node, object_ptr_type_node,
1081 NULL_TREE);
1082 soft_checkarraystore_node
1083 = add_builtin_function ("_Jv_CheckArrayStore", t,
1084 0, NOT_BUILT_IN, NULL, NULL_TREE);
1085 t = build_function_type_list (ptr_type_node,
1086 ptr_type_node, ptr_type_node, int_type_node,
1087 NULL_TREE);
1088 soft_lookupinterfacemethod_node
1089 = add_builtin_function ("_Jv_LookupInterfaceMethodIdx", t,
1090 0, NOT_BUILT_IN, NULL, NULL_TREE);
1091 DECL_PURE_P (soft_lookupinterfacemethod_node) = 1;
1093 t = build_function_type_list (ptr_type_node,
1094 ptr_type_node, ptr_type_node, ptr_type_node,
1095 NULL_TREE);
1096 soft_lookupinterfacemethodbyname_node
1097 = add_builtin_function ("_Jv_LookupInterfaceMethod", t,
1098 0, NOT_BUILT_IN, NULL, NULL_TREE);
1099 t = build_function_type_list (ptr_type_node,
1100 object_ptr_type_node, ptr_type_node,
1101 ptr_type_node, int_type_node, NULL_TREE);
1102 soft_lookupjnimethod_node
1103 = add_builtin_function ("_Jv_LookupJNIMethod", t,
1104 0, NOT_BUILT_IN, NULL, NULL_TREE);
1105 t = build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE);
1106 soft_getjnienvnewframe_node
1107 = add_builtin_function ("_Jv_GetJNIEnvNewFrame", t,
1108 0, NOT_BUILT_IN, NULL, NULL_TREE);
1109 t = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
1110 soft_jnipopsystemframe_node
1111 = add_builtin_function ("_Jv_JNI_PopSystemFrame", t,
1112 0, NOT_BUILT_IN, NULL, NULL_TREE);
1114 t = build_function_type_list (object_ptr_type_node,
1115 object_ptr_type_node, NULL_TREE);
1116 soft_unwrapjni_node
1117 = add_builtin_function ("_Jv_UnwrapJNIweakReference", t,
1118 0, NOT_BUILT_IN, NULL, NULL_TREE);
1120 t = build_function_type_list (int_type_node,
1121 int_type_node, int_type_node, NULL_TREE);
1122 soft_idiv_node
1123 = add_builtin_function ("_Jv_divI", t,
1124 0, NOT_BUILT_IN, NULL, NULL_TREE);
1126 soft_irem_node
1127 = add_builtin_function ("_Jv_remI", t,
1128 0, NOT_BUILT_IN, NULL, NULL_TREE);
1130 t = build_function_type_list (long_type_node,
1131 long_type_node, long_type_node, NULL_TREE);
1132 soft_ldiv_node
1133 = add_builtin_function ("_Jv_divJ", t,
1134 0, NOT_BUILT_IN, NULL, NULL_TREE);
1136 soft_lrem_node
1137 = add_builtin_function ("_Jv_remJ", t,
1138 0, NOT_BUILT_IN, NULL, NULL_TREE);
1140 initialize_builtins ();
1142 soft_fmod_node = builtin_decl_explicit (BUILT_IN_FMOD);
1144 parse_version ();
1148 /* Look up NAME in the current binding level and its superiors
1149 in the namespace of variables, functions and typedefs.
1150 Return a ..._DECL node of some kind representing its definition,
1151 or return 0 if it is undefined. */
1153 tree
1154 lookup_name (tree name)
1156 tree val;
1157 if (current_binding_level != global_binding_level
1158 && IDENTIFIER_LOCAL_VALUE (name))
1159 val = IDENTIFIER_LOCAL_VALUE (name);
1160 else
1161 val = IDENTIFIER_GLOBAL_VALUE (name);
1162 return val;
1165 /* Similar to `lookup_name' but look only at current binding level and
1166 the previous one if it's the parameter level. */
1168 static tree
1169 lookup_name_current_level (tree name)
1171 tree t;
1173 if (current_binding_level == global_binding_level)
1174 return IDENTIFIER_GLOBAL_VALUE (name);
1176 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1177 return 0;
1179 for (t = current_binding_level->names; t; t = DECL_CHAIN (t))
1180 if (DECL_NAME (t) == name)
1181 break;
1183 return t;
1186 /* Record a decl-node X as belonging to the current lexical scope.
1187 Check for errors (such as an incompatible declaration for the same
1188 name already seen in the same scope).
1190 Returns either X or an old decl for the same name.
1191 If an old decl is returned, it may have been smashed
1192 to agree with what X says. */
1194 tree
1195 pushdecl (tree x)
1197 tree t;
1198 tree name = DECL_NAME (x);
1199 struct binding_level *b = current_binding_level;
1201 if (TREE_CODE (x) != TYPE_DECL)
1202 DECL_CONTEXT (x) = current_function_decl;
1203 if (name)
1205 t = lookup_name_current_level (name);
1206 if (t != 0 && t == error_mark_node)
1207 /* error_mark_node is 0 for a while during initialization! */
1209 t = 0;
1210 error ("%q+D used prior to declaration", x);
1213 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1214 to point to the TYPE_DECL.
1215 Since Java does not have typedefs, a type can only have
1216 one (true) name, given by a class, interface, or builtin. */
1217 if (TREE_CODE (x) == TYPE_DECL
1218 && TYPE_NAME (TREE_TYPE (x)) == 0
1219 && TREE_TYPE (x) != error_mark_node)
1221 TYPE_NAME (TREE_TYPE (x)) = x;
1222 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1225 /* This name is new in its binding level.
1226 Install the new declaration and return it. */
1227 if (b == global_binding_level)
1229 /* Install a global value. */
1231 IDENTIFIER_GLOBAL_VALUE (name) = x;
1233 else
1235 /* Here to install a non-global value. */
1236 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1237 IDENTIFIER_LOCAL_VALUE (name) = x;
1239 /* If storing a local value, there may already be one (inherited).
1240 If so, record it for restoration when this binding level ends. */
1241 if (oldlocal != 0)
1242 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1246 /* Put decls on list in reverse order.
1247 We will reverse them later if necessary. */
1248 DECL_CHAIN (x) = b->names;
1249 b->names = x;
1251 return x;
1254 void
1255 pushdecl_force_head (tree x)
1257 current_binding_level->names = x;
1260 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1262 tree
1263 pushdecl_top_level (tree x)
1265 tree t;
1266 struct binding_level *b = current_binding_level;
1268 current_binding_level = global_binding_level;
1269 t = pushdecl (x);
1270 current_binding_level = b;
1271 return t;
1274 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1276 tree
1277 pushdecl_function_level (tree x)
1279 tree t;
1280 struct binding_level *b = current_binding_level;
1282 current_binding_level = function_binding_level;
1283 t = pushdecl (x);
1284 current_binding_level = b;
1285 return t;
1288 /* Return true if we are in the global binding level. */
1290 bool
1291 global_bindings_p (void)
1293 return current_binding_level == global_binding_level;
1296 /* Return the list of declarations of the current level.
1297 Note that this list is in reverse order unless/until
1298 you nreverse it; and when you do nreverse it, you must
1299 store the result back using `storedecls' or you will lose. */
1301 tree
1302 getdecls (void)
1304 return current_binding_level->names;
1307 /* Create a new `struct binding_level'. */
1309 static struct binding_level *
1310 make_binding_level (void)
1312 /* NOSTRICT */
1313 return ggc_cleared_alloc<binding_level> ();
1316 void
1317 pushlevel (int unused ATTRIBUTE_UNUSED)
1319 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1321 /* Reuse or create a struct for this binding level. */
1323 if (free_binding_level)
1325 newlevel = free_binding_level;
1326 free_binding_level = free_binding_level->level_chain;
1328 else
1330 newlevel = make_binding_level ();
1333 /* Add this level to the front of the chain (stack) of levels that
1334 are active. */
1336 *newlevel = clear_binding_level;
1337 newlevel->level_chain = current_binding_level;
1338 newlevel->loc = input_location;
1339 current_binding_level = newlevel;
1340 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1341 newlevel->binding_depth = binding_depth;
1342 indent ();
1343 fprintf (stderr, "push %s level %p pc %d\n",
1344 (is_class_level) ? "class" : "block", newlevel, current_pc);
1345 is_class_level = 0;
1346 binding_depth++;
1347 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1350 /* Exit a binding level.
1351 Pop the level off, and restore the state of the identifier-decl mappings
1352 that were in effect when this level was entered.
1354 If KEEP is nonzero, this level had explicit declarations, so
1355 and create a "block" (a BLOCK node) for the level
1356 to record its declarations and subblocks for symbol table output.
1358 If FUNCTIONBODY is nonzero, this level is the body of a function,
1359 so create a block as if KEEP were set and also clear out all
1360 label names.
1362 If REVERSE is nonzero, reverse the order of decls before putting
1363 them into the BLOCK. */
1365 tree
1366 poplevel (int keep, int reverse, int functionbody)
1368 tree link;
1369 /* The chain of decls was accumulated in reverse order.
1370 Put it into forward order, just for cleanliness. */
1371 tree decls;
1372 tree subblocks = current_binding_level->blocks;
1373 tree block = 0;
1374 tree decl;
1375 tree bind = 0;
1377 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1378 binding_depth--;
1379 indent ();
1380 if (current_binding_level->end_pc != LARGEST_PC)
1381 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1382 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1383 current_binding_level->end_pc);
1384 else
1385 fprintf (stderr, "pop %s level %p pc %d\n",
1386 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1387 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1389 /* Get the decls in the order they were written.
1390 Usually current_binding_level->names is in reverse order.
1391 But parameter decls were previously put in forward order. */
1393 if (reverse)
1394 current_binding_level->names
1395 = decls = nreverse (current_binding_level->names);
1396 else
1397 decls = current_binding_level->names;
1399 for (decl = decls; decl; decl = DECL_CHAIN (decl))
1400 if (TREE_CODE (decl) == VAR_DECL
1401 && DECL_LANG_SPECIFIC (decl) != NULL
1402 && DECL_LOCAL_SLOT_NUMBER (decl))
1403 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1405 /* If there were any declarations in that level,
1406 or if this level is a function body,
1407 create a BLOCK to record them for the life of this function. */
1409 block = 0;
1410 if (keep || functionbody)
1411 block = make_node (BLOCK);
1413 if (current_binding_level->exception_range)
1414 expand_end_java_handler (current_binding_level->exception_range);
1416 if (block != 0)
1418 /* If any statements have been generated at this level, create a
1419 BIND_EXPR to hold them and copy the variables to it. This
1420 only applies to the bytecode compiler. */
1421 if (current_binding_level->stmts)
1423 tree decl = decls;
1424 tree *var = &BLOCK_VARS (block);
1426 /* Copy decls from names list, ignoring labels. */
1427 while (decl)
1429 tree next = DECL_CHAIN (decl);
1430 if (TREE_CODE (decl) != LABEL_DECL)
1432 *var = decl;
1433 var = &DECL_CHAIN (decl);
1435 decl = next;
1437 *var = NULL;
1439 bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block),
1440 BLOCK_EXPR_BODY (block), block);
1441 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1443 if (BIND_EXPR_BODY (bind)
1444 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1445 TREE_SIDE_EFFECTS (bind) = 1;
1447 /* FIXME: gimplifier brain damage. */
1448 if (BIND_EXPR_BODY (bind) == NULL)
1449 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1451 SET_EXPR_LOCATION (bind, current_binding_level->loc);
1453 current_binding_level->stmts = NULL;
1455 else
1457 BLOCK_VARS (block) = decls;
1459 BLOCK_SUBBLOCKS (block) = subblocks;
1462 /* In each subblock, record that this is its superior. */
1464 for (link = subblocks; link; link = BLOCK_CHAIN (link))
1465 BLOCK_SUPERCONTEXT (link) = block;
1467 /* Clear out the meanings of the local variables of this level. */
1469 for (link = decls; link; link = DECL_CHAIN (link))
1471 tree name = DECL_NAME (link);
1472 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1474 /* If the ident. was used or addressed via a local extern decl,
1475 don't forget that fact. */
1476 if (DECL_EXTERNAL (link))
1478 if (TREE_USED (link))
1479 TREE_USED (name) = 1;
1480 if (TREE_ADDRESSABLE (link))
1481 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1483 IDENTIFIER_LOCAL_VALUE (name) = 0;
1487 /* Restore all name-meanings of the outer levels
1488 that were shadowed by this level. */
1490 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1491 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1493 /* If the level being exited is the top level of a function,
1494 check over all the labels, and clear out the current
1495 (function local) meanings of their names. */
1497 if (functionbody)
1499 /* If this is the top level block of a function,
1500 the vars are the function's parameters.
1501 Don't leave them in the BLOCK because they are
1502 found in the FUNCTION_DECL instead. */
1504 BLOCK_VARS (block) = 0;
1507 /* Pop the current level, and free the structure for reuse. */
1510 struct binding_level *level = current_binding_level;
1511 current_binding_level = current_binding_level->level_chain;
1513 level->level_chain = free_binding_level;
1514 free_binding_level = level;
1517 /* Dispose of the block that we just made inside some higher level. */
1518 if (functionbody)
1520 DECL_INITIAL (current_function_decl) = block;
1521 DECL_SAVED_TREE (current_function_decl) = bind;
1523 else
1525 if (block)
1527 current_binding_level->blocks
1528 = block_chainon (current_binding_level->blocks, block);
1530 /* If we did not make a block for the level just exited,
1531 any blocks made for inner levels
1532 (since they cannot be recorded as subblocks in that level)
1533 must be carried forward so they will later become subblocks
1534 of something else. */
1535 else if (subblocks)
1536 current_binding_level->blocks
1537 = block_chainon (current_binding_level->blocks, subblocks);
1539 if (bind)
1540 java_add_stmt (bind);
1543 if (block)
1544 TREE_USED (block) = 1;
1545 return block;
1548 void
1549 maybe_pushlevels (int pc)
1551 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1552 current_pc = pc;
1553 #endif
1555 while (pending_local_decls != NULL_TREE &&
1556 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1558 tree *ptr = &pending_local_decls;
1559 tree decl = *ptr, next;
1560 int end_pc = DECL_LOCAL_END_PC (decl);
1562 while (*ptr != NULL_TREE
1563 && DECL_LOCAL_START_PC (*ptr) <= pc
1564 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1565 ptr = &DECL_CHAIN (*ptr);
1566 pending_local_decls = *ptr;
1567 *ptr = NULL_TREE;
1569 /* Force non-nested range to be nested in current range by
1570 truncating variable lifetimes. */
1571 if (end_pc > current_binding_level->end_pc)
1573 tree t;
1574 end_pc = current_binding_level->end_pc;
1575 for (t = decl; t != NULL_TREE; t = DECL_CHAIN (t))
1576 DECL_LOCAL_END_PC (t) = end_pc;
1579 maybe_start_try (pc, end_pc);
1581 pushlevel (1);
1583 current_binding_level->end_pc = end_pc;
1584 current_binding_level->start_pc = pc;
1585 current_binding_level->names = NULL;
1586 for ( ; decl != NULL_TREE; decl = next)
1588 int index = DECL_LOCAL_SLOT_NUMBER (decl);
1589 tree base_decl;
1590 next = DECL_CHAIN (decl);
1591 push_jvm_slot (index, decl);
1592 pushdecl (decl);
1593 base_decl
1594 = find_local_variable (index, TREE_TYPE (decl), pc);
1595 if (TREE_CODE (TREE_TYPE (base_decl)) == POINTER_TYPE)
1596 base_decl = TREE_VEC_ELT (base_decl_map, index);
1597 SET_DECL_VALUE_EXPR (decl, base_decl);
1598 DECL_HAS_VALUE_EXPR_P (decl) = 1;
1602 maybe_start_try (pc, 0);
1605 void
1606 maybe_poplevels (int pc)
1608 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1609 current_pc = pc;
1610 #endif
1612 /* FIXME: I'm pretty sure that this is wrong. Variable scopes are
1613 inclusive, so a variable is live if pc == end_pc. Here, we
1614 terminate a range if the current pc is equal to the end of the
1615 range, and this is *before* we have generated code for the
1616 instruction at end_pc. We're closing a binding level one
1617 instruction too early.*/
1618 while (current_binding_level->end_pc <= pc)
1619 poplevel (1, 0, 0);
1622 /* Terminate any binding which began during the range beginning at
1623 start_pc. This tidies up improperly nested local variable ranges
1624 and exception handlers; a variable declared within an exception
1625 range is forcibly terminated when that exception ends. */
1627 void
1628 force_poplevels (int start_pc)
1630 while (current_binding_level->start_pc > start_pc)
1632 if (pedantic && current_binding_level->start_pc > start_pc)
1633 warning (0, "In %+D: overlapped variable and exception ranges at %d",
1634 current_function_decl,
1635 current_binding_level->start_pc);
1636 poplevel (1, 0, 0);
1640 /* integrate_decl_tree calls this function. */
1642 void
1643 java_dup_lang_specific_decl (tree node)
1645 int lang_decl_size;
1646 struct lang_decl *x;
1648 if (!DECL_LANG_SPECIFIC (node))
1649 return;
1651 lang_decl_size = sizeof (struct lang_decl);
1652 x = ggc_alloc<struct lang_decl> ();
1653 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1654 DECL_LANG_SPECIFIC (node) = x;
1657 void
1658 give_name_to_locals (JCF *jcf)
1660 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1661 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1662 tree parm;
1663 pending_local_decls = NULL_TREE;
1664 if (n == 0)
1665 return;
1666 JCF_SEEK (jcf, n);
1667 n = JCF_readu2 (jcf);
1668 for (i = 0; i < n; i++)
1670 int start_pc = JCF_readu2 (jcf);
1671 int length = JCF_readu2 (jcf);
1672 int name_index = JCF_readu2 (jcf);
1673 int signature_index = JCF_readu2 (jcf);
1674 int slot = JCF_readu2 (jcf);
1675 tree name = get_name_constant (jcf, name_index);
1676 tree type = parse_signature (jcf, signature_index);
1677 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1678 && start_pc == 0
1679 && length == DECL_CODE_LENGTH (current_function_decl))
1681 tree decl = TREE_VEC_ELT (decl_map, slot);
1682 DECL_NAME (decl) = name;
1683 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1684 warning (0, "bad type in parameter debug info");
1686 else
1688 tree *ptr;
1689 int end_pc = start_pc + length;
1690 tree decl = build_decl (input_location, VAR_DECL, name, type);
1691 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1693 warning (0, "bad PC range for debug info for local %q+D",
1694 decl);
1695 end_pc = DECL_CODE_LENGTH (current_function_decl);
1698 /* Adjust start_pc if necessary so that the local's first
1699 store operation will use the relevant DECL as a
1700 destination. Fore more information, read the leading
1701 comments for expr.c:maybe_adjust_start_pc. */
1702 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1704 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1705 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1706 DECL_LOCAL_START_PC (decl) = start_pc;
1707 DECL_LOCAL_END_PC (decl) = end_pc;
1709 /* Now insert the new decl in the proper place in
1710 pending_local_decls. We are essentially doing an insertion sort,
1711 which works fine, since the list input will normally already
1712 be sorted. */
1713 ptr = &pending_local_decls;
1714 while (*ptr != NULL_TREE
1715 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1716 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1717 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1718 ptr = &DECL_CHAIN (*ptr);
1719 DECL_CHAIN (decl) = *ptr;
1720 *ptr = decl;
1724 pending_local_decls = nreverse (pending_local_decls);
1726 /* Fill in default names for the parameters. */
1727 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1728 parm != NULL_TREE; parm = DECL_CHAIN (parm), i++)
1730 if (DECL_NAME (parm) == NULL_TREE)
1732 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1733 if (arg_i == 0)
1734 DECL_NAME (parm) = get_identifier ("this");
1735 else
1737 char buffer[12];
1738 sprintf (buffer, "ARG_%d", arg_i);
1739 DECL_NAME (parm) = get_identifier (buffer);
1745 tree
1746 build_result_decl (tree fndecl)
1748 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1749 tree result = DECL_RESULT (fndecl);
1750 if (! result)
1752 result = build_decl (DECL_SOURCE_LOCATION (fndecl),
1753 RESULT_DECL, NULL_TREE, restype);
1754 DECL_ARTIFICIAL (result) = 1;
1755 DECL_IGNORED_P (result) = 1;
1756 DECL_CONTEXT (result) = fndecl;
1757 DECL_RESULT (fndecl) = result;
1759 return result;
1762 void
1763 start_java_method (tree fndecl)
1765 tree tem, *ptr;
1766 int i;
1768 uniq = 0;
1770 current_function_decl = fndecl;
1771 announce_function (fndecl);
1773 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1774 decl_map = make_tree_vec (i);
1775 base_decl_map = make_tree_vec (i);
1776 type_map = XRESIZEVEC (tree, type_map, i);
1778 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1779 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1780 current_pc = 0;
1781 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1782 pushlevel (1); /* Push parameters. */
1784 ptr = &DECL_ARGUMENTS (fndecl);
1785 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1786 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1788 tree parm_name = NULL_TREE, parm_decl;
1789 tree parm_type = TREE_VALUE (tem);
1790 gcc_assert (i < DECL_MAX_LOCALS (fndecl));
1792 parm_decl = build_decl (input_location, PARM_DECL, parm_name, parm_type);
1793 DECL_CONTEXT (parm_decl) = fndecl;
1794 if (targetm.calls.promote_prototypes (parm_type)
1795 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1796 && INTEGRAL_TYPE_P (parm_type))
1797 parm_type = integer_type_node;
1798 DECL_ARG_TYPE (parm_decl) = parm_type;
1800 *ptr = parm_decl;
1801 ptr = &DECL_CHAIN (parm_decl);
1803 /* Add parm_decl to the decl_map. */
1804 push_jvm_slot (i, parm_decl);
1806 /* The this parameter of methods is artificial. */
1807 if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE && i == 0)
1808 DECL_ARTIFICIAL (parm_decl) = 1;
1810 type_map[i] = TREE_TYPE (parm_decl);
1811 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1813 i++;
1814 type_map[i] = void_type_node;
1817 *ptr = NULL_TREE;
1818 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1820 while (i < DECL_MAX_LOCALS(fndecl))
1821 type_map[i++] = NULL_TREE;
1823 build_result_decl (fndecl);
1824 DECL_SOURCE_LOCATION (fndecl) = input_location;
1826 /* Push local variables. */
1827 pushlevel (2);
1829 function_binding_level = current_binding_level;
1832 void
1833 end_java_method (void)
1835 tree fndecl = current_function_decl;
1837 /* pop out of function */
1838 poplevel (1, 1, 0);
1840 /* pop out of its parameters */
1841 poplevel (1, 0, 1);
1843 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1845 if (DECL_SAVED_TREE (fndecl))
1847 tree fbody, block_body;
1848 /* Before we check initialization, attached all class initialization
1849 variable to the block_body */
1850 fbody = DECL_SAVED_TREE (fndecl);
1851 block_body = BIND_EXPR_BODY (fbody);
1852 hash_table<treetreehasher> *ht = DECL_FUNCTION_INIT_TEST_TABLE (fndecl);
1853 ht->traverse<tree, attach_init_test_initialization_flags> (block_body);
1856 finish_method (fndecl);
1858 current_function_decl = NULL_TREE;
1859 base_decl_map = NULL_TREE;
1862 /* Prepare a method for expansion. */
1864 void
1865 finish_method (tree fndecl)
1867 tree *tp = &DECL_SAVED_TREE (fndecl);
1869 /* Wrap body of synchronized methods in a monitorenter,
1870 plus monitorexit cleanup. */
1871 if (METHOD_SYNCHRONIZED (fndecl))
1873 tree enter, exit, lock;
1874 if (METHOD_STATIC (fndecl))
1875 lock = build_class_ref (DECL_CONTEXT (fndecl));
1876 else
1877 lock = DECL_ARGUMENTS (fndecl);
1878 BUILD_MONITOR_ENTER (enter, lock);
1879 BUILD_MONITOR_EXIT (exit, lock);
1880 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1881 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1884 /* Convert function tree to GENERIC prior to inlining. */
1885 java_genericize (fndecl);
1887 /* Store the end of the function, so that we get good line number
1888 info for the epilogue. */
1889 if (DECL_STRUCT_FUNCTION (fndecl))
1890 set_cfun (DECL_STRUCT_FUNCTION (fndecl));
1891 else
1892 allocate_struct_function (fndecl, false);
1893 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
1895 /* Defer inlining and expansion to the cgraph optimizers. */
1896 cgraph_node::finalize_function (fndecl, false);
1899 /* We pessimistically marked all methods and fields external until we
1900 knew what set of classes we were planning to compile. Now mark those
1901 associated with CLASS to be generated locally as not external. */
1903 static void
1904 java_mark_decl_local (tree decl)
1906 DECL_EXTERNAL (decl) = 0;
1908 #ifdef ENABLE_CHECKING
1909 /* Double check that we didn't pass the function to the callgraph early. */
1910 if (TREE_CODE (decl) == FUNCTION_DECL)
1912 struct cgraph_node *node = cgraph_node::get (decl);
1913 gcc_assert (!node || !node->definition);
1915 #endif
1916 gcc_assert (!DECL_RTL_SET_P (decl));
1919 /* Given appropriate target support, G++ will emit hidden aliases for native
1920 methods. Using this hidden name is required for proper operation of
1921 _Jv_Method::ncode, but it doesn't hurt to use it everywhere. Look for
1922 proper target support, then mark the method for aliasing. */
1924 static void
1925 java_mark_cni_decl_local (tree decl)
1927 #if !defined(HAVE_GAS_HIDDEN) || !defined(ASM_OUTPUT_DEF)
1928 return;
1929 #endif
1931 DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
1932 DECL_LOCAL_CNI_METHOD_P (decl) = 1;
1934 /* Setting DECL_LOCAL_CNI_METHOD_P changes the behavior of the
1935 mangler. We might have already referenced this native method and
1936 therefore created its name, but even if we have it won't hurt.
1937 We'll just go via its externally visible name, rather than its
1938 hidden alias. However, we must force things so that the correct
1939 mangling is done. */
1941 if (DECL_ASSEMBLER_NAME_SET_P (decl))
1942 java_mangle_decl (decl);
1943 if (DECL_RTL_SET_P (decl))
1945 SET_DECL_RTL (decl, 0);
1946 make_decl_rtl (decl);
1950 /* Use the preceding two functions and mark all members of the class. */
1952 void
1953 java_mark_class_local (tree klass)
1955 tree t;
1957 for (t = TYPE_FIELDS (klass); t ; t = DECL_CHAIN (t))
1958 if (FIELD_STATIC (t))
1959 java_mark_decl_local (t);
1961 for (t = TYPE_METHODS (klass); t ; t = DECL_CHAIN (t))
1962 if (!METHOD_ABSTRACT (t))
1964 if (METHOD_NATIVE (t) && !flag_jni)
1965 java_mark_cni_decl_local (t);
1966 else
1967 java_mark_decl_local (t);
1971 /* Add a statement to a compound_expr. */
1973 tree
1974 add_stmt_to_compound (tree existing, tree type, tree stmt)
1976 if (!stmt)
1977 return existing;
1978 else if (existing)
1980 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
1981 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
1982 | TREE_SIDE_EFFECTS (stmt);
1983 return expr;
1985 else
1986 return stmt;
1989 /* If this node is an expr, mark its input location. Called from
1990 walk_tree(). */
1992 static tree
1993 set_input_location (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
1994 void *data ATTRIBUTE_UNUSED)
1996 tree t = *tp;
1998 if (CAN_HAVE_LOCATION_P (t))
2000 if (EXPR_HAS_LOCATION(t))
2001 return t; /* Don't walk any further into this expr. */
2002 else
2003 SET_EXPR_LOCATION (t, input_location);
2006 return NULL_TREE; /* Continue walking this expr. */
2009 /* Add a statement to the statement_list currently being constructed.
2010 If the statement_list is null, we don't create a singleton list.
2011 This is necessary because poplevel() assumes that adding a
2012 statement to a null statement_list returns the statement. */
2014 tree
2015 java_add_stmt (tree new_stmt)
2017 tree stmts = current_binding_level->stmts;
2018 tree_stmt_iterator i;
2020 if (LOCATION_FILE (input_location))
2021 walk_tree (&new_stmt, set_input_location, NULL, NULL);
2023 if (stmts == NULL)
2024 return current_binding_level->stmts = new_stmt;
2026 /* Force STMTS to be a statement_list. */
2027 if (TREE_CODE (stmts) != STATEMENT_LIST)
2029 tree t = make_node (STATEMENT_LIST);
2030 i = tsi_last (t);
2031 tsi_link_after (&i, stmts, TSI_CONTINUE_LINKING);
2032 stmts = t;
2035 i = tsi_last (stmts);
2036 tsi_link_after (&i, new_stmt, TSI_CONTINUE_LINKING);
2037 TREE_TYPE (stmts) = void_type_node;
2039 return current_binding_level->stmts = stmts;
2042 /* Add a variable to the current scope. */
2044 tree
2045 java_add_local_var (tree decl)
2047 tree *vars = &current_binding_level->names;
2048 tree next = *vars;
2049 DECL_CHAIN (decl) = next;
2050 *vars = decl;
2051 DECL_CONTEXT (decl) = current_function_decl;
2052 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2053 return decl;
2056 /* Return a pointer to the compound_expr currently being
2057 constructed. */
2059 tree *
2060 get_stmts (void)
2062 return &current_binding_level->stmts;
2065 /* Register an exception range as belonging to the current binding
2066 level. There may only be one: if there are more, we'll create more
2067 binding levels. However, each range can have multiple handlers,
2068 and these are expanded when we call expand_end_java_handler(). */
2070 void
2071 register_exception_range (struct eh_range *range, int pc, int end_pc)
2073 gcc_assert (! current_binding_level->exception_range);
2074 current_binding_level->exception_range = range;
2075 current_binding_level->end_pc = end_pc;
2076 current_binding_level->start_pc = pc;
2079 #include "gt-java-decl.h"