GCC Middle and Back End API Reference
selftest-diagnostic-show-locus.h
Go to the documentation of this file.
1/* Support for selftests involving diagnostic_show_locus.
2 Copyright (C) 1999-2025 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H
21#define GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H
22
23#include "selftest.h"
24
25/* The selftest code should entirely disappear in a production
26 configuration, hence we guard all of it with #if CHECKING_P. */
27
28#if CHECKING_P
29
30namespace selftest {
31
32/* RAII class for use in selftests involving diagnostic_show_locus.
33
34 Manages creating and cleaning up the following:
35 - writing out a temporary .c file containing CONTENT
36 - temporarily override the global "line_table" (using CASE_) and
37 push a line_map starting at the first line of the temporary file
38 - provide a file_cache. */
39
40struct diagnostic_show_locus_fixture
41{
42 diagnostic_show_locus_fixture (const line_table_case &case_,
43 const char *content);
44
45 const char *get_filename () const
46 {
47 return m_tmp_source_file.get_filename ();
48 }
49
50 const char *m_content;
51 temp_source_file m_tmp_source_file;
52 line_table_test m_ltt;
53 file_cache m_fc;
54};
55
56/* Fixture for one-liner tests exercising multibyte awareness. For
57 simplicity we stick to using two multibyte characters in the test, U+1F602
58 == "\xf0\x9f\x98\x82", which uses 4 bytes and 2 display columns, and U+03C0
59 == "\xcf\x80", which uses 2 bytes and 1 display column.
60
61 This works with the following 1-line source file:
62
63 .0000000001111111111222222 display
64 .1234567890123456789012345 columns
65 "SS_foo = P_bar.SS_fieldP;\n"
66 .0000000111111111222222223 byte
67 .1356789012456789134567891 columns
68
69 Here SS represents the two display columns for the U+1F602 emoji and
70 P represents the one display column for the U+03C0 pi symbol. */
71
72struct diagnostic_show_locus_fixture_one_liner_utf8
73 : public diagnostic_show_locus_fixture
74{
75 diagnostic_show_locus_fixture_one_liner_utf8 (const line_table_case &case_);
76};
77
78} // namespace selftest
79
80#endif /* #if CHECKING_P */
81
82#endif /* GCC_SELFTEST_DIAGNOSTIC_SHOW_LOCUS_H */
Definition input.h:136
Definition dump-context.h:31