diff options
author | jvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-12-19 05:55:17 +0000 |
---|---|---|
committer | jvdelisle <jvdelisle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-12-19 05:55:17 +0000 |
commit | bd7403cbe7769d93291506f7ba167b628aca29b3 (patch) | |
tree | 8d46a7fd4ab40e69eada39bcffb95ac4624d95c4 | |
parent | ec72810190559999bc44557632023b39141d86d7 (diff) | |
download | gcc-bd7403cbe7769d93291506f7ba167b628aca29b3.tar.gz |
2007-12-19 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/34325
* match.h: New function declaration.
* match.c (gfc_match_parens): New function to look for mismatched
parenthesis. (gfc_match_if): Use new function to catch missing '('.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@131052 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/fortran/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fortran/match.c | 74 | ||||
-rw-r--r-- | gcc/fortran/match.h | 1 |
3 files changed, 80 insertions, 2 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 56585cf55b7..e3d10923232 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2007-12-19 Jerry DeLisle <jvdelisle@gcc.gnu.org> + + PR fortran/34325 + * match.h: New function declaration. + * match.c (gfc_match_parens): New function to look for mismatched + parenthesis. (gfc_match_if): Use new function to catch missing '('. + 2007-12-19 Daniel Franke <franke.daniel@gmail.com> PR fortran/34495 diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 2586dd4c2ca..78ed75413b2 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -104,6 +104,68 @@ gfc_op2string (gfc_intrinsic_op op) /******************** Generic matching subroutines ************************/ +/* This function scans the current statement counting the opened and closed + parenthesis to make sure they are balanced. */ + +match +gfc_match_parens (void) +{ + locus old_loc, where; + int c, count, instring; + char quote; + + old_loc = gfc_current_locus; + count = 0; + instring = 0; + quote = ' '; + + for (;;) + { + c = gfc_next_char_literal (instring); + if (c == '\n') + break; + if (quote == ' ' && ((c == '\'') || (c == '"'))) + { + quote = (char) c; + instring = 1; + continue; + } + if (quote != ' ' && c == quote) + { + quote = ' '; + instring = 0; + continue; + } + + if (c == '(' && quote == ' ') + { + count++; + where = gfc_current_locus; + } + if (c == ')' && quote == ' ') + { + count--; + where = gfc_current_locus; + } + } + + gfc_current_locus = old_loc; + + if (count > 0) + { + gfc_error ("Missing ')' in statement before %L", &where); + return MATCH_ERROR; + } + if (count < 0) + { + gfc_error ("Missing '(' in statement before %L", &where); + return MATCH_ERROR; + } + + return MATCH_YES; +} + + /* See if the next character is a special character that has escaped by a \ via the -fbackslash option. */ @@ -1321,7 +1383,7 @@ gfc_match_if (gfc_statement *if_type) { gfc_expr *expr; gfc_st_label *l1, *l2, *l3; - locus old_loc; + locus old_loc, old_loc2; gfc_code *p; match m, n; @@ -1335,6 +1397,14 @@ gfc_match_if (gfc_statement *if_type) if (m != MATCH_YES) return m; + old_loc2 = gfc_current_locus; + gfc_current_locus = old_loc; + + if (gfc_match_parens () == MATCH_ERROR) + return MATCH_ERROR; + + gfc_current_locus = old_loc2; + if (gfc_match_char (')') != MATCH_YES) { gfc_error ("Syntax error in IF-expression at %C"); @@ -1386,7 +1456,7 @@ gfc_match_if (gfc_statement *if_type) if (n == MATCH_YES) { - gfc_error ("Block label is not appropriate IF statement at %C"); + gfc_error ("Block label is not appropriate for IF statement at %C"); gfc_free_expr (expr); return MATCH_ERROR; } diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h index 5c4053cc7ec..eac543308f4 100644 --- a/gcc/fortran/match.h +++ b/gcc/fortran/match.h @@ -54,6 +54,7 @@ match gfc_match_intrinsic_op (gfc_intrinsic_op *); match gfc_match_char (char); match gfc_match (const char *, ...); match gfc_match_iterator (gfc_iterator *, int); +match gfc_match_parens (void); /* Statement matchers. */ match gfc_match_program (void); |