summaryrefslogtreecommitdiff
path: root/flex_code_macros.m4
blob: a27a19e4f39153b0ba3fc51e0de0ab284f20da60 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#===================================================================
m4_dnl /* Generate the code to find the next compressed-table state. */
m4_define([[M4_GEN_NEXT_COMPRESSED_STATE]],
[[
	register YY_CHAR yy_c = $1;

m4_dnl	/* Save the backing-up info \before/ computing the next state
m4_dnl	 * because we always compute one more state than needed - we
m4_dnl	 * always proceed until we reach a jam state
m4_dnl	 */
M4_GEN_BACKING_UP()

	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
	{
		yy_current_state = (int) yy_def[yy_current_state];
    m4_ifdef([[M4_YY_META_ECS]],
    [[
m4_dnl		/* Templates are arranged so that they never chain
m4_dnl		 * to one another.  This means we can afford to make a
m4_dnl		 * very simple test to see if we need to convert to
m4_dnl		 * yy_c's meta-equivalence class without worrying
m4_dnl		 * about erroneously looking up the meta-equivalence
m4_dnl		 * class twice
m4_dnl		 */
m4_dnl		/* lastdfa + 2 is the beginning of the templates */
		if ( yy_current_state >= (YY_LASTDFA+2) )
			yy_c = yy_meta[(unsigned int) yy_c];
    ]])
	}
	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
]])
#===================================================================
m4_dnl /* Generate the code to find the start state. */
m4_define([[M4_GEN_START_STATE]],
[[
    m4_ifdef( [[M4_YY_FULLSPD]],
    [[
	m4_ifdef( [[M4_YY_BOL_NEEDED]],
	[[
		yy_current_state = yy_start_state_list[yy_start + YY_AT_BOL()];
	]],
	[[
		yy_current_state = yy_start_state_list[yy_start];
	]])
    ]],
    [[
		yy_current_state = yy_start;
	m4_ifdef( [[M4_YY_BOL_NEEDED]],
	[[
		yy_current_state += YY_AT_BOL();
	]])
	m4_ifdef( [[M4_YY_USES_REJECT]],[[m4_dnl /* Set up for storing up states. */
		yy_state_ptr = yy_state_buf;
		*yy_state_ptr++ = yy_current_state;
	]])
    ]])
]])
#===================================================================
m4_ifdef([[M4_YY_NEED_BACKING_UP]],
[[
    m4_define([[M4_GEN_BACKING_UP]],
    [[
	m4_ifdef( [[M4_YY_FULLSPD]],
	[[
	if ( yy_current_state[-1].yy_nxt )
	]],
	[[
	if ( yy_accept[yy_current_state] )
	]])
	{
		yy_last_accepting_state = yy_current_state;
		yy_last_accepting_cpos = yy_cp;
	}
    ]])
]],
[[
    m4_define([[M4_GEN_BACKING_UP]],[[]])
]])
#===================================================================
# Generate the code to find the next match.
# NOTE - changes in here should be reflected in gen_next_state() and
# gen_NUL_trans().
m4_ifdef([[M4_YY_ECS]],
[[
    m4_define([[M4_CHARMAP1]],[[yy_ec[YY_SC_TO_UI(*yy_cp)] ]])
    m4_define([[M4_CHARMAP2]],[[yy_ec[YY_SC_TO_UI(*(++yy_cp))] ]])
]],
[[
    m4_define([[M4_CHARMAP1]],[[YY_SC_TO_UI(*yy_cp)]])
    m4_define([[M4_CHARMAP2]],[[YY_SC_TO_UI(*(++yy_cp))]])
]])
#===================================================================
m4_define([[M4_GEN_NEXT_MATCH]],
[[
    m4_ifdef( [[M4_YY_FULLTBL]],
[[
	while ( (yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + ]]M4_CHARMAP1[[ ]) > 0 )
	{
M4_GEN_BACKING_UP()
		++yy_cp;
	}
	yy_current_state = -yy_current_state;
    ]],
    [[
	m4_ifdef([[M4_YY_FULLSPD]],
	[[
	{
		register const struct yy_trans_info *yy_trans_info;
		register YY_CHAR yy_c;
		for ( yy_c = M4_CHARMAP1;
		      (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->yy_verify == yy_c;
		      yy_c = M4_CHARMAP2)
		{
M4_GEN_BACKING_UP()
			yy_current_state += yy_trans_info->yy_nxt;
		}
	}
	]],[[ m4_dnl else COMPRESSED
	do {
M4_GEN_NEXT_STATE(0)
		++yy_cp;
	}
	    m4_ifdef([[M4_YY_INTERACTIVE]],
	    [[
		while ( yy_base[yy_current_state] != YY_JAMBASE );
	    ]],
	    [[
		while ( yy_current_state != YY_JAMSTATE );
		m4_ifdef([[M4_YY_USES_REJECT]],,
		[[
/* Do the guaranteed-needed backing up to figure out the match. */
		yy_cp = yy_last_accepting_cpos;
		yy_current_state = yy_last_accepting_state;
		]])
	    ]])
	]])
    ]])
]])
#===================================================================
m4_dnl /* Generate the code to find the action number. */
m4_define([[M4_GEN_FIND_ACTION_NUMBER]],
[[
    m4_if_elseif([[M4_YY_FULLSPD]],
    [[
		yy_act = yy_current_state[-1].yy_nxt;
    ]],
    [[M4_YY_FULLTBL]],
    [[
		yy_act = yy_accept[yy_current_state];
    ]],
    [[M4_YY_USES_REJECT]],
    [[
		yy_current_state = *--yy_state_ptr;
		yy_lp = yy_accept[yy_current_state];

find_rule: /* we branch to this label when backing up */

		for ( ; ; ) /* until we find what rule we matched */
		{

			if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )
			{
				yy_act = yy_acclist[yy_lp];

	m4_ifdef( [[M4_YY_VARIABLE_TRAILING_CONTEXT_RULES]],
	[[
				if ( yy_act & YY_TRAILING_HEAD_MASK ||
					yy_looking_for_trail_begin )
				{
					if ( yy_act == yy_looking_for_trail_begin )
					{
						yy_looking_for_trail_begin = 0;
						yy_act &= ~YY_TRAILING_HEAD_MASK;
						break;
					}
				}
				else if ( yy_act & YY_TRAILING_MASK )
				{
					yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;
					yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;

	    m4_ifdef([[M4_YY_REAL_REJECT]],
	    [[
		/* Remember matched text in case we back up
		 * due to REJECT.
		 */
					yy_full_match = yy_cp;
					yy_full_state = yy_state_ptr;
					yy_full_lp = yy_lp;
	    ]])
				}
				else
				{
					yy_full_match = yy_cp;
					yy_full_state = yy_state_ptr;
					yy_full_lp = yy_lp;
					break;
				}

				++yy_lp;
				goto find_rule;

			}
	]],
	[[
		/* Remember matched text in case we back up due to
		 * trailing context plus REJECT.
		 */
			{
				yy_full_match = yy_cp;
				break;
			}
	]])

		}
		--yy_cp;

	/* We could consolidate the following two lines with those at
	 * the beginning, but at the cost of complaints that we're
	 * branching inside a loop.
	 */
		yy_current_state = *--yy_state_ptr;
		yy_lp = yy_accept[yy_current_state];
	}
    ]],
    [[m4_dnl else compressed, no reject
		yy_act = yy_accept[yy_current_state];
	m4_ifdef([[M4_YY_INTERACTIVE]],
	[[
m4_dnl		/* Do the guaranteed-needed backing up to figure out
m4_dnl		 * the match.
m4_dnl		 */
		if ( yy_act == 0 )
		{ /* have to back up */
			yy_cp = yy_last_accepting_cpos;
			yy_current_state = yy_last_accepting_state;
			yy_act = yy_accept[yy_current_state];
		}
	]])
    ]])
]])

