1 /* Process declarations and variables for the GNU compiler for the
3 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Java and all Java-based marks are trademarks or registered trademarks
23 of Sun Microsystems, Inc. in the United States and other countries.
24 The Free Software Foundation is independent of Sun Microsystems, Inc. */
26 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
33 #include "java-tree.h"
39 #include "java-except.h"
41 #if defined (DEBUG_JAVA_BINDING_LEVELS)
42 extern void indent PROTO((void));
45 static tree push_jvm_slot PARAMS ((int, tree));
46 static tree lookup_name_current_level PARAMS ((tree));
47 static tree push_promoted_type PARAMS ((const char *, tree));
48 static struct binding_level *make_binding_level PARAMS ((void));
50 /* Set to non-zero value in order to emit class initilization code
51 before static field references. */
52 extern int always_initialize_class_p;
55 #define INT_TYPE_SIZE BITS_PER_WORD
58 /* The DECL_MAP is a mapping from (index, type) to a decl node.
59 If index < max_locals, it is the index of a local variable.
60 if index >= max_locals, then index-max_locals is a stack slot.
61 The DECL_MAP mapping is represented as a TREE_VEC whose elements
62 are a list of decls (VAR_DECL or PARM_DECL) chained by
63 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
64 we search the chain for a decl with a matching TREE_TYPE. */
68 /* A list of local variables VAR_DECLs for this method that we have seen
69 debug information, but we have not reached their starting (byte) PC yet. */
71 tree pending_local_decls = NULL_TREE;
73 /* Push a local variable or stack slot into the decl_map,
74 and assign it an rtl. */
76 #if defined(DEBUG_JAVA_BINDING_LEVELS)
77 int binding_depth = 0;
78 int is_class_level = 0;
86 for (i = 0; i < binding_depth*2; i++)
89 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
92 push_jvm_slot (index, decl)
96 struct rtx_def *rtl = NULL;
97 tree type = TREE_TYPE (decl);
100 DECL_CONTEXT (decl) = current_function_decl;
101 layout_decl (decl, 0);
103 /* See if we have an appropriate rtl (i.e. same mode) at this index.
104 If so, we must use it. */
105 tmp = TREE_VEC_ELT (decl_map, index);
106 while (tmp != NULL_TREE)
108 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
109 rtl = DECL_RTL (tmp);
112 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
115 DECL_RTL (decl) = rtl;
118 if (index >= DECL_MAX_LOCALS (current_function_decl))
119 DECL_REGISTER (decl) = 1;
123 /* Now link the decl into the decl_map. */
124 if (DECL_LANG_SPECIFIC (decl) == NULL)
126 DECL_LANG_SPECIFIC (decl)
127 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
128 DECL_LOCAL_START_PC (decl) = 0;
129 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
130 DECL_LOCAL_SLOT_NUMBER (decl) = index;
132 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
133 TREE_VEC_ELT (decl_map, index) = decl;
137 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
138 that is valid at PC (or -1 if any pc).
139 If there is no existing matching decl, allocate one.
140 If we find a decl with matching modes but different types,
141 we re-use the rtl, but create a new decl. */
144 find_local_variable (index, type, pc)
149 tree decl = TREE_VEC_ELT (decl_map, index);
150 tree best = NULL_TREE;
151 while (decl != NULL_TREE)
155 || (pc >= DECL_LOCAL_START_PC (decl)
156 && pc < DECL_LOCAL_END_PC (decl));
158 if ((TREE_TYPE (decl) == type
159 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
160 && type == ptr_type_node))
163 if (best == NULL_TREE
164 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
165 || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
166 || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
169 decl = DECL_LOCAL_SLOT_CHAIN (decl);
171 if (best != NULL_TREE)
173 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
177 /* Same as find_local_index, except that INDEX is a stack index. */
180 find_stack_slot (index, type)
184 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
190 /* A chain of _DECL nodes for all variables, constants, functions,
191 * and typedef types. These are in the reverse of the order supplied.
195 /* For each level, a list of shadowed outer-level local definitions
196 to be restored when this level is popped.
197 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
198 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
201 /* For each level (except not the global one),
202 a chain of BLOCK nodes for all the levels
203 that were entered and exited one level down. */
206 /* The BLOCK node for this level, if one has been preallocated.
207 If 0, the BLOCK is allocated (if needed) when the level is popped. */
210 /* The binding level which this one is contained in (inherits from). */
211 struct binding_level *level_chain;
213 /* 1 means make a BLOCK for this level regardless of all else.
214 2 for temporary binding contours created by the compiler. */
217 /* Nonzero means make a BLOCK if this level has any subblocks. */
218 char keep_if_subblocks;
220 /* Nonzero if this level can safely have additional
221 cleanup-needing variables added to it. */
222 char more_cleanups_ok;
225 /* The bytecode PC that marks the end of this level. */
227 /* The bytecode PC that marks the start of this level. */
230 #if defined(DEBUG_JAVA_BINDING_LEVELS)
231 /* Binding depth at which this level began. */
232 unsigned binding_depth;
233 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
236 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
238 /* The binding level currently in effect. */
240 static struct binding_level *current_binding_level;
242 /* A chain of binding_level structures awaiting reuse. */
244 static struct binding_level *free_binding_level;
246 /* The outermost binding level, for names of file scope.
247 This is created when the compiler is started and exists
248 through the entire run. */
250 static struct binding_level *global_binding_level;
252 /* A PC value bigger than any PC value we may ever may encounter. */
254 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
256 /* Binding level structures are initialized by copying this one. */
258 static struct binding_level clear_binding_level
259 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
260 NULL_BINDING_LEVEL, 0, 0, 0, 0, LARGEST_PC, 0};
263 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
264 that have names. Here so we can clear out their names' definitions
265 at the end of the function. */
267 static tree named_labels;
269 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
271 static tree shadowed_labels;
274 int flag_traditional;
276 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
278 static int keep_next_level_flag;
280 /* Nonzero means make a BLOCK for the next level pushed
281 if it has subblocks. */
283 static int keep_next_if_subblocks;
285 tree object_type_node;
286 tree unqualified_object_id_node;
287 tree object_ptr_type_node;
288 tree string_type_node;
289 tree string_ptr_type_node;
290 tree throwable_type_node;
291 tree runtime_exception_type_node;
292 tree error_exception_type_node;
293 tree *predef_filenames;
294 int predef_filenames_size;
296 tree boolean_type_node;
298 tree return_address_type_node;
301 tree short_type_node;
305 tree promoted_byte_type_node;
306 tree promoted_short_type_node;
307 tree promoted_char_type_node;
308 tree promoted_boolean_type_node;
310 tree unsigned_byte_type_node;
311 tree unsigned_short_type_node;
312 tree unsigned_int_type_node;
313 tree unsigned_long_type_node;
315 /* The type for struct methodtable. */
316 tree methodtable_type;
317 tree methodtable_ptr_type;
320 tree utf8const_ptr_type;
321 tree class_type_node;
323 tree field_type_node;
324 tree field_ptr_type_node;
325 tree field_info_union_node;
326 tree jexception_type;
327 tree jexception_ptr_type;
328 tree lineNumberEntry_type;
329 tree lineNumbers_type;
330 tree constants_type_node;
332 tree dtable_ptr_type;
333 tree method_type_node;
334 tree method_ptr_type_node;
335 tree nativecode_ptr_array_type_node;
336 tree one_elt_array_domain_type;
337 tree access_flags_type_node;
338 tree class_dtable_decl;
340 /* Expressions that are constants with value zero, of types
341 `long', `float' and `double'. */
343 tree float_zero_node;
344 tree double_zero_node;
346 tree empty_stmt_node;
348 /* Nodes for boolean constants TRUE and FALSE. */
349 tree boolean_true_node, boolean_false_node;
351 tree TYPE_identifier_node;
352 tree init_identifier_node;
353 tree clinit_identifier_node;
354 tree finit_identifier_node;
355 tree void_signature_node;
356 tree length_identifier_node;
357 tree this_identifier_node;
358 tree super_identifier_node;
359 tree continue_identifier_node;
361 tree end_params_node;
363 /* References to internal libjava functions we use. */
364 tree alloc_object_node;
365 tree soft_instanceof_node;
366 tree soft_checkcast_node;
367 tree soft_initclass_node;
368 tree soft_newarray_node;
369 tree soft_anewarray_node;
370 tree soft_multianewarray_node;
371 tree soft_badarrayindex_node;
373 tree soft_checkarraystore_node;
374 tree soft_monitorenter_node;
375 tree soft_monitorexit_node;
376 tree soft_lookupinterfacemethod_node;
378 tree soft_exceptioninfo_call_node;
384 /* Build (and pushdecl) a "promoted type" for all standard
385 types shorter than int. */
388 push_promoted_type (name, actual_type)
392 tree type = make_node (TREE_CODE (actual_type));
394 tree in_min = TYPE_MIN_VALUE (int_type_node);
395 tree in_max = TYPE_MAX_VALUE (int_type_node);
397 tree in_min = TYPE_MIN_VALUE (actual_type);
398 tree in_max = TYPE_MAX_VALUE (actual_type);
400 TYPE_MIN_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_min),
401 TREE_INT_CST_HIGH (in_min));
402 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
403 TYPE_MAX_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_max),
404 TREE_INT_CST_HIGH (in_max));
405 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
406 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
408 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
412 /* Nodes for integer constants. */
413 tree integer_two_node, integer_four_node;
414 tree integer_negative_one_node;
416 /* Return a definition for a builtin function named NAME and whose data type
417 is TYPE. TYPE should be a function type with argument types.
418 FUNCTION_CODE tells later passes how to compile calls to this function.
419 See tree.h for its possible values.
421 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
422 the name to be called if we can't opencode the function. */
425 builtin_function (name, type, function_code, class, library_name)
429 enum built_in_class class;
430 const char *library_name;
432 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
433 DECL_EXTERNAL (decl) = 1;
434 TREE_PUBLIC (decl) = 1;
436 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
437 make_decl_rtl (decl, NULL_PTR, 1);
439 DECL_BUILT_IN_CLASS (decl) = class;
440 DECL_FUNCTION_CODE (decl) = function_code;
445 init_decl_processing ()
447 register tree endlink;
448 tree field = NULL_TREE;
451 current_function_decl = NULL;
452 current_binding_level = NULL_BINDING_LEVEL;
453 free_binding_level = NULL_BINDING_LEVEL;
454 pushlevel (0); /* make the binding_level structure for global names */
455 global_binding_level = current_binding_level;
457 error_mark_node = make_node (ERROR_MARK);
458 TREE_TYPE (error_mark_node) = error_mark_node;
460 /* Create sizetype first - needed for other types. */
461 initialize_sizetypes ();
462 set_sizetype (make_unsigned_type (POINTER_SIZE));
463 size_zero_node = build_int_2 (0, 0);
464 TREE_TYPE (size_zero_node) = sizetype;
465 size_one_node = build_int_2 (1, 0);
466 TREE_TYPE (size_one_node) = sizetype;
468 byte_type_node = make_signed_type (8);
469 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
470 short_type_node = make_signed_type (16);
471 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
472 int_type_node = make_signed_type (32);
473 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
474 long_type_node = make_signed_type (64);
475 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
477 unsigned_byte_type_node = make_unsigned_type (8);
478 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
479 unsigned_byte_type_node));
480 unsigned_short_type_node = make_unsigned_type (16);
481 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
482 unsigned_short_type_node));
483 unsigned_int_type_node = make_unsigned_type (32);
484 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
485 unsigned_int_type_node));
486 unsigned_long_type_node = make_unsigned_type (64);
487 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
488 unsigned_long_type_node));
490 integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
492 integer_zero_node = build_int_2 (0, 0);
493 integer_one_node = build_int_2 (1, 0);
494 integer_two_node = build_int_2 (2, 0);
495 integer_four_node = build_int_2 (4, 0);
496 integer_negative_one_node = build_int_2 (-1, 0);
498 long_zero_node = build_int_2 (0, 0);
499 TREE_TYPE (long_zero_node) = long_type_node;
501 void_type_node = make_node (VOID_TYPE);
502 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
503 layout_type (void_type_node); /* Uses size_zero_node */
504 ptr_type_node = build_pointer_type (void_type_node);
505 t = make_node (VOID_TYPE);
506 layout_type (t); /* Uses size_zero_node */
507 return_address_type_node = build_pointer_type (t);
509 null_pointer_node = build_int_2 (0, 0);
510 TREE_TYPE (null_pointer_node) = ptr_type_node;
512 /* Used by the parser to represent empty statements and blocks. */
513 empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
514 CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
517 /* Make a type to be the domain of a few array types
518 whose domains don't really matter.
519 200 is small enough that it always fits in size_t
520 and large enough that it can hold most function names for the
521 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
522 short_array_type_node = build_prim_array_type (short_type_node, 200);
524 char_type_node = make_node (CHAR_TYPE);
525 TYPE_PRECISION (char_type_node) = 16;
526 fixup_unsigned_type (char_type_node);
527 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
529 boolean_type_node = make_node (BOOLEAN_TYPE);
530 TYPE_PRECISION (boolean_type_node) = 1;
531 fixup_unsigned_type (boolean_type_node);
532 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
534 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
535 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
537 promoted_byte_type_node
538 = push_promoted_type ("promoted_byte", byte_type_node);
539 promoted_short_type_node
540 = push_promoted_type ("promoted_short", short_type_node);
541 promoted_char_type_node
542 = push_promoted_type ("promoted_char", char_type_node);
543 promoted_boolean_type_node
544 = push_promoted_type ("promoted_boolean", boolean_type_node);
546 float_type_node = make_node (REAL_TYPE);
547 TYPE_PRECISION (float_type_node) = 32;
548 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
550 layout_type (float_type_node);
552 double_type_node = make_node (REAL_TYPE);
553 TYPE_PRECISION (double_type_node) = 64;
554 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
556 layout_type (double_type_node);
558 float_zero_node = build_real (float_type_node, dconst0);
559 double_zero_node = build_real (double_type_node, dconst0);
561 /* As your adding items here, please update the code right after
562 this section, so that the filename containing the source code of
563 the pre-defined class gets registered correctly. */
564 unqualified_object_id_node = get_identifier ("Object");
565 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
566 object_ptr_type_node = promote_type (object_type_node);
567 string_type_node = lookup_class (get_identifier ("java.lang.String"));
568 string_ptr_type_node = promote_type (string_type_node);
569 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
570 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
571 runtime_exception_type_node =
572 lookup_class (get_identifier ("java.lang.RuntimeException"));
573 error_exception_type_node =
574 lookup_class (get_identifier ("java.lang.Error"));
576 /* This section has to be updated as items are added to the previous
578 predef_filenames_size = 6;
579 predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
580 predef_filenames [0] = get_identifier ("java/lang/Class.java");
581 predef_filenames [1] = get_identifier ("java/lang/Error.java");
582 predef_filenames [2] = get_identifier ("java/lang/Object.java");
583 predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
584 predef_filenames [4] = get_identifier ("java/lang/String.java");
585 predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
587 methodtable_type = make_node (RECORD_TYPE);
588 layout_type (methodtable_type);
589 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
590 methodtable_ptr_type = build_pointer_type (methodtable_type);
592 TYPE_identifier_node = get_identifier ("TYPE");
593 init_identifier_node = get_identifier ("<init>");
594 clinit_identifier_node = get_identifier ("<clinit>");
595 finit_identifier_node = get_identifier ("$finit$");
596 void_signature_node = get_identifier ("()V");
597 length_identifier_node = get_identifier ("length");
598 this_identifier_node = get_identifier ("this");
599 super_identifier_node = get_identifier ("super");
600 continue_identifier_node = get_identifier ("continue");
602 /* for lack of a better place to put this stub call */
603 init_expr_processing();
605 utf8const_type = make_node (RECORD_TYPE);
606 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
607 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
608 FINISH_RECORD (utf8const_type);
609 utf8const_ptr_type = build_pointer_type (utf8const_type);
611 constants_type_node = make_node (RECORD_TYPE);
612 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
613 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
614 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
615 FINISH_RECORD (constants_type_node);
616 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
618 access_flags_type_node = unsigned_short_type_node;
620 dtable_type = make_node (RECORD_TYPE);
621 dtable_ptr_type = build_pointer_type (dtable_type);
623 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
624 PUSH_FIELD (object_type_node, field, "sync_info", ptr_type_node);
625 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
626 FIELD_PRIVATE (t) = 1;
627 FINISH_RECORD (object_type_node);
629 class_dtable_decl = build_dtable_decl (class_type_node);
630 TREE_STATIC (class_dtable_decl) = 1;
631 DECL_ARTIFICIAL (class_dtable_decl) = 1;
632 DECL_IGNORED_P (class_dtable_decl) = 1;
633 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
635 field_type_node = make_node (RECORD_TYPE);
636 field_ptr_type_node = build_pointer_type (field_type_node);
637 method_type_node = make_node (RECORD_TYPE);
638 method_ptr_type_node = build_pointer_type (method_type_node);
640 set_super_info (0, class_type_node, object_type_node, 0);
641 set_super_info (0, string_type_node, object_type_node, 0);
642 class_ptr_type = build_pointer_type (class_type_node);
644 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
645 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
646 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
647 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
648 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
649 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
650 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
651 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
652 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
653 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
654 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
655 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
656 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
657 PUSH_FIELD (class_type_node, field, "interfaces",
658 build_pointer_type (class_ptr_type));
659 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
660 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
661 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
662 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
663 PUSH_FIELD (class_type_node, field, "depth", short_type_node);
664 PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
665 PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
666 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
667 FIELD_PRIVATE (t) = 1;
668 push_super_field (class_type_node, object_type_node);
669 FINISH_RECORD (class_type_node);
670 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
672 field_info_union_node = make_node (UNION_TYPE);
673 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
674 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
676 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
678 layout_type (field_info_union_node);
680 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
681 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
682 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
683 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
684 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
685 FINISH_RECORD (field_type_node);
686 CLASS_LOADED_P (field_type_node) = 1;
687 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
689 one_elt_array_domain_type = build_index_type (integer_one_node);
690 nativecode_ptr_array_type_node
691 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
693 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
694 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
695 FINISH_RECORD (dtable_type);
696 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
698 #define jint_type int_type_node
699 #define jint_ptr_type ptr_type_node
701 jexception_type = make_node (RECORD_TYPE);
702 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
703 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
704 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
705 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
706 FINISH_RECORD (jexception_type);
707 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
708 jexception_ptr_type = build_pointer_type (jexception_type);
710 lineNumberEntry_type = make_node (RECORD_TYPE);
711 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
712 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
713 FINISH_RECORD (lineNumberEntry_type);
715 lineNumbers_type = make_node (RECORD_TYPE);
716 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
717 FINISH_RECORD (lineNumbers_type);
719 #define instn_ptr_type_node ptr_type_node /* XXX JH */
721 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
723 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
724 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
725 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
726 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
727 FINISH_RECORD (method_type_node);
728 CLASS_LOADED_P (method_type_node) = 1;
729 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
731 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
733 t = tree_cons (NULL_TREE, class_ptr_type,
734 tree_cons (NULL_TREE, int_type_node, endlink));
735 alloc_object_node = builtin_function ("_Jv_AllocObject",
736 build_function_type (ptr_type_node, t),
737 0, NOT_BUILT_IN, NULL_PTR);
738 DECL_IS_MALLOC (alloc_object_node) = 1;
739 soft_initclass_node = builtin_function ("_Jv_InitClass",
740 build_function_type (void_type_node,
744 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
745 throw_node[0] = builtin_function ("_Jv_Throw",
746 build_function_type (ptr_type_node, t),
747 0, NOT_BUILT_IN, NULL_PTR);
748 /* Mark throw_nodes as `noreturn' functions with side effects. */
749 TREE_THIS_VOLATILE (throw_node[0]) = 1;
750 TREE_SIDE_EFFECTS (throw_node[0]) = 1;
751 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
752 throw_node[1] = builtin_function ("_Jv_Sjlj_Throw",
753 build_function_type (ptr_type_node, t),
754 0, NOT_BUILT_IN, NULL_PTR);
755 TREE_THIS_VOLATILE (throw_node[1]) = 1;
756 TREE_SIDE_EFFECTS (throw_node[1]) = 1;
757 t = build_function_type (int_type_node, endlink);
758 soft_monitorenter_node
759 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
761 soft_monitorexit_node
762 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
765 t = tree_cons (NULL_TREE, int_type_node,
766 tree_cons (NULL_TREE, int_type_node, endlink));
768 = builtin_function ("_Jv_NewArray",
769 build_function_type(ptr_type_node, t),
770 0, NOT_BUILT_IN, NULL_PTR);
771 DECL_IS_MALLOC (soft_newarray_node) = 1;
773 t = tree_cons (NULL_TREE, int_type_node,
774 tree_cons (NULL_TREE, class_ptr_type,
775 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
777 = builtin_function ("_Jv_NewObjectArray",
778 build_function_type (ptr_type_node, t),
779 0, NOT_BUILT_IN, NULL_PTR);
780 DECL_IS_MALLOC (soft_anewarray_node) = 1;
782 t = tree_cons (NULL_TREE, ptr_type_node,
783 tree_cons (NULL_TREE, int_type_node, endlink));
784 soft_multianewarray_node
785 = builtin_function ("_Jv_NewMultiArray",
786 build_function_type (ptr_type_node, t),
787 0, NOT_BUILT_IN, NULL_PTR);
788 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
790 t = build_function_type (void_type_node,
791 tree_cons (NULL_TREE, int_type_node, endlink));
792 soft_badarrayindex_node
793 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
794 0, NOT_BUILT_IN, NULL_PTR);
795 /* Mark soft_badarrayindex_node as a `noreturn' function with side
797 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
798 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
800 t = tree_cons (NULL_TREE, class_ptr_type,
801 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
803 = builtin_function ("_Jv_CheckCast",
804 build_function_type (ptr_type_node, t),
805 0, NOT_BUILT_IN, NULL_PTR);
806 t = tree_cons (NULL_TREE, object_ptr_type_node,
807 tree_cons (NULL_TREE, class_ptr_type, endlink));
809 = builtin_function ("_Jv_IsInstanceOf",
810 build_function_type (boolean_type_node, t),
811 0, NOT_BUILT_IN, NULL_PTR);
812 t = tree_cons (NULL_TREE, object_ptr_type_node,
813 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
814 soft_checkarraystore_node
815 = builtin_function ("_Jv_CheckArrayStore",
816 build_function_type (void_type_node, t),
817 0, NOT_BUILT_IN, NULL_PTR);
818 t = tree_cons (NULL_TREE, ptr_type_node,
819 tree_cons (NULL_TREE, ptr_type_node,
820 tree_cons (NULL_TREE, int_type_node, endlink)));
821 soft_lookupinterfacemethod_node
822 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
823 build_function_type (ptr_type_node, t),
824 0, NOT_BUILT_IN, NULL_PTR);
825 t = tree_cons (NULL_TREE, double_type_node,
826 tree_cons (NULL_TREE, double_type_node, endlink));
828 = builtin_function ("__builtin_fmod",
829 build_function_type (double_type_node, t),
830 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod");
832 soft_exceptioninfo_call_node
836 (builtin_function ("_Jv_exception_info",
837 build_function_type (ptr_type_node, endlink),
838 0, NOT_BUILT_IN, NULL_PTR)),
839 NULL_TREE, NULL_TREE);
840 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
842 t = tree_cons (NULL_TREE, float_type_node,
843 tree_cons (NULL_TREE, float_type_node, endlink));
845 = builtin_function ("__builtin_fmodf",
846 build_function_type (float_type_node, t),
847 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf");
851 = builtin_function ("_Jv_divI",
852 build_function_type (int_type_node, t),
853 0, NOT_BUILT_IN, NULL_PTR);
856 = builtin_function ("_Jv_remI",
857 build_function_type (int_type_node, t),
858 0, NOT_BUILT_IN, NULL_PTR);
861 = builtin_function ("_Jv_divJ",
862 build_function_type (long_type_node, t),
863 0, NOT_BUILT_IN, NULL_PTR);
866 = builtin_function ("_Jv_remJ",
867 build_function_type (long_type_node, t),
868 0, NOT_BUILT_IN, NULL_PTR);
870 init_class_processing ();
874 /* Look up NAME in the current binding level and its superiors
875 in the namespace of variables, functions and typedefs.
876 Return a ..._DECL node of some kind representing its definition,
877 or return 0 if it is undefined. */
884 if (current_binding_level != global_binding_level
885 && IDENTIFIER_LOCAL_VALUE (name))
886 val = IDENTIFIER_LOCAL_VALUE (name);
888 val = IDENTIFIER_GLOBAL_VALUE (name);
892 /* Similar to `lookup_name' but look only at current binding level and
893 the previous one if its the parameter level. */
896 lookup_name_current_level (name)
901 if (current_binding_level == global_binding_level)
902 return IDENTIFIER_GLOBAL_VALUE (name);
904 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
907 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
908 if (DECL_NAME (t) == name)
914 /* Use a binding level to record a labeled block declaration */
917 push_labeled_block (lb)
920 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
921 register struct binding_level *b = current_binding_level;
922 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
924 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
925 TREE_CHAIN (lb) = b->names;
927 IDENTIFIER_LOCAL_VALUE (name) = lb;
930 /* Pop the current binding level, reinstalling values for the previous
936 struct binding_level *b = current_binding_level;
937 tree label = b->names;
938 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
941 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
942 TREE_VALUE (b->shadowed);
944 /* Pop the current level, and free the structure for reuse. */
945 current_binding_level = current_binding_level->level_chain;
946 b->level_chain = free_binding_level;
947 free_binding_level = b;
950 /* Record a decl-node X as belonging to the current lexical scope.
951 Check for errors (such as an incompatible declaration for the same
952 name already seen in the same scope).
954 Returns either X or an old decl for the same name.
955 If an old decl is returned, it may have been smashed
956 to agree with what X says. */
963 register tree name = DECL_NAME (x);
964 register struct binding_level *b = current_binding_level;
966 DECL_CONTEXT (x) = current_function_decl;
972 t = lookup_name_current_level (name);
973 if (t != 0 && t == error_mark_node)
974 /* error_mark_node is 0 for a while during initialization! */
977 error_with_decl (x, "`%s' used prior to declaration");
982 file = DECL_SOURCE_FILE (t);
983 line = DECL_SOURCE_LINE (t);
986 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
987 to point to the TYPE_DECL.
988 Since Java does not have typedefs, a type can only have
989 one (true) name, given by a class, interface, or builtin. */
990 if (TREE_CODE (x) == TYPE_DECL
991 && TYPE_NAME (TREE_TYPE (x)) == 0
992 && TREE_TYPE (x) != error_mark_node)
994 TYPE_NAME (TREE_TYPE (x)) = x;
995 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
998 /* This name is new in its binding level.
999 Install the new declaration and return it. */
1000 if (b == global_binding_level)
1002 /* Install a global value. */
1004 IDENTIFIER_GLOBAL_VALUE (name) = x;
1008 /* Here to install a non-global value. */
1009 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1010 IDENTIFIER_LOCAL_VALUE (name) = x;
1013 /* Warn if shadowing an argument at the top level of the body. */
1014 if (oldlocal != 0 && !DECL_EXTERNAL (x)
1015 /* This warning doesn't apply to the parms of a nested fcn. */
1016 && ! current_binding_level->parm_flag
1017 /* Check that this is one level down from the parms. */
1018 && current_binding_level->level_chain->parm_flag
1019 /* Check that the decl being shadowed
1020 comes from the parm level, one level up. */
1021 && chain_member (oldlocal, current_binding_level->level_chain->names))
1023 if (TREE_CODE (oldlocal) == PARM_DECL)
1024 pedwarn ("declaration of `%s' shadows a parameter",
1025 IDENTIFIER_POINTER (name));
1027 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1028 IDENTIFIER_POINTER (name));
1031 /* Maybe warn if shadowing something else. */
1032 else if (warn_shadow && !DECL_EXTERNAL (x)
1033 /* No shadow warnings for internally generated vars. */
1034 && DECL_SOURCE_LINE (x) != 0
1035 /* No shadow warnings for vars made for inlining. */
1036 && ! DECL_FROM_INLINE (x))
1038 const char *warnstring = 0;
1040 if (TREE_CODE (x) == PARM_DECL
1041 && current_binding_level->level_chain->parm_flag)
1042 /* Don't warn about the parm names in function declarator
1043 within a function declarator.
1044 It would be nice to avoid warning in any function
1045 declarator in a declaration, as opposed to a definition,
1046 but there is no way to tell it's not a definition. */
1048 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1049 warnstring = "declaration of `%s' shadows a parameter";
1050 else if (oldlocal != 0)
1051 warnstring = "declaration of `%s' shadows previous local";
1052 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1053 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1054 warnstring = "declaration of `%s' shadows global declaration";
1057 warning (warnstring, IDENTIFIER_POINTER (name));
1061 /* If storing a local value, there may already be one (inherited).
1062 If so, record it for restoration when this binding level ends. */
1064 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1068 /* Put decls on list in reverse order.
1069 We will reverse them later if necessary. */
1070 TREE_CHAIN (x) = b->names;
1076 pushdecl_force_head (x)
1079 current_binding_level->names = x;
1082 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1085 pushdecl_top_level (x)
1089 register struct binding_level *b = current_binding_level;
1091 current_binding_level = global_binding_level;
1093 current_binding_level = b;
1097 /* Nonzero if we are currently in the global binding level. */
1100 global_bindings_p ()
1102 return current_binding_level == global_binding_level;
1105 /* Return the list of declarations of the current level.
1106 Note that this list is in reverse order unless/until
1107 you nreverse it; and when you do nreverse it, you must
1108 store the result back using `storedecls' or you will lose. */
1113 return current_binding_level->names;
1116 /* Create a new `struct binding_level'. */
1119 struct binding_level *
1120 make_binding_level ()
1123 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1128 int unused ATTRIBUTE_UNUSED;
1130 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1133 /* If this is the top level of a function,
1134 just make sure that NAMED_LABELS is 0. */
1136 if (current_binding_level == global_binding_level)
1140 /* Reuse or create a struct for this binding level. */
1142 if (free_binding_level)
1144 newlevel = free_binding_level;
1145 free_binding_level = free_binding_level->level_chain;
1149 newlevel = make_binding_level ();
1152 /* Add this level to the front of the chain (stack) of levels that
1155 *newlevel = clear_binding_level;
1156 newlevel->level_chain = current_binding_level;
1157 current_binding_level = newlevel;
1158 newlevel->keep = keep_next_level_flag;
1159 keep_next_level_flag = 0;
1160 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1161 keep_next_if_subblocks = 0;
1162 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1163 newlevel->binding_depth = binding_depth;
1165 fprintf (stderr, "push %s level 0x%08x pc %d\n",
1166 (is_class_level) ? "class" : "block", newlevel, current_pc);
1169 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1172 /* Exit a binding level.
1173 Pop the level off, and restore the state of the identifier-decl mappings
1174 that were in effect when this level was entered.
1176 If KEEP is nonzero, this level had explicit declarations, so
1177 and create a "block" (a BLOCK node) for the level
1178 to record its declarations and subblocks for symbol table output.
1180 If FUNCTIONBODY is nonzero, this level is the body of a function,
1181 so create a block as if KEEP were set and also clear out all
1184 If REVERSE is nonzero, reverse the order of decls before putting
1185 them into the BLOCK. */
1188 poplevel (keep, reverse, functionbody)
1194 /* The chain of decls was accumulated in reverse order.
1195 Put it into forward order, just for cleanliness. */
1197 tree subblocks = current_binding_level->blocks;
1200 int block_previously_created;
1202 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1205 if (current_binding_level->end_pc != LARGEST_PC)
1206 fprintf (stderr, "pop %s level 0x%08x pc %d (end pc %d)\n",
1207 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1208 current_binding_level->end_pc);
1210 fprintf (stderr, "pop %s level 0x%08x pc %d\n",
1211 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1213 if (is_class_level != (current_binding_level == class_binding_level))
1216 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1220 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1222 keep |= current_binding_level->keep;
1224 /* Get the decls in the order they were written.
1225 Usually current_binding_level->names is in reverse order.
1226 But parameter decls were previously put in forward order. */
1229 current_binding_level->names
1230 = decls = nreverse (current_binding_level->names);
1232 decls = current_binding_level->names;
1234 /* Output any nested inline functions within this block
1235 if they weren't already output. */
1237 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1238 if (TREE_CODE (decl) == FUNCTION_DECL
1239 && ! TREE_ASM_WRITTEN (decl)
1240 && DECL_INITIAL (decl) != 0
1241 && TREE_ADDRESSABLE (decl))
1243 /* If this decl was copied from a file-scope decl
1244 on account of a block-scope extern decl,
1245 propagate TREE_ADDRESSABLE to the file-scope decl.
1247 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1248 true, since then the decl goes through save_for_inline_copying. */
1249 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1250 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1251 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1254 push_function_context ();
1255 output_inline_function (decl);
1256 pop_function_context ();
1260 /* If there were any declarations in that level,
1261 or if this level is a function body,
1262 create a BLOCK to record them for the life of this function. */
1265 block_previously_created = (current_binding_level->this_block != 0);
1266 if (block_previously_created)
1267 block = current_binding_level->this_block;
1268 else if (keep || functionbody
1269 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1270 block = make_node (BLOCK);
1273 BLOCK_VARS (block) = decls;
1274 BLOCK_SUBBLOCKS (block) = subblocks;
1277 /* In each subblock, record that this is its superior. */
1279 for (link = subblocks; link; link = TREE_CHAIN (link))
1280 BLOCK_SUPERCONTEXT (link) = block;
1282 /* Clear out the meanings of the local variables of this level. */
1284 for (link = decls; link; link = TREE_CHAIN (link))
1286 tree name = DECL_NAME (link);
1287 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1289 /* If the ident. was used or addressed via a local extern decl,
1290 don't forget that fact. */
1291 if (DECL_EXTERNAL (link))
1293 if (TREE_USED (link))
1294 TREE_USED (name) = 1;
1295 if (TREE_ADDRESSABLE (link))
1296 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1298 IDENTIFIER_LOCAL_VALUE (name) = 0;
1302 /* Restore all name-meanings of the outer levels
1303 that were shadowed by this level. */
1305 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1306 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1308 /* If the level being exited is the top level of a function,
1309 check over all the labels, and clear out the current
1310 (function local) meanings of their names. */
1314 /* If this is the top level block of a function,
1315 the vars are the function's parameters.
1316 Don't leave them in the BLOCK because they are
1317 found in the FUNCTION_DECL instead. */
1319 BLOCK_VARS (block) = 0;
1321 /* Clear out the definitions of all label names,
1322 since their scopes end here,
1323 and add them to BLOCK_VARS. */
1326 for (link = named_labels; link; link = TREE_CHAIN (link))
1328 register tree label = TREE_VALUE (link);
1330 if (DECL_INITIAL (label) == 0)
1332 error_with_decl (label, "label `%s' used but not defined");
1333 /* Avoid crashing later. */
1334 define_label (input_filename, lineno,
1337 else if (warn_unused && !TREE_USED (label))
1338 warning_with_decl (label, "label `%s' defined but not used");
1339 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1341 /* Put the labels into the "variables" of the
1342 top-level block, so debugger can see them. */
1343 TREE_CHAIN (label) = BLOCK_VARS (block);
1344 BLOCK_VARS (block) = label;
1349 /* Pop the current level, and free the structure for reuse. */
1352 register struct binding_level *level = current_binding_level;
1353 current_binding_level = current_binding_level->level_chain;
1355 level->level_chain = free_binding_level;
1356 free_binding_level = level;
1359 /* Dispose of the block that we just made inside some higher level. */
1361 DECL_INITIAL (current_function_decl) = block;
1364 if (!block_previously_created)
1365 current_binding_level->blocks
1366 = chainon (current_binding_level->blocks, block);
1368 /* If we did not make a block for the level just exited,
1369 any blocks made for inner levels
1370 (since they cannot be recorded as subblocks in that level)
1371 must be carried forward so they will later become subblocks
1372 of something else. */
1374 current_binding_level->blocks
1375 = chainon (current_binding_level->blocks, subblocks);
1377 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1378 binding contour so that they point to the appropriate construct, i.e.
1379 either to the current FUNCTION_DECL node, or else to the BLOCK node
1380 we just constructed.
1382 Note that for tagged types whose scope is just the formal parameter
1383 list for some function type specification, we can't properly set
1384 their TYPE_CONTEXTs here, because we don't have a pointer to the
1385 appropriate FUNCTION_TYPE node readily available to us. For those
1386 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1387 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1388 node which will represent the "scope" for these "parameter list local"
1393 TREE_USED (block) = 1;
1398 maybe_pushlevels (pc)
1401 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1405 while (pending_local_decls != NULL_TREE &&
1406 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1408 tree *ptr = &pending_local_decls;
1410 int end_pc = DECL_LOCAL_END_PC (decl);
1412 while (*ptr != NULL_TREE
1413 && DECL_LOCAL_START_PC (*ptr) <= pc
1414 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1415 ptr = &TREE_CHAIN (*ptr);
1416 pending_local_decls = *ptr;
1419 /* Force non-nested range to be nested in current range. */
1420 if (end_pc > current_binding_level->end_pc)
1421 end_pc = current_binding_level->end_pc;
1423 maybe_start_try (pc, end_pc);
1426 expand_start_bindings (0);
1428 current_binding_level->end_pc = end_pc;
1429 current_binding_level->start_pc = pc;
1430 current_binding_level->names = decl;
1431 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1433 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1437 maybe_start_try (pc, 0);
1441 maybe_poplevels (pc)
1444 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1448 while (current_binding_level->end_pc <= pc)
1450 expand_end_bindings (getdecls (), 1, 0);
1451 maybe_end_try (current_binding_level->start_pc, pc);
1454 maybe_end_try (0, pc);
1457 /* Terminate any binding which began during the range beginning at
1458 start_pc. This tidies up improperly nested local variable ranges
1459 and exception handlers; a variable declared within an exception
1460 range is forcibly terminated when that exception ends. */
1463 force_poplevels (start_pc)
1466 while (current_binding_level->start_pc > start_pc)
1468 if (pedantic && current_binding_level->start_pc > start_pc)
1469 warning_with_decl (current_function_decl,
1470 "In %s: overlapped variable and exception ranges at %d",
1471 current_binding_level->start_pc);
1472 expand_end_bindings (getdecls (), 1, 0);
1477 /* Insert BLOCK at the end of the list of subblocks of the
1478 current binding level. This is used when a BIND_EXPR is expanded,
1479 to handle the BLOCK node inside the BIND_EXPR. */
1482 insert_block (block)
1485 TREE_USED (block) = 1;
1486 current_binding_level->blocks
1487 = chainon (current_binding_level->blocks, block);
1490 /* Set the BLOCK node for the innermost scope
1491 (the one we are currently in). */
1495 register tree block;
1497 current_binding_level->this_block = block;
1500 /* integrate_decl_tree calls this function. */
1503 copy_lang_decl (node)
1507 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1508 : sizeof (struct lang_decl);
1509 struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1510 bcopy ((PTR) DECL_LANG_SPECIFIC (node), (PTR) x, lang_decl_size);
1511 DECL_LANG_SPECIFIC (node) = x;
1514 /* If DECL has a cleanup, build and return that cleanup here.
1515 This is a callback called by expand_expr. */
1518 maybe_build_cleanup (decl)
1519 tree decl ATTRIBUTE_UNUSED;
1521 /* There are no cleanups in Java (I think). */
1526 give_name_to_locals (jcf)
1529 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1531 pending_local_decls = NULL_TREE;
1535 n = JCF_readu2 (jcf);
1536 for (i = 0; i < n; i++)
1538 int start_pc = JCF_readu2 (jcf);
1539 int length = JCF_readu2 (jcf);
1540 int name_index = JCF_readu2 (jcf);
1541 int signature_index = JCF_readu2 (jcf);
1542 int slot = JCF_readu2 (jcf);
1543 tree name = get_name_constant (jcf, name_index);
1544 tree type = parse_signature (jcf, signature_index);
1545 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1547 && length == DECL_CODE_LENGTH (current_function_decl))
1549 tree decl = TREE_VEC_ELT (decl_map, slot);
1550 DECL_NAME (decl) = name;
1551 DECL_ASSEMBLER_NAME (decl) = name;
1552 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1553 warning ("bad type in parameter debug info");
1558 int end_pc = start_pc + length;
1559 tree decl = build_decl (VAR_DECL, name, type);
1560 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1562 warning_with_decl (decl,
1563 "bad PC range for debug info for local `%s'");
1564 end_pc = DECL_CODE_LENGTH (current_function_decl);
1566 DECL_LANG_SPECIFIC (decl)
1567 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1568 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1569 DECL_LOCAL_START_PC (decl) = start_pc;
1571 /* FIXME: The range used internally for exceptions and local
1572 variable ranges, is a half-open interval:
1573 start_pc <= pc < end_pc. However, the range used in the
1574 Java VM spec is inclusive at both ends:
1575 start_pc <= pc <= end_pc. */
1578 DECL_LOCAL_END_PC (decl) = end_pc;
1580 /* Now insert the new decl in the proper place in
1581 pending_local_decls. We are essentially doing an insertion sort,
1582 which works fine, since the list input will normally already
1584 ptr = &pending_local_decls;
1585 while (*ptr != NULL_TREE
1586 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1587 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1588 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1589 ptr = &TREE_CHAIN (*ptr);
1590 TREE_CHAIN (decl) = *ptr;
1595 pending_local_decls = nreverse (pending_local_decls);
1597 /* Fill in default names for the parameters. */
1598 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1599 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1601 if (DECL_NAME (parm) == NULL_TREE)
1603 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1605 DECL_NAME (parm) = get_identifier ("this");
1609 sprintf (buffer, "ARG_%d", arg_i);
1610 DECL_NAME (parm) = get_identifier (buffer);
1612 DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1618 build_result_decl (fndecl)
1621 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1622 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1623 if (INTEGRAL_TYPE_P (restype)
1624 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1625 restype = integer_type_node;
1626 return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
1630 /* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
1631 to emit initialization code for each test flag. */
1634 emit_init_test_initialization (entry, key)
1635 struct hash_entry *entry;
1636 hash_table_key key ATTRIBUTE_UNUSED;
1638 struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
1639 expand_decl (ite->init_test_decl);
1641 expand_expr_stmt (build (MODIFY_EXPR, boolean_type_node,
1642 ite->init_test_decl, boolean_false_node));
1648 complete_start_java_method (fndecl)
1651 if (! flag_emit_class_files)
1653 /* Initialize the RTL code for the function. */
1654 init_function_start (fndecl, input_filename, lineno);
1656 /* Set up parameters and prepare for return, for the function. */
1657 expand_function_start (fndecl, 0);
1659 /* Emit initialization code for test flags. */
1660 if (! always_initialize_class_p)
1661 hash_traverse (&DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1662 emit_init_test_initialization, 0);
1665 /* Allocate further tree nodes temporarily during compilation
1666 of this function only. */
1667 temporary_allocation ();
1670 /* If this fcn was already referenced via a block-scope `extern' decl (or
1671 an implicit decl), propagate certain information about the usage. */
1672 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1673 TREE_ADDRESSABLE (current_function_decl) = 1;
1677 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1678 && ! flag_emit_class_files
1679 && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1681 tree clas = DECL_CONTEXT (fndecl);
1682 tree init = build (CALL_EXPR, void_type_node,
1683 build_address_of (soft_initclass_node),
1684 build_tree_list (NULL_TREE, build_class_ref (clas)),
1686 TREE_SIDE_EFFECTS (init) = 1;
1687 expand_expr_stmt (init);
1690 /* Push local variables. Function compiled from source code are
1691 using a different local variables management, and for them,
1692 pushlevel shouldn't be called from here. */
1693 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1696 if (! flag_emit_class_files)
1697 expand_start_bindings (1);
1700 if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1702 /* Warp function body with a monitorenter plus monitorexit cleanup. */
1703 tree enter, exit, lock;
1704 if (METHOD_STATIC (fndecl))
1705 lock = build_class_ref (DECL_CONTEXT (fndecl));
1707 lock = DECL_ARGUMENTS (fndecl);
1708 BUILD_MONITOR_ENTER (enter, lock);
1709 BUILD_MONITOR_EXIT (exit, lock);
1710 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1712 expand_expr_stmt (enter);
1713 expand_decl_cleanup (NULL_TREE, exit);
1717 tree function_body = DECL_FUNCTION_BODY (fndecl);
1718 tree body = BLOCK_EXPR_BODY (function_body);
1719 lock = build (WITH_CLEANUP_EXPR, void_type_node,
1720 enter, NULL_TREE, exit);
1721 TREE_SIDE_EFFECTS (lock) = 1;
1722 lock = build (COMPOUND_EXPR, TREE_TYPE (body), lock, body);
1723 TREE_SIDE_EFFECTS (lock) = 1;
1724 lock = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (body), lock);
1725 TREE_SIDE_EFFECTS (lock) = 1;
1726 BLOCK_EXPR_BODY (function_body) = lock;
1732 start_java_method (fndecl)
1738 current_function_decl = fndecl;
1739 announce_function (fndecl);
1741 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1742 decl_map = make_tree_vec (i);
1743 type_map = (tree *) oballoc (i * sizeof (tree));
1745 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1746 fprintf (stderr, "%s:\n", (*decl_printable_name) (fndecl, 2));
1748 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1749 pushlevel (1); /* Push parameters. */
1751 ptr = &DECL_ARGUMENTS (fndecl);
1752 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1753 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1755 tree parm_name = NULL_TREE, parm_decl;
1756 tree parm_type = TREE_VALUE (tem);
1757 if (i >= DECL_MAX_LOCALS(fndecl))
1758 fatal ("function has more parameters than local slots");
1760 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1761 DECL_CONTEXT (parm_decl) = fndecl;
1762 if (PROMOTE_PROTOTYPES
1763 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1764 && INTEGRAL_TYPE_P (parm_type))
1765 parm_type = integer_type_node;
1766 DECL_ARG_TYPE (parm_decl) = parm_type;
1769 ptr = &TREE_CHAIN (parm_decl);
1771 /* Add parm_decl to the decl_map. */
1772 push_jvm_slot (i, parm_decl);
1774 type_map[i] = TREE_TYPE (parm_decl);
1775 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1778 type_map[i] = void_type_node;
1782 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1784 while (i < DECL_MAX_LOCALS(fndecl))
1785 type_map[i++] = NULL_TREE;
1787 build_result_decl (fndecl);
1788 complete_start_java_method (fndecl);
1794 tree fndecl = current_function_decl;
1795 int flag_asynchronous_exceptions = asynchronous_exceptions;
1797 expand_end_bindings (getdecls (), 1, 0);
1798 /* pop out of function */
1801 /* pop out of its parameters */
1804 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1808 /* Generate rtl for function exit. */
1809 expand_function_end (input_filename, lineno, 0);
1811 /* FIXME: If the current method contains any exception handlers,
1812 force asynchronous_exceptions: this is necessary because signal
1813 handlers in libjava may throw exceptions. This is far from being
1814 a perfect solution, but it's better than doing nothing at all.*/
1816 asynchronous_exceptions = 1;
1818 /* Run the optimizers and output assembler code for this function. */
1819 rest_of_compilation (fndecl);
1821 current_function_decl = NULL_TREE;
1822 permanent_allocation (1);
1823 asynchronous_exceptions = flag_asynchronous_exceptions;