Commit eff71ab0 by Per Bothner

cp-tree.h (TYPE_FOR_JAVA): New macro.

d
	* cp-tree.h (TYPE_FOR_JAVA):  New macro.
	* decl.c, cp-tree.h (java_byte_type_node, java_short_type_node,
	java_int_type_node, java_long_type_node, java_float_type_node,
	java_double_type_node, java_char_type_node, java_boolean_type_node):
	New "primitive" types, with predefined names __java_byte etc.
	(record_builtin_java_type):  New function.
	(init_decl_processing):  Make Java types with record_builtin_java_type.
	(pushtag, grokdeclarator):  Set TYPE_FOR_JAVA if in extern "JAVA".
	(xref_baseypes):  If base class was TYPE_FOR_JAVA, so is this class.
	(grokfndecl):  Call check_java_method for Java classes.
	* method.c (is_java_type):  Removed.  Replaced with TYPE_FOR_JAVA.
	(process_overload_item):  Match types against specific
	java_XX_type_node types, rather than using is_java_type.
	* class.c (finish_struct_1):  Don't add default copy constructor
	or operator= if TYPE_FOR_JAVA.
	(pop_lang_conext):  Restore strict_prototyp proper if Java.
	* decl2.c (acceptable_java_type, check_java_method):  New functions.
	* pt.c (instantiate_class_template):  Copy TYPE_FOR_JAVA from pattern.
	(tsubst):  Move common statement after if statement.
	* typeck.c (comptypes):  If strict, TYPE_FOR_JAVA must match.

