]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/java/parse.y
Daily bump.
[gcc.git] / gcc / java / parse.y
index 84de8f71b9496768ce4084edfc4c9f9fa3f2c3e3..75ffbc3cc6170092e0f778abb617b4a8c73d8a50 100644 (file)
@@ -1,6 +1,6 @@
 /* Source code parsing and tree node generation for the GNU compiler
    for the Java(TM) language.
-   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
 
 This file is part of GNU CC.
@@ -35,7 +35,6 @@ Language Specification. J. Gosling, B. Joy, G. Steele. Addison Wesley
 The following modifications were brought to the original grammar:
 
 method_body: added the rule '| block SC_TK'
-constructor_declaration: added two rules to accept SC_TK. 
 static_initializer: added the rule 'static block SC_TK'. 
 
 Note: All the extra rules described above should go away when the
@@ -47,17 +46,9 @@ Some rules have been modified to support JDK1.1 inner classes
 definitions and other extensions.  */
 
 %{
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
 #include "config.h"
+#include "system.h"
+#include <dirent.h>
 #include "tree.h"
 #include "rtl.h"
 #include "obstack.h"
@@ -68,6 +59,186 @@ definitions and other extensions.  */
 #include "lex.h"
 #include "parse.h"
 #include "zipfile.h"
+#include "convert.h"
+#include "buffer.h"
+
+#ifndef DIR_SEPARATOR
+#define DIR_SEPARATOR '/'
+#endif
+
+/* Local function prototypes */
+static char *java_accstring_lookup PROTO ((int));
+static void  classitf_redefinition_error PROTO ((char *,tree, tree, tree));
+static void  variable_redefinition_error PROTO ((tree, tree, tree, int));
+static void  check_modifiers PROTO ((char *, int, int));
+static tree  create_class PROTO ((int, tree, tree, tree));
+static tree  create_interface PROTO ((int, tree, tree));
+static tree  find_field PROTO ((tree, tree));
+static tree lookup_field_wrapper PROTO ((tree, tree));
+static int   duplicate_declaration_error_p PROTO ((tree, tree, tree));
+static void  register_fields PROTO ((int, tree, tree));
+static tree parser_qualified_classname PROTO ((tree));
+static int  parser_check_super PROTO ((tree, tree, tree));
+static int  parser_check_super_interface PROTO ((tree, tree, tree));
+static void check_modifiers_consistency PROTO ((int));
+static tree lookup_cl PROTO ((tree));
+static tree lookup_java_method2 PROTO ((tree, tree, int));
+static tree method_header PROTO ((int, tree, tree, tree));
+static void fix_method_argument_names PROTO ((tree ,tree));
+static tree method_declarator PROTO ((tree, tree));
+static void parse_warning_context PVPROTO ((tree cl, const char *msg, ...))
+  ATTRIBUTE_PRINTF_2;
+static void issue_warning_error_from_context PROTO ((tree, const char *msg, va_list));
+static tree parse_jdk1_1_error PROTO ((char *));
+static void complete_class_report_errors PROTO ((jdep *));
+static int process_imports PROTO ((void));
+static void read_import_dir PROTO ((tree));
+static int find_in_imports_on_demand PROTO ((tree));
+static int find_in_imports PROTO ((tree));
+static int check_pkg_class_access PROTO ((tree, tree));
+static tree resolve_package PROTO ((tree, tree *));
+static tree lookup_package_type PROTO ((char *, int));
+static tree resolve_class PROTO ((tree, tree, tree));
+static void declare_local_variables PROTO ((int, tree, tree));
+static void source_start_java_method PROTO ((tree));
+static void source_end_java_method PROTO ((void));
+static void expand_start_java_method PROTO ((tree));
+static tree find_name_in_single_imports PROTO ((tree));
+static void check_abstract_method_header PROTO ((tree));
+static tree lookup_java_interface_method2 PROTO ((tree, tree));
+static tree resolve_expression_name PROTO ((tree, 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 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));
+static int invocation_mode PROTO ((tree, int));
+static tree find_applicable_accessible_methods_list PROTO ((int, tree, 
+                                                           tree, tree));
+static tree find_most_specific_methods_list PROTO ((tree));
+static int argument_types_convertible PROTO ((tree, tree));
+static tree patch_invoke PROTO ((tree, tree, tree));
+static tree lookup_method_invoke PROTO ((int, tree, tree, tree, tree));
+static tree register_incomplete_type PROTO ((int, tree, tree, tree));
+static tree obtain_incomplete_type PROTO ((tree));
+static tree java_complete_lhs PROTO ((tree));
+static tree java_complete_tree PROTO ((tree));
+static void java_complete_expand_method PROTO ((tree));
+static int  unresolved_type_p PROTO ((tree, tree *));
+static void create_jdep_list PROTO ((struct parser_ctxt *));
+static tree build_expr_block PROTO ((tree, tree));
+static tree enter_block PROTO ((void));
+static tree enter_a_block PROTO ((tree));
+static tree exit_block PROTO ((void));
+static tree lookup_name_in_blocks PROTO ((tree));
+static void maybe_absorb_scoping_blocks PROTO ((void));
+static tree build_method_invocation PROTO ((tree, tree));
+static tree build_new_invocation PROTO ((tree, tree));
+static tree build_assignment PROTO ((int, int, tree, tree));
+static tree build_binop PROTO ((enum tree_code, int, tree, tree));
+static int check_final_assignment PROTO ((tree ,tree));
+static tree patch_assignment PROTO ((tree, tree, tree ));
+static tree patch_binop PROTO ((tree, tree, tree));
+static tree build_unaryop PROTO ((int, int, tree));
+static tree build_incdec PROTO ((int, int, tree, int));
+static tree patch_unaryop PROTO ((tree, tree));
+static tree build_cast PROTO ((int, tree, tree));
+static tree build_null_of_type PROTO ((tree));
+static tree patch_cast PROTO ((tree, tree));
+static int valid_ref_assignconv_cast_p PROTO ((tree, tree, int));
+static int valid_builtin_assignconv_identity_widening_p PROTO ((tree, tree));
+static int valid_cast_to_p PROTO ((tree, tree));
+static int valid_method_invocation_conversion_p PROTO ((tree, tree));
+static tree try_builtin_assignconv PROTO ((tree, tree, tree));
+static tree try_reference_assignconv PROTO ((tree, tree));
+static tree build_unresolved_array_type PROTO ((tree));
+static tree build_array_from_name PROTO ((tree, tree, tree, tree *));
+static tree build_array_ref PROTO ((int, tree, tree));
+static tree patch_array_ref PROTO ((tree));
+static tree make_qualified_name PROTO ((tree, tree, int));
+static tree merge_qualified_name PROTO ((tree, tree));
+static tree make_qualified_primary PROTO ((tree, tree, int));
+static int resolve_qualified_expression_name PROTO ((tree, tree *, 
+                                                    tree *, tree *));
+static void qualify_ambiguous_name PROTO ((tree));
+static void maybe_generate_clinit PROTO ((void));
+static tree resolve_field_access PROTO ((tree, tree *, tree *));
+static tree build_newarray_node PROTO ((tree, tree, int));
+static tree patch_newarray PROTO ((tree));
+static tree resolve_type_during_patch PROTO ((tree));
+static tree build_this PROTO ((int));
+static tree build_return PROTO ((int, tree));
+static tree patch_return PROTO ((tree));
+static tree maybe_access_field PROTO ((tree, tree, tree));
+static int complete_function_arguments PROTO ((tree));
+static int check_for_static_method_reference PROTO ((tree, tree, tree, tree, tree));
+static int not_accessible_p PROTO ((tree, tree, int));
+static void check_deprecation PROTO ((tree, tree));
+static int class_in_current_package PROTO ((tree));
+static tree build_if_else_statement PROTO ((int, tree, tree, tree));
+static tree patch_if_else_statement PROTO ((tree));
+static tree add_stmt_to_compound PROTO ((tree, tree, tree));
+static tree add_stmt_to_block PROTO ((tree, tree, tree));
+static tree patch_exit_expr PROTO ((tree));
+static tree build_labeled_block PROTO ((int, tree));
+static tree generate_labeled_block PROTO (());
+static tree complete_labeled_statement PROTO ((tree, tree));
+static tree build_bc_statement PROTO ((int, int, tree));
+static tree patch_bc_statement PROTO ((tree));
+static tree patch_loop_statement PROTO ((tree));
+static tree build_new_loop PROTO ((tree));
+static tree build_loop_body PROTO ((int, tree, int));
+static tree complete_loop_body PROTO ((int, tree, tree, int));
+static tree build_debugable_stmt PROTO ((int, tree));
+static tree complete_for_loop PROTO ((int, tree, tree, tree));
+static tree patch_switch_statement PROTO ((tree));
+static tree string_constant_concatenation PROTO ((tree, tree));
+static tree build_string_concatenation PROTO ((tree, tree));
+static tree patch_string_cst PROTO ((tree));
+static tree patch_string PROTO ((tree));
+static tree build_try_statement PROTO ((int, tree, tree));
+static tree build_try_finally_statement PROTO ((int, 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 ((tree));
+static void purge_unchecked_exceptions PROTO ((tree));
+static void check_throws_clauses PROTO ((tree, tree, tree));
+static void complete_method_declaration PROTO ((tree));
+static tree build_super_invocation PROTO (());
+static int verify_constructor_circularity PROTO ((tree, tree));
+static char *constructor_circularity_msg PROTO ((tree, tree));
+static tree build_this_super_qualified_invocation PROTO ((int, tree, tree,
+                                                         int, int));
+static char *get_printable_method_name PROTO ((tree));
+static tree patch_conditional_expr PROTO ((tree, tree, tree));
+static void maybe_generate_finit PROTO (());
+static void fix_constructors PROTO ((tree));
+static int verify_constructor_super PROTO (());
+static tree create_artificial_method PROTO ((tree, int, tree, tree, tree));
+static void start_artificial_method_body PROTO ((tree));
+static void end_artificial_method_body PROTO ((tree));
+static int check_method_redefinition PROTO ((tree, tree));
+static int reset_method_name PROTO ((tree));
+static void java_check_regular_methods PROTO ((tree));
+static void java_check_abstract_methods PROTO ((tree));
+static tree maybe_build_primttype_type_ref PROTO ((tree, tree));
+static void unreachable_stmt_error PROTO ((tree));
+static tree find_expr_with_wfl PROTO ((tree));
+static void missing_return_error PROTO ((tree));
+static tree build_new_array_init PROTO ((int, tree));
+static tree patch_new_array_init PROTO ((tree, tree));
+static tree maybe_build_array_element_wfl PROTO ((tree));
+static int array_constructor_check_entry PROTO ((tree, tree));
+static char *purify_type_name PROTO ((char *));
+static tree patch_initialized_static_field PROTO ((tree));
+static tree fold_constant_for_init PROTO ((tree, tree));
+static tree strip_out_static_field_access_decl PROTO ((tree));
+static jdeplist *reverse_jdep_list PROTO ((struct parser_ctxt *));
 
 /* Number of error found so far. */
 int java_error_count; 
@@ -99,7 +270,7 @@ static enum tree_code binop_lookup[19] =
 
 /* Fake WFL used to report error message. It is initialized once if
    needed and reused with it's location information is overriden.  */
-static tree wfl_operator = NULL_TREE;
+tree wfl_operator = NULL_TREE;
 
 /* The "$L" identifier we use to create labels.  */
 static tree label_id = NULL_TREE;
@@ -112,6 +283,12 @@ static tree wfl_append = NULL_TREE;
 
 /* The "toString" identifier used for String `+' operator. */
 static tree wfl_to_string = NULL_TREE;
+
+/* The "java.lang" import qualified name.  */
+static tree java_lang_id = NULL_TREE;
+
+/* The "java.lang.Cloneable" qualified name.  */
+static tree java_lang_cloneable = NULL_TREE;
 %}
 
 %union {
@@ -196,18 +373,17 @@ static tree wfl_to_string = NULL_TREE;
                        abstract_method_declaration interface_type_list
 %type   <node>         class_body_declaration class_member_declaration
                        static_initializer constructor_declaration block
-%type   <node>         class_body_declarations
+%type   <node>         class_body_declarations constructor_header
 %type    <node>                class_or_interface_type class_type class_type_list
                        constructor_declarator explicit_constructor_invocation
 %type    <node>         dim_expr dim_exprs this_or_super throws
 
 %type   <node>         variable_declarator_id variable_declarator
                        variable_declarators variable_initializer
-                       variable_initializers
+                       variable_initializers constructor_body
+                       array_initializer
 
-%type   <node>         class_body
-%type   <node>         block_statement local_variable_declaration_statement
-                       block_statements local_variable_declaration
+%type   <node>         class_body block_end
 %type   <node>         statement statement_without_trailing_substatement
                        labeled_statement if_then_statement label_decl
                        if_then_else_statement while_statement for_statement
@@ -234,10 +410,7 @@ static tree wfl_to_string = NULL_TREE;
                        constant_expression do_statement_begin empty_statement
                        switch_statement synchronized_statement throw_statement
                        try_statement switch_expression switch_block
-                       switch_block_statement_groups switch_labels
-                       switch_block_statement_group switch_label
-                       group_of_labels catches catch_clause 
-                       catch_clause_parameter finally
+                       catches catch_clause catch_clause_parameter finally
 %type    <node>         return_statement break_statement continue_statement
 
 %type    <operator>     ASSIGN_TK      MULT_ASSIGN_TK  DIV_ASSIGN_TK  
@@ -248,8 +421,8 @@ static tree wfl_to_string = NULL_TREE;
 %token   <operator>     EQ_TK GTE_TK ZRS_TK SRS_TK GT_TK LTE_TK LS_TK 
 %token   <operator>     BOOL_AND_TK AND_TK BOOL_OR_TK OR_TK INCR_TK PLUS_TK
 %token   <operator>     DECR_TK MINUS_TK MULT_TK DIV_TK XOR_TK REM_TK NEQ_TK
-%token   <operator>     NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK
-%token   <operator>     OP_TK OSB_TK DOT_TK THROW_TK
+%token   <operator>     NEG_TK REL_QM_TK REL_CL_TK NOT_TK LT_TK OCB_TK
+%token   <operator>     OP_TK OSB_TK DOT_TK THROW_TK INSTANCEOF_TK
 %type    <operator>    THIS_TK SUPER_TK RETURN_TK BREAK_TK CONTINUE_TK 
 %type   <operator>     CASE_TK DEFAULT_TK TRY_TK CATCH_TK SYNCHRONIZED_TK
 
@@ -410,14 +583,11 @@ single_type_import_declaration:
                          ($2, "Ambiguous class: `%s' and `%s'",
                           IDENTIFIER_POINTER (name), 
                           IDENTIFIER_POINTER (err));
+                     else
+                       REGISTER_IMPORT ($2, last_name)
                    }
                  else
-                   {
-                     IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (last_name) = 1;
-                     node = build_tree_list ($2, last_name);
-                     TREE_CHAIN (node) = ctxp->import_list;
-                     ctxp->import_list = node;
-                   }
+                   REGISTER_IMPORT ($2, last_name);
                }
 |      IMPORT_TK error
                {yyerror ("Missing name"); RECOVER;}
@@ -429,14 +599,14 @@ type_import_on_demand_declaration:
        IMPORT_TK name DOT_TK MULT_TK SC_TK
                {
                  tree name = EXPR_WFL_NODE ($2);
-                 tree node = build_tree_list ($2, NULL_TREE);
-                 if (!IS_AN_IMPORT_ON_DEMAND_P (name))
+                 /* Don't import java.lang.* twice. */
+                 if (name != java_lang_id)
                    {
+                     tree node = build_tree_list ($2, NULL_TREE);
                      read_import_dir ($2);
-                     IS_AN_IMPORT_ON_DEMAND_P (name) = 1;
+                     TREE_CHAIN (node) = ctxp->import_demand_list;
+                     ctxp->import_demand_list = node;
                    }
-                 TREE_CHAIN (node) = ctxp->import_demand_list;
-                 ctxp->import_demand_list = node;
                }
 |      IMPORT_TK name DOT_TK error
                {yyerror ("'*' expected"); RECOVER;}
@@ -447,6 +617,7 @@ type_import_on_demand_declaration:
 type_declaration:
        class_declaration
                {
+                 maybe_generate_finit ();
                  maybe_generate_clinit ();
                  $$ = $1;
                }
@@ -501,7 +672,10 @@ class_declaration:
 |      CLASS_TK error
                {yyerror ("Missing class name"); RECOVER;}
 |       CLASS_TK identifier error
-               {if (!ctxp->class_err) yyerror ("'{' expected"); DRECOVER(class1);}
+               {
+                 if (!ctxp->class_err) yyerror ("'{' expected"); 
+                 DRECOVER(class1);
+               }
 |       modifiers CLASS_TK identifier error
                {if (!ctxp->class_err) yyerror ("'{' expected"); RECOVER;}
 ;
@@ -564,6 +738,8 @@ class_body_declaration:
 
 class_member_declaration:
        field_declaration
+|      field_declaration SC_TK
+               { $$ = $1; }
 |      method_declaration
 |      class_declaration       /* Added, JDK1.1 inner classes */
                { $$ = parse_jdk1_1_error ("inner classe declaration"); }
@@ -633,7 +809,6 @@ variable_declarator_id:
 variable_initializer:
        expression
 |      array_initializer
-               { $$ = NULL; }
 ;
 
 /* 19.8.3 Productions from 8.4: Method Declarations  */
@@ -644,18 +819,7 @@ method_declaration:
                  source_start_java_method (current_function_decl);
                }
        method_body
-               { 
-                 BLOCK_EXPR_BODY 
-                   (DECL_FUNCTION_BODY (current_function_decl)) = $3;
-                 maybe_absorb_scoping_blocks ();
-                 exit_block (); /* Exit function's body. */
-
-                 /* Merge last line of the function with first line,
-                    directly in the function decl. It will be used to
-                    emit correct debug info. */
-                 DECL_SOURCE_LINE_MERGE (current_function_decl,
-                                         ctxp->last_ccb_indent1);
-               }
+               { complete_method_declaration ($3); }
 |      method_header error
                {YYNOT_TWICE yyerror ("'{' expected"); RECOVER;}
 ;
@@ -691,8 +855,12 @@ method_declarator:
                { $$ = method_declarator ($1, $3); }
 |      method_declarator OSB_TK CSB_TK
                {
-                 /* Issue a warning here: obsolete declaration. FIXME */
-                 $$ = NULL;    /* FIXME */
+                 EXPR_WFL_LINECOL (wfl_operator) = $2.location;
+                 TREE_PURPOSE ($1) = 
+                   build_unresolved_array_type (TREE_PURPOSE ($1));
+                 parse_warning_context 
+                   (wfl_operator, 
+                    "Discouraged form of returned type specification");
                }
 |      identifier OP_TK error
                {yyerror ("')' expected"); DRECOVER(method_declarator);}
@@ -719,8 +887,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
@@ -740,9 +908,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;}
 ;
@@ -774,51 +942,61 @@ static:                           /* Test lval.sub_token here */
 ;
 
 /* 19.8.5 Productions from 8.6: Constructor Declarations  */
-/* NOTE FOR FURTHER WORK ON CONSTRUCTORS:
-   - If a forbidded modifier is found, the the error is either the use of
-     a forbidded modifier for a constructor OR bogus attempt to declare a
-     method without having specified the return type. FIXME */
 constructor_declaration:
-       constructor_declarator throws constructor_body
-               {
-                 RULE ("CONSTRUCTOR_DECLARATION");
-               }
-|      modifiers constructor_declarator throws constructor_body
-               {
-                 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
-                 RULE ("CONSTRUCTOR_DECLARATION (modifier)");
-               }
-/* extra SC_TK, FIXME */
-|      constructor_declarator throws constructor_body SC_TK
-               {
-                 RULE ("CONSTRUCTOR_DECLARATION");
-               }
-/* extra SC_TK, FIXME */
-|      modifiers constructor_declarator throws constructor_body SC_TK
+       constructor_header
                {
-                 SOURCE_FRONTEND_DEBUG (("Modifiers: %d", $1));
-                 RULE ("CONSTRUCTOR_DECLARATION (modifier)");
+                 current_function_decl = $1;
+                 source_start_java_method (current_function_decl);
                }
-/* I'm not happy with the SC_TK addition. It isn't in the grammer and should
-   probably be matched by and empty statement. But it doesn't work. FIXME */
+       constructor_body
+               { complete_method_declaration ($3); }
+;
+
+constructor_header:
+       constructor_declarator throws
+               { $$ = method_header (0, NULL_TREE, $1, $2); }
+|      modifiers constructor_declarator throws
+               { $$ = method_header ($1, NULL_TREE, $2, $3); }
 ;
 
 constructor_declarator:
        simple_name OP_TK CP_TK
+               { $$ = method_declarator ($1, NULL_TREE); }
 |      simple_name OP_TK formal_parameter_list CP_TK
+               { $$ = method_declarator ($1, $3); }
 ;
 
 constructor_body:
-       OCB_TK CCB_TK
-|      OCB_TK explicit_constructor_invocation CCB_TK
-|      OCB_TK block_statements CCB_TK
-|       OCB_TK explicit_constructor_invocation block_statements CCB_TK
+       /* Unlike regular method, we always need a complete (empty)
+          body so we can safely perform all the required code
+          addition (super invocation and field initialization) */
+       block_begin block_end
+               { 
+                 BLOCK_EXPR_BODY ($2) = empty_stmt_node;
+                 $$ = $2;
+               }
+|      block_begin explicit_constructor_invocation block_end
+               { $$ = $3; }
+|      block_begin block_statements block_end
+               { $$ = $3; }
+|       block_begin explicit_constructor_invocation block_statements block_end
+               { $$ = $4; }
 ;
 
 /* Error recovery for that rule moved down expression_statement: rule.  */
 explicit_constructor_invocation:
        this_or_super OP_TK CP_TK SC_TK
+               { 
+                 $$ = build_method_invocation ($1, NULL_TREE); 
+                 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
+                 $$ = java_method_add_stmt (current_function_decl, $$);
+               }
 |      this_or_super OP_TK argument_list CP_TK SC_TK
+               { 
+                 $$ = build_method_invocation ($1, $3); 
+                 $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $$);
+                 $$ = java_method_add_stmt (current_function_decl, $$);
+               }
         /* Added, JDK1.1 inner classes. Modified because the rule
           'primary' couldn't work.  */
 |      name DOT_TK SUPER_TK OP_TK argument_list CP_TK SC_TK
@@ -872,9 +1050,9 @@ interface_declaration:
                  $$ = $6;
                }
 |      INTERFACE_TK identifier error
-               {yyerror ("(here)'{' expected"); RECOVER;}
+               {yyerror ("'{' expected"); RECOVER;}
 |      modifiers INTERFACE_TK identifier error
-               {yyerror ("(there)'{' expected"); RECOVER;}
+               {yyerror ("'{' expected"); RECOVER;}
 ;
 
 extends_interfaces:
@@ -932,26 +1110,23 @@ abstract_method_declaration:
 /* 19.10 Productions from 10: Arrays  */
 array_initializer:
        OCB_TK CCB_TK
-               {
-                 RULE ("ARRAY_INITIALIZER (empty)");
-               }
+               { $$ = build_new_array_init ($1.location, NULL_TREE); }
 |      OCB_TK variable_initializers CCB_TK
-               {
-                 RULE ("ARRAY_INITIALIZER (variable)");
-               }
-|      OCB_TK C_TK CCB_TK
-               {
-                 RULE ("ARRAY_INITIALIZER (,)");
-               }
+               { $$ = build_new_array_init ($1.location, $2); }
 |      OCB_TK variable_initializers C_TK CCB_TK
-               {
-                 RULE ("ARRAY_INITIALIZER (variable, ,)");
-               }
+               { $$ = build_new_array_init ($1.location, $2); }
 ;
 
 variable_initializers:
        variable_initializer
+               { 
+                 $$ = tree_cons (maybe_build_array_element_wfl ($1), 
+                                 $1, NULL_TREE);
+               }
 |      variable_initializers C_TK variable_initializer
+               {
+                 $$ = tree_cons (maybe_build_array_element_wfl ($3), $3, $1);
+               }
 |      variable_initializers C_TK error
                {yyerror ("Missing term"); RECOVER;}
 ;
@@ -959,10 +1134,17 @@ variable_initializers:
 /* 19.11 Production from 14: Blocks and Statements  */
 block:
        OCB_TK CCB_TK
-               { $$ = size_zero_node; }
-|      OCB_TK 
+               { $$ = empty_stmt_node; }
+|      block_begin block_statements block_end
+               { $$ = $3; }
+;
+
+block_begin:
+       OCB_TK
                { enter_block (); }
-       block_statements
+;
+
+block_end:
        CCB_TK
                { 
                  maybe_absorb_scoping_blocks ();
@@ -978,9 +1160,9 @@ block_statements:
 block_statement:
        local_variable_declaration_statement
 |      statement
-               { $$ = java_method_add_stmt (current_function_decl, $1); }
+               { java_method_add_stmt (current_function_decl, $1); }
 |      class_declaration       /* Added, JDK1.1 inner classes */
-               { $$ = parse_jdk1_1_error ("inner class declaration"); }
+               { parse_jdk1_1_error ("inner class declaration"); }
 ;
 
 local_variable_declaration_statement:
@@ -1034,7 +1216,7 @@ statement_without_trailing_substatement:
 
 empty_statement:
        SC_TK
-               { $$ = size_zero_node; }
+               { $$ = empty_stmt_node; }
 ;
 
 label_decl:
@@ -1101,11 +1283,19 @@ expression_statement:
 |       this_or_super OP_TK error
                {yyerror ("')' expected"); RECOVER;}
 |       this_or_super OP_TK CP_TK error
-               {yyerror ("';' expected"); RECOVER;}
+               {
+                 yyerror ("Constructor invocation must be first "
+                          "thing in a constructor"); 
+                 RECOVER;
+               }
 |       this_or_super OP_TK argument_list error
                {yyerror ("')' expected"); RECOVER;}
 |       this_or_super OP_TK argument_list CP_TK error
-               {yyerror ("';' expected"); RECOVER;}
+               {
+                 yyerror ("Constructor invocation must be first "
+                          "thing in a constructor"); 
+                 RECOVER;
+               }
 |      name DOT_TK SUPER_TK error
                {yyerror ("'(' expected"); RECOVER;}
 |      name DOT_TK SUPER_TK OP_TK error
@@ -1130,7 +1320,10 @@ statement_expression:
 
 if_then_statement:
        IF_TK OP_TK expression CP_TK statement
-       { $$ = build_if_else_statement ($2.location, $3, $5, NULL_TREE); }
+               { 
+                 $$ = build_if_else_statement ($2.location, $3, 
+                                               $5, NULL_TREE);
+               }
 |      IF_TK error
                {yyerror ("'(' expected"); RECOVER;}
 |      IF_TK OP_TK error
@@ -1141,18 +1334,26 @@ if_then_statement:
 
 if_then_else_statement:
        IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement
-       { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
+               { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
 ;
 
 if_then_else_statement_nsi:
        IF_TK OP_TK expression CP_TK statement_nsi ELSE_TK statement_nsi
-       { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
+               { $$ = build_if_else_statement ($2.location, $3, $5, $7); }
 ;
 
 switch_statement:
-       switch_expression switch_block
+       switch_expression
+               {
+                 enter_block ();
+               }
+       switch_block
                { 
-                 TREE_OPERAND ($1, 1) = $2;
+                 /* Make into "proper list" of COMPOUND_EXPRs.
+                    I.e. make the last statment also have its own
+                    COMPOUND_EXPR. */
+                 maybe_absorb_scoping_blocks ();
+                 TREE_OPERAND ($1, 1) = exit_block ();
                  $$ = build_debugable_stmt (EXPR_WFL_LINECOL ($1), $1);
                }
 ;
@@ -1171,64 +1372,46 @@ switch_expression:
                {yyerror ("'{' expected"); RECOVER;}
 ;
 
+/* Default assignment is there to avoid type node on switch_block
+   node. */
+
 switch_block:
        OCB_TK CCB_TK
                { $$ = NULL_TREE; }
 |      OCB_TK switch_labels CCB_TK
-               { $$ = build_tree_list ($2, NULL_TREE); }
+               { $$ = NULL_TREE; }
 |      OCB_TK switch_block_statement_groups CCB_TK
-               { $$ = $2; }
+               { $$ = NULL_TREE; }
 |      OCB_TK switch_block_statement_groups switch_labels CCB_TK
-               { 
-                 /* Switch labels alone are empty switch statements */
-                 tree sl = build_tree_list ($3, NULL_TREE);
-                 TREE_CHAIN (sl) = $2;
-                 $$ = sl;
-               }
+               { $$ = NULL_TREE; }
 ;
 
 switch_block_statement_groups: 
        switch_block_statement_group
 |      switch_block_statement_groups switch_block_statement_group
-               { 
-                 TREE_CHAIN ($2) = $1;
-                 $$ = $2;
-               }
 ;
 
 switch_block_statement_group:
-       group_of_labels block_statements
-               { $$ = build_tree_list ($1, exit_block ()); }
+       switch_labels block_statements
 ;
 
-group_of_labels:
-       switch_labels
-               { 
-                 /* All statements attached to this group of cases
-                    will be stored in a block */
-                 enter_block ();
-                 $$ = $1;
-               }
-
 switch_labels:
        switch_label
 |      switch_labels switch_label
-               {
-                 TREE_CHAIN ($2) = $1;
-                 $$ = $2;
-               }
 ;
 
 switch_label:
        CASE_TK constant_expression REL_CL_TK
                { 
-                 $$ = build1 (CASE_EXPR, NULL_TREE, $2);
-                 EXPR_WFL_LINECOL ($$) = $1.location;
+                 tree lab = build1 (CASE_EXPR, NULL_TREE, $2);
+                 EXPR_WFL_LINECOL (lab) = $1.location;
+                 java_method_add_stmt (current_function_decl, lab);
                }
 |      DEFAULT_TK REL_CL_TK
                { 
-                 $$ = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
-                 EXPR_WFL_LINECOL ($$) = $1.location;
+                 tree lab = build1 (DEFAULT_EXPR, NULL_TREE, NULL_TREE);
+                 EXPR_WFL_LINECOL (lab) = $1.location;
+                 java_method_add_stmt (current_function_decl, lab);
                }
 |      CASE_TK error
                {yyerror ("Missing or invalid constant expression"); RECOVER;}
@@ -1278,13 +1461,13 @@ do_statement:
 
 for_statement:
        for_begin SC_TK expression SC_TK for_update CP_TK statement
-               { $$ = complete_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7);}
+               { $$ = complete_for_loop (EXPR_WFL_LINECOL ($3), $3, $5, $7); }
 |      for_begin SC_TK SC_TK for_update CP_TK statement
                { 
                  $$ = complete_for_loop (0, NULL_TREE, $4, $6);
                  /* We have not condition, so we get rid of the EXIT_EXPR */
                  LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) = 
-                   size_zero_node;
+                   empty_stmt_node;
                }
 |      for_begin SC_TK error
                {yyerror ("Invalid control expression"); RECOVER;}
@@ -1302,7 +1485,7 @@ for_statement_nsi:
                  $$ = complete_for_loop (0, NULL_TREE, $4, $6);
                  /* We have not condition, so we get rid of the EXIT_EXPR */
                  LOOP_EXPR_BODY_CONDITION_EXPR (LOOP_EXPR_BODY ($$), 0) = 
-                   size_zero_node;
+                   empty_stmt_node;
                }
 ;
 
@@ -1333,7 +1516,7 @@ for_begin:
                }
 ;
 for_init:                      /* Can be empty */
