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