OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / fortran / io.c
index 97f304b..ea56292 100644 (file)
@@ -1,5 +1,5 @@
 /* Deal with I/O statements & related stuff.
-   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
@@ -38,8 +38,8 @@ typedef struct
 io_tag;
 
 static const io_tag
-       tag_file        = { "FILE", " file =", " %e", BT_CHARACTER },
-       tag_status      = { "STATUS", " status =", " %e", BT_CHARACTER},
+       tag_file        = {"FILE", " file =", " %e", BT_CHARACTER },
+       tag_status      = {"STATUS", " status =", " %e", BT_CHARACTER},
        tag_e_access    = {"ACCESS", " access =", " %e", BT_CHARACTER},
        tag_e_form      = {"FORM", " form =", " %e", BT_CHARACTER},
        tag_e_recl      = {"RECL", " recl =", " %e", BT_INTEGER},
@@ -94,7 +94,8 @@ static const io_tag
        tag_end         = {"END", " end =", " %l", BT_UNKNOWN},
        tag_eor         = {"EOR", " eor =", " %l", BT_UNKNOWN},
        tag_id          = {"ID", " id =", " %v", BT_INTEGER},
-       tag_pending     = {"PENDING", " pending =", " %v", BT_LOGICAL};
+       tag_pending     = {"PENDING", " pending =", " %v", BT_LOGICAL},
+       tag_newunit     = {"NEWUNIT", " newunit =", " %v", BT_INTEGER};
 
 static gfc_dt *current_dt;
 
@@ -118,6 +119,7 @@ format_token;
    used to back up by a single format token during the parsing
    process.  */
 static gfc_char_t *format_string;
+static int format_string_pos;
 static int format_length, use_last_char;
 static char error_element;
 static locus format_locus;
@@ -170,6 +172,8 @@ next_char (int in_string)
   if (mode != MODE_STRING)
     format_locus = gfc_current_locus;
 
+  format_string_pos++;
+
   c = gfc_wide_toupper (c);
   return c;
 }
@@ -503,6 +507,7 @@ check_format (bool is_input)
   level = 0;
   repeat = 0;
   rv = SUCCESS;
+  format_string_pos = 0;
 
   t = format_lex ();
   if (t == FMT_ERROR)
@@ -729,15 +734,19 @@ data_desc:
              saved_token = u;
              break;
            }
-
          u = format_lex ();
-         if (u == FMT_ERROR)
-           goto fail;
          if (u != FMT_POSINT)
            {
              error = posint_required;
              goto syntax;
            }
+         u = format_lex ();
+         if (u == FMT_E)
+           {
+             error = _("E specifier not allowed with g0 descriptor");
+             goto syntax;
+           }
+         saved_token = u;
          break;
        }
 
@@ -983,6 +992,8 @@ extension_optional_comma:
   goto format_item;
 
 syntax:
+  if (mode != MODE_FORMAT)
+    format_locus.nextc += format_string_pos;
   if (error == unexpected_element)
     gfc_error (error, error_element, &format_locus);
   else
@@ -1224,8 +1235,11 @@ resolve_tag_format (const gfc_expr *e)
   /* If e's rank is zero and e is not an element of an array, it should be
      of integer or character type.  The integer variable should be
      ASSIGNED.  */
