/* Language-independent diagnostic subroutines for the GNU Compiler Collection
- Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
+ Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
Free Software Foundation, Inc.
Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
#include "diagnostic.h"
#include "langhooks.h"
#include "langhooks-def.h"
+#include "opts.h"
/* Prototypes. */
diagnostic->message.format_spec = _(msgid);
diagnostic->location = location;
diagnostic->kind = kind;
+ diagnostic->option_index = 0;
}
/* Return a malloc'd string describing a location. The caller is
#undef DEFINE_DIAGNOSTIC_KIND
"must-not-happen"
};
+ const char *text = _(diagnostic_kind_text[diagnostic->kind]);
expanded_location s = expand_location (diagnostic->location);
gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
- return s.file
- ? build_message_string ("%s:%d: %s",
- s.file, s.line,
- _(diagnostic_kind_text[diagnostic->kind]))
- : build_message_string ("%s: %s", progname,
- _(diagnostic_kind_text[diagnostic->kind]));
+ return
+ (s.file == NULL
+ ? build_message_string ("%s: %s", progname, text)
+#ifdef USE_MAPPED_LOCATION
+ : flag_show_column && s.column != 0
+ ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
+#endif
+ : build_message_string ("%s:%d: %s", s.file, s.line, text));
}
/* Count a diagnostic. Return true if the message should be printed. */
static void
default_diagnostic_finalizer (diagnostic_context *context,
- diagnostic_info *diagnostic __attribute__((unused)))
+ diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
{
pp_destroy_prefix (context->printer);
}
if (diagnostic_count_diagnostic (context, diagnostic))
{
+ if (diagnostics_show_options && diagnostic->option_index)
+ diagnostic->message.format_spec
+ = ACONCAT ((diagnostic->message.format_spec,
+ " [", cl_options[diagnostic->option_index].opt_text, "]", NULL));
+
pp_prepare_to_format (context->printer, &diagnostic->message,
&diagnostic->location);
(*diagnostic_starter (context)) (context, diagnostic);
p++, q++;
/* Now go backwards until the previous directory separator. */
- while (p > name && IS_DIR_SEPARATOR (p[-1]))
+ while (p > name && !IS_DIR_SEPARATOR (p[-1]))
p--;
return p;
/* A warning. Use this for code which is correct according to the
relevant language specification but is likely to be buggy anyway. */
void
-warning (const char *msgid, ...)
+warning (int opt, const char *msgid, ...)
+{
+ diagnostic_info diagnostic;
+ va_list ap;
+
+ if (opt && ! option_enabled (opt))
+ return;
+
+ va_start (ap, msgid);
+ diagnostic_set_info (&diagnostic, msgid, &ap, input_location, DK_WARNING);
+ diagnostic.option_index = opt;
+
+ report_diagnostic (&diagnostic);
+ va_end (ap);
+}
+
+void
+warning0 (const char *msgid, ...)
{
diagnostic_info diagnostic;
va_list ap;