diff options
| author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2009-04-22 15:32:18 +0000 |
|---|---|---|
| committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2009-04-22 15:32:18 +0000 |
| commit | cfc935327585254eabd5c18f298b1b4bc28a2b02 (patch) | |
| tree | 51e37b610f5f0eae957aa2a3cee06eec9ab65abb /libcpp | |
| parent | 8632d02a43457ecbcef85175e7575e5da6784646 (diff) | |
| download | gcc-cfc935327585254eabd5c18f298b1b4bc28a2b02.tar.gz gcc-cfc935327585254eabd5c18f298b1b4bc28a2b02.tar.bz2 gcc-cfc935327585254eabd5c18f298b1b4bc28a2b02.zip | |
re PR c++/14875 (When using 'or' keyword, the error message speaks of a '||' token)
2009-04-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/14875
* c-common.c (c_parse_error): Take a token_flags parameter.
Use token_type for the token type instead.
Pass token_flags to cpp_type2name.
* c-common.h (c_parse_error): Update declaration.
* c-parser.c (c_parser_error): Pass 0 as token flags.
libcpp/
* lex.c (cpp_type2name): Take a flags parameter. Call
cpp_named_operator2name for named operators and cpp_digraph2name
for digraphs.
(cpp_digraph2name): New.
(cpp_spell_token): Use it.
(cpp_output_token): Likewise.
* include/cpplib.h (cpp_type2name): Update declaration.
* init.c (cpp_named_operator2name): New.
* internal.h (cpp_named_operator2name): Declare.
cp/
* parser.c (cp_parser_error): Pass token->flags to c_parse_error.
testsuite/
* g++.dg/parse/parser-pr14875.C: New.
* g++.dg/parse/parser-pr14875-2.C: New.
* g++.dg/parse/error6.C: Update match string.
From-SVN: r146589
Diffstat (limited to 'libcpp')
| -rw-r--r-- | libcpp/ChangeLog | 13 | ||||
| -rw-r--r-- | libcpp/include/cpplib.h | 2 | ||||
| -rw-r--r-- | libcpp/init.c | 18 | ||||
| -rw-r--r-- | libcpp/internal.h | 1 | ||||
| -rw-r--r-- | libcpp/lex.c | 25 |
5 files changed, 51 insertions, 8 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 7fdc737239f..ff720612a56 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,16 @@ +2009-04-22 Manuel Lopez-Ibanez <manu@gcc.gnu.org> + + PR c++/14875 + * lex.c (cpp_type2name): Take a flags parameter. Call + cpp_named_operator2name for named operators and cpp_digraph2name + for digraphs. + (cpp_digraph2name): New. + (cpp_spell_token): Use it. + (cpp_output_token): Likewise. + * include/cpplib.h (cpp_type2name): Update declaration. + * init.c (cpp_named_operator2name): New. + * internal.h (cpp_named_operator2name): Declare. + 2009-04-21 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR c++/13358 diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 3aeb035f48f..b38d9f43ef5 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -841,7 +841,7 @@ extern void cpp_output_line (cpp_reader *, FILE *); extern unsigned char *cpp_output_line_to_string (cpp_reader *, const unsigned char *); extern void cpp_output_token (const cpp_token *, FILE *); -extern const char *cpp_type2name (enum cpp_ttype); +extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags); /* Returns the value of an escape sequence, truncated to the correct target precision. PSTR points to the input pointer, which is just after the backslash. LIMIT is how much text we have. WIDE is true diff --git a/libcpp/init.c b/libcpp/init.c index c21121707d3..aef39981792 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -381,6 +381,24 @@ mark_named_operators (cpp_reader *pfile) } } +/* Helper function of cpp_type2name. Return the string associated with + named operator TYPE. */ +const char * +cpp_named_operator2name (enum cpp_ttype type) +{ + const struct builtin_operator *b; + + for (b = operator_array; + b < (operator_array + ARRAY_SIZE (operator_array)); + b++) + { + if (type == b->value) + return (const char *) b->name; + } + + return NULL; +} + void cpp_init_special_builtins (cpp_reader *pfile) { diff --git a/libcpp/internal.h b/libcpp/internal.h index 4368ebbe998..22e6d238906 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -570,6 +570,7 @@ extern void _cpp_init_tokenrun (tokenrun *, unsigned int); /* In init.c. */ extern void _cpp_maybe_push_include_file (cpp_reader *); +extern const char *cpp_named_operator2name (enum cpp_ttype type); /* In directives.c */ extern int _cpp_test_assertion (cpp_reader *, unsigned int *); diff --git a/libcpp/lex.c b/libcpp/lex.c index 63e291c64c0..af5c06a7abc 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -1416,6 +1416,13 @@ utf8_to_ucn (unsigned char *buffer, const unsigned char *name) return ucn_len; } +/* Given a token TYPE corresponding to a digraph, return a pointer to + the spelling of the digraph. */ +static const unsigned char * +cpp_digraph2name (enum cpp_ttype type) +{ + return digraph_spellings[(int) type - (int) CPP_FIRST_DIGRAPH]; +} /* Write the spelling of a token TOKEN to BUFFER. The buffer must already contain the enough space to hold the token's spelling. @@ -1435,8 +1442,7 @@ cpp_spell_token (cpp_reader *pfile, const cpp_token *token, unsigned char c; if (token->flags & DIGRAPH) - spelling - = digraph_spellings[(int) token->type - (int) CPP_FIRST_DIGRAPH]; + spelling = cpp_digraph2name (token->type); else if (token->flags & NAMED_OP) goto spell_ident; else @@ -1499,11 +1505,17 @@ cpp_token_as_text (cpp_reader *pfile, const cpp_token *token) return start; } -/* Used by C front ends, which really should move to using - cpp_token_as_text. */ +/* Returns a pointer to a string which spells the token defined by + TYPE and FLAGS. Used by C front ends, which really should move to + using cpp_token_as_text. */ const char * -cpp_type2name (enum cpp_ttype type) +cpp_type2name (enum cpp_ttype type, unsigned char flags) { + if (flags & DIGRAPH) + return (const char *) cpp_digraph2name (type); + else if (flags & NAMED_OP) + return cpp_named_operator2name (type); + return (const char *) token_spellings[type].name; } @@ -1521,8 +1533,7 @@ cpp_output_token (const cpp_token *token, FILE *fp) int c; if (token->flags & DIGRAPH) - spelling - = digraph_spellings[(int) token->type - (int) CPP_FIRST_DIGRAPH]; + spelling = cpp_digraph2name (token->type); else if (token->flags & NAMED_OP) goto spell_ident; else |