-  if (e->symtree == NULL || e->symtree->n.sym->as == NULL
-      || e->symtree->n.sym->as->rank == 0)
+  if (e->rank == 0
+      && (e->expr_type != EXPR_VARIABLE
+         || e->symtree == NULL
+         || e->symtree->n.sym->as == NULL
+         || e->symtree->n.sym->as->rank == 0))
     {
       if (e->ts.type != BT_CHARACTER && e->ts.type != BT_INTEGER)
        {
@@ -1256,20 +1270,34 @@ resolve_tag_format (const gfc_expr *e)
       return SUCCESS;
     }
 
-  /* If rank is nonzero, we allow the type to be character under GFC_STD_GNU
-     and other type under GFC_STD_LEGACY. It may be assigned an Hollerith
-     constant.  */
-  if (e->ts.type == BT_CHARACTER)
-    {
-      if (gfc_notify_std (GFC_STD_GNU, "Extension: Character array "
-                         "in FORMAT tag at %L", &e->where) == FAILURE)
-       return FAILURE;
-    }
-  else
+  /* If rank is nonzero and type is not character, we allow it under GFC_STD_LEGACY.
+     It may be assigned an Hollerith constant.  */
+  if (e->ts.type != BT_CHARACTER)
     {
       if (gfc_notify_std (GFC_STD_LEGACY, "Extension: Non-character "
                          "in FORMAT tag at %L", &e->where) == FAILURE)
        return FAILURE;
+
+      if (e->rank == 0 && e->symtree->n.sym->as->type == AS_ASSUMED_SHAPE)
+       {
+         gfc_error ("Non-character assumed shape array element in FORMAT"
+                    " tag at %L", &e->where);
+         return FAILURE;
+       }
+
+      if (e->rank == 0 && e->symtree->n.sym->as->type == AS_ASSUMED_SIZE)
+       {
+         gfc_error ("Non-character assumed size array element in FORMAT"
+                    " tag at %L", &e->where);
+         return FAILURE;
+       }
+
+      if (e->rank == 0 && e->symtree->n.sym->attr.pointer)
+       {
+         gfc_error ("Non-character pointer array element in FORMAT tag at %L",
+                    &e->where);
+         return FAILURE;
+       }
     }
 
   return SUCCESS;
@@ -1397,6 +1425,9 @@ match_open_element (gfc_open *open)
   m = match_etag (&tag_convert, &open->convert);
   if (m != MATCH_NO)
     return m;
+  m = match_out_tag (&tag_newunit, &open->newunit);
+  if (m != MATCH_NO)
+    return m;
 
   return MATCH_NO;
 }
@@ -1429,6 +1460,7 @@ gfc_free_open (gfc_open *open)
   gfc_free_expr (open->sign);
   gfc_free_expr (open->convert);
   gfc_free_expr (open->asynchronous);
+  gfc_free_expr (open->newunit);
   gfc_free (open);
 }
 
@@ -1458,6 +1490,7 @@ gfc_resolve_open (gfc_open *open)
   RESOLVE_TAG (&tag_e_round, open->round);
   RESOLVE_TAG (&tag_e_sign, open->sign);
   RESOLVE_TAG (&tag_convert, open->convert);
+  RESOLVE_TAG (&tag_newunit, open->newunit);
 
   if (gfc_reference_st_label (open->err, ST_LABEL_TARGET) == FAILURE)
     return FAILURE;
@@ -1618,6 +1651,26 @@ gfc_match_open (void)
     }
 
   warn = (open->err || open->iostat) ? true : false;
+
+  /* Checks on NEWUNIT specifier.  */
+  if (open->newunit)
+    {
+      if (open->unit)
+       {
+         gfc_error ("UNIT specifier not allowed with NEWUNIT at %C");
+         goto cleanup;
+       }
+
+      if (!(open->file || (open->status
+          && gfc_wide_strncasecmp (open->status->value.character.string,
+                                  "scratch", 7) == 0)))
+       {
+         gfc_error ("NEWUNIT specifier must have FILE= "
+                    "or STATUS='scratch' at %C");
+         goto cleanup;
+       }
+    }
+
   /* Checks on the ACCESS specifier.  */
   if (open->access && open->access->expr_type == EXPR_CONSTANT)
     {
@@ -2045,6 +2098,14 @@ gfc_resolve_close (gfc_close *close)
   if (gfc_reference_st_label (close->err, ST_LABEL_TARGET) == FAILURE)
     return FAILURE;
 
+  if (close->unit->expr_type == EXPR_CONSTANT
+      && close->unit->ts.type == BT_INTEGER
+      && mpz_sgn (close->unit->value.integer) < 0)
+    {
+      gfc_error ("UNIT number in CLOSE statement at %L must be non-negative",
+                &close->unit->where);
+    }
+
   return SUCCESS;
 }
 
