Sun Mar 8 17:38:37 2020 UTC ()
Add debugging, no functional change.


(christos)
diff -r1.29 -r1.30 src/usr.bin/config/scan.l

cvs diff -r1.29 -r1.30 src/usr.bin/config/scan.l (expand / switch to unified diff)

--- src/usr.bin/config/scan.l 2020/03/08 00:04:11 1.29
+++ src/usr.bin/config/scan.l 2020/03/08 17:38:37 1.30
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: scan.l,v 1.29 2020/03/08 00:04:11 christos Exp $ */ 2/* $NetBSD: scan.l,v 1.30 2020/03/08 17:38:37 christos Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1992, 1993 5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This software was developed by the Computer Systems Engineering group 8 * This software was developed by the Computer Systems Engineering group
9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 * contributed to Berkeley. 10 * contributed to Berkeley.
11 * 11 *
12 * All advertising materials mentioning features or use of this software 12 * All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement: 13 * must display the following acknowledgement:
14 * This product includes software developed by the University of 14 * This product includes software developed by the University of
15 * California, Lawrence Berkeley Laboratories. 15 * California, Lawrence Berkeley Laboratories.
@@ -32,27 +32,27 @@ @@ -32,27 +32,27 @@
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE. 39 * SUCH DAMAGE.
40 * 40 *
41 * from: @(#)scan.l 8.1 (Berkeley) 6/6/93 41 * from: @(#)scan.l 8.1 (Berkeley) 6/6/93
42 */ 42 */
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45__RCSID("$NetBSD: scan.l,v 1.29 2020/03/08 00:04:11 christos Exp $"); 45__RCSID("$NetBSD: scan.l,v 1.30 2020/03/08 17:38:37 christos Exp $");
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <errno.h> 48#include <errno.h>
49#include <libgen.h> 49#include <libgen.h>
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <string.h> 52#include <string.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <stddef.h> 54#include <stddef.h>
55#include <ctype.h> 55#include <ctype.h>
56#include <util.h> 56#include <util.h>
57#undef ECHO 57#undef ECHO
58#include "defs.h" 58#include "defs.h"
@@ -69,27 +69,45 @@ int ifdefshift = -1; @@ -69,27 +69,45 @@ int ifdefshift = -1;
69 * The state is represented by 3 bits. 69 * The state is represented by 3 bits.
70 */ 70 */
71#define IDS_MATCH 1ll 71#define IDS_MATCH 1ll
72#define IDS_ELIF 2ll 72#define IDS_ELIF 2ll
73#define IDS_ELSE 4ll 73#define IDS_ELSE 4ll
74 74
75#define IDS_BITS 7 75#define IDS_BITS 7
76#define IDS_SHIFT 3 76#define IDS_SHIFT 3
77 77
78#define IDS_ISMATCH(st) (((st) & IDS_MATCH) != 0) 78#define IDS_ISMATCH(st) (((st) & IDS_MATCH) != 0)
79#define IDS_PARENT_DISABLED \ 79#define IDS_PARENT_DISABLED \
80 (ifdefshift > 0 && !IDS_ISMATCH(ifdefstate >> IDS_SHIFT)) 80 (ifdefshift > 0 && !IDS_ISMATCH(ifdefstate >> IDS_SHIFT))
81#define IDS_MAX_DEPTH 21 /* 64 / 3 */ 81#define IDS_MAX_DEPTH 21 /* 64 / 3 */
82  82
 83#ifdef IDS_DEBUG
 84# define IDS_PRINT(s, st, x) \
 85 do { \
 86 for (int i = 0; i < ifdefshift + 1; i++) \
 87 fprintf(stderr, " "); \
 88 printf("%s%s [%d,%d,%d] %#" PRIx64 "\n", x, # s, \
 89 IDS_PARENT_DISABLED, IDS_ISMATCH(st), getcurifdef(), \
 90 ifdefstate); \
 91 } while (/*CONSTCOND*/0)
 92#else
 93# define IDS_PRINT(s, st, x) __nothing
 94#endif
 95
 96#define IDS_ENTER(s, st) \
 97 IDS_PRINT(s, st, ">")
 98#define IDS_EXIT(s, st) \
 99 IDS_PRINT(s, st, "<")
 100
