/* Various declarations for language-independent pretty-print subroutines.
- Copyright (C) 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
This file is part of GCC.
<http://www.gnu.org/licenses/>. */
#include "config.h"
-#undef FLOAT /* This is for hpux. They should change hpux. */
-#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"
-#include "ggc.h"
#if HAVE_ICONV
#include <iconv.h>
#endif
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
-
/* A pointer to the formatted diagnostic message. */
#define pp_formatted_text_data(PP) \
((const char *) obstack_base (pp_base (PP)->buffer->obstack))
%.*s: a substring the length of which is specified by an argument
integer.
%Ns: likewise, but length specified as constant in the format string.
- %H: location_t.
- %J: a decl tree, from which DECL_SOURCE_LOCATION will be recorded.
- %K: a statement, from which EXPR_LOCATION and TREE_BLOCK will be recorded.
Flag 'q': quote formatted text (must come immediately after '%').
Arguments can be used sequentially, or through %N$ resp. *N$
this point. */
memset (formatters, 0, sizeof formatters);
-
+
for (p = text->format_spec; *p; )
{
while (*p != '\0' && *p != '%')
{
case '\0':
gcc_unreachable ();
-
+
case '%':
obstack_1grow (&buffer->chunk_obstack, '%');
p++;
gcc_assert (chunk < PP_NL_ARGMAX * 2);
args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
args[chunk] = 0;
-
+
/* Set output to the argument obstack, and switch line-wrapping and
prefixing off. */
buffer->obstack = &buffer->chunk_obstack;
(pp, *text->args_ptr, precision, unsigned, "x");
break;
- case 'H':
- {
- location_t *locus = va_arg (*text->args_ptr, location_t *);
- gcc_assert (text->locus != NULL);
- *text->locus = *locus;
- }
- break;
-
- case 'J':
- {
- tree t = va_arg (*text->args_ptr, tree);
- gcc_assert (text->locus != NULL);
- *text->locus = DECL_SOURCE_LOCATION (t);
- }
- break;
-
- case 'K':
- {
- tree t = va_arg (*text->args_ptr, tree), block;
- gcc_assert (text->locus != NULL);
- *text->locus = EXPR_LOCATION (t);
- gcc_assert (text->abstract_origin != NULL);
- block = TREE_BLOCK (t);
- *text->abstract_origin = NULL;
- while (block
- && TREE_CODE (block) == BLOCK
- && BLOCK_ABSTRACT_ORIGIN (block))
- {
- tree ao = BLOCK_ABSTRACT_ORIGIN (block);
-
- while (TREE_CODE (ao) == BLOCK
- && BLOCK_ABSTRACT_ORIGIN (ao)
- && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
- ao = BLOCK_ABSTRACT_ORIGIN (ao);
-
- if (TREE_CODE (ao) == FUNCTION_DECL)
- {
- *text->abstract_origin = block;
- break;
- }
- block = BLOCK_SUPERCONTEXT (block);
- }
- }
- break;
-
case '.':
{
int n;
pp_line_cutoff (pp) = maximum_length;
pp_prefixing_rule (pp) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
pp_set_prefix (pp, prefix);
+ pp_translate_identifiers (pp) = true;
}
/* Append a string delimited by START and END to the output area of
pp_base (pp)->padding = pp_none;
}
}
-
-/* Print the identifier ID to PRETTY-PRINTER. */
-
-void
-pp_base_tree_identifier (pretty_printer *pp, tree id)
-{
- const char *text = identifier_to_locale (IDENTIFIER_POINTER (id));
- pp_append_text (pp, text, text + strlen (text));
-}
\f
/* The string starting at P has LEN (at least 1) bytes left; if they
start with a valid UTF-8 sequence, return the length of that
}
}
+/* Allocator for identifier_to_locale and corresponding function to
+ free memory. */
+
+void *(*identifier_to_locale_alloc) (size_t) = xmalloc;
+void (*identifier_to_locale_free) (void *) = free;
+
/* Given IDENT, an identifier in the internal encoding, return a
version of IDENT suitable for diagnostics in the locale character
- set: either IDENT itself, or a garbage-collected string converted
- to the locale character set and using escape sequences if not
- representable in the locale character set or containing control
- characters or invalid byte sequences. Existing backslashes in
- IDENT are not doubled, so the result may not uniquely specify the
- contents of an arbitrary byte sequence identifier. */
+ set: either IDENT itself, or a string, allocated using
+ identifier_to_locale_alloc, converted to the locale character set
+ and using escape sequences if not representable in the locale
+ character set or containing control characters or invalid byte
+ sequences. Existing backslashes in IDENT are not doubled, so the
+ result may not uniquely specify the contents of an arbitrary byte
+ sequence identifier. */
const char *
identifier_to_locale (const char *ident)
outside printable ASCII. */
if (!valid_printable_utf8)
{
- char *ret = GGC_NEWVEC (char, 4 * idlen + 1);
+ char *ret = (char *) identifier_to_locale_alloc (4 * idlen + 1);
char *p = ret;
for (i = 0; i < idlen; i++)
{
size_t outbytesleft = ret_alloc - 1;
size_t iconv_ret;
- ret = GGC_NEWVEC (char, ret_alloc);
+ ret = (char *) identifier_to_locale_alloc (ret_alloc);
outbuf = ret;
if (iconv (cd, 0, 0, 0, 0) == (size_t) -1)
if (errno == E2BIG)
{
ret_alloc *= 2;
- ggc_free (ret);
+ identifier_to_locale_free (ret);
ret = NULL;
continue;
}
if (errno == E2BIG)
{
ret_alloc *= 2;
- ggc_free (ret);
+ identifier_to_locale_free (ret);
ret = NULL;
continue;
}
/* Otherwise, convert non-ASCII characters in IDENT to UCNs. */
{
- char *ret = GGC_NEWVEC (char, 10 * idlen + 1);
+ char *ret = (char *) identifier_to_locale_alloc (10 * idlen + 1);
char *p = ret;
for (i = 0; i < idlen;)
{