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"
39 static tree push_jvm_slot
PROTO ((int, tree
));
40 static tree builtin_function
PROTO ((const char *, tree
,
41 enum built_in_function
, const char *));
42 static tree lookup_name_current_level
PROTO ((tree
));
43 static tree push_promoted_type
PROTO ((const char *, tree
));
44 static struct binding_level
*make_binding_level
PROTO ((void));
47 #define INT_TYPE_SIZE BITS_PER_WORD
50 /* The DECL_MAP is a mapping from (index, type) to a decl node.
51 If index < max_locals, it is the index of a local variable.
52 if index >= max_locals, then index-max_locals is a stack slot.
53 The DECL_MAP mapping is represented as a TREE_VEC whose elements
54 are a list of decls (VAR_DECL or PARM_DECL) chained by
55 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
56 we search the chain for a decl with a matching TREE_TYPE. */
60 /* A list of local variables VAR_DECLs for this method that we have seen
61 debug information, but we have not reached their starting (byte) PC yet. */
63 tree pending_local_decls
= NULL_TREE
;
65 /* Push a local variable or stack slot into the decl_map,
66 and assign it an rtl. */
69 push_jvm_slot (index
, decl
)
73 struct rtx_def
*rtl
= NULL
;
74 tree type
= TREE_TYPE (decl
);
77 DECL_CONTEXT (decl
) = current_function_decl
;
78 layout_decl (decl
, 0);
80 /* See if we have an appropriate rtl (i.e. same mode) at this index.
81 If so, we must use it. */
82 tmp
= TREE_VEC_ELT (decl_map
, index
);
83 while (tmp
!= NULL_TREE
)
85 if (TYPE_MODE (type
) == TYPE_MODE (TREE_TYPE (tmp
)))
89 tmp
= DECL_LOCAL_SLOT_CHAIN (tmp
);
92 DECL_RTL (decl
) = rtl
;
95 if (index
>= DECL_MAX_LOCALS (current_function_decl
))
96 DECL_REGISTER (decl
) = 1;
100 /* Now link the decl into the decl_map. */
101 if (DECL_LANG_SPECIFIC (decl
) == NULL
)
103 DECL_LANG_SPECIFIC (decl
)
104 = (struct lang_decl
*) permalloc (sizeof (struct lang_decl_var
));
105 DECL_LOCAL_START_PC (decl
) = 0;
106 DECL_LOCAL_END_PC (decl
) = DECL_CODE_LENGTH (current_function_decl
);
107 DECL_LOCAL_SLOT_NUMBER (decl
) = index
;
109 DECL_LOCAL_SLOT_CHAIN (decl
) = TREE_VEC_ELT (decl_map
, index
);
110 TREE_VEC_ELT (decl_map
, index
) = decl
;
114 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
115 that is valid at PC (or -1 if any pc).
116 If there is no existing matching decl, allocate one.
117 If we find a decl with matching modes but different types,
118 we re-use the rtl, but create a new decl. */
121 find_local_variable (index
, type
, pc
)
126 tree decl
= TREE_VEC_ELT (decl_map
, index
);
127 tree best
= NULL_TREE
;
128 while (decl
!= NULL_TREE
)
132 || (pc
>= DECL_LOCAL_START_PC (decl
)
133 && pc
< DECL_LOCAL_END_PC (decl
));
135 if ((TREE_TYPE (decl
) == type
136 || (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
137 && type
== ptr_type_node
))
140 if (best
== NULL_TREE
141 || (TREE_TYPE (decl
) == type
&& TREE_TYPE (best
) != type
)
142 || DECL_LOCAL_START_PC (decl
) > DECL_LOCAL_START_PC (best
)
143 || DECL_LOCAL_END_PC (decl
) < DECL_LOCAL_START_PC (decl
))
146 decl
= DECL_LOCAL_SLOT_CHAIN (decl
);
148 if (best
!= NULL_TREE
)
150 return push_jvm_slot (index
, build_decl (VAR_DECL
, NULL_TREE
, type
));
154 /* Same as find_local_index, except that INDEX is a stack index. */
157 find_stack_slot (index
, type
)
161 return find_local_variable (index
+ DECL_MAX_LOCALS (current_function_decl
),
167 /* A chain of _DECL nodes for all variables, constants, functions,
168 * and typedef types. These are in the reverse of the order supplied.
172 /* For each level, a list of shadowed outer-level local definitions
173 to be restored when this level is popped.
174 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
175 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
178 /* For each level (except not the global one),
179 a chain of BLOCK nodes for all the levels
180 that were entered and exited one level down. */
183 /* The BLOCK node for this level, if one has been preallocated.
184 If 0, the BLOCK is allocated (if needed) when the level is popped. */
187 /* The binding level which this one is contained in (inherits from). */
188 struct binding_level
*level_chain
;
190 /* 1 means make a BLOCK for this level regardless of all else.
191 2 for temporary binding contours created by the compiler. */
194 /* Nonzero means make a BLOCK if this level has any subblocks. */
195 char keep_if_subblocks
;
197 /* Nonzero if this level can safely have additional
198 cleanup-needing variables added to it. */
199 char more_cleanups_ok
;
202 /* The bytecode PC that marks the end of this level. */
206 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
208 /* The binding level currently in effect. */
210 static struct binding_level
*current_binding_level
;
212 /* A chain of binding_level structures awaiting reuse. */
214 static struct binding_level
*free_binding_level
;
216 /* The outermost binding level, for names of file scope.
217 This is created when the compiler is started and exists
218 through the entire run. */
220 static struct binding_level
*global_binding_level
;
222 /* Binding level structures are initialized by copying this one. */
224 static struct binding_level clear_binding_level
225 = {NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
,
226 NULL_BINDING_LEVEL
, 0, 0, 0, 0, 1000000000};
229 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
230 that have names. Here so we can clear out their names' definitions
231 at the end of the function. */
233 static tree named_labels
;
235 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
237 static tree shadowed_labels
;
240 int flag_traditional
;
242 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
244 static int keep_next_level_flag
;
246 /* Nonzero means make a BLOCK for the next level pushed
247 if it has subblocks. */
249 static int keep_next_if_subblocks
;
251 /* The FUNCTION_DECL for the function currently being compiled,
252 or 0 if between functions. */
253 tree current_function_decl
;
255 /* The type node for the ordinary character type. */
258 tree object_type_node
;
259 tree unqualified_object_id_node
;
260 tree object_ptr_type_node
;
261 tree string_type_node
;
262 tree string_ptr_type_node
;
263 tree throwable_type_node
;
264 tree runtime_exception_type_node
;
265 tree error_exception_type_node
;
266 tree
*predef_filenames
;
267 int predef_filenames_size
;
269 tree boolean_type_node
;
271 tree float_type_node
;
272 tree double_type_node
;
274 /* a VOID_TYPE node. */
278 tree return_address_type_node
;
280 tree integer_type_node
;
283 tree short_type_node
;
287 tree promoted_byte_type_node
;
288 tree promoted_short_type_node
;
289 tree promoted_char_type_node
;
290 tree promoted_boolean_type_node
;
292 tree unsigned_byte_type_node
;
293 tree unsigned_short_type_node
;
294 tree unsigned_int_type_node
;
295 tree unsigned_long_type_node
;
297 /* The type for struct methodtable. */
298 tree methodtable_type
;
299 tree methodtable_ptr_type
;
302 tree utf8const_ptr_type
;
303 tree class_type_node
;
305 tree field_type_node
;
306 tree field_ptr_type_node
;
307 tree field_info_union_node
;
308 tree jexception_type
;
309 tree jexception_ptr_type
;
310 tree lineNumberEntry_type
;
311 tree lineNumbers_type
;
312 tree constants_type_node
;
314 tree dtable_ptr_type
;
315 tree method_type_node
;
316 tree method_ptr_type_node
;
317 tree nativecode_ptr_array_type_node
;
318 tree one_elt_array_domain_type
;
319 tree access_flags_type_node
;
320 tree class_dtable_decl
;
322 /* a node which has tree code ERROR_MARK, and whose type is itself.
323 All erroneous expressions are replaced with this node. All functions
324 that accept nodes as arguments should avoid generating error messages
325 if this node is one of the arguments, since it is undesirable to get
326 multiple error messages from one error in the input. */
328 tree error_mark_node
;
330 /* Two expressions that are constants with value zero.
331 The first is of type `int', the second of type `void *'.
332 Other of type `long', `float' and `double' follow. */
333 tree integer_zero_node
;
334 tree null_pointer_node
;
336 tree float_zero_node
;
337 tree double_zero_node
;
339 tree empty_stmt_node
;
341 /* Nodes for boolean constants TRUE and FALSE. */
342 tree boolean_true_node
, boolean_false_node
;
344 tree TYPE_identifier_node
;
345 tree init_identifier_node
;
346 tree clinit_identifier_node
;
347 tree finit_identifier_node
;
348 tree void_signature_node
;
349 tree length_identifier_node
;
350 tree this_identifier_node
;
351 tree super_identifier_node
;
352 tree continue_identifier_node
;
354 tree end_params_node
;
356 /* References to internal libjava functions we use. */
357 tree alloc_object_node
;
358 tree soft_instanceof_node
;
359 tree soft_checkcast_node
;
360 tree soft_initclass_node
;
361 tree soft_newarray_node
;
362 tree soft_anewarray_node
;
363 tree soft_multianewarray_node
;
364 tree soft_badarrayindex_node
;
366 tree soft_checkarraystore_node
;
367 tree soft_monitorenter_node
;
368 tree soft_monitorexit_node
;
369 tree soft_lookupinterfacemethod_node
;
371 tree soft_exceptioninfo_call_node
;
377 /* __builtin_va_list; unused by java, but referenced by target files. */
378 tree va_list_type_node
;
380 /* Build (and pushdecl) a "promoted type" for all standard
381 types shorter than int. */
384 push_promoted_type (name
, actual_type
)
388 tree type
= make_node (TREE_CODE (actual_type
));
390 tree in_min
= TYPE_MIN_VALUE (int_type_node
);
391 tree in_max
= TYPE_MAX_VALUE (int_type_node
);
393 tree in_min
= TYPE_MIN_VALUE (actual_type
);
394 tree in_max
= TYPE_MAX_VALUE (actual_type
);
396 TYPE_MIN_VALUE (type
) = build_int_2 (TREE_INT_CST_LOW (in_min
),
397 TREE_INT_CST_HIGH (in_min
));
398 TREE_TYPE (TYPE_MIN_VALUE (type
)) = type
;
399 TYPE_MAX_VALUE (type
) = build_int_2 (TREE_INT_CST_LOW (in_max
),
400 TREE_INT_CST_HIGH (in_max
));
401 TREE_TYPE (TYPE_MAX_VALUE (type
)) = type
;
402 TYPE_PRECISION (type
) = TYPE_PRECISION (int_type_node
);
404 pushdecl (build_decl (TYPE_DECL
, get_identifier (name
), type
));
408 /* Nodes for integer constants. */
409 tree integer_one_node
, integer_two_node
, integer_four_node
;
410 tree integer_negative_one_node
;
412 /* Return a definition for a builtin function named NAME and whose data type
413 is TYPE. TYPE should be a function type with argument types.
414 FUNCTION_CODE tells later passes how to compile calls to this function.
415 See tree.h for its possible values.
417 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
418 the name to be called if we can't opencode the function. */
421 builtin_function (name
, type
, function_code
, library_name
)
424 enum built_in_function function_code
;
425 const char *library_name
;
427 tree decl
= build_decl (FUNCTION_DECL
, get_identifier (name
), type
);
428 DECL_EXTERNAL (decl
) = 1;
429 TREE_PUBLIC (decl
) = 1;
431 DECL_ASSEMBLER_NAME (decl
) = get_identifier (library_name
);
432 make_decl_rtl (decl
, NULL_PTR
, 1);
434 if (function_code
!= NOT_BUILT_IN
)
436 DECL_BUILT_IN (decl
) = 1;
437 DECL_FUNCTION_CODE (decl
) = function_code
;
443 init_decl_processing ()
445 register tree endlink
;
446 tree field
= NULL_TREE
;
449 current_function_decl
= NULL
;
450 current_binding_level
= NULL_BINDING_LEVEL
;
451 free_binding_level
= NULL_BINDING_LEVEL
;
452 pushlevel (0); /* make the binding_level structure for global names */
453 global_binding_level
= current_binding_level
;
455 error_mark_node
= make_node (ERROR_MARK
);
456 TREE_TYPE (error_mark_node
) = error_mark_node
;
458 /* Create sizetype first - needed for other types. */
459 sizetype
= make_unsigned_type (POINTER_SIZE
);
460 size_zero_node
= build_int_2 (0, 0);
461 TREE_TYPE (size_zero_node
) = sizetype
;
462 size_one_node
= build_int_2 (1, 0);
463 TREE_TYPE (size_one_node
) = sizetype
;
465 byte_type_node
= make_signed_type (8);
466 pushdecl (build_decl (TYPE_DECL
, get_identifier ("byte"), byte_type_node
));
467 short_type_node
= make_signed_type (16);
468 pushdecl (build_decl (TYPE_DECL
, get_identifier ("short"), short_type_node
));
469 int_type_node
= make_signed_type (32);
470 pushdecl (build_decl (TYPE_DECL
, get_identifier ("int"), int_type_node
));
471 long_type_node
= make_signed_type (64);
472 pushdecl (build_decl (TYPE_DECL
, get_identifier ("long"), long_type_node
));
474 unsigned_byte_type_node
= make_unsigned_type (8);
475 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned byte"),
476 unsigned_byte_type_node
));
477 unsigned_short_type_node
= make_unsigned_type (16);
478 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned short"),
479 unsigned_short_type_node
));
480 unsigned_int_type_node
= make_unsigned_type (32);
481 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned int"),
482 unsigned_int_type_node
));
483 unsigned_long_type_node
= make_unsigned_type (64);
484 pushdecl (build_decl (TYPE_DECL
, get_identifier ("unsigned long"),
485 unsigned_long_type_node
));
487 integer_type_node
= type_for_size (INT_TYPE_SIZE
, 0);
489 integer_zero_node
= build_int_2 (0, 0);
490 integer_one_node
= build_int_2 (1, 0);
491 integer_two_node
= build_int_2 (2, 0);
492 integer_four_node
= build_int_2 (4, 0);
493 integer_negative_one_node
= build_int_2 (-1, 0);
495 long_zero_node
= build_int_2 (0, 0);
496 TREE_TYPE (long_zero_node
) = long_type_node
;
498 void_type_node
= make_node (VOID_TYPE
);
499 pushdecl (build_decl (TYPE_DECL
, get_identifier ("void"), void_type_node
));
500 layout_type (void_type_node
); /* Uses size_zero_node */
501 ptr_type_node
= build_pointer_type (void_type_node
);
502 t
= make_node (VOID_TYPE
);
503 layout_type (t
); /* Uses size_zero_node */
504 return_address_type_node
= build_pointer_type (t
);
506 null_pointer_node
= build_int_2 (0, 0);
507 TREE_TYPE (null_pointer_node
) = ptr_type_node
;
509 /* Used by the parser to represent empty statements and blocks. */
510 empty_stmt_node
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
511 CAN_COMPLETE_NORMALLY (empty_stmt_node
) = 1;
514 /* Make a type to be the domain of a few array types
515 whose domains don't really matter.
516 200 is small enough that it always fits in size_t
517 and large enough that it can hold most function names for the
518 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
519 short_array_type_node
= build_prim_array_type (short_type_node
, 200);
521 char_type_node
= make_node (CHAR_TYPE
);
522 TYPE_PRECISION (char_type_node
) = 16;
523 fixup_unsigned_type (char_type_node
);
524 pushdecl (build_decl (TYPE_DECL
, get_identifier ("char"), char_type_node
));
526 boolean_type_node
= make_node (BOOLEAN_TYPE
);
527 TYPE_PRECISION (boolean_type_node
) = 1;
528 fixup_unsigned_type (boolean_type_node
);
529 pushdecl (build_decl (TYPE_DECL
, get_identifier ("boolean"),
531 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
532 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
534 promoted_byte_type_node
535 = push_promoted_type ("promoted_byte", byte_type_node
);
536 promoted_short_type_node
537 = push_promoted_type ("promoted_short", short_type_node
);
538 promoted_char_type_node
539 = push_promoted_type ("promoted_char", char_type_node
);
540 promoted_boolean_type_node
541 = push_promoted_type ("promoted_boolean", boolean_type_node
);
543 float_type_node
= make_node (REAL_TYPE
);
544 TYPE_PRECISION (float_type_node
) = 32;
545 pushdecl (build_decl (TYPE_DECL
, get_identifier ("float"),
547 layout_type (float_type_node
);
549 double_type_node
= make_node (REAL_TYPE
);
550 TYPE_PRECISION (double_type_node
) = 64;
551 pushdecl (build_decl (TYPE_DECL
, get_identifier ("double"),
553 layout_type (double_type_node
);
555 float_zero_node
= build_real (float_type_node
, dconst0
);
556 double_zero_node
= build_real (double_type_node
, dconst0
);
558 /* As your adding items here, please update the code right after
559 this section, so that the filename containing the source code of
560 the pre-defined class gets registered correctly. */
561 unqualified_object_id_node
= get_identifier ("Object");
562 object_type_node
= lookup_class (get_identifier ("java.lang.Object"));
563 object_ptr_type_node
= promote_type (object_type_node
);
564 string_type_node
= lookup_class (get_identifier ("java.lang.String"));
565 string_ptr_type_node
= promote_type (string_type_node
);
566 class_type_node
= lookup_class (get_identifier ("java.lang.Class"));
567 throwable_type_node
= lookup_class (get_identifier ("java.lang.Throwable"));
568 runtime_exception_type_node
=
569 lookup_class (get_identifier ("java.lang.RuntimeException"));
570 error_exception_type_node
=
571 lookup_class (get_identifier ("java.lang.Error"));
573 /* This section has to be updated as items are added to the previous
575 predef_filenames_size
= 6;
576 predef_filenames
= (tree
*)xmalloc (predef_filenames_size
* sizeof (tree
));
577 predef_filenames
[0] = get_identifier ("java/lang/Class.java");
578 predef_filenames
[1] = get_identifier ("java/lang/Error.java");
579 predef_filenames
[2] = get_identifier ("java/lang/Object.java");
580 predef_filenames
[3] = get_identifier ("java/lang/RuntimeException.java");
581 predef_filenames
[4] = get_identifier ("java/lang/String.java");
582 predef_filenames
[5] = get_identifier ("java/lang/Throwable.java");
584 methodtable_type
= make_node (RECORD_TYPE
);
585 layout_type (methodtable_type
);
586 build_decl (TYPE_DECL
, get_identifier ("methodtable"), methodtable_type
);
587 methodtable_ptr_type
= build_pointer_type (methodtable_type
);
589 TYPE_identifier_node
= get_identifier ("TYPE");
590 init_identifier_node
= get_identifier ("<init>");
591 clinit_identifier_node
= get_identifier ("<clinit>");
592 finit_identifier_node
= get_identifier ("$finit$");
593 void_signature_node
= get_identifier ("()V");
594 length_identifier_node
= get_identifier ("length");
595 this_identifier_node
= get_identifier ("this");
596 super_identifier_node
= get_identifier ("super");
597 continue_identifier_node
= get_identifier ("continue");
599 /* for lack of a better place to put this stub call */
600 init_expr_processing();
602 utf8const_type
= make_node (RECORD_TYPE
);
603 PUSH_FIELD (utf8const_type
, field
, "hash", unsigned_short_type_node
);
604 PUSH_FIELD (utf8const_type
, field
, "length", unsigned_short_type_node
);
605 FINISH_RECORD (utf8const_type
);
606 utf8const_ptr_type
= build_pointer_type (utf8const_type
);
608 constants_type_node
= make_node (RECORD_TYPE
);
609 PUSH_FIELD (constants_type_node
, field
, "size", unsigned_int_type_node
);
610 PUSH_FIELD (constants_type_node
, field
, "tags", ptr_type_node
);
611 PUSH_FIELD (constants_type_node
, field
, "data", ptr_type_node
);
612 FINISH_RECORD (constants_type_node
);
613 build_decl (TYPE_DECL
, get_identifier ("constants"), constants_type_node
);
615 access_flags_type_node
= unsigned_short_type_node
;
617 dtable_type
= make_node (RECORD_TYPE
);
618 dtable_ptr_type
= build_pointer_type (dtable_type
);
620 PUSH_FIELD (object_type_node
, field
, "vtable", dtable_ptr_type
);
621 PUSH_FIELD (object_type_node
, field
, "sync_info", ptr_type_node
);
622 for (t
= TYPE_FIELDS (object_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
623 FIELD_PRIVATE (t
) = 1;
624 FINISH_RECORD (object_type_node
);
626 class_dtable_decl
= build_dtable_decl (class_type_node
);
627 TREE_STATIC (class_dtable_decl
) = 1;
628 DECL_ARTIFICIAL (class_dtable_decl
) = 1;
629 DECL_IGNORED_P (class_dtable_decl
) = 1;
630 rest_of_decl_compilation (class_dtable_decl
, (char*) 0, 1, 0);
632 field_type_node
= make_node (RECORD_TYPE
);
633 field_ptr_type_node
= build_pointer_type (field_type_node
);
634 method_type_node
= make_node (RECORD_TYPE
);
635 method_ptr_type_node
= build_pointer_type (method_type_node
);
637 set_super_info (0, class_type_node
, object_type_node
, 0);
638 set_super_info (0, string_type_node
, object_type_node
, 0);
639 class_ptr_type
= build_pointer_type (class_type_node
);
641 PUSH_FIELD (class_type_node
, field
, "next", class_ptr_type
);
642 PUSH_FIELD (class_type_node
, field
, "name", utf8const_ptr_type
);
643 PUSH_FIELD (class_type_node
, field
, "accflags", access_flags_type_node
);
644 PUSH_FIELD (class_type_node
, field
, "superclass", class_ptr_type
);
645 PUSH_FIELD (class_type_node
, field
, "constants", constants_type_node
);
646 PUSH_FIELD (class_type_node
, field
, "methods", method_ptr_type_node
);
647 PUSH_FIELD (class_type_node
, field
, "method_count", short_type_node
);
648 PUSH_FIELD (class_type_node
, field
, "vtable_method_count", short_type_node
);
649 PUSH_FIELD (class_type_node
, field
, "fields", field_ptr_type_node
);
650 PUSH_FIELD (class_type_node
, field
, "size_in_bytes", int_type_node
);
651 PUSH_FIELD (class_type_node
, field
, "field_count", short_type_node
);
652 PUSH_FIELD (class_type_node
, field
, "static_field_count", short_type_node
);
653 PUSH_FIELD (class_type_node
, field
, "vtable", dtable_ptr_type
);
654 PUSH_FIELD (class_type_node
, field
, "interfaces",
655 build_pointer_type (class_ptr_type
));
656 PUSH_FIELD (class_type_node
, field
, "loader", ptr_type_node
);
657 PUSH_FIELD (class_type_node
, field
, "interface_count", short_type_node
);
658 PUSH_FIELD (class_type_node
, field
, "state", byte_type_node
);
659 PUSH_FIELD (class_type_node
, field
, "thread", ptr_type_node
);
660 for (t
= TYPE_FIELDS (class_type_node
); t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
661 FIELD_PRIVATE (t
) = 1;
662 push_super_field (class_type_node
, object_type_node
);
663 FINISH_RECORD (class_type_node
);
664 build_decl (TYPE_DECL
, get_identifier ("Class"), class_type_node
);
666 field_info_union_node
= make_node (UNION_TYPE
);
667 PUSH_FIELD (field_info_union_node
, field
, "boffset", int_type_node
);
668 PUSH_FIELD (field_info_union_node
, field
, "addr", ptr_type_node
);
670 PUSH_FIELD (field_info_union_node
, field
, "idx", unsigned_short_type_node
);
672 layout_type (field_info_union_node
);
674 PUSH_FIELD (field_type_node
, field
, "name", utf8const_ptr_type
);
675 PUSH_FIELD (field_type_node
, field
, "type", class_ptr_type
);
676 PUSH_FIELD (field_type_node
, field
, "accflags", access_flags_type_node
);
677 PUSH_FIELD (field_type_node
, field
, "bsize", unsigned_short_type_node
);
678 PUSH_FIELD (field_type_node
, field
, "info", field_info_union_node
);
679 FINISH_RECORD (field_type_node
);
680 CLASS_LOADED_P (field_type_node
) = 1;
681 build_decl (TYPE_DECL
, get_identifier ("Field"), field_type_node
);
683 one_elt_array_domain_type
= build_index_type (integer_one_node
);
684 nativecode_ptr_array_type_node
685 = build_array_type (nativecode_ptr_type_node
, one_elt_array_domain_type
);
687 PUSH_FIELD (dtable_type
, field
, "class", class_ptr_type
);
688 PUSH_FIELD (dtable_type
, field
, "methods", nativecode_ptr_array_type_node
);
689 FINISH_RECORD (dtable_type
);
690 build_decl (TYPE_DECL
, get_identifier ("dispatchTable"), dtable_type
);
692 #define jint_type int_type_node
693 #define jint_ptr_type ptr_type_node
695 jexception_type
= make_node (RECORD_TYPE
);
696 PUSH_FIELD (jexception_type
, field
, "start_pc", ptr_type_node
);
697 PUSH_FIELD (jexception_type
, field
, "end_pc", ptr_type_node
);
698 PUSH_FIELD (jexception_type
, field
, "handler_pc", ptr_type_node
);
699 PUSH_FIELD (jexception_type
, field
, "catch_type", class_ptr_type
);
700 FINISH_RECORD (jexception_type
);
701 build_decl (TYPE_DECL
, get_identifier ("jexception"), field_type_node
);
702 jexception_ptr_type
= build_pointer_type (jexception_type
);
704 lineNumberEntry_type
= make_node (RECORD_TYPE
);
705 PUSH_FIELD (lineNumberEntry_type
, field
, "line_nr", unsigned_short_type_node
);
706 PUSH_FIELD (lineNumberEntry_type
, field
, "start_pc", ptr_type_node
);
707 FINISH_RECORD (lineNumberEntry_type
);
709 lineNumbers_type
= make_node (RECORD_TYPE
);
710 PUSH_FIELD (lineNumbers_type
, field
, "length", unsigned_int_type_node
);
711 FINISH_RECORD (lineNumbers_type
);
713 #define instn_ptr_type_node ptr_type_node /* XXX JH */
715 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
717 PUSH_FIELD (method_type_node
, field
, "name", utf8const_ptr_type
);
718 PUSH_FIELD (method_type_node
, field
, "signature", utf8const_ptr_type
);
719 PUSH_FIELD (method_type_node
, field
, "accflags", access_flags_type_node
);
720 PUSH_FIELD (method_type_node
, field
, "ncode", nativecode_ptr_type_node
);
721 FINISH_RECORD (method_type_node
);
722 CLASS_LOADED_P (method_type_node
) = 1;
723 build_decl (TYPE_DECL
, get_identifier ("Method"), method_type_node
);
725 endlink
= end_params_node
= tree_cons (NULL_TREE
, void_type_node
, NULL_TREE
);
727 t
= tree_cons (NULL_TREE
, class_ptr_type
,
728 tree_cons (NULL_TREE
, int_type_node
, endlink
));
729 alloc_object_node
= builtin_function ("_Jv_AllocObject",
730 build_function_type (ptr_type_node
, t
),
731 NOT_BUILT_IN
, NULL_PTR
);
732 soft_initclass_node
= builtin_function ("_Jv_InitClass",
733 build_function_type (void_type_node
,
735 NOT_BUILT_IN
, NULL_PTR
);
736 t
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
737 throw_node
= builtin_function ("_Jv_Throw",
738 build_function_type (ptr_type_node
, t
),
739 NOT_BUILT_IN
, NULL_PTR
);
740 t
= build_function_type (int_type_node
, endlink
);
741 soft_monitorenter_node
742 = builtin_function ("_Jv_MonitorEnter", t
, NOT_BUILT_IN
, NULL_PTR
);
743 soft_monitorexit_node
744 = builtin_function ("_Jv_MonitorExit", t
, NOT_BUILT_IN
, NULL_PTR
);
746 t
= tree_cons (NULL_TREE
, int_type_node
,
747 tree_cons (NULL_TREE
, int_type_node
, endlink
));
749 = builtin_function ("_Jv_NewArray",
750 build_function_type(ptr_type_node
, t
),
751 NOT_BUILT_IN
, NULL_PTR
);
753 t
= tree_cons (NULL_TREE
, int_type_node
,
754 tree_cons (NULL_TREE
, class_ptr_type
,
755 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
)));
757 = builtin_function ("_Jv_NewObjectArray",
758 build_function_type (ptr_type_node
, t
),
759 NOT_BUILT_IN
, NULL_PTR
);
761 t
= tree_cons (NULL_TREE
, ptr_type_node
,
762 tree_cons (NULL_TREE
, int_type_node
, endlink
));
763 soft_multianewarray_node
764 = builtin_function ("_Jv_NewMultiArray",
765 build_function_type (ptr_type_node
, t
),
766 NOT_BUILT_IN
, NULL_PTR
);
768 t
= build_function_type (void_type_node
,
769 tree_cons (NULL_TREE
, int_type_node
, endlink
));
770 soft_badarrayindex_node
771 = builtin_function ("_Jv_ThrowBadArrayIndex", t
,
772 NOT_BUILT_IN
, NULL_PTR
);
773 TREE_THIS_VOLATILE (soft_badarrayindex_node
) = 1;
774 TREE_SIDE_EFFECTS (soft_badarrayindex_node
) = 1;
776 t
= tree_cons (NULL_TREE
, class_ptr_type
,
777 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
779 = builtin_function ("_Jv_CheckCast",
780 build_function_type (ptr_type_node
, t
),
781 NOT_BUILT_IN
, NULL_PTR
);
782 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
783 tree_cons (NULL_TREE
, class_ptr_type
, endlink
));
785 = builtin_function ("_Jv_IsInstanceOf",
786 build_function_type (promoted_boolean_type_node
, t
),
787 NOT_BUILT_IN
, NULL_PTR
);
788 t
= tree_cons (NULL_TREE
, object_ptr_type_node
,
789 tree_cons (NULL_TREE
, object_ptr_type_node
, endlink
));
790 soft_checkarraystore_node
791 = builtin_function ("_Jv_CheckArrayStore",
792 build_function_type (void_type_node
, t
),
793 NOT_BUILT_IN
, NULL_PTR
);
794 t
= tree_cons (NULL_TREE
, ptr_type_node
,
795 tree_cons (NULL_TREE
, ptr_type_node
,
796 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)));
797 soft_lookupinterfacemethod_node
798 = builtin_function ("_Jv_LookupInterfaceMethod",
799 build_function_type (ptr_type_node
, t
),
800 NOT_BUILT_IN
, NULL_PTR
);
801 t
= tree_cons (NULL_TREE
, double_type_node
,
802 tree_cons (NULL_TREE
, double_type_node
, endlink
));
804 = builtin_function ("__builtin_fmod",
805 build_function_type (double_type_node
, t
),
806 BUILT_IN_FMOD
, "fmod");
808 soft_exceptioninfo_call_node
812 (builtin_function ("_Jv_exception_info",
813 build_function_type (ptr_type_node
, endlink
),
814 NOT_BUILT_IN
, NULL_PTR
)),
815 NULL_TREE
, NULL_TREE
);
816 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node
) = 1;
818 t
= tree_cons (NULL_TREE
, float_type_node
,
819 tree_cons (NULL_TREE
, float_type_node
, endlink
));
821 = builtin_function ("__builtin_fmodf",
822 build_function_type (float_type_node
, t
),
823 BUILT_IN_FMOD
, "fmodf");
827 = builtin_function ("_Jv_divI",
828 build_function_type (int_type_node
, t
),
829 NOT_BUILT_IN
, NULL_PTR
);
832 = builtin_function ("_Jv_remI",
833 build_function_type (int_type_node
, t
),
834 NOT_BUILT_IN
, NULL_PTR
);
837 = builtin_function ("_Jv_divJ",
838 build_function_type (long_type_node
, t
),
839 NOT_BUILT_IN
, NULL_PTR
);
842 = builtin_function ("_Jv_remJ",
843 build_function_type (long_type_node
, t
),
844 NOT_BUILT_IN
, NULL_PTR
);
846 init_class_processing ();
850 /* Look up NAME in the current binding level and its superiors
851 in the namespace of variables, functions and typedefs.
852 Return a ..._DECL node of some kind representing its definition,
853 or return 0 if it is undefined. */
860 if (current_binding_level
!= global_binding_level
861 && IDENTIFIER_LOCAL_VALUE (name
))
862 val
= IDENTIFIER_LOCAL_VALUE (name
);
864 val
= IDENTIFIER_GLOBAL_VALUE (name
);
868 /* Similar to `lookup_name' but look only at current binding level and
869 the previous one if its the parameter level. */
872 lookup_name_current_level (name
)
877 if (current_binding_level
== global_binding_level
)
878 return IDENTIFIER_GLOBAL_VALUE (name
);
880 if (IDENTIFIER_LOCAL_VALUE (name
) == 0)
883 for (t
= current_binding_level
->names
; t
; t
= TREE_CHAIN (t
))
884 if (DECL_NAME (t
) == name
)
890 /* Use a binding level to record a labeled block declaration */
893 push_labeled_block (lb
)
896 register tree name
= DECL_NAME (LABELED_BLOCK_LABEL (lb
));
897 register struct binding_level
*b
= current_binding_level
;
898 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
900 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
901 TREE_CHAIN (lb
) = b
->names
;
903 IDENTIFIER_LOCAL_VALUE (name
) = lb
;
906 /* Pop the current binding level, reinstalling values for the previous
912 struct binding_level
*b
= current_binding_level
;
913 tree label
= b
->names
;
914 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label
))) =
917 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b
->shadowed
)) =
918 TREE_VALUE (b
->shadowed
);
920 /* Pop the current level, and free the structure for reuse. */
921 current_binding_level
= current_binding_level
->level_chain
;
922 b
->level_chain
= free_binding_level
;
923 free_binding_level
= b
;
926 /* Record a decl-node X as belonging to the current lexical scope.
927 Check for errors (such as an incompatible declaration for the same
928 name already seen in the same scope).
930 Returns either X or an old decl for the same name.
931 If an old decl is returned, it may have been smashed
932 to agree with what X says. */
939 register tree name
= DECL_NAME (x
);
940 register struct binding_level
*b
= current_binding_level
;
942 DECL_CONTEXT (x
) = current_function_decl
;
948 t
= lookup_name_current_level (name
);
949 if (t
!= 0 && t
== error_mark_node
)
950 /* error_mark_node is 0 for a while during initialization! */
953 error_with_decl (x
, "`%s' used prior to declaration");
958 file
= DECL_SOURCE_FILE (t
);
959 line
= DECL_SOURCE_LINE (t
);
962 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
963 to point to the TYPE_DECL.
964 Since Java does not have typedefs, a type can only have
965 one (true) name, given by a class, interface, or builtin. */
966 if (TREE_CODE (x
) == TYPE_DECL
967 && TYPE_NAME (TREE_TYPE (x
)) == 0
968 && TREE_TYPE (x
) != error_mark_node
)
970 TYPE_NAME (TREE_TYPE (x
)) = x
;
971 TYPE_STUB_DECL (TREE_TYPE (x
)) = x
;
974 /* This name is new in its binding level.
975 Install the new declaration and return it. */
976 if (b
== global_binding_level
)
978 /* Install a global value. */
980 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
984 /* Here to install a non-global value. */
985 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
986 IDENTIFIER_LOCAL_VALUE (name
) = x
;
989 /* Warn if shadowing an argument at the top level of the body. */
990 if (oldlocal
!= 0 && !DECL_EXTERNAL (x
)
991 /* This warning doesn't apply to the parms of a nested fcn. */
992 && ! current_binding_level
->parm_flag
993 /* Check that this is one level down from the parms. */
994 && current_binding_level
->level_chain
->parm_flag
995 /* Check that the decl being shadowed
996 comes from the parm level, one level up. */
997 && chain_member (oldlocal
, current_binding_level
->level_chain
->names
))
999 if (TREE_CODE (oldlocal
) == PARM_DECL
)
1000 pedwarn ("declaration of `%s' shadows a parameter",
1001 IDENTIFIER_POINTER (name
));
1003 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1004 IDENTIFIER_POINTER (name
));
1007 /* Maybe warn if shadowing something else. */
1008 else if (warn_shadow
&& !DECL_EXTERNAL (x
)
1009 /* No shadow warnings for internally generated vars. */
1010 && DECL_SOURCE_LINE (x
) != 0
1011 /* No shadow warnings for vars made for inlining. */
1012 && ! DECL_FROM_INLINE (x
))
1014 const char *warnstring
= 0;
1016 if (TREE_CODE (x
) == PARM_DECL
1017 && current_binding_level
->level_chain
->parm_flag
)
1018 /* Don't warn about the parm names in function declarator
1019 within a function declarator.
1020 It would be nice to avoid warning in any function
1021 declarator in a declaration, as opposed to a definition,
1022 but there is no way to tell it's not a definition. */
1024 else if (oldlocal
!= 0 && TREE_CODE (oldlocal
) == PARM_DECL
)
1025 warnstring
= "declaration of `%s' shadows a parameter";
1026 else if (oldlocal
!= 0)
1027 warnstring
= "declaration of `%s' shadows previous local";
1028 else if (IDENTIFIER_GLOBAL_VALUE (name
) != 0
1029 && IDENTIFIER_GLOBAL_VALUE (name
) != error_mark_node
)
1030 warnstring
= "declaration of `%s' shadows global declaration";
1033 warning (warnstring
, IDENTIFIER_POINTER (name
));
1037 /* If storing a local value, there may already be one (inherited).
1038 If so, record it for restoration when this binding level ends. */
1040 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
1044 /* Put decls on list in reverse order.
1045 We will reverse them later if necessary. */
1046 TREE_CHAIN (x
) = b
->names
;
1052 pushdecl_force_head (x
)
1055 current_binding_level
->names
= x
;
1058 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1061 pushdecl_top_level (x
)
1065 register struct binding_level
*b
= current_binding_level
;
1067 current_binding_level
= global_binding_level
;
1069 current_binding_level
= b
;
1073 /* Nonzero if we are currently in the global binding level. */
1076 global_bindings_p ()
1078 return current_binding_level
== global_binding_level
;
1081 /* Return the list of declarations of the current level.
1082 Note that this list is in reverse order unless/until
1083 you nreverse it; and when you do nreverse it, you must
1084 store the result back using `storedecls' or you will lose. */
1089 return current_binding_level
->names
;
1092 /* Create a new `struct binding_level'. */
1095 struct binding_level
*
1096 make_binding_level ()
1099 return (struct binding_level
*) xmalloc (sizeof (struct binding_level
));
1104 int unused ATTRIBUTE_UNUSED
;
1106 register struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
1109 /* If this is the top level of a function,
1110 just make sure that NAMED_LABELS is 0. */
1112 if (current_binding_level
== global_binding_level
)
1116 /* Reuse or create a struct for this binding level. */
1118 if (free_binding_level
)
1120 newlevel
= free_binding_level
;
1121 free_binding_level
= free_binding_level
->level_chain
;
1125 newlevel
= make_binding_level ();
1128 /* Add this level to the front of the chain (stack) of levels that
1131 *newlevel
= clear_binding_level
;
1132 newlevel
->level_chain
= current_binding_level
;
1133 current_binding_level
= newlevel
;
1134 newlevel
->keep
= keep_next_level_flag
;
1135 keep_next_level_flag
= 0;
1136 newlevel
->keep_if_subblocks
= keep_next_if_subblocks
;
1137 keep_next_if_subblocks
= 0;
1140 /* Exit a binding level.
1141 Pop the level off, and restore the state of the identifier-decl mappings
1142 that were in effect when this level was entered.
1144 If KEEP is nonzero, this level had explicit declarations, so
1145 and create a "block" (a BLOCK node) for the level
1146 to record its declarations and subblocks for symbol table output.
1148 If FUNCTIONBODY is nonzero, this level is the body of a function,
1149 so create a block as if KEEP were set and also clear out all
1152 If REVERSE is nonzero, reverse the order of decls before putting
1153 them into the BLOCK. */
1156 poplevel (keep
, reverse
, functionbody
)
1162 /* The chain of decls was accumulated in reverse order.
1163 Put it into forward order, just for cleanliness. */
1165 tree subblocks
= current_binding_level
->blocks
;
1168 int block_previously_created
;
1170 keep
|= current_binding_level
->keep
;
1172 /* Get the decls in the order they were written.
1173 Usually current_binding_level->names is in reverse order.
1174 But parameter decls were previously put in forward order. */
1177 current_binding_level
->names
1178 = decls
= nreverse (current_binding_level
->names
);
1180 decls
= current_binding_level
->names
;
1182 /* Output any nested inline functions within this block
1183 if they weren't already output. */
1185 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1186 if (TREE_CODE (decl
) == FUNCTION_DECL
1187 && ! TREE_ASM_WRITTEN (decl
)
1188 && DECL_INITIAL (decl
) != 0
1189 && TREE_ADDRESSABLE (decl
))
1191 /* If this decl was copied from a file-scope decl
1192 on account of a block-scope extern decl,
1193 propagate TREE_ADDRESSABLE to the file-scope decl.
1195 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1196 true, since then the decl goes through save_for_inline_copying. */
1197 if (DECL_ABSTRACT_ORIGIN (decl
) != 0
1198 && DECL_ABSTRACT_ORIGIN (decl
) != decl
)
1199 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl
)) = 1;
1202 push_function_context ();
1203 output_inline_function (decl
);
1204 pop_function_context ();
1208 /* If there were any declarations in that level,
1209 or if this level is a function body,
1210 create a BLOCK to record them for the life of this function. */
1213 block_previously_created
= (current_binding_level
->this_block
!= 0);
1214 if (block_previously_created
)
1215 block
= current_binding_level
->this_block
;
1216 else if (keep
|| functionbody
1217 || (current_binding_level
->keep_if_subblocks
&& subblocks
!= 0))
1218 block
= make_node (BLOCK
);
1221 BLOCK_VARS (block
) = decls
;
1222 BLOCK_TYPE_TAGS (block
) = NULL_TREE
;
1223 BLOCK_SUBBLOCKS (block
) = subblocks
;
1224 remember_end_note (block
);
1227 /* In each subblock, record that this is its superior. */
1229 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1230 BLOCK_SUPERCONTEXT (link
) = block
;
1232 /* Clear out the meanings of the local variables of this level. */
1234 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1236 tree name
= DECL_NAME (link
);
1237 if (name
!= 0 && IDENTIFIER_LOCAL_VALUE (name
) == link
)
1239 /* If the ident. was used or addressed via a local extern decl,
1240 don't forget that fact. */
1241 if (DECL_EXTERNAL (link
))
1243 if (TREE_USED (link
))
1244 TREE_USED (name
) = 1;
1245 if (TREE_ADDRESSABLE (link
))
1246 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1248 IDENTIFIER_LOCAL_VALUE (name
) = 0;
1252 /* Restore all name-meanings of the outer levels
1253 that were shadowed by this level. */
1255 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1256 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1258 /* If the level being exited is the top level of a function,
1259 check over all the labels, and clear out the current
1260 (function local) meanings of their names. */
1264 /* If this is the top level block of a function,
1265 the vars are the function's parameters.
1266 Don't leave them in the BLOCK because they are
1267 found in the FUNCTION_DECL instead. */
1269 BLOCK_VARS (block
) = 0;
1271 /* Clear out the definitions of all label names,
1272 since their scopes end here,
1273 and add them to BLOCK_VARS. */
1276 for (link
= named_labels
; link
; link
= TREE_CHAIN (link
))
1278 register tree label
= TREE_VALUE (link
);
1280 if (DECL_INITIAL (label
) == 0)
1282 error_with_decl (label
, "label `%s' used but not defined");
1283 /* Avoid crashing later. */
1284 define_label (input_filename
, lineno
,
1287 else if (warn_unused
&& !TREE_USED (label
))
1288 warning_with_decl (label
, "label `%s' defined but not used");
1289 IDENTIFIER_LABEL_VALUE (DECL_NAME (label
)) = 0;
1291 /* Put the labels into the "variables" of the
1292 top-level block, so debugger can see them. */
1293 TREE_CHAIN (label
) = BLOCK_VARS (block
);
1294 BLOCK_VARS (block
) = label
;
1299 /* Pop the current level, and free the structure for reuse. */
1302 register struct binding_level
*level
= current_binding_level
;
1303 current_binding_level
= current_binding_level
->level_chain
;
1305 level
->level_chain
= free_binding_level
;
1306 free_binding_level
= level
;
1309 /* Dispose of the block that we just made inside some higher level. */
1311 DECL_INITIAL (current_function_decl
) = block
;
1314 if (!block_previously_created
)
1315 current_binding_level
->blocks
1316 = chainon (current_binding_level
->blocks
, block
);
1318 /* If we did not make a block for the level just exited,
1319 any blocks made for inner levels
1320 (since they cannot be recorded as subblocks in that level)
1321 must be carried forward so they will later become subblocks
1322 of something else. */
1324 current_binding_level
->blocks
1325 = chainon (current_binding_level
->blocks
, subblocks
);
1327 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1328 binding contour so that they point to the appropriate construct, i.e.
1329 either to the current FUNCTION_DECL node, or else to the BLOCK node
1330 we just constructed.
1332 Note that for tagged types whose scope is just the formal parameter
1333 list for some function type specification, we can't properly set
1334 their TYPE_CONTEXTs here, because we don't have a pointer to the
1335 appropriate FUNCTION_TYPE node readily available to us. For those
1336 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1337 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1338 node which will represent the "scope" for these "parameter list local"
1343 TREE_USED (block
) = 1;
1348 maybe_pushlevels (pc
)
1351 while (pending_local_decls
!= NULL_TREE
&&
1352 DECL_LOCAL_START_PC (pending_local_decls
) <= pc
)
1354 tree
*ptr
= &pending_local_decls
;
1356 int end_pc
= DECL_LOCAL_END_PC (decl
);
1358 while (*ptr
!= NULL_TREE
1359 && DECL_LOCAL_START_PC (*ptr
) <= pc
1360 && DECL_LOCAL_END_PC (*ptr
) == end_pc
)
1361 ptr
= &TREE_CHAIN (*ptr
);
1362 pending_local_decls
= *ptr
;
1365 /* Force non-nested range to be nested in current range. */
1366 if (end_pc
> current_binding_level
->end_pc
)
1367 end_pc
= current_binding_level
->end_pc
;
1370 expand_start_bindings (0);
1371 current_binding_level
->end_pc
= end_pc
;
1373 current_binding_level
->names
= decl
;
1374 for ( ; decl
!= NULL_TREE
; decl
= TREE_CHAIN (decl
))
1376 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl
), decl
);
1382 maybe_poplevels (pc
)
1385 while (current_binding_level
->end_pc
<= pc
)
1387 expand_end_bindings (getdecls (), 1, 0);
1392 /* Insert BLOCK at the end of the list of subblocks of the
1393 current binding level. This is used when a BIND_EXPR is expanded,
1394 to handle the BLOCK node inside the BIND_EXPR. */
1397 insert_block (block
)
1400 TREE_USED (block
) = 1;
1402 current_binding_level
->blocks
1403 = chainon (current_binding_level
->blocks
, block
);
1406 /* Set the BLOCK node for the innermost scope
1407 (the one we are currently in). */
1411 register tree block
;
1413 current_binding_level
->this_block
= block
;
1416 /* integrate_decl_tree calls this function. */
1419 copy_lang_decl (node
)
1423 = TREE_CODE (node
) == VAR_DECL
? sizeof (struct lang_decl_var
)
1424 : sizeof (struct lang_decl
);
1425 struct lang_decl
*x
= (struct lang_decl
*) oballoc (lang_decl_size
);
1426 bcopy ((PTR
) DECL_LANG_SPECIFIC (node
), (PTR
) x
, lang_decl_size
);
1427 DECL_LANG_SPECIFIC (node
) = x
;
1430 /* If DECL has a cleanup, build and return that cleanup here.
1431 This is a callback called by expand_expr. */
1434 maybe_build_cleanup (decl
)
1435 tree decl ATTRIBUTE_UNUSED
;
1437 /* There are no cleanups in Java (I think). */
1442 give_name_to_locals (jcf
)
1445 int i
, n
= DECL_LOCALVARIABLES_OFFSET (current_function_decl
);
1447 pending_local_decls
= NULL_TREE
;
1451 n
= JCF_readu2 (jcf
);
1452 for (i
= 0; i
< n
; i
++)
1454 int start_pc
= JCF_readu2 (jcf
);
1455 int length
= JCF_readu2 (jcf
);
1456 int name_index
= JCF_readu2 (jcf
);
1457 int signature_index
= JCF_readu2 (jcf
);
1458 int slot
= JCF_readu2 (jcf
);
1459 tree name
= get_name_constant (jcf
, name_index
);
1460 tree type
= parse_signature (jcf
, signature_index
);
1461 if (slot
< DECL_ARG_SLOT_COUNT (current_function_decl
)
1463 && length
== DECL_CODE_LENGTH (current_function_decl
))
1465 tree decl
= TREE_VEC_ELT (decl_map
, slot
);
1466 DECL_NAME (decl
) = name
;
1467 DECL_ASSEMBLER_NAME (decl
) = name
;
1468 if (TREE_CODE (decl
) != PARM_DECL
|| TREE_TYPE (decl
) != type
)
1469 warning ("bad type in parameter debug info");
1474 int end_pc
= start_pc
+ length
;
1475 tree decl
= build_decl (VAR_DECL
, name
, type
);
1476 if (end_pc
> DECL_CODE_LENGTH (current_function_decl
))
1478 warning_with_decl (decl
,
1479 "bad PC range for debug info for local `%s'");
1480 end_pc
= DECL_CODE_LENGTH (current_function_decl
);
1482 DECL_LANG_SPECIFIC (decl
)
1483 = (struct lang_decl
*) permalloc (sizeof (struct lang_decl_var
));
1484 DECL_LOCAL_SLOT_NUMBER (decl
) = slot
;
1485 DECL_LOCAL_START_PC (decl
) = start_pc
;
1486 DECL_LOCAL_END_PC (decl
) = end_pc
;
1488 /* Now insert the new decl in the proper place in
1489 pending_local_decls. We are essentially doing an insertion sort,
1490 which works fine, since the list input will normally already
1492 ptr
= &pending_local_decls
;
1493 while (*ptr
!= NULL_TREE
1494 && (DECL_LOCAL_START_PC (*ptr
) > start_pc
1495 || (DECL_LOCAL_START_PC (*ptr
) == start_pc
1496 && DECL_LOCAL_END_PC (*ptr
) < end_pc
)))
1497 ptr
= &TREE_CHAIN (*ptr
);
1498 TREE_CHAIN (decl
) = *ptr
;
1503 pending_local_decls
= nreverse (pending_local_decls
);
1505 /* Fill in default names for the parameters. */
1506 for (parm
= DECL_ARGUMENTS (current_function_decl
), i
= 0;
1507 parm
!= NULL_TREE
; parm
= TREE_CHAIN (parm
), i
++)
1509 if (DECL_NAME (parm
) == NULL_TREE
)
1511 int arg_i
= METHOD_STATIC (current_function_decl
) ? i
+1 : i
;
1513 DECL_NAME (parm
) = get_identifier ("this");
1517 sprintf (buffer
, "ARG_%d", arg_i
);
1518 DECL_NAME (parm
) = get_identifier (buffer
);
1520 DECL_ASSEMBLER_NAME (parm
) = DECL_NAME (parm
);
1526 build_result_decl (fndecl
)
1529 tree restype
= TREE_TYPE (TREE_TYPE (fndecl
));
1530 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1531 if (INTEGRAL_TYPE_P (restype
)
1532 && TYPE_PRECISION (restype
) < TYPE_PRECISION (integer_type_node
))
1533 restype
= integer_type_node
;
1534 return (DECL_RESULT (fndecl
) = build_decl (RESULT_DECL
, NULL_TREE
, restype
));
1538 complete_start_java_method (fndecl
)
1541 if (! flag_emit_class_files
)
1543 /* Initialize the RTL code for the function. */
1544 init_function_start (fndecl
, input_filename
, lineno
);
1546 /* Set up parameters and prepare for return, for the function. */
1547 expand_function_start (fndecl
, 0);
1550 /* Allocate further tree nodes temporarily during compilation
1551 of this function only. */
1552 temporary_allocation ();
1555 /* If this fcn was already referenced via a block-scope `extern' decl (or
1556 an implicit decl), propagate certain information about the usage. */
1557 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl
)))
1558 TREE_ADDRESSABLE (current_function_decl
) = 1;
1562 if (METHOD_STATIC (fndecl
) && ! METHOD_PRIVATE (fndecl
)
1563 && ! flag_emit_class_files
1564 && ! CLASS_INTERFACE (TYPE_NAME (current_class
)))
1566 tree clas
= DECL_CONTEXT (fndecl
);
1567 tree init
= build (CALL_EXPR
, void_type_node
,
1568 build_address_of (soft_initclass_node
),
1569 build_tree_list (NULL_TREE
, build_class_ref (clas
)),
1571 TREE_SIDE_EFFECTS (init
) = 1;
1572 expand_expr_stmt (init
);
1575 /* Push local variables. Function compiled from source code are
1576 using a different local variables management, and for them,
1577 pushlevel shouldn't be called from here. */
1578 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl
)))
1581 if (! flag_emit_class_files
)
1582 expand_start_bindings (1);
1585 if (METHOD_SYNCHRONIZED (fndecl
) && ! flag_emit_class_files
)
1587 /* Warp function body with a monitorenter plus monitorexit cleanup. */
1588 tree enter
, exit
, lock
;
1589 if (METHOD_STATIC (fndecl
))
1590 lock
= build_class_ref (DECL_CONTEXT (fndecl
));
1592 lock
= DECL_ARGUMENTS (fndecl
);
1593 BUILD_MONITOR_ENTER (enter
, lock
);
1594 BUILD_MONITOR_EXIT (exit
, lock
);
1595 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl
)))
1597 expand_expr_stmt (enter
);
1598 expand_decl_cleanup (NULL_TREE
, exit
);
1602 tree function_body
= DECL_FUNCTION_BODY (fndecl
);
1603 tree body
= BLOCK_EXPR_BODY (function_body
);
1604 lock
= build (WITH_CLEANUP_EXPR
, void_type_node
,
1605 enter
, NULL_TREE
, exit
);
1606 TREE_SIDE_EFFECTS (lock
) = 1;
1607 lock
= build (COMPOUND_EXPR
, TREE_TYPE (body
), lock
, body
);
1608 TREE_SIDE_EFFECTS (lock
) = 1;
1609 lock
= build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (body
), lock
);
1610 TREE_SIDE_EFFECTS (lock
) = 1;
1611 BLOCK_EXPR_BODY (function_body
) = lock
;
1617 start_java_method (fndecl
)
1623 current_function_decl
= fndecl
;
1624 announce_function (fndecl
);
1626 i
= DECL_MAX_LOCALS(fndecl
) + DECL_MAX_STACK(fndecl
);
1627 decl_map
= make_tree_vec (i
);
1628 type_map
= (tree
*) oballoc (i
* sizeof (tree
));
1630 pushlevel (1); /* Push parameters. */
1632 ptr
= &DECL_ARGUMENTS (fndecl
);
1633 for (tem
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)), i
= 0;
1634 tem
!= end_params_node
; tem
= TREE_CHAIN (tem
), i
++)
1636 tree parm_name
= NULL_TREE
, parm_decl
;
1637 tree parm_type
= TREE_VALUE (tem
);
1638 if (i
>= DECL_MAX_LOCALS(fndecl
))
1639 fatal ("function has more parameters than local slots");
1641 parm_decl
= build_decl (PARM_DECL
, parm_name
, parm_type
);
1642 DECL_CONTEXT (parm_decl
) = fndecl
;
1643 if (PROMOTE_PROTOTYPES
1644 && TYPE_PRECISION (parm_type
) < TYPE_PRECISION (integer_type_node
)
1645 && INTEGRAL_TYPE_P (parm_type
))
1646 parm_type
= integer_type_node
;
1647 DECL_ARG_TYPE (parm_decl
) = parm_type
;
1650 ptr
= &TREE_CHAIN (parm_decl
);
1652 /* Add parm_decl to the decl_map. */
1653 push_jvm_slot (i
, parm_decl
);
1655 type_map
[i
] = TREE_TYPE (parm_decl
);
1656 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl
)))
1659 type_map
[i
] = void_type_node
;
1663 DECL_ARG_SLOT_COUNT (current_function_decl
) = i
;
1665 while (i
< DECL_MAX_LOCALS(fndecl
))
1666 type_map
[i
++] = NULL_TREE
;
1668 build_result_decl (fndecl
);
1669 complete_start_java_method (fndecl
);
1675 tree fndecl
= current_function_decl
;
1676 int flag_asynchronous_exceptions
= asynchronous_exceptions
;
1678 expand_end_bindings (getdecls (), 1, 0);
1679 /* pop out of function */
1682 /* pop out of its parameters */
1685 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
1689 /* Generate rtl for function exit. */
1690 expand_function_end (input_filename
, lineno
, 0);
1692 /* FIXME: If the current method contains any exception handlers,
1693 force asynchronous_exceptions: this is necessary because signal
1694 handlers in libjava may throw exceptions. This is far from being
1695 a perfect solution, but it's better than doing nothing at all.*/
1697 asynchronous_exceptions
= 1;
1699 /* Run the optimizers and output assembler code for this function. */
1700 rest_of_compilation (fndecl
);
1702 current_function_decl
= NULL_TREE
;
1703 permanent_allocation (1);
1704 asynchronous_exceptions
= flag_asynchronous_exceptions
;