Hello Pietro.
Thanks for the patch.
> Use a location_t to track the position of LINE_T's. Use use linemap
> associated with the location to track the file name the line belongs
> to.
This is a very good improvement!
See a few notes below.
> [...]
> @@ -357,20 +358,27 @@ read_source_file (const char *filename)
> A68_PARSER (scan_buf)[l] = '\0';
> if (k < source_file_size)
> k++;
> - append_source_line (A68_PARSER (scan_buf), &ref_l, &line_num,
> - FILE_SOURCE_NAME (&A68_JOB));
> + append_source_line (A68_PARSER (scan_buf), &ref_l, &line_num);
> SCAN_ERROR (l != (ssize_t) strlen (A68_PARSER (scan_buf)),
> NO_LINE, NO_TEXT, "invalid characters in source file");
> }
>
> + /* Extra line before adding postlude. */
> + linemap_line_start (line_table,
> + line_num,
> + 80 /* max_column_hint */);
> +
What is max_column_hint for?
> /* Postlude. */
> append_environ (OPTION_STROPPING (&A68_JOB) == UPPER_STROPPING
> ? upper_postlude : supper_postlude,
> - &ref_l, &line_num, "postlude");
> + &ref_l, "postlude");
>
> /* Include files. */
> include_files (TOP_LINE (&A68_JOB));
>
> + linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
> + linemap_check_files_exited (line_table);
> +
> if (fclose (FILE_SOURCE_FD (&A68_JOB)) != 0)
> gcc_unreachable ();
> return ret;
> @@ -1057,6 +1065,8 @@ include_files (LINE_T *top)
> SCAN_ERROR ((size_t) bytes_read != fsize, start_l, start_c,
> "error while reading file");
>
> + linemap_add (line_table, LC_ENTER, 0 /* sys_p */, fn,
> + 0 /* to_line */);
> /* Buffer still usable?. */
> if (fsize > A68_PARSER (max_scan_buf_length))
> {
> @@ -1074,7 +1084,7 @@ include_files (LINE_T *top)
> /* If file is empty, insert single empty line. */
> A68_PARSER (scan_buf)[0] = NEWLINE_CHAR;
> A68_PARSER (scan_buf)[1] = NULL_CHAR;
> - append_source_line (A68_PARSER (scan_buf), &t, &linum, fn);
> + append_source_line (A68_PARSER (scan_buf), &t, &linum);
> }
> else
> {
> @@ -1095,11 +1105,12 @@ include_files (LINE_T *top)
> A68_PARSER (scan_buf)[n] = NULL_CHAR;
> if (k < fsize)
> k++;
> - append_source_line (A68_PARSER (scan_buf), &t, &linum,
> fn);
> + append_source_line (A68_PARSER (scan_buf), &t, &linum);
> }
> }
>
> /* Conclude and go find another include directive, if any. */
> + linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
> NEXT (t) = s;
> PREVIOUS (s) = t;
> if (fclose (fp) != 0)
> diff --git a/gcc/algol68/a68-parser-top-down.cc
> b/gcc/algol68/a68-parser-top-down.cc
> index 238749fcb66..b3f332101b8 100644
> --- a/gcc/algol68/a68-parser-top-down.cc
> +++ b/gcc/algol68/a68-parser-top-down.cc
> @@ -64,7 +64,8 @@ const char *
> a68_phrase_to_text (NODE_T * p, NODE_T ** w)
> {
> #define MAX_TERMINALS 8
> - int count = 0, line = -1;
> + int count = 0;
> + unsigned int line = 0;
> static BUFFER buffer;
>
> for (buffer[0] = '\0'; p != NO_NODE && count < MAX_TERMINALS; FORWARD (p))
> diff --git a/gcc/algol68/a68-parser.cc b/gcc/algol68/a68-parser.cc
> index 4303d5297e8..878d9d6cd9b 100644
> --- a/gcc/algol68/a68-parser.cc
> +++ b/gcc/algol68/a68-parser.cc
> @@ -1153,18 +1153,9 @@ a68_get_node_location (NODE_T *p)
> if (line == NO_LINE)
> return UNKNOWN_LOCATION;
>
> - unsigned line_number = NUMBER (line);
> - unsigned column_number = CHAR_IN_LINE (INFO (p)) - STRING (line) + 1;
> - const char *filename = FILENAME (line);
> -
> - location_t gcc_location;
> -
> - linemap_add (line_table, LC_ENTER, 0, filename, line_number);
> - linemap_line_start (line_table, line_number, 0);
> - gcc_location = linemap_position_for_column (line_table, column_number);
> - linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
> -
> - return gcc_location;
> + const char *start_pos = CHAR_IN_LINE (INFO (p));
> + location_t start_loc = a68_get_line_location (line, start_pos);
> + return start_loc;
> }
>
> /* Get the location of POS inside LINE as a GCC location. */
> @@ -1172,11 +1163,9 @@ a68_get_node_location (NODE_T *p)
> location_t
> a68_get_line_location (LINE_T *line, const char *pos)
> {
> - location_t loc;
> -
> - linemap_add (line_table, LC_ENTER, 0, FILENAME (line), NUMBER (line));
> - linemap_line_start (line_table, NUMBER (line), 0);
> - loc = linemap_position_for_column (line_table, pos - STRING (line) + 1);
> - linemap_add (line_table, LC_LEAVE, 0, NULL, 0);
> + unsigned column_number = pos - STRING (line) + 1;
> + location_t loc = linemap_position_for_loc_and_offset (line_table,
> + LOCATION(line),
> + column_number);
> return loc;
> }
> diff --git a/gcc/algol68/a68-pretty-print.h b/gcc/algol68/a68-pretty-print.h
> index 16dbb415b86..0b78599876f 100644
> --- a/gcc/algol68/a68-pretty-print.h
> +++ b/gcc/algol68/a68-pretty-print.h
> @@ -223,14 +223,15 @@ public:
> a68_line_format_token (LINE_T *l, NODE_T *n)
> {
> gcc_assert (l != NO_LINE);
> - if (NUMBER (l) == 0)
> + const char *fname = FILENAME (l);
> + if (strcmp (fname, "prelude") == 0 || strcmp (fname, "postlude") == 0)
> m_str = xstrdup ("in standard environment");
> - else if (n != NO_NODE && NUMBER (l) == LINE_NUMBER (n))
> + else if (n != NO_NODE && LINE_NO (l) == LINE_NUMBER (n))
> m_str = xstrdup ("in this line");
> else
> {
> m_str = (char *) xmalloc (18);
> - if (snprintf (m_str, 18, "in line %d", NUMBER (l)) < 0)
> + if (snprintf (m_str, 18, "in line %d", LINE_NO (l)) < 0)
> gcc_unreachable ();
> }
> }
> diff --git a/gcc/algol68/a68-types.h b/gcc/algol68/a68-types.h
> index 5bf348890f7..472a8bb29ef 100644
> --- a/gcc/algol68/a68-types.h
> +++ b/gcc/algol68/a68-types.h
> @@ -537,8 +537,7 @@ struct GTY((chain_next ("%h.next"))) LINE_T
> {
> char marker[6];
> char * GTY((skip)) string;
> - const char *filename;
> - int number;
> + location_t location;
> LINE_T *next, *previous;
> };
> #define NO_LINE ((LINE_T *) 0)
> @@ -949,7 +948,6 @@ struct GTY(()) A68_T
> #define EXTRACT_VARIABLE(p) ((p)->variable)
> #define WARNING_COUNT(p) ((p)->warning_count)
> #define F(p) ((p)->f)
> -#define FILENAME(p) ((p)->filename)
> #define FILE_SOURCE_FD(p) ((p)->file_source_fd)
> #define FILE_SOURCE_NAME(p) ((p)->file_source_name)
> #define FLEXO(p) ((p).flexo)
> @@ -996,10 +994,11 @@ struct GTY(()) A68_T
> #define LEX_LEVEL(p) (LEVEL (TABLE (p)))
> #define LINBUF(p) ((p)->linbuf)
> #define LINE(p) ((p)->line)
> +#define LOCATION(p) ((p)->location)
> #define LINE_APPLIED(p) ((p)->line_applied)
> #define LINE_DEFINED(p) ((p)->line_defined)
> #define LINE_END_MENDED(p) ((p)->line_end_mended)
> -#define LINE_NUMBER(p) (NUMBER (LINE (INFO (p))))
> +#define LINE_NUMBER(p) (LINE_NO (LINE (INFO (p))))
> #define LINSIZ(p) ((p)->linsiz)
> #define LIST(p) ((p)->list)
> #define ln(x) (log (x))
> diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
> index 13603061290..50f2349b15a 100644
> --- a/gcc/algol68/a68.h
> +++ b/gcc/algol68/a68.h
> @@ -107,6 +107,30 @@ enum
>
> #include "a68-types.h"
>
> +/* Location-tracking functions. */
> +
> +/* Get the line name that LINE belongs to. */
line name? Wouldn't that be line contents?
> +
> +inline const char *
> +FILENAME (LINE_T *line)
> +{
> + const line_map_ordinary * ord_map;
> + ord_map = (const line_map_ordinary *)(linemap_lookup (line_table,
> + LOCATION (line)));
> + return LINEMAP_FILE (ord_map);
> +}
> +
> +/* Get the 1-based line nuber of LINE. */
Typo, s/nuber/number.
> +
> +inline unsigned int
> +LINE_NO (LINE_T *line)
> +{
> + location_t loc = LOCATION (line);
> + const line_map_ordinary * ord_map;
> + ord_map = (const line_map_ordinary *)(linemap_lookup (line_table, loc));
> + return SOURCE_LINE (ord_map, loc);
> +}
> +
> /* Front-end global state. */
>
> extern GTY(()) A68_T a68_common;