-               { $$ = size_zero_node; }
+               { $$ = empty_stmt_node; }
 |      statement_expression_list
                { 
                  /* Init statement recorded within the previously
@@ -1351,7 +1534,7 @@ for_init:                 /* Can be empty */
 ;
 
 for_update:                    /* Can be empty */
-               {$$ = size_zero_node;}
+               {$$ = empty_stmt_node;}
 |      statement_expression_list
                { $$ = build_debugable_stmt (BUILD_LOCATION (), $1); }
 ;
@@ -1437,11 +1620,14 @@ synchronized:
 
 try_statement:
        TRY_TK block catches
-               { $$ = build_try_statement ($1.location, $2, $3, NULL_TREE); }
+               { $$ = build_try_statement ($1.location, $2, $3); }
 |      TRY_TK block finally
-               { $$ = build_try_statement ($1.location, $2, NULL_TREE, $3); }
+               { $$ = build_try_finally_statement ($1.location, $2, $3); }
 |      TRY_TK block catches finally
-               { $$ = build_try_statement ($1.location, $2, $3, $4); }
+               { $$ = build_try_finally_statement 
+                   ($1.location, build_try_statement ($1.location,
+                                                      $2, $3), $4);
+               }
 |      TRY_TK error
                {yyerror ("'{' expected"); DRECOVER (try_statement);}
 ;
@@ -1490,10 +1676,7 @@ catch_clause_parameter:
 
 finally:
        FINALLY_TK block
-               { 
-                 $$ = build (FINALLY_EXPR, NULL_TREE,
-                             create_label_decl (generate_name ()), $2);
-               }
+               { $$ = $2; }
 |      FINALLY_TK error
                {yyerror ("'{' expected"); RECOVER; }
 ;
@@ -1518,11 +1701,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.  */
@@ -1597,9 +1780,9 @@ array_creation_expression:
 |      NEW_TK class_or_interface_type dim_exprs
                { $$ = build_newarray_node ($2, $3, 0); }
 |      NEW_TK primitive_type dim_exprs dims
-               { $$ = build_newarray_node ($2, $3, ctxp->osb_number); }
+               { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
 |      NEW_TK class_or_interface_type dim_exprs dims
-               { $$ = build_newarray_node ($2, $3, ctxp->osb_number); }
+               { $$ = build_newarray_node ($2, $3, CURRENT_OSB (ctxp));}
         /* Added, JDK1.1 anonymous array. Initial documentation rule
            modified */
 |      NEW_TK class_or_interface_type dims array_initializer
@@ -1637,9 +1820,33 @@ dim_expr:
 
 dims:                          
        OSB_TK CSB_TK
-               { ctxp->osb_number = 1; }
+               { 
+                 int allocate = 0;
+                 /* If not initialized, allocate memory for the osb
+                     numbers stack */
+                 if (!ctxp->osb_limit)
+                   {
+                     allocate = ctxp->osb_limit = 32;
+                     ctxp->osb_depth = -1;
+                   }
+                 /* If capacity overflown, reallocate a bigger chuck */
+                 else if (ctxp->osb_depth+1 == ctxp->osb_limit)
+                   allocate = ctxp->osb_limit << 1;
+                 
+                 if (allocate)
+                   {
+                     allocate *= sizeof (int);
+                     if (ctxp->osb_number)
+                       ctxp->osb_number = (int *)xrealloc (ctxp->osb_number,
+                                                           allocate);
+                     else
+                       ctxp->osb_number = (int *)xmalloc (allocate);
+                   }
+                 ctxp->osb_depth++;
+                 CURRENT_OSB (ctxp) = 1;
+               }
 |      dims OSB_TK CSB_TK
-               { ctxp->osb_number++; }
+               { CURRENT_OSB (ctxp)++; }
 |      dims OSB_TK error
                { yyerror ("']' expected"); RECOVER;}
 ;
@@ -1647,6 +1854,8 @@ dims:
 field_access:
        primary DOT_TK identifier
                { $$ = make_qualified_primary ($1, $3, $2.location); }
+               /*  FIXME - REWRITE TO: 
+               { $$ = build_binop (COMPONENT_REF, $2.location, $1, $3); } */
 |      SUPER_TK DOT_TK identifier
                {
                  tree super_wfl = 
@@ -1666,31 +1875,35 @@ method_invocation:
                { $$ = build_method_invocation ($1, $3); }
 |      primary DOT_TK identifier OP_TK CP_TK
                { 
-                 tree invok = build_method_invocation ($3, NULL_TREE);
-                 $$ = make_qualified_primary ($1, invok, $2.location);
+                 if (TREE_CODE ($1) == THIS_EXPR)
+                   $$ = build_this_super_qualified_invocation 
+                     (1, $3, NULL_TREE, 0, $2.location);
+                 else
+                   {
+                     tree invok = build_method_invocation ($3, NULL_TREE);
+                     $$ = make_qualified_primary ($1, invok, $2.location);
+                   }
                }
 |      primary DOT_TK identifier OP_TK argument_list CP_TK
                { 
-                 tree invok = build_method_invocation ($3, $5);
-                 $$ = make_qualified_primary ($1, invok, $2.location);
+                 if (TREE_CODE ($1) == THIS_EXPR)
+                   $$ = build_this_super_qualified_invocation 
+                     (1, $3, $5, 0, $2.location);
+                 else
+                   {
+                     tree invok = build_method_invocation ($3, $5);
+                     $$ = make_qualified_primary ($1, invok, $2.location);
+                   }
                }
 |      SUPER_TK DOT_TK identifier OP_TK CP_TK
-               {
-                 tree invok;
-                 tree wfl = build_wfl_node (super_identifier_node, 
-                                            input_filename, 0, 0);
-                 EXPR_WFL_LINECOL (wfl) = $1.location;
-                 invok = build_method_invocation ($3, NULL_TREE);
-                 $$ = make_qualified_primary (wfl, invok, $2.location);
+               { 
+                 $$ = build_this_super_qualified_invocation 
+                   (0, $3, NULL_TREE, $1.location, $2.location);
                }
 |      SUPER_TK DOT_TK identifier OP_TK argument_list CP_TK
                {
-                 tree invok;
-                 tree wfl = build_wfl_node (super_identifier_node, 
-                                            input_filename, 0, 0);
-                 EXPR_WFL_LINECOL (wfl) = $1.location;
-                 invok = build_method_invocation ($3, $5);
-                 $$ = make_qualified_primary (wfl, invok, $2.location);
+                 $$ = build_this_super_qualified_invocation 
+                   (0, $3, $5, $1.location, $2.location);
                }
         /* Screws up thing. I let it here until I'm convinced it can
            be removed. FIXME
@@ -1791,8 +2004,9 @@ cast_expression:          /* Error handling here is potentially weak */
        OP_TK primitive_type dims CP_TK unary_expression
                { 
                  tree type = $2;
-                 while (ctxp->osb_number--)
+                 while (CURRENT_OSB (ctxp)--)
                    type = build_java_array_type (type, -1);
+                 ctxp->osb_depth--;
                  $$ = build_cast ($1.location, type, $5); 
                }
 |      OP_TK primitive_type CP_TK unary_expression
@@ -1802,8 +2016,9 @@ cast_expression:          /* Error handling here is potentially weak */
 |      OP_TK name dims CP_TK unary_expression_not_plus_minus
                { 
                  char *ptr;
-                 while (ctxp->osb_number--)
+                 while (CURRENT_OSB (ctxp)--)
                    obstack_1grow (&temporary_obstack, '[');
+                 ctxp->osb_depth--;
                  obstack_grow0 (&temporary_obstack, 
                                 IDENTIFIER_POINTER (EXPR_WFL_NODE ($2)),
                                 IDENTIFIER_LENGTH (EXPR_WFL_NODE ($2)));
@@ -1918,6 +2133,7 @@ relational_expression:
                                    $1, $3); 
                }
 |      relational_expression INSTANCEOF_TK reference_type
+               { $$ = build_binop (INSTANCEOF_EXPR, $2.location, $1, $3); }
 |      relational_expression LT_TK error
                {yyerror ("Missing term"); RECOVER;}
 |      relational_expression GT_TK error
@@ -2006,6 +2222,10 @@ conditional_or_expression:
 conditional_expression:                /* Error handling here is weak */
        conditional_or_expression
 |      conditional_or_expression REL_QM_TK expression REL_CL_TK conditional_expression
+               {
+                 $$ = build (CONDITIONAL_EXPR, NULL_TREE, $1, $3, $5);
+                 EXPR_WFL_LINECOL ($$) = $2.location;
+               }
 |      conditional_or_expression REL_QM_TK REL_CL_TK error
                {
                  YYERROR_NOW;
@@ -2070,18 +2290,32 @@ void
 java_push_parser_context ()
 {
   struct parser_ctxt *new = 
-    (struct parser_ctxt *)malloc(sizeof (struct parser_ctxt));
+    (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
 
   bzero (new, sizeof (struct parser_ctxt));
   new->next = ctxp;
   ctxp = new;
   if (ctxp->next)
-    ctxp->incomplete_class = ctxp->next->incomplete_class;
+    {
+      ctxp->incomplete_class = ctxp->next->incomplete_class;
+      ctxp->gclass_list = ctxp->next->gclass_list;
+    }
 }  
 
+/* If the first file of a file list was a class file, no context
+   exists for a source file to be parsed. This boolean remembers that
+   java_parser_context_save_global might have created a dummy one, so
+   that java_parser_context_restore_global can pop it.  */
+static int extra_ctxp_pushed_p = 0;
+
 void
 java_parser_context_save_global ()
 {
+  if (!ctxp)
+    {
+      java_push_parser_context ();
+      extra_ctxp_pushed_p = 1;
+    }
   ctxp->finput = finput;
   ctxp->lineno = lineno;
   ctxp->current_class = current_class;
@@ -2097,6 +2331,11 @@ java_parser_context_restore_global ()
   current_class = ctxp->current_class;
   input_filename = ctxp->filename;
   current_function_decl = ctxp->current_function_decl;
+  if (!ctxp->next && extra_ctxp_pushed_p)
+    {
+      java_pop_parser_context (0);
+      extra_ctxp_pushed_p = 0;
+    }
 }
 
 void 
@@ -2104,12 +2343,17 @@ java_pop_parser_context (generate)
      int generate;
 {
   tree current;
-  struct parser_ctxt *toFree = ctxp;
-  struct parser_ctxt *next = ctxp->next;
+  struct parser_ctxt *toFree, *next;
+
+  if (!ctxp)
+    return;
 
+  toFree = ctxp;
+  next = ctxp->next;
   if (next)
     {
       next->incomplete_class = ctxp->incomplete_class;
+      next->gclass_list = ctxp->gclass_list;
       lineno = ctxp->lineno;
       finput = ctxp->finput;
       current_class = ctxp->current_class;
@@ -2142,7 +2386,7 @@ parse_jdk1_1_error (msg)
 {
   sorry (": `%s' JDK1.1(TM) feature", msg);
   java_error_count++;
-  return size_zero_node;
+  return empty_stmt_node;
 }
 
 static int do_warning = 0;
@@ -2214,68 +2458,151 @@ yyerror (msg)
 }
 
 static void
-parse_error (msg)
-     char *msg;
+issue_warning_error_from_context (cl, msg, ap)
+     tree cl;
+     const char *msg;
+     va_list ap;
 {
+  char *saved, *saved_input_filename;
+  char buffer [4096];
+  vsprintf (buffer, msg, ap);
+  force_error = 1;
+
+  ctxp->elc.line = EXPR_WFL_LINENO (cl);
+  ctxp->elc.col  = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 : 
+                   (EXPR_WFL_COLNO (cl) == 0xffe ? -2 : EXPR_WFL_COLNO (cl)));
+
+  /* We have a CL, that's a good reason for using it if it contains data */
+  saved = ctxp->filename;
+  if (TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION && EXPR_WFL_FILENAME_NODE (cl))
+    ctxp->filename = EXPR_WFL_FILENAME (cl);
+  saved_input_filename = input_filename;
+  input_filename = ctxp->filename;
   java_error (NULL);
-  java_error (msg);
+  java_error (buffer);
+  ctxp->filename = saved;
+  input_filename = saved_input_filename;
+  force_error = 0;
 }
 
 /* Issue an error message at a current source line CL */
 
-static void
-parse_error_context VPROTO ((tree cl, char *msg, ...))
+void
+parse_error_context VPROTO ((tree cl, const char *msg, ...))
 {
-#ifndef __STDC__
+#ifndef ANSI_PROTOTYPES
   tree cl;
-  char *msg;
+  const char *msg;
 #endif
-  char buffer [4096];
   va_list ap;
 
   VA_START (ap, msg);
-#ifndef __STDC__
+#ifndef ANSI_PROTOTYPES
   cl = va_arg (ap, tree);
-  msg = va_arg (ap, char *);
+  msg = va_arg (ap, const char *);
 #endif
-  vsprintf (buffer, msg, ap);
-
-  force_error = 1;
-  ctxp->elc.line = EXPR_WFL_LINENO (cl);
-  ctxp->elc.col  = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 : EXPR_WFL_COLNO (cl));
-
-  parse_error (buffer);
-  force_error = 0;
+  issue_warning_error_from_context (cl, msg, ap);
+  va_end (ap);
 }
 
 /* Issue a warning at a current source line CL */
 
 static void
-parse_warning_context VPROTO ((tree cl, char *msg, ...))
+parse_warning_context VPROTO ((tree cl, const char *msg, ...))
 {
-#ifndef __STDC__
+#ifndef ANSI_PROTOTYPES
   tree cl;
-  char *msg;
+  const char *msg;
 #endif
-  char buffer [4096];
   va_list ap;
 
   VA_START (ap, msg);
-#ifndef __STDC__
+#ifndef ANSI_PROTOTYPES
   cl = va_arg (ap, tree);
-  msg = va_arg (ap, char *);
+  msg = va_arg (ap, const char *);
 #endif
-  vsprintf (buffer, msg, ap);
 
   force_error = do_warning = 1;
-  ctxp->elc.line = EXPR_WFL_LINENO (cl);
-  ctxp->elc.col  = (EXPR_WFL_COLNO (cl) == 0xfff ? -1 : EXPR_WFL_COLNO (cl));
-
-  parse_error (buffer);
+  issue_warning_error_from_context (cl, msg, ap);
   do_warning = force_error = 0;
+  va_end (ap);
 }
 
-void
+static tree
+find_expr_with_wfl (node)
+     tree node;
+{
+  while (node)
+    {
+      char code;
+      tree to_return;
+
+      switch (TREE_CODE (node))
+       {
+       case BLOCK:
+         node = BLOCK_EXPR_BODY (node);
+         continue;
+
+       case COMPOUND_EXPR:
+         to_return = find_expr_with_wfl (TREE_OPERAND (node, 0));
+         if (to_return)
+           return to_return;
+         node = TREE_OPERAND (node, 1);
+         continue;
+
+       case LOOP_EXPR:
+         node = TREE_OPERAND (node, 0);
+         continue;
+         
+       case LABELED_BLOCK_EXPR:
+         node = TREE_OPERAND (node, 1);
+         continue;
+
+       default:
+         code = TREE_CODE_CLASS (TREE_CODE (node));
+         if (((code == '1') || (code == '2') || (code == 'e'))
+             && EXPR_WFL_LINECOL (node))
+           return node;
+         return NULL_TREE;
+       }
+    }
+  return NULL_TREE;
+}
+
+/* Issue a missing return statement error. Uses METHOD to figure the
+   last line of the method the error occurs in.  */
+
+static void
+missing_return_error (method)
+     tree method;
+{
+  EXPR_WFL_SET_LINECOL (wfl_operator, DECL_SOURCE_LINE_LAST (method), -2);
+  parse_error_context (wfl_operator, "Missing return statement");
+}
+
+/* Issue an unreachable statement error. From NODE, find the next
+   statement to report appropriately.  */
+static void
+unreachable_stmt_error (node)
+     tree node;
+{
+  /* Browse node to find the next expression node that has a WFL. Use
+     the location to report the error */
+  if (TREE_CODE (node) == COMPOUND_EXPR)
+    node = find_expr_with_wfl (TREE_OPERAND (node, 1));
+  else
+    node = find_expr_with_wfl (node);
+
+  if (node)
+    {
+      EXPR_WFL_SET_LINECOL (wfl_operator, EXPR_WFL_LINENO (node), -2);
+      parse_error_context (wfl_operator, "Unreachable statement");
+    }
+  else
+    fatal ("Can't get valid statement - unreachable_stmt_error");
+}
+
+int
 java_report_errors ()
 {
   if (java_error_count)
@@ -2286,6 +2613,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 *
@@ -2336,8 +2664,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);
 
@@ -2363,18 +2691,18 @@ build_array_from_name (type, type_wfl, name, ret_name)
   /* If we have, then craft a new type for this variable */
   if (more_dims)
     {
-      name = get_identifier (&more_dims [string]);
+      name = get_identifier (&string [more_dims]);
 
-      /* If type already is a reference on an array, get the base type */
-      if ((TREE_CODE (type) == POINTER_TYPE) && 
-         TYPE_ARRAY_P (TREE_TYPE (type)))
-       type = TREE_TYPE (type);
+      /* If we have a pointer, use its type */
+      if (TREE_CODE (type) == POINTER_TYPE)
+        type = TREE_TYPE (type);
 
       /* Building the first dimension of a primitive type uses this
          function */
       if (JPRIMITIVE_TYPE_P (type))
        {
          type = build_java_array_type (type, -1);
+         CLASS_LOADED_P (type) = 1;
          more_dims--;
        }
       /* Otherwise, if we have a WFL for this type, use it (the type
@@ -2406,7 +2734,7 @@ build_unresolved_array_type (type_or_wfl)
 {
   char *ptr;
 
-  /* TYPE_OR_WFL might be an array on a primitive type. In this case,
+  /* TYPE_OR_WFL might be an array on a resolved type. In this case,
      just create a array type */
   if (TREE_CODE (type_or_wfl) == RECORD_TYPE)
     {
@@ -2496,8 +2824,10 @@ check_class_interface_creation (is_interface, flags, raw_name, qualified_name, d
 
       /* Contains OS dependent assumption on path separator. FIXME */
       for (f = &input_filename [strlen (input_filename)]; 
-          f != input_filename && f[0] != '/'; f--);
-      if (f[0] == '/')
+          f != input_filename && f[0] != '/' && f[0] != DIR_SEPARATOR;
+          f--)
+       ;
+      if (f[0] == '/' || f[0] == DIR_SEPARATOR)
        f++;
       if (strncmp (IDENTIFIER_POINTER (raw_name), 
                   f , IDENTIFIER_LENGTH (raw_name)) ||
@@ -2523,9 +2853,7 @@ static tree
 maybe_create_class_interface_decl (decl, qualified_name, cl)
      tree decl, qualified_name, cl;
 {
-  if (decl)
-    DECL_ARTIFICIAL (decl) = 1; /* FIXME */
-  else
+  if (!decl)
     decl = push_class (make_class (), qualified_name);
   
   /* Take care of the file and line business */
@@ -2540,6 +2868,11 @@ maybe_create_class_interface_decl (decl, qualified_name, cl)
   /* Link the declaration to the already seen ones */
   TREE_CHAIN (decl) = ctxp->class_list;
   ctxp->class_list = decl;
+
+  /* Create a new nodes in the global lists */
+  ctxp->gclass_list = tree_cons (NULL_TREE, decl, ctxp->gclass_list);
+  all_class_list = tree_cons (NULL_TREE, decl, all_class_list);
+
   /* Install a new dependency list element */
   create_jdep_list (ctxp);
 
@@ -2562,11 +2895,12 @@ add_superinterfaces (decl, interface_list)
    defined.  */
   for (node = interface_list; node; node = TREE_CHAIN (node))
     {
-      tree current = TREE_PURPOSE (node), interface_decl;
-      if ((interface_decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current))))
+      tree current = TREE_PURPOSE (node);
+      tree idecl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (current));
+      if (idecl && CLASS_LOADED_P (TREE_TYPE (idecl)))
        {
-         if (!parser_check_super_interface (interface_decl, decl, current))
-           parser_add_interface (decl, interface_decl, current);
+         if (!parser_check_super_interface (idecl, decl, current))
+           parser_add_interface (decl, idecl, current);
        }
       else
        register_incomplete_type (JDEP_INTERFACE,
@@ -2596,22 +2930,17 @@ 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 
-      (MODIFIER_WFL (ABSTRACT_TK),
-       "Can't specify both `public' and `abstract' modifiers in the "
-       "definition of interface `%s'", IDENTIFIER_POINTER (raw_name));
 
   /* Create a new decl if DECL is NULL, otherwise fix it */
   decl = maybe_create_class_interface_decl (decl, q_name, id);
 
   /* Set super info and mark the class a complete */
-  set_super_info (ACC_ABSTRACT | ACC_INTERFACE | flags, TREE_TYPE (decl), 
+  set_super_info (ACC_INTERFACE | flags, TREE_TYPE (decl), 
                  object_type_node, ctxp->interface_number);
   ctxp->interface_number = 0;
   CLASS_COMPLETE_P (decl) = 1;
@@ -2634,6 +2963,7 @@ create_class (flags, id, super, interfaces)
 
   class_id = parser_qualified_classname (id);
   decl = IDENTIFIER_CLASS_VALUE (class_id);
+  ctxp->current_parsed_class_un = EXPR_WFL_NODE (id);
   EXPR_WFL_NODE (id) = class_id;
 
   /* Basic check: scope, redefinition, modifiers */
@@ -2661,17 +2991,8 @@ create_class (flags, id, super, interfaces)
          return NULL_TREE;
        }
 
-      /* The class is known and exists if there is a decl. Otherwise,
-         postpone the operation and do it later. */
-      super_decl = IDENTIFIER_CLASS_VALUE (EXPR_WFL_NODE (super));
-      if (super_decl)
-       {
-         parser_check_super (super_decl, decl, id);
-         super_decl_type = TREE_TYPE (super_decl);
-       }
-      else
-       super_decl_type = 
-         register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
+      super_decl_type = 
+       register_incomplete_type (JDEP_SUPER, super, decl, NULL_TREE);
     }
   else if (TREE_TYPE (decl) != object_type_node)
     super_decl_type = object_type_node;
@@ -2686,6 +3007,9 @@ create_class (flags, id, super, interfaces)
   CLASS_COMPLETE_P (decl) = 1;
   add_superinterfaces (decl, interfaces);
 
+  /* Eventually sets the @deprecated tag flag */
+  CHECK_DEPRECATED (decl);
+
   return decl;
 }
 
@@ -2714,7 +3038,11 @@ lookup_field_wrapper (class, name)
      tree class, name;
 {
   tree type = class;
-  return lookup_field (&type, name);
+  tree decl;
+  java_parser_context_save_global ();
+  decl = lookup_field (&type, name);
+  java_parser_context_restore_global ();
+  return decl;
 }
 
 /* Find duplicate field within the same class declarations and report
@@ -2730,12 +3058,18 @@ duplicate_declaration_error_p (new_field_name, new_type, cl)
                          new_field_name);
   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)));
+      char *t1 = strdup (purify_type_name
+                        ((TREE_CODE (new_type) == POINTER_TYPE 
+                          && TREE_TYPE (new_type) == NULL_TREE) ?
+                         IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
+                         lang_printable_name (new_type, 1)));
+      /* The type may not have been completed by the time we report
+        the error */
+      char *t2 = strdup (purify_type_name
+                        ((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),
@@ -2784,12 +3118,12 @@ register_fields (flags, type, variable_list)
   SET_TYPE_FOR_RESOLUTION (type, wfl, must_chain);
 
   /* If TYPE is fully resolved and we don't have a reference, make one */
-  if (!must_chain && TREE_CODE (type) == RECORD_TYPE)
-    type = promote_type (type);
+  PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
 
   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);
@@ -2798,94 +3132,107 @@ 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. */
-      if (type != saved_type && !must_chain 
-         && (TREE_CODE (type) == RECORD_TYPE))
-       type = promote_type (type);
+        a reference if we can and don't have one already. Also
+        change the name if we have an init. */
+      if (type != saved_type)
+       {
+         PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
+         if (init)
+           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 */
+         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. */
       if (must_chain)
        register_incomplete_type (JDEP_FIELD, wfl, field_decl, type);
          
-      /* Default value of a static field is 0 and it is considered
-        initialized. */
-      if (flags & ACC_STATIC)
-       INITIALIZED_P (field_decl) = 1;
-      
       /* If we have an initialization value tied to the field */
       if (init)
        {
          /* The field is declared static */
          if (flags & ACC_STATIC)
            {
-             /* FIXME */
-             if (flags & ACC_FINAL)
-               ;               
-             /* Otherwise, the field should be initialized in
-                <clinit>. This field is remembered so we can
-                generate <clinit> later. */
-             else
-               {
-                 INITIALIZED_P (field_decl) = 1;
-                 TREE_CHAIN (init) = ctxp->static_initialized;
-                 ctxp->static_initialized = init;
-               }
+             /* We include the field and its initialization part into
+                a list used to generate <clinit>. After <clinit> is
+                walked, field initializations will be processed and
+                fields initialized with known constants will be taken
+                out of <clinit> and have their DECL_INITIAL set
+                appropriately. */
+             TREE_CHAIN (init) = ctxp->static_initialized;
+             ctxp->static_initialized = init;
+             DECL_INITIAL (field_decl) = TREE_OPERAND (init, 1);
+             if (TREE_CODE (TREE_OPERAND (init, 1)) == NEW_ARRAY_INIT)
+               TREE_STATIC (TREE_OPERAND (init, 1)) = 1;
            }
-         /* A non-static field declared with an immediate
-            initialization is to be initialized in <init>, if
-            any.  This field is remembered to be processed at the
-            time of the generation of <init>. */
+         /* A non-static field declared with an immediate initialization is
+            to be initialized in <init>, if any.  This field is remembered
+            to be processed at the time of the generation of <init>. */
          else
            {
              TREE_CHAIN (init) = ctxp->non_static_initialized;
              ctxp->non_static_initialized = init;
            }
+         MODIFY_EXPR_FROM_INITIALIZATION_P (init) = 1;
        }
     }
   lineno = saved_lineno;
 }
 
+/* Generate the method $finit$ that initializes fields initialized
+   upon declaration.  */
+
+static void
+maybe_generate_finit ()
+{
+  tree mdecl, current;
+  
+  if (!ctxp->non_static_initialized || java_error_count)
+    return;
+
+  mdecl = create_artificial_method (TREE_TYPE (ctxp->current_parsed_class),
+                                   ACC_PRIVATE, void_type_node,
+                                   finit_identifier_node, end_params_node);
+  start_artificial_method_body (mdecl);
+
+  ctxp->non_static_initialized = nreverse (ctxp->non_static_initialized);
+  for (current = ctxp->non_static_initialized; current;
+       current = TREE_CHAIN (current))
+    java_method_add_stmt (mdecl, 
+                         build_debugable_stmt (EXPR_WFL_LINECOL (current), 
+                                               current));
+
+  end_artificial_method_body (mdecl);
+  CLASS_HAS_FINIT_P (TREE_TYPE (ctxp->current_parsed_class)) = 1;
+  ctxp->non_static_initialized = NULL_TREE;
+}
+
 /* Check whether it is necessary to generate a <clinit> for the class
    we just parsed. */
 
 static void
 maybe_generate_clinit ()
 {
-  int saved_lineno;
-  tree meth, mdecl, c;
-  tree cclass, class_wfl;
+  tree mdecl, c;
 
   if (!ctxp->static_initialized || java_error_count)
     return;
 
-  cclass = TREE_TYPE (ctxp->current_parsed_class);
-  class_wfl = build_expr_wfl (DECL_NAME (TYPE_NAME (cclass)),
-                             input_filename, 0, 0);
-  
-  saved_lineno = lineno;
-  lineno = 0;
-  meth = make_node (FUNCTION_TYPE);
-  TREE_TYPE (meth) = void_type_node;
-  TYPE_ARG_TYPES (meth) = NULL_TREE;
-  mdecl = add_method (cclass, ACC_STATIC, clinit_identifier_node,
-                    build_java_signature (meth));
-  lineno = saved_lineno;
-
-  DECL_SOURCE_LINE (mdecl) = 1;
-  DECL_SOURCE_LINE_MERGE (mdecl, 1);
-  source_start_java_method (mdecl);
-  enter_block ();
+  mdecl = create_artificial_method (TREE_TYPE (ctxp->current_parsed_class),
+                                   ACC_STATIC, void_type_node,
+                                   clinit_identifier_node, end_params_node);
+  start_artificial_method_body (mdecl);
 
   /* Keep initialization in order to enforce 8.5 */
   ctxp->static_initialized = nreverse (ctxp->static_initialized);
@@ -2898,11 +3245,11 @@ maybe_generate_clinit ()
       /* We build the assignment expression that will initialize the
         field to its value. There are strict rules on static
         initializers (8.5). FIXME */
-      java_method_add_stmt (mdecl, c);
+      java_method_add_stmt (mdecl, 
+                           build_debugable_stmt (EXPR_WFL_LINECOL (c), c));
     }
 
-  BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();
-  exit_block ();
+  end_artificial_method_body (mdecl);
   ctxp->static_initialized = NULL_TREE;
 }
 
@@ -2917,7 +3264,8 @@ static int patch_stage;
 /* Check the method declaration and add the method to its current
    class.  If the argument list is known to contain incomplete types,
    the method is partially added and the registration will be resume
-   once the method arguments resolved  */
+   once the method arguments resolved. If TYPE is NULL, we're dealing
+   with a constructor.  */
 
 static tree
 method_header (flags, type, mdecl, throws)
@@ -2927,32 +3275,58 @@ method_header (flags, type, mdecl, throws)
   tree meth = TREE_VALUE (mdecl);
   tree id = TREE_PURPOSE (mdecl);
   tree this_class = TREE_TYPE (ctxp->current_parsed_class);
-  tree meth_name, returned_type, current;
+  tree type_wfl = NULL_TREE;
+  tree meth_name = NULL_TREE, current, orig_arg;
   int saved_lineno;
+  int constructor_ok = 0, must_chain;
   
   check_modifiers_consistency (flags);
   
   /* There are some forbidden modifiers for an abstract method and its
      class must be abstract as well.  */
-  if (flags & ACC_ABSTRACT)
+  if (type && (flags & ACC_ABSTRACT))
     {
       ABSTRACT_CHECK (flags, ACC_PRIVATE, id, "Private");
       ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
       ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
       ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
       ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED,id, "Synchronized");
-      if (!CLASS_ABSTRACT (TYPE_NAME (this_class)))
+      if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
+         && !CLASS_INTERFACE (TYPE_NAME (this_class)))
        parse_error_context 
          (id, "Class `%s' must be declared abstract to define abstract "
           "method `%s'", 
           IDENTIFIER_POINTER (DECL_NAME (ctxp->current_parsed_class)),
           IDENTIFIER_POINTER (EXPR_WFL_NODE (id)));
     }
-
+  /* Things to be checked when declaring a constructor */
+  if (!type)
+    {
+      int ec = java_error_count;
+      /* 8.6: Constructor declarations: we might be trying to define a
+         method without specifying a return type. */
+      if (EXPR_WFL_NODE (id) != ctxp->current_parsed_class_un)
+       parse_error_context 
+         (id, "Invalid method declaration, return type required");
+      /* 8.6.3: Constructor modifiers */
+      else
+       {
+         JCONSTRUCTOR_CHECK (flags, ACC_ABSTRACT, id, "abstract");
+         JCONSTRUCTOR_CHECK (flags, ACC_STATIC, id, "static");
+         JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
+         JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
+         JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
+       }
+      /* If we found error here, we don't consider it's OK to tread
+        the method definition as a constructor, for the rest of this
+        function */
+      if (ec == java_error_count)
+       constructor_ok = 1;
+    }
 
   /* Method declared within the scope of an interface are implicitly
      abstract and public. Conflicts with other erroneously provided
-     modifiers are check right after. */
+     modifiers are checked right after. */
 
   if (CLASS_INTERFACE (TYPE_NAME (this_class)))
     {
@@ -2970,18 +3344,31 @@ method_header (flags, type, mdecl, throws)
   /* Modifiers context reset moved up, so abstract method declaration
      modifiers can be later checked.  */
 
-  meth_name = EXPR_WFL_NODE (id);
-
-  if (unresolved_type_p (type, &returned_type))
+  /* Set constructor returned type to void and method name to <init>,
+     unless we found an error identifier the constructor (in which
+     case we retain the original name) */
+  if (!type)
     {
-      if (returned_type)
-       TREE_TYPE (meth) = returned_type;
-      else 
-       {
-         patch_stage = JDEP_METHOD_RETURN;
-         TREE_TYPE (meth) = 
-           register_incomplete_type (patch_stage, type, id, NULL_TREE);
-       }
+      type = void_type_node;
+      if (constructor_ok)
+       meth_name = init_identifier_node;
+    }
+  else
+    meth_name = EXPR_WFL_NODE (id);
+
+  /* Do the returned type resolution and registration if necessary */
+  SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
+
+  if (meth_name)
+    type = build_array_from_name (type, type_wfl, meth_name, &meth_name);
+  EXPR_WFL_NODE (id) = meth_name;
+  PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
+
+  if (must_chain)
+    {
+      patch_stage = JDEP_METHOD_RETURN;
+      register_incomplete_type (patch_stage, type_wfl, id, type);
+      TREE_TYPE (meth) = GET_REAL_TYPE (type);
     }
   else
     TREE_TYPE (meth) = type;
@@ -2993,6 +3380,9 @@ method_header (flags, type, mdecl, throws)
   lineno = (ctxp->first_ccb_indent1 ? ctxp->first_ccb_indent1 : 
            EXPR_WFL_LINENO (id));
 
+  /* Remember the original argument list */
+  orig_arg = TYPE_ARG_TYPES (meth);
+
   if (patch_stage)             /* includes ret type and/or all args */
     {
       jdep *jdep;
@@ -3008,28 +3398,15 @@ method_header (flags, type, mdecl, throws)
       register_incomplete_type (JDEP_METHOD_END, NULL_TREE, meth, NULL_TREE);
     }
   else
-    {
-      tree signature = build_java_signature (meth);
-      tree arg, orig_arg;
-      /* Save original argument list, including argument's names */
-      orig_arg = TYPE_ARG_TYPES (meth);
-      /* Add the method to its class */
-      meth = add_method (this_class, flags, meth_name, signature);
-      /* Fix the method argument list so we have the argument name
-         information */
-      arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
-      if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
-       {
-         TREE_PURPOSE (arg) = this_identifier_node;
-         arg = TREE_CHAIN (arg);
-       }
-      while (orig_arg)
-        {
-         TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
-         orig_arg = TREE_CHAIN (orig_arg);
-         arg = TREE_CHAIN (arg);
-       }
-    }
+    meth = add_method (this_class, flags, meth_name, 
+                      build_java_signature (meth));
+
+  /* Fix the method argument list so we have the argument name
+     information */
+  fix_method_argument_names (orig_arg, meth);
+
+  /* Register the parameter number and re-install the current line
+     number */
   DECL_MAX_LOCALS (meth) = ctxp->formal_parameter_number+1;
   lineno = saved_lineno;
 
@@ -3055,12 +3432,113 @@ method_header (flags, type, mdecl, throws)
      redefinition error accurately. When method are verified,
      DECL_NAME is reinstalled properly (using the content of the
      WFL node ID) (see check_method_redefinition). We don't do that
-     when Object is being defined. */
+     when Object is being defined. Constructor <init> names will be
+     reinstalled the same way. */
   if (TREE_TYPE (ctxp->current_parsed_class) != object_type_node)
     DECL_NAME (meth) = id;
+
+  /* Set the flag if we correctly processed a constructor */
+  if (constructor_ok)
+    DECL_CONSTRUCTOR_P (meth) = 1;
+
+  /* Eventually set the @deprecated tag flag */
+  CHECK_DEPRECATED (meth);
+
   return meth;
 }
 
+static void
+fix_method_argument_names (orig_arg, meth)
+    tree orig_arg, meth;
+{
+  tree arg = TYPE_ARG_TYPES (TREE_TYPE (meth));
+  if (TREE_CODE (TREE_TYPE (meth)) == METHOD_TYPE)
+    {
+      TREE_PURPOSE (arg) = this_identifier_node;
+      arg = TREE_CHAIN (arg);
+    }
+  while (orig_arg != end_params_node)
+    {
+      TREE_PURPOSE (arg) = TREE_PURPOSE (orig_arg);
+      orig_arg = TREE_CHAIN (orig_arg);
+      arg = TREE_CHAIN (arg);
+    }
+}
+
+/* Complete the method declaration with METHOD_BODY.  */
+
+static void
+complete_method_declaration (method_body)
+     tree method_body;
+{
+  BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)) = method_body;
+  maybe_absorb_scoping_blocks ();
+  /* Exit function's body */
+  exit_block ();
+  /* Merge last line of the function with first line, directly in the
+     function decl. It will be used to emit correct debug info. */
+  DECL_SOURCE_LINE_MERGE (current_function_decl, ctxp->last_ccb_indent1);
+}
+
+/* Build a an error message for constructor circularity errors.  */
+
+static char *
+constructor_circularity_msg (from, to)
+     tree from, to;
+{
+  static char string [4096];
+  char *t = strdup (lang_printable_name (from, 0));
+  sprintf (string, "`%s' invokes `%s'", t, lang_printable_name (to, 0));
+  free (t);
+  return string;
+}
+
+/* Verify a circular call to METH. Return 1 if an error is found, 0
+   otherwise.  */
+
+static int
+verify_constructor_circularity (meth, current)
+     tree meth, current;
+{
+  static tree list = NULL_TREE;
+  tree c;
+  for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
+    {
+      if (TREE_VALUE (c) == meth)
+       {
+         char *t;
+         if (list)
+           {
+             tree liste;
+             list = nreverse (list);
+             for (liste = list; liste; liste = TREE_CHAIN (liste))
+               {
+                 parse_error_context 
+                   (TREE_PURPOSE (TREE_PURPOSE (liste)),
+                    constructor_circularity_msg
+                     (TREE_VALUE (liste), TREE_VALUE (TREE_PURPOSE (liste)))); 
+                 java_error_count--;
+               }
+           }
+         t = strdup (lang_printable_name (meth, 0));
+         parse_error_context (TREE_PURPOSE (c), 
+                              "%s: recursive invocation of constructor `%s'",
+                              constructor_circularity_msg (current, meth), t);
+         free (t);
+         list = NULL_TREE;
+         return 1;
+       }
+    }
+  for (c = DECL_CONSTRUCTOR_CALLS (current); c; c = TREE_CHAIN (c))
+    {
+      list = tree_cons (c, current, list);
+      if (verify_constructor_circularity (meth, TREE_VALUE (c)))
+       return 1;
+      list = TREE_CHAIN (list);
+    }
+  return 0;
+}
+
 /* Check modifiers that can be declared but exclusively */
 
 static void
