#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "rtl.h"
#include "real.h"
#include "toplev.h"
#include "flags.h"
#include "java-tree.h"
#include "jcf.h"
#include "function.h"
#include "expr.h"
#include "libfuncs.h"
#include "except.h"
#include "java-except.h"
#include "ggc.h"
#include "timevar.h"
#include "cgraph.h"
#include "tree-inline.h"
#include "target.h"
#include "version.h"
#if defined (DEBUG_JAVA_BINDING_LEVELS)
extern void indent (void);
#endif
static tree push_jvm_slot (int, tree);
static tree lookup_name_current_level (tree);
static tree push_promoted_type (const char *, tree);
static struct binding_level *make_binding_level (void);
static tree create_primitive_vtable (const char *);
static tree check_local_unnamed_variable (tree, tree, tree);
static void parse_version (void);
#define GCJ_BINARYCOMPAT_ADDITION 5
tree gcj_abi_version;
tree java_lang_cloneable_identifier_node;
tree java_io_serializable_identifier_node;
static GTY(()) tree decl_map;
static GTY(()) tree base_decl_map;
static int uniq;
static GTY(()) tree pending_local_decls;
#if defined(DEBUG_JAVA_BINDING_LEVELS)
int binding_depth = 0;
int is_class_level = 0;
int current_pc;
void
indent (void)
{
int i;
for (i = 0; i < binding_depth*2; i++)
putc (' ', stderr);
}
#endif
static bool
debug_variable_p (tree decl)
{
if (TREE_CODE (decl) == PARM_DECL)
return false;
if (LOCAL_SLOT_P (decl))
return false;
return true;
}
void
update_aliases (tree decl, int index, int pc)
{
tree decl_type = TREE_TYPE (decl);
tree tmp;
if (debug_variable_p (decl))
abort ();
for (tmp = TREE_VEC_ELT (decl_map, index);
tmp != NULL_TREE;
tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
{
tree tmp_type = TREE_TYPE (tmp);
if (tmp != decl
&& LOCAL_SLOT_P (tmp) == 0
&& (pc == -1
|| (pc >= DECL_LOCAL_START_PC (tmp)
&& pc < DECL_LOCAL_END_PC (tmp)))
&& (tmp_type == decl_type
|| (INTEGRAL_TYPE_P (tmp_type)
&& INTEGRAL_TYPE_P (decl_type)
&& TYPE_PRECISION (decl_type) <= 32
&& TYPE_PRECISION (tmp_type) <= 32)
|| (TREE_CODE (tmp_type) == POINTER_TYPE
&& TREE_CODE (decl_type) == POINTER_TYPE)))
{
tree src = build1 (NOP_EXPR, tmp_type, decl);
if (LOCAL_VAR_OUT_OF_SCOPE_P (tmp))
abort ();
java_add_stmt (build2 (MODIFY_EXPR, tmp_type, tmp, src));
}
}
}
static tree
push_jvm_slot (int index, tree decl)
{
DECL_CONTEXT (decl) = current_function_decl;
layout_decl (decl, 0);
if (DECL_LANG_SPECIFIC (decl) == NULL)
{
MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
DECL_LOCAL_START_PC (decl) = 0;
DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
DECL_LOCAL_SLOT_NUMBER (decl) = index;
}
DECL_LOCAL_SLOT_CHAIN (decl) = TREE_VEC_ELT (decl_map, index);
TREE_VEC_ELT (decl_map, index) = decl;
return decl;
}
static void
initialize_local_variable (tree decl, int index)
{
tree decl_type = TREE_TYPE (decl);
if (TREE_CODE (decl_type) == POINTER_TYPE)
{
tree tmp = TREE_VEC_ELT (base_decl_map, index);
if (tmp)
{
tree src = build1 (NOP_EXPR, decl_type, tmp);
java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, src));
}
}
else
{
tree tmp;
for (tmp = TREE_VEC_ELT (decl_map, index);
tmp != NULL_TREE;
tmp = DECL_LOCAL_SLOT_CHAIN (tmp))
{
tree tmp_type = TREE_TYPE (tmp);
if (tmp != decl
&& ! debug_variable_p (tmp)
&& (tmp_type == decl_type
|| (INTEGRAL_TYPE_P (tmp_type)
&& INTEGRAL_TYPE_P (decl_type)
&& TYPE_PRECISION (decl_type) <= 32
&& TYPE_PRECISION (tmp_type) <= 32
&& TYPE_PRECISION (tmp_type)
>= TYPE_PRECISION (decl_type))))
{
java_add_stmt (build2 (MODIFY_EXPR, decl_type, decl, tmp));
return;
}
}
}
}
static tree
check_local_unnamed_variable (tree best, tree decl, tree type)
{
tree decl_type = TREE_TYPE (decl);
if (LOCAL_VAR_OUT_OF_SCOPE_P (decl))
abort ();
if (decl_type == type
|| (INTEGRAL_TYPE_P (decl_type)
&& INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (decl_type) <= 32
&& TYPE_PRECISION (type) <= 32
&& TYPE_PRECISION (decl_type) >= TYPE_PRECISION (type))
|| (TREE_CODE (decl_type) == POINTER_TYPE
&& type == ptr_type_node)
|| (TREE_CODE (decl_type) == POINTER_TYPE
&& TREE_CODE (decl) == PARM_DECL
&& TREE_CODE (type) == POINTER_TYPE))
{
if (best == NULL_TREE
|| (decl_type == type && TREE_TYPE (best) != type))
return decl;
}
return best;
}
tree
find_local_variable (int index, tree type, int pc ATTRIBUTE_UNUSED)
{
tree tmp = TREE_VEC_ELT (decl_map, index);
tree decl = NULL_TREE;
while (tmp != NULL_TREE)
{
if (! debug_variable_p (tmp))
decl = check_local_unnamed_variable (decl, tmp, type);
tmp = DECL_LOCAL_SLOT_CHAIN (tmp);
}
if (TREE_CODE (type) == BOOLEAN_TYPE)
type = integer_type_node;
if (! decl)
{
char buf[64];
tree name;
sprintf (buf, "#slot#%d#%d", index, uniq++);
name = get_identifier (buf);
decl = build_decl (VAR_DECL, name, type);
DECL_IGNORED_P (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
decl = push_jvm_slot (index, decl);
LOCAL_SLOT_P (decl) = 1;
if (TREE_CODE (type) != POINTER_TYPE)
pushdecl_function_level (decl);
}
if (TREE_CODE (type) == POINTER_TYPE
&& ! TREE_VEC_ELT (base_decl_map, index))
{
char buf[64];
tree name;
tree base_decl;
sprintf (buf, "#ref#%d#%d", index, uniq++);
name = get_identifier (buf);
base_decl
= TREE_VEC_ELT (base_decl_map, index)
= build_decl (VAR_DECL, name, ptr_type_node);
pushdecl_function_level (base_decl);
DECL_IGNORED_P (base_decl) = 1;
DECL_ARTIFICIAL (base_decl) = 1;
}
return decl;
}
tree
java_replace_reference (tree var_decl, bool want_lvalue)
{
tree decl_type;
if (! base_decl_map)
return var_decl;
decl_type = TREE_TYPE (var_decl);
if (TREE_CODE (decl_type) == POINTER_TYPE)
{
if (DECL_LANG_SPECIFIC (var_decl)
&& LOCAL_SLOT_P (var_decl))
{
int index = DECL_LOCAL_SLOT_NUMBER (var_decl);
tree base_decl = TREE_VEC_ELT (base_decl_map, index);
if (! base_decl)
abort ();
if (! want_lvalue)
base_decl = build1 (NOP_EXPR, decl_type, base_decl);
return base_decl;
}
}
return var_decl;
}
tree
find_stack_slot (int index, tree type)
{
return find_local_variable (index + DECL_MAX_LOCALS (current_function_decl),
type, -1);
}
struct binding_level GTY(())
{
tree names;
tree shadowed;
tree blocks;
struct binding_level *level_chain;
int end_pc;
int start_pc;
tree stmts;
struct eh_range * GTY((skip (""))) exception_range;
unsigned binding_depth;
};
#define NULL_BINDING_LEVEL (struct binding_level *) NULL
static GTY(()) struct binding_level *current_binding_level;
static GTY(()) struct binding_level *free_binding_level;
static GTY(()) struct binding_level *global_binding_level;
static struct binding_level *function_binding_level;
#define LARGEST_PC (( (unsigned int)1 << (HOST_BITS_PER_INT - 1)) - 1)
static const struct binding_level clear_binding_level
= {
NULL_TREE,
NULL_TREE,
NULL_TREE,
NULL_BINDING_LEVEL,
LARGEST_PC,
0,
NULL,
NULL,
0,
};
#if 0
static tree named_labels;
static tree shadowed_labels;
#endif
tree java_global_trees[JTI_MAX];
static tree
push_promoted_type (const char *name, tree actual_type)
{
tree type = make_node (TREE_CODE (actual_type));
#if 1
tree in_min = TYPE_MIN_VALUE (int_type_node);
tree in_max = TYPE_MAX_VALUE (int_type_node);
#else
tree in_min = TYPE_MIN_VALUE (actual_type);
tree in_max = TYPE_MAX_VALUE (actual_type);
#endif
TYPE_MIN_VALUE (type) = copy_node (in_min);
TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
TYPE_MAX_VALUE (type) = copy_node (in_max);
TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
TYPE_PRECISION (type) = TYPE_PRECISION (int_type_node);
layout_type (type);
pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));
return type;
}
tree
builtin_function (const char *name,
tree type,
int function_code,
enum built_in_class cl,
const char *library_name,
tree ARG_UNUSED (attrs))
{
tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
DECL_EXTERNAL (decl) = 1;
TREE_PUBLIC (decl) = 1;
if (library_name)
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
make_decl_rtl (decl);
pushdecl (decl);
DECL_BUILT_IN_CLASS (decl) = cl;
DECL_FUNCTION_CODE (decl) = function_code;
return decl;
}
static tree
create_primitive_vtable (const char *name)
{
tree r;
char buf[50];
sprintf (buf, "_Jv_%sVTable", name);
r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
DECL_EXTERNAL (r) = 1;
return r;
}
static tree
do_nothing (tree t)
{
return t;
}
static void
parse_version (void)
{
const char *p = version_string;
unsigned int major = 0, minor = 0;
unsigned int abi_version;
while (*p && !ISDIGIT (*p))
++p;
gcc_assert (*p);
while (ISDIGIT (*p))
{
major = major * 10 + *p - '0';
++p;
}
gcc_assert (*p == '.' && ISDIGIT (p[1]));
++p;
while (ISDIGIT (*p))
{
minor = minor * 10 + *p - '0';
++p;
}
abi_version = 10000 * major + 10 * minor;
if (flag_indirect_dispatch)
abi_version += GCJ_BINARYCOMPAT_ADDITION;
gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
}
void
java_init_decl_processing (void)
{
tree endlink;
tree field = NULL_TREE;
tree t;
init_class_processing ();
current_function_decl = NULL;
current_binding_level = NULL_BINDING_LEVEL;
free_binding_level = NULL_BINDING_LEVEL;
pushlevel (0);
global_binding_level = current_binding_level;
error_mark_node = make_node (ERROR_MARK);
TREE_TYPE (error_mark_node) = error_mark_node;
initialize_sizetypes (false);
byte_type_node = make_signed_type (8);
pushdecl (build_decl (TYPE_DECL, get_identifier ("byte"), byte_type_node));
short_type_node = make_signed_type (16);
pushdecl (build_decl (TYPE_DECL, get_identifier ("short"), short_type_node));
int_type_node = make_signed_type (32);
pushdecl (build_decl (TYPE_DECL, get_identifier ("int"), int_type_node));
long_type_node = make_signed_type (64);
pushdecl (build_decl (TYPE_DECL, get_identifier ("long"), long_type_node));
unsigned_byte_type_node = make_unsigned_type (8);
pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned byte"),
unsigned_byte_type_node));
unsigned_short_type_node = make_unsigned_type (16);
pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned short"),
unsigned_short_type_node));
unsigned_int_type_node = make_unsigned_type (32);
pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
unsigned_int_type_node));
unsigned_long_type_node = make_unsigned_type (64);
pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned long"),
unsigned_long_type_node));
size_type_node = make_unsigned_type (POINTER_SIZE);
set_sizetype (size_type_node);
integer_type_node = java_type_for_size (INT_TYPE_SIZE, 0);
integer_zero_node = build_int_cst (NULL_TREE, 0);
integer_one_node = build_int_cst (NULL_TREE, 1);
integer_two_node = build_int_cst (NULL_TREE, 2);
integer_four_node = build_int_cst (NULL_TREE, 4);
integer_minus_one_node = build_int_cst (NULL_TREE, -1);
decimal_int_max = build_int_cstu (unsigned_int_type_node, 0x80000000);
#if HOST_BITS_PER_WIDE_INT == 64
decimal_long_max = build_int_cstu (unsigned_long_type_node,
0x8000000000000000LL);
#elif HOST_BITS_PER_WIDE_INT == 32
decimal_long_max = build_int_cst_wide (unsigned_long_type_node,
0, 0x80000000);
#else
#error "unsupported size"
#endif
size_zero_node = size_int (0);
size_one_node = size_int (1);
bitsize_zero_node = bitsize_int (0);
bitsize_one_node = bitsize_int (1);
bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
long_zero_node = build_int_cst (long_type_node, 0);
void_type_node = make_node (VOID_TYPE);
pushdecl (build_decl (TYPE_DECL, get_identifier ("void"), void_type_node));
layout_type (void_type_node);
ptr_type_node = build_pointer_type (void_type_node);
const_ptr_type_node
= build_pointer_type (build_type_variant (void_type_node, 1, 0));
t = make_node (VOID_TYPE);
layout_type (t);
return_address_type_node = build_pointer_type (t);
null_pointer_node = build_int_cst (ptr_type_node, 0);
#if 0
short_array_type_node = build_prim_array_type (short_type_node, 200);
#endif
char_type_node = make_node (CHAR_TYPE);
TYPE_PRECISION (char_type_node) = 16;
fixup_unsigned_type (char_type_node);
pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), char_type_node));
boolean_type_node = make_node (BOOLEAN_TYPE);
TYPE_PRECISION (boolean_type_node) = 1;
fixup_unsigned_type (boolean_type_node);
pushdecl (build_decl (TYPE_DECL, get_identifier ("boolean"),
boolean_type_node));
boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
promoted_byte_type_node
= push_promoted_type ("promoted_byte", byte_type_node);
promoted_short_type_node
= push_promoted_type ("promoted_short", short_type_node);
promoted_char_type_node
= push_promoted_type ("promoted_char", char_type_node);
promoted_boolean_type_node
= push_promoted_type ("promoted_boolean", boolean_type_node);
float_type_node = make_node (REAL_TYPE);
TYPE_PRECISION (float_type_node) = 32;
pushdecl (build_decl (TYPE_DECL, get_identifier ("float"),
float_type_node));
layout_type (float_type_node);
double_type_node = make_node (REAL_TYPE);
TYPE_PRECISION (double_type_node) = 64;
pushdecl (build_decl (TYPE_DECL, get_identifier ("double"),
double_type_node));
layout_type (double_type_node);
float_zero_node = build_real (float_type_node, dconst0);
double_zero_node = build_real (double_type_node, dconst0);
boolean_array_vtable = create_primitive_vtable ("boolean");
byte_array_vtable = create_primitive_vtable ("byte");
char_array_vtable = create_primitive_vtable ("char");
short_array_vtable = create_primitive_vtable ("short");
int_array_vtable = create_primitive_vtable ("int");
long_array_vtable = create_primitive_vtable ("long");
float_array_vtable = create_primitive_vtable ("float");
double_array_vtable = create_primitive_vtable ("double");
one_elt_array_domain_type = build_index_type (integer_one_node);
utf8const_type = make_node (RECORD_TYPE);
PUSH_FIELD (utf8const_type, field, "hash", unsigned_short_type_node);
PUSH_FIELD (utf8const_type, field, "length", unsigned_short_type_node);
FINISH_RECORD (utf8const_type);
utf8const_ptr_type = build_pointer_type (utf8const_type);
atable_type = build_array_type (ptr_type_node,
one_elt_array_domain_type);
TYPE_NONALIASED_COMPONENT (atable_type) = 1;
atable_ptr_type = build_pointer_type (atable_type);
itable_type = build_array_type (ptr_type_node,
one_elt_array_domain_type);
TYPE_NONALIASED_COMPONENT (itable_type) = 1;
itable_ptr_type = build_pointer_type (itable_type);
symbol_type = make_node (RECORD_TYPE);
PUSH_FIELD (symbol_type, field, "clname", utf8const_ptr_type);
PUSH_FIELD (symbol_type, field, "name", utf8const_ptr_type);
PUSH_FIELD (symbol_type, field, "signature", utf8const_ptr_type);
FINISH_RECORD (symbol_type);
symbols_array_type = build_array_type (symbol_type,
one_elt_array_domain_type);
symbols_array_ptr_type = build_pointer_type (symbols_array_type);
assertion_entry_type = make_node (RECORD_TYPE);
PUSH_FIELD (assertion_entry_type, field, "assertion_code", integer_type_node);
PUSH_FIELD (assertion_entry_type, field, "op1", utf8const_ptr_type);
PUSH_FIELD (assertion_entry_type, field, "op2", utf8const_ptr_type);
FINISH_RECORD (assertion_entry_type);
assertion_table_type = build_array_type (assertion_entry_type,
one_elt_array_domain_type);
unqualified_object_id_node = get_identifier ("Object");
object_type_node = lookup_class (get_identifier ("java.lang.Object"));
object_ptr_type_node = promote_type (object_type_node);
string_type_node = lookup_class (get_identifier ("java.lang.String"));
string_ptr_type_node = promote_type (string_type_node);
class_type_node = lookup_class (get_identifier ("java.lang.Class"));
throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
exception_type_node = lookup_class (get_identifier ("java.lang.Exception"));
runtime_exception_type_node =
lookup_class (get_identifier ("java.lang.RuntimeException"));
error_exception_type_node =
lookup_class (get_identifier ("java.lang.Error"));
rawdata_ptr_type_node
= promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
add_predefined_file (get_identifier ("java/lang/Class.java"));
add_predefined_file (get_identifier ("java/lang/Error.java"));
add_predefined_file (get_identifier ("java/lang/Object.java"));
add_predefined_file (get_identifier ("java/lang/RuntimeException.java"));
add_predefined_file (get_identifier ("java/lang/String.java"));
add_predefined_file (get_identifier ("java/lang/Throwable.java"));
add_predefined_file (get_identifier ("gnu/gcj/RawData.java"));
add_predefined_file (get_identifier ("java/lang/Exception.java"));
add_predefined_file (get_identifier ("java/lang/ClassNotFoundException.java"));
add_predefined_file (get_identifier ("java/lang/NoClassDefFoundError.java"));
methodtable_type = make_node (RECORD_TYPE);
layout_type (methodtable_type);
build_decl (TYPE_DECL, get_identifier ("methodtable"), methodtable_type);
methodtable_ptr_type = build_pointer_type (methodtable_type);
TYPE_identifier_node = get_identifier ("TYPE");
init_identifier_node = get_identifier ("<init>");
clinit_identifier_node = get_identifier ("<clinit>");
finit_identifier_node = get_identifier ("finit$");
instinit_identifier_node = get_identifier ("instinit$");
void_signature_node = get_identifier ("()V");
length_identifier_node = get_identifier ("length");
finalize_identifier_node = get_identifier ("finalize");
this_identifier_node = get_identifier ("this");
super_identifier_node = get_identifier ("super");
continue_identifier_node = get_identifier ("continue");
access0_identifier_node = get_identifier ("access$0");
classdollar_identifier_node = get_identifier ("class$");
java_lang_cloneable_identifier_node = get_identifier ("java.lang.Cloneable");
java_io_serializable_identifier_node =
get_identifier ("java.io.Serializable");
init_expr_processing();
constants_type_node = make_node (RECORD_TYPE);
PUSH_FIELD (constants_type_node, field, "size", unsigned_int_type_node);
PUSH_FIELD (constants_type_node, field, "tags", ptr_type_node);
PUSH_FIELD (constants_type_node, field, "data", ptr_type_node);
FINISH_RECORD (constants_type_node);
build_decl (TYPE_DECL, get_identifier ("constants"), constants_type_node);
access_flags_type_node = unsigned_short_type_node;
dtable_type = make_node (RECORD_TYPE);
dtable_ptr_type = build_pointer_type (dtable_type);
otable_type = build_array_type (integer_type_node,
one_elt_array_domain_type);
TYPE_NONALIASED_COMPONENT (otable_type) = 1;
otable_ptr_type = build_pointer_type (otable_type);
PUSH_FIELD (object_type_node, field, "vtable", dtable_ptr_type);
DECL_FCONTEXT (field) = object_type_node;
TYPE_VFIELD (object_type_node) = field;
if (! flag_hash_synchronization)
PUSH_FIELD (object_type_node, field, "sync_info",
build_pointer_type (object_type_node));
for (t = TYPE_FIELDS (object_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
FIELD_PRIVATE (t) = 1;
FINISH_RECORD (object_type_node);
field_type_node = make_node (RECORD_TYPE);
field_ptr_type_node = build_pointer_type (field_type_node);
method_type_node = make_node (RECORD_TYPE);
method_ptr_type_node = build_pointer_type (method_type_node);
set_super_info (0, class_type_node, object_type_node, 0);
set_super_info (0, string_type_node, object_type_node, 0);
class_ptr_type = build_pointer_type (class_type_node);
PUSH_FIELD (class_type_node, field, "next_or_version", class_ptr_type);
PUSH_FIELD (class_type_node, field, "name", utf8const_ptr_type);
PUSH_FIELD (class_type_node, field, "accflags", access_flags_type_node);
PUSH_FIELD (class_type_node, field, "superclass", class_ptr_type);
PUSH_FIELD (class_type_node, field, "constants", constants_type_node);
PUSH_FIELD (class_type_node, field, "methods", method_ptr_type_node);
PUSH_FIELD (class_type_node, field, "method_count", short_type_node);
PUSH_FIELD (class_type_node, field, "vtable_method_count", short_type_node);
PUSH_FIELD (class_type_node, field, "fields", field_ptr_type_node);
PUSH_FIELD (class_type_node, field, "size_in_bytes", int_type_node);
PUSH_FIELD (class_type_node, field, "field_count", short_type_node);
PUSH_FIELD (class_type_node, field, "static_field_count", short_type_node);
PUSH_FIELD (class_type_node, field, "vtable", dtable_ptr_type);
PUSH_FIELD (class_type_node, field, "otable", otable_ptr_type);
PUSH_FIELD (class_type_node, field, "otable_syms",
symbols_array_ptr_type);
PUSH_FIELD (class_type_node, field, "atable", atable_ptr_type);
PUSH_FIELD (class_type_node, field, "atable_syms",
symbols_array_ptr_type);
PUSH_FIELD (class_type_node, field, "itable", itable_ptr_type);
PUSH_FIELD (class_type_node, field, "itable_syms",
symbols_array_ptr_type);
PUSH_FIELD (class_type_node, field, "catch_classes", ptr_type_node);
PUSH_FIELD (class_type_node, field, "interfaces",
build_pointer_type (class_ptr_type));
PUSH_FIELD (class_type_node, field, "loader", ptr_type_node);
PUSH_FIELD (class_type_node, field, "interface_count", short_type_node);
PUSH_FIELD (class_type_node, field, "state", byte_type_node);
PUSH_FIELD (class_type_node, field, "thread", ptr_type_node);
PUSH_FIELD (class_type_node, field, "depth", short_type_node);
PUSH_FIELD (class_type_node, field, "ancestors", ptr_type_node);
PUSH_FIELD (class_type_node, field, "idt", ptr_type_node);
PUSH_FIELD (class_type_node, field, "arrayclass", ptr_type_node);
PUSH_FIELD (class_type_node, field, "protectionDomain", ptr_type_node);
PUSH_FIELD (class_type_node, field, "assertion_table", ptr_type_node);
PUSH_FIELD (class_type_node, field, "hack_signers", ptr_type_node);
PUSH_FIELD (class_type_node, field, "chain", ptr_type_node);
PUSH_FIELD (class_type_node, field, "aux_info", ptr_type_node);
PUSH_FIELD (class_type_node, field, "engine", ptr_type_node);
for (t = TYPE_FIELDS (class_type_node); t != NULL_TREE; t = TREE_CHAIN (t))
FIELD_PRIVATE (t) = 1;
push_super_field (class_type_node, object_type_node);
FINISH_RECORD (class_type_node);
build_decl (TYPE_DECL, get_identifier ("Class"), class_type_node);
field_info_union_node = make_node (UNION_TYPE);
PUSH_FIELD (field_info_union_node, field, "boffset", int_type_node);
PUSH_FIELD (field_info_union_node, field, "addr", ptr_type_node);
#if 0
PUSH_FIELD (field_info_union_node, field, "idx", unsigned_short_type_node);
#endif
layout_type (field_info_union_node);
PUSH_FIELD (field_type_node, field, "name", utf8const_ptr_type);
PUSH_FIELD (field_type_node, field, "type", class_ptr_type);
PUSH_FIELD (field_type_node, field, "accflags", access_flags_type_node);
PUSH_FIELD (field_type_node, field, "bsize", unsigned_short_type_node);
PUSH_FIELD (field_type_node, field, "info", field_info_union_node);
FINISH_RECORD (field_type_node);
build_decl (TYPE_DECL, get_identifier ("Field"), field_type_node);
nativecode_ptr_array_type_node
= build_array_type (nativecode_ptr_type_node, one_elt_array_domain_type);
PUSH_FIELD (dtable_type, field, "class", class_ptr_type);
PUSH_FIELD (dtable_type, field, "methods", nativecode_ptr_array_type_node);
FINISH_RECORD (dtable_type);
build_decl (TYPE_DECL, get_identifier ("dispatchTable"), dtable_type);
jexception_type = make_node (RECORD_TYPE);
PUSH_FIELD (jexception_type, field, "start_pc", ptr_type_node);
PUSH_FIELD (jexception_type, field, "end_pc", ptr_type_node);
PUSH_FIELD (jexception_type, field, "handler_pc", ptr_type_node);
PUSH_FIELD (jexception_type, field, "catch_type", class_ptr_type);
FINISH_RECORD (jexception_type);
build_decl (TYPE_DECL, get_identifier ("jexception"), field_type_node);
jexception_ptr_type = build_pointer_type (jexception_type);
lineNumberEntry_type = make_node (RECORD_TYPE);
PUSH_FIELD (lineNumberEntry_type, field, "line_nr", unsigned_short_type_node);
PUSH_FIELD (lineNumberEntry_type, field, "start_pc", ptr_type_node);
FINISH_RECORD (lineNumberEntry_type);
lineNumbers_type = make_node (RECORD_TYPE);
PUSH_FIELD (lineNumbers_type, field, "length", unsigned_int_type_node);
FINISH_RECORD (lineNumbers_type);
PUSH_FIELD (method_type_node, field, "name", utf8const_ptr_type);
PUSH_FIELD (method_type_node, field, "signature", utf8const_ptr_type);
PUSH_FIELD (method_type_node, field, "accflags", access_flags_type_node);
PUSH_FIELD (method_type_node, field, "index", unsigned_short_type_node);
PUSH_FIELD (method_type_node, field, "ncode", nativecode_ptr_type_node);
PUSH_FIELD (method_type_node, field, "throws", ptr_type_node);
FINISH_RECORD (method_type_node);
build_decl (TYPE_DECL, get_identifier ("Method"), method_type_node);
endlink = end_params_node = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
t = tree_cons (NULL_TREE, class_ptr_type, endlink);
alloc_object_node = builtin_function ("_Jv_AllocObject",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_MALLOC (alloc_object_node) = 1;
alloc_no_finalizer_node =
builtin_function ("_Jv_AllocObjectNoFinalizer",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_MALLOC (alloc_no_finalizer_node) = 1;
t = tree_cons (NULL_TREE, ptr_type_node, endlink);
soft_initclass_node = builtin_function ("_Jv_InitClass",
build_function_type (void_type_node,
t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
throw_node = builtin_function ("_Jv_Throw",
build_function_type (void_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
TREE_THIS_VOLATILE (throw_node) = 1;
TREE_SIDE_EFFECTS (throw_node) = 1;
t = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node,
endlink));
soft_monitorenter_node
= builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
NULL, NULL_TREE);
soft_monitorexit_node
= builtin_function ("_Jv_MonitorExit", t, 0, NOT_BUILT_IN,
NULL, NULL_TREE);
t = tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, int_type_node, endlink));
soft_newarray_node
= builtin_function ("_Jv_NewPrimArray",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_MALLOC (soft_newarray_node) = 1;
t = tree_cons (NULL_TREE, int_type_node,
tree_cons (NULL_TREE, class_ptr_type,
tree_cons (NULL_TREE, object_ptr_type_node,
endlink)));
soft_anewarray_node
= builtin_function ("_Jv_NewObjectArray",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_MALLOC (soft_anewarray_node) = 1;
t = tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, int_type_node, NULL_TREE));
soft_multianewarray_node
= builtin_function ("_Jv_NewMultiArray",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_MALLOC (soft_multianewarray_node) = 1;
t = build_function_type (void_type_node,
tree_cons (NULL_TREE, int_type_node, endlink));
soft_badarrayindex_node
= builtin_function ("_Jv_ThrowBadArrayIndex", t,
0, NOT_BUILT_IN, NULL, NULL_TREE);
TREE_THIS_VOLATILE (soft_badarrayindex_node) = 1;
TREE_SIDE_EFFECTS (soft_badarrayindex_node) = 1;
soft_nullpointer_node
= builtin_function ("_Jv_ThrowNullPointerException",
build_function_type (void_type_node, endlink),
0, NOT_BUILT_IN, NULL, NULL_TREE);
TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
t = tree_cons (NULL_TREE, class_ptr_type,
tree_cons (NULL_TREE, object_ptr_type_node, endlink));
soft_checkcast_node
= builtin_function ("_Jv_CheckCast",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = tree_cons (NULL_TREE, object_ptr_type_node,
tree_cons (NULL_TREE, class_ptr_type, endlink));
soft_instanceof_node
= builtin_function ("_Jv_IsInstanceOf",
build_function_type (boolean_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_PURE (soft_instanceof_node) = 1;
t = tree_cons (NULL_TREE, object_ptr_type_node,
tree_cons (NULL_TREE, object_ptr_type_node, endlink));
soft_checkarraystore_node
= builtin_function ("_Jv_CheckArrayStore",
build_function_type (void_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, int_type_node, endlink)));
soft_lookupinterfacemethod_node
= builtin_function ("_Jv_LookupInterfaceMethodIdx",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
DECL_IS_PURE (soft_lookupinterfacemethod_node) = 1;
t = tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node, endlink)));
soft_lookupinterfacemethodbyname_node
= builtin_function ("_Jv_LookupInterfaceMethod",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = tree_cons (NULL_TREE, object_ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, ptr_type_node,
tree_cons (NULL_TREE, int_type_node,
endlink))));
soft_lookupjnimethod_node
= builtin_function ("_Jv_LookupJNIMethod",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = tree_cons (NULL_TREE, ptr_type_node, endlink);
soft_getjnienvnewframe_node
= builtin_function ("_Jv_GetJNIEnvNewFrame",
build_function_type (ptr_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
soft_jnipopsystemframe_node
= builtin_function ("_Jv_JNI_PopSystemFrame",
build_function_type (void_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = tree_cons (NULL_TREE, int_type_node,
tree_cons (NULL_TREE, int_type_node, endlink));
soft_idiv_node
= builtin_function ("_Jv_divI",
build_function_type (int_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
soft_irem_node
= builtin_function ("_Jv_remI",
build_function_type (int_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
t = tree_cons (NULL_TREE, long_type_node,
tree_cons (NULL_TREE, long_type_node, endlink));
soft_ldiv_node
= builtin_function ("_Jv_divJ",
build_function_type (long_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
soft_lrem_node
= builtin_function ("_Jv_remJ",
build_function_type (long_type_node, t),
0, NOT_BUILT_IN, NULL, NULL_TREE);
eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
? "__gcj_personality_sj0"
: "__gcj_personality_v0");
lang_eh_runtime_type = do_nothing;
init_jcf_parse ();
initialize_builtins ();
soft_fmod_node = built_in_decls[BUILT_IN_FMOD];
#if 0
soft_fmodf_node = built_in_decls[BUILT_IN_FMODF];
#endif
parse_version ();
}
tree
lookup_name (tree name)
{
tree val;
if (current_binding_level != global_binding_level
&& IDENTIFIER_LOCAL_VALUE (name))
val = IDENTIFIER_LOCAL_VALUE (name);
else
val = IDENTIFIER_GLOBAL_VALUE (name);
return val;
}
static tree
lookup_name_current_level (tree name)
{
tree t;
if (current_binding_level == global_binding_level)
return IDENTIFIER_GLOBAL_VALUE (name);
if (IDENTIFIER_LOCAL_VALUE (name) == 0)
return 0;
for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
if (DECL_NAME (t) == name)
break;
return t;
}
void
push_labeled_block (tree lb)
{
tree name = DECL_NAME (LABELED_BLOCK_LABEL (lb));
struct binding_level *b = current_binding_level;
tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
if (oldlocal != 0)
b->shadowed = tree_cons (name, oldlocal, b->shadowed);
TREE_CHAIN (lb) = b->names;
b->names = lb;
IDENTIFIER_LOCAL_VALUE (name) = lb;
}
void
pop_labeled_block (void)
{
struct binding_level *b = current_binding_level;
tree label = b->names;
IDENTIFIER_LOCAL_VALUE (DECL_NAME (LABELED_BLOCK_LABEL (label))) =
NULL_TREE;
if (b->shadowed)
IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (b->shadowed)) =
TREE_VALUE (b->shadowed);
current_binding_level = current_binding_level->level_chain;
b->level_chain = free_binding_level;
free_binding_level = b;
}
tree
pushdecl (tree x)
{
tree t;
tree name = DECL_NAME (x);
struct binding_level *b = current_binding_level;
if (TREE_CODE (x) != TYPE_DECL)
DECL_CONTEXT (x) = current_function_decl;
if (name)
{
t = lookup_name_current_level (name);
if (t != 0 && t == error_mark_node)
{
t = 0;
error ("%J'%D' used prior to declaration", x, x);
}
if (TREE_CODE (x) == TYPE_DECL
&& TYPE_NAME (TREE_TYPE (x)) == 0
&& TREE_TYPE (x) != error_mark_node)
{
TYPE_NAME (TREE_TYPE (x)) = x;
TYPE_STUB_DECL (TREE_TYPE (x)) = x;
}
if (b == global_binding_level)
{
IDENTIFIER_GLOBAL_VALUE (name) = x;
}
else
{
tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
IDENTIFIER_LOCAL_VALUE (name) = x;
#if 0
if (oldlocal != 0 && !DECL_EXTERNAL (x)
&& ! current_binding_level->parm_flag
&& current_binding_level->level_chain->parm_flag
&& chain_member (oldlocal, current_binding_level->level_chain->names))
{
if (TREE_CODE (oldlocal) == PARM_DECL)
pedwarn ("declaration of %qs shadows a parameter",
IDENTIFIER_POINTER (name));
else
pedwarn ("declaration of %qs shadows a symbol from the parameter list",
IDENTIFIER_POINTER (name));
}
else if (warn_shadow && !DECL_EXTERNAL (x)
&& DECL_SOURCE_LINE (x) != 0
&& ! DECL_FROM_INLINE (x))
{
const char *warnstring = 0;
if (TREE_CODE (x) == PARM_DECL
&& current_binding_level->level_chain->parm_flag)
;
else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
warnstring = "declaration of %qs shadows a parameter";
else if (oldlocal != 0)
warnstring = "declaration of %qs shadows previous local";
else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
&& IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
warnstring = "declaration of %qs shadows global declaration";
if (warnstring)
warning (warnstring, IDENTIFIER_POINTER (name));
}
#endif
if (oldlocal != 0)
b->shadowed = tree_cons (name, oldlocal, b->shadowed);
}
}
TREE_CHAIN (x) = b->names;
b->names = x;
return x;
}
void
pushdecl_force_head (tree x)
{
current_binding_level->names = x;
}
tree
pushdecl_top_level (tree x)
{
tree t;
struct binding_level *b = current_binding_level;
current_binding_level = global_binding_level;
t = pushdecl (x);
current_binding_level = b;
return t;
}
tree
pushdecl_function_level (tree x)
{
tree t;
struct binding_level *b = current_binding_level;
current_binding_level = function_binding_level;
t = pushdecl (x);
current_binding_level = b;
return t;
}
int
global_bindings_p (void)
{
return current_binding_level == global_binding_level;
}
tree
getdecls (void)
{
return current_binding_level->names;
}
static struct binding_level *
make_binding_level (void)
{
return ggc_alloc_cleared (sizeof (struct binding_level));
}
void
pushlevel (int unused ATTRIBUTE_UNUSED)
{
struct binding_level *newlevel = NULL_BINDING_LEVEL;
#if 0
if (current_binding_level == global_binding_level)
named_labels = 0;
#endif
if (free_binding_level)
{
newlevel = free_binding_level;
free_binding_level = free_binding_level->level_chain;
}
else
{
newlevel = make_binding_level ();
}
*newlevel = clear_binding_level;
newlevel->level_chain = current_binding_level;
current_binding_level = newlevel;
#if defined(DEBUG_JAVA_BINDING_LEVELS)
newlevel->binding_depth = binding_depth;
indent ();
fprintf (stderr, "push %s level %p pc %d\n",
(is_class_level) ? "class" : "block", newlevel, current_pc);
is_class_level = 0;
binding_depth++;
#endif
}
tree
poplevel (int keep, int reverse, int functionbody)
{
tree link;
tree decls;
tree subblocks = current_binding_level->blocks;
tree block = 0;
tree decl;
tree bind = 0;
#if defined(DEBUG_JAVA_BINDING_LEVELS)
binding_depth--;
indent ();
if (current_binding_level->end_pc != LARGEST_PC)
fprintf (stderr, "pop %s level %p pc %d (end pc %d)\n",
(is_class_level) ? "class" : "block", current_binding_level, current_pc,
current_binding_level->end_pc);
else
fprintf (stderr, "pop %s level %p pc %d\n",
(is_class_level) ? "class" : "block", current_binding_level, current_pc);
#if 0
if (is_class_level != (current_binding_level == class_binding_level))
{
indent ();
fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
}
is_class_level = 0;
#endif
#endif
if (reverse)
current_binding_level->names
= decls = nreverse (current_binding_level->names);
else
decls = current_binding_level->names;
for (decl = decls; decl; decl = TREE_CHAIN (decl))
if (TREE_CODE (decl) == VAR_DECL
&& DECL_LANG_SPECIFIC (decl) != NULL
&& DECL_LOCAL_SLOT_NUMBER (decl))
LOCAL_VAR_OUT_OF_SCOPE_P (decl) = 1;
block = 0;
if (keep || functionbody)
{
block = make_node (BLOCK);
TREE_TYPE (block) = void_type_node;
}
if (current_binding_level->exception_range)
expand_end_java_handler (current_binding_level->exception_range);
if (block != 0)
{
if (current_binding_level->stmts)
{
tree decl = decls;
tree *var = &BLOCK_VARS (block);
while (decl)
{
tree next = TREE_CHAIN (decl);
if (TREE_CODE (decl) != LABEL_DECL)
{
*var = decl;
var = &TREE_CHAIN (decl);
}
decl = next;
}
*var = NULL;
bind = build3 (BIND_EXPR, TREE_TYPE (block), BLOCK_VARS (block),
BLOCK_EXPR_BODY (block), block);
BIND_EXPR_BODY (bind) = current_binding_level->stmts;
if (BIND_EXPR_BODY (bind)
&& TREE_SIDE_EFFECTS (BIND_EXPR_BODY (bind)))
TREE_SIDE_EFFECTS (bind) = 1;
if (BIND_EXPR_BODY (bind) == NULL)
BIND_EXPR_BODY (bind) = build_java_empty_stmt ();
current_binding_level->stmts = NULL;
}
else
{
BLOCK_VARS (block) = decls;
}
BLOCK_SUBBLOCKS (block) = subblocks;
}
for (link = subblocks; link; link = TREE_CHAIN (link))
BLOCK_SUPERCONTEXT (link) = block;
for (link = decls; link; link = TREE_CHAIN (link))
{
tree name = DECL_NAME (link);
if (name != 0 && IDENTIFIER_LOCAL_VALUE (name) == link)
{
if (DECL_EXTERNAL (link))
{
if (TREE_USED (link))
TREE_USED (name) = 1;
if (TREE_ADDRESSABLE (link))
TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
}
IDENTIFIER_LOCAL_VALUE (name) = 0;
}
}
for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
if (functionbody)
{
BLOCK_VARS (block) = 0;
#if 0
for (link = named_labels; link; link = TREE_CHAIN (link))
{
tree label = TREE_VALUE (link);
if (DECL_INITIAL (label) == 0)
{
error ("%Jlabel '%D' used but not defined", label, label);
define_label (input_location, DECL_NAME (label));
}
else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
warning ("%Jlabel '%D' defined but not used", label, label);
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
TREE_CHAIN (label) = BLOCK_VARS (block);
BLOCK_VARS (block) = label;
}
#endif
}
{
struct binding_level *level = current_binding_level;
current_binding_level = current_binding_level->level_chain;
level->level_chain = free_binding_level;
free_binding_level = level;
}
if (functionbody)
{
DECL_INITIAL (current_function_decl) = block;
DECL_SAVED_TREE (current_function_decl) = bind;
}
else
{
if (block)
{
current_binding_level->blocks
= chainon (current_binding_level->blocks, block);
}
else if (subblocks)
current_binding_level->blocks
= chainon (current_binding_level->blocks, subblocks);
if (bind)
java_add_stmt (bind);
}
if (block)
TREE_USED (block) = 1;
return block;
}
void
maybe_pushlevels (int pc)
{
#if defined(DEBUG_JAVA_BINDING_LEVELS)
current_pc = pc;
#endif
while (pending_local_decls != NULL_TREE &&
DECL_LOCAL_START_PC (pending_local_decls) <= pc)
{
tree *ptr = &pending_local_decls;
tree decl = *ptr, next;
int end_pc = DECL_LOCAL_END_PC (decl);
while (*ptr != NULL_TREE
&& DECL_LOCAL_START_PC (*ptr) <= pc
&& DECL_LOCAL_END_PC (*ptr) == end_pc)
ptr = &TREE_CHAIN (*ptr);
pending_local_decls = *ptr;
*ptr = NULL_TREE;
if (end_pc > current_binding_level->end_pc)
{
end_pc = current_binding_level->end_pc;
DECL_LOCAL_END_PC (decl) = end_pc;
}
maybe_start_try (pc, end_pc);
pushlevel (1);
current_binding_level->end_pc = end_pc;
current_binding_level->start_pc = pc;
current_binding_level->names = NULL;
for ( ; decl != NULL_TREE; decl = next)
{
next = TREE_CHAIN (decl);
push_jvm_slot (DECL_LOCAL_SLOT_NUMBER (decl), decl);
pushdecl (decl);
initialize_local_variable (decl, DECL_LOCAL_SLOT_NUMBER (decl));
}
}
maybe_start_try (pc, 0);
}
void
maybe_poplevels (int pc)
{
#if defined(DEBUG_JAVA_BINDING_LEVELS)
current_pc = pc;
#endif
while (current_binding_level->end_pc <= pc)
poplevel (1, 0, 0);
}
void
force_poplevels (int start_pc)
{
while (current_binding_level->start_pc > start_pc)
{
if (pedantic && current_binding_level->start_pc > start_pc)
warning ("%JIn %D: overlapped variable and exception ranges at %d",
current_function_decl, current_function_decl,
current_binding_level->start_pc);
poplevel (1, 0, 0);
}
}
void
insert_block (tree block)
{
TREE_USED (block) = 1;
current_binding_level->blocks
= chainon (current_binding_level->blocks, block);
}
void
java_dup_lang_specific_decl (tree node)
{
int lang_decl_size;
struct lang_decl *x;
if (!DECL_LANG_SPECIFIC (node))
return;
lang_decl_size = sizeof (struct lang_decl);
x = ggc_alloc (lang_decl_size);
memcpy (x, DECL_LANG_SPECIFIC (node), lang_decl_size);
DECL_LANG_SPECIFIC (node) = x;
}
void
give_name_to_locals (JCF *jcf)
{
int i, n = DECL_LOCALVARIABLES_OFFSET (current_function_decl);
int code_offset = DECL_CODE_OFFSET (current_function_decl);
tree parm;
pending_local_decls = NULL_TREE;
if (n == 0)
return;
JCF_SEEK (jcf, n);
n = JCF_readu2 (jcf);
for (i = 0; i < n; i++)
{
int start_pc = JCF_readu2 (jcf);
int length = JCF_readu2 (jcf);
int name_index = JCF_readu2 (jcf);
int signature_index = JCF_readu2 (jcf);
int slot = JCF_readu2 (jcf);
tree name = get_name_constant (jcf, name_index);
tree type = parse_signature (jcf, signature_index);
if (slot < DECL_ARG_SLOT_COUNT (current_function_decl)
&& start_pc == 0
&& length == DECL_CODE_LENGTH (current_function_decl))
{
tree decl = TREE_VEC_ELT (decl_map, slot);
DECL_NAME (decl) = name;
SET_DECL_ASSEMBLER_NAME (decl, name);
if (TREE_CODE (decl) != PARM_DECL || TREE_TYPE (decl) != type)
warning ("bad type in parameter debug info");
}
else
{
tree *ptr;
int end_pc = start_pc + length;
tree decl = build_decl (VAR_DECL, name, type);
if (end_pc > DECL_CODE_LENGTH (current_function_decl))
{
warning ("%Jbad PC range for debug info for local '%D'",
decl, decl);
end_pc = DECL_CODE_LENGTH (current_function_decl);
}
start_pc = maybe_adjust_start_pc (jcf, code_offset, start_pc, slot);
MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
DECL_LOCAL_SLOT_NUMBER (decl) = slot;
DECL_LOCAL_START_PC (decl) = start_pc;
#if 0
end_pc++;
#endif
DECL_LOCAL_END_PC (decl) = end_pc;
ptr = &pending_local_decls;
while (*ptr != NULL_TREE
&& (DECL_LOCAL_START_PC (*ptr) > start_pc
|| (DECL_LOCAL_START_PC (*ptr) == start_pc
&& DECL_LOCAL_END_PC (*ptr) < end_pc)))
ptr = &TREE_CHAIN (*ptr);
TREE_CHAIN (decl) = *ptr;
*ptr = decl;
}
}
pending_local_decls = nreverse (pending_local_decls);
for (parm = DECL_ARGUMENTS (current_function_decl), i = 0;
parm != NULL_TREE; parm = TREE_CHAIN (parm), i++)
{
if (DECL_NAME (parm) == NULL_TREE)
{
int arg_i = METHOD_STATIC (current_function_decl) ? i+1 : i;
if (arg_i == 0)
DECL_NAME (parm) = get_identifier ("this");
else
{
char buffer[12];
sprintf (buffer, "ARG_%d", arg_i);
DECL_NAME (parm) = get_identifier (buffer);
}
SET_DECL_ASSEMBLER_NAME (parm, DECL_NAME (parm));
}
}
}
tree
build_result_decl (tree fndecl)
{
tree restype = TREE_TYPE (TREE_TYPE (fndecl));
tree result = DECL_RESULT (fndecl);
if (! result)
{
if (INTEGRAL_TYPE_P (restype)
&& TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
restype = integer_type_node;
result = build_decl (RESULT_DECL, NULL_TREE, restype);
DECL_ARTIFICIAL (result) = 1;
DECL_IGNORED_P (result) = 1;
DECL_CONTEXT (result) = fndecl;
DECL_RESULT (fndecl) = result;
}
return result;
}
void
start_java_method (tree fndecl)
{
tree tem, *ptr;
int i;
uniq = 0;
current_function_decl = fndecl;
announce_function (fndecl);
i = DECL_MAX_LOCALS(fndecl) + DECL_MAX_STACK(fndecl);
decl_map = make_tree_vec (i);
base_decl_map = make_tree_vec (i);
type_map = xrealloc (type_map, i * sizeof (tree));
#if defined(DEBUG_JAVA_BINDING_LEVELS)
fprintf (stderr, "%s:\n", lang_printable_name (fndecl, 2));
current_pc = 0;
#endif
pushlevel (1);
ptr = &DECL_ARGUMENTS (fndecl);
for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
tem != end_params_node; tem = TREE_CHAIN (tem), i++)
{
tree parm_name = NULL_TREE, parm_decl;
tree parm_type = TREE_VALUE (tem);
if (i >= DECL_MAX_LOCALS (fndecl))
abort ();
parm_decl = build_decl (PARM_DECL, parm_name, parm_type);
DECL_CONTEXT (parm_decl) = fndecl;
if (targetm.calls.promote_prototypes (parm_type)
&& TYPE_PRECISION (parm_type) < TYPE_PRECISION (integer_type_node)
&& INTEGRAL_TYPE_P (parm_type))
parm_type = integer_type_node;
DECL_ARG_TYPE (parm_decl) = parm_type;
*ptr = parm_decl;
ptr = &TREE_CHAIN (parm_decl);
push_jvm_slot (i, parm_decl);
type_map[i] = TREE_TYPE (parm_decl);
if (TYPE_IS_WIDE (TREE_TYPE (parm_decl)))
{
i++;
type_map[i] = void_type_node;
}
}
*ptr = NULL_TREE;
DECL_ARG_SLOT_COUNT (current_function_decl) = i;
while (i < DECL_MAX_LOCALS(fndecl))
type_map[i++] = NULL_TREE;
build_result_decl (fndecl);
pushlevel (2);
function_binding_level = current_binding_level;
}
void
end_java_method (void)
{
tree fndecl = current_function_decl;
poplevel (1, 1, 0);
poplevel (1, 0, 1);
BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
if (DECL_SAVED_TREE (fndecl))
{
tree fbody, block_body;
fbody = DECL_SAVED_TREE (fndecl);
block_body = BIND_EXPR_BODY (fbody);
htab_traverse (DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
attach_init_test_initialization_flags, block_body);
}
flag_unit_at_a_time = 0;
finish_method (fndecl);
if (! flag_unit_at_a_time)
{
DECL_SAVED_TREE (fndecl) = NULL;
DECL_STRUCT_FUNCTION (fndecl) = NULL;
DECL_INITIAL (fndecl) = NULL_TREE;
}
current_function_decl = NULL_TREE;
}
void
finish_method (tree fndecl)
{
tree *tp = &DECL_SAVED_TREE (fndecl);
if (METHOD_SYNCHRONIZED (fndecl))
{
tree enter, exit, lock;
if (METHOD_STATIC (fndecl))
lock = build_class_ref (DECL_CONTEXT (fndecl));
else
lock = DECL_ARGUMENTS (fndecl);
BUILD_MONITOR_ENTER (enter, lock);
BUILD_MONITOR_EXIT (exit, lock);
*tp = build2 (COMPOUND_EXPR, void_type_node, enter,
build2 (TRY_FINALLY_EXPR, void_type_node, *tp, exit));
}
if (METHOD_STATIC (fndecl) && ! METHOD_PRIVATE (fndecl)
&& ! DECL_CLINIT_P (fndecl)
&& ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (fndecl))))
{
tree clas = DECL_CONTEXT (fndecl);
tree init = build3 (CALL_EXPR, void_type_node,
build_address_of (soft_initclass_node),
build_tree_list (NULL_TREE, build_class_ref (clas)),
NULL_TREE);
*tp = build2 (COMPOUND_EXPR, TREE_TYPE (*tp), init, *tp);
}
java_genericize (fndecl);
if (DECL_STRUCT_FUNCTION (fndecl))
cfun = DECL_STRUCT_FUNCTION (fndecl);
else
allocate_struct_function (fndecl);
#ifdef USE_MAPPED_LOCATION
cfun->function_end_locus = DECL_FUNCTION_LAST_LINE (fndecl);
#else
cfun->function_end_locus.file = DECL_SOURCE_FILE (fndecl);
cfun->function_end_locus.line = DECL_FUNCTION_LAST_LINE (fndecl);
#endif
cgraph_finalize_function (fndecl, false);
}
void
java_expand_body (tree fndecl)
{
tree_rest_of_compilation (fndecl);
}
static void
java_mark_decl_local (tree decl)
{
DECL_EXTERNAL (decl) = 0;
if (DECL_RTL_SET_P (decl))
make_decl_rtl (decl);
}
void
java_mark_class_local (tree class)
{
tree t;
for (t = TYPE_FIELDS (class); t ; t = TREE_CHAIN (t))
if (FIELD_STATIC (t))
java_mark_decl_local (t);
for (t = TYPE_METHODS (class); t ; t = TREE_CHAIN (t))
if (!METHOD_ABSTRACT (t) && (!METHOD_NATIVE (t) || flag_jni))
java_mark_decl_local (t);
}
tree
add_stmt_to_compound (tree existing, tree type, tree stmt)
{
if (!stmt)
return existing;
else if (existing)
{
tree expr = build2 (COMPOUND_EXPR, type, existing, stmt);
TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (existing)
| TREE_SIDE_EFFECTS (stmt);
return expr;
}
else
return stmt;
}
tree
java_add_stmt (tree stmt)
{
if (input_filename)
SET_EXPR_LOCATION (stmt, input_location);
return current_binding_level->stmts
= add_stmt_to_compound (current_binding_level->stmts,
TREE_TYPE (stmt), stmt);
}
tree
java_add_local_var (tree decl)
{
tree *vars = ¤t_binding_level->names;
tree next = *vars;
TREE_CHAIN (decl) = next;
*vars = decl;
DECL_CONTEXT (decl) = current_function_decl;
MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
return decl;
}
tree *
get_stmts (void)
{
return ¤t_binding_level->stmts;
}
void
register_exception_range (struct eh_range *range, int pc, int end_pc)
{
if (current_binding_level->exception_range)
abort ();
current_binding_level->exception_range = range;
current_binding_level->end_pc = end_pc;
current_binding_level->start_pc = pc;
}
#include "gt-java-decl.h"