vtkParse.l 27.2 KB
Newer Older
Andy Cedilnik's avatar
Andy Cedilnik committed
1
%option yylineno
2
%{
3
4
5
6
7
8
9

/*

This file must be translated to C and modified to build everywhere.

Run flex like this:

10
  flex --nodefault -olex.yy.c vtkParse.l
11
12

Modify lex.yy.c:
David Gobbi's avatar
David Gobbi committed
13
14
15
  - convert tabs to spaces (8 spaces per tab)
  - remove extra space from end of lines
  - remove blank lines from end of file
16
  - replace "int yyl" with "yy_size_t yyl"
17
  - compile with gcc and "-Wsign-compare", there should be no warnings
18
19
20

*/

21
22
/* We do not care of interactive mode */
#define YY_NEVER_INTERACTIVE 1
23

24
25
26
27
28
29
/* Do not include unistd.h in generated source. */
#define YY_NO_UNISTD_H

/* Skip declaring this function.  It is a macro.  */
#define YY_SKIP_YYWRAP

30
#ifdef _WIN32
31
#pragma warning ( disable : 4018 )
32
#pragma warning ( disable : 4127 )
33
#pragma warning ( disable : 4131 )
34
#pragma warning ( disable : 4244 )
35
36
#pragma warning ( disable : 4251 )
#pragma warning ( disable : 4267 )
37
38
39
#pragma warning ( disable : 4305 )
#pragma warning ( disable : 4309 )
#pragma warning ( disable : 4706 )
40
#pragma warning ( disable : 4786 )
41
42
#endif

43
44
45
46
47
#define SKIP_MATCH_MAXLEN 15

/*
 * Skip ahead until one of the strings is found,
 * then skip to the end of the line.
48
 * Return 0 if no match found.
49
 */
50
static int skip_comment();
51
52
static int skip_ahead_multi(const char *strings[]);
static int skip_ahead_until(const char *text);
53
54
static int skip_to_next_directive();
static int skip_conditional_block();
55

56
static void print_preprocessor_error(int result, const char *cp, size_t n);
57
58
59
60
static const char *get_macro_arguments();

static void push_buffer();
static int pop_buffer();
61

62
63
64
%}


65
66
%%

67
"/*" { skip_comment(); };
68

69
^[\t ]*"//BTX".* {
70
       if (!IgnoreBTX) {
71
         skip_ahead_until("//ETX");
72
       }
73
74
     };

75
^[\t ]*"//ETX".* ;
76

77
78
^[\t ]*("@interface"|"@implementation") {
       skip_ahead_until("@end");
79
80
     };

81
^[\t ]*"// .NAME".* {
82
     size_t pos = 1;
83
84
     while (yytext[pos-1] != 'M' || yytext[pos] != 'E')
       {
85
       pos++;
86
       }
87
     data.NameComment = vtkstrndup(&yytext[pos + 1], yyleng - pos - 1);
88
89
     };

90
91
92
93
94
95
96
97
98
99
^[\t ]*"// Description:".*         { setCommentState(1); };
^[\t ]*"// .SECTION Description".* { setCommentState(2); };
^[\t ]*"// .SECTION See Also".*    { setCommentState(3); };
^[\t ]*"// .SECTION see also".*    { setCommentState(3); };
^[\t ]*"// .SECTION Caveats".*     { setCommentState(4); };
^[\t ]*[\r\n]                      { closeOrClearComment(); };
^[\t ]*"//".*  {
     size_t pos = 2;
     while (yytext[pos-2] != '/' || yytext[pos-1] != '/') pos++;
     addCommentLine(&yytext[pos], yyleng - pos);
100
101
     };

102
"//".* ;
103

104
^[\t ]*"#"[\t ]*"define"[\t ]+"VTK_"[a-zA-Z0-9_]+[^(](\\\n|\\\r\n|[^\n])*  {
105
106
107
108
     int result;
     MacroInfo *macro;
     result = vtkParsePreprocess_HandleDirective(&preprocessor, yytext);
     if (result == VTK_PARSE_OK)
109
       {
110
111
       macro = preprocessor.Macros[preprocessor.NumberOfMacros-1];
       if (!macro->IsFunction)
112
         {
113
         add_constant(macro->Name, vtkstrdup(macro->Definition), 0, NULL, 1);
114
         }
115
       }
116
     };
117

118
119
120
121
122
123
124
125
126
127
128
129
^[\t ]*"#"(\\\n|\\\r\n|[^\n])*  {
     int result = 0;
     result = vtkParsePreprocess_HandleDirective(&preprocessor, yytext);
     if (result == VTK_PARSE_SKIP)
       {
       skip_conditional_block();
       }
     else if (result != VTK_PARSE_OK)
       {
       print_preprocessor_error(result, yytext, yyleng);
       }
     };
130
131

\"([^\"]|\\\")*\"      {
132
                yylval.str = vtkstrndup(yytext, yyleng);
133
134
135
                return(STRING_LITERAL); }

