]> gcc.gnu.org Git - gcc.git/blob - gcc/java/decl.c
* decl.c (init_decl_processing): Initialize sizetype properly.
[gcc.git] / gcc / java / decl.c
1 /* Process declarations and variables for the GNU compiler for the
2 Java(TM) language.
3
4 Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
5
6 This file is part of GNU CC.
7
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)
11 any later version.
12
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.
17
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.
22
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. */
26
27 /* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
28
29 #include "config.h"
30 #include "system.h"
31 #include "tree.h"
32 #include "toplev.h"
33 #include "flags.h"
34 #include "java-tree.h"
35 #include "jcf.h"
36 #include "toplev.h"
37 #include "function.h"
38 #include "except.h"
39 #include "defaults.h"
40 #include "java-except.h"
41
42 #if defined (DEBUG_JAVA_BINDING_LEVELS)
43 extern void indent PROTO((void));
44 #endif
45
46 static tree push_jvm_slot PARAMS ((int, tree));
47 static tree lookup_name_current_level PARAMS ((tree));
48 static tree push_promoted_type PARAMS ((const char *, tree));
49 static struct binding_level *make_binding_level PARAMS ((void));
50
51 /* Set to non-zero value in order to emit class initilization code
52 before static field references. */
53 extern int always_initialize_class_p;
54
55 #ifndef INT_TYPE_SIZE
56 #define INT_TYPE_SIZE BITS_PER_WORD
57 #endif
58
59 /* The DECL_MAP is a mapping from (index, type) to a decl node.
60 If index < max_locals, it is the index of a local variable.
61 if index >= max_locals, then index-max_locals is a stack slot.
62 The DECL_MAP mapping is represented as a TREE_VEC whose elements
63 are a list of decls (VAR_DECL or PARM_DECL) chained by
64 DECL_LOCAL_SLOT_CHAIN; the index finds the TREE_VEC element, and then
65 we search the chain for a decl with a matching TREE_TYPE. */
66
67 tree decl_map;
68
69 /* A list of local variables VAR_DECLs for this method that we have seen
70 debug information, but we have not reached their starting (byte) PC yet. */
71
72 tree pending_local_decls = NULL_TREE;
73
74 /* Push a local variable or stack slot into the decl_map,
75 and assign it an rtl. */
76
77 #if defined(DEBUG_JAVA_BINDING_LEVELS)
78 int binding_depth = 0;
79 int is_class_level = 0;
80 int current_pc;
81
82 void
83 indent ()
84 {
85 register unsigned i;
86
87 for (i = 0; i < binding_depth*2; i++)
88 putc (' ', stderr);
89 }
90 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
91
92 static tree
93 push_jvm_slot (index, decl)
94 int index;
95 tree decl;
96 {
97 struct rtx_def *rtl = NULL;
98 tree type = TREE_TYPE (decl);
99 tree tmp;
100
101 DECL_CONTEXT (decl) = current_function_decl;
102 layout_decl (decl, 0);
103
104 /* See if we have an appropriate rtl (i.e. same mode) at this index.
105 If so, we must use it. */
106 tmp = TREE_VEC_ELT (decl_map, index);
107 while (tmp != NULL_TREE)
108 {
109 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
110 rtl = DECL_RTL (tmp);
111 if (rtl != NULL)
112 break;
113 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
114 }
115 if (rtl != NULL)
116 DECL_RTL (decl) = rtl;
117 else
118 {
119 if (index >= DECL_MAX_LOCALS (current_function_decl))
120 DECL_REGISTER (decl) = 1;
121 expand_decl (decl);
122 }
123
124 /* Now link the decl into the decl_map. */
125 if (DECL_LANG_SPECIFIC (decl) == NULL)
126 {
127 DECL_LANG_SPECIFIC (decl)
128 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
129 DECL_LOCAL_START_PC (decl) = 0;
130 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
131 DECL_LOCAL_SLOT_NUMBER (decl) = index;
132 }
133 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
134 TREE_VEC_ELT (decl_map, index) = decl;
135 return decl;
136 }
137
138 /* Find a VAR_DECL (or PARM_DECL) at local index INDEX that has type TYPE,
139 that is valid at PC (or -1 if any pc).
140 If there is no existing matching decl, allocate one.
141 If we find a decl with matching modes but different types,
142 we re-use the rtl, but create a new decl. */
143
144 tree
145 find_local_variable (index, type, pc)
146 int index;
147 tree type;
148 int pc;
149 {
150 tree decl = TREE_VEC_ELT (decl_map, index);
151 tree best = NULL_TREE;
152 while (decl != NULL_TREE)
153 {
154 int in_range;
155 in_range = pc < 0
156 || (pc >= DECL_LOCAL_START_PC (decl)
157 && pc < DECL_LOCAL_END_PC (decl));
158
159 if ((TREE_TYPE (decl) == type
160 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
161 && type == ptr_type_node))
162 && in_range)
163 {
164 if (best == NULL_TREE
165 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type)
166 || DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
167 || DECL_LOCAL_END_PC (decl) < DECL_LOCAL_START_PC (decl))
168 best = decl;
169 }
170 decl = DECL_LOCAL_SLOT_CHAIN (decl);
171 }
172 if (best != NULL_TREE)
173 return best;
174 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
175 }
176
177
178 /* Same as find_local_index, except that INDEX is a stack index. */
179
180 tree
181 find_stack_slot (index, type)
182 int index;
183 tree type;
184 {
185 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
186 type, -1);
187 }
188
189 struct binding_level
190 {
191 /* A chain of _DECL nodes for all variables, constants, functions,
192 * and typedef types. These are in the reverse of the order supplied.
193 */
194 tree names;
195
196 /* For each level, a list of shadowed outer-level local definitions
197 to be restored when this level is popped.
198 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
199 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
200 tree shadowed;
201
202 /* For each level (except not the global one),
203 a chain of BLOCK nodes for all the levels
204 that were entered and exited one level down. */
205 tree blocks;
206
207 /* The BLOCK node for this level, if one has been preallocated.
208 If 0, the BLOCK is allocated (if needed) when the level is popped. */
209 tree this_block;
210
211 /* The binding level which this one is contained in (inherits from). */
212 struct binding_level *level_chain;
213
214 /* 1 means make a BLOCK for this level regardless of all else.
215 2 for temporary binding contours created by the compiler. */
216 char keep;
217
218 /* Nonzero means make a BLOCK if this level has any subblocks. */
219 char keep_if_subblocks;
220
221 /* Nonzero if this level can safely have additional
222 cleanup-needing variables added to it. */
223 char more_cleanups_ok;
224 char have_cleanups;
225
226 /* The bytecode PC that marks the end of this level. */
227 int end_pc;
228 /* The bytecode PC that marks the start of this level. */
229 int start_pc;
230
231 #if defined(DEBUG_JAVA_BINDING_LEVELS)
232 /* Binding depth at which this level began. */
233 unsigned binding_depth;
234 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
235 };
236
237 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
238
239 /* The binding level currently in effect. */
240
241 static struct binding_level *current_binding_level;
242
243 /* A chain of binding_level structures awaiting reuse. */
244
245 static struct binding_level *free_binding_level;
246
247 /* The outermost binding level, for names of file scope.
248 This is created when the compiler is started and exists
249 through the entire run. */
250
251 static struct binding_level *global_binding_level;
252
253 /* A PC value bigger than any PC value we may ever may encounter. */
254
255 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
256
257 /* Binding level structures are initialized by copying this one. */
258
259 static struct binding_level clear_binding_level
260 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
261 NULL_BINDING_LEVEL, 0, 0, 0, 0, LARGEST_PC, 0};
262
263 #if 0
264 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
265 that have names. Here so we can clear out their names' definitions
266 at the end of the function. */
267
268 static tree named_labels;
269
270 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
271
272 static tree shadowed_labels;
273 #endif
274
275 int flag_traditional;
276
277 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
278
279 static int keep_next_level_flag;
280
281 /* Nonzero means make a BLOCK for the next level pushed
282 if it has subblocks. */
283
284 static int keep_next_if_subblocks;
285
286 tree object_type_node;
287 tree unqualified_object_id_node;
288 tree object_ptr_type_node;
289 tree string_type_node;
290 tree string_ptr_type_node;
291 tree throwable_type_node;
292 tree runtime_exception_type_node;
293 tree error_exception_type_node;
294 tree *predef_filenames;
295 int predef_filenames_size;
296
297 tree boolean_type_node;
298
299 tree return_address_type_node;
300
301 tree byte_type_node;
302 tree short_type_node;
303 tree int_type_node;
304 tree long_type_node;
305
306 tree promoted_byte_type_node;
307 tree promoted_short_type_node;
308 tree promoted_char_type_node;
309 tree promoted_boolean_type_node;
310
311 tree unsigned_byte_type_node;
312 tree unsigned_short_type_node;
313 tree unsigned_int_type_node;
314 tree unsigned_long_type_node;
315
316 /* The type for struct methodtable. */
317 tree methodtable_type;
318 tree methodtable_ptr_type;
319
320 tree utf8const_type;
321 tree utf8const_ptr_type;
322 tree class_type_node;
323 tree class_ptr_type;
324 tree field_type_node;
325 tree field_ptr_type_node;
326 tree field_info_union_node;
327 tree jexception_type;
328 tree jexception_ptr_type;
329 tree lineNumberEntry_type;
330 tree lineNumbers_type;
331 tree constants_type_node;
332 tree dtable_type;
333 tree dtable_ptr_type;
334 tree method_type_node;
335 tree method_ptr_type_node;
336 tree nativecode_ptr_array_type_node;
337 tree one_elt_array_domain_type;
338 tree access_flags_type_node;
339 tree class_dtable_decl;
340
341 /* Expressions that are constants with value zero, of types
342 `long', `float' and `double'. */
343 tree long_zero_node;
344 tree float_zero_node;
345 tree double_zero_node;
346
347 tree empty_stmt_node;
348
349 /* Nodes for boolean constants TRUE and FALSE. */
350 tree boolean_true_node, boolean_false_node;
351
352 tree TYPE_identifier_node;
353 tree init_identifier_node;
354 tree clinit_identifier_node;
355 tree finit_identifier_node;
356 tree void_signature_node;
357 tree length_identifier_node;
358 tree this_identifier_node;
359 tree super_identifier_node;
360 tree continue_identifier_node;
361
362 tree end_params_node;
363
364 /* References to internal libjava functions we use. */
365 tree alloc_object_node;
366 tree soft_instanceof_node;
367 tree soft_checkcast_node;
368 tree soft_initclass_node;
369 tree soft_newarray_node;
370 tree soft_anewarray_node;
371 tree soft_multianewarray_node;
372 tree soft_badarrayindex_node;
373 tree throw_node [2];
374 tree soft_checkarraystore_node;
375 tree soft_monitorenter_node;
376 tree soft_monitorexit_node;
377 tree soft_lookupinterfacemethod_node;
378 tree soft_fmod_node;
379 tree soft_exceptioninfo_call_node;
380 tree soft_idiv_node;
381 tree soft_irem_node;
382 tree soft_ldiv_node;
383 tree soft_lrem_node;
384
385 /* Build (and pushdecl) a "promoted type" for all standard
386 types shorter than int. */
387
388 static tree
389 push_promoted_type (name, actual_type)
390 const char *name;
391 tree actual_type;
392 {
393 tree type = make_node (TREE_CODE (actual_type));
394 #if 1
395 tree in_min = TYPE_MIN_VALUE (int_type_node);
396 tree in_max = TYPE_MAX_VALUE (int_type_node);
397 #else
398 tree in_min = TYPE_MIN_VALUE (actual_type);
399 tree in_max = TYPE_MAX_VALUE (actual_type);
400 #endif
401 TYPE_MIN_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_min),
402 TREE_INT_CST_HIGH (in_min));
403 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
404 TYPE_MAX_VALUE (type) = build_int_2 (TREE_INT_CST_LOW (in_max),
405 TREE_INT_CST_HIGH (in_max));
406 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
407 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
408 layout_type (type);
409 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
410 return type;
411 }
412
413 /* Nodes for integer constants. */
414 tree integer_two_node, integer_four_node;
415 tree integer_negative_one_node;
416
417 /* Return a definition for a builtin function named NAME and whose data type
418 is TYPE. TYPE should be a function type with argument types.
419 FUNCTION_CODE tells later passes how to compile calls to this function.
420 See tree.h for its possible values.
421
422 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
423 the name to be called if we can't opencode the function. */
424
425 tree
426 builtin_function (name, type, function_code, class, library_name)
427 const char *name;
428 tree type;
429 int function_code;
430 enum built_in_class class;
431 const char *library_name;
432 {
433 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
434 DECL_EXTERNAL (decl) = 1;
435 TREE_PUBLIC (decl) = 1;
436 if (library_name)
437 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
438 make_decl_rtl (decl, NULL_PTR, 1);
439 pushdecl (decl);
440 DECL_BUILT_IN_CLASS (decl) = class;
441 DECL_FUNCTION_CODE (decl) = function_code;
442 return decl;
443 }
444
445 void
446 init_decl_processing ()
447 {
448 register tree endlink;
449 tree field = NULL_TREE;
450 tree t;
451
452 current_function_decl = NULL;
453 current_binding_level = NULL_BINDING_LEVEL;
454 free_binding_level = NULL_BINDING_LEVEL;
455 pushlevel (0); /* make the binding_level structure for global names */
456 global_binding_level = current_binding_level;
457
458 error_mark_node = make_node (ERROR_MARK);
459 TREE_TYPE (error_mark_node) = error_mark_node;
460
461 /* Create sizetype first - needed for other types. */
462 initialize_sizetypes ();
463 set_sizetype (make_unsigned_type (POINTER_SIZE));
464 size_zero_node = build_int_2 (0, 0);
465 TREE_TYPE (size_zero_node) = sizetype;
466 size_one_node = build_int_2 (1, 0);
467 TREE_TYPE (size_one_node) = sizetype;
468
469 byte_type_node = make_signed_type (8);
470 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
471 short_type_node = make_signed_type (16);
472 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
473 int_type_node = make_signed_type (32);
474 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
475 long_type_node = make_signed_type (64);
476 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
477
478 unsigned_byte_type_node = make_unsigned_type (8);
479 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
480 unsigned_byte_type_node));
481 unsigned_short_type_node = make_unsigned_type (16);
482 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
483 unsigned_short_type_node));
484 unsigned_int_type_node = make_unsigned_type (32);
485 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
486 unsigned_int_type_node));
487 unsigned_long_type_node = make_unsigned_type (64);
488 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
489 unsigned_long_type_node));
490
491 integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
492
493 integer_zero_node = build_int_2 (0, 0);
494 integer_one_node = build_int_2 (1, 0);
495 integer_two_node = build_int_2 (2, 0);
496 integer_four_node = build_int_2 (4, 0);
497 integer_negative_one_node = build_int_2 (-1, 0);
498
499 long_zero_node = build_int_2 (0, 0);
500 TREE_TYPE (long_zero_node) = long_type_node;
501
502 void_type_node = make_node (VOID_TYPE);
503 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
504 layout_type (void_type_node); /* Uses size_zero_node */
505 ptr_type_node = build_pointer_type (void_type_node);
506 t = make_node (VOID_TYPE);
507 layout_type (t); /* Uses size_zero_node */
508 return_address_type_node = build_pointer_type (t);
509
510 null_pointer_node = build_int_2 (0, 0);
511 TREE_TYPE (null_pointer_node) = ptr_type_node;
512
513 /* Used by the parser to represent empty statements and blocks. */
514 empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
515 CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
516
517 #if 0
518 /* Make a type to be the domain of a few array types
519 whose domains don't really matter.
520 200 is small enough that it always fits in size_t
521 and large enough that it can hold most function names for the
522 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
523 short_array_type_node = build_prim_array_type (short_type_node, 200);
524 #endif
525 char_type_node = make_node (CHAR_TYPE);
526 TYPE_PRECISION (char_type_node) = 16;
527 fixup_unsigned_type (char_type_node);
528 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
529
530 boolean_type_node = make_node (BOOLEAN_TYPE);
531 TYPE_PRECISION (boolean_type_node) = 1;
532 fixup_unsigned_type (boolean_type_node);
533 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
534 boolean_type_node));
535 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
536 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
537
538 promoted_byte_type_node
539 = push_promoted_type ("promoted_byte", byte_type_node);
540 promoted_short_type_node
541 = push_promoted_type ("promoted_short", short_type_node);
542 promoted_char_type_node
543 = push_promoted_type ("promoted_char", char_type_node);
544 promoted_boolean_type_node
545 = push_promoted_type ("promoted_boolean", boolean_type_node);
546
547 float_type_node = make_node (REAL_TYPE);
548 TYPE_PRECISION (float_type_node) = 32;
549 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
550 float_type_node));
551 layout_type (float_type_node);
552
553 double_type_node = make_node (REAL_TYPE);
554 TYPE_PRECISION (double_type_node) = 64;
555 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
556 double_type_node));
557 layout_type (double_type_node);
558
559 float_zero_node = build_real (float_type_node, dconst0);
560 double_zero_node = build_real (double_type_node, dconst0);
561
562 /* As your adding items here, please update the code right after
563 this section, so that the filename containing the source code of
564 the pre-defined class gets registered correctly. */
565 unqualified_object_id_node = get_identifier ("Object");
566 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
567 object_ptr_type_node = promote_type (object_type_node);
568 string_type_node = lookup_class (get_identifier ("java.lang.String"));
569 string_ptr_type_node = promote_type (string_type_node);
570 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
571 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
572 runtime_exception_type_node =
573 lookup_class (get_identifier ("java.lang.RuntimeException"));
574 error_exception_type_node =
575 lookup_class (get_identifier ("java.lang.Error"));
576
577 /* This section has to be updated as items are added to the previous
578 section. */
579 predef_filenames_size = 6;
580 predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
581 predef_filenames [0] = get_identifier ("java/lang/Class.java");
582 predef_filenames [1] = get_identifier ("java/lang/Error.java");
583 predef_filenames [2] = get_identifier ("java/lang/Object.java");
584 predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
585 predef_filenames [4] = get_identifier ("java/lang/String.java");
586 predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
587
588 methodtable_type = make_node (RECORD_TYPE);
589 layout_type (methodtable_type);
590 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
591 methodtable_ptr_type = build_pointer_type (methodtable_type);
592
593 TYPE_identifier_node = get_identifier ("TYPE");
594 init_identifier_node = get_identifier ("<init>");
595 clinit_identifier_node = get_identifier ("<clinit>");
596 finit_identifier_node = get_identifier ("$finit$");
597 void_signature_node = get_identifier ("()V");
598 length_identifier_node = get_identifier ("length");
599 this_identifier_node = get_identifier ("this");
600 super_identifier_node = get_identifier ("super");
601 continue_identifier_node = get_identifier ("continue");
602
603 /* for lack of a better place to put this stub call */
604 init_expr_processing();
605
606 utf8const_type = make_node (RECORD_TYPE);
607 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
608 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
609 FINISH_RECORD (utf8const_type);
610 utf8const_ptr_type = build_pointer_type (utf8const_type);
611
612 constants_type_node = make_node (RECORD_TYPE);
613 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
614 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
615 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
616 FINISH_RECORD (constants_type_node);
617 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
618
619 access_flags_type_node = unsigned_short_type_node;
620
621 dtable_type = make_node (RECORD_TYPE);
622 dtable_ptr_type = build_pointer_type (dtable_type);
623
624 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
625 PUSH_FIELD (object_type_node, field, "sync_info", ptr_type_node);
626 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
627 FIELD_PRIVATE (t) = 1;
628 FINISH_RECORD (object_type_node);
629
630 class_dtable_decl = build_dtable_decl (class_type_node);
631 TREE_STATIC (class_dtable_decl) = 1;
632 DECL_ARTIFICIAL (class_dtable_decl) = 1;
633 DECL_IGNORED_P (class_dtable_decl) = 1;
634 rest_of_decl_compilation (class_dtable_decl, (char*) 0, 1, 0);
635
636 field_type_node = make_node (RECORD_TYPE);
637 field_ptr_type_node = build_pointer_type (field_type_node);
638 method_type_node = make_node (RECORD_TYPE);
639 method_ptr_type_node = build_pointer_type (method_type_node);
640
641 set_super_info (0, class_type_node, object_type_node, 0);
642 set_super_info (0, string_type_node, object_type_node, 0);
643 class_ptr_type = build_pointer_type (class_type_node);
644
645 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
646 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
647 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
648 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
649 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
650 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
651 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
652 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
653 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
654 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
655 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
656 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
657 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
658 PUSH_FIELD (class_type_node, field, "interfaces",
659 build_pointer_type (class_ptr_type));
660 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
661 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
662 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
663 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
664 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
665 FIELD_PRIVATE (t) = 1;
666 push_super_field (class_type_node, object_type_node);
667 FINISH_RECORD (class_type_node);
668 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
669
670 field_info_union_node = make_node (UNION_TYPE);
671 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
672 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
673 #if 0
674 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
675 #endif
676 layout_type (field_info_union_node);
677
678 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
679 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
680 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
681 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
682 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
683 FINISH_RECORD (field_type_node);
684 CLASS_LOADED_P (field_type_node) = 1;
685 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
686
687 one_elt_array_domain_type = build_index_type (integer_one_node);
688 nativecode_ptr_array_type_node
689 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
690
691 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
692 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
693 FINISH_RECORD (dtable_type);
694 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
695
696 #define jint_type int_type_node
697 #define jint_ptr_type ptr_type_node
698
699 jexception_type = make_node (RECORD_TYPE);
700 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
701 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
702 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
703 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
704 FINISH_RECORD (jexception_type);
705 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
706 jexception_ptr_type = build_pointer_type (jexception_type);
707
708 lineNumberEntry_type = make_node (RECORD_TYPE);
709 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
710 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
711 FINISH_RECORD (lineNumberEntry_type);
712
713 lineNumbers_type = make_node (RECORD_TYPE);
714 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
715 FINISH_RECORD (lineNumbers_type);
716
717 #define instn_ptr_type_node ptr_type_node /* XXX JH */
718
719 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
720
721 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
722 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
723 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
724 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
725 FINISH_RECORD (method_type_node);
726 CLASS_LOADED_P (method_type_node) = 1;
727 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
728
729 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
730
731 t = tree_cons (NULL_TREE, class_ptr_type,
732 tree_cons (NULL_TREE, int_type_node, endlink));
733 alloc_object_node = builtin_function ("_Jv_AllocObject",
734 build_function_type (ptr_type_node, t),
735 0, NOT_BUILT_IN, NULL_PTR);
736 DECL_IS_MALLOC (alloc_object_node) = 1;
737 soft_initclass_node = builtin_function ("_Jv_InitClass",
738 build_function_type (void_type_node,
739 t),
740 0, NOT_BUILT_IN,
741 NULL_PTR);
742 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
743 throw_node[0] = builtin_function ("_Jv_Throw",
744 build_function_type (ptr_type_node, t),
745 0, NOT_BUILT_IN, NULL_PTR);
746 /* Mark throw_nodes as `noreturn' functions with side effects. */
747 TREE_THIS_VOLATILE (throw_node[0]) = 1;
748 TREE_SIDE_EFFECTS (throw_node[0]) = 1;
749 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
750 throw_node[1] = builtin_function ("_Jv_Sjlj_Throw",
751 build_function_type (ptr_type_node, t),
752 0, NOT_BUILT_IN, NULL_PTR);
753 TREE_THIS_VOLATILE (throw_node[1]) = 1;
754 TREE_SIDE_EFFECTS (throw_node[1]) = 1;
755 t = build_function_type (int_type_node, endlink);
756 soft_monitorenter_node
757 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
758 NULL_PTR);
759 soft_monitorexit_node
760 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
761 NULL_PTR);
762
763 t = tree_cons (NULL_TREE, int_type_node,
764 tree_cons (NULL_TREE, int_type_node, endlink));
765 soft_newarray_node
766 = builtin_function ("_Jv_NewArray",
767 build_function_type(ptr_type_node, t),
768 0, NOT_BUILT_IN, NULL_PTR);
769 DECL_IS_MALLOC (soft_newarray_node) = 1;
770
771 t = tree_cons (NULL_TREE, int_type_node,
772 tree_cons (NULL_TREE, class_ptr_type,
773 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
774 soft_anewarray_node
775 = builtin_function ("_Jv_NewObjectArray",
776 build_function_type (ptr_type_node, t),
777 0, NOT_BUILT_IN, NULL_PTR);
778 DECL_IS_MALLOC (soft_anewarray_node) = 1;
779
780 t = tree_cons (NULL_TREE, ptr_type_node,
781 tree_cons (NULL_TREE, int_type_node, endlink));
782 soft_multianewarray_node
783 = builtin_function ("_Jv_NewMultiArray",
784 build_function_type (ptr_type_node, t),
785 0, NOT_BUILT_IN, NULL_PTR);
786 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
787
788 t = build_function_type (void_type_node,
789 tree_cons (NULL_TREE, int_type_node, endlink));
790 soft_badarrayindex_node
791 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
792 0, NOT_BUILT_IN, NULL_PTR);
793 /* Mark soft_badarrayindex_node as a `noreturn' function with side
794 effects. */
795 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
796 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
797
798 t = tree_cons (NULL_TREE, class_ptr_type,
799 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
800 soft_checkcast_node
801 = builtin_function ("_Jv_CheckCast",
802 build_function_type (ptr_type_node, t),
803 0, NOT_BUILT_IN, NULL_PTR);
804 t = tree_cons (NULL_TREE, object_ptr_type_node,
805 tree_cons (NULL_TREE, class_ptr_type, endlink));
806 soft_instanceof_node
807 = builtin_function ("_Jv_IsInstanceOf",
808 build_function_type (boolean_type_node, t),
809 0, NOT_BUILT_IN, NULL_PTR);
810 t = tree_cons (NULL_TREE, object_ptr_type_node,
811 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
812 soft_checkarraystore_node
813 = builtin_function ("_Jv_CheckArrayStore",
814 build_function_type (void_type_node, t),
815 0, NOT_BUILT_IN, NULL_PTR);
816 t = tree_cons (NULL_TREE, ptr_type_node,
817 tree_cons (NULL_TREE, ptr_type_node,
818 tree_cons (NULL_TREE, ptr_type_node, endlink)));
819 soft_lookupinterfacemethod_node
820 = builtin_function ("_Jv_LookupInterfaceMethod",
821 build_function_type (ptr_type_node, t),
822 0, NOT_BUILT_IN, NULL_PTR);
823 t = tree_cons (NULL_TREE, double_type_node,
824 tree_cons (NULL_TREE, double_type_node, endlink));
825 soft_fmod_node
826 = builtin_function ("__builtin_fmod",
827 build_function_type (double_type_node, t),
828 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod");
829
830 soft_exceptioninfo_call_node
831 = build (CALL_EXPR,
832 ptr_type_node,
833 build_address_of
834 (builtin_function ("_Jv_exception_info",
835 build_function_type (ptr_type_node, endlink),
836 0, NOT_BUILT_IN, NULL_PTR)),
837 NULL_TREE, NULL_TREE);
838 TREE_SIDE_EFFECTS (soft_exceptioninfo_call_node) = 1;
839 #if 0
840 t = tree_cons (NULL_TREE, float_type_node,
841 tree_cons (NULL_TREE, float_type_node, endlink));
842 soft_fmodf_node
843 = builtin_function ("__builtin_fmodf",
844 build_function_type (float_type_node, t),
845 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf");
846 #endif
847
848 soft_idiv_node
849 = builtin_function ("_Jv_divI",
850 build_function_type (int_type_node, t),
851 0, NOT_BUILT_IN, NULL_PTR);
852
853 soft_irem_node
854 = builtin_function ("_Jv_remI",
855 build_function_type (int_type_node, t),
856 0, NOT_BUILT_IN, NULL_PTR);
857
858 soft_ldiv_node
859 = builtin_function ("_Jv_divJ",
860 build_function_type (long_type_node, t),
861 0, NOT_BUILT_IN, NULL_PTR);
862
863 soft_lrem_node
864 = builtin_function ("_Jv_remJ",
865 build_function_type (long_type_node, t),
866 0, NOT_BUILT_IN, NULL_PTR);
867
868 init_class_processing ();
869 }
870
871
872 /* Look up NAME in the current binding level and its superiors
873 in the namespace of variables, functions and typedefs.
874 Return a ..._DECL node of some kind representing its definition,
875 or return 0 if it is undefined. */
876
877 tree
878 lookup_name (name)
879 tree name;
880 {
881 register tree val;
882 if (current_binding_level != global_binding_level
883 && IDENTIFIER_LOCAL_VALUE (name))
884 val = IDENTIFIER_LOCAL_VALUE (name);
885 else
886 val = IDENTIFIER_GLOBAL_VALUE (name);
887 return val;
888 }
889
890 /* Similar to `lookup_name' but look only at current binding level and
891 the previous one if its the parameter level. */
892
893 static tree
894 lookup_name_current_level (name)
895 tree name;
896 {
897 register tree t;
898
899 if (current_binding_level == global_binding_level)
900 return IDENTIFIER_GLOBAL_VALUE (name);
901
902 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
903 return 0;
904
905 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
906 if (DECL_NAME (t) == name)
907 break;
908
909 return t;
910 }
911
912 /* Use a binding level to record a labeled block declaration */
913
914 void
915 push_labeled_block (lb)
916 tree lb;
917 {
918 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
919 register struct binding_level *b = current_binding_level;
920 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
921 if (oldlocal != 0)
922 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
923 TREE_CHAIN (lb) = b->names;
924 b->names = lb;
925 IDENTIFIER_LOCAL_VALUE (name) = lb;
926 }
927
928 /* Pop the current binding level, reinstalling values for the previous
929 labeled block */
930
931 void
932 pop_labeled_block ()
933 {
934 struct binding_level *b = current_binding_level;
935 tree label = b->names;
936 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
937 NULL_TREE;
938 if (b->shadowed)
939 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
940 TREE_VALUE (b->shadowed);
941
942 /* Pop the current level, and free the structure for reuse. */
943 current_binding_level = current_binding_level->level_chain;
944 b->level_chain = free_binding_level;
945 free_binding_level = b;
946 }
947
948 /* Record a decl-node X as belonging to the current lexical scope.
949 Check for errors (such as an incompatible declaration for the same
950 name already seen in the same scope).
951
952 Returns either X or an old decl for the same name.
953 If an old decl is returned, it may have been smashed
954 to agree with what X says. */
955
956 tree
957 pushdecl (x)
958 tree x;
959 {
960 register tree t;
961 register tree name = DECL_NAME (x);
962 register struct binding_level *b = current_binding_level;
963
964 DECL_CONTEXT (x) = current_function_decl;
965 if (name)
966 {
967 const char *file;
968 int line;
969
970 t = lookup_name_current_level (name);
971 if (t != 0 && t == error_mark_node)
972 /* error_mark_node is 0 for a while during initialization! */
973 {
974 t = 0;
975 error_with_decl (x, "`%s' used prior to declaration");
976 }
977
978 if (t != 0)
979 {
980 file = DECL_SOURCE_FILE (t);
981 line = DECL_SOURCE_LINE (t);
982 }
983
984 /* If we're naming a hitherto-unnamed type, set its TYPE_NAME
985 to point to the TYPE_DECL.
986 Since Java does not have typedefs, a type can only have
987 one (true) name, given by a class, interface, or builtin. */
988 if (TREE_CODE (x) == TYPE_DECL
989 && TYPE_NAME (TREE_TYPE (x)) == 0
990 && TREE_TYPE (x) != error_mark_node)
991 {
992 TYPE_NAME (TREE_TYPE (x)) = x;
993 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
994 }
995
996 /* This name is new in its binding level.
997 Install the new declaration and return it. */
998 if (b == global_binding_level)
999 {
1000 /* Install a global value. */
1001
1002 IDENTIFIER_GLOBAL_VALUE (name) = x;
1003 }
1004 else
1005 {
1006 /* Here to install a non-global value. */
1007 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
1008 IDENTIFIER_LOCAL_VALUE (name) = x;
1009
1010 #if 0
1011 /* Warn if shadowing an argument at the top level of the body. */
1012 if (oldlocal != 0 && !DECL_EXTERNAL (x)
1013 /* This warning doesn't apply to the parms of a nested fcn. */
1014 && ! current_binding_level->parm_flag
1015 /* Check that this is one level down from the parms. */
1016 && current_binding_level->level_chain->parm_flag
1017 /* Check that the decl being shadowed
1018 comes from the parm level, one level up. */
1019 && chain_member (oldlocal, current_binding_level->level_chain->names))
1020 {
1021 if (TREE_CODE (oldlocal) == PARM_DECL)
1022 pedwarn ("declaration of `%s' shadows a parameter",
1023 IDENTIFIER_POINTER (name));
1024 else
1025 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
1026 IDENTIFIER_POINTER (name));
1027 }
1028
1029 /* Maybe warn if shadowing something else. */
1030 else if (warn_shadow && !DECL_EXTERNAL (x)
1031 /* No shadow warnings for internally generated vars. */
1032 && DECL_SOURCE_LINE (x) != 0
1033 /* No shadow warnings for vars made for inlining. */
1034 && ! DECL_FROM_INLINE (x))
1035 {
1036 const char *warnstring = 0;
1037
1038 if (TREE_CODE (x) == PARM_DECL
1039 && current_binding_level->level_chain->parm_flag)
1040 /* Don't warn about the parm names in function declarator
1041 within a function declarator.
1042 It would be nice to avoid warning in any function
1043 declarator in a declaration, as opposed to a definition,
1044 but there is no way to tell it's not a definition. */
1045 ;
1046 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
1047 warnstring = "declaration of `%s' shadows a parameter";
1048 else if (oldlocal != 0)
1049 warnstring = "declaration of `%s' shadows previous local";
1050 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
1051 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
1052 warnstring = "declaration of `%s' shadows global declaration";
1053
1054 if (warnstring)
1055 warning (warnstring, IDENTIFIER_POINTER (name));
1056 }
1057 #endif
1058
1059 /* If storing a local value, there may already be one (inherited).
1060 If so, record it for restoration when this binding level ends. */
1061 if (oldlocal != 0)
1062 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
1063 }
1064 }
1065
1066 /* Put decls on list in reverse order.
1067 We will reverse them later if necessary. */
1068 TREE_CHAIN (x) = b->names;
1069 b->names = x;
1070
1071 return x;
1072 }
1073 void
1074 pushdecl_force_head (x)
1075 tree x;
1076 {
1077 current_binding_level->names = x;
1078 }
1079
1080 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */
1081
1082 tree
1083 pushdecl_top_level (x)
1084 tree x;
1085 {
1086 register tree t;
1087 register struct binding_level *b = current_binding_level;
1088
1089 current_binding_level = global_binding_level;
1090 t = pushdecl (x);
1091 current_binding_level = b;
1092 return t;
1093 }
1094
1095 /* Nonzero if we are currently in the global binding level. */
1096
1097 int
1098 global_bindings_p ()
1099 {
1100 return current_binding_level == global_binding_level;
1101 }
1102
1103 /* Return the list of declarations of the current level.
1104 Note that this list is in reverse order unless/until
1105 you nreverse it; and when you do nreverse it, you must
1106 store the result back using `storedecls' or you will lose. */
1107
1108 tree
1109 getdecls ()
1110 {
1111 return current_binding_level->names;
1112 }
1113
1114 /* Create a new `struct binding_level'. */
1115
1116 static
1117 struct binding_level *
1118 make_binding_level ()
1119 {
1120 /* NOSTRICT */
1121 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
1122 }
1123
1124 void
1125 pushlevel (unused)
1126 int unused ATTRIBUTE_UNUSED;
1127 {
1128 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
1129
1130 #if 0
1131 /* If this is the top level of a function,
1132 just make sure that NAMED_LABELS is 0. */
1133
1134 if (current_binding_level == global_binding_level)
1135 named_labels = 0;
1136 #endif
1137
1138 /* Reuse or create a struct for this binding level. */
1139
1140 if (free_binding_level)
1141 {
1142 newlevel = free_binding_level;
1143 free_binding_level = free_binding_level->level_chain;
1144 }
1145 else
1146 {
1147 newlevel = make_binding_level ();
1148 }
1149
1150 /* Add this level to the front of the chain (stack) of levels that
1151 are active. */
1152
1153 *newlevel = clear_binding_level;
1154 newlevel->level_chain = current_binding_level;
1155 current_binding_level = newlevel;
1156 newlevel->keep = keep_next_level_flag;
1157 keep_next_level_flag = 0;
1158 newlevel->keep_if_subblocks = keep_next_if_subblocks;
1159 keep_next_if_subblocks = 0;
1160 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1161 newlevel->binding_depth = binding_depth;
1162 indent ();
1163 fprintf (stderr, "push %s level 0x%08x pc %d\n",
1164 (is_class_level) ? "class" : "block", newlevel, current_pc);
1165 is_class_level = 0;
1166 binding_depth++;
1167 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1168 }
1169
1170 /* Exit a binding level.
1171 Pop the level off, and restore the state of the identifier-decl mappings
1172 that were in effect when this level was entered.
1173
1174 If KEEP is nonzero, this level had explicit declarations, so
1175 and create a "block" (a BLOCK node) for the level
1176 to record its declarations and subblocks for symbol table output.
1177
1178 If FUNCTIONBODY is nonzero, this level is the body of a function,
1179 so create a block as if KEEP were set and also clear out all
1180 label names.
1181
1182 If REVERSE is nonzero, reverse the order of decls before putting
1183 them into the BLOCK. */
1184
1185 tree
1186 poplevel (keep, reverse, functionbody)
1187 int keep;
1188 int reverse;
1189 int functionbody;
1190 {
1191 register tree link;
1192 /* The chain of decls was accumulated in reverse order.
1193 Put it into forward order, just for cleanliness. */
1194 tree decls;
1195 tree subblocks = current_binding_level->blocks;
1196 tree block = 0;
1197 tree decl;
1198 int block_previously_created;
1199
1200 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1201 binding_depth--;
1202 indent ();
1203 if (current_binding_level->end_pc != LARGEST_PC)
1204 fprintf (stderr, "pop %s level 0x%08x pc %d (end pc %d)\n",
1205 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
1206 current_binding_level->end_pc);
1207 else
1208 fprintf (stderr, "pop %s level 0x%08x pc %d\n",
1209 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
1210 #if 0
1211 if (is_class_level != (current_binding_level == class_binding_level))
1212 {
1213 indent ();
1214 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
1215 }
1216 is_class_level = 0;
1217 #endif
1218 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1219
1220 keep |= current_binding_level->keep;
1221
1222 /* Get the decls in the order they were written.
1223 Usually current_binding_level->names is in reverse order.
1224 But parameter decls were previously put in forward order. */
1225
1226 if (reverse)
1227 current_binding_level->names
1228 = decls = nreverse (current_binding_level->names);
1229 else
1230 decls = current_binding_level->names;
1231
1232 /* Output any nested inline functions within this block
1233 if they weren't already output. */
1234
1235 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1236 if (TREE_CODE (decl) == FUNCTION_DECL
1237 && ! TREE_ASM_WRITTEN (decl)
1238 && DECL_INITIAL (decl) != 0
1239 && TREE_ADDRESSABLE (decl))
1240 {
1241 /* If this decl was copied from a file-scope decl
1242 on account of a block-scope extern decl,
1243 propagate TREE_ADDRESSABLE to the file-scope decl.
1244
1245 DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is
1246 true, since then the decl goes through save_for_inline_copying. */
1247 if (DECL_ABSTRACT_ORIGIN (decl) != 0
1248 && DECL_ABSTRACT_ORIGIN (decl) != decl)
1249 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1250 else
1251 {
1252 push_function_context ();
1253 output_inline_function (decl);
1254 pop_function_context ();
1255 }
1256 }
1257
1258 /* If there were any declarations in that level,
1259 or if this level is a function body,
1260 create a BLOCK to record them for the life of this function. */
1261
1262 block = 0;
1263 block_previously_created = (current_binding_level->this_block != 0);
1264 if (block_previously_created)
1265 block = current_binding_level->this_block;
1266 else if (keep || functionbody
1267 || (current_binding_level->keep_if_subblocks && subblocks != 0))
1268 block = make_node (BLOCK);
1269 if (block != 0)
1270 {
1271 BLOCK_VARS (block) = decls;
1272 BLOCK_SUBBLOCKS (block) = subblocks;
1273 }
1274
1275 /* In each subblock, record that this is its superior. */
1276
1277 for (link = subblocks; link; link = TREE_CHAIN (link))
1278 BLOCK_SUPERCONTEXT (link) = block;
1279
1280 /* Clear out the meanings of the local variables of this level. */
1281
1282 for (link = decls; link; link = TREE_CHAIN (link))
1283 {
1284 tree name = DECL_NAME (link);
1285 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
1286 {
1287 /* If the ident. was used or addressed via a local extern decl,
1288 don't forget that fact. */
1289 if (DECL_EXTERNAL (link))
1290 {
1291 if (TREE_USED (link))
1292 TREE_USED (name) = 1;
1293 if (TREE_ADDRESSABLE (link))
1294 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1295 }
1296 IDENTIFIER_LOCAL_VALUE (name) = 0;
1297 }
1298 }
1299
1300 /* Restore all name-meanings of the outer levels
1301 that were shadowed by this level. */
1302
1303 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1304 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1305
1306 /* If the level being exited is the top level of a function,
1307 check over all the labels, and clear out the current
1308 (function local) meanings of their names. */
1309
1310 if (functionbody)
1311 {
1312 /* If this is the top level block of a function,
1313 the vars are the function's parameters.
1314 Don't leave them in the BLOCK because they are
1315 found in the FUNCTION_DECL instead. */
1316
1317 BLOCK_VARS (block) = 0;
1318
1319 /* Clear out the definitions of all label names,
1320 since their scopes end here,
1321 and add them to BLOCK_VARS. */
1322
1323 #if 0
1324 for (link = named_labels; link; link = TREE_CHAIN (link))
1325 {
1326 register tree label = TREE_VALUE (link);
1327
1328 if (DECL_INITIAL (label) == 0)
1329 {
1330 error_with_decl (label, "label `%s' used but not defined");
1331 /* Avoid crashing later. */
1332 define_label (input_filename, lineno,
1333 DECL_NAME (label));
1334 }
1335 else if (warn_unused && !TREE_USED (label))
1336 warning_with_decl (label, "label `%s' defined but not used");
1337 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
1338
1339 /* Put the labels into the "variables" of the
1340 top-level block, so debugger can see them. */
1341 TREE_CHAIN (label) = BLOCK_VARS (block);
1342 BLOCK_VARS (block) = label;
1343 }
1344 #endif
1345 }
1346
1347 /* Pop the current level, and free the structure for reuse. */
1348
1349 {
1350 register struct binding_level *level = current_binding_level;
1351 current_binding_level = current_binding_level->level_chain;
1352
1353 level->level_chain = free_binding_level;
1354 free_binding_level = level;
1355 }
1356
1357 /* Dispose of the block that we just made inside some higher level. */
1358 if (functionbody)
1359 DECL_INITIAL (current_function_decl) = block;
1360 else if (block)
1361 {
1362 if (!block_previously_created)
1363 current_binding_level->blocks
1364 = chainon (current_binding_level->blocks, block);
1365 }
1366 /* If we did not make a block for the level just exited,
1367 any blocks made for inner levels
1368 (since they cannot be recorded as subblocks in that level)
1369 must be carried forward so they will later become subblocks
1370 of something else. */
1371 else if (subblocks)
1372 current_binding_level->blocks
1373 = chainon (current_binding_level->blocks, subblocks);
1374
1375 /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
1376 binding contour so that they point to the appropriate construct, i.e.
1377 either to the current FUNCTION_DECL node, or else to the BLOCK node
1378 we just constructed.
1379
1380 Note that for tagged types whose scope is just the formal parameter
1381 list for some function type specification, we can't properly set
1382 their TYPE_CONTEXTs here, because we don't have a pointer to the
1383 appropriate FUNCTION_TYPE node readily available to us. For those
1384 cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
1385 in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
1386 node which will represent the "scope" for these "parameter list local"
1387 tagged types.
1388 */
1389
1390 if (block)
1391 TREE_USED (block) = 1;
1392 return block;
1393 }
1394
1395 void
1396 maybe_pushlevels (pc)
1397 int pc;
1398 {
1399 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1400 current_pc = pc;
1401 #endif
1402
1403 while (pending_local_decls != NULL_TREE &&
1404 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
1405 {
1406 tree *ptr = &pending_local_decls;
1407 tree decl = *ptr;
1408 int end_pc = DECL_LOCAL_END_PC (decl);
1409
1410 while (*ptr != NULL_TREE
1411 && DECL_LOCAL_START_PC (*ptr) <= pc
1412 && DECL_LOCAL_END_PC (*ptr) == end_pc)
1413 ptr = &TREE_CHAIN (*ptr);
1414 pending_local_decls = *ptr;
1415 *ptr = NULL_TREE;
1416
1417 /* Force non-nested range to be nested in current range. */
1418 if (end_pc > current_binding_level->end_pc)
1419 end_pc = current_binding_level->end_pc;
1420
1421 maybe_start_try (pc, end_pc);
1422
1423 pushlevel (1);
1424 expand_start_bindings (0);
1425
1426 current_binding_level->end_pc = end_pc;
1427 current_binding_level->start_pc = pc;
1428 current_binding_level->names = decl;
1429 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1430 {
1431 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
1432 }
1433 }
1434
1435 maybe_start_try (pc, 0);
1436 }
1437
1438 void
1439 maybe_poplevels (pc)
1440 int pc;
1441 {
1442 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1443 current_pc = pc;
1444 #endif
1445
1446 while (current_binding_level->end_pc <= pc)
1447 {
1448 expand_end_bindings (getdecls (), 1, 0);
1449 maybe_end_try (current_binding_level->start_pc, pc);
1450 poplevel (1, 0, 0);
1451 }
1452 maybe_end_try (0, pc);
1453 }
1454
1455 /* Terminate any binding which began during the range beginning at
1456 start_pc. This tidies up improperly nested local variable ranges
1457 and exception handlers; a variable declared within an exception
1458 range is forcibly terminated when that exception ends. */
1459
1460 void
1461 force_poplevels (start_pc)
1462 int start_pc;
1463 {
1464 while (current_binding_level->start_pc > start_pc)
1465 {
1466 if (pedantic && current_binding_level->start_pc > start_pc)
1467 warning_with_decl (current_function_decl,
1468 "In %s: overlapped variable and exception ranges at %d",
1469 current_binding_level->start_pc);
1470 expand_end_bindings (getdecls (), 1, 0);
1471 poplevel (1, 0, 0);
1472 }
1473 }
1474
1475 /* Insert BLOCK at the end of the list of subblocks of the
1476 current binding level. This is used when a BIND_EXPR is expanded,
1477 to handle the BLOCK node inside the BIND_EXPR. */
1478
1479 void
1480 insert_block (block)
1481 tree block;
1482 {
1483 TREE_USED (block) = 1;
1484 current_binding_level->blocks
1485 = chainon (current_binding_level->blocks, block);
1486 }
1487
1488 /* Set the BLOCK node for the innermost scope
1489 (the one we are currently in). */
1490
1491 void
1492 set_block (block)
1493 register tree block;
1494 {
1495 current_binding_level->this_block = block;
1496 }
1497
1498 /* integrate_decl_tree calls this function. */
1499
1500 void
1501 copy_lang_decl (node)
1502 tree node;
1503 {
1504 int lang_decl_size
1505 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
1506 : sizeof (struct lang_decl);
1507 struct lang_decl *x = (struct lang_decl *) oballoc (lang_decl_size);
1508 bcopy ((PTR) DECL_LANG_SPECIFIC (node), (PTR) x, lang_decl_size);
1509 DECL_LANG_SPECIFIC (node) = x;
1510 }
1511
1512 /* If DECL has a cleanup, build and return that cleanup here.
1513 This is a callback called by expand_expr. */
1514
1515 tree
1516 maybe_build_cleanup (decl)
1517 tree decl ATTRIBUTE_UNUSED;
1518 {
1519 /* There are no cleanups in Java (I think). */
1520 return NULL_TREE;
1521 }
1522
1523 void
1524 give_name_to_locals (jcf)
1525 JCF *jcf;
1526 {
1527 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
1528 tree parm;
1529 pending_local_decls = NULL_TREE;
1530 if (n == 0)
1531 return;
1532 JCF_SEEK (jcf, n);
1533 n = JCF_readu2 (jcf);
1534 for (i = 0; i < n; i++)
1535 {
1536 int start_pc = JCF_readu2 (jcf);
1537 int length = JCF_readu2 (jcf);
1538 int name_index = JCF_readu2 (jcf);
1539 int signature_index = JCF_readu2 (jcf);
1540 int slot = JCF_readu2 (jcf);
1541 tree name = get_name_constant (jcf, name_index);
1542 tree type = parse_signature (jcf, signature_index);
1543 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
1544 && start_pc == 0
1545 && length == DECL_CODE_LENGTH (current_function_decl))
1546 {
1547 tree decl = TREE_VEC_ELT (decl_map, slot);
1548 DECL_NAME (decl) = name;
1549 DECL_ASSEMBLER_NAME (decl) = name;
1550 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
1551 warning ("bad type in parameter debug info");
1552 }
1553 else
1554 {
1555 tree *ptr;
1556 int end_pc = start_pc + length;
1557 tree decl = build_decl (VAR_DECL, name, type);
1558 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
1559 {
1560 warning_with_decl (decl,
1561 "bad PC range for debug info for local `%s'");
1562 end_pc = DECL_CODE_LENGTH (current_function_decl);
1563 }
1564 DECL_LANG_SPECIFIC (decl)
1565 = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
1566 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
1567 DECL_LOCAL_START_PC (decl) = start_pc;
1568 #if 0
1569 /* FIXME: The range used internally for exceptions and local
1570 variable ranges, is a half-open interval:
1571 start_pc <= pc < end_pc. However, the range used in the
1572 Java VM spec is inclusive at both ends:
1573 start_pc <= pc <= end_pc. */
1574 end_pc++;
1575 #endif
1576 DECL_LOCAL_END_PC (decl) = end_pc;
1577
1578 /* Now insert the new decl in the proper place in
1579 pending_local_decls. We are essentially doing an insertion sort,
1580 which works fine, since the list input will normally already
1581 be sorted. */
1582 ptr = &pending_local_decls;
1583 while (*ptr != NULL_TREE
1584 && (DECL_LOCAL_START_PC (*ptr) > start_pc
1585 || (DECL_LOCAL_START_PC (*ptr) == start_pc
1586 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
1587 ptr = &TREE_CHAIN (*ptr);
1588 TREE_CHAIN (decl) = *ptr;
1589 *ptr = decl;
1590 }
1591 }
1592
1593 pending_local_decls = nreverse (pending_local_decls);
1594
1595 /* Fill in default names for the parameters. */
1596 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
1597 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
1598 {
1599 if (DECL_NAME (parm) == NULL_TREE)
1600 {
1601 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
1602 if (arg_i == 0)
1603 DECL_NAME (parm) = get_identifier ("this");
1604 else
1605 {
1606 char buffer[12];
1607 sprintf (buffer, "ARG_%d", arg_i);
1608 DECL_NAME (parm) = get_identifier (buffer);
1609 }
1610 DECL_ASSEMBLER_NAME (parm) = DECL_NAME (parm);
1611 }
1612 }
1613 }
1614
1615 tree
1616 build_result_decl (fndecl)
1617 tree fndecl;
1618 {
1619 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
1620 /* To be compatible with C_PROMOTING_INTEGER_TYPE_P in cc1/cc1plus. */
1621 if (INTEGRAL_TYPE_P (restype)
1622 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
1623 restype = integer_type_node;
1624 return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
1625 }
1626
1627
1628 /* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
1629 to emit initialization code for each test flag. */
1630
1631 static boolean
1632 emit_init_test_initialization (entry, key)
1633 struct hash_entry *entry;
1634 hash_table_key key;
1635 {
1636 struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
1637 expand_decl (ite->init_test_decl);
1638
1639 expand_expr_stmt (build (MODIFY_EXPR, boolean_type_node,
1640 ite->init_test_decl, boolean_false_node));
1641
1642 return true;
1643 }
1644
1645 void
1646 complete_start_java_method (fndecl)
1647 tree fndecl;
1648 {
1649 if (! flag_emit_class_files)
1650 {
1651 /* Initialize the RTL code for the function. */
1652 init_function_start (fndecl, input_filename, lineno);
1653
1654 /* Set up parameters and prepare for return, for the function. */
1655 expand_function_start (fndecl, 0);
1656
1657 /* Emit initialization code for test flags. */
1658 if (! always_initialize_class_p)
1659 hash_traverse (&DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
1660 emit_init_test_initialization, 0);
1661 }
1662
1663 /* Allocate further tree nodes temporarily during compilation
1664 of this function only. */
1665 temporary_allocation ();
1666
1667 #if 0
1668 /* If this fcn was already referenced via a block-scope `extern' decl (or
1669 an implicit decl), propagate certain information about the usage. */
1670 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1671 TREE_ADDRESSABLE (current_function_decl) = 1;
1672
1673 #endif
1674
1675 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
1676 && ! flag_emit_class_files
1677 && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
1678 {
1679 tree clas = DECL_CONTEXT (fndecl);
1680 tree init = build (CALL_EXPR, void_type_node,
1681 build_address_of (soft_initclass_node),
1682 build_tree_list (NULL_TREE, build_class_ref (clas)),
1683 NULL_TREE);
1684 TREE_SIDE_EFFECTS (init) = 1;
1685 expand_expr_stmt (init);
1686 }
1687
1688 /* Push local variables. Function compiled from source code are
1689 using a different local variables management, and for them,
1690 pushlevel shouldn't be called from here. */
1691 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1692 {
1693 pushlevel (2);
1694 if (! flag_emit_class_files)
1695 expand_start_bindings (1);
1696 }
1697
1698 if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
1699 {
1700 /* Warp function body with a monitorenter plus monitorexit cleanup. */
1701 tree enter, exit, lock;
1702 if (METHOD_STATIC (fndecl))
1703 lock = build_class_ref (DECL_CONTEXT (fndecl));
1704 else
1705 lock = DECL_ARGUMENTS (fndecl);
1706 BUILD_MONITOR_ENTER (enter, lock);
1707 BUILD_MONITOR_EXIT (exit, lock);
1708 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
1709 {
1710 expand_expr_stmt (enter);
1711 expand_decl_cleanup (NULL_TREE, exit);
1712 }
1713 else
1714 {
1715 tree function_body = DECL_FUNCTION_BODY (fndecl);
1716 tree body = BLOCK_EXPR_BODY (function_body);
1717 lock = build (WITH_CLEANUP_EXPR, void_type_node,
1718 enter, NULL_TREE, exit);
1719 TREE_SIDE_EFFECTS (lock) = 1;
1720 lock = build (COMPOUND_EXPR, TREE_TYPE (body), lock, body);
1721 TREE_SIDE_EFFECTS (lock) = 1;
1722 lock = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (body), lock);
1723 TREE_SIDE_EFFECTS (lock) = 1;
1724 BLOCK_EXPR_BODY (function_body) = lock;
1725 }
1726 }
1727 }
1728
1729 void
1730 start_java_method (fndecl)
1731 tree fndecl;
1732 {
1733 tree tem, *ptr;
1734 int i;
1735
1736 current_function_decl = fndecl;
1737 announce_function (fndecl);
1738
1739 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
1740 decl_map = make_tree_vec (i);
1741 type_map = (tree *) oballoc (i * sizeof (tree));
1742
1743 #if defined(DEBUG_JAVA_BINDING_LEVELS)
1744 fprintf (stderr, "%s:\n", (*decl_printable_name) (fndecl, 2));
1745 current_pc = 0;
1746 #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */
1747 pushlevel (1); /* Push parameters. */
1748
1749 ptr = &DECL_ARGUMENTS (fndecl);
1750 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
1751 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
1752 {
1753 tree parm_name = NULL_TREE, parm_decl;
1754 tree parm_type = TREE_VALUE (tem);
1755 if (i >= DECL_MAX_LOCALS(fndecl))
1756 fatal ("function has more parameters than local slots");
1757
1758 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
1759 DECL_CONTEXT (parm_decl) = fndecl;
1760 if (PROMOTE_PROTOTYPES
1761 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
1762 && INTEGRAL_TYPE_P (parm_type))
1763 parm_type = integer_type_node;
1764 DECL_ARG_TYPE (parm_decl) = parm_type;
1765
1766 *ptr = parm_decl;
1767 ptr = &TREE_CHAIN (parm_decl);
1768
1769 /* Add parm_decl to the decl_map. */
1770 push_jvm_slot (i, parm_decl);
1771
1772 type_map[i] = TREE_TYPE (parm_decl);
1773 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
1774 {
1775 i++;
1776 type_map[i] = void_type_node;
1777 }
1778 }
1779 *ptr = NULL_TREE;
1780 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
1781
1782 while (i < DECL_MAX_LOCALS(fndecl))
1783 type_map[i++] = NULL_TREE;
1784
1785 build_result_decl (fndecl);
1786 complete_start_java_method (fndecl);
1787 }
1788
1789 void
1790 end_java_method ()
1791 {
1792 tree fndecl = current_function_decl;
1793 int flag_asynchronous_exceptions = asynchronous_exceptions;
1794
1795 expand_end_bindings (getdecls (), 1, 0);
1796 /* pop out of function */
1797 poplevel (1, 1, 0);
1798
1799 /* pop out of its parameters */
1800 poplevel (1, 0, 1);
1801
1802 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1803
1804 emit_handlers ();
1805
1806 /* Generate rtl for function exit. */
1807 expand_function_end (input_filename, lineno, 0);
1808
1809 /* FIXME: If the current method contains any exception handlers,
1810 force asynchronous_exceptions: this is necessary because signal
1811 handlers in libjava may throw exceptions. This is far from being
1812 a perfect solution, but it's better than doing nothing at all.*/
1813 if (catch_clauses)
1814 asynchronous_exceptions = 1;
1815
1816 /* Run the optimizers and output assembler code for this function. */
1817 rest_of_compilation (fndecl);
1818
1819 current_function_decl = NULL_TREE;
1820 permanent_allocation (1);
1821 asynchronous_exceptions = flag_asynchronous_exceptions;
1822 }
This page took 0.106282 seconds and 5 git commands to generate.