83/* 101/*
84 * Data for returning to previous files from include files. 102 * Data for returning to previous files from include files.
85 */ 103 */
86struct incl { 104struct incl {
87 struct incl *in_prev; /* previous includes in effect, if any */ 105 struct incl *in_prev; /* previous includes in effect, if any */
88 YY_BUFFER_STATE in_buf; /* previous lex state */ 106 YY_BUFFER_STATE in_buf; /* previous lex state */
89 struct where in_where; 107 struct where in_where;
90 int in_ateof; /* token to insert at EOF */ 108 int in_ateof; /* token to insert at EOF */
91 int in_interesting; /* previous value for "interesting" */ 109 int in_interesting; /* previous value for "interesting" */
92 uint64_t in_ifdefstate; /* conditional level */ 110 uint64_t in_ifdefstate; /* conditional level */
93 int in_ifdefshift; /* conditional level */ 111 int in_ifdefshift; /* conditional level */
94}; 112};
95static struct incl *incl; 113static struct incl *incl;
@@ -165,102 +183,114 @@ source return SOURCE; @@ -165,102 +183,114 @@ source return SOURCE;
165type return TYPE; 183type return TYPE;
166vector return VECTOR; 184vector return VECTOR;
167version return VERSION; 185version return VERSION;
168with return WITH; 186with return WITH;
169 187
170\+= return PLUSEQ; 188\+= return PLUSEQ;
171:= return COLONEQ; 189:= return COLONEQ;
172 190
173<*>{WS}ifdef[ \t]+{WORD}{RESTOFLINE} { 191<*>{WS}ifdef[ \t]+{WORD}{RESTOFLINE} {
174 ifdefstate <<= IDS_SHIFT; 192 ifdefstate <<= IDS_SHIFT;
175 if (++ifdefshift >= IDS_MAX_DEPTH) { 193 if (++ifdefshift >= IDS_MAX_DEPTH) {
176 yyerror("too many levels of conditional"); 194 yyerror("too many levels of conditional");
177 } 195 }
 196 IDS_ENTER(ifdef, 0);
178 if (IDS_PARENT_DISABLED || !getcurifdef()) { 197 if (IDS_PARENT_DISABLED || !getcurifdef()) {
179 BEGIN(IGNORED); 198 BEGIN(IGNORED);
180 } else { 199 } else {
181 ifdefstate |= IDS_MATCH; 200 ifdefstate |= IDS_MATCH;
182 BEGIN(INITIAL); 201 BEGIN(INITIAL);
183 } 202 }
 203 IDS_EXIT(ifdef, 0);
184 yyline++; 204 yyline++;
185 } 205 }
186 206
187<*>{WS}ifndef[ \t]+{WORD}{RESTOFLINE} { 207<*>{WS}ifndef[ \t]+{WORD}{RESTOFLINE} {
188 ifdefstate <<= IDS_SHIFT; 208 ifdefstate <<= IDS_SHIFT;
189 if (++ifdefshift >= IDS_MAX_DEPTH) { 209 if (++ifdefshift >= IDS_MAX_DEPTH) {
190 yyerror("too many levels of conditional"); 210 yyerror("too many levels of conditional");
191 } 211 }
 212 IDS_ENTER(ifndef, 0);
192 if (IDS_PARENT_DISABLED || getcurifdef()) { 213 if (IDS_PARENT_DISABLED || getcurifdef()) {
193 BEGIN(IGNORED); 214 BEGIN(IGNORED);
194 } else { 215 } else {
195 ifdefstate |= IDS_MATCH; 216 ifdefstate |= IDS_MATCH;
196 BEGIN(INITIAL); 217 BEGIN(INITIAL);
197 } 218 }
 219 IDS_EXIT(ifndef, 0);
198 yyline++; 220 yyline++;
199 } 221 }
200 222
201 223
202<*>{WS}elifdef[ \t]+{WORD}{RESTOFLINE} { 224<*>{WS}elifdef[ \t]+{WORD}{RESTOFLINE} {
203 int st = ifdefstate & IDS_BITS; 225 int st = ifdefstate & IDS_BITS;
 226 IDS_ENTER(elifdef, st);
204 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { 227 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) {
205 yyerror("mismatched elifdef"); 228 yyerror("mismatched elifdef");
206 } 229 }
207 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || !getcurifdef()) { 230 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || !getcurifdef()) {
208 BEGIN(IGNORED); 231 BEGIN(IGNORED);
209 } else { 232 } else {
210 ifdefstate |= IDS_MATCH; 233 ifdefstate |= IDS_MATCH;
211 BEGIN(INITIAL); 234 BEGIN(INITIAL);
212 } 235 }
213 ifdefstate |= IDS_ELIF; 236 ifdefstate |= IDS_ELIF;
 237 IDS_EXIT(elifdef, st);
214 yyline++; 238 yyline++;
215 } 239 }
216 240
217<*>{WS}elifndef[ \t]+{WORD}{RESTOFLINE} { 241<*>{WS}elifndef[ \t]+{WORD}{RESTOFLINE} {
218 int st = ifdefstate & IDS_BITS; 242 int st = ifdefstate & IDS_BITS;
 243 IDS_ENTER(elifndef, st);
219 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { 244 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) {
220 yyerror("mismatched elifndef"); 245 yyerror("mismatched elifndef");
221 } 246 }
222 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || getcurifdef()) { 247 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || getcurifdef()) {
223 BEGIN(IGNORED); 248 BEGIN(IGNORED);
224 } else { 249 } else {
225 ifdefstate |= IDS_MATCH; 250 ifdefstate |= IDS_MATCH;
226 BEGIN(INITIAL); 251 BEGIN(INITIAL);
227 } 252 }
228 ifdefstate |= IDS_ELIF; 253 ifdefstate |= IDS_ELIF;
 254 IDS_EXIT(elifndef, st);
229 yyline++; 255 yyline++;
230 } 256 }
231 257
232<*>{WS}else{RESTOFLINE} { 258<*>{WS}else{RESTOFLINE} {
233 int st = ifdefstate & IDS_BITS; 259 int st = ifdefstate & IDS_BITS;
 260 IDS_ENTER(else, st);
234 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { 261 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) {
235 yyerror("mismatched else"); 262 yyerror("mismatched else");
236 } 263 }
237 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st)) { 264 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st)) {
238 BEGIN(IGNORED); 265 BEGIN(IGNORED);
239 } else { 266 } else {
240 ifdefstate |= IDS_MATCH; 267 ifdefstate |= IDS_MATCH;
241 BEGIN(INITIAL); 268 BEGIN(INITIAL);
242 } 269 }
243 ifdefstate |= IDS_ELSE; 270 ifdefstate |= IDS_ELSE;
 271 IDS_ENTER(else, st);
244 yyline++; 272 yyline++;
245 } 273 }
246 274
247<*>{WS}endif{RESTOFLINE} { 275<*>{WS}endif{RESTOFLINE} {
 276 IDS_ENTER(endif, 0);
248 if (ifdefshift == -1) { 277 if (ifdefshift == -1) {
249 yyerror("mismatched endif"); 278 yyerror("mismatched endif");
250 } 279 }
251 if (!IDS_PARENT_DISABLED) { 280 if (!IDS_PARENT_DISABLED) {
252 BEGIN(INITIAL); 281 BEGIN(INITIAL);
253 } 282 }
 283 IDS_EXIT(endif, 0);
254 ifdefshift--; 284 ifdefshift--;
255 ifdefstate >>= IDS_SHIFT; 285 ifdefstate >>= IDS_SHIFT;
256 yyline++; 286 yyline++;
257 } 287 }
258 288
259<IGNORED>\n { 289<IGNORED>\n {
260 yyline++; 290 yyline++;
261 } 291 }
262 292
263<IGNORED>. /* ignore */ 293<IGNORED>. /* ignore */
264 294
265include[ \t]+{FILENAME}{RESTOFLINE} { 295include[ \t]+{FILENAME}{RESTOFLINE} {
266 yyline++; 296 yyline++;