diff options
author | Daniel Kraft <d@domob.eu> | 2010-06-10 16:47:49 +0200 |
---|---|---|
committer | Daniel Kraft <domob@gcc.gnu.org> | 2010-06-10 16:47:49 +0200 |
commit | 03af1e4c73f8e9b0b9fcfd18ca5d3965a6879bbb (patch) | |
tree | 92cc0dfbe516055a3602f51eff555b7609833069 /gcc/fortran/match.c | |
parent | 29aba2bbfed88ef9fb5f68ff8dda08f0bfd48d0c (diff) | |
download | gcc-03af1e4c73f8e9b0b9fcfd18ca5d3965a6879bbb.zip gcc-03af1e4c73f8e9b0b9fcfd18ca5d3965a6879bbb.tar.gz gcc-03af1e4c73f8e9b0b9fcfd18ca5d3965a6879bbb.tar.bz2 |
re PR fortran/38936 ([F03] ASSOCIATE construct / improved SELECT TYPE (a=>expr))
2010-06-10 Daniel Kraft <d@domob.eu>
PR fortran/38936
* gfortran.h (enum gfc_statement): Add ST_ASSOCIATE, ST_END_ASSOCIATE.
(struct gfc_symbol): New field `assoc'.
(struct gfc_association_list): New struct.
(struct gfc_code): New struct `block' in union, move `ns' there
and add association list.
(gfc_free_association_list): New method.
(gfc_has_vector_subscript): Made public;
* match.h (gfc_match_associate): New method.
* parse.h (enum gfc_compile_state): Add COMP_ASSOCIATE.
* decl.c (gfc_match_end): Handle ST_END_ASSOCIATE.
* interface.c (gfc_has_vector_subscript): Made public.
(compare_actual_formal): Rename `has_vector_subscript' accordingly.
* match.c (gfc_match_associate): New method.
(gfc_match_select_type): Change reference to gfc_code's `ns' field.
* primary.c (match_variable): Don't allow names associated to expr here.
* parse.c (decode_statement): Try matching ASSOCIATE statement.
(case_exec_markers, case_end): Add ASSOCIATE statement.
(gfc_ascii_statement): Hande ST_ASSOCIATE and ST_END_ASSOCIATE.
(parse_associate): New method.
(parse_executable): Handle ST_ASSOCIATE.
(parse_block_construct): Change reference to gfc_code's `ns' field.
* resolve.c (resolve_select_type): Ditto.
(resolve_code): Ditto.
(resolve_block_construct): Ditto and add comment.
(resolve_select_type): Set association list in generated BLOCK to NULL.
(resolve_symbol): Resolve associate names.
* st.c (gfc_free_statement): Change reference to gfc_code's `ns' field
and free association list.
(gfc_free_association_list): New method.
* symbol.c (gfc_new_symbol): NULL new field `assoc'.
* trans-stmt.c (gfc_trans_block_construct): Change reference to
gfc_code's `ns' field.
2010-06-10 Daniel Kraft <d@domob.eu>
PR fortran/38936
* gfortran.dg/associate_1.f03: New test.
* gfortran.dg/associate_2.f95: New test.
* gfortran.dg/associate_3.f03: New test.
* gfortran.dg/associate_4.f08: New test.
From-SVN: r160550
Diffstat (limited to 'gcc/fortran/match.c')
-rw-r--r-- | gcc/fortran/match.c | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 2cbac02..8c43531 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -1797,6 +1797,98 @@ gfc_match_block (void) } +/* Match an ASSOCIATE statement. */ + +match +gfc_match_associate (void) +{ + if (gfc_match_label () == MATCH_ERROR) + return MATCH_ERROR; + + if (gfc_match (" associate") != MATCH_YES) + return MATCH_NO; + + /* Match the association list. */ + if (gfc_match_char ('(') != MATCH_YES) + { + gfc_error ("Expected association list at %C"); + return MATCH_ERROR; + } + new_st.ext.block.assoc = NULL; + while (true) + { + gfc_association_list* newAssoc = gfc_get_association_list (); + gfc_association_list* a; + + /* Match the next association. */ + if (gfc_match (" %n => %e", newAssoc->name, &newAssoc->target) + != MATCH_YES) + { + gfc_error ("Expected association at %C"); + goto assocListError; + } + + /* Check that the current name is not yet in the list. */ + for (a = new_st.ext.block.assoc; a; a = a->next) + if (!strcmp (a->name, newAssoc->name)) + { + gfc_error ("Duplicate name '%s' in association at %C", + newAssoc->name); + goto assocListError; + } + + /* The target expression must not be coindexed. */ + if (gfc_is_coindexed (newAssoc->target)) + { + gfc_error ("Association target at %C must not be coindexed"); + goto assocListError; + } + + /* The target is a variable (and may be used as lvalue) if it's an + EXPR_VARIABLE and does not have vector-subscripts. */ + newAssoc->variable = (newAssoc->target->expr_type == EXPR_VARIABLE + && !gfc_has_vector_subscript (newAssoc->target)); + + /* Put it into the list. */ + newAssoc->next = new_st.ext.block.assoc; + new_st.ext.block.assoc = newAssoc; + + /* Try next one or end if closing parenthesis is found. */ + gfc_gobble_whitespace (); + if (gfc_peek_char () == ')') + break; + if (gfc_match_char (',') != MATCH_YES) + { + gfc_error ("Expected ')' or ',' at %C"); + return MATCH_ERROR; + } + + continue; + +assocListError: + gfc_free (newAssoc); + goto error; + } + if (gfc_match_char (')') != MATCH_YES) + { + /* This should never happen as we peek above. */ + gcc_unreachable (); + } + + if (gfc_match_eos () != MATCH_YES) + { + gfc_error ("Junk after ASSOCIATE statement at %C"); + goto error; + } + + return MATCH_YES; + +error: + gfc_free_association_list (new_st.ext.block.assoc); + return MATCH_ERROR; +} + + /* Match a DO statement. */ match @@ -4361,7 +4453,7 @@ gfc_match_select_type (void) new_st.op = EXEC_SELECT_TYPE; new_st.expr1 = expr1; new_st.expr2 = expr2; - new_st.ext.ns = gfc_current_ns; + new_st.ext.block.ns = gfc_current_ns; select_type_push (expr1->symtree->n.sym); |