1 /* Process declarations and variables for the GNU compiler for the
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)
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. */
31 #include "coretypes.h"
38 #include "java-tree.h"
44 #include "java-except.h"
48 #include "tree-inline.h"
51 #if defined (DEBUG_JAVA_BINDING_LEVELS)
52 extern void indent (void);
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_named_variable (tree
, tree
, int, int *);
61 static tree
check_local_unnamed_variable (tree
, tree
, tree
);
63 /* Name of the Cloneable class. */
64 tree java_lang_cloneable_identifier_node
;
66 /* Name of the Serializable class. */
67 tree java_io_serializable_identifier_node
;
69 /* The DECL_MAP is a mapping from (index, type) to a decl node.
70 If index < max_locals, it is the index of a local variable.
71 if index >= max_locals, then index-max_locals is a stack slot.
72 The DECL_MAP mapping is represented as a TREE_VEC whose elements
73 are a list of decls (VAR_DECL or PARM_DECL) chained by
74 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
75 we search the chain for a decl with a matching TREE_TYPE. */
77 static GTY(()) tree decl_map
;
79 /* A list of local variables VAR_DECLs for this method that we have seen
80 debug information, but we have not reached their starting (byte) PC yet. */
82 static GTY(()) tree pending_local_decls
;
84 /* Push a local variable or stack slot into the decl_map,
85 and assign it an rtl. */
87 #if defined(DEBUG_JAVA_BINDING_LEVELS)
88 int binding_depth
= 0;
89 int is_class_level
= 0;
97 for (i
= 0; i
< binding_depth
*2; i
++)
100 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
102 /* Copy the value in decl into every alias in the same local variable
105 update_aliases (tree decl
, int index
)
107 tree tmp
= TREE_VEC_ELT (decl_map
, index
);
108 tree type
= TREE_TYPE (decl
);
109 while (tmp
!= NULL_TREE
)
112 && ! LOCAL_VAR_OUT_OF_SCOPE_P (tmp
)
113 && TYPE_MODE (type
) == TYPE_MODE (TREE_TYPE (tmp
)))
115 tree src
= build1 (NOP_EXPR
, TREE_TYPE (tmp
), decl
);
117 (build (MODIFY_EXPR
, TREE_TYPE (tmp
), tmp
, src
));
119 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
124 push_jvm_slot (int index
, tree decl
)
126 tree type
= TREE_TYPE (decl
);
129 DECL_CONTEXT (decl
) = current_function_decl
;
130 layout_decl (decl
, 0);
132 /* Look for another variable of the same mode in this slot. */
133 tmp
= TREE_VEC_ELT (decl_map
, index
);
134 while (tmp
!= NULL_TREE
)
136 if (! LOCAL_VAR_OUT_OF_SCOPE_P (tmp
)
137 && TYPE_MODE (type
) == TYPE_MODE (TREE_TYPE (tmp
)))
139 /* At the point of its creation this decl inherits whatever
141 tree src
= build1 (NOP_EXPR
, TREE_TYPE (decl
), tmp
);
143 (build (MODIFY_EXPR
, TREE_TYPE (decl
), decl
, src
));
146 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
149 /* Now link the decl into the decl_map. */
150 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
152 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
153 DECL_LOCAL_START_PC (decl
) = 0;
154 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
155 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
157 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
158 TREE_VEC_ELT (decl_map
, index
) = decl
;
160 if (TREE_CODE (decl
) != PARM_DECL
)
165 /* Find out if 'decl' passed in fits the defined PC location better than
166 'best'. Return decl if it does, return best if it doesn't. If decl
167 is returned, then updated is set to true. */
170 check_local_named_variable (tree best
, tree decl
, int pc
, int *updated
)
172 if (pc
>= DECL_LOCAL_START_PC (decl
)
173 && pc
< DECL_LOCAL_END_PC (decl
))
175 if (best
== NULL_TREE
176 || (DECL_LOCAL_START_PC (decl
) > DECL_LOCAL_START_PC (best
)
177 && DECL_LOCAL_END_PC (decl
) < DECL_LOCAL_END_PC (best
)))
187 /* Find the best declaration based upon type. If 'decl' fits 'type' better
188 than 'best', return 'decl'. Otherwise return 'best'. */
191 check_local_unnamed_variable (tree best
, tree decl
, tree type
)
193 if (TREE_TYPE (decl
) == type
194 || (TREE_CODE (TREE_TYPE (decl
)) == TREE_CODE (type
)
195 && TYPE_PRECISION (TREE_TYPE (decl
)) <= 32
196 && TYPE_PRECISION (type
) <= 32
197 && TREE_CODE (type
) != POINTER_TYPE
)
198 || (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
199 && type
== ptr_type_node
))
201 if (best
== NULL_TREE
202 || (TREE_TYPE (decl
) == type
&& TREE_TYPE (best
) != type
))
210 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
211 that is valid at PC (or -1 if any pc).
212 If there is no existing matching decl, allocate one. */
215 find_local_variable (int index
, tree type
, int pc
)
217 tree decl
= TREE_VEC_ELT (decl_map
, index
);
218 tree best
= NULL_TREE
;
219 int found_scoped_var
= 0;
221 /* Scan through every declaration that has been created in this slot. */
222 while (decl
!= NULL_TREE
)
224 bool has_name
= false;
225 tree name
= DECL_NAME (decl
);
226 if (name
&& IDENTIFIER_POINTER (name
))
227 has_name
= IDENTIFIER_POINTER (name
)[0] != '#';
229 /* Variables created in give_name_to_locals() have a name and have
230 a specified scope, so we can handle them specifically. We want
231 to use the specific decls created for those so they are assigned
232 the right variables in the debugging information. */
235 /* This is a variable we have a name for, so it has a scope
236 supplied in the class file. But it only matters when we
237 actually have a PC to use. If pc<0, then we are asking
238 for a stack slot and this decl won't be one of those. */
240 best
= check_local_named_variable (best
, decl
, pc
,
243 /* We scan for type information unless we found a variable in the
244 proper scope already. */
245 else if (!found_scoped_var
)
247 /* If we don't have scoping information for a variable, we use
248 a different method to look it up. */
249 best
= check_local_unnamed_variable (best
, decl
, type
);
252 decl
= DECL_LOCAL_SLOT_CHAIN (decl
);
255 if (best
!= NULL_TREE
)
258 /* If we don't find a match, create one with the type passed in.
259 Ths name of the variable is #n#m, which n is the variable index
260 in the local variable area and m is a dummy identifier for
261 uniqueness -- multiple variables may share the same local
267 sprintf (buf
, "#%d#%d", index
, uniq
++);
268 name
= get_identifier (buf
);
270 return push_jvm_slot (index
, build_decl (VAR_DECL
, name
, type
));
275 /* Same as find_local_index, except that INDEX is a stack index. */
278 find_stack_slot (int index
, tree type
)
280 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
286 /* A chain of _DECL nodes for all variables, constants, functions,
287 * and typedef types. These are in the reverse of the order supplied.
291 /* For each level, a list of shadowed outer-level local definitions
292 to be restored when this level is popped.
293 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
294 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
297 /* For each level (except not the global one),
298 a chain of BLOCK nodes for all the levels
299 that were entered and exited one level down. */
302 /* The BLOCK node for this level, if one has been preallocated.
303 If 0, the BLOCK is allocated (if needed) when the level is popped. */
306 /* The binding level which this one is contained in (inherits from). */
307 struct binding_level
*level_chain
;
309 /* The bytecode PC that marks the end of this level. */
311 /* The bytecode PC that marks the start of this level. */
314 /* The statements in this binding level. */
317 #if defined(DEBUG_JAVA_BINDING_LEVELS)
318 /* Binding depth at which this level began. */
319 unsigned binding_depth
;
320 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
323 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
325 /* The binding level currently in effect. */
327 static struct binding_level
*current_binding_level
;
329 /* A chain of binding_level structures awaiting reuse. */
331 static struct binding_level
*free_binding_level
;
333 /* The outermost binding level, for names of file scope.
334 This is created when the compiler is started and exists
335 through the entire run. */
337 static struct binding_level
*global_binding_level
;
339 /* A PC value bigger than any PC value we may ever may encounter. */
341 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
343 /* Binding level structures are initialized by copying this one. */
345 static const struct binding_level clear_binding_level
346 = {NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
,
347 NULL_BINDING_LEVEL
, LARGEST_PC
, 0, NULL
,
348 #if defined(DEBUG_JAVA_BINDING_LEVELS)
350 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
354 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
355 that have names. Here so we can clear out their names' definitions
356 at the end of the function. */
358 static tree named_labels
;
360 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
362 static tree shadowed_labels
;
365 tree java_global_trees
[JTI_MAX
];
367 /* Build (and pushdecl) a "promoted type" for all standard
368 types shorter than int. */
371 push_promoted_type (const char *name
, tree actual_type
)
373 tree type
= make_node (TREE_CODE (actual_type
));
375 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
376 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
378 tree in_min
= TYPE_MIN_VALUE (actual_type
);
379 tree in_max
= TYPE_MAX_VALUE (actual_type
);
381 TYPE_MIN_VALUE (type
) = copy_node (in_min
);
382 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
383 TYPE_MAX_VALUE (type
) = copy_node (in_max
);
384 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
385 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
387 pushdecl (build_decl (TYPE_DECL
, get_identifier (name
), type
));
391 /* Return a definition for a builtin function named NAME and whose data type
392 is TYPE. TYPE should be a function type with argument types.
393 FUNCTION_CODE tells later passes how to compile calls to this function.
394 See tree.h for its possible values.
396 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
397 the name to be called if we can't opencode the function. If
398 ATTRS is nonzero, use that for the function's attribute list. */
401 builtin_function (const char *name
,
404 enum built_in_class
class,
405 const char *library_name
,
406 tree attrs ATTRIBUTE_UNUSED
)
408 tree decl
= build_decl (FUNCTION_DECL
, get_identifier (name
), type
);
409 DECL_EXTERNAL (decl
) = 1;
410 TREE_PUBLIC (decl
) = 1;
412 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (library_name
));
413 make_decl_rtl (decl
, NULL
);
415 DECL_BUILT_IN_CLASS (decl
) = class;
416 DECL_FUNCTION_CODE (decl
) = function_code
;
420 /* Return tree that represents a vtable for a primitive array. */
422 create_primitive_vtable (const char *name
)
427 sprintf (buf
, "_Jv_%sVTable", name
);
428 r
= build_decl (VAR_DECL
, get_identifier (buf
), ptr_type_node
);
429 DECL_EXTERNAL (r
) = 1;
441 java_init_decl_processing (void)
444 tree field
= NULL_TREE
;
447 init_class_processing ();
448 init_resource_processing ();
450 current_function_decl
= NULL
;
451 current_binding_level
= NULL_BINDING_LEVEL
;
452 free_binding_level
= NULL_BINDING_LEVEL
;
453 pushlevel (0); /* make the binding_level structure for global names */
454 global_binding_level
= current_binding_level
;
456 /* The code here must be similar to build_common_tree_nodes{,_2} in
457 tree.c, especially as to the order of initializing common nodes. */
458 error_mark_node
= make_node (ERROR_MARK
);
459 TREE_TYPE (error_mark_node
) = error_mark_node
;
461 /* Create sizetype first - needed for other types. */
462 initialize_sizetypes ();
464 byte_type_node
= make_signed_type (8);
465 pushdecl (build_decl (TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
466 short_type_node
= make_signed_type (16);
467 pushdecl (build_decl (TYPE_DECL
, get_identifier ("short"), short_type_node
));
468 int_type_node
= make_signed_type (32);
469 pushdecl (build_decl (TYPE_DECL
, get_identifier ("int"), int_type_node
));
470 long_type_node
= make_signed_type (64);
471 pushdecl (build_decl (TYPE_DECL
, get_identifier ("long"), long_type_node
));
473 unsigned_byte_type_node
= make_unsigned_type (8);
474 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned byte"),
475 unsigned_byte_type_node
));
476 unsigned_short_type_node
= make_unsigned_type (16);
477 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned short"),
478 unsigned_short_type_node
));
479 unsigned_int_type_node
= make_unsigned_type (32);
480 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned int"),
481 unsigned_int_type_node
));
482 unsigned_long_type_node
= make_unsigned_type (64);
483 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned long"),
484 unsigned_long_type_node
));
486 /* This is not a java type, however tree-dfa requires a definition for
488 size_type_node
= make_unsigned_type (POINTER_SIZE
);
489 set_sizetype (size_type_node
);
491 /* Define these next since types below may used them. */
492 integer_type_node
= java_type_for_size (INT_TYPE_SIZE
, 0);
493 integer_zero_node
= build_int_2 (0, 0);
494 integer_one_node
= build_int_2 (1, 0);
495 integer_two_node
= build_int_2 (2, 0);
496 integer_four_node
= build_int_2 (4, 0);
497 integer_minus_one_node
= build_int_2 (-1, -1);
499 /* A few values used for range checking in the lexer. */
500 decimal_int_max
= build_int_2 (0x80000000, 0);
501 TREE_TYPE (decimal_int_max
) = unsigned_int_type_node
;
502 #if HOST_BITS_PER_WIDE_INT == 64
503 decimal_long_max
= build_int_2 (0x8000000000000000LL
, 0);
505 #if HOST_BITS_PER_WIDE_INT == 32
506 decimal_long_max
= build_int_2 (0, 0x80000000);
508 #error "unsupported size"
511 TREE_TYPE (decimal_long_max
) = unsigned_long_type_node
;
513 size_zero_node
= size_int (0);
514 size_one_node
= size_int (1);
515 bitsize_zero_node
= bitsize_int (0);
516 bitsize_one_node
= bitsize_int (1);
517 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
519 long_zero_node
= build_int_2 (0, 0);
520 TREE_TYPE (long_zero_node
) = long_type_node
;
522 void_type_node
= make_node (VOID_TYPE
);
523 pushdecl (build_decl (TYPE_DECL
, get_identifier ("void"), void_type_node
));
524 layout_type (void_type_node
); /* Uses size_zero_node */
525 ptr_type_node
= build_pointer_type (void_type_node
);
526 t
= make_node (VOID_TYPE
);
527 layout_type (t
); /* Uses size_zero_node */
528 return_address_type_node
= build_pointer_type (t
);
530 null_pointer_node
= build_int_2 (0, 0);
531 TREE_TYPE (null_pointer_node
) = ptr_type_node
;
534 /* Make a type to be the domain of a few array types
535 whose domains don't really matter.
536 200 is small enough that it always fits in size_t
537 and large enough that it can hold most function names for the
538 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
539 short_array_type_node
= build_prim_array_type (short_type_node
, 200);
541 char_type_node
= make_node (CHAR_TYPE
);
542 TYPE_PRECISION (char_type_node
) = 16;
543 fixup_unsigned_type (char_type_node
);
544 pushdecl (build_decl (TYPE_DECL
, get_identifier ("char"), char_type_node
));
546 boolean_type_node
= make_node (BOOLEAN_TYPE
);
547 TYPE_PRECISION (boolean_type_node
) = 1;
548 fixup_unsigned_type (boolean_type_node
);
549 pushdecl (build_decl (TYPE_DECL
, get_identifier ("boolean"),
551 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
552 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
554 promoted_byte_type_node
555 = push_promoted_type ("promoted_byte", byte_type_node
);
556 promoted_short_type_node
557 = push_promoted_type ("promoted_short", short_type_node
);
558 promoted_char_type_node
559 = push_promoted_type ("promoted_char", char_type_node
);
560 promoted_boolean_type_node
561 = push_promoted_type ("promoted_boolean", boolean_type_node
);
563 float_type_node
= make_node (REAL_TYPE
);
564 TYPE_PRECISION (float_type_node
) = 32;
565 pushdecl (build_decl (TYPE_DECL
, get_identifier ("float"),
567 layout_type (float_type_node
);
569 double_type_node
= make_node (REAL_TYPE
);
570 TYPE_PRECISION (double_type_node
) = 64;
571 pushdecl (build_decl (TYPE_DECL
, get_identifier ("double"),
573 layout_type (double_type_node
);
575 float_zero_node
= build_real (float_type_node
, dconst0
);
576 double_zero_node
= build_real (double_type_node
, dconst0
);
578 /* These are the vtables for arrays of primitives. */
579 boolean_array_vtable
= create_primitive_vtable ("boolean");
580 byte_array_vtable
= create_primitive_vtable ("byte");
581 char_array_vtable
= create_primitive_vtable ("char");
582 short_array_vtable
= create_primitive_vtable ("short");
583 int_array_vtable
= create_primitive_vtable ("int");
584 long_array_vtable
= create_primitive_vtable ("long");
585 float_array_vtable
= create_primitive_vtable ("float");
586 double_array_vtable
= create_primitive_vtable ("double");
588 one_elt_array_domain_type
= build_index_type (integer_one_node
);
589 utf8const_type
= make_node (RECORD_TYPE
);
590 PUSH_FIELD (utf8const_type
, field
, "hash", unsigned_short_type_node
);
591 PUSH_FIELD (utf8const_type
, field
, "length", unsigned_short_type_node
);
592 FINISH_RECORD (utf8const_type
);
593 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
595 atable_type
= build_array_type (ptr_type_node
,
596 one_elt_array_domain_type
);
597 TYPE_NONALIASED_COMPONENT (atable_type
) = 1;
598 atable_ptr_type
= build_pointer_type (atable_type
);
600 symbol_type
= make_node (RECORD_TYPE
);
601 PUSH_FIELD (symbol_type
, field
, "clname", utf8const_ptr_type
);
602 PUSH_FIELD (symbol_type
, field
, "name", utf8const_ptr_type
);
603 PUSH_FIELD (symbol_type
, field
, "signature", utf8const_ptr_type
);
604 FINISH_RECORD (symbol_type
);
606 symbols_array_type
= build_array_type (symbol_type
,
607 one_elt_array_domain_type
);
608 symbols_array_ptr_type
= build_pointer_type (symbols_array_type
);
610 /* As you're adding items here, please update the code right after
611 this section, so that the filename containing the source code of
612 the pre-defined class gets registered correctly. */
613 unqualified_object_id_node
= get_identifier ("Object");
614 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
615 object_ptr_type_node
= promote_type (object_type_node
);
616 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
617 string_ptr_type_node
= promote_type (string_type_node
);
618 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
619 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
620 exception_type_node
= lookup_class (get_identifier ("java.lang.Exception"));
621 runtime_exception_type_node
=
622 lookup_class (get_identifier ("java.lang.RuntimeException"));
623 error_exception_type_node
=
624 lookup_class (get_identifier ("java.lang.Error"));
626 rawdata_ptr_type_node
627 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
629 add_predefined_file (get_identifier ("java/lang/Class.java"));
630 add_predefined_file (get_identifier ("java/lang/Error.java"));
631 add_predefined_file (get_identifier ("java/lang/Object.java"));
632 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
633 add_predefined_file (get_identifier ("java/lang/String.java"));
634 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
635 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
636 add_predefined_file (get_identifier ("java/lang/Exception.java"));
637 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
638 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
640 methodtable_type
= make_node (RECORD_TYPE
);
641 layout_type (methodtable_type
);
642 build_decl (TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
643 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
645 TYPE_identifier_node
= get_identifier ("TYPE");
646 init_identifier_node
= get_identifier ("<init>");
647 clinit_identifier_node
= get_identifier ("<clinit>");
648 finit_identifier_node
= get_identifier ("finit$");
649 instinit_identifier_node
= get_identifier ("instinit$");
650 void_signature_node
= get_identifier ("()V");
651 length_identifier_node
= get_identifier ("length");
652 finalize_identifier_node
= get_identifier ("finalize");
653 this_identifier_node
= get_identifier ("this");
654 super_identifier_node
= get_identifier ("super");
655 continue_identifier_node
= get_identifier ("continue");
656 access0_identifier_node
= get_identifier ("access$0");
657 classdollar_identifier_node
= get_identifier ("class$");
659 java_lang_cloneable_identifier_node
= get_identifier ("java.lang.Cloneable");
660 java_io_serializable_identifier_node
=
661 get_identifier ("java.io.Serializable");
663 /* for lack of a better place to put this stub call */
664 init_expr_processing();
666 constants_type_node
= make_node (RECORD_TYPE
);
667 PUSH_FIELD (constants_type_node
, field
, "size", unsigned_int_type_node
);
668 PUSH_FIELD (constants_type_node
, field
, "tags", ptr_type_node
);
669 PUSH_FIELD (constants_type_node
, field
, "data", ptr_type_node
);
670 FINISH_RECORD (constants_type_node
);
671 build_decl (TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
673 access_flags_type_node
= unsigned_short_type_node
;
675 dtable_type
= make_node (RECORD_TYPE
);
676 dtable_ptr_type
= build_pointer_type (dtable_type
);
678 otable_type
= build_array_type (integer_type_node
,
679 one_elt_array_domain_type
);
680 TYPE_NONALIASED_COMPONENT (otable_type
) = 1;
681 otable_ptr_type
= build_pointer_type (otable_type
);
683 PUSH_FIELD (object_type_node
, field
, "vtable", dtable_ptr_type
);
684 DECL_FCONTEXT (field
) = object_type_node
;
685 TYPE_VFIELD (object_type_node
) = field
;
687 /* This isn't exactly true, but it is what we have in the source.
688 There is an unresolved issue here, which is whether the vtable
689 should be marked by the GC. */
690 if (! flag_hash_synchronization
)
691 PUSH_FIELD (object_type_node
, field
, "sync_info",
692 build_pointer_type (object_type_node
));
693 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
694 FIELD_PRIVATE (t
) = 1;
695 FINISH_RECORD (object_type_node
);
697 field_type_node
= make_node (RECORD_TYPE
);
698 field_ptr_type_node
= build_pointer_type (field_type_node
);
699 method_type_node
= make_node (RECORD_TYPE
);
700 method_ptr_type_node
= build_pointer_type (method_type_node
);
702 set_super_info (0, class_type_node
, object_type_node
, 0);
703 set_super_info (0, string_type_node
, object_type_node
, 0);
704 class_ptr_type
= build_pointer_type (class_type_node
);
706 PUSH_FIELD (class_type_node
, field
, "next", class_ptr_type
);
707 PUSH_FIELD (class_type_node
, field
, "name", utf8const_ptr_type
);
708 PUSH_FIELD (class_type_node
, field
, "accflags", access_flags_type_node
);
709 PUSH_FIELD (class_type_node
, field
, "superclass", class_ptr_type
);
710 PUSH_FIELD (class_type_node
, field
, "constants", constants_type_node
);
711 PUSH_FIELD (class_type_node
, field
, "methods", method_ptr_type_node
);
712 PUSH_FIELD (class_type_node
, field
, "method_count", short_type_node
);
713 PUSH_FIELD (class_type_node
, field
, "vtable_method_count", short_type_node
);
714 PUSH_FIELD (class_type_node
, field
, "fields", field_ptr_type_node
);
715 PUSH_FIELD (class_type_node
, field
, "size_in_bytes", int_type_node
);
716 PUSH_FIELD (class_type_node
, field
, "field_count", short_type_node
);
717 PUSH_FIELD (class_type_node
, field
, "static_field_count", short_type_node
);
718 PUSH_FIELD (class_type_node
, field
, "vtable", dtable_ptr_type
);
719 PUSH_FIELD (class_type_node
, field
, "otable", otable_ptr_type
);
720 PUSH_FIELD (class_type_node
, field
, "otable_syms",
721 symbols_array_ptr_type
);
722 PUSH_FIELD (class_type_node
, field
, "atable", atable_ptr_type
);
723 PUSH_FIELD (class_type_node
, field
, "atable_syms",
724 symbols_array_ptr_type
);
725 PUSH_FIELD (class_type_node
, field
, "catch_classes", ptr_type_node
);
726 PUSH_FIELD (class_type_node
, field
, "interfaces",
727 build_pointer_type (class_ptr_type
));
728 PUSH_FIELD (class_type_node
, field
, "loader", ptr_type_node
);
729 PUSH_FIELD (class_type_node
, field
, "interface_count", short_type_node
);
730 PUSH_FIELD (class_type_node
, field
, "state", byte_type_node
);
731 PUSH_FIELD (class_type_node
, field
, "thread", ptr_type_node
);
732 PUSH_FIELD (class_type_node
, field
, "depth", short_type_node
);
733 PUSH_FIELD (class_type_node
, field
, "ancestors", ptr_type_node
);
734 PUSH_FIELD (class_type_node
, field
, "idt", ptr_type_node
);
735 PUSH_FIELD (class_type_node
, field
, "arrayclass", ptr_type_node
);
736 PUSH_FIELD (class_type_node
, field
, "protectionDomain", ptr_type_node
);
737 PUSH_FIELD (class_type_node
, field
, "hack_signers", ptr_type_node
);
738 PUSH_FIELD (class_type_node
, field
, "chain", ptr_type_node
);
739 PUSH_FIELD (class_type_node
, field
, "aux_info", ptr_type_node
);
740 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
741 FIELD_PRIVATE (t
) = 1;
742 push_super_field (class_type_node
, object_type_node
);
744 FINISH_RECORD (class_type_node
);
745 build_decl (TYPE_DECL
, get_identifier ("Class"), class_type_node
);
747 field_info_union_node
= make_node (UNION_TYPE
);
748 PUSH_FIELD (field_info_union_node
, field
, "boffset", int_type_node
);
749 PUSH_FIELD (field_info_union_node
, field
, "addr", ptr_type_node
);
751 PUSH_FIELD (field_info_union_node
, field
, "idx", unsigned_short_type_node
);
753 layout_type (field_info_union_node
);
755 PUSH_FIELD (field_type_node
, field
, "name", utf8const_ptr_type
);
756 PUSH_FIELD (field_type_node
, field
, "type", class_ptr_type
);
757 PUSH_FIELD (field_type_node
, field
, "accflags", access_flags_type_node
);
758 PUSH_FIELD (field_type_node
, field
, "bsize", unsigned_short_type_node
);
759 PUSH_FIELD (field_type_node
, field
, "info", field_info_union_node
);
760 FINISH_RECORD (field_type_node
);
761 build_decl (TYPE_DECL
, get_identifier ("Field"), field_type_node
);
763 nativecode_ptr_array_type_node
764 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
766 PUSH_FIELD (dtable_type
, field
, "class", class_ptr_type
);
767 PUSH_FIELD (dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
768 FINISH_RECORD (dtable_type
);
769 build_decl (TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
771 #define jint_type int_type_node
772 #define jint_ptr_type ptr_type_node
774 jexception_type
= make_node (RECORD_TYPE
);
775 PUSH_FIELD (jexception_type
, field
, "start_pc", ptr_type_node
);
776 PUSH_FIELD (jexception_type
, field
, "end_pc", ptr_type_node
);
777 PUSH_FIELD (jexception_type
, field
, "handler_pc", ptr_type_node
);
778 PUSH_FIELD (jexception_type
, field
, "catch_type", class_ptr_type
);
779 FINISH_RECORD (jexception_type
);
780 build_decl (TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
781 jexception_ptr_type
= build_pointer_type (jexception_type
);
783 lineNumberEntry_type
= make_node (RECORD_TYPE
);
784 PUSH_FIELD (lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
785 PUSH_FIELD (lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
786 FINISH_RECORD (lineNumberEntry_type
);
788 lineNumbers_type
= make_node (RECORD_TYPE
);
789 PUSH_FIELD (lineNumbers_type
, field
, "length", unsigned_int_type_node
);
790 FINISH_RECORD (lineNumbers_type
);
792 #define instn_ptr_type_node ptr_type_node /* XXX JH */
794 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
796 PUSH_FIELD (method_type_node
, field
, "name", utf8const_ptr_type
);
797 PUSH_FIELD (method_type_node
, field
, "signature", utf8const_ptr_type
);
798 PUSH_FIELD (method_type_node
, field
, "accflags", access_flags_type_node
);
799 PUSH_FIELD (method_type_node
, field
, "index", unsigned_short_type_node
);
800 PUSH_FIELD (method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
801 PUSH_FIELD (method_type_node
, field
, "throws", ptr_type_node
);
802 FINISH_RECORD (method_type_node
);
803 build_decl (TYPE_DECL
, get_identifier ("Method"), method_type_node
);
805 endlink
= end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
807 t
= tree_cons (NULL_TREE
, class_ptr_type
,
808 tree_cons (NULL_TREE
, int_type_node
, endlink
));
809 alloc_object_node
= builtin_function ("_Jv_AllocObject",
810 build_function_type (ptr_type_node
, t
),
811 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
812 DECL_IS_MALLOC (alloc_object_node
) = 1;
813 alloc_no_finalizer_node
=
814 builtin_function ("_Jv_AllocObjectNoFinalizer",
815 build_function_type (ptr_type_node
, t
),
816 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
817 DECL_IS_MALLOC (alloc_no_finalizer_node
) = 1;
819 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
820 soft_initclass_node
= builtin_function ("_Jv_InitClass",
821 build_function_type (void_type_node
,
823 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
825 throw_node
= builtin_function ("_Jv_Throw",
826 build_function_type (ptr_type_node
, t
),
827 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
828 /* Mark throw_nodes as `noreturn' functions with side effects. */
829 TREE_THIS_VOLATILE (throw_node
) = 1;
830 TREE_SIDE_EFFECTS (throw_node
) = 1;
832 t
= build_function_type (int_type_node
, endlink
);
833 soft_monitorenter_node
834 = builtin_function ("_Jv_MonitorEnter", t
, 0, NOT_BUILT_IN
,
836 soft_monitorexit_node
837 = builtin_function ("_Jv_MonitorExit", t
, 0, NOT_BUILT_IN
,
840 t
= tree_cons (NULL_TREE
, int_type_node
,
841 tree_cons (NULL_TREE
, int_type_node
, endlink
));
843 = builtin_function ("_Jv_NewPrimArray",
844 build_function_type(ptr_type_node
, t
),
845 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
846 DECL_IS_MALLOC (soft_newarray_node
) = 1;
848 t
= tree_cons (NULL_TREE
, int_type_node
,
849 tree_cons (NULL_TREE
, class_ptr_type
,
850 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
)));
852 = builtin_function ("_Jv_NewObjectArray",
853 build_function_type (ptr_type_node
, t
),
854 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
855 DECL_IS_MALLOC (soft_anewarray_node
) = 1;
857 /* There is no endlink here because _Jv_NewMultiArray is a varargs
859 t
= tree_cons (NULL_TREE
, ptr_type_node
,
860 tree_cons (NULL_TREE
, int_type_node
, NULL_TREE
));
861 soft_multianewarray_node
862 = builtin_function ("_Jv_NewMultiArray",
863 build_function_type (ptr_type_node
, t
),
864 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
865 DECL_IS_MALLOC (soft_multianewarray_node
) = 1;
867 t
= build_function_type (void_type_node
,
868 tree_cons (NULL_TREE
, int_type_node
, endlink
));
869 soft_badarrayindex_node
870 = builtin_function ("_Jv_ThrowBadArrayIndex", t
,
871 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
872 /* Mark soft_badarrayindex_node as a `noreturn' function with side
874 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
875 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
877 soft_nullpointer_node
878 = builtin_function ("_Jv_ThrowNullPointerException",
879 build_function_type (void_type_node
, endlink
),
880 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
881 /* Mark soft_nullpointer_node as a `noreturn' function with side
883 TREE_THIS_VOLATILE (soft_nullpointer_node
) = 1;
884 TREE_SIDE_EFFECTS (soft_nullpointer_node
) = 1;
886 t
= tree_cons (NULL_TREE
, class_ptr_type
,
887 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
889 = builtin_function ("_Jv_CheckCast",
890 build_function_type (ptr_type_node
, t
),
891 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
892 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
893 tree_cons (NULL_TREE
, class_ptr_type
, endlink
));
895 = builtin_function ("_Jv_IsInstanceOf",
896 build_function_type (boolean_type_node
, t
),
897 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
898 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
899 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
900 soft_checkarraystore_node
901 = builtin_function ("_Jv_CheckArrayStore",
902 build_function_type (void_type_node
, t
),
903 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
904 t
= tree_cons (NULL_TREE
, ptr_type_node
,
905 tree_cons (NULL_TREE
, ptr_type_node
,
906 tree_cons (NULL_TREE
, int_type_node
, endlink
)));
907 soft_lookupinterfacemethod_node
908 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
909 build_function_type (ptr_type_node
, t
),
910 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
912 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
913 tree_cons (NULL_TREE
, ptr_type_node
,
914 tree_cons (NULL_TREE
, ptr_type_node
,
915 tree_cons (NULL_TREE
, int_type_node
,
917 soft_lookupjnimethod_node
918 = builtin_function ("_Jv_LookupJNIMethod",
919 build_function_type (ptr_type_node
, t
),
920 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
921 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
922 soft_getjnienvnewframe_node
923 = builtin_function ("_Jv_GetJNIEnvNewFrame",
924 build_function_type (ptr_type_node
, t
),
925 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
926 soft_jnipopsystemframe_node
927 = builtin_function ("_Jv_JNI_PopSystemFrame",
928 build_function_type (ptr_type_node
, t
),
929 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
932 = builtin_function ("_Jv_divI",
933 build_function_type (int_type_node
, t
),
934 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
937 = builtin_function ("_Jv_remI",
938 build_function_type (int_type_node
, t
),
939 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
942 = builtin_function ("_Jv_divJ",
943 build_function_type (long_type_node
, t
),
944 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
947 = builtin_function ("_Jv_remJ",
948 build_function_type (long_type_node
, t
),
949 0, NOT_BUILT_IN
, NULL
, NULL_TREE
);
951 /* Initialize variables for except.c. */
952 eh_personality_libfunc
= init_one_libfunc (USING_SJLJ_EXCEPTIONS
953 ? "__gcj_personality_sj0"
954 : "__gcj_personality_v0");
956 lang_eh_runtime_type
= do_nothing
;
960 initialize_builtins ();
961 soft_fmod_node
= built_in_decls
[BUILT_IN_FMOD
];
963 soft_fmodf_node
= built_in_decls
[BUILT_IN_FMODF
];
968 /* Look up NAME in the current binding level and its superiors
969 in the namespace of variables, functions and typedefs.
970 Return a ..._DECL node of some kind representing its definition,
971 or return 0 if it is undefined. */
974 lookup_name (tree name
)
977 if (current_binding_level
!= global_binding_level
978 && IDENTIFIER_LOCAL_VALUE (name
))
979 val
= IDENTIFIER_LOCAL_VALUE (name
);
981 val
= IDENTIFIER_GLOBAL_VALUE (name
);
985 /* Similar to `lookup_name' but look only at current binding level and
986 the previous one if its the parameter level. */
989 lookup_name_current_level (tree name
)
993 if (current_binding_level
== global_binding_level
)
994 return IDENTIFIER_GLOBAL_VALUE (name
);
996 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
999 for (t
= current_binding_level
->names
; t
; t
= TREE_CHAIN (t
))
1000 if (DECL_NAME (t
) == name
)
1006 /* Use a binding level to record a labeled block declaration */
1009 push_labeled_block (tree lb
)
1011 tree name
= DECL_NAME (LABELED_BLOCK_LABEL (lb
));
1012 struct binding_level
*b
= current_binding_level
;
1013 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1015 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1016 TREE_CHAIN (lb
) = b
->names
;
1018 IDENTIFIER_LOCAL_VALUE (name
) = lb
;
1021 /* Pop the current binding level, reinstalling values for the previous
1025 pop_labeled_block (void)
1027 struct binding_level
*b
= current_binding_level
;
1028 tree label
= b
->names
;
1029 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label
))) =
1032 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b
->shadowed
)) =
1033 TREE_VALUE (b
->shadowed
);
1035 /* Pop the current level, and free the structure for reuse. */
1036 current_binding_level
= current_binding_level
->level_chain
;
1037 b
->level_chain
= free_binding_level
;
1038 free_binding_level
= b
;
1041 /* Record a decl-node X as belonging to the current lexical scope.
1042 Check for errors (such as an incompatible declaration for the same
1043 name already seen in the same scope).
1045 Returns either X or an old decl for the same name.
1046 If an old decl is returned, it may have been smashed
1047 to agree with what X says. */
1053 tree name
= DECL_NAME (x
);
1054 struct binding_level
*b
= current_binding_level
;
1056 if (TREE_CODE (x
) != TYPE_DECL
)
1057 DECL_CONTEXT (x
) = current_function_decl
;
1060 t
= lookup_name_current_level (name
);
1061 if (t
!= 0 && t
== error_mark_node
)
1062 /* error_mark_node is 0 for a while during initialization! */
1065 error ("%J'%D' used prior to declaration", x
, x
);
1068 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
1069 to point to the TYPE_DECL.
1070 Since Java does not have typedefs, a type can only have
1071 one (true) name, given by a class, interface, or builtin. */
1072 if (TREE_CODE (x
) == TYPE_DECL
1073 && TYPE_NAME (TREE_TYPE (x
)) == 0
1074 && TREE_TYPE (x
) != error_mark_node
)
1076 TYPE_NAME (TREE_TYPE (x
)) = x
;
1077 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
1080 /* This name is new in its binding level.
1081 Install the new declaration and return it. */
1082 if (b
== global_binding_level
)
1084 /* Install a global value. */
1086 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
1090 /* Here to install a non-global value. */
1091 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
1092 IDENTIFIER_LOCAL_VALUE (name
) = x
;
1095 /* Warn if shadowing an argument at the top level of the body. */
1096 if (oldlocal
!= 0 && !DECL_EXTERNAL (x
)
1097 /* This warning doesn't apply to the parms of a nested fcn. */
1098 && ! current_binding_level
->parm_flag
1099 /* Check that this is one level down from the parms. */
1100 && current_binding_level
->level_chain
->parm_flag
1101 /* Check that the decl being shadowed
1102 comes from the parm level, one level up. */
1103 && chain_member (oldlocal
, current_binding_level
->level_chain
->names
))
1105 if (TREE_CODE (oldlocal
) == PARM_DECL
)
1106 pedwarn ("declaration of `%s' shadows a parameter",
1107 IDENTIFIER_POINTER (name
));
1109 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1110 IDENTIFIER_POINTER (name
));
1113 /* Maybe warn if shadowing something else. */
1114 else if (warn_shadow
&& !DECL_EXTERNAL (x
)
1115 /* No shadow warnings for internally generated vars. */
1116 && DECL_SOURCE_LINE (x
) != 0
1117 /* No shadow warnings for vars made for inlining. */
1118 && ! DECL_FROM_INLINE (x
))
1120 const char *warnstring
= 0;
1122 if (TREE_CODE (x
) == PARM_DECL
1123 && current_binding_level
->level_chain
->parm_flag
)
1124 /* Don't warn about the parm names in function declarator
1125 within a function declarator.
1126 It would be nice to avoid warning in any function
1127 declarator in a declaration, as opposed to a definition,
1128 but there is no way to tell it's not a definition. */
1130 else if (oldlocal
!= 0 && TREE_CODE (oldlocal
) == PARM_DECL
)
1131 warnstring
= "declaration of `%s' shadows a parameter";
1132 else if (oldlocal
!= 0)
1133 warnstring
= "declaration of `%s' shadows previous local";
1134 else if (IDENTIFIER_GLOBAL_VALUE (name
) != 0
1135 && IDENTIFIER_GLOBAL_VALUE (name
) != error_mark_node
)
1136 warnstring
= "declaration of `%s' shadows global declaration";
1139 warning (warnstring
, IDENTIFIER_POINTER (name
));
1143 /* If storing a local value, there may already be one (inherited).
1144 If so, record it for restoration when this binding level ends. */
1146 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1150 /* Put decls on list in reverse order.
1151 We will reverse them later if necessary. */
1152 TREE_CHAIN (x
) = b
->names
;
1159 pushdecl_force_head (tree x
)
1161 current_binding_level
->names
= x
;
1164 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1167 pushdecl_top_level (tree x
)
1170 struct binding_level
*b
= current_binding_level
;
1172 current_binding_level
= global_binding_level
;
1174 current_binding_level
= b
;
1178 /* Nonzero if we are currently in the global binding level. */
1181 global_bindings_p (void)
1183 return current_binding_level
== global_binding_level
;
1186 /* Return the list of declarations of the current level.
1187 Note that this list is in reverse order unless/until
1188 you nreverse it; and when you do nreverse it, you must
1189 store the result back using `storedecls' or you will lose. */
1194 return current_binding_level
->names
;
1197 /* Create a new `struct binding_level'. */
1199 static struct binding_level
*
1200 make_binding_level (void)
1203 return xmalloc (sizeof (struct binding_level
));
1207 pushlevel (int unused ATTRIBUTE_UNUSED
)
1209 struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1212 /* If this is the top level of a function,
1213 just make sure that NAMED_LABELS is 0. */
1215 if (current_binding_level
== global_binding_level
)
1219 /* Reuse or create a struct for this binding level. */
1221 if (free_binding_level
)
1223 newlevel
= free_binding_level
;
1224 free_binding_level
= free_binding_level
->level_chain
;
1228 newlevel
= make_binding_level ();
1231 /* Add this level to the front of the chain (stack) of levels that
1234 *newlevel
= clear_binding_level
;
1235 newlevel
->level_chain
= current_binding_level
;
1236 current_binding_level
= newlevel
;
1237 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1238 newlevel
->binding_depth
= binding_depth
;
1240 fprintf (stderr
, "push %s level %p pc %d\n",
1241 (is_class_level
) ? "class" : "block", newlevel
, current_pc
);
1244 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1247 /* Exit a binding level.
1248 Pop the level off, and restore the state of the identifier-decl mappings
1249 that were in effect when this level was entered.
1251 If KEEP is nonzero, this level had explicit declarations, so
1252 and create a "block" (a BLOCK node) for the level
1253 to record its declarations and subblocks for symbol table output.
1255 If FUNCTIONBODY is nonzero, this level is the body of a function,
1256 so create a block as if KEEP were set and also clear out all
1259 If REVERSE is nonzero, reverse the order of decls before putting
1260 them into the BLOCK. */
1263 poplevel (int keep
, int reverse
, int functionbody
)
1266 /* The chain of decls was accumulated in reverse order.
1267 Put it into forward order, just for cleanliness. */
1269 tree subblocks
= current_binding_level
->blocks
;
1273 int block_previously_created
;
1275 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1278 if (current_binding_level
->end_pc
!= LARGEST_PC
)
1279 fprintf (stderr
, "pop %s level %p pc %d (end pc %d)\n",
1280 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
,
1281 current_binding_level
->end_pc
);
1283 fprintf (stderr
, "pop %s level %p pc %d\n",
1284 (is_class_level
) ? "class" : "block", current_binding_level
, current_pc
);
1286 if (is_class_level
!= (current_binding_level
== class_binding_level
))
1289 fprintf (stderr
, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1293 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1295 /* Get the decls in the order they were written.
1296 Usually current_binding_level->names is in reverse order.
1297 But parameter decls were previously put in forward order. */
1300 current_binding_level
->names
1301 = decls
= nreverse (current_binding_level
->names
);
1303 decls
= current_binding_level
->names
;
1305 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1306 if (TREE_CODE (decl
) == VAR_DECL
1307 && DECL_LANG_SPECIFIC (decl
) != NULL
1308 && DECL_LOCAL_SLOT_NUMBER (decl
))
1309 LOCAL_VAR_OUT_OF_SCOPE_P (decl
) = 1;
1311 /* If there were any declarations in that level,
1312 or if this level is a function body,
1313 create a BLOCK to record them for the life of this function. */
1316 block_previously_created
= (current_binding_level
->this_block
!= 0);
1317 if (block_previously_created
)
1318 block
= current_binding_level
->this_block
;
1319 else if (keep
|| functionbody
)
1321 block
= make_node (BLOCK
);
1322 TREE_TYPE (block
) = void_type_node
;
1327 /* If any statements have been generated at this level, create a
1328 BIND_EXPR to hold them and copy the variables to it. This
1329 only applies to the bytecode compiler. */
1330 if (current_binding_level
->stmts
)
1333 tree
*var
= &BLOCK_VARS (block
);
1335 /* Copy decls from names list, ignoring labels. */
1338 tree next
= TREE_CHAIN (decl
);
1339 if (TREE_CODE (decl
) != LABEL_DECL
)
1342 var
= &TREE_CHAIN (decl
);
1348 bind
= build (BIND_EXPR
, TREE_TYPE (block
), BLOCK_VARS (block
),
1349 BLOCK_EXPR_BODY (block
), block
);
1351 BIND_EXPR_BODY (bind
) = current_binding_level
->stmts
;
1353 if (BIND_EXPR_BODY (bind
)
1354 && TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind
)))
1355 TREE_SIDE_EFFECTS (bind
) = 1;
1357 /* FIXME: gimplifier brain damage. */
1358 if (BIND_EXPR_BODY (bind
) == NULL
)
1359 BIND_EXPR_BODY (bind
) = build_java_empty_stmt ();
1361 current_binding_level
->stmts
= NULL
;
1365 BLOCK_VARS (block
) = decls
;
1367 BLOCK_SUBBLOCKS (block
) = subblocks
;
1370 /* In each subblock, record that this is its superior. */
1372 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1373 BLOCK_SUPERCONTEXT (link
) = block
;
1375 /* Clear out the meanings of the local variables of this level. */
1377 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1379 tree name
= DECL_NAME (link
);
1380 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1382 /* If the ident. was used or addressed via a local extern decl,
1383 don't forget that fact. */
1384 if (DECL_EXTERNAL (link
))
1386 if (TREE_USED (link
))
1387 TREE_USED (name
) = 1;
1388 if (TREE_ADDRESSABLE (link
))
1389 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1391 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1395 /* Restore all name-meanings of the outer levels
1396 that were shadowed by this level. */
1398 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1399 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1401 /* If the level being exited is the top level of a function,
1402 check over all the labels, and clear out the current
1403 (function local) meanings of their names. */
1407 /* If this is the top level block of a function,
1408 the vars are the function's parameters.
1409 Don't leave them in the BLOCK because they are
1410 found in the FUNCTION_DECL instead. */
1412 BLOCK_VARS (block
) = 0;
1414 /* Clear out the definitions of all label names,
1415 since their scopes end here,
1416 and add them to BLOCK_VARS. */
1419 for (link
= named_labels
; link
; link
= TREE_CHAIN (link
))
1421 tree label
= TREE_VALUE (link
);
1423 if (DECL_INITIAL (label
) == 0)
1425 error ("%Jlabel '%D' used but not defined", label
, label
);
1426 /* Avoid crashing later. */
1427 define_label (input_location
, DECL_NAME (label
));
1429 else if (warn_unused
[UNUSED_LABEL
] && !TREE_USED (label
))
1430 warning ("%Jlabel '%D' defined but not used", label
, label
);
1431 IDENTIFIER_LABEL_VALUE (DECL_NAME (label
)) = 0;
1433 /* Put the labels into the "variables" of the
1434 top-level block, so debugger can see them. */
1435 TREE_CHAIN (label
) = BLOCK_VARS (block
);
1436 BLOCK_VARS (block
) = label
;
1441 /* Pop the current level, and free the structure for reuse. */
1444 struct binding_level
*level
= current_binding_level
;
1445 current_binding_level
= current_binding_level
->level_chain
;
1447 level
->level_chain
= free_binding_level
;
1448 free_binding_level
= level
;
1451 /* Dispose of the block that we just made inside some higher level. */
1454 DECL_INITIAL (current_function_decl
) = block
;
1455 DECL_SAVED_TREE (current_function_decl
) = bind
;
1459 if (!block_previously_created
)
1460 current_binding_level
->blocks
1461 = chainon (current_binding_level
->blocks
, block
);
1463 /* If we did not make a block for the level just exited,
1464 any blocks made for inner levels
1465 (since they cannot be recorded as subblocks in that level)
1466 must be carried forward so they will later become subblocks
1467 of something else. */
1469 current_binding_level
->blocks
1470 = chainon (current_binding_level
->blocks
, subblocks
);
1473 java_add_stmt (bind
);
1476 TREE_USED (block
) = 1;
1481 maybe_pushlevels (int pc
)
1483 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1487 while (pending_local_decls
!= NULL_TREE
&&
1488 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1490 tree
*ptr
= &pending_local_decls
;
1491 tree decl
= *ptr
, next
;
1492 int end_pc
= DECL_LOCAL_END_PC (decl
);
1494 while (*ptr
!= NULL_TREE
1495 && DECL_LOCAL_START_PC (*ptr
) <= pc
1496 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1497 ptr
= &TREE_CHAIN (*ptr
);
1498 pending_local_decls
= *ptr
;
1501 /* Force non-nested range to be nested in current range. */
1502 if (end_pc
> current_binding_level
->end_pc
)
1503 end_pc
= current_binding_level
->end_pc
;
1505 maybe_start_try (pc
, end_pc
);
1509 current_binding_level
->end_pc
= end_pc
;
1510 current_binding_level
->start_pc
= pc
;
1511 current_binding_level
->names
= NULL
;
1512 for ( ; decl
!= NULL_TREE
; decl
= next
)
1514 next
= TREE_CHAIN (decl
);
1515 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl
), decl
);
1519 maybe_start_try (pc
, 0);
1523 maybe_poplevels (int pc
)
1525 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1529 while (current_binding_level
->end_pc
<= pc
)
1531 maybe_end_try (current_binding_level
->start_pc
, pc
);
1534 maybe_end_try (0, pc
);
1537 /* Terminate any binding which began during the range beginning at
1538 start_pc. This tidies up improperly nested local variable ranges
1539 and exception handlers; a variable declared within an exception
1540 range is forcibly terminated when that exception ends. */
1543 force_poplevels (int start_pc
)
1545 while (current_binding_level
->start_pc
> start_pc
)
1547 if (pedantic
&& current_binding_level
->start_pc
> start_pc
)
1548 warning ("%JIn %D: overlapped variable and exception ranges at %d",
1549 current_function_decl
, current_function_decl
,
1550 current_binding_level
->start_pc
);
1551 expand_end_bindings (getdecls (), 1, 0);
1556 /* Insert BLOCK at the end of the list of subblocks of the
1557 current binding level. This is used when a BIND_EXPR is expanded,
1558 to handle the BLOCK node inside the BIND_EXPR. */
1561 insert_block (tree block
)
1563 TREE_USED (block
) = 1;
1564 current_binding_level
->blocks
1565 = chainon (current_binding_level
->blocks
, block
);
1568 /* Set the BLOCK node for the innermost scope
1569 (the one we are currently in). */
1572 set_block (tree block
)
1574 current_binding_level
->this_block
= block
;
1575 current_binding_level
->names
= chainon (current_binding_level
->names
,
1576 BLOCK_VARS (block
));
1577 current_binding_level
->blocks
= chainon (current_binding_level
->blocks
,
1578 BLOCK_SUBBLOCKS (block
));
1581 /* integrate_decl_tree calls this function. */
1584 java_dup_lang_specific_decl (tree node
)
1587 struct lang_decl
*x
;
1589 if (!DECL_LANG_SPECIFIC (node
))
1592 lang_decl_size
= sizeof (struct lang_decl
);
1593 x
= ggc_alloc (lang_decl_size
);
1594 memcpy (x
, DECL_LANG_SPECIFIC (node
), lang_decl_size
);
1595 DECL_LANG_SPECIFIC (node
) = x
;
1599 give_name_to_locals (JCF
*jcf
)
1601 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1602 int code_offset
= DECL_CODE_OFFSET (current_function_decl
);
1604 pending_local_decls
= NULL_TREE
;
1608 n
= JCF_readu2 (jcf
);
1609 for (i
= 0; i
< n
; i
++)
1611 int start_pc
= JCF_readu2 (jcf
);
1612 int length
= JCF_readu2 (jcf
);
1613 int name_index
= JCF_readu2 (jcf
);
1614 int signature_index
= JCF_readu2 (jcf
);
1615 int slot
= JCF_readu2 (jcf
);
1616 tree name
= get_name_constant (jcf
, name_index
);
1617 tree type
= parse_signature (jcf
, signature_index
);
1618 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1620 && length
== DECL_CODE_LENGTH (current_function_decl
))
1622 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1623 DECL_NAME (decl
) = name
;
1624 SET_DECL_ASSEMBLER_NAME (decl
, name
);
1625 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1626 warning ("bad type in parameter debug info");
1631 int end_pc
= start_pc
+ length
;
1632 tree decl
= build_decl (VAR_DECL
, name
, type
);
1633 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1635 warning ("%Jbad PC range for debug info for local '%D'",
1637 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1640 /* Adjust start_pc if necessary so that the local's first
1641 store operation will use the relevant DECL as a
1642 destination. Fore more information, read the leading
1643 comments for expr.c:maybe_adjust_start_pc. */
1644 start_pc
= maybe_adjust_start_pc (jcf
, code_offset
, start_pc
, slot
);
1646 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1647 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1648 DECL_LOCAL_START_PC (decl
) = start_pc
;
1650 /* FIXME: The range used internally for exceptions and local
1651 variable ranges, is a half-open interval:
1652 start_pc <= pc < end_pc. However, the range used in the
1653 Java VM spec is inclusive at both ends:
1654 start_pc <= pc <= end_pc. */
1657 DECL_LOCAL_END_PC (decl
) = end_pc
;
1659 /* Now insert the new decl in the proper place in
1660 pending_local_decls. We are essentially doing an insertion sort,
1661 which works fine, since the list input will normally already
1663 ptr
= &pending_local_decls
;
1664 while (*ptr
!= NULL_TREE
1665 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1666 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1667 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1668 ptr
= &TREE_CHAIN (*ptr
);
1669 TREE_CHAIN (decl
) = *ptr
;
1674 pending_local_decls
= nreverse (pending_local_decls
);
1676 /* Fill in default names for the parameters. */
1677 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1678 parm
!= NULL_TREE
; parm
= TREE_CHAIN (parm
), i
++)
1680 if (DECL_NAME (parm
) == NULL_TREE
)
1682 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1684 DECL_NAME (parm
) = get_identifier ("this");
1688 sprintf (buffer
, "ARG_%d", arg_i
);
1689 DECL_NAME (parm
) = get_identifier (buffer
);
1691 SET_DECL_ASSEMBLER_NAME (parm
, DECL_NAME (parm
));
1697 build_result_decl (tree fndecl
)
1699 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1700 tree result
= DECL_RESULT (fndecl
);
1703 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1704 if (INTEGRAL_TYPE_P (restype
)
1705 && TYPE_PRECISION (restype
) < TYPE_PRECISION (integer_type_node
))
1706 restype
= integer_type_node
;
1707 result
= build_decl (RESULT_DECL
, NULL_TREE
, restype
);
1708 DECL_CONTEXT (result
) = fndecl
;
1709 DECL_RESULT (fndecl
) = result
;
1715 start_java_method (tree fndecl
)
1720 current_function_decl
= fndecl
;
1721 announce_function (fndecl
);
1723 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1724 decl_map
= make_tree_vec (i
);
1725 type_map
= xrealloc (type_map
, i
* sizeof (tree
));
1727 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1728 fprintf (stderr
, "%s:\n", lang_printable_name (fndecl
, 2));
1730 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1731 pushlevel (1); /* Push parameters. */
1733 ptr
= &DECL_ARGUMENTS (fndecl
);
1734 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1735 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1737 tree parm_name
= NULL_TREE
, parm_decl
;
1738 tree parm_type
= TREE_VALUE (tem
);
1739 if (i
>= DECL_MAX_LOCALS (fndecl
))
1742 parm_decl
= build_decl (PARM_DECL
, parm_name
, parm_type
);
1743 DECL_CONTEXT (parm_decl
) = fndecl
;
1744 if (targetm
.calls
.promote_prototypes (parm_type
)
1745 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1746 && INTEGRAL_TYPE_P (parm_type
))
1747 parm_type
= integer_type_node
;
1748 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1751 ptr
= &TREE_CHAIN (parm_decl
);
1753 /* Add parm_decl to the decl_map. */
1754 push_jvm_slot (i
, parm_decl
);
1756 type_map
[i
] = TREE_TYPE (parm_decl
);
1757 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1760 type_map
[i
] = void_type_node
;
1764 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1766 while (i
< DECL_MAX_LOCALS(fndecl
))
1767 type_map
[i
++] = NULL_TREE
;
1769 build_result_decl (fndecl
);
1771 /* Push local variables. */
1776 end_java_method (void)
1778 tree fndecl
= current_function_decl
;
1780 /* pop out of function */
1783 /* pop out of its parameters */
1786 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1788 flag_unit_at_a_time
= 0;
1789 finish_method (fndecl
);
1791 current_function_decl
= NULL_TREE
;
1794 /* Prepare a method for expansion. */
1797 finish_method (tree fndecl
)
1799 tree
*tp
= &DECL_SAVED_TREE (fndecl
);
1801 /* Wrap body of synchronized methods in a monitorenter,
1802 plus monitorexit cleanup. */
1803 if (METHOD_SYNCHRONIZED (fndecl
))
1805 tree enter
, exit
, lock
;
1806 if (METHOD_STATIC (fndecl
))
1807 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1809 lock
= DECL_ARGUMENTS (fndecl
);
1810 BUILD_MONITOR_ENTER (enter
, lock
);
1811 BUILD_MONITOR_EXIT (exit
, lock
);
1812 *tp
= build (COMPOUND_EXPR
, void_type_node
,
1814 build (TRY_FINALLY_EXPR
, void_type_node
, *tp
, exit
));
1817 /* Prepend class initialization for static methods reachable from
1819 if (METHOD_STATIC (fndecl
) && ! METHOD_PRIVATE (fndecl
)
1820 && ! DECL_CLINIT_P (fndecl
)
1821 && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl
))))
1823 tree clas
= DECL_CONTEXT (fndecl
);
1824 tree init
= build (CALL_EXPR
, void_type_node
,
1825 build_address_of (soft_initclass_node
),
1826 build_tree_list (NULL_TREE
, build_class_ref (clas
)),
1828 *tp
= build (COMPOUND_EXPR
, TREE_TYPE (*tp
), init
, *tp
);
1831 /* Convert function tree to GENERIC prior to inlining. */
1832 java_genericize (fndecl
);
1834 /* Store the end of the function, so that we get good line number
1835 info for the epilogue. */
1836 if (DECL_STRUCT_FUNCTION (fndecl
))
1837 cfun
= DECL_STRUCT_FUNCTION (fndecl
);
1839 allocate_struct_function (fndecl
);
1840 cfun
->function_end_locus
.file
= DECL_SOURCE_FILE (fndecl
);
1841 cfun
->function_end_locus
.line
= DECL_FUNCTION_LAST_LINE (fndecl
);
1843 /* Defer inlining and expansion to the cgraph optimizers. */
1844 cgraph_finalize_function (fndecl
, false);
1847 /* Optimize and expand a function's entire body. */
1850 java_expand_body (tree fndecl
)
1852 tree_rest_of_compilation (fndecl
, 0);
1855 /* We pessimistically marked all methods and fields external until we
1856 knew what set of classes we were planning to compile. Now mark those
1857 associated with CLASS to be generated locally as not external. */
1860 java_mark_decl_local (tree decl
)
1862 DECL_EXTERNAL (decl
) = 0;
1864 /* If we've already constructed DECL_RTL, give encode_section_info
1865 a second chance, now that we've changed the flags. */
1866 if (DECL_RTL_SET_P (decl
))
1867 make_decl_rtl (decl
, NULL
);
1871 java_mark_class_local (tree
class)
1875 for (t
= TYPE_FIELDS (class); t
; t
= TREE_CHAIN (t
))
1876 if (FIELD_STATIC (t
))
1877 java_mark_decl_local (t
);
1879 for (t
= TYPE_METHODS (class); t
; t
= TREE_CHAIN (t
))
1880 if (!METHOD_ABSTRACT (t
) && (!METHOD_NATIVE (t
) || flag_jni
))
1881 java_mark_decl_local (t
);
1884 /* Add a statement to a compound_expr. */
1887 add_stmt_to_compound (existing
, type
, stmt
)
1888 tree existing
, type
, stmt
;
1894 tree expr
= build (COMPOUND_EXPR
, type
, existing
, stmt
);
1895 TREE_SIDE_EFFECTS (expr
)
1896 = TREE_SIDE_EFFECTS (existing
) | TREE_SIDE_EFFECTS (stmt
);
1903 /* Add a statement to the compound_expr currently being
1907 java_add_stmt (stmt
)
1911 annotate_with_locus (stmt
, input_location
);
1913 return current_binding_level
->stmts
1914 = add_stmt_to_compound (current_binding_level
->stmts
,
1915 TREE_TYPE (stmt
), stmt
);
1918 /* Add a variable to the current scope. */
1921 java_add_local_var (tree decl
)
1923 tree
*vars
= ¤t_binding_level
->names
;
1925 TREE_CHAIN (decl
) = next
;
1927 DECL_CONTEXT (decl
) = current_function_decl
;
1928 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl
);
1932 /* Return a pointer to the compound_expr currently being
1938 return ¤t_binding_level
->stmts
;
1942 #include "gt-java-decl.h"