@@ -3087,8 +3565,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'",
@@ -3124,6 +3601,7 @@ method_declarator (id, list)
       tree name = EXPR_WFL_NODE (wfl_name);
       tree already, arg_node;
       tree type_wfl = NULL_TREE;
+      tree real_type;
 
       /* Obtain a suitable type for resolution, if necessary */
       SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
@@ -3132,6 +3610,14 @@ method_declarator (id, list)
       type = build_array_from_name (type, type_wfl, name, &name);
       EXPR_WFL_NODE (wfl_name) = name;
 
+      real_type = GET_REAL_TYPE (type);
+      if (TREE_CODE (real_type) == RECORD_TYPE)
+       {
+         real_type = promote_type (real_type);
+         if (TREE_CODE (type) == TREE_LIST)
+           TREE_PURPOSE (type) = real_type;
+       }
+
       /* Check redefinition */
       for (already = arg_types; already; already = TREE_CHAIN (already))
        if (TREE_PURPOSE (already) == name)
@@ -3156,13 +3642,13 @@ method_declarator (id, list)
        }
 
       /* The argument node: a name and a (possibly) incomplete type */
-      arg_node = build_tree_list (name, type);
+      arg_node = build_tree_list (name, real_type);
       if (jdep)
        JDEP_GET_PATCH (jdep) = &TREE_VALUE (arg_node);
       TREE_CHAIN (arg_node) = arg_types;
       arg_types = arg_node;
     }
-  TYPE_ARG_TYPES (meth) = nreverse (arg_types);
+  TYPE_ARG_TYPES (meth) = chainon (nreverse (arg_types), end_params_node);
   node = build_tree_list (id, meth);
   return node;
 }
@@ -3274,11 +3760,7 @@ static void
 create_jdep_list (ctxp)
      struct parser_ctxt *ctxp;
 {
-  jdeplist *new = malloc (sizeof (jdeplist));  
-  
-  if (!new)
-    fatal ("Can't alloc jdeplist - create_jdep_list");
-    
+  jdeplist *new = (jdeplist *)xmalloc (sizeof (jdeplist));     
   new->first = new->last = NULL;
   new->next = ctxp->classd_list;
   ctxp->classd_list = new;
@@ -3298,25 +3780,32 @@ reverse_jdep_list (ctxp)
   return prev;
 }
 
-/* Create a fake pointer based on the ID stored in the WFL */
+/* Create a fake pointer based on the ID stored in
+   TYPE_NAME. TYPE_NAME can be a WFL or a incomplete type asking to be
+   registered again. */
 
 static tree
-obtain_incomplete_type (wfl)
-     tree wfl;
+obtain_incomplete_type (type_name)
+     tree type_name;
 {
-  tree ptr;
-  tree name = EXPR_WFL_NODE (wfl);
+  tree ptr, name;
+
+  if (TREE_CODE (type_name) == EXPR_WITH_FILE_LOCATION)
+    name = EXPR_WFL_NODE (type_name);
+  else if (INCOMPLETE_TYPE_P (type_name))
+    name = TYPE_NAME (type_name);
+  else
+    fatal ("invalid type name - obtain_incomplete_type");
 
   for (ptr = ctxp->incomplete_class; ptr; ptr = TREE_CHAIN (ptr))
-    if (TYPE_NAME (TREE_PURPOSE (ptr)) == name)
+    if (TYPE_NAME (ptr) == name)
       break;
 
   if (!ptr)
     {
-      tree core;
       push_obstacks (&permanent_obstack, &permanent_obstack);
-      BUILD_PTR_FROM_NAME (core, name);
-      ptr = build_tree_list (core, NULL_TREE);
+      BUILD_PTR_FROM_NAME (ptr, name);
+      layout_type (ptr);
       pop_obstacks ();
       TREE_CHAIN (ptr) = ctxp->incomplete_class;
       ctxp->incomplete_class = ptr;
@@ -3335,10 +3824,8 @@ register_incomplete_type (kind, wfl, decl, ptr)
      int kind;
      tree wfl, decl, ptr;
 {
-  jdep *new = malloc (sizeof (jdep));
+  jdep *new = (jdep *)xmalloc (sizeof (jdep));
 
-  if (!new)
-    fatal ("Can't allocate new jdep - register_incomplete_type");
   if (!ptr && kind != JDEP_METHOD_END) /* JDEP_METHOD_END is a mere marker */
     ptr = obtain_incomplete_type (wfl);
 
@@ -3387,6 +3874,10 @@ java_check_circular_reference ()
     }
 }
 
+/* safe_layout_class just makes sure that we can load a class without
+   disrupting the current_class, input_file, lineno, etc, information
+   about the class processed currently.  */
+
 void
 safe_layout_class (class)
      tree class;
@@ -3394,11 +3885,12 @@ safe_layout_class (class)
   tree save_current_class = current_class;
   char *save_input_filename = input_filename;
   int save_lineno = lineno;
-  
+
   push_obstacks (&permanent_obstack, &permanent_obstack);
+
   layout_class (class);
   pop_obstacks ();
-  
+
   current_class = save_current_class;
   input_filename = save_input_filename;
   lineno = save_lineno;
@@ -3411,20 +3903,18 @@ jdep_resolve_class (dep)
 {
   tree decl;
 
-  if (!JDEP_RESOLVED_P (dep))
+  if (JDEP_RESOLVED_P (dep))
+    decl = JDEP_RESOLVED_DECL (dep);
+  else
     {
-      decl = 
-       resolve_class (JDEP_TO_RESOLVE (dep), JDEP_DECL (dep), JDEP_WFL (dep));
+      decl = resolve_class (JDEP_TO_RESOLVE (dep), 
+                           JDEP_DECL (dep), JDEP_WFL (dep));
       JDEP_RESOLVED (dep, decl);
     }
-  else
-    decl = JDEP_RESOLVED_DECL (dep);
-
+    
   if (!decl)
-    {
-      complete_class_report_errors (dep);
-      return NULL_TREE;
-    }
+    complete_class_report_errors (dep);
+
   return decl;
 }
 
@@ -3448,7 +3938,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))
@@ -3457,7 +3947,6 @@ java_complete_class ()
       for (dep = CLASSD_FIRST (cclassd); dep; dep = JDEP_CHAIN (dep))
        {
          tree decl;
-
          if (!(decl = jdep_resolve_class (dep)))
            continue;
 
@@ -3482,6 +3971,8 @@ java_complete_class ()
                  field_type = promote_type (field_type);
                pop_obstacks ();
                TREE_TYPE (field_decl) = field_type;
+               DECL_ALIGN (field_decl) = 0;
+               layout_decl (field_decl, 0);
                SOURCE_FRONTEND_DEBUG 
                  (("Completed field/var decl `%s' with `%s'",
                    IDENTIFIER_POINTER (DECL_NAME (field_decl)),
@@ -3551,21 +4042,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:
@@ -3587,8 +4067,22 @@ resolve_class (class_type, decl, cl)
 {
   char *name = IDENTIFIER_POINTER (TYPE_NAME (class_type));
   char *base = name;
-  tree resolved_type, resolved_type_decl;
+  tree resolved_type = TREE_TYPE (class_type);
+  tree resolved_type_decl;
   
+  if (resolved_type != NULL_TREE)
+    {
+      tree resolved_type_decl = TYPE_NAME (resolved_type);
+      if (resolved_type_decl == NULL_TREE
+         || TREE_CODE (resolved_type_decl) == IDENTIFIER_NODE)
+       {
+         resolved_type_decl = build_decl (TYPE_DECL,
+                                          TYPE_NAME (class_type),
+                                          resolved_type);
+       }
+      return resolved_type_decl;
+    }
+
   /* 1- Check to see if we have an array. If true, find what we really
      want to resolve  */
   while (name[0] == '[')
@@ -3619,14 +4113,16 @@ resolve_class (class_type, decl, cl)
       /* Figure how those two things are important for error report. FIXME */
       DECL_SOURCE_LINE (resolved_type_decl) = 0;
       DECL_SOURCE_FILE (resolved_type_decl) = input_filename;
+      TYPE_NAME (class_type) = TYPE_NAME (resolved_type);
     }
+  TREE_TYPE (class_type) = resolved_type;
   return resolved_type_decl;
 }
 
 /* Effectively perform the resolution of class CLASS_TYPE. DECL or CL
    are used to report error messages.  */
 
-static tree
+tree
 do_resolve_class (class_type, decl, cl)
      tree class_type;
      tree decl;
@@ -3644,7 +4140,6 @@ do_resolve_class (class_type, decl, cl)
 
   /* 2- And check for the type in the current compilation unit. If it fails,
      try with a name qualified with the package name if appropriate. */
-
   if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
     {
       if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
@@ -3657,6 +4152,9 @@ do_resolve_class (class_type, decl, cl)
   if (!QUALIFIED_P (TYPE_NAME (class_type)) && ctxp->package)
     TYPE_NAME (class_type) = merge_qualified_name (ctxp->package, 
                                                   TYPE_NAME (class_type));
+#if 1
+  if (!(new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
+    load_class (TYPE_NAME (class_type), 0);
   if ((new_class_decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type))))
     {
       if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
@@ -3664,6 +4162,27 @@ do_resolve_class (class_type, decl, cl)
        load_class (TYPE_NAME (class_type), 0);
       return IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
     }
+#else
+  new_name = TYPE_NAME (class_type);
+  if ((new_class_decl = IDENTIFIER_CLASS_VALUE (new_name)) != NULL_TREE)
+    {
+      if (!CLASS_LOADED_P (TREE_TYPE (new_class_decl)) &&
+          !CLASS_FROM_SOURCE_P (TREE_TYPE (new_class_decl)))
+        load_class (new_name, 0);
+      return IDENTIFIER_CLASS_VALUE (new_name);
+    }
+  else
+    {
+      tree class = read_class (new_name);
+      if (class != NULL_TREE)
+       {
+         tree decl = IDENTIFIER_CLASS_VALUE (new_name);
+         if (decl == NULL_TREE)
+           decl = push_class (class, new_name);
+         return decl;
+       }
+    }
+#endif
   TYPE_NAME (class_type) = original_name;
 
   /* 3- Check an other compilation unit that bears the name of type */
@@ -3686,17 +4205,59 @@ do_resolve_class (class_type, decl, cl)
 }
 
 /* Resolve NAME and lay it out (if not done and if not the current
-   parsed class). Return a decl node.  */
+   parsed class). Return a decl node. This function is meant to be
+   called when type resolution is necessary during the walk pass.  */
 
 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);
-  if (decl && TREE_TYPE (decl) != current_class 
-      && !CLASS_LOADED_P (TREE_TYPE (decl)))
+  tree decl;
+
+  /* Don't do that on the current class */
+  if (something == current_class)
+    return TYPE_NAME (current_class);
+
+  /* Don't do anything for void and other primitive types */
+  if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
+    return NULL_TREE;
+
+  /* Pointer types can be reall pointer types or fake pointers. When
+     finding a real pointer, recheck for primitive types */
+  if (TREE_CODE (something) == POINTER_TYPE)
+    {
+      if (TREE_TYPE (something))
+       {
+         something = TREE_TYPE (something);
+         if (JPRIMITIVE_TYPE_P (something) || something == void_type_node)
+           return NULL_TREE;
+       }
+      else
+       something = TYPE_NAME (something);
+    }
+
+  /* Don't do anything for arrays of primitive types */
+  if (TREE_CODE (something) == RECORD_TYPE && TYPE_ARRAY_P (something)
+      && JPRIMITIVE_TYPE_P (TYPE_ARRAY_ELEMENT (something)))
+    return NULL_TREE;
+
+  /* If something is not and IDENTIFIER_NODE, it can be a a TYPE_DECL
+     or a real TYPE */
+  if (TREE_CODE (something) != IDENTIFIER_NODE)
+    something = (TREE_CODE (TYPE_NAME (something)) == TYPE_DECL ?
+           DECL_NAME (TYPE_NAME (something)) : TYPE_NAME (something));
+
+  if (!(decl = resolve_no_layout (something, cl)))
+    return NULL_TREE;
+
+  /* Resolve and layout if necessary */
+  layout_class_methods (TREE_TYPE (decl));
+  if (CLASS_FROM_SOURCE_P (TREE_TYPE (decl)))
+    CHECK_METHODS (decl);
+  if (TREE_TYPE (decl) != current_class && !CLASS_LOADED_P (TREE_TYPE (decl)))
     safe_layout_class (TREE_TYPE (decl));
+
   return decl;
 }
 
@@ -3716,8 +4277,8 @@ resolve_no_layout (name, cl)
   return decl;
 }
 
-/* Called to report errors. Skip leader '[' in a complex array type
-   description that failed to be resolved. */
+/* Called when reporting errors. Skip leader '[' in a complex array
+   type description that failed to be resolved.  */
 
 static char *
 purify_type_name (name)
@@ -3734,25 +4295,31 @@ static void
 complete_class_report_errors (dep)
      jdep *dep;
 {
+  char *name;
+
+  if (!JDEP_WFL (dep))
+    return;
+
+  name = IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep)));
   switch (JDEP_KIND (dep))
     {
     case JDEP_SUPER:
       parse_error_context  
        (JDEP_WFL (dep), "Superclass `%s' of class `%s' not found",
-        IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
+        purify_type_name (name),
         IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
       break;
     case JDEP_FIELD:
       parse_error_context
        (JDEP_WFL (dep), "Type `%s' not found in declaration of field `%s'",
-        IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
+        purify_type_name (name),
         IDENTIFIER_POINTER (DECL_NAME (JDEP_DECL (dep))));
       break;
     case JDEP_METHOD:          /* Covers arguments */
       parse_error_context
        (JDEP_WFL (dep), "Type `%s' not found in the declaration of the "
         "argument `%s' of method `%s'",
-        IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
+        purify_type_name (name),
         IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))),
         IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_MISC (dep))));
       break;
@@ -3760,7 +4327,7 @@ complete_class_report_errors (dep)
       parse_error_context
        (JDEP_WFL (dep), "Type `%s' not found in the declaration of the "
         "return type of method `%s'", 
-        IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_WFL (dep))),
+        purify_type_name (name),
         IDENTIFIER_POINTER (EXPR_WFL_NODE (JDEP_DECL_WFL (dep))));
       break;
     case JDEP_INTERFACE:
@@ -3797,35 +4364,107 @@ java_check_final ()
 {
 }
 
+/* Return a static string containing the DECL prototype string. If
+   DECL is a constructor, use the class name instead of the form
+   <init> */
+
+static char *
+get_printable_method_name (decl)
+     tree decl;
+{
+  char *to_return;
+  tree name;
+
+  if (DECL_CONSTRUCTOR_P (decl))
+    {
+      name = DECL_NAME (decl);
+      DECL_NAME (decl) = DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)));
+    }
+      
+  to_return = lang_printable_name (decl, 0);
+  if (DECL_CONSTRUCTOR_P (decl))
+    DECL_NAME (decl) = name;
+  
+  return to_return;
+}
+
+/* Reinstall the proper DECL_NAME on METHOD. Return 0 if the method
+   nevertheless needs to be verfied, 1 otherwise.  */
+
 static int
-check_method_redefinition (class, method)
-     tree class, method;
+reset_method_name (method)
+     tree method;
 {
-  tree redef, name;
-  tree cl = DECL_NAME (method);
-  tree sig = TYPE_LANG_SPECIFIC (TREE_TYPE (method))->signature;
-  /* decl name of generated <clinit> doesn't need to be fixed and
-     checked */
-  if (DECL_NAME (method) != clinit_identifier_node)
+  if (DECL_NAME (method) != clinit_identifier_node
+      && DECL_NAME (method) != finit_identifier_node)
     {
       /* NAME is just the plain name when Object is being defined */
-      if (class != object_type_node)
-       name = DECL_NAME (method) = EXPR_WFL_NODE (DECL_NAME (method));
-      else
-       name = DECL_NAME (method);
+      if (DECL_CONTEXT (method) != object_type_node)
+       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;
+
+  /* Explain here why METHOD_DECL doesn't have the DECL_CONSTRUCTUR_P
+     and still can be a constructor. FIXME */
+
+  /* Don't confuse method only bearing the name of their class as
+     constructors */
+  else if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (method_decl))
+          && ctxp
+          && ctxp->current_parsed_class_un == EXPR_WFL_NODE (method_name)
+          && get_access_flags_from_decl (method_decl) <= ACC_PROTECTED
+          && TREE_TYPE (TREE_TYPE (method_decl)) == void_type_node)
+    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 */
+
+static int
+check_method_redefinition (class, method)
+     tree class, method;
+{
+  tree redef, name;
+  tree cl = DECL_NAME (method);
+  tree sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
+  /* decl name of artificial <clinit> and $finit$ doesn't need to be
+     fixed and checked */
+
+  /* Reset the method name before running the check. If it returns 1,
+     the method doesn't need to be verified with respect to method
+     redeclaration and we return 0 */
+  if (reset_method_name (method))
     return 0;
-  
+
+  name = DECL_NAME (method);
   for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
     {
-      struct lang_type *t = TYPE_LANG_SPECIFIC (TREE_TYPE (redef));
-      
-      if (! t || (redef == method))
+      if (redef == method)
        break;
-      if (DECL_NAME (redef) == name && sig == t->signature)
+      if (DECL_NAME (redef) == name 
+         && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef)))
        {
-         parse_error_context (cl, "Duplicate method declaration");
+         parse_error_context 
+           (cl, "Duplicate %s declaration `%s'",
+            (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
+            get_printable_method_name (redef));
          return 1;
        }
     }
@@ -3840,34 +4479,78 @@ static void
 java_check_regular_methods (class_decl)
      tree class_decl;
 {
+  int saw_constructor = 0;
   tree method;
   tree class = CLASS_TO_HANDLE_TYPE (TREE_TYPE (class_decl));
   tree super_class = CLASSTYPE_SUPER (class);
-  int seen_constructor = 0;
+  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));
+  if (!TYPE_NVIRTUALS (class))
+    TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
 
   /* Should take interfaces into account. FIXME */
   for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
     {
-      tree found, sig;
+      tree sig;
       tree method_wfl = DECL_NAME (method);
       int aflags;
 
-     if (DECL_CONSTRUCTOR_P (method))
-       seen_constructor = 1;
+      /* If we previously found something and its name was saved,
+         reinstall it now */
+      if (found && saved_found_wfl)
+       {
+         DECL_NAME (found) = saved_found_wfl;
+         saved_found_wfl = NULL_TREE;
+       }
 
       /* Check for redefinitions */
       if (check_method_redefinition (class, method))
        continue;
 
-      sig = build_java_argument_signature (TREE_TYPE (method));
+      /* If we see one constructor a mark so we don't generate the
+        default one. Also skip other verifications: constructors
+        can't be inherited hence hiden or overriden */
+     if (DECL_CONSTRUCTOR_P (method))
+       {
+        saw_constructor = 1;
+        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);
 
-      /* Nothing overrides or it's a private method */
-      if (!found || (found && METHOD_PRIVATE (found)))
-        continue;
+      /* Nothing overrides or it's a private method. */
+      if (!found)
+       continue;
+      if (METHOD_PRIVATE (found))
+       {
+         found = NULL_TREE;
+         continue;
+       }
+
+      /* If found wasn't verified, it's DECL_NAME won't be set properly. 
+        We set it temporarily for the sake of the error report. */
+      saved_found_wfl = DECL_NAME (found);
+      reset_method_name (found);
+
       /* Can't override a method with the same name and different return
         types. */
       if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
@@ -3911,19 +4594,27 @@ java_check_regular_methods (class_decl)
               (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
          continue;
        }
-      /* Overriding/hiding public must be public or
-        overriding/hiding protected must be protected or public */
-      if ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method)) ||
-         (METHOD_PROTECTED (found) 
-          && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method))))
+
+      aflags = get_access_flags_from_decl (found);
+      /* - Overriding/hiding public must be public
+        - Overriding/hiding protected must be protected or public
+         - If the overriden or hidden method has default (package)
+           access, then the overriding or hiding method must not be
+           private; otherwise, a compile-time error occurs */
+      if ((METHOD_PUBLIC (found) && !METHOD_PUBLIC (method)) 
+         || (METHOD_PROTECTED (found) 
+             && !(METHOD_PUBLIC (method) || METHOD_PROTECTED (method)))
+         || (!(aflags & (ACC_PUBLIC | ACC_PRIVATE | ACC_STATIC))
+             && METHOD_PRIVATE (method)))
        {
          parse_error_context 
            (method_wfl,
             "Methods can't be overridden to be more private. Method `%s' is "
-            "%s in class `%s'", lang_printable_name (found, 0),
-            (METHOD_PUBLIC (found) ? "public" : "protected"),
-            IDENTIFIER_POINTER 
-              (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
+            "not %s in class `%s'", lang_printable_name (method, 0),
+            (METHOD_PUBLIC (method) ? "public" : 
+             (METHOD_PRIVATE (method) ? "private" : "protected")),
+            IDENTIFIER_POINTER (DECL_NAME 
+                                (TYPE_NAME (DECL_CONTEXT (found)))));
          continue;
        }
 
@@ -3933,10 +4624,12 @@ java_check_regular_methods (class_decl)
 
       /* 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 */
-      aflags = get_access_flags_from_decl (found);
-      if ((!aflags || (aflags > ACC_PROTECTED))
-         && !class_in_current_package (DECL_CONTEXT (found)))
+        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))
+         && flag_not_overriding)
        parse_warning_context 
          (method_wfl, "Method `%s' in class `%s' does not "
           "override the corresponding method in class `%s', which is "
@@ -3945,25 +4638,37 @@ java_check_regular_methods (class_decl)
           IDENTIFIER_POINTER (DECL_NAME (class_decl)),
           IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
 
-      /* Check on (default) package access. FIXME.  */
       /* Inheriting multiple methods with the same signature. FIXME */
     }
   
-  TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
+  /* Don't forget eventual pending found and saved_found_wfl. Take
+     into account that we might have exited because we saw an
+     aritifical method as the last entry. */
+
+  if (found && !DECL_ARTIFICIAL (found) && saved_found_wfl)
+    DECL_NAME (found) = saved_found_wfl;
 
-  if (!seen_constructor)
+  if (!TYPE_NVIRTUALS (class))
+    TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
+
+  if (!saw_constructor)
     {
-      /* No constructor seen, we craft one, at line 0 */
-      int saved_lineno = lineno;
-      tree meth, decl;
-      lineno = 0;
-      meth = make_node (FUNCTION_TYPE);
-      TREE_TYPE (meth) = void_type_node;
-      TYPE_ARG_TYPES (meth) = NULL_TREE; 
-      decl = add_method (class, 0, init_identifier_node,
-                        build_java_signature (meth));
+      /* No constructor seen, we craft one, at line 0. Since this
+       operation takes place after we laid methods out
+       (layout_class_methods), we prepare the its DECL
+       appropriately. */
+      int flags;
+      tree decl;
+
+      /* If the class is declared PUBLIC, the default constructor is
+         PUBLIC otherwise it has default access implied by no access
+         modifiers. */
+      flags = (get_access_flags_from_decl (class_decl) & ACC_PUBLIC ?
+              ACC_PUBLIC : 0);
+      decl = create_artificial_method (class, flags, void_type_node, 
+                                      init_identifier_node, end_params_node);
       DECL_CONSTRUCTOR_P (decl) = 1;
-      lineno = saved_lineno;
+      layout_class_method (TREE_TYPE (class_decl), NULL_TREE, decl, NULL_TREE);
     }
 }
 
@@ -3976,11 +4681,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); 
@@ -4004,11 +4713,12 @@ check_throws_clauses (method, method_wfl, found)
 /* Check abstract method of interface INTERFACE */
 
 static void
-java_check_abstract_methods (interface)
-     tree interface;
+java_check_abstract_methods (interface_decl)
+     tree interface_decl;
 {
   int i, n;
   tree method, basetype_vec, found;
+  tree interface = TREE_TYPE (interface_decl);
 
   for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
     {
@@ -4023,16 +4733,20 @@ java_check_abstract_methods (interface)
       found = lookup_java_interface_method2 (interface, method);
       if (found)
        {
-         char *t = strdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)),
-                                                0));
+         char *t;
+         tree saved_found_wfl = DECL_NAME (found);
+         reset_method_name (found);
+         t = strdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
          parse_error_context 
            (method_wfl,
-            "Method `%s' was defined with return type `%s' in class `%s ",
+            "Method `%s' was defined with return type `%s' in class `%s'",
             lang_printable_name (found, 0), t,
             IDENTIFIER_POINTER 
               (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
          free (t);
          continue;
+         
+         DECL_NAME (found) = saved_found_wfl;
        }
     }
 
@@ -4054,41 +4768,27 @@ java_check_abstract_methods (interface)
          found = lookup_java_interface_method2 (interface, 
                                                 sub_interface_method);
          if (found && (found != sub_interface_method))
-           parse_error_context 
-             (lookup_cl (sub_interface_method),
-              "Interface `%s' inherits method `%s' from interface `%s'. This "
-              "method is redefined with a different return "
-              "type in interface `%s'",
-              IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
-              lang_printable_name (found, 0),
-              IDENTIFIER_POINTER 
-                (DECL_NAME (TYPE_NAME (DECL_CONTEXT (sub_interface_method)))),
-              IDENTIFIER_POINTER 
-                (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
+           {
+             tree saved_found_wfl = DECL_NAME (found);
+             reset_method_name (found);
+             parse_error_context 
+               (lookup_cl (sub_interface_method),
+                "Interface `%s' inherits method `%s' from interface `%s'. "
+                "This method is redefined with a different return type in "
+                "interface `%s'",
+                IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (interface))),
+                lang_printable_name (found, 0),
+                IDENTIFIER_POINTER 
+                  (DECL_NAME (TYPE_NAME 
+                              (DECL_CONTEXT (sub_interface_method)))),
+                IDENTIFIER_POINTER 
+                  (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
+             DECL_NAME (found) = saved_found_wfl;
+           }
        }
     }
 }
 
-/* Check the method on all the defined classes. Should be done to the
-   classes declared in the compilation unit only. FIXME  */
-
-void
-java_check_methods ()
-{
-
-  tree current;
-  for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
-    if (CLASS_FROM_SOURCE_P (TREE_TYPE (current)))
-      {
-       tree class = CLASS_TO_HANDLE_TYPE (TREE_TYPE (current));
-
-       if (CLASS_INTERFACE (TYPE_NAME (class)))
-         java_check_abstract_methods (class);
-       else
-         java_check_regular_methods (current);
-      }
-}
-
 /* Lookup methods in interfaces using their name and partial
    signature. Return a matching method only if their types differ.  */
 
@@ -4130,9 +4830,12 @@ lookup_java_method2 (clas, method_decl, do_interface)
      tree clas, method_decl;
      int do_interface;
 {
-  tree method, method_signature, method_name, method_type;
+  tree method, method_signature, method_name, method_type, name;
+
   method_signature = build_java_argument_signature (TREE_TYPE (method_decl));
-  method_name = DECL_NAME (method_decl);
+  name = DECL_NAME (method_decl);
+  method_name = (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ? 
+                EXPR_WFL_NODE (name) : name);
   method_type = TREE_TYPE (TREE_TYPE (method_decl));
 
   while (clas != NULL_TREE)
@@ -4141,12 +4844,12 @@ lookup_java_method2 (clas, method_decl, do_interface)
           method != NULL_TREE;  method = TREE_CHAIN (method))
        {
          tree method_sig = build_java_argument_signature (TREE_TYPE (method));
-         if (DECL_NAME (method) == method_name 
+         tree name = DECL_NAME (method);
+         if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
+              EXPR_WFL_NODE (name) : name) == method_name
              && method_sig == method_signature 
              && TREE_TYPE (TREE_TYPE (method)) != method_type)
-           {
-             return method;
-           }
+           return method;
        }
       clas = (do_interface ? NULL_TREE : CLASSTYPE_SUPER (clas));
     }
@@ -4235,104 +4938,134 @@ find_in_imports (class_type)
       {
        TYPE_NAME (class_type) = EXPR_WFL_NODE (TREE_PURPOSE (import));
        QUALIFIED_P (TYPE_NAME (class_type)) = 1;
-       return check_pkg_class_access (TYPE_NAME (class_type), 
-                                      TREE_PURPOSE (import));
       }
   return 0;
 }
 
-/* Process a import on demand statement (lazy) */
-
 static int
