From 73c299fc2276884f695006a361aac9450f1671da Mon Sep 17 00:00:00 2001 From: Alexandre Petit-Bianco Date: Thu, 5 Apr 2001 15:59:12 -0700 Subject: re PR java/1315 (Inner class initializer crash) 2001-04-04 Alexandre Petit-Bianco * java-tree.h (struct lang_decl): New macro `DECL_FIXED_CONSTRUCTOR_P.' New field `fixed_ctor.' * parse.y (build_instance_initializer): New function. (add_instance_initializer): Use it. (java_fix_constructors): Set `current_class' before fix pass. (fix_constructors): Just return if already fixed. Move `super()' invokation ahead. Use `build_instance_initializer.' Fixes PR java/1315. (http://gcc.gnu.org/ml/gcc-patches/2001-04/msg00343.html) From-SVN: r41129 --- gcc/java/parse.y | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) (limited to 'gcc/java/parse.y') diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 4ab60e9..4032409 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -238,6 +238,7 @@ static const char *get_printable_method_name PARAMS ((tree)); static tree patch_conditional_expr PARAMS ((tree, tree, tree)); static tree generate_finit PARAMS ((tree)); static void add_instance_initializer PARAMS ((tree)); +static tree build_instance_initializer PARAMS ((tree)); static void fix_constructors PARAMS ((tree)); static tree build_alias_initializer_parameter_list PARAMS ((int, tree, tree, int *)); @@ -4302,22 +4303,29 @@ generate_finit (class_type) return mdecl; } -static void -add_instance_initializer (mdecl) +static tree +build_instance_initializer (mdecl) tree mdecl; { - tree current; - tree stmt_list = TYPE_II_STMT_LIST (DECL_CONTEXT (mdecl)); tree compound = NULL_TREE; + tree stmt_list = TYPE_II_STMT_LIST (DECL_CONTEXT (mdecl)); + tree current; - if (stmt_list) - { - for (current = stmt_list; current; current = TREE_CHAIN (current)) - compound = add_stmt_to_compound (compound, NULL_TREE, current); + for (current = stmt_list; current; current = TREE_CHAIN (current)) + compound = add_stmt_to_compound (compound, NULL_TREE, current); - java_method_add_stmt (mdecl, build1 (INSTANCE_INITIALIZERS_EXPR, - NULL_TREE, compound)); - } + return compound; +} + +static void +add_instance_initializer (mdecl) + tree mdecl; +{ + tree compound = build_instance_initializer (mdecl); + + if (compound) + java_method_add_stmt (mdecl, build1 (INSTANCE_INITIALIZERS_EXPR, + NULL_TREE, compound)); } /* Shared accros method_declarator and method_header to remember the @@ -5233,6 +5241,7 @@ java_fix_constructors () if (CLASS_INTERFACE (TYPE_NAME (class_type))) continue; + current_class = class_type; for (decl = TYPE_METHODS (class_type); decl; decl = TREE_CHAIN (decl)) { if (DECL_CONSTRUCTOR_P (decl)) @@ -8456,6 +8465,10 @@ fix_constructors (mdecl) tree thisn_assign, compound = NULL_TREE; tree class_type = DECL_CONTEXT (mdecl); + if (DECL_FIXED_CONSTRUCTOR_P (mdecl)) + return; + DECL_FIXED_CONSTRUCTOR_P (mdecl) = 1; + if (!body) { /* It is an error for the compiler to generate a default @@ -8499,7 +8512,9 @@ fix_constructors (mdecl) else { int found = 0; + tree found_call = NULL_TREE; tree main_block = BLOCK_EXPR_BODY (body); + tree ii; /* Instance Initializer */ while (body) switch (TREE_CODE (body)) @@ -8510,9 +8525,11 @@ fix_constructors (mdecl) break; case COMPOUND_EXPR: case EXPR_WITH_FILE_LOCATION: + found_call = body; body = TREE_OPERAND (body, 0); break; case BLOCK: + found_call = body; body = BLOCK_EXPR_BODY (body); break; default: @@ -8523,14 +8540,23 @@ fix_constructors (mdecl) if (!found) compound = add_stmt_to_compound (compound, NULL_TREE, build_super_invocation (mdecl)); + + /* Explicit super() invokation should be kept as the first + statement, we move it. */ + else + { + compound = add_stmt_to_compound (compound, NULL_TREE, + TREE_OPERAND (found_call, 0)); + TREE_OPERAND (found_call, 0) = empty_stmt_node; + } /* Generate the assignment to this$, if necessary */ if ((thisn_assign = build_thisn_assign ())) compound = add_stmt_to_compound (compound, NULL_TREE, thisn_assign); - /* Insert the instance initializer block right here, after the - super invocation. */ - add_instance_initializer (mdecl); + /* Insert the instance initializer block right after. */ + if ((ii = build_instance_initializer (mdecl))) + compound = add_stmt_to_compound (compound, NULL_TREE, ii); /* Fix the constructor main block if we're adding extra stmts */ if (compound) -- cgit v1.1