summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/cp/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/cp/error.c')
-rw-r--r--contrib/gcc/cp/error.c290
1 files changed, 149 insertions, 141 deletions
diff --git a/contrib/gcc/cp/error.c b/contrib/gcc/cp/error.c
index a0217ae..804c918 100644
--- a/contrib/gcc/cp/error.c
+++ b/contrib/gcc/cp/error.c
@@ -24,10 +24,10 @@ Boston, MA 02111-1307, USA. */
#include "tree.h"
#include "cp-tree.h"
#include "real.h"
-#include "obstack.h"
#include "toplev.h"
#include "flags.h"
#include "diagnostic.h"
+#include "langhooks-def.h"
enum pad { none, before, after };
@@ -44,11 +44,6 @@ enum pad { none, before, after };
print_non_consecutive_character ((BUFFER), '<')
#define print_template_argument_list_end(BUFFER) \
print_non_consecutive_character ((BUFFER), '>')
-#define print_whitespace(BUFFER, TFI) \
- do { \
- output_add_space (BUFFER); \
- put_whitespace (TFI) = none; \
- } while (0)
#define print_tree_identifier(BUFFER, TID) \
output_add_string ((BUFFER), IDENTIFIER_POINTER (TID))
#define print_identifier(BUFFER, ID) output_add_string ((BUFFER), (ID))
@@ -104,20 +99,19 @@ static void dump_scope PARAMS ((tree, int));
static void dump_template_parms PARAMS ((tree, int, int));
static const char *function_category PARAMS ((tree));
-static void lang_print_error_function PARAMS ((diagnostic_context *,
- const char *));
-static void maybe_print_instantiation_context PARAMS ((output_buffer *));
-static void print_instantiation_full_context PARAMS ((output_buffer *));
-static void print_instantiation_partial_context PARAMS ((output_buffer *, tree,
+static void maybe_print_instantiation_context PARAMS ((diagnostic_context *));
+static void print_instantiation_full_context PARAMS ((diagnostic_context *));
+static void print_instantiation_partial_context PARAMS ((diagnostic_context *,
+ tree,
const char *, int));
-static void cp_diagnostic_starter PARAMS ((output_buffer *,
- diagnostic_context *));
-static void cp_diagnostic_finalizer PARAMS ((output_buffer *,
- diagnostic_context *));
-static void cp_print_error_function PARAMS ((output_buffer *,
- diagnostic_context *));
-
-static int cp_printer PARAMS ((output_buffer *));
+static void cp_diagnostic_starter PARAMS ((diagnostic_context *,
+ diagnostic_info *));
+static void cp_diagnostic_finalizer PARAMS ((diagnostic_context *,
+ diagnostic_info *));
+static void cp_print_error_function PARAMS ((diagnostic_context *,
+ diagnostic_info *));
+
+static bool cp_printer PARAMS ((output_buffer *, text_info *));
static void print_non_consecutive_character PARAMS ((output_buffer *, int));
static void print_integer PARAMS ((output_buffer *, HOST_WIDE_INT));
static tree locate_error PARAMS ((const char *, va_list));
@@ -125,7 +119,6 @@ static tree locate_error PARAMS ((const char *, va_list));
void
init_error ()
{
- print_error_function = lang_print_error_function;
diagnostic_starter (global_dc) = cp_diagnostic_starter;
diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
diagnostic_format_decoder (global_dc) = cp_printer;
@@ -322,8 +315,8 @@ dump_template_bindings (parms, args)
}
}
-/* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
- controls the format. */
+/* Dump a human-readable equivalent of TYPE. FLAGS controls the
+ format. */
static void
dump_type (t, flags)
@@ -387,7 +380,7 @@ dump_type (t, flags)
which has no name and is not very useful for diagnostics. So
look up the equivalent C type and print its name. */
tree elt = TREE_TYPE (t);
- elt = type_for_mode (TYPE_MODE (elt), TREE_UNSIGNED (elt));
+ elt = c_common_type_for_mode (TYPE_MODE (elt), TREE_UNSIGNED (elt));
dump_type (elt, flags);
}
break;
@@ -417,7 +410,7 @@ dump_type (t, flags)
break;
case TEMPLATE_TEMPLATE_PARM:
- /* For parameters inside template signature. */
+ /* For parameters inside template signature. */
if (TYPE_IDENTIFIER (t))
print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
else
@@ -459,7 +452,7 @@ dump_type (t, flags)
break;
}
case TYPENAME_TYPE:
- if (IMPLICIT_TYPENAME_P (t))
+ if (!IMPLICIT_TYPENAME_P (t))
output_add_string (scratch_buffer, "typename ");
dump_typename (t, flags);
break;
@@ -479,7 +472,7 @@ dump_type (t, flags)
default:
sorry_for_unsupported_tree (t);
- /* Fall through to error. */
+ /* Fall through to error. */
case ERROR_MARK:
print_identifier (scratch_buffer, "<type error>");
@@ -692,6 +685,7 @@ dump_type_prefix (t, flags)
case TYPENAME_TYPE:
case COMPLEX_TYPE:
case VECTOR_TYPE:
+ case TYPEOF_TYPE:
dump_type (t, flags);
padding = before;
break;
@@ -788,6 +782,7 @@ dump_type_suffix (t, flags)
case TYPENAME_TYPE:
case COMPLEX_TYPE:
case VECTOR_TYPE:
+ case TYPEOF_TYPE:
break;
default:
@@ -855,7 +850,7 @@ dump_decl (t, flags)
{
if ((flags & TFF_DECL_SPECIFIERS)
&& TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
- /* Say `class T' not just `T'. */
+ /* Say `class T' not just `T'. */
output_add_string (scratch_buffer, "class ");
dump_type (TREE_TYPE (t), flags);
@@ -1013,7 +1008,11 @@ dump_decl (t, flags)
output_add_string (scratch_buffer, "using ");
dump_type (DECL_INITIAL (t), flags);
print_scope_operator (scratch_buffer);
- print_tree_identifier (scratch_buffer, DECL_NAME (t));
+ dump_decl (DECL_NAME (t), flags);
+ break;
+
+ case BASELINK:
+ dump_decl (BASELINK_FUNCTIONS (t), flags);
break;
default:
@@ -1065,7 +1064,7 @@ dump_template_decl (t, flags)
nreverse(orig_parms);
if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
- /* Say `template<arg> class TT' not just `template<arg> TT'. */
+ /* Say `template<arg> class TT' not just `template<arg> TT'. */
output_add_string (scratch_buffer, "class ");
}
@@ -1085,7 +1084,7 @@ dump_template_decl (t, flags)
dump_function_decl (t, flags | TFF_TEMPLATE_NAME);
break;
default:
- /* This case can occur with some illegal code. */
+ /* This case can occur with some invalid code. */
dump_type (TREE_TYPE (t),
(flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
| (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0));
@@ -1095,7 +1094,7 @@ dump_template_decl (t, flags)
/* Pretty print a function decl. There are several ways we want to print a
function declaration. The TFF_ bits in FLAGS tells us how to behave.
As error can only apply the '#' flag once to give 0 and 1 for V, there
- is %D which doesn't print the throw specs, and %F which does. */
+ is %D which doesn't print the throw specs, and %F which does. */
static void
dump_function_decl (t, flags)
@@ -1189,7 +1188,7 @@ dump_function_decl (t, flags)
/* Print a parameter list. If this is for a member function, the
member object ptr (and any other hidden args) should have
- already been removed. */
+ already been removed. */
static void
dump_parameters (parmtypes, flags)
@@ -1223,7 +1222,7 @@ dump_parameters (parmtypes, flags)
print_right_paren (scratch_buffer);
}
-/* Print an exception specification. T is the exception specification. */
+/* Print an exception specification. T is the exception specification. */
static void
dump_exception_spec (t, flags)
@@ -1256,6 +1255,9 @@ dump_function_name (t, flags)
{
tree name = DECL_NAME (t);
+ if (TREE_CODE (t) == TEMPLATE_DECL)
+ t = DECL_TEMPLATE_RESULT (t);
+
/* Don't let the user see __comp_ctor et al. */
if (DECL_CONSTRUCTOR_P (t)
|| DECL_DESTRUCTOR_P (t))
@@ -1436,16 +1438,16 @@ dump_expr_list (l, flags)
}
}
-/* Print out an expression E under control of FLAGS. */
+/* Print out an expression E under control of FLAGS. */
static void
dump_expr (t, flags)
tree t;
int flags;
{
- if (t == 0)
- return;
-
+ if (t == 0)
+ return;
+
switch (TREE_CODE (t))
{
case VAR_DECL:
@@ -1534,17 +1536,8 @@ dump_expr (t, flags)
break;
case REAL_CST:
-#ifndef REAL_IS_NOT_DOUBLE
- sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
-#else
- {
- const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
- size_t i;
- strcpy (digit_buffer, "0x");
- for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
- sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
- }
-#endif
+ real_to_decimal (digit_buffer, &TREE_REAL_CST (t),
+ sizeof (digit_buffer), 0, 1);
output_add_string (scratch_buffer, digit_buffer);
break;
@@ -1657,6 +1650,7 @@ dump_expr (t, flags)
case NEW_EXPR:
{
tree type = TREE_OPERAND (t, 1);
+ tree init = TREE_OPERAND (t, 2);
if (NEW_EXPR_USE_GLOBAL (t))
print_scope_operator (scratch_buffer);
output_add_string (scratch_buffer, "new ");
@@ -1673,10 +1667,17 @@ dump_expr (t, flags)
TREE_OPERAND (type, 1),
integer_one_node))));
dump_type (type, flags);
- if (TREE_OPERAND (t, 2))
+ if (init)
{
print_left_paren (scratch_buffer);
- dump_expr_list (TREE_OPERAND (t, 2), flags);
+ if (TREE_CODE (init) == TREE_LIST)
+ dump_expr_list (init, flags);
+ else if (init == void_zero_node)
+ /* This representation indicates an empty initializer,
+ e.g.: "new int()". */
+ ;
+ else
+ dump_expr (init, flags);
print_right_paren (scratch_buffer);
}
}
@@ -1860,7 +1861,7 @@ dump_expr (t, flags)
case CONSTRUCTOR:
if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
{
- tree idx = build_component_ref (t, pfn_identifier, NULL_TREE, 0);
+ tree idx = build_ptrmemfunc_access_expr (t, pfn_identifier);
if (integer_zerop (idx))
{
@@ -1898,9 +1899,19 @@ dump_expr (t, flags)
}
}
}
- output_add_character (scratch_buffer, '{');
- dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
- output_add_character (scratch_buffer, '}');
+ /* We've gotten an rvalue of the form 'T()'. */
+ else if (TREE_TYPE (t))
+ {
+ dump_type (TREE_TYPE (t), flags);
+ print_left_paren (scratch_buffer);
+ print_right_paren (scratch_buffer);
+ }
+ else
+ {
+ output_add_character (scratch_buffer, '{');
+ dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
+ output_add_character (scratch_buffer, '}');
+ }
break;
case OFFSET_REF:
@@ -1913,7 +1924,8 @@ dump_expr (t, flags)
/* A::f */
dump_expr (t, flags | TFF_EXPR_IN_PARENS);
else if (BASELINK_P (t))
- dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TFF_EXPR_IN_PARENS);
+ dump_expr (OVL_CURRENT (BASELINK_FUNCTIONS (t)),
+ flags | TFF_EXPR_IN_PARENS);
else
dump_decl (t, flags);
}
@@ -2056,6 +2068,10 @@ dump_expr (t, flags)
output_add_string (scratch_buffer, ") break; ");
break;
+ case BASELINK:
+ print_tree_identifier (scratch_buffer, DECL_NAME (get_first_fn (t)));
+ break;
+
case TREE_LIST:
if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
{
@@ -2159,7 +2175,7 @@ context_as_string (context, flags)
return output_finalize_message (scratch_buffer);
}
-/* Generate the three forms of printable names for lang_printable_name. */
+/* Generate the three forms of printable names for cxx_printable_name. */
const char *
lang_decl_name (decl, v)
@@ -2238,7 +2254,7 @@ decl_to_string (decl, verbose)
|| TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
flags = TFF_CLASS_KEY_OR_ENUM;
if (verbose)
- flags |= TFF_DECL_SPECIFIERS | TFF_FUNCTION_DEFAULT_ARGUMENTS;
+ flags |= TFF_DECL_SPECIFIERS;
else if (TREE_CODE (decl) == FUNCTION_DECL)
flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE;
flags |= TFF_TEMPLATE_HEADER;
@@ -2405,70 +2421,63 @@ cv_to_string (p, v)
return output_finalize_message (scratch_buffer);
}
-static void
-lang_print_error_function (context, file)
+/* Langhook for print_error_function. */
+void
+cxx_print_error_function (context, file)
diagnostic_context *context;
const char *file;
{
- output_state os;
-
- default_print_error_function (context, file);
- os = output_buffer_state (context);
- output_set_prefix ((output_buffer *)context, file);
- maybe_print_instantiation_context ((output_buffer *)context);
- output_buffer_state (context) = os;
+ lhd_print_error_function (context, file);
+ output_set_prefix (&context->buffer, file);
+ maybe_print_instantiation_context (context);
}
static void
-cp_diagnostic_starter (buffer, dc)
- output_buffer *buffer;
- diagnostic_context *dc;
+cp_diagnostic_starter (context, diagnostic)
+ diagnostic_context *context;
+ diagnostic_info *diagnostic;
{
- report_problematic_module (buffer);
- cp_print_error_function (buffer, dc);
- maybe_print_instantiation_context (buffer);
- output_set_prefix (buffer,
- context_as_prefix (diagnostic_file_location (dc),
- diagnostic_line_location (dc),
- diagnostic_is_warning (dc)));
+ diagnostic_report_current_module (context);
+ cp_print_error_function (context, diagnostic);
+ maybe_print_instantiation_context (context);
+ output_set_prefix (&context->buffer, diagnostic_build_prefix (diagnostic));
}
static void
-cp_diagnostic_finalizer (buffer, dc)
- output_buffer *buffer;
- diagnostic_context *dc __attribute__ ((__unused__));
+cp_diagnostic_finalizer (context, diagnostic)
+ diagnostic_context *context;
+ diagnostic_info *diagnostic __attribute__((unused));
{
- output_destroy_prefix (buffer);
+ output_destroy_prefix (&context->buffer);
}
/* Print current function onto BUFFER, in the process of reporting
a diagnostic message. Called from cp_diagnostic_starter. */
static void
-cp_print_error_function (buffer, dc)
- output_buffer *buffer;
- diagnostic_context *dc;
+cp_print_error_function (context, diagnostic)
+ diagnostic_context *context;
+ diagnostic_info *diagnostic;
{
- if (error_function_changed ())
+ if (diagnostic_last_function_changed (context))
{
- char *prefix = diagnostic_file_location (dc)
- ? file_name_as_prefix (diagnostic_file_location (dc))
+ const char *old_prefix = output_prefix (&context->buffer);
+ char *new_prefix = diagnostic->location.file
+ ? file_name_as_prefix (diagnostic->location.file)
: NULL;
- output_state os;
- os = output_buffer_state (buffer);
- output_set_prefix (buffer, prefix);
+ output_set_prefix (&context->buffer, new_prefix);
if (current_function_decl == NULL)
- output_add_string (buffer, "At global scope:");
+ output_add_string (&context->buffer, "At global scope:");
else
- output_printf
- (buffer, "In %s `%s':", function_category (current_function_decl),
- (*decl_printable_name) (current_function_decl, 2));
- output_add_newline (buffer);
-
- record_last_error_function ();
- output_destroy_prefix (buffer);
- output_buffer_state (buffer) = os;
+ output_printf (&context->buffer, "In %s `%s':",
+ function_category (current_function_decl),
+ cxx_printable_name (current_function_decl, 2));
+ output_add_newline (&context->buffer);
+
+ diagnostic_set_last_function (context);
+ output_destroy_prefix (&context->buffer);
+ context->buffer.state.prefix = old_prefix;
}
}
@@ -2497,8 +2506,8 @@ function_category (fn)
/* Report the full context of a current template instantiation,
onto BUFFER. */
static void
-print_instantiation_full_context (buffer)
- output_buffer *buffer;
+print_instantiation_full_context (context)
+ diagnostic_context *context;
{
tree p = current_instantiation ();
int line = lineno;
@@ -2517,7 +2526,8 @@ print_instantiation_full_context (buffer)
if (current_function_decl == TINST_DECL (p))
/* Avoid redundancy with the the "In function" line. */;
else
- output_verbatim (buffer, "%s: In instantiation of `%s':\n", file,
+ output_verbatim (&context->buffer,
+ "%s: In instantiation of `%s':\n", file,
decl_as_string (TINST_DECL (p),
TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
@@ -2527,13 +2537,13 @@ print_instantiation_full_context (buffer)
}
}
- print_instantiation_partial_context (buffer, p, file, line);
+ print_instantiation_partial_context (context, p, file, line);
}
/* Same as above but less verbose. */
static void
-print_instantiation_partial_context (buffer, t, file, line)
- output_buffer *buffer;
+print_instantiation_partial_context (context, t, file, line)
+ diagnostic_context *context;
tree t;
const char *file;
int line;
@@ -2541,24 +2551,24 @@ print_instantiation_partial_context (buffer, t, file, line)
for (; t; t = TREE_CHAIN (t))
{
output_verbatim
- (buffer, "%s:%d: instantiated from `%s'\n", file, line,
+ (&context->buffer, "%s:%d: instantiated from `%s'\n", file, line,
decl_as_string (TINST_DECL (t), TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
line = TINST_LINE (t);
file = TINST_FILE (t);
}
- output_verbatim (buffer, "%s:%d: instantiated from here\n", file, line);
+ output_verbatim (&context->buffer, "%s:%d: instantiated from here\n", file, line);
}
/* Called from cp_thing to print the template context for an error. */
static void
-maybe_print_instantiation_context (buffer)
- output_buffer *buffer;
+maybe_print_instantiation_context (context)
+ diagnostic_context *context;
{
if (!problematic_instantiation_changed () || current_instantiation () == 0)
return;
record_last_problematic_instantiation ();
- print_instantiation_full_context (buffer);
+ print_instantiation_full_context (context);
}
/* Report the bare minimum context of a template instantiation. */
@@ -2566,8 +2576,8 @@ void
print_instantiation_context ()
{
print_instantiation_partial_context
- (diagnostic_buffer, current_instantiation (), input_filename, lineno);
- flush_diagnostic_buffer ();
+ (global_dc, current_instantiation (), input_filename, lineno);
+ diagnostic_flush_buffer (global_dc);
}
/* Called from output_format -- during diagnostic message processing --
@@ -2583,26 +2593,27 @@ print_instantiation_context ()
%Q assignment operator.
%T type.
%V cv-qualifier. */
-static int
-cp_printer (buffer)
+static bool
+cp_printer (buffer, text)
output_buffer *buffer;
+ text_info *text;
{
int verbose = 0;
const char *result;
-#define next_tree va_arg (output_buffer_format_args (buffer), tree)
-#define next_tcode va_arg (output_buffer_format_args (buffer), enum tree_code)
-#define next_lang va_arg (output_buffer_format_args (buffer), enum languages)
-#define next_int va_arg (output_buffer_format_args (buffer), int)
-
- if (*output_buffer_text_cursor (buffer) == '+')
- ++output_buffer_text_cursor (buffer);
- if (*output_buffer_text_cursor (buffer) == '#')
+#define next_tree va_arg (*text->args_ptr, tree)
+#define next_tcode va_arg (*text->args_ptr, enum tree_code)
+#define next_lang va_arg (*text->args_ptr, enum languages)
+#define next_int va_arg (*text->args_ptr, int)
+
+ if (*text->format_spec == '+')
+ ++text->format_spec;
+ if (*text->format_spec == '#')
{
verbose = 1;
- ++output_buffer_text_cursor (buffer);
+ ++text->format_spec;
}
- switch (*output_buffer_text_cursor (buffer))
+ switch (*text->format_spec)
{
case 'A': result = args_to_string (next_tree, verbose); break;
case 'C': result = code_to_string (next_tcode, verbose); break;
@@ -2617,11 +2628,11 @@ cp_printer (buffer)
case 'V': result = cv_to_string (next_tree, verbose); break;
default:
- return 0;
+ return false;
}
output_add_string (buffer, result);
- return 1;
+ return true;
#undef next_tree
#undef next_tcode
#undef next_lang
@@ -2715,7 +2726,7 @@ void
cp_error_at VPARAMS ((const char *msgid, ...))
{
tree here;
- diagnostic_context dc;
+ diagnostic_info diagnostic;
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
@@ -2725,10 +2736,9 @@ cp_error_at VPARAMS ((const char *msgid, ...))
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
- set_diagnostic_context (&dc, msgid, &ap,
- cp_file_of (here),
- cp_line_of (here), /* warning = */ 0);
- report_diagnostic (&dc);
+ diagnostic_set_info (&diagnostic, msgid, &ap,
+ cp_file_of (here), cp_line_of (here), DK_ERROR);
+ report_diagnostic (&diagnostic);
VA_CLOSE (ap);
}
@@ -2736,7 +2746,7 @@ void
cp_warning_at VPARAMS ((const char *msgid, ...))
{
tree here;
- diagnostic_context dc;
+ diagnostic_info diagnostic;
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
@@ -2746,10 +2756,9 @@ cp_warning_at VPARAMS ((const char *msgid, ...))
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
- set_diagnostic_context (&dc, msgid, &ap,
- cp_file_of (here),
- cp_line_of (here), /* warning = */ 1);
- report_diagnostic (&dc);
+ diagnostic_set_info (&diagnostic, msgid, &ap,
+ cp_file_of (here), cp_line_of (here), DK_WARNING);
+ report_diagnostic (&diagnostic);
VA_CLOSE (ap);
}
@@ -2757,7 +2766,7 @@ void
cp_pedwarn_at VPARAMS ((const char *msgid, ...))
{
tree here;
- diagnostic_context dc;
+ diagnostic_info diagnostic;
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
@@ -2767,10 +2776,9 @@ cp_pedwarn_at VPARAMS ((const char *msgid, ...))
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
- set_diagnostic_context (&dc, msgid, &ap,
- cp_file_of (here),
- cp_line_of (here),
- /* warning = */ !flag_pedantic_errors);
- report_diagnostic (&dc);
+ diagnostic_set_info (&diagnostic, msgid, &ap,
+ cp_file_of (here), cp_line_of (here),
+ pedantic_error_kind());
+ report_diagnostic (&diagnostic);
VA_CLOSE (ap);
}
OpenPOWER on IntegriCloud