From-SVN: r20174
parent 44ec7e59
...@@ -3601,7 +3601,7 @@ finish_struct_1 (t, warn_anon) ...@@ -3601,7 +3601,7 @@ finish_struct_1 (t, warn_anon)
} }
/* Create default copy constructor, if needed. */ /* Create default copy constructor, if needed. */
if (! TYPE_HAS_INIT_REF (t) && ! IS_SIGNATURE (t)) if (! TYPE_HAS_INIT_REF (t) && ! IS_SIGNATURE (t) && ! TYPE_FOR_JAVA (t))
{ {
/* ARM 12.18: You get either X(X&) or X(const X&), but /* ARM 12.18: You get either X(X&) or X(const X&), but
not both. --Chip */ not both. --Chip */
...@@ -3616,7 +3616,7 @@ finish_struct_1 (t, warn_anon) ...@@ -3616,7 +3616,7 @@ finish_struct_1 (t, warn_anon)
TYPE_HAS_COMPLEX_ASSIGN_REF (t) TYPE_HAS_COMPLEX_ASSIGN_REF (t)
|= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t); |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
if (! TYPE_HAS_ASSIGN_REF (t) && ! IS_SIGNATURE (t)) if (! TYPE_HAS_ASSIGN_REF (t) && ! IS_SIGNATURE (t) && ! TYPE_FOR_JAVA (t))
{ {
tree default_fn = cons_up_default_function (t, name, tree default_fn = cons_up_default_function (t, name,
5 + no_const_asn_ref); 5 + no_const_asn_ref);
...@@ -4915,7 +4915,8 @@ void ...@@ -4915,7 +4915,8 @@ void
pop_lang_context () pop_lang_context ()
{ {
current_lang_name = *--current_lang_stack; current_lang_name = *--current_lang_stack;
if (current_lang_name == lang_name_cplusplus) if (current_lang_name == lang_name_cplusplus
|| current_lang_name == lang_name_java)
strict_prototype = strict_prototypes_lang_cplusplus; strict_prototype = strict_prototypes_lang_cplusplus;
else if (current_lang_name == lang_name_c) else if (current_lang_name == lang_name_c)
strict_prototype = strict_prototypes_lang_c; strict_prototype = strict_prototypes_lang_c;
......
...@@ -234,6 +234,15 @@ tree unsigned_intSI_type_node; ...@@ -234,6 +234,15 @@ tree unsigned_intSI_type_node;
tree unsigned_intDI_type_node; tree unsigned_intDI_type_node;
tree unsigned_intTI_type_node; tree unsigned_intTI_type_node;
tree java_byte_type_node;
tree java_short_type_node;
tree java_int_type_node;
tree java_long_type_node;
tree java_float_type_node;
tree java_double_type_node;
tree java_char_type_node;
tree java_boolean_type_node;
/* A VOID_TYPE node, and the same, packaged in a TREE_LIST. */ /* A VOID_TYPE node, and the same, packaged in a TREE_LIST. */
tree void_type_node, void_list_node; tree void_type_node, void_list_node;
...@@ -2227,6 +2236,8 @@ pushtag (name, type, globalize) ...@@ -2227,6 +2236,8 @@ pushtag (name, type, globalize)
{ {
newdecl = 1; newdecl = 1;
d = build_decl (TYPE_DECL, name, type); d = build_decl (TYPE_DECL, name, type);
if (current_lang_name == lang_name_java)
TYPE_FOR_JAVA (type) = 1;
SET_DECL_ARTIFICIAL (d); SET_DECL_ARTIFICIAL (d);
if (! in_class) if (! in_class)
set_identifier_type_value_with_scope (name, type, b); set_identifier_type_value_with_scope (name, type, b);
...@@ -5055,6 +5066,37 @@ record_builtin_type (rid_index, name, type) ...@@ -5055,6 +5066,37 @@ record_builtin_type (rid_index, name, type)
} }
} }
/* Record one of the standard Java types.
* Declare it as having the given NAME.
* If SIZE > 0, it is the size of one of the integral types;
* otherwise it is the negative of the size of one of the other types. */
static tree
record_builtin_java_type (name, size)
char *name;
int size;
{
tree type, decl;
if (size > 0)
type = make_signed_type (size);
else if (size > -32)
{ /* "__java_char" or ""__java_boolean". */
type = make_unsigned_type (-size);
/*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/
}
else
{ /* "__java_float" or ""__java_double". */
type = make_node (REAL_TYPE);
TYPE_PRECISION (type) = - size;
layout_type (type);
}
record_builtin_type (RID_MAX, name, type);
decl = TYPE_NAME (type);
DECL_IGNORED_P (decl) = 1;
TYPE_FOR_JAVA (type) = 1;
return type;
}
/* Push a type into the namespace so that the back-ends ignore it. */ /* Push a type into the namespace so that the back-ends ignore it. */
static void static void
...@@ -5329,6 +5371,15 @@ init_decl_processing () ...@@ -5329,6 +5371,15 @@ init_decl_processing ()
TREE_TYPE (complex_long_double_type_node) = long_double_type_node; TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
layout_type (complex_long_double_type_node); layout_type (complex_long_double_type_node);
java_byte_type_node = record_builtin_java_type ("__java_byte", 8);
java_short_type_node = record_builtin_java_type ("__java_short", 16);
java_int_type_node = record_builtin_java_type ("__java_int", 32);
java_long_type_node = record_builtin_java_type ("__java_long", 64);
java_float_type_node = record_builtin_java_type ("__java_float", -32);
java_double_type_node = record_builtin_java_type ("__java_double", -64);
java_char_type_node = record_builtin_java_type ("__java_char", -16);
java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);
integer_zero_node = build_int_2 (0, 0); integer_zero_node = build_int_2 (0, 0);
TREE_TYPE (integer_zero_node) = integer_type_node; TREE_TYPE (integer_zero_node) = integer_type_node;
integer_one_node = build_int_2 (1, 0); integer_one_node = build_int_2 (1, 0);
...@@ -7617,7 +7668,8 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, ...@@ -7617,7 +7668,8 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
2 * (funcdef_flag != 0) + 2 * (funcdef_flag != 0) +
4 * (friendp != 0)); 4 * (friendp != 0));
if (check) if ((! TYPE_FOR_JAVA (ctype) || check_java_method (ctype, decl))
&& check)
{ {
tmp = check_classfn (ctype, decl); tmp = check_classfn (ctype, decl);
...@@ -7662,8 +7714,9 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, ...@@ -7662,8 +7714,9 @@ grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals,
template_count, template_count,
2 * (funcdef_flag != 0) + 2 * (funcdef_flag != 0) +
4 * (friendp != 0)); 4 * (friendp != 0));
if (ctype != NULL_TREE
if (ctype != NULL_TREE && check) && (! TYPE_FOR_JAVA (ctype) || check_java_method (ctype, decl))
&& check)
{ {
tmp = check_classfn (ctype, decl); tmp = check_classfn (ctype, decl);
...@@ -9572,6 +9625,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) ...@@ -9572,6 +9625,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
in typenames, fields or parameters. */ in typenames, fields or parameters. */
if (constp || volatilep) if (constp || volatilep)
type = cp_build_type_variant (type, constp, volatilep); type = cp_build_type_variant (type, constp, volatilep);
if (current_lang_name == lang_name_java)
TYPE_FOR_JAVA (type) = 1;
if (decl_context == FIELD) if (decl_context == FIELD)
{ {
...@@ -9582,8 +9637,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) ...@@ -9582,8 +9637,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
if (IS_SIGNATURE (current_class_type) && opaque_typedef) if (IS_SIGNATURE (current_class_type) && opaque_typedef)
SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
} }
else if (current_lang_name == lang_name_java)
decl = build_lang_decl (TYPE_DECL, declarator, type);
else else
{ {
/* Make sure this typedef lives as long as its type, /* Make sure this typedef lives as long as its type,
...@@ -11249,6 +11302,10 @@ xref_basetypes (code_type_node, name, ref, binfo) ...@@ -11249,6 +11302,10 @@ xref_basetypes (code_type_node, name, ref, binfo)
continue; continue;
} }
if (TYPE_FOR_JAVA (basetype)
&& current_lang_stack == current_lang_base)
TYPE_FOR_JAVA (ref) = 1;
/* Note that the BINFO records which describe individual /* Note that the BINFO records which describe individual
inheritances are *not* shared in the lattice! They inheritances are *not* shared in the lattice! They
cannot be shared because a given baseclass may be cannot be shared because a given baseclass may be
......
...@@ -1375,6 +1375,56 @@ check_member_template (tmpl) ...@@ -1375,6 +1375,56 @@ check_member_template (tmpl)
cp_error ("template declaration of `%#D'", decl); cp_error ("template declaration of `%#D'", decl);
} }
/* Return true iff TYPE is a valid Java parameter or return type. */
int
acceptable_java_type (type)
tree type;
{
if (TREE_CODE (type) == VOID_TYPE || TYPE_FOR_JAVA (type))
return 1;
if (TREE_CODE (type) == POINTER_TYPE)
{
type = TREE_TYPE (type);
if (TREE_CODE (type) == RECORD_TYPE)
{
complete_type (type);
return TYPE_FOR_JAVA (type);
}
}
return 0;
}
/* For a METHOD in a Java class CTYPE, return 1 if
the parameter and return types are valid Java types.
Otherwise, print appropriate error messages, and return 0. */
int
check_java_method (ctype, method)
tree ctype, method;
{
int jerr = 0;
tree arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
tree ret_type = TREE_TYPE (TREE_TYPE (method));
if (! acceptable_java_type (ret_type))
{
cp_error ("Java method '%D' has non-Java return type `%T'",
method, ret_type);
jerr++;
}
for (; arg_types != NULL_TREE; arg_types = TREE_CHAIN (arg_types))
{
tree type = TREE_VALUE (arg_types);
if (! acceptable_java_type (type))
{
cp_error ("Java method '%D' has non-Java parameter type `%T'",
method, type);
jerr++;
}
}
return jerr ? 0 : 1;
}
/* Sanity check: report error if this function FUNCTION is not /* Sanity check: report error if this function FUNCTION is not
really a member of the class (CTYPE) it is supposed to belong to. really a member of the class (CTYPE) it is supposed to belong to.
CNAME is the same here as it is for grokclassfn above. */ CNAME is the same here as it is for grokclassfn above. */
......
...@@ -3749,6 +3749,7 @@ instantiate_class_template (type) ...@@ -3749,6 +3749,7 @@ instantiate_class_template (type)
= TYPE_USES_VIRTUAL_BASECLASSES (pattern); = TYPE_USES_VIRTUAL_BASECLASSES (pattern);
TYPE_PACKED (type) = TYPE_PACKED (pattern); TYPE_PACKED (type) = TYPE_PACKED (pattern);
TYPE_ALIGN (type) = TYPE_ALIGN (pattern); TYPE_ALIGN (type) = TYPE_ALIGN (pattern);
TYPE_FOR_JAVA (type) = TYPE_FOR_JAVA (pattern); /* For libjava's JArray<T> */
CLASSTYPE_LOCAL_TYPEDECLS (type) = CLASSTYPE_LOCAL_TYPEDECLS (pattern); CLASSTYPE_LOCAL_TYPEDECLS (type) = CLASSTYPE_LOCAL_TYPEDECLS (pattern);
...@@ -4498,14 +4499,13 @@ tsubst (t, args, in_decl) ...@@ -4498,14 +4499,13 @@ tsubst (t, args, in_decl)
else else
member = 1; member = 1;
ctx = tsubst (DECL_CLASS_CONTEXT (t), args, t); ctx = tsubst (DECL_CLASS_CONTEXT (t), args, t);
type = tsubst (type, args, in_decl);
} }
else else
{ {
member = 0; member = 0;
ctx = NULL_TREE; ctx = NULL_TREE;
type = tsubst (type, args, in_decl);
} }
type = tsubst (type, args, in_decl);
/* If we are instantiating a specialization, get the other args. */ /* If we are instantiating a specialization, get the other args. */
if (DECL_TEMPLATE_INFO (t) != NULL_TREE) if (DECL_TEMPLATE_INFO (t) != NULL_TREE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment