compiler/libec: (#307, #70) Warning on undeclared class; Overriding namespaces
[sdk] / compiler / libec / src / lexer.l
1 D         [0-9]
2 L         [a-zA-Z_]
3 H         [a-fA-F0-9]
4 E         [Ee][+-]?{D}+
5 P         [Pp][+-]?{D}+
6 FS         (f|F|l|L|i|I|j|J)*
7 IS         (u|U|l|L|i|I|j|J)*
8 IDENT    {L}({L}|{D})*
9
10 %option nounput
11
12 %{
13 import "ecdefs"
14 #define YYLTYPE Location
15 #define YY_NEVER_INTERACTIVE 1    // Avoid calling isatty on eC File object
16
17 #include "grammar.h"
18
19 bool echoOn = true;
20 public void SetEchoOn(bool b) { echoOn = b; }
21
22 extern YYLTYPE type_yylloc;
23 extern YYLTYPE expression_yylloc;
24
25 extern File fileInput;
26 int preprocessor();
27 int comment();
28
29 void TESTTTT()
30 {
31    yylloc.end.charPos += yyleng;
32    yylloc.end.pos += yyleng;
33    type_yylloc.end.charPos += yyleng;
34    type_yylloc.end.pos += yyleng;
35    expression_yylloc.end.charPos += yyleng;
36    expression_yylloc.end.pos += yyleng;
37 }
38
39 #define YY_USER_ACTION  \
40    TESTTTT();
41
42    /*
43    yylloc.end.charPos += yyleng;
44    yylloc.end.pos += yyleng;
45    */
46
47 #define YY_INPUT(buf,result,max_size) \
48    result = fileInput.Read(buf, 1, max_size) \
49
50 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
51 File fileStack[MAX_INCLUDE_DEPTH];
52 char sourceFileStack[MAX_INCLUDE_DEPTH][MAX_LOCATION];
53 public void SetSomeSourceFileStack(const char * fileName, int index) { strcpy(sourceFileStack[index], fileName); }
54 YYLTYPE locStack[MAX_INCLUDE_DEPTH];
55 AccessMode declModeStack[MAX_INCLUDE_DEPTH];
56 int include_stack_ptr = 0;
57
58 #define uint _uint
59 default:
60
61 %}
62
63 %%
64
65 %{
66    yylloc.start = yylloc.end;
67    type_yylloc.start = type_yylloc.end;
68    expression_yylloc.start = expression_yylloc.end;
69 %}
70
71 "#"                  { preprocessor(); }
72 "/*"                 { comment(); }
73 "//"                 { commentCPP(); }
74
75 "auto"               { return(AUTO); }
76 "break"              { return(BREAK); }
77 "case"               { return(CASE); }
78 "char"               { return(CHAR); }
79 "const"              { return(CONST); }
80 "continue"           { return(CONTINUE); }
81 "default"            { return(DEFAULT); }
82 "do"                 { return(DO); }
83 "double"             { return(DOUBLE); }
84 "else"               { return(ELSE); }
85 "enum"               { return(ENUM); }
86 "extern"             { return(EXTERN); }
87 "float"              { return(FLOAT); }
88 "for"                { return(FOR); }
89 "goto"               { return(GOTO); }
90 "if"                 { return(IF); }
91 "int"                { return(INT); }
92 "uint"               { return(UINT); }
93  /* "uint16"            { return(UINT16); } */
94  /* "uint32"            { return(UINT32); } */
95  /* "bool"              { return(BOOL_TOKEN); } */
96 "long"               { return(LONG); }
97 "register"           { return(REGISTER); }
98 "return"             { return(RETURN); }
99 "short"              { return(SHORT); }
100 "signed"             { return(SIGNED); }
101 "__signed"           { return(SIGNED); }
102 "__signed__"         { return(SIGNED); }
103 "sizeof"             { return(SIZEOF); }
104 "__alignof__"        { return(ALIGNOF); }
105 "static"             { return(STATIC); }
106 "__thread"           { return(THREAD); }
107 "struct"             { return(STRUCT); }
108 "switch"             { return(SWITCH); }
109 "typedef"            { return(TYPEDEF); }
110 "union"              { return(UNION); }
111 "unsigned"           { return(UNSIGNED); }
112 "void"               { return(VOID); }
113 "volatile"           { return(VOLATILE); }
114 "__volatile__"       { return(VOLATILE); }
115 "__volatile"         { return(VOLATILE); }
116 "while"              { return(WHILE); }
117
118 "property"           { return(PROPERTY); }
119 "set"                { return(SETPROP); }    // TODO: Don't make this a keyword...
120 "get"                { return(GETPROP); }    // TODO: Don't make this a keyword...
121 "isset"              { return(ISPROPSET); }    // TODO: Don't make this a keyword...
122 "class"              { return(CLASS); }
123 "thisclass"          { return(THISCLASS); }
124 "virtual"            { return(VIRTUAL); }
125 "delete"             { return(DELETE); }
126 "new"                { return(NEWOP); }
127 "new0"               { return(NEW0OP); }
128 "renew"              { return(RENEW); }
129 "renew0"             { return(RENEW0); }
130 "import"             { return(IMPORT); }
131 "define"             { return(DEFINE); }
132 "__int64"            { return(INT64); }
133 "int64"              { return(INT64); }
134 "__builtin_va_list"  { return(VALIST); }
135 "__builtin_va_arg"   { return(VAARG); }
136 "Bool"               { return(BOOL); }
137 "_Bool"              { return(_BOOL); }
138 "_Complex"           { return(_COMPLEX); }
139 "_Imaginary"         { return(_IMAGINARY); }
140 "restrict"           { return(EXT_DECL); }
141
142  /* "__attribute__".?"(("({D}|{L})*"))" { return(EXT_ATTRIB); } */
143
144  /* DID I MEAN? "__attribute__"" "*"(("" "*({D}|{L})*" "*("("({D}|{L})*(" "*","" "*({D}|{L})*)*" "*")")?" "*"))" { return(EXT_ATTRIB); } */
145
146  /*
147  "__attribute_deprecated__"(" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
148  "__attribute__"           (" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
149  "__attribute"             (" "*)"(("(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*)(","(" "*)({D}|{L})*(" "*)("("({D}|{L}|\")*((" "*)","(" "*)({D}|{L}|\")*)*(" "*)")")?(" "*))*"))" { return(EXT_ATTRIB); }
150  */
151  /*
152  [__attribute__] [spaces]
153    [((] [spaces]
154       [digits | letters] [spaces]
155          ( [(]  [digits or letters or "]  ( [spaces] [,] [spaces] [digits or letters or "] )*  [spaces]  [)] )?
156       [spaces]
157       ( [,] [spaces]  [digits or letters]  [spaces]
158          ( [(]  [digits or letters or "]
159             ( [spaces] [,] [spaces] [digits or letters or "] )*  [spaces] [)]
160          )? [spaces]
161       )*
162    [))]
163  */
164  /* "__attribute__".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); } */
165  /* "__attribute".?"((".?({D}|{L})*.?("("({D}|{L})*(.?",".?({D}|{L})*)*.?")")?.?"))" { return(EXT_ATTRIB); }*/
166
167 "__attribute_deprecated__" { return ATTRIB_DEP; }
168 "__attribute__" { return ATTRIB; }
169 "__attribute" { return __ATTRIB; }
170
171 "__inline__"               { return(EXT_STORAGE); }
172 "_inline"                  { return(EXT_STORAGE); }
173 "__inline"                 { return(EXT_STORAGE); }
174 "inline"                   { return(EXT_STORAGE); }
175 "__declspec("({D}|{L})*")" { return(EXT_STORAGE); }
176 "dllexport"                { return(EXT_STORAGE); }
177 "dllimport"                { return(EXT_STORAGE); }
178 "__cdecl"                  { return(EXT_DECL); }
179 "__stdcall"                { return(EXT_DECL); }
180 "__stdcall__"              { return(EXT_DECL); }
181 "_stdcall"                 { return(EXT_DECL); }
182 "stdcall"                  { return(EXT_DECL); }
183 "__restrict"               { return(EXT_DECL); }
184 "__const"                  { return(CONST /*EXT_DECL*/); }
185 "__restrict__"             { return(EXT_DECL); }
186 "public"                   { return(PUBLIC); }
187 "private"                  { return(PRIVATE); }
188 "typed_object"             { return(TYPED_OBJECT); }
189 "any_object"               { return(ANY_OBJECT); }
190 "incref"                   { return(_INCREF); }
191 "__extension__"            { return(EXTENSION); }
192 "_extension_"              { return(EXTENSION); }
193 "__asm__"                  { return(ASM); }
194 "asm"                      { return(ASM); }
195 "__asm"                    { return(ASM); }
196 "__typeof"                 { return(TYPEOF); }
197 "watch"                    { return(WATCH); }
198 "stopwatching"             { return(STOPWATCHING); }
199 "firewatchers"             { return(FIREWATCHERS); }
200 "watchable"                { return(WATCHABLE); }
201 "class_designer"           { return(CLASS_DESIGNER); }
202 "class_no_expansion"       { return(CLASS_NO_EXPANSION); }
203 "class_fixed"              { return(CLASS_FIXED); }
204 "class_default_property"   { return(CLASS_DEFAULT_PROPERTY); }
205 "property_category"        { return(PROPERTY_CATEGORY); }
206 "class_data"               { return(CLASS_DATA); }
207 "class_property"           { return(CLASS_PROPERTY); }
208 "subclass"                 { return(SUBCLASS); }
209 "namespace"                { return(NAMESPACE); }
210 "dbtable"                  { return(DBTABLE); }
211 "dbfield"                  { return(DBFIELD); }
212 "dbindex"                  { return(DBINDEX); }
213 "database_open"            { return(DATABASE_OPEN); }
214
215 ("::"?(({IDENT}"&"?"::")*)){IDENT}?    { return(check_type()); }     // {L}({L}|{D})*      { return(check_type()); }  // ("::"|(({IDENT}"::")*)){IDENT}  { return(check_type()); }     // {L}({L}|{D})*      { return(check_type()); }
216
217 0[xX]{H}+{IS}?          { return(CONSTANT); }
218
219 0[xX]{H}+{P}{FS}?    { return(CONSTANT); }
220 0[xX]{H}*"."{H}+({P})?{FS}?    { return(CONSTANT); }
221 0[xX]{H}+"."{H}*({P})?{FS}?    { return(CONSTANT); }
222
223 0{D}+{IS}?              { return(CONSTANT); }
224 {D}+{IS}?               { return(CONSTANT); }
225 L?'(\\.|[^\\'])+'       { return(CONSTANT); }
226
227 {D}+{E}{FS}?            { return(CONSTANT); }
228 {D}*"."{D}+({E})?{FS}?  { return(CONSTANT); }
229 {D}+"."{D}*({E})?{FS}?  { return(CONSTANT); }
230
231 \"(\\.|[^\\"])*\"     { return(STRING_LITERAL); }
232 L\"(\\.|[^\\"])*\"     { return(WIDE_STRING_LITERAL); }
233
234 "..."       { return(ELLIPSIS); }
235 ">>="       { return(RIGHT_ASSIGN); }
236 "<<="       { return(LEFT_ASSIGN); }
237 "+="        { return(ADD_ASSIGN); }
238 "-="        { return(SUB_ASSIGN); }
239 "*="        { return(MUL_ASSIGN); }
240 "/="        { return(DIV_ASSIGN); }
241 "%="        { return(MOD_ASSIGN); }
242 "&="        { return(AND_ASSIGN); }
243 "^="        { return(XOR_ASSIGN); }
244 "|="        { return(OR_ASSIGN); }
245 ">>"        { return(RIGHT_OP); }
246 "<<"        { return(LEFT_OP); }
247 "++"        { return(INC_OP); }
248 "--"        { return(DEC_OP); }
249 "->"        { return(PTR_OP); }
250 "&&"        { return(AND_OP); }
251 "||"        { return(OR_OP); }
252 "<="        { return(LE_OP); }
253 ">="        { return(GE_OP); }
254 "=="        { return(EQ_OP); }
255 "!="        { return(NE_OP); }
256    /* "::"        { return(CLASS_OP); } */
257 ";"         { return(';'); }
258 ("{"|"<%")  { return('{'); }
259 ("}"|"%>")  { return('}'); }
260 ","         { return(','); }
261 ":"         { return(':'); }
262 "="         { return('='); }
263 "("         { return('('); }
264 ")"         { return(')'); }
265 ("["|"<:")  { return('['); }
266 ("]"|":>")  { return(']'); }
267 "."         { return('.'); }
268 "&"         { return('&'); }
269 "!"         { return('!'); }
270 "~"         { return('~'); }
271 "-"         { return('-'); }
272 "+"         { return('+'); }
273 "*"         { return('*'); }
274 "/"         { return('/'); }
275 "%"         { return('%'); }
276 "<"         { return('<'); }
277 ">"         { return('>'); }
278 "^"         { return('^'); }
279 "|"         { return('|'); }
280 "?"         { return('?'); }
281 "$"         { return('$'); }
282
283 <<EOF>> {
284       while(include_stack_ptr && !fileStack[include_stack_ptr-1])
285       {
286          --include_stack_ptr;
287          defaultDeclMode = declMode = structDeclMode = declModeStack[include_stack_ptr];
288       }
289
290       if ( --include_stack_ptr < 0 )
291       {
292          include_stack_ptr = 0;
293          yyterminate();
294       }
295       else
296       {
297          delete fileInput;
298          yy_delete_buffer( YY_CURRENT_BUFFER );
299          fileInput = fileStack[include_stack_ptr];
300          yylloc = locStack[include_stack_ptr];
301          type_yylloc = locStack[include_stack_ptr];
302          expression_yylloc = locStack[include_stack_ptr];
303          yy_switch_to_buffer(include_stack[include_stack_ptr] );
304          defaultDeclMode = declMode = structDeclMode = declModeStack[include_stack_ptr];
305       }
306    }
307
308
309 [ \v\f]   { yylloc.start = yylloc.end; type_yylloc.start = type_yylloc.end; expression_yylloc.start = expression_yylloc.end;}
310 [\n+]    {
311    yylloc.end.charPos = 1; yylloc.end.line += yyleng; yylloc.start = yylloc.end;
312    type_yylloc.end.charPos = 1; type_yylloc.end.line += yyleng; type_yylloc.start = type_yylloc.end;
313    expression_yylloc.end.charPos = 1; expression_yylloc.end.line += yyleng; expression_yylloc.start = expression_yylloc.end;
314    }
315 [\t]     {
316    yylloc.start.charPos++ /*= 3 - (yylloc.start.col % 3)*/; yylloc.end.charPos = yylloc.start.charPos; yylloc.start.pos = yylloc.end.pos;
317    expression_yylloc.start.charPos++ /*= 3 - (expression_yylloc.start.col % 3)*/; expression_yylloc.end.charPos = expression_yylloc.start.charPos; expression_yylloc.start.pos = expression_yylloc.end.pos;
318    type_yylloc.start.charPos++ /*= 3 - (type_yylloc.start.col % 3)*/; type_yylloc.end.charPos = type_yylloc.start.charPos; type_yylloc.start.pos = type_yylloc.end.pos;
319    }
320 [\r]  { yylloc.start = yylloc.end; expression_yylloc.start = expression_yylloc.end;  type_yylloc.start = type_yylloc.end; }
321 .         {
322    yylloc.start = yylloc.end; expression_yylloc.start = expression_yylloc.end;  type_yylloc.start = type_yylloc.end;
323    if(inCompiler)
324       printf("lexer error: invalid char 0x%X at line %d, col %d\n", (unsigned char)yytext[0], yylloc.start.line, yylloc.start.charPos);
325    yyerror();
326    }
327
328 %%
329
330 private:
331
332 int yywrap()
333 {
334    return(1);
335 }
336
337 int comment()
338 {
339    int c, last = 0;
340    for(;;)
341    {
342       c = input();
343       if(c == EOF) break;
344
345       // fputc(c, output);
346       // putchar(c);
347       if(c == '\n')
348       {
349          yylloc.end.charPos = 1;
350          yylloc.end.pos++;
351          yylloc.end.line++;
352       }
353       else if (c == '\t')
354       {
355          yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
356          yylloc.end.pos++;
357       }
358       else
359       {
360          yylloc.end.charPos++;
361          yylloc.end.pos++;
362       }
363       if(c == '/' && last == '*')
364          break;
365       last = c;
366    }
367    yylloc.start = yylloc.end;
368    return 0;
369 }
370
371 int commentCPP()
372 {
373    int c; //, last = 0;
374    for(;;)
375    {
376       c = input();
377       if(c == EOF) break;
378
379       // fputc(c, output);
380       // putchar(c);
381       if(c == '\n')
382       {
383          yylloc.end.charPos = 1;
384          yylloc.end.pos++;
385          yylloc.end.line++;
386          break;
387       }
388       else if (c == '\t')
389       {
390          yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
391          yylloc.end.pos++;
392       }
393       else
394       {
395          yylloc.end.charPos++;
396          yylloc.end.pos++;
397       }
398       //last = c;
399    }
400    yylloc.start = yylloc.end;
401    return 0;
402 }
403
404 int preprocessor()
405 {
406    int c, last = 0;
407    int count = 0;
408    char line[1024];
409
410    line[0] = '\0';
411
412    for(;;)
413    {
414       c = input();
415       if(c == EOF) break;
416
417       if(c == '\n')
418       {
419          yylloc.end.charPos = 1;
420          yylloc.end.pos++;
421          yylloc.end.line++;
422          if(last != '\\')
423          {
424             char * pointer = line + 1;
425             int lineNumber;
426             line[count] = 0;
427             lineNumber = GetValue(&pointer);
428             if(lineNumber)
429             {
430                char fileName[MAX_LOCATION];
431
432                int inOut;
433
434                fileName[0] = 0;
435                GetString(&pointer, fileName, MAX_LOCATION);
436                inOut = GetValue(&pointer);
437
438                if(inOut == 1)
439                {
440                   char extension[MAX_EXTENSION];
441
442                   defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
443
444                   GetExtension(fileName, extension);
445                   if(!strcmp(extension, "c") || !strcmp(extension, "h"))
446                      declMode = defaultDeclMode = structDeclMode = defaultAccess;
447
448                   fileStack[include_stack_ptr] = null;
449                   include_stack_ptr++;
450                }
451                else if(inOut == 2)
452                {
453                   include_stack_ptr--;
454                   defaultDeclMode = declMode = structDeclMode = declModeStack[include_stack_ptr];
455                }
456
457                yylloc.end.charPos = 1;
458                yylloc.end.line = lineNumber;
459                //yylloc.end.pos -= count;
460
461                if(include_stack_ptr > 0 || (lineNumber && fileName[0]))
462                   yylloc.end.included = GetIncludeFileID(fileName);
463                else
464                   yylloc.end.included = 0;
465             }
466             /*
467             int lineNumber = strtol(line+1, &endPtr, 0);
468             if(lineNumber)
469             {
470                GetString(&
471                endPtr
472
473                yylloc.end.charPos = 1;
474                yylloc.end.line = lineNumber;
475                yylloc.end.pos -= count;
476             }
477             */
478             break;
479          }
480          count = 0;
481       }
482       else if (c == '\t')
483       {
484          yylloc.end.charPos++ /* += 3 - (yylloc.end.col % 3)*/;
485          yylloc.end.pos++;
486          line[count++] = c;
487       }
488       else
489       {
490          yylloc.end.pos++;
491          if(c != '\r')
492          {
493             yylloc.end.charPos++;
494             line[count++] = c;
495          }
496       }
497       last = c;
498    }
499    yylloc.start = yylloc.end;
500    line[count] = 0;
501
502    TrimLSpaces(line, line);
503    for(c = 0; line[c] && line[c] != ' '; c++);
504    if(!strncmp(line, "include", c))
505    {
506       char includeFile[MAX_LOCATION] = "";
507
508       memmove(line, line+c, strlen(line+c)+1);
509       TrimLSpaces(line, line);
510       if(line[0] == '\"')
511       {
512          for(c = 1; line[c]; c++)
513          {
514             if(line[c] == '\"')
515             {
516                strncpy(includeFile, line+1, c-1);
517                includeFile[c-1] = '\0';
518                break;
519             }
520          }
521       }
522       else if(line[0] == '<')
523       {
524          for(c = 1; line[c]; c++)
525             if(line[c] == '>')
526             {
527                strncpy(includeFile, line+1, c-1);
528                includeFile[c-1] = '\0';
529                break;
530             }
531       }
532
533       if ( include_stack_ptr >= MAX_INCLUDE_DEPTH )
534       {
535          fprintf( stderr, "%s", $"Includes nested too deeply" );
536          exit( 1 );
537       }
538
539       if(inCompiler || !FindIncludeFileID(includeFile))
540       {
541          File file = OpenIncludeFile(includeFile);
542          if(file)
543          {
544             char extension[MAX_EXTENSION];
545
546             fileStack[include_stack_ptr] = fileInput;
547             locStack[include_stack_ptr] = yylloc;
548             defaultDeclMode = declModeStack[include_stack_ptr] = declMode;
549             include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
550
551             yylloc.start.charPos = yylloc.end.charPos = 1;
552             yylloc.start.line = yylloc.end.line = 1;
553             yylloc.start.pos = yylloc.end.pos = 0;
554             yylloc.start.included = yylloc.end.included = GetIncludeFileID(includeFile);
555
556             GetExtension(includeFile, extension);
557             if(!strcmp(extension, "c") || !strcmp(extension, "h"))
558                declMode = defaultDeclMode = structDeclMode = defaultAccess;
559
560             fileInput = file;
561             yy_switch_to_buffer( yy_create_buffer( fileInput, YY_BUF_SIZE ) );
562             BEGIN(INITIAL);
563          }
564       }
565    }
566    return 0;
567 }
568
569 public void resetScanner()
570 {
571    YY_FLUSH_BUFFER;
572    yylloc.start.charPos = yylloc.end.charPos = 1;
573    yylloc.start.line = yylloc.end.line = 1;
574    yylloc.start.pos = yylloc.end.pos = 0;
575    yylloc.start.included = yylloc.end.included = 0;
576
577    expression_yylloc.start.charPos = expression_yylloc.end.charPos = 1;
578    expression_yylloc.start.line = expression_yylloc.end.line = 1;
579    expression_yylloc.start.pos = expression_yylloc.end.pos = 0;
580    expression_yylloc.start.included = expression_yylloc.end.included = 0;
581
582    type_yylloc.start.charPos = type_yylloc.end.charPos = 1;
583    type_yylloc.start.line = type_yylloc.end.line = 1;
584    type_yylloc.start.pos = type_yylloc.end.pos = 0;
585    type_yylloc.start.included = type_yylloc.end.included = 0;
586
587    include_stack_ptr = 0;
588 }
589
590 void resetScannerPos(CodePosition pos)
591 {
592    YY_FLUSH_BUFFER;
593    yylloc.start = yylloc.end = pos;
594    type_yylloc.start = type_yylloc.end = pos;
595    expression_yylloc.start = expression_yylloc.end = pos;
596 }
597
598 class LexerBackup
599 {
600    YYLTYPE yylloc;
601    YYLTYPE type_yylloc;
602    YYLTYPE expression_yylloc;
603
604    AccessMode declMode;
605    AccessMode defaultDeclMode;
606
607    File fileInput;
608    YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
609    File fileStack[MAX_INCLUDE_DEPTH];
610    char sourceFileStack[MAX_INCLUDE_DEPTH][MAX_LOCATION];
611    YYLTYPE locStack[MAX_INCLUDE_DEPTH];
612    AccessMode declModeStack[MAX_INCLUDE_DEPTH];
613    int include_stack_ptr;
614    YY_BUFFER_STATE buffer;
615
616    int yy_n_chars;
617    char * yytext_ptr;
618    char * yy_c_buf_p;
619    FILE * yyin;
620    char yy_hold_char;
621    int yychar;
622    int yy_init;
623    int yy_start;
624
625 };
626
627 LexerBackup pushLexer()
628 {
629    LexerBackup backup { };
630
631    backup.yylloc = yylloc;
632    backup.type_yylloc = type_yylloc;
633    backup.expression_yylloc = expression_yylloc;
634    backup.fileInput = fileInput;
635    memcpy(backup.include_stack, include_stack, sizeof(include_stack));
636    memcpy(backup.fileStack, fileStack, sizeof(fileStack));
637    memcpy(backup.sourceFileStack, sourceFileStack, sizeof(sourceFileStack));
638    memcpy(backup.locStack, locStack, sizeof(locStack));
639    memcpy(backup.declModeStack, declModeStack, sizeof(declModeStack));
640    backup.include_stack_ptr = include_stack_ptr;
641    backup.defaultDeclMode = defaultDeclMode;
642    backup.declMode = declMode;
643    backup.buffer = yy_current_buffer;
644
645    backup.yy_n_chars = yy_n_chars;
646    backup.yytext_ptr = yytext_ptr;
647    backup.yy_c_buf_p = yy_c_buf_p;
648    backup.yyin = yyin;
649    backup.yy_hold_char = yy_hold_char;
650    backup.yychar = yychar;
651    backup.yy_init = yy_init;
652    backup.yy_start = yy_start;
653
654    yy_init = 1;
655
656    yy_current_buffer = 0;
657
658    yylloc.start.charPos = yylloc.end.charPos = 1;
659    yylloc.start.line = yylloc.end.line = 1;
660    yylloc.start.pos = yylloc.end.pos = 0;
661    yylloc.start.included = yylloc.end.included = 0;
662
663    expression_yylloc.start.charPos = expression_yylloc.end.charPos = 1;
664    expression_yylloc.start.line = expression_yylloc.end.line = 1;
665    expression_yylloc.start.pos = expression_yylloc.end.pos = 0;
666    expression_yylloc.start.included = expression_yylloc.end.included = 0;
667
668    type_yylloc.start.charPos = type_yylloc.end.charPos = 1;
669    type_yylloc.start.line = type_yylloc.end.line = 1;
670    type_yylloc.start.pos = type_yylloc.end.pos = 0;
671    type_yylloc.start.included = type_yylloc.end.included = 0;
672
673    include_stack_ptr = 0;
674
675    return backup;
676 }
677
678 void popLexer(LexerBackup backup)
679 {
680    yylloc = backup.yylloc;
681    type_yylloc = backup.type_yylloc;
682    expression_yylloc = backup.expression_yylloc;
683    fileInput = backup.fileInput;
684    memcpy(include_stack, backup.include_stack, sizeof(include_stack));
685    memcpy(fileStack, backup.fileStack, sizeof(fileStack));
686    memcpy(sourceFileStack, backup.sourceFileStack, sizeof(sourceFileStack));
687    memcpy(locStack, backup.locStack, sizeof(locStack));
688    memcpy(declModeStack, backup.declModeStack, sizeof(declModeStack));
689    include_stack_ptr = backup.include_stack_ptr;
690    defaultDeclMode = backup.defaultDeclMode;
691    declMode = structDeclMode = backup.declMode;
692
693    // yy_switch_to_buffer(backup.buffer);
694    yy_current_buffer = backup.buffer;
695    yy_n_chars = backup.yy_n_chars;
696    yytext_ptr = backup.yytext_ptr;
697    yy_c_buf_p = backup.yy_c_buf_p;
698    yyin = backup.yyin;
699    yy_hold_char = backup.yy_hold_char;
700    yychar = backup.yychar;
701    yy_init = backup.yy_init;
702    yy_start = backup.yy_start;
703
704    delete backup;
705 }