This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] help needed with patch


I'm trying to convert the compiler to make --enable-mapped-location
the default, which means we must convert the remaining front-ends.
I took a stab at converting the Fortran front-end (see attached patch).
The compiler builds, but it fails compiling libgfortran with a strange
syntax error.  Presumably something in my patch is confusing the
lexer or scanner, perhaps causing it to loose or add tokens.

I'm unfamiliar with the Fortran front-end, so I'm hoping someone
familiar with it will take a look at my patch and maybe figure
out what is wrong.  I.e. apply the patch and debug it.  Yes, I
know it's weird asking others to debug my patch, but it affacts
parts of the compiler I don't know and don't have time to to learn,
while on the other hand the Fortran maintainers will need to
learn how to use the source_location type.  (A modest enhancement
of my patch would allow column numbers in debug symbols, by the
way, but I'll leave that for the Fortran maintainers to consider.)

The basic idea is that all front-ends must be converted to use
the "source_location" types in libcpp/include/line-map.h,
and to map between source_location and (filename, line[, column])
pair/triples using the global line_table.

You may notice a FIXME in gfc_get_backend_locus.  This does *not*
appear to be related the Syntax error, since I get the error messages
before I hit a breakpoint set at gfc_get_backend_locus.  The FIXME
is because the old code subtracts one from the input_line, but the
new code doesn't.  This will probably cause a problem.  I'm puzzled
by the logic, because it seems a simple save/restore of the current
input_location around some code that temporarily changes the
input_location - but I don't understand what the subtraction
accomplishes.   If I did I could perhaps suggest a fix.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/

Index: error.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/error.c,v
retrieving revision 1.6
diff -u -p -r1.6 error.c
--- error.c	28 Aug 2004 14:07:03 -0000	1.6
+++ error.c	4 Sep 2004 05:22:48 -0000
@@ -127,7 +127,13 @@ show_locus (int offset, locus * loc)
 
   lb = loc->lb;
   f = lb->file;
-  error_printf ("In file %s:%d\n", f->filename, lb->linenum);
+  error_printf ("In file %s:%d\n", f->filename,
+#ifdef USE_MAPPED_LOCATION
+		LOCATION_LINE (lb->location)
+#else
+		lb->linenum
+#endif
+		);
 
   for (;;)
     {
Index: f95-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/f95-lang.c,v
retrieving revision 1.17
diff -u -p -r1.17 f95-lang.c
--- f95-lang.c	31 Aug 2004 13:39:40 -0000	1.17
+++ f95-lang.c	4 Sep 2004 05:22:49 -0000
@@ -280,6 +280,11 @@ gfc_be_parse_file (int set_yydebug ATTRI
 static bool
 gfc_init (void)
 {
+#ifdef USE_MAPPED_LOCATION
+  linemap_add (&line_table, LC_ENTER, false, gfc_option.source, 1);
+  linemap_add (&line_table, LC_RENAME, false, "<built-in>", 0);
+#endif
+
   /* First initialize the backend.  */
   gfc_init_decl_processing ();
   gfc_static_ctors = NULL_TREE;
Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.34
diff -u -p -r1.34 gfortran.h
--- gfortran.h	30 Aug 2004 21:59:07 -0000	1.34
+++ gfortran.h	4 Sep 2004 05:22:49 -0000
@@ -33,6 +33,7 @@ Software Foundation, 59 Temple Place - S
    seem to be sufficient on some systems.  */
 #include "system.h"
 #include "coretypes.h"
+#include "input.h"
 
 /* The following ifdefs are recommended by the autoconf documentation
    for any code using alloca.  */
@@ -459,7 +460,11 @@ typedef struct gfc_file 
 
 typedef struct gfc_linebuf 
 {
+#ifdef USE_MAPPED_LOCATION
+  source_location location;
+#else
   int linenum;
+#endif
   struct gfc_file *file;
   struct gfc_linebuf *next;
 
Index: scanner.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/scanner.c,v
retrieving revision 1.7
diff -u -p -r1.7 scanner.c
--- scanner.c	18 Jul 2004 13:00:34 -0000	1.7
+++ scanner.c	4 Sep 2004 05:22:49 -0000
@@ -801,7 +801,7 @@ load_line (FILE * input, char **pbuf, ch
    the file stack.  */
 
 static gfc_file *
-get_file (char *name)
+get_file (char *name, enum lc_reason reason)
 {
   gfc_file *f;
 
@@ -817,6 +817,10 @@ get_file (char *name)
   if (current_file != NULL)
     f->inclusion_line = current_file->line;
 
+#ifdef USE_MAPPED_LOCATION
+  linemap_add (&line_table, reason, false, f->filename, 1);
+#endif
+
   return f;
 }
 
@@ -874,7 +878,7 @@ preprocessor_line (char *c)
   
   if (flag[1] || flag[3]) /* Starting new file.  */
     {
-      f = get_file (filename);
+      f = get_file (filename, LC_RENAME);
       f->up = current_file;
       current_file = f;
     }
@@ -999,7 +1003,7 @@ load_file (char *filename, bool initial)
 
   /* Load the file.  */
 
-  f = get_file (filename);
+  f = get_file (filename, initial ? LC_RENAME : LC_ENTER);
   f->up = current_file;
   current_file = f;
   current_file->line = 1;
@@ -1032,7 +1036,12 @@ load_file (char *filename, bool initial)
 
       b = gfc_getmem (sizeof (gfc_linebuf) + len + 1);
 
+#ifdef USE_MAPPED_LOCATION
+      b->location
+	= linemap_line_start (&line_table, current_file->line++, 120);
+#else
       b->linenum = current_file->line++;
+#endif
       b->file = current_file;
       strcpy (b->line, line);
 
@@ -1050,6 +1059,9 @@ load_file (char *filename, bool initial)
   fclose (input);
 
   current_file = current_file->up;
+#ifdef USE_MAPPED_LOCATION
+  linemap_add (&line_table, LC_LEAVE, 0, NULL, 0);
+#endif
   return SUCCESS;
 }
 
@@ -1167,7 +1179,12 @@ gfc_new_file (const char *filename, gfc_
 #if 0 /* Debugging aid.  */
   for (; line_head; line_head = line_head->next)
     gfc_status ("%s:%3d %s\n", line_head->file->filename, 
-		line_head->linenum, line_head->line);
+#ifdef USE_MAPPED_LOCATION
+		LOCATION_LINE (line_head->location),
+#else
+		line_head->linenum,
+#endif
+		line_head->line);
 
   exit (0);
 #endif
Index: trans-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-decl.c,v
retrieving revision 1.40
diff -u -p -r1.40 trans-decl.c
--- trans-decl.c	31 Aug 2004 14:06:46 -0000	1.40
+++ trans-decl.c	4 Sep 2004 05:22:50 -0000
@@ -239,8 +239,12 @@ gfc_get_label_decl (gfc_st_label * lp)
       /* Tell the debugger where the label came from.  */
       if (lp->value <= MAX_LABEL_VALUE)	/* An internal label.  */
 	{
+#ifdef USE_MAPPED_LOCATION
+	  DECL_SOURCE_LOCATION (label_decl) = lp->where.lb->location;
+#else
 	  DECL_SOURCE_LINE (label_decl) = lp->where.lb->linenum;
 	  DECL_SOURCE_FILE (label_decl) = lp->where.lb->file->filename;
+#endif
 	}
       else
 	DECL_ARTIFICIAL (label_decl) = 1;
@@ -2338,7 +2342,7 @@ gfc_generate_constructors (void)
 
   make_decl_rtl (fndecl);
 
-  init_function_start (fndecl, input_filename, input_line);
+  init_function_start (fndecl);
 
   pushlevel (0);
 
Index: trans-io.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-io.c,v
retrieving revision 1.16
diff -u -p -r1.16 trans-io.c
--- trans-io.c	31 Aug 2004 14:06:47 -0000	1.16
+++ trans-io.c	4 Sep 2004 05:22:50 -0000
@@ -524,7 +524,11 @@ set_error_locus (stmtblock_t * block, lo
   tmp = gfc_build_addr_expr (pchar_type_node, tmp);
   gfc_add_modify_expr (block, locus_file, tmp);
 
+#ifdef USE_MAPPED_LOCATION
+  line = LOCATION_LINE (where->lb->location);
+#else
   line = where->lb->linenum;
+#endif
   gfc_add_modify_expr (block, locus_line, build_int_cst (NULL_TREE, line));
 }
 
Index: trans.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans.c,v
retrieving revision 1.14
diff -u -p -r1.14 trans.c
--- trans.c	30 Aug 2004 19:08:38 -0000	1.14
+++ trans.c	4 Sep 2004 05:22:50 -0000
@@ -442,7 +442,11 @@ void
 gfc_get_backend_locus (locus * loc)
 {
   loc->lb = gfc_getmem (sizeof (gfc_linebuf));    
+#ifdef USE_MAPPED_LOCATION
+  loc->lb->location = input_location; // FIXME adjust??
+#else
   loc->lb->linenum = input_line - 1;
+#endif
   loc->lb->file = gfc_current_backend_file;
 }
 
@@ -452,9 +456,13 @@ gfc_get_backend_locus (locus * loc)
 void
 gfc_set_backend_locus (locus * loc)
 {
-  input_line = loc->lb->linenum;
   gfc_current_backend_file = loc->lb->file;
+#ifdef USE_MAPPED_LOCATION
+  input_location = loc->lb->location;
+#else
+  input_line = loc->lb->linenum;
   input_filename = loc->lb->file->filename;
+#endif
 }
 
 
@@ -626,7 +634,7 @@ gfc_trans_code (gfc_code * code)
 	  if (TREE_CODE (res) == STATEMENT_LIST)
 	    annotate_all_with_locus (&res, input_location);
 	  else
-	    annotate_with_locus (res, input_location);
+	    SET_EXPR_LOCATION (res, input_location);
 
 	  /* Add the new statemment to the block.  */
 	  gfc_add_expr_to_block (&block, res);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]