diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/plugin')
8 files changed, 504 insertions, 3 deletions
diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c index e494315..e0fc9cd 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c @@ -155,7 +155,7 @@ class double_save_thread : public gil_diagnostic return m_call == sub_other.m_call; } - bool emit (rich_location *rich_loc) final override + bool emit (rich_location *rich_loc, logger *) final override { return warning_at (rich_loc, get_controlling_option (), "nested usage of %qs", "Py_BEGIN_ALLOW_THREADS"); @@ -194,7 +194,7 @@ class fncall_without_gil : public gil_diagnostic && m_arg_idx == sub_other.m_arg_idx); } - bool emit (rich_location *rich_loc) final override + bool emit (rich_location *rich_loc, logger *) final override { auto_diagnostic_group d; if (m_callee_fndecl) @@ -245,7 +245,7 @@ class pyobject_usage_without_gil : public gil_diagnostic ((const pyobject_usage_without_gil&)base_other).m_expr); } - bool emit (rich_location *rich_loc) final override + bool emit (rich_location *rich_loc, logger *) final override { auto_diagnostic_group d; return warning_at (rich_loc, get_controlling_option (), diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-ascii-bw.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-ascii-bw.c new file mode 100644 index 0000000..e4239aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-ascii-bw.c @@ -0,0 +1,57 @@ +/* { dg-additional-options "-fdiagnostics-text-art-charset=ascii -fdiagnostics-color=never" } */ + +int non_empty; + +/* { dg-begin-multiline-output "" } + + A + B + C + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ + ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ + + + + + ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ + ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + +--+ + |🙂| + +--+ + + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + + +-------+-----+---------------+---------------------+-----------------------+-----------------------+ + |Offsets|Octet| 0 | 1 | 2 | 3 | + +-------+-----+-+-+-+-+-+-+-+-+-+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | Octet | Bit |0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31| + +-------+-----+-+-+-+-+-+-+-+-+-+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | 0 | 0 |Version| IHL | DSCP | ECN | Total Length | + +-------+-----+-------+-------+---------------+-----+--------+--------------------------------------+ + | 4 | 32 | Identification | Flags | Fragment Offset | + +-------+-----+---------------+---------------------+--------+--------------------------------------+ + | 8 | 64 | Time To Live | Protocol | Header Checksum | + +-------+-----+---------------+---------------------+-----------------------------------------------+ + | 12 | 96 | Source IP Address | + +-------+-----+-------------------------------------------------------------------------------------+ + | 16 | 128 | Destination IP Address | + +-------+-----+-------------------------------------------------------------------------------------+ + | 20 | 160 | | + +-------+-----+ | + | ... | ... | Options | + +-------+-----+ | + | 56 | 448 | | + +-------+-----+-------------------------------------------------------------------------------------+ + + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-ascii-color.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-ascii-color.c new file mode 100644 index 0000000..0650428 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-ascii-color.c @@ -0,0 +1,58 @@ +/* { dg-additional-options "-fdiagnostics-text-art-charset=ascii -fdiagnostics-color=always" } */ + +int non_empty; + +/* { dg-begin-multiline-output "" } + + A + B + C + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + [38;2;0;0;0;48;2;240;217;181m[K♜ [38;2;0;0;0;48;2;181;136;99m[K♞ [38;2;0;0;0;48;2;240;217;181m[K♝ [38;2;0;0;0;48;2;181;136;99m[K♛ [38;2;0;0;0;48;2;240;217;181m[K♚ [38;2;0;0;0;48;2;181;136;99m[K♝ [38;2;0;0;0;48;2;240;217;181m[K♞ [38;2;0;0;0;48;2;181;136;99m[K♜ [m[K + [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [m[K + [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [m[K + [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [m[K + [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [m[K + [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [m[K + [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [m[K + [38;2;255;255;255;48;2;181;136;99m[K♖ [38;2;255;255;255;48;2;240;217;181m[K♘ [38;2;255;255;255;48;2;181;136;99m[K♗ [38;2;255;255;255;48;2;240;217;181m[K♕ [38;2;255;255;255;48;2;181;136;99m[K♔ [38;2;255;255;255;48;2;240;217;181m[K♗ [38;2;255;255;255;48;2;181;136;99m[K♘ [38;2;255;255;255;48;2;240;217;181m[K♖ [m[K + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + +--+ + |🙂| + +--+ + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + +-------+-----+---------------+---------------------+-----------------------+-----------------------+ + |Offsets|Octet| 0 | 1 | 2 | 3 | + +-------+-----+-+-+-+-+-+-+-+-+-+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | Octet | Bit |0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31| + +-------+-----+-+-+-+-+-+-+-+-+-+-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | 0 | 0 |Version| IHL | DSCP | ECN | Total Length | + +-------+-----+-------+-------+---------------+-----+--------+--------------------------------------+ + | 4 | 32 | Identification | Flags | Fragment Offset | + +-------+-----+---------------+---------------------+--------+--------------------------------------+ + | 8 | 64 | Time To Live | Protocol | Header Checksum | + +-------+-----+---------------+---------------------+-----------------------------------------------+ + | 12 | 96 | Source IP Address | + +-------+-----+-------------------------------------------------------------------------------------+ + | 16 | 128 | Destination IP Address | + +-------+-----+-------------------------------------------------------------------------------------+ + | 20 | 160 | | + +-------+-----+ | + | ... | ... | Options | + +-------+-----+ | + | 56 | 448 | | + +-------+-----+-------------------------------------------------------------------------------------+ + + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-none.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-none.c new file mode 100644 index 0000000..c8118b4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-none.c @@ -0,0 +1,5 @@ +/* { dg-additional-options "-fdiagnostics-text-art-charset=none" } */ + +int non_empty; + +/* We expect no output. */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-unicode-bw.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-unicode-bw.c new file mode 100644 index 0000000..c9f5b36 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-unicode-bw.c @@ -0,0 +1,58 @@ +/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode -fdiagnostics-color=never" } */ + +int non_empty; + +/* { dg-begin-multiline-output "" } + + A + B + C + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ + ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ + + + + + ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ + ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + ┌──┐ + │🙂│ + └──┘ + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + ┌───────┬─────┬───────────────┬─────────────────────┬───────────────────────┬───────────────────────┐ + │Offsets│Octet│ 0 │ 1 │ 2 │ 3 │ + ├───────┼─────┼─┬─┬─┬─┬─┬─┬─┬─┼─┬─┬──┬──┬──┬──┬──┬──┼──┬──┬──┬──┬──┬──┬──┬──┼──┬──┬──┬──┬──┬──┬──┬──┤ + │ Octet │ Bit │0│1│2│3│4│5│6│7│8│9│10│11│12│13│14│15│16│17│18│19│20│21│22│23│24│25│26│27│28│29│30│31│ + ├───────┼─────┼─┴─┴─┴─┼─┴─┴─┴─┼─┴─┴──┴──┴──┴──┼──┴──┼──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┤ + │ 0 │ 0 │Version│ IHL │ DSCP │ ECN │ Total Length │ + ├───────┼─────┼───────┴───────┴───────────────┴─────┼────────┬──────────────────────────────────────┤ + │ 4 │ 32 │ Identification │ Flags │ Fragment Offset │ + ├───────┼─────┼───────────────┬─────────────────────┼────────┴──────────────────────────────────────┤ + │ 8 │ 64 │ Time To Live │ Protocol │ Header Checksum │ + ├───────┼─────┼───────────────┴─────────────────────┴───────────────────────────────────────────────┤ + │ 12 │ 96 │ Source IP Address │ + ├───────┼─────┼─────────────────────────────────────────────────────────────────────────────────────┤ + │ 16 │ 128 │ Destination IP Address │ + ├───────┼─────┼─────────────────────────────────────────────────────────────────────────────────────┤ + │ 20 │ 160 │ │ + ├───────┼─────┤ │ + │ ... │ ... │ Options │ + ├───────┼─────┤ │ + │ 56 │ 448 │ │ + └───────┴─────┴─────────────────────────────────────────────────────────────────────────────────────┘ + + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-unicode-color.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-unicode-color.c new file mode 100644 index 0000000..f402836 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-text-art-unicode-color.c @@ -0,0 +1,59 @@ +/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode -fdiagnostics-color=always" } */ + +int non_empty; + + +/* { dg-begin-multiline-output "" } + + A + B + C + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + [38;2;0;0;0;48;2;240;217;181m[K♜ [38;2;0;0;0;48;2;181;136;99m[K♞ [38;2;0;0;0;48;2;240;217;181m[K♝ [38;2;0;0;0;48;2;181;136;99m[K♛ [38;2;0;0;0;48;2;240;217;181m[K♚ [38;2;0;0;0;48;2;181;136;99m[K♝ [38;2;0;0;0;48;2;240;217;181m[K♞ [38;2;0;0;0;48;2;181;136;99m[K♜ [m[K + [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [38;2;0;0;0;48;2;181;136;99m[K♟ [38;2;0;0;0;48;2;240;217;181m[K♟ [m[K + [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [m[K + [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [m[K + [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [m[K + [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [48;2;181;136;99m[K [48;2;240;217;181m[K [m[K + [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [38;2;255;255;255;48;2;240;217;181m[K♙ [38;2;255;255;255;48;2;181;136;99m[K♙ [m[K + [38;2;255;255;255;48;2;181;136;99m[K♖ [38;2;255;255;255;48;2;240;217;181m[K♘ [38;2;255;255;255;48;2;181;136;99m[K♗ [38;2;255;255;255;48;2;240;217;181m[K♕ [38;2;255;255;255;48;2;181;136;99m[K♔ [38;2;255;255;255;48;2;240;217;181m[K♗ [38;2;255;255;255;48;2;181;136;99m[K♘ [38;2;255;255;255;48;2;240;217;181m[K♖ [m[K + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + ┌──┐ + │🙂│ + └──┘ + + { dg-end-multiline-output "" } */ + +/* { dg-begin-multiline-output "" } + + ┌───────┬─────┬───────────────┬─────────────────────┬───────────────────────┬───────────────────────┐ + │Offsets│Octet│ 0 │ 1 │ 2 │ 3 │ + ├───────┼─────┼─┬─┬─┬─┬─┬─┬─┬─┼─┬─┬──┬──┬──┬──┬──┬──┼──┬──┬──┬──┬──┬──┬──┬──┼──┬──┬──┬──┬──┬──┬──┬──┤ + │ Octet │ Bit │0│1│2│3│4│5│6│7│8│9│10│11│12│13│14│15│16│17│18│19│20│21│22│23│24│25│26│27│28│29│30│31│ + ├───────┼─────┼─┴─┴─┴─┼─┴─┴─┴─┼─┴─┴──┴──┴──┴──┼──┴──┼──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┤ + │ 0 │ 0 │Version│ IHL │ DSCP │ ECN │ Total Length │ + ├───────┼─────┼───────┴───────┴───────────────┴─────┼────────┬──────────────────────────────────────┤ + │ 4 │ 32 │ Identification │ Flags │ Fragment Offset │ + ├───────┼─────┼───────────────┬─────────────────────┼────────┴──────────────────────────────────────┤ + │ 8 │ 64 │ Time To Live │ Protocol │ Header Checksum │ + ├───────┼─────┼───────────────┴─────────────────────┴───────────────────────────────────────────────┤ + │ 12 │ 96 │ Source IP Address │ + ├───────┼─────┼─────────────────────────────────────────────────────────────────────────────────────┤ + │ 16 │ 128 │ Destination IP Address │ + ├───────┼─────┼─────────────────────────────────────────────────────────────────────────────────────┤ + │ 20 │ 160 │ │ + ├───────┼─────┤ │ + │ ... │ ... │ Options │ + ├───────┼─────┤ │ + │ 56 │ 448 │ │ + └───────┴─────┴─────────────────────────────────────────────────────────────────────────────────────┘ + + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.c new file mode 100644 index 0000000..58b219b --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.c @@ -0,0 +1,258 @@ +/* { dg-options "-O" } */ + +/* This plugin exercises the text_art code. */ + +#define INCLUDE_VECTOR +#include "gcc-plugin.h" +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "plugin-version.h" +#include "diagnostic.h" +#include "diagnostic-diagram.h" +#include "text-art/canvas.h" +#include "text-art/table.h" + +int plugin_is_GPL_compatible; + +using namespace text_art; + +/* Canvas tests. */ + +static void +emit_canvas (const canvas &c, const char *alt_text) +{ + diagnostic_diagram diagram (c, alt_text); + diagnostic_emit_diagram (global_dc, diagram); +} + +static void +test_abc () +{ + style_manager sm; + canvas c (canvas::size_t (3, 3), sm); + c.paint (canvas::coord_t (0, 0), styled_unichar ('A')); + c.paint (canvas::coord_t (1, 1), styled_unichar ('B')); + c.paint (canvas::coord_t (2, 2), styled_unichar ('C')); + emit_canvas (c, "test_abc"); +} + +/* Test of procedural art using 24-bit color: chess starting position. */ + +static void +test_chessboard () +{ + /* With the exception of NONE, these are in order of the chess symbols + in the Unicode Miscellaneous Symbols block. */ + enum class piece { KING, QUEEN, ROOK, BISHOP, KNIGHT, PAWN, NONE }; + enum class color { BLACK, WHITE, NONE }; + + style_manager sm; + + /* We assume double-column chars for the pieces, so allow two canvas + columns per square. */ + canvas canvas (canvas::size_t (16, 8), sm); + + for (int x = 0; x < 8; x++) + for (int y = 0; y < 8; y++) + { + enum piece piece_kind; + enum color piece_color; + switch (y) + { + case 0: + case 7: + switch (x) + { + default: + gcc_unreachable (); + case 0: + piece_kind = piece::ROOK; + break; + case 1: + piece_kind = piece::KNIGHT; + break; + case 2: + piece_kind = piece::BISHOP; + break; + case 3: + piece_kind = piece::QUEEN; + break; + case 4: + piece_kind = piece::KING; + break; + case 5: + piece_kind = piece::BISHOP; + break; + case 6: + piece_kind = piece::KNIGHT; + break; + case 7: + piece_kind = piece::ROOK; + break; + } + piece_color = (y == 0) ? color::BLACK : color::WHITE; + break; + case 1: + case 6: + piece_kind = piece::PAWN; + piece_color = (y == 1) ? color::BLACK : color::WHITE; + break; + default: + piece_kind = piece::NONE; + piece_color = color::NONE; + break; + } + + style s; + const bool white_square = (x + y) % 2 == 0; + if (white_square) + s.m_bg_color = style::color (0xf0, 0xd9, 0xb5); + else + s.m_bg_color = style::color (0xb5, 0x88, 0x63); + switch (piece_color) + { + default: + gcc_unreachable (); + case color::WHITE: + s.m_fg_color = style::color (0xff, 0xff, 0xff); + break; + case color::BLACK: + s.m_fg_color = style::color (0x00, 0x00, 0x00); + break; + case color::NONE: + break; + } + style::id_t style_id = sm.get_or_create_id (s); + + cppchar_t ch; + if (piece_kind == piece::NONE) + ch = ' '; + else + { + const cppchar_t WHITE_KING = 0x2654; + const cppchar_t BLACK_KING = 0x265A; + cppchar_t base ((piece_color == color::WHITE) + ? WHITE_KING : BLACK_KING); + ch = base + ((int)piece_kind - (int)piece::KING); + } + canvas.paint (canvas::coord_t (x * 2, y), + canvas::cell_t (ch, false, style_id)); + canvas.paint (canvas::coord_t (x * 2 + 1, y), + canvas::cell_t (' ', false, style_id)); + } + emit_canvas (canvas, "test_chessboard"); +} + +/* Table tests. */ + +static void +emit_table (const table &table, const style_manager &sm, const char *alt_text) +{ + const text_art::theme *theme = global_dc->m_diagrams.m_theme; + if (!theme) + return; + canvas c (table.to_canvas (*theme, sm)); + emit_canvas (c, alt_text); +} + +static void +test_double_width_chars () +{ + style_manager sm; + table table (table::size_t (1, 1)); + table.set_cell (table::coord_t (0,0), + styled_string ((cppchar_t)0x1f642)); + + emit_table (table, sm, "test_double_width_chars"); +} + +static void +test_ipv4_header () +{ + style_manager sm; + table table (table::size_t (34, 10)); + table.set_cell (table::coord_t (0, 0), styled_string (sm, "Offsets")); + table.set_cell (table::coord_t (1, 0), styled_string (sm, "Octet")); + table.set_cell (table::coord_t (0, 1), styled_string (sm, "Octet")); + for (int octet = 0; octet < 4; octet++) + table.set_cell_span (table::rect_t (table::coord_t (2 + (octet * 8), 0), + table::size_t (8, 1)), + styled_string::from_fmt (sm, nullptr, "%i", octet)); + table.set_cell (table::coord_t (1, 1), styled_string (sm, "Bit")); + for (int bit = 0; bit < 32; bit++) + table.set_cell (table::coord_t (bit + 2, 1), + styled_string::from_fmt (sm, nullptr, "%i", bit)); + for (int word = 0; word < 6; word++) + { + table.set_cell (table::coord_t (0, word + 2), + styled_string::from_fmt (sm, nullptr, "%i", word * 4)); + table.set_cell (table::coord_t (1, word + 2), + styled_string::from_fmt (sm, nullptr, "%i", word * 32)); + } + + table.set_cell (table::coord_t (0, 8), styled_string (sm, "...")); + table.set_cell (table::coord_t (1, 8), styled_string (sm, "...")); + table.set_cell (table::coord_t (0, 9), styled_string (sm, "56")); + table.set_cell (table::coord_t (1, 9), styled_string (sm, "448")); + +#define SET_BITS(FIRST, LAST, NAME) \ + do { \ + const int first = (FIRST); \ + const int last = (LAST); \ + const char *name = (NAME); \ + const int row = first / 32; \ + gcc_assert (last / 32 == row); \ + table::rect_t rect (table::coord_t ((first % 32) + 2, row + 2), \ + table::size_t (last + 1 - first , 1)); \ + table.set_cell_span (rect, styled_string (sm, name)); \ + } while (0) + + SET_BITS (0, 3, "Version"); + SET_BITS (4, 7, "IHL"); + SET_BITS (8, 13, "DSCP"); + SET_BITS (14, 15, "ECN"); + SET_BITS (16, 31, "Total Length"); + + SET_BITS (32 + 0, 32 + 15, "Identification"); + SET_BITS (32 + 16, 32 + 18, "Flags"); + SET_BITS (32 + 19, 32 + 31, "Fragment Offset"); + + SET_BITS (64 + 0, 64 + 7, "Time To Live"); + SET_BITS (64 + 8, 64 + 15, "Protocol"); + SET_BITS (64 + 16, 64 + 31, "Header Checksum"); + + SET_BITS (96 + 0, 96 + 31, "Source IP Address"); + SET_BITS (128 + 0, 128 + 31, "Destination IP Address"); + + table.set_cell_span(table::rect_t (table::coord_t (2, 7), + table::size_t (32, 3)), + styled_string (sm, "Options")); + + emit_table (table, sm, "test_ipv4_header"); +} + +static void +show_diagrams () +{ + test_abc (); + test_chessboard (); + test_double_width_chars (); + test_ipv4_header (); +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + const char *plugin_name = plugin_info->base_name; + int argc = plugin_info->argc; + struct plugin_argument *argv = plugin_info->argv; + + if (!plugin_default_version_check (version, &gcc_version)) + return 1; + + show_diagrams (); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index 4d6304c..60723a2 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -114,6 +114,12 @@ set plugin_test_list [list \ diagnostic-path-format-inline-events-1.c \ diagnostic-path-format-inline-events-2.c \ diagnostic-path-format-inline-events-3.c } \ + { diagnostic_plugin_test_text_art.c \ + diagnostic-test-text-art-none.c \ + diagnostic-test-text-art-ascii-bw.c \ + diagnostic-test-text-art-ascii-color.c \ + diagnostic-test-text-art-unicode-bw.c \ + diagnostic-test-text-art-unicode-color.c } \ { location_overflow_plugin.c \ location-overflow-test-1.c \ location-overflow-test-2.c \ |