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 /gcc/fortran/match.c | |
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
Diffstat (limited to 'gcc/fortran/match.c')
-rw-r--r-- | gcc/fortran/match.c | 74 |
1 files changed, 72 insertions, 2 deletions
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; } |