Commit d7fb38e9 by Janne Blomqvist

PR 25708 Avoid seeking when parsing strings and when peeking.

2011-12-01  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/25708
	* module.c (parse_string): Read string into resizable array
	instead of parsing twice and seeking.
	(peek_atom): New implementation avoiding seeks.
	(require_atom): Save and set column and line explicitly for error
	handling.

From-SVN: r181879
parent c136d696
2011-12-01 Janne Blomqvist <jb@gcc.gnu.org> 2011-12-01 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/25708
* module.c (parse_string): Read string into resizable array
instead of parsing twice and seeking.
(peek_atom): New implementation avoiding seeks.
(require_atom): Save and set column and line explicitly for error
handling.
2011-12-01 Janne Blomqvist <jb@gcc.gnu.org>
* misc.c (gfc_open_file): Don't call stat. * misc.c (gfc_open_file): Don't call stat.
2011-11-29 Thomas Koenig <tkoenig@gcc.gnu.org> 2011-11-29 Thomas Koenig <tkoenig@gcc.gnu.org>
......
...@@ -1069,51 +1069,37 @@ module_unget_char (void) ...@@ -1069,51 +1069,37 @@ module_unget_char (void)
static void static void
parse_string (void) parse_string (void)
{ {
module_locus start; int c;
int len, c; size_t cursz = 30;
char *p; size_t len = 0;
get_module_locus (&start);
len = 0; atom_string = XNEWVEC (char, cursz);
/* See how long the string is. */
for ( ; ; ) for ( ; ; )
{ {
c = module_char (); c = module_char ();
if (c == EOF)
bad_module ("Unexpected end of module in string constant");
if (c != '\'')
{
len++;
continue;
}
c = module_char ();
if (c == '\'') if (c == '\'')
{ {
len++; int c2 = module_char ();
continue; if (c2 != '\'')
} {
module_unget_char ();
break; break;
} }
}
set_module_locus (&start); if (len >= cursz)
atom_string = p = XCNEWVEC (char, len + 1);
for (; len > 0; len--)
{ {
c = module_char (); cursz *= 2;
if (c == '\'') atom_string = XRESIZEVEC (char, atom_string, cursz);
module_char (); /* Guaranteed to be another \'. */ }
*p++ = c; atom_string[len] = c;
len++;
} }
module_char (); /* Terminating \'. */ atom_string = XRESIZEVEC (char, atom_string, len + 1);
*p = '\0'; /* C-style string for debug purposes. */ atom_string[len] = '\0'; /* C-style string for debug purposes. */
} }
...@@ -1279,17 +1265,99 @@ parse_atom (void) ...@@ -1279,17 +1265,99 @@ parse_atom (void)
static atom_type static atom_type
peek_atom (void) peek_atom (void)
{ {
module_locus m; int c;
atom_type a;
get_module_locus (&m); do
{
c = module_char ();
}
while (c == ' ' || c == '\r' || c == '\n');
a = parse_atom (); switch (c)
if (a == ATOM_STRING) {
free (atom_string); case '(':
module_unget_char ();
return ATOM_LPAREN;
case ')':
module_unget_char ();
return ATOM_RPAREN;
case '\'':
module_unget_char ();
return ATOM_STRING;
set_module_locus (&m); case '0':
return a; case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
module_unget_char ();
return ATOM_INTEGER;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
module_unget_char ();
return ATOM_NAME;
default:
bad_module ("Bad name");
}
} }
...@@ -1299,11 +1367,12 @@ peek_atom (void) ...@@ -1299,11 +1367,12 @@ peek_atom (void)
static void static void
require_atom (atom_type type) require_atom (atom_type type)
{ {
module_locus m;
atom_type t; atom_type t;
const char *p; const char *p;
int column, line;
get_module_locus (&m); column = module_column;
line = module_line;
t = parse_atom (); t = parse_atom ();
if (t != type) if (t != type)
...@@ -1329,7 +1398,8 @@ require_atom (atom_type type) ...@@ -1329,7 +1398,8 @@ require_atom (atom_type type)
gfc_internal_error ("require_atom(): bad atom type required"); gfc_internal_error ("require_atom(): bad atom type required");
} }
set_module_locus (&m); module_column = column;
module_line = line;
bad_module (p); bad_module (p);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment