From: David Malcolm Date: Tue, 4 Oct 2016 17:10:41 +0000 (+0000) Subject: read-md.c: track column numbers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3814e88007d6d9abfbdfd53dbcdc92fe1aed23de;p=gcc.git read-md.c: track column numbers gcc/ChangeLog: * genattrtab.c (make_internal_attr): Supply dummy column number to file_location ctor. (main): Likewise. * genoutput.c (init_insn_for_nothing): Likewise. * gensupport.c (add_define_attr): Likewise. * read-md.c (message_at_1): Print column number. (fatal_with_file_and_line): Likewise. (rtx_reader::read_char): Track column numbers. (rtx_reader::unread_char): Likewise. (rtx_reader::rtx_reader): Initialize m_read_md_colno. (rtx_reader::handle_include): Stash and restore m_read_md_colno. (rtx_reader::handle_file): Initialize m_read_md_colno. (rtx_reader::get_current_location): Supply column number to file_location ctor. * read-md.h (struct file_location): Add field "colno". (file_location::file_location): Likewise. (rtx_reader::get_colno): New accessor. (rtx_reader::m_read_md_colno): New field. (rtx_reader::m_last_line_colno): New field. From-SVN: r240752 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8aa75ab867b..60aeafb0a16 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,25 @@ +2016-10-04 David Malcolm + + * genattrtab.c (make_internal_attr): Supply dummy column number to + file_location ctor. + (main): Likewise. + * genoutput.c (init_insn_for_nothing): Likewise. + * gensupport.c (add_define_attr): Likewise. + * read-md.c (message_at_1): Print column number. + (fatal_with_file_and_line): Likewise. + (rtx_reader::read_char): Track column numbers. + (rtx_reader::unread_char): Likewise. + (rtx_reader::rtx_reader): Initialize m_read_md_colno. + (rtx_reader::handle_include): Stash and restore m_read_md_colno. + (rtx_reader::handle_file): Initialize m_read_md_colno. + (rtx_reader::get_current_location): Supply column number to + file_location ctor. + * read-md.h (struct file_location): Add field "colno". + (file_location::file_location): Likewise. + (rtx_reader::get_colno): New accessor. + (rtx_reader::m_read_md_colno): New field. + (rtx_reader::m_last_line_colno): New field. + 2016-10-04 Jakub Jelinek * doc/extend.texi (Java Exceptions): Remove. diff --git a/gcc/genattrtab.c b/gcc/genattrtab.c index 3b47f34ec75..6e0a9b9b626 100644 --- a/gcc/genattrtab.c +++ b/gcc/genattrtab.c @@ -4659,7 +4659,7 @@ make_internal_attr (const char *name, rtx value, int special) attr->is_numeric = 1; attr->is_const = 0; attr->is_special = (special & ATTR_SPECIAL) != 0; - attr->default_val = get_attr_value (file_location ("", 0), + attr->default_val = get_attr_value (file_location ("", 0, 0), value, attr, -2); } @@ -5281,7 +5281,7 @@ main (int argc, const char **argv) md_rtx_info info; info.def = rtx_alloc (DEFINE_ASM_ATTRIBUTES); XVEC (info.def, 0) = rtvec_alloc (0); - info.loc = file_location ("", 0); + info.loc = file_location ("", 0, 0); info.index = -1; gen_insn (&info); } diff --git a/gcc/genoutput.c b/gcc/genoutput.c index 59092580e49..f792cb462bf 100644 --- a/gcc/genoutput.c +++ b/gcc/genoutput.c @@ -980,7 +980,7 @@ init_insn_for_nothing (void) idata = XCNEW (struct data); new (idata) data (); idata->name = "*placeholder_for_nothing"; - idata->loc = file_location ("", 0); + idata->loc = file_location ("", 0, 0); idata_end = &idata->next; } diff --git a/gcc/gensupport.c b/gcc/gensupport.c index 1648c9cc649..cb74aeac2ea 100644 --- a/gcc/gensupport.c +++ b/gcc/gensupport.c @@ -446,7 +446,7 @@ add_define_attr (const char *name) XEXP (t1, 2) = rtx_alloc (CONST_STRING); XSTR (XEXP (t1, 2), 0) = "yes"; e->data = t1; - e->loc = file_location ("built-in", -1); + e->loc = file_location ("built-in", -1, -1); e->next = define_attr_queue; define_attr_queue = e; diff --git a/gcc/read-md.c b/gcc/read-md.c index f069ba5a88d..e158be55f9a 100644 --- a/gcc/read-md.c +++ b/gcc/read-md.c @@ -218,7 +218,7 @@ print_c_condition (const char *cond) static void ATTRIBUTE_PRINTF(2,0) message_at_1 (file_location loc, const char *msg, va_list ap) { - fprintf (stderr, "%s:%d: ", loc.filename, loc.lineno); + fprintf (stderr, "%s:%d:%d: ", loc.filename, loc.lineno, loc.colno); vfprintf (stderr, msg, ap); fputc ('\n', stderr); } @@ -274,8 +274,8 @@ fatal_with_file_and_line (const char *msg, ...) va_start (ap, msg); - fprintf (stderr, "%s:%d: error: ", rtx_reader_ptr->get_filename (), - rtx_reader_ptr->get_lineno ()); + fprintf (stderr, "%s:%d:%d: error: ", rtx_reader_ptr->get_filename (), + rtx_reader_ptr->get_lineno (), rtx_reader_ptr->get_colno ()); vfprintf (stderr, msg, ap); putc ('\n', stderr); @@ -294,9 +294,9 @@ fatal_with_file_and_line (const char *msg, ...) } context[i] = '\0'; - fprintf (stderr, "%s:%d: note: following context is `%s'\n", + fprintf (stderr, "%s:%d:%d: note: following context is `%s'\n", rtx_reader_ptr->get_filename (), rtx_reader_ptr->get_lineno (), - context); + rtx_reader_ptr->get_colno (), context); va_end (ap); exit (1); @@ -384,7 +384,13 @@ rtx_reader::read_char (void) ch = getc (m_read_md_file); if (ch == '\n') - m_read_md_lineno++; + { + m_read_md_lineno++; + m_last_line_colno = m_read_md_colno; + m_read_md_colno = 0; + } + else + m_read_md_colno++; return ch; } @@ -395,7 +401,12 @@ void rtx_reader::unread_char (int ch) { if (ch == '\n') - m_read_md_lineno--; + { + m_read_md_lineno--; + m_read_md_colno = m_last_line_colno; + } + else + m_read_md_colno--; ungetc (ch, m_read_md_file); } @@ -908,6 +919,7 @@ rtx_reader::rtx_reader () m_read_md_file (NULL), m_read_md_filename (NULL), m_read_md_lineno (0), + m_read_md_colno (0), m_first_dir_md_include (NULL), m_last_dir_md_include_ptr (&m_first_dir_md_include) { @@ -933,7 +945,7 @@ rtx_reader::handle_include (file_location loc) { const char *filename; const char *old_filename; - int old_lineno; + int old_lineno, old_colno; char *pathname; FILE *input_file, *old_file; @@ -982,6 +994,7 @@ rtx_reader::handle_include (file_location loc) old_file = m_read_md_file; old_filename = m_read_md_filename; old_lineno = m_read_md_lineno; + old_colno = m_read_md_colno; if (include_callback) include_callback (pathname); @@ -995,6 +1008,7 @@ rtx_reader::handle_include (file_location loc) m_read_md_file = old_file; m_read_md_filename = old_filename; m_read_md_lineno = old_lineno; + m_read_md_colno = old_colno; /* Do not free the pathname. It is attached to the various rtx queue elements. */ @@ -1011,6 +1025,7 @@ rtx_reader::handle_file () int c; m_read_md_lineno = 1; + m_read_md_colno = 0; while ((c = read_skip_spaces ()) != EOF) { file_location loc = get_current_location (); @@ -1055,7 +1070,7 @@ rtx_reader::handle_toplevel_file () file_location rtx_reader::get_current_location () const { - return file_location (m_read_md_filename, m_read_md_lineno); + return file_location (m_read_md_filename, m_read_md_lineno, m_read_md_colno); } /* Parse a -I option with argument ARG. */ diff --git a/gcc/read-md.h b/gcc/read-md.h index 82a628bedfa..a74cc726b79 100644 --- a/gcc/read-md.h +++ b/gcc/read-md.h @@ -25,14 +25,15 @@ along with GCC; see the file COPYING3. If not see /* Records a position in the file. */ struct file_location { file_location () {} - file_location (const char *, int); + file_location (const char *, int, int); const char *filename; int lineno; + int colno; }; -inline file_location::file_location (const char *filename_in, int lineno_in) - : filename (filename_in), lineno (lineno_in) {} +inline file_location::file_location (const char *filename_in, int lineno_in, int colno_in) +: filename (filename_in), lineno (lineno_in), colno (colno_in) {} /* Holds one symbol or number in the .md file. */ struct md_name { @@ -112,6 +113,7 @@ class rtx_reader const char *get_top_level_filename () const { return m_toplevel_fname; } const char *get_filename () const { return m_read_md_filename; } int get_lineno () const { return m_read_md_lineno; } + int get_colno () const { return m_read_md_colno; } private: /* A singly-linked list of filenames. */ @@ -144,6 +146,14 @@ class rtx_reader /* The current line number in m_read_md_file. */ int m_read_md_lineno; + /* The current column number in m_read_md_file. */ + int m_read_md_colno; + + /* The column number before the last newline, so that + we can handle unread_char ('\n') at least once whilst + retaining column information. */ + int m_last_line_colno; + /* The first directory to search. */ file_name_list *m_first_dir_md_include;