-read_import_entry (jcf, dirp, returned_name)
-     JCF *jcf;
-     DIR *dirp;
-     char **returned_name;
+note_possible_classname (name, len)
+     char *name;
+     int len;
 {
-  if (dirp)
-    {
-      struct dirent *direntp = readdir (dirp);
-      if (!direntp)
-       {
-         *returned_name = NULL;
-         return 0;
-       }
-      else
-       {
-         *returned_name = direntp->d_name;
-         return (strlen (direntp->d_name));
-       }
-    }
+  tree node;
+  if (len > 5 && strncmp (&name [len-5], ".java", 5) == 0)
+    len = len - 5;
+  else if (len > 6 && strncmp (&name [len-6], ".class", 6) == 0)
+    len = len - 6;
   else
-    {
-      int current_dir_len = strlen (jcf->classname);
-      char *current_entry;
-      int current_entry_len;
+    return 0;
+  node = ident_subst (name, len, "", '/', '.', "");
+  IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
+  QUALIFIED_P (node) = 1; /* As soon as we turn / into . */
+  return 1;
+}
 
-      /* Here we read a zip directory as a file directory. The files
-        we're selecting must have the same root than the directory
-        we're examining. */
+/* Read a import directory, gathering potential match for further type
+   references. Indifferently reads a filesystem or a ZIP archive
+   directory.  */
 
-      ZipDirectory *zipd = (ZipDirectory *)jcf->zipd; 
+static void
+read_import_dir (wfl)
+     tree wfl;
+{
+  tree package_id = EXPR_WFL_NODE (wfl);
+  char *package_name = IDENTIFIER_POINTER (package_id);
+  int package_length = IDENTIFIER_LENGTH (package_id);
+  DIR *dirp = NULL;
+  JCF *saved_jcf = current_jcf;
 
-      while (zipd)
+  int found = 0;
+  int k;
+  void *entry;
+  struct buffer filename[1];
+
+
+  if (IS_AN_IMPORT_ON_DEMAND_P (package_id))
+    return;
+  IS_AN_IMPORT_ON_DEMAND_P (package_id) = 1;
+
+  BUFFER_INIT (filename);
+  buffer_grow (filename, package_length + 100);
+
+  for (entry = jcf_path_start (); entry != NULL; entry = jcf_path_next (entry))
+    {
+      char *entry_name = jcf_path_name (entry);
+      int entry_length = strlen (entry_name);
+      if (jcf_path_is_zipfile (entry))
        {
-         current_entry = ZIPDIR_FILENAME (zipd);
-         current_entry_len = zipd->filename_length;
-         while (current_entry_len && current_entry [current_entry_len] != '/')
-           current_entry_len--;
-         /* If the path of the current file doesn't match the directory we're
-            scanning, that the end of the search */
-         current_entry_len++;
-         if (strncmp (jcf->classname, current_entry, current_dir_len))
+         ZipFile *zipf;
+         buffer_grow (filename, entry_length);
+         memcpy (filename->data, entry_name, entry_length - 1);
+         filename->data[entry_length-1] = '\0';
+         zipf = opendir_in_zip (filename->data, jcf_path_is_system (entry));
+         if (zipf == NULL)
+           error ("malformed .zip archive in CLASSPATH: %s", entry_name);
+         else
            {
-             *returned_name = NULL;
-             return 0;
+             ZipDirectory *zipd = (ZipDirectory *) zipf->central_directory;
+             BUFFER_RESET (filename);
+             for (k = 0; k < package_length; k++)
+               {
+                 char ch = package_name[k];
+                 *filename->ptr++ = ch == '.' ? '/' : ch;
+               }
+             *filename->ptr++ = '/';
+
+             for (k = 0; k < zipf->count;  k++, zipd = ZIPDIR_NEXT (zipd))
+               {
+                 char *current_entry = ZIPDIR_FILENAME (zipd);
+                 int current_entry_len = zipd->filename_length;
+
+                 if (current_entry_len >= BUFFER_LENGTH (filename)
+                     && strncmp (filename->data, current_entry, 
+                                 BUFFER_LENGTH (filename)) != 0)
+                   continue;
+                 found |= note_possible_classname (current_entry,
+                                                   current_entry_len);
+               }
            }
-         /* Ok, we have at least the same path. The position of the last '/'
-            of the current file we're examining should match the size of
-            name of the directory we're browsing, otherwise that an entry
-            belonging to a sub directory, we want to skip it. */
-         if (current_entry_len != current_dir_len)
-           zipd = ZIPDIR_NEXT (zipd);
-         else
+       }
+      else
+       {
+         BUFFER_RESET (filename);
+         buffer_grow (filename, entry_length + package_length + 4);
+         strcpy (filename->data, entry_name);
+         filename->ptr = filename->data + entry_length;
+         for (k = 0; k < package_length; k++)
+           {
+             char ch = package_name[k];
+             *filename->ptr++ = ch == '.' ? '/' : ch;
+           }
+         *filename->ptr = '\0';
+
+         dirp = opendir (filename->data);
+         if (dirp == NULL)
+           continue;
+         *filename->ptr++ = '/';
+         for (;;)
            {
-             jcf->zipd = ZIPDIR_NEXT (zipd); /* Prepare next read */
-             *returned_name = &current_entry [current_entry_len];
-             return (zipd->filename_length - current_entry_len);
+             int len; 
+             char *d_name;
+             struct dirent *direntp = readdir (dirp);
+             if (!direntp)
+               break;
+             d_name = direntp->d_name;
+             len = strlen (direntp->d_name);
+             buffer_grow (filename, len+1);
+             strcpy (filename->ptr, d_name);
+             found |= note_possible_classname (filename->data + entry_length,
+                                               package_length+len+1);
            }
+         if (dirp)
+           closedir (dirp);
        }
-      *returned_name = NULL;
-      return 0;
     }
-}
-
-/* Read a import directory, gathering potential match for further type
-   references. Indifferently reads a filesystem or a ZIP archive
-   directory.  */
-
-static void
-read_import_dir (wfl)
-     tree wfl;
-{
-  char *name = IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl));
-  int name_len = IDENTIFIER_LENGTH (EXPR_WFL_NODE (wfl)), reclen;
-  DIR *dirp = NULL;
-  JCF jcfr, *jcf, *saved_jcf = current_jcf;
-  char *founddirname, *d_name;
 
-  jcf = &jcfr;
-  if (!(founddirname = find_class (name, name_len, jcf, 0)))
-    fatal ("Can't import `%s'", name);
-  if (jcf->outofsynch)
-    jcf_out_of_synch (jcf);
-  if (jcf->seen_in_zip)
-    jcf->zipd = ZIPDIR_NEXT ((ZipDirectory *)jcf->zipd);
+  free (filename->data);
 
-  else if (founddirname)
-    dirp = opendir (founddirname);
-
-  if (!founddirname && !dirp)
+  /* Here we should have a unified way of retrieving an entry, to be
+     indexed. */
+  if (!found)
     {
       static int first = 1;
       if (first)
@@ -4340,55 +5073,17 @@ read_import_dir (wfl)
          char buffer [256];
          sprintf (buffer, "Can't find default package `%s'. Check "
                   "the CLASSPATH environment variable and the access to the "
-                  "archives.", name);
+                  "archives.", package_name);
          error (buffer);
          java_error_count++;
          first = 0;
        }
       else
-       parse_error_context (wfl, "Package `%s' not found in import", name);
+       parse_error_context (wfl, "Package `%s' not found in import",
+                            package_name);
       current_jcf = saved_jcf;
       return;
     }
-
-  /* Here we should have a unified way of retrieving an entry, to be
-     indexed. */
-  while ((reclen = read_import_entry (jcf, dirp, &d_name)))
-    {
-      int java_or_class = 0;
-      int len; 
-      if ((reclen > 5) 
-         && !strcmp (&d_name [reclen-5], ".java"))
-       {
-         java_or_class = 1;
-         len = reclen - 5;
-       }
-         
-      if (!java_or_class && (reclen > 6) &&
-         !strcmp (&d_name [reclen-6], ".class"))
-       {
-         java_or_class = 2;
-         len = reclen - 6;
-       }
-
-      if (java_or_class)
-       {
-         char *id_name;
-         tree node;
-
-         obstack_grow (&temporary_obstack, name, name_len);
-         obstack_1grow (&temporary_obstack, '/');
-         obstack_grow0 (&temporary_obstack, d_name, len);
-         id_name = obstack_finish (&temporary_obstack);
-
-         node = get_identifier (id_name);
-         IS_A_CLASSFILE_NAME (node) = 1; /* Or soon to be */
-         QUALIFIED_P (node) = 1; /* As soon as we turn / into . */
-       }
-    }
-  if (dirp)
-    closedir (dirp);
-  
   current_jcf = saved_jcf;
 }
 
@@ -4410,7 +5105,7 @@ find_in_imports_on_demand (class_type)
       obstack_grow (&temporary_obstack, 
                    IDENTIFIER_POINTER (EXPR_WFL_NODE (TREE_PURPOSE (import))),
                    IDENTIFIER_LENGTH (EXPR_WFL_NODE (TREE_PURPOSE (import))));
-      obstack_1grow (&temporary_obstack, '/');
+      obstack_1grow (&temporary_obstack, '.');
       obstack_grow0 (&temporary_obstack, 
                     IDENTIFIER_POINTER (TYPE_NAME (class_type)),
                     IDENTIFIER_LENGTH (TYPE_NAME (class_type)));
@@ -4443,9 +5138,7 @@ find_in_imports_on_demand (class_type)
       tree decl;
       int saved_lineno = lineno;
       lineno = EXPR_WFL_LINENO (cl);
-      TYPE_NAME (class_type) = ident_subst (IDENTIFIER_POINTER (node_to_use),
-                                           IDENTIFIER_LENGTH (node_to_use),
-                                           "", '/', '.', "");
+      TYPE_NAME (class_type) = node_to_use;
       QUALIFIED_P (TYPE_NAME (class_type)) = 1;
       decl = IDENTIFIER_CLASS_VALUE (TYPE_NAME (class_type));
       /* If there is no DECL set for the class or if the class isn't
@@ -4460,6 +5153,49 @@ find_in_imports_on_demand (class_type)
     return (seen_once < 0 ? 0 : seen_once); /* It's ok not to have found */
 }
 
+static tree
+resolve_package (pkg, next)
+     tree pkg, *next;
+{
+  tree type_name = NULL_TREE;
+  char *name = IDENTIFIER_POINTER (EXPR_WFL_NODE (pkg));
+
+  /* The trick is to determine when the package name stops and were
+     the name of something contained in the package starts. Then we
+     return a fully qualified name of what we want to get. */
+
+  /* Do a quick search on well known package names */
+  if (!strncmp (name, "java.lang.reflect", 17))
+    {
+      *next = 
+       TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg))));
+      type_name = lookup_package_type (name, 17);
+    }
+  else if (!strncmp (name, "java.lang", 9))
+    {
+      *next = TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg)));
+      type_name = lookup_package_type (name, 9);
+    }
+  else
+    return NULL_TREE;          /* FIXME, search all imported packages. */
+
+  return type_name;
+}
+
+static tree
+lookup_package_type (name, from)
+     char *name;
+     int from;
+{
+  char subname [128];
+  char *sub = &name[from+1];
+  while (*sub != '.' && *sub)
+    sub++;
+  strncpy (subname, name, sub-name);
+  subname [sub-name] = '\0';
+  return get_identifier (subname);
+}
+
 /* Check that CLASS_NAME refers to a PUBLIC class. Return 0 if no
    access violations were found, 1 otherwise.  */
 
@@ -4478,6 +5214,13 @@ check_pkg_class_access (class_name, cl)
 
   if (!CLASS_PUBLIC (TYPE_NAME (type)))
     {
+      /* Access to a private class within the same package is
+         allowed. */
+      tree l, r;
+      breakdown_qualified (&l, &r, class_name);
+      if (l == ctxp->package)
+       return 0;
+
       parse_error_context 
        (cl, "Can't access %s `%s'. Only public classes and interfaces in "
         "other packages can be accessed",
@@ -4500,7 +5243,7 @@ declare_local_variables (modifier, type, vlist)
   tree type_wfl = NULL_TREE;
   int must_chain = 0;
 
-  /* Push a new block if statement were seen between the last time we
+  /* Push a new block if statements were seen between the last time we
      pushed a block and now. Keep a cound of block to close */
   if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (current_function_decl)))
     {
@@ -4513,12 +5256,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
@@ -4527,14 +5278,13 @@ declare_local_variables (modifier, type, vlist)
   SET_TYPE_FOR_RESOLUTION (type, type_wfl, must_chain);
 
   /* If TYPE is fully resolved and we don't have a reference, make one */
-  if (!must_chain && TREE_CODE (type) == RECORD_TYPE)
-    type = promote_type (type);
+  PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
 
   /* Go through all the declared variables */
   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);
@@ -4553,13 +5303,12 @@ declare_local_variables (modifier, type, vlist)
       /* 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. */
-      if (type != saved_type && !must_chain 
-         && (TREE_CODE (type) == RECORD_TYPE))
-       type = promote_type (type);
-      
+      PROMOTE_RECORD_IF_COMPLETE (type, must_chain);
+
+      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 */
@@ -4604,19 +5353,19 @@ source_start_java_method (fndecl)
   /* New scope for the function */
   enter_block ();
   for (tem = TYPE_ARG_TYPES (TREE_TYPE (fndecl)), i = 0;
-       tem != NULL_TREE; tem = TREE_CHAIN (tem), i++)
+       tem != end_params_node; tem = TREE_CHAIN (tem), i++)
     {
       tree type = TREE_VALUE (tem);
       tree name = TREE_PURPOSE (tem);
       
-      /* If type is incomplete. Layout can't take place
-        now. Create an incomplete decl and ask for the decl to be
-        patched later */
+      /* If type is incomplete. Create an incomplete decl and ask for
+        the decl to be patched later */
       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);
+         type = obtain_incomplete_type (type);
          register_incomplete_type (JDEP_PARM, NULL_TREE, NULL_TREE, type);
          jdep = CLASSD_LAST (ctxp->classd_list);
          JDEP_MISC (jdep) = name;
@@ -4633,6 +5382,47 @@ source_start_java_method (fndecl)
   DECL_ARG_SLOT_COUNT (current_function_decl) = i;
 }
 
+/* Called during parsing. Creates an artificial method declaration.  */
+
+static tree
+create_artificial_method (class, flags, type, name, args)
+     tree class;
+     int flags;
+     tree type, name, args;
+{
+  int saved_lineno = lineno;                                       
+  tree mdecl;
+
+  lineno = 0;                                                              
+  mdecl = make_node (FUNCTION_TYPE);                               
+  TREE_TYPE (mdecl) = type;
+  TYPE_ARG_TYPES (mdecl) = args;
+  mdecl = add_method (class, flags, name, build_java_signature (mdecl)); 
+  lineno = saved_lineno;                                                   
+  DECL_ARTIFICIAL (mdecl) = 1;                                     
+  return mdecl;
+}
+
+/* Starts the body if an artifical method.  */
+
+static void
+start_artificial_method_body (mdecl)
+     tree mdecl;
+{
+  DECL_SOURCE_LINE (mdecl) = 1;
+  DECL_SOURCE_LINE_MERGE (mdecl, 1);
+  source_start_java_method (mdecl);
+  enter_block ();
+}
+
+static void
+end_artificial_method_body (mdecl)
+     tree mdecl;
+{
+  BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = exit_block ();
+  exit_block ();
+}
+
 /* Called during expansion. Push decls formerly built from argument
    list so they're usable during expansion. */
 
@@ -4660,7 +5450,6 @@ expand_start_java_method (fndecl)
       DECL_ARG_TYPE (tem) = type;
       layout_decl (tem, 0);
       pushdecl (tem);
-      INITIALIZED_P (tem) = 1; /* Parms are initialized */
       *ptr = tem;
       ptr = &TREE_CHAIN (tem);
       tem = next;
@@ -4668,7 +5457,6 @@ expand_start_java_method (fndecl)
   *ptr = NULL_TREE;
   pushdecl_force_head (DECL_ARGUMENTS (fndecl));
   lineno = DECL_SOURCE_LINE_FIRST (fndecl);
-  complete_start_java_method (fndecl); 
 }
 
 /* Terminate a function and expand its body.  */
@@ -4745,39 +5533,103 @@ static tree
 add_stmt_to_compound (existing, type, stmt)
      tree existing, type, stmt;
 {
-  tree node;
-
-  if (existing && (TREE_CODE (existing) == COMPOUND_EXPR)
-      && TREE_OPERAND (existing, 1) == size_zero_node)
-    {
-      TREE_OPERAND (existing, 1) = stmt;
-      TREE_TYPE (existing) = type;
-      return existing;
-    }
-  else if (existing)
-    node = build (COMPOUND_EXPR, type, existing, stmt);
+  if (existing)
+    return build (COMPOUND_EXPR, type, existing, stmt);
   else
-    node = build (COMPOUND_EXPR, type, stmt, size_zero_node);
-  
-  return node;
+    return stmt;
 }
 
 /* Hold THIS for the scope of the current public method decl.  */
 static tree current_this;
 
-/* Layout all class found during parsing */
+void java_layout_seen_class_methods ()
+{
+  tree previous_list = all_class_list;
+  tree end = NULL_TREE;
+  tree current;
+
+  while (1)
+    {
+      for (current = previous_list; 
+          current != end; current = TREE_CHAIN (current))
+       layout_class_methods (TREE_TYPE (TREE_VALUE (current)));
+      
+      if (previous_list != all_class_list)
+       {
+         end = previous_list;
+         previous_list = all_class_list;
+       }
+      else
+       break;
+    }
+}
+
+/* Layout the methods of all classes loaded in one way on an
+   other. Check methods of source parsed classes. Then reorder the
+   fields and layout the classes or the type of all source parsed
+   classes */
 
 void
 java_layout_classes ()
 {
   tree current;
-  for (current = ctxp->class_list; current; current = TREE_CHAIN (current))
+  int save_error_count = java_error_count;
+
+  /* Layout the methods of all classes seen so far */
+  java_layout_seen_class_methods ();
+  java_parse_abort_on_error ();
+  all_class_list = NULL_TREE;
+
+  /* Then check the methods of all parsed classes */
+  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));
+  java_parse_abort_on_error ();
+
+  for (current = ctxp->gclass_list; current; current = TREE_CHAIN (current))
     {
-      current_class = TREE_TYPE (current);
-      TYPE_FIELDS (current_class) = nreverse (TYPE_FIELDS (current_class));
-      if (!TYPE_SIZE (current_class))
-       safe_layout_class (current_class);
+      current_class = TREE_TYPE (TREE_VALUE (current));
+
+      /* 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)
+      {
+       /* If the dummy field is there, reverse the right fields and
+          just layout the type for proper fields offset */
+       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);
+         }
+       /* We don't have a dummy field, we need to layout the class,
+           after having reversed the fields */
+       else
+         {
+           TYPE_FIELDS (current_class) = 
+             nreverse (TYPE_FIELDS (current_class));
+           TYPE_SIZE (current_class) = NULL_TREE;
+           layout_class (current_class);
+         }
+      }
+      else
+       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;
     }
+
+  /* We might have reloaded classes durign the process of laying out
+     classes for code generation. We must layout the methods of those
+     late additions, as constructor checks might use them */
+  java_layout_seen_class_methods ();
+  java_parse_abort_on_error ();
 }
 
 /* Expand all methods in all registered classes.  */
@@ -4797,6 +5649,16 @@ java_complete_expand_methods ()
       /* Initialize a new constant pool */
       init_outgoing_cpool ();
 
+      /* We want <clinit> (if any) to be processed first. */
+      decl = tree_last (TYPE_METHODS (class_type));
+      if (decl && DECL_NAME (decl) == clinit_identifier_node)
+       {
+         tree list = nreverse (TYPE_METHODS (class_type));
+         list = TREE_CHAIN (list);
+         TREE_CHAIN (decl) = NULL_TREE;
+         TYPE_METHODS (class_type) = chainon (decl, nreverse (list));
+       }
+
       /* Don't process function bodies in interfaces */
       if (!CLASS_INTERFACE (TYPE_NAME (current_class)))
        for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
@@ -4815,18 +5677,28 @@ java_complete_expand_methods ()
                    restore_line_number_status (0);
                  }
              }
-           else
+           else if (METHOD_ABSTRACT (decl) || METHOD_NATIVE (decl))
+             continue;
+           else 
              java_complete_expand_method (decl);
          }
 
+      /* Now verify constructor circularity (stop after the first one
+         we find) */
+      if (!CLASS_INTERFACE (TYPE_NAME (current_class)))
+       for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl))
+         if (DECL_CONSTRUCTOR_P (decl) && 
+             verify_constructor_circularity (decl, decl))
+           break;
+
       /* Make the class data, register it and run the rest of decl
          compilation on it */
-      if (!java_error_count && ! flag_emit_class_files)
+      if (!java_error_count)
        {
-         make_class_data (current_class);
-         register_class ();
-         rest_of_decl_compilation (TYPE_NAME (current_class), 
-                                   (char*) 0, 1, 0);
+         if (flag_emit_class_files)
+           write_classfile (current_class);
+         else if (! flag_syntax_only)
+           finish_class (current_class);
        }
     }
 }
@@ -4841,54 +5713,17 @@ static void
 java_complete_expand_method (mdecl)
      tree mdecl;
 {
-  int no_ac_found = 1;
-
-  /* We generate some code for an empty constructor */
-  if (DECL_CONSTRUCTOR_P (mdecl) && !DECL_FUNCTION_BODY (mdecl))
-    {
-      tree arg_list, func, call;
-      tree method_type = TREE_TYPE (mdecl);
-      tree class_type = CLASS_TO_HANDLE_TYPE (current_class);
-      tree self_type = (CLASSTYPE_SUPER (class_type) ? 
-                       CLASSTYPE_SUPER (class_type) : class_type);
-      tree method_signature = 
-       TYPE_LANG_SPECIFIC (method_type)->signature;
-      tree method = 
-       lookup_java_constructor (CLASS_TO_HANDLE_TYPE (self_type),
-                                method_signature);
-      tree block, compound;
-
-      /* Fixe the begining/ending lines of the method so that with
-         no_line_numbers set to 1 it doesn't generate debug info at
-         line 1 for this artificial constructor. */
-      DECL_SOURCE_LINE (mdecl) = 1;
-      DECL_SOURCE_LINE_MERGE (mdecl, 1);
-      source_start_java_method (mdecl);
-      arg_list = BLOCK_EXPR_DECLS (DECL_FUNCTION_BODY (mdecl));
-      enter_block ();
-      func = build_known_method_ref (method, method_type, self_type,
-                                    method_signature, arg_list);
-      
-      if (! flag_emit_class_files)
-       func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
-      call = build (CALL_EXPR, TREE_TYPE (method_type), func, 
-                   build_tree_list (NULL_TREE, arg_list), NULL_TREE);
-      TREE_SIDE_EFFECTS (call) = 1;
-      call = build_class_init (self_type, call);
-      compound = java_method_add_stmt (mdecl, call);
-      block = exit_block ();
-      BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) = block;
-      /* The function decl, its block and the compound statement
-         within this block are all of void type. */
-      TREE_TYPE (block) = TREE_TYPE (compound) = 
-       TREE_TYPE (DECL_FUNCTION_BODY (mdecl)) = void_type_node;
-      exit_block ();
-      no_ac_found = 0;
-    }
+  /* Fix constructors before expanding them */
+  if (DECL_CONSTRUCTOR_P (mdecl))
+    fix_constructors (mdecl);
   
+  /* Expand functions that have a body */
   if (DECL_FUNCTION_BODY (mdecl))
     {
+      tree fbody = DECL_FUNCTION_BODY (mdecl);
+      tree block_body = BLOCK_EXPR_BODY (fbody);
       expand_start_java_method (mdecl);
+      build_result_decl (mdecl);
 
       current_this 
        = (!METHOD_STATIC (mdecl) ? 
@@ -4900,12 +5735,28 @@ java_complete_expand_method (mdecl)
       /* Install exceptions thrown with `throws' */
       PUSH_EXCEPTIONS (DECL_FUNCTION_THROWS (mdecl));
 
-      if (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)) && no_ac_found)
-       java_complete_tree (BLOCK_EXPR_BODY (DECL_FUNCTION_BODY (mdecl)));
+      if (block_body != NULL_TREE)
+       {
+         block_body = java_complete_tree (block_body);
+         check_for_initialization (block_body);
+       }
+      BLOCK_EXPR_BODY (fbody) = block_body;
+
+      if ((block_body == NULL_TREE || CAN_COMPLETE_NORMALLY (block_body))
+         && TREE_CODE (TREE_TYPE (TREE_TYPE (mdecl))) != VOID_TYPE)
+       missing_return_error (current_function_decl);
+
+      complete_start_java_method (mdecl); 
+
       /* Don't go any further if we've found error(s) during the
          expansion */
       if (!java_error_count)
        source_end_java_method ();
+      else
+       {
+         pushdecl_force_head (DECL_ARGUMENTS (mdecl));
+         poplevel (1, 0, 1);
+       }
 
       /* Pop the exceptions and sanity check */
       POP_EXCEPTIONS();
@@ -4914,6 +5765,109 @@ java_complete_expand_method (mdecl)
     }
 }
 
+/* Craft a body for default constructor. Patch existing constructor
+   bodies with call to super() and field initialization statements if
+   necessary.  */
+
+static void
+fix_constructors (mdecl)
+     tree mdecl;
+{
+  tree body = DECL_FUNCTION_BODY (mdecl);
+
+  if (!body)
+    {
+      /* The constructor body must be crafted by hand. It's the
+        constructor we defined when we realize we didn't have the
+        CLASSNAME() constructor */
+
+      tree compound;
+
+      /* It is an error for the compiler to generate a default
+        constructor if the superclass doesn't have a constructor that
+        takes no argument */
+      if (verify_constructor_super ())
+       {
+         tree sclass_decl = TYPE_NAME (CLASSTYPE_SUPER (current_class));
+         char *n = IDENTIFIER_POINTER (DECL_NAME (sclass_decl));
+         parse_error_context (lookup_cl (TYPE_NAME (current_class)), 
+                              "No constructor matching `%s()' found in "
+                              "class `%s'", n, n);
+       }
+      
+      start_artificial_method_body (mdecl);
+      
+      /* We don't generate a super constructor invocation if we're
+        compiling java.lang.Object. build_super_invocation takes care
+        of that. */
+      compound = java_method_add_stmt (mdecl, build_super_invocation ());
+
+      end_artificial_method_body (mdecl);
+    }
+  /* Search for an explicit constructor invocation */
+  else 
+    {
+      int found = 0;
+      tree main_block = BLOCK_EXPR_BODY (body);
+      tree compound = NULL_TREE;
+      
+      while (body)
+       switch (TREE_CODE (body))
+         {
+         case CALL_EXPR:
+           found = CALL_EXPLICIT_CONSTRUCTOR_P (body);
+           body = NULL_TREE;
+           break;
+         case COMPOUND_EXPR:
+         case EXPR_WITH_FILE_LOCATION:
+           body = TREE_OPERAND (body, 0);
+           break;
+         case BLOCK:
+           body = BLOCK_EXPR_BODY (body);
+           break;
+         default:
+           found = 0;
+           body = NULL_TREE;
+         }
+      /* The constructor is missing an invocation of super() */
+      if (!found)
+       compound = add_stmt_to_compound (compound, NULL_TREE,
+                                        build_super_invocation ());
+      
+      /* Fix the constructor main block if we're adding extra stmts */
+      if (compound)
+       {
+         compound = add_stmt_to_compound (compound, NULL_TREE,
+                                          BLOCK_EXPR_BODY (main_block));
+         BLOCK_EXPR_BODY (main_block) = compound;
+       }
+    }
+}
+
+/* Browse constructors in the super class, searching for a constructor
+   that doesn't take any argument. Return 0 if one is found, 1
+   otherwise. */
+
+static int
+verify_constructor_super ()
+{
+  tree class = CLASSTYPE_SUPER (current_class);
+  if (!class)
+    return 0;
+
+  if (class)
+    {
+      tree mdecl;
+      for (mdecl = TYPE_METHODS (class); mdecl; mdecl = TREE_CHAIN (mdecl))
+       {
+         if (DECL_CONSTRUCTOR_P (mdecl)
+             && TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (mdecl))) == end_params_node)
+           return 0;
+       }
+    }
+  return 1;
+}
+
 /* Expand finals.  */
 
 void
@@ -4921,11 +5875,18 @@ java_expand_finals ()
 {
 }
 
-/* Generate code for all context remembered for code generation */
+/* Generate code for all context remembered for code generation */
 
 void
 java_expand_classes ()
 {
+  int save_error_count = java_error_count;
+  java_parse_abort_on_error ();
+  if (!(ctxp = ctxp_for_generation))
+    return;
+  java_layout_classes ();
+  java_parse_abort_on_error ();
+
   for (; ctxp_for_generation; ctxp_for_generation = ctxp_for_generation->next)
     {
       ctxp = ctxp_for_generation;
@@ -5010,6 +5971,11 @@ make_qualified_name (left, right, location)
      tree left, right;
      int location;
 {
+#ifdef USE_COMPONENT_REF
+  tree node = build (COMPONENT_REF, NULL_TREE, left, right);
+  EXPR_WFL_LINECOL (node) = location;
+  return node;
+#else
   tree left_id = EXPR_WFL_NODE (left);
   tree right_id = EXPR_WFL_NODE (right);
   tree wfl, merge;
@@ -5030,6 +5996,7 @@ make_qualified_name (left, right, location)
 
   EXPR_WFL_NODE (left) = merge;
   return left;
+#endif
 }
 
 /* Extract the last identifier component of the qualified in WFL. The
@@ -5055,8 +6022,9 @@ cut_identifier_in_qualified (wfl)
 /* Resolve the expression name NAME. Return its decl.  */
 
 static tree
-resolve_expression_name (id)
+resolve_expression_name (id, orig)
      tree id;
+     tree *orig;
 {
   tree name = EXPR_WFL_NODE (id);
   tree decl;
@@ -5089,9 +6057,26 @@ resolve_expression_name (id)
                                         (TYPE_NAME (current_class))));
                  return error_mark_node;
                }
+             /* Instance variables can't appear as an argument of
+                an explicit constructor invocation */
+             if (!fs && ctxp->explicit_constructor_p)
+               {
+                 parse_error_context
+                   (id, "Can't reference `%s' before the superclass "
+                    "constructor has been called", IDENTIFIER_POINTER (name));
+                 return error_mark_node;
+               }
+
+             /* Otherwise build what it takes to access the field */
              decl = build_field_ref ((fs ? NULL_TREE : current_this),
                                      current_class, name);
-             return (fs ? build_class_init (current_class, decl) : decl);
+             if (fs && !flag_emit_class_files)
+               decl = build_class_init (current_class, decl);
+             /* We may be asked to save the real field access node */
+             if (orig)
+               *orig = decl;
+             /* And we return what we got */
+             return decl;
            }
          /* Fall down to error report on undefined variable */
        }
@@ -5099,6 +6084,8 @@ resolve_expression_name (id)
   /* 6.5.5.2 Qualified Expression Names */
   else
     {
+      if (orig)
+       *orig = NULL_TREE;
       qualify_ambiguous_name (id);
       /* 15.10.1 Field Access Using a Primary and/or Expression Name */
       /* 15.10.2: Accessing Superclass Members using super */
@@ -5140,23 +6127,36 @@ resolve_field_access (qual_wfl, field_decl, field_type)
     }
   /* We might have been trying to resolve field.method(). In which
      case, the resolution is over and decl is the answer */
-  else if (DECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
+  else if (JDECL_P (decl) && IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) == decl)
     field_ref = decl;
-  else if (DECL_P (decl))
-    {
-      is_static = DECL_P (decl) && FIELD_STATIC (decl);
-      field_ref = build_field_ref ((is_static ? NULL_TREE : where_found), 
-                                  type_found, DECL_NAME (decl));
+  else if (JDECL_P (decl))
+    {
+      int static_final_found = 0;
+      if (!type_found)
+       type_found = DECL_CONTEXT (decl);
+      is_static = JDECL_P (decl) && FIELD_STATIC (decl);
+      if (FIELD_FINAL (decl) 
+         && JPRIMITIVE_TYPE_P (TREE_TYPE (decl))
+         && DECL_LANG_SPECIFIC (decl)
+         && DECL_INITIAL (decl))
+       {
+         field_ref = DECL_INITIAL (decl);
+         static_final_found = 1;
+       }
+      else
+       field_ref = build_field_ref ((is_static ? NULL_TREE : where_found), 
+                                    type_found, DECL_NAME (decl));
       if (field_ref == error_mark_node)
        return error_mark_node;
-      if (is_static)
+      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);
@@ -5169,10 +6169,35 @@ 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;
 }
 
+/* If NODE is an access to f static field, strip out the class
+   initialization part and return the field decl, otherwise, return
+   NODE. */
+
+static tree
+strip_out_static_field_access_decl (node)
+    tree node;
+{
+  if (TREE_CODE (node) == COMPOUND_EXPR)
+    {
+      tree op1 = TREE_OPERAND (node, 1);
+      if (TREE_CODE (op1) == COMPOUND_EXPR)
+        {
+          tree call = TREE_OPERAND (op1, 0);
+          if (TREE_CODE (call) == CALL_EXPR
+              && TREE_CODE (TREE_OPERAND (call, 0)) == ADDR_EXPR
+              && TREE_OPERAND (TREE_OPERAND (call, 0), 0)
+              == soft_initclass_node)
+            return TREE_OPERAND (op1, 1);
+        }
+    }
+  return node;
+}
+
 /* 6.5.5.2: Qualified Expression Names */
 
 static int
@@ -5185,32 +6210,33 @@ 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))
     {
       tree qual_wfl = QUAL_WFL (q);
 
       /* 15.10.1 Field Access Using a Primary */
-      
       switch (TREE_CODE (qual_wfl))
        {
        case CALL_EXPR:
        case NEW_CLASS_EXPR:
          /* If the access to the function call is a non static field,
             build the code to access it. */
-         if (DECL_P (decl) && !FIELD_STATIC (decl))
+         if (JDECL_P (decl) && !FIELD_STATIC (decl))
            {
-             decl = maybe_access_field (decl, *where_found, type);
+             decl = maybe_access_field (decl, *where_found, 
+                                        DECL_CONTEXT (decl));
              if (decl == error_mark_node)
                return 1;
            }
          /* And code for the function call */
          if (complete_function_arguments (qual_wfl))
            return 1;
+         if (from_super && TREE_CODE (qual_wfl) == CALL_EXPR)
+           CALL_USING_SUPER (qual_wfl) = 1;
          *where_found = 
-           patch_method_invocation_stmt (qual_wfl, decl, type,
-                                         &is_static, NULL);
+           patch_method_invocation (qual_wfl, decl, type, &is_static, NULL);
          if (*where_found == error_mark_node)
            return 1;
          *type_found = type = QUAL_DECL_TYPE (*where_found);
@@ -5231,6 +6257,14 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
            }
          continue;
 
+       case NEW_ARRAY_EXPR:
+         *where_found = decl = java_complete_tree (qual_wfl);
+         if (decl == error_mark_node)
+           return 1;
+         *type_found = type = QUAL_DECL_TYPE (decl);
+         CLASS_LOADED_P (type) = 1;
+         continue;
+
        case CONVERT_EXPR:
          *where_found = decl = java_complete_tree (qual_wfl);
          if (decl == error_mark_node)
@@ -5239,10 +6273,18 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
          from_cast = 1;
          continue;
 
+       case CONDITIONAL_EXPR:
+       case STRING_CST:
+         *where_found = decl = java_complete_tree (qual_wfl);
+         if (decl == error_mark_node)
+           return 1;
+         *type_found = type = QUAL_DECL_TYPE (decl);
+         continue;
+
        case ARRAY_REF:
          /* If the access to the function call is a non static field,
             build the code to access it. */
-         if (DECL_P (decl) && !FIELD_STATIC (decl))
+         if (JDECL_P (decl) && !FIELD_STATIC (decl))
            {
              decl = maybe_access_field (decl, *where_found, type);
              if (decl == error_mark_node)
@@ -5274,7 +6316,7 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
            }
          /* We have to generate code for intermediate acess */
          *where_found = decl = current_this;
-         type = QUAL_DECL_TYPE (decl);
+         *type_found = type = QUAL_DECL_TYPE (decl);
          continue;
        }
 
@@ -5295,6 +6337,8 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
                             CLASSTYPE_SUPER (current_class),
                             build_this (EXPR_WFL_LINECOL (qual_wfl)));
          *where_found = decl = java_complete_tree (node);
+         if (decl == error_mark_node)
+           return 1;
          *type_found = type = QUAL_DECL_TYPE (decl);
          from_super = from_type = 1;
          continue;
