00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "config.h"
00030 #include "system.h"
00031 #include "tree.h"
00032 #include "rtl.h"
00033 #include "toplev.h"
00034 #include "flags.h"
00035 #include "java-tree.h"
00036 #include "jcf.h"
00037 #include "function.h"
00038 #include "expr.h"
00039 #include "libfuncs.h"
00040 #include "except.h"
00041 #include "java-except.h"
00042 #include "ggc.h"
00043
00044 #if defined (DEBUG_JAVA_BINDING_LEVELS)
00045 extern void indent PROTO((void));
00046 #endif
00047
00048 static tree push_jvm_slot PARAMS ((int, tree));
00049 static tree lookup_name_current_level PARAMS ((tree));
00050 static tree push_promoted_type PARAMS ((const char *, tree));
00051 static struct binding_level *make_binding_level PARAMS ((void));
00052 static tree create_primitive_vtable PARAMS ((const char *));
00053 static tree check_local_named_variable PARAMS ((tree, tree, int, int *));
00054 static tree check_local_unnamed_variable PARAMS ((tree, tree, tree));
00055
00056
00057
00058 extern int always_initialize_class_p;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 tree decl_map;
00069
00070
00071
00072
00073 static tree pending_local_decls = NULL_TREE;
00074
00075
00076
00077
00078 #if defined(DEBUG_JAVA_BINDING_LEVELS)
00079 int binding_depth = 0;
00080 int is_class_level = 0;
00081 int current_pc;
00082
00083 void
00084 indent ()
00085 {
00086 register unsigned i;
00087
00088 for (i = 0; i < binding_depth*2; i++)
00089 putc (' ', stderr);
00090 }
00091 #endif
00092
00093 static tree
00094 push_jvm_slot (index, decl)
00095 int index;
00096 tree decl;
00097 {
00098 struct rtx_def *rtl = NULL;
00099 tree type = TREE_TYPE (decl);
00100 tree tmp;
00101
00102 DECL_CONTEXT (decl) = current_function_decl;
00103 layout_decl (decl, 0);
00104
00105
00106
00107 tmp = TREE_VEC_ELT (decl_map, index);
00108 while (tmp != NULL_TREE)
00109 {
00110 if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (tmp)))
00111 rtl = DECL_RTL_IF_SET (tmp);
00112 if (rtl != NULL)
00113 break;
00114 tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
00115 }
00116 if (rtl != NULL)
00117 SET_DECL_RTL (decl, rtl);
00118 else
00119 {
00120 if (index >= DECL_MAX_LOCALS (current_function_decl))
00121 DECL_REGISTER (decl) = 1;
00122 expand_decl (decl);
00123 }
00124
00125
00126 if (DECL_LANG_SPECIFIC (decl) == NULL)
00127 {
00128 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
00129 DECL_LOCAL_START_PC (decl) = 0;
00130 DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
00131 DECL_LOCAL_SLOT_NUMBER (decl) = index;
00132 }
00133 DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
00134 TREE_VEC_ELT (decl_map, index) = decl;
00135 return decl;
00136 }
00137
00138
00139
00140
00141
00142 static tree
00143 check_local_named_variable (best, decl, pc, updated)
00144 tree best;
00145 tree decl;
00146 int pc;
00147 int *updated;
00148 {
00149 if (pc >= DECL_LOCAL_START_PC (decl)
00150 && pc < DECL_LOCAL_END_PC (decl))
00151 {
00152 if (best == NULL_TREE
00153 || (DECL_LOCAL_START_PC (decl) > DECL_LOCAL_START_PC (best)
00154 && DECL_LOCAL_END_PC (decl) < DECL_LOCAL_END_PC (best)))
00155 {
00156 *updated = 1;
00157 return decl;
00158 }
00159 }
00160
00161 return best;
00162 }
00163
00164
00165
00166
00167 static tree
00168 check_local_unnamed_variable (best, decl, type)
00169 tree best;
00170 tree decl;
00171 tree type;
00172 {
00173 if (TREE_TYPE (decl) == type
00174 || (TREE_CODE (TREE_TYPE (decl)) == TREE_CODE (type)
00175 && TYPE_PRECISION (TREE_TYPE (decl)) <= 32
00176 && TYPE_PRECISION (type) <= 32
00177 && TREE_CODE (type) != POINTER_TYPE)
00178 || (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
00179 && type == ptr_type_node))
00180 {
00181 if (best == NULL_TREE
00182 || (TREE_TYPE (decl) == type && TREE_TYPE (best) != type))
00183 return decl;
00184 }
00185
00186 return best;
00187 }
00188
00189
00190
00191
00192
00193
00194 tree
00195 find_local_variable (index, type, pc)
00196 int index;
00197 tree type;
00198 int pc;
00199 {
00200 tree decl = TREE_VEC_ELT (decl_map, index);
00201 tree best = NULL_TREE;
00202 int found_scoped_var = 0;
00203
00204
00205 while (decl != NULL_TREE)
00206 {
00207
00208
00209
00210
00211 if (DECL_NAME (decl) != NULL_TREE)
00212 {
00213
00214
00215
00216
00217 if (pc >= 0)
00218 best = check_local_named_variable (best, decl, pc,
00219 &found_scoped_var);
00220 }
00221
00222
00223 else if (!found_scoped_var)
00224 {
00225
00226
00227 best = check_local_unnamed_variable (best, decl, type);
00228 }
00229
00230 decl = DECL_LOCAL_SLOT_CHAIN (decl);
00231 }
00232
00233 if (best != NULL_TREE)
00234 return best;
00235
00236
00237 return push_jvm_slot (index, build_decl (VAR_DECL, NULL_TREE, type));
00238 }
00239
00240
00241
00242
00243 tree
00244 find_stack_slot (index, type)
00245 int index;
00246 tree type;
00247 {
00248 return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
00249 type, -1);
00250 }
00251
00252 struct binding_level
00253 {
00254
00255
00256
00257 tree names;
00258
00259
00260
00261
00262
00263 tree shadowed;
00264
00265
00266
00267
00268 tree blocks;
00269
00270
00271
00272 tree this_block;
00273
00274
00275 struct binding_level *level_chain;
00276
00277
00278 int end_pc;
00279
00280 int start_pc;
00281
00282 #if defined(DEBUG_JAVA_BINDING_LEVELS)
00283
00284 unsigned binding_depth;
00285 #endif
00286 };
00287
00288 #define NULL_BINDING_LEVEL (struct binding_level *) NULL
00289
00290
00291
00292 static struct binding_level *current_binding_level;
00293
00294
00295
00296 static struct binding_level *free_binding_level;
00297
00298
00299
00300
00301
00302 static struct binding_level *global_binding_level;
00303
00304
00305
00306 #define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
00307
00308
00309
00310 static struct binding_level clear_binding_level
00311 = {NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
00312 NULL_BINDING_LEVEL, LARGEST_PC, 0};
00313
00314 #if 0
00315
00316
00317
00318
00319 static tree named_labels;
00320
00321
00322
00323 static tree shadowed_labels;
00324 #endif
00325
00326 int flag_traditional;
00327
00328 tree java_global_trees[JTI_MAX];
00329
00330
00331
00332
00333 static tree
00334 push_promoted_type (name, actual_type)
00335 const char *name;
00336 tree actual_type;
00337 {
00338 tree type = make_node (TREE_CODE (actual_type));
00339 #if 1
00340 tree in_min = TYPE_MIN_VALUE (int_type_node);
00341 tree in_max = TYPE_MAX_VALUE (int_type_node);
00342 #else
00343 tree in_min = TYPE_MIN_VALUE (actual_type);
00344 tree in_max = TYPE_MAX_VALUE (actual_type);
00345 #endif
00346 TYPE_MIN_VALUE (type) = copy_node (in_min);
00347 TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
00348 TYPE_MAX_VALUE (type) = copy_node (in_max);
00349 TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
00350 TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
00351 layout_type (type);
00352 pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
00353 return type;
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 tree
00365 builtin_function (name, type, function_code, class, library_name)
00366 const char *name;
00367 tree type;
00368 int function_code;
00369 enum built_in_class class;
00370 const char *library_name;
00371 {
00372 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
00373 DECL_EXTERNAL (decl) = 1;
00374 TREE_PUBLIC (decl) = 1;
00375 if (library_name)
00376 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
00377 make_decl_rtl (decl, NULL);
00378 pushdecl (decl);
00379 DECL_BUILT_IN_CLASS (decl) = class;
00380 DECL_FUNCTION_CODE (decl) = function_code;
00381 return decl;
00382 }
00383
00384
00385 static tree
00386 create_primitive_vtable (name)
00387 const char *name;
00388 {
00389 tree r;
00390 char buf[50];
00391
00392 sprintf (buf, "_Jv_%sVTable", name);
00393 r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
00394 DECL_EXTERNAL (r) = 1;
00395 return r;
00396 }
00397
00398 void
00399 java_init_decl_processing ()
00400 {
00401 register tree endlink;
00402 tree field = NULL_TREE;
00403 tree t;
00404
00405 init_class_processing ();
00406
00407 current_function_decl = NULL;
00408 current_binding_level = NULL_BINDING_LEVEL;
00409 free_binding_level = NULL_BINDING_LEVEL;
00410 pushlevel (0);
00411 global_binding_level = current_binding_level;
00412
00413
00414
00415 error_mark_node = make_node (ERROR_MARK);
00416 TREE_TYPE (error_mark_node) = error_mark_node;
00417
00418
00419 initialize_sizetypes ();
00420
00421 byte_type_node = make_signed_type (8);
00422 pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
00423 short_type_node = make_signed_type (16);
00424 pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
00425 int_type_node = make_signed_type (32);
00426 pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
00427 long_type_node = make_signed_type (64);
00428 pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
00429
00430 unsigned_byte_type_node = make_unsigned_type (8);
00431 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
00432 unsigned_byte_type_node));
00433 unsigned_short_type_node = make_unsigned_type (16);
00434 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
00435 unsigned_short_type_node));
00436 unsigned_int_type_node = make_unsigned_type (32);
00437 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
00438 unsigned_int_type_node));
00439 unsigned_long_type_node = make_unsigned_type (64);
00440 pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
00441 unsigned_long_type_node));
00442
00443 set_sizetype (make_unsigned_type (POINTER_SIZE));
00444
00445
00446 integer_type_node = type_for_size (INT_TYPE_SIZE, 0);
00447 integer_zero_node = build_int_2 (0, 0);
00448 integer_one_node = build_int_2 (1, 0);
00449 integer_two_node = build_int_2 (2, 0);
00450 integer_four_node = build_int_2 (4, 0);
00451 integer_minus_one_node = build_int_2 (-1, -1);
00452
00453 size_zero_node = size_int (0);
00454 size_one_node = size_int (1);
00455 bitsize_zero_node = bitsize_int (0);
00456 bitsize_one_node = bitsize_int (1);
00457 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
00458
00459 long_zero_node = build_int_2 (0, 0);
00460 TREE_TYPE (long_zero_node) = long_type_node;
00461
00462 void_type_node = make_node (VOID_TYPE);
00463 pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
00464 layout_type (void_type_node);
00465 ptr_type_node = build_pointer_type (void_type_node);
00466 t = make_node (VOID_TYPE);
00467 layout_type (t);
00468 return_address_type_node = build_pointer_type (t);
00469
00470 null_pointer_node = build_int_2 (0, 0);
00471 TREE_TYPE (null_pointer_node) = ptr_type_node;
00472
00473
00474 empty_stmt_node = build1 (NOP_EXPR, void_type_node, size_zero_node);
00475 CAN_COMPLETE_NORMALLY (empty_stmt_node) = 1;
00476
00477 #if 0
00478
00479
00480
00481
00482
00483 short_array_type_node = build_prim_array_type (short_type_node, 200);
00484 #endif
00485 char_type_node = make_node (CHAR_TYPE);
00486 TYPE_PRECISION (char_type_node) = 16;
00487 fixup_unsigned_type (char_type_node);
00488 pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
00489
00490 boolean_type_node = make_node (BOOLEAN_TYPE);
00491 TYPE_PRECISION (boolean_type_node) = 1;
00492 fixup_unsigned_type (boolean_type_node);
00493 pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
00494 boolean_type_node));
00495 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
00496 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
00497
00498 promoted_byte_type_node
00499 = push_promoted_type ("promoted_byte", byte_type_node);
00500 promoted_short_type_node
00501 = push_promoted_type ("promoted_short", short_type_node);
00502 promoted_char_type_node
00503 = push_promoted_type ("promoted_char", char_type_node);
00504 promoted_boolean_type_node
00505 = push_promoted_type ("promoted_boolean", boolean_type_node);
00506
00507 float_type_node = make_node (REAL_TYPE);
00508 TYPE_PRECISION (float_type_node) = 32;
00509 pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
00510 float_type_node));
00511 layout_type (float_type_node);
00512
00513 double_type_node = make_node (REAL_TYPE);
00514 TYPE_PRECISION (double_type_node) = 64;
00515 pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
00516 double_type_node));
00517 layout_type (double_type_node);
00518
00519 float_zero_node = build_real (float_type_node, dconst0);
00520 double_zero_node = build_real (double_type_node, dconst0);
00521
00522
00523 boolean_array_vtable = create_primitive_vtable ("boolean");
00524 byte_array_vtable = create_primitive_vtable ("byte");
00525 char_array_vtable = create_primitive_vtable ("char");
00526 short_array_vtable = create_primitive_vtable ("short");
00527 int_array_vtable = create_primitive_vtable ("int");
00528 long_array_vtable = create_primitive_vtable ("long");
00529 float_array_vtable = create_primitive_vtable ("float");
00530 double_array_vtable = create_primitive_vtable ("double");
00531
00532
00533
00534
00535 unqualified_object_id_node = get_identifier ("Object");
00536 object_type_node = lookup_class (get_identifier ("java.lang.Object"));
00537 object_ptr_type_node = promote_type (object_type_node);
00538 string_type_node = lookup_class (get_identifier ("java.lang.String"));
00539 string_ptr_type_node = promote_type (string_type_node);
00540 class_type_node = lookup_class (get_identifier ("java.lang.Class"));
00541 throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
00542 exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
00543 runtime_exception_type_node =
00544 lookup_class (get_identifier ("java.lang.RuntimeException"));
00545 error_exception_type_node =
00546 lookup_class (get_identifier ("java.lang.Error"));
00547 class_not_found_type_node =
00548 lookup_class (get_identifier ("java.lang.ClassNotFoundException"));
00549 no_class_def_found_type_node =
00550 lookup_class (get_identifier ("java.lang.NoClassDefFoundError"));
00551
00552 rawdata_ptr_type_node
00553 = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
00554
00555 add_predefined_file (get_identifier ("java/lang/Class.java"));
00556 add_predefined_file (get_identifier ("java/lang/Error.java"));
00557 add_predefined_file (get_identifier ("java/lang/Object.java"));
00558 add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
00559 add_predefined_file (get_identifier ("java/lang/String.java"));
00560 add_predefined_file (get_identifier ("java/lang/Throwable.java"));
00561 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
00562 add_predefined_file (get_identifier ("java/lang/Exception.java"));
00563 add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
00564 add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
00565 add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
00566
00567 methodtable_type = make_node (RECORD_TYPE);
00568 layout_type (methodtable_type);
00569 build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
00570 methodtable_ptr_type = build_pointer_type (methodtable_type);
00571
00572 TYPE_identifier_node = get_identifier ("TYPE");
00573 init_identifier_node = get_identifier ("<init>");
00574 clinit_identifier_node = get_identifier ("<clinit>");
00575 finit_identifier_node = get_identifier ("finit$");
00576 instinit_identifier_node = get_identifier ("instinit$");
00577 void_signature_node = get_identifier ("()V");
00578 length_identifier_node = get_identifier ("length");
00579 finalize_identifier_node = get_identifier ("finalize");
00580 this_identifier_node = get_identifier ("this");
00581 super_identifier_node = get_identifier ("super");
00582 continue_identifier_node = get_identifier ("continue");
00583 access0_identifier_node = get_identifier ("access$0");
00584 classdollar_identifier_node = get_identifier ("class$");
00585
00586
00587 init_expr_processing();
00588
00589 utf8const_type = make_node (RECORD_TYPE);
00590 PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
00591 PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
00592 FINISH_RECORD (utf8const_type);
00593 utf8const_ptr_type = build_pointer_type (utf8const_type);
00594
00595 constants_type_node = make_node (RECORD_TYPE);
00596 PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
00597 PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
00598 PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
00599 FINISH_RECORD (constants_type_node);
00600 build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
00601
00602 access_flags_type_node = unsigned_short_type_node;
00603
00604 dtable_type = make_node (RECORD_TYPE);
00605 dtable_ptr_type = build_pointer_type (dtable_type);
00606
00607 one_elt_array_domain_type = build_index_type (integer_one_node);
00608 otable_type = build_array_type (integer_type_node,
00609 one_elt_array_domain_type);
00610 otable_ptr_type = build_pointer_type (otable_type);
00611
00612 method_symbol_type = make_node (RECORD_TYPE);
00613 PUSH_FIELD (method_symbol_type, field, "clname", utf8const_ptr_type);
00614 PUSH_FIELD (method_symbol_type, field, "name", utf8const_ptr_type);
00615 PUSH_FIELD (method_symbol_type, field, "signature", utf8const_ptr_type);
00616 FINISH_RECORD (method_symbol_type);
00617
00618 method_symbols_array_type = build_array_type (method_symbol_type,
00619 one_elt_array_domain_type);
00620 method_symbols_array_ptr_type = build_pointer_type
00621 (method_symbols_array_type);
00622
00623 otable_decl = build_decl (VAR_DECL, get_identifier ("otable"), otable_type);
00624 DECL_EXTERNAL (otable_decl) = 1;
00625 TREE_STATIC (otable_decl) = 1;
00626 TREE_READONLY (otable_decl) = 1;
00627 pushdecl (otable_decl);
00628
00629 otable_syms_decl = build_decl (VAR_DECL, get_identifier ("otable_syms"),
00630 method_symbols_array_type);
00631 TREE_STATIC (otable_syms_decl) = 1;
00632 TREE_CONSTANT (otable_syms_decl) = 1;
00633 pushdecl (otable_syms_decl);
00634
00635 PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
00636
00637
00638
00639 if (! flag_hash_synchronization)
00640 PUSH_FIELD (object_type_node, field, "sync_info",
00641 build_pointer_type (object_type_node));
00642 for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
00643 FIELD_PRIVATE (t) = 1;
00644 FINISH_RECORD (object_type_node);
00645
00646 field_type_node = make_node (RECORD_TYPE);
00647 field_ptr_type_node = build_pointer_type (field_type_node);
00648 method_type_node = make_node (RECORD_TYPE);
00649 method_ptr_type_node = build_pointer_type (method_type_node);
00650
00651 set_super_info (0, class_type_node, object_type_node, 0);
00652 set_super_info (0, string_type_node, object_type_node, 0);
00653 class_ptr_type = build_pointer_type (class_type_node);
00654
00655 PUSH_FIELD (class_type_node, field, "next", class_ptr_type);
00656 PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
00657 PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
00658 PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
00659 PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
00660 PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
00661 PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
00662 PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
00663 PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
00664 PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
00665 PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
00666 PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
00667 PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
00668 PUSH_FIELD (class_type_node, field, "otable", otable_ptr_type);
00669 PUSH_FIELD (class_type_node, field, "otable_syms",
00670 method_symbols_array_ptr_type);
00671 PUSH_FIELD (class_type_node, field, "interfaces",
00672 build_pointer_type (class_ptr_type));
00673 PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
00674 PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
00675 PUSH_FIELD (class_type_node, field, "state", byte_type_node);
00676 PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
00677 PUSH_FIELD (class_type_node, field, "depth", short_type_node);
00678 PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
00679 PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
00680 PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);
00681 PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
00682 for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
00683 FIELD_PRIVATE (t) = 1;
00684 push_super_field (class_type_node, object_type_node);
00685
00686 FINISH_RECORD (class_type_node);
00687 build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
00688
00689 field_info_union_node = make_node (UNION_TYPE);
00690 PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
00691 PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
00692 #if 0
00693 PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
00694 #endif
00695 layout_type (field_info_union_node);
00696
00697 PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
00698 PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
00699 PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
00700 PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
00701 PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
00702 FINISH_RECORD (field_type_node);
00703 build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
00704
00705 nativecode_ptr_array_type_node
00706 = build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
00707
00708 PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
00709 PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
00710 FINISH_RECORD (dtable_type);
00711 build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
00712
00713 #define jint_type int_type_node
00714 #define jint_ptr_type ptr_type_node
00715
00716 jexception_type = make_node (RECORD_TYPE);
00717 PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
00718 PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
00719 PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
00720 PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
00721 FINISH_RECORD (jexception_type);
00722 build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
00723 jexception_ptr_type = build_pointer_type (jexception_type);
00724
00725 lineNumberEntry_type = make_node (RECORD_TYPE);
00726 PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
00727 PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
00728 FINISH_RECORD (lineNumberEntry_type);
00729
00730 lineNumbers_type = make_node (RECORD_TYPE);
00731 PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
00732 FINISH_RECORD (lineNumbers_type);
00733
00734 #define instn_ptr_type_node ptr_type_node
00735
00736 #define lineNumbers_ptr_type_node build_pointer_type(lineNumbers_type)
00737
00738 PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
00739 PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
00740 PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
00741 PUSH_FIELD (method_type_node, field, "index", unsigned_short_type_node);
00742 PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
00743 PUSH_FIELD (method_type_node, field, "throws", ptr_type_node);
00744 FINISH_RECORD (method_type_node);
00745 build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
00746
00747 endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
00748
00749 t = tree_cons (NULL_TREE, class_ptr_type,
00750 tree_cons (NULL_TREE, int_type_node, endlink));
00751 alloc_object_node = builtin_function ("_Jv_AllocObject",
00752 build_function_type (ptr_type_node, t),
00753 0, NOT_BUILT_IN, NULL);
00754 DECL_IS_MALLOC (alloc_object_node) = 1;
00755 alloc_no_finalizer_node =
00756 builtin_function ("_Jv_AllocObjectNoFinalizer",
00757 build_function_type (ptr_type_node, t),
00758 0, NOT_BUILT_IN, NULL);
00759 DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
00760
00761 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
00762 soft_initclass_node = builtin_function ("_Jv_InitClass",
00763 build_function_type (void_type_node,
00764 t),
00765 0, NOT_BUILT_IN, NULL);
00766
00767 throw_node = builtin_function ("_Jv_Throw",
00768 build_function_type (ptr_type_node, t),
00769 0, NOT_BUILT_IN, NULL);
00770
00771 TREE_THIS_VOLATILE (throw_node) = 1;
00772 TREE_SIDE_EFFECTS (throw_node) = 1;
00773
00774 t = build_function_type (int_type_node, endlink);
00775 soft_monitorenter_node
00776 = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN, NULL);
00777 soft_monitorexit_node
00778 = builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN, NULL);
00779
00780 t = tree_cons (NULL_TREE, int_type_node,
00781 tree_cons (NULL_TREE, int_type_node, endlink));
00782 soft_newarray_node
00783 = builtin_function ("_Jv_NewPrimArray",
00784 build_function_type(ptr_type_node, t),
00785 0, NOT_BUILT_IN, NULL);
00786 DECL_IS_MALLOC (soft_newarray_node) = 1;
00787
00788 t = tree_cons (NULL_TREE, int_type_node,
00789 tree_cons (NULL_TREE, class_ptr_type,
00790 tree_cons (NULL_TREE, object_ptr_type_node, endlink)));
00791 soft_anewarray_node
00792 = builtin_function ("_Jv_NewObjectArray",
00793 build_function_type (ptr_type_node, t),
00794 0, NOT_BUILT_IN, NULL);
00795 DECL_IS_MALLOC (soft_anewarray_node) = 1;
00796
00797 t = tree_cons (NULL_TREE, ptr_type_node,
00798 tree_cons (NULL_TREE, int_type_node, endlink));
00799 soft_multianewarray_node
00800 = builtin_function ("_Jv_NewMultiArray",
00801 build_function_type (ptr_type_node, t),
00802 0, NOT_BUILT_IN, NULL);
00803 DECL_IS_MALLOC (soft_multianewarray_node) = 1;
00804
00805 t = build_function_type (void_type_node,
00806 tree_cons (NULL_TREE, int_type_node, endlink));
00807 soft_badarrayindex_node
00808 = builtin_function ("_Jv_ThrowBadArrayIndex", t,
00809 0, NOT_BUILT_IN, NULL);
00810
00811
00812 TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
00813 TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
00814
00815 soft_nullpointer_node
00816 = builtin_function ("_Jv_ThrowNullPointerException",
00817 build_function_type (void_type_node, endlink),
00818 0, NOT_BUILT_IN, NULL);
00819
00820
00821 TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
00822 TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
00823
00824 t = tree_cons (NULL_TREE, class_ptr_type,
00825 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
00826 soft_checkcast_node
00827 = builtin_function ("_Jv_CheckCast",
00828 build_function_type (ptr_type_node, t),
00829 0, NOT_BUILT_IN, NULL);
00830 t = tree_cons (NULL_TREE, object_ptr_type_node,
00831 tree_cons (NULL_TREE, class_ptr_type, endlink));
00832 soft_instanceof_node
00833 = builtin_function ("_Jv_IsInstanceOf",
00834 build_function_type (boolean_type_node, t),
00835 0, NOT_BUILT_IN, NULL);
00836 t = tree_cons (NULL_TREE, object_ptr_type_node,
00837 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
00838 soft_checkarraystore_node
00839 = builtin_function ("_Jv_CheckArrayStore",
00840 build_function_type (void_type_node, t),
00841 0, NOT_BUILT_IN, NULL);
00842 t = tree_cons (NULL_TREE, ptr_type_node,
00843 tree_cons (NULL_TREE, ptr_type_node,
00844 tree_cons (NULL_TREE, int_type_node, endlink)));
00845 soft_lookupinterfacemethod_node
00846 = builtin_function ("_Jv_LookupInterfaceMethodIdx",
00847 build_function_type (ptr_type_node, t),
00848 0, NOT_BUILT_IN, NULL);
00849
00850 t = tree_cons (NULL_TREE, object_ptr_type_node,
00851 tree_cons (NULL_TREE, ptr_type_node,
00852 tree_cons (NULL_TREE, ptr_type_node, endlink)));
00853 soft_lookupjnimethod_node
00854 = builtin_function ("_Jv_LookupJNIMethod",
00855 build_function_type (ptr_type_node, t),
00856 0, NOT_BUILT_IN, NULL);
00857 t = tree_cons (NULL_TREE, ptr_type_node, endlink);
00858 soft_getjnienvnewframe_node
00859 = builtin_function ("_Jv_GetJNIEnvNewFrame",
00860 build_function_type (ptr_type_node, t),
00861 0, NOT_BUILT_IN, NULL);
00862 soft_jnipopsystemframe_node
00863 = builtin_function ("_Jv_JNI_PopSystemFrame",
00864 build_function_type (ptr_type_node, t),
00865 0, NOT_BUILT_IN, NULL);
00866
00867 t = tree_cons (NULL_TREE, double_type_node,
00868 tree_cons (NULL_TREE, double_type_node, endlink));
00869 soft_fmod_node
00870 = builtin_function ("__builtin_fmod",
00871 build_function_type (double_type_node, t),
00872 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmod");
00873
00874 #if 0
00875 t = tree_cons (NULL_TREE, float_type_node,
00876 tree_cons (NULL_TREE, float_type_node, endlink));
00877 soft_fmodf_node
00878 = builtin_function ("__builtin_fmodf",
00879 build_function_type (float_type_node, t),
00880 BUILT_IN_FMOD, BUILT_IN_NORMAL, "fmodf");
00881 #endif
00882
00883 soft_idiv_node
00884 = builtin_function ("_Jv_divI",
00885 build_function_type (int_type_node, t),
00886 0, NOT_BUILT_IN, NULL);
00887
00888 soft_irem_node
00889 = builtin_function ("_Jv_remI",
00890 build_function_type (int_type_node, t),
00891 0, NOT_BUILT_IN, NULL);
00892
00893 soft_ldiv_node
00894 = builtin_function ("_Jv_divJ",
00895 build_function_type (long_type_node, t),
00896 0, NOT_BUILT_IN, NULL);
00897
00898 soft_lrem_node
00899 = builtin_function ("_Jv_remJ",
00900 build_function_type (long_type_node, t),
00901 0, NOT_BUILT_IN, NULL);
00902
00903
00904 eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
00905 ? "__gcj_personality_sj0"
00906 : "__gcj_personality_v0");
00907 lang_eh_runtime_type = prepare_eh_table_type;
00908
00909 init_jcf_parse ();
00910
00911
00912 ggc_add_tree_root (java_global_trees,
00913 sizeof (java_global_trees) / sizeof (tree));
00914 ggc_add_tree_root (&decl_map, 1);
00915 ggc_add_tree_root (&pending_local_decls, 1);
00916
00917 initialize_builtins ();
00918 }
00919
00920
00921
00922
00923
00924
00925
00926 tree
00927 lookup_name (name)
00928 tree name;
00929 {
00930 register tree val;
00931 if (current_binding_level != global_binding_level
00932 && IDENTIFIER_LOCAL_VALUE (name))
00933 val = IDENTIFIER_LOCAL_VALUE (name);
00934 else
00935 val = IDENTIFIER_GLOBAL_VALUE (name);
00936 return val;
00937 }
00938
00939
00940
00941
00942 static tree
00943 lookup_name_current_level (name)
00944 tree name;
00945 {
00946 register tree t;
00947
00948 if (current_binding_level == global_binding_level)
00949 return IDENTIFIER_GLOBAL_VALUE (name);
00950
00951 if (IDENTIFIER_LOCAL_VALUE (name) == 0)
00952 return 0;
00953
00954 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
00955 if (DECL_NAME (t) == name)
00956 break;
00957
00958 return t;
00959 }
00960
00961
00962
00963 void
00964 push_labeled_block (lb)
00965 tree lb;
00966 {
00967 register tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
00968 register struct binding_level *b = current_binding_level;
00969 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
00970 if (oldlocal != 0)
00971 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
00972 TREE_CHAIN (lb) = b->names;
00973 b->names = lb;
00974 IDENTIFIER_LOCAL_VALUE (name) = lb;
00975 }
00976
00977
00978
00979
00980 void
00981 pop_labeled_block ()
00982 {
00983 struct binding_level *b = current_binding_level;
00984 tree label = b->names;
00985 IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
00986 NULL_TREE;
00987 if (b->shadowed)
00988 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
00989 TREE_VALUE (b->shadowed);
00990
00991
00992 current_binding_level = current_binding_level->level_chain;
00993 b->level_chain = free_binding_level;
00994 free_binding_level = b;
00995 }
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005 tree
01006 pushdecl (x)
01007 tree x;
01008 {
01009 register tree t;
01010 register tree name = DECL_NAME (x);
01011 register struct binding_level *b = current_binding_level;
01012
01013 if (TREE_CODE (x) != TYPE_DECL)
01014 DECL_CONTEXT (x) = current_function_decl;
01015 if (name)
01016 {
01017 const char *file;
01018 int line;
01019
01020 t = lookup_name_current_level (name);
01021 if (t != 0 && t == error_mark_node)
01022
01023 {
01024 t = 0;
01025 error_with_decl (x, "`%s' used prior to declaration");
01026 }
01027
01028 if (t != 0)
01029 {
01030 file = DECL_SOURCE_FILE (t);
01031 line = DECL_SOURCE_LINE (t);
01032 }
01033
01034
01035
01036
01037
01038 if (TREE_CODE (x) == TYPE_DECL
01039 && TYPE_NAME (TREE_TYPE (x)) == 0
01040 && TREE_TYPE (x) != error_mark_node)
01041 {
01042 TYPE_NAME (TREE_TYPE (x)) = x;
01043 TYPE_STUB_DECL (TREE_TYPE (x)) = x;
01044 }
01045
01046
01047
01048 if (b == global_binding_level)
01049 {
01050
01051
01052 IDENTIFIER_GLOBAL_VALUE (name) = x;
01053 }
01054 else
01055 {
01056
01057 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
01058 IDENTIFIER_LOCAL_VALUE (name) = x;
01059
01060 #if 0
01061
01062 if (oldlocal != 0 && !DECL_EXTERNAL (x)
01063
01064 && ! current_binding_level->parm_flag
01065
01066 && current_binding_level->level_chain->parm_flag
01067
01068
01069 && chain_member (oldlocal, current_binding_level->level_chain->names))
01070 {
01071 if (TREE_CODE (oldlocal) == PARM_DECL)
01072 pedwarn ("declaration of `%s' shadows a parameter",
01073 IDENTIFIER_POINTER (name));
01074 else
01075 pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
01076 IDENTIFIER_POINTER (name));
01077 }
01078
01079
01080 else if (warn_shadow && !DECL_EXTERNAL (x)
01081
01082 && DECL_SOURCE_LINE (x) != 0
01083
01084 && ! DECL_FROM_INLINE (x))
01085 {
01086 const char *warnstring = 0;
01087
01088 if (TREE_CODE (x) == PARM_DECL
01089 && current_binding_level->level_chain->parm_flag)
01090
01091
01092
01093
01094
01095 ;
01096 else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
01097 warnstring = "declaration of `%s' shadows a parameter";
01098 else if (oldlocal != 0)
01099 warnstring = "declaration of `%s' shadows previous local";
01100 else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
01101 && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
01102 warnstring = "declaration of `%s' shadows global declaration";
01103
01104 if (warnstring)
01105 warning (warnstring, IDENTIFIER_POINTER (name));
01106 }
01107 #endif
01108
01109
01110
01111 if (oldlocal != 0)
01112 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
01113 }
01114 }
01115
01116
01117
01118 TREE_CHAIN (x) = b->names;
01119 b->names = x;
01120
01121 return x;
01122 }
01123
01124 void
01125 pushdecl_force_head (x)
01126 tree x;
01127 {
01128 current_binding_level->names = x;
01129 }
01130
01131
01132
01133 tree
01134 pushdecl_top_level (x)
01135 tree x;
01136 {
01137 register tree t;
01138 register struct binding_level *b = current_binding_level;
01139
01140 current_binding_level = global_binding_level;
01141 t = pushdecl (x);
01142 current_binding_level = b;
01143 return t;
01144 }
01145
01146
01147
01148 int
01149 global_bindings_p ()
01150 {
01151 return current_binding_level == global_binding_level;
01152 }
01153
01154
01155
01156
01157
01158
01159 tree
01160 getdecls ()
01161 {
01162 return current_binding_level->names;
01163 }
01164
01165
01166
01167 static struct binding_level *
01168 make_binding_level ()
01169 {
01170
01171 return (struct binding_level *) xmalloc (sizeof (struct binding_level));
01172 }
01173
01174 void
01175 pushlevel (unused)
01176 int unused ATTRIBUTE_UNUSED;
01177 {
01178 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
01179
01180 #if 0
01181
01182
01183
01184 if (current_binding_level == global_binding_level)
01185 named_labels = 0;
01186 #endif
01187
01188
01189
01190 if (free_binding_level)
01191 {
01192 newlevel = free_binding_level;
01193 free_binding_level = free_binding_level->level_chain;
01194 }
01195 else
01196 {
01197 newlevel = make_binding_level ();
01198 }
01199
01200
01201
01202
01203 *newlevel = clear_binding_level;
01204 newlevel->level_chain = current_binding_level;
01205 current_binding_level = newlevel;
01206 #if defined(DEBUG_JAVA_BINDING_LEVELS)
01207 newlevel->binding_depth = binding_depth;
01208 indent ();
01209 fprintf (stderr, "push %s level 0x%08x pc %d\n",
01210 (is_class_level) ? "class" : "block", newlevel, current_pc);
01211 is_class_level = 0;
01212 binding_depth++;
01213 #endif
01214 }
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231 tree
01232 poplevel (keep, reverse, functionbody)
01233 int keep;
01234 int reverse;
01235 int functionbody;
01236 {
01237 register tree link;
01238
01239
01240 tree decls;
01241 tree subblocks = current_binding_level->blocks;
01242 tree block = 0;
01243 tree decl;
01244 int block_previously_created;
01245
01246 #if defined(DEBUG_JAVA_BINDING_LEVELS)
01247 binding_depth--;
01248 indent ();
01249 if (current_binding_level->end_pc != LARGEST_PC)
01250 fprintf (stderr, "pop %s level 0x%08x pc %d (end pc %d)\n",
01251 (is_class_level) ? "class" : "block", current_binding_level, current_pc,
01252 current_binding_level->end_pc);
01253 else
01254 fprintf (stderr, "pop %s level 0x%08x pc %d\n",
01255 (is_class_level) ? "class" : "block", current_binding_level, current_pc);
01256 #if 0
01257 if (is_class_level != (current_binding_level == class_binding_level))
01258 {
01259 indent ();
01260 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
01261 }
01262 is_class_level = 0;
01263 #endif
01264 #endif
01265
01266
01267
01268
01269
01270 if (reverse)
01271 current_binding_level->names
01272 = decls = nreverse (current_binding_level->names);
01273 else
01274 decls = current_binding_level->names;
01275
01276
01277
01278
01279 for (decl = decls; decl; decl = TREE_CHAIN (decl))
01280 if (TREE_CODE (decl) == FUNCTION_DECL
01281 && ! TREE_ASM_WRITTEN (decl)
01282 && DECL_INITIAL (decl) != 0
01283 && TREE_ADDRESSABLE (decl))
01284 {
01285
01286
01287
01288
01289
01290
01291 if (DECL_ABSTRACT_ORIGIN (decl) != 0
01292 && DECL_ABSTRACT_ORIGIN (decl) != decl)
01293 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
01294 else
01295 {
01296 push_function_context ();
01297 output_inline_function (decl);
01298 pop_function_context ();
01299 }
01300 }
01301
01302
01303
01304
01305
01306 block = 0;
01307 block_previously_created = (current_binding_level->this_block != 0);
01308 if (block_previously_created)
01309 block = current_binding_level->this_block;
01310 else if (keep || functionbody)
01311 block = make_node (BLOCK);
01312 if (block != 0)
01313 {
01314 BLOCK_VARS (block) = decls;
01315 BLOCK_SUBBLOCKS (block) = subblocks;
01316 }
01317
01318
01319
01320 for (link = subblocks; link; link = TREE_CHAIN (link))
01321 BLOCK_SUPERCONTEXT (link) = block;
01322
01323
01324
01325 for (link = decls; link; link = TREE_CHAIN (link))
01326 {
01327 tree name = DECL_NAME (link);
01328 if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
01329 {
01330
01331
01332 if (DECL_EXTERNAL (link))
01333 {
01334 if (TREE_USED (link))
01335 TREE_USED (name) = 1;
01336 if (TREE_ADDRESSABLE (link))
01337 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
01338 }
01339 IDENTIFIER_LOCAL_VALUE (name) = 0;
01340 }
01341 }
01342
01343
01344
01345
01346 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
01347 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
01348
01349
01350
01351
01352
01353 if (functionbody)
01354 {
01355
01356
01357
01358
01359
01360 BLOCK_VARS (block) = 0;
01361
01362
01363
01364
01365
01366 #if 0
01367 for (link = named_labels; link; link = TREE_CHAIN (link))
01368 {
01369 register tree label = TREE_VALUE (link);
01370
01371 if (DECL_INITIAL (label) == 0)
01372 {
01373 error_with_decl (label, "label `%s' used but not defined");
01374
01375 define_label (input_filename, lineno,
01376 DECL_NAME (label));
01377 }
01378 else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
01379 warning_with_decl (label, "label `%s' defined but not used");
01380 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
01381
01382
01383
01384 TREE_CHAIN (label) = BLOCK_VARS (block);
01385 BLOCK_VARS (block) = label;
01386 }
01387 #endif
01388 }
01389
01390
01391
01392 {
01393 register struct binding_level *level = current_binding_level;
01394 current_binding_level = current_binding_level->level_chain;
01395
01396 level->level_chain = free_binding_level;
01397 free_binding_level = level;
01398 }
01399
01400
01401 if (functionbody)
01402 DECL_INITIAL (current_function_decl) = block;
01403 else if (block)
01404 {
01405 if (!block_previously_created)
01406 current_binding_level->blocks
01407 = chainon (current_binding_level->blocks, block);
01408 }
01409
01410
01411
01412
01413
01414 else if (subblocks)
01415 current_binding_level->blocks
01416 = chainon (current_binding_level->blocks, subblocks);
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433 if (block)
01434 TREE_USED (block) = 1;
01435 return block;
01436 }
01437
01438 void
01439 maybe_pushlevels (pc)
01440 int pc;
01441 {
01442 #if defined(DEBUG_JAVA_BINDING_LEVELS)
01443 current_pc = pc;
01444 #endif
01445
01446 while (pending_local_decls != NULL_TREE &&
01447 DECL_LOCAL_START_PC (pending_local_decls) <= pc)
01448 {
01449 tree *ptr = &pending_local_decls;
01450 tree decl = *ptr;
01451 int end_pc = DECL_LOCAL_END_PC (decl);
01452
01453 while (*ptr != NULL_TREE
01454 && DECL_LOCAL_START_PC (*ptr) <= pc
01455 && DECL_LOCAL_END_PC (*ptr) == end_pc)
01456 ptr = &TREE_CHAIN (*ptr);
01457 pending_local_decls = *ptr;
01458 *ptr = NULL_TREE;
01459
01460
01461 if (end_pc > current_binding_level->end_pc)
01462 end_pc = current_binding_level->end_pc;
01463
01464 maybe_start_try (pc, end_pc);
01465
01466 pushlevel (1);
01467 expand_start_bindings (0);
01468
01469 current_binding_level->end_pc = end_pc;
01470 current_binding_level->start_pc = pc;
01471 current_binding_level->names = decl;
01472 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
01473 {
01474 push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
01475 }
01476 }
01477
01478 maybe_start_try (pc, 0);
01479 }
01480
01481 void
01482 maybe_poplevels (pc)
01483 int pc;
01484 {
01485 #if defined(DEBUG_JAVA_BINDING_LEVELS)
01486 current_pc = pc;
01487 #endif
01488
01489 while (current_binding_level->end_pc <= pc)
01490 {
01491 expand_end_bindings (getdecls (), 1, 0);
01492 maybe_end_try (current_binding_level->start_pc, pc);
01493 poplevel (1, 0, 0);
01494 }
01495 maybe_end_try (0, pc);
01496 }
01497
01498
01499
01500
01501
01502
01503 void
01504 force_poplevels (start_pc)
01505 int start_pc;
01506 {
01507 while (current_binding_level->start_pc > start_pc)
01508 {
01509 if (pedantic && current_binding_level->start_pc > start_pc)
01510 warning_with_decl (current_function_decl,
01511 "In %s: overlapped variable and exception ranges at %d",
01512 current_binding_level->start_pc);
01513 expand_end_bindings (getdecls (), 1, 0);
01514 poplevel (1, 0, 0);
01515 }
01516 }
01517
01518
01519
01520
01521
01522 void
01523 insert_block (block)
01524 tree block;
01525 {
01526 TREE_USED (block) = 1;
01527 current_binding_level->blocks
01528 = chainon (current_binding_level->blocks, block);
01529 }
01530
01531
01532
01533
01534 void
01535 set_block (block)
01536 register tree block;
01537 {
01538 current_binding_level->this_block = block;
01539 current_binding_level->names = chainon (current_binding_level->names,
01540 BLOCK_VARS (block));
01541 current_binding_level->blocks = chainon (current_binding_level->blocks,
01542 BLOCK_SUBBLOCKS (block));
01543 }
01544
01545
01546
01547 void
01548 copy_lang_decl (node)
01549 tree node;
01550 {
01551 int lang_decl_size
01552 = TREE_CODE (node) == VAR_DECL ? sizeof (struct lang_decl_var)
01553 : sizeof (struct lang_decl);
01554 struct lang_decl *x = (struct lang_decl *) ggc_alloc (lang_decl_size);
01555 memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
01556 DECL_LANG_SPECIFIC (node) = x;
01557 }
01558
01559
01560
01561
01562 tree
01563 maybe_build_cleanup (decl)
01564 tree decl ATTRIBUTE_UNUSED;
01565 {
01566
01567 return NULL_TREE;
01568 }
01569
01570 void
01571 give_name_to_locals (jcf)
01572 JCF *jcf;
01573 {
01574 int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
01575 int code_offset = DECL_CODE_OFFSET (current_function_decl);
01576 tree parm;
01577 pending_local_decls = NULL_TREE;
01578 if (n == 0)
01579 return;
01580 JCF_SEEK (jcf, n);
01581 n = JCF_readu2 (jcf);
01582 for (i = 0; i < n; i++)
01583 {
01584 int start_pc = JCF_readu2 (jcf);
01585 int length = JCF_readu2 (jcf);
01586 int name_index = JCF_readu2 (jcf);
01587 int signature_index = JCF_readu2 (jcf);
01588 int slot = JCF_readu2 (jcf);
01589 tree name = get_name_constant (jcf, name_index);
01590 tree type = parse_signature (jcf, signature_index);
01591 if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
01592 && start_pc == 0
01593 && length == DECL_CODE_LENGTH (current_function_decl))
01594 {
01595 tree decl = TREE_VEC_ELT (decl_map, slot);
01596 DECL_NAME (decl) = name;
01597 SET_DECL_ASSEMBLER_NAME (decl, name);
01598 if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
01599 warning ("bad type in parameter debug info");
01600 }
01601 else
01602 {
01603 tree *ptr;
01604 int end_pc = start_pc + length;
01605 tree decl = build_decl (VAR_DECL, name, type);
01606 if (end_pc > DECL_CODE_LENGTH (current_function_decl))
01607 {
01608 warning_with_decl (decl,
01609 "bad PC range for debug info for local `%s'");
01610 end_pc = DECL_CODE_LENGTH (current_function_decl);
01611 }
01612
01613
01614
01615
01616
01617 start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
01618
01619 MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
01620 DECL_LOCAL_SLOT_NUMBER (decl) = slot;
01621 DECL_LOCAL_START_PC (decl) = start_pc;
01622 #if 0
01623
01624
01625
01626
01627
01628 end_pc++;
01629 #endif
01630 DECL_LOCAL_END_PC (decl) = end_pc;
01631
01632
01633
01634
01635
01636 ptr = &pending_local_decls;
01637 while (*ptr != NULL_TREE
01638 && (DECL_LOCAL_START_PC (*ptr) > start_pc
01639 || (DECL_LOCAL_START_PC (*ptr) == start_pc
01640 && DECL_LOCAL_END_PC (*ptr) < end_pc)))
01641 ptr = &TREE_CHAIN (*ptr);
01642 TREE_CHAIN (decl) = *ptr;
01643 *ptr = decl;
01644 }
01645 }
01646
01647 pending_local_decls = nreverse (pending_local_decls);
01648
01649
01650 for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
01651 parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
01652 {
01653 if (DECL_NAME (parm) == NULL_TREE)
01654 {
01655 int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
01656 if (arg_i == 0)
01657 DECL_NAME (parm) = get_identifier ("this");
01658 else
01659 {
01660 char buffer[12];
01661 sprintf (buffer, "ARG_%d", arg_i);
01662 DECL_NAME (parm) = get_identifier (buffer);
01663 }
01664 SET_DECL_ASSEMBLER_NAME (parm, DECL_NAME (parm));
01665 }
01666 }
01667 }
01668
01669 tree
01670 build_result_decl (fndecl)
01671 tree fndecl;
01672 {
01673 tree restype = TREE_TYPE (TREE_TYPE (fndecl));
01674
01675 if (INTEGRAL_TYPE_P (restype)
01676 && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
01677 restype = integer_type_node;
01678 return (DECL_RESULT (fndecl) = build_decl (RESULT_DECL, NULL_TREE, restype));
01679 }
01680
01681 void
01682 complete_start_java_method (fndecl)
01683 tree fndecl;
01684 {
01685 if (! flag_emit_class_files)
01686 {
01687
01688 init_function_start (fndecl, input_filename, lineno);
01689
01690
01691 expand_function_start (fndecl, 0);
01692 }
01693
01694 #if 0
01695
01696
01697 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
01698 TREE_ADDRESSABLE (current_function_decl) = 1;
01699
01700 #endif
01701
01702 if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
01703 && ! flag_emit_class_files
01704 && ! DECL_CLINIT_P (fndecl)
01705 && ! CLASS_INTERFACE (TYPE_NAME (current_class)))
01706 {
01707 tree clas = DECL_CONTEXT (fndecl);
01708 tree init = build (CALL_EXPR, void_type_node,
01709 build_address_of (soft_initclass_node),
01710 build_tree_list (NULL_TREE, build_class_ref (clas)),
01711 NULL_TREE);
01712 TREE_SIDE_EFFECTS (init) = 1;
01713 expand_expr_stmt (init);
01714 }
01715
01716
01717
01718
01719 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
01720 {
01721 pushlevel (2);
01722 if (! flag_emit_class_files)
01723 expand_start_bindings (1);
01724 }
01725
01726 if (METHOD_SYNCHRONIZED (fndecl) && ! flag_emit_class_files)
01727 {
01728
01729 tree enter, exit, lock;
01730 if (METHOD_STATIC (fndecl))
01731 lock = build_class_ref (DECL_CONTEXT (fndecl));
01732 else
01733 lock = DECL_ARGUMENTS (fndecl);
01734 BUILD_MONITOR_ENTER (enter, lock);
01735 BUILD_MONITOR_EXIT (exit, lock);
01736 if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (fndecl)))
01737 {
01738 expand_expr_stmt (enter);
01739 expand_decl_cleanup (NULL_TREE, exit);
01740 }
01741 else
01742 {
01743 tree function_body = DECL_FUNCTION_BODY (fndecl);
01744 tree body = BLOCK_EXPR_BODY (function_body);
01745 lock = build (COMPOUND_EXPR, void_type_node,
01746 enter,
01747 build (TRY_FINALLY_EXPR, void_type_node, body, exit));
01748 TREE_SIDE_EFFECTS (lock) = 1;
01749 BLOCK_EXPR_BODY (function_body) = lock;
01750 }
01751 }
01752 }
01753
01754 void
01755 start_java_method (fndecl)
01756 tree fndecl;
01757 {
01758 tree tem, *ptr;
01759 int i;
01760
01761 current_function_decl = fndecl;
01762 announce_function (fndecl);
01763
01764 i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
01765 decl_map = make_tree_vec (i);
01766 type_map = (tree *) xrealloc (type_map, i * sizeof (tree));
01767
01768 #if defined(DEBUG_JAVA_BINDING_LEVELS)
01769 fprintf (stderr, "%s:\n", (*decl_printable_name) (fndecl, 2));
01770 current_pc = 0;
01771 #endif
01772 pushlevel (1);
01773
01774 ptr = &DECL_ARGUMENTS (fndecl);
01775 for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
01776 tem != end_params_node; tem = TREE_CHAIN (tem), i++)
01777 {
01778 tree parm_name = NULL_TREE, parm_decl;
01779 tree parm_type = TREE_VALUE (tem);
01780 if (i >= DECL_MAX_LOCALS (fndecl))
01781 abort ();
01782
01783 parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
01784 DECL_CONTEXT (parm_decl) = fndecl;
01785 if (PROMOTE_PROTOTYPES
01786 && TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
01787 && INTEGRAL_TYPE_P (parm_type))
01788 parm_type = integer_type_node;
01789 DECL_ARG_TYPE (parm_decl) = parm_type;
01790
01791 *ptr = parm_decl;
01792 ptr = &TREE_CHAIN (parm_decl);
01793
01794
01795 push_jvm_slot (i, parm_decl);
01796
01797 type_map[i] = TREE_TYPE (parm_decl);
01798 if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
01799 {
01800 i++;
01801 type_map[i] = void_type_node;
01802 }
01803 }
01804 *ptr = NULL_TREE;
01805 DECL_ARG_SLOT_COUNT (current_function_decl) = i;
01806
01807 while (i < DECL_MAX_LOCALS(fndecl))
01808 type_map[i++] = NULL_TREE;
01809
01810 build_result_decl (fndecl);
01811 complete_start_java_method (fndecl);
01812 }
01813
01814 void
01815 end_java_method ()
01816 {
01817 tree fndecl = current_function_decl;
01818
01819 expand_end_bindings (getdecls (), 1, 0);
01820
01821 poplevel (1, 1, 0);
01822
01823
01824 poplevel (1, 0, 1);
01825
01826 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
01827
01828
01829 expand_function_end (input_filename, lineno, 0);
01830
01831
01832 rest_of_compilation (fndecl);
01833
01834 current_function_decl = NULL_TREE;
01835 }
01836
01837
01838
01839 void
01840 lang_mark_tree (t)
01841 tree t;
01842 {
01843 if (TREE_CODE (t) == IDENTIFIER_NODE)
01844 {
01845 struct lang_identifier *li = (struct lang_identifier *) t;
01846 ggc_mark_tree (li->global_value);
01847 ggc_mark_tree (li->local_value);
01848 ggc_mark_tree (li->utf8_ref);
01849 }
01850 else if (TREE_CODE (t) == VAR_DECL
01851 || TREE_CODE (t) == PARM_DECL
01852 || TREE_CODE (t) == FIELD_DECL)
01853 {
01854 struct lang_decl_var *ldv =
01855 ((struct lang_decl_var *) DECL_LANG_SPECIFIC (t));
01856 if (ldv)
01857 {
01858 ggc_mark (ldv);
01859 ggc_mark_tree (ldv->slot_chain);
01860 ggc_mark_tree (ldv->am);
01861 ggc_mark_tree (ldv->wfl);
01862 }
01863 }
01864 else if (TREE_CODE (t) == FUNCTION_DECL)
01865 {
01866 struct lang_decl *ld = DECL_LANG_SPECIFIC (t);
01867
01868 if (ld)
01869 {
01870 ggc_mark (ld);
01871 ggc_mark_tree (ld->wfl);
01872 ggc_mark_tree (ld->throws_list);
01873 ggc_mark_tree (ld->function_decl_body);
01874 ggc_mark_tree (ld->called_constructor);
01875 ggc_mark_tree (ld->inner_access);
01876 ggc_mark_tree_hash_table (&ld->init_test_table);
01877 ggc_mark_tree_hash_table (&ld->ict);
01878 ggc_mark_tree (ld->smic);
01879 }
01880 }
01881 else if (TYPE_P (t))
01882 {
01883 struct lang_type *lt = TYPE_LANG_SPECIFIC (t);
01884
01885 if (lt)
01886 {
01887 ggc_mark (lt);
01888 ggc_mark_tree (lt->signature);
01889 ggc_mark_tree (lt->cpool_data_ref);
01890 ggc_mark_tree (lt->finit_stmt_list);
01891 ggc_mark_tree (lt->clinit_stmt_list);
01892 ggc_mark_tree (lt->ii_block);
01893 ggc_mark_tree (lt->dot_class);
01894 ggc_mark_tree (lt->package_list);
01895 }
01896 }
01897 }