aboutsummaryrefslogtreecommitdiff
path: root/gcc/java/parse.y
diff options
context:
space:
mode:
authorAlexandre Petit-Bianco <apbianco@cygnus.com>1998-11-19 01:54:44 +0000
committerAlexandre Petit-Bianco <apbianco@gcc.gnu.org>1998-11-18 17:54:44 -0800
commitc877974e79791c251316548175df8749ed657df9 (patch)
tree865a2a98275258f86565ef8f672d4b7845d11d54 /gcc/java/parse.y
parent423165659be7520d02a498334fab715718b4fab8 (diff)
downloadgcc-c877974e79791c251316548175df8749ed657df9.zip
gcc-c877974e79791c251316548175df8749ed657df9.tar.gz
gcc-c877974e79791c251316548175df8749ed657df9.tar.bz2
class.c (unmangle_classname): Set QUALIFIED_P when appropriate.
Wed Nov 18 23:54:53 1998 Alexandre Petit-Bianco <apbianco@cygnus.com> * class.c (unmangle_classname): Set QUALIFIED_P when appropriate. (layout_class): Cope with methods featuring WFL in decl names. * decl.c (unqualified_object_id_node): New global variable, initialized. (build_decl_no_layout): Removed. * expr.c (build_primtype_type_ref): Handle Double. (java_lang_expand_expr): Fixed indentations. * java-tree.h (CLASS_METHOD_CHECKED_P): Flag deleted. (flag_wall, flag_redundant, flag_not_overriding, flag_static_local_jdk1_1, unqualified_object_id_node): Global variable declarations. (build_decl_no_layout): Removed prototype. (java_get_real_method_name): Added prototype. (IS_UNCHECKED_EXPRESSION_P): Renamed IS_UNCHECKED_EXCEPTION_P. (java_parse_abort_on_error): Macro now just returns. * jcf-parse.c (jcf_parse_source): Check fclose returned value. Call emit_register_classes if java_report_errors returns zero. * lanc.c (flag_wall, flag_redundant, flag_not_overriding, flag_static_local_jdk1_1): New integer flags. (lang_decode_option): New flags set here. * parse.h (GET_REAL_TYPE, GET_METHOD_NAME): New macros. (OBSOLETE_MODIFIER_WARNING): Issue error message conditionally to the flag_redundant variable. (SET_TYPE_FOR_RESOLUTION): Consider Object being java.lang.Object when parsing java.lang.Object class. (BUILD_MONITOR_ENTER, BUILD_MONITOR_EXIT): Added terminal NULL_TREE to build. (resolve_qualified_expression_name): Fixed indentation. (patch_array_ref): Changed prototype. (not_initialized_as_it_should_p): Prototype removed. (java_report_errors): Added function prototype. * parse.y (formal_parameter:): Changed error message for not yet supported final parameters. (class_type_list:): Set both PURPOSE and VALUE of created TREE_LIST to be class_type. (primary_no_new_array:): Handle class literals on primitive types. (parse_warning_context): Reinstalled correct force_error and do_warning flags setups. (java_report_errors): Changed prototype. Return java_error_count value. (variable_redefinition_error): Consider treating variable type as a fake pointer. (create_interface): Warn about redundant abstract modifier if flag_redundant is set. Changed error message. (lookup_field_wrapper): Save/restore globals before/after looking up field. (duplicate_declaration_error_p): Consider treating declaration type as a fake pointer. (register_fields): Extract real type from dependency node. Check for duplicate field declaration after type adjustment. Use DECL_INITIAL to store static final initialized values. (method_header): Extract real function type from dependency node. (check_abstract_method_header): Use GET_METHOD_NAME. (obtain_incomplete_type): Layout fake pointer type. (safe_layout_class): Don't try to check for methods before layout. (java_complete_class): Don't check for correct throws clause elements inheritance here. (resolve_and_layout): Broadened name parameter meaning. (reset_method_name): Use GET_METHOD_NAME. (java_get_real_method_name): New function. (java_check_regular_methods): Don't check methods in java.lang.Object. Verify lineage of throws clause elements. Use flag_no_overriding in warning report. (check_throws_clauses): Don't check if class was from bytecode. Use IS_UNCHECKED_EXCEPTION_P macro. (java_check_methods): Don't set CLASS_METHOD_CHECKED_P flag. (declare_local_variables): Use flag_static_local_jdk1_1 to report warning on unsupported final local variables. Use build_decl instead of build_decl_no_layout. Get real local variable type from dependency node. (source_start_java_method): Get real parameter type from dependency node. Call build_decl instead of build_decl_no_layout. (java_layout_classes): Reverse tree and layout type and class as required. Mark class as loaded when done. (resolve_field_access): Fixed indentation. Restricted condition leading to static field access code generation. Set field_type decl's TREE_TYPE if QUAL_DECL_TYPE not available. (resolve_qualified_expression_name): Initialize type_found to null. Handle static field resolved during qualification. Fixed layout on non primitive field decl types. (not_accessible_p): Fixed typo in comment. (patch_method_invocation): Resolve and layout class to search from type. (lookup_method_invoke): Keep integer constant 0 as is. Resolve and layout non primitive type, if necessary. Make method node only to report errors. (find_applicable_accessible_methods_list): Consider WFL'ed method decl names. Fixed indentation. (argument_types_convertible): Resolve and layout target type if necessary. (java_complete_tree): Fixed indentation problems. Rewrote CALL_EXPR thrown exceptions check. Re-installed further processing of the assignment in certain cases. (patch_assignment): Call maybe_build_primttype_type_ref to perform inlining on class literals. (valid_builtin_assignconv_identity_widening_p): Cope with constant 0 literal. (valid_method_invocation_conversion_p): Likewise. (patch_string): Temporary disable forbidden use of `this' in explicit constructor invocations when doing string concatenation within their scope. (patch_unaryop): Added comment. Reinstalled code to disable further check on assignment operation with cast expression RHS. (patch_switch_statement): Fixed indentation. (build_try_statement): Call build_decl instead of build_decl_no_layout. (patch_synchronized_statement): Likewise. (patch_throw_statement): Use IS_UNCHECKED_EXCEPTION_P instead of IS_UNCHECKED_EXPRESSION_P. (check_thrown_exceptions_do): Changed leading comment. Resolve and layout argument exception type. (purge_unchecked_exceptions): Use IS_UNCHECKED_EXCEPTION_P instead of IS_UNCHECKED_EXPRESSION_P. Fixed problems found when compiling a mixture of .class and .java files in the same package. Some support for the compilation of libjava. From-SVN: r23704
Diffstat (limited to 'gcc/java/parse.y')
-rw-r--r--gcc/java/parse.y427
1 files changed, 267 insertions, 160 deletions
diff --git a/gcc/java/parse.y b/gcc/java/parse.y
index 7a114c2..6832228 100644
--- a/gcc/java/parse.y
+++ b/gcc/java/parse.y
@@ -701,8 +701,8 @@ formal_parameter:
{
$$ = build_tree_list ($2, $1);
}
-| modifiers type variable_declarator_id /* Added, JDK1.1 final locals */
- { $$ = parse_jdk1_1_error ("final local"); }
+| modifiers type variable_declarator_id /* Added, JDK1.1 final parms */
+ { $$ = parse_jdk1_1_error ("final parameters"); }
| type error
{yyerror ("Missing identifier"); RECOVER;}
| modifiers type error
@@ -722,9 +722,9 @@ throws:
class_type_list:
class_type
- { $$ = build_tree_list (NULL_TREE, $1); }
+ { $$ = build_tree_list ($1, $1); }
| class_type_list C_TK class_type
- { $$ = tree_cons (NULL_TREE, $3, $1); }
+ { $$ = tree_cons ($3, $3, $1); }
| class_type_list C_TK error
{yyerror ("Missing class type term"); RECOVER;}
;
@@ -1507,11 +1507,11 @@ primary_no_new_array:
'type' into its components. Missing is something for array,
which will complete the reference_type part. FIXME */
| name DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
- { $$ = parse_jdk1_1_error ("class literals"); }
+ { $$ = parse_jdk1_1_error ("named class literals"); }
| primitive_type DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
- { $$ = parse_jdk1_1_error ("class literals"); }
+ { $$ = build_class_ref ($1); }
| VOID_TK DOT_TK CLASS_TK /* Added, JDK1.1 class literals */
- { $$ = parse_jdk1_1_error ("class literals"); }
+ { $$ = build_class_ref (void_type_node); }
/* Added, JDK1.1 inner classes. Documentation is wrong
refering to a 'ClassName' (class_name) rule that doesn't
exist. Used name instead. */
@@ -2298,13 +2298,13 @@ parse_warning_context VPROTO ((tree cl, char *msg, ...))
msg = va_arg (ap, char *);
#endif
- do_warning = 1;
+ force_error = do_warning = 1;
issue_warning_error_from_context (cl, msg, ap);
- force_error = 0;
+ do_warning = force_error = 0;
va_end (ap);
}
-void
+int
java_report_errors ()
{
if (java_error_count)
@@ -2315,6 +2315,7 @@ java_report_errors ()
java_warning_count, (java_warning_count == 1 ? "" : "s"));
if (java_error_count || java_warning_count)
putc ('\n', stderr);
+ return java_error_count;
}
static char *
@@ -2365,8 +2366,8 @@ variable_redefinition_error (context, name, type, line)
char *type_name;
/* Figure a proper name for type. We might haven't resolved it */
- if (TREE_CODE (type) == TREE_LIST)
- type_name = IDENTIFIER_POINTER (TYPE_NAME (TREE_PURPOSE (type)));
+ if (TREE_CODE (type) == POINTER_TYPE && !TREE_TYPE (type))
+ type_name = IDENTIFIER_POINTER (TYPE_NAME (type));
else
type_name = lang_printable_name (type, 0);
@@ -2629,10 +2630,10 @@ create_interface (flags, id, super)
- public/abstract allowed (already done at that point)
- abstract is obsolete (comes first, it's a warning, or should be)
- Can't use twice the same (checked in the modifier rule) */
- if (flags & ACC_ABSTRACT)
+ if ((flags & ACC_ABSTRACT) && flag_redundant)
parse_warning_context
(MODIFIER_WFL (ABSTRACT_TK),
- "Obsolete use of `abstract' modifier. Interface `%s' is implicitely "
+ "Redundant use of `abstract' modifier. Interface `%s' is implicitely "
"abstract", IDENTIFIER_POINTER (raw_name));
if (flags & ACC_PUBLIC && flags & ACC_ABSTRACT)
parse_error_context
@@ -2751,7 +2752,9 @@ lookup_field_wrapper (class, name)
tree class, name;
{
tree type = class;
+ java_parser_context_save_global ();
return lookup_field (&type, name);
+ java_parser_context_restore_global ();
}
/* Find duplicate field within the same class declarations and report
@@ -2768,11 +2771,12 @@ duplicate_declaration_error_p (new_field_name, new_type, cl)
if (decl)
{
char *t1 = strdup (lang_printable_name (new_type, 1));
- char *t2 =
- strdup ((TREE_CODE (TREE_TYPE (decl)) == TREE_LIST ?
- IDENTIFIER_POINTER (TYPE_NAME
- (TREE_PURPOSE (TREE_TYPE (decl)))) :
- lang_printable_name (TREE_TYPE (decl), 1)));
+ /* The type may not have been completed by the time we report
+ the error */
+ char *t2 = strdup (((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
+ && TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
+ IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
+ lang_printable_name (TREE_TYPE (decl), 1)));
parse_error_context
(cl , "Duplicate variable declaration: `%s %s' was `%s %s' (%s:%d)",
t1, IDENTIFIER_POINTER (new_field_name),
@@ -2827,6 +2831,7 @@ register_fields (flags, type, variable_list)
for (current = variable_list, saved_type = type; current;
current = TREE_CHAIN (current), type = saved_type)
{
+ tree real_type;
tree field_decl;
tree cl = TREE_PURPOSE (current);
tree init = TREE_VALUE (current);
@@ -2835,10 +2840,6 @@ register_fields (flags, type, variable_list)
/* Process NAME, as it may specify extra dimension(s) for it */
type = build_array_from_name (type, wfl, current_name, &current_name);
- /* Check for redeclarations */
- if (duplicate_declaration_error_p (current_name, type, cl))
- continue;
-
/* Type adjustment. We may have just readjusted TYPE because
the variable specified more dimensions. Make sure we have
a reference if we can and don't have one already. Also
@@ -2851,10 +2852,15 @@ register_fields (flags, type, variable_list)
EXPR_WFL_NODE (TREE_OPERAND (init, 0)) = current_name;
}
+ real_type = GET_REAL_TYPE (type);
+ /* Check for redeclarations */
+ if (duplicate_declaration_error_p (current_name, real_type, cl))
+ continue;
+
/* Set lineno to the line the field was found and create a
declaration for it. Eventually sets the @deprecated tag flag. */
lineno = EXPR_WFL_LINENO (cl);
- field_decl = add_field (class_type, current_name, type, flags);
+ field_decl = add_field (class_type, current_name, real_type, flags);
CHECK_DEPRECATED (field_decl);
/* Check if we must chain. */
@@ -2879,6 +2885,8 @@ register_fields (flags, type, variable_list)
permalloc (sizeof (struct lang_decl_var));
DECL_LOCAL_STATIC_VALUE (field_decl) =
TREE_OPERAND (init, 1);
+ if (TREE_CONSTANT (TREE_OPERAND (init, 1)))
+ DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
}
/* Otherwise, the field should be initialized in <clinit>.
This field is remembered so we can generate <clinit> later */
@@ -3073,9 +3081,11 @@ method_header (flags, type, mdecl, throws)
TREE_TYPE (meth) = returned_type;
else
{
+ tree itype;
patch_stage = JDEP_METHOD_RETURN;
- TREE_TYPE (meth) =
- register_incomplete_type (patch_stage, type, id, NULL_TREE);
+ itype = register_incomplete_type (patch_stage, type, id, NULL_TREE);
+ TREE_TYPE (meth) = (TREE_CODE (itype) == TREE_LIST ?
+ TREE_PURPOSE (itype) : itype);
}
}
else
@@ -3277,8 +3287,7 @@ check_abstract_method_header (meth)
{
int flags = get_access_flags_from_decl (meth);
/* DECL_NAME might still be a WFL node */
- tree name = (TREE_CODE (DECL_NAME (meth)) == EXPR_WITH_FILE_LOCATION ?
- EXPR_WFL_NODE (DECL_NAME (meth)) : DECL_NAME (meth));
+ tree name = GET_METHOD_NAME (meth);
OBSOLETE_MODIFIER_WARNING (MODIFIER_WFL (ABSTRACT_TK), flags,
ACC_ABSTRACT, "abstract method `%s'",
@@ -3509,6 +3518,7 @@ obtain_incomplete_type (wfl)
tree core;
push_obstacks (&permanent_obstack, &permanent_obstack);
BUILD_PTR_FROM_NAME (core, name);
+ layout_type (core);
ptr = build_tree_list (core, NULL_TREE);
pop_obstacks ();
TREE_CHAIN (ptr) = ctxp->incomplete_class;
@@ -3590,10 +3600,6 @@ safe_layout_class (class)
push_obstacks (&permanent_obstack, &permanent_obstack);
- if (!CLASS_METHOD_CHECKED_P (class))
- CHECK_METHODS (TYPE_NAME (class));
- CLASS_METHOD_CHECKED_P (class) = 1;
-
layout_class (class);
pop_obstacks ();
@@ -3646,7 +3652,7 @@ java_complete_class ()
/* Rever things so we have the right order */
ctxp->class_list = nreverse (ctxp->class_list);
ctxp->classd_list = reverse_jdep_list (ctxp);
-
+
for (cclassd = ctxp->classd_list, cclass = ctxp->class_list;
cclass && cclassd;
cclass = TREE_CHAIN (cclass), cclassd = CLASSD_CHAIN (cclassd))
@@ -3655,7 +3661,6 @@ java_complete_class ()
for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
{
tree decl;
-
if (!(decl = jdep_resolve_class (dep)))
continue;
@@ -3751,21 +3756,10 @@ java_complete_class ()
break;
case JDEP_EXCEPTION:
- /* Check for righteous inheritance here */
- if (!inherits_from_p (TREE_TYPE (decl), throwable_type_node))
- {
- parse_error_context
- (JDEP_WFL (dep), "Class `%s' in `throws' clause must be "
- "a subclass of class `java.lang.Throwable'",
- IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))));
- }
- else
- {
- JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
- SOURCE_FRONTEND_DEBUG
- (("Completing `%s' `throws' argument node",
- IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
- }
+ JDEP_APPLY_PATCH (dep, TREE_TYPE (decl));
+ SOURCE_FRONTEND_DEBUG
+ (("Completing `%s' `throws' argument node",
+ IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)))));
break;
default:
@@ -3890,11 +3884,23 @@ do_resolve_class (class_type, decl, cl)
parsed class). Return a decl node. */
static tree
-resolve_and_layout (name, cl)
- tree name;
+resolve_and_layout (something, cl)
+ tree something;
tree cl;
{
- tree decl = resolve_no_layout (name, cl);
+ tree decl;
+
+ if (TREE_CODE (something) == POINTER_TYPE)
+ something = TREE_TYPE (something);
+
+ if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
+ return NULL_TREE;
+
+ if (TREE_CODE (something) != IDENTIFIER_NODE)
+ something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
+ DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
+
+ decl = resolve_no_layout (something, cl);
if (decl && TREE_TYPE (decl) != current_class
&& !CLASS_LOADED_P (TREE_TYPE (decl)))
safe_layout_class (TREE_TYPE (decl));
@@ -4034,16 +4040,30 @@ reset_method_name (method)
{
/* NAME is just the plain name when Object is being defined */
if (DECL_CONTEXT (method) != object_type_node)
- DECL_NAME (method) =
- (DECL_CONSTRUCTOR_P (method) ? init_identifier_node :
- (TREE_CODE (DECL_NAME (method)) == EXPR_WITH_FILE_LOCATION ?
- EXPR_WFL_NODE (DECL_NAME (method)) : DECL_NAME (method)));
+ DECL_NAME (method) = (DECL_CONSTRUCTOR_P (method) ?
+ init_identifier_node : GET_METHOD_NAME (method));
return 0;
}
else
return 1;
}
+/* Return the name of METHOD_DECL, when DECL_NAME is a WFL */
+
+tree
+java_get_real_method_name (method_decl)
+ tree method_decl;
+{
+ tree method_name = DECL_NAME (method_decl);
+ if (DECL_CONSTRUCTOR_P (method_decl))
+ return init_identifier_node;
+ else if (ctxp
+ && ctxp->current_parsed_class_un == EXPR_WFL_NODE (method_name))
+ return init_identifier_node;
+ else
+ return EXPR_WFL_NODE (method_name);
+}
+
/* Track method being redefined inside the same class. As a side
effect, set DECL_NAME to an IDENTIFIER (prior entering this
function it's a FWL, so we can track errors more accurately */
@@ -4097,6 +4117,11 @@ java_check_regular_methods (class_decl)
tree class = CLASS_TO_HANDLE_TYPE (TREE_TYPE (class_decl));
tree super_class = CLASSTYPE_SUPER (class);
tree saved_found_wfl = NULL_TREE, found = NULL_TREE;
+ tree mthrows;
+
+ /* It is not necessary to check methods defined in java.lang.Object */
+ if (class == object_type_node)
+ return;
TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
@@ -4125,6 +4150,19 @@ java_check_regular_methods (class_decl)
continue;
}
+ /* We verify things thrown by the method. They must inherits from
+ java.lang.Throwable */
+ for (mthrows = DECL_FUNCTION_THROWS (method);
+ mthrows; mthrows = TREE_CHAIN (mthrows))
+ {
+ if (!inherits_from_p (TREE_VALUE (mthrows), throwable_type_node))
+ parse_error_context
+ (TREE_PURPOSE (mthrows), "Class `%s' in `throws' clause must be "
+ "a subclass of class `java.lang.Throwable'",
+ IDENTIFIER_POINTER
+ (DECL_NAME (TYPE_NAME (TREE_VALUE (mthrows)))));
+ }
+
sig = build_java_argument_signature (TREE_TYPE (method));
found = lookup_argument_method (super_class, DECL_NAME (method), sig);
@@ -4208,14 +4246,14 @@ java_check_regular_methods (class_decl)
exceptions, if any */
check_throws_clauses (method, method_wfl, found);
-#if 0
/* If the method has default access in an other package, then
issue a warning that the current method doesn't override the
one that was found elsewhere. Do not issue this warning when
the match was found in java.lang.Object. */
if (DECL_CONTEXT (found) != object_type_node
&& (!aflags || (aflags > ACC_PROTECTED))
- && !class_in_current_package (DECL_CONTEXT (found)))
+ && !class_in_current_package (DECL_CONTEXT (found))
+ && flag_not_overriding)
parse_warning_context
(method_wfl, "Method `%s' in class `%s' does not "
"override the corresponding method in class `%s', which is "
@@ -4223,7 +4261,6 @@ java_check_regular_methods (class_decl)
lang_printable_name (found, 0),
IDENTIFIER_POINTER (DECL_NAME (class_decl)),
IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
-#endif
/* Inheriting multiple methods with the same signature. FIXME */
}
@@ -4263,11 +4300,15 @@ check_throws_clauses (method, method_wfl, found)
{
tree mthrows, fthrows;
+ /* Can't check these things with class loaded from bytecode. FIXME */
+ if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (found)))
+ return;
+
for (mthrows = DECL_FUNCTION_THROWS (method);
mthrows; mthrows = TREE_CHAIN (mthrows))
{
/* We don't verify unchecked expressions */
- if (IS_UNCHECKED_EXPRESSION_P (TREE_VALUE (mthrows)))
+ if (IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (mthrows)))
continue;
/* Checked expression must be compatible */
for (fthrows = DECL_FUNCTION_THROWS (found);
@@ -4376,10 +4417,7 @@ java_check_methods ()
tree current;
for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
if (CLASS_FROM_SOURCE_P (TREE_TYPE (TREE_VALUE (current))))
- {
- CHECK_METHODS (TREE_VALUE (current));
- CLASS_METHOD_CHECKED_P (TREE_TYPE (TREE_VALUE (current))) = 1;
- }
+ CHECK_METHODS (TREE_VALUE (current));
}
/* Lookup methods in interfaces using their name and partial
@@ -4850,12 +4888,20 @@ declare_local_variables (modifier, type, vlist)
{
int i;
for (i = 0; i <= 10; i++) if (1 << i & modifier) break;
- parse_error_context
- (ctxp->modifier_ctx [i],
- (modifier == ACC_FINAL ?
- "Unsupported JDK1.1 `final' locals" :
- "Only `final' is allowed as a local variables modifier"));
- return;
+ if (modifier == ACC_FINAL)
+ {
+ if (flag_static_local_jdk1_1)
+ parse_warning_context (ctxp->modifier_ctx [i],
+ "Unsupported JDK1.1 `final' local variable "
+ "(treated as non final)");
+ }
+ else
+ {
+ parse_error_context
+ (ctxp->modifier_ctx [i],
+ "Only `final' is allowed as a local variables modifier");
+ return;
+ }
}
/* Obtain an incomplete type if TYPE is not complete. TYPE_WFL will
@@ -4871,7 +4917,7 @@ declare_local_variables (modifier, type, vlist)
for (current = vlist, saved_type = type; current;
current = TREE_CHAIN (current), type = saved_type)
{
- tree other;
+ tree other, real_type;
tree wfl = TREE_PURPOSE (current);
tree name = EXPR_WFL_NODE (wfl);
tree init = TREE_VALUE (current);
@@ -4893,10 +4939,11 @@ declare_local_variables (modifier, type, vlist)
if (type != saved_type && !must_chain
&& (TREE_CODE (type) == RECORD_TYPE))
type = promote_type (type);
-
+
+ real_type = GET_REAL_TYPE (type);
/* Never layout this decl. This will be done when its scope
will be entered */
- decl = build_decl_no_layout (VAR_DECL, name, type);
+ decl = build_decl (VAR_DECL, name, real_type);
BLOCK_CHAIN_DECL (decl);
/* Don't try to use an INIT statement when an error was found */
@@ -4952,8 +4999,8 @@ source_start_java_method (fndecl)
if (INCOMPLETE_TYPE_P (type))
{
jdep *jdep;
- parm_decl = build_decl_no_layout (PARM_DECL, name, type);
-
+ tree real_type = GET_REAL_TYPE (type);
+ parm_decl = build_decl (PARM_DECL, name, real_type);
register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
jdep = CLASSD_LAST (ctxp->classd_list);
JDEP_MISC (jdep) = name;
@@ -5148,17 +5195,39 @@ java_layout_classes ()
{
current_class = TREE_TYPE (TREE_VALUE (current));
- /* Reverse the fields if it's necessary (they've already
- reversed if the dummy field has been inserted at the
- beginning of the list */
- if (TYPE_FIELDS (current_class)
- && !DECL_IGNORED_P (TYPE_FIELDS (current_class)))
- TYPE_FIELDS (current_class) = nreverse (TYPE_FIELDS (current_class));
+ /* Reverse the fields, but leave the dummy field in front.
+ Fields are already ordered for Object and Class */
+ if (TYPE_FIELDS (current_class) && current_class != object_type_node
+ && current_class != class_type_node)
+ {
+ /* Always leave the dummy field in front if its already there,
+ and layout the class for proper field offets. */
+ if (!DECL_NAME (TYPE_FIELDS (current_class)))
+ {
+ tree fields = TYPE_FIELDS (current_class);
+ TREE_CHAIN (fields) = nreverse (TREE_CHAIN (fields));
+ TYPE_SIZE (current_class) = NULL_TREE;
+ layout_type (current_class);
+ }
+ /* It's time to layout the class */
+ else
+ {
+ TYPE_FIELDS (current_class) =
+ nreverse (TYPE_FIELDS (current_class));
+ TYPE_SIZE (current_class) = NULL_TREE;
+ layout_class (current_class);
+ }
+ }
/* Do a layout if necessary */
- if (!TYPE_SIZE (current_class) || (current_class == object_type_node))
+ if (!TYPE_SIZE (current_class)
+ || (current_class == object_type_node)
+ || current_class == class_type_node)
safe_layout_class (current_class);
+ /* From now on, the class is considered completely loaded */
+ CLASS_LOADED_P (current_class) = 1;
+
/* Error reported by the caller */
if (java_error_count)
return;
@@ -5694,15 +5763,15 @@ resolve_field_access (qual_wfl, field_decl, field_type)
type_found, DECL_NAME (decl));
if (field_ref == error_mark_node)
return error_mark_node;
- if (is_static && !static_final_found
- && ! flag_emit_class_files)
+ if (is_static && !static_final_found && !flag_emit_class_files)
{
field_ref = build_class_init (type_found, field_ref);
/* If the static field was identified by an expression that
needs to be generated, make the field access a compound
expression whose first part of the evaluation of the
field selector part. */
- if (where_found && TREE_CODE (where_found) != TYPE_DECL)
+ if (where_found && TREE_CODE (where_found) != TYPE_DECL
+ && TREE_CODE (where_found) != RECORD_TYPE)
{
tree type = QUAL_DECL_TYPE (field_ref);
field_ref = build (COMPOUND_EXPR, type, where_found, field_ref);
@@ -5715,7 +5784,8 @@ resolve_field_access (qual_wfl, field_decl, field_type)
if (field_decl)
*field_decl = decl;
if (field_type)
- *field_type = QUAL_DECL_TYPE (decl);
+ *field_type = (QUAL_DECL_TYPE (decl) ?
+ QUAL_DECL_TYPE (decl) : TREE_TYPE (decl));
return field_ref;
}
@@ -5731,7 +5801,7 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
int previous_call_static = 0;
int is_static;
tree decl = NULL_TREE, type = NULL_TREE, q;
- *where_found = NULL_TREE;
+ *type_found = *where_found = NULL_TREE;
for (q = EXPR_WFL_QUALIFICATION (wfl); q; q = TREE_CHAIN (q))
{
@@ -5922,10 +5992,16 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
if (!from_super && QUAL_RESOLUTION (q))
{
decl = QUAL_RESOLUTION (q);
- if (!type && !FIELD_STATIC (decl))
+ if (!type)
{
- *where_found = current_this;
- *type_found = type;
+ if (!FIELD_STATIC (decl))
+ *where_found = current_this;
+ else
+ {
+ *where_found = TREE_TYPE (decl);
+ if (TREE_CODE (*where_found) == POINTER_TYPE)
+ *where_found = TREE_TYPE (*where_found);
+ }
}
}
@@ -5961,15 +6037,19 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
}
/* Layout the type of field_decl, since we may need
- it. Don't do primitive types or loaded classes */
+ it. Don't do primitive types or loaded classes. The
+ situation of non primitive arrays may not handled
+ properly here. FIXME */
if (TREE_CODE (TREE_TYPE (field_decl)) == POINTER_TYPE)
field_decl_type = TREE_TYPE (TREE_TYPE (field_decl));
else
field_decl_type = TREE_TYPE (field_decl);
if (!JPRIMITIVE_TYPE_P (field_decl_type)
- && !CLASS_LOADED_P (field_decl_type))
- resolve_and_layout (DECL_NAME (TYPE_NAME (field_decl_type)),
- NULL_TREE);
+ && !CLASS_LOADED_P (field_decl_type)
+ && !TYPE_ARRAY_P (field_decl_type))
+ resolve_and_layout (field_decl_type, NULL_TREE);
+ if (TYPE_ARRAY_P (field_decl_type))
+ CLASS_LOADED_P (field_decl_type) = 1;
/* Check on accessibility here */
if (not_accessible_p (type, field_decl, from_super))
@@ -6065,8 +6145,7 @@ int not_accessible_p (reference, member, from_super)
}
/* Check access on private members. Access is granted only if it
- occurs from within the class in witch it is declared*/
-
+ occurs from within the class in witch it is declared */
if (access_flag & ACC_PRIVATE)
return (current_class == DECL_CONTEXT (member) ? 0 : 1);
@@ -6265,9 +6344,9 @@ patch_method_invocation (patch, primary, where, is_static, ret_decl, super)
/* 2- Do the layout of the class where the last field
was found, so we can search it. */
- class_decl =
- resolve_and_layout (DECL_NAME (TYPE_NAME (type)), NULL_TREE);
-
+ class_decl = resolve_and_layout (type, NULL_TREE);
+ type = TREE_TYPE (class_decl);
+
/* 3- Retrieve a filtered list of method matches, Refine
if necessary. In any cases, point out errors. */
list = lookup_method_invoke (0, identifier_wfl, type,
@@ -6349,6 +6428,7 @@ patch_method_invocation (patch, primary, where, is_static, ret_decl, super)
/* NAME is a simple identifier or comes from a primary. Search
in the class whose declaration contain the method being
invoked. */
+ resolve_and_layout (class_to_search, NULL_TREE);
list = lookup_method_invoke (lc, wfl, class_to_search, name, args);
/* Don't continue if no method were found, as the next statement
@@ -6563,20 +6643,26 @@ lookup_method_invoke (lc, cl, class, name, arg_list)
tree cl;
tree class, name, arg_list;
{
- tree method = make_node (FUNCTION_TYPE);
tree atl = NULL_TREE; /* Arg Type List */
- tree signature, list, node;
+ tree method, signature, list, node;
char *candidates; /* Used for error report */
/* Fix the arguments */
for (node = arg_list; node; node = TREE_CHAIN (node))
{
- tree current_arg = TREE_TYPE (TREE_VALUE (node));
+ tree current_arg = TREE_VALUE (node);
+ /* Integer constant 0 passed as itself, not as a type */
+ if (current_arg != integer_zero_node)
+ current_arg = TREE_TYPE (TREE_VALUE (node));
+ /* Non primitive type may have to be resolved */
+ if (current_arg != integer_zero_node
+ && !JPRIMITIVE_TYPE_P (current_arg))
+ resolve_and_layout (current_arg, NULL_TREE);
+ /* And promoted */
if (TREE_CODE (current_arg) == RECORD_TYPE)
- current_arg = promote_type (current_arg);
+ current_arg = promote_type (current_arg);
atl = tree_cons (NULL_TREE, current_arg, atl);
}
- TYPE_ARG_TYPES (method) = atl;
/* Find all candidates and then refine the list, searching for the
most specific method. */
@@ -6610,6 +6696,11 @@ lookup_method_invoke (lc, cl, class, name, arg_list)
candidates = obstack_finish (&temporary_obstack);
}
/* Issue the error message */
+ for (node = atl; node; node = TREE_CHAIN (node))
+ if (TREE_VALUE (node) == integer_zero_node)
+ TREE_VALUE (node) = long_type_node;
+ method = make_node (FUNCTION_TYPE);
+ TYPE_ARG_TYPES (method) = atl;
signature = build_java_argument_signature (method);
parse_error_context (cl, "Can't find %s `%s(%s)' in class `%s'%s",
(lc ? "constructor" : "method"),
@@ -6641,13 +6732,14 @@ find_applicable_accessible_methods_list (lc, class, name, arglist)
if (lc && !DECL_CONSTRUCTOR_P (method))
continue;
else if (!lc && (DECL_CONSTRUCTOR_P (method)
- || DECL_NAME (method) != name))
+ || (GET_METHOD_NAME (method) != name)))
continue;
if (argument_types_convertible (method, arglist))
{
/* Retain accessible methods only */
- if (!not_accessible_p (DECL_CONTEXT (current_function_decl), method, 0))
+ if (!not_accessible_p (DECL_CONTEXT (current_function_decl),
+ method, 0))
list = tree_cons (NULL_TREE, method, list);
else
/* Also retain all selected method here */
@@ -6754,6 +6846,7 @@ argument_types_convertible (m1, m2_or_arglist)
while (m1_arg && m2_arg)
{
+ resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
TREE_VALUE (m2_arg)))
break;
@@ -6988,7 +7081,8 @@ java_complete_tree (node)
int error_seen = 0;
if (TREE_CODE (stmt) == COMPOUND_EXPR)
{
- /* Re-order from (((A; B); C); ...; Z) to (A; (B; (C ; (...; Z)))).
+ /* Re-order from (((A; B); C); ...; Z) to
+ (A; (B; (C ; (...; Z)))).
This makes it easier to scan the statements left-to-right
without using recursion (which might overflow the stack
if the block has many statements. */
@@ -7004,7 +7098,8 @@ java_complete_tree (node)
BLOCK_EXPR_BODY (node) = stmt;
}
- /* Now do the actual complete, without deep recursion for long blocks. */
+ /* Now do the actual complete, without deep recursion for
+ long blocks. */
ptr = &BLOCK_EXPR_BODY (node);
while (TREE_CODE (*ptr) == COMPOUND_EXPR)
{
@@ -7029,7 +7124,8 @@ java_complete_tree (node)
&& TREE_CODE (wfl_op2) != DEFAULT_EXPR)
{
SET_WFL_OPERATOR (wfl_operator, *ptr, wfl_op2);
- parse_error_context (wfl_operator, "Unreachable statement");
+ parse_error_context (wfl_operator,
+ "Unreachable statement");
}
}
ptr = next;
@@ -7097,7 +7193,8 @@ java_complete_tree (node)
nn = ctxp->current_loop;
/* It must be assignable to the type of the switch expression. */
- if (!try_builtin_assignconv (NULL_TREE, TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
+ if (!try_builtin_assignconv (NULL_TREE,
+ TREE_TYPE (TREE_OPERAND (nn, 0)), cn))
{
EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
parse_error_context
@@ -7276,18 +7373,17 @@ java_complete_tree (node)
tree decl, wfl = TREE_OPERAND (node, 0);
int in_this = CALL_THIS_CONSTRUCTOR_P (node);
- node = patch_method_invocation (node, NULL_TREE,
+ node = patch_method_invocation (node, NULL_TREE,
NULL_TREE, 0, &decl, 0);
- if (node != error_mark_node)
- {
- check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl);
- /* If we call this(...), register signature and positions */
- if (in_this)
- DECL_CONSTRUCTOR_CALLS (current_function_decl) =
- tree_cons (wfl, decl,
- DECL_CONSTRUCTOR_CALLS (current_function_decl));
-
- }
+ if (node == error_mark_node)
+ return error_mark_node;
+
+ check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl);
+ /* If we call this(...), register signature and positions */
+ if (in_this)
+ DECL_CONSTRUCTOR_CALLS (current_function_decl) =
+ tree_cons (wfl, decl,
+ DECL_CONSTRUCTOR_CALLS (current_function_decl));
return node;
}
@@ -7317,6 +7413,13 @@ java_complete_tree (node)
nn = java_complete_tree (TREE_OPERAND (node, 1));
if (nn == error_mark_node)
{
+ /* It's hopeless, but we can further things on to discover
+ an error during the assignment. In any cases, the
+ assignment operation fails. */
+ if (TREE_CODE (TREE_OPERAND (node, 1)) != EXPR_WITH_FILE_LOCATION
+ && TREE_TYPE (TREE_OPERAND (node, 1)) != error_mark_node)
+ patch_assignment (node, wfl_op1, wfl_op2);
+
/* Now, we still mark the lhs as initialized */
if (DECL_P (TREE_OPERAND (node, 0)))
INITIALIZED_P (TREE_OPERAND (node, 0)) = 1;
@@ -7413,7 +7516,7 @@ java_complete_tree (node)
return error_mark_node;
if (!flag_emit_class_files)
TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
- return patch_array_ref (node, wfl_op1, wfl_op2);
+ return patch_array_ref (node);
#if 0
COMPONENT_REF:
@@ -7873,18 +7976,9 @@ patch_assignment (node, wfl_op1, wfl_op2)
/* Inline read access to java.lang.PRIMTYPE.TYPE */
rhs = maybe_build_primttype_type_ref (rhs, wfl_op2);
- if (TREE_CODE (rhs) == COMPOUND_EXPR)
- {
- tree n = TREE_OPERAND (rhs, 1);
- if (TREE_CODE (n) == VAR_DECL
- && DECL_NAME (n) == TYPE_identifier_node
- && rhs_type == class_ptr_type)
- {
- char *self_name = IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl_op2));
- if (!strncmp (self_name, "java.lang.", 10))
- rhs = build_primtype_type_ref (self_name);
- }
- }
+ /* Inline read access to java.lang.PRIMTYPE.TYPE */
+ if (new_rhs)
+ new_rhs = maybe_build_primttype_type_ref (new_rhs, wfl_op2);
if (error_found)
return error_mark_node;
@@ -7987,6 +8081,11 @@ valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type)
if (lhs_type == rhs_type)
return 1;
+ /* Sometimes, instead of passing a type, we pass integer_zero_node
+ so we know that an integral type can accomodate it */
+ if (JINTEGRAL_TYPE_P (lhs_type) && (rhs_type == integer_zero_node))
+ return 1;
+
all_primitive =
JPRIMITIVE_TYPE_P (lhs_type) && JPRIMITIVE_TYPE_P (rhs_type);
@@ -8167,7 +8266,7 @@ static int
valid_method_invocation_conversion_p (dest, source)
tree dest, source;
{
- return ((JPRIMITIVE_TYPE_P (source)
+ return (((JPRIMITIVE_TYPE_P (source) || (source == integer_zero_node))
&& JPRIMITIVE_TYPE_P (dest)
&& valid_builtin_assignconv_identity_widening_p (dest, source))
|| ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
@@ -8268,14 +8367,6 @@ patch_binop (node, wfl_op1, wfl_op2)
after checking for the initialization of the RHS */
int error_found = 0;
- /* Figure what is going to be checked first for initialization prior
- its use. If NODE is part of a compound assignment, we check the
- second operand first, otherwise the first one first. We also
- initialize the matching WFL for the error report. `cfi' stands
- for Check For Initialization */
- tree cfi = (COMPOUND_ASSIGN_P (node) ? op2 : op1);
- tree cfi_wfl = (COMPOUND_ASSIGN_P (node) ? wfl_op2 : wfl_op1);
-
EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
switch (code)
@@ -8730,8 +8821,15 @@ patch_string (node)
return patch_string_cst (node);
else if (IS_CRAFTED_STRING_BUFFER_P (node))
{
+ int saved = ctxp->explicit_constructor_p;
tree invoke = build_method_invocation (wfl_to_string, NULL_TREE);
- return java_complete_tree (make_qualified_primary (node, invoke, 0));
+ tree ret;
+ /* Temporary disable forbid the use of `this'. */
+ ctxp->explicit_constructor_p = 0;
+ ret = java_complete_tree (make_qualified_primary (node, invoke, 0));
+ /* Restore it at its previous value */
+ ctxp->explicit_constructor_p = saved;
+ return ret;
}
return NULL_TREE;
}
@@ -8929,6 +9027,8 @@ patch_unaryop (node, wfl_op)
if (TREE_CODE (op_type) != BOOLEAN_TYPE)
{
ERROR_CANT_CONVERT_TO_BOOLEAN (wfl_operator, node, op_type);
+ /* But the type is known. We will report an error if further
+ attempt of a assignment is made with this rhs */
TREE_TYPE (node) = boolean_type_node;
error_found = 1;
}
@@ -8940,8 +9040,15 @@ patch_unaryop (node, wfl_op)
case CONVERT_EXPR:
value = patch_cast (node, wfl_operator);
if (value == error_mark_node)
- return value;
- node = value;
+ {
+ /* If this cast is part of an assignment, we tell the code
+ that deals with it not to complain about a mismatch,
+ because things have been cast, anyways */
+ TREE_TYPE (node) = error_mark_node;
+ error_found = 1;
+ }
+ else
+ node = value;
break;
}
@@ -9081,8 +9188,8 @@ build_array_ref (location, array, index)
/* 15.12 Array Access Expression */
static tree
-patch_array_ref (node, wfl_array, wfl_index)
- tree node, wfl_array, wfl_index;
+patch_array_ref (node)
+ tree node;
{
tree array = TREE_OPERAND (node, 0);
tree array_type = TREE_TYPE (array);
@@ -9793,7 +9900,7 @@ static tree
patch_switch_statement (node)
tree node;
{
- tree se = TREE_OPERAND (node, 0), se_type, sb;
+ tree se = TREE_OPERAND (node, 0), se_type;
/* Complete the switch expression */
se = TREE_OPERAND (node, 0) = java_complete_tree (se);
@@ -9822,7 +9929,8 @@ patch_switch_statement (node)
TREE_TYPE (node) = void_type_node;
TREE_SIDE_EFFECTS (node) = 1;
CAN_COMPLETE_NORMALLY (node)
- = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)) || ! SWITCH_HAS_DEFAULT (node);
+ = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
+ || ! SWITCH_HAS_DEFAULT (node);
return node;
}
@@ -9870,8 +9978,7 @@ build_try_statement (location, try_block, catches, finally)
sequence. It hold a local variable used to return from the
finally using a computed goto. We call it
return_from_finally (RFF). */
- rff = build_decl_no_layout (VAR_DECL, generate_name (),
- return_address_type_node);
+ rff = build_decl (VAR_DECL, generate_name (), return_address_type_node);
/* Modification of the try block. */
try_block = build_jump_to_finally (try_block, rff,
@@ -9906,8 +10013,7 @@ build_try_statement (location, try_block, catches, finally)
CALL_EXPR
Jv_ReThrow
exception_parameter */
- catch_decl = build_decl_no_layout (VAR_DECL, generate_name (),
- ptr_type_node);
+ catch_decl = build_decl (VAR_DECL, generate_name (), ptr_type_node);
BUILD_ASSIGN_EXCEPTION_INFO (stmt, catch_decl);
catch_block = build_expr_block (stmt, NULL_TREE);
catch_block = build_jump_to_finally (catch_block, rff,
@@ -10039,7 +10145,6 @@ patch_try_statement (node)
break;
}
}
-
/* Complete the catch clause block */
catch_block = java_complete_tree (TREE_OPERAND (current, 0));
if (catch_block == error_mark_node)
@@ -10058,7 +10163,6 @@ patch_try_statement (node)
/* Link this type to the caught type list */
caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
-
}
PUSH_EXCEPTIONS (caught_type_list);
@@ -10136,7 +10240,7 @@ patch_synchronized_statement (node, wfl_op1)
try_block = build_expr_block (compound, NULL_TREE);
/* CATCH_ALL block */
- decl = build_decl_no_layout (VAR_DECL, generate_name (), ptr_type_node);
+ decl = build_decl (VAR_DECL, generate_name (), ptr_type_node);
BUILD_ASSIGN_EXCEPTION_INFO (stmt, decl);
compound = add_stmt_to_compound (NULL_TREE, void_type_node, stmt);
BUILD_MONITOR_EXIT (stmt, expr);
@@ -10178,7 +10282,7 @@ patch_throw_statement (node, wfl_op1)
/* The type of the throw expression is a not checked exception,
i.e. is a unchecked expression. */
- unchecked_ok = IS_UNCHECKED_EXPRESSION_P (TREE_TYPE (type));
+ unchecked_ok = IS_UNCHECKED_EXCEPTION_P (TREE_TYPE (type));
/* Throw is contained in a try statement and at least one catch
clause can receive the thrown expression or the current method is
@@ -10251,7 +10355,7 @@ check_thrown_exceptions (location, decl)
}
}
-/* Return 1 if EXCEPTION is caught at the current nesting level of
+/* Return 1 if checked EXCEPTION is caught at the current nesting level of
try-catch blocks, OR is listed in the `throws' clause of the
current method. */
@@ -10260,8 +10364,11 @@ check_thrown_exceptions_do (exception)
tree exception;
{
tree list = currently_caught_type_list;
+ resolve_and_layout (exception, NULL_TREE);
/* First, all the nested try-catch-finally at that stage. The
last element contains `throws' clause exceptions, if any. */
+ if (IS_UNCHECKED_EXCEPTION_P (exception))
+ return 1;
while (list)
{
tree caught;
@@ -10283,7 +10390,7 @@ purge_unchecked_exceptions (mdecl)
while (throws)
{
tree next = TREE_CHAIN (throws);
- if (!IS_UNCHECKED_EXPRESSION_P (TREE_VALUE (throws)))
+ if (!IS_UNCHECKED_EXCEPTION_P (TREE_VALUE (throws)))
{
TREE_CHAIN (throws) = new;
new = throws;