@@ -5304,17 +6348,33 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
         assume a variable/class name was meant. */
       if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
        {
-         if (from_super || from_cast)
-           parse_error_context 
-             ((from_cast ? qual_wfl : wfl),
-              "No variable `%s' defined in class `%s'",
-              IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
-              lang_printable_name (type, 0));
+         tree name = resolve_package (wfl, &q);
+         if (name)
+           {
+             *where_found = decl = resolve_no_layout (name, qual_wfl);
+             /* We wan't to be absolutely that the class is laid
+                 out. We're going to search something inside it. */
+             *type_found = type = TREE_TYPE (decl);
+             layout_class (type);
+             from_type = 1;
+             /* Should be a list, really. FIXME */
+             RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (TREE_CHAIN (q))) = 1;
+             RESOLVE_PACKAGE_NAME_P (QUAL_WFL (TREE_CHAIN (q))) = 0;
+           }
          else
-           parse_error_context
-             (qual_wfl, "Undefined variable or class name: `%s'",
-              IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)));
-         return 1;
+           {
+             if (from_super || from_cast)
+               parse_error_context 
+                 ((from_cast ? qual_wfl : wfl),
+                  "No variable `%s' defined in class `%s'",
+                  IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)),
+                  lang_printable_name (type, 0));
+             else
+               parse_error_context
+                 (qual_wfl, "Undefined variable or class name: `%s'",
+                  IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)));
+             return 1;
+           }
        }
 
       /* We have a type name. It's been already resolved when the
@@ -5329,11 +6389,12 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
              parse_error_context 
                (qual_wfl, "Can't access %s field `%s.%s' from `%s'",
                 java_accstring_lookup (get_access_flags_from_decl (decl)),
-                IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
+                GET_TYPE_NAME (type),
                 IDENTIFIER_POINTER (DECL_NAME (decl)),
                 IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
              return 1;
            }
+         check_deprecation (qual_wfl, decl);
          
          type = TREE_TYPE (decl);
          from_type = 1;
@@ -5350,18 +6411,30 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
          if (!from_super && QUAL_RESOLUTION (q))
            {
              decl = QUAL_RESOLUTION (q);
-             *type_found = type;
-           }
+             if (!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);
+                   }
+               }
+           }
 
          /* We have to search for a field, knowing the type of its
              container. The flag FROM_TYPE indicates that we resolved
              the last member of the expression as a type name, which
-             means that for the resolution of this field, will check
-             on other errors than if the it was resolved as a member
-             of an other field. */
+             means that for the resolution of this field, we'll look
+             for other errors than if it was resolved as a member of
+             an other field. */
          else
            {
              int is_static;
+             tree field_decl_type; /* For layout */
+
              if (!from_type && !JREFERENCE_TYPE_P (type))
                {
                  parse_error_context 
@@ -5372,15 +6445,33 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
                  return 1;
                }
              
-             if (!(field_decl = 
-                   lookup_field_wrapper (type, EXPR_WFL_NODE (qual_wfl))))
+             field_decl = lookup_field_wrapper (type,
+                                                EXPR_WFL_NODE (qual_wfl));
+             if (field_decl == NULL_TREE)
                {
                  parse_error_context 
-                   (qual_wfl, "No variable `%s' defined in class `%s'",
+                   (qual_wfl, "No variable `%s' defined in type `%s'",
                     IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)), 
-                    IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
+                    GET_TYPE_NAME (type));
                  return 1;
                }
+             if (field_decl == error_mark_node)
+               return 1;
+
+             /* Layout the type of field_decl, since we may need
+                 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)
+                 && !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))
@@ -5390,12 +6481,13 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
                     "Can't access %s field `%s.%s' from `%s'",
                     java_accstring_lookup 
                       (get_access_flags_from_decl (field_decl)),
-                    IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
+                    GET_TYPE_NAME (type),
                     IDENTIFIER_POINTER (DECL_NAME (field_decl)),
                     IDENTIFIER_POINTER 
                       (DECL_NAME (TYPE_NAME (current_class))));
                  return 1;
                }
+             check_deprecation (qual_wfl, field_decl);
              
              /* There are things to check when fields are accessed
                 from type. There are no restrictions on a static
@@ -5414,8 +6506,9 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
                }
              from_cast = from_super = 0;
 
-             /* If we need to generate something to get a proper handle
-                on what this field is accessed from, do it now. */
+             /* If we need to generate something to get a proper
+                handle on what this field is accessed from, do it
+                now. */
              if (!is_static)
                {
                  decl = maybe_access_field (decl, *where_found, *type_found);
@@ -5462,32 +6555,19 @@ int not_accessible_p (reference, member, from_super)
       if (class_in_current_package (DECL_CONTEXT (member)))
        return 0;
 
-      if (TREE_CODE (member) == FUNCTION_DECL && DECL_CONSTRUCTOR_P (member))
-       {
-         /* Access from SUPER is granted */
-         if (from_super)
-           return 0;
-         /* Otherwise, access isn't granted */
-         return 1;
-       }
-      else
-       {
-         /* If accessed with the form `super.member', then access is
-             granted */
-         if (from_super)
-           return 0;
+      /* If accessed with the form `super.member', then access is granted */
+      if (from_super)
+       return 0;
 
-         /* Otherwise, access is granted if occuring from the class where
-            member is declared or a subclass of it */
-         if (inherits_from_p (reference, current_class))
-           return 0;
-       }
+      /* Otherwise, access is granted if occuring from the class where
+        member is declared or a subclass of it */
+      if (inherits_from_p (reference, current_class))
+       return 0;
       return 1;
     }
 
   /* 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);
 
@@ -5501,6 +6581,40 @@ int not_accessible_p (reference, member, from_super)
   return 0;
 }
 
+/* Test deprecated decl access.  */
+static void
+check_deprecation (wfl, decl)
+     tree wfl, decl;
+{
+  char *file = DECL_SOURCE_FILE (decl);
+  /* Complain if the field is deprecated and the file it was defined
+     in isn't compiled at the same time the file which contains its
+     use is */
+  if (DECL_DEPRECATED (decl) 
+      && !IS_A_COMMAND_LINE_FILENAME_P (get_identifier (file)))
+    {
+      char the [20];
+      switch (TREE_CODE (decl))
+       {
+       case FUNCTION_DECL:
+         strcpy (the, "method");
+         break;
+       case FIELD_DECL:
+         strcpy (the, "field");
+         break;
+       case TYPE_DECL:
+         strcpy (the, "class");
+         break;
+       default:
+         fatal ("unexpected DECL code - check_deprecation");
+       }
+      parse_warning_context 
+       (wfl, "The %s `%s' in class `%s' has been deprecated", 
+        the, lang_printable_name (decl, 0),
+        IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))));
+    }
+}
+
 /* Returns 1 if class was declared in the current package, 0 otherwise */
 
 static int
@@ -5545,22 +6659,20 @@ static tree
 maybe_access_field (decl, where, type)
   tree decl, where, type;
 {
-  if (DECL_P (decl) && decl != current_this
-      && (!(TREE_CODE (decl) != PARM_DECL
-           && FIELD_STATIC (decl)))
-      && !IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)))
+  if (TREE_CODE (decl) == FIELD_DECL && decl != current_this
+      && !FIELD_STATIC (decl))
     decl = build_field_ref (where ? where : current_this, 
                            (type ? type : DECL_CONTEXT (decl)),
                            DECL_NAME (decl));
   return decl;
 }
 
-/* Build a method invocation statement, by patching PATCH. If non NULL
+/* Build a method invocation, by patching PATCH. If non NULL
    and according to the situation, PRIMARY and WHERE may be
    used. IS_STATIC is set to 1 if the invoked function is static. */
 
 static tree
-patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
+patch_method_invocation (patch, primary, where, is_static, ret_decl)
      tree patch, primary, where;
      int *is_static;
      tree *ret_decl;
@@ -5568,7 +6680,10 @@ patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
   tree wfl = TREE_OPERAND (patch, 0);
   tree args = TREE_OPERAND (patch, 1);
   tree name = EXPR_WFL_NODE (wfl);
-  tree list, class_type;
+  tree list;
+  int is_static_flag = 0;
+  int is_super_init = 0;
+  tree this_arg = NULL_TREE;
   
   /* Should be overriden if everything goes well. Otherwise, if
      something fails, it should keep this value. It stop the
@@ -5638,6 +6753,7 @@ patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
              free (fct_name);
              PATCH_METHOD_RETURN_ERROR ();
            }
+         args = nreverse (args);
        }
       /* We're resolving an expression name */
       else
@@ -5648,24 +6764,28 @@ patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
          field = resolve_field_access (wfl, NULL, &type);
          if (field == error_mark_node)
            PATCH_METHOD_RETURN_ERROR ();
+         /* field is used in lieu of a primary. It alows us not to
+          report errors on erroneous use of `this' in
+          constructors. */
+         primary = field;      
          
          /* 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);
+         if (class_decl != 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, 
                                       identifier, args);
 
          /* 4- Add the field as an argument */
-         args = tree_cons (NULL_TREE, field, nreverse (args));
+         args = nreverse (args);
+         this_arg = field;
        }
 
-      /* CLASS_TYPE is used during the call to not_accessible_p and
-        IDENTIFIER_WFL will be used to report any problem further */
-      class_type = TREE_TYPE (class_decl);
+      /* IDENTIFIER_WFL will be used to report any problem further */
       wfl = identifier_wfl;
     }
   /* Resolution of simple names, names generated after a primary: or
@@ -5678,24 +6798,54 @@ patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
       /* We search constructor in their target class */
       if (CALL_CONSTRUCTOR_P (patch))
        {
-         class_to_search = resolve_no_layout (EXPR_WFL_NODE (wfl), NULL_TREE);
-         if (!class_to_search)
+         if (TREE_CODE (patch) == NEW_CLASS_EXPR)
+           class_to_search = EXPR_WFL_NODE (wfl);
+         else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) == 
+                  this_identifier_node)
+           class_to_search = NULL_TREE;
+         else if (EXPR_WFL_NODE (TREE_OPERAND (patch, 0)) ==
+                  super_identifier_node)
            {
-             parse_error_context 
-               (wfl, "Class `%s' not found in type declaration",
-                IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
-             PATCH_METHOD_RETURN_ERROR ();
+             is_super_init = 1;
+             if (CLASSTYPE_SUPER (current_class))
+               class_to_search = 
+                 DECL_NAME (TYPE_NAME (CLASSTYPE_SUPER (current_class)));
+             else
+               {
+                 parse_error_context (wfl, "Can't invoke super constructor "
+                                      "on java.lang.Object");
+                 PATCH_METHOD_RETURN_ERROR ();
+               }
            }
-         
-         /* Can't instantiate an abstract class */
-         if (CLASS_ABSTRACT (class_to_search))
+
+         /* Class to search is NULL if we're searching the current one */
+         if (class_to_search)
            {
-             parse_error_context 
-               (wfl, "Class `%s' is an abstract class. It can't be "
-                "instantiated", IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
-             PATCH_METHOD_RETURN_ERROR ();
+             class_to_search = resolve_and_layout (class_to_search, 
+                                                   NULL_TREE);
+             if (!class_to_search)
+               {
+                 parse_error_context 
+                   (wfl, "Class `%s' not found in type declaration",
+                    IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
+                 PATCH_METHOD_RETURN_ERROR ();
+               }
+             
+             /* Can't instantiate an abstract class, but we can
+                invoke it's constructor. It's use within the `new'
+                context is denied here. */
+             if (CLASS_ABSTRACT (class_to_search) 
+                 && TREE_CODE (patch) == NEW_CLASS_EXPR)
+               {
+                 parse_error_context 
+                   (wfl, "Class `%s' is an abstract class. It can't be "
+                    "instantiated", IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
+                 PATCH_METHOD_RETURN_ERROR ();
+               }
+             class_to_search = TREE_TYPE (class_to_search);
            }
-         class_to_search = TREE_TYPE (class_to_search);
+         else
+           class_to_search = current_class;
          lc = 1;
        }
       /* This is a regular search in the local class, unless an
@@ -5709,6 +6859,7 @@ patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
       /* 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
@@ -5721,14 +6872,13 @@ patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
                                             class_to_search, primary))
        PATCH_METHOD_RETURN_ERROR ();
 
-      /* Non static/constructor methods are called with the current
-        object extra argument. If method is resolved as a primary,
-        use the primary otherwise use the current THIS. */
+      /* Non static methods are called with the current object extra
+        argument. If patch a `new TYPE()', the argument is the value
+        returned by the object allocator. If method is resolved as a
+        primary, use the primary otherwise use the current THIS. */
       args = nreverse (args);
-      if (!CALL_CONSTRUCTOR_P (patch) && !METHOD_STATIC (list))
-       args = tree_cons (NULL_TREE, primary ? primary : current_this, args);
-
-      class_type = class_to_search;
+      if (TREE_CODE (patch) != NEW_CLASS_EXPR)
+       this_arg = primary ? primary : current_this;
     }
 
   /* Merge point of all resolution schemes. If we have nothing, this
@@ -5738,27 +6888,61 @@ patch_method_invocation_stmt (patch, primary, where, is_static, ret_decl)
 
   /* Check accessibility, position the is_static flag, build and
      return the call */
-  if (not_accessible_p (class_type, list, 0))
+  if (not_accessible_p (DECL_CONTEXT (current_function_decl), list, 0))
     {
       char *fct_name = strdup (lang_printable_name (list, 0));
       parse_error_context 
        (wfl, "Can't access %s method `%s %s.%s' from `%s'",
         java_accstring_lookup (get_access_flags_from_decl (list)),
         lang_printable_name (TREE_TYPE (TREE_TYPE (list)), 0), 
-        IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class_type))), fct_name,
-        IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
+        IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (list)))), 
+        fct_name, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class))));
       free (fct_name);
       PATCH_METHOD_RETURN_ERROR ();
     }
-  
-  if (is_static) 
-    *is_static = METHOD_STATIC (list);
+  check_deprecation (wfl, list);
+
+  is_static_flag = METHOD_STATIC (list);
+  if (! METHOD_STATIC (list) && this_arg != NULL_TREE)
+    args = tree_cons (NULL_TREE, this_arg, args);
+
+  /* In the context of an explicit constructor invocation, we can't
+     invoke any method relying on `this'. Exceptions are: we're
+     invoking a static function, primary exists and is not the current
+     this, we're creating a new object. */
+  if (ctxp->explicit_constructor_p 
+      && !is_static_flag 
+      && (!primary || primary == current_this)
+      && (TREE_CODE (patch) != NEW_CLASS_EXPR))
+    {
+      parse_error_context 
+       (wfl, "Can't reference `this' before the superclass constructor has "
+        "been called");
+      PATCH_METHOD_RETURN_ERROR ();
+    }
   java_parser_context_restore_global ();
+  if (is_static) 
+    *is_static = is_static_flag;
   /* Sometimes, we want the decl of the selected method. Such as for
      EH checking */
   if (ret_decl)
     *ret_decl = list;
-  return patch_invoke (patch, list, args);
+  patch = patch_invoke (patch, list, args);
+  if (is_super_init && CLASS_HAS_FINIT_P (current_class))
+    {
+      /* Generate the code used to initialize fields declared with an
+        initialization statement. For now, it returns a call the the
+        artificial function $finit$, if required. */
+
+      tree finit_call =
+       build_method_invocation (build_expr_wfl (finit_identifier_node,  
+                                                input_filename, 0, 0),  
+                                NULL_TREE);
+      patch = build (COMPOUND_EXPR, void_type_node, patch,
+                    java_complete_tree (finit_call));
+      CAN_COMPLETE_NORMALLY (patch) = 1;
+    }
+  return patch;
 }
 
 /* Check that we're not trying to do a static reference to a method in
@@ -5789,50 +6973,73 @@ static tree
 patch_invoke (patch, method, args)
      tree patch, method, args;
 {
-  int im;
   tree dtable, func;
-  tree signature = build_java_signature (TREE_TYPE (method));
   tree original_call, t, ta;
 
-  /* Last step for args: convert build-in types */
-  for (t = TYPE_ARG_TYPES (TREE_TYPE (method)),
-       ta = args; t && ta; t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
+  /* Last step for args: convert build-in types. If we're dealing with
+     a new TYPE() type call, the first argument to the constructor
+     isn't found in the incomming argument list, but delivered by
+     `new' */
+  t = TYPE_ARG_TYPES (TREE_TYPE (method));
+  if (TREE_CODE (patch) == NEW_CLASS_EXPR)
+    t = TREE_CHAIN (t);
+  for (ta = args; t != end_params_node && ta; 
+       t = TREE_CHAIN (t), ta = TREE_CHAIN (ta))
     if (JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_VALUE (ta))) &&
        TREE_TYPE (TREE_VALUE (ta)) != TREE_VALUE (t))
       TREE_VALUE (ta) = convert (TREE_VALUE (t), TREE_VALUE (ta));
-       
-  switch ((im = invocation_mode (method, 0)))
+  
+  if (flag_emit_class_files)
+    func = method;
+  else
     {
-    case INVOKE_VIRTUAL:
-      dtable = invoke_build_dtable (0, args);
-      func = build_invokevirtual (dtable, method);
-      break;
+      tree signature = build_java_signature (TREE_TYPE (method));
+      switch (invocation_mode (method, CALL_USING_SUPER (patch)))
+       {
+       case INVOKE_VIRTUAL:
+         dtable = invoke_build_dtable (0, args);
+         func = build_invokevirtual (dtable, method);
+         break;
 
-    case INVOKE_STATIC:
-      func = build_known_method_ref (method, TREE_TYPE (method),
-                                    DECL_CONTEXT (method), signature, args);
-      break;
+       case INVOKE_SUPER:
+       case INVOKE_STATIC:
+         func = build_known_method_ref (method, TREE_TYPE (method),
+                                        DECL_CONTEXT (method),
+                                        signature, args);
+         break;
 
-    default:
-      fatal ("Unknown invocation mode - build_invoke");
-      return NULL_TREE;
+       case INVOKE_INTERFACE:
+         dtable = invoke_build_dtable (1, args);
+         func = build_invokeinterface (dtable, DECL_NAME (method), signature);
+         break;
+
+       default:
+         fatal ("internal error - unknown invocation_mode result");
+       }
+
+      /* Ensure self_type is initialized, (invokestatic). FIXME */
+      func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
     }
 
-  /* Ensure self_type is initialized, (invokestatic). FIXME */
-  func = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (method)), func);
   TREE_TYPE (patch) = TREE_TYPE (TREE_TYPE (method));
   TREE_OPERAND (patch, 0) = func;
   TREE_OPERAND (patch, 1) = args;
   original_call = patch;
 
-  /* We're calling a constructor. New is called an its returned value
-     is an argument to the constructor. We build a COMPOUND_EXPR and
-     use saved expression so that the overall NEW expression value is
-     a pointer to a newly created and initialized class. */
-  if (CALL_CONSTRUCTOR_P (original_call))
+  /* We're processing a `new TYPE ()' form. New is called an its
+     returned value is the first argument to the constructor. We build
+     a COMPOUND_EXPR and use saved expression so that the overall NEW
+     expression value is a pointer to a newly created and initialized
+     class. */
+  if (TREE_CODE (original_call) == NEW_CLASS_EXPR)
     {
       tree class = DECL_CONTEXT (method);
       tree c1, saved_new, size, new;
+      if (flag_emit_class_files)
+       {
+         TREE_TYPE (patch) = build_pointer_type (class);
+         return patch;
+       }
       if (!TYPE_SIZE (class))
        safe_layout_class (class);
       size = size_in_bytes (class);
@@ -5859,21 +7066,21 @@ invocation_mode (method, super)
 {
   int access = get_access_flags_from_decl (method);
 
-  if (access & ACC_STATIC || access & ACC_FINAL)
+  if (super)
+    return INVOKE_SUPER;
+
+  if (access & ACC_STATIC || access & ACC_FINAL || access & ACC_PRIVATE)
     return INVOKE_STATIC;
 
   if (CLASS_FINAL (TYPE_NAME (DECL_CONTEXT (method))))
     return INVOKE_STATIC;
   
-  if (super)
-    return INVOKE_SUPER;
-  
   if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
     return INVOKE_INTERFACE;
   
   if (DECL_CONSTRUCTOR_P (method))
     return INVOKE_STATIC;
-  
+
   return INVOKE_VIRTUAL;
 }
 
@@ -5886,35 +7093,27 @@ lookup_method_invoke (lc, cl, class, name, arg_list)
      tree cl;
      tree class, name, arg_list;
 {
-  tree method = make_node (FUNCTION_TYPE);
-  tree arg_type_list = NULL_TREE;
-  tree signature, list, node;
+  tree atl = end_params_node;          /* Arg Type List */
+  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));
+      /* Non primitive type may have to be resolved */
+      if (!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);
-      arg_type_list = tree_cons (NULL_TREE, current_arg, arg_type_list);
-    }
-  TYPE_ARG_TYPES (method) = arg_type_list;
-
-  if (!lc)
-    {
-      list = find_applicable_accessible_methods_list (class, name, 
-                                                     arg_type_list);
-      list = find_most_specific_methods_list (list);
-    }
-  else
-    {
-      TREE_TYPE (method) = void_type_node;
-      signature = build_java_signature (method);
-      list = lookup_java_constructor (class, signature);
+        current_arg = promote_type (current_arg);
+      atl = tree_cons (NULL_TREE, current_arg, atl);
     }
 
-  if (lc && list)
-    return list;
+  /* Find all candidates and then refine the list, searching for the
+     most specific method. */
+  list = find_applicable_accessible_methods_list (lc, class, name, atl);
+  list = find_most_specific_methods_list (list);
   if (list && !TREE_CHAIN (list))
     return TREE_VALUE (list);
 
@@ -5932,11 +7131,9 @@ lookup_method_invoke (lc, cl, class, name, arg_list)
          char string [4096];
          if (!cm || not_accessible_p (class, cm, 0))
            continue;
-         signature = build_java_argument_signature (TREE_TYPE (cm));
          sprintf 
-           (string, "  `%s(%s)' in `%s'%s",
-            IDENTIFIER_POINTER (name), 
-            IDENTIFIER_POINTER (signature),
+           (string, "  `%s' in `%s'%s",
+            get_printable_method_name (cm),
             IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (DECL_CONTEXT (cm)))),
             (TREE_CHAIN (current) ? "\n" : ""));
          obstack_grow (&temporary_obstack, string, strlen (string));
@@ -5945,19 +7142,26 @@ lookup_method_invoke (lc, cl, class, name, arg_list)
       candidates = obstack_finish (&temporary_obstack);
     }
   /* Issue the error message */
+  method = make_node (FUNCTION_TYPE);
+  TYPE_ARG_TYPES (method) = atl;
   signature = build_java_argument_signature (method);
-  parse_error_context (cl, "Can't find method `%s(%s)' in class `%s'%s",
-                      IDENTIFIER_POINTER (name),
+  parse_error_context (cl, "Can't find %s `%s(%s)' in class `%s'%s",
+                      (lc ? "constructor" : "method"),
+                      (lc ? 
+                       IDENTIFIER_POINTER(DECL_NAME (TYPE_NAME (class))) :
+                       IDENTIFIER_POINTER (name)),
                       IDENTIFIER_POINTER (signature),
                       IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (class))),
                       (candidates ? candidates : ""));
   return NULL_TREE;
 }
 
-/* 15.11.2.1: Find Methods that are Applicable and Accessible */
+/* 15.11.2.1: Find Methods that are Applicable and Accessible. LC is 1
+   when we're looking for a constructor. */
 
 static tree
-find_applicable_accessible_methods_list (class, name, arglist)
+find_applicable_accessible_methods_list (lc, class, name, arglist)
+     int lc;
      tree class, name, arglist;
 {
   tree method;
@@ -5968,22 +7172,26 @@ find_applicable_accessible_methods_list (class, name, arglist)
       for (method = TYPE_METHODS (class);
           method != NULL_TREE;  method = TREE_CHAIN (method))
        {
-         /* Names have to match and we're not looking for constructor */
-         if (DECL_NAME (method) != name
-             || DECL_CONSTRUCTOR_P (method))
+         if (lc && !DECL_CONSTRUCTOR_P (method))
            continue;
-
+         else if (!lc && (DECL_CONSTRUCTOR_P (method)
+                          || (GET_METHOD_NAME (method) != name)))
+           continue;
+         
          if (argument_types_convertible (method, arglist))
            {
              /* Retain accessible methods only */
-             if (!not_accessible_p (class, 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 */
                all_list = tree_cons (NULL_TREE, method, list);
            }
        }
-      class = CLASSTYPE_SUPER (class);
+      /* When dealing with constructor, stop here, otherwise search
+         other classes */
+      class = (lc ? NULL_TREE : CLASSTYPE_SUPER (class));
     }
   /* Either return the list obtained or all selected (but
      inaccessible) methods for better error report. */
@@ -6079,15 +7287,16 @@ argument_types_convertible (m1, m2_or_arglist)
       m2_arg_cache = m2_arg;
     }
 
-  while (m1_arg && m2_arg)
+  while (m1_arg != end_params_node && m2_arg != end_params_node)
     {
+      resolve_and_layout (TREE_VALUE (m1_arg), NULL_TREE);
       if (!valid_method_invocation_conversion_p (TREE_VALUE (m1_arg),
                                                 TREE_VALUE (m2_arg)))
        break;
       m1_arg = TREE_CHAIN (m1_arg);
       m2_arg = TREE_CHAIN (m2_arg);
     }
-  return (!m1_arg && !m2_arg ? 1 : 0);
+  return m1_arg == end_params_node && m2_arg == end_params_node;
 }
 
 /* Qualification routines */
@@ -6097,7 +7306,7 @@ qualify_ambiguous_name (id)
      tree id;
 {
   tree qual, qual_wfl, name, decl, ptr_type, saved_current_class;
-  int again, super_found = 0, this_found = 0;
+  int again, super_found = 0, this_found = 0, new_array_found = 0;
 
   /* We first qualify the first element, then derive qualification of
      others based on the first one. If the first element is qualified
@@ -6125,6 +7334,10 @@ qualify_ambiguous_name (id)
            qual_wfl = QUAL_WFL (qual);
          }
        break;
+      case NEW_ARRAY_EXPR:
+       qual = TREE_CHAIN (qual);
+       new_array_found = again = 1;
+       continue;
       case NEW_CLASS_EXPR:
       case CONVERT_EXPR:
        qual_wfl = TREE_OPERAND (qual_wfl, 0);
@@ -6145,7 +7358,10 @@ qualify_ambiguous_name (id)
       {
        qual = TREE_CHAIN (qual);
        qual_wfl = QUAL_WFL (qual);
-       name = EXPR_WFL_NODE (qual_wfl);
+       if (TREE_CODE (qual_wfl) == CALL_EXPR)
+         again = 1;
+       else
+         name = EXPR_WFL_NODE (qual_wfl);
        this_found = 1;
       }
     /* If we have a SUPER, we set the context accordingly */
@@ -6164,13 +7380,22 @@ qualify_ambiguous_name (id)
        /* Do one more interation to set things up */
        super_found = again = 1;
       }
+    /* Loop one more time if we're dealing with ?: or a string
+       constant, or a convert expression */
+    if (TREE_CODE (qual_wfl) == CONDITIONAL_EXPR
+       || TREE_CODE (qual_wfl) == STRING_CST
+       || TREE_CODE (qual_wfl) == CONVERT_EXPR)
+      {
+       qual = TREE_CHAIN (qual);
+       qual_wfl = QUAL_WFL (qual);
+       again = 1;
+      }
   } while (again);
   
   /* If name appears within the scope of a location variable
      declaration or parameter declaration, then it is an expression
      name. We don't carry this test out if we're in the context of the
      use of SUPER or THIS */
-
   if (!this_found && !super_found && (decl = IDENTIFIER_LOCAL_VALUE (name)))
     {
       RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
@@ -6179,11 +7404,13 @@ qualify_ambiguous_name (id)
 
   /* If within the class/interface NAME was found to be used there
      exists a (possibly inherited) field named NAME, then this is an
-     expression name. */
-  else if ((decl = lookup_field_wrapper (ptr_type, name)))
+     expression name. If we saw a NEW_ARRAY_EXPR before and want to
+     address length, it is OK. */
+  else if ((decl = lookup_field_wrapper (ptr_type, name))
+          || (new_array_found && name == length_identifier_node))
     {
       RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
-      QUAL_RESOLUTION (qual) = decl;
+      QUAL_RESOLUTION (qual) = (new_array_found ? NULL_TREE : decl);
     }
 
   /* We reclassify NAME as a type name if:
@@ -6201,7 +7428,8 @@ qualify_ambiguous_name (id)
     }
 
   /* Method call are expression name */
-  else if (TREE_CODE (QUAL_WFL (qual)) == CALL_EXPR)
+  else if (TREE_CODE (QUAL_WFL (qual)) == CALL_EXPR
+          || TREE_CODE (QUAL_WFL (qual)) == ARRAY_REF)
     RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
 
   /* Check here that NAME isn't declared by more than one
@@ -6262,28 +7490,53 @@ breakdown_qualified (left, right, source)
   return 0;
 }
 
-static int
-not_initialized_as_it_should_p (decl)
-     tree decl;
+/* Patch tree nodes in a function body. When a BLOCK is found, push
+   local variable decls if present.
+   Same as java_complete_lhs, but does resolve static finals to values. */
+
+static tree
+java_complete_tree (node)
+     tree node;
 {
-  if (DECL_P (decl))
+  node = java_complete_lhs (node);
+  if (TREE_CODE (node) == VAR_DECL && FIELD_STATIC (node)
+      && FIELD_FINAL (node) && DECL_INITIAL (node) != NULL_TREE)
     {
-      if (TREE_CODE (decl) == FIELD_DECL
-         && METHOD_STATIC (current_function_decl))
-       return 0;
-      return DECL_P (decl) && !INITIALIZED_P (decl);
+      tree value = DECL_INITIAL (node);
+      DECL_INITIAL (node) = NULL_TREE;
+      value = fold_constant_for_init (value, node);
+      DECL_INITIAL (node) = value;
+      if (value != NULL_TREE)
+       return value;
     }
-  return 0;
+  return node;
+}
+
+static tree
+java_stabilize_reference (node)
+     tree node;
+{
+  if (TREE_CODE (node) == COMPOUND_EXPR)
+    {
+      tree op0 = TREE_OPERAND (node, 0);
+      tree op1 = TREE_OPERAND (node, 1);
+      TREE_OPERAND (node, 0) = build1 (SAVE_EXPR, TREE_TYPE (op0), op0);
+      TREE_OPERAND (node, 1) = java_stabilize_reference (op1);
+      return node;
+    }
+  else
+    return stabilize_reference (node);
 }
 
 /* Patch tree nodes in a function body. When a BLOCK is found, push
-   local variable decls if present.  */
+   local variable decls if present.
+   Same as java_complete_tree, but does not resolve static finals to values. */
 
 static tree
-java_complete_tree (node)
+java_complete_lhs (node)
      tree node;
 {
-  tree nn, cn, wfl_op1, wfl_op2;
+  tree nn, cn, wfl_op1, wfl_op2, wfl_op3;
   int flag;
 
   /* CONVERT_EXPR always has its type set, even though it needs to be
@@ -6306,13 +7559,67 @@ java_complete_tree (node)
        {
          DECL_CONTEXT (cn) = current_function_decl;
          IDENTIFIER_LOCAL_VALUE (DECL_NAME (cn)) = cn;
-         INITIALIZED_P (cn) = 0;
        }
-      if (BLOCK_EXPR_BODY (node))
+      if (BLOCK_EXPR_BODY (node) == NULL_TREE)
+         CAN_COMPLETE_NORMALLY (node) = 1;
+      else
        {
-         BLOCK_EXPR_BODY (node) = java_complete_tree (BLOCK_EXPR_BODY (node));
-         if (BLOCK_EXPR_BODY (node) == error_mark_node)
+         tree stmt = BLOCK_EXPR_BODY (node);
+         tree *ptr;
+         int error_seen = 0;
+         if (TREE_CODE (stmt) == COMPOUND_EXPR)
+           {
+             /* 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. */
+             for (;;)
+               {
+                 tree left = TREE_OPERAND (stmt, 0);
+                 if (TREE_CODE (left) != COMPOUND_EXPR)
+                   break;
+                 TREE_OPERAND (stmt, 0) = TREE_OPERAND (left, 1);
+                 TREE_OPERAND (left, 1) = stmt;
+                 stmt = left;
+               }
+             BLOCK_EXPR_BODY (node) = stmt;
+           }
+
+         /* Now do the actual complete, without deep recursion for
+             long blocks. */
+         ptr = &BLOCK_EXPR_BODY (node);
+         while (TREE_CODE (*ptr) == COMPOUND_EXPR
+                && TREE_OPERAND (*ptr, 1) != empty_stmt_node)
+           {
+             tree cur = java_complete_tree (TREE_OPERAND (*ptr, 0));
+             tree *next = &TREE_OPERAND (*ptr, 1);
+             TREE_OPERAND (*ptr, 0) = cur;
+             if (TREE_CODE (cur) == ERROR_MARK)
+               error_seen++;
+             else if (! CAN_COMPLETE_NORMALLY (cur))
+               {
+                 wfl_op2 = *next;
+                 for (;;)
+                   {
+                     if (TREE_CODE (wfl_op2) == BLOCK)
+                       wfl_op2 = BLOCK_EXPR_BODY (wfl_op2);
+                     else if (TREE_CODE (wfl_op2) == COMPOUND_EXPR)
+                       wfl_op2 = TREE_OPERAND (wfl_op2, 0);
+                     else
+                       break;
+                   }
+                 if (TREE_CODE (wfl_op2) != CASE_EXPR
+                     && TREE_CODE (wfl_op2) != DEFAULT_EXPR)
+                   unreachable_stmt_error (*ptr);
+               }
+             ptr = next;
+           }
+         *ptr = java_complete_tree (*ptr);
+
+         if (TREE_CODE (*ptr) == ERROR_MARK || error_seen > 0)
            return error_mark_node;
+         CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (*ptr);
        }
       /* Turn local bindings to null */
       for (cn = BLOCK_EXPR_DECLS (node); cn; cn = TREE_CHAIN (cn))