\'([^\']|\\\')+\'      {
136
                yylval.str = vtkstrndup(yytext, yyleng);
137
138
                return(CHAR_LITERAL); }

139
[A-Za-z0-9_]*"_EXPORT" ;
140

141
"vtkNotUsed"([ \t]*"("[^)]*")")? {
142
     size_t i; size_t j = 0;
143
144
145
146
147
148
149
150
151
152
     yylval.str = "";
     if (yytext[yyleng-1] == ')')
       {
       while (yytext[j]!='(') { j++; }
       while (yytext[j]==' ' || yytext[j]=='\t') { j++; }
       j++; i = j;
       while (yytext[j]!=')' && yytext[j] != ' ' && yytext[j] != '\t') { j++; }
       yylval.str = vtkstrndup(&yytext[i], j-i);
       return(ID);
       }
153
     };
154

155
156
157
("friend"[\t\n\r ]+)?("template"[\t\n\r ]*"<"[^>]*">"[\t\n\r ]*)?"class"[\t\n\r ]+[a-zA-Z_][a-zA-Z0-9_]*("::"[a-zA-Z_][a-zA-Z0-9_]*)*[\t\n\r ]*";" {
     return(CLASS_REF);
     };
158

159
160
161
("friend"[\t\n\r ]+)?("template"[\t\n\r ]*"<"[^>]*">"[\t\n\r ]*)?"struct"[\t\n\r ]+[a-zA-Z_][a-zA-Z0-9_]*("::"[a-zA-Z_][a-zA-Z0-9_]*)*[\t\n\r ]*";" {
     return(CLASS_REF);
     };
162

163
164
165
166
("friend"[\t\n\r ]+)?("template"[\t\n\r ]*"<"[^>]*">"[\t\n\r ]*)?"union"[\t\n\r ]+[a-zA-Z_][a-zA-Z0-9_]*("::"[a-zA-Z_][a-zA-Z0-9_]*)*[\t\n\r ]*";" {
     return(CLASS_REF);
     };

167
"void"[\t\n\r ]*"("[\t\n\r ]*"*"[a-zA-Z0-9_]*[\t\n\r ]*")"[\t\n\r ]*"("[\t\n\r ]*"void"[\t\n\r ]*"*"[\n\t ]*")" {
168
     size_t i = 0; size_t j = 0;
169
170
171
172
     while (yytext[j] != '*') { i++; j++; }
     i++; j++;
     while (yytext[i] != ' ' && yytext[i] != '\t' &&
            yytext[i] != '\n' && yytext[i] != '\r' && yytext[i] != ')') {i++;}
173
     yylval.str = vtkstrndup(&yytext[j], i-j);
174
175
     return(VAR_FUNCTION);
     };
176

177
178
179
180
181
182
183
184
185
186
187
"long"[\t\n\r ]*"double"                       return(LONG_DOUBLE);
"double"                                       return(DOUBLE);
"float"                                        return(FLOAT);

"unsigned"[\t\n\r ]*"__int64"                  return(UNSIGNED_INT64__);
"__int64"[\t\n\r ]*"unsigned"                  return(UNSIGNED_INT64__);

"signed"[\t\n\r ]*"__int64"                    return(INT64__);
"__int64"[\t\n\r ]*"signed"                    return(INT64__);
"__int64"                                      return(INT64__);

188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"int"[\t\n\r ]*"unsigned"[\t\n\r ]*"long"[\t\n\r ]*"long" return(UNSIGNED_LONG_LONG);
"unsigned"[\t\n\r ]*"int"[\t\n\r ]*"long"[\t\n\r ]*"long" return(UNSIGNED_LONG_LONG);
"long"[\t\n\r ]*"long"[\t\n\r ]*"unsigned"[\t\n\r ]*"int" return(UNSIGNED_LONG_LONG);
"long"[\t\n\r ]*"long"[\t\n\r ]*"int"[\t\n\r ]*"unsigned" return(UNSIGNED_LONG_LONG);
"int"[\t\n\r ]*"long"[\t\n\r ]*"long"[\t\n\r ]*"unsigned" return(UNSIGNED_LONG_LONG);
"unsigned"[\t\n\r ]*"long"[\t\n\r ]*"long"[\t\n\r ]*"int" return(UNSIGNED_LONG_LONG);
"unsigned"[\t\n\r ]*"long"[\t\n\r ]*"long"     return(UNSIGNED_LONG_LONG);
"long"[\t\n\r ]*"long"[\t\n\r ]*"unsigned"     return(UNSIGNED_LONG_LONG);

"int"[\t\n\r ]*"signed"[\t\n\r ]*"long"[\t\n\r ]*"long"  return(LONG_LONG);
"signed"[\t\n\r ]*"int"[\t\n\r ]*"long"[\t\n\r ]*"long"  return(LONG_LONG);
"long"[\t\n\r ]*"long"[\t\n\r ]*"signed"[\t\n\r ]*"int"  return(LONG_LONG);
"long"[\t\n\r ]*"long"[\t\n\r ]*"int"[\t\n\r ]*"signed"  return(LONG_LONG);
"int"[\t\n\r ]*"long"[\t\n\r ]*"long"[\t\n\r ]*"signed"  return(LONG_LONG);
"signed"[\t\n\r ]*"long"[\t\n\r ]*"long"[\t\n\r ]*"int"  return(LONG_LONG);
"signed"[\t\n\r ]*"long"[\t\n\r ]*"long"       return(LONG_LONG);
"long"[\t\n\r ]*"long"[\t\n\r ]*"signed"       return(LONG_LONG);
"int"[\t\n\r ]*"long"[\t\n\r ]*"long"          return(LONG_LONG);
"long"[\t\n\r ]*"long"[\t\n\r ]*"int"          return(LONG_LONG);
"long"[\t\n\r ]*"long"                         return(LONG_LONG);
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262

"int"[\t\n\r ]*"unsigned"[\t\n\r ]*"short"     return(UNSIGNED_SHORT);
"unsigned"[\t\n\r ]*"int"[\t\n\r ]*"short"     return(UNSIGNED_SHORT);
"short"[\t\n\r ]*"unsigned"[\t\n\r ]*"int"     return(UNSIGNED_SHORT);
"short"[\t\n\r ]*"int"[\t\n\r ]*"unsigned"     return(UNSIGNED_SHORT);
"int"[\t\n\r ]*"short"[\t\n\r ]*"unsigned"     return(UNSIGNED_SHORT);
"unsigned"[\t\n\r ]*"short"[\t\n\r ]*"int"     return(UNSIGNED_SHORT);
"unsigned"[\t\n\r ]*"short"                    return(UNSIGNED_SHORT);
"short"[\t\n\r ]*"unsigned"                    return(UNSIGNED_SHORT);

"int"[\t\n\r ]*"signed"[\t\n\r ]*"short"       return(SHORT);
"signed"[\t\n\r ]*"int"[\t\n\r ]*"short"       return(SHORT);
"short"[\t\n\r ]*"signed"[\t\n\r ]*"int"       return(SHORT);
"short"[\t\n\r ]*"int"[\t\n\r ]*"signed"       return(SHORT);
"int"[\t\n\r ]*"short"[\t\n\r ]*"signed"       return(SHORT);
"signed"[\t\n\r ]*"short"[\t\n\r ]*"int"       return(SHORT);
"signed"[\t\n\r ]*"short"                      return(SHORT);
"short"[\t\n\r ]*"signed"                      return(SHORT);
"int"[\t\n\r ]*"short"                         return(SHORT);
"short"[\t\n\r ]*"int"                         return(SHORT);
"short"                                        return(SHORT);

"int"[\t\n\r ]*"unsigned"[\t\n\r ]*"long"      return(UNSIGNED_LONG);
"unsigned"[\t\n\r ]*"int"[\t\n\r ]*"long"      return(UNSIGNED_LONG);
"long"[\t\n\r ]*"unsigned"[\t\n\r ]*"int"      return(UNSIGNED_LONG);
"long"[\t\n\r ]*"int"[\t\n\r ]*"unsigned"      return(UNSIGNED_LONG);
"int"[\t\n\r ]*"long"[\t\n\r ]*"unsigned"      return(UNSIGNED_LONG);
"unsigned"[\t\n\r ]*"long"[\t\n\r ]*"int"      return(UNSIGNED_LONG);
"unsigned"[\t\n\r ]*"long"                     return(UNSIGNED_LONG);
"long"[\t\n\r ]*"unsigned"                     return(UNSIGNED_LONG);

"int"[\t\n\r ]*"signed"[\t\n\r ]*"long"        return(LONG);
"signed"[\t\n\r ]*"int"[\t\n\r ]*"long"        return(LONG);
"long"[\t\n\r ]*"signed"[\t\n\r ]*"int"        return(LONG);
"long"[\t\n\r ]*"int"[\t\n\r ]*"signed"        return(LONG);
"int"[\t\n\r ]*"long"[\t\n\r ]*"signed"        return(LONG);
"signed"[\t\n\r ]*"long"[\t\n\r ]*"int"        return(LONG);
"signed"[\t\n\r ]*"long"                       return(LONG);
"long"[\t\n\r ]*"signed"                       return(LONG);
"int"[\t\n\r ]*"long"                          return(LONG);
"long"[\t\n\r ]*"int"                          return(LONG);
"long"                                         return(LONG);

"unsigned"[\t\n\r ]*"char"                     return(UNSIGNED_CHAR);
"char"[\t\n\r ]*"unsigned"                     return(UNSIGNED_CHAR);
"char"[\t\n\r ]*"signed"                       return(SIGNED_CHAR);
"signed"[\t\n\r ]*"char"                       return(SIGNED_CHAR);
"char"                                         return(CHAR);

"unsigned"[\t\n\r ]*"int"                      return(UNSIGNED_INT);
"int"[\t\n\r ]*"unsigned"                      return(UNSIGNED_INT);

"signed"[\t\n\r ]*"int"                        return(INT);
"int"[\t\n\r ]*"signed"                        return(INT);
"int"                                          return(INT);
263

264
265
"unsigned"      return(UNSIGNED);
"signed"        return(SIGNED);
266

267
268
"void"          return(VOID);
"bool"          return(BOOL);
269

270
271
"size_t"        return(SIZE_T);
"ssize_t"       return(SSIZE_T);
272

273
274
275
276
277
278
"Q_OBJECT"                     ;
"public"[\t\n\r ]*"slots"/:    return(PUBLIC);
"private"[\t\n\r ]*"slots"/:   return(PRIVATE);
"protected"[\t\n\r ]*"slots"/: return(PROTECTED);
"signals"/:                    return(PROTECTED);

279
"class"         return(CLASS);
280
"struct"        return(STRUCT);
281
282
283
284
285
"public"        return(PUBLIC);
"private"       return(PRIVATE);
"protected"     return(PROTECTED);
"enum"          return(ENUM);
"union"         return(UNION);
286
287
"virtual"       return(VIRTUAL);
"const"         return(CONST);
288
"mutable"       return(MUTABLE);
289
290
"operator"      return(OPERATOR);
"friend"        return(FRIEND);
291
"inline"        return(INLINE);
292
"static"        return(STATIC);
293
"extern"        return(EXTERN);
294
295
296
297
298
299
300
"template"      return(TEMPLATE);
"typename"      return(TYPENAME);
"typedef"       return(TYPEDEF);
"namespace"     return(NAMESPACE);
"using"         return(USING);
"new"           return(NEW);
"delete"        return(DELETE);
301
302
"explicit"      return(EXPLICIT);

303
304
305
306
307
"static_cast"   return(STATIC_CAST);
"dynamic_cast"  return(DYNAMIC_CAST);
"const_cast"    return(CONST_CAST);
"reinterpret_cast" return(REINTERPRET_CAST);

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
"auto"          ;
"register"      ;
"volatile"      ;

"and"           return(OP_LOGIC_AND);
"and_eq"        return(OP_AND_EQ);
"or"            return(OP_LOGIC_OR);
"or_eq"         return(OP_OR_EQ);
"not"           return('!');
"not_eq"        return(OP_LOGIC_NEQ);
"xor"           return('^');
"xor_eq"        return(OP_XOR_EQ);
"bitand"        return('&');
"bitor"         return('|');
"compl"         return('~');
323

