2005-01-22 Thomas Koenig <Thomas.Koenig@online.de>
[official-gcc.git] / gcc / java / decl.c
blob5ec5d7846ae8ecf470e2051c70db09993b3cef9a
1 /* Process declarations and variables for the GNU compiler for the
2 Java(TM) language.
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Java and all Java-based marks are trademarks or registered trademarks
24 of Sun Microsystems, Inc. in the United States and other countries.
25 The Free Software Foundation is independent of Sun Microsystems, Inc. */
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
29 #include "config.h"
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include "tree.h"
34 #include "rtl.h"
35 #include "real.h"
36 #include "toplev.h"
37 #include "flags.h"
38 #include "java-tree.h"
39 #include "jcf.h"
40 #include "function.h"
41 #include "expr.h"
42 #include "libfuncs.h"
43 #include "except.h"
44 #include "java-except.h"
45 #include "ggc.h"
46 #include "timevar.h"
47 #include "cgraph.h"
48 #include "tree-inline.h"
49 #include "target.h"
51 #if defined (DEBUG_JAVA_BINDING_LEVELS)
52 extern void indent (void);
53 #endif
55 static tree push_jvm_slot (int, tree);
56 static tree lookup_name_current_level (tree);
57 static tree push_promoted_type (const char *, tree);
58 static struct binding_level *make_binding_level (void);
59 static tree create_primitive_vtable (const char *);
60 static tree check_local_unnamed_variable (tree, tree, tree);
62 /* Name of the Cloneable class. */
63 tree java_lang_cloneable_identifier_node;
65 /* Name of the Serializable class. */
66 tree java_io_serializable_identifier_node;
68 /* The DECL_MAP is a mapping from (index, type) to a decl node.
69 If index < max_locals, it is the index of a local variable.
70 if index >= max_locals, then index-max_locals is a stack slot.
71 The DECL_MAP mapping is represented as a TREE_VEC whose elements
72 are a list of decls (VAR_DECL or PARM_DECL) chained by
73 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
74 we search the chain for a decl with a matching TREE_TYPE. */
76 static GTY(()) tree decl_map;
78 /* The base_decl_map is contains one variable of ptr_type: this is
79 used to contain every variable of reference type that is ever
80 stored in a local variable slot. */
82 static GTY(()) tree base_decl_map;
84 /* An index used to make temporary identifiers unique. */
85 static int uniq;
87 /* A list of local variables VAR_DECLs for this method that we have seen
88 debug information, but we have not reached their starting (byte) PC yet. */
90 static GTY(()) tree pending_local_decls;
92 #if defined(DEBUG_JAVA_BINDING_LEVELS)
93 int binding_depth = 0;
94 int is_class_level = 0;
95 int current_pc;
97 void
98 indent (void)
100 int i;
102 for (i = 0; i < binding_depth*2; i++)
103 putc (' ', stderr);
105 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
107 /* True if decl is a named local variable, i.e. if it is an alias
108 that's used only for debugging purposes. */
110 static bool
111 debug_variable_p (tree decl)
113 if (TREE_CODE (decl) == PARM_DECL)
114 return false;
116 if (LOCAL_SLOT_P (decl))
117 return false;
119 return true;
122 /* Copy the value in decl into every live alias in the same local
123 variable slot. Some of these will be dead stores removed by the
124 optimizer. */
126 void
127 update_aliases (tree decl, int index, int pc)
129 tree decl_type = TREE_TYPE (decl);
130 tree tmp;
132 if (debug_variable_p (decl))
133 abort ();
135 for (tmp = TREE_VEC_ELT (decl_map, index);
136 tmp != NULL_TREE;
137 tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
139 tree tmp_type = TREE_TYPE (tmp);
140 if (tmp != decl
141 && LOCAL_SLOT_P (tmp) == 0
142 && (pc == -1
143 || (pc >= DECL_LOCAL_START_PC (tmp)
144 && pc <= DECL_LOCAL_END_PC (tmp)))
145 && (tmp_type == decl_type
146 || (INTEGRAL_TYPE_P (tmp_type)
147 && INTEGRAL_TYPE_P (decl_type)
148 && TYPE_PRECISION (decl_type) <= 32
149 && TYPE_PRECISION (tmp_type) <= 32)
150 || (TREE_CODE (tmp_type) == POINTER_TYPE
151 && TREE_CODE (decl_type) == POINTER_TYPE)))
153 tree src = build1 (NOP_EXPR, tmp_type, decl);
154 if (LOCAL_VAR_OUT_OF_SCOPE_P (tmp))
155 abort ();
156 java_add_stmt (build2 (MODIFY_EXPR, tmp_type, tmp, src));
161 static tree
162 push_jvm_slot (int index, tree decl)
164 DECL_CONTEXT (decl) = current_function_decl;
165 layout_decl (decl, 0);
167 /* Now link the decl into the decl_map. */
168 if (DECL_LANG_SPECIFIC (decl) == NULL)
170 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
171 DECL_LOCAL_START_PC (decl) = 0;
172 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
173 DECL_LOCAL_SLOT_NUMBER (decl) = index;
175 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
176 TREE_VEC_ELT (decl_map, index) = decl;
178 return decl;
181 /* At the point of its creation a local variable decl inherits
182 whatever is already in the same slot. In the case of a local
183 variable that is declared but unused, we won't find anything. */
185 static void
186 initialize_local_variable (tree decl, int index)
188 tree decl_type = TREE_TYPE (decl);
189 if (TREE_CODE (decl_type) == POINTER_TYPE)
191 tree tmp = TREE_VEC_ELT (base_decl_map, index);
193 if (tmp)
195 /* At the point of its creation this decl inherits whatever
196 is in the slot. */
197 tree src = build1 (NOP_EXPR, decl_type, tmp);
198 java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, src));
201 else
203 tree tmp;
205 for (tmp = TREE_VEC_ELT (decl_map, index);
206 tmp != NULL_TREE;
207 tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
209 tree tmp_type = TREE_TYPE (tmp);
210 if (tmp != decl
211 && ! debug_variable_p (tmp)
212 && (tmp_type == decl_type
213 || (INTEGRAL_TYPE_P (tmp_type)
214 && INTEGRAL_TYPE_P (decl_type)
215 && TYPE_PRECISION (decl_type) <= 32
216 && TYPE_PRECISION (tmp_type) <= 32
217 && TYPE_PRECISION (tmp_type)
218 >= TYPE_PRECISION (decl_type))))
220 java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, tmp));
221 return;
227 /* Find the best declaration based upon type. If 'decl' fits 'type' better
228 than 'best', return 'decl'. Otherwise return 'best'. */
230 static tree
231 check_local_unnamed_variable (tree best, tree decl, tree type)
233 tree decl_type = TREE_TYPE (decl);
235 if (LOCAL_VAR_OUT_OF_SCOPE_P (decl))
236 abort ();
238 /* Use the same decl for all integer types <= 32 bits. This is
239 necessary because sometimes a value is stored as (for example)
240 boolean but loaded as int. */
241 if (decl_type == type
242 || (INTEGRAL_TYPE_P (decl_type)
243 && INTEGRAL_TYPE_P (type)
244 && TYPE_PRECISION (decl_type) <= 32
245 && TYPE_PRECISION (type) <= 32
246 && TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
247 /* ptr_type_node is used for null pointers, which are
248 assignment compatible with everything. */
249 || (TREE_CODE (decl_type) == POINTER_TYPE
250 && type == ptr_type_node)
251 /* Whenever anyone wants to use a slot that is initially
252 occupied by a PARM_DECL of pointer type they must get that
253 decl, even if they asked for a pointer to a different type.
254 However, if someone wants a scalar variable in a slot that
255 initially held a pointer arg -- or vice versa -- we create a
256 new VAR_DECL.
258 ???: As long as verification is correct, this will be a
259 compatible type. But maybe we should create a dummy variable
260 and replace all references to it with the DECL and a
261 NOP_EXPR.
263 || (TREE_CODE (decl_type) == POINTER_TYPE
264 && TREE_CODE (decl) == PARM_DECL
265 && TREE_CODE (type) == POINTER_TYPE)
267 /* The new verifier requires a similar treatment in the
268 situation where the parameter has an integral type which
269 promotes to `int'. */
270 || (flag_new_verifier
271 && TREE_CODE (decl) == PARM_DECL
272 && INTEGRAL_TYPE_P (decl_type)
273 && TYPE_PRECISION (decl_type) <= 32
274 && INTEGRAL_TYPE_P (type)
275 && TYPE_PRECISION (type) <= 32))
277 if (best == NULL_TREE
278 || (decl_type == type && TREE_TYPE (best) != type))
279 return decl;
282 return best;
286 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
287 that is valid at PC (or -1 if any pc).
288 If there is no existing matching decl, allocate one. */
290 tree
291 find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
293 tree tmp = TREE_VEC_ELT (decl_map, index);
294 tree decl = NULL_TREE;
296 /* Scan through every declaration that has been created in this
297 slot. We're only looking for variables that correspond to local
298 index declarations and PARM_DECLs, not named variables: such
299 local variables are used only for debugging information. */
300 while (tmp != NULL_TREE)
302 if (! debug_variable_p (tmp))
303 decl = check_local_unnamed_variable (decl, tmp, type);
304 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
307 /* If we don't find a match, create one with the type passed in.
308 The name of the variable is #n#m, which n is the variable index
309 in the local variable area and m is a dummy identifier for
310 uniqueness -- multiple variables may share the same local
311 variable index. We don't call pushdecl() to push pointer types
312 into a binding expr because they'll all be replaced by a single
313 variable that is used for every reference in that local variable
314 slot. */
315 if (! decl)
317 char buf[64];
318 tree name;
319 sprintf (buf, "#slot#%d#%d", index, uniq++);
320 name = get_identifier (buf);
321 decl = build_decl (VAR_DECL, name, type);
322 DECL_IGNORED_P (decl) = 1;
323 DECL_ARTIFICIAL (decl) = 1;
324 decl = push_jvm_slot (index, decl);
325 LOCAL_SLOT_P (decl) = 1;
327 if (TREE_CODE (type) != POINTER_TYPE)
328 pushdecl_function_level (decl);
331 /* As well as creating a local variable that matches the type, we
332 also create a base variable (of ptr_type) that will hold all its
333 aliases. */
334 if (TREE_CODE (type) == POINTER_TYPE
335 && ! TREE_VEC_ELT (base_decl_map, index))
337 char buf[64];
338 tree name;
339 tree base_decl;
340 sprintf (buf, "#ref#%d#%d", index, uniq++);
341 name = get_identifier (buf);
342 base_decl
343 = TREE_VEC_ELT (base_decl_map, index)
344 = build_decl (VAR_DECL, name, ptr_type_node);
345 pushdecl_function_level (base_decl);
346 DECL_IGNORED_P (base_decl) = 1;
347 DECL_ARTIFICIAL (base_decl) = 1;
350 return decl;
353 /* Called during gimplification for every variable. If the variable
354 is a temporary of pointer type, replace it with a common variable
355 thath is used to hold all pointer types that are ever stored in
356 that slot. Set WANT_LVALUE if you want a variable that is to be
357 written to. */
359 tree
360 java_replace_reference (tree var_decl, bool want_lvalue)
362 tree decl_type;
364 if (! base_decl_map)
365 return var_decl;
367 decl_type = TREE_TYPE (var_decl);
369 if (TREE_CODE (decl_type) == POINTER_TYPE)
371 if (DECL_LANG_SPECIFIC (var_decl)
372 && LOCAL_SLOT_P (var_decl))
374 int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
375 tree base_decl = TREE_VEC_ELT (base_decl_map, index);
377 if (! base_decl)
378 abort ();
380 if (! want_lvalue)
381 base_decl = build1 (NOP_EXPR, decl_type, base_decl);
383 return base_decl;
387 return var_decl;
391 /* Same as find_local_index, except that INDEX is a stack index. */
393 tree
394 find_stack_slot (int index, tree type)
396 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
397 type, -1);
400 struct binding_level GTY(())
402 /* A chain of _DECL nodes for all variables, constants, functions,
403 * and typedef types. These are in the reverse of the order supplied.
405 tree names;
407 /* For each level, a list of shadowed outer-level local definitions
408 to be restored when this level is popped.
409 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
410 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
411 tree shadowed;
413 /* For each level (except not the global one),
414 a chain of BLOCK nodes for all the levels
415 that were entered and exited one level down. */
416 tree blocks;
418 /* The binding level which this one is contained in (inherits from). */
419 struct binding_level *level_chain;
421 /* The bytecode PC that marks the end of this level. */
422 int end_pc;
423 /* The bytecode PC that marks the start of this level. */
424 int start_pc;
426 /* The statements in this binding level. */
427 tree stmts;
429 /* An exception range associated with this binding level. */
430 struct eh_range * GTY((skip (""))) exception_range;
432 /* Binding depth at which this level began. Used only for debugging. */
433 unsigned binding_depth;
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 */
476 #if 0
477 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
478 that have names. Here so we can clear out their names' definitions
479 at the end of the function. */
481 static tree named_labels;
483 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
485 static tree shadowed_labels;
486 #endif
488 tree java_global_trees[JTI_MAX];
490 /* Build (and pushdecl) a "promoted type" for all standard
491 types shorter than int. */
493 static tree
494 push_promoted_type (const char *name, tree actual_type)
496 tree type = make_node (TREE_CODE (actual_type));
497 #if 1
498 tree in_min = TYPE_MIN_VALUE (int_type_node);
499 tree in_max = TYPE_MAX_VALUE (int_type_node);
500 #else
501 tree in_min = TYPE_MIN_VALUE (actual_type);
502 tree in_max = TYPE_MAX_VALUE (actual_type);
503 #endif
504 TYPE_MIN_VALUE (type) = copy_node (in_min);
505 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
506 TYPE_MAX_VALUE (type) = copy_node (in_max);
507 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
508 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
509 layout_type (type);
510 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
511 return type;
514 /* Return a definition for a builtin function named NAME and whose data type
515 is TYPE. TYPE should be a function type with argument types.
516 FUNCTION_CODE tells later passes how to compile calls to this function.
517 See tree.h for its possible values.
519 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
520 the name to be called if we can't opencode the function. If
521 ATTRS is nonzero, use that for the function's attribute list. */
523 tree
524 builtin_function (const char *name,
525 tree type,
526 int function_code,
527 enum built_in_class cl,
528 const char *library_name,
529 tree ARG_UNUSED (attrs))
531 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
532 DECL_EXTERNAL (decl) = 1;
533 TREE_PUBLIC (decl) = 1;
534 if (library_name)
535 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
536 make_decl_rtl (decl);
537 pushdecl (decl);
538 DECL_BUILT_IN_CLASS (decl) = cl;
539 DECL_FUNCTION_CODE (decl) = function_code;
540 return decl;
543 /* Return tree that represents a vtable for a primitive array. */
544 static tree
545 create_primitive_vtable (const char *name)
547 tree r;
548 char buf[50];
550 sprintf (buf, "_Jv_%sVTable", name);
551 r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
552 DECL_EXTERNAL (r) = 1;
553 return r;
556 static tree
557 do_nothing (tree t)
559 return t;
563 void
564 java_init_decl_processing (void)
566 tree endlink;
567 tree field = NULL_TREE;
568 tree t;
570 init_class_processing ();
572 current_function_decl = NULL;
573 current_binding_level = NULL_BINDING_LEVEL;
574 free_binding_level = NULL_BINDING_LEVEL;
575 pushlevel (0); /* make the binding_level structure for global names */
576 global_binding_level = current_binding_level;
578 /* The code here must be similar to build_common_tree_nodes{,_2} in
579 tree.c, especially as to the order of initializing common nodes. */
580 error_mark_node = make_node (ERROR_MARK);
581 TREE_TYPE (error_mark_node) = error_mark_node;
583 /* Create sizetype first - needed for other types. */
584 initialize_sizetypes (false);
586 byte_type_node = make_signed_type (8);
587 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
588 short_type_node = make_signed_type (16);
589 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
590 int_type_node = make_signed_type (32);
591 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
592 long_type_node = make_signed_type (64);
593 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
595 unsigned_byte_type_node = make_unsigned_type (8);
596 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
597 unsigned_byte_type_node));
598 unsigned_short_type_node = make_unsigned_type (16);
599 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
600 unsigned_short_type_node));
601 unsigned_int_type_node = make_unsigned_type (32);
602 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
603 unsigned_int_type_node));
604 unsigned_long_type_node = make_unsigned_type (64);
605 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
606 unsigned_long_type_node));
608 /* This is not a java type, however tree-dfa requires a definition for
609 size_type_node. */
610 size_type_node = make_unsigned_type (POINTER_SIZE);
611 set_sizetype (size_type_node);
613 /* Define these next since types below may used them. */
614 integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
615 integer_zero_node = build_int_cst (NULL_TREE, 0);
616 integer_one_node = build_int_cst (NULL_TREE, 1);
617 integer_two_node = build_int_cst (NULL_TREE, 2);
618 integer_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 #if HOST_BITS_PER_WIDE_INT == 64
624 decimal_long_max = build_int_cstu (unsigned_long_type_node,
625 0x8000000000000000LL);
626 #elif HOST_BITS_PER_WIDE_INT == 32
627 decimal_long_max = build_int_cst_wide (unsigned_long_type_node,
628 0, 0x80000000);
629 #else
630 #error "unsupported size"
631 #endif
633 size_zero_node = size_int (0);
634 size_one_node = size_int (1);
635 bitsize_zero_node = bitsize_int (0);
636 bitsize_one_node = bitsize_int (1);
637 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
639 long_zero_node = build_int_cst (long_type_node, 0);
641 void_type_node = make_node (VOID_TYPE);
642 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
643 layout_type (void_type_node); /* Uses size_zero_node */
644 ptr_type_node = build_pointer_type (void_type_node);
645 t = make_node (VOID_TYPE);
646 layout_type (t); /* Uses size_zero_node */
647 return_address_type_node = build_pointer_type (t);
649 null_pointer_node = build_int_cst (ptr_type_node, 0);
651 #if 0
652 /* Make a type to be the domain of a few array types
653 whose domains don't really matter.
654 200 is small enough that it always fits in size_t
655 and large enough that it can hold most function names for the
656 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
657 short_array_type_node = build_prim_array_type (short_type_node, 200);
658 #endif
659 char_type_node = make_node (CHAR_TYPE);
660 TYPE_PRECISION (char_type_node) = 16;
661 fixup_unsigned_type (char_type_node);
662 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
664 boolean_type_node = make_node (BOOLEAN_TYPE);
665 TYPE_PRECISION (boolean_type_node) = 1;
666 fixup_unsigned_type (boolean_type_node);
667 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
668 boolean_type_node));
669 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
670 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
672 promoted_byte_type_node
673 = push_promoted_type ("promoted_byte", byte_type_node);
674 promoted_short_type_node
675 = push_promoted_type ("promoted_short", short_type_node);
676 promoted_char_type_node
677 = push_promoted_type ("promoted_char", char_type_node);
678 promoted_boolean_type_node
679 = push_promoted_type ("promoted_boolean", boolean_type_node);
681 float_type_node = make_node (REAL_TYPE);
682 TYPE_PRECISION (float_type_node) = 32;
683 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
684 float_type_node));
685 layout_type (float_type_node);
687 double_type_node = make_node (REAL_TYPE);
688 TYPE_PRECISION (double_type_node) = 64;
689 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
690 double_type_node));
691 layout_type (double_type_node);
693 float_zero_node = build_real (float_type_node, dconst0);
694 double_zero_node = build_real (double_type_node, dconst0);
696 /* These are the vtables for arrays of primitives. */
697 boolean_array_vtable = create_primitive_vtable ("boolean");
698 byte_array_vtable = create_primitive_vtable ("byte");
699 char_array_vtable = create_primitive_vtable ("char");
700 short_array_vtable = create_primitive_vtable ("short");
701 int_array_vtable = create_primitive_vtable ("int");
702 long_array_vtable = create_primitive_vtable ("long");
703 float_array_vtable = create_primitive_vtable ("float");
704 double_array_vtable = create_primitive_vtable ("double");
706 one_elt_array_domain_type = build_index_type (integer_one_node);
707 utf8const_type = make_node (RECORD_TYPE);
708 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
709 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
710 FINISH_RECORD (utf8const_type);
711 utf8const_ptr_type = build_pointer_type (utf8const_type);
713 atable_type = build_array_type (ptr_type_node,
714 one_elt_array_domain_type);
715 TYPE_NONALIASED_COMPONENT (atable_type) = 1;
716 atable_ptr_type = build_pointer_type (atable_type);
718 itable_type = build_array_type (ptr_type_node,
719 one_elt_array_domain_type);
720 TYPE_NONALIASED_COMPONENT (itable_type) = 1;
721 itable_ptr_type = build_pointer_type (itable_type);
723 symbol_type = make_node (RECORD_TYPE);
724 PUSH_FIELD (symbol_type, field, "clname", utf8const_ptr_type);
725 PUSH_FIELD (symbol_type, field, "name", utf8const_ptr_type);
726 PUSH_FIELD (symbol_type, field, "signature", utf8const_ptr_type);
727 FINISH_RECORD (symbol_type);
729 symbols_array_type = build_array_type (symbol_type,
730 one_elt_array_domain_type);
731 symbols_array_ptr_type = build_pointer_type (symbols_array_type);
733 assertion_entry_type = make_node (RECORD_TYPE);
734 PUSH_FIELD (assertion_entry_type, field, "assertion_code", integer_type_node);
735 PUSH_FIELD (assertion_entry_type, field, "op1", utf8const_ptr_type);
736 PUSH_FIELD (assertion_entry_type, field, "op2", utf8const_ptr_type);
737 FINISH_RECORD (assertion_entry_type);
739 assertion_table_type = build_array_type (assertion_entry_type,
740 one_elt_array_domain_type);
742 /* As you're adding items here, please update the code right after
743 this section, so that the filename containing the source code of
744 the pre-defined class gets registered correctly. */
745 unqualified_object_id_node = get_identifier ("Object");
746 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
747 object_ptr_type_node = promote_type (object_type_node);
748 string_type_node = lookup_class (get_identifier ("java.lang.String"));
749 string_ptr_type_node = promote_type (string_type_node);
750 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
751 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
752 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
753 runtime_exception_type_node =
754 lookup_class (get_identifier ("java.lang.RuntimeException"));
755 error_exception_type_node =
756 lookup_class (get_identifier ("java.lang.Error"));
758 rawdata_ptr_type_node
759 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
761 add_predefined_file (get_identifier ("java/lang/Class.java"));
762 add_predefined_file (get_identifier ("java/lang/Error.java"));
763 add_predefined_file (get_identifier ("java/lang/Object.java"));
764 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
765 add_predefined_file (get_identifier ("java/lang/String.java"));
766 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
767 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
768 add_predefined_file (get_identifier ("java/lang/Exception.java"));
769 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
770 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
772 methodtable_type = make_node (RECORD_TYPE);
773 layout_type (methodtable_type);
774 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
775 methodtable_ptr_type = build_pointer_type (methodtable_type);
777 TYPE_identifier_node = get_identifier ("TYPE");
778 init_identifier_node = get_identifier ("<init>");
779 clinit_identifier_node = get_identifier ("<clinit>");
780 finit_identifier_node = get_identifier ("finit$");
781 instinit_identifier_node = get_identifier ("instinit$");
782 void_signature_node = get_identifier ("()V");
783 length_identifier_node = get_identifier ("length");
784 finalize_identifier_node = get_identifier ("finalize");
785 this_identifier_node = get_identifier ("this");
786 super_identifier_node = get_identifier ("super");
787 continue_identifier_node = get_identifier ("continue");
788 access0_identifier_node = get_identifier ("access$0");
789 classdollar_identifier_node = get_identifier ("class$");
791 java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
792 java_io_serializable_identifier_node =
793 get_identifier ("java.io.Serializable");
795 /* for lack of a better place to put this stub call */
796 init_expr_processing();
798 constants_type_node = make_node (RECORD_TYPE);
799 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
800 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
801 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
802 FINISH_RECORD (constants_type_node);
803 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
805 access_flags_type_node = unsigned_short_type_node;
807 dtable_type = make_node (RECORD_TYPE);
808 dtable_ptr_type = build_pointer_type (dtable_type);
810 otable_type = build_array_type (integer_type_node,
811 one_elt_array_domain_type);
812 TYPE_NONALIASED_COMPONENT (otable_type) = 1;
813 otable_ptr_type = build_pointer_type (otable_type);
815 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
816 DECL_FCONTEXT (field) = object_type_node;
817 TYPE_VFIELD (object_type_node) = field;
819 /* This isn't exactly true, but it is what we have in the source.
820 There is an unresolved issue here, which is whether the vtable
821 should be marked by the GC. */
822 if (! flag_hash_synchronization)
823 PUSH_FIELD (object_type_node, field, "sync_info",
824 build_pointer_type (object_type_node));
825 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
826 FIELD_PRIVATE (t) = 1;
827 FINISH_RECORD (object_type_node);
829 field_type_node = make_node (RECORD_TYPE);
830 field_ptr_type_node = build_pointer_type (field_type_node);
831 method_type_node = make_node (RECORD_TYPE);
832 method_ptr_type_node = build_pointer_type (method_type_node);
834 set_super_info (0, class_type_node, object_type_node, 0);
835 set_super_info (0, string_type_node, object_type_node, 0);
836 class_ptr_type = build_pointer_type (class_type_node);
838 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
839 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
840 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
841 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
842 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
843 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
844 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
845 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
846 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
847 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
848 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
849 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
850 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
851 PUSH_FIELD (class_type_node, field, "otable", otable_ptr_type);
852 PUSH_FIELD (class_type_node, field, "otable_syms",
853 symbols_array_ptr_type);
854 PUSH_FIELD (class_type_node, field, "atable", atable_ptr_type);
855 PUSH_FIELD (class_type_node, field, "atable_syms",
856 symbols_array_ptr_type);
857 PUSH_FIELD (class_type_node, field, "itable", itable_ptr_type);
858 PUSH_FIELD (class_type_node, field, "itable_syms",
859 symbols_array_ptr_type);
860 PUSH_FIELD (class_type_node, field, "catch_classes", ptr_type_node);
861 PUSH_FIELD (class_type_node, field, "interfaces",
862 build_pointer_type (class_ptr_type));
863 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
864 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
865 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
866 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
867 PUSH_FIELD (class_type_node, field, "depth", short_type_node);
868 PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
869 PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
870 PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);
871 PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
872 PUSH_FIELD (class_type_node, field, "assertion_table", ptr_type_node);
873 PUSH_FIELD (class_type_node, field, "hack_signers", ptr_type_node);
874 PUSH_FIELD (class_type_node, field, "chain", ptr_type_node);
875 PUSH_FIELD (class_type_node, field, "aux_info", ptr_type_node);
876 PUSH_FIELD (class_type_node, field, "engine", ptr_type_node);
877 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
878 FIELD_PRIVATE (t) = 1;
879 push_super_field (class_type_node, object_type_node);
881 FINISH_RECORD (class_type_node);
882 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
884 field_info_union_node = make_node (UNION_TYPE);
885 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
886 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
887 #if 0
888 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
889 #endif
890 layout_type (field_info_union_node);
892 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
893 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
894 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
895 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
896 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
897 FINISH_RECORD (field_type_node);
898 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
900 nativecode_ptr_array_type_node
901 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
903 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
904 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
905 FINISH_RECORD (dtable_type);
906 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
908 jexception_type = make_node (RECORD_TYPE);
909 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
910 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
911 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
912 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
913 FINISH_RECORD (jexception_type);
914 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
915 jexception_ptr_type = build_pointer_type (jexception_type);
917 lineNumberEntry_type = make_node (RECORD_TYPE);
918 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
919 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
920 FINISH_RECORD (lineNumberEntry_type);
922 lineNumbers_type = make_node (RECORD_TYPE);
923 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
924 FINISH_RECORD (lineNumbers_type);
926 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
927 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
928 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
929 PUSH_FIELD (method_type_node, field, "index", unsigned_short_type_node);
930 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
931 PUSH_FIELD (method_type_node, field, "throws", ptr_type_node);
932 FINISH_RECORD (method_type_node);
933 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
935 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
937 t = tree_cons (NULL_TREE, class_ptr_type,
938 tree_cons (NULL_TREE, int_type_node, endlink));
939 alloc_object_node = builtin_function ("_Jv_AllocObject",
940 build_function_type (ptr_type_node, t),
941 0, NOT_BUILT_IN, NULL, NULL_TREE);
942 DECL_IS_MALLOC (alloc_object_node) = 1;
943 alloc_no_finalizer_node =
944 builtin_function ("_Jv_AllocObjectNoFinalizer",
945 build_function_type (ptr_type_node, t),
946 0, NOT_BUILT_IN, NULL, NULL_TREE);
947 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
949 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
950 soft_initclass_node = builtin_function ("_Jv_InitClass",
951 build_function_type (void_type_node,
953 0, NOT_BUILT_IN, NULL, NULL_TREE);
955 throw_node = builtin_function ("_Jv_Throw",
956 build_function_type (ptr_type_node, t),
957 0, NOT_BUILT_IN, NULL, NULL_TREE);
958 /* Mark throw_nodes as `noreturn' functions with side effects. */
959 TREE_THIS_VOLATILE (throw_node) = 1;
960 TREE_SIDE_EFFECTS (throw_node) = 1;
962 t = build_function_type (int_type_node, endlink);
963 soft_monitorenter_node
964 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
965 NULL, NULL_TREE);
966 soft_monitorexit_node
967 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
968 NULL, NULL_TREE);
970 t = tree_cons (NULL_TREE, int_type_node,
971 tree_cons (NULL_TREE, int_type_node, endlink));
972 soft_newarray_node
973 = builtin_function ("_Jv_NewPrimArray",
974 build_function_type(ptr_type_node, t),
975 0, NOT_BUILT_IN, NULL, NULL_TREE);
976 DECL_IS_MALLOC (soft_newarray_node) = 1;
978 t = tree_cons (NULL_TREE, int_type_node,
979 tree_cons (NULL_TREE, class_ptr_type,
980 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
981 soft_anewarray_node
982 = builtin_function ("_Jv_NewObjectArray",
983 build_function_type (ptr_type_node, t),
984 0, NOT_BUILT_IN, NULL, NULL_TREE);
985 DECL_IS_MALLOC (soft_anewarray_node) = 1;
987 /* There is no endlink here because _Jv_NewMultiArray is a varargs
988 function. */
989 t = tree_cons (NULL_TREE, ptr_type_node,
990 tree_cons (NULL_TREE, int_type_node, NULL_TREE));
991 soft_multianewarray_node
992 = builtin_function ("_Jv_NewMultiArray",
993 build_function_type (ptr_type_node, t),
994 0, NOT_BUILT_IN, NULL, NULL_TREE);
995 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
997 t = build_function_type (void_type_node,
998 tree_cons (NULL_TREE, int_type_node, endlink));
999 soft_badarrayindex_node
1000 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
1001 0, NOT_BUILT_IN, NULL, NULL_TREE);
1002 /* Mark soft_badarrayindex_node as a `noreturn' function with side
1003 effects. */
1004 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
1005 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
1007 soft_nullpointer_node
1008 = builtin_function ("_Jv_ThrowNullPointerException",
1009 build_function_type (void_type_node, endlink),
1010 0, NOT_BUILT_IN, NULL, NULL_TREE);
1011 /* Mark soft_nullpointer_node as a `noreturn' function with side
1012 effects. */
1013 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
1014 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
1016 t = tree_cons (NULL_TREE, class_ptr_type,
1017 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1018 soft_checkcast_node
1019 = builtin_function ("_Jv_CheckCast",
1020 build_function_type (ptr_type_node, t),
1021 0, NOT_BUILT_IN, NULL, NULL_TREE);
1022 t = tree_cons (NULL_TREE, object_ptr_type_node,
1023 tree_cons (NULL_TREE, class_ptr_type, endlink));
1024 soft_instanceof_node
1025 = builtin_function ("_Jv_IsInstanceOf",
1026 build_function_type (boolean_type_node, t),
1027 0, NOT_BUILT_IN, NULL, NULL_TREE);
1028 DECL_IS_PURE (soft_instanceof_node) = 1;
1029 t = tree_cons (NULL_TREE, object_ptr_type_node,
1030 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
1031 soft_checkarraystore_node
1032 = builtin_function ("_Jv_CheckArrayStore",
1033 build_function_type (void_type_node, t),
1034 0, NOT_BUILT_IN, NULL, NULL_TREE);
1035 t = tree_cons (NULL_TREE, ptr_type_node,
1036 tree_cons (NULL_TREE, ptr_type_node,
1037 tree_cons (NULL_TREE, int_type_node, endlink)));
1038 soft_lookupinterfacemethod_node
1039 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
1040 build_function_type (ptr_type_node, t),
1041 0, NOT_BUILT_IN, NULL, NULL_TREE);
1042 DECL_IS_PURE (soft_lookupinterfacemethod_node) = 1;
1043 t = tree_cons (NULL_TREE, ptr_type_node,
1044 tree_cons (NULL_TREE, ptr_type_node,
1045 tree_cons (NULL_TREE, ptr_type_node, endlink)));
1046 soft_lookupinterfacemethodbyname_node
1047 = builtin_function ("_Jv_LookupInterfaceMethod",
1048 build_function_type (ptr_type_node, t),
1049 0, NOT_BUILT_IN, NULL, NULL_TREE);
1050 t = tree_cons (NULL_TREE, object_ptr_type_node,
1051 tree_cons (NULL_TREE, ptr_type_node,
1052 tree_cons (NULL_TREE, ptr_type_node,
1053 tree_cons (NULL_TREE, int_type_node,
1054 endlink))));
1055 soft_lookupjnimethod_node
1056 = builtin_function ("_Jv_LookupJNIMethod",
1057 build_function_type (ptr_type_node, t),
1058 0, NOT_BUILT_IN, NULL, NULL_TREE);
1059 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
1060 soft_getjnienvnewframe_node
1061 = builtin_function ("_Jv_GetJNIEnvNewFrame",
1062 build_function_type (ptr_type_node, t),
1063 0, NOT_BUILT_IN, NULL, NULL_TREE);
1064 soft_jnipopsystemframe_node
1065 = builtin_function ("_Jv_JNI_PopSystemFrame",
1066 build_function_type (ptr_type_node, t),
1067 0, NOT_BUILT_IN, NULL, NULL_TREE);
1069 soft_idiv_node
1070 = builtin_function ("_Jv_divI",
1071 build_function_type (int_type_node, t),
1072 0, NOT_BUILT_IN, NULL, NULL_TREE);
1074 soft_irem_node
1075 = builtin_function ("_Jv_remI",
1076 build_function_type (int_type_node, t),
1077 0, NOT_BUILT_IN, NULL, NULL_TREE);
1079 soft_ldiv_node
1080 = builtin_function ("_Jv_divJ",
1081 build_function_type (long_type_node, t),
1082 0, NOT_BUILT_IN, NULL, NULL_TREE);
1084 soft_lrem_node
1085 = builtin_function ("_Jv_remJ",
1086 build_function_type (long_type_node, t),
1087 0, NOT_BUILT_IN, NULL, NULL_TREE);
1089 /* Initialize variables for except.c. */
1090 eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
1091 ? "__gcj_personality_sj0"
1092 : "__gcj_personality_v0");
1094 lang_eh_runtime_type = do_nothing;
1096 init_jcf_parse ();
1098 initialize_builtins ();
1099 soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
1100 #if 0
1101 soft_fmodf_node = built_in_decls[BUILT_IN_FMODF];
1102 #endif
1106 /* Look up NAME in the current binding level and its superiors
1107 in the namespace of variables, functions and typedefs.
1108 Return a ..._DECL node of some kind representing its definition,
1109 or return 0 if it is undefined. */
1111 tree
1112 lookup_name (tree name)
1114 tree val;
1115 if (current_binding_level != global_binding_level
1116 && IDENTIFIER_LOCAL_VALUE (name))
1117 val = IDENTIFIER_LOCAL_VALUE (name);
1118 else
1119 val = IDENTIFIER_GLOBAL_VALUE (name);
1120 return val;
1123 /* Similar to `lookup_name' but look only at current binding level and
1124 the previous one if its the parameter level. */
1126 static tree
1127 lookup_name_current_level (tree name)
1129 tree t;
1131 if (current_binding_level == global_binding_level)
1132 return IDENTIFIER_GLOBAL_VALUE (name);
1134 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
1135 return 0;
1137 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
1138 if (DECL_NAME (t) == name)
1139 break;
1141 return t;
1144 /* Use a binding level to record a labeled block declaration */
1146 void
1147 push_labeled_block (tree lb)
1149 tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
1150 struct binding_level *b = current_binding_level;
1151 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1152 if (oldlocal != 0)
1153 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1154 TREE_CHAIN (lb) = b->names;
1155 b->names = lb;
1156 IDENTIFIER_LOCAL_VALUE (name) = lb;
1159 /* Pop the current binding level, reinstalling values for the previous
1160 labeled block */
1162 void
1163 pop_labeled_block (void)
1165 struct binding_level *b = current_binding_level;
1166 tree label = b->names;
1167 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
1168 NULL_TREE;
1169 if (b->shadowed)
1170 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
1171 TREE_VALUE (b->shadowed);
1173 /* Pop the current level, and free the structure for reuse. */
1174 current_binding_level = current_binding_level->level_chain;
1175 b->level_chain = free_binding_level;
1176 free_binding_level = b;
1179 /* Record a decl-node X as belonging to the current lexical scope.
1180 Check for errors (such as an incompatible declaration for the same
1181 name already seen in the same scope).
1183 Returns either X or an old decl for the same name.
1184 If an old decl is returned, it may have been smashed
1185 to agree with what X says. */
1187 tree
1188 pushdecl (tree x)
1190 tree t;
1191 tree name = DECL_NAME (x);
1192 struct binding_level *b = current_binding_level;
1194 if (TREE_CODE (x) != TYPE_DECL)
1195 DECL_CONTEXT (x) = current_function_decl;
1196 if (name)
1198 t = lookup_name_current_level (name);
1199 if (t != 0 && t == error_mark_node)
1200 /* error_mark_node is 0 for a while during initialization! */
1202 t = 0;
1203 error ("%J'%D' used prior to declaration", x, x);
1206 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1207 to point to the TYPE_DECL.
1208 Since Java does not have typedefs, a type can only have
1209 one (true) name, given by a class, interface, or builtin. */
1210 if (TREE_CODE (x) == TYPE_DECL
1211 && TYPE_NAME (TREE_TYPE (x)) == 0
1212 && TREE_TYPE (x) != error_mark_node)
1214 TYPE_NAME (TREE_TYPE (x)) = x;
1215 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
1218 /* This name is new in its binding level.
1219 Install the new declaration and return it. */
1220 if (b == global_binding_level)
1222 /* Install a global value. */
1224 IDENTIFIER_GLOBAL_VALUE (name) = x;
1226 else
1228 /* Here to install a non-global value. */
1229 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1230 IDENTIFIER_LOCAL_VALUE (name) = x;
1232 #if 0
1233 /* Warn if shadowing an argument at the top level of the body. */
1234 if (oldlocal != 0 && !DECL_EXTERNAL (x)
1235 /* This warning doesn't apply to the parms of a nested fcn. */
1236 && ! current_binding_level->parm_flag
1237 /* Check that this is one level down from the parms. */
1238 && current_binding_level->level_chain->parm_flag
1239 /* Check that the decl being shadowed
1240 comes from the parm level, one level up. */
1241 && chain_member (oldlocal, current_binding_level->level_chain->names))
1243 if (TREE_CODE (oldlocal) == PARM_DECL)
1244 pedwarn ("declaration of %qs shadows a parameter",
1245 IDENTIFIER_POINTER (name));
1246 else
1247 pedwarn ("declaration of %qs shadows a symbol from the parameter list",
1248 IDENTIFIER_POINTER (name));
1251 /* Maybe warn if shadowing something else. */
1252 else if (warn_shadow && !DECL_EXTERNAL (x)
1253 /* No shadow warnings for internally generated vars. */
1254 && DECL_SOURCE_LINE (x) != 0
1255 /* No shadow warnings for vars made for inlining. */
1256 && ! DECL_FROM_INLINE (x))
1258 const char *warnstring = 0;
1260 if (TREE_CODE (x) == PARM_DECL
1261 && current_binding_level->level_chain->parm_flag)
1262 /* Don't warn about the parm names in function declarator
1263 within a function declarator.
1264 It would be nice to avoid warning in any function
1265 declarator in a declaration, as opposed to a definition,
1266 but there is no way to tell it's not a definition. */
1268 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1269 warnstring = "declaration of %qs shadows a parameter";
1270 else if (oldlocal != 0)
1271 warnstring = "declaration of %qs shadows previous local";
1272 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1273 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1274 warnstring = "declaration of %qs shadows global declaration";
1276 if (warnstring)
1277 warning (warnstring, IDENTIFIER_POINTER (name));
1279 #endif
1281 /* If storing a local value, there may already be one (inherited).
1282 If so, record it for restoration when this binding level ends. */
1283 if (oldlocal != 0)
1284 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1288 /* Put decls on list in reverse order.
1289 We will reverse them later if necessary. */
1290 TREE_CHAIN (x) = b->names;
1291 b->names = x;
1293 return x;
1296 void
1297 pushdecl_force_head (tree x)
1299 current_binding_level->names = x;
1302 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1304 tree
1305 pushdecl_top_level (tree x)
1307 tree t;
1308 struct binding_level *b = current_binding_level;
1310 current_binding_level = global_binding_level;
1311 t = pushdecl (x);
1312 current_binding_level = b;
1313 return t;
1316 /* Like pushdecl, only it places X in FUNCTION_BINDING_LEVEL, if appropriate. */
1318 tree
1319 pushdecl_function_level (tree x)
1321 tree t;
1322 struct binding_level *b = current_binding_level;
1324 current_binding_level = function_binding_level;
1325 t = pushdecl (x);
1326 current_binding_level = b;
1327 return t;
1330 /* Nonzero if we are currently in the global binding level. */
1333 global_bindings_p (void)
1335 return current_binding_level == global_binding_level;
1338 /* Return the list of declarations of the current level.
1339 Note that this list is in reverse order unless/until
1340 you nreverse it; and when you do nreverse it, you must
1341 store the result back using `storedecls' or you will lose. */
1343 tree
1344 getdecls (void)
1346 return current_binding_level->names;
1349 /* Create a new `struct binding_level'. */
1351 static struct binding_level *
1352 make_binding_level (void)
1354 /* NOSTRICT */
1355 return ggc_alloc_cleared (sizeof (struct binding_level));
1358 void
1359 pushlevel (int unused ATTRIBUTE_UNUSED)
1361 struct binding_level *newlevel = NULL_BINDING_LEVEL;
1363 #if 0
1364 /* If this is the top level of a function,
1365 just make sure that NAMED_LABELS is 0. */
1367 if (current_binding_level == global_binding_level)
1368 named_labels = 0;
1369 #endif
1371 /* Reuse or create a struct for this binding level. */
1373 if (free_binding_level)
1375 newlevel = free_binding_level;
1376 free_binding_level = free_binding_level->level_chain;
1378 else
1380 newlevel = make_binding_level ();
1383 /* Add this level to the front of the chain (stack) of levels that
1384 are active. */
1386 *newlevel = clear_binding_level;
1387 newlevel->level_chain = current_binding_level;
1388 current_binding_level = newlevel;
1389 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1390 newlevel->binding_depth = binding_depth;
1391 indent ();
1392 fprintf (stderr, "push %s level %p pc %d\n",
1393 (is_class_level) ? "class" : "block", newlevel, current_pc);
1394 is_class_level = 0;
1395 binding_depth++;
1396 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1399 /* Exit a binding level.
1400 Pop the level off, and restore the state of the identifier-decl mappings
1401 that were in effect when this level was entered.
1403 If KEEP is nonzero, this level had explicit declarations, so
1404 and create a "block" (a BLOCK node) for the level
1405 to record its declarations and subblocks for symbol table output.
1407 If FUNCTIONBODY is nonzero, this level is the body of a function,
1408 so create a block as if KEEP were set and also clear out all
1409 label names.
1411 If REVERSE is nonzero, reverse the order of decls before putting
1412 them into the BLOCK. */
1414 tree
1415 poplevel (int keep, int reverse, int functionbody)
1417 tree link;
1418 /* The chain of decls was accumulated in reverse order.
1419 Put it into forward order, just for cleanliness. */
1420 tree decls;
1421 tree subblocks = current_binding_level->blocks;
1422 tree block = 0;
1423 tree decl;
1424 tree bind = 0;
1426 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1427 binding_depth--;
1428 indent ();
1429 if (current_binding_level->end_pc != LARGEST_PC)
1430 fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
1431 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1432 current_binding_level->end_pc);
1433 else
1434 fprintf (stderr, "pop %s level %p pc %d\n",
1435 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1436 #if 0
1437 if (is_class_level != (current_binding_level == class_binding_level))
1439 indent ();
1440 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1442 is_class_level = 0;
1443 #endif
1444 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1446 /* Get the decls in the order they were written.
1447 Usually current_binding_level->names is in reverse order.
1448 But parameter decls were previously put in forward order. */
1450 if (reverse)
1451 current_binding_level->names
1452 = decls = nreverse (current_binding_level->names);
1453 else
1454 decls = current_binding_level->names;
1456 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1457 if (TREE_CODE (decl) == VAR_DECL
1458 && DECL_LANG_SPECIFIC (decl) != NULL
1459 && DECL_LOCAL_SLOT_NUMBER (decl))
1460 LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
1462 /* If there were any declarations in that level,
1463 or if this level is a function body,
1464 create a BLOCK to record them for the life of this function. */
1466 block = 0;
1467 if (keep || functionbody)
1469 block = make_node (BLOCK);
1470 TREE_TYPE (block) = void_type_node;
1473 if (current_binding_level->exception_range)
1474 expand_end_java_handler (current_binding_level->exception_range);
1476 if (block != 0)
1478 /* If any statements have been generated at this level, create a
1479 BIND_EXPR to hold them and copy the variables to it. This
1480 only applies to the bytecode compiler. */
1481 if (current_binding_level->stmts)
1483 tree decl = decls;
1484 tree *var = &BLOCK_VARS (block);
1486 /* Copy decls from names list, ignoring labels. */
1487 while (decl)
1489 tree next = TREE_CHAIN (decl);
1490 if (TREE_CODE (decl) != LABEL_DECL)
1492 *var = decl;
1493 var = &TREE_CHAIN (decl);
1495 decl = next;
1497 *var = NULL;
1499 bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
1500 BLOCK_EXPR_BODY (block), block);
1501 BIND_EXPR_BODY (bind) = current_binding_level->stmts;
1503 if (BIND_EXPR_BODY (bind)
1504 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
1505 TREE_SIDE_EFFECTS (bind) = 1;
1507 /* FIXME: gimplifier brain damage. */
1508 if (BIND_EXPR_BODY (bind) == NULL)
1509 BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
1511 current_binding_level->stmts = NULL;
1513 else
1515 BLOCK_VARS (block) = decls;
1517 BLOCK_SUBBLOCKS (block) = subblocks;
1520 /* In each subblock, record that this is its superior. */
1522 for (link = subblocks; link; link = TREE_CHAIN (link))
1523 BLOCK_SUPERCONTEXT (link) = block;
1525 /* Clear out the meanings of the local variables of this level. */
1527 for (link = decls; link; link = TREE_CHAIN (link))
1529 tree name = DECL_NAME (link);
1530 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1532 /* If the ident. was used or addressed via a local extern decl,
1533 don't forget that fact. */
1534 if (DECL_EXTERNAL (link))
1536 if (TREE_USED (link))
1537 TREE_USED (name) = 1;
1538 if (TREE_ADDRESSABLE (link))
1539 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1541 IDENTIFIER_LOCAL_VALUE (name) = 0;
1545 /* Restore all name-meanings of the outer levels
1546 that were shadowed by this level. */
1548 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1549 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1551 /* If the level being exited is the top level of a function,
1552 check over all the labels, and clear out the current
1553 (function local) meanings of their names. */
1555 if (functionbody)
1557 /* If this is the top level block of a function,
1558 the vars are the function's parameters.
1559 Don't leave them in the BLOCK because they are
1560 found in the FUNCTION_DECL instead. */
1562 BLOCK_VARS (block) = 0;
1564 /* Clear out the definitions of all label names,
1565 since their scopes end here,
1566 and add them to BLOCK_VARS. */
1568 #if 0
1569 for (link = named_labels; link; link = TREE_CHAIN (link))
1571 tree label = TREE_VALUE (link);
1573 if (DECL_INITIAL (label) == 0)
1575 error ("%Jlabel '%D' used but not defined", label, label);
1576 /* Avoid crashing later. */
1577 define_label (input_location, DECL_NAME (label));
1579 else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
1580 warning ("%Jlabel '%D' defined but not used", label, label);
1581 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1583 /* Put the labels into the "variables" of the
1584 top-level block, so debugger can see them. */
1585 TREE_CHAIN (label) = BLOCK_VARS (block);
1586 BLOCK_VARS (block) = label;
1588 #endif
1591 /* Pop the current level, and free the structure for reuse. */
1594 struct binding_level *level = current_binding_level;
1595 current_binding_level = current_binding_level->level_chain;
1597 level->level_chain = free_binding_level;
1598 free_binding_level = level;
1601 /* Dispose of the block that we just made inside some higher level. */
1602 if (functionbody)
1604 DECL_INITIAL (current_function_decl) = block;
1605 DECL_SAVED_TREE (current_function_decl) = bind;
1607 else
1609 if (block)
1611 current_binding_level->blocks
1612 = chainon (current_binding_level->blocks, block);
1614 /* If we did not make a block for the level just exited,
1615 any blocks made for inner levels
1616 (since they cannot be recorded as subblocks in that level)
1617 must be carried forward so they will later become subblocks
1618 of something else. */
1619 else if (subblocks)
1620 current_binding_level->blocks
1621 = chainon (current_binding_level->blocks, subblocks);
1623 if (bind)
1624 java_add_stmt (bind);
1627 if (block)
1628 TREE_USED (block) = 1;
1629 return block;
1632 void
1633 maybe_pushlevels (int pc)
1635 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1636 current_pc = pc;
1637 #endif
1639 while (pending_local_decls != NULL_TREE &&
1640 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1642 tree *ptr = &pending_local_decls;
1643 tree decl = *ptr, next;
1644 int end_pc = DECL_LOCAL_END_PC (decl);
1646 while (*ptr != NULL_TREE
1647 && DECL_LOCAL_START_PC (*ptr) <= pc
1648 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1649 ptr = &TREE_CHAIN (*ptr);
1650 pending_local_decls = *ptr;
1651 *ptr = NULL_TREE;
1653 /* Force non-nested range to be nested in current range by
1654 truncating variable lifetimes. */
1655 if (end_pc > current_binding_level->end_pc)
1657 end_pc = current_binding_level->end_pc;
1658 DECL_LOCAL_END_PC (decl) = end_pc;
1661 maybe_start_try (pc, end_pc);
1663 pushlevel (1);
1665 current_binding_level->end_pc = end_pc;
1666 current_binding_level->start_pc = pc;
1667 current_binding_level->names = NULL;
1668 for ( ; decl != NULL_TREE; decl = next)
1670 next = TREE_CHAIN (decl);
1671 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1672 pushdecl (decl);
1673 initialize_local_variable (decl, DECL_LOCAL_SLOT_NUMBER (decl));
1677 maybe_start_try (pc, 0);
1680 void
1681 maybe_poplevels (int pc)
1683 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1684 current_pc = pc;
1685 #endif
1687 while (current_binding_level->end_pc <= pc)
1688 poplevel (1, 0, 0);
1691 /* Terminate any binding which began during the range beginning at
1692 start_pc. This tidies up improperly nested local variable ranges
1693 and exception handlers; a variable declared within an exception
1694 range is forcibly terminated when that exception ends. */
1696 void
1697 force_poplevels (int start_pc)
1699 while (current_binding_level->start_pc > start_pc)
1701 if (pedantic && current_binding_level->start_pc > start_pc)
1702 warning ("%JIn %D: overlapped variable and exception ranges at %d",
1703 current_function_decl, current_function_decl,
1704 current_binding_level->start_pc);
1705 poplevel (1, 0, 0);
1709 /* Insert BLOCK at the end of the list of subblocks of the
1710 current binding level. This is used when a BIND_EXPR is expanded,
1711 to handle the BLOCK node inside the BIND_EXPR. */
1713 void
1714 insert_block (tree block)
1716 TREE_USED (block) = 1;
1717 current_binding_level->blocks
1718 = chainon (current_binding_level->blocks, block);
1721 /* integrate_decl_tree calls this function. */
1723 void
1724 java_dup_lang_specific_decl (tree node)
1726 int lang_decl_size;
1727 struct lang_decl *x;
1729 if (!DECL_LANG_SPECIFIC (node))
1730 return;
1732 lang_decl_size = sizeof (struct lang_decl);
1733 x = ggc_alloc (lang_decl_size);
1734 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
1735 DECL_LANG_SPECIFIC (node) = x;
1738 void
1739 give_name_to_locals (JCF *jcf)
1741 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1742 int code_offset = DECL_CODE_OFFSET (current_function_decl);
1743 tree parm;
1744 pending_local_decls = NULL_TREE;
1745 if (n == 0)
1746 return;
1747 JCF_SEEK (jcf, n);
1748 n = JCF_readu2 (jcf);
1749 for (i = 0; i < n; i++)
1751 int start_pc = JCF_readu2 (jcf);
1752 int length = JCF_readu2 (jcf);
1753 int name_index = JCF_readu2 (jcf);
1754 int signature_index = JCF_readu2 (jcf);
1755 int slot = JCF_readu2 (jcf);
1756 tree name = get_name_constant (jcf, name_index);
1757 tree type = parse_signature (jcf, signature_index);
1758 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1759 && start_pc == 0
1760 && length == DECL_CODE_LENGTH (current_function_decl))
1762 tree decl = TREE_VEC_ELT (decl_map, slot);
1763 DECL_NAME (decl) = name;
1764 SET_DECL_ASSEMBLER_NAME (decl, name);
1765 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1766 warning ("bad type in parameter debug info");
1768 else
1770 tree *ptr;
1771 int end_pc = start_pc + length;
1772 tree decl = build_decl (VAR_DECL, name, type);
1773 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1775 warning ("%Jbad PC range for debug info for local '%D'",
1776 decl, decl);
1777 end_pc = DECL_CODE_LENGTH (current_function_decl);
1780 /* Adjust start_pc if necessary so that the local's first
1781 store operation will use the relevant DECL as a
1782 destination. Fore more information, read the leading
1783 comments for expr.c:maybe_adjust_start_pc. */
1784 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
1786 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
1787 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1788 DECL_LOCAL_START_PC (decl) = start_pc;
1789 #if 0
1790 /* FIXME: The range used internally for exceptions and local
1791 variable ranges, is a half-open interval:
1792 start_pc <= pc < end_pc. However, the range used in the
1793 Java VM spec is inclusive at both ends:
1794 start_pc <= pc <= end_pc. */
1795 end_pc++;
1796 #endif
1797 DECL_LOCAL_END_PC (decl) = end_pc;
1799 /* Now insert the new decl in the proper place in
1800 pending_local_decls. We are essentially doing an insertion sort,
1801 which works fine, since the list input will normally already
1802 be sorted. */
1803 ptr = &pending_local_decls;
1804 while (*ptr != NULL_TREE
1805 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1806 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1807 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1808 ptr = &TREE_CHAIN (*ptr);
1809 TREE_CHAIN (decl) = *ptr;
1810 *ptr = decl;
1814 pending_local_decls = nreverse (pending_local_decls);
1816 /* Fill in default names for the parameters. */
1817 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1818 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1820 if (DECL_NAME (parm) == NULL_TREE)
1822 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1823 if (arg_i == 0)
1824 DECL_NAME (parm) = get_identifier ("this");
1825 else
1827 char buffer[12];
1828 sprintf (buffer, "ARG_%d", arg_i);
1829 DECL_NAME (parm) = get_identifier (buffer);
1831 SET_DECL_ASSEMBLER_NAME (parm, DECL_NAME (parm));
1836 tree
1837 build_result_decl (tree fndecl)
1839 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1840 tree result = DECL_RESULT (fndecl);
1841 if (! result)
1843 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1844 if (INTEGRAL_TYPE_P (restype)
1845 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1846 restype = integer_type_node;
1847 result = build_decl (RESULT_DECL, NULL_TREE, restype);
1848 DECL_ARTIFICIAL (result) = 1;
1849 DECL_IGNORED_P (result) = 1;
1850 DECL_CONTEXT (result) = fndecl;
1851 DECL_RESULT (fndecl) = result;
1853 return result;
1856 void
1857 start_java_method (tree fndecl)
1859 tree tem, *ptr;
1860 int i;
1862 uniq = 0;
1864 current_function_decl = fndecl;
1865 announce_function (fndecl);
1867 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1868 decl_map = make_tree_vec (i);
1869 base_decl_map = make_tree_vec (i);
1870 type_map = xrealloc (type_map, i * sizeof (tree));
1872 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1873 fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
1874 current_pc = 0;
1875 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1876 pushlevel (1); /* Push parameters. */
1878 ptr = &DECL_ARGUMENTS (fndecl);
1879 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1880 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1882 tree parm_name = NULL_TREE, parm_decl;
1883 tree parm_type = TREE_VALUE (tem);
1884 if (i >= DECL_MAX_LOCALS (fndecl))
1885 abort ();
1887 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1888 DECL_CONTEXT (parm_decl) = fndecl;
1889 if (targetm.calls.promote_prototypes (parm_type)
1890 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1891 && INTEGRAL_TYPE_P (parm_type))
1892 parm_type = integer_type_node;
1893 DECL_ARG_TYPE (parm_decl) = parm_type;
1895 *ptr = parm_decl;
1896 ptr = &TREE_CHAIN (parm_decl);
1898 /* Add parm_decl to the decl_map. */
1899 push_jvm_slot (i, parm_decl);
1901 type_map[i] = TREE_TYPE (parm_decl);
1902 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1904 i++;
1905 type_map[i] = void_type_node;
1908 *ptr = NULL_TREE;
1909 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1911 while (i < DECL_MAX_LOCALS(fndecl))
1912 type_map[i++] = NULL_TREE;
1914 build_result_decl (fndecl);
1916 /* Push local variables. */
1917 pushlevel (2);
1919 function_binding_level = current_binding_level;
1922 void
1923 end_java_method (void)
1925 tree fndecl = current_function_decl;
1927 /* pop out of function */
1928 poplevel (1, 1, 0);
1930 /* pop out of its parameters */
1931 poplevel (1, 0, 1);
1933 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1935 if (DECL_SAVED_TREE (fndecl))
1937 tree fbody, block_body;
1938 /* Before we check initialization, attached all class initialization
1939 variable to the block_body */
1940 fbody = DECL_SAVED_TREE (fndecl);
1941 block_body = BIND_EXPR_BODY (fbody);
1942 htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1943 attach_init_test_initialization_flags, block_body);
1946 flag_unit_at_a_time = 0;
1947 finish_method (fndecl);
1949 if (! flag_unit_at_a_time)
1951 /* Nulling these fields when we no longer need them saves
1952 memory. */
1953 DECL_SAVED_TREE (fndecl) = NULL;
1954 DECL_STRUCT_FUNCTION (fndecl) = NULL;
1955 DECL_INITIAL (fndecl) = NULL_TREE;
1957 current_function_decl = NULL_TREE;
1960 /* Prepare a method for expansion. */
1962 void
1963 finish_method (tree fndecl)
1965 tree *tp = &DECL_SAVED_TREE (fndecl);
1967 /* Wrap body of synchronized methods in a monitorenter,
1968 plus monitorexit cleanup. */
1969 if (METHOD_SYNCHRONIZED (fndecl))
1971 tree enter, exit, lock;
1972 if (METHOD_STATIC (fndecl))
1973 lock = build_class_ref (DECL_CONTEXT (fndecl));
1974 else
1975 lock = DECL_ARGUMENTS (fndecl);
1976 BUILD_MONITOR_ENTER (enter, lock);
1977 BUILD_MONITOR_EXIT (exit, lock);
1978 *tp = build2 (COMPOUND_EXPR, void_type_node, enter,
1979 build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
1982 /* Prepend class initialization for static methods reachable from
1983 other classes. */
1984 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1985 && ! DECL_CLINIT_P (fndecl)
1986 && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl))))
1988 tree clas = DECL_CONTEXT (fndecl);
1989 tree init = build3 (CALL_EXPR, void_type_node,
1990 build_address_of (soft_initclass_node),
1991 build_tree_list (NULL_TREE, build_class_ref (clas)),
1992 NULL_TREE);
1993 *tp = build2 (COMPOUND_EXPR, TREE_TYPE (*tp), init, *tp);
1996 /* Convert function tree to GENERIC prior to inlining. */
1997 java_genericize (fndecl);
1999 /* Store the end of the function, so that we get good line number
2000 info for the epilogue. */
2001 if (DECL_STRUCT_FUNCTION (fndecl))
2002 cfun = DECL_STRUCT_FUNCTION (fndecl);
2003 else
2004 allocate_struct_function (fndecl);
2005 #ifdef USE_MAPPED_LOCATION
2006 cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
2007 #else
2008 cfun->function_end_locus.file = DECL_SOURCE_FILE (fndecl);
2009 cfun->function_end_locus.line = DECL_FUNCTION_LAST_LINE (fndecl);
2010 #endif
2012 /* Defer inlining and expansion to the cgraph optimizers. */
2013 cgraph_finalize_function (fndecl, false);
2016 /* Optimize and expand a function's entire body. */
2018 void
2019 java_expand_body (tree fndecl)
2021 tree_rest_of_compilation (fndecl);
2024 /* We pessimistically marked all methods and fields external until we
2025 knew what set of classes we were planning to compile. Now mark those
2026 associated with CLASS to be generated locally as not external. */
2028 static void
2029 java_mark_decl_local (tree decl)
2031 DECL_EXTERNAL (decl) = 0;
2033 /* If we've already constructed DECL_RTL, give encode_section_info
2034 a second chance, now that we've changed the flags. */
2035 if (DECL_RTL_SET_P (decl))
2036 make_decl_rtl (decl);
2039 void
2040 java_mark_class_local (tree class)
2042 tree t;
2044 for (t = TYPE_FIELDS (class); t ; t = TREE_CHAIN (t))
2045 if (FIELD_STATIC (t))
2046 java_mark_decl_local (t);
2048 for (t = TYPE_METHODS (class); t ; t = TREE_CHAIN (t))
2049 if (!METHOD_ABSTRACT (t) && (!METHOD_NATIVE (t) || flag_jni))
2050 java_mark_decl_local (t);
2053 /* Add a statement to a compound_expr. */
2055 tree
2056 add_stmt_to_compound (tree existing, tree type, tree stmt)
2058 if (!stmt)
2059 return existing;
2060 else if (existing)
2062 tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
2063 TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
2064 | TREE_SIDE_EFFECTS (stmt);
2065 return expr;
2067 else
2068 return stmt;
2071 /* Add a statement to the compound_expr currently being
2072 constructed. */
2074 tree
2075 java_add_stmt (tree stmt)
2077 if (input_filename)
2078 SET_EXPR_LOCATION (stmt, input_location);
2080 return current_binding_level->stmts
2081 = add_stmt_to_compound (current_binding_level->stmts,
2082 TREE_TYPE (stmt), stmt);
2085 /* Add a variable to the current scope. */
2087 tree
2088 java_add_local_var (tree decl)
2090 tree *vars = &current_binding_level->names;
2091 tree next = *vars;
2092 TREE_CHAIN (decl) = next;
2093 *vars = decl;
2094 DECL_CONTEXT (decl) = current_function_decl;
2095 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
2096 return decl;
2099 /* Return a pointer to the compound_expr currently being
2100 constructed. */
2102 tree *
2103 get_stmts (void)
2105 return &current_binding_level->stmts;
2108 /* Register an exception range as belonging to the current binding
2109 level. There may only be one: if there are more, we'll create more
2110 binding levels. However, each range can have multiple handlers,
2111 and these are expanded when we call expand_end_java_handler(). */
2113 void
2114 register_exception_range (struct eh_range *range, int pc, int end_pc)
2116 if (current_binding_level->exception_range)
2117 abort ();
2118 current_binding_level->exception_range = range;
2119 current_binding_level->end_pc = end_pc;
2120 current_binding_level->start_pc = pc;
2123 #include "gt-java-decl.h"