@@ -6326,23 +7633,48 @@ java_complete_tree (node)
     case THROW_EXPR:
       wfl_op1 = TREE_OPERAND (node, 0);
       COMPLETE_CHECK_OP_0 (node);
+      /* CAN_COMPLETE_NORMALLY (node) = 0; */
       return patch_throw_statement (node, wfl_op1);
 
     case SYNCHRONIZED_EXPR:
       wfl_op1 = TREE_OPERAND (node, 0);
-      COMPLETE_CHECK_OP_0 (node);
-      COMPLETE_CHECK_OP_1 (node);
       return patch_synchronized_statement (node, wfl_op1);
 
     case TRY_EXPR:
       return patch_try_statement (node);
 
+    case TRY_FINALLY_EXPR:
+      COMPLETE_CHECK_OP_0 (node);
+      COMPLETE_CHECK_OP_1 (node);
+      CAN_COMPLETE_NORMALLY (node)
+       = (CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0))
+          && CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1)));
+      TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 0));
+      return node;
+
+    case CLEANUP_POINT_EXPR:
+      COMPLETE_CHECK_OP_0 (node);
+      TREE_TYPE (node) = void_type_node;
+      CAN_COMPLETE_NORMALLY (node) = 
+       CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
+      return node;
+
+    case WITH_CLEANUP_EXPR:
+      COMPLETE_CHECK_OP_0 (node);
+      COMPLETE_CHECK_OP_2 (node);
+      CAN_COMPLETE_NORMALLY (node) = 
+       CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 0));
+      TREE_TYPE (node) = void_type_node;
+      return node;
+
     case LABELED_BLOCK_EXPR:
       PUSH_LABELED_BLOCK (node);
       if (LABELED_BLOCK_BODY (node))
        COMPLETE_CHECK_OP_1 (node);
       TREE_TYPE (node) = void_type_node;
       POP_LABELED_BLOCK ();
+      if (CAN_COMPLETE_NORMALLY (LABELED_BLOCK_BODY (node)))
+       CAN_COMPLETE_NORMALLY (node) = 1;
       return node;
 
     case EXIT_BLOCK_EXPR:
@@ -6350,6 +7682,63 @@ java_complete_tree (node)
          the EXIT_BLOCK_EXPR which doesn't exist it Java */
       return patch_bc_statement (node);
 
+    case CASE_EXPR:
+      cn = java_complete_tree (TREE_OPERAND (node, 0));
+      if (cn == error_mark_node)
+       return cn;
+
+      /* First, the case expression must be constant */
+      cn = fold (cn);
+
+      if (!TREE_CONSTANT (cn))
+       {
+         EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
+         parse_error_context (node, "Constant expression required");
+         return error_mark_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))
+       {
+         EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
+         parse_error_context 
+           (wfl_operator,
+            "Incompatible type for case. Can't convert `%s' to `int'",
+            lang_printable_name (TREE_TYPE (cn), 0));
+         return error_mark_node;
+       }
+
+      cn = fold (convert (int_type_node, cn));
+
+      /* Multiple instance of a case label bearing the same
+        value is checked during code generation. The case
+        expression is allright so far. */
+      TREE_OPERAND (node, 0) = cn;
+      TREE_TYPE (node) = void_type_node;
+      CAN_COMPLETE_NORMALLY (node) = 1;
+      TREE_SIDE_EFFECTS (node) = 1;
+      break;
+
+    case DEFAULT_EXPR:
+      nn = ctxp->current_loop;
+      /* Only one default label is allowed per switch statement */
+      if (SWITCH_HAS_DEFAULT (nn))
+       {
+         EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
+         parse_error_context (wfl_operator, 
+                              "Duplicate case label: `default'");
+         return error_mark_node;
+       }
+      else
+       SWITCH_HAS_DEFAULT (nn) = 1;
+      TREE_TYPE (node) = void_type_node;
+      TREE_SIDE_EFFECTS (node) = 1;
+      CAN_COMPLETE_NORMALLY (node) = 1;
+      break;
+
     case SWITCH_EXPR:
     case LOOP_EXPR:
       PUSH_LOOP (node);
@@ -6371,7 +7760,11 @@ java_complete_tree (node)
       /* If we returned something different, that's because we
          inserted a label. Pop the label too. */
       if (nn != node)
-       POP_LABELED_BLOCK ();
+       {
+         if (CAN_COMPLETE_NORMALLY (node))
+           CAN_COMPLETE_NORMALLY (nn) = 1;
+         POP_LABELED_BLOCK ();
+       }
       POP_LOOP ();
       return nn;
 
@@ -6394,27 +7787,71 @@ java_complete_tree (node)
       return patch_if_else_statement (node);
       break;
 
+    case CONDITIONAL_EXPR:
+      /* Condition */
+      wfl_op1 = TREE_OPERAND (node, 0);
+      COMPLETE_CHECK_OP_0 (node);
+      wfl_op2 = TREE_OPERAND (node, 1);
+      COMPLETE_CHECK_OP_1 (node);
+      wfl_op3 = TREE_OPERAND (node, 2);
+      COMPLETE_CHECK_OP_2 (node);
+      return patch_conditional_expr (node, wfl_op1, wfl_op2);
+
       /* 3- Expression section */
     case COMPOUND_EXPR:
-      TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
-      TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
-      if (TREE_OPERAND (node, 1) == error_mark_node)
-       return error_mark_node;
+      wfl_op2 = TREE_OPERAND (node, 1);
+      TREE_OPERAND (node, 0) = nn = 
+       java_complete_tree (TREE_OPERAND (node, 0));
+      if (wfl_op2 == empty_stmt_node)
+       CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (nn);
+      else
+       {
+         if (! CAN_COMPLETE_NORMALLY (nn) && TREE_CODE (nn) != ERROR_MARK)
+           {
+             /* An unreachable condition in a do-while statement
+                is *not* (technically) an unreachable statement. */
+             nn = wfl_op2;
+             if (TREE_CODE (nn) == EXPR_WITH_FILE_LOCATION)
+               nn = EXPR_WFL_NODE (nn);
+             if (TREE_CODE (nn) != EXIT_EXPR)
+               {
+                 SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
+                 parse_error_context (wfl_operator, "Unreachable statement");
+               }
+           }
+         TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
+         if (TREE_OPERAND (node, 1) == error_mark_node)
+           return error_mark_node;
+         CAN_COMPLETE_NORMALLY (node)
+           = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1));
+       }
       TREE_TYPE (node) = TREE_TYPE (TREE_OPERAND (node, 1));
       break;
 
     case RETURN_EXPR:
+      /* CAN_COMPLETE_NORMALLY (node) = 0; */
       return patch_return (node);
 
     case EXPR_WITH_FILE_LOCATION:
       if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
          || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
-        return resolve_expression_name (node);
+       {
+         node = resolve_expression_name (node, NULL);
+         if (node == error_mark_node)
+           return node;
+         CAN_COMPLETE_NORMALLY (node) = 1;
+       }
       else
        {
-         EXPR_WFL_NODE (node) = java_complete_tree (EXPR_WFL_NODE (node));
-         TREE_SIDE_EFFECTS (node) = 1;
-         if (EXPR_WFL_NODE (node) == error_mark_node)
+         tree body;
+         int save_lineno = lineno;
+         lineno = EXPR_WFL_LINENO (node);
+         body = java_complete_tree (EXPR_WFL_NODE (node));
+         lineno = save_lineno;
+         EXPR_WFL_NODE (node) = body;
+         TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (body);
+         CAN_COMPLETE_NORMALLY (node) = CAN_COMPLETE_NORMALLY (body);
+         if (body == error_mark_node)
            {
              /* Its important for the evaluation of assignment that
                 this mark on the TREE_TYPE is propagated. */
@@ -6423,6 +7860,7 @@ java_complete_tree (node)
            }
          else
            TREE_TYPE (node) = TREE_TYPE (EXPR_WFL_NODE (node));
+         
        }
       break;
 
@@ -6450,6 +7888,7 @@ java_complete_tree (node)
        }
       /* They complete the array creation expression, if no errors
          were found. */
+      CAN_COMPLETE_NORMALLY (node) = 1;
       return (flag ? error_mark_node : patch_newarray (node));
 
     case NEW_CLASS_EXPR:
@@ -6459,53 +7898,61 @@ java_complete_tree (node)
        return error_mark_node;
       else
        {
-         tree decl;
-         node = patch_method_invocation_stmt (node, NULL_TREE, 
-                                              NULL_TREE, 0, &decl);
-         if (node != error_mark_node)
-           check_thrown_exceptions (EXPR_WFL_LINECOL (node), decl);
-         return node;
+         tree decl, wfl = TREE_OPERAND (node, 0);
+         int in_this = CALL_THIS_CONSTRUCTOR_P (node);
+
+         node = patch_method_invocation (node, NULL_TREE, 
+                                         NULL_TREE, 0, &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));
+         CAN_COMPLETE_NORMALLY (node) = 1;
+         return force_evaluation_order (node);
        }
 
     case MODIFY_EXPR:
       /* Save potential wfls */
       wfl_op1 = TREE_OPERAND (node, 0);
       wfl_op2 = TREE_OPERAND (node, 1);
-      TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
+      TREE_OPERAND (node, 0) = java_complete_lhs (wfl_op1);
       if (TREE_OPERAND (node, 0) == error_mark_node)
        return error_mark_node;
 
       if (COMPOUND_ASSIGN_P (wfl_op2))
        {
-         tree lvalue;
-         tree other = 
-           java_complete_tree (TREE_OPERAND (wfl_op2, 0));
+         tree lvalue = java_stabilize_reference (TREE_OPERAND (node, 0)); 
 
          /* Hand stablize the lhs on both places */
-         lvalue = stabilize_reference (other); 
          TREE_OPERAND (node, 0) = lvalue;
          TREE_OPERAND (TREE_OPERAND (node, 1), 0) = lvalue;
+
+         /* Now complete the RHS. We write it back later on. */
+         nn = java_complete_tree (TREE_OPERAND (node, 1));
+
+         /* The last part of the rewrite for E1 op= E2 is to have 
+            E1 = (T)(E1 op E2), with T being the type of E1. */
+         nn = build_cast (EXPR_WFL_LINECOL (wfl_op2), TREE_TYPE (lvalue), nn);
        }
 
-      /* There are cases where the type of RHS is fixed. In those
-        cases, if the evaluation of the RHS fails, we further the
-        evaluation of the assignment to detect more errors. */
-      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);
+      /* If we're about to patch a NEW_ARRAY_INIT, we call a special
+        function to complete this RHS */
+      else if (TREE_CODE (wfl_op2) == NEW_ARRAY_INIT)
+       nn = patch_new_array_init (TREE_TYPE (TREE_OPERAND (node, 0)),
+                                  TREE_OPERAND (node, 1));
+      /* Otherwise we simply complete the RHS */
+      else
+       nn = java_complete_tree (TREE_OPERAND (node, 1));
 
-         /* Now, we still mark the lhs as initialized */
-         if (DECL_P (TREE_OPERAND (node, 0)))
-           INITIALIZED_P (TREE_OPERAND (node, 0)) = 1;
+      if (nn == error_mark_node)
+       return error_mark_node;
 
-         return error_mark_node;
-       }
+      /* Write back the RHS as we evaluated it. */
       TREE_OPERAND (node, 1) = nn;
 
       /* In case we're handling = with a String as a RHS, we need to
@@ -6513,7 +7960,19 @@ java_complete_tree (node)
         STRING_CST or a StringBuffer at this stage */
       if ((nn = patch_string (TREE_OPERAND (node, 1))))
        TREE_OPERAND (node, 1) = nn;
-      return patch_assignment (node, wfl_op1, wfl_op2);
+      node = patch_assignment (node, wfl_op1, wfl_op2);
+      CAN_COMPLETE_NORMALLY (node) = 1;
+
+      /* Before returning the node, in the context of a static field
+         assignment in <clinit>, we may want to carray further
+         optimizations. (VAR_DECL means it's a static field. See
+         add_field. */
+      if (DECL_NAME (current_function_decl) == clinit_identifier_node
+         && MODIFY_EXPR_FROM_INITIALIZATION_P (node)
+         && TREE_CODE (TREE_OPERAND (node, 0)) == VAR_DECL)
+       node = patch_initialized_static_field (node);
+
+      return node;
 
     case MULT_EXPR:
     case PLUS_EXPR:
@@ -6539,20 +7998,32 @@ java_complete_tree (node)
       wfl_op1 = TREE_OPERAND (node, 0);
       wfl_op2 = TREE_OPERAND (node, 1);
 
+      CAN_COMPLETE_NORMALLY (node) = 1;
       /* Don't complete string nodes if dealing with the PLUS operand. */
       if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op1))
-       {
-         TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
-         if (TREE_OPERAND (node, 0) == error_mark_node)
-           return error_mark_node;
-       }
+        {
+          nn = java_complete_tree (wfl_op1);
+          if (nn == error_mark_node)
+            return error_mark_node;
+          if ((cn = patch_string (nn)))
+            nn = cn;
+          TREE_OPERAND (node, 0) = nn;
+        }
       if (TREE_CODE (node) != PLUS_EXPR || !JSTRING_P (wfl_op2))
-       {
-         TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
-         if (TREE_OPERAND (node, 1) == error_mark_node)
-           return error_mark_node;
-       }
-      return patch_binop (node, wfl_op1, wfl_op2);
+        {
+          nn = java_complete_tree (wfl_op2);
+          if (nn == error_mark_node)
+            return error_mark_node;
+          if ((cn = patch_string (nn)))
+            nn = cn;
+          TREE_OPERAND (node, 1) = nn;
+        }
+      return force_evaluation_order (patch_binop (node, wfl_op1, wfl_op2));
+
+    case INSTANCEOF_EXPR:
+      wfl_op1 = TREE_OPERAND (node, 0);
+      COMPLETE_CHECK_OP_0 (node);
+      return patch_binop (node, wfl_op1, TREE_OPERAND (node, 1));
 
     case UNARY_PLUS_EXPR:
     case NEGATE_EXPR:
@@ -6566,10 +8037,13 @@ java_complete_tree (node)
       /* There are cases were wfl_op1 is a WFL. patch_unaryop knows
         how to handle those cases. */
       wfl_op1 = TREE_OPERAND (node, 0);
+      CAN_COMPLETE_NORMALLY (node) = 1;
       TREE_OPERAND (node, 0) = java_complete_tree (wfl_op1);
       if (TREE_OPERAND (node, 0) == error_mark_node)
        return error_mark_node;
-      return patch_unaryop (node, wfl_op1);
+      node = patch_unaryop (node, wfl_op1);
+      CAN_COMPLETE_NORMALLY (node) = 1;
+      break;
 
     case ARRAY_REF:
       /* There are cases were wfl_op1 is a WFL. patch_array_ref knows
@@ -6585,22 +8059,60 @@ java_complete_tree (node)
       TREE_OPERAND (node, 1) = java_complete_tree (wfl_op2);
       if (TREE_OPERAND (node, 1) == error_mark_node)
        return error_mark_node;
-      TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
-      return patch_array_ref (node, wfl_op1, wfl_op2);
+      if (!flag_emit_class_files)
+       TREE_OPERAND (node, 1) = save_expr (TREE_OPERAND (node, 1));
+      return patch_array_ref (node);
 
-    case THIS_EXPR:
-      /* Can't use THIS in a static environment */
-      if (!current_this)
-       {
-         EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
-         parse_error_context (wfl_operator, "Keyword `this' used outside "
-                              "allowed context");
-         TREE_TYPE (node) = error_mark_node;
-         return error_mark_node;
-       }
-      return current_this;
+    case RECORD_TYPE:
+      return node;;
+
+    case COMPONENT_REF:
+      /* The first step in the re-write of qualified name handling.  FIXME.
+        So far, this is only to support PRIMTYPE.class -> PRIMCLASS.TYPE. */
+      TREE_OPERAND (node, 0) = java_complete_tree (TREE_OPERAND (node, 0));
+      if (TREE_CODE (TREE_OPERAND (node, 0)) == RECORD_TYPE)
+       {
+         tree name = TREE_OPERAND (node, 1);
+         tree field = lookup_field_wrapper (TREE_OPERAND (node, 0), name);
+         if (field == NULL_TREE)
+           {
+             error ("missing static field `%s'", IDENTIFIER_POINTER (name));
+             return error_mark_node;
+           }
+         if (! FIELD_STATIC (field))
+           {
+             error ("not a static field `%s'", IDENTIFIER_POINTER (name));
+             return error_mark_node;
+           }
+         return field;
+       }
+      else
+       fatal ("unimplemented java_complete_tree for COMPONENT_REF");
+      break;
+
+    case THIS_EXPR:
+      /* Can't use THIS in a static environment */
+      if (!current_this)
+       {
+         EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
+         parse_error_context (wfl_operator, "Keyword `this' used outside "
+                              "allowed context");
+         TREE_TYPE (node) = error_mark_node;
+         return error_mark_node;
+       }
+      if (ctxp->explicit_constructor_p)
+       {
+         EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
+         parse_error_context 
+           (wfl_operator, "Can't reference `this' or `super' before the "
+            "superclass constructor has been called");
+         TREE_TYPE (node) = error_mark_node;
+         return error_mark_node;
+       }
+      return current_this;
 
     default:
+      CAN_COMPLETE_NORMALLY (node) = 1;
       /* Ok: may be we have a STRING_CST or a crafted `StringBuffer'
         and it's time to turn it into the appropriate String object
         */
@@ -6622,6 +8134,7 @@ complete_function_arguments (node)
   int flag = 0;
   tree cn;
 
+  ctxp->explicit_constructor_p += (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
   for (cn = TREE_OPERAND (node, 1); cn; cn = TREE_CHAIN (cn))
     {
       tree wfl = TREE_VALUE (cn), parm, temp;
@@ -6636,14 +8149,12 @@ complete_function_arguments (node)
         `+' operator. Build `parm.toString()' and expand it. */
       if ((temp = patch_string (parm)))
        parm = temp;
-      TREE_VALUE (cn) = parm;
+      /* Inline PRIMTYPE.TYPE read access */
+      parm = maybe_build_primttype_type_ref (parm, wfl);
 
-      if (not_initialized_as_it_should_p (parm))
-       {
-         ERROR_VARIABLE_NOT_INITIALIZED (wfl, EXPR_WFL_NODE (wfl));
-         INITIALIZED_P (parm) = 1;
-       }
+      TREE_VALUE (cn) = parm;
     }
+  ctxp->explicit_constructor_p -= (CALL_THIS_CONSTRUCTOR_P (node) ? 1 : 0);
   return flag;
 }
 
@@ -6769,6 +8280,40 @@ maybe_absorb_scoping_blocks ()
    are building incomplete tree nodes and the patch_* functions that
    are completing them.  */
 
+/* Build a super() constructor invocation. Returns empty_stmt_node if
+   we're currently dealing with the class java.lang.Object. */
+
+static tree
+build_super_invocation ()
+{
+  if (current_class == object_type_node)
+    return empty_stmt_node;
+  else
+    {
+      tree super_wfl = build_wfl_node (super_identifier_node, 
+                                      input_filename, 0, 0);
+      return build_method_invocation (super_wfl, NULL_TREE);
+    }
+}
+
+/* Build a SUPER/THIS qualified method invocation.  */
+
+static tree
+build_this_super_qualified_invocation (use_this, name, args, lloc, rloc)
+     int use_this;
+     tree name, args;
+     int lloc, rloc;
+
+{
+  tree invok;
+  tree wfl = 
+    build_wfl_node ((use_this ? this_identifier_node : super_identifier_node),
+                   input_filename, 0, 0);
+  EXPR_WFL_LINECOL (wfl) = lloc;
+  invok = build_method_invocation (name, args);
+  return make_qualified_primary (wfl, invok, rloc);
+}
+
 /* Build an incomplete CALL_EXPR node. */
 
 static tree
@@ -6818,7 +8363,7 @@ build_assignment (op, op_location, lhs, rhs)
 
 /* Print an INTEGER_CST node in a static buffer, and return the buffer. */
 
-static char *
+char *
 print_int_node (node)
     tree node;
 {
@@ -6843,6 +8388,48 @@ print_int_node (node)
   return buffer;
 }
 
+/* Return 1 if you an assignment of a FINAL is attempted */
+
+static int
+check_final_assignment (lvalue, wfl)
+     tree lvalue, wfl;
+{
+  if (JDECL_P (lvalue) && FIELD_FINAL (lvalue) &&
+      DECL_NAME (current_function_decl) != clinit_identifier_node)
+    {
+      parse_error_context 
+        (wfl, "Can't assign a value to the final variable `%s'",
+        IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl)));
+      return 1;
+    }
+  return 0;
+}
+
+/* Inline references to java.lang.PRIMTYPE.TYPE when accessed in
+   read. This is needed to avoid circularities in the implementation
+   of these fields in libjava. */
+
+static tree
+maybe_build_primttype_type_ref (rhs, wfl)
+    tree rhs, wfl;
+{
+  tree to_return = NULL_TREE;
+  tree rhs_type = TREE_TYPE (rhs);
+  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));
+         if (!strncmp (self_name, "java.lang.", 10))
+           to_return = build_primtype_type_ref (self_name);
+       }
+    }
+  return (to_return ? to_return : rhs );
+}
+
 /* 15.25 Assignment operators. */
 
 static tree
@@ -6852,26 +8439,20 @@ patch_assignment (node, wfl_op1, wfl_op2)
      tree wfl_op2;
 {
   tree rhs = TREE_OPERAND (node, 1);
-  tree lvalue = TREE_OPERAND (node, 0);
+  tree lvalue = TREE_OPERAND (node, 0), llvalue;
   tree lhs_type, rhs_type, new_rhs = NULL_TREE;
   int error_found = 0;
   int lvalue_from_array = 0;
 
   /* Can't assign to a final. */
-  if (DECL_P (lvalue) && FIELD_FINAL (lvalue))
-    {
-      parse_error_context 
-        (wfl_op1, "Can't assign a value to the final variable `%s'",
-        IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl_op1)));
-      error_found = 1;
-    }
+  if (check_final_assignment (lvalue, wfl_op1))
+    error_found = 1;
 
   EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
 
   /* Lhs can be a named variable */
-  if (DECL_P (lvalue))
+  if (JDECL_P (lvalue))
     {
-      INITIALIZED_P (lvalue) = 1;
       lhs_type = TREE_TYPE (lvalue);
     }
   /* Or Lhs can be a array acccess. Should that be lvalue ? FIXME +
@@ -6887,8 +8468,18 @@ patch_assignment (node, wfl_op1, wfl_op2)
   /* Or a function return slot */
   else if (TREE_CODE (lvalue) == RESULT_DECL)
     lhs_type = TREE_TYPE (lvalue);
-  /* Otherwise, this is an error */
-  else
+  /* Otherwise, we might want to try to write into an optimized static
+     final, this is an of a different nature, reported further on. */
+  else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
+          && resolve_expression_name (wfl_op1, &llvalue)
+          && check_final_assignment (llvalue, wfl_op1))
+    {
+      error_found = 1;
+      /* What we should do instead is resetting the all the flags
+         previously set, exchange lvalue for llvalue and continue. */
+      return error_mark_node;
+    }
+  else 
     {
       parse_error_context (wfl_op1, "Invalid left hand side of assignment");
       error_found = 1;
@@ -6947,13 +8538,9 @@ patch_assignment (node, wfl_op1, wfl_op2)
       error_found = 1;
     }
 
-  /* Before reporting type incompatibility errors, check that the rhs
-     is initialized, if a variable */
-  if (not_initialized_as_it_should_p (rhs))
-    {
-      ERROR_VARIABLE_NOT_INITIALIZED (wfl_op2, DECL_NAME (rhs));
-      INITIALIZED_P (rhs) = 1;
-    }
+  /* 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;
@@ -6962,13 +8549,42 @@ patch_assignment (node, wfl_op1, wfl_op2)
      assignment into an array element, return it here. */
   if (TREE_CODE (node) == COMPOUND_EXPR)
     return node;
-      
+
   TREE_OPERAND (node, 0) = lvalue;
   TREE_OPERAND (node, 1) = new_rhs;
   TREE_TYPE (node) = lhs_type;
   return node;
 }
 
+/* Optimize static (final) field initialized upon declaration.
+     - If the field is static final and is assigned to a primitive
+       constant type, then set its DECL_INITIAL to the value.
+     - More to come.  */
+
+static tree
+patch_initialized_static_field (node)
+     tree node;
+{
+  tree field = TREE_OPERAND (node, 0);
+  tree value = TREE_OPERAND (node, 1);
+
+  if (DECL_INITIAL (field) != NULL_TREE)
+    {
+      tree type = TREE_TYPE (value);
+      if (FIELD_FINAL (field) && TREE_CONSTANT (value)
+         && (JPRIMITIVE_TYPE_P (type)
+             || (flag_emit_class_files
+                 && TREE_CODE (type) == POINTER_TYPE
+                 && TREE_TYPE (type) == string_type_node)))
+       {
+         DECL_INITIAL (field) = value;
+         return empty_stmt_node;
+       }
+      DECL_INITIAL (field) = NULL_TREE;
+    }
+  return node;
+}
+
 /* Check that type SOURCE can be cast into type DEST. If the cast
    can't occur at all, return 0 otherwise 1. This function is used to
    produce accurate error messages on the reasons why an assignment
@@ -7008,9 +8624,15 @@ try_builtin_assignconv (wfl_op1, lhs_type, rhs)
   tree new_rhs = NULL_TREE;
   tree rhs_type = TREE_TYPE (rhs);
 
+  /* Zero accepted everywhere */
+  if (TREE_CODE (rhs) == INTEGER_CST 
+      && TREE_INT_CST_HIGH (rhs) == 0 && TREE_INT_CST_LOW (rhs) == 0
+      && JPRIMITIVE_TYPE_P (rhs_type))
+    new_rhs = convert (lhs_type, rhs);
+
   /* 5.1.1 Try Identity Conversion,
      5.1.2 Try Widening Primitive Conversion */
-  if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
+  else if (valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type))
     new_rhs = convert (lhs_type, rhs);
 
   /* Try a narrowing primitive conversion (5.1.3): 
@@ -7045,27 +8667,37 @@ static int
 valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type)
      tree lhs_type, rhs_type;
 {
-  int all_primitive = 
-    JPRIMITIVE_TYPE_P (lhs_type) && JPRIMITIVE_TYPE_P (rhs_type);
-
-  if (!all_primitive)
-    return 0;
-
+  /* 5.1.1: This is the identity conversion part. */
   if (lhs_type == rhs_type)
     return 1;
 
-  /* byte, even if it's smaller than a char can't be converted into a
-     char. Short can't too, but the < test below takes care of that */
+  /* Reject non primitive types */
+  if (!JPRIMITIVE_TYPE_P (lhs_type) || !JPRIMITIVE_TYPE_P (rhs_type))
+    return 0;
+
+  /* 5.1.2: widening primitive conversion. byte, even if it's smaller
+     than a char can't be converted into a char. Short can't too, but
+     the < test below takes care of that */
   if (lhs_type == char_type_node && rhs_type == byte_type_node)
     return 0;
 
-  if (JINTEGRAL_TYPE_P (rhs_type)
-      && ((TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type))
-         || (JFLOAT_TYPE_P (lhs_type) &&
-             TYPE_PRECISION (rhs_type) == TYPE_PRECISION (lhs_type))))
+  /* Accept all promoted type here. Note, we can't use <= in the test
+     below, because we still need to bounce out assignments of short
+     to char and the likes */
+  if (lhs_type == int_type_node
+      && (rhs_type == promoted_byte_type_node
+         || rhs_type == promoted_short_type_node
+         || rhs_type == promoted_char_type_node
+         || rhs_type == promoted_boolean_type_node))
     return 1;
-  else if (JFLOAT_TYPE_P (rhs_type)
-          && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
+
+  /* From here, an integral is widened if its precision is smaller
+     than the precision of the LHS or if the LHS is a floating point
+     type, or the RHS is a float and the RHS a double. */
+  if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type) 
+       && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)))
+      || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type))
+      || (rhs_type == float_type_node && lhs_type == double_type_node))
     return 1;
 
   return 0;
@@ -7083,6 +8715,11 @@ valid_ref_assignconv_cast_p (source, dest, cast)
      tree dest;
      int cast;
 {
+  /* SOURCE or DEST might be null if not from a declared entity. */
+  if (!source || !dest)
+    return 0;
+  if (JNULLP_TYPE_P (source))
+    return 1;
   if (TREE_CODE (source) == POINTER_TYPE)
     source = TREE_TYPE (source);
   if (TREE_CODE (dest) == POINTER_TYPE)
@@ -7158,8 +8795,10 @@ valid_ref_assignconv_cast_p (source, dest, cast)
     {
       if (TYPE_CLASS_P (dest))
        return dest == object_type_node;
+      /* Can't cast an array to an interface unless the interface is
+        java.lang.Cloneable */
       if (TYPE_INTERFACE_P (dest))
-       return 0;               /* Install test on Clonable. FIXME */
+       return (DECL_NAME (TYPE_NAME (dest)) == java_lang_cloneable ? 1 : 0);
       else                     /* Arrays */
        {
          tree source_element_type = TYPE_ARRAY_ELEMENT (source);
@@ -7201,16 +8840,28 @@ valid_cast_to_p (source, dest)
    converted to type DEST through the methond invocation conversion
    process (5.3) */
 
+static tree
+do_unary_numeric_promotion (arg)
+     tree arg;
+{
+  tree type = TREE_TYPE (arg);
+  if (TREE_CODE (type) == INTEGER_TYPE ? TYPE_PRECISION (type) < 32
+      : TREE_CODE (type) == CHAR_TYPE)
+    arg = convert (int_type_node, arg);
+  return arg;
+}
+
+/* Return a non zero value if SOURCE can be converted into DEST using
+   the method invocation conversion rule (5.3).  */
 static int
 valid_method_invocation_conversion_p (dest, source)
      tree dest, source;
 {
-  return ((JPRIMITIVE_TYPE_P (source) 
-           && JPRIMITIVE_TYPE_P (dest)
-           && valid_builtin_assignconv_identity_widening_p (dest, source))
-          || (JREFERENCE_TYPE_P (source) 
-              && JREFERENCE_TYPE_P (dest)
-              && valid_ref_assignconv_cast_p (source, dest, 0)));
+  return ((JPRIMITIVE_TYPE_P (source) && JPRIMITIVE_TYPE_P (dest)
+          && valid_builtin_assignconv_identity_widening_p (dest, source))
+         || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source))
+             && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest))
+             && valid_ref_assignconv_cast_p (source, dest, 0)));
 }
 
 /* Build an incomplete binop expression. */
@@ -7221,9 +8872,7 @@ build_binop (op, op_location, op1, op2)
      int op_location;
      tree op1, op2;
 {
-  tree binop;
-
-  binop = build (op, NULL_TREE, op1, op2);
+  tree binop = build (op, NULL_TREE, op1, op2);
   TREE_SIDE_EFFECTS (binop) = 1;
   /* Store the location of the operator, for better error report. The
      string of the operator will be rebuild based on the OP value. */
@@ -7308,24 +8957,8 @@ 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);
 
-  /* Check initialization of LHS first. We then silence further error
-     message if the variable wasn't initialized */
-  if (not_initialized_as_it_should_p (cfi))
-    {
-      ERROR_VARIABLE_NOT_INITIALIZED (cfi_wfl, DECL_NAME (cfi));
-      INITIALIZED_P (op1) = 1;
-    }
-
   switch (code)
     {
     /* 15.16 Multiplicative operators */
@@ -7346,10 +8979,18 @@ patch_binop (node, wfl_op1, wfl_op2)
       /* Change the division operator if necessary */
       if (code == RDIV_EXPR && TREE_CODE (prom_type) == INTEGER_TYPE)
        TREE_SET_CODE (node, TRUNC_DIV_EXPR);
-      /* This one is more complicated. FLOATs are processed by a function
-        call to soft_fmod. */
+
+      /* This one is more complicated. FLOATs are processed by a
+        function call to soft_fmod. Duplicate the value of the
+        COMPOUND_ASSIGN_P flag. */
       if (code == TRUNC_MOD_EXPR)
-       return build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
+       {
+         tree mod = build_java_binop (TRUNC_MOD_EXPR, prom_type, op1, op2);
+         COMPOUND_ASSIGN_P (mod) = COMPOUND_ASSIGN_P (node);
+         TREE_SIDE_EFFECTS (mod)
+           = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
+         return mod;
+       }
       break;
 
     /* 15.17 Additive Operators */
@@ -7406,8 +9047,8 @@ patch_binop (node, wfl_op1, wfl_op2)
 
       /* Unary numeric promotion (5.6.1) is performed on each operand
          separatly */
-      op1 = convert (promote_type (op1_type), op1);
-      op2 = convert (promote_type (op2_type), op2);
+      op1 = do_unary_numeric_promotion (op1);
+      op2 = do_unary_numeric_promotion (op2);
 
       /* The type of the shift expression is the type of the promoted
          type of the left-hand operand */
@@ -7422,13 +9063,86 @@ patch_binop (node, wfl_op1, wfl_op2)
                           build_int_2 (0x3f, 0)));
 
       /* The >>> operator is a >> operating on unsigned quantities */
