OSDN Git Service

* pretty-print.c (pp_base_format_text): Support %< instead of %`
[pf3gnuchains/gcc-fork.git] / gcc / pretty-print.c
index 9d0ed01..f5a1a77 100644 (file)
@@ -1,5 +1,5 @@
 /* Various declarations for language-independent pretty-print subroutines.
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
 
 This file is part of GCC.
@@ -24,6 +24,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #undef FFS  /* Some systems define this in param.h.  */
 #include "system.h"
 #include "coretypes.h"
+#include "intl.h"
 #include "pretty-print.h"
 
 #define obstack_chunk_alloc xmalloc
@@ -90,21 +91,8 @@ pp_clear_state (pretty_printer *pp)
   pp_indentation (pp) = 0;
 }
 
-/* Insert enough spaces into the output area of PRETTY-PRINTER to bring
-   the column position to the current indentation level, assuming that a
-   newline has just been written to the buffer.  */
-static void
-pp_indent (pretty_printer *pp)
-{
-  int n = pp_indentation (pp);
-  int i;
-
-  for (i = 0; i < n; ++i)
-    pp_space (pp);
-}
-
 /* Flush the formatted text of PRETTY-PRINTER onto the attached stream.  */
-static inline void
+void
 pp_write_text_to_stream (pretty_printer *pp)
 {
   const char *text = pp_formatted_text (pp);
@@ -164,6 +152,19 @@ pp_append_r (pretty_printer *pp, const char *start, int length)
   pp->buffer->line_length += length;
 }
 
+/* Insert enough spaces into the output area of PRETTY-PRINTER to bring
+   the column position to the current indentation level, assuming that a
+   newline has just been written to the buffer.  */
+void
+pp_base_indent (pretty_printer *pp)
+{
+  int n = pp_indentation (pp);
+  int i;
+
+  for (i = 0; i < n; ++i)
+    pp_space (pp);
+}
+
 /* Format a message pointed to by TEXT.  The following format specifiers are
    recognized as being client independent:
    %d, %i: (signed) integer in base ten.
@@ -177,9 +178,14 @@ pp_append_r (pretty_printer *pp, const char *start, int length)
    %s: string.
    %p: pointer.
    %m: strerror(text->err_no) - does not consume a value from args_ptr.
-   %%: `%'.
-   %*.s: a substring the length of which is specified by an integer.
-   %H: location_t.  */
+   %%: '%'.
+   %<: opening quote.
+   %>: closing quote.
+   %': apostrophe (should only be used in untranslated messages;
+       translations should use appropriate punctuation directly).
+   %.*s: a substring the length of which is specified by an integer.
+   %H: location_t.
+   Flag 'q': quote formatted text (must come immediately after '%').  */
 void
 pp_base_format_text (pretty_printer *pp, text_info *text)
 {
@@ -187,6 +193,7 @@ pp_base_format_text (pretty_printer *pp, text_info *text)
     {
       int precision = 0;
       bool wide = false;
+      bool quoted = false;
 
       /* Ignore text.  */
       {
@@ -200,8 +207,14 @@ pp_base_format_text (pretty_printer *pp, text_info *text)
       if (*text->format_spec == '\0')
        break;
 
-      /* We got a '%'.  Parse precision modifiers, if any.  */
-      switch (*++text->format_spec)
+      /* We got a '%'.  Check for 'q', then parse precision modifiers,
+        if any.  */
+      if (*++text->format_spec == 'q')
+       {
+         quoted = true;
+         ++text->format_spec;
+       }
+      switch (*text->format_spec)
         {
         case 'w':
           wide = true;
@@ -217,10 +230,12 @@ pp_base_format_text (pretty_printer *pp, text_info *text)
         default:
           break;
         }
-      /* We don't support precision behond that of "long long".  */
+      /* We don't support precision beyond that of "long long".  */
       if (precision > 2)
         abort();
 
+      if (quoted)
+       pp_string (pp, open_quote);
       switch (*text->format_spec)
        {
        case 'c':
@@ -279,6 +294,15 @@ pp_base_format_text (pretty_printer *pp, text_info *text)
          pp_character (pp, '%');
          break;
 
+       case '<':
+         pp_string (pp, open_quote);
+         break;
+
+       case '>':
+       case '\'':
+         pp_string (pp, close_quote);
+         break;
+
         case 'H':
           {
             const location_t *locus = va_arg (*text->args_ptr, location_t *);
@@ -293,7 +317,7 @@ pp_base_format_text (pretty_printer *pp, text_info *text)
          {
            int n;
            const char *s;
-           /* We handle no precision specifier but `%.*s'.  */
+           /* We handle no precision specifier but '%.*s'.  */
            if (*++text->format_spec != '*')
              abort ();
            else if (*++text->format_spec != 's')
@@ -314,6 +338,8 @@ pp_base_format_text (pretty_printer *pp, text_info *text)
              abort ();
            }
        }
+      if (quoted)
+       pp_string (pp, close_quote);
     }
 }
 
@@ -343,6 +369,7 @@ pp_base_flush (pretty_printer *pp)
   pp_clear_state (pp);
   fputc ('\n', pp->buffer->stream);
   fflush (pp->buffer->stream);
+  pp_needs_newline (pp) = false;
 }
 
 /* Sets the number of maximum characters per line PRETTY-PRINTER can
@@ -399,7 +426,7 @@ pp_base_emit_prefix (pretty_printer *pp)
        case DIAGNOSTICS_SHOW_PREFIX_ONCE:
          if (pp->emitted_prefix)
            {
-             pp_indent (pp);
+             pp_base_indent (pp);
              break;
            }
          pp_indentation (pp) += 3;
@@ -422,7 +449,7 @@ void
 pp_construct (pretty_printer *pp, const char *prefix, int maximum_length)
 {
   memset (pp, 0, sizeof (pretty_printer));
-  pp->buffer = xmalloc (sizeof (output_buffer));
+  pp->buffer = xcalloc (1, sizeof (output_buffer));
   obstack_init (&pp->buffer->obstack);
   pp->buffer->stream = stderr;
   pp_line_cutoff (pp) = maximum_length;
@@ -472,7 +499,7 @@ pp_base_last_position_in_text (const pretty_printer *pp)
 }
 
 /* Return the amount of characters PRETTY-PRINTER can accept to
-   make a full line.  Meaningfull only in line-wrapping mode.  */
+   make a full line.  Meaningful only in line-wrapping mode.  */
 int
 pp_base_remaining_character_count_for_line (pretty_printer *pp)
 {
@@ -544,4 +571,14 @@ pp_base_string (pretty_printer *pp, const char *str)
   pp_maybe_wrap_text (pp, str, str + (str ? strlen (str) : 0));
 }
 
+/* Maybe print out a whitespace if needed.   */
 
+void
+pp_base_maybe_space (pretty_printer *pp)
+{
+  if (pp_base (pp)->padding != pp_none)
+    {
+      pp_space (pp);
+      pp_base (pp)->padding = pp_none;
+    }
+}