Commit b9f7e36c by Alexandre Petit-Bianco Committed by Alexandre Petit-Bianco

decl.c (runtime_exception_type_node, [...]): New global variables.

Tue Oct 13 03:50:28 1998  Alexandre Petit-Bianco  <apbianco@cygnus.com>
	* decl.c (runtime_exception_type_node, error_exception_type_node):
 	New global variables.
	(init_decl_processing): Initialized.
	* expr.c (java_lang_expand_expr): Set caught exception type to
 	null if catch handler argument doesn't exit.
	* java-tree.def (SYNCHRONIZED_EXPR, THROW_EXPR): New Java specific
 	tree codes.
	* java-tree.h (runtime_exception_type_node,
 	error_exception_type_node): Global variables declared.
	(DECL_FUNCTION_THROWS): New macro.
	(DECL_FUNCTION_BODY): Modified comment.
	(DECL_SPECIFIC_COUNT): Likewise.
	(struct lang_decl): New field throws_list.
	(IS_UNCHECKED_EXPRESSION_P): New macro.
	* lex.c (java_lex): Generate location information for THROW_TK.
	* parse.h (PUSH_EXCEPTIONS, POP_EXCEPTIONS, IN_TRY_BLOCK_P,
 	EXCEPTIONS_P): New macros.
	(enum jdep_code): New value JDEP_EXCEPTION.
	(BUILD_MONITOR_ENTER, BUILD_MONITOR_EXIT,
 	BUILD_ASSIGN_EXCEPTION_INFO, BUILD_THROW, SET_WFL_OPERATOR,
 	PATCH_METHOD_RETURN_ERROR): New macros.
	(patch_method_invocation_stmt): Added new argument to prototype.
	(patch_synchronized_statement, patch_throw_statement,
 	check_thrown_exceptions, check_thrown_exceptions_do,
 	purge_unchecked_exceptions, check_throws_clauses): New function
 	prototypes.
	* parse.y Fixed typo in keyword section.
	(throw:): Rule tagged <node>.
	(THROW_TK): Keyword tagged <operator>.
	(method_header:): Last argument to call to method_header passed
 	from throws: rule.
	(throws:, class_type_list:, throw_statement:,
 	synchronized_statement:, synchronized:): Defined actions.
	(method_header): New local variable current. Register exceptions
 	from throws clause.
	(java_complete_tree): Complete and verify exceptions from throws
 	clause.
	(complete_class_report_errors): Error message on exceptions not
 	found
	(java_check_regular_methods): Fixed typo. Shortcut on private
 	overriding methods. Changed error message on method
 	redefinition. Check for throws clause compatibility.
	(check_throws_clauses): New function.
	(java_check_abstract_methods): Use DECL_NAME for wfl or current
 	method. Changed error message on method redefinition.
	(currently_caught_type_list): New static variable.
	(java_complete_expand_methods): Purge unchecked exceptions from
 	throws clause list. Call PUSH_EXCEPTIONS before walk and
 	POP_EXCEPTIONS after.
	(resolve_qualified_expression_name): Pass new argument as NULL to
 	patch_method_invocation_stmt.
	(patch_method_invocation_stmt): New argument ref_decl. Invoke
 	PATCH_METHOD_RETURN_ERROR when returning with error. Reverse
 	argument list when appropriate. Use new argument if non null to
 	store selected method decl.
	(patch_invoke): Convert if necessary args of builtin types before
 	forming CALL_EXPR. Argument list no longer reversed here.
	(invocation_mode): Treat final methods as static methods.
	(java_complete_tree): New cases for THROW_EXPR: and
 	SYNCHRONIZED_EXPR:. Check thrown exceptions when completing
 	function call.
	(complete_function_arguments): No more RECORD_TYPE
 	conversion. Function parameter nodes no longer saved.
	(valid_ref_assignconv_cast_p): Avoid handling null type.
	(patch_binop): Fixed null constant reference handling.
	(build_try_statement): Use BUILD_ASSIGN_EXCEPTION_INFO and
 	BUILD_THROW macros.
	(patch_try_statement): Fixed comments. Record caught types in
 	list, push the list, expand try block and pop the list.
	(patch_synchronized_statement, patch_throw_statement,
 	check_thrown_exceptions, check_thrown_exceptions_do,
 	purge_unchecked_exceptions): New functions.
	* typeck.c (lookup_argument_method): Allow WFL in place of method
 	DECL_NAME during method definition check
