From 73c299fc2276884f695006a361aac9450f1671da Mon Sep 17 00:00:00 2001 From: Alexandre Petit-Bianco Date: Thu, 5 Apr 2001 15:59:12 -0700 Subject: [PATCH] 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/ChangeLog | 11 +++++++++ gcc/java/java-tree.h | 2 ++ gcc/java/parse.y | 54 ++++++++++++++++++++++++++++++++------------ 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 834aed62695..12b2cd7373f 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,14 @@ +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. + 2001-04-04 Alexandre Petit-Bianco * parse.y (resolve_qualified_expression_name): Pass field's diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h index 95cd99c9f9c..0163b49d09d 100644 --- a/gcc/java/java-tree.h +++ b/gcc/java/java-tree.h @@ -715,6 +715,7 @@ struct lang_identifier /* True if DECL initializes all its finals */ #define DECL_FUNCTION_ALL_FINAL_INITIALIZED(DECL) \ (DECL_LANG_SPECIFIC(DECL)->init_final) +#define DECL_FIXED_CONSTRUCTOR_P(DECL) (DECL_LANG_SPECIFIC(DECL)->fixed_ctor) /* True when DECL aliases an outer context local variable. */ #define FIELD_LOCAL_ALIAS(DECL) DECL_LANG_FLAG_6 (DECL) @@ -864,6 +865,7 @@ struct lang_decl int native : 1; /* Nonzero if this is a native method */ int synthetic_ctor : 1; /* Nonzero if this is a synthetic ctor */ int init_final : 1; /* Nonzero all finals are initialized */ + int fixed_ctor : 1; }; /* init_test_table hash table entry structure. */ diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 4ab60e9f6a6..40324098d65 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) -- 2.30.2