1 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20
21 #include "Lexer.h"
22 #include "Token.h"
23
24 namespace CPlusPlus {
25
classify2(const char * s,LanguageFeatures)26 static inline int classify2(const char *s, LanguageFeatures)
27 {
28 if (s[0] == 'd') {
29 if (s[1] == 'o') {
30 return T_DO;
31 }
32 }
33 else if (s[0] == 'i') {
34 if (s[1] == 'f') {
35 return T_IF;
36 }
37 }
38 return T_IDENTIFIER;
39 }
40
classify3(const char * s,LanguageFeatures features)41 static inline int classify3(const char *s, LanguageFeatures features)
42 {
43 if (s[0] == 'a') {
44 if (s[1] == 's') {
45 if (s[2] == 'm') {
46 return T_ASM;
47 }
48 }
49 }
50 else if (s[0] == 'f') {
51 if (s[1] == 'o') {
52 if (s[2] == 'r') {
53 return T_FOR;
54 }
55 }
56 }
57 else if (s[0] == 'i') {
58 if (s[1] == 'n') {
59 if (s[2] == 't') {
60 return T_INT;
61 }
62 }
63 }
64 else if (s[0] == 'n') {
65 if (s[1] == 'e') {
66 if (s[2] == 'w') {
67 return T_NEW;
68 }
69 }
70 }
71 else if (s[0] == 't') {
72 if (s[1] == 'r') {
73 if (s[2] == 'y') {
74 return T_TRY;
75 }
76 }
77 }
78 else if (features.qtMocRunEnabled && s[0] == 'Q') {
79 if (s[1] == '_') {
80 if (s[2] == 'D') {
81 return T_Q_D;
82 }
83 else if (s[2] == 'Q') {
84 return T_Q_Q;
85 }
86 }
87 }
88 return T_IDENTIFIER;
89 }
90
classify4(const char * s,LanguageFeatures features)91 static inline int classify4(const char *s, LanguageFeatures features)
92 {
93 if (s[0] == 'a') {
94 if (s[1] == 'u') {
95 if (s[2] == 't') {
96 if (s[3] == 'o') {
97 return T_AUTO;
98 }
99 }
100 }
101 }
102 else if (s[0] == 'b') {
103 if (s[1] == 'o') {
104 if (s[2] == 'o') {
105 if (s[3] == 'l') {
106 return T_BOOL;
107 }
108 }
109 }
110 }
111 else if (s[0] == 'c') {
112 if (s[1] == 'a') {
113 if (s[2] == 's') {
114 if (s[3] == 'e') {
115 return T_CASE;
116 }
117 }
118 }
119 else if (s[1] == 'h') {
120 if (s[2] == 'a') {
121 if (s[3] == 'r') {
122 return T_CHAR;
123 }
124 }
125 }
126 }
127 else if (s[0] == 'e') {
128 if (s[1] == 'l') {
129 if (s[2] == 's') {
130 if (s[3] == 'e') {
131 return T_ELSE;
132 }
133 }
134 }
135 else if (s[1] == 'n') {
136 if (s[2] == 'u') {
137 if (s[3] == 'm') {
138 return T_ENUM;
139 }
140 }
141 }
142 else if (features.qtKeywordsEnabled && s[1] == 'm') {
143 if (s[2] == 'i') {
144 if (s[3] == 't') {
145 return T_EMIT;
146 }
147 }
148 }
149 }
150 else if (s[0] == 'g') {
151 if (s[1] == 'o') {
152 if (s[2] == 't') {
153 if (s[3] == 'o') {
154 return T_GOTO;
155 }
156 }
157 }
158 }
159 else if (s[0] == 'l') {
160 if (s[1] == 'o') {
161 if (s[2] == 'n') {
162 if (s[3] == 'g') {
163 return T_LONG;
164 }
165 }
166 }
167 }
168 else if (s[0] == 't') {
169 if (s[1] == 'h') {
170 if (s[2] == 'i') {
171 if (s[3] == 's') {
172 return T_THIS;
173 }
174 }
175 }
176 else if (s[1] == 'r') {
177 if (s[2] == 'u') {
178 if (s[3] == 'e') {
179 return T_TRUE;
180 }
181 }
182 }
183 }
184 else if (s[0] == 'v') {
185 if (s[1] == 'o') {
186 if (s[2] == 'i') {
187 if (s[3] == 'd') {
188 return T_VOID;
189 }
190 }
191 }
192 }
193 else if (features.qtEnabled && s[0] == 'S') {
194 if (s[1] == 'L') {
195 if (s[2] == 'O') {
196 if (s[3] == 'T') {
197 return T_SLOT;
198 }
199 }
200 }
201 }
202 return T_IDENTIFIER;
203 }
204
classify5(const char * s,LanguageFeatures features)205 static inline int classify5(const char *s, LanguageFeatures features)
206 {
207 if (s[0] == '_') {
208 if (s[1] == '_') {
209 if (s[2] == 'a') {
210 if (s[3] == 's') {
211 if (s[4] == 'm') {
212 return T___ASM;
213 }
214 }
215 }
216 }
217 }
218 else if (s[0] == 'b') {
219 if (s[1] == 'r') {
220 if (s[2] == 'e') {
221 if (s[3] == 'a') {
222 if (s[4] == 'k') {
223 return T_BREAK;
224 }
225 }
226 }
227 }
228 }
229 else if (s[0] == 'c') {
230 if (s[1] == 'a') {
231 if (s[2] == 't') {
232 if (s[3] == 'c') {
233 if (s[4] == 'h') {
234 return T_CATCH;
235 }
236 }
237 }
238 }
239 else if (s[1] == 'l') {
240 if (s[2] == 'a') {
241 if (s[3] == 's') {
242 if (s[4] == 's') {
243 return T_CLASS;
244 }
245 }
246 }
247 }
248 else if (s[1] == 'o') {
249 if (s[2] == 'n') {
250 if (s[3] == 's') {
251 if (s[4] == 't') {
252 return T_CONST;
253 }
254 }
255 }
256 }
257 }
258 else if (s[0] == 'f') {
259 if (s[1] == 'a') {
260 if (s[2] == 'l') {
261 if (s[3] == 's') {
262 if (s[4] == 'e') {
263 return T_FALSE;
264 }
265 }
266 }
267 }
268 else if (s[1] == 'l') {
269 if (s[2] == 'o') {
270 if (s[3] == 'a') {
271 if (s[4] == 't') {
272 return T_FLOAT;
273 }
274 }
275 }
276 }
277 }
278 else if (s[0] == 's') {
279 if (s[1] == 'h') {
280 if (s[2] == 'o') {
281 if (s[3] == 'r') {
282 if (s[4] == 't') {
283 return T_SHORT;
284 }
285 }
286 }
287 }
288 else if (features.qtKeywordsEnabled) {
289 if (s[1] == 'l') {
290 if (s[2] == 'o') {
291 if (s[3] == 't') {
292 if (s[4] == 's') {
293 return T_Q_SLOTS;
294 }
295 }
296 }
297 }
298 }
299 }
300 else if (s[0] == 't') {
301 if (s[1] == 'h') {
302 if (s[2] == 'r') {
303 if (s[3] == 'o') {
304 if (s[4] == 'w') {
305 return T_THROW;
306 }
307 }
308 }
309 }
310 }
311 else if (s[0] == 'u') {
312 if (s[1] == 'n') {
313 if (s[2] == 'i') {
314 if (s[3] == 'o') {
315 if (s[4] == 'n') {
316 return T_UNION;
317 }
318 }
319 }
320 }
321 else if (s[1] == 's') {
322 if (s[2] == 'i') {
323 if (s[3] == 'n') {
324 if (s[4] == 'g') {
325 return T_USING;
326 }
327 }
328 }
329 }
330 }
331 else if (s[0] == 'w') {
332 if (s[1] == 'h') {
333 if (s[2] == 'i') {
334 if (s[3] == 'l') {
335 if (s[4] == 'e') {
336 return T_WHILE;
337 }
338 }
339 }
340 }
341 }
342 return T_IDENTIFIER;
343 }
344
classify6(const char * s,LanguageFeatures features)345 static inline int classify6(const char *s, LanguageFeatures features)
346 {
347 if (s[0] == 'd') {
348 if (s[1] == 'e') {
349 if (s[2] == 'l') {
350 if (s[3] == 'e') {
351 if (s[4] == 't') {
352 if (s[5] == 'e') {
353 return T_DELETE;
354 }
355 }
356 }
357 }
358 }
359 else if (s[1] == 'o') {
360 if (s[2] == 'u') {
361 if (s[3] == 'b') {
362 if (s[4] == 'l') {
363 if (s[5] == 'e') {
364 return T_DOUBLE;
365 }
366 }
367 }
368 }
369 }
370 }
371 else if (s[0] == 'e') {
372 if (s[1] == 'x') {
373 if (s[2] == 'p') {
374 if (s[3] == 'o') {
375 if (s[4] == 'r') {
376 if (s[5] == 't') {
377 return T_EXPORT;
378 }
379 }
380 }
381 }
382 else if (s[2] == 't') {
383 if (s[3] == 'e') {
384 if (s[4] == 'r') {
385 if (s[5] == 'n') {
386 return T_EXTERN;
387 }
388 }
389 }
390 }
391 }
392 }
393 else if (s[0] == 'f') {
394 if (s[1] == 'r') {
395 if (s[2] == 'i') {
396 if (s[3] == 'e') {
397 if (s[4] == 'n') {
398 if (s[5] == 'd') {
399 return T_FRIEND;
400 }
401 }
402 }
403 }
404 }
405 }
406 else if (s[0] == 'i') {
407 if (s[1] == 'n') {
408 if (s[2] == 'l') {
409 if (s[3] == 'i') {
410 if (s[4] == 'n') {
411 if (s[5] == 'e') {
412 return T_INLINE;
413 }
414 }
415 }
416 }
417 }
418 }
419 else if (s[0] == 'p') {
420 if (s[1] == 'u') {
421 if (s[2] == 'b') {
422 if (s[3] == 'l') {
423 if (s[4] == 'i') {
424 if (s[5] == 'c') {
425 return T_PUBLIC;
426 }
427 }
428 }
429 }
430 }
431 }
432 else if (s[0] == 'r') {
433 if (s[1] == 'e') {
434 if (s[2] == 't') {
435 if (s[3] == 'u') {
436 if (s[4] == 'r') {
437 if (s[5] == 'n') {
438 return T_RETURN;
439 }
440 }
441 }
442 }
443 }
444 }
445 else if (s[0] == 's') {
446 if (s[1] == 'i') {
447 if (s[2] == 'g') {
448 if (s[3] == 'n') {
449 if (s[4] == 'e') {
450 if (s[5] == 'd') {
451 return T_SIGNED;
452 }
453 }
454 }
455 }
456 else if (s[2] == 'z') {
457 if (s[3] == 'e') {
458 if (s[4] == 'o') {
459 if (s[5] == 'f') {
460 return T_SIZEOF;
461 }
462 }
463 }
464 }
465 }
466 else if (s[1] == 't') {
467 if (s[2] == 'a') {
468 if (s[3] == 't') {
469 if (s[4] == 'i') {
470 if (s[5] == 'c') {
471 return T_STATIC;
472 }
473 }
474 }
475 }
476 else if (s[2] == 'r') {
477 if (s[3] == 'u') {
478 if (s[4] == 'c') {
479 if (s[5] == 't') {
480 return T_STRUCT;
481 }
482 }
483 }
484 }
485 }
486 else if (s[1] == 'w') {
487 if (s[2] == 'i') {
488 if (s[3] == 't') {
489 if (s[4] == 'c') {
490 if (s[5] == 'h') {
491 return T_SWITCH;
492 }
493 }
494 }
495 }
496 }
497 }
498 else if (s[0] == 't') {
499 if (s[1] == 'y') {
500 if (s[2] == 'p') {
501 if (s[3] == 'e') {
502 if (s[4] == 'i') {
503 if (s[5] == 'd') {
504 return T_TYPEID;
505 }
506 }
507 else if (s[4] == 'o') {
508 if (s[5] == 'f') {
509 return T_TYPEOF;
510 }
511 }
512 }
513 }
514 }
515 }
516 else if (features.qtKeywordsEnabled && s[0] == 'S') {
517 if (s[1] == 'I') {
518 if (s[2] == 'G') {
519 if (s[3] == 'N') {
520 if (s[4] == 'A') {
521 if (s[5] == 'L') {
522 return T_SIGNAL;
523 }
524 }
525 }
526 }
527 }
528 }
529 else if (features.qtKeywordsEnabled && s[0] == 'Q') {
530 if (s[1] == '_') {
531 if (s[2] == 'S') {
532 if (s[3] == 'L') {
533 if (s[4] == 'O') {
534 if (s[5] == 'T') {
535 return T_Q_SLOT;
536 }
537 }
538 }
539 }
540 else if (s[2] == 'E') {
541 if (s[3] == 'M') {
542 if (s[4] == 'I') {
543 if (s[5] == 'T') {
544 return T_Q_EMIT;
545 }
546 }
547 }
548 }
549 }
550 }
551 return T_IDENTIFIER;
552 }
553
classify7(const char * s,LanguageFeatures features)554 static inline int classify7(const char *s, LanguageFeatures features)
555 {
556 if (s[0] == '_') {
557 if (s[1] == '_') {
558 if (s[2] == 'a') {
559 if (s[3] == 's') {
560 if (s[4] == 'm') {
561 if (s[5] == '_') {
562 if (s[6] == '_') {
563 return T___ASM__;
564 }
565 }
566 }
567 }
568 }
569 else if (s[2] == 'c') {
570 if (s[3] == 'o') {
571 if (s[4] == 'n') {
572 if (s[5] == 's') {
573 if (s[6] == 't') {
574 return T___CONST;
575 }
576 }
577 }
578 }
579 }
580 }
581 }
582 else if (features.cxx11Enabled && s[0] == 'a') {
583 if (s[1] == 'l') {
584 if (s[2] == 'i') {
585 if (s[3] == 'g') {
586 if (s[4] == 'n') {
587 if (s[5] == 'a') {
588 if (s[6] == 's') {
589 return T_ALIGNAS;
590 }
591 }
592 else if (s[5] == 'o') {
593 if (s[6] == 'f') {
594 return T_ALIGNOF;
595 }
596 }
597 }
598 }
599 }
600 }
601 }
602 else if (s[0] == 'd') {
603 if (s[1] == 'e') {
604 if (s[2] == 'f') {
605 if (s[3] == 'a') {
606 if (s[4] == 'u') {
607 if (s[5] == 'l') {
608 if (s[6] == 't') {
609 return T_DEFAULT;
610 }
611 }
612 }
613 }
614 }
615 }
616 }
617 else if (s[0] == 'm') {
618 if (s[1] == 'u') {
619 if (s[2] == 't') {
620 if (s[3] == 'a') {
621 if (s[4] == 'b') {
622 if (s[5] == 'l') {
623 if (s[6] == 'e') {
624 return T_MUTABLE;
625 }
626 }
627 }
628 }
629 }
630 }
631 }
632 else if (features.cxx11Enabled && s[0] == 'n') {
633 if (s[1] == 'u') {
634 if (s[2] == 'l') {
635 if (s[3] == 'l') {
636 if (s[4] == 'p') {
637 if (s[5] == 't') {
638 if (s[6] == 'r') {
639 return T_NULLPTR;
640 }
641 }
642 }
643 }
644 }
645 }
646 }
647 else if (s[0] == 'p') {
648 if (s[1] == 'r') {
649 if (s[2] == 'i') {
650 if (s[3] == 'v') {
651 if (s[4] == 'a') {
652 if (s[5] == 't') {
653 if (s[6] == 'e') {
654 return T_PRIVATE;
655 }
656 }
657 }
658 }
659 }
660 }
661 }
662 else if (features.qtKeywordsEnabled && s[0] == 'f') {
663 if (s[1] == 'o') {
664 if (s[2] == 'r') {
665 if (s[3] == 'e') {
666 if (s[4] == 'a') {
667 if (s[5] == 'c') {
668 if (s[6] == 'h') {
669 return T_Q_FOREACH;
670 }
671 }
672 }
673 }
674 }
675 }
676 }
677 else if (features.qtEnabled && s[0] == 's') {
678 if (s[1] == 'i') {
679 if (s[2] == 'g') {
680 if (s[3] == 'n') {
681 if (s[4] == 'a') {
682 if (s[5] == 'l') {
683 if (s[6] == 's') {
684 return T_Q_SIGNALS;
685 }
686 }
687 }
688 }
689 }
690 }
691 }
692 else if (s[0] == 't') {
693 if (s[1] == 'y') {
694 if (s[2] == 'p') {
695 if (s[3] == 'e') {
696 if (s[4] == 'd') {
697 if (s[5] == 'e') {
698 if (s[6] == 'f') {
699 return T_TYPEDEF;
700 }
701 }
702 }
703 }
704 }
705 }
706 }
707 else if (s[0] == 'v') {
708 if (s[1] == 'i') {
709 if (s[2] == 'r') {
710 if (s[3] == 't') {
711 if (s[4] == 'u') {
712 if (s[5] == 'a') {
713 if (s[6] == 'l') {
714 return T_VIRTUAL;
715 }
716 }
717 }
718 }
719 }
720 }
721 }
722 else if (s[0] == 'w') {
723 if (s[1] == 'c') {
724 if (s[2] == 'h') {
725 if (s[3] == 'a') {
726 if (s[4] == 'r') {
727 if (s[5] == '_') {
728 if (s[6] == 't') {
729 return T_WCHAR_T;
730 }
731 }
732 }
733 }
734 }
735 }
736 }
737 else if (features.qtEnabled && s[0] == 'Q') {
738 if (s[1] == '_') {
739 if (s[2] == 'S') {
740 if (s[3] == 'L') {
741 if (s[4] == 'O') {
742 if (s[5] == 'T') {
743 if (s[6] == 'S') {
744 return T_Q_SLOTS;
745 }
746 }
747 }
748 }
749 }
750 else if (s[2] == 'E') {
751 if (s[3] == 'N') {
752 if (s[4] == 'U') {
753 if (s[5] == 'M') {
754 if (s[6] == 'S') {
755 return T_Q_ENUMS;
756 }
757 }
758 }
759 }
760 }
761 else if (s[2] == 'F') {
762 if (s[3] == 'L') {
763 if (s[4] == 'A') {
764 if (s[5] == 'G') {
765 if (s[6] == 'S') {
766 return T_Q_FLAGS;
767 }
768 }
769 }
770 }
771 }
772 }
773 }
774 return T_IDENTIFIER;
775 }
776
classify8(const char * s,LanguageFeatures features)777 static inline int classify8(const char *s, LanguageFeatures features)
778 {
779 if (s[0] == '_') {
780 if (s[1] == '_') {
781 if (s[2] == 'i') {
782 if (s[3] == 'n') {
783 if (s[4] == 'l') {
784 if (s[5] == 'i') {
785 if (s[6] == 'n') {
786 if (s[7] == 'e') {
787 return T___INLINE;
788 }
789 }
790 }
791 }
792 }
793 }
794 else if (s[2] == 't') {
795 if (s[3] == 'y') {
796 if (s[4] == 'p') {
797 if (s[5] == 'e') {
798 if (s[6] == 'o') {
799 if (s[7] == 'f') {
800 return T___TYPEOF;
801 }
802 }
803 }
804 }
805 }
806 else if (s[3] == 'h') {
807 if (s[4] == 'r') {
808 if (s[5] == 'e') {
809 if (s[6] == 'a') {
810 if (s[7] == 'd') {
811 return T___THREAD;
812 }
813 }
814 }
815 }
816 }
817 }
818 }
819 }
820 else if (s[0] == 'c') {
821 if (s[1] == 'o') {
822 if (s[2] == 'n') {
823 if (s[3] == 't') {
824 if (s[4] == 'i') {
825 if (s[5] == 'n') {
826 if (s[6] == 'u') {
827 if (s[7] == 'e') {
828 return T_CONTINUE;
829 }
830 }
831 }
832 }
833 }
834 }
835 } else if (features.cxx11Enabled && s[1] == 'h') {
836 if (s[2] == 'a') {
837 if (s[3] == 'r') {
838 if (s[4] == '1') {
839 if (s[5] == '6') {
840 if (s[6] == '_') {
841 if (s[7] == 't') {
842 return T_CHAR16_T;
843 }
844 }
845 }
846 } else if (s[4] == '3') {
847 if (s[5] == '2') {
848 if (s[6] == '_') {
849 if (s[7] == 't') {
850 return T_CHAR32_T;
851 }
852 }
853 }
854 }
855 }
856 }
857 }
858 }
859 else if (features.cxx11Enabled && s[0] == 'd') {
860 if (s[1] == 'e') {
861 if (s[2] == 'c') {
862 if (s[3] == 'l') {
863 if (s[4] == 't') {
864 if (s[5] == 'y') {
865 if (s[6] == 'p') {
866 if (s[7] == 'e') {
867 return T_DECLTYPE;
868 }
869 }
870 }
871 }
872 }
873 }
874 }
875 }
876 else if (s[0] == 'e') {
877 if (s[1] == 'x') {
878 if (s[2] == 'p') {
879 if (s[3] == 'l') {
880 if (s[4] == 'i') {
881 if (s[5] == 'c') {
882 if (s[6] == 'i') {
883 if (s[7] == 't') {
884 return T_EXPLICIT;
885 }
886 }
887 }
888 }
889 }
890 }
891 }
892 }
893 else if (features.cxx11Enabled && s[0] == 'n') {
894 if (s[1] == 'o') {
895 if (s[2] == 'e') {
896 if (s[3] == 'x') {
897 if (s[4] == 'c') {
898 if (s[5] == 'e') {
899 if (s[6] == 'p') {
900 if (s[7] == 't') {
901 return T_NOEXCEPT;
902 }
903 }
904 }
905 }
906 }
907 }
908 }
909 }
910 else if (s[0] == 'o') {
911 if (s[1] == 'p') {
912 if (s[2] == 'e') {
913 if (s[3] == 'r') {
914 if (s[4] == 'a') {
915 if (s[5] == 't') {
916 if (s[6] == 'o') {
917 if (s[7] == 'r') {
918 return T_OPERATOR;
919 }
920 }
921 }
922 }
923 }
924 }
925 }
926 }
927 else if (s[0] == 'r') {
928 if (s[1] == 'e') {
929 if (s[2] == 'g') {
930 if (s[3] == 'i') {
931 if (s[4] == 's') {
932 if (s[5] == 't') {
933 if (s[6] == 'e') {
934 if (s[7] == 'r') {
935 return T_REGISTER;
936 }
937 }
938 }
939 }
940 }
941 }
942 }
943 }
944 else if (s[0] == 't') {
945 if (s[1] == 'e') {
946 if (s[2] == 'm') {
947 if (s[3] == 'p') {
948 if (s[4] == 'l') {
949 if (s[5] == 'a') {
950 if (s[6] == 't') {
951 if (s[7] == 'e') {
952 return T_TEMPLATE;
953 }
954 }
955 }
956 }
957 }
958 }
959 }
960 else if (s[1] == 'y') {
961 if (s[2] == 'p') {
962 if (s[3] == 'e') {
963 if (s[4] == 'n') {
964 if (s[5] == 'a') {
965 if (s[6] == 'm') {
966 if (s[7] == 'e') {
967 return T_TYPENAME;
968 }
969 }
970 }
971 }
972 }
973 }
974 }
975 }
976 else if (s[0] == 'u') {
977 if (s[1] == 'n') {
978 if (s[2] == 's') {
979 if (s[3] == 'i') {
980 if (s[4] == 'g') {
981 if (s[5] == 'n') {
982 if (s[6] == 'e') {
983 if (s[7] == 'd') {
984 return T_UNSIGNED;
985 }
986 }
987 }
988 }
989 }
990 }
991 }
992 }
993 else if (s[0] == 'v') {
994 if (s[1] == 'o') {
995 if (s[2] == 'l') {
996 if (s[3] == 'a') {
997 if (s[4] == 't') {
998 if (s[5] == 'i') {
999 if (s[6] == 'l') {
1000 if (s[7] == 'e') {
1001 return T_VOLATILE;
1002 }
1003 }
1004 }
1005 }
1006 }
1007 }
1008 }
1009 }
1010 else if (features.qtEnabled && s[0] == 'Q') {
1011 if (s[1] == '_') {
1012 if (s[2] == 'G') {
1013 if (s[3] == 'A') {
1014 if (s[4] == 'D') {
1015 if (s[5] == 'G') {
1016 if (s[6] == 'E') {
1017 if (s[7] == 'T') {
1018 return T_Q_GADGET;
1019 }
1020 }
1021 }
1022 }
1023 }
1024 }
1025 else if (s[2] == 'O') {
1026 if (s[3] == 'B') {
1027 if (s[4] == 'J') {
1028 if (s[5] == 'E') {
1029 if (s[6] == 'C') {
1030 if (s[7] == 'T') {
1031 return T_Q_OBJECT;
1032 }
1033 }
1034 }
1035 }
1036 }
1037 }
1038 else if (s[2] == 'S') {
1039 if (s[3] == 'I') {
1040 if (s[4] == 'G') {
1041 if (s[5] == 'N') {
1042 if (s[6] == 'A') {
1043 if (s[7] == 'L') {
1044 return T_Q_SIGNAL;
1045 }
1046 }
1047 }
1048 }
1049 }
1050 }
1051 }
1052 }
1053 return T_IDENTIFIER;
1054 }
1055
classify9(const char * s,LanguageFeatures features)1056 static inline int classify9(const char *s, LanguageFeatures features)
1057 {
1058 if (s[0] == '_') {
1059 if (s[1] == '_') {
1060 if (s[2] == 'c') {
1061 if (s[3] == 'o') {
1062 if (s[4] == 'n') {
1063 if (s[5] == 's') {
1064 if (s[6] == 't') {
1065 if (s[7] == '_') {
1066 if (s[8] == '_') {
1067 return T___CONST__;
1068 }
1069 }
1070 }
1071 }
1072 }
1073 }
1074 }
1075 }
1076 }
1077 else if (features.cxx11Enabled && s[0] == 'c') {
1078 if (s[1] == 'o') {
1079 if (s[2] == 'n') {
1080 if (s[3] == 's') {
1081 if (s[4] == 't') {
1082 if (s[5] == 'e') {
1083 if (s[6] == 'x') {
1084 if (s[7] == 'p') {
1085 if (s[8] == 'r') {
1086 return T_CONSTEXPR;
1087 }
1088 }
1089 }
1090 }
1091 }
1092 }
1093 }
1094 }
1095 }
1096 else if (s[0] == 'n') {
1097 if (s[1] == 'a') {
1098 if (s[2] == 'm') {
1099 if (s[3] == 'e') {
1100 if (s[4] == 's') {
1101 if (s[5] == 'p') {
1102 if (s[6] == 'a') {
1103 if (s[7] == 'c') {
1104 if (s[8] == 'e') {
1105 return T_NAMESPACE;
1106 }
1107 }
1108 }
1109 }
1110 }
1111 }
1112 }
1113 }
1114 }
1115 else if (s[0] == 'p') {
1116 if (s[1] == 'r') {
1117 if (s[2] == 'o') {
1118 if (s[3] == 't') {
1119 if (s[4] == 'e') {
1120 if (s[5] == 'c') {
1121 if (s[6] == 't') {
1122 if (s[7] == 'e') {
1123 if (s[8] == 'd') {
1124 return T_PROTECTED;
1125 }
1126 }
1127 }
1128 }
1129 }
1130 }
1131 }
1132 }
1133 }
1134 else if (features.qtEnabled && s[0] == 'Q') {
1135 if (s[1] == '_') {
1136 if (s[2] == 'S') {
1137 if (s[3] == 'I') {
1138 if (s[4] == 'G') {
1139 if (s[5] == 'N') {
1140 if (s[6] == 'A') {
1141 if (s[7] == 'L') {
1142 if (s[8] == 'S') {
1143 return T_Q_SIGNALS;
1144 }
1145 }
1146 }
1147 }
1148 }
1149 }
1150 } else if (s[2] == 'F') {
1151 if (s[3] == 'O') {
1152 if (s[4] == 'R') {
1153 if (s[5] == 'E') {
1154 if (s[6] == 'A') {
1155 if (s[7] == 'C') {
1156 if (s[8] == 'H') {
1157 return T_Q_FOREACH;
1158 }
1159 }
1160 }
1161 }
1162 }
1163 }
1164 }
1165 }
1166 }
1167 return T_IDENTIFIER;
1168 }
1169
classify10(const char * s,LanguageFeatures features)1170 static inline int classify10(const char *s, LanguageFeatures features)
1171 {
1172 if (s[0] == '_') {
1173 if (s[1] == '_') {
1174 if (s[2] == 'i') {
1175 if (s[3] == 'n') {
1176 if (s[4] == 'l') {
1177 if (s[5] == 'i') {
1178 if (s[6] == 'n') {
1179 if (s[7] == 'e') {
1180 if (s[8] == '_') {
1181 if (s[9] == '_') {
1182 return T___INLINE__;
1183 }
1184 }
1185 }
1186 }
1187 }
1188 }
1189 }
1190 }
1191 else if (s[2] == 'd') {
1192 if (s[3] == 'e') {
1193 if (s[4] == 'c') {
1194 if (s[5] == 'l') {
1195 if (s[6] == 't') {
1196 if (s[7] == 'y') {
1197 if (s[8] == 'p') {
1198 if (s[9] == 'e') {
1199 return T___DECLTYPE;
1200 }
1201 }
1202 }
1203 }
1204 }
1205 }
1206 }
1207 }
1208 else if (s[2] == 't') {
1209 if (s[3] == 'y') {
1210 if (s[4] == 'p') {
1211 if (s[5] == 'e') {
1212 if (s[6] == 'o') {
1213 if (s[7] == 'f') {
1214 if (s[8] == '_') {
1215 if (s[9] == '_') {
1216 return T___TYPEOF__;
1217 }
1218 }
1219 }
1220 }
1221 }
1222 }
1223 }
1224 }
1225 else if (s[2] == 'v') {
1226 if (s[3] == 'o') {
1227 if (s[4] == 'l') {
1228 if (s[5] == 'a') {
1229 if (s[6] == 't') {
1230 if (s[7] == 'i') {
1231 if (s[8] == 'l') {
1232 if (s[9] == 'e') {
1233 return T___VOLATILE;
1234 }
1235 }
1236 }
1237 }
1238 }
1239 }
1240 }
1241 }
1242 }
1243 }
1244 else if (s[0] == 'c') {
1245 if (s[1] == 'o') {
1246 if (s[2] == 'n') {
1247 if (s[3] == 's') {
1248 if (s[4] == 't') {
1249 if (s[5] == '_') {
1250 if (s[6] == 'c') {
1251 if (s[7] == 'a') {
1252 if (s[8] == 's') {
1253 if (s[9] == 't') {
1254 return T_CONST_CAST;
1255 }
1256 }
1257 }
1258 }
1259 }
1260 }
1261 }
1262 }
1263 }
1264 }
1265 else if (features.qtEnabled && s[0] == 'Q') {
1266 if (s[1] == '_') {
1267 if (s[2] == 'O') {
1268 if (s[3] == 'V') {
1269 if (s[4] == 'E') {
1270 if (s[5] == 'R') {
1271 if (s[6] == 'R') {
1272 if (s[7] == 'I') {
1273 if (s[8] == 'D') {
1274 if (s[9] == 'E') {
1275 return T_Q_PROPERTY; // Q_OVERRIDE is just an alias for Q_PROPERTY
1276 }
1277 }
1278 }
1279 }
1280 }
1281 }
1282 }
1283 }
1284 else if (s[2] == 'P') {
1285 if (s[3] == 'R') {
1286 if (s[4] == 'O') {
1287 if (s[5] == 'P') {
1288 if (s[6] == 'E') {
1289 if (s[7] == 'R') {
1290 if (s[8] == 'T') {
1291 if (s[9] == 'Y') {
1292 return T_Q_PROPERTY;
1293 }
1294 }
1295 }
1296 }
1297 }
1298 }
1299 }
1300 }
1301 }
1302 }
1303 return T_IDENTIFIER;
1304 }
1305
classify11(const char * s,LanguageFeatures features)1306 static inline int classify11(const char *s, LanguageFeatures features)
1307 {
1308 if (s[0] == '_') {
1309 if (s[1] == '_') {
1310 if (s[2] == 'a') {
1311 if (s[3] == 't') {
1312 if (s[4] == 't') {
1313 if (s[5] == 'r') {
1314 if (s[6] == 'i') {
1315 if (s[7] == 'b') {
1316 if (s[8] == 'u') {
1317 if (s[9] == 't') {
1318 if (s[10] == 'e') {
1319 return T___ATTRIBUTE;
1320 }
1321 }
1322 }
1323 }
1324 }
1325 }
1326 }
1327 }
1328 }
1329 }
1330 }
1331 else if (s[0] == 's') {
1332 if (s[1] == 't') {
1333 if (s[2] == 'a') {
1334 if (s[3] == 't') {
1335 if (s[4] == 'i') {
1336 if (s[5] == 'c') {
1337 if (s[6] == '_') {
1338 if (s[7] == 'c') {
1339 if (s[8] == 'a') {
1340 if (s[9] == 's') {
1341 if (s[10] == 't') {
1342 return T_STATIC_CAST;
1343 }
1344 }
1345 }
1346 }
1347 }
1348 }
1349 }
1350 }
1351 }
1352 }
1353 }
1354 else if (features.qtEnabled && s[0] == 'Q') {
1355 if (s[1] == '_') {
1356 if (s[2] == 'I') {
1357 if (s[3] == 'N') {
1358 if (s[4] == 'V') {
1359 if (s[5] == 'O') {
1360 if (s[6] == 'K') {
1361 if (s[7] == 'A') {
1362 if (s[8] == 'B') {
1363 if (s[9] == 'L') {
1364 if (s[10] == 'E') {
1365 return T_Q_INVOKABLE;
1366 }
1367 }
1368 }
1369 }
1370 }
1371 }
1372 }
1373 }
1374 }
1375 }
1376 }
1377 return T_IDENTIFIER;
1378 }
1379
classify12(const char * s,LanguageFeatures features)1380 static inline int classify12(const char *s, LanguageFeatures features)
1381 {
1382 if (s[0] == '_') {
1383 if (s[1] == '_') {
1384 if (s[2] == 'v') {
1385 if (s[3] == 'o') {
1386 if (s[4] == 'l') {
1387 if (s[5] == 'a') {
1388 if (s[6] == 't') {
1389 if (s[7] == 'i') {
1390 if (s[8] == 'l') {
1391 if (s[9] == 'e') {
1392 if (s[10] == '_') {
1393 if (s[11] == '_') {
1394 return T___VOLATILE__;
1395 }
1396 }
1397 }
1398 }
1399 }
1400 }
1401 }
1402 }
1403 }
1404 }
1405 }
1406 }
1407 else if (features.qtEnabled && s[0] == 'Q') {
1408 if (s[1] == '_') {
1409 if (s[2] == 'I') {
1410 if (s[3] == 'N') {
1411 if (s[4] == 'T') {
1412 if (s[5] == 'E') {
1413 if (s[6] == 'R') {
1414 if (s[7] == 'F') {
1415 if (s[8] == 'A') {
1416 if (s[9] == 'C') {
1417 if (s[10] == 'E') {
1418 if (s[11] == 'S') {
1419 return T_Q_INTERFACES;
1420 }
1421 }
1422 }
1423 }
1424 }
1425 }
1426 }
1427 }
1428 }
1429 }
1430 }
1431 }
1432 else if (s[0] == 'd') {
1433 if (s[1] == 'y') {
1434 if (s[2] == 'n') {
1435 if (s[3] == 'a') {
1436 if (s[4] == 'm') {
1437 if (s[5] == 'i') {
1438 if (s[6] == 'c') {
1439 if (s[7] == '_') {
1440 if (s[8] == 'c') {
1441 if (s[9] == 'a') {
1442 if (s[10] == 's') {
1443 if (s[11] == 't') {
1444 return T_DYNAMIC_CAST;
1445 }
1446 }
1447 }
1448 }
1449 }
1450 }
1451 }
1452 }
1453 }
1454 }
1455 }
1456 }
1457 else if (features.cxx11Enabled && s[0] == 't') {
1458 if (s[1] == 'h') {
1459 if (s[2] == 'r') {
1460 if (s[3] == 'e') {
1461 if (s[4] == 'a') {
1462 if (s[5] == 'd') {
1463 if (s[6] == '_') {
1464 if (s[7] == 'l') {
1465 if (s[8] == 'o') {
1466 if (s[9] == 'c') {
1467 if (s[10] == 'a') {
1468 if (s[11] == 'l') {
1469 return T_THREAD_LOCAL;
1470 }
1471 }
1472 }
1473 }
1474 }
1475 }
1476 }
1477 }
1478 }
1479 }
1480 }
1481 }
1482 return T_IDENTIFIER;
1483 }
1484
classify13(const char * s,LanguageFeatures features)1485 static inline int classify13(const char *s, LanguageFeatures features)
1486 {
1487 if (s[0] == '_') {
1488 if (s[1] == '_') {
1489 if (s[2] == 'a') {
1490 if (s[3] == 't') {
1491 if (s[4] == 't') {
1492 if (s[5] == 'r') {
1493 if (s[6] == 'i') {
1494 if (s[7] == 'b') {
1495 if (s[8] == 'u') {
1496 if (s[9] == 't') {
1497 if (s[10] == 'e') {
1498 if (s[11] == '_') {
1499 if (s[12] == '_') {
1500 return T___ATTRIBUTE__;
1501 }
1502 }
1503 }
1504 }
1505 }
1506 }
1507 }
1508 }
1509 }
1510 }
1511 }
1512 }
1513 } else if (features.cxx11Enabled && s[0] == 's') {
1514 if (s[1] == 't') {
1515 if (s[2] == 'a') {
1516 if (s[3] == 't') {
1517 if (s[4] == 'i') {
1518 if (s[5] == 'c') {
1519 if (s[6] == '_') {
1520 if (s[7] == 'a') {
1521 if (s[8] == 's') {
1522 if (s[9] == 's') {
1523 if (s[10] == 'e') {
1524 if (s[11] == 'r') {
1525 if (s[12] == 't') {
1526 return T_STATIC_ASSERT;
1527 }
1528 }
1529 }
1530 }
1531 }
1532 }
1533 }
1534 }
1535 }
1536 }
1537 }
1538 }
1539 }
1540 return T_IDENTIFIER;
1541 }
1542
classify16(const char * s,LanguageFeatures)1543 static inline int classify16(const char *s, LanguageFeatures)
1544 {
1545 if (s[0] == 'r') {
1546 if (s[1] == 'e') {
1547 if (s[2] == 'i') {
1548 if (s[3] == 'n') {
1549 if (s[4] == 't') {
1550 if (s[5] == 'e') {
1551 if (s[6] == 'r') {
1552 if (s[7] == 'p') {
1553 if (s[8] == 'r') {
1554 if (s[9] == 'e') {
1555 if (s[10] == 't') {
1556 if (s[11] == '_') {
1557 if (s[12] == 'c') {
1558 if (s[13] == 'a') {
1559 if (s[14] == 's') {
1560 if (s[15] == 't') {
1561 return T_REINTERPRET_CAST;
1562 }
1563 }
1564 }
1565 }
1566 }
1567 }
1568 }
1569 }
1570 }
1571 }
1572 }
1573 }
1574 }
1575 }
1576 }
1577 }
1578 return T_IDENTIFIER;
1579 }
1580
classify14(const char * s,LanguageFeatures features)1581 static inline int classify14(const char *s, LanguageFeatures features)
1582 {
1583 if (features.qtEnabled && s[0] == 'Q') {
1584 if (s[1] == '_') {
1585 if (s[2] == 'P') {
1586 if (s[3] == 'R') {
1587 if (s[4] == 'I') {
1588 if (s[5] == 'V') {
1589 if (s[6] == 'A') {
1590 if (s[7] == 'T') {
1591 if (s[8] == 'E') {
1592 if (s[9] == '_') {
1593 if (s[10] == 'S') {
1594 if (s[11] == 'L') {
1595 if (s[12] == 'O') {
1596 if (s[13] == 'T') {
1597 return T_Q_PRIVATE_SLOT;
1598 }
1599 }
1600 }
1601 }
1602 }
1603 }
1604 }
1605 }
1606 }
1607 }
1608 }
1609 }
1610 }
1611 }
1612 return T_IDENTIFIER;
1613 }
1614
classify18(const char * s,LanguageFeatures features)1615 static inline int classify18(const char *s, LanguageFeatures features)
1616 {
1617 if (features.qtEnabled && s[0] == 'Q') {
1618 if (s[1] == '_') {
1619 if (s[2] == 'P') {
1620 if (s[3] == 'R') {
1621 if (s[4] == 'I') {
1622 if (s[5] == 'V') {
1623 if (s[6] == 'A') {
1624 if (s[7] == 'T') {
1625 if (s[8] == 'E') {
1626 if (s[9] == '_') {
1627 if (s[10] == 'P') {
1628 if (s[11] == 'R') {
1629 if (s[12] == 'O') {
1630 if (s[13] == 'P') {
1631 if (s[14] == 'E') {
1632 if (s[15] == 'R') {
1633 if (s[16] == 'T') {
1634 if (s[17] == 'Y') {
1635 return T_Q_PRIVATE_PROPERTY;
1636 }
1637 }
1638 }
1639 }
1640 }
1641 }
1642 }
1643 }
1644 }
1645 }
1646 }
1647 }
1648 }
1649 }
1650 }
1651 }
1652 }
1653 }
1654 return T_IDENTIFIER;
1655 }
1656
classify19(const char * s,LanguageFeatures features)1657 static inline int classify19(const char *s, LanguageFeatures features)
1658 {
1659 if (features.qtEnabled && s[0] == 'Q') {
1660 if (s[1] == '_') {
1661 if (s[2] == 'D') {
1662 if (s[3] == 'E') {
1663 if (s[4] == 'C') {
1664 if (s[5] == 'L') {
1665 if (s[6] == 'A') {
1666 if (s[7] == 'R') {
1667 if (s[8] == 'E') {
1668 if (s[9] == '_') {
1669 if (s[10] == 'I') {
1670 if (s[11] == 'N') {
1671 if (s[12] == 'T') {
1672 if (s[13] == 'E') {
1673 if (s[14] == 'R') {
1674 if (s[15] == 'F') {
1675 if (s[16] == 'A') {
1676 if (s[17] == 'C') {
1677 if (s[18] == 'E') {
1678 return T_Q_DECLARE_INTERFACE;
1679 }
1680 }
1681 }
1682 }
1683 }
1684 }
1685 }
1686 }
1687 }
1688 }
1689 }
1690 }
1691 }
1692 }
1693 }
1694 }
1695 }
1696 }
1697 }
1698 return T_IDENTIFIER;
1699 }
1700
1701
classify(const char * s,int n,LanguageFeatures features)1702 int Lexer::classify(const char *s, int n, LanguageFeatures features) {
1703 switch (n) {
1704 case 2: return classify2(s, features);
1705 case 3: return classify3(s, features);
1706 case 4: return classify4(s, features);
1707 case 5: return classify5(s, features);
1708 case 6: return classify6(s, features);
1709 case 7: return classify7(s, features);
1710 case 8: return classify8(s, features);
1711 case 9: return classify9(s, features);
1712 case 10: return classify10(s, features);
1713 case 11: return classify11(s, features);
1714 case 12: return classify12(s, features);
1715 case 13: return classify13(s, features);
1716 case 14: return classify14(s, features);
1717 case 16: return classify16(s, features);
1718 case 18: return classify18(s, features);
1719 case 19: return classify19(s, features);
1720 default: return T_IDENTIFIER;
1721 } // switch
1722 }
1723
classifyOperator2(const char * s)1724 static inline int classifyOperator2(const char *s) {
1725 if (s[0] == 'o') {
1726 if (s[1] == 'r') {
1727 return T_OR;
1728 }
1729 }
1730 return T_IDENTIFIER;
1731 }
1732
classifyOperator3(const char * s)1733 static inline int classifyOperator3(const char *s) {
1734 if (s[0] == 'a') {
1735 if (s[1] == 'n') {
1736 if (s[2] == 'd') {
1737 return T_AND;
1738 }
1739 }
1740 }
1741 else if (s[0] == 'n') {
1742 if (s[1] == 'o') {
1743 if (s[2] == 't') {
1744 return T_NOT;
1745 }
1746 }
1747 }
1748 else if (s[0] == 'x') {
1749 if (s[1] == 'o') {
1750 if (s[2] == 'r') {
1751 return T_XOR;
1752 }
1753 }
1754 }
1755 return T_IDENTIFIER;
1756 }
1757
classifyOperator5(const char * s)1758 static inline int classifyOperator5(const char *s) {
1759 if (s[0] == 'b') {
1760 if (s[1] == 'i') {
1761 if (s[2] == 't') {
1762 if (s[3] == 'o') {
1763 if (s[4] == 'r') {
1764 return T_BITOR;
1765 }
1766 }
1767 }
1768 }
1769 }
1770 else if (s[0] == 'c') {
1771 if (s[1] == 'o') {
1772 if (s[2] == 'm') {
1773 if (s[3] == 'p') {
1774 if (s[4] == 'l') {
1775 return T_COMPL;
1776 }
1777 }
1778 }
1779 }
1780 }
1781 else if (s[0] == 'o') {
1782 if (s[1] == 'r') {
1783 if (s[2] == '_') {
1784 if (s[3] == 'e') {
1785 if (s[4] == 'q') {
1786 return T_OR_EQ;
1787 }
1788 }
1789 }
1790 }
1791 }
1792 return T_IDENTIFIER;
1793 }
1794
classifyOperator6(const char * s)1795 static inline int classifyOperator6(const char *s) {
1796 if (s[0] == 'a') {
1797 if (s[1] == 'n') {
1798 if (s[2] == 'd') {
1799 if (s[3] == '_') {
1800 if (s[4] == 'e') {
1801 if (s[5] == 'q') {
1802 return T_AND_EQ;
1803 }
1804 }
1805 }
1806 }
1807 }
1808 }
1809 else if (s[0] == 'b') {
1810 if (s[1] == 'i') {
1811 if (s[2] == 't') {
1812 if (s[3] == 'a') {
1813 if (s[4] == 'n') {
1814 if (s[5] == 'd') {
1815 return T_BITAND;
1816 }
1817 }
1818 }
1819 }
1820 }
1821 }
1822 else if (s[0] == 'n') {
1823 if (s[1] == 'o') {
1824 if (s[2] == 't') {
1825 if (s[3] == '_') {
1826 if (s[4] == 'e') {
1827 if (s[5] == 'q') {
1828 return T_NOT_EQ;
1829 }
1830 }
1831 }
1832 }
1833 }
1834 }
1835 else if (s[0] == 'x') {
1836 if (s[1] == 'o') {
1837 if (s[2] == 'r') {
1838 if (s[3] == '_') {
1839 if (s[4] == 'e') {
1840 if (s[5] == 'q') {
1841 return T_XOR_EQ;
1842 }
1843 }
1844 }
1845 }
1846 }
1847 }
1848 return T_IDENTIFIER;
1849 }
1850
classifyOperator(const char * s,int n)1851 int Lexer::classifyOperator(const char *s, int n) {
1852 switch (n) {
1853 case 2: return classifyOperator2(s);
1854 case 3: return classifyOperator3(s);
1855 case 5: return classifyOperator5(s);
1856 case 6: return classifyOperator6(s);
1857 default: return T_IDENTIFIER;
1858 } // switch
1859 }
1860
1861
1862 } // namespace CPlusPlus
1863