Implements the `synchronized' statement, the `throw' statements and
the `throws' clause. Fixes method invocation bugs.

From-SVN: r23087
parent 8e30605e
......@@ -47,6 +47,83 @@ Tue Oct 13 23:34:12 1998 Jeffrey A Law (law@cygnus.com)
(disassemble_method): Undefine RET to avoid clash with
config/i386/i386.h.
Tue Oct 13 03:50:28 1998 Alexandre Petit-Bianco <apbianco@cygnus.com>
* decl.c (runtime_exception_type_node, error_exception_type_node):
New global variables.
(init_decl_processing): Initialized.
* expr.c (java_lang_expand_expr): Set caught exception type to
null if catch handler argument doesn't exit.
* java-tree.def (SYNCHRONIZED_EXPR, THROW_EXPR): New Java specific
tree codes.
* java-tree.h (runtime_exception_type_node,
error_exception_type_node): Global variables declared.
(DECL_FUNCTION_THROWS): New macro.
(DECL_FUNCTION_BODY): Modified comment.
(DECL_SPECIFIC_COUNT): Likewise.
(struct lang_decl): New field throws_list.
(IS_UNCHECKED_EXPRESSION_P): New macro.
* lex.c (java_lex): Generate location information for THROW_TK.
* parse.h (PUSH_EXCEPTIONS, POP_EXCEPTIONS, IN_TRY_BLOCK_P,
EXCEPTIONS_P): New macros.
(enum jdep_code): New value JDEP_EXCEPTION.
(BUILD_MONITOR_ENTER, BUILD_MONITOR_EXIT,
BUILD_ASSIGN_EXCEPTION_INFO, BUILD_THROW, SET_WFL_OPERATOR,
PATCH_METHOD_RETURN_ERROR): New macros.
(patch_method_invocation_stmt): Added new argument to prototype.
(patch_synchronized_statement, patch_throw_statement,
check_thrown_exceptions, check_thrown_exceptions_do,
purge_unchecked_exceptions, check_throws_clauses): New function
prototypes.
* parse.y Fixed typo in keyword section.
(throw:): Rule tagged <node>.
(THROW_TK): Keyword tagged <operator>.
(method_header:): Last argument to call to method_header passed
from throws: rule.
(throws:, class_type_list:, throw_statement:,
synchronized_statement:, synchronized:): Defined actions.
(method_header): New local variable current. Register exceptions
from throws clause.
(java_complete_tree): Complete and verify exceptions from throws
clause.
(complete_class_report_errors): Error message on exceptions not
found
(java_check_regular_methods): Fixed typo. Shortcut on private
overriding methods. Changed error message on method
redefinition. Check for throws clause compatibility.
(check_throws_clauses): New function.
(java_check_abstract_methods): Use DECL_NAME for wfl or current
method. Changed error message on method redefinition.
(currently_caught_type_list): New static variable.
(java_complete_expand_methods): Purge unchecked exceptions from
throws clause list. Call PUSH_EXCEPTIONS before walk and
POP_EXCEPTIONS after.
(resolve_qualified_expression_name): Pass new argument as NULL to
patch_method_invocation_stmt.
(patch_method_invocation_stmt): New argument ref_decl. Invoke
PATCH_METHOD_RETURN_ERROR when returning with error. Reverse
argument list when appropriate. Use new argument if non null to
store selected method decl.
(patch_invoke): Convert if necessary args of builtin types before
forming CALL_EXPR. Argument list no longer reversed here.
(invocation_mode): Treat final methods as static methods.
(java_complete_tree): New cases for THROW_EXPR: and
SYNCHRONIZED_EXPR:. Check thrown exceptions when completing
function call.
(complete_function_arguments): No more RECORD_TYPE
conversion. Function parameter nodes no longer saved.
(valid_ref_assignconv_cast_p): Avoid handling null type.
(patch_binop): Fixed null constant reference handling.
(build_try_statement): Use BUILD_ASSIGN_EXCEPTION_INFO and
BUILD_THROW macros.
(patch_try_statement): Fixed comments. Record caught types in
list, push the list, expand try block and pop the list.
(patch_synchronized_statement, patch_throw_statement,
check_thrown_exceptions, check_thrown_exceptions_do,
purge_unchecked_exceptions): New functions.
* typeck.c (lookup_argument_method): Allow WFL in place of method
DECL_NAME during method definition check
1998-10-09 Tom Tromey <tromey@cygnus.com>
* gjavah.c (decode_signature_piece): New function.
......
......@@ -250,6 +250,8 @@ tree object_type_node;
tree object_ptr_type_node;
tree string_type_node;
tree throwable_type_node;
tree runtime_exception_type_node;
tree error_exception_type_node;
tree boolean_type_node;
......@@ -518,6 +520,10 @@ init_decl_processing ()
string_type_node = lookup_class (get_identifier ("java.lang.String"));
class_type_node = lookup_class (get_identifier ("java.lang.Class"));
throwable_type_node = lookup_class (get_identifier ("java.lang.Throwable"));
runtime_exception_type_node =
lookup_class (get_identifier ("java.lang.RuntimeException"));
error_exception_type_node =
lookup_class (get_identifier ("java.lang.Error"));
methodtable_type = make_node (RECORD_TYPE);
layout_type (methodtable_type);
......
......@@ -1750,7 +1750,7 @@ java_lang_expand_expr (exp, target, tmode, modifier)
{
tree catch = java_get_catch_block (current, has_finally_p);
tree decl = BLOCK_EXPR_DECLS (catch);
type = TREE_TYPE (TREE_TYPE (decl));
type = (decl ? TREE_TYPE (TREE_TYPE (decl)) : NULL_TREE);
}
start_catch_handler (prepare_eh_table_type (type));
expand_expr_stmt (TREE_OPERAND (current, 0));
......@@ -1772,7 +1772,8 @@ java_lang_expand_expr (exp, target, tmode, modifier)
if (has_finally_p)
{
tree finally = TREE_OPERAND (exp, 2);
emit_label (label_rtx (FINALLY_EXPR_LABEL (finally)));
if (FINALLY_EXPR_LABEL (finally))
emit_label (label_rtx (FINALLY_EXPR_LABEL (finally)));
expand_expr_stmt (FINALLY_EXPR_BLOCK (finally));
}
expand_end_all_catch ();
......
......@@ -55,3 +55,12 @@ DEFTREECODE (CATCH_EXPR, "catch", '1', 1)
Operand 0 is the finally label.
Operand 1 is the finally block. */
DEFTREECODE (FINALLY_EXPR, "finally", 'e', 2)
/* Synchronized statement.
Operand 0 is the expression on which we whish to synchronize,
Operand 1 is the synchronized expression block. */
DEFTREECODE (SYNCHRONIZED_EXPR, "synchronized", 'e', 2)
/* Throw statement.
Operand 0 is the throw expresion. */
DEFTREECODE (THROW_EXPR, "throw", '1', 1)
......@@ -175,6 +175,8 @@ extern tree object_type_node;
extern tree object_ptr_type_node;
extern tree string_type_node;
extern tree throwable_type_node;
extern tree runtime_exception_type_node;
extern tree error_exception_type_node;
extern tree byte_array_type_node;
extern tree short_array_type_node;
......@@ -317,8 +319,14 @@ struct lang_identifier
#define DECL_MAX_STACK(DECL) (DECL_LANG_SPECIFIC(DECL)->max_stack)
/* Number of local variable slots needed for the arguments of this function. */
#define DECL_ARG_SLOT_COUNT(DECL) (DECL_LANG_SPECIFIC(DECL)->arg_slot_count)
/* Pointer to the function's COMPOUND_EXPR tree */
/* List of checked thrown exceptions, as specified with the `throws'
keyword */
#define DECL_FUNCTION_THROWS(DECL) (DECL_LANG_SPECIFIC(DECL)->throws_list)
/* Pointer to the function's current's COMPOUND_EXPR tree (while
completing its body) or the function's block */
#define DECL_FUNCTION_BODY(DECL) (DECL_LANG_SPECIFIC(DECL)->function_decl_body)
/* How specific the function is (for method selection - Java source
code front-end */
#define DECL_SPECIFIC_COUNT(DECL) DECL_ARG_SLOT_COUNT(DECL)
/* In a LABEL_DECL, a TREE_VEC that saves the type_map at that point. */
......@@ -391,6 +399,7 @@ struct lang_decl
long localvariables_offset;
int arg_slots;
int max_locals, max_stack, arg_slot_count;
tree throws_list; /* Exception specified by `throws' */
tree function_decl_body; /* Hold all function's statements */
};
......@@ -726,3 +735,8 @@ extern tree *type_map;
/* Using a CATCH_EXPR node */
#define CATCH_EXPR_GET_EXPR(NODE, V) (V ? LABELED_BLOCK_BODY (NODE) : (NODE))
/* Non zero if TYPE is an unchecked expression */
#define IS_UNCHECKED_EXPRESSION_P(TYPE) \
(inherits_from_p ((TYPE), runtime_exception_type_node) \
|| inherits_from_p ((TYPE), error_exception_type_node))
......@@ -1209,6 +1209,7 @@ java_lex (java_lval)
case CONTINUE_TK:
case TRY_TK:
case CATCH_TK:
case THROW_TK:
BUILD_OPERATOR (kw->token);
default:
......
......@@ -262,6 +262,24 @@ extern tree stabilize_reference PROTO ((tree));
}
#define POP_LOOP() ctxp->current_loop = TREE_CHAIN (ctxp->current_loop)
#define PUSH_EXCEPTIONS(E) \
currently_caught_type_list = \
tree_cons (NULL_TREE, (E), currently_caught_type_list);
#define POP_EXCEPTIONS() \
currently_caught_type_list = TREE_CHAIN (currently_caught_type_list)
/* Check that we're inside a try block */
#define IN_TRY_BLOCK_P() \
(currently_caught_type_list \
&& ((TREE_VALUE (currently_caught_type_list) != \
DECL_FUNCTION_THROWS (current_function_decl)) \
|| TREE_CHAIN (currently_caught_type_list)))
/* Check that we have exceptions in E */
#define EXCEPTIONS_P(E) ((E) ? TREE_VALUE (E) : NULL_TREE)
/* Invocation modes, as returned by invocation_mode (). */
enum {
INVOKE_STATIC,
......@@ -317,6 +335,7 @@ enum jdep_code {
JDEP_TYPE, /* Patch a random tree node type,
without the need for any specific
actions */
JDEP_EXCEPTION, /* Patch exceptions specified by `throws' */
};
typedef struct _jdep {
......@@ -431,6 +450,51 @@ static jdeplist *reverse_jdep_list ();
build_new_invocation (wfl_string_buffer, \
(ARG ? build_tree_list (NULL, (ARG)) : NULL_TREE))
/* For exception handling, build diverse function calls */
#define BUILD_MONITOR_ENTER(WHERE, ARG) \
{ \
(WHERE) = build (CALL_EXPR, int_type_node, \
build_address_of (soft_monitorenter_node), \
build_tree_list (NULL_TREE, (ARG))); \
TREE_SIDE_EFFECTS (WHERE) = 1; \
}
#define BUILD_MONITOR_EXIT(WHERE, ARG) \
{ \
(WHERE) = build (CALL_EXPR, int_type_node, \
build_address_of (soft_monitorexit_node), \
build_tree_list (NULL_TREE, (ARG))); \
TREE_SIDE_EFFECTS (WHERE) = 1; \
}
#define BUILD_ASSIGN_EXCEPTION_INFO(WHERE, TO) \
{ \
(WHERE) = build (MODIFY_EXPR, void_type_node, (TO), \
soft_exceptioninfo_call_node); \
TREE_SIDE_EFFECTS (WHERE) = 1; \
}
#define BUILD_THROW(WHERE, WHAT) \
{ \
(WHERE) = build (CALL_EXPR, void_type_node, \
build_address_of (throw_node), \
build_tree_list (NULL_TREE, (WHAT)), NULL_TREE); \
TREE_SIDE_EFFECTS ((WHERE)) = 1; \
}
/* Set wfl_operator for the most accurate error location */
#define SET_WFL_OPERATOR(WHICH, NODE, WFL) \
EXPR_WFL_LINECOL (WHICH) = \
(TREE_CODE (WFL) == EXPR_WITH_FILE_LOCATION ? \
EXPR_WFL_LINECOL (WFL) : EXPR_WFL_LINECOL (NODE))
#define PATCH_METHOD_RETURN_ERROR() \
{ \
if (ret_decl) \
*ret_decl = NULL_TREE; \
return error_mark_node; \
}
/* Parser context data structure. */
struct parser_ctxt {
......@@ -527,7 +591,7 @@ static tree lookup_java_interface_method2 PROTO ((tree, tree));
static tree resolve_expression_name PROTO ((tree));
static tree maybe_create_class_interface_decl PROTO ((tree, tree, tree));
static int check_class_interface_creation PROTO ((int, int, tree, tree, tree, tree));
static tree patch_method_invocation_stmt PROTO ((tree, tree, tree, int *));
static tree patch_method_invocation_stmt PROTO ((tree, tree, tree, int *, tree *));
static int breakdown_qualified PROTO ((tree *, tree *, tree));
static tree resolve_and_layout PROTO ((tree, tree));
static tree resolve_no_layout PROTO ((tree, tree));
......@@ -613,6 +677,12 @@ static tree patch_string PROTO ((tree));
static tree build_jump_to_finally PROTO ((tree, tree, tree, tree));
static tree build_try_statement PROTO ((int, tree, tree, tree));
static tree patch_try_statement PROTO ((tree));
static tree patch_synchronized_statement PROTO ((tree, tree));
static tree patch_throw_statement PROTO ((tree, tree));
static void check_thrown_exceptions PROTO ((int, tree));
static int check_thrown_exceptions_do PROTO ((int, tree));
static void purge_unchecked_exceptions PROTO ((tree));
static void check_throws_clauses PROTO ((tree, tree, tree));
void safe_layout_class PROTO ((tree));
void java_complete_class PROTO ((void));
......
......@@ -662,7 +662,10 @@ lookup_argument_method (clas, method_name, method_signature)
method != NULL_TREE; method = TREE_CHAIN (method))
{
tree method_sig = build_java_argument_signature (TREE_TYPE (method));
if (DECL_NAME (method) == method_name && method_sig == method_signature)
tree name = DECL_NAME (method);
if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
EXPR_WFL_NODE (DECL_NAME (method)) : name) == method_name
&& method_sig == method_signature)
return method;
}
clas = CLASSTYPE_SUPER (clas);
......@@ -686,7 +689,8 @@ lookup_java_method (clas, method_name, method_signature)
method != NULL_TREE; method = TREE_CHAIN (method))
{
tree method_sig = build_java_signature (TREE_TYPE (method));
if (DECL_NAME (method) == method_name && method_sig == method_signature)
if (DECL_NAME (method) == method_name
&& method_sig == method_signature)
return method;
}
clas = CLASSTYPE_SUPER (clas);
......
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