]> git.ipfire.org Git - thirdparty/gcc.git/blame - fixincludes/fixtests.c
c++: Implement C++26 P2573R2 - = delete("should have a reason"); [PR114458]
[thirdparty/gcc.git] / fixincludes / fixtests.c
CommitLineData
5abc1f74
BK
1
2/*
3
4 Test to see if a particular fix should be applied to a header file.
5
90d04a44
JJ
6 Copyright (C) 1997, 1998, 1999, 2000, 2009, 2012
7 Free Software Foundation, Inc.
5abc1f74
BK
8
9= = = = = = = = = = = = = = = = = = = = = = = = =
10
11NOTE TO DEVELOPERS
12
b7976767 13The routines you write here must work closely with fixincl.c.
5abc1f74
BK
14
15Here are the rules:
16
171. Every test procedure name must be suffixed with "_test".
18 These routines will be referenced from inclhack.def, sans the suffix.
19
202. Use the "TEST_FOR_FIX_PROC_HEAD()" macro _with_ the "_test" suffix
21 (I cannot use the ## magic from ANSI C) for defining your entry point.
22
233. Put your test name into the FIX_TEST_TABLE
24
254. Do not write anything to stdout. It may be closed.
26
275. Write to stderr only in the event of a reportable error
28 In such an event, call "exit(1)".
29
30= = = = = = = = = = = = = = = = = = = = = = = = =
31
6e6a1681 32This file is part of GCC.
5abc1f74 33
6e6a1681 34GCC is free software; you can redistribute it and/or modify
5abc1f74 35it under the terms of the GNU General Public License as published by
748086b7 36the Free Software Foundation; either version 3, or (at your option)
5abc1f74
BK
37any later version.
38
6e6a1681 39GCC is distributed in the hope that it will be useful,
5abc1f74
BK
40but WITHOUT ANY WARRANTY; without even the implied warranty of
41MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42GNU General Public License for more details.
43
44You should have received a copy of the GNU General Public License
748086b7
JJ
45along with GCC; see the file COPYING3. If not see
46<http://www.gnu.org/licenses/>. */
5abc1f74
BK
47
48#include "fixlib.h"
49
7e416541 50#define _ENV_(v,m,n,t) extern char const * v;
7b78a14a
BK
51ENV_TABLE
52#undef _ENV_
53
f4dbf936 54typedef apply_fix_p_t t_test_proc ( tCC* file, tCC* text );
3af556f7 55
5abc1f74 56typedef struct {
3af556f7
BK
57 tCC* test_name;
58 t_test_proc* test_proc;
5abc1f74
BK
59} test_entry_t;
60
1c99d804
RH
61#define FIX_TEST_TABLE \
62 _FT_( "machine_name", machine_name_test ) \
a26c3bb5 63 _FT_( "stdc_0_in_system_headers", stdc_0_in_system_headers_test )
5abc1f74 64
f4dbf936
NN
65#define TEST_FOR_FIX_PROC_HEAD( test ) \
66static apply_fix_p_t test ( tCC* fname ATTRIBUTE_UNUSED, \
67 tCC* text ATTRIBUTE_UNUSED )
8f9ca912 68
52c207e2
ZW
69TEST_FOR_FIX_PROC_HEAD( machine_name_test )
70{
71 regex_t *label_re, *name_re;
72 regmatch_t match[2];
73 tCC *base, *limit;
2629a114 74 IGNORE_ARG(fname);
52c207e2 75
89b8abbf
PB
76 if (!mn_get_regexps (&label_re, &name_re, "machine_name_test"))
77 return SKIP_FIX;
52c207e2
ZW
78
79 for (base = text;
ab747408 80 xregexec (label_re, base, 2, match, 0) == 0;
52c207e2
ZW
81 base = limit)
82 {
83 base += match[0].rm_eo;
84 /* We're looking at an #if or #ifdef. Scan forward for the
85 next non-escaped newline. */
86 limit = base;
87 do
88 {
89 limit++;
90 limit = strchr (limit, '\n');
91 if (!limit)
92 return SKIP_FIX;
93 }
94 while (limit[-1] == '\\');
95
96 /* If the 'name_pat' matches in between base and limit, we have
97 a bogon. It is not worth the hassle of excluding comments,
98 because comments on #if/#ifdef/#ifndef lines are rare,
99 and strings on such lines are illegal.
100
101 REG_NOTBOL means 'base' is not at the beginning of a line, which
102 shouldn't matter since the name_re has no ^ anchor, but let's
103 be accurate anyway. */
104
ab747408 105 if (xregexec (name_re, base, 1, match, REG_NOTBOL))
52c207e2
ZW
106 return SKIP_FIX; /* No match in file - no fix needed */
107
108 /* Match; is it on the line? */
cef40e9f 109 if (match[0].rm_eo <= limit - base)
52c207e2
ZW
110 return APPLY_FIX; /* Yup */
111
112 /* Otherwise, keep looking... */
113 }
114 return SKIP_FIX;
115}
116
5c0d5b94 117
a26c3bb5
RO
118TEST_FOR_FIX_PROC_HEAD( stdc_0_in_system_headers_test )
119{
120#ifdef STDC_0_IN_SYSTEM_HEADERS
89e50a58 121 return (pz_machine == NULL) ? APPLY_FIX : SKIP_FIX;
a26c3bb5
RO
122#else
123 return APPLY_FIX;
124#endif
125}
126
127
5abc1f74
BK
128/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
129
130 test for fix selector
131
132 THIS IS THE ONLY EXPORTED ROUTINE
133
134*/
135apply_fix_p_t
f4dbf936 136run_test( tCC* tname, tCC* fname, tCC* text )
5abc1f74 137{
99d525c9 138#define _FT_(n,p) { n, p },
5abc1f74 139 static test_entry_t test_table[] = { FIX_TEST_TABLE { NULL, NULL }};
99d525c9 140#undef _FT_
b6a1cbae 141#define TEST_TABLE_CT (ARRAY_SIZE (test_table)-1)
5abc1f74
BK
142
143 int ct = TEST_TABLE_CT;
144 test_entry_t* pte = test_table;
145
146 do
147 {
148 if (strcmp( pte->test_name, tname ) == 0)
149 return (*pte->test_proc)( fname, text );
8f9ca912 150 pte++;
5abc1f74
BK
151 } while (--ct > 0);
152 fprintf( stderr, "fixincludes error: the `%s' fix test is unknown\n",
153 tname );
154 exit( 3 );
155}