aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/scanner.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-07-07 17:55:53 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2005-07-07 17:55:53 +0200
commit4c3a6ca189d0bf3a62b4f529275e0a666543650c (patch)
tree6b2f9b6876ae8fbaeef20fec5fcae091d024b66a /gcc/fortran/scanner.c
parent452190fb6ac2ab8706715a14e82d742ae545d6c2 (diff)
downloadgcc-4c3a6ca189d0bf3a62b4f529275e0a666543650c.zip
gcc-4c3a6ca189d0bf3a62b4f529275e0a666543650c.tar.gz
gcc-4c3a6ca189d0bf3a62b4f529275e0a666543650c.tar.bz2
scanner.c (preprocessor_line): Only set current_file->line when errors have not been encountered.
* scanner.c (preprocessor_line): Only set current_file->line when errors have not been encountered. Warn and don't crash if a file leave preprocessor line has no corresponding entering line. Formatting. * gfortran.dg/badline.f: New test. From-SVN: r101717
Diffstat (limited to 'gcc/fortran/scanner.c')
-rw-r--r--gcc/fortran/scanner.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index 5aaecdb..b2efd81 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -839,15 +839,13 @@ preprocessor_line (char *c)
line = atoi (c);
- /* Set new line number. */
- current_file->line = line;
-
- c = strchr (c, ' ');
+ c = strchr (c, ' ');
if (c == NULL)
- /* No file name given. */
- return;
-
-
+ {
+ /* No file name given. Set new line number. */
+ current_file->line = line;
+ return;
+ }
/* Skip spaces. */
while (*c == ' ' || *c == '\t')
@@ -880,7 +878,7 @@ preprocessor_line (char *c)
/* Get flags. */
-
+
flag[1] = flag[2] = flag[3] = flag[4] = flag[5] = false;
for (;;)
@@ -895,24 +893,32 @@ preprocessor_line (char *c)
if (1 <= i && i <= 4)
flag[i] = true;
}
-
+
/* Interpret flags. */
-
+
if (flag[1] || flag[3]) /* Starting new file. */
{
f = get_file (filename, LC_RENAME);
f->up = current_file;
current_file = f;
}
-
+
if (flag[2]) /* Ending current file. */
{
- current_file = current_file->up;
+ if (strcmp (current_file->filename, filename) != 0)
+ {
+ gfc_warning_now ("%s:%d: file %s left but not entered",
+ current_file->filename, current_file->line,
+ filename);
+ return;
+ }
+ if (current_file->up)
+ current_file = current_file->up;
}
-
+
/* The name of the file can be a temporary file produced by
cpp. Replace the name if it is different. */
-
+
if (strcmp (current_file->filename, filename) != 0)
{
gfc_free (current_file->filename);
@@ -920,10 +926,12 @@ preprocessor_line (char *c)
strcpy (current_file->filename, filename);
}
+ /* Set new line number. */
+ current_file->line = line;
return;
bad_cpp_line:
- gfc_warning_now ("%s:%d: Illegal preprocessor directive",
+ gfc_warning_now ("%s:%d: Illegal preprocessor directive",
current_file->filename, current_file->line);
current_file->line++;
}