-      if (code == URSHIFT_EXPR)
+      if (code == URSHIFT_EXPR && ! flag_emit_class_files)
        {
-         op1 = convert (unsigned_type (prom_type), op1);
+         tree to_return;
+          tree utype = unsigned_type (prom_type);
+          op1 = convert (utype, op1);
          TREE_SET_CODE (node, RSHIFT_EXPR);
+          TREE_OPERAND (node, 0) = op1;
+          TREE_OPERAND (node, 1) = op2;
+          TREE_TYPE (node) = utype;
+         to_return = convert (prom_type, node);
+         /* Copy the original value of the COMPOUND_ASSIGN_P flag */
+         COMPOUND_ASSIGN_P (to_return) = COMPOUND_ASSIGN_P (node);
+         TREE_SIDE_EFFECTS (to_return)
+           = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
+         return to_return;
        }
       break;
+
+      /* 15.19.1 Type Comparison Operator instaceof */
+    case INSTANCEOF_EXPR:
+
+      TREE_TYPE (node) = boolean_type_node;
+
+      if (!(op2_type = resolve_type_during_patch (op2)))
+       return error_mark_node;
+
+      /* The first operand must be a reference type or the null type */
+      if (!JREFERENCE_TYPE_P (op1_type) && op1 != null_pointer_node)
+       error_found = 1;        /* Error reported further below */
+
+      /* The second operand must be a reference type */
+      if (!JREFERENCE_TYPE_P (op2_type))
+       {
+         SET_WFL_OPERATOR (wfl_operator, node, wfl_op2);
+         parse_error_context
+           (wfl_operator, "Invalid argument `%s' for `instanceof'",
+            lang_printable_name (op2_type, 0));
+         error_found = 1;
+       }
+
+      if (!error_found && valid_ref_assignconv_cast_p (op1_type, op2_type, 1))
+       {
+         /* If the first operand is null, the result is always false */
+         if (op1 == null_pointer_node)
+           return boolean_false_node;
+         else if (flag_emit_class_files)
+           {
+             TREE_OPERAND (node, 1) = op2_type;
+             TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1);
+             return node;
+           }
+         /* Otherwise we have to invoke instance of to figure it out */
+         else
+           {
+             tree call =
+               build (CALL_EXPR, boolean_type_node,
+                      build_address_of (soft_instanceof_node),
+                      tree_cons 
+                      (NULL_TREE, op1,
+                       build_tree_list (NULL_TREE,
+                                        build_class_ref (op2_type))),
+                      NULL_TREE);
+             TREE_SIDE_EFFECTS (call) = TREE_SIDE_EFFECTS (op1);
+             return call;
+           }
+       }
+      /* There is no way the expression operand can be an instance of
+        the type operand. This is a compile time error. */
+      else
+       {
+         char *t1 = strdup (lang_printable_name (op1_type, 0));
+         SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
+         parse_error_context 
+           (wfl_operator, "Impossible for `%s' to be instance of `%s'",
+            t1, lang_printable_name (op2_type, 0));
+         free (t1);
+         error_found = 1;
+       }
       
+      break;
 
       /* 15.21 Bitwise and Logical Operators */
     case BIT_AND_EXPR:
@@ -7504,7 +9218,7 @@ patch_binop (node, wfl_op1, wfl_op2)
     case NE_EXPR:
       /* 15.20.1 Numerical Equality Operators == and != */
       /* Binary numeric promotion is performed on the operands */
-      if (JPRIMITIVE_TYPE_P (op1_type) && JPRIMITIVE_TYPE_P (op2_type))
+      if (JNUMERIC_TYPE_P (op1_type) && JNUMERIC_TYPE_P (op2_type))
        binary_numeric_promotion (op1_type, op2_type, &op1, &op2);
       
       /* 15.20.2 Boolean Equality Operators == and != */
@@ -7513,10 +9227,14 @@ patch_binop (node, wfl_op1, wfl_op2)
        ;                       /* Nothing to do here */
       
       /* 15.20.3 Reference Equality Operators == and != */
-      /* Types have to be either references or the null type */
+      /* Types have to be either references or the null type. If
+         they're references, it must be possible to convert either
+         type to the other by casting conversion. */
       else if (op1 == null_pointer_node || op2 == null_pointer_node 
               || (JREFERENCE_TYPE_P (op1_type) && JREFERENCE_TYPE_P (op2_type)
-                  && ((op1_type == op2_type))))
+                  && (valid_ref_assignconv_cast_p (op1_type, op2_type, 1)
+                      || valid_ref_assignconv_cast_p (op2_type, 
+                                                      op1_type, 1))))
        ;                       /* Nothing to do here */
          
       /* Else we have an error figure what can't be converted into
@@ -7538,22 +9256,14 @@ patch_binop (node, wfl_op1, wfl_op2)
       break;
     }
 
-  /* Then check the initialization of the RHS. We don't do that if
-     we're dealing with a node that is part of a compound
-     assignment. We then silence further error message if the variable
-     wasn't initialized */
-  if (not_initialized_as_it_should_p (op2) && !COMPOUND_ASSIGN_P (node))
-    {
-      ERROR_VARIABLE_NOT_INITIALIZED (wfl_op2, DECL_NAME (op2));
-      INITIALIZED_P (op2) = 1;
-    }
-
   if (error_found)
     return error_mark_node;
 
   TREE_OPERAND (node, 0) = op1;
   TREE_OPERAND (node, 1) = op2;
   TREE_TYPE (node) = prom_type;
+  TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
+  
   return fold (node);
 }
 
@@ -7673,25 +9383,40 @@ build_string_concatenation (op1, op2)
      tree op1, op2;
 {
   tree result;
+  int side_effects = TREE_SIDE_EFFECTS (op1) | TREE_SIDE_EFFECTS (op2);
+
   
   /* Try to do some static optimization */
   if ((result = string_constant_concatenation (op1, op2)))
     return result;
 
-  /* If operands are string constant, turn then into object references */
+  /* Discard empty strings on either side of the expression */
+  if (TREE_CODE (op1) == STRING_CST && TREE_STRING_LENGTH (op1) == 0)
+    {
+      op1 = op2;
+      op2 = NULL_TREE;
+    }
+  else if (TREE_CODE (op2) == STRING_CST && TREE_STRING_LENGTH (op2) == 0)
+    op2 = NULL_TREE;
 
+  /* If operands are string constant, turn then into object references */
   if (TREE_CODE (op1) == STRING_CST)
     op1 = patch_string_cst (op1);
-  if (TREE_CODE (op2) == STRING_CST)
+  if (op2 && TREE_CODE (op2) == STRING_CST)
     op2 = patch_string_cst (op2);
 
+  /* If either one of the constant is null and the other non null
+     operand is a String object, return it. */
+  if (JSTRING_TYPE_P (TREE_TYPE (op1)) && !op2)
+    return op1;
+
   /* If OP1 isn't already a StringBuffer, create and
      initialize a new one */
   if (!IS_CRAFTED_STRING_BUFFER_P (op1))
     {
       /* Two solutions here: 
         1) OP1 is a string reference, we call new StringBuffer(OP1)
-        2) Op2 is something else, we call new StringBuffer().append(OP1). */
+        2) OP1 is something else, we call new StringBuffer().append(OP1). */
       if (JSTRING_TYPE_P (TREE_TYPE (op1)))
        op1 = BUILD_STRING_BUFFER (op1);
       else
@@ -7701,13 +9426,19 @@ build_string_concatenation (op1, op2)
        }
     }
 
-  /* No longer the last node holding a crafted StringBuffer */
-  IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
-  /* Create a node for `{new...,xxx}.append (op2)' */
-  op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
+  if (op2)
+    {
+      /* OP1 is no longer the last node holding a crafted StringBuffer */
+      IS_CRAFTED_STRING_BUFFER_P (op1) = 0;
+      /* Create a node for `{new...,xxx}.append (op2)' */
+      if (op2)
+       op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0);
+    }
+
   /* Mark the last node holding a crafted StringBuffer */
   IS_CRAFTED_STRING_BUFFER_P (op1) = 1;
-  
+
+  TREE_SIDE_EFFECTS (op1) = side_effects;
   return op1;
 }
 
@@ -7719,12 +9450,21 @@ static tree
 patch_string (node)
     tree node;
 {
+  if (node == error_mark_node)
+    return error_mark_node;
   if (TREE_CODE (node) == STRING_CST)
     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;
 }
@@ -7736,10 +9476,13 @@ patch_string_cst (node)
      tree node;
 {
   int location;
-  push_obstacks (&permanent_obstack, &permanent_obstack);
-  node = get_identifier (TREE_STRING_POINTER (node));
-  location = alloc_name_constant (CONSTANT_String, node);
-  node = build_ref_from_constant_pool (location);
+  if (! flag_emit_class_files)
+    {
+      push_obstacks (&permanent_obstack, &permanent_obstack);
+      node = get_identifier (TREE_STRING_POINTER (node));
+      location = alloc_name_constant (CONSTANT_String, node);
+      node = build_ref_from_constant_pool (location);
+    }
   TREE_TYPE (node) = promote_type (string_type_node);
   TREE_CONSTANT (node) = 1;
   return node;
@@ -7821,7 +9564,7 @@ patch_unaryop (node, wfl_op)
 {
   tree op = TREE_OPERAND (node, 0);
   tree op_type = TREE_TYPE (op);
-  tree prom_type, value;
+  tree prom_type, value, decl;
   int code = TREE_CODE (node);
   int error_found = 0;
 
@@ -7837,22 +9580,27 @@ patch_unaryop (node, wfl_op)
     case PREINCREMENT_EXPR:
       /* 15.14.2 Prefix Decrement Operator -- */
     case PREDECREMENT_EXPR:
-      if (!DECL_P (op) && !(TREE_CODE (op) == INDIRECT_REF 
-                           && JPRIMITIVE_TYPE_P (TREE_TYPE (op))))
-       {
-         parse_error_context (wfl_operator, "Invalid argument to `%s'",
-                              operator_string (node));
-         TREE_TYPE (node) = error_mark_node;
-         error_found = 1;
-       }
-      else if (FIELD_FINAL (op))
+      decl = strip_out_static_field_access_decl (op);
+      if (!JDECL_P (decl) 
+         && !((TREE_CODE (decl) == INDIRECT_REF 
+               || TREE_CODE (decl) == COMPONENT_REF) 
+              && JPRIMITIVE_TYPE_P (TREE_TYPE (decl))))
        {
-         parse_error_context 
-           (wfl_op, "Can't assign a value to the final variable `%s'",
-            IDENTIFIER_POINTER (EXPR_WFL_NODE (wfl_op)));
+         tree lvalue;
+         /* Before screaming, check that we're not in fact trying to
+            increment a optimized static final access, in which case
+            we issue an different error message. */
+         if (!(TREE_CODE (wfl_op) == EXPR_WITH_FILE_LOCATION
+               && resolve_expression_name (wfl_op, &lvalue)
+               && check_final_assignment (lvalue, wfl_op)))
+           parse_error_context (wfl_operator, "Invalid argument to `%s'",
+                                operator_string (node));
          TREE_TYPE (node) = error_mark_node;
          error_found = 1;
        }
+      else if (check_final_assignment (op, wfl_op))
+       error_found = 1;
+
       /* From now on, we know that op if a variable and that it has a
          valid wfl. We use wfl_op to locate errors related to the
          ++/-- operand. */
@@ -7866,13 +9614,16 @@ patch_unaryop (node, wfl_op)
        }
       else
        {
-         /* Before the addition, binary numeric promotion if performed on
+         /* Before the addition, binary numeric promotion is performed on
             both operands */
-         value = integer_one_node;
-         prom_type = binary_numeric_promotion (op_type, TREE_TYPE (value), 
-                                               &op, &value);
-         /* And write the promoted increment back */
+         value = build_int_2 (1, 0);
+         TREE_TYPE (node) = 
+           binary_numeric_promotion (op_type, TREE_TYPE (value), &op, &value);
+         /* And write the promoted incremented and increment */
+         TREE_OPERAND (node, 0) = op;
          TREE_OPERAND (node, 1) = value;
+         /* Convert the overall back into its original type. */
+         return fold (convert (op_type, node));
        }
       break;
 
@@ -7889,10 +9640,10 @@ patch_unaryop (node, wfl_op)
       /* Unary numeric promotion is performed on operand */
       else
        {
-         prom_type = promote_type (op_type);
-         op = convert (prom_type, op);
+         op = do_unary_numeric_promotion (op);
+         prom_type = TREE_TYPE (op);
          if (code == UNARY_PLUS_EXPR)
-           node = op;
+           return fold (op);
        }
       break;
 
@@ -7906,8 +9657,8 @@ patch_unaryop (node, wfl_op)
        }
       else
        {
-         prom_type = promote_type (op_type);
-         op = convert (prom_type, op);
+         op = do_unary_numeric_promotion (op);
+         prom_type = TREE_TYPE (op);
        }
       break;
 
@@ -7916,6 +9667,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;
        }
@@ -7928,29 +9681,30 @@ patch_unaryop (node, wfl_op)
       value = patch_cast (node, wfl_operator);
       if (value == error_mark_node)
        {
+         /* 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;
+       {
+         value = fold (value);
+         TREE_SIDE_EFFECTS (value) = TREE_SIDE_EFFECTS (op);
+         return value;
+       }
       break;
     }
   
-  /* Check variable initialization */
-  if (not_initialized_as_it_should_p (op))
-    {
-      ERROR_VARIABLE_NOT_INITIALIZED (wfl_op, DECL_NAME (op));
-      INITIALIZED_P (op) = 1;
-    }
-  
   if (error_found)
     return error_mark_node;
-  /* In the case of UNARY_PLUS_EXPR, we replaced NODE by a new one */
-  else if (code != UNARY_PLUS_EXPR && code != CONVERT_EXPR)
-    {
-      TREE_OPERAND (node, 0) = op;
-      TREE_TYPE (node) = prom_type;
-    }
+
+  /* There are cases where node has been replaced by something else
+     and we don't end up returning here: UNARY_PLUS_EXPR,
+     CONVERT_EXPR, {POST,PRE}{INCR,DECR}EMENT_EXPR. */
+  TREE_OPERAND (node, 0) = fold (op);
+  TREE_TYPE (node) = prom_type;
+  TREE_SIDE_EFFECTS (node) = TREE_SIDE_EFFECTS (op);
   return fold (node);
 }
 
@@ -7973,7 +9727,10 @@ resolve_type_during_patch (type)
          return NULL_TREE;
        }
       else
-       return TREE_TYPE (type_decl);
+       {
+         CLASS_LOADED_P (TREE_TYPE (type_decl)) = 1;
+         return TREE_TYPE (type_decl);
+       }
     }
   return type;
 }
@@ -8002,16 +9759,29 @@ patch_cast (node, wfl_operator)
       if (cast_type == op_type)
        return node;
 
+      /* float and double type are converted to the original type main
+        variant and then to the target type. */
+      if (JFLOAT_TYPE_P (op_type) && TREE_CODE (cast_type) == CHAR_TYPE)
+       op = convert (integer_type_node, op);
+
       /* Try widening/narowwing convertion. Potentially, things need
         to be worked out in gcc so we implement the extreme cases
         correctly. fold_convert() needs to be fixed. */
       return convert (cast_type, op);
     }
 
+  /* It's also valid to cast a boolean into a boolean */
+  if (op_type == boolean_type_node && cast_type == boolean_type_node)
+    return node;
+
+  /* null can be casted to references */
+  if (op == null_pointer_node && JREFERENCE_TYPE_P (cast_type))
+    return build_null_of_type (cast_type);
+
   /* The remaining legal casts involve conversion between reference
      types. Check for their compile time correctness. */
   if (JREFERENCE_TYPE_P (op_type) && JREFERENCE_TYPE_P (cast_type) 
-      && valid_ref_assignconv_cast_p (cast_type, op_type, 1))
+      && valid_ref_assignconv_cast_p (op_type, cast_type, 1))
     {
       TREE_TYPE (node) = promote_type (cast_type);
       /* Now, the case can be determined correct at compile time if
@@ -8019,7 +9789,16 @@ patch_cast (node, wfl_operator)
          conversion (5.2) */
 
       if (valid_ref_assignconv_cast_p (op_type, cast_type, 0))
-       return node;
+       {
+         TREE_SET_CODE (node, NOP_EXPR);
+         return node;
+       }
+
+      if (flag_emit_class_files)
+       {
+         TREE_SET_CODE (node, CONVERT_EXPR);
+         return node;
+       }
 
       /* The cast requires a run-time check */
       return build (CALL_EXPR, promote_type (cast_type),
@@ -8037,6 +9816,17 @@ patch_cast (node, wfl_operator)
   return error_mark_node;
 }
 
+/* Build a null constant and give it the type TYPE.  */
+
+static tree
+build_null_of_type (type)
+     tree type;
+{
+  tree node = build_int_2 (0, 0);
+  TREE_TYPE (node) = promote_type (type);
+  return node;
+}
+
 /* Build an ARRAY_REF incomplete tree node. Note that operand 1 isn't
    a list of indices. */
 static tree
@@ -8052,24 +9842,17 @@ 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);
   tree index = TREE_OPERAND (node, 1);
   tree index_type = TREE_TYPE (index);
-  tree promoted_index_type;
   int error_found = 0;
 
   EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
 
-  if (not_initialized_as_it_should_p (array))
-    {
-      ERROR_VARIABLE_NOT_INITIALIZED (wfl_array, DECL_NAME (array));
-      INITIALIZED_P (array) = 1;
-    }
-
   if (TREE_CODE (array_type) == POINTER_TYPE)
     array_type = TREE_TYPE (array_type);
 
@@ -8085,8 +9868,8 @@ patch_array_ref (node, wfl_array, wfl_index)
 
   /* The array index underdoes unary numeric promotion. The promoted
      type must be int */
-  promoted_index_type = promote_type (index_type);
-  if (promoted_index_type != int_type_node)
+  index = do_unary_numeric_promotion (index);
+  if (TREE_TYPE (index) != int_type_node)
     {
       int could_cast = valid_cast_to_p (index_type, int_type_node);
       parse_error_context 
@@ -8099,26 +9882,27 @@ patch_array_ref (node, wfl_array, wfl_index)
       error_found = 1;
     }
 
-  /* Now if the index is a var/parm decl, check on its initialization */
-  if (not_initialized_as_it_should_p (index))
-    {
-      ERROR_VARIABLE_NOT_INITIALIZED (wfl_index, DECL_NAME (index));
-      INITIALIZED_P (index) = 1;
-    }
-
   if (error_found)
     return error_mark_node;
-  index = convert (promoted_index_type, index);
 
-  if (TREE_CODE (array_type) == RECORD_TYPE)
-    array_type = promote_type (TYPE_ARRAY_ELEMENT (array_type));
+  array_type = TYPE_ARRAY_ELEMENT (array_type);
+
   if (flag_emit_class_files)
     {
-      TREE_OPERAND (node, 0)= array;
-      TREE_OPERAND (node, 1)= index;
+      TREE_OPERAND (node, 0) = array;
+      TREE_OPERAND (node, 1) = index;
     }
   else
-    node = build_java_arrayaccess (array, array_type, index);
+    {
+      /* The save_expr is for correct evaluation order.  It would be cleaner
+        to use force_evaluation_order (see comment there), but that is
+        difficult when we also have to deal with bounds checking. */
+      if (TREE_SIDE_EFFECTS (index))
+       array = save_expr (array);
+      node = build_java_arrayaccess (array, array_type, index);
+      if (TREE_SIDE_EFFECTS (index))
+       node = build (COMPOUND_EXPR, array_type, array, node);
+    }
   TREE_TYPE (node) = array_type;
   return node;
 }
@@ -8147,7 +9931,6 @@ patch_newarray (node)
   int error_found = 0;
   int ndims = 0;
   int xdims = TREE_INT_CST_LOW (TREE_OPERAND (node, 2));
-  int total_dims;
 
   /* Dimension types are verified. It's better for the types to be
      verified in order. */
@@ -8167,7 +9950,7 @@ patch_newarray (node)
         promoted type must be int. */
       else
        {
-         dim = convert (promote_type (TREE_TYPE (dim)), dim);
+         dim = do_unary_numeric_promotion (dim);
          if (TREE_TYPE (dim) != int_type_node)
            dim_error = 1;
        }
@@ -8185,15 +9968,6 @@ patch_newarray (node)
          error_found = 1;
        }
 
-      /* Check for uninitialized variables */
-      if (not_initialized_as_it_should_p (dim))
-       {
-         ERROR_VARIABLE_NOT_INITIALIZED (TREE_PURPOSE (cdim), 
-                                         DECL_NAME (dim));
-         INITIALIZED_P (dim) = 1;
-         error_found = 1;
-       }
-
       TREE_PURPOSE (cdim) = NULL_TREE;
     }
 
@@ -8209,95 +9983,225 @@ patch_newarray (node)
       return error_mark_node;
     }
 
+  /* Set array_type to the actual (promoted) array type of the result. */
+  if (TREE_CODE (type) == RECORD_TYPE)
+    type = build_pointer_type (type);
+  while (--xdims >= 0)
+    {
+      type = promote_type (build_java_array_type (type, -1));
+    }
+  dims = nreverse (dims);
+  array_type = type;
+  for (cdim = dims; cdim; cdim = TREE_CHAIN (cdim))
+    {
+      type = array_type;
+      array_type = build_java_array_type (type,
+                                         TREE_CODE (cdim) == INTEGER_CST ?
+                                         TREE_INT_CST_LOW (cdim) : -1);
+      array_type = promote_type (array_type);
+    }
+  dims = nreverse (dims);
+
   /* The node is transformed into a function call. Things are done
      differently according to the number of dimensions. If the number
      of dimension is equal to 1, then the nature of the base type
      (primitive or not) matters. */
-  total_dims = xdims + ndims;
-  if (total_dims == 1)
-    {
-      if (JPRIMITIVE_TYPE_P (type))
-       {
-         int type_code;
-         if (type == boolean_type_node)
-           type_code = 4;
-         else if (type == char_type_node)
-           type_code = 5;
-         else if (type == float_type_node)
-           type_code = 6;
-         else if (type == double_type_node)
-           type_code = 7;
-         else if (type == byte_type_node)
-           type_code = 8;
-         else if (type == short_type_node)
-           type_code = 9;
-         else if (type == int_type_node)
-           type_code = 10;
-         else if (type == long_type_node)
-           type_code = 11;
-         else
-           fatal ("Can't compute type code - patch_newarray");
-         return build_newarray (type_code, TREE_VALUE (dims));
-       }
-      else
-       return build_anewarray (type, TREE_VALUE (dims));
-    }
+  if (ndims == 1)
+    return build_new_array (type, TREE_VALUE (dims));
   
-  /* Add extra dimensions as unknown dimensions */
-  while (xdims--)
-    dims = 
-      chainon (dims, build_tree_list (NULL_TREE, integer_negative_one_node));
-  dims = chainon (dims, build_tree_list (NULL_TREE, integer_zero_node));
-
   /* Can't reuse what's already written in expr.c because it uses the
      JVM stack representation. Provide a build_multianewarray. FIXME */
-  array_type = type;
-  for (cdim = TREE_CHAIN (dims); cdim; cdim = TREE_CHAIN (cdim))
-    array_type = build_java_array_type (promote_type (array_type), 
-                                       TREE_CODE (cdim) == INTEGER_CST ?
-                                       TREE_INT_CST_LOW (cdim) : -1);
-  return build (CALL_EXPR,
-               promote_type (array_type),
+  return build (CALL_EXPR, array_type,
                build_address_of (soft_multianewarray_node),
-               tree_cons (NULL_TREE, build_class_ref (array_type),
+               tree_cons (NULL_TREE, build_class_ref (TREE_TYPE (array_type)),
                           tree_cons (NULL_TREE, 
-                                     build_int_2 (total_dims, 0), dims )),
+                                     build_int_2 (ndims, 0), dims )),
                NULL_TREE);
 }
 
+/* 10.6 Array initializer.  */
+
+/* Build a wfl for array element that don't have one, so we can
+   pin-point errors.  */
+
 static tree
-build_this (location)
-     int location;
+maybe_build_array_element_wfl (node)
+     tree node;
 {
-  tree node = build_wfl_node (this_identifier_node, input_filename, 0, 0);
-  TREE_SET_CODE (node, THIS_EXPR);
-  EXPR_WFL_LINECOL (node) = location;
-  return node;
+  if (TREE_CODE (node) != EXPR_WITH_FILE_LOCATION)
+    return build_expr_wfl (NULL_TREE, ctxp->filename,
+                          ctxp->elc.line, ctxp->elc.prev_col);
+  else
+    return NULL_TREE;
 }
 
-/* 14.15 The return statement. It builds a modify expression that
-   assigns the returned value to the RESULT_DECL that hold the value
-   to be returned. */
+/* Build a NEW_ARRAY_INIT that features a CONSTRUCTOR node. This makes
+   identification of initialized arrays easier to detect during walk
+   and expansion.  */
 
 static tree
-build_return (location, op)
+build_new_array_init (location, values)
      int location;
-     tree op;
+     tree values;
 {
-  tree node = build1 (RETURN_EXPR, NULL_TREE, op);
-  EXPR_WFL_LINECOL (node) = location;
-  node = build_debugable_stmt (location, node);
-  return node;
+  tree constructor = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, values);
+  tree to_return = build1 (NEW_ARRAY_INIT, NULL_TREE, constructor);
+  EXPR_WFL_LINECOL (to_return) = location;
+  return to_return;
 }
 
+/* Expand a NEW_ARRAY_INIT node. Return error_mark_node if an error
+   occurred.  Otherwise return NODE after having set its type
+   appropriately.  */
+
 static tree
-patch_return (node)
+patch_new_array_init (type, node)
+     tree type, node;
+{
+  int error_seen = 0;
+  tree current, element_type;
+  HOST_WIDE_INT length;
+  int all_constant = 1;
+  tree init = TREE_OPERAND (node, 0);
+
+  if (TREE_CODE (type) != POINTER_TYPE || ! TYPE_ARRAY_P (TREE_TYPE (type)))
+    {
+      parse_error_context (node,
+                          "Invalid array initializer for non-array type `%s'",
+                          lang_printable_name (type, 1));
+      return error_mark_node;
+    }
+  type = TREE_TYPE (type);
+  element_type = TYPE_ARRAY_ELEMENT (type);
+
+  CONSTRUCTOR_ELTS (init) = nreverse (CONSTRUCTOR_ELTS (init));
+
+  for (length = 0, current = CONSTRUCTOR_ELTS (init);
+       current;  length++, current = TREE_CHAIN (current))
+    {
+      tree elt = TREE_VALUE (current);
+      if (elt == NULL_TREE || TREE_CODE (elt) != NEW_ARRAY_INIT)
+       {
+         error_seen |= array_constructor_check_entry (element_type, current);
+         elt = TREE_VALUE (current);
+         /* When compiling to native code, STRING_CST is converted to
+            INDIRECT_REF, but still with a TREE_CONSTANT flag. */
+         if (! TREE_CONSTANT (elt) || TREE_CODE (elt) == INDIRECT_REF)
+           all_constant = 0;
+       }
+      else
+       {
+         TREE_VALUE (current) = patch_new_array_init (element_type, elt);
+         TREE_PURPOSE (current) = NULL_TREE;
+         all_constant = 0;
+       }
+      if (elt && TREE_VALUE (elt) == error_mark_node)
+       error_seen = 1;
+    }
+
+  if (error_seen)
+    return error_mark_node;
+
+  /* Create a new type. We can't reuse the one we have here by
+     patching its dimension because it originally is of dimension -1
+     hence reused by gcc. This would prevent triangular arrays. */
+  type = build_java_array_type (element_type, length);
+  TREE_TYPE (init) = TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (type))));
+  TREE_TYPE (node) = promote_type (type);
+  TREE_CONSTANT (init) = all_constant;
+  TREE_CONSTANT (node) = all_constant;
+  return node;
+}
+
+/* Verify that one entry of the initializer element list can be
+   assigned to the array base type. Report 1 if an error occurred, 0
+   otherwise.  */
+
+static int
+array_constructor_check_entry (type, entry)
+     tree type, entry;
+{
+  char *array_type_string = NULL;      /* For error reports */
+  tree value, type_value, new_value, wfl_value, patched;
+  int error_seen = 0;
+
+  new_value = NULL_TREE;
+  wfl_value = TREE_VALUE (entry);
+
+  value = java_complete_tree (TREE_VALUE (entry));
+  /* patch_string return error_mark_node if arg is error_mark_node */
+  if ((patched = patch_string (value)))
+    value = patched;
+  if (value == error_mark_node)
+    return 1;
+  
+  type_value = TREE_TYPE (value);
+  
+  /* At anytime, try_builtin_assignconv can report a warning on
+     constant overflow during narrowing. */
+  SET_WFL_OPERATOR (wfl_operator, TREE_PURPOSE (entry), wfl_value);
+  new_value = try_builtin_assignconv (wfl_operator, type, value);
+  if (!new_value && (new_value = try_reference_assignconv (type, value)))
+    type_value = promote_type (type);
+  
+  /* Check and report errors */
+  if (!new_value)
+    {
+      char *msg = (!valid_cast_to_p (type_value, type) ?
+                  "Can't" : "Explicit cast needed to");
+      if (!array_type_string)
+       array_type_string = strdup (lang_printable_name (type, 1));
+      parse_error_context 
+       (wfl_operator, "Incompatible type for array. %s convert `%s' to `%s'",
+        msg, lang_printable_name (type_value, 1), array_type_string);
+      error_seen = 1;
+    }
+  
+  if (new_value)
+    {
+      new_value = maybe_build_primttype_type_ref (new_value, wfl_operator);
+      TREE_VALUE (entry) = new_value;
+    }
+
+  if (array_type_string)
+    free (array_type_string);
+
+  TREE_PURPOSE (entry) = NULL_TREE;
+  return error_seen;
+}
+
+static tree
+build_this (location)
+     int location;
+{
+  tree node = build_wfl_node (this_identifier_node, input_filename, 0, 0);
+  TREE_SET_CODE (node, THIS_EXPR);
+  EXPR_WFL_LINECOL (node) = location;
+  return node;
+}
+
+/* 14.15 The return statement. It builds a modify expression that
+   assigns the returned value to the RESULT_DECL that hold the value
+   to be returned. */
+
+static tree
+build_return (location, op)
+     int location;
+     tree op;
+{
+  tree node = build1 (RETURN_EXPR, NULL_TREE, op);
+  EXPR_WFL_LINECOL (node) = location;
+  node = build_debugable_stmt (location, node);
+  return node;
+}
+
+static tree
+patch_return (node)
      tree node;
 {
   tree return_exp = TREE_OPERAND (node, 0);
   tree meth = current_function_decl;
   tree mtype = TREE_TYPE (TREE_TYPE (current_function_decl));
-  tree modify;
   int error_found = 0;
 
   TREE_TYPE (node) = error_mark_node;
@@ -8315,20 +10219,49 @@ patch_return (node)
 
   if (error_found)
     {
-      char *t = strdup (lang_printable_name (mtype, 0));
-      parse_error_context (wfl_operator, "`return' with%s value from `%s %s'",
-                          (error_found == 1 ? "" : "out"), t,
-                          lang_printable_name (meth, 0));
-      free (t);
+      if (!DECL_CONSTRUCTOR_P (meth))
+       {
+         char *t = strdup (lang_printable_name (mtype, 0));
+         parse_error_context (wfl_operator, 
+                              "`return' with%s value from `%s %s'",
+                              (error_found == 1 ? "" : "out"), 
+                              t, lang_printable_name (meth, 0));
+         free (t);
+       }
+      else
+       parse_error_context (wfl_operator, 
+                            "`return' with value from constructor `%s'",
+                            lang_printable_name (meth, 0));
       return error_mark_node;
     }
 
-  /* If we have a return_exp, build a modify expression and expand it */
+  /* If we have a return_exp, build a modify expression and expand
+     it. Note: at that point, the assignment is declared valid, but we
+     may want to carry some more hacks */
   if (return_exp)
     {
-      modify = build (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), return_exp);
+      tree exp = java_complete_tree (return_exp);
+      tree modify, patched;
+
+      /* If the function returned value and EXP are booleans, EXP has
+      to be converted into the type of DECL_RESULT, which is integer
+      (see complete_start_java_method) */
+      if (TREE_TYPE (exp) == boolean_type_node &&
+         TREE_TYPE (TREE_TYPE (meth)) == boolean_type_node)
+       exp = convert_to_integer (TREE_TYPE (DECL_RESULT (meth)), exp);
+
+      /* `null' can be assigned to a function returning a reference */
+      if (JREFERENCE_TYPE_P (TREE_TYPE (TREE_TYPE (meth))) &&
+         exp == null_pointer_node)
+       exp = build_null_of_type (TREE_TYPE (TREE_TYPE (meth)));
+
+      if ((patched = patch_string (exp)))
+       exp = patched;
+      
+      modify = build (MODIFY_EXPR, NULL_TREE, DECL_RESULT (meth), exp);
       EXPR_WFL_LINECOL (modify) = EXPR_WFL_LINECOL (node);
       modify = java_complete_tree (modify);
+
       if (modify != error_mark_node)
        {
          TREE_SIDE_EFFECTS (modify) = 1;
@@ -8350,10 +10283,8 @@ build_if_else_statement (location, expression, if_body, else_body)
      tree expression, if_body, else_body;
 {
   tree node;
-  /* FIXME: make else body be a void node, where this function is
-     called */
   if (!else_body)
-    else_body = build (COMPOUND_EXPR, void_type_node, NULL_TREE, NULL_TREE);
+    else_body = empty_stmt_node;
   node = build (COND_EXPR, NULL_TREE, expression, if_body, else_body);
   EXPR_WFL_LINECOL (node) = location;
   node = build_debugable_stmt (location, node);
@@ -8382,6 +10313,9 @@ patch_if_else_statement (node)
   
   TREE_TYPE (node) = void_type_node;
   TREE_SIDE_EFFECTS (node) = 1;
+  CAN_COMPLETE_NORMALLY (node)
+    = CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 1))
+    | CAN_COMPLETE_NORMALLY (TREE_OPERAND (node, 2));
   return node;
 }
 
@@ -8399,20 +10333,20 @@ build_labeled_block (location, label)
   tree label_name = merge_qualified_name (label_id, label);
   tree label_decl, node;
 
-  /* Issue a warning if we try to reuse a label that was previously
+  /* Issue an error if we try to reuse a label that was previously
      declared */
   if (IDENTIFIER_LOCAL_VALUE (label_name))
     {
       EXPR_WFL_LINECOL (wfl_operator) = location;
-      parse_warning_context (wfl_operator, "Declaration of `%s' shadows "
-                            "a previous declaration",
+      parse_error_context (wfl_operator, "Declaration of `%s' shadows "
+                            "a previous label declaration",
                             IDENTIFIER_POINTER (label));
       EXPR_WFL_LINECOL (wfl_operator) = 
         EXPR_WFL_LINECOL (IDENTIFIER_LOCAL_VALUE (label_name));
-      parse_warning_context (wfl_operator, "This is the location of the "
-                            "previous declaration of label `%s'",
-                            IDENTIFIER_POINTER (label));
-      java_warning_count--;
+      parse_error_context (wfl_operator, "This is the location of the "
+                          "previous declaration of label `%s'",
+                          IDENTIFIER_POINTER (label));
+      java_error_count--;
     }
 
   label_decl = create_label_decl (label_name);
@@ -8474,7 +10408,7 @@ build_new_loop (loop_body)
        COMPOUND_EXPR           (loop main body)
          EXIT_EXPR             (this order is for while/for loops.
          LABELED_BLOCK_EXPR      the order is reversed for do loops)
-           LABEL_DECL           (continue occurding here branche at the 
+           LABEL_DECL           (a continue occuring here branches at the 
            BODY                         end of this labeled block)
        INCREMENT               (if any)
 
@@ -8507,7 +10441,7 @@ build_loop_body (location, condition, reversed)
   second = (reversed ? condition : body);
   return 
     build (COMPOUND_EXPR, NULL_TREE, 
-          build (COMPOUND_EXPR, NULL_TREE, first, second), size_zero_node);
+          build (COMPOUND_EXPR, NULL_TREE, first, second), empty_stmt_node);
 }
 
 /* Install CONDITION (if any) and loop BODY (using REVERSED to tell
@@ -8665,6 +10599,16 @@ patch_bc_statement (node)
   /* Find the statement we're targeting. */
   target_stmt = LABELED_BLOCK_BODY (bc_label);
 
+  /* Target loop is slightly burrowed in the case of a for loop, it
+     appears at the first sight to be a block. */
+  if (TREE_CODE (target_stmt) == BLOCK)
+    {
+      tree sub = BLOCK_SUBBLOCKS (target_stmt);
+      if (sub && TREE_CODE (sub) == COMPOUND_EXPR && TREE_OPERAND (sub, 1)
+         && TREE_CODE (TREE_OPERAND (sub, 1)) == LOOP_EXPR)
+       target_stmt = TREE_OPERAND (sub, 1);
+    }
+
   /* 14.13 The break Statement */
   if (IS_BREAK_STMT_P (node))
     {
@@ -8673,7 +10617,7 @@ patch_bc_statement (node)
          while/do/for/switch */
       if (is_unlabeled &&
          !(TREE_CODE (target_stmt) == LOOP_EXPR        /* do/while/for */
-           || TREE_CODE (target_stmt) == SWITCH_EXPR)) /* switch FIXME */
+           || TREE_CODE (target_stmt) == SWITCH_EXPR)) /* switch */
        {
          parse_error_context (wfl_operator, 
                               "`break' must be in loop or switch");
@@ -8684,20 +10628,25 @@ patch_bc_statement (node)
        EXIT_BLOCK_LABELED_BLOCK (node) = bc_label;
     }
   /* 14.14 The continue Statement */
-  /* The continue statement must always target a loop */
+  /* The continue statement must always target a loop, unnamed or not. */
   else 
-    {
+    { 
       if (TREE_CODE (target_stmt) != LOOP_EXPR) /* do/while/for */
        {
          parse_error_context (wfl_operator, "`continue' must be in loop");
          return error_mark_node;
        }
       /* Everything looks good. We can fix the `continue' jump to go
-         at the place in the loop were the continue is. The continue
-        is the current labeled block, by construction. */
-      EXIT_BLOCK_LABELED_BLOCK (node) = ctxp->current_labeled_block;
+        at the place in the loop were the continue is.  For unlabeled
+        continue, the continuation point is the current labeled
+        block, by construction. */
+      if (is_unlabeled)
+       EXIT_BLOCK_LABELED_BLOCK (node) = 
+         bc_label = ctxp->current_labeled_block;
     }
 
+  CAN_COMPLETE_NORMALLY (bc_label) = 1;
+
   /* Our break/continue don't return values. */
   TREE_TYPE (node) = void_type_node;
   /* Encapsulate the break within a compound statement so that it's
@@ -8733,6 +10682,15 @@ patch_exit_expr (node)
      return */
   TREE_OPERAND (node, 0) = 
     fold (build1 (TRUTH_NOT_EXPR, boolean_type_node, expression));
+
+  if (! integer_zerop (TREE_OPERAND (node, 0))
+      && ctxp->current_loop != NULL_TREE
+      && TREE_CODE (ctxp->current_loop) == LOOP_EXPR)
+    CAN_COMPLETE_NORMALLY (ctxp->current_loop) = 1;
+  if (! integer_onep (TREE_OPERAND (node, 0)))
+    CAN_COMPLETE_NORMALLY (node) = 1;
+
+
   TREE_TYPE (node) = void_type_node;
   return node;
 }
@@ -8743,9 +10701,7 @@ static tree
 patch_switch_statement (node)
      tree node;
 {
-  int error_found = 0;
-  tree se = TREE_OPERAND (node, 0), se_type, sb;
-  tree default_found = NULL_TREE;
+  tree se = TREE_OPERAND (node, 0), se_type;
 
   /* Complete the switch expression */
   se = TREE_OPERAND (node, 0) = java_complete_tree (se);
@@ -8763,269 +10719,42 @@ patch_switch_statement (node)
       return error_mark_node;
     }
 
-  /* Process the switch body. We should have a list of TREE_LIST. The
-     PURPOSE of each node should be a list of case values, VALUE
-     should be the associated block. We try to process all cases and
-     defaults before returning, possibly finding errors.  */
-  TREE_OPERAND (node, 1) = nreverse (TREE_OPERAND (node, 1));
-  for (sb = TREE_OPERAND (node, 1); sb; sb = TREE_CHAIN (sb))
-    {
-      tree label;
-
-      /* If we don't have a TREE_LIST here, we have a statement inside
-        the switch that isn't tied to a label. This error is caught
-        by the parser and we don't have to report it here. */
-
-      TREE_PURPOSE (sb) = nreverse (TREE_PURPOSE (sb));
-      for (label = TREE_PURPOSE (sb); label; label = TREE_CHAIN (label))
-       {
-         tree case_expr;
-         
-         /* Verification of the default label */
-         if (TREE_CODE (label) == DEFAULT_EXPR)
-           {
-             /* Only one default label is allowed per switch
-                 statement */
-             if (default_found)
-               {
-                 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (label);
-                 parse_error_context (wfl_operator, 
-                                      "Duplicate case label: `default'");
-                 error_found = 1;
-               }
-             else
-               default_found = label;
-             continue;
-           }
-         /* Verification of case labels */
-         else
-           {
-             case_expr = java_complete_tree (TREE_OPERAND (label, 0));
-             if (case_expr == error_mark_node)
-               continue;
-
-             /* First, the case expression must be constant */
-             case_expr = fold (case_expr);
-             if (!TREE_CONSTANT (case_expr))
-               {
-                 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (label);
-                 parse_error_context (label, "Constant expression required");
-                 error_found = 1;
-                 break;
-               }
-             
-             /* It must be assignable to the type of the switch
-                expression. */
-             if (!try_builtin_assignconv (NULL_TREE, se_type, case_expr))
-               {
-                 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (label);
-                 parse_error_context 
-                   (wfl_operator,
-                    "Incompatible type for case. Can't convert `%s' to `int'",
-                    lang_printable_name (TREE_TYPE (case_expr), 0));
-                 error_found = 1;
-                 break;
-               }
-
-             /* Multiple instance of a case label bearing the same
-                 value is checked during code generation. The case
-                 expression is allright so far. */
-             TREE_OPERAND (label, 0) = case_expr;
-           }
-       }
-
-      /* First TREE_VALUE should be the block tied to this list of
-         cases. Check that this block exists and the walk it */
-      if (TREE_VALUE (sb))
-       {
-         TREE_VALUE (sb) = java_complete_tree (TREE_VALUE (sb));
-         if (TREE_VALUE (sb) == error_mark_node)
-           error_found = 1;
-       }
-    }
+  TREE_OPERAND (node, 1) = java_complete_tree (TREE_OPERAND (node, 1));
 
   /* Ready to return */
-  if (error_found)
+  if (TREE_CODE (TREE_OPERAND (node, 1)) == ERROR_MARK)
     {
       TREE_TYPE (node) = error_mark_node;
       return error_mark_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);
   return node;
 }
 
-/* Do the expansion of a Java switch. With Gcc, switches are front-end
-   dependant things, but they rely on gcc routines. This function is
-   placed here because it uses things defined locally in parse.y. */
-
-static tree case_identity (t, v)
-     tree t __attribute__ ((__unused__));
-     tree v;
-{
-  return v;
-}
-
-void
-java_expand_switch (exp)
-     tree exp;
-{
-  tree sb;
-  expand_start_case (0, TREE_OPERAND (exp, 0), int_type_node, "switch");
-
-  for (sb = TREE_OPERAND (exp, 1); sb; sb = TREE_CHAIN (sb))
-    {
-      /* We have a list of TREE_LIST. PURPOSE is the case value, and
-        when it exists, VALUE is the associated block */
-      
-      /* The first CASE element should contain the associated block,
-        if any. All other should be case statements related to the
-        same block */
-      tree label;
-      for (label = TREE_PURPOSE (sb); label; label = TREE_CHAIN (label))
-       {
-         tree label_decl = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
-         if (TREE_CODE (label) == CASE_EXPR)
-           {
-             tree duplicate;
-             if (pushcase (TREE_OPERAND (label, 0), case_identity,
-                           label_decl, &duplicate) == 2)
-               {
-                 EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (label);
-                 parse_error_context
-                   (wfl_operator, "Duplicate case label: `%s'",
-                    print_int_node (TREE_OPERAND (label, 0)));
-               }
-           }
-         else
-           pushcase (NULL_TREE, 0, label_decl, NULL);
-       }
-      /* Expand the associated block, if any */
-      if (TREE_VALUE (sb))
-       expand_expr_stmt (TREE_VALUE (sb));
-    } 
-  expand_end_case (TREE_OPERAND (exp, 0));
-}
-
 /* 14.18 The try statement */
 
-/* Wrap BLOCK around a LABELED_BLOCK, set DECL to the newly generated
-   exit labeld and issue a jump to FINALLY_LABEL:
-     
-   LABELED_BLOCK
-     BLOCK
-       <orignal_statments>
-       DECL = &LABEL_DECL
-       GOTO_EXPR
-         FINALLY_LABEL
-     LABEL_DECL */
-
 static tree
-build_jump_to_finally (block, decl, finally_label, type)
-     tree block, decl, finally_label, type;
+build_try_statement (location, try_block, catches)
+     int location;
+     tree try_block, catches;
 {
-  tree stmt;
-  tree new_block = build (LABELED_BLOCK_EXPR, type,
-                         create_label_decl (generate_name ()), block);
-
-  stmt = build (MODIFY_EXPR, void_type_node, decl,
-               build_address_of (LABELED_BLOCK_LABEL (new_block)));
-  TREE_SIDE_EFFECTS (stmt) = 1;
-  add_stmt_to_block (block, type, stmt);
-  stmt = build (GOTO_EXPR, void_type_node, finally_label);
-  TREE_SIDE_EFFECTS (stmt) = 1;
-  add_stmt_to_block (block, type, stmt);
-  return new_block;
+  tree node = build (TRY_EXPR, NULL_TREE, try_block, catches);
+  EXPR_WFL_LINECOL (node) = location;
+  return node;
 }
 
 static tree
-build_try_statement (location, try_block, catches, finally)
+build_try_finally_statement (location, try_block, finally)
      int location;
-     tree try_block, catches, finally;
-{
-  tree node, rff;
-
-  if (finally)
-    {
-      /* This block defines a scope for the entire try[-catch]-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);
-
-      /* Modification of the try block. */
-      try_block = build_jump_to_finally (try_block, rff, 
-                                        FINALLY_EXPR_LABEL (finally), 
-                                        NULL_TREE);
-
-      /* To the finally block: add the computed goto */
-      add_stmt_to_block (FINALLY_EXPR_BLOCK (finally), NULL_TREE,
-                        build (GOTO_EXPR, void_type_node, rff));
-
-      /* Modification of each catch blocks, if any */
-      if (catches)
-       {
-         tree catch, catch_decl, catch_block, stmt;
-
-         for (catch = catches; catch; catch = TREE_CHAIN (catch))
-           TREE_OPERAND (catch, 0) = 
-             build_jump_to_finally (TREE_OPERAND (catch, 0), rff,
-                                    FINALLY_EXPR_LABEL (finally),
-                                    NULL_TREE);
-
-         /* Plus, at the end of the list, we add the catch clause that
-            will catch an uncaught exception, call finally and rethrow it:
-              BLOCK
-                void *exception_parameter; (catch_decl)
-                LABELED_BLOCK
-                  BLOCK
-                    exception_parameter = _Jv_exception_info ();
-                    RFF = &LABEL_DECL;
-                    goto finally;
-                LABEL_DECL;
-                CALL_EXPR
-                  Jv_ReThrow
-                  exception_parameter */
-         catch_decl = build_decl_no_layout (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, 
-                                              FINALLY_EXPR_LABEL (finally), 
-                                              void_type_node);
-         BUILD_THROW (stmt, catch_decl);
-         catch_block = build_expr_block (catch_block, catch_decl);
-         add_stmt_to_block (catch_block, void_type_node, stmt);
-
-         /* Link the new handler to the existing list as the first
-            entry. It will be the last one to be generated. */
-         catch = build1 (CATCH_EXPR, void_type_node, catch_block);
-         TREE_CHAIN (catch) = catches;
-         catches = catch;
-       }
-    }
-
-  node = build (TRY_EXPR, NULL_TREE, try_block, catches, finally);
-  EXPR_WFL_LINECOL (node) = location;
-  
-  /* If we have a finally, surround this whole thing by a block where
-     the RFF local variable is defined. */
-
-  return (finally ? build_expr_block (node, rff) : node);
-}
-
-/* Get the catch clause block from an element of the catch clause
-   list. If depends on whether a finally clause exists or node (in
-   which case the original catch clause was surrounded by a
-   LABELED_BLOCK_EXPR. */
-
-tree
-java_get_catch_block (node, finally_present_p)
-     tree node;
-     int finally_present_p;
+     tree try_block, finally;
 {
-  return (CATCH_EXPR_GET_EXPR (TREE_OPERAND (node, 0), finally_present_p));
+  tree node = build (TRY_FINALLY_EXPR, NULL_TREE, try_block, finally);
+  EXPR_WFL_LINECOL (node) = location;
+  return node;
 }
 
 static tree
@@ -9036,8 +10765,6 @@ patch_try_statement (node)
   tree try = TREE_OPERAND (node, 0);
   /* Exception handlers are considered in left to right order */
   tree catch = nreverse (TREE_OPERAND (node, 1));
-  tree finally = TREE_OPERAND (node, 2);
-  int finally_p = (finally ? 1 : 0);
   tree current, caught_type_list = NULL_TREE;
 
   /* Check catch clauses, if any. Every time we find an error, we try
@@ -9050,29 +10777,14 @@ patch_try_statement (node)
       tree sub_current, catch_block, catch_clause;
       int unreachable;
 
-      /* Always detect the last catch clause if a finally is
-         present. This is the catch-all handler and it just needs to
-         be walked. */
-      if (!TREE_CHAIN (current) && finally)
-       {
-         TREE_OPERAND (current, 0) = 
-           java_complete_tree (TREE_OPERAND (current, 0));
-         continue;
-       }
-
       /* At this point, the structure of the catch clause is
-         LABELED_BLOCK_EXPR    (if we have a finally)
           CATCH_EXPR           (catch node)
             BLOCK              (with the decl of the parameter)
                COMPOUND_EXPR
-                 MODIFIY_EXPR   (assignemnt of the catch parameter)
+                 MODIFY_EXPR   (assignment of the catch parameter)
                 BLOCK          (catch clause block)
-           LABEL_DECL          (where to return after finally (if any))
-
-        Since the structure of the catch clause depends on the
-        presence of a finally, we use a function call to get to the
-        cath clause */
-      catch_clause = java_get_catch_block (current, finally_p);
+       */
+      catch_clause = TREE_OPERAND (current, 0);
       carg_decl = BLOCK_EXPR_DECLS (catch_clause);
       carg_type = TREE_TYPE (TREE_TYPE (carg_decl));
 
@@ -9106,7 +10818,7 @@ patch_try_statement (node)
           sub_current != current; sub_current = TREE_CHAIN (sub_current))
        {
          tree sub_catch_clause, decl;
-         sub_catch_clause = java_get_catch_block (sub_current, finally_p);
+         sub_catch_clause = TREE_OPERAND (sub_current, 0);
          decl = BLOCK_EXPR_DECLS (sub_catch_clause);
 
          if (inherits_from_p (carg_type, TREE_TYPE (TREE_TYPE (decl))))
@@ -9119,14 +10831,6 @@ patch_try_statement (node)
              break;
            }
        }
-      if (unreachable)
-       continue;
-
-      /* Things to do here: the exception must be thrown */
-
-      /* Link this type to the caught type list */
-      caught_type_list = tree_cons (NULL_TREE, carg_type, caught_type_list);
-
       /* Complete the catch clause block */
       catch_block = java_complete_tree (TREE_OPERAND (current, 0));
       if (catch_block == error_mark_node)
@@ -9134,30 +10838,32 @@ patch_try_statement (node)
          error_found = 1;
          continue;
        }
+      if (CAN_COMPLETE_NORMALLY (catch_block))
+       CAN_COMPLETE_NORMALLY (node) = 1;
       TREE_OPERAND (current, 0) = catch_block;
+
+      if (unreachable)
+       continue;
+
+      /* Things to do here: the exception must be thrown */
+
+      /* 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);
   if ((try = java_complete_tree (try)) == error_mark_node)
     error_found = 1;
+  if (CAN_COMPLETE_NORMALLY (try))
+    CAN_COMPLETE_NORMALLY (node) = 1;
   POP_EXCEPTIONS ();
 
-  /* Process finally */
-  if (finally)
-    {
-      FINALLY_EXPR_BLOCK (finally) = 
-       java_complete_tree (FINALLY_EXPR_BLOCK (finally));
-      if (FINALLY_EXPR_BLOCK (finally) == error_mark_node)
-       error_found = 1;
-    }
-
   /* Verification ends here */
   if (error_found) 
     return error_mark_node;
 
   TREE_OPERAND (node, 0) = try;
   TREE_OPERAND (node, 1) = catch;
-  TREE_OPERAND (node, 2) = finally;
   TREE_TYPE (node) = void_type_node;
   return node;
 }
@@ -9168,12 +10874,19 @@ static tree
 patch_synchronized_statement (node, wfl_op1)
     tree node, wfl_op1;
 {
-  tree expr = TREE_OPERAND (node, 0);
+  tree expr = java_complete_tree (TREE_OPERAND (node, 0));
   tree block = TREE_OPERAND (node, 1);
-  tree try_block, catch_all, stmt, compound, decl;
+
+  tree enter, exit, expr_decl, assignment;
+
+  if (expr == error_mark_node)
+    {
+      block = java_complete_tree (block);
+      return expr;
+    }
 
   /* The TYPE of expr must be a reference type */
-  if (!JREFERENCE_TYPE_P (TREE_TYPE (TREE_OPERAND (node, 0))))
+  if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))
     {
       SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
       parse_error_context (wfl_operator, "Incompatible type for `synchronized'"
@@ -9199,28 +10912,23 @@ patch_synchronized_statement (node, wfl_op1)
         Throw (e);
        } */
 
-  /* TRY block */
-  BUILD_MONITOR_ENTER (stmt, expr);
-  compound = add_stmt_to_compound (NULL_TREE, int_type_node, stmt);
-  compound = add_stmt_to_compound (compound, void_type_node, block);
-  BUILD_MONITOR_EXIT (stmt, expr);
-  compound = add_stmt_to_compound (compound, int_type_node, stmt);
-  try_block = build_expr_block (compound, NULL_TREE);
-
-  /* CATCH_ALL block */
-  decl = build_decl_no_layout (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);
-  compound = add_stmt_to_compound (compound, int_type_node, stmt);
-  BUILD_THROW (stmt, decl);
-  compound = add_stmt_to_compound (compound, void_type_node, stmt);
-  catch_all = build_expr_block (compound, decl);
-  catch_all = build_expr_block (catch_all, NULL_TREE);
-  catch_all = build1 (CATCH_EXPR, void_type_node, catch_all);
-
-  /* TRY-CATCH statement */
-  return build (TRY_EXPR, void_type_node, try_block, catch_all, NULL_TREE);
+  expr_decl = build_decl (VAR_DECL, generate_name (), TREE_TYPE (expr));
+  BUILD_MONITOR_ENTER (enter, expr_decl);
+  BUILD_MONITOR_EXIT (exit, expr_decl);
+  CAN_COMPLETE_NORMALLY (enter) = 1;
+  CAN_COMPLETE_NORMALLY (exit) = 1;
+  assignment = build (MODIFY_EXPR, NULL_TREE, expr_decl, expr);
+  TREE_SIDE_EFFECTS (assignment) = 1;
+  node = build1 (CLEANUP_POINT_EXPR, NULL_TREE,
+                build (COMPOUND_EXPR, NULL_TREE,
+                       build (WITH_CLEANUP_EXPR, NULL_TREE,
+                              build (COMPOUND_EXPR, NULL_TREE,
+                                     assignment, enter),
+                              NULL_TREE, exit),
+                       block));
+  node = build_expr_block (node, expr_decl);
+
+  return java_complete_tree (node);
 }
 
 /* 14.16 The throw Statement */
@@ -9250,7 +10958,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
@@ -9295,7 +11003,8 @@ patch_throw_statement (node, wfl_op1)
      unchecked exception or its value is always caught by some try
      statement that contains it. FIXME, static initializer. */
   
-  BUILD_THROW (node, expr);
+  if (! flag_emit_class_files)
+    BUILD_THROW (node, expr);
   return node;
 }
 
@@ -9313,6 +11022,11 @@ check_thrown_exceptions (location, decl)
        throws = TREE_CHAIN (throws)) 
     if (!check_thrown_exceptions_do (TREE_VALUE (throws)))
       {
+#if 1
+       /* Temporary hack to suppresses errors about cloning arrays. FIXME */
+       if (DECL_NAME (decl) == get_identifier ("clone"))
+         continue;
+#endif
        EXPR_WFL_LINECOL (wfl_operator) = location;
        parse_error_context 
          (wfl_operator, "Exception `%s' must be caught, or it must be "
@@ -9322,7 +11036,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.  */
 
@@ -9331,8 +11045,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;
@@ -9354,7 +11071,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;
@@ -9364,3 +11081,275 @@ purge_unchecked_exceptions (mdecl)
   /* List is inverted here, but it doesn't matter */
   DECL_FUNCTION_THROWS (mdecl) = new;
 }
+
+/* 15.24 Conditional Operator ?: */
+
+static tree
+patch_conditional_expr (node, wfl_cond, wfl_op1)
+     tree node, wfl_cond, wfl_op1;
+{
+  tree cond = TREE_OPERAND (node, 0);
+  tree op1 = TREE_OPERAND (node, 1);
+  tree op2 = TREE_OPERAND (node, 2);
+  tree resulting_type = NULL_TREE;
+  tree t1, t2, patched;
+  int error_found = 0;
+
+  /* Operands of ?: might be StringBuffers crafted as a result of a
+     string concatenation. Obtain a descent operand here.  */
+  if ((patched = patch_string (op1)))
+    TREE_OPERAND (node, 1) = op1 = patched;
+  if ((patched = patch_string (op2)))
+    TREE_OPERAND (node, 2) = op2 = patched;
+
+  t1 = TREE_TYPE (op1);
+  t2 = TREE_TYPE (op2);
+
+  /* The first expression must be a boolean */
+  if (TREE_TYPE (cond) != boolean_type_node)
+    {
+      SET_WFL_OPERATOR (wfl_operator, node, wfl_cond);
+      parse_error_context (wfl_operator, "Incompatible type for `?:'. Can't "
+                          "convert `%s' to `boolean'",
+                          lang_printable_name (TREE_TYPE (cond), 0));
+      error_found = 1;
+    }
+
+  /* Second and third can be numeric, boolean (i.e. primitive),
+     references or null. Anything else results in an error */
+  if (!((JNUMERIC_TYPE_P (t1) && JNUMERIC_TYPE_P (t2))
+       || ((JREFERENCE_TYPE_P (t1) || op1 == null_pointer_node) 
+           && (JREFERENCE_TYPE_P (t2) || op2 == null_pointer_node))
+       || (t1 == boolean_type_node && t2 == boolean_type_node)))
+    error_found = 1;
+
+  /* Determine the type of the conditional expression. Same types are
+     easy to deal with */
+  else if (t1 == t2)
+    resulting_type = t1;
+
+  /* There are different rules for numeric types */
+  else if (JNUMERIC_TYPE_P (t1))
+    {
+      /* if byte/short found, the resulting type is short */
+      if ((t1 == byte_type_node && t2 == short_type_node)
+         || (t1 == short_type_node && t2 == byte_type_node))
+       resulting_type = short_type_node;
+
+      /* If t1 is a constant int and t2 is of type byte, short or char
+        and t1's value fits in t2, then the resulting type is t2 */
+      else if ((t1 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 1)))
+         && JBSC_TYPE_P (t2) && int_fits_type_p (TREE_OPERAND (node, 1), t2))
+       resulting_type = t2;
+
+      /* If t2 is a constant int and t1 is of type byte, short or char
+        and t2's value fits in t1, then the resulting type is t1 */
+      else if ((t2 == int_type_node && TREE_CONSTANT (TREE_OPERAND (node, 2)))
+         && JBSC_TYPE_P (t1) && int_fits_type_p (TREE_OPERAND (node, 2), t1))
+       resulting_type = t1;
+
+      /* Otherwise, binary numeric promotion is applied and the
+        resulting type is the promoted type of operand 1 and 2 */
+      else 
+       resulting_type = binary_numeric_promotion (t2, t2, 
+                                                  &TREE_OPERAND (node, 1), 
+                                                  &TREE_OPERAND (node, 2));
+    }
+
+  /* Cases of a reference and a null type */
+  else if (JREFERENCE_TYPE_P (t1) && op2 == null_pointer_node)
+    resulting_type = t1;
+
+  else if (JREFERENCE_TYPE_P (t2) && op1 == null_pointer_node)
+    resulting_type = t2;
+
+  /* Last case: different reference types. If a type can be converted
+     into the other one by assignment conversion, the latter
+     determines the type of the expression */
+  else if ((resulting_type = try_reference_assignconv (t1, op2)))
+    resulting_type = promote_type (t1);
+
+  else if ((resulting_type = try_reference_assignconv (t2, op1)))
+    resulting_type = promote_type (t2);
+
+  /* If we don't have any resulting type, we're in trouble */
+  if (!resulting_type)
+    {
+      char *t = strdup (lang_printable_name (t1, 0));
+      SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
+      parse_error_context (wfl_operator, "Incompatible type for `?:'. Can't "
+                          "convert `%s' to `%s'", t,
+                          lang_printable_name (t2, 0));
+      free (t);
+      error_found = 1;
+    }
+
+  if (error_found)
+    {
+      TREE_TYPE (node) = error_mark_node;
+      return error_mark_node;
+    }
+
+  TREE_TYPE (node) = resulting_type;
+  TREE_SET_CODE (node, COND_EXPR);
+  CAN_COMPLETE_NORMALLY (node) = 1;
+  return node;
+}
+
+/* Try to constant fold NODE.
+   If NODE is not a constant expression, return NULL_EXPR.
+   CONTEXT is a static final VAR_DECL whose initializer we are folding. */
+
+static tree
+fold_constant_for_init (node, context)
+     tree node;
+     tree context;
+{
+  tree op0, op1, val;
+  enum tree_code code = TREE_CODE (node);
+
+  if (code == INTEGER_CST || code == REAL_CST || code == STRING_CST)
+    return node;
+  if (TREE_TYPE (node) != NULL_TREE)
+    return NULL_TREE;
+
+  switch (code)
+    {
+    case PLUS_EXPR:
+    case MINUS_EXPR:
+    case MULT_EXPR:
+    case TRUNC_MOD_EXPR:
+    case RDIV_EXPR:
+    case LSHIFT_EXPR:
+    case RSHIFT_EXPR:
+    case URSHIFT_EXPR:
+    case BIT_AND_EXPR:
+    case BIT_XOR_EXPR:
+    case BIT_IOR_EXPR:
+    case TRUTH_ANDIF_EXPR:
+    case TRUTH_ORIF_EXPR:
+    case EQ_EXPR: 
+    case NE_EXPR:
+    case GT_EXPR:
+    case GE_EXPR:
+    case LT_EXPR:
+    case LE_EXPR:
+      op0 = TREE_OPERAND (node, 0);
+      op1 = TREE_OPERAND (node, 1);
+      val = fold_constant_for_init (op0, context);
+      if (val == NULL_TREE || ! TREE_CONSTANT (val))
+       return NULL_TREE;
+      TREE_OPERAND (node, 0) = val;
+      val = fold_constant_for_init (op1, context);
+      if (val == NULL_TREE || ! TREE_CONSTANT (val))
+       return NULL_TREE;
+      TREE_OPERAND (node, 1) = val;
+      return patch_binop (node, op0, op1);
+
+    case UNARY_PLUS_EXPR:
+    case NEGATE_EXPR:
+    case TRUTH_NOT_EXPR:
+    case BIT_NOT_EXPR:
+    case CONVERT_EXPR:
+      op0 = TREE_OPERAND (node, 0);
+      val = fold_constant_for_init (op0, context);
+      if (val == NULL_TREE || ! TREE_CONSTANT (val))
+       return NULL_TREE;
+      TREE_OPERAND (node, 0) = val;
+      return patch_unaryop (node, op0);
+      break;
+
+    case COND_EXPR:
+      val = fold_constant_for_init (TREE_OPERAND (node, 0), context);
+      if (val == NULL_TREE || ! TREE_CONSTANT (val))
+       return NULL_TREE;
+      TREE_OPERAND (node, 0) = val;
+      val = fold_constant_for_init (TREE_OPERAND (node, 1), context);
+      if (val == NULL_TREE || ! TREE_CONSTANT (val))
+       return NULL_TREE;
+      TREE_OPERAND (node, 1) = val;
+      val = fold_constant_for_init (TREE_OPERAND (node, 2), context);
+      if (val == NULL_TREE || ! TREE_CONSTANT (val))
+       return NULL_TREE;
+      TREE_OPERAND (node, 2) = val;
+      return integer_zerop (TREE_OPERAND (node, 0)) ? TREE_OPERAND (node, 1)
+       : TREE_OPERAND (node, 2);
+
+    case VAR_DECL:
+      if (! FIELD_STATIC (node) || ! FIELD_FINAL (node)
+         || DECL_INITIAL (node) == NULL_TREE)
+       return NULL_TREE;
+      val = DECL_INITIAL (node);
+      /* Guard against infinite recursion. */
+      DECL_INITIAL (node) = NULL_TREE;
+      val = fold_constant_for_init (val, DECL_CONTEXT (node));
+      DECL_INITIAL (node) = val;
+      return val;
+
+    case EXPR_WITH_FILE_LOCATION:
+      /* Compare java_complete_tree and resolve_expression_name. */
+      if (!EXPR_WFL_NODE (node) /* Or a PRIMARY flag ? */
+         || TREE_CODE (EXPR_WFL_NODE (node)) == IDENTIFIER_NODE)
+       {
+         tree name = EXPR_WFL_NODE (node);
+         tree decl;
+         if (PRIMARY_P (node))
+           return NULL_TREE;
+         else if (! QUALIFIED_P (name))
+           {
+             decl = lookup_field_wrapper (DECL_CONTEXT (context), name);
+             if (! FIELD_STATIC (decl))
+               return NULL_TREE;
+             return fold_constant_for_init (decl, decl);
+           }
+         else
+           {
+#if 0
+             /* Wait until the USE_COMPONENT_REF re-write.  FIXME. */
+             qualify_ambiguous_name (node);
+             if (resolve_field_access (node, &decl, NULL)
+                 && decl != NULL_TREE)
+               return fold_constant_for_init (decl, decl);
+#endif
+             return NULL_TREE;
+           }
+       }
+      else
+       {
+         op0 = TREE_OPERAND (node, 0);
+         val = fold_constant_for_init (op0, context);
+         if (val == NULL_TREE || ! TREE_CONSTANT (val))
+           return NULL_TREE;
+         TREE_OPERAND (node, 0) = val;
+         return val;
+       }
+
+#ifdef USE_COMPONENT_REF
+    case IDENTIFIER:
+    case COMPONENT_REF:
+      ?;
+#endif
+
+    default:
+      return NULL_TREE;
+    }
+}
+
+#ifdef USE_COMPONENT_REF
+/* Context is 'T' for TypeName, 'P' for PackageName,
+   'M' for MethodName, 'E' for ExpressionName, and 'A' for AmbiguousName. */
+
+tree
+resolve_simple_name (name, context)
+     tree name;
+     int context;
+{
+}
+
+tree
+resolve_qualified_name (name, context)
+     tree name;
+     int context;
+{
+}
+#endif
This page took 0.225113 seconds and 5 git commands to generate.