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