public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc/cp/pt.c: use ngettext() when needed
@ 2010-02-17 15:23 Marco Poletti
  2010-02-17 15:25 ` Marco Poletti
  2010-02-17 17:06 ` Gabriel Dos Reis
  0 siblings, 2 replies; 30+ messages in thread
From: Marco Poletti @ 2010-02-17 15:23 UTC (permalink / raw)
  To: gcc-patches

In the file pt.c, there were translatable strings like "redeclared
with %d template parameter(s)" that are hard to translate.
Instead, it should use the ngettext() function to allow more flexible
translations.
I've added two functions inform_translated() and error_translated() to
diagnostic.c, that are called by pt.c.
This is my second patch to GCC, I could have done something wrong.
Critics are very appreciated.

Changelog for gcc/cp/:
      * pt.c (redeclare_class_template): Use inform_translated and
error_translated

Changelog for gcc/
      * diagnostic.h (inform_translated): Declare.
      (error_translated): Declare.
      * diagnostic.c (inform_translated): New function.
      (error_translated): New function.

Patch:

Index: gcc/diagnostic.c
===================================================================
--- gcc/diagnostic.c	(revisione 156824)
+++ gcc/diagnostic.c	(copia locale)
@@ -519,6 +519,20 @@ inform (location_t location, const char
   va_end (ap);
 }

+/* An informative note at LOCATION.  Use this for additional details
on an error
+   message. The message is already translated.  */
+void
+inform_translated (location_t location, const char *gmsgid, ...)
+{
+  diagnostic_info diagnostic;
+  va_list ap;
+
+  va_start (ap, gmsgid);
+  diagnostic_set_info_translated (&diagnostic, gmsgid, &ap, location, DK_NOTE);
+  report_diagnostic (&diagnostic);
+  va_end (ap);
+}
+
 /* A warning at INPUT_LOCATION.  Use this for code which is correct according
    to the relevant language specification but is likely to be buggy anyway.
    Returns true if the warning was printed, false if it was inhibited.  */
@@ -613,6 +627,21 @@ error (const char *gmsgid, ...)
   report_diagnostic (&diagnostic);
   va_end (ap);
 }
+
+/* A hard error: the code is definitely ill-formed, and an object file
+   will not be produced. The message is already translated.  */
+void
+error_translated (const char *gmsgid, ...)
+{
+  diagnostic_info diagnostic;
+  va_list ap;
+
+  va_start (ap, gmsgid);
+  diagnostic_set_info_translated (&diagnostic, gmsgid, &ap, input_location,
+                                  DK_ERROR);
+  report_diagnostic (&diagnostic);
+  va_end (ap);
+}

 /* Same as ebove, but use location LOC instead of input_location.  */
 void
Index: gcc/toplev.h
===================================================================
--- gcc/toplev.h	(revisione 156824)
+++ gcc/toplev.h	(copia locale)
@@ -63,6 +63,7 @@ extern bool warning (int, const char *,
 extern bool warning_at (location_t, int, const char *, ...)
     ATTRIBUTE_GCC_DIAG(3,4);
 extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void error_translated (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
      ATTRIBUTE_NORETURN;
@@ -72,6 +73,8 @@ extern bool pedwarn (location_t, int, co
 extern bool permerror (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
+extern void inform_translated (location_t, const char *, ...)
+ATTRIBUTE_GCC_DIAG(2,3);
 extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);

 extern void rest_of_decl_compilation (tree, int, int);
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revisione 156824)
+++ gcc/cp/pt.c	(copia locale)
@@ -4614,10 +4614,15 @@ redeclare_class_template (tree type, tre

   if (TREE_VEC_LENGTH (parms) != TREE_VEC_LENGTH (tmpl_parms))
     {
-      error ("redeclared with %d template parameter(s)",
-             TREE_VEC_LENGTH (parms));
-      inform (input_location, "previous declaration %q+D used %d
template parameter(s)",
-             tmpl, TREE_VEC_LENGTH (tmpl_parms));
+      error_translated (ngettext ("redeclared with %d template parameter",
+                                  "redeclared with %d template parameters",
+                                  TREE_VEC_LENGTH (parms)),
+                        TREE_VEC_LENGTH (parms));
+      inform_translated (input_location,
+                         ngettext("previous declaration %q+D used %d
template parameter",
+                                  "previous declaration %q+D used %d
template parameters",
+                                  TREE_VEC_LENGTH (tmpl_parms)),
+                         tmpl, TREE_VEC_LENGTH (tmpl_parms));
       return false;
     }

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2010-03-01 15:12 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-17 15:23 gcc/cp/pt.c: use ngettext() when needed Marco Poletti
2010-02-17 15:25 ` Marco Poletti
2010-02-17 17:06 ` Gabriel Dos Reis
2010-02-17 18:02   ` Marco Poletti
2010-02-17 18:29   ` Paolo Bonzini
2010-02-17 20:07     ` Marco Poletti
2010-02-17 21:26     ` Joseph S. Myers
2010-02-17 21:32       ` Marco Poletti
2010-02-17 23:23         ` Paolo Bonzini
2010-02-18 14:33           ` Marco Poletti
2010-02-18 14:40             ` Jakub Jelinek
2010-02-18 14:49               ` Marco Poletti
2010-02-22  9:38                 ` Marco Poletti
2010-02-24  6:47                   ` Shujing Zhao
2010-02-24  6:57                     ` Paolo Bonzini
2010-02-24  8:55                       ` Shujing Zhao
2010-02-24 10:22                         ` Paolo Bonzini
2010-02-26  7:30                     ` Gabriel Dos Reis
2010-02-26  7:31                       ` Marco Poletti
2010-02-26  9:32                         ` Gabriel Dos Reis
2010-02-26  9:43                           ` Paolo Bonzini
2010-02-26  9:56                             ` Gabriel Dos Reis
2010-02-26 10:03                               ` Jakub Jelinek
2010-02-26 10:04                                 ` Gabriel Dos Reis
2010-02-26 10:09                                   ` Shujing Zhao
2010-02-26 10:42                                     ` Paolo Bonzini
2010-02-26 10:43                                       ` Jakub Jelinek
2010-03-01 10:00                                         ` Shujing Zhao
2010-03-01 10:16                                           ` Shujing Zhao
2010-03-01 15:12                                             ` Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).