1 /* Process declarations and variables for the GNU compiler for the
4 Copyright (C) 1996, 97-98, 1999 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC 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 GNU CC 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 GNU CC; 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. */
32 #include "java-tree.h"
37 static tree push_jvm_slot PROTO ((int, tree));
38 static tree builtin_function PROTO ((const char *, tree,
39 enum built_in_function, const char *));
40 static tree lookup_name_current_level PROTO ((tree));
43 #define INT_TYPE_SIZE BITS_PER_WORD
46 /* The DECL_MAP is a mapping from (index, type) to a decl node.
47 If index < max_locals, it is the index of a local variable.
48 if index >= max_locals, then index-max_locals is a stack slot.
49 The DECL_MAP mapping is represented as a TREE_VEC whose elements
50 are a list of decls (VAR_DECL or PARM_DECL) chained by
51 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
52 we search the chain for a decl with a matching TREE_TYPE. */
56 /* A list of local variables VAR_DECLs for this method that we have seen
57 debug information, but we have not reached their starting (byte) PC yet. */
59 tree pending_local_decls = NULL_TREE;
61 /* Push a local variable or stack slot into the decl_map,
62 and assign it an rtl. */
65 push_jvm_slot (index, decl)
69 struct rtx_def *rtl = NULL;
70 tree type = TREE_TYPE (decl);
73 DECL_CONTEXT (decl) = current_function_decl;
74 layout_decl (decl, 0);
76 /* See if we have an appropriate rtl (i.e. same mode) at this index.
77 If so, we must use it. */
78 tmp = TREE_VEC_ELT (decl_map, index);
79 while (tmp != NULL_TREE)
81 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
85 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
88 DECL_RTL (decl) = rtl;
91 if (index >= DECL_MAX_LOCALS (current_function_decl))
92 DECL_REGISTER (decl) = 1;
96 /* Now link the decl into the decl_map. */
97 if (DECL_LANG_SPECIFIC (decl) == NULL)
99 DECL_LANG_SPECIFIC (decl)
100 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
101 DECL_LOCAL_START_PC (decl) = 0;
102 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
103 DECL_LOCAL_SLOT_NUMBER (decl) = index;
105 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
106 TREE_VEC_ELT (decl_map, index) = decl;
110 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
111 that is valid at PC (or -1 if any pc).
112 If there is no existing matching decl, allocate one.
113 If we find a decl with matching modes but different types,
114 we re-use the rtl, but create a new decl. */
117 find_local_variable (index, type, pc)
122 tree decl = TREE_VEC_ELT (decl_map, index);
123 tree best = NULL_TREE;
124 while (decl != NULL_TREE)
128 || (pc >= DECL_LOCAL_START_PC (decl)
129 && pc < DECL_LOCAL_END_PC (decl));
131 if ((TREE_TYPE (decl) == type
132 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
133 && type == ptr_type_node))
136 if (best == NULL_TREE
137 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
138 || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
139 || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
142 decl = DECL_LOCAL_SLOT_CHAIN (decl);
144 if (best != NULL_TREE)
146 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
150 /* Same as find_local_index, except that INDEX is a stack index. */
153 find_stack_slot (index, type)
157 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
163 /* A chain of _DECL nodes for all variables, constants, functions,
164 * and typedef types. These are in the reverse of the order supplied.
168 /* For each level, a list of shadowed outer-level local definitions
169 to be restored when this level is popped.
170 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
171 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
174 /* For each level (except not the global one),
175 a chain of BLOCK nodes for all the levels
176 that were entered and exited one level down. */
179 /* The BLOCK node for this level, if one has been preallocated.
180 If 0, the BLOCK is allocated (if needed) when the level is popped. */
183 /* The binding level which this one is contained in (inherits from). */
184 struct binding_level *level_chain;
186 /* 1 means make a BLOCK for this level regardless of all else.
187 2 for temporary binding contours created by the compiler. */
190 /* Nonzero means make a BLOCK if this level has any subblocks. */
191 char keep_if_subblocks;
193 /* Nonzero if this level can safely have additional
194 cleanup-needing variables added to it. */
195 char more_cleanups_ok;
198 /* The bytecode PC that marks the end of this level. */
202 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
204 /* The binding level currently in effect. */
206 static struct binding_level *current_binding_level;
208 /* A chain of binding_level structures awaiting reuse. */
210 static struct binding_level *free_binding_level;
212 /* The outermost binding level, for names of file scope.
213 This is created when the compiler is started and exists
214 through the entire run. */
216 static struct binding_level *global_binding_level;
218 /* Binding level structures are initialized by copying this one. */
220 static struct binding_level clear_binding_level
221 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
222 NULL_BINDING_LEVEL, 0, 0, 0, 0, 1000000000};
225 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
226 that have names. Here so we can clear out their names' definitions
227 at the end of the function. */
229 static tree named_labels;
231 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
233 static tree shadowed_labels;
236 int flag_traditional;
238 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
240 static int keep_next_level_flag;
242 /* Nonzero means make a BLOCK for the next level pushed
243 if it has subblocks. */
245 static int keep_next_if_subblocks;
247 /* The FUNCTION_DECL for the function currently being compiled,
248 or 0 if between functions. */
249 tree current_function_decl;
251 /* The type node for the ordinary character type. */
254 tree object_type_node;
255 tree unqualified_object_id_node;
256 tree object_ptr_type_node;
257 tree string_type_node;
258 tree string_ptr_type_node;
259 tree throwable_type_node;
260 tree runtime_exception_type_node;
261 tree error_exception_type_node;
262 tree *predef_filenames;
263 int predef_filenames_size;
265 tree boolean_type_node;
267 tree float_type_node;
268 tree double_type_node;
270 /* a VOID_TYPE node. */
274 tree return_address_type_node;
276 tree integer_type_node;
279 tree short_type_node;
283 tree promoted_byte_type_node;
284 tree promoted_short_type_node;
285 tree promoted_char_type_node;
286 tree promoted_boolean_type_node;
288 tree unsigned_byte_type_node;
289 tree unsigned_short_type_node;
290 tree unsigned_int_type_node;
291 tree unsigned_long_type_node;
293 /* The type for struct methodtable. */
294 tree methodtable_type;
295 tree methodtable_ptr_type;
298 tree utf8const_ptr_type;
299 tree class_type_node;
301 tree field_type_node;
302 tree field_ptr_type_node;
303 tree field_info_union_node;
304 tree jexception_type;
305 tree jexception_ptr_type;
306 tree lineNumberEntry_type;
307 tree lineNumbers_type;
308 tree constants_type_node;
310 tree dtable_ptr_type;
311 tree method_type_node;
312 tree method_ptr_type_node;
313 tree nativecode_ptr_array_type_node;
314 tree one_elt_array_domain_type;
315 tree access_flags_type_node;
316 tree class_dtable_decl;
318 /* a node which has tree code ERROR_MARK, and whose type is itself.
319 All erroneous expressions are replaced with this node. All functions
320 that accept nodes as arguments should avoid generating error messages
321 if this node is one of the arguments, since it is undesirable to get
322 multiple error messages from one error in the input. */
324 tree error_mark_node;
326 /* Two expressions that are constants with value zero.
327 The first is of type `int', the second of type `void *'.
328 Other of type `long', `float' and `double' follow. */
329 tree integer_zero_node;
330 tree null_pointer_node;
332 tree float_zero_node;
333 tree double_zero_node;
335 tree empty_stmt_node;
337 /* Nodes for boolean constants TRUE and FALSE. */
338 tree boolean_true_node, boolean_false_node;
340 tree TYPE_identifier_node;
341 tree init_identifier_node;
342 tree clinit_identifier_node;
343 tree finit_identifier_node;
344 tree void_signature_node;
345 tree length_identifier_node;
346 tree this_identifier_node;
347 tree super_identifier_node;
348 tree continue_identifier_node;
350 tree end_params_node;
352 /* References to internal libjava functions we use. */
353 tree alloc_object_node;
354 tree soft_instanceof_node;
355 tree soft_checkcast_node;
356 tree soft_initclass_node;
357 tree soft_newarray_node;
358 tree soft_anewarray_node;
359 tree soft_multianewarray_node;
360 tree soft_badarrayindex_node;
362 tree soft_checkarraystore_node;
363 tree soft_monitorenter_node;
364 tree soft_monitorexit_node;
365 tree soft_lookupinterfacemethod_node;
367 tree soft_exceptioninfo_call_node;
369 /* Build (and pushdecl) a "promoted type" for all standard
370 types shorter than int. */
373 push_promoted_type (name, actual_type)
377 tree type = make_node (TREE_CODE (actual_type));
379 tree in_min = TYPE_MIN_VALUE (int_type_node);
380 tree in_max = TYPE_MAX_VALUE (int_type_node);
382 tree in_min = TYPE_MIN_VALUE (actual_type);
383 tree in_max = TYPE_MAX_VALUE (actual_type);
385 TYPE_MIN_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_min),
386 TREE_INT_CST_HIGH (in_min));
387 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
388 TYPE_MAX_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_max),
389 TREE_INT_CST_HIGH (in_max));
390 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
391 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
393 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
397 /* Nodes for integer constants. */
398 tree integer_one_node, integer_two_node, integer_four_node;
399 tree integer_negative_one_node;
401 /* Return a definition for a builtin function named NAME and whose data type
402 is TYPE. TYPE should be a function type with argument types.
403 FUNCTION_CODE tells later passes how to compile calls to this function.
404 See tree.h for its possible values.
406 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
407 the name to be called if we can't opencode the function. */
410 builtin_function (name, type, function_code, library_name)
413 enum built_in_function function_code;
414 const char *library_name;
416 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
417 DECL_EXTERNAL (decl) = 1;
418 TREE_PUBLIC (decl) = 1;
420 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
421 make_decl_rtl (decl, NULL_PTR, 1);
423 if (function_code != NOT_BUILT_IN)
425 DECL_BUILT_IN (decl) = 1;
426 DECL_FUNCTION_CODE (decl) = function_code;
432 init_decl_processing ()
434 register tree endlink;
438 current_function_decl = NULL;
439 current_binding_level = NULL_BINDING_LEVEL;
440 free_binding_level = NULL_BINDING_LEVEL;
441 pushlevel (0); /* make the binding_level structure for global names */
442 global_binding_level = current_binding_level;
444 error_mark_node = make_node (ERROR_MARK);
445 TREE_TYPE (error_mark_node) = error_mark_node;
447 /* Create sizetype first - needed for other types. */
448 sizetype = make_unsigned_type (POINTER_SIZE);
449 size_zero_node = build_int_2 (0, 0);
450 TREE_TYPE (size_zero_node) = sizetype;
451 size_one_node = build_int_2 (1, 0);
452 TREE_TYPE (size_one_node) = sizetype;
454 byte_type_node = make_signed_type (8);
455 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
456 short_type_node = make_signed_type (16);
457 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
458 int_type_node = make_signed_type (32);
459 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
460 long_type_node = make_signed_type (64);
461 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
463 unsigned_byte_type_node = make_unsigned_type (8);
464 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
465 unsigned_byte_type_node));
466 unsigned_short_type_node = make_unsigned_type (16);
467 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
468 unsigned_short_type_node));
469 unsigned_int_type_node = make_unsigned_type (32);
470 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
471 unsigned_int_type_node));
472 unsigned_long_type_node = make_unsigned_type (64);
473 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
474 unsigned_long_type_node));
476 integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
478 integer_zero_node = build_int_2 (0, 0);
479 integer_one_node = build_int_2 (1, 0);
480 integer_two_node = build_int_2 (2, 0);
481 integer_four_node = build_int_2 (4, 0);
482 integer_negative_one_node = build_int_2 (-1, 0);
484 long_zero_node = build_int_2 (0, 0);
485 TREE_TYPE (long_zero_node) = long_type_node;
487 void_type_node = make_node (VOID_TYPE);
488 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
489 layout_type (void_type_node); /* Uses size_zero_node */
490 ptr_type_node = build_pointer_type (void_type_node);
491 t = make_node (VOID_TYPE);
492 layout_type (t); /* Uses size_zero_node */
493 return_address_type_node = build_pointer_type (t);
495 null_pointer_node = build_int_2 (0, 0);
496 TREE_TYPE (null_pointer_node) = ptr_type_node;
498 /* Used by the parser to represent empty statements and blocks. */
499 empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
500 CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
503 /* Make a type to be the domain of a few array types
504 whose domains don't really matter.
505 200 is small enough that it always fits in size_t
506 and large enough that it can hold most function names for the
507 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
508 short_array_type_node = build_prim_array_type (short_type_node, 200);
510 char_type_node = make_node (CHAR_TYPE);
511 TYPE_PRECISION (char_type_node) = 16;
512 fixup_unsigned_type (char_type_node);
513 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
515 boolean_type_node = make_node (BOOLEAN_TYPE);
516 TYPE_PRECISION (boolean_type_node) = 1;
517 fixup_unsigned_type (boolean_type_node);
518 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
520 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
521 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
523 promoted_byte_type_node
524 = push_promoted_type ("promoted_byte", byte_type_node);
525 promoted_short_type_node
526 = push_promoted_type ("promoted_short", short_type_node);
527 promoted_char_type_node
528 = push_promoted_type ("promoted_char", char_type_node);
529 promoted_boolean_type_node
530 = push_promoted_type ("promoted_boolean", boolean_type_node);
532 float_type_node = make_node (REAL_TYPE);
533 TYPE_PRECISION (float_type_node) = 32;
534 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
536 layout_type (float_type_node);
538 double_type_node = make_node (REAL_TYPE);
539 TYPE_PRECISION (double_type_node) = 64;
540 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
542 layout_type (double_type_node);
544 float_zero_node = build_real (float_type_node, dconst0);
545 double_zero_node = build_real (double_type_node, dconst0);
547 /* As your adding items here, please update the code right after
548 this section, so that the filename containing the source code of
549 the pre-defined class gets registered correctly. */
550 unqualified_object_id_node = get_identifier ("Object");
551 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
552 object_ptr_type_node = promote_type (object_type_node);
553 string_type_node = lookup_class (get_identifier ("java.lang.String"));
554 string_ptr_type_node = promote_type (string_type_node);
555 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
556 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
557 runtime_exception_type_node =
558 lookup_class (get_identifier ("java.lang.RuntimeException"));
559 error_exception_type_node =
560 lookup_class (get_identifier ("java.lang.Error"));
562 /* This section has to be updated as items are added to the previous
564 predef_filenames_size = 6;
565 predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
566 predef_filenames [0] = get_identifier ("java/lang/Class.java");
567 predef_filenames [1] = get_identifier ("java/lang/Error.java");
568 predef_filenames [2] = get_identifier ("java/lang/Object.java");
569 predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
570 predef_filenames [4] = get_identifier ("java/lang/String.java");
571 predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
573 methodtable_type = make_node (RECORD_TYPE);
574 layout_type (methodtable_type);
575 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
576 methodtable_ptr_type = build_pointer_type (methodtable_type);
578 TYPE_identifier_node = get_identifier ("TYPE");
579 init_identifier_node = get_identifier ("<init>");
580 clinit_identifier_node = get_identifier ("<clinit>");
581 finit_identifier_node = get_identifier ("$finit$");
582 void_signature_node = get_identifier ("()V");
583 length_identifier_node = get_identifier ("length");
584 this_identifier_node = get_identifier ("this");
585 super_identifier_node = get_identifier ("super");
586 continue_identifier_node = get_identifier ("continue");
588 /* for lack of a better place to put this stub call */
589 init_expr_processing();
591 utf8const_type = make_node (RECORD_TYPE);
592 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
593 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
594 FINISH_RECORD (utf8const_type);
595 utf8const_ptr_type = build_pointer_type (utf8const_type);
597 constants_type_node = make_node (RECORD_TYPE);
598 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
599 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
600 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
601 FINISH_RECORD (constants_type_node);
602 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
604 access_flags_type_node = unsigned_short_type_node;
606 dtable_type = make_node (RECORD_TYPE);
607 dtable_ptr_type = build_pointer_type (dtable_type);
609 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
610 PUSH_FIELD (object_type_node, field, "sync_info", ptr_type_node);
611 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
612 FIELD_PRIVATE (t) = 1;
613 FINISH_RECORD (object_type_node);
615 class_dtable_decl = build_dtable_decl (class_type_node);
616 TREE_STATIC (class_dtable_decl) = 1;
617 DECL_ARTIFICIAL (class_dtable_decl) = 1;
618 DECL_IGNORED_P (class_dtable_decl) = 1;
619 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
621 field_type_node = make_node (RECORD_TYPE);
622 field_ptr_type_node = build_pointer_type (field_type_node);
623 method_type_node = make_node (RECORD_TYPE);
624 method_ptr_type_node = build_pointer_type (method_type_node);
626 set_super_info (0, class_type_node, object_type_node, 0);
627 set_super_info (0, string_type_node, object_type_node, 0);
628 class_ptr_type = build_pointer_type (class_type_node);
630 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
631 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
632 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
633 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
634 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
635 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
636 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
637 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
638 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
639 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
640 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
641 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
642 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
643 PUSH_FIELD (class_type_node, field, "interfaces",
644 build_pointer_type (class_ptr_type));
645 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
646 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
647 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
648 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
649 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
650 FIELD_PRIVATE (t) = 1;
651 push_super_field (class_type_node, object_type_node);
652 FINISH_RECORD (class_type_node);
653 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
655 field_info_union_node = make_node (UNION_TYPE);
656 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
657 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
659 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
661 layout_type (field_info_union_node);
663 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
664 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
665 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
666 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
667 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
668 FINISH_RECORD (field_type_node);
669 CLASS_LOADED_P (field_type_node) = 1;
670 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
672 one_elt_array_domain_type = build_index_type (integer_one_node);
673 nativecode_ptr_array_type_node
674 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
676 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
677 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
678 FINISH_RECORD (dtable_type);
679 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
681 #define jint_type int_type_node
682 #define jint_ptr_type ptr_type_node
684 jexception_type = make_node (RECORD_TYPE);
685 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
686 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
687 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
688 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
689 FINISH_RECORD (jexception_type);
690 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
691 jexception_ptr_type = build_pointer_type (jexception_type);
693 lineNumberEntry_type = make_node (RECORD_TYPE);
694 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
695 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
696 FINISH_RECORD (lineNumberEntry_type);
698 lineNumbers_type = make_node (RECORD_TYPE);
699 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
700 FINISH_RECORD (lineNumbers_type);
702 #define instn_ptr_type_node ptr_type_node /* XXX JH */
704 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
706 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
707 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
708 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
709 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
710 FINISH_RECORD (method_type_node);
711 CLASS_LOADED_P (method_type_node) = 1;
712 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
714 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
716 t = tree_cons (NULL_TREE, class_ptr_type,
717 tree_cons (NULL_TREE, int_type_node, endlink));
718 alloc_object_node = builtin_function ("_Jv_AllocObject",
719 build_function_type (ptr_type_node, t),
720 NOT_BUILT_IN, NULL_PTR);
721 soft_initclass_node = builtin_function ("_Jv_InitClass",
722 build_function_type (void_type_node,
724 NOT_BUILT_IN, NULL_PTR);
725 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
726 throw_node = builtin_function ("_Jv_Throw",
727 build_function_type (ptr_type_node, t),
728 NOT_BUILT_IN, NULL_PTR);
729 t = build_function_type (int_type_node, endlink);
730 soft_monitorenter_node
731 = builtin_function ("_Jv_MonitorEnter", t, NOT_BUILT_IN, NULL_PTR);
732 soft_monitorexit_node
733 = builtin_function ("_Jv_MonitorExit", t, NOT_BUILT_IN, NULL_PTR);
735 t = tree_cons (NULL_TREE, int_type_node,
736 tree_cons (NULL_TREE, int_type_node, endlink));
738 = builtin_function ("_Jv_NewArray",
739 build_function_type(ptr_type_node, t),
740 NOT_BUILT_IN, NULL_PTR );
742 t = tree_cons (NULL_TREE, int_type_node,
743 tree_cons (NULL_TREE, class_ptr_type,
744 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
746 = builtin_function ("_Jv_NewObjectArray",
747 build_function_type (ptr_type_node, t),
748 NOT_BUILT_IN, NULL_PTR );
750 t = tree_cons (NULL_TREE, ptr_type_node,
751 tree_cons (NULL_TREE, int_type_node, endlink));
752 soft_multianewarray_node
753 = builtin_function ("_Jv_NewMultiArray",
754 build_function_type (ptr_type_node, t),
755 NOT_BUILT_IN, NULL_PTR );
757 t = build_function_type (void_type_node,
758 tree_cons (NULL_TREE, int_type_node, endlink));
759 soft_badarrayindex_node
760 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
761 NOT_BUILT_IN, NULL_PTR);
762 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
763 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
765 t = tree_cons (NULL_TREE, class_ptr_type,
766 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
768 = builtin_function ("_Jv_CheckCast",
769 build_function_type (ptr_type_node, t),
770 NOT_BUILT_IN, NULL_PTR);
771 t = tree_cons (NULL_TREE, object_ptr_type_node,
772 tree_cons (NULL_TREE, class_ptr_type, endlink));
774 = builtin_function ("_Jv_IsInstanceOf",
775 build_function_type (promoted_boolean_type_node, t),
776 NOT_BUILT_IN, NULL_PTR);
777 t = tree_cons (NULL_TREE, object_ptr_type_node,
778 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
779 soft_checkarraystore_node
780 = builtin_function ("_Jv_CheckArrayStore",
781 build_function_type (void_type_node, t),
782 NOT_BUILT_IN, NULL_PTR);
783 t = tree_cons (NULL_TREE, ptr_type_node,
784 tree_cons (NULL_TREE, ptr_type_node,
785 tree_cons (NULL_TREE, ptr_type_node, endlink)));
786 soft_lookupinterfacemethod_node
787 = builtin_function ("_Jv_LookupInterfaceMethod",
788 build_function_type (ptr_type_node, t),
789 NOT_BUILT_IN, NULL_PTR);
790 t = tree_cons (NULL_TREE, double_type_node,
791 tree_cons (NULL_TREE, double_type_node, endlink));
793 = builtin_function ("__builtin_fmod",
794 build_function_type (double_type_node, t),
795 BUILT_IN_FMOD, "fmod");
797 soft_exceptioninfo_call_node
801 (builtin_function ("_Jv_exception_info",
802 build_function_type (ptr_type_node, endlink),
803 NOT_BUILT_IN, NULL_PTR)),
804 NULL_TREE, NULL_TREE);
805 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
807 t = tree_cons (NULL_TREE, float_type_node,
808 tree_cons (NULL_TREE, float_type_node, endlink));
810 = builtin_function ("__builtin_fmodf",
811 build_function_type (float_type_node, t),
812 BUILT_IN_FMOD, "fmodf");
815 init_class_processing ();
819 /* Look up NAME in the current binding level and its superiors
820 in the namespace of variables, functions and typedefs.
821 Return a ..._DECL node of some kind representing its definition,
822 or return 0 if it is undefined. */
829 if (current_binding_level != global_binding_level
830 && IDENTIFIER_LOCAL_VALUE (name))
831 val = IDENTIFIER_LOCAL_VALUE (name);
833 val = IDENTIFIER_GLOBAL_VALUE (name);
837 /* Similar to `lookup_name' but look only at current binding level and
838 the previous one if its the parameter level. */
841 lookup_name_current_level (name)
846 if (current_binding_level == global_binding_level)
847 return IDENTIFIER_GLOBAL_VALUE (name);
849 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
852 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
853 if (DECL_NAME (t) == name)
859 /* Use a binding level to record a labeled block declaration */
862 push_labeled_block (lb)
865 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
866 register struct binding_level *b = current_binding_level;
867 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
869 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
870 TREE_CHAIN (lb) = b->names;
872 IDENTIFIER_LOCAL_VALUE (name) = lb;
875 /* Pop the current binding level, reinstalling values for the previous
881 struct binding_level *b = current_binding_level;
882 tree label = b->names;
883 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
886 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
887 TREE_VALUE (b->shadowed);
889 /* Pop the current level, and free the structure for reuse. */
890 current_binding_level = current_binding_level->level_chain;
891 b->level_chain = free_binding_level;
892 free_binding_level = b;
895 /* Record a decl-node X as belonging to the current lexical scope.
896 Check for errors (such as an incompatible declaration for the same
897 name already seen in the same scope).
899 Returns either X or an old decl for the same name.
900 If an old decl is returned, it may have been smashed
901 to agree with what X says. */
908 register tree name = DECL_NAME (x);
909 register struct binding_level *b = current_binding_level;
911 DECL_CONTEXT (x) = current_function_decl;
917 t = lookup_name_current_level (name);
918 if (t != 0 && t == error_mark_node)
919 /* error_mark_node is 0 for a while during initialization! */
922 error_with_decl (x, "`%s' used prior to declaration");
927 file = DECL_SOURCE_FILE (t);
928 line = DECL_SOURCE_LINE (t);
931 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
932 to point to the TYPE_DECL.
933 Since Java does not have typedefs, a type can only have
934 one (true) name, given by a class, interface, or builtin. */
935 if (TREE_CODE (x) == TYPE_DECL
936 && TYPE_NAME (TREE_TYPE (x)) == 0
937 && TREE_TYPE (x) != error_mark_node)
939 TYPE_NAME (TREE_TYPE (x)) = x;
940 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
943 /* This name is new in its binding level.
944 Install the new declaration and return it. */
945 if (b == global_binding_level)
947 /* Install a global value. */
949 IDENTIFIER_GLOBAL_VALUE (name) = x;
953 /* Here to install a non-global value. */
954 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
955 IDENTIFIER_LOCAL_VALUE (name) = x;
958 /* Warn if shadowing an argument at the top level of the body. */
959 if (oldlocal != 0 && !DECL_EXTERNAL (x)
960 /* This warning doesn't apply to the parms of a nested fcn. */
961 && ! current_binding_level->parm_flag
962 /* Check that this is one level down from the parms. */
963 && current_binding_level->level_chain->parm_flag
964 /* Check that the decl being shadowed
965 comes from the parm level, one level up. */
966 && chain_member (oldlocal, current_binding_level->level_chain->names))
968 if (TREE_CODE (oldlocal) == PARM_DECL)
969 pedwarn ("declaration of `%s' shadows a parameter",
970 IDENTIFIER_POINTER (name));
972 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
973 IDENTIFIER_POINTER (name));
976 /* Maybe warn if shadowing something else. */
977 else if (warn_shadow && !DECL_EXTERNAL (x)
978 /* No shadow warnings for internally generated vars. */
979 && DECL_SOURCE_LINE (x) != 0
980 /* No shadow warnings for vars made for inlining. */
981 && ! DECL_FROM_INLINE (x))
983 char *warnstring = 0;
985 if (TREE_CODE (x) == PARM_DECL
986 && current_binding_level->level_chain->parm_flag)
987 /* Don't warn about the parm names in function declarator
988 within a function declarator.
989 It would be nice to avoid warning in any function
990 declarator in a declaration, as opposed to a definition,
991 but there is no way to tell it's not a definition. */
993 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
994 warnstring = "declaration of `%s' shadows a parameter";
995 else if (oldlocal != 0)
996 warnstring = "declaration of `%s' shadows previous local";
997 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
998 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
999 warnstring = "declaration of `%s' shadows global declaration";
1002 warning (warnstring, IDENTIFIER_POINTER (name));
1006 /* If storing a local value, there may already be one (inherited).
1007 If so, record it for restoration when this binding level ends. */
1009 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1013 /* Put decls on list in reverse order.
1014 We will reverse them later if necessary. */
1015 TREE_CHAIN (x) = b->names;
1021 pushdecl_force_head (x)
1024 current_binding_level->names = x;
1027 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1030 pushdecl_top_level (x)
1034 register struct binding_level *b = current_binding_level;
1036 current_binding_level = global_binding_level;
1038 current_binding_level = b;
1042 /* Nonzero if we are currently in the global binding level. */
1045 global_bindings_p ()
1047 return current_binding_level == global_binding_level;
1050 /* Return the list of declarations of the current level.
1051 Note that this list is in reverse order unless/until
1052 you nreverse it; and when you do nreverse it, you must
1053 store the result back using `storedecls' or you will lose. */
1058 return current_binding_level->names;
1061 /* Create a new `struct binding_level'. */
1064 struct binding_level *
1065 make_binding_level ()
1068 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1073 int unused ATTRIBUTE_UNUSED;
1075 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1078 /* If this is the top level of a function,
1079 just make sure that NAMED_LABELS is 0. */
1081 if (current_binding_level == global_binding_level)
1085 /* Reuse or create a struct for this binding level. */
1087 if (free_binding_level)
1089 newlevel = free_binding_level;
1090 free_binding_level = free_binding_level->level_chain;
1094 newlevel = make_binding_level ();
1097 /* Add this level to the front of the chain (stack) of levels that
1100 *newlevel = clear_binding_level;
1101 newlevel->level_chain = current_binding_level;
1102 current_binding_level = newlevel;
1103 newlevel->keep = keep_next_level_flag;
1104 keep_next_level_flag = 0;
1105 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1106 keep_next_if_subblocks = 0;
1109 /* Exit a binding level.
1110 Pop the level off, and restore the state of the identifier-decl mappings
1111 that were in effect when this level was entered.
1113 If KEEP is nonzero, this level had explicit declarations, so
1114 and create a "block" (a BLOCK node) for the level
1115 to record its declarations and subblocks for symbol table output.
1117 If FUNCTIONBODY is nonzero, this level is the body of a function,
1118 so create a block as if KEEP were set and also clear out all
1121 If REVERSE is nonzero, reverse the order of decls before putting
1122 them into the BLOCK. */
1125 poplevel (keep, reverse, functionbody)
1131 /* The chain of decls was accumulated in reverse order.
1132 Put it into forward order, just for cleanliness. */
1134 tree subblocks = current_binding_level->blocks;
1137 int block_previously_created;
1139 keep |= current_binding_level->keep;
1141 /* Get the decls in the order they were written.
1142 Usually current_binding_level->names is in reverse order.
1143 But parameter decls were previously put in forward order. */
1146 current_binding_level->names
1147 = decls = nreverse (current_binding_level->names);
1149 decls = current_binding_level->names;
1151 /* Output any nested inline functions within this block
1152 if they weren't already output. */
1154 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1155 if (TREE_CODE (decl) == FUNCTION_DECL
1156 && ! TREE_ASM_WRITTEN (decl)
1157 && DECL_INITIAL (decl) != 0
1158 && TREE_ADDRESSABLE (decl))
1160 /* If this decl was copied from a file-scope decl
1161 on account of a block-scope extern decl,
1162 propagate TREE_ADDRESSABLE to the file-scope decl.
1164 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1165 true, since then the decl goes through save_for_inline_copying. */
1166 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1167 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1168 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1171 push_function_context ();
1172 output_inline_function (decl);
1173 pop_function_context ();
1177 /* If there were any declarations in that level,
1178 or if this level is a function body,
1179 create a BLOCK to record them for the life of this function. */
1182 block_previously_created = (current_binding_level->this_block != 0);
1183 if (block_previously_created)
1184 block = current_binding_level->this_block;
1185 else if (keep || functionbody
1186 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1187 block = make_node (BLOCK);
1190 BLOCK_VARS (block) = decls;
1191 BLOCK_TYPE_TAGS (block) = NULL_TREE;
1192 BLOCK_SUBBLOCKS (block) = subblocks;
1193 remember_end_note (block);
1196 /* In each subblock, record that this is its superior. */
1198 for (link = subblocks; link; link = TREE_CHAIN (link))
1199 BLOCK_SUPERCONTEXT (link) = block;
1201 /* Clear out the meanings of the local variables of this level. */
1203 for (link = decls; link; link = TREE_CHAIN (link))
1205 tree name = DECL_NAME (link);
1206 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1208 /* If the ident. was used or addressed via a local extern decl,
1209 don't forget that fact. */
1210 if (DECL_EXTERNAL (link))
1212 if (TREE_USED (link))
1213 TREE_USED (name) = 1;
1214 if (TREE_ADDRESSABLE (link))
1215 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1217 IDENTIFIER_LOCAL_VALUE (name) = 0;
1221 /* Restore all name-meanings of the outer levels
1222 that were shadowed by this level. */
1224 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1225 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1227 /* If the level being exited is the top level of a function,
1228 check over all the labels, and clear out the current
1229 (function local) meanings of their names. */
1233 /* If this is the top level block of a function,
1234 the vars are the function's parameters.
1235 Don't leave them in the BLOCK because they are
1236 found in the FUNCTION_DECL instead. */
1238 BLOCK_VARS (block) = 0;
1240 /* Clear out the definitions of all label names,
1241 since their scopes end here,
1242 and add them to BLOCK_VARS. */
1245 for (link = named_labels; link; link = TREE_CHAIN (link))
1247 register tree label = TREE_VALUE (link);
1249 if (DECL_INITIAL (label) == 0)
1251 error_with_decl (label, "label `%s' used but not defined");
1252 /* Avoid crashing later. */
1253 define_label (input_filename, lineno,
1256 else if (warn_unused && !TREE_USED (label))
1257 warning_with_decl (label, "label `%s' defined but not used");
1258 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1260 /* Put the labels into the "variables" of the
1261 top-level block, so debugger can see them. */
1262 TREE_CHAIN (label) = BLOCK_VARS (block);
1263 BLOCK_VARS (block) = label;
1268 /* Pop the current level, and free the structure for reuse. */
1271 register struct binding_level *level = current_binding_level;
1272 current_binding_level = current_binding_level->level_chain;
1274 level->level_chain = free_binding_level;
1275 free_binding_level = level;
1278 /* Dispose of the block that we just made inside some higher level. */
1280 DECL_INITIAL (current_function_decl) = block;
1283 if (!block_previously_created)
1284 current_binding_level->blocks
1285 = chainon (current_binding_level->blocks, block);
1287 /* If we did not make a block for the level just exited,
1288 any blocks made for inner levels
1289 (since they cannot be recorded as subblocks in that level)
1290 must be carried forward so they will later become subblocks
1291 of something else. */
1293 current_binding_level->blocks
1294 = chainon (current_binding_level->blocks, subblocks);
1296 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1297 binding contour so that they point to the appropriate construct, i.e.
1298 either to the current FUNCTION_DECL node, or else to the BLOCK node
1299 we just constructed.
1301 Note that for tagged types whose scope is just the formal parameter
1302 list for some function type specification, we can't properly set
1303 their TYPE_CONTEXTs here, because we don't have a pointer to the
1304 appropriate FUNCTION_TYPE node readily available to us. For those
1305 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1306 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1307 node which will represent the "scope" for these "parameter list local"
1312 TREE_USED (block) = 1;
1317 maybe_pushlevels (pc)
1320 while (pending_local_decls != NULL_TREE &&
1321 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1323 tree *ptr = &pending_local_decls;
1325 int end_pc = DECL_LOCAL_END_PC (decl);
1327 while (*ptr != NULL_TREE
1328 && DECL_LOCAL_START_PC (*ptr) <= pc
1329 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1330 ptr = &TREE_CHAIN (*ptr);
1331 pending_local_decls = *ptr;
1334 /* Force non-nested range to be nested in current range. */
1335 if (end_pc > current_binding_level->end_pc)
1336 end_pc = current_binding_level->end_pc;
1339 expand_start_bindings (0);
1340 current_binding_level->end_pc = end_pc;
1342 current_binding_level->names = decl;
1343 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1345 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1351 maybe_poplevels (pc)
1354 while (current_binding_level->end_pc <= pc)
1356 expand_end_bindings (getdecls (), 1, 0);
1361 /* Insert BLOCK at the end of the list of subblocks of the
1362 current binding level. This is used when a BIND_EXPR is expanded,
1363 to handle the BLOCK node inside the BIND_EXPR. */
1366 insert_block (block)
1369 TREE_USED (block) = 1;
1371 current_binding_level->blocks
1372 = chainon (current_binding_level->blocks, block);
1375 /* Set the BLOCK node for the innermost scope
1376 (the one we are currently in). */
1380 register tree block;
1382 current_binding_level->this_block = block;
1385 /* integrate_decl_tree calls this function. */
1388 copy_lang_decl (node)
1392 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1393 : sizeof (struct lang_decl);
1394 struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1395 bcopy ((PTR) DECL_LANG_SPECIFIC (node), (PTR) x, lang_decl_size);
1396 DECL_LANG_SPECIFIC (node) = x;
1399 /* If DECL has a cleanup, build and return that cleanup here.
1400 This is a callback called by expand_expr. */
1403 maybe_build_cleanup (decl)
1404 tree decl ATTRIBUTE_UNUSED;
1406 /* There are no cleanups in Java (I think). */
1411 give_name_to_locals (jcf)
1414 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1416 pending_local_decls = NULL_TREE;
1420 n = JCF_readu2 (jcf);
1421 for (i = 0; i < n; i++)
1423 int start_pc = JCF_readu2 (jcf);
1424 int length = JCF_readu2 (jcf);
1425 int name_index = JCF_readu2 (jcf);
1426 int signature_index = JCF_readu2 (jcf);
1427 int slot = JCF_readu2 (jcf);
1428 tree name = get_name_constant (jcf, name_index);
1429 tree type = parse_signature (jcf, signature_index);
1430 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1432 && length == DECL_CODE_LENGTH (current_function_decl))
1434 tree decl = TREE_VEC_ELT (decl_map, slot);
1435 DECL_NAME (decl) = name;
1436 DECL_ASSEMBLER_NAME (decl) = name;
1437 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1438 warning ("bad type in parameter debug info");
1443 int end_pc = start_pc + length;
1444 tree decl = build_decl (VAR_DECL, name, type);
1445 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1447 warning_with_decl (decl,
1448 "bad PC range for debug info for local `%s'");
1449 end_pc = DECL_CODE_LENGTH (current_function_decl);
1451 DECL_LANG_SPECIFIC (decl)
1452 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1453 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1454 DECL_LOCAL_START_PC (decl) = start_pc;
1455 DECL_LOCAL_END_PC (decl) = end_pc;
1457 /* Now insert the new decl in the proper place in
1458 pending_local_decls. We are essentially doing an insertion sort,
1459 which works fine, since the list input will normally already
1461 ptr = &pending_local_decls;
1462 while (*ptr != NULL_TREE
1463 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1464 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1465 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1466 ptr = &TREE_CHAIN (*ptr);
1467 TREE_CHAIN (decl) = *ptr;
1472 pending_local_decls = nreverse (pending_local_decls);
1474 /* Fill in default names for the parameters. */
1475 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1476 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1478 if (DECL_NAME (parm) == NULL_TREE)
1480 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1482 DECL_NAME (parm) = get_identifier ("this");
1486 sprintf (buffer, "ARG_%d", arg_i);
1487 DECL_NAME (parm) = get_identifier (buffer);
1489 DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1495 build_result_decl (fndecl)
1498 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1499 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1500 if (INTEGRAL_TYPE_P (restype)
1501 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1502 restype = integer_type_node;
1503 return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
1507 complete_start_java_method (fndecl)
1510 if (! flag_emit_class_files)
1512 /* Initialize the RTL code for the function. */
1513 init_function_start (fndecl, input_filename, lineno);
1515 /* Set up parameters and prepare for return, for the function. */
1516 expand_function_start (fndecl, 0);
1519 /* Allocate further tree nodes temporarily during compilation
1520 of this function only. */
1521 temporary_allocation ();
1524 /* If this fcn was already referenced via a block-scope `extern' decl (or
1525 an implicit decl), propagate certain information about the usage. */
1526 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1527 TREE_ADDRESSABLE (current_function_decl) = 1;
1531 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1532 && ! flag_emit_class_files
1533 && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1535 tree clas = DECL_CONTEXT (fndecl);
1536 tree init = build (CALL_EXPR, void_type_node,
1537 build_address_of (soft_initclass_node),
1538 build_tree_list (NULL_TREE, build_class_ref (clas)),
1540 TREE_SIDE_EFFECTS (init) = 1;
1541 expand_expr_stmt (init);
1544 /* Push local variables. Function compiled from source code are
1545 using a different local variables management, and for them,
1546 pushlevel shouldn't be called from here. */
1547 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1550 if (! flag_emit_class_files)
1551 expand_start_bindings (1);
1554 if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1556 /* Warp function body with a monitorenter plus monitorexit cleanup. */
1557 tree enter, exit, lock;
1558 if (METHOD_STATIC (fndecl))
1559 lock = build_class_ref (DECL_CONTEXT (fndecl));
1561 lock = DECL_ARGUMENTS (fndecl);
1562 BUILD_MONITOR_ENTER (enter, lock);
1563 BUILD_MONITOR_EXIT (exit, lock);
1564 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1566 expand_expr_stmt (enter);
1567 expand_decl_cleanup (NULL_TREE, exit);
1571 tree function_body = DECL_FUNCTION_BODY (fndecl);
1572 tree body = BLOCK_EXPR_BODY (function_body);
1573 lock = build (WITH_CLEANUP_EXPR, void_type_node,
1574 enter, NULL_TREE, exit);
1575 TREE_SIDE_EFFECTS (lock) = 1;
1576 lock = build (COMPOUND_EXPR, TREE_TYPE (body), lock, body);
1577 TREE_SIDE_EFFECTS (lock) = 1;
1578 lock = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (body), lock);
1579 TREE_SIDE_EFFECTS (lock) = 1;
1580 BLOCK_EXPR_BODY (function_body) = lock;
1586 start_java_method (fndecl)
1592 current_function_decl = fndecl;
1593 announce_function (fndecl);
1595 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1596 decl_map = make_tree_vec (i);
1597 type_map = (tree *) oballoc (i * sizeof (tree));
1599 pushlevel (1); /* Push parameters. */
1601 ptr = &DECL_ARGUMENTS (fndecl);
1602 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1603 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1605 tree parm_name = NULL_TREE, parm_decl;
1606 tree parm_type = TREE_VALUE (tem);
1607 if (i >= DECL_MAX_LOCALS(fndecl))
1608 fatal ("function has more parameters than local slots");
1610 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1611 DECL_CONTEXT (parm_decl) = fndecl;
1612 #ifdef PROMOTE_PROTOTYPES
1613 if (TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1614 && INTEGRAL_TYPE_P (parm_type))
1615 parm_type = integer_type_node;
1617 DECL_ARG_TYPE (parm_decl) = parm_type;
1620 ptr = &TREE_CHAIN (parm_decl);
1622 /* Add parm_decl to the decl_map. */
1623 push_jvm_slot (i, parm_decl);
1625 type_map[i] = TREE_TYPE (parm_decl);
1626 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1629 type_map[i] = void_type_node;
1633 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1635 while (i < DECL_MAX_LOCALS(fndecl))
1636 type_map[i++] = NULL_TREE;
1638 build_result_decl (fndecl);
1639 complete_start_java_method (fndecl);
1645 tree fndecl = current_function_decl;
1646 int flag_asynchronous_exceptions = asynchronous_exceptions;
1648 expand_end_bindings (getdecls (), 1, 0);
1649 /* pop out of function */
1652 /* pop out of its parameters */
1655 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1659 /* Generate rtl for function exit. */
1660 expand_function_end (input_filename, lineno, 0);
1662 /* FIXME: If the current method contains any exception handlers,
1663 force asynchronous_exceptions: this is necessary because signal
1664 handlers in libjava may throw exceptions. This is far from being
1665 a perfect solution, but it's better than doing nothing at all.*/
1667 asynchronous_exceptions = 1;
1669 /* Run the optimizers and output assembler code for this function. */
1670 rest_of_compilation (fndecl);
1672 current_function_decl = NULL_TREE;
1673 permanent_allocation (1);
1674 asynchronous_exceptions = flag_asynchronous_exceptions;