summaryrefslogtreecommitdiff
path: root/test/rlhc.d/case/mailbox1.cpp-C-F0--goto-backend.in
blob: b5d2c125e328cced0c7bd583fab658097f0edcce (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
host( "working/mailbox1.rl", 1 ) @{/*
	* @@LANG: c++
	* @@CFLAGS: -I../aapl
	*
	* Test works with split code gen.
	*/
	
	/*
	* Parses unix mail boxes into headers and bodies.
	*/
	
	#include "mailbox1.h"
	
	#ifdef PERF_TEST
	
	/* Calibrated to 1s on yoho. */
	#define perf_iters ( 134408ll * S )
	
	int _perf_dummy = 0;
	#define perf_printf(...) ( _perf_dummy += 1 )
	#define perf_loop long _pi; for ( _pi = 0; _pi < perf_iters; _pi++ )
	
	#else
	
	#define perf_printf(...) printf( __VA_ARGS__ )
	#define perf_loop
	
	#endif
	
	
	
}@
array s8 _MBox_actions( 0, 4 ) = { 0, 1, 0, 1, 1, 1, 3, 1, 4, 2, 2, 0, 2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4, 4, 4, 4, 0 };

array s16 _MBox_index_offsets( 0, 700 ) = { 0, 0, 1, 2, 3, 4, 7, 16, 29, 42, 45, 54, 67, 80, 83, 92, 101, 104, 113, 119, 126, 132, 138, 145, 154, 160, 166, 172, 178, 181, 190, 196, 202, 208, 211, 224, 225, 226, 239, 251, 262, 265, 268, 277, 290, 303, 306, 315, 328, 341, 344, 353, 362, 365, 374, 380, 387, 393, 399, 406, 415, 421, 427, 433, 439, 442, 451, 457, 463, 469, 472, 478, 484, 490, 493, 502, 508, 521, 530, 543, 552, 558, 564, 567, 573, 583, 584, 598, 604, 610, 616, 619, 628, 634, 647, 656, 669, 678, 684, 690, 693, 699, 700, 0 };

array s8 _MBox_indicies( 0, 105 ) = { 0, 2, 3, 4, 1, 4, 5, 1, 4, 5, 4, 4, 4, 4, 6, 6, 1, 4, 5, 4, 4, 4, 4, 4, 4, 7, 7, 7, 7, 1, 4, 5, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 1, 4, 9, 1, 4, 5, 4, 4, 4, 4, 10, 10, 1, 4, 5, 4, 4, 4, 4, 4, 4, 11, 11, 11, 11, 1, 4, 5, 4, 4, 4, 4, 4, 4, 12, 12, 12, 12, 1, 4, 13, 1, 4, 14, 4, 4, 15, 4, 10, 10, 1, 4, 5, 4, 4, 16, 4, 6, 6, 1, 4, 17, 1, 4, 5, 4, 4, 18, 4, 6, 6, 1, 4, 5, 4, 4, 19, 1, 4, 5, 4, 4, 4, 20, 1, 4, 5, 4, 4, 21, 1, 4, 5, 4, 4, 22, 1, 4, 23, 4, 4, 4, 24, 1, 4, 5, 4, 25, 26, 4, 27, 27, 1, 4, 5, 4, 4, 28, 1, 4, 5, 4, 4, 29, 1, 4, 5, 4, 4, 30, 1, 4, 5, 4, 4, 31, 1, 4, 32, 1, 4, 5, 4, 4, 33, 4, 6, 6, 1, 4, 5, 4, 4, 34, 1, 4, 5, 4, 4, 35, 1, 4, 5, 4, 4, 36, 37, 4, 5, 38, 1, 1, 39, 39, 39, 1, 39, 39, 39, 39, 39, 39, 41, 42, 42, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 43, 42, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 44, 42, 40, 40, 40, 40, 40, 40, 40, 40, 40, 45, 42, 40, 46, 42, 46, 47, 42, 46, 47, 46, 46, 46, 46, 48, 48, 42, 46, 47, 46, 46, 46, 46, 46, 46, 49, 49, 49, 49, 42, 46, 47, 46, 46, 46, 46, 46, 46, 50, 50, 50, 50, 42, 46, 51, 42, 46, 47, 46, 46, 46, 46, 52, 52, 42, 46, 47, 46, 46, 46, 46, 46, 46, 53, 53, 53, 53, 42, 46, 47, 46, 46, 46, 46, 46, 46, 54, 54, 54, 54, 42, 46, 55, 42, 46, 56, 46, 46, 57, 46, 52, 52, 42, 46, 47, 46, 46, 58, 46, 48, 48, 42, 46, 59, 42, 46, 47, 46, 46, 60, 46, 48, 48, 42, 46, 47, 46, 46, 61, 42, 46, 47, 46, 46, 46, 62, 42, 46, 47, 46, 46, 63, 42, 46, 47, 46, 46, 64, 42, 46, 65, 46, 46, 46, 66, 42, 46, 47, 46, 67, 68, 46, 69, 69, 42, 46, 47, 46, 46, 70, 42, 46, 47, 46, 46, 71, 42, 46, 47, 46, 46, 72, 42, 46, 47, 46, 46, 73, 42, 46, 74, 42, 46, 47, 46, 46, 75, 46, 48, 48, 42, 46, 47, 46, 46, 76, 42, 46, 47, 46, 46, 77, 42, 46, 47, 46, 46, 78, 37, 46, 47, 42, 46, 47, 46, 46, 79, 42, 46, 47, 46, 46, 80, 42, 46, 47, 46, 46, 81, 37, 46, 82, 42, 46, 47, 46, 83, 46, 46, 84, 84, 42, 46, 47, 46, 46, 75, 42, 46, 47, 46, 46, 46, 46, 85, 85, 49, 49, 49, 49, 42, 46, 47, 46, 46, 46, 46, 78, 78, 42, 46, 47, 46, 46, 46, 46, 86, 86, 49, 49, 49, 49, 42, 46, 47, 46, 46, 46, 46, 73, 73, 42, 46, 47, 46, 46, 87, 42, 46, 47, 46, 46, 88, 42, 46, 65, 42, 46, 47, 46, 46, 58, 39, 39, 39, 89, 39, 39, 39, 39, 39, 39, 91, 90, 92, 1, 90, 93, 93, 93, 1, 93, 93, 93, 93, 93, 93, 1, 4, 5, 4, 4, 94, 1, 4, 5, 4, 4, 95, 1, 4, 5, 4, 4, 96, 37, 4, 97, 1, 4, 5, 4, 98, 4, 4, 99, 99, 1, 4, 5, 4, 4, 33, 1, 4, 5, 4, 4, 4, 4, 100, 100, 7, 7, 7, 7, 1, 4, 5, 4, 4, 4, 4, 36, 36, 1, 4, 5, 4, 4, 4, 4, 101, 101, 7, 7, 7, 7, 1, 4, 5, 4, 4, 4, 4, 31, 31, 1, 4, 5, 4, 4, 102, 1, 4, 5, 4, 4, 103, 1, 4, 23, 1, 4, 5, 4, 4, 16, 104, 41, 40, 40, 40, 40, 40, 40, 40, 105, 0 };

array s8 _MBox_index_defaults( 0, 90 ) = { 0, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 40, 40, 40, 40, 40, 40, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 1, 90, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 40, 0 };

array s8 _MBox_trans_cond_spaces( -1, 0 ) = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 };

array s8 _MBox_cond_targs( 0, 102 ) = { 2, 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 16, 17, 18, 19, 20, 21, 22, 23, 97, 24, 87, 95, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 84, 36, 102, 35, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 83, 52, 53, 54, 55, 56, 57, 58, 59, 80, 60, 70, 78, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 79, 81, 82, 85, 85, 86, 35, 84, 88, 89, 90, 91, 92, 93, 94, 96, 98, 99, 1, 37, 0 };

array s8 _MBox_cond_actions( 0, 12 ) = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 12, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

array s8 _MBox_nfa_targs( 0, 0 ) = { 0, 0 };

array s8 _MBox_nfa_offsets( 0, 0 ) = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

array s8 _MBox_nfa_push_actions( 0, 0 ) = { 0, 0 };

array s8 _MBox_nfa_pop_trans( 0, 0 ) = { 0, 0 };

value int MBox_start = 101;
value int MBox_first_final = 101;
value int MBox_error = 0;

value int MBox_en_main = 101;

host( "working/mailbox1.rl", 111 ) @{
	
	void MBox::execute( const char *data, int len )
	{
		perf_loop
		{
			const char *p = data;
			const char *pe = data + len;
		}@
		{
			host( "-", 1 ) @{this->}@ -> cs = cast(int)MBox_start;
		}
		
		{
			int _trans = 0;
			index s8 _acts;
			uint _nacts;
			index char _keys;
			index s8 _inds;
			entry {
				
				if ( p == pe )
				goto _test_eof;
				if ( host( "-", 1 ) @{this->}@ -> cs == 0 )
				goto _out;
				label _resume {
					_keys = offset( _MBox_trans_keys, (host( "-", 1 ) @{this->}@ -> cs<<1) );
					_inds = offset( _MBox_indicies, _MBox_index_offsets[host( "-", 1 ) @{this->}@ -> cs] );
					
					if ( ( deref( data, p )) <= 126 && ( deref( data, p )) >= 9 )
					{
						int _ic = cast(int)_MBox_char_class[cast(int)( deref( data, p )) - 9];
						if ( _ic <= cast(int)deref( _MBox_trans_keys, _keys+1 ) && _ic >= cast(int)deref( _MBox_trans_keys, _keys ) )
						_trans = cast(int)deref( _MBox_indicies, _inds + cast(int)( _ic - cast(int)deref( _MBox_trans_keys, _keys ) )  ); 
						else
						_trans = cast(int)_MBox_index_defaults[host( "-", 1 ) @{this->}@ -> cs];
					}
					else {
						_trans = cast(int)_MBox_index_defaults[host( "-", 1 ) @{this->}@ -> cs];
					}
					
					goto _match_cond;
				}
				label _match_cond {
					host( "-", 1 ) @{this->}@ -> cs = cast(int)_MBox_cond_targs[_trans];
					
					if ( _MBox_cond_actions[_trans] == 0 )
					goto _again;
					
					_acts = offset( _MBox_actions, _MBox_cond_actions[_trans] );
					_nacts = cast(uint)deref( _MBox_actions, _acts );
					_acts += 1;
					while ( _nacts > 0 ) {
						switch ( deref( _MBox_actions, _acts ) )
						{
							case 0 {
								host( "working/mailbox1.rl", 34 ) ${ headName.append(={( deref( data, p ))}=); }$
							}
							case 1 {
								host( "working/mailbox1.rl", 37 ) ${ headContent.append(={( deref( data, p ))}=); }$
							}
							case 2 {
								host( "working/mailbox1.rl", 40 ) ${
									/* Terminate the buffers. */
									headName.append(0);
									headContent.append(0);
									
									/* Print the header. Interesting headers. */
									perf_printf("%s:%s\n", headName.data, headContent.data);
									
									/* Clear for the next time we use them. */
									headName.clear();
									headContent.clear();
								}$
							}
							case 3 {
								host( "working/mailbox1.rl", 53 ) ${
									perf_printf("NEW MESSAGE\n");
								}$
							}
							case 4 {
								host( "working/mailbox1.rl", 58 ) ${
									perf_printf("\n");
								}$
							}
						}
						_nacts -= 1;
						_acts += 1;
					}
					
					
				}
				label _again {
					if ( host( "-", 1 ) @{this->}@ -> cs == 0 )
					goto _out;
					p += 1;
					if ( p != pe )
					goto _resume;
				}
				label _test_eof { {}
				}
				label _out { {}
				}
			}
		}
		host( "working/mailbox1.rl", 122 ) @{
		}
	}
	
	int MBox::finish( )
	{
		if ( cs == MBox_error )
		return -1;
		if ( cs >= MBox_first_final )
		return 1;
		return 0;
	}
	
	MBox mbox;
	
	void test( const char *buf )
	{
		int len = strlen( buf );
		mbox.execute( buf, len );
		if ( mbox.finish() > 0 ) {
			perf_printf("ACCEPT\n");
		}
		else {
			perf_printf("FAIL\n");
		}
	}
	
	
	int main()
	{
		test(
		"From email address goes here Wed Nov 28 13:30:05 2001 -0500\n"
		"Header1: this is the header contents\n"
		" there is more on the second line\n"
		"	and more on the third line.\n"
		"Header2: slkdj\n"
		"\n"
		"This is the message data\n"
		"\n"
		"From email Wed Nov 28 13:30:05 2001 -0500\n"
		"Header: \n"
		"\n"
		"mail message\n"
		"\n"
		);
		
		test(
		"From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"\n"
		"There are no headers. \n"
		"\n"
		"From email Wed Nov 28 13:30:05 EST 2000\n"
		"\n"
		"There are no headers.\n"
		"\n"
		);
		
		test(
		"From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"Header:alsdj\n"
		"\n"
		"Header:\n"
		"salkfj\n"
		"\n"
		"There are no headers. \n"
		"\n"
		);
		
		test(
		"From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"Header:alsdj\n"
		"\n"
		"Header:\n"
		"salkfj\n"
		"\n"
		"There are no headers. \n"
		"\n"
		">From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"\n"
		);
		
		test(
		"From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"Header:alsdj\n"
		"\n"
		"Header:\n"
		"salkfj\n"
		"\n"
		"There are no headers. \n"
		"\n"
		"From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"\n"
		);
		
		test(
		"From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"Header:alsdj\n"
		"\n"
		"Header:\n"
		"salkfj\n"
		"\n"
		"There are no headers. \n"
		"\n"
		"From user@@host.dom Wed Nov 28 13:30:05 2001\n"
		"\n"
		"\n"
		);
		
		return 0;
	}
	
}@