diff options
author | Kris Van Hees <kris.van.hees@oracle.com> | 2008-04-18 13:58:08 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2008-04-18 09:58:08 -0400 |
commit | b6baa67d7947f7e4fc1481c87fcb55d54c56f0cf (patch) | |
tree | 7a2e1b1d5ba3460de2699e7cd1bc2b1739fc3119 /gcc/cp | |
parent | 14a8726b8a54cf83654426302e4fe91877cad971 (diff) | |
download | gcc-b6baa67d7947f7e4fc1481c87fcb55d54c56f0cf.zip gcc-b6baa67d7947f7e4fc1481c87fcb55d54c56f0cf.tar.gz gcc-b6baa67d7947f7e4fc1481c87fcb55d54c56f0cf.tar.bz2 |
cpp-id-data.h (UC): Was U, conflicts with U...
libcpp/ChangeLog:
2008-04-14 Kris Van Hees <kris.van.hees@oracle.com>
* include/cpp-id-data.h (UC): Was U, conflicts with U... literal.
* include/cpplib.h (CHAR16, CHAR32, STRING16, STRING32): New tokens.
(struct cpp_options): Added uliterals.
(cpp_interpret_string): Update prototype.
(cpp_interpret_string_notranslate): Idem.
* charset.c (init_iconv_desc): New width member in cset_converter.
(cpp_init_iconv): Add support for char{16,32}_cset_desc.
(convert_ucn): Idem.
(emit_numeric_escape): Idem.
(convert_hex): Idem.
(convert_oct): Idem.
(convert_escape): Idem.
(converter_for_type): New function.
(cpp_interpret_string): Use converter_for_type, support u and U prefix.
(cpp_interpret_string_notranslate): Match changed prototype.
(wide_str_to_charconst): Use converter_for_type.
(cpp_interpret_charconst): Add support for CPP_CHAR{16,32}.
* directives.c (linemarker_dir): Macro U changed to UC.
(parse_include): Idem.
(register_pragma_1): Idem.
(restore_registered_pragmas): Idem.
(get__Pragma_string): Support CPP_STRING{16,32}.
* expr.c (eval_token): Support CPP_CHAR{16,32}.
* init.c (struct lang_flags): Added uliterals.
(lang_defaults): Idem.
* internal.h (struct cset_converter) <width>: New field.
(struct cpp_reader) <char16_cset_desc>: Idem.
(struct cpp_reader) <char32_cset_desc>: Idem.
* lex.c (digraph_spellings): Macro U changed to UC.
(OP, TK): Idem.
(lex_string): Add support for u'...', U'...', u... and U....
(_cpp_lex_direct): Idem.
* macro.c (_cpp_builtin_macro_text): Macro U changed to UC.
(stringify_arg): Support CPP_CHAR{16,32} and CPP_STRING{16,32}.
gcc/ChangeLog:
2008-04-14 Kris Van Hees <kris.van.hees@oracle.com>
* c-common.c (CHAR16_TYPE, CHAR32_TYPE): New macros.
(fname_as_string): Match updated cpp_interpret_string prototype.
(fix_string_type): Support char16_t* and char32_t*.
(c_common_nodes_and_builtins): Add char16_t and char32_t (and
derivative) nodes. Register as builtin if C++0x.
(c_parse_error): Support CPP_CHAR{16,32}.
* c-common.h (RID_CHAR16, RID_CHAR32): New elements.
(enum c_tree_index) <CTI_CHAR16_TYPE, CTI_SIGNED_CHAR16_TYPE,
CTI_UNSIGNED_CHAR16_TYPE, CTI_CHAR32_TYPE, CTI_SIGNED_CHAR32_TYPE,
CTI_UNSIGNED_CHAR32_TYPE, CTI_CHAR16_ARRAY_TYPE,
CTI_CHAR32_ARRAY_TYPE>: New elements.
(char16_type_node, signed_char16_type_node, unsigned_char16_type_node,
char32_type_node, signed_char32_type_node, char16_array_type_node,
char32_array_type_node): New defines.
* c-lex.c (cb_ident): Match updated cpp_interpret_string prototype.
(c_lex_with_flags): Support CPP_CHAR{16,32} and CPP_STRING{16,32}.
(lex_string): Support CPP_STRING{16,32}, match updated
cpp_interpret_string and cpp_interpret_string_notranslate prototypes.
(lex_charconst): Support CPP_CHAR{16,32}.
* c-parser.c (c_parser_postfix_expression): Support CPP_CHAR{16,32}
and CPP_STRING{16,32}.
gcc/cp/ChangeLog:
2008-04-14 Kris Van Hees <kris.van.hees@oracle.com>
* cvt.c (type_promotes_to): Support char16_t and char32_t.
* decl.c (grokdeclarator): Disallow signed/unsigned/short/long on
char16_t and char32_t.
* lex.c (reswords): Add char16_t and char32_t (for c++0x).
* mangle.c (write_builtin_type): Mangle char16_t/char32_t as vendor
extended builtin type u8char32_t.
* parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Support
RID_CHAR{16,32}.
(cp_lexer_print_token): Support CPP_STRING{16,32}.
(cp_parser_is_string_literal): Idem.
(cp_parser_string_literal): Idem.
(cp_parser_primary_expression): Support CPP_CHAR{16,32} and
CPP_STRING{16,32}.
(cp_parser_simple_type_specifier): Support RID_CHAR{16,32}.
* tree.c (char_type_p): Support char16_t and char32_t as char types.
* typeck.c (string_conv_p): Support char16_t and char32_t.
gcc/testsuite/ChangeLog:
2008-04-14 Kris Van Hees <kris.van.hees@oracle.com>
Tests for char16_t and char32_t support.
* g++.dg/ext/utf-cvt.C: New
* g++.dg/ext/utf-cxx0x.C: New
* g++.dg/ext/utf-cxx98.C: New
* g++.dg/ext/utf-dflt.C: New
* g++.dg/ext/utf-gnuxx0x.C: New
* g++.dg/ext/utf-gnuxx98.C: New
* g++.dg/ext/utf-mangle.C: New
* g++.dg/ext/utf-typedef-cxx0x.C: New
* g++.dg/ext/utf-typedef-
* g++.dg/ext/utf-typespec.C: New
* g++.dg/ext/utf16-1.C: New
* g++.dg/ext/utf16-2.C: New
* g++.dg/ext/utf16-3.C: New
* g++.dg/ext/utf16-4.C: New
* g++.dg/ext/utf32-1.C: New
* g++.dg/ext/utf32-2.C: New
* g++.dg/ext/utf32-3.C: New
* g++.dg/ext/utf32-4.C: New
* gcc.dg/utf-cvt.c: New
* gcc.dg/utf-dflt.c: New
* gcc.dg/utf16-1.c: New
* gcc.dg/utf16-2.c: New
* gcc.dg/utf16-3.c: New
* gcc.dg/utf16-4.c: New
* gcc.dg/utf32-1.c: New
* gcc.dg/utf32-2.c: New
* gcc.dg/utf32-3.c: New
* gcc.dg/utf32-4.c: New
libiberty/ChangeLog:
2008-04-14 Kris Van Hees <kris.van.hees@oracle.com>
* testsuite/demangle-expected: Added tests for char16_t and char32_t.
From-SVN: r134438
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 19 | ||||
-rw-r--r-- | gcc/cp/cvt.c | 2 | ||||
-rw-r--r-- | gcc/cp/decl.c | 7 | ||||
-rw-r--r-- | gcc/cp/lex.c | 2 | ||||
-rw-r--r-- | gcc/cp/mangle.c | 8 | ||||
-rw-r--r-- | gcc/cp/parser.c | 72 | ||||
-rw-r--r-- | gcc/cp/tree.c | 2 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 4 |
8 files changed, 99 insertions, 17 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3169ba0..b348c0d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,22 @@ +2008-04-18 Kris Van Hees <kris.van.hees@oracle.com> + + * cvt.c (type_promotes_to): Support char16_t and char32_t. + * decl.c (grokdeclarator): Disallow signed/unsigned/short/long on + char16_t and char32_t. + * lex.c (reswords): Add char16_t and char32_t (for c++0x). + * mangle.c (write_builtin_type): Mangle char16_t/char32_t as vendor + extended builtin type "u8char{16,32}_t". + * parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Support + RID_CHAR{16,32}. + (cp_lexer_print_token): Support CPP_STRING{16,32}. + (cp_parser_is_string_literal): Idem. + (cp_parser_string_literal): Idem. + (cp_parser_primary_expression): Support CPP_CHAR{16,32} and + CPP_STRING{16,32}. + (cp_parser_simple_type_specifier): Support RID_CHAR{16,32}. + * tree.c (char_type_p): Support char16_t and char32_t as char types. + * typeck.c (string_conv_p): Support char16_t and char32_t. + 2008-04-17 Jason Merrill <jason@redhat.com> PR c++/35773 diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index fe1ed29..b2c17c5 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1219,6 +1219,8 @@ type_promotes_to (tree type) /* Normally convert enums to int, but convert wide enums to something wider. */ else if (TREE_CODE (type) == ENUMERAL_TYPE + || type == char16_type_node + || type == char32_type_node || type == wchar_type_node) { int precision = MAX (TYPE_PRECISION (type), diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 66e8f42..d16cb78 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7732,6 +7732,13 @@ grokdeclarator (const cp_declarator *declarator, error ("%<long%> or %<short%> specified with char for %qs", name); else if (long_p && short_p) error ("%<long%> and %<short%> specified together for %qs", name); + else if (type == char16_type_node || type == char32_type_node) + { + if (signed_p || unsigned_p) + error ("%<signed%> or %<unsigned%> invalid for %qs", name); + else if (short_p || long_p) + error ("%<short%> or %<long%> invalid for %qs", name); + } else { ok = 1; diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 4552305..8484a4b 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -241,6 +241,8 @@ static const struct resword reswords[] = { "case", RID_CASE, 0 }, { "catch", RID_CATCH, 0 }, { "char", RID_CHAR, 0 }, + { "char16_t", RID_CHAR16, D_CXX0X }, + { "char32_t", RID_CHAR32, D_CXX0X }, { "class", RID_CLASS, 0 }, { "const", RID_CONST, 0 }, { "const_cast", RID_CONSTCAST, 0 }, diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 09a34562..5ac5bce 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -1782,10 +1782,14 @@ write_builtin_type (tree type) break; case INTEGER_TYPE: - /* TYPE may still be wchar_t, since that isn't in - integer_type_nodes. */ + /* TYPE may still be wchar_t, char16_t, or char32_t, since that + isn't in integer_type_nodes. */ if (type == wchar_type_node) write_char ('w'); + else if (type == char16_type_node) + write_string ("u8char16_t"); + else if (type == char32_type_node) + write_string ("u8char32_t"); else if (TYPE_FOR_JAVA (type)) write_java_integer_type_codes (type); else diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f57ce28..f2acddb 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -556,6 +556,8 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer) case RID_TYPENAME: /* Simple type specifiers. */ case RID_CHAR: + case RID_CHAR16: + case RID_CHAR32: case RID_WCHAR: case RID_BOOL: case RID_SHORT: @@ -789,6 +791,8 @@ cp_lexer_print_token (FILE * stream, cp_token *token) break; case CPP_STRING: + case CPP_STRING16: + case CPP_STRING32: case CPP_WSTRING: fprintf (stream, " \"%s\"", TREE_STRING_POINTER (token->u.value)); break; @@ -2033,7 +2037,10 @@ cp_parser_parsing_tentatively (cp_parser* parser) static bool cp_parser_is_string_literal (cp_token* token) { - return (token->type == CPP_STRING || token->type == CPP_WSTRING); + return (token->type == CPP_STRING || + token->type == CPP_STRING16 || + token->type == CPP_STRING32 || + token->type == CPP_WSTRING); } /* Returns nonzero if TOKEN is the indicated KEYWORD. */ @@ -2867,11 +2874,11 @@ static tree cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok) { tree value; - bool wide = false; size_t count; struct obstack str_ob; cpp_string str, istr, *strs; cp_token *tok; + enum cpp_ttype type; tok = cp_lexer_peek_token (parser->lexer); if (!cp_parser_is_string_literal (tok)) @@ -2880,6 +2887,8 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok) return error_mark_node; } + type = tok->type; + /* Try to avoid the overhead of creating and destroying an obstack for the common case of just one string. */ if (!cp_parser_is_string_literal @@ -2890,8 +2899,6 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok) str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value); str.len = TREE_STRING_LENGTH (tok->u.value); count = 1; - if (tok->type == CPP_WSTRING) - wide = true; strs = &str; } @@ -2906,8 +2913,14 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok) count++; str.text = (const unsigned char *)TREE_STRING_POINTER (tok->u.value); str.len = TREE_STRING_LENGTH (tok->u.value); - if (tok->type == CPP_WSTRING) - wide = true; + + if (type != tok->type) + { + if (type == CPP_STRING) + type = tok->type; + else if (tok->type != CPP_STRING) + error ("unsupported non-standard concatenation of string literals"); + } obstack_grow (&str_ob, &str, sizeof (cpp_string)); @@ -2918,19 +2931,35 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok) strs = (cpp_string *) obstack_finish (&str_ob); } - if (wide && !wide_ok) + if (type != CPP_STRING && !wide_ok) { cp_parser_error (parser, "a wide string is invalid in this context"); - wide = false; + type = CPP_STRING; } if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate) - (parse_in, strs, count, &istr, wide)) + (parse_in, strs, count, &istr, type)) { value = build_string (istr.len, (const char *)istr.text); free (CONST_CAST (unsigned char *, istr.text)); - TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node; + switch (type) + { + default: + case CPP_STRING: + TREE_TYPE (value) = char_array_type_node; + break; + case CPP_STRING16: + TREE_TYPE (value) = char16_array_type_node; + break; + case CPP_STRING32: + TREE_TYPE (value) = char32_array_type_node; + break; + case CPP_WSTRING: + TREE_TYPE (value) = wchar_array_type_node; + break; + } + value = fix_string_type (value); } else @@ -3085,6 +3114,8 @@ cp_parser_primary_expression (cp_parser *parser, string-literal boolean-literal */ case CPP_CHAR: + case CPP_CHAR16: + case CPP_CHAR32: case CPP_WCHAR: case CPP_NUMBER: token = cp_lexer_consume_token (parser->lexer); @@ -3136,6 +3167,8 @@ cp_parser_primary_expression (cp_parser *parser, return token->u.value; case CPP_STRING: + case CPP_STRING16: + case CPP_STRING32: case CPP_WSTRING: /* ??? Should wide strings be allowed when parser->translate_strings_p is false (i.e. in attributes)? If not, we can kill the third @@ -10762,6 +10795,8 @@ cp_parser_type_specifier (cp_parser* parser, simple-type-specifier: auto decltype ( expression ) + char16_t + char32_t GNU Extension: @@ -10791,6 +10826,12 @@ cp_parser_simple_type_specifier (cp_parser* parser, decl_specs->explicit_char_p = true; type = char_type_node; break; + case RID_CHAR16: + type = char16_type_node; + break; + case RID_CHAR32: + type = char32_type_node; + break; case RID_WCHAR: type = wchar_type_node; break; @@ -17754,13 +17795,16 @@ cp_parser_set_decl_spec_type (cp_decl_specifier_seq *decl_specs, { decl_specs->any_specifiers_p = true; - /* If the user tries to redeclare bool or wchar_t (with, for - example, in "typedef int wchar_t;") we remember that this is what - happened. In system headers, we ignore these declarations so - that G++ can work with system headers that are not C++-safe. */ + /* If the user tries to redeclare bool, char16_t, char32_t, or wchar_t + (with, for example, in "typedef int wchar_t;") we remember that + this is what happened. In system headers, we ignore these + declarations so that G++ can work with system headers that are not + C++-safe. */ if (decl_specs->specs[(int) ds_typedef] && !user_defined_p && (type_spec == boolean_type_node + || type_spec == char16_type_node + || type_spec == char32_type_node || type_spec == wchar_type_node) && (decl_specs->type || decl_specs->specs[(int) ds_long] diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 027f1c9..73adbb5 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2474,6 +2474,8 @@ char_type_p (tree type) return (same_type_p (type, char_type_node) || same_type_p (type, unsigned_char_type_node) || same_type_p (type, signed_char_type_node) + || same_type_p (type, char16_type_node) + || same_type_p (type, char32_type_node) || same_type_p (type, wchar_type_node)); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index de10c0e..9e9d461 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1722,12 +1722,14 @@ string_conv_p (const_tree totype, const_tree exp, int warn) t = TREE_TYPE (totype); if (!same_type_p (t, char_type_node) + && !same_type_p (t, char16_type_node) + && !same_type_p (t, char32_type_node) && !same_type_p (t, wchar_type_node)) return 0; if (TREE_CODE (exp) == STRING_CST) { - /* Make sure that we don't try to convert between char and wchar_t. */ + /* Make sure that we don't try to convert between char and wide chars. */ if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (exp))), t)) return 0; } |