blob: 4a57647741d07ed6575a13ade5ef427d2c153f66 [file] [log] [blame]
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001#line 16 "./Tokenizer.l"
2//
3// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// This file is auto-generated by generate_parser.sh. DO NOT EDIT!
9
10
11
12#line 13 "./Tokenizer.cpp"
13
14#define YY_INT_ALIGNED short int
15
16/* A lexical scanner generated by flex */
17
18#define FLEX_SCANNER
19#define YY_FLEX_MAJOR_VERSION 2
20#define YY_FLEX_MINOR_VERSION 5
21#define YY_FLEX_SUBMINOR_VERSION 35
22#if YY_FLEX_SUBMINOR_VERSION > 0
23#define FLEX_BETA
24#endif
25
26/* First, we deal with platform-specific or compiler-specific issues. */
27
28/* begin standard C headers. */
29#include <stdio.h>
30#include <string.h>
31#include <errno.h>
32#include <stdlib.h>
33
34/* end standard C headers. */
35
36/* flex integer type definitions */
37
38#ifndef FLEXINT_H
39#define FLEXINT_H
40
41/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
42
43#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
44
45/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
46 * if you want the limit (max/min) macros for int types.
47 */
48#ifndef __STDC_LIMIT_MACROS
49#define __STDC_LIMIT_MACROS 1
50#endif
51
52#include <inttypes.h>
53typedef int8_t flex_int8_t;
54typedef uint8_t flex_uint8_t;
55typedef int16_t flex_int16_t;
56typedef uint16_t flex_uint16_t;
57typedef int32_t flex_int32_t;
58typedef uint32_t flex_uint32_t;
daniel@transgaming.comb3077d02013-01-11 04:12:09 +000059typedef uint64_t flex_uint64_t;
alokp@chromium.org04d7d222012-05-16 19:24:07 +000060#else
61typedef signed char flex_int8_t;
62typedef short int flex_int16_t;
63typedef int flex_int32_t;
64typedef unsigned char flex_uint8_t;
65typedef unsigned short int flex_uint16_t;
66typedef unsigned int flex_uint32_t;
67#endif /* ! C99 */
68
69/* Limits of integral types. */
70#ifndef INT8_MIN
71#define INT8_MIN (-128)
72#endif
73#ifndef INT16_MIN
74#define INT16_MIN (-32767-1)
75#endif
76#ifndef INT32_MIN
77#define INT32_MIN (-2147483647-1)
78#endif
79#ifndef INT8_MAX
80#define INT8_MAX (127)
81#endif
82#ifndef INT16_MAX
83#define INT16_MAX (32767)
84#endif
85#ifndef INT32_MAX
86#define INT32_MAX (2147483647)
87#endif
88#ifndef UINT8_MAX
89#define UINT8_MAX (255U)
90#endif
91#ifndef UINT16_MAX
92#define UINT16_MAX (65535U)
93#endif
94#ifndef UINT32_MAX
95#define UINT32_MAX (4294967295U)
96#endif
97
98#endif /* ! FLEXINT_H */
99
100#ifdef __cplusplus
101
102/* The "const" storage-class-modifier is valid. */
103#define YY_USE_CONST
104
105#else /* ! __cplusplus */
106
107/* C99 requires __STDC__ to be defined as 1. */
108#if defined (__STDC__)
109
110#define YY_USE_CONST
111
112#endif /* defined (__STDC__) */
113#endif /* ! __cplusplus */
114
115#ifdef YY_USE_CONST
116#define yyconst const
117#else
118#define yyconst
119#endif
120
121/* Returned upon end-of-file. */
122#define YY_NULL 0
123
124/* Promotes a possibly negative, possibly signed char to an unsigned
125 * integer for use as an array index. If the signed char is negative,
126 * we want to instead treat it as an 8-bit unsigned char, hence the
127 * double cast.
128 */
129#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
130
131/* An opaque pointer. */
132#ifndef YY_TYPEDEF_YY_SCANNER_T
133#define YY_TYPEDEF_YY_SCANNER_T
134typedef void* yyscan_t;
135#endif
136
137/* For convenience, these vars (plus the bison vars far below)
138 are macros in the reentrant scanner. */
139#define yyin yyg->yyin_r
140#define yyout yyg->yyout_r
141#define yyextra yyg->yyextra_r
142#define yyleng yyg->yyleng_r
143#define yytext yyg->yytext_r
144#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
145#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
146#define yy_flex_debug yyg->yy_flex_debug_r
147
148/* Enter a start condition. This macro really ought to take a parameter,
149 * but we do it the disgusting crufty way forced on us by the ()-less
150 * definition of BEGIN.
151 */
152#define BEGIN yyg->yy_start = 1 + 2 *
153
154/* Translate the current start state into a value that can be later handed
155 * to BEGIN to return to the state. The YYSTATE alias is for lex
156 * compatibility.
157 */
158#define YY_START ((yyg->yy_start - 1) / 2)
159#define YYSTATE YY_START
160
161/* Action number for EOF rule of a given start state. */
162#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
163
164/* Special action meaning "start processing a new file". */
165#define YY_NEW_FILE pprestart(yyin ,yyscanner )
166
167#define YY_END_OF_BUFFER_CHAR 0
168
169/* Size of default input buffer. */
170#ifndef YY_BUF_SIZE
171#define YY_BUF_SIZE 16384
172#endif
173
174/* The state buf must be large enough to hold one state per character in the main buffer.
175 */
176#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
177
178#ifndef YY_TYPEDEF_YY_BUFFER_STATE
179#define YY_TYPEDEF_YY_BUFFER_STATE
180typedef struct yy_buffer_state *YY_BUFFER_STATE;
181#endif
182
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000183#ifndef YY_TYPEDEF_YY_SIZE_T
184#define YY_TYPEDEF_YY_SIZE_T
185typedef size_t yy_size_t;
186#endif
187
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000188#define EOB_ACT_CONTINUE_SCAN 0
189#define EOB_ACT_END_OF_FILE 1
190#define EOB_ACT_LAST_MATCH 2
191
192 #define YY_LESS_LINENO(n)
193
194/* Return all but the first "n" matched characters back to the input stream. */
195#define yyless(n) \
196 do \
197 { \
198 /* Undo effects of setting up yytext. */ \
199 int yyless_macro_arg = (n); \
200 YY_LESS_LINENO(yyless_macro_arg);\
201 *yy_cp = yyg->yy_hold_char; \
202 YY_RESTORE_YY_MORE_OFFSET \
203 yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
204 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
205 } \
206 while ( 0 )
207
208#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
209
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000210#ifndef YY_STRUCT_YY_BUFFER_STATE
211#define YY_STRUCT_YY_BUFFER_STATE
212struct yy_buffer_state
213 {
214 FILE *yy_input_file;
215
216 char *yy_ch_buf; /* input buffer */
217 char *yy_buf_pos; /* current position in input buffer */
218
219 /* Size of input buffer in bytes, not including room for EOB
220 * characters.
221 */
222 yy_size_t yy_buf_size;
223
224 /* Number of characters read into yy_ch_buf, not including EOB
225 * characters.
226 */
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000227 yy_size_t yy_n_chars;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000228
229 /* Whether we "own" the buffer - i.e., we know we created it,
230 * and can realloc() it to grow it, and should free() it to
231 * delete it.
232 */
233 int yy_is_our_buffer;
234
235 /* Whether this is an "interactive" input source; if so, and
236 * if we're using stdio for input, then we want to use getc()
237 * instead of fread(), to make sure we stop fetching input after
238 * each newline.
239 */
240 int yy_is_interactive;
241
242 /* Whether we're considered to be at the beginning of a line.
243 * If so, '^' rules will be active on the next match, otherwise
244 * not.
245 */
246 int yy_at_bol;
247
248 int yy_bs_lineno; /**< The line count. */
249 int yy_bs_column; /**< The column count. */
250
251 /* Whether to try to fill the input buffer when we reach the
252 * end of it.
253 */
254 int yy_fill_buffer;
255
256 int yy_buffer_status;
257
258#define YY_BUFFER_NEW 0
259#define YY_BUFFER_NORMAL 1
260 /* When an EOF's been seen but there's still some text to process
261 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
262 * shouldn't try reading from the input source any more. We might
263 * still have a bunch of tokens to match, though, because of
264 * possible backing-up.
265 *
266 * When we actually see the EOF, we change the status to "new"
267 * (via pprestart()), so that the user can continue scanning by
268 * just pointing yyin at a new input file.
269 */
270#define YY_BUFFER_EOF_PENDING 2
271
272 };
273#endif /* !YY_STRUCT_YY_BUFFER_STATE */
274
275/* We provide macros for accessing buffer states in case in the
276 * future we want to put the buffer states in a more general
277 * "scanner state".
278 *
279 * Returns the top of the stack, or NULL.
280 */
281#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
282 ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
283 : NULL)
284
285/* Same as previous macro, but useful when we know that the buffer stack is not
286 * NULL or when we need an lvalue. For internal use only.
287 */
288#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
289
290void pprestart (FILE *input_file ,yyscan_t yyscanner );
291void pp_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
292YY_BUFFER_STATE pp_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
293void pp_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
294void pp_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
295void pppush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
296void pppop_buffer_state (yyscan_t yyscanner );
297
298static void ppensure_buffer_stack (yyscan_t yyscanner );
299static void pp_load_buffer_state (yyscan_t yyscanner );
300static void pp_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
301
302#define YY_FLUSH_BUFFER pp_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
303
304YY_BUFFER_STATE pp_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
305YY_BUFFER_STATE pp_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000306YY_BUFFER_STATE pp_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000307
308void *ppalloc (yy_size_t ,yyscan_t yyscanner );
309void *pprealloc (void *,yy_size_t ,yyscan_t yyscanner );
310void ppfree (void * ,yyscan_t yyscanner );
311
312#define yy_new_buffer pp_create_buffer
313
314#define yy_set_interactive(is_interactive) \
315 { \
316 if ( ! YY_CURRENT_BUFFER ){ \
317 ppensure_buffer_stack (yyscanner); \
318 YY_CURRENT_BUFFER_LVALUE = \
319 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
320 } \
321 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
322 }
323
324#define yy_set_bol(at_bol) \
325 { \
326 if ( ! YY_CURRENT_BUFFER ){\
327 ppensure_buffer_stack (yyscanner); \
328 YY_CURRENT_BUFFER_LVALUE = \
329 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
330 } \
331 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
332 }
333
334#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
335
336/* Begin user sect3 */
337
338#define ppwrap(n) 1
339#define YY_SKIP_YYWRAP
340
341typedef unsigned char YY_CHAR;
342
343typedef int yy_state_type;
344
345#define yytext_ptr yytext_r
346
347static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
348static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
349static int yy_get_next_buffer (yyscan_t yyscanner );
350static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
351
352/* Done after the current pattern has been matched and before the
353 * corresponding action - sets up yytext.
354 */
355#define YY_DO_BEFORE_ACTION \
356 yyg->yytext_ptr = yy_bp; \
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000357 yyleng = (yy_size_t) (yy_cp - yy_bp); \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000358 yyg->yy_hold_char = *yy_cp; \
359 *yy_cp = '\0'; \
360 yyg->yy_c_buf_p = yy_cp;
361
362#define YY_NUM_RULES 37
363#define YY_END_OF_BUFFER 38
364/* This struct is not used in this scanner,
365 but its presence is necessary. */
366struct yy_trans_info
367 {
368 flex_int32_t yy_verify;
369 flex_int32_t yy_nxt;
370 };
371static yyconst flex_int16_t yy_accept[84] =
372 { 0,
373 0, 0, 0, 0, 38, 36, 34, 35, 35, 33,
374 7, 33, 33, 33, 33, 33, 33, 33, 33, 9,
375 9, 33, 33, 33, 8, 33, 33, 3, 5, 5,
376 4, 34, 35, 19, 27, 20, 30, 25, 12, 23,
377 13, 24, 10, 2, 1, 26, 10, 9, 11, 11,
378 11, 11, 9, 14, 16, 18, 17, 15, 8, 31,
379 21, 32, 22, 3, 5, 6, 11, 10, 11, 1,
380 10, 11, 0, 10, 9, 28, 29, 0, 10, 10,
381 10, 10, 0
382 } ;
383
384static yyconst flex_int32_t yy_ec[256] =
385 { 0,
386 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
387 2, 2, 4, 1, 1, 1, 1, 1, 1, 1,
388 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
389 1, 2, 5, 1, 6, 1, 7, 8, 1, 9,
390 9, 10, 11, 9, 12, 13, 14, 15, 16, 16,
391 16, 16, 16, 16, 16, 17, 17, 9, 9, 18,
392 19, 20, 9, 1, 21, 21, 21, 21, 22, 21,
393 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
394 23, 23, 23, 23, 23, 23, 23, 24, 23, 23,
395 9, 1, 9, 25, 23, 1, 21, 21, 21, 21,
396
397 22, 21, 23, 23, 23, 23, 23, 23, 23, 23,
398 23, 23, 23, 23, 23, 23, 23, 23, 23, 24,
399 23, 23, 9, 26, 9, 9, 1, 1, 1, 1,
400 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
401 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
402 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
403 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
404 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
405 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
406 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
407
408 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
409 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
410 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
411 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
412 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
413 1, 1, 1, 1, 1
414 } ;
415
416static yyconst flex_int32_t yy_meta[27] =
417 { 0,
418 1, 1, 2, 2, 1, 1, 1, 1, 1, 3,
419 1, 1, 4, 1, 5, 5, 5, 1, 1, 1,
420 5, 5, 5, 5, 1, 1
421 } ;
422
423static yyconst flex_int16_t yy_base[89] =
424 { 0,
425 0, 0, 24, 26, 158, 159, 150, 159, 145, 128,
426 159, 112, 23, 159, 111, 21, 25, 30, 29, 36,
427 46, 36, 100, 45, 0, 16, 47, 0, 159, 84,
428 65, 73, 159, 159, 159, 159, 159, 159, 159, 159,
429 159, 159, 61, 159, 0, 159, 73, 32, 56, 83,
430 95, 68, 0, 31, 159, 159, 159, 19, 0, 159,
431 159, 159, 159, 0, 159, 159, 98, 0, 110, 0,
432 0, 117, 52, 90, 80, 159, 159, 101, 97, 112,
433 120, 123, 159, 140, 28, 145, 150, 152
434 } ;
435
436static yyconst flex_int16_t yy_def[89] =
437 { 0,
438 83, 1, 84, 84, 83, 83, 83, 83, 83, 83,
439 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
440 20, 83, 83, 83, 85, 83, 83, 86, 83, 83,
441 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
442 83, 83, 83, 83, 87, 83, 83, 20, 20, 47,
443 50, 88, 21, 83, 83, 83, 83, 83, 85, 83,
444 83, 83, 83, 86, 83, 83, 43, 43, 67, 87,
445 47, 50, 83, 51, 88, 83, 83, 83, 69, 72,
446 83, 83, 0, 83, 83, 83, 83, 83
447 } ;
448
449static yyconst flex_int16_t yy_nxt[186] =
450 { 0,
451 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
452 16, 17, 18, 19, 20, 21, 21, 22, 23, 24,
453 25, 25, 25, 25, 26, 27, 29, 30, 29, 30,
454 36, 39, 59, 31, 60, 31, 41, 77, 44, 40,
455 61, 37, 45, 42, 43, 43, 43, 46, 47, 76,
456 48, 48, 49, 54, 55, 50, 50, 51, 50, 52,
457 53, 53, 53, 57, 58, 62, 81, 81, 81, 50,
458 49, 49, 63, 67, 32, 68, 68, 68, 66, 50,
459 50, 67, 69, 67, 67, 50, 65, 71, 71, 71,
460 50, 50, 50, 50, 72, 50, 50, 50, 50, 50,
461
462 83, 83, 50, 50, 50, 73, 73, 83, 83, 74,
463 74, 74, 67, 67, 67, 82, 82, 82, 56, 67,
464 78, 78, 83, 83, 79, 79, 79, 78, 78, 38,
465 35, 80, 80, 80, 81, 81, 81, 82, 82, 82,
466 28, 28, 28, 28, 28, 64, 34, 33, 64, 64,
467 70, 32, 70, 70, 70, 75, 75, 83, 5, 83,
468 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
469 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
470 83, 83, 83, 83, 83
471 } ;
472
473static yyconst flex_int16_t yy_chk[186] =
474 { 0,
475 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
476 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
477 1, 1, 1, 1, 1, 1, 3, 3, 4, 4,
478 13, 16, 85, 3, 26, 4, 17, 58, 19, 16,
479 26, 13, 19, 17, 18, 18, 18, 19, 20, 54,
480 20, 20, 20, 22, 22, 48, 20, 20, 20, 20,
481 21, 21, 21, 24, 24, 27, 73, 73, 73, 21,
482 49, 49, 27, 43, 32, 43, 43, 43, 31, 49,
483 52, 43, 43, 43, 43, 47, 30, 47, 47, 47,
484 52, 52, 75, 47, 47, 47, 47, 50, 50, 50,
485
486 74, 74, 75, 75, 50, 51, 51, 79, 79, 51,
487 51, 51, 67, 67, 67, 78, 78, 78, 23, 67,
488 69, 69, 80, 80, 69, 69, 69, 72, 72, 15,
489 12, 72, 72, 72, 81, 81, 81, 82, 82, 82,
490 84, 84, 84, 84, 84, 86, 10, 9, 86, 86,
491 87, 7, 87, 87, 87, 88, 88, 5, 83, 83,
492 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
493 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
494 83, 83, 83, 83, 83
495 } ;
496
497/* The intent behind this definition is that it'll catch
498 * any uses of REJECT which flex missed.
499 */
500#define REJECT reject_used_but_not_detected
501#define yymore() yymore_used_but_not_detected
502#define YY_MORE_ADJ 0
503#define YY_RESTORE_YY_MORE_OFFSET
504/*
505//
506// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
507// Use of this source code is governed by a BSD-style license that can be
508// found in the LICENSE file.
509//
510
511This file contains the Lex specification for GLSL ES preprocessor.
512Based on Microsoft Visual Studio 2010 Preprocessor Grammar:
513http://msdn.microsoft.com/en-us/library/2scxys89.aspx
514
515IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
516*/
517
518#include "Tokenizer.h"
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000519
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000520#include "DiagnosticsBase.h"
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000521#include "Token.h"
522
maxvujovic@gmail.comc6b3b3c2012-06-27 22:49:39 +0000523#if defined(__GNUC__)
524// Triggered by the auto-generated yy_fatal_error function.
525#pragma GCC diagnostic ignored "-Wmissing-noreturn"
526#endif
527
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000528typedef std::string YYSTYPE;
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000529typedef pp::SourceLocation YYLTYPE;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000530
531// Use the unused yycolumn variable to track file (string) number.
532#define yyfileno yycolumn
533
534#define YY_USER_INIT \
535 do { \
536 yyfileno = 0; \
537 yylineno = 1; \
538 yyextra->leadingSpace = false; \
539 yyextra->lineStart = true; \
540 } while(0);
541
alokp@chromium.org19d7aa62012-05-31 17:34:05 +0000542#define YY_USER_ACTION \
543 do \
544 { \
545 pp::Input* input = &yyextra->input; \
546 pp::Input::Location* scanLoc = &yyextra->scanLoc; \
547 while ((scanLoc->sIndex < input->count()) && \
548 (scanLoc->cIndex >= input->length(scanLoc->sIndex))) \
549 { \
550 scanLoc->cIndex -= input->length(scanLoc->sIndex++); \
551 ++yyfileno; yylineno = 1; \
552 } \
553 yylloc->file = yyfileno; \
554 yylloc->line = yylineno; \
555 scanLoc->cIndex += yyleng; \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000556 } while(0);
557
558#define YY_INPUT(buf, result, maxSize) \
559 result = yyextra->input.read(buf, maxSize);
560
561#define INITIAL 0
562#define COMMENT 1
563
564#define YY_EXTRA_TYPE pp::Tokenizer::Context*
565
566/* Holds the entire state of the reentrant scanner. */
567struct yyguts_t
568 {
569
570 /* User-defined. Not touched by flex. */
571 YY_EXTRA_TYPE yyextra_r;
572
573 /* The rest are the same as the globals declared in the non-reentrant scanner. */
574 FILE *yyin_r, *yyout_r;
575 size_t yy_buffer_stack_top; /**< index of top of stack. */
576 size_t yy_buffer_stack_max; /**< capacity of stack. */
577 YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
578 char yy_hold_char;
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000579 yy_size_t yy_n_chars;
580 yy_size_t yyleng_r;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000581 char *yy_c_buf_p;
582 int yy_init;
583 int yy_start;
584 int yy_did_buffer_switch_on_eof;
585 int yy_start_stack_ptr;
586 int yy_start_stack_depth;
587 int *yy_start_stack;
588 yy_state_type yy_last_accepting_state;
589 char* yy_last_accepting_cpos;
590
591 int yylineno_r;
592 int yy_flex_debug_r;
593
594 char *yytext_r;
595 int yy_more_flag;
596 int yy_more_len;
597
598 YYSTYPE * yylval_r;
599
600 YYLTYPE * yylloc_r;
601
602 }; /* end struct yyguts_t */
603
604static int yy_init_globals (yyscan_t yyscanner );
605
606 /* This must go here because YYSTYPE and YYLTYPE are included
607 * from bison output in section 1.*/
608 # define yylval yyg->yylval_r
609
610 # define yylloc yyg->yylloc_r
611
612int pplex_init (yyscan_t* scanner);
613
614int pplex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
615
616/* Accessor methods to globals.
617 These are made visible to non-reentrant scanners for convenience. */
618
619int pplex_destroy (yyscan_t yyscanner );
620
621int ppget_debug (yyscan_t yyscanner );
622
623void ppset_debug (int debug_flag ,yyscan_t yyscanner );
624
625YY_EXTRA_TYPE ppget_extra (yyscan_t yyscanner );
626
627void ppset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
628
629FILE *ppget_in (yyscan_t yyscanner );
630
631void ppset_in (FILE * in_str ,yyscan_t yyscanner );
632
633FILE *ppget_out (yyscan_t yyscanner );
634
635void ppset_out (FILE * out_str ,yyscan_t yyscanner );
636
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000637yy_size_t ppget_leng (yyscan_t yyscanner );
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000638
639char *ppget_text (yyscan_t yyscanner );
640
641int ppget_lineno (yyscan_t yyscanner );
642
643void ppset_lineno (int line_number ,yyscan_t yyscanner );
644
645YYSTYPE * ppget_lval (yyscan_t yyscanner );
646
647void ppset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
648
649 YYLTYPE *ppget_lloc (yyscan_t yyscanner );
650
651 void ppset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
652
653/* Macros after this point can all be overridden by user definitions in
654 * section 1.
655 */
656
657#ifndef YY_SKIP_YYWRAP
658#ifdef __cplusplus
659extern "C" int ppwrap (yyscan_t yyscanner );
660#else
661extern int ppwrap (yyscan_t yyscanner );
662#endif
663#endif
664
665#ifndef yytext_ptr
666static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
667#endif
668
669#ifdef YY_NEED_STRLEN
670static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
671#endif
672
673#ifndef YY_NO_INPUT
674
675#ifdef __cplusplus
676static int yyinput (yyscan_t yyscanner );
677#else
678static int input (yyscan_t yyscanner );
679#endif
680
681#endif
682
683/* Amount of stuff to slurp up with each read. */
684#ifndef YY_READ_BUF_SIZE
685#define YY_READ_BUF_SIZE 8192
686#endif
687
688/* Copy whatever the last rule matched to the standard output. */
689#ifndef ECHO
690/* This used to be an fputs(), but since the string might contain NUL's,
691 * we now use fwrite().
692 */
693#define ECHO fwrite( yytext, yyleng, 1, yyout )
694#endif
695
696/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
697 * is returned in "result".
698 */
699#ifndef YY_INPUT
700#define YY_INPUT(buf,result,max_size) \
701 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
702 { \
703 int c = '*'; \
daniel@transgaming.comb3077d02013-01-11 04:12:09 +0000704 yy_size_t n; \
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000705 for ( n = 0; n < max_size && \
706 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
707 buf[n] = (char) c; \
708 if ( c == '\n' ) \
709 buf[n++] = (char) c; \
710 if ( c == EOF && ferror( yyin ) ) \
711 YY_FATAL_ERROR( "input in flex scanner failed" ); \
712 result = n; \
713 } \
714 else \
715 { \
716 errno=0; \
717 while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
718 { \
719 if( errno != EINTR) \
720 { \
721 YY_FATAL_ERROR( "input in flex scanner failed" ); \
722 break; \
723 } \
724 errno=0; \
725 clearerr(yyin); \
726 } \
727 }\
728\
729
730#endif
731
732/* No semi-colon after return; correct usage is to write "yyterminate();" -
733 * we don't want an extra ';' after the "return" because that will cause
734 * some compilers to complain about unreachable statements.
735 */
736#ifndef yyterminate
737#define yyterminate() return YY_NULL
738#endif
739
740/* Number of entries by which start-condition stack grows. */
741#ifndef YY_START_STACK_INCR
742#define YY_START_STACK_INCR 25
743#endif
744
745/* Report a fatal error. */
746#ifndef YY_FATAL_ERROR
747#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
748#endif
749
750/* end tables serialization structures and prototypes */
751
752/* Default declaration of generated scanner - a define so the user can
753 * easily add parameters.
754 */
755#ifndef YY_DECL
756#define YY_DECL_IS_OURS 1
757
758extern int pplex \
759 (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
760
761#define YY_DECL int pplex \
762 (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
763#endif /* !YY_DECL */
764
765/* Code executed at the beginning of each rule, after yytext and yyleng
766 * have been set up.
767 */
768#ifndef YY_USER_ACTION
769#define YY_USER_ACTION
770#endif
771
772/* Code executed at the end of each rule. */
773#ifndef YY_BREAK
774#define YY_BREAK break;
775#endif
776
777#define YY_RULE_SETUP \
778 YY_USER_ACTION
779
780/** The main scanner function which does all the work.
781 */
782YY_DECL
783{
784 register yy_state_type yy_current_state;
785 register char *yy_cp, *yy_bp;
786 register int yy_act;
787 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
788
789 /* Line comment */
790
791 yylval = yylval_param;
792
793 yylloc = yylloc_param;
794
795 if ( !yyg->yy_init )
796 {
797 yyg->yy_init = 1;
798
799#ifdef YY_USER_INIT
800 YY_USER_INIT;
801#endif
802
803 if ( ! yyg->yy_start )
804 yyg->yy_start = 1; /* first start state */
805
806 if ( ! yyin )
807 yyin = stdin;
808
809 if ( ! yyout )
810 yyout = stdout;
811
812 if ( ! YY_CURRENT_BUFFER ) {
813 ppensure_buffer_stack (yyscanner);
814 YY_CURRENT_BUFFER_LVALUE =
815 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
816 }
817
818 pp_load_buffer_state(yyscanner );
819 }
820
821 while ( 1 ) /* loops until end-of-file is reached */
822 {
823 yy_cp = yyg->yy_c_buf_p;
824
825 /* Support of yytext. */
826 *yy_cp = yyg->yy_hold_char;
827
828 /* yy_bp points to the position in yy_ch_buf of the start of
829 * the current run.
830 */
831 yy_bp = yy_cp;
832
833 yy_current_state = yyg->yy_start;
834yy_match:
835 do
836 {
837 register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
838 if ( yy_accept[yy_current_state] )
839 {
840 yyg->yy_last_accepting_state = yy_current_state;
841 yyg->yy_last_accepting_cpos = yy_cp;
842 }
843 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
844 {
845 yy_current_state = (int) yy_def[yy_current_state];
846 if ( yy_current_state >= 84 )
847 yy_c = yy_meta[(unsigned int) yy_c];
848 }
849 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
850 ++yy_cp;
851 }
852 while ( yy_current_state != 83 );
853 yy_cp = yyg->yy_last_accepting_cpos;
854 yy_current_state = yyg->yy_last_accepting_state;
855
856yy_find_action:
857 yy_act = yy_accept[yy_current_state];
858
859 YY_DO_BEFORE_ACTION;
860
861do_action: /* This label is used only to access EOF actions. */
862
863 switch ( yy_act )
864 { /* beginning of action switch */
865 case 0: /* must back up */
866 /* undo the effects of YY_DO_BEFORE_ACTION */
867 *yy_cp = yyg->yy_hold_char;
868 yy_cp = yyg->yy_last_accepting_cpos;
869 yy_current_state = yyg->yy_last_accepting_state;
870 goto yy_find_action;
871
872case 1:
873YY_RULE_SETUP
874
875 YY_BREAK
876/* Block comment */
877/* Line breaks are just counted - not returned. */
878/* The comment is replaced by a single space. */
879case 2:
880YY_RULE_SETUP
881{ BEGIN(COMMENT); }
882 YY_BREAK
883case 3:
884YY_RULE_SETUP
885
886 YY_BREAK
887case 4:
888YY_RULE_SETUP
889
890 YY_BREAK
891case 5:
892/* rule 5 can match eol */
893YY_RULE_SETUP
894{ ++yylineno; }
895 YY_BREAK
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000896case 6:
897YY_RULE_SETUP
alokp@chromium.org2c958ee2012-05-17 20:35:42 +0000898{
899 yyextra->leadingSpace = true;
900 BEGIN(INITIAL);
901}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000902 YY_BREAK
903case 7:
904YY_RULE_SETUP
905{
906 // # is only valid at start of line for preprocessor directives.
alokp@chromium.org432d6fc2012-06-27 22:13:21 +0000907 yylval->assign(1, yytext[0]);
908 return yyextra->lineStart ? pp::Token::PP_HASH : pp::Token::PP_OTHER;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000909}
910 YY_BREAK
911case 8:
912YY_RULE_SETUP
913{
914 yylval->assign(yytext, yyleng);
915 return pp::Token::IDENTIFIER;
916}
917 YY_BREAK
918case 9:
919YY_RULE_SETUP
920{
921 yylval->assign(yytext, yyleng);
922 return pp::Token::CONST_INT;
923}
924 YY_BREAK
925case 10:
926YY_RULE_SETUP
927{
928 yylval->assign(yytext, yyleng);
929 return pp::Token::CONST_FLOAT;
930}
931 YY_BREAK
932/* Anything that starts with a {DIGIT} or .{DIGIT} must be a number. */
933/* Rule to catch all invalid integers and floats. */
934case 11:
935YY_RULE_SETUP
936{
alokp@chromium.org432d6fc2012-06-27 22:13:21 +0000937 yylval->assign(yytext, yyleng);
938 return pp::Token::PP_NUMBER;
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000939}
940 YY_BREAK
941case 12:
942YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000943{
944 yylval->assign(yytext, yyleng);
945 return pp::Token::OP_INC;
946}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000947 YY_BREAK
948case 13:
949YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000950{
951 yylval->assign(yytext, yyleng);
952 return pp::Token::OP_DEC;
953}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000954 YY_BREAK
955case 14:
956YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000957{
958 yylval->assign(yytext, yyleng);
959 return pp::Token::OP_LEFT;
960}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000961 YY_BREAK
962case 15:
963YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000964{
965 yylval->assign(yytext, yyleng);
966 return pp::Token::OP_RIGHT;
967}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000968 YY_BREAK
969case 16:
970YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000971{
972 yylval->assign(yytext, yyleng);
973 return pp::Token::OP_LE;
974}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000975 YY_BREAK
976case 17:
977YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000978{
979 yylval->assign(yytext, yyleng);
980 return pp::Token::OP_GE;
981}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000982 YY_BREAK
983case 18:
984YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000985{
986 yylval->assign(yytext, yyleng);
987 return pp::Token::OP_EQ;
988}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000989 YY_BREAK
990case 19:
991YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000992{
993 yylval->assign(yytext, yyleng);
994 return pp::Token::OP_NE;
995}
alokp@chromium.org04d7d222012-05-16 19:24:07 +0000996 YY_BREAK
997case 20:
998YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +0000999{
1000 yylval->assign(yytext, yyleng);
1001 return pp::Token::OP_AND;
1002}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001003 YY_BREAK
1004case 21:
1005YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001006{
1007 yylval->assign(yytext, yyleng);
1008 return pp::Token::OP_XOR;
1009}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001010 YY_BREAK
1011case 22:
1012YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001013{
1014 yylval->assign(yytext, yyleng);
1015 return pp::Token::OP_OR;
1016}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001017 YY_BREAK
1018case 23:
1019YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001020{
1021 yylval->assign(yytext, yyleng);
1022 return pp::Token::OP_ADD_ASSIGN;
1023}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001024 YY_BREAK
1025case 24:
1026YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001027{
1028 yylval->assign(yytext, yyleng);
1029 return pp::Token::OP_SUB_ASSIGN;
1030}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001031 YY_BREAK
1032case 25:
1033YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001034{
1035 yylval->assign(yytext, yyleng);
1036 return pp::Token::OP_MUL_ASSIGN;
1037}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001038 YY_BREAK
1039case 26:
1040YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001041{
1042 yylval->assign(yytext, yyleng);
1043 return pp::Token::OP_DIV_ASSIGN;
1044}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001045 YY_BREAK
1046case 27:
1047YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001048{
1049 yylval->assign(yytext, yyleng);
1050 return pp::Token::OP_MOD_ASSIGN;
1051}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001052 YY_BREAK
1053case 28:
1054YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001055{
1056 yylval->assign(yytext, yyleng);
1057 return pp::Token::OP_LEFT_ASSIGN;
1058}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001059 YY_BREAK
1060case 29:
1061YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001062{
1063 yylval->assign(yytext, yyleng);
1064 return pp::Token::OP_RIGHT_ASSIGN;
1065}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001066 YY_BREAK
1067case 30:
1068YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001069{
1070 yylval->assign(yytext, yyleng);
1071 return pp::Token::OP_AND_ASSIGN;
1072}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001073 YY_BREAK
1074case 31:
1075YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001076{
1077 yylval->assign(yytext, yyleng);
1078 return pp::Token::OP_XOR_ASSIGN;
1079}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001080 YY_BREAK
1081case 32:
1082YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001083{
1084 yylval->assign(yytext, yyleng);
1085 return pp::Token::OP_OR_ASSIGN;
1086}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001087 YY_BREAK
1088case 33:
1089YY_RULE_SETUP
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001090{
1091 yylval->assign(1, yytext[0]);
1092 return yytext[0];
1093}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001094 YY_BREAK
1095case 34:
1096YY_RULE_SETUP
1097{ yyextra->leadingSpace = true; }
1098 YY_BREAK
1099case 35:
1100/* rule 35 can match eol */
1101YY_RULE_SETUP
1102{
1103 ++yylineno;
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001104 yylval->assign(1, '\n');
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001105 return '\n';
1106}
1107 YY_BREAK
1108case 36:
1109YY_RULE_SETUP
1110{
alokp@chromium.org432d6fc2012-06-27 22:13:21 +00001111 yylval->assign(1, yytext[0]);
1112 return pp::Token::PP_OTHER;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001113}
1114 YY_BREAK
1115case YY_STATE_EOF(INITIAL):
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001116case YY_STATE_EOF(COMMENT):
1117{
alokp@chromium.org19d7aa62012-05-31 17:34:05 +00001118 // YY_USER_ACTION is not invoked for handling EOF.
1119 // Set the location for EOF token manually.
1120 pp::Input* input = &yyextra->input;
1121 pp::Input::Location* scanLoc = &yyextra->scanLoc;
1122 int sIndexMax = std::max(0, input->count() - 1);
1123 if (scanLoc->sIndex != sIndexMax)
1124 {
1125 // We can only reach here if there are empty strings at the
1126 // end of the input.
1127 scanLoc->sIndex = sIndexMax; scanLoc->cIndex = 0;
1128 yyfileno = sIndexMax; yylineno = 1;
1129 }
1130 yylloc->file = yyfileno;
1131 yylloc->line = yylineno;
1132 yylval->clear();
1133
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001134 if (YY_START == COMMENT)
1135 {
1136 yyextra->diagnostics->report(pp::Diagnostics::EOF_IN_COMMENT,
1137 pp::SourceLocation(yyfileno, yylineno),
1138 "");
1139 }
alokp@chromium.org07d921d2012-05-22 20:22:08 +00001140 yyterminate();
1141}
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001142 YY_BREAK
1143case 37:
1144YY_RULE_SETUP
1145ECHO;
1146 YY_BREAK
1147
1148 case YY_END_OF_BUFFER:
1149 {
1150 /* Amount of text matched not including the EOB char. */
1151 int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1152
1153 /* Undo the effects of YY_DO_BEFORE_ACTION. */
1154 *yy_cp = yyg->yy_hold_char;
1155 YY_RESTORE_YY_MORE_OFFSET
1156
1157 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1158 {
1159 /* We're scanning a new file or input source. It's
1160 * possible that this happened because the user
1161 * just pointed yyin at a new source and called
1162 * pplex(). If so, then we have to assure
1163 * consistency between YY_CURRENT_BUFFER and our
1164 * globals. Here is the right place to do so, because
1165 * this is the first action (other than possibly a
1166 * back-up) that will match for the new input source.
1167 */
1168 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1169 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1170 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1171 }
1172
1173 /* Note that here we test for yy_c_buf_p "<=" to the position
1174 * of the first EOB in the buffer, since yy_c_buf_p will
1175 * already have been incremented past the NUL character
1176 * (since all states make transitions on EOB to the
1177 * end-of-buffer state). Contrast this with the test
1178 * in input().
1179 */
1180 if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1181 { /* This was really a NUL. */
1182 yy_state_type yy_next_state;
1183
1184 yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
1185
1186 yy_current_state = yy_get_previous_state( yyscanner );
1187
1188 /* Okay, we're now positioned to make the NUL
1189 * transition. We couldn't have
1190 * yy_get_previous_state() go ahead and do it
1191 * for us because it doesn't know how to deal
1192 * with the possibility of jamming (and we don't
1193 * want to build jamming into it because then it
1194 * will run more slowly).
1195 */
1196
1197 yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
1198
1199 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1200
1201 if ( yy_next_state )
1202 {
1203 /* Consume the NUL. */
1204 yy_cp = ++yyg->yy_c_buf_p;
1205 yy_current_state = yy_next_state;
1206 goto yy_match;
1207 }
1208
1209 else
1210 {
1211 yy_cp = yyg->yy_last_accepting_cpos;
1212 yy_current_state = yyg->yy_last_accepting_state;
1213 goto yy_find_action;
1214 }
1215 }
1216
1217 else switch ( yy_get_next_buffer( yyscanner ) )
1218 {
1219 case EOB_ACT_END_OF_FILE:
1220 {
1221 yyg->yy_did_buffer_switch_on_eof = 0;
1222
1223 if ( ppwrap(yyscanner ) )
1224 {
1225 /* Note: because we've taken care in
1226 * yy_get_next_buffer() to have set up
1227 * yytext, we can now set up
1228 * yy_c_buf_p so that if some total
1229 * hoser (like flex itself) wants to
1230 * call the scanner after we return the
1231 * YY_NULL, it'll still work - another
1232 * YY_NULL will get returned.
1233 */
1234 yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1235
1236 yy_act = YY_STATE_EOF(YY_START);
1237 goto do_action;
1238 }
1239
1240 else
1241 {
1242 if ( ! yyg->yy_did_buffer_switch_on_eof )
1243 YY_NEW_FILE;
1244 }
1245 break;
1246 }
1247
1248 case EOB_ACT_CONTINUE_SCAN:
1249 yyg->yy_c_buf_p =
1250 yyg->yytext_ptr + yy_amount_of_matched_text;
1251
1252 yy_current_state = yy_get_previous_state( yyscanner );
1253
1254 yy_cp = yyg->yy_c_buf_p;
1255 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1256 goto yy_match;
1257
1258 case EOB_ACT_LAST_MATCH:
1259 yyg->yy_c_buf_p =
1260 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1261
1262 yy_current_state = yy_get_previous_state( yyscanner );
1263
1264 yy_cp = yyg->yy_c_buf_p;
1265 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1266 goto yy_find_action;
1267 }
1268 break;
1269 }
1270
1271 default:
1272 YY_FATAL_ERROR(
1273 "fatal flex scanner internal error--no action found" );
1274 } /* end of action switch */
1275 } /* end of scanning one token */
1276} /* end of pplex */
1277
1278/* yy_get_next_buffer - try to read in a new buffer
1279 *
1280 * Returns a code representing an action:
1281 * EOB_ACT_LAST_MATCH -
1282 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1283 * EOB_ACT_END_OF_FILE - end of file
1284 */
1285static int yy_get_next_buffer (yyscan_t yyscanner)
1286{
1287 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1288 register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1289 register char *source = yyg->yytext_ptr;
1290 register int number_to_move, i;
1291 int ret_val;
1292
1293 if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1294 YY_FATAL_ERROR(
1295 "fatal flex scanner internal error--end of buffer missed" );
1296
1297 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1298 { /* Don't try to fill the buffer, so this is an EOF. */
1299 if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1300 {
1301 /* We matched a single character, the EOB, so
1302 * treat this as a final EOF.
1303 */
1304 return EOB_ACT_END_OF_FILE;
1305 }
1306
1307 else
1308 {
1309 /* We matched some text prior to the EOB, first
1310 * process it.
1311 */
1312 return EOB_ACT_LAST_MATCH;
1313 }
1314 }
1315
1316 /* Try to read more data. */
1317
1318 /* First move last chars to start of buffer. */
1319 number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
1320
1321 for ( i = 0; i < number_to_move; ++i )
1322 *(dest++) = *(source++);
1323
1324 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1325 /* don't do the read, it's not guaranteed to return an EOF,
1326 * just force an EOF
1327 */
1328 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
1329
1330 else
1331 {
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001332 yy_size_t num_to_read =
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001333 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1334
1335 while ( num_to_read <= 0 )
1336 { /* Not enough room in the buffer - grow it. */
1337
1338 /* just a shorter name for the current buffer */
1339 YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
1340
1341 int yy_c_buf_p_offset =
1342 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
1343
1344 if ( b->yy_is_our_buffer )
1345 {
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001346 yy_size_t new_size = b->yy_buf_size * 2;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001347
1348 if ( new_size <= 0 )
1349 b->yy_buf_size += b->yy_buf_size / 8;
1350 else
1351 b->yy_buf_size *= 2;
1352
1353 b->yy_ch_buf = (char *)
1354 /* Include room in for 2 EOB chars. */
1355 pprealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
1356 }
1357 else
1358 /* Can't grow it, we don't own it. */
1359 b->yy_ch_buf = 0;
1360
1361 if ( ! b->yy_ch_buf )
1362 YY_FATAL_ERROR(
1363 "fatal error - scanner input buffer overflow" );
1364
1365 yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
1366
1367 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1368 number_to_move - 1;
1369
1370 }
1371
1372 if ( num_to_read > YY_READ_BUF_SIZE )
1373 num_to_read = YY_READ_BUF_SIZE;
1374
1375 /* Read in more data. */
1376 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001377 yyg->yy_n_chars, num_to_read );
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001378
1379 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1380 }
1381
1382 if ( yyg->yy_n_chars == 0 )
1383 {
1384 if ( number_to_move == YY_MORE_ADJ )
1385 {
1386 ret_val = EOB_ACT_END_OF_FILE;
1387 pprestart(yyin ,yyscanner);
1388 }
1389
1390 else
1391 {
1392 ret_val = EOB_ACT_LAST_MATCH;
1393 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1394 YY_BUFFER_EOF_PENDING;
1395 }
1396 }
1397
1398 else
1399 ret_val = EOB_ACT_CONTINUE_SCAN;
1400
1401 if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1402 /* Extend the array by 50%, plus the number we really need. */
1403 yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
1404 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) pprealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
1405 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1406 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1407 }
1408
1409 yyg->yy_n_chars += number_to_move;
1410 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1411 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1412
1413 yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1414
1415 return ret_val;
1416}
1417
1418/* yy_get_previous_state - get the state just before the EOB char was reached */
1419
1420 static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
1421{
1422 register yy_state_type yy_current_state;
1423 register char *yy_cp;
1424 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1425
1426 yy_current_state = yyg->yy_start;
1427
1428 for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1429 {
1430 register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1431 if ( yy_accept[yy_current_state] )
1432 {
1433 yyg->yy_last_accepting_state = yy_current_state;
1434 yyg->yy_last_accepting_cpos = yy_cp;
1435 }
1436 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1437 {
1438 yy_current_state = (int) yy_def[yy_current_state];
1439 if ( yy_current_state >= 84 )
1440 yy_c = yy_meta[(unsigned int) yy_c];
1441 }
1442 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1443 }
1444
1445 return yy_current_state;
1446}
1447
1448/* yy_try_NUL_trans - try to make a transition on the NUL character
1449 *
1450 * synopsis
1451 * next_state = yy_try_NUL_trans( current_state );
1452 */
1453 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
1454{
1455 register int yy_is_jam;
1456 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
1457 register char *yy_cp = yyg->yy_c_buf_p;
1458
1459 register YY_CHAR yy_c = 1;
1460 if ( yy_accept[yy_current_state] )
1461 {
1462 yyg->yy_last_accepting_state = yy_current_state;
1463 yyg->yy_last_accepting_cpos = yy_cp;
1464 }
1465 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1466 {
1467 yy_current_state = (int) yy_def[yy_current_state];
1468 if ( yy_current_state >= 84 )
1469 yy_c = yy_meta[(unsigned int) yy_c];
1470 }
1471 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1472 yy_is_jam = (yy_current_state == 83);
1473
1474 return yy_is_jam ? 0 : yy_current_state;
1475}
1476
1477#ifndef YY_NO_INPUT
1478#ifdef __cplusplus
1479 static int yyinput (yyscan_t yyscanner)
1480#else
1481 static int input (yyscan_t yyscanner)
1482#endif
1483
1484{
1485 int c;
1486 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1487
1488 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1489
1490 if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1491 {
1492 /* yy_c_buf_p now points to the character we want to return.
1493 * If this occurs *before* the EOB characters, then it's a
1494 * valid NUL; if not, then we've hit the end of the buffer.
1495 */
1496 if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1497 /* This was really a NUL. */
1498 *yyg->yy_c_buf_p = '\0';
1499
1500 else
1501 { /* need more input */
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001502 yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001503 ++yyg->yy_c_buf_p;
1504
1505 switch ( yy_get_next_buffer( yyscanner ) )
1506 {
1507 case EOB_ACT_LAST_MATCH:
1508 /* This happens because yy_g_n_b()
1509 * sees that we've accumulated a
1510 * token and flags that we need to
1511 * try matching the token before
1512 * proceeding. But for input(),
1513 * there's no matching to consider.
1514 * So convert the EOB_ACT_LAST_MATCH
1515 * to EOB_ACT_END_OF_FILE.
1516 */
1517
1518 /* Reset buffer status. */
1519 pprestart(yyin ,yyscanner);
1520
1521 /*FALLTHROUGH*/
1522
1523 case EOB_ACT_END_OF_FILE:
1524 {
1525 if ( ppwrap(yyscanner ) )
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001526 return 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001527
1528 if ( ! yyg->yy_did_buffer_switch_on_eof )
1529 YY_NEW_FILE;
1530#ifdef __cplusplus
1531 return yyinput(yyscanner);
1532#else
1533 return input(yyscanner);
1534#endif
1535 }
1536
1537 case EOB_ACT_CONTINUE_SCAN:
1538 yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
1539 break;
1540 }
1541 }
1542 }
1543
1544 c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
1545 *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
1546 yyg->yy_hold_char = *++yyg->yy_c_buf_p;
1547
1548 return c;
1549}
1550#endif /* ifndef YY_NO_INPUT */
1551
1552/** Immediately switch to a different input stream.
1553 * @param input_file A readable stream.
1554 * @param yyscanner The scanner object.
1555 * @note This function does not reset the start condition to @c INITIAL .
1556 */
1557 void pprestart (FILE * input_file , yyscan_t yyscanner)
1558{
1559 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1560
1561 if ( ! YY_CURRENT_BUFFER ){
1562 ppensure_buffer_stack (yyscanner);
1563 YY_CURRENT_BUFFER_LVALUE =
1564 pp_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
1565 }
1566
1567 pp_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
1568 pp_load_buffer_state(yyscanner );
1569}
1570
1571/** Switch to a different input buffer.
1572 * @param new_buffer The new input buffer.
1573 * @param yyscanner The scanner object.
1574 */
1575 void pp_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1576{
1577 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1578
1579 /* TODO. We should be able to replace this entire function body
1580 * with
1581 * pppop_buffer_state();
1582 * pppush_buffer_state(new_buffer);
1583 */
1584 ppensure_buffer_stack (yyscanner);
1585 if ( YY_CURRENT_BUFFER == new_buffer )
1586 return;
1587
1588 if ( YY_CURRENT_BUFFER )
1589 {
1590 /* Flush out information for old buffer. */
1591 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1592 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1593 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1594 }
1595
1596 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1597 pp_load_buffer_state(yyscanner );
1598
1599 /* We don't actually know whether we did this switch during
1600 * EOF (ppwrap()) processing, but the only time this flag
1601 * is looked at is after ppwrap() is called, so it's safe
1602 * to go ahead and always set it.
1603 */
1604 yyg->yy_did_buffer_switch_on_eof = 1;
1605}
1606
1607static void pp_load_buffer_state (yyscan_t yyscanner)
1608{
1609 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1610 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1611 yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1612 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1613 yyg->yy_hold_char = *yyg->yy_c_buf_p;
1614}
1615
1616/** Allocate and initialize an input buffer state.
1617 * @param file A readable stream.
1618 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1619 * @param yyscanner The scanner object.
1620 * @return the allocated buffer state.
1621 */
1622 YY_BUFFER_STATE pp_create_buffer (FILE * file, int size , yyscan_t yyscanner)
1623{
1624 YY_BUFFER_STATE b;
1625
1626 b = (YY_BUFFER_STATE) ppalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
1627 if ( ! b )
1628 YY_FATAL_ERROR( "out of dynamic memory in pp_create_buffer()" );
1629
1630 b->yy_buf_size = size;
1631
1632 /* yy_ch_buf has to be 2 characters longer than the size given because
1633 * we need to put in 2 end-of-buffer characters.
1634 */
1635 b->yy_ch_buf = (char *) ppalloc(b->yy_buf_size + 2 ,yyscanner );
1636 if ( ! b->yy_ch_buf )
1637 YY_FATAL_ERROR( "out of dynamic memory in pp_create_buffer()" );
1638
1639 b->yy_is_our_buffer = 1;
1640
1641 pp_init_buffer(b,file ,yyscanner);
1642
1643 return b;
1644}
1645
1646/** Destroy the buffer.
1647 * @param b a buffer created with pp_create_buffer()
1648 * @param yyscanner The scanner object.
1649 */
1650 void pp_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1651{
1652 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1653
1654 if ( ! b )
1655 return;
1656
1657 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1658 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1659
1660 if ( b->yy_is_our_buffer )
1661 ppfree((void *) b->yy_ch_buf ,yyscanner );
1662
1663 ppfree((void *) b ,yyscanner );
1664}
1665
1666/* Initializes or reinitializes a buffer.
1667 * This function is sometimes called more than once on the same buffer,
1668 * such as during a pprestart() or at EOF.
1669 */
1670 static void pp_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
1671
1672{
1673 int oerrno = errno;
1674 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1675
1676 pp_flush_buffer(b ,yyscanner);
1677
1678 b->yy_input_file = file;
1679 b->yy_fill_buffer = 1;
1680
1681 /* If b is the current buffer, then pp_init_buffer was _probably_
1682 * called from pprestart() or through yy_get_next_buffer.
1683 * In that case, we don't want to reset the lineno or column.
1684 */
1685 if (b != YY_CURRENT_BUFFER){
1686 b->yy_bs_lineno = 1;
1687 b->yy_bs_column = 0;
1688 }
1689
1690 b->yy_is_interactive = 0;
1691
1692 errno = oerrno;
1693}
1694
1695/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1696 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1697 * @param yyscanner The scanner object.
1698 */
1699 void pp_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1700{
1701 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1702 if ( ! b )
1703 return;
1704
1705 b->yy_n_chars = 0;
1706
1707 /* We always need two end-of-buffer characters. The first causes
1708 * a transition to the end-of-buffer state. The second causes
1709 * a jam in that state.
1710 */
1711 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1712 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1713
1714 b->yy_buf_pos = &b->yy_ch_buf[0];
1715
1716 b->yy_at_bol = 1;
1717 b->yy_buffer_status = YY_BUFFER_NEW;
1718
1719 if ( b == YY_CURRENT_BUFFER )
1720 pp_load_buffer_state(yyscanner );
1721}
1722
1723/** Pushes the new state onto the stack. The new state becomes
1724 * the current state. This function will allocate the stack
1725 * if necessary.
1726 * @param new_buffer The new state.
1727 * @param yyscanner The scanner object.
1728 */
1729void pppush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1730{
1731 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1732 if (new_buffer == NULL)
1733 return;
1734
1735 ppensure_buffer_stack(yyscanner);
1736
1737 /* This block is copied from pp_switch_to_buffer. */
1738 if ( YY_CURRENT_BUFFER )
1739 {
1740 /* Flush out information for old buffer. */
1741 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1742 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1743 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1744 }
1745
1746 /* Only push if top exists. Otherwise, replace top. */
1747 if (YY_CURRENT_BUFFER)
1748 yyg->yy_buffer_stack_top++;
1749 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1750
1751 /* copied from pp_switch_to_buffer. */
1752 pp_load_buffer_state(yyscanner );
1753 yyg->yy_did_buffer_switch_on_eof = 1;
1754}
1755
1756/** Removes and deletes the top of the stack, if present.
1757 * The next element becomes the new top.
1758 * @param yyscanner The scanner object.
1759 */
1760void pppop_buffer_state (yyscan_t yyscanner)
1761{
1762 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1763 if (!YY_CURRENT_BUFFER)
1764 return;
1765
1766 pp_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
1767 YY_CURRENT_BUFFER_LVALUE = NULL;
1768 if (yyg->yy_buffer_stack_top > 0)
1769 --yyg->yy_buffer_stack_top;
1770
1771 if (YY_CURRENT_BUFFER) {
1772 pp_load_buffer_state(yyscanner );
1773 yyg->yy_did_buffer_switch_on_eof = 1;
1774 }
1775}
1776
1777/* Allocates the stack if it does not exist.
1778 * Guarantees space for at least one push.
1779 */
1780static void ppensure_buffer_stack (yyscan_t yyscanner)
1781{
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001782 yy_size_t num_to_alloc;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001783 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1784
1785 if (!yyg->yy_buffer_stack) {
1786
1787 /* First allocation is just for 2 elements, since we don't know if this
1788 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1789 * immediate realloc on the next call.
1790 */
1791 num_to_alloc = 1;
1792 yyg->yy_buffer_stack = (struct yy_buffer_state**)ppalloc
1793 (num_to_alloc * sizeof(struct yy_buffer_state*)
1794 , yyscanner);
1795 if ( ! yyg->yy_buffer_stack )
1796 YY_FATAL_ERROR( "out of dynamic memory in ppensure_buffer_stack()" );
1797
1798 memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1799
1800 yyg->yy_buffer_stack_max = num_to_alloc;
1801 yyg->yy_buffer_stack_top = 0;
1802 return;
1803 }
1804
1805 if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
1806
1807 /* Increase the buffer to prepare for a possible push. */
1808 int grow_size = 8 /* arbitrary grow size */;
1809
1810 num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
1811 yyg->yy_buffer_stack = (struct yy_buffer_state**)pprealloc
1812 (yyg->yy_buffer_stack,
1813 num_to_alloc * sizeof(struct yy_buffer_state*)
1814 , yyscanner);
1815 if ( ! yyg->yy_buffer_stack )
1816 YY_FATAL_ERROR( "out of dynamic memory in ppensure_buffer_stack()" );
1817
1818 /* zero only the new slots.*/
1819 memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
1820 yyg->yy_buffer_stack_max = num_to_alloc;
1821 }
1822}
1823
1824/** Setup the input buffer state to scan directly from a user-specified character buffer.
1825 * @param base the character buffer
1826 * @param size the size in bytes of the character buffer
1827 * @param yyscanner The scanner object.
1828 * @return the newly allocated buffer state object.
1829 */
1830YY_BUFFER_STATE pp_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
1831{
1832 YY_BUFFER_STATE b;
1833
1834 if ( size < 2 ||
1835 base[size-2] != YY_END_OF_BUFFER_CHAR ||
1836 base[size-1] != YY_END_OF_BUFFER_CHAR )
1837 /* They forgot to leave room for the EOB's. */
1838 return 0;
1839
1840 b = (YY_BUFFER_STATE) ppalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
1841 if ( ! b )
1842 YY_FATAL_ERROR( "out of dynamic memory in pp_scan_buffer()" );
1843
1844 b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
1845 b->yy_buf_pos = b->yy_ch_buf = base;
1846 b->yy_is_our_buffer = 0;
1847 b->yy_input_file = 0;
1848 b->yy_n_chars = b->yy_buf_size;
1849 b->yy_is_interactive = 0;
1850 b->yy_at_bol = 1;
1851 b->yy_fill_buffer = 0;
1852 b->yy_buffer_status = YY_BUFFER_NEW;
1853
1854 pp_switch_to_buffer(b ,yyscanner );
1855
1856 return b;
1857}
1858
1859/** Setup the input buffer state to scan a string. The next call to pplex() will
1860 * scan from a @e copy of @a str.
1861 * @param yystr a NUL-terminated string to scan
1862 * @param yyscanner The scanner object.
1863 * @return the newly allocated buffer state object.
1864 * @note If you want to scan bytes that may contain NUL values, then use
1865 * pp_scan_bytes() instead.
1866 */
1867YY_BUFFER_STATE pp_scan_string (yyconst char * yystr , yyscan_t yyscanner)
1868{
1869
1870 return pp_scan_bytes(yystr,strlen(yystr) ,yyscanner);
1871}
1872
1873/** Setup the input buffer state to scan the given bytes. The next call to pplex() will
1874 * scan from a @e copy of @a bytes.
1875 * @param bytes the byte buffer to scan
1876 * @param len the number of bytes in the buffer pointed to by @a bytes.
1877 * @param yyscanner The scanner object.
1878 * @return the newly allocated buffer state object.
1879 */
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001880YY_BUFFER_STATE pp_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001881{
1882 YY_BUFFER_STATE b;
1883 char *buf;
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001884 yy_size_t n, i;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001885
1886 /* Get memory for full buffer, including space for trailing EOB's. */
1887 n = _yybytes_len + 2;
1888 buf = (char *) ppalloc(n ,yyscanner );
1889 if ( ! buf )
1890 YY_FATAL_ERROR( "out of dynamic memory in pp_scan_bytes()" );
1891
1892 for ( i = 0; i < _yybytes_len; ++i )
1893 buf[i] = yybytes[i];
1894
1895 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
1896
1897 b = pp_scan_buffer(buf,n ,yyscanner);
1898 if ( ! b )
1899 YY_FATAL_ERROR( "bad buffer in pp_scan_bytes()" );
1900
1901 /* It's okay to grow etc. this buffer, and we should throw it
1902 * away when we're done.
1903 */
1904 b->yy_is_our_buffer = 1;
1905
1906 return b;
1907}
1908
1909#ifndef YY_EXIT_FAILURE
1910#define YY_EXIT_FAILURE 2
1911#endif
1912
1913static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
1914{
1915 (void) fprintf( stderr, "%s\n", msg );
1916 exit( YY_EXIT_FAILURE );
1917}
1918
1919/* Redefine yyless() so it works in section 3 code. */
1920
1921#undef yyless
1922#define yyless(n) \
1923 do \
1924 { \
1925 /* Undo effects of setting up yytext. */ \
1926 int yyless_macro_arg = (n); \
1927 YY_LESS_LINENO(yyless_macro_arg);\
1928 yytext[yyleng] = yyg->yy_hold_char; \
1929 yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
1930 yyg->yy_hold_char = *yyg->yy_c_buf_p; \
1931 *yyg->yy_c_buf_p = '\0'; \
1932 yyleng = yyless_macro_arg; \
1933 } \
1934 while ( 0 )
1935
1936/* Accessor methods (get/set functions) to struct members. */
1937
1938/** Get the user-defined data for this scanner.
1939 * @param yyscanner The scanner object.
1940 */
1941YY_EXTRA_TYPE ppget_extra (yyscan_t yyscanner)
1942{
1943 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1944 return yyextra;
1945}
1946
1947/** Get the current line number.
1948 * @param yyscanner The scanner object.
1949 */
1950int ppget_lineno (yyscan_t yyscanner)
1951{
1952 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1953
1954 if (! YY_CURRENT_BUFFER)
1955 return 0;
1956
1957 return yylineno;
1958}
1959
1960/** Get the current column number.
1961 * @param yyscanner The scanner object.
1962 */
1963int ppget_column (yyscan_t yyscanner)
1964{
1965 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1966
1967 if (! YY_CURRENT_BUFFER)
1968 return 0;
1969
1970 return yycolumn;
1971}
1972
1973/** Get the input stream.
1974 * @param yyscanner The scanner object.
1975 */
1976FILE *ppget_in (yyscan_t yyscanner)
1977{
1978 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1979 return yyin;
1980}
1981
1982/** Get the output stream.
1983 * @param yyscanner The scanner object.
1984 */
1985FILE *ppget_out (yyscan_t yyscanner)
1986{
1987 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1988 return yyout;
1989}
1990
1991/** Get the length of the current token.
1992 * @param yyscanner The scanner object.
1993 */
daniel@transgaming.comb3077d02013-01-11 04:12:09 +00001994yy_size_t ppget_leng (yyscan_t yyscanner)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00001995{
1996 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1997 return yyleng;
1998}
1999
2000/** Get the current token.
2001 * @param yyscanner The scanner object.
2002 */
2003
2004char *ppget_text (yyscan_t yyscanner)
2005{
2006 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2007 return yytext;
2008}
2009
2010/** Set the user-defined data. This data is never touched by the scanner.
2011 * @param user_defined The data to be associated with this scanner.
2012 * @param yyscanner The scanner object.
2013 */
2014void ppset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
2015{
2016 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2017 yyextra = user_defined ;
2018}
2019
2020/** Set the current line number.
2021 * @param line_number
2022 * @param yyscanner The scanner object.
2023 */
2024void ppset_lineno (int line_number , yyscan_t yyscanner)
2025{
2026 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2027
2028 /* lineno is only valid if an input buffer exists. */
2029 if (! YY_CURRENT_BUFFER )
2030 yy_fatal_error( "ppset_lineno called with no buffer" , yyscanner);
2031
2032 yylineno = line_number;
2033}
2034
2035/** Set the current column.
2036 * @param line_number
2037 * @param yyscanner The scanner object.
2038 */
2039void ppset_column (int column_no , yyscan_t yyscanner)
2040{
2041 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2042
2043 /* column is only valid if an input buffer exists. */
2044 if (! YY_CURRENT_BUFFER )
2045 yy_fatal_error( "ppset_column called with no buffer" , yyscanner);
2046
2047 yycolumn = column_no;
2048}
2049
2050/** Set the input stream. This does not discard the current
2051 * input buffer.
2052 * @param in_str A readable stream.
2053 * @param yyscanner The scanner object.
2054 * @see pp_switch_to_buffer
2055 */
2056void ppset_in (FILE * in_str , yyscan_t yyscanner)
2057{
2058 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2059 yyin = in_str ;
2060}
2061
2062void ppset_out (FILE * out_str , yyscan_t yyscanner)
2063{
2064 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2065 yyout = out_str ;
2066}
2067
2068int ppget_debug (yyscan_t yyscanner)
2069{
2070 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2071 return yy_flex_debug;
2072}
2073
2074void ppset_debug (int bdebug , yyscan_t yyscanner)
2075{
2076 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2077 yy_flex_debug = bdebug ;
2078}
2079
2080/* Accessor methods for yylval and yylloc */
2081
2082YYSTYPE * ppget_lval (yyscan_t yyscanner)
2083{
2084 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2085 return yylval;
2086}
2087
2088void ppset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
2089{
2090 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2091 yylval = yylval_param;
2092}
2093
2094YYLTYPE *ppget_lloc (yyscan_t yyscanner)
2095{
2096 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2097 return yylloc;
2098}
2099
2100void ppset_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner)
2101{
2102 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2103 yylloc = yylloc_param;
2104}
2105
2106/* User-visible API */
2107
2108/* pplex_init is special because it creates the scanner itself, so it is
2109 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2110 * That's why we explicitly handle the declaration, instead of using our macros.
2111 */
2112
2113int pplex_init(yyscan_t* ptr_yy_globals)
2114
2115{
2116 if (ptr_yy_globals == NULL){
2117 errno = EINVAL;
2118 return 1;
2119 }
2120
2121 *ptr_yy_globals = (yyscan_t) ppalloc ( sizeof( struct yyguts_t ), NULL );
2122
2123 if (*ptr_yy_globals == NULL){
2124 errno = ENOMEM;
2125 return 1;
2126 }
2127
2128 /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2129 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2130
2131 return yy_init_globals ( *ptr_yy_globals );
2132}
2133
2134/* pplex_init_extra has the same functionality as pplex_init, but follows the
2135 * convention of taking the scanner as the last argument. Note however, that
2136 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2137 * is the reason, too, why this function also must handle its own declaration).
2138 * The user defined value in the first argument will be available to ppalloc in
2139 * the yyextra field.
2140 */
2141
2142int pplex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
2143
2144{
2145 struct yyguts_t dummy_yyguts;
2146
2147 ppset_extra (yy_user_defined, &dummy_yyguts);
2148
2149 if (ptr_yy_globals == NULL){
2150 errno = EINVAL;
2151 return 1;
2152 }
2153
2154 *ptr_yy_globals = (yyscan_t) ppalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2155
2156 if (*ptr_yy_globals == NULL){
2157 errno = ENOMEM;
2158 return 1;
2159 }
2160
2161 /* By setting to 0xAA, we expose bugs in
2162 yy_init_globals. Leave at 0x00 for releases. */
2163 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2164
2165 ppset_extra (yy_user_defined, *ptr_yy_globals);
2166
2167 return yy_init_globals ( *ptr_yy_globals );
2168}
2169
2170static int yy_init_globals (yyscan_t yyscanner)
2171{
2172 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2173 /* Initialization is the same as for the non-reentrant scanner.
2174 * This function is called from pplex_destroy(), so don't allocate here.
2175 */
2176
2177 yyg->yy_buffer_stack = 0;
2178 yyg->yy_buffer_stack_top = 0;
2179 yyg->yy_buffer_stack_max = 0;
2180 yyg->yy_c_buf_p = (char *) 0;
2181 yyg->yy_init = 0;
2182 yyg->yy_start = 0;
2183
2184 yyg->yy_start_stack_ptr = 0;
2185 yyg->yy_start_stack_depth = 0;
2186 yyg->yy_start_stack = NULL;
2187
2188/* Defined in main.c */
2189#ifdef YY_STDINIT
2190 yyin = stdin;
2191 yyout = stdout;
2192#else
2193 yyin = (FILE *) 0;
2194 yyout = (FILE *) 0;
2195#endif
2196
2197 /* For future reference: Set errno on error, since we are called by
2198 * pplex_init()
2199 */
2200 return 0;
2201}
2202
2203/* pplex_destroy is for both reentrant and non-reentrant scanners. */
2204int pplex_destroy (yyscan_t yyscanner)
2205{
2206 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2207
2208 /* Pop the buffer stack, destroying each element. */
2209 while(YY_CURRENT_BUFFER){
2210 pp_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
2211 YY_CURRENT_BUFFER_LVALUE = NULL;
2212 pppop_buffer_state(yyscanner);
2213 }
2214
2215 /* Destroy the stack itself. */
2216 ppfree(yyg->yy_buffer_stack ,yyscanner);
2217 yyg->yy_buffer_stack = NULL;
2218
2219 /* Destroy the start condition stack. */
2220 ppfree(yyg->yy_start_stack ,yyscanner );
2221 yyg->yy_start_stack = NULL;
2222
2223 /* Reset the globals. This is important in a non-reentrant scanner so the next time
2224 * pplex() is called, initialization will occur. */
2225 yy_init_globals( yyscanner);
2226
2227 /* Destroy the main struct (reentrant only). */
2228 ppfree ( yyscanner , yyscanner );
2229 yyscanner = NULL;
2230 return 0;
2231}
2232
2233/*
2234 * Internal utility routines.
2235 */
2236
2237#ifndef yytext_ptr
2238static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
2239{
2240 register int i;
2241 for ( i = 0; i < n; ++i )
2242 s1[i] = s2[i];
2243}
2244#endif
2245
2246#ifdef YY_NEED_STRLEN
2247static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
2248{
2249 register int n;
2250 for ( n = 0; s[n]; ++n )
2251 ;
2252
2253 return n;
2254}
2255#endif
2256
2257void *ppalloc (yy_size_t size , yyscan_t yyscanner)
2258{
2259 return (void *) malloc( size );
2260}
2261
2262void *pprealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
2263{
2264 /* The cast to (char *) in the following accommodates both
2265 * implementations that use char* generic pointers, and those
2266 * that use void* generic pointers. It works with the latter
2267 * because both ANSI C and C++ allow castless assignment from
2268 * any pointer type to void*, and deal with argument conversions
2269 * as though doing an assignment.
2270 */
2271 return (void *) realloc( (char *) ptr, size );
2272}
2273
2274void ppfree (void * ptr , yyscan_t yyscanner)
2275{
2276 free( (char *) ptr ); /* see pprealloc() for (char *) cast */
2277}
2278
2279#define YYTABLES_NAME "yytables"
2280
2281namespace pp {
2282
alokp@chromium.orgc022c3a2012-07-09 15:56:42 +00002283// TODO(alokp): Maximum token length should ideally be specified by
2284// the preprocessor client, i.e., the compiler.
2285const size_t Tokenizer::kMaxTokenLength = 256;
2286
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00002287Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0)
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002288{
alokp@chromium.org2c958ee2012-05-17 20:35:42 +00002289 mContext.diagnostics = diagnostics;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002290}
2291
2292Tokenizer::~Tokenizer()
2293{
2294 destroyScanner();
2295}
2296
2297bool Tokenizer::init(int count, const char* const string[], const int length[])
2298{
2299 if (count < 0) return false;
2300 if ((count > 0) && (string == 0)) return false;
2301
2302 mContext.input = Input(count, string, length);
2303 return initScanner();
2304}
2305
alokp@chromium.org46aa13d2012-06-15 15:40:27 +00002306void Tokenizer::setFileNumber(int file)
2307{
2308 // We use column number as file number.
2309 // See macro yyfileno.
2310 ppset_column(file,mHandle);
2311}
2312
2313void Tokenizer::setLineNumber(int line)
2314{
2315 ppset_lineno(line,mHandle);
2316}
2317
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002318void Tokenizer::lex(Token* token)
2319{
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +00002320 token->type = pplex(&token->text,&token->location,mHandle);
alokp@chromium.orgc022c3a2012-07-09 15:56:42 +00002321 if (token->text.size() > kMaxTokenLength)
2322 {
2323 mContext.diagnostics->report(Diagnostics::TOKEN_TOO_LONG,
2324 token->location, token->text);
2325 token->text.erase(kMaxTokenLength);
2326 }
2327
alokp@chromium.org7fc38dd2012-06-14 18:23:23 +00002328 token->flags = 0;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002329
alokp@chromium.org19d7aa62012-05-31 17:34:05 +00002330 token->setAtStartOfLine(mContext.lineStart);
2331 mContext.lineStart = token->type == '\n';
2332
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002333 token->setHasLeadingSpace(mContext.leadingSpace);
2334 mContext.leadingSpace = false;
alokp@chromium.org04d7d222012-05-16 19:24:07 +00002335}
2336
2337bool Tokenizer::initScanner()
2338{
2339 if ((mHandle == NULL) && pplex_init_extra(&mContext,&mHandle))
2340 return false;
2341
2342 pprestart(0,mHandle);
2343 return true;
2344}
2345
2346void Tokenizer::destroyScanner()
2347{
2348 if (mHandle == NULL)
2349 return;
2350
2351 pplex_destroy(mHandle);
2352 mHandle = NULL;
2353}
2354
2355} // namespace pp
2356