324
"vtkFloatingPointType" return(FloatType);
325
"vtkIdType"            return(IdType);
326
327
328
329
330
331
332
333
334
335
336
"vtkSetMacro"          return(SetMacro);
"vtkGetMacro"          return(GetMacro);
"vtkSetStringMacro"    return(SetStringMacro);
"vtkGetStringMacro"    return(GetStringMacro);
"vtkSetClampMacro"     return(SetClampMacro);
"vtkSetObjectMacro"    return(SetObjectMacro);
"vtkGetObjectMacro"    return(GetObjectMacro);
"vtkBooleanMacro"      return(BooleanMacro);
"vtkSetVector2Macro"   return(SetVector2Macro);
"vtkSetVector3Macro"   return(SetVector3Macro);
"vtkSetVector4Macro"   return(SetVector4Macro);
337
"vtkSetVector6Macro"   return(SetVector6Macro);
338
339
340
"vtkGetVector2Macro"   return(GetVector2Macro);
"vtkGetVector3Macro"   return(GetVector3Macro);
"vtkGetVector4Macro"   return(GetVector4Macro);
341
"vtkGetVector6Macro"   return(GetVector6Macro);
342
343
"vtkSetVectorMacro"    return(SetVectorMacro);
"vtkGetVectorMacro"    return(GetVectorMacro);
344
"vtkViewportCoordinateMacro" return(ViewportCoordinateMacro);
Ken Martin's avatar
Ken Martin committed
345
"vtkWorldCoordinateMacro" return(WorldCoordinateMacro);
346
347
"vtkExportedTypeMacro" return(TypeMacro);
"vtkExportedTypeRevisionMacro" return(TypeMacro);
Will Schroeder's avatar
Will Schroeder committed
348
"vtkTypeMacro"         return(TypeMacro);
349
"vtkTypeRevisionMacro" return(TypeMacro);
350
"VTK_LEGACY"           return(VTK_LEGACY);
351
352
"VTK_WRAP_EXTERN"      ;
"VTK_BYTE_SWAP_DECL"   return(VTK_BYTE_SWAP_DECL);
353
354
355
356
357
358
359
360
361
362
363
"vtkTypeInt8"          return(TypeInt8);
"vtkTypeUInt8"         return(TypeUInt8);
"vtkTypeInt16"         return(TypeInt16);
"vtkTypeUInt16"        return(TypeUInt16);
"vtkTypeInt32"         return(TypeInt32);
"vtkTypeUInt32"        return(TypeUInt32);
"vtkTypeInt64"         return(TypeInt64);
"vtkTypeUInt64"        return(TypeUInt64);
"vtkTypeFloat32"       return(TypeFloat32);
"vtkTypeFloat64"       return(TypeFloat64);

364
"*"[\r\n\t ]*"const"   return(CONST_PTR);
365
"const"[\r\n\t ]*"="   return(CONST_EQUAL);
366

367
"("[\t\n\r ]*([a-zA-Z_][a-zA-Z0-9_]*::)*"&" {
368
369
                size_t i = 1;
                size_t j;
370
371
372
373
                while (yytext[i]==' ' || yytext[i]=='\t' ||
                       yytext[i]=='\r' || yytext[i]=='\n') { i++; }
                j = i;
                while (yytext[j]!='&') { j++; }
374
                yylval.str = vtkstrndup(&yytext[i], j-i);
375
376
377
                return(LA); }

"("[\t\n\r ]*([a-zA-Z_][a-zA-Z0-9_]*::)*"*" {
378
379
                size_t i = 1;
                size_t j;
380
381
382
383
                while (yytext[i]==' ' || yytext[i]=='\t' ||
                       yytext[i]=='\r' || yytext[i]=='\n') { i++; }
                j = i;
                while (yytext[j]!='*') { j++; }
384
                yylval.str = vtkstrndup(&yytext[i], j-i);
385
386
387
                return(LP); }

"("[\t\n\r ]*("APIENTRY"|"CALLBACK"|"WINAPI")[\t\n\r ]*"*" {
388
                yylval.str = "";
389
390
391
                return(LP); }

"("[\t\n\r ]*("APIENTRYP"|"CALLBACKP"|"WINAPIP") {
392
                yylval.str = "";
393
394
395
396
397
398
399
400
401
                return(LP); }

("APIENTRYP"|"CALLBACKP"|"WINAPIP") { return('*'); }

"APIENTRY" ;
"CALLBACK" ;
"WINAPI" ;

("vtkstd::"|"std::")?"ostream" {
402
                     yylval.str = vtkstrndup(yytext, yyleng);
403
404
405
                     return(OSTREAM); }

("vtkstd::"|"std::")?"istream" {
406
                     yylval.str = vtkstrndup(yytext, yyleng);
407
408
                     return(ISTREAM); }

409
("vtkStdString"|("vtkstd::"|"std::")?"string")/[^a-zA-Z0-9_] {
410
                     yylval.str = vtkstrndup(yytext, yyleng);
411
                     return(StdString); }
412

413
"vtkUnicodeString" { yylval.str = vtkstrndup(yytext, yyleng);
414
                     return(UnicodeString); }
415

416
"vtkDataArray" { yylval.str = vtkstrdup("vtkDataArray"); return(VTK_ID); }
417

418
419
"VTK_"[0-9a-zA-Z_]* { yylval.str = vtkstrndup(yytext, yyleng);
                      return(ID); }
420
421
422

"Qt::"[0-9a-zA-Z_]* { yylval.str = vtkstrndup(yytext, yyleng);
                      return(QT_ID); }
423

424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
"__attribute__" { get_macro_arguments(); };