@@ -2167,6 +2228,14 @@ gfc_resolve_filepos (gfc_filepos *fp)
   if (gfc_reference_st_label (fp->err, ST_LABEL_TARGET) == FAILURE)
     return FAILURE;
 
+  if (fp->unit->expr_type == EXPR_CONSTANT
+      && fp->unit->ts.type == BT_INTEGER
+      && mpz_sgn (fp->unit->value.integer) < 0)
+    {
+      gfc_error ("UNIT number in statement at %L must be non-negative",
+                &fp->unit->where);
+    }
+
   return SUCCESS;
 }
 
@@ -2562,6 +2631,12 @@ gfc_resolve_dt (gfc_dt *dt)
       return FAILURE;
     }
 
+  if (e->expr_type == EXPR_CONSTANT && e->ts.type == BT_INTEGER
+      && mpz_sgn (e->value.integer) < 0)
+    {
+      gfc_error ("UNIT number in statement at %L must be non-negative", &e->where);
+    }
+
   if (dt->extra_comma
       && gfc_notify_std (GFC_STD_GNU, "Extension: Comma before i/o "
                         "item list at %L", &dt->extra_comma->where) == FAILURE)
@@ -2820,7 +2895,7 @@ match_io_element (io_kind k, gfc_code **cpp)
 
   cp = gfc_get_code ();
   cp->op = EXEC_TRANSFER;
-  cp->expr = expr;
+  cp->expr1 = expr;
 
   *cpp = cp;
   return MATCH_YES;
@@ -2931,6 +3006,10 @@ if (condition) \
       io_constraint (dt->rec != NULL,
                     "REC tag at %L is incompatible with internal file",
                     &dt->rec->where);
+    
+      io_constraint (dt->pos != NULL,
+                    "POS tag at %L is incompatible with internal file",
+                    &dt->pos->where);
 
       io_constraint (unformatted,
                     "Unformatted I/O not allowed with internal unit at %L",
@@ -3169,7 +3248,7 @@ if (condition) \
 
       io_constraint (dt->format_expr,
                     "IO spec-list cannot contain both NAMELIST group name "
-                    "and format specification at %L.",
+                    "and format specification at %L",
                     &dt->format_expr->where);
 
       io_constraint (dt->format_label,
@@ -3178,22 +3257,26 @@ if (condition) \
 
       io_constraint (dt->rec,
                     "NAMELIST IO is not allowed with a REC= specifier "
-                    "at %L.", &dt->rec->where);
+                    "at %L", &dt->rec->where);
 
       io_constraint (dt->advance,
                     "NAMELIST IO is not allowed with a ADVANCE= specifier "
-                    "at %L.", &dt->advance->where);
+                    "at %L", &dt->advance->where);
     }
 
   if (dt->rec)
     {
       io_constraint (dt->end,
                     "An END tag is not allowed with a "
-                    "REC= specifier at %L.", &dt->end_where);
+                    "REC= specifier at %L", &dt->end_where);
 
       io_constraint (dt->format_label == &format_asterisk,
                     "FMT=* is not allowed with a REC= specifier "
-                    "at %L.", spec_end);
+                    "at %L", spec_end);
+
+      io_constraint (dt->pos,
+                    "POS= is not allowed with REC= specifier "
+                    "at %L", &dt->pos->where);
     }
 
   if (dt->advance)
@@ -3644,7 +3727,7 @@ gfc_match_inquire (void)
        goto syntax;
 
       new_st.op = EXEC_IOLENGTH;
-      new_st.expr = inquire->iolength;
+      new_st.expr1 = inquire->iolength;
       new_st.ext.inquire = inquire;
 
       if (gfc_pure (NULL))