PR fortran/33739
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Nov 2007 19:19:50 +0000 (19:19 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 8 Nov 2007 19:19:50 +0000 (19:19 +0000)
* scanner.c (start_source_file, end_source_file,
exit_remaining_files): New functions.
(gfc_advance_line): Use the new functions.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130016 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/scanner.c

index 0ce1bfa..4306a92 100644 (file)
@@ -1,5 +1,12 @@
 2007-11-08  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
+       PR fortran/33739
+       * scanner.c (start_source_file, end_source_file,
+       exit_remaining_files): New functions.
+       (gfc_advance_line): Use the new functions.
+
+2007-11-08  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
        PR fortran/34028
        * trans-intrinsic.c (gfc_conv_intrinsic_ishft): Use correct type.
 
index b9e7114..89aef49 100644 (file)
@@ -300,13 +300,59 @@ gfc_at_eol (void)
 }
 
 
+struct file_entered_chainon
+{
+  gfc_file *file;
+  struct file_entered_chainon *prev;
+};
+
+static struct file_entered_chainon *last_file_entered = NULL;
+
+static void
+start_source_file (int line, gfc_file *file)
+{
+  struct file_entered_chainon *f = gfc_getmem (sizeof
+                                       (struct file_entered_chainon));
+
+  f->file = file;
+  f->prev = last_file_entered;
+  last_file_entered = f;
+
+  (*debug_hooks->start_source_file) (line, file->filename);
+}
+
+static void
+end_source_file (int line)
+{
+  gcc_assert (last_file_entered);
+  last_file_entered = last_file_entered->prev;
+  (*debug_hooks->end_source_file) (line);
+}
+
+static void
+exit_remaining_files (void)
+{
+  struct file_entered_chainon *f = last_file_entered;
+  while (f)
+    {
+      /* The line number doesn't matter much, because we're at the end of
+         the toplevel file anyway.  */
+      (*debug_hooks->end_source_file) (0);
+
+      f = f->prev;
+    }
+}
+
 /* Advance the current line pointer to the next line.  */
 
 void
 gfc_advance_line (void)
 {
   if (gfc_at_end ())
-    return;
+    {
+      exit_remaining_files ();
+      return;
+    }
 
   if (gfc_current_locus.lb == NULL) 
     {
@@ -322,17 +368,15 @@ gfc_advance_line (void)
          && gfc_current_locus.lb->file->up == gfc_current_locus.lb->next->file)
        {
          /* We exit from an included file. */
-         (*debug_hooks->end_source_file)
-               (gfc_linebuf_linenum (gfc_current_locus.lb->next));
+         end_source_file (gfc_linebuf_linenum (gfc_current_locus.lb->next));
          gfc_current_locus.lb->next->dbg_emitted = true;
        }
       else if (gfc_current_locus.lb->next->file != gfc_current_locus.lb->file
               && !gfc_current_locus.lb->next->dbg_emitted)
        {
          /* We enter into a new file.  */
-         (*debug_hooks->start_source_file)
-               (gfc_linebuf_linenum (gfc_current_locus.lb),
-                gfc_current_locus.lb->next->file->filename);
+         start_source_file (gfc_linebuf_linenum (gfc_current_locus.lb),
+                            gfc_current_locus.lb->next->file);
          gfc_current_locus.lb->next->dbg_emitted = true;
        }
     }