[a-zA-Z_][0-9a-zA-Z_]*  {
     const char *name = vtkstrndup(yytext, yyleng);
     MacroInfo *macro = vtkParsePreprocess_GetMacro(&preprocessor, name);
     int expanded = 0;

     if (macro)
       {
       if (macro->IsFunction)
         {
         const char *args = get_macro_arguments();
         const char *emacro = NULL;
         if (args)
           {
           emacro = vtkParsePreprocess_ExpandMacro(macro, args);
           free((char *)args);
441
442
443
444
445
446
447
448
449
450
451
452
           if (emacro)
             {
             push_buffer();
             yy_switch_to_buffer(yy_scan_string(emacro));
             vtkParsePreprocess_FreeExpandedMacro(emacro);
             expanded = 1;
             }
           else
             {
             print_preprocessor_error(
               VTK_PARSE_MACRO_NUMARGS, macro->Name, strlen(macro->Name));
             }
453
           }
454
         }
455
       /* non-function macro expansion breaks "real superclass" trick
456
457
458
459
460
461
       else if (macro->Definition)
         {
         push_buffer();
         yy_switch_to_buffer(yy_scan_string(macro->Definition));
         expanded = 1;
         }
462
       */
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
       }
     if (!expanded)
       {
       yylval.str = name;
       if (yyleng > 3 && name[0] == 'v' && name[1] == 't' && name[2] == 'k')
         {
         return(VTK_ID);
         }
       else if (name[0] == 'Q')
         {
         return(QT_ID);
         }
       else
         {
         return(ID);
         }
       }
     };
481

482
[0-9]+"."[0-9]*([eE][+-]?[0-9]+)?[a-zA-Z_]*  {
483
                     yylval.str = vtkstrndup(yytext, yyleng);
484
                     return(FLOAT_LITERAL); }
485

486
"0"[xX][0-9a-fA-F]+[g-zG-Z_]*      {
487
                     yylval.str = vtkstrndup(yytext, yyleng);
488
                     return(HEX_LITERAL); }
489

490
"0"[0-9]+[a-zA-Z_]*   {
491
                     yylval.str = vtkstrndup(yytext, yyleng);
492
                     return(OCT_LITERAL); }
493

494
[1-9][0-9]*[a-zA-Z_]* {
495
                     yylval.str = vtkstrndup(yytext, yyleng);
496
                     return(INT_LITERAL); }
497

498
"0"                { yylval.str = vtkstrndup(yytext, yyleng);
499
                     return(ZERO); };
500

501
502
"\\\n" ;
"\\\r\n" ;
503
[\t\n\r ] ;
504

505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
"<<="             return(OP_LSHIFT_EQ);
">>="             return(OP_RSHIFT_EQ);
"<<"              return(OP_LSHIFT);
"->*"             return(OP_ARROW_POINTER);
"->"              return(OP_ARROW);
">>"              return(OP_RSHIFT);
"++"              return(OP_INCR);
"--"              return(OP_DECR);
"+="              return(OP_PLUS_EQ);
"-="              return(OP_MINUS_EQ);
"*="              return(OP_TIMES_EQ);
"/="              return(OP_DIVIDE_EQ);
"%="              return(OP_REMAINDER_EQ);
"&="              return(OP_AND_EQ);
"|="              return(OP_OR_EQ);
"^="              return(OP_XOR_EQ);
"&&="             return(OP_LOGIC_AND_EQ);
"||="             return(OP_LOGIC_OR_EQ);
"&&"              return(OP_LOGIC_AND);
"||"              return(OP_LOGIC_OR);
"=="              return(OP_LOGIC_EQ);
"!="              return(OP_LOGIC_NEQ);
"<="              return(OP_LOGIC_LEQ);
">="              return(OP_LOGIC_GEQ);
"..."             return(ELLIPSIS);
"::"              return(DOUBLE_COLON);

"[" { return(yytext[0]); }
"]" { return(yytext[0]); }

[~{}()<>:;*/%=,&.!+|^\-] { return(yytext[0]); }
536

537
538
539
540
<<EOF>> { if (!pop_buffer()) { yyterminate(); } }

.  { return(OTHER); }

541
%%
542

543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/*
 * Return a parenthetical macro arg list as a new string.
 */
