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