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