X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fpretty-print.c;h=f20a8dee637fbbb2f24ec9f9ddc373c3eaefa90f;hb=576aff9d272cd8ebec2b93b10dcf5eae125e9667;hp=86d4cb82e6b761ab3e90b5b2327e609c0167bd30;hpb=292fdb55aabf6c648010a9d35041181da2cb5905;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c index 86d4cb82e6b..f20a8dee637 100644 --- a/gcc/pretty-print.c +++ b/gcc/pretty-print.c @@ -1,5 +1,5 @@ /* Various declarations for language-independent pretty-print subroutines. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis This file is part of GCC. @@ -24,7 +24,9 @@ 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" +#include "tree.h" #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free @@ -91,7 +93,7 @@ pp_clear_state (pretty_printer *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 +166,40 @@ pp_base_indent (pretty_printer *pp) pp_space (pp); } +/* Prepare PP to format a message pointed to by TEXT, with tentative + location LOCUS. It is expected that a call to pp_format_text with + exactly the same PP and TEXT arguments will follow. This routine + may modify the data in memory at TEXT and LOCP, and if it does, + caller is expected to notice. + + Currently, all this does is notice a %H or %J escape at the beginning + of the string, and update LOCUS to match. */ +void +pp_base_prepare_to_format (pretty_printer *pp ATTRIBUTE_UNUSED, + text_info *text, + location_t *locus) +{ + const char *p = text->format_spec; + tree t; + + /* Extract the location information if any. */ + if (p[0] == '%') + switch (p[1]) + { + case 'H': + *locus = *va_arg (*text->args_ptr, location_t *); + text->format_spec = p + 2; + break; + + case 'J': + t = va_arg (*text->args_ptr, tree); + *locus = DECL_SOURCE_LOCATION (t); + text->format_spec = p + 2; + break; + } +} + + /* 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 +213,14 @@ pp_base_indent (pretty_printer *pp) %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 +228,7 @@ pp_base_format_text (pretty_printer *pp, text_info *text) { int precision = 0; bool wide = false; + bool quoted = false; /* Ignore text. */ { @@ -200,8 +242,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; @@ -218,9 +266,10 @@ pp_base_format_text (pretty_printer *pp, text_info *text) break; } /* We don't support precision beyond that of "long long". */ - if (precision > 2) - abort(); + gcc_assert (precision <= 2); + if (quoted) + pp_string (pp, open_quote); switch (*text->format_spec) { case 'c': @@ -279,13 +328,23 @@ 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 *); + location_t *locus = va_arg (*text->args_ptr, location_t *); + expanded_location s = expand_location (*locus); pp_string (pp, "file '"); - pp_string (pp, locus->file); + pp_string (pp, s.file); pp_string (pp, "', line "); - pp_decimal_int (pp, locus->line); + pp_decimal_int (pp, s.line); } break; @@ -293,11 +352,12 @@ pp_base_format_text (pretty_printer *pp, text_info *text) { int n; const char *s; - /* We handle no precision specifier but `%.*s'. */ - if (*++text->format_spec != '*') - abort (); - else if (*++text->format_spec != 's') - abort (); + /* We handle no precision specifier but '%.*s'. */ + ++text->format_spec; + gcc_assert (*text->format_spec == '*'); + ++text->format_spec; + gcc_assert (*text->format_spec == 's'); + n = va_arg (*text->args_ptr, int); s = va_arg (*text->args_ptr, const char *); pp_append_text (pp, s, s + n); @@ -305,15 +365,16 @@ pp_base_format_text (pretty_printer *pp, text_info *text) break; default: - if (!pp_format_decoder (pp) || !(*pp_format_decoder (pp)) (pp, text)) - { - /* Hmmm. The client failed to install a format translator - but called us with an unrecognized format. Or, maybe, the - translated string just contains an invalid format, or - has formats in the wrong order. Sorry. */ - abort (); - } + { + bool ok; + + gcc_assert (pp_format_decoder (pp)); + ok = pp_format_decoder (pp) (pp, text); + gcc_assert (ok); + } } + if (quoted) + pp_string (pp, close_quote); } } @@ -545,7 +606,7 @@ 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. */ +/* Maybe print out a whitespace if needed. */ void pp_base_maybe_space (pretty_printer *pp)