From a608187fcbe47b23b3a69b928505802f08950e23 Mon Sep 17 00:00:00 2001 From: jsm28 Date: Sun, 10 May 2009 10:28:34 +0000 Subject: [PATCH] * pretty-print.h (struct pretty_print_info): Add translate_identifiers. (pp_translate_identifiers): New. (pp_identifier): Only conditionally translate identifier to locale character set. * pretty-print.c (pp_construct): Set pp_translate_identifiers. (pp_base_tree_identifier): Only conditionally translate identifier to locale character set. * c-pretty-print.c (M_): Define. (pp_c_type_specifier, pp_c_primary_expression): Mark English fragments for conditional translation with M_. * tree-pretty-print.c (maybe_init_pretty_print): Disable identifier translation. cp: * call.c (name_as_c_string): Call type_as_string_translate. Translate identifiers to locale character set. * cp-tree.h (lang_decl_name): Update prototype. (type_as_string_translate, decl_as_string_translate, cxx_printable_name_translate): Declare. * cxx-pretty-print.c (M_): Define. (pp_cxx_unqualified_id, pp_cxx_canonical_template_parameter): Mark English fragments for conditional translation with M_. * decl.c (grokdeclarator): Translate identifiers to locale character set for diagnostics. * error.c (M_): Define. (dump_template_bindings, dump_type, dump_aggr_type, dump_type_prefix, dump_global_iord, dump_simple_decl, dump_decl, dump_function_decl, dump_template_parms, dump_expr, dump_binary_op, op_to_string, assop_to_string): Mark English fragments for conditional translation with M_. (type_as_string): Disable translation of identifiers. (type_as_string_translate): New. (expr_as_string): Disable translation of identifiers. (decl_as_string): Disable translation of identifiers. (decl_as_string_translate): New. (lang_decl_name): Add parameter translate. (args_to_string): Call type_as_string_translate. (cp_print_error_function): Call cxx_printable_name_translate. (print_instantiation_full_context, print_instantiation_partial_context): Call decl_as_string_translate. * parser.c (cp_lexer_get_preprocessor_token): Use %qE for identifier in diagnostic. * tree.c (cxx_printable_name): Change to cxx_printable_name_internal. Add parameter translate. (cxx_printable_name, cxx_printable_name_translate): New wrappers round cxx_printable_name_internal. objc: * objc-act.c: Include intl.h. (objc_lookup_protocol): Use complete sentences for diagnostics with %qE for identifiers and translating results of gen_type_name_0 to locale character set. (objc_check_decl, check_protocol_recursively, lookup_and_install_protocols, objc_build_string_object, objc_get_class_reference, objc_declare_alias, objc_declare_class, objc_get_class_ivars, error_with_ivar, check_duplicates, objc_finish_message_expr, objc_build_protocol_expr, objc_build_selector_expr, build_ivar_reference, objc_add_method, add_category, add_instance_variable, objc_is_public, check_methods, check_methods_accessible, check_protocol, start_class, finish_class, start_protocol, really_start_method, get_super_receiver, objc_lookup_ivar): Use %E and %qE for identifiers in diagnostics. Translate generated text to locale character set as needed. (check_protocol, check_protocols): Change name parameter to type tree. (lang_report_error_function): Remove. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@147333 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 16 +++ gcc/c-pretty-print.c | 24 +++-- gcc/cp/ChangeLog | 36 +++++++ gcc/cp/call.c | 8 +- gcc/cp/cp-tree.h | 5 +- gcc/cp/cxx-pretty-print.c | 10 +- gcc/cp/decl.c | 8 +- gcc/cp/error.c | 100 +++++++++++------- gcc/cp/parser.c | 4 +- gcc/cp/tree.c | 24 ++++- gcc/objc/ChangeLog | 22 ++++ gcc/objc/objc-act.c | 263 ++++++++++++++++++++++------------------------ gcc/pretty-print.c | 11 +- gcc/pretty-print.h | 12 ++- gcc/tree-pretty-print.c | 1 + 15 files changed, 335 insertions(+), 209 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0752599ece0..c2e3f12bd65 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2009-05-10 Joseph Myers + + * pretty-print.h (struct pretty_print_info): Add + translate_identifiers. + (pp_translate_identifiers): New. + (pp_identifier): Only conditionally translate identifier to locale + character set. + * pretty-print.c (pp_construct): Set pp_translate_identifiers. + (pp_base_tree_identifier): Only conditionally translate identifier + to locale character set. + * c-pretty-print.c (M_): Define. + (pp_c_type_specifier, pp_c_primary_expression): Mark English + fragments for conditional translation with M_. + * tree-pretty-print.c (maybe_init_pretty_print): Disable + identifier translation. + 2009-05-10 Richard Guenther PR tree-optimization/40081 diff --git a/gcc/c-pretty-print.c b/gcc/c-pretty-print.c index efd15ac9b26..f9694bfc080 100644 --- a/gcc/c-pretty-print.c +++ b/gcc/c-pretty-print.c @@ -31,6 +31,10 @@ along with GCC; see the file COPYING3. If not see #include "tree-iterator.h" #include "diagnostic.h" +/* Translate if being used for diagnostics, but not for dump files or + __PRETTY_FUNCTION. */ +#define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid)) + /* The pretty-printer code is primarily designed to closely follow (GNU) C and C++ grammars. That is to be contrasted with spaghetti codes we used to have in the past. Following a structured @@ -307,7 +311,7 @@ pp_c_type_specifier (c_pretty_printer *pp, tree t) switch (code) { case ERROR_MARK: - pp_c_ws_string (pp, _("")); + pp_c_ws_string (pp, M_("")); break; case IDENTIFIER_NODE: @@ -346,14 +350,14 @@ pp_c_type_specifier (c_pretty_printer *pp, tree t) { case INTEGER_TYPE: pp_string (pp, (TYPE_UNSIGNED (t) - ? _("")); + pp_c_ws_string (pp, M_("")); break; case UNION_TYPE: @@ -381,12 +385,12 @@ pp_c_type_specifier (c_pretty_printer *pp, tree t) else if (code == ENUMERAL_TYPE) pp_c_ws_string (pp, "enum"); else - pp_c_ws_string (pp, _("")); + pp_c_ws_string (pp, M_("")); if (TYPE_NAME (t)) pp_id_expression (pp, TYPE_NAME (t)); else - pp_c_ws_string (pp, _("")); + pp_c_ws_string (pp, M_("")); break; default: @@ -1119,11 +1123,11 @@ pp_c_primary_expression (c_pretty_printer *pp, tree e) break; case ERROR_MARK: - pp_c_ws_string (pp, _("")); + pp_c_ws_string (pp, M_("")); break; case RESULT_DECL: - pp_c_ws_string (pp, _("")); + pp_c_ws_string (pp, M_("")); break; case INTEGER_CST: diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cc7b5f77848..8117f22dccb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,39 @@ +2009-05-10 Joseph Myers + + * call.c (name_as_c_string): Call type_as_string_translate. + Translate identifiers to locale character set. + * cp-tree.h (lang_decl_name): Update prototype. + (type_as_string_translate, decl_as_string_translate, + cxx_printable_name_translate): Declare. + * cxx-pretty-print.c (M_): Define. + (pp_cxx_unqualified_id, pp_cxx_canonical_template_parameter): Mark + English fragments for conditional translation with M_. + * decl.c (grokdeclarator): Translate identifiers to locale + character set for diagnostics. + * error.c (M_): Define. + (dump_template_bindings, dump_type, dump_aggr_type, + dump_type_prefix, dump_global_iord, dump_simple_decl, dump_decl, + dump_function_decl, dump_template_parms, dump_expr, + dump_binary_op, op_to_string, assop_to_string): Mark English + fragments for conditional translation with M_. + (type_as_string): Disable translation of identifiers. + (type_as_string_translate): New. + (expr_as_string): Disable translation of identifiers. + (decl_as_string): Disable translation of identifiers. + (decl_as_string_translate): New. + (lang_decl_name): Add parameter translate. + (args_to_string): Call type_as_string_translate. + (cp_print_error_function): Call cxx_printable_name_translate. + (print_instantiation_full_context, + print_instantiation_partial_context): Call + decl_as_string_translate. + * parser.c (cp_lexer_get_preprocessor_token): Use %qE for + identifier in diagnostic. + * tree.c (cxx_printable_name): Change to + cxx_printable_name_internal. Add parameter translate. + (cxx_printable_name, cxx_printable_name_translate): New wrappers + round cxx_printable_name_internal. + 2009-05-08 H.J. Lu PR c/36892 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index ba8dac153a3..ee13ba2a414 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5731,7 +5731,7 @@ name_as_c_string (tree name, tree type, bool *free_p) if (IDENTIFIER_CTOR_OR_DTOR_P (name)) { pretty_name - = CONST_CAST (char *, IDENTIFIER_POINTER (constructor_name (type))); + = CONST_CAST (char *, identifier_to_locale (IDENTIFIER_POINTER (constructor_name (type)))); /* For a destructor, add the '~'. */ if (name == complete_dtor_identifier || name == base_dtor_identifier @@ -5745,14 +5745,14 @@ name_as_c_string (tree name, tree type, bool *free_p) else if (IDENTIFIER_TYPENAME_P (name)) { pretty_name = concat ("operator ", - type_as_string (TREE_TYPE (name), - TFF_PLAIN_IDENTIFIER), + type_as_string_translate (TREE_TYPE (name), + TFF_PLAIN_IDENTIFIER), NULL); /* Remember that we need to free the memory allocated. */ *free_p = true; } else - pretty_name = CONST_CAST (char *, IDENTIFIER_POINTER (name)); + pretty_name = CONST_CAST (char *, identifier_to_locale (IDENTIFIER_POINTER (name))); return pretty_name; } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ae93e66366a..0ea2d8623f6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4422,9 +4422,11 @@ extern int parm_index (tree); /* in error.c */ extern void init_error (void); extern const char *type_as_string (tree, int); +extern const char *type_as_string_translate (tree, int); extern const char *decl_as_string (tree, int); +extern const char *decl_as_string_translate (tree, int); extern const char *expr_as_string (tree, int); -extern const char *lang_decl_name (tree, int); +extern const char *lang_decl_name (tree, int, bool); extern const char *language_to_string (enum languages); extern const char *class_key_or_enum_as_string (tree); extern void print_instantiation_context (void); @@ -4839,6 +4841,7 @@ extern tree get_first_fn (tree); extern tree ovl_cons (tree, tree); extern tree build_overload (tree, tree); extern const char *cxx_printable_name (tree, int); +extern const char *cxx_printable_name_translate (tree, int); extern tree build_exception_variant (tree, tree); extern tree bind_template_template_parm (tree, tree); extern tree array_type_nelts_total (tree); diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index 2edffd37548..b8732896aa4 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -29,6 +29,10 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "toplev.h" +/* Translate if being used for diagnostics, but not for dump files or + __PRETTY_FUNCTION. */ +#define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid)) + static void pp_cxx_unqualified_id (cxx_pretty_printer *, tree); static void pp_cxx_nested_name_specifier (cxx_pretty_printer *, tree); static void pp_cxx_qualified_id (cxx_pretty_printer *, tree); @@ -147,7 +151,7 @@ pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t) switch (code) { case RESULT_DECL: - pp_cxx_ws_string (pp, _("")); + pp_cxx_ws_string (pp, M_("")); break; case OVERLOAD: @@ -166,7 +170,7 @@ pp_cxx_unqualified_id (cxx_pretty_printer *pp, tree t) case IDENTIFIER_NODE: if (t == NULL) - pp_cxx_ws_string (pp, _("")); + pp_cxx_ws_string (pp, M_("")); else if (IDENTIFIER_TYPENAME_P (t)) pp_cxx_conversion_function_id (pp, t); else @@ -2048,7 +2052,7 @@ pp_cxx_canonical_template_parameter (cxx_pretty_printer *pp, tree parm) parm = TEMPLATE_TYPE_PARM_INDEX (parm); pp_cxx_begin_template_argument_list (pp); - pp_cxx_ws_string (pp, _("template-parameter-")); + pp_cxx_ws_string (pp, M_("template-parameter-")); pp_wide_integer (pp, TEMPLATE_PARM_LEVEL (parm)); pp_minus (pp); pp_wide_integer (pp, TEMPLATE_PARM_IDX (parm) + 1); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index fb916476b35..fd944f713db 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7701,7 +7701,7 @@ grokdeclarator (const cp_declarator *declarator, type = TREE_OPERAND (decl, 0); if (TYPE_P (type)) type = constructor_name (type); - name = IDENTIFIER_POINTER (type); + name = identifier_to_locale (IDENTIFIER_POINTER (type)); dname = decl; } break; @@ -7727,10 +7727,10 @@ grokdeclarator (const cp_declarator *declarator, { error ("declarator-id missing; using reserved word %qD", dname); - name = IDENTIFIER_POINTER (dname); + name = identifier_to_locale (IDENTIFIER_POINTER (dname)); } else if (!IDENTIFIER_TYPENAME_P (dname)) - name = IDENTIFIER_POINTER (dname); + name = identifier_to_locale (IDENTIFIER_POINTER (dname)); else { gcc_assert (flags == NO_SPECIAL); @@ -7738,7 +7738,7 @@ grokdeclarator (const cp_declarator *declarator, ctor_return_type = TREE_TYPE (dname); sfk = sfk_conversion; if (is_typename_at_global_scope (dname)) - name = IDENTIFIER_POINTER (dname); + name = identifier_to_locale (IDENTIFIER_POINTER (dname)); else name = ""; } diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 13b32ad1850..3c7a8d5c58e 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -41,6 +41,10 @@ along with GCC; see the file COPYING3. If not see static cxx_pretty_printer scratch_pretty_printer; #define cxx_pp (&scratch_pretty_printer) +/* Translate if being used for diagnostics, but not for dump files or + __PRETTY_FUNCTION. */ +#define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid)) + # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T))) static const char *args_to_string (tree, int); @@ -298,7 +302,7 @@ dump_template_bindings (tree parms, tree args, VEC(tree,gc)* typenames) if (arg) dump_template_argument (arg, TFF_PLAIN_IDENTIFIER); else - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); ++arg_idx; need_comma = 1; @@ -339,9 +343,9 @@ dump_type (tree t, int flags) { case UNKNOWN_TYPE: if (t == init_list_type_node) - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); else - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); break; case TREE_LIST: @@ -481,7 +485,7 @@ dump_type (tree t, int flags) /* Fall through to error. */ case ERROR_MARK: - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); break; } } @@ -578,9 +582,9 @@ dump_aggr_type (tree t, int flags) if (name == 0 || ANON_AGGRNAME_P (name)) { if (flags & TFF_CLASS_KEY_OR_ENUM) - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); else - pp_printf (pp_base (cxx_pp), _(""), variety); + pp_printf (pp_base (cxx_pp), M_(""), variety); } else pp_cxx_tree_identifier (cxx_pp, name); @@ -702,7 +706,7 @@ dump_type_prefix (tree t, int flags) pp_unsupported_tree (cxx_pp, t); /* fall through. */ case ERROR_MARK: - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); break; } } @@ -812,9 +816,9 @@ dump_global_iord (tree t) const char *p = NULL; if (DECL_GLOBAL_CTOR_P (t)) - p = _("(static initializers for %s)"); + p = M_("(static initializers for %s)"); else if (DECL_GLOBAL_DTOR_P (t)) - p = _("(static destructors for %s)"); + p = M_("(static destructors for %s)"); else gcc_unreachable (); @@ -841,7 +845,7 @@ dump_simple_decl (tree t, tree type, int flags) if (DECL_NAME (t)) dump_decl (DECL_NAME (t), flags); else - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); if (flags & TFF_DECL_SPECIFIERS) dump_type_suffix (type, flags); } @@ -884,7 +888,7 @@ dump_decl (tree t, int flags) case VAR_DECL: if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t))) { - pp_string (cxx_pp, _("vtable for ")); + pp_string (cxx_pp, M_("vtable for ")); gcc_assert (TYPE_P (DECL_CONTEXT (t))); dump_type (DECL_CONTEXT (t), flags); break; @@ -896,7 +900,7 @@ dump_decl (tree t, int flags) break; case RESULT_DECL: - pp_string (cxx_pp, _(" ")); + pp_string (cxx_pp, M_(" ")); dump_simple_decl (t, TREE_TYPE (t), flags); break; @@ -909,7 +913,7 @@ dump_decl (tree t, int flags) dump_scope (CP_DECL_CONTEXT (t), flags); flags &= ~TFF_UNQUALIFIED_NAME; if (DECL_NAME (t) == NULL_TREE) - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); else pp_cxx_tree_identifier (cxx_pp, DECL_NAME (t)); } @@ -983,7 +987,7 @@ dump_decl (tree t, int flags) case FUNCTION_DECL: if (! DECL_LANG_SPECIFIC (t)) - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); else if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t)) dump_global_iord (t); else @@ -1022,7 +1026,7 @@ dump_decl (tree t, int flags) else if (DECL_INITIAL (t)) dump_expr (DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS); else - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); break; case USING_DECL: @@ -1062,7 +1066,7 @@ dump_decl (tree t, int flags) /* Fall through to error. */ case ERROR_MARK: - pp_string (cxx_pp, _("")); + pp_string (cxx_pp, M_("")); break; } } @@ -1292,7 +1296,7 @@ dump_function_decl (tree t, int flags) { pp_cxx_whitespace (cxx_pp); pp_cxx_left_bracket (cxx_pp); - pp_cxx_ws_string (cxx_pp, _("with")); + pp_cxx_ws_string (cxx_pp, M_("with")); pp_cxx_whitespace (cxx_pp); dump_template_bindings (template_parms, template_args, typenames); pp_cxx_right_bracket (cxx_pp); @@ -1457,7 +1461,7 @@ dump_template_parms (tree info, int primary, int flags) pp_separate_with_comma (cxx_pp); if (!arg) - pp_string (cxx_pp, _("