const char *get_macro_arguments()
{
  char *cp = NULL;
  size_t i = 0;
  int depth;
  int ws = 0;
  int sl = 0;
  int c1 = input();
  while (c1 == ' ' || c1 == '\t' || c1 == '\r' || c1 == '\n')
    {
    c1 = input();
    }

  cp = (char *)malloc(4);

  if (c1 != '(')
    {
    unput(c1);
    return NULL;
    }

  cp[i++] = '(';
  depth = 1;
  c1 = input();

  for (;;)
    {
    ws = 0;
    sl = 0;
    /* skip all whitespace */
    while (c1 == ' ' || c1 == '\t' || c1 == '\r' || c1 == '\n')
      {
      ws = 1;
      c1 = input();
      }
    if (c1 == '/')
      {
      c1 = input();
      if (c1 == '*')
        {
        /* skip a C style comment */
        ws = 1;
        if (skip_comment() == 0)
          {
          return NULL;
          }
        c1 = input();
        }
      else if (c1 == '/')
        {
        /* skip a C++ style comment */
        ws = 1;
        do { c1 = input(); }
        while (c1 != '\n' && c1 != '\0');
        if (c1 == '\0')
          {
          return NULL;
          }
        c1 = input();
        }
      else
        {
        sl = 1;
        }
      }
    if (ws)
      {
      /* add a single space to replace any whitespace */
      cp[i++] = ' ';
      if (i >= 4 && (i & (i-1)) == 0)
        {
        cp = (char *)realloc(cp, 2*i);
        }
      }
    if (sl)
      {
      /* add a single space to replace any whitespace */
      cp[i++] = '/';
      if (i >= 4 && (i & (i-1)) == 0)
        {
        cp = (char *)realloc(cp, 2*i);
        }
      }
    if (c1 == '\"' || c1 == '\'')
      {
      int c2 = c1;
      int escaped = 2;
      int firstloop = 1;
      do
        {
        if (escaped)
          {
          --escaped;
          }
        if (!firstloop)
          {
          c1 = input();
          }
        firstloop = 0;
        if (c1 == '\0')
          {
          break;
          }
        if (escaped == 0 && c1 == '\\')
          {
          escaped = 2;
          }
        cp[i++] = (char)c1;
        if (i >= 4 && (i & (i-1)) == 0)
          {
          cp = (char *)realloc(cp, 2*i);
          }
        }
      while (c1 != c2 || escaped);
      }
    else if (c1 != '\0')
      {
      cp[i++] = (char)c1;
      if (i >= 4 && (i & (i-1)) == 0)
        {
        cp = (char *)realloc(cp, 2*i);
        }
      cp[i] = '\0';
      if (c1 == '(')
        {
        depth++;
        }
      if (c1 == ')')
        {
        if (--depth == 0)
          {
          break;
          }
        }
      }
    else
      {
      return NULL;
      }
    c1 = input();
    }

  return cp;
}

691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
/*
 * Skip a C-style comment, return 0 if unterminated.
 */
int skip_comment()
{
   int c1 = 0, c2 = input();
   for (;;)
     {
     if (c2 == 0)
       {
       fprintf(yyout,"Cannot find closing comment.\n");
       return 0;
       }
     if (c1 == '*' && c2 == '/') break;
     c1 = c2; c2 = input();
     }
   return 1;
}

/*
 * Skip ahead until the next preprocessor directive.
 * This will eat the '#' that starts the directive.
 * Return 0 if none found.
 */
int skip_to_next_directive()
{
  int state = 0;
  int c;

  do
    {
    c = input();
    if (c == 0)
      {
      break;
      }

    /* newline changes state */
    if (c == '\n')
      {
      state = 0;
      c = input();
      }
    /* skip comments */
    if (c == '/')
      {
      if ( (c = input()) == '*')
        {
        if (skip_comment() == 0)
          {
          return 0;
          }
        c = input();
        }
      }
    /* skip escaped newlines */
    if (c == '\\')
      {
      if ( (c = input()) == '\r')
        {
        c = input();
        }
      if (c == '\n')
        {
        c = input();
        }
      }
    /* skip allowed whitespace */
    while (c == ' ' || c == '\t')
      {
      c = input();
      }
    /* look for the directive */
    if (state == 0 && c == '#')
      {
      break;
      }
    }
  while (c != 0);

  return c;
}

/*
 * Skip to the next #else or #elif or #endif
 */
int skip_conditional_block()
{
  static char *linebuf = NULL;
  static size_t linemaxlen = 80;
  size_t i;
  int c;
  int result;

  if (linebuf == 0)
    {
    linebuf = (char *)malloc(linemaxlen);
    }

  for (;;)
    {
    if (skip_to_next_directive() == 0)
      {
      return 0;
      }
    c = input();
    while (c == ' ' || c == '\t')
      {
      c = input();
      }
    if (c == 0)
      {
      return 0;
      }

    /* eat the whole line */
    i = 0;
    linebuf[i++] = '#';
    while (c != 0 && c != '\n')
      {
      if (i >= linemaxlen-5)
        {
        linemaxlen += i+5;
        linebuf = (char *)realloc(linebuf, linemaxlen);
        }
      linebuf[i++] = c;
      /* be sure to skip escaped newlines */
      if (c == '\\')
        {
        c = input();
        linebuf[i++] = c;
        if (c == '\r')
          {
          c = input();
          linebuf[i++] = c;
          }
        }
      c = input();
      }
    linebuf[i++] = c;

    result = vtkParsePreprocess_HandleDirective(&preprocessor, linebuf);
    if (result != VTK_PARSE_SKIP && result != VTK_PARSE_OK)
      {
      print_preprocessor_error(result, linebuf, i);
      }
    else if (result != VTK_PARSE_SKIP)
      {
      break;
      }
    }

  return 1;
}

