]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/34325 (Wrong error message for syntax error)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Wed, 19 Dec 2007 05:55:17 +0000 (05:55 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Wed, 19 Dec 2007 05:55:17 +0000 (05:55 +0000)
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 '('.

From-SVN: r131052

gcc/fortran/ChangeLog
gcc/fortran/match.c
gcc/fortran/match.h

index 56585cf55b762fd7c78df42a3f8151ce4c507508..e3d109232328684c8e0590b9aa0c84ed16c8352b 100644 (file)
@@ -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
index 2586dd4c2ca8c92ae281b95567520b1a000f9e21..78ed75413b20624c20c3fc72eb990bef4dc31c8f 100644 (file)
@@ -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;
     }
index 5c4053cc7ecfebaf3afd6d785c28f49d06c00964..eac543308f419c4537baa5ca82ad529ed5dc8ffd 100644 (file)
@@ -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);