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