846
847
848
849
850
851
852
853
/*
 * Skip ahead until one of the strings is found,
 * then skip to the end of the line.
 */
int skip_ahead_multi(const char *strings[])
{
  char textbuf[SKIP_MATCH_MAXLEN+1];
  char c = 0;
854
  size_t i;
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894

  for (i = 0; i < (SKIP_MATCH_MAXLEN+1); i++)
    {
    textbuf[i] = '\0';
    }

  for (;;)
    {
    for (i = 0; i < SKIP_MATCH_MAXLEN; i++)
      {
      textbuf[i] = textbuf[i+1];
      }

    if ((c = (char)input()) == '\0')
      {
      fprintf(yyout, "Cannot find matching %s.\n", strings[0]);
      return 0;
      }

    textbuf[SKIP_MATCH_MAXLEN-1] = c;

    for (i = 0; strings[i]; i++)
      {
      if (strcmp(&textbuf[SKIP_MATCH_MAXLEN-strlen(strings[i])],
                 strings[i]) == 0)
        {
        break;
        }
      }
    if (strings[i])
      {
      break;
      }
    }

  while (c != '\0' && c != '\n')
    {
    c = (char)input();
    }

895
  return 1;
896
897
898
}

/*
899
 * Skip ahead until the string is found.
900
901
902
903
904
905
906
907
908
 */
int skip_ahead_until(const char *text)
{
  const char *strings[2];
  strings[0] = text;
  strings[1] = NULL;

  return skip_ahead_multi(strings);
}
909

910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
/*
 * buffer stack, used for macro expansion and include files
 */
static size_t buffer_stack_size = 0;
static YY_BUFFER_STATE *buffer_stack = NULL;

/*
 * push the current buffer onto the buffer stack.
 */
void push_buffer()
{
  size_t n = buffer_stack_size;
  if (buffer_stack == NULL)
    {
    buffer_stack = (YY_BUFFER_STATE *)malloc(4*sizeof(YY_BUFFER_STATE));
    }
  // grow the stack whenever size reaches a power of two
  else if (n >= 4 && (n & (n-1)) == 0)
    {
    buffer_stack = (YY_BUFFER_STATE *)realloc(
      buffer_stack, 2*n*sizeof(YY_BUFFER_STATE));
    }
  buffer_stack[buffer_stack_size++] = YY_CURRENT_BUFFER;
}

/*
 * pop the buffer stack and restore the previous buffer
 */
int pop_buffer()
{
  if (buffer_stack_size == 0)
    {
    return 0;
    }
  yy_delete_buffer(YY_CURRENT_BUFFER);
  yy_switch_to_buffer(buffer_stack[--buffer_stack_size]);
  return 1;
}

949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
/*
 * print an error with filename and line number.
 */
void print_preprocessor_error(int result, const char *cp, size_t n)
{
  size_t j = 0;
  const char *fn = "";
  const char *text = "";

  switch (result)
    {
    case VTK_PARSE_OK:
    case VTK_PARSE_SKIP:
      return;
    case VTK_PARSE_PREPROC_DOUBLE:
      text = "double in preprocessor conditional";
      break;
    case VTK_PARSE_PREPROC_FLOAT:
      text = "float in preprocessor conditional";
      break;
    case VTK_PARSE_PREPROC_STRING:
      text = "string in preprocessor conditional";
      break;
    case VTK_PARSE_MACRO_UNDEFINED:
      text = "undefined macro";
      break;
    case VTK_PARSE_MACRO_REDEFINED:
      text = "redefined macro";
      break;
    case VTK_PARSE_FILE_NOT_FOUND:
      text = "file not found";
      break;
    case VTK_PARSE_FILE_OPEN_ERROR:
      text = "can\'t open file";
      break;
    case VTK_PARSE_FILE_READ_ERROR:
      text = "input/output error";
      break;
987
988
989
    case VTK_PARSE_MACRO_NUMARGS:
      text = "wrong number of args for macro";
      break;
990
991
992
993
994
995
996
997
998
999
1000
    case VTK_PARSE_SYNTAX_ERROR:
      text = "syntax error";
      break;
    }

  /* be silent about missing include files */
  if (result == VTK_PARSE_FILE_NOT_FOUND)
    {
    return;
    }