#===================================================================
m4_dnl /* Generate the code to find the next state. */
m4_dnl /* NOTE - changes in here should be reflected in gen_next_match() */
# M4_GEN_NEXT_STATE(bool worry_about_NULs)
# ----------------------------------------
m4_define([[M4_GEN_NEXT_STATE]],
[[
    m4_if(($1 && !m4_defined([[M4_YY_NULTRANS]])),
    [[
	m4_ifdef([[M4_YY_ECS]],
	[[
	    m4_define([[M4_CHARMAP]],[[(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : YY_NUL_EC)]])
	]],
	[[
	    m4_define([[M4_CHARMAP]],[[(*yy_cp ? YY_SC_TO_UI(*yy_cp) : YY_NUL_EC)]])
	]])
    ]],
    [[
	m4_ifdef([[M4_YY_ECS]],
	[[
	    m4_define([[M4_CHARMAP]],[[yy_ec[YY_SC_TO_UI(*yy_cp)] ]])
	]],
	[[
	    m4_define([[M4_CHARMAP]],[[YY_SC_TO_UI(*yy_cp)]])
	]])
    ]])
    m4_if(($1 && m4_defined([[M4_YY_NULTRANS]])),
    [[
	m4_ifdef([[M4_YY_COMPRESSED]],
	[[
m4_dnl		/* Compressed tables back up *before* they match. */
M4_GEN_BACKING_UP()
	]])
	if ( *yy_cp )
	{
    ]])
    m4_ifdef([[M4_YY_FULLTBL]],
    [[
	yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + M4_CHARMAP];
    ]],
    [[
	m4_ifdef([[M4_YY_FULLSPD]],
	[[
		yy_current_state += yy_current_state[M4_CHARMAP].yy_nxt;
	]],
	[[
M4_GEN_NEXT_COMPRESSED_STATE(M4_CHARMAP)
	]])
    ]])
    m4_if(($1 && m4_defined([[M4_YY_NULTRANS]])),
    [[
	}
	else
		yy_current_state = yy_nul_trans[yy_current_state];
    ]])
    m4_ifdef([[M4_YY_COMPRESSED]],,
    [[
M4_GEN_BACKING_UP()
    ]])
    m4_ifdef([[M4_YY_USES_REJECT]],
[[
		*yy_state_ptr++ = yy_current_state;
    ]])
]])

#===================================================================
m4_dnl /* Generate the code to make a NUL transition. */
m4_dnl /* NOTE - changes in here should be reflected in gen_next_match()
m4_dnl  * Only generate a definition for "yy_cp" if we'll generate code
m4_dnl  * that uses it.  Otherwise lint and the like complain.
m4_dnl  */
m4_define([[M4_GEN_NUL_TRANSITION]],
[[
    m4_if((m4_defined([[M4_YY_NEED_BACKING_UP]]) && (!m4_defined([[M4_YY_NULTRANS]]) ||
	    m4_defined([[M4_YY_FULLSPD]]) || m4_defined([[M4_YY_FULLTBL]]))),
    [[
m4_dnl /* We're going to need yy_cp lying around for the call
m4_dnl  * below to gen_backing_up().
m4_dnl  */
	register char *yy_cp = yy_c_buf_p;
    ]])

    m4_if_elseif([[M4_YY_NULTRANS]],
    [[
	yy_current_state = yy_nul_trans[yy_current_state];
	yy_is_jam = (yy_current_state == 0);
    ]],[[M4_YY_FULLTBL]],
    [[
	yy_current_state = yy_nxt[yy_current_state*YY_NXT_LOLEN + YY_NUL_EC];
	yy_is_jam = (yy_current_state <= 0);
    ]],[[M4_YY_FULLSPD]],
    [[
	register int yy_c = YY_NUL_EC;
	register const struct yy_trans_info *yy_trans_info;
	yy_trans_info = &yy_current_state[(unsigned int) yy_c];
	yy_current_state += yy_trans_info->yy_nxt;
	yy_is_jam = (yy_trans_info->yy_verify != yy_c);
    ]],
    [[
M4_GEN_NEXT_COMPRESSED_STATE([[YY_NUL_EC]])
	yy_is_jam = (yy_current_state == YY_JAMSTATE);
	m4_ifdef([[M4_YY_REJECT]],
	[[
m4_dnl /* Only stack this state if it's a transition we
m4_dnl * actually make.  If we stack it on a jam, then
m4_dnl * the state stack and yy_c_buf_p get out of sync.
m4_dnl */
	if ( ! yy_is_jam )
		*yy_state_ptr++ = yy_current_state;
	]])
    ]])
m4_dnl /* If we've entered an accepting state, back up; note that
m4_dnl * compressed tables have *already* done such backing up, so
m4_dnl * we needn't bother with it again.
m4_dnl */
    m4_if((m4_defined([[M4_YY_NEED_BACKING_UP]]) && !m4_defined([[M4_YY_COMPRESSED]])),
    [[
	if ( ! yy_is_jam )
	{
M4_GEN_BACKING_UP()
	}
    ]])
]])

m4_dnl Define the default C code for YY_INPUT:
m4_ifdef( [[M4_YY_USE_READ]],
[[
    m4_define([[M4_YY_INPUT]],
    [[
	errno=0; 
	while ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 )
		{
		if ( errno != EINTR)
			{
			YY_FATAL_ERROR("input in flex scanner failed");
			break;
			}
		errno=0;
		clearerr(yyin);
		}
    ]])
]],
[[
    m4_define([[M4_YY_INPUT]],
    [[
	if ( YY_CURRENT_BUFFER->is_interactive )
		{
		int c = '*';
		int n;
		for( n = 0; n < (int)max_size &&
			     (c = getc( yyin )) != EOF && c != '\n'; ++n )
			buf[n] = (char) c;
		if ( c == '\n' )
			buf[n++] = (char) c;
		if ( c == EOF && ferror( yyin ) )
			YY_FATAL_ERROR("input in flex scanner failed");
		result = n;
		}
	else
		{
		errno=0;
		while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin))
			{
			if ( errno != EINTR)
				{
				YY_FATAL_ERROR("input in flex scanner failed");
				break;
				}
			errno=0;
			clearerr(yyin);
			}
		}
    ]])
]])
#===================================================================