This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Java: Method body check and yet unsupported `final' parameters fix.
- To: egcs-patches at egcs dot cygnus dot com
- Subject: [PATCH] Java: Method body check and yet unsupported `final' parameters fix.
- From: Alexandre Petit-Bianco <apbianco at cygnus dot com>
- Date: Sat, 22 May 1999 14:43:55 -0700
I just checked in a patch to report errors when methods are illegally
declared with our without a body. An other fix prevents jc1 from
looping endlessly when several unsupported `final' parameters are
found for a method declaration.
./A
Sat May 22 13:54:41 1999 Alexandre Petit-Bianco <apbianco@cygnus.com>
* parse.y (formal_parameter:): Construct argument tree list
element even if a yet unsupported final parameter was encountered.
Tue May 18 00:28:58 1999 Alexandre Petit-Bianco <apbianco@cygnus.com>
* parse.y (finish_method_declaration): Issue errors for native or
abstract methods declared with a method body, as well as for non
native or non abstract methods with no method body.
Index: parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/java/parse.y,v
retrieving revision 1.86
diff -u -p -r1.86 parse.y
--- parse.y 1999/05/19 11:30:19 1.86
+++ parse.y 1999/05/22 21:36:48
@@ -917,7 +917,10 @@ formal_parameter:
$$ = build_tree_list ($2, $1);
}
| modifiers type variable_declarator_id /* Added, JDK1.1 final parms */
- { $$ = parse_jdk1_1_error ("final parameters"); }
+ {
+ parse_jdk1_1_error ("final parameters");
+ $$ = build_tree_list ($3, $2);
+ }
| type error
{yyerror ("Missing identifier"); RECOVER;}
| modifiers type error
@@ -3516,6 +3519,29 @@ static void
finish_method_declaration (method_body)
tree method_body;
{
+ int flags = get_access_flags_from_decl (current_function_decl);
+
+ /* 8.4.5 Method Body */
+ if ((flags & ACC_ABSTRACT || flags & ACC_NATIVE) && method_body)
+ {
+ tree wfl = DECL_NAME (current_function_decl);
+ parse_error_context (wfl,
+ "%s method `%s' can't have a body defined",
+ (METHOD_NATIVE (current_function_decl) ?
+ "Native" : "Abstract"),
+ IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
+ method_body = NULL_TREE;
+ }
+ else if (!(flags & ACC_ABSTRACT) && !(flags & ACC_NATIVE) && !method_body)
+ {
+ tree wfl = DECL_NAME (current_function_decl);
+ parse_error_context (wfl,
+ "Non native and non abstract method `%s' must "
+ "have a body defined",
+ IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
+ method_body = NULL_TREE;
+ }
+
BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
maybe_absorb_scoping_blocks ();
/* Exit function's body */