#include "langhooks-def.h" /* For lhd_simulate_record_decl */
#include "coroutines.h"
#include "gcc-urlifier.h"
+#include "diagnostic-highlight-colors.h"
+#include "pretty-print-markup.h"
/* Possible cases of bad specifiers type used by bad_specifiers. */
enum bad_spec_place {
return false;
}
+/* Issue an error about two mutually incompatible declspecs
+ with the given names and locations
+ e.g. "error: `signed' and `unsigned' specified together" */
+
+static void
+complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
+ const char *name_b, location_t loc_b)
+{
+ gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
+ richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
+ nullptr, highlight_colors::rhs);
+ pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
+ pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
+ error_at (&richloc, "%e and %e specified together",
+ &e_name_a, &e_name_b);
+}
+
/* Given declspecs and a declarator (abstract or otherwise), determine
the name and type of the object declared and construct a DECL node
for it.
int ok = 0;
if (signed_p && unsigned_p)
- {
- gcc_rich_location richloc (declspecs->locations[ds_signed]);
- richloc.add_range (declspecs->locations[ds_unsigned]);
- error_at (&richloc,
- "%<signed%> and %<unsigned%> specified together");
- }
+ complain_about_incompatible_declspecs
+ ("signed", declspecs->locations[ds_signed],
+ "unsigned", declspecs->locations[ds_unsigned]);
else if (long_p && short_p)
- {
- gcc_rich_location richloc (declspecs->locations[ds_long]);
- richloc.add_range (declspecs->locations[ds_short]);
- error_at (&richloc, "%<long%> and %<short%> specified together");
- }
+ complain_about_incompatible_declspecs
+ ("long", declspecs->locations[ds_long],
+ "short", declspecs->locations[ds_short]);
else if (TREE_CODE (type) != INTEGER_TYPE
|| type == char8_type_node
|| type == char16_type_node
extern const char *const expected;
extern const char *const actual;
-/* Color names for expressing "LHS" vs "RHS" values in a binary operation. */
+/* Color names for expressing "LHS" vs "RHS" values in a binary operation
+ or when we are listing two different things. */
extern const char *const lhs;
extern const char *const rhs;
} // namespace pp_markup
+class pp_element_quoted_string : public pp_element
+{
+public:
+ pp_element_quoted_string (const char *text,
+ const char *highlight_color = nullptr)
+ : m_text (text),
+ m_highlight_color (highlight_color)
+ {}
+
+ void add_to_phase_2 (pp_markup::context &ctxt) final override
+ {
+ ctxt.begin_quote ();
+ if (m_highlight_color)
+ ctxt.begin_highlight_color (m_highlight_color);
+ pp_string (&ctxt.m_pp, m_text);
+ if (m_highlight_color)
+ ctxt.end_highlight_color ();
+ ctxt.end_quote ();
+ }
+
+private:
+ const char *m_text;
+ const char *m_highlight_color;
+};
+
#endif /* GCC_PRETTY_PRINT_MARKUP_H */
(ARG1), (ARG2), (ARG3)); \
SELFTEST_END_STMT
-class test_element : public pp_element
-{
-public:
- test_element (const char *text) : m_text (text) {}
-
- void add_to_phase_2 (pp_markup::context &ctxt) final override
- {
- ctxt.begin_quote ();
- pp_string (&ctxt.m_pp, m_text);
- ctxt.end_quote ();
- }
-
-private:
- const char *m_text;
-};
-
/* Verify that pp_format works, for various format codes. */
static void
/* Verify %e. */
{
- test_element foo ("foo");
- test_element bar ("bar");
+ pp_element_quoted_string foo ("foo");
+ pp_element_quoted_string bar ("bar");
ASSERT_PP_FORMAT_2 ("before `foo' `bar' after",
"before %e %e after",
&foo, &bar);
{
pretty_printer pp;
pp.set_url_format (URL_FORMAT_ST);
- test_element elem ("-foption");
+ pp_element_quoted_string elem ("-foption");
pp_printf_with_urlifier (&pp, &urlifier,
"foo %e bar",
&elem);
--- /dev/null
+// Verify colorization of printing of declspec mismatches
+// Use dg-*-multiline-output to avoid regexp interpretation.
+
+// { dg-options "-fdiagnostics-color=always -fdiagnostics-show-caret" }
+
+long short int a;
+/* { dg-begin-multiline-output "" }
+\e[m\e[K'\e[01m\e[K\e[01;32m\e[Klong\e[m\e[K\e[m\e[K' and '\e[01m\e[K\e[01;34m\e[Kshort\e[m\e[K\e[m\e[K' specified together
+ \e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Ko\e[m\e[K\e[01;32m\e[Kn\e[m\e[K\e[01;32m\e[Kg\e[m\e[K \e[01;34m\e[Ks\e[m\e[K\e[01;34m\e[Kh\e[m\e[K\e[01;34m\e[Ko\e[m\e[K\e[01;34m\e[Kr\e[m\e[K\e[01;34m\e[Kt\e[m\e[K int a;
+ \e[01;32m\e[K^\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K \e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K
+ { dg-end-multiline-output "" } */
+short long int b;
+/* { dg-begin-multiline-output "" }
+\e[m\e[K'\e[01m\e[K\e[01;32m\e[Klong\e[m\e[K\e[m\e[K' and '\e[01m\e[K\e[01;34m\e[Kshort\e[m\e[K\e[m\e[K' specified together
+ \e[01;34m\e[Ks\e[m\e[K\e[01;34m\e[Kh\e[m\e[K\e[01;34m\e[Ko\e[m\e[K\e[01;34m\e[Kr\e[m\e[K\e[01;34m\e[Kt\e[m\e[K \e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Ko\e[m\e[K\e[01;32m\e[Kn\e[m\e[K\e[01;32m\e[Kg\e[m\e[K int b;
+ \e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K \e[01;32m\e[K^\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K
+ { dg-end-multiline-output "" } */
+
+// Discard the remaining colorized output that confuses dejagnu.
+// { dg-prune-output diagnostic/long-short-colorization.C }