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