aboutsummaryrefslogtreecommitdiff
path: root/gcc/input.c
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2012-04-11 09:26:48 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2012-04-11 09:26:48 +0000
commit9fec00429dd36ea51798afeaf5f6b9c1987b85cd (patch)
tree9e780906c85f6be0ad543abba26314c0c15e5512 /gcc/input.c
parent13a7578b180de6d8bb91a2f340817e71c61a9988 (diff)
downloadgcc-9fec00429dd36ea51798afeaf5f6b9c1987b85cd.zip
gcc-9fec00429dd36ea51798afeaf5f6b9c1987b85cd.tar.gz
gcc-9fec00429dd36ea51798afeaf5f6b9c1987b85cd.tar.bz2
re PR c++/24985 (caret diagnostics)
2012-04-11 Manuel López-Ibáñez <manu@gcc.gnu.org> PR 24985 gcc/ * diagnostic.h (show_caret): Declare. (caret_max_width): Declare. (diagnostic_show_locus): Declare. * diagnostic.c (diagnostic_initialize): Initialize to false. (diagnostic_show_locus): New. (diagnostic_report_diagnostic): Call it. (getenv_columns): New. (adjust_line): New. (diagnostic_set_caret_max_width): New. * input.c (read_line): New. (location_get_source_line): New. * input.h (location_get_source_line): Declare. * toplev.c (general_init): Initialize show_caret from options. * dwarf2out.c (gen_producer_string): Handle fdiagnostics-show-caret. * opts.c (common_handle_option): Likewise. * pretty-print.h (pp_get_prefix): New. (pp_base_get_prefix): New. * common.opt (fdiagnostics-show-caret): New option. * doc/invoke.texi (fdiagnostics-show-caret): Document it. testsuite/ * lib/prune.exp: Add -fno-diagnostics-show-caret. libstdc++-v3/ * testsuite/lib/prune.exp: Handle caret. libmudflap/ * testsuite/lib/libmudflap.exp: Handle caret. From-SVN: r186305
Diffstat (limited to 'gcc/input.c')
-rw-r--r--gcc/input.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/gcc/input.c b/gcc/input.c
index 4077f9e..bf5fe48 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -50,6 +50,65 @@ expand_location (source_location loc)
return xloc;
}
+/* Reads one line from file into a static buffer. */
+static const char *
+read_line (FILE *file)
+{
+ static char *string;
+ static size_t string_len;
+ size_t pos = 0;
+ char *ptr;
+
+ if (!string_len)
+ {
+ string_len = 200;
+ string = XNEWVEC (char, string_len);
+ }
+
+ while ((ptr = fgets (string + pos, string_len - pos, file)))
+ {
+ size_t len = strlen (string + pos);
+
+ if (string[pos + len - 1] == '\n')
+ {
+ string[pos + len - 1] = 0;
+ return string;
+ }
+ pos += len;
+ ptr = XNEWVEC (char, string_len * 2);
+ if (ptr)
+ {
+ memcpy (ptr, string, pos);
+ string = ptr;
+ string_len += 2;
+ }
+ else
+ pos = 0;
+ }
+
+ return pos ? string : NULL;
+}
+
+/* Return the physical source line that corresponds to xloc in a
+ buffer that is statically allocated. The newline is replaced by
+ the null character. */
+
+const char *
+location_get_source_line(expanded_location xloc)
+{
+ const char *buffer;
+ int lines = 1;
+ FILE *stream = xloc.file ? fopen (xloc.file, "r") : NULL;
+ if (!stream)
+ return NULL;
+
+ while ((buffer = read_line (stream)) && lines < xloc.line)
+ lines++;
+
+ fclose (stream);
+ return buffer;
+}
+
#define ONE_K 1024
#define ONE_M (ONE_K * ONE_K)