diff options
author | gdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-31 02:10:12 +0000 |
---|---|---|
committer | gdr <gdr@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-31 02:10:12 +0000 |
commit | 209c9752c4626d6a6f46bed656e7ba071206a4d9 (patch) | |
tree | db4116bd3ccfb5c043412bc6f6fbd74c9d552967 /gcc | |
parent | d6583a5ff1599ea0f0808355f6ab375b5877f5d0 (diff) | |
download | gcc-209c9752c4626d6a6f46bed656e7ba071206a4d9.tar.gz |
* c-common.c (catenate_strings): New.
(c_parse_error): Use it. Don't over-escape.
testsuite/
* gcc.dg/20040910-1.c: Adjust regex.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89910 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-common.c | 61 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/20040910-1.c | 2 |
4 files changed, 60 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 78c19ddc43d..05f4e819137 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-10-30 Gabriel Dos Reis <gdr@integrable-solutions.net> + + * c-common.c (catenate_strings): New. + (c_parse_error): Use it. Don't over-escape. + 2004-10-30 Kaz Kojima <kkojima@gcc.gnu.org> * config/sh/sh.c (calc_live_regs): Declare reg as unsigned and diff --git a/gcc/c-common.c b/gcc/c-common.c index 271b4365961..ea8b26c5743 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -5479,36 +5479,75 @@ resort_sorted_fields (void *obj, resort_field_decl_cmp); } +/* Subroutine of c_parse_error. + Return the result of concatenating LHS and RHS. RHS is really + a string literal, its first character is indicated by RHS_START and + RHS_SIZE is its lenght (including the terminating NUL character). + + The caller is responsible for deleting the returned pointer. */ + +static char * +catenate_strings (const char *lhs, const char *rhs_start, int rhs_size) +{ + const int lhs_size = strlen (lhs); + char *result = XNEWVEC (char, lhs_size + rhs_size); + strncpy (result, lhs, lhs_size); + strncpy (result + lhs_size, rhs_start, rhs_size); + return result; +} + /* Issue the error given by MSGID, indicating that it occurred before TOKEN, which had the associated VALUE. */ void c_parse_error (const char *msgid, enum cpp_ttype token, tree value) { - const char *string = _(msgid); +#define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2)) + + char *message = NULL; if (token == CPP_EOF) - error ("%s at end of input", string); + message = catenate_messages (msgid, " at end of input"); else if (token == CPP_CHAR || token == CPP_WCHAR) { unsigned int val = TREE_INT_CST_LOW (value); const char *const ell = (token == CPP_CHAR) ? "" : "L"; if (val <= UCHAR_MAX && ISGRAPH (val)) - error ("%s before %s'%c'", string, ell, val); + message = catenate_messages (msgid, " before %s'%c'"); else - error ("%s before %s'\\x%x'", string, ell, val); + message = catenate_messages (msgid, " before %s'\\x%x'"); + + error (message, ell, val); + free (message); + message = NULL; } - else if (token == CPP_STRING - || token == CPP_WSTRING) - error ("%s before string constant", string); + else if (token == CPP_STRING || token == CPP_WSTRING) + message = catenate_messages (msgid, " before string constant"); else if (token == CPP_NUMBER) - error ("%s before numeric constant", string); + message = catenate_messages (msgid, " before numeric constant"); else if (token == CPP_NAME) - error ("%s before \"%s\"", string, IDENTIFIER_POINTER (value)); + { + message = catenate_messages (msgid, " before %qs"); + error (message, IDENTIFIER_POINTER (value)); + free (message); + message = NULL; + } else if (token < N_TTYPES) - error ("%s before %qs token", string, cpp_type2name (token)); + { + message = catenate_messages (msgid, " before %qs token"); + error (message, cpp_type2name (token)); + free (message); + message = NULL; + } else - error ("%s", string); + error (msgid); + + if (message) + { + error (message); + free (message); + } +#undef catenate_messages } /* Walk a gimplified function and warn for functions whose return value is diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aa3247ef5fd..98b107fc853 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-10-30 Gabriel Dos Reis <gdr@integrable-solutions.net> + + * gcc.dg/20040910-1.c: Adjust regex. + 2004-10-30 Roger Sayle <roger@eyesopen.com> PR rtl-optimization/18084 diff --git a/gcc/testsuite/gcc.dg/20040910-1.c b/gcc/testsuite/gcc.dg/20040910-1.c index 25b51ff7e1b..10f5fb32662 100644 --- a/gcc/testsuite/gcc.dg/20040910-1.c +++ b/gcc/testsuite/gcc.dg/20040910-1.c @@ -1,2 +1,2 @@ /* Tests error recovery for invalid code. */ -__attribute__((foo) int f (){} /* { dg-error "(parse|syntax) error before \"int\"" } */ +__attribute__((foo) int f (){} /* { dg-error "(parse|syntax) error before 'int'" } */ |