-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathscanner.l
1872 lines (1634 loc) · 67.8 KB
/
scanner.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
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
536
537
538
539
540
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
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
846
847
848
849
850
851
852
853
854
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
895
896
897
898
899
900
901
902
903
904
905
906
907
908
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
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
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%option nounput
%option noinput
%option stack
%option noyywrap
%{
#if defined _MSC_VER
// signed/unsigned mismatch
#pragma warning(disable:4365)
// macro re-definition: flex conditonally defines INT32_MAX et al. and thus
// they are set before library headers get to define them
#pragma warning(disable:4005)
#endif
/*
* This scanner is based on:
*
* cpp5.l, a C/C++ scanner written by James A. Roskind.
* "Portions Copyright (c) 1989, 1990 James A. Roskind".
* (http://www.idiom.com/free-compilers/,
* ftp://ftp.infoseek.com/ftp/pub/c++grammar/,
* ftp://ftp.sra.co.jp/.a/pub/cmd/c++grammar2.0.tar.gz)
*/
#ifdef _WIN32
#define YY_NO_UNISTD_H
static int isatty(int) { return 0; }
#endif
#include <util/string_constant.h>
#include <util/string2int.h>
#include <util/unicode.h>
#include "preprocessor_line.h"
#include "literals/convert_float_literal.h"
#include "literals/convert_integer_literal.h"
#include "literals/convert_character_literal.h"
#include "literals/convert_string_literal.h"
#include "literals/unescape_string.h"
#define PARSER (*ansi_c_parser)
#define YYSTYPE unsigned
#undef ECHO
#define ECHO
#include "ansi_c_parser.h"
#include "ansi_c_y.tab.h"
#ifdef ANSI_C_DEBUG
extern int yyansi_cdebug;
#endif
static ansi_c_parsert *ansi_c_parser;
void ansi_c_scanner_init(ansi_c_parsert &_ansi_c_parser)
{
#ifdef ANSI_C_DEBUG
yyansi_cdebug=1;
#endif
ansi_c_parser = &_ansi_c_parser;
YY_FLUSH_BUFFER;
BEGIN(0);
}
int yyansi_cerror(const std::string &error)
{
ansi_c_parser->parse_error(error, yyansi_ctext);
return 0;
}
#define loc() \
{ newstack(yyansi_clval); PARSER.set_source_location(parser_stack(yyansi_clval)); }
int make_identifier()
{
loc();
// deal with universal charater names
std::string final_base_name;
final_base_name.reserve(yyleng);
for(const char *p=yytext; *p!=0; p++)
{
if(p[0]=='\\' && (p[1]=='u' || p[1]=='U'))
{
p++;
unsigned digits=(*p=='u')?4:8;
p++;
unsigned letter=hex_to_unsigned(p, digits);
for(; *p!=0 && digits>0; digits--, p++);
p--; // go back for p++ later
std::basic_string<unsigned> utf32;
utf32+=letter;
// turn into utf-8
const std::string utf8_value = utf32_native_endian_to_utf8(utf32);
final_base_name+=utf8_value;
}
else
final_base_name+=*p;
}
if(PARSER.cpp98)
{
parser_stack(yyansi_clval).id(ID_symbol);
parser_stack(yyansi_clval).set(ID_C_base_name, final_base_name);
return PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO ?
TOK_MSC_IDENTIFIER : TOK_GCC_IDENTIFIER;
}
else
{
// this hashes the base name
irep_idt base_name=final_base_name;
// figure out if this is a typedef or something else
irep_idt identifier;
ansi_c_id_classt result=
PARSER.lookup(base_name, identifier, PARSER.tag_following, false);
PARSER.tag_following=false;
parser_stack(yyansi_clval).set(ID_C_base_name, base_name);
parser_stack(yyansi_clval).set(ID_identifier, identifier);
parser_stack(yyansi_clval).set(ID_C_id_class, static_cast<int>(result));
if(result==ansi_c_id_classt::ANSI_C_TYPEDEF)
{
parser_stack(yyansi_clval).id(ID_typedef_type);
return TOK_TYPEDEFNAME;
}
else
{
parser_stack(yyansi_clval).id(ID_symbol);
return PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO ?
TOK_MSC_IDENTIFIER : TOK_GCC_IDENTIFIER;
}
}
}
int MSC_Keyword(int token)
{
if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{
loc();
PARSER.tag_following=false;
return token;
}
else
return make_identifier();
}
int cpp98_keyword(int token)
{
if(PARSER.cpp98)
{
loc();
return token;
}
else
return make_identifier();
}
int cpp11_keyword(int token)
{
if(PARSER.cpp11)
{
loc();
return token;
}
else
return make_identifier();
}
int MSC_cpp_keyword(int token)
{
if(PARSER.cpp98 && PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{
loc();
return token;
}
else
return make_identifier();
}
int cpp_operator(int token)
{
if(PARSER.cpp98)
{
loc();
return token;
}
else
{
yyansi_cerror("C++ operator not allowed in C mode");
return TOK_SCANNER_ERROR;
}
}
#include <util/pragma_wsign_compare.def> // IWYU pragma: keep
#include <util/pragma_wnull_conversion.def> // IWYU pragma: keep
#include <util/pragma_wdeprecated_register.def> // IWYU pragma: keep
/*** macros for easier rule definition **********************************/
%}
delimiter [ \t\b\r]
newline [\n\f\v]|"\\\n"
whitespace {delimiter}+
ws {delimiter}*
ucletter [A-Z]
lcletter [a-z]
letter ({ucletter}|{lcletter})
digit [0-9]
bindigit [01]
octdigit [0-7]
hexdigit [0-9a-fA-F]
utf8letter [\x80-\xff]
universal_character ("\\u"{hexdigit}{4})|("\\U"{hexdigit}{8})
identifier (({letter}|"_"|"$"|{utf8letter}|{universal_character})({letter}|{digit}|"_"|"$"|{utf8letter}|{universal_character})*)
integer {digit}+
binary {bindigit}+
msiw_suffix ([iI]("8"|"16"|"32"|"64"|"128"))
int_suffix [uUlLiIjJ]*|[uU]?{msiw_suffix}
bininteger "0"[bB]({bindigit}|"'")+{int_suffix}
decinteger [1-9]({digit}|"'")*{int_suffix}
octinteger "0"({octdigit}|"'")*{int_suffix}
hexinteger "0"[xX]{hexdigit}({hexdigit}|"'")*{int_suffix}
integer_s {decinteger}|{bininteger}|{octinteger}|{hexinteger}
exponent [eE][+-]?{integer}
fraction {integer}
float1 {integer}"."{fraction}?({exponent})?
float2 "."{fraction}({exponent})?
float3 {integer}{exponent}
hexfloat1 "0"[xX]{hexdigit}*"."{hexdigit}+[pP][+-]?{integer}
hexfloat2 "0"[xX]{hexdigit}*"."[pP][+-]?{integer}
hexfloat3 "0"[xX]{hexdigit}*[pP][+-]?{integer}
float_suffix [fFlLiIjJ]*
clang_ext_float_suffix [qQ]|"f16"|"F16"
gcc_ext_float_width (("bf"|"BF")"16")|([fF]("32"|"64"|"128"|"32x"|"64x"|"128x"))
gcc_ext_float_suffix {clang_ext_float_suffix}|[wW]|[dD][fFdDlL]?|{gcc_ext_float_width}
float {float1}|{float2}|{float3}|{hexfloat1}|{hexfloat2}|{hexfloat3}
float_s {float}{float_suffix}|{integer}[fF]
gcc_ext_float_s {float}{gcc_ext_float_suffix}
clang_ext_float_s {float}{clang_ext_float_suffix}
cppstart {ws}"#"{ws}
cpplineno {cppstart}"line"*{ws}{integer}{ws}.*{newline}
cppdirective {cppstart}({newline}|[^p].*|"p"[^r].*|"pr"[^a].*|"pra"[^g].*|"prag"[^m].*|"pragm"[^a].*)
escape_sequence [\\][^\n]
c_char [^'\\\n]|{escape_sequence}
s_char [^"\\\n]|{escape_sequence}
char_lit ("L"|"u"|"U")?[']{c_char}+[']
string_lit ("L"|"u"|"U"|"u8")?["]{s_char}*["]
CPROVER_PREFIX "__CPROVER_"
arith_check ("conversion"|"undefined-shift"|"nan"|"div-by-zero"|"float-div-by-zero")
enum_check "enum-range"
pointer_primitive "pointer-primitive"
memory_check ("bounds"|"pointer"|"memory-leak")
overflow_check ("signed"|"unsigned"|"pointer"|"float")"-overflow"
named_check ["]({arith_check}|{enum_check}|{memory_check}|{overflow_check}|{pointer_primitive})["]
enable_or_disable ("enable"|"disable")
%x GRAMMAR
%x COMMENT1
%x COMMENT2
%x STRING_LITERAL
%x STRING_LITERAL_COMMENT
%x ASM_BLOCK
%x MSC_ASM
%x IGNORE_PARENS
%x MSC_PRAGMA
%x MSC_ANNOTATION
%x GCC_ATTRIBUTE1
%x GCC_ATTRIBUTE1a
%x GCC_ATTRIBUTE2
%x GCC_ATTRIBUTE3
%x GCC_ATTRIBUTE4
%x GCC_ATTRIBUTE5
%x GCC_ASM
%x GCC_ASM_PAREN
%x CPROVER_ID
%x CPROVER_PRAGMA
%x OTHER_PRAGMA
%%
<INITIAL>.|\n { BEGIN(GRAMMAR);
yyless(0); /* start again with this character */
}
<GRAMMAR>"/*" { BEGIN(COMMENT1); } /* begin C comment state */
<COMMENT1>{
"*/" { BEGIN(GRAMMAR); } /* end comment state, back to GRAMMAR */
"/*" { yyansi_cerror("Probably nested comments"); }
<<EOF>> { yyansi_cerror("Unterminated comment"); return TOK_SCANNER_ERROR; }
[^*/\n]* { /* ignore every char except '*' and NL (performance!) */ }
. { } /* all single characters within comments are ignored */
\n { }
}
<STRING_LITERAL_COMMENT>{
"*/" { yy_pop_state(); } /* end comment state, back to STRING_LITERAL */
"/*" { yyansi_cerror("Probably nested comments"); }
<<EOF>> { yyansi_cerror("Unterminated comment"); return TOK_SCANNER_ERROR; }
[^*/\n]* { /* ignore every char except '*' and NL (performance!) */ }
. { } /* all single characters within comments are ignored */
\n { }
}
<GRAMMAR>"//" { BEGIN(COMMENT2); } /* begin C++ comment state */
<COMMENT2>{
\n { BEGIN(GRAMMAR); } /* end comment state, back GRAMMAR */
.* { } /* all characters within comments are ignored */
}
<GRAMMAR>{char_lit} {
loc();
source_locationt l=parser_stack(yyansi_clval).source_location();
parser_stack(yyansi_clval)=convert_character_literal(yytext, true, l);
return TOK_CHARACTER;
}
<GRAMMAR,GCC_ATTRIBUTE3>{string_lit} {
PARSER.string_literal.clear();
PARSER.string_literal.append(yytext);
loc();
// String literals can be continued in
// the next line
yy_push_state(STRING_LITERAL);
// use yy_top_state() to keep the compiler happy
(void)yy_top_state();
}
<STRING_LITERAL>{string_lit} { PARSER.string_literal.append(yytext); }
<STRING_LITERAL>{newline} { /* ignore */ }
<STRING_LITERAL>{whitespace} { /* ignore */ }
<STRING_LITERAL>{cpplineno} {
preprocessor_line(yytext, PARSER);
PARSER.set_line_no(PARSER.get_line_no()-1);
}
<STRING_LITERAL>{cppstart}.* { /* ignore */ }
<STRING_LITERAL>"/*" { yy_push_state(STRING_LITERAL_COMMENT); /* C comment, ignore */ }
<STRING_LITERAL>"//".*\n { /* C++ comment, ignore */ }
<STRING_LITERAL>. { // anything else: back to normal
source_locationt l=parser_stack(yyansi_clval).source_location();
parser_stack(yyansi_clval)=convert_string_literal(PARSER.string_literal);
parser_stack(yyansi_clval).add_source_location().swap(l);
yy_pop_state(); // back to normal
yyless(0); // put back
return TOK_STRING;
}
<GRAMMAR>{newline} { } /* skipped */
<GRAMMAR>{whitespace} { } /* skipped */
<GRAMMAR>{cpplineno} {
preprocessor_line(yytext, PARSER);
PARSER.set_line_no(PARSER.get_line_no()-1);
}
<GRAMMAR>{cppstart}"pragma"{ws}"pack"{ws}"("{ws}"push"{ws}")"{ws}{newline} {
// Done by Visual Studio and gcc
// http://msdn.microsoft.com/en-us/library/2e70t5y1%28v=vs.80%29.aspx
// push, pop could also use identifiers
if(PARSER.pragma_pack.empty())
PARSER.pragma_pack.push_back(convert_integer_literal("0"));
else
PARSER.pragma_pack.push_back(PARSER.pragma_pack.back());
}
<GRAMMAR>{cppstart}"pragma"{ws}"pack"{ws}"("{ws}"push"{ws}","{ws}{integer_s}{ws}")"{ws}{newline} {
// Done by Visual Studio and gcc
// http://msdn.microsoft.com/en-us/library/2e70t5y1%28v=vs.80%29.aspx
// push, pop could also use identifiers
std::string tmp(yytext);
std::string::size_type p=tmp.find(',')+1;
while(tmp[p]==' ' || tmp[p]=='\t') ++p;
std::string value=std::string(tmp, p, tmp.find_last_not_of(") \t\n\r")+1-p);
exprt n=convert_integer_literal(value);
PARSER.pragma_pack.push_back(n);
}
<GRAMMAR>{cppstart}"pragma"{ws}"pack"{ws}"("{ws}{integer_s}{ws}")"{ws}{newline} {
// Done by Visual Studio and gcc
// http://msdn.microsoft.com/en-us/library/2e70t5y1%28v=vs.80%29.aspx
std::string tmp(yytext);
std::string::size_type p=tmp.find('(')+1;
while(tmp[p]==' ' || tmp[p]=='\t') ++p;
std::string value=std::string(tmp, p, tmp.find_last_not_of(") \t\n\r")+1-p);
exprt n=convert_integer_literal(value);
PARSER.pragma_pack.push_back(n);
}
<GRAMMAR>{cppstart}"pragma"{ws}"pack"{ws}"("{ws}"pop"{ws}")"{ws}{newline} {
// Done by Visual Studio and gcc
// http://msdn.microsoft.com/en-us/library/2e70t5y1%28v=vs.80%29.aspx
// push, pop could also use identifiers
if(!PARSER.pragma_pack.empty()) PARSER.pragma_pack.pop_back();
}
<GRAMMAR>{cppstart}"pragma"{ws}"pack"{ws}"("{ws}")"{ws}{newline} {
// Done by Visual Studio and gcc
// http://msdn.microsoft.com/en-us/library/2e70t5y1%28v=vs.80%29.aspx
// should be equivalent to pop-all
PARSER.pragma_pack.clear();
}
<GRAMMAR>{cppstart}"pragma"{ws}"CPROVER" { BEGIN(CPROVER_PRAGMA); }
<CPROVER_PRAGMA>{ws}{newline} { BEGIN(GRAMMAR); }
/* CProver specific pragmas: hint to disable named checks */
<CPROVER_PRAGMA>{ws}"check"{ws}"push" {
PARSER.pragma_cprover_push();
}
<CPROVER_PRAGMA>{ws}"check"{ws}"pop" {
if(!PARSER.pragma_cprover_empty())
{
PARSER.pragma_cprover_pop();
PARSER.set_pragma_cprover();
}
}
<CPROVER_PRAGMA>{ws}"check"{ws}{enable_or_disable}{ws}{named_check} {
std::string tmp(yytext);
bool enable = tmp.find("enable")!=std::string::npos;
std::string::size_type p = tmp.find('"') + 1;
std::string check_name =
std::string(tmp, p, tmp.size() - p - 1) +
std::string("-check");
bool clash = PARSER.pragma_cprover_clash(check_name, enable);
if(clash)
{
yyansi_cerror(
"Found enable and disable pragmas for " +
id2string(check_name));
return TOK_SCANNER_ERROR;
}
PARSER.pragma_cprover_add_check(check_name, enable);
PARSER.set_pragma_cprover();
}
<CPROVER_PRAGMA>{ws}"unwind"{ws}{integer} {
std::string tmp(yytext);
std::string::size_type p = tmp.rfind('d') + 1;
auto bound = string2optional_size_t(tmp.substr(p));
if(!bound.has_value())
{
ansi_c_parser->parse_error(
"Found invalid loop unwinding annotation " + tmp, "");
return TOK_SCANNER_ERROR;
}
PARSER.pragma_cprover_add_unwind(*bound);
PARSER.set_pragma_cprover();
}
<CPROVER_PRAGMA>. {
yyansi_cerror("Unsupported #pragma CPROVER");
return TOK_SCANNER_ERROR;
}
<GRAMMAR>{cppstart}"pragma" { BEGIN(OTHER_PRAGMA); }
<OTHER_PRAGMA>.*{newline} {
/* silently ignore other pragmas */
BEGIN(GRAMMAR);
}
<GRAMMAR>{cppstart}"ident"{ws}.* { /* ignore */ }
<GRAMMAR>{cppstart}"define"{ws}.* { /* ignore */ }
<GRAMMAR>{cppstart}"undef"{ws}.* { /* ignore */ }
<GRAMMAR>{cppstart}"asm" {
if(PARSER.mode==configt::ansi_ct::flavourt::GCC) // really, this is BCC
{
BEGIN(ASM_BLOCK);
PARSER.string_literal.clear();
loc();
return '{';
}
else
return make_identifier();
}
<GRAMMAR>{cppstart}"endasm" {
loc();
return '}';
}
<GRAMMAR>{cppdirective} {
yyansi_cerror("Preprocessor directive found");
return TOK_SCANNER_ERROR;
}
%{
/*** keywords ***/
%}
<GRAMMAR,GCC_ATTRIBUTE3>{
"auto" { loc(); return TOK_AUTO; }
"_Bool" { if(PARSER.cpp98)
return make_identifier();
else
{ loc(); return TOK_BOOL; }
}
"break" { loc(); return TOK_BREAK; }
"case" { loc(); return TOK_CASE; }
"char" { loc(); return TOK_CHAR; }
"_Complex" { loc(); return TOK_COMPLEX; }
"const" { loc(); return TOK_CONST; }
"continue" { loc(); return TOK_CONTINUE; }
"default" { loc(); return TOK_DEFAULT; }
"do" { loc(); return TOK_DO; }
"double" { loc(); return TOK_DOUBLE; }
"else" { loc(); return TOK_ELSE; }
"enum" { loc(); PARSER.tag_following=true; return TOK_ENUM; }
"extern" { loc(); return TOK_EXTERN; }
"float" { loc(); return TOK_FLOAT; }
"for" { loc(); return TOK_FOR; }
"goto" { loc(); return TOK_GOTO; }
"if" { loc(); return TOK_IF; }
"inline" { loc(); return TOK_INLINE; }
"int" { loc(); return TOK_INT; }
"long" { loc(); return TOK_LONG; }
"register" { loc(); return TOK_REGISTER; }
"restrict" { loc(); return TOK_RESTRICT; }
"return" { loc(); return TOK_RETURN; }
"short" { loc(); return TOK_SHORT; }
"signed" { loc(); return TOK_SIGNED; }
"sizeof" { loc(); return TOK_SIZEOF; }
"static" { loc(); return TOK_STATIC; }
"struct" { loc(); PARSER.tag_following=true; return TOK_STRUCT; }
"switch" { loc(); return TOK_SWITCH; }
"typedef" { loc(); return TOK_TYPEDEF; }
"union" { loc(); PARSER.tag_following=true; return TOK_UNION; }
"unsigned" { loc(); return TOK_UNSIGNED; }
"void" { loc(); return TOK_VOID; }
"volatile" { loc(); return TOK_VOLATILE; }
"while" { loc(); return TOK_WHILE; }
"__auto_type" { if((PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG)
&& !PARSER.cpp98)
{ loc(); return TOK_GCC_AUTO_TYPE; }
else
return make_identifier();
}
"_Float16" { if(PARSER.float16_type)
{ loc(); return TOK_GCC_FLOAT16; }
else
return make_identifier();
}
{CPROVER_PREFIX}"Float16" {
loc(); return TOK_GCC_FLOAT16;
}
"__bf16" { if(PARSER.bf16_type)
{ loc(); return TOK_GCC_FLOAT16; }
else
return make_identifier();
}
"__fp16" { if(PARSER.fp16_type)
{ loc(); return TOK_GCC_FLOAT16; }
else
return make_identifier();
}
"_Float32" { if(PARSER.ts_18661_3_Floatn_types)
{ loc(); return TOK_GCC_FLOAT32; }
else
return make_identifier();
}
"_Float32x" { if(PARSER.ts_18661_3_Floatn_types)
{ loc(); return TOK_GCC_FLOAT32X; }
else
return make_identifier();
}
"_Float64" { if(PARSER.ts_18661_3_Floatn_types)
{ loc(); return TOK_GCC_FLOAT64; }
else
return make_identifier();
}
"_Float64x" { if(PARSER.ts_18661_3_Floatn_types)
{ loc(); return TOK_GCC_FLOAT64X; }
else
return make_identifier();
}
{CPROVER_PREFIX}"Float64x" {
loc(); return TOK_GCC_FLOAT64X;
}
{CPROVER_PREFIX}"Float80" {
loc(); return TOK_GCC_FLOAT80;
}
"__float128" { if(PARSER.__float128_is_keyword)
{ loc(); return TOK_GCC_FLOAT128; }
else
return make_identifier();
}
"_Float128" { if(PARSER.ts_18661_3_Floatn_types)
{ loc(); return TOK_GCC_FLOAT128; }
else
return make_identifier();
}
{CPROVER_PREFIX}"Float128" {
loc(); return TOK_GCC_FLOAT128;
}
"_Float128x" { if(PARSER.ts_18661_3_Floatn_types)
{ loc(); return TOK_GCC_FLOAT128X; }
else
return make_identifier();
}
"__int128" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG)
{ loc(); return TOK_GCC_INT128; }
else
return make_identifier();
}
"_Decimal32" { // clang doesn't have it
if(PARSER.mode==configt::ansi_ct::flavourt::GCC)
{ loc(); return TOK_GCC_DECIMAL32; }
else
return make_identifier();
}
"_Decimal64" { // clang doesn't have it
if(PARSER.mode==configt::ansi_ct::flavourt::GCC)
{ loc(); return TOK_GCC_DECIMAL64; }
else
return make_identifier();
}
"_Decimal128" { // clang doesn't have it
if(PARSER.mode==configt::ansi_ct::flavourt::GCC)
{ loc(); return TOK_GCC_DECIMAL128; }
else
return make_identifier();
}
"__int8" { return MSC_Keyword(TOK_INT8); }
"__int16" { return MSC_Keyword(TOK_INT16); }
"__int32" { return MSC_Keyword(TOK_INT32); }
"__int64" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO ||
PARSER.mode==configt::ansi_ct::flavourt::ARM ||
PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR)
{ loc(); return TOK_INT64; }
else
return make_identifier();
}
"_int64" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{ loc(); return TOK_INT64; }
else
return make_identifier();
}
"__ptr32" { return MSC_Keyword(TOK_PTR32); }
"__ptr64" { return MSC_Keyword(TOK_PTR64); }
%{
/*
"__stdcall" { return MSC_Keyword(TOK_STDCALL); }
"__fastcall" { return MSC_Keyword(TOK_FASTCALL); }
"__clrcall" { return MSC_Keyword(TOK_CLRCALL); }
*/
%}
"__complex__" |
"__complex" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_COMPLEX; }
else
return make_identifier();
}
"__real__" |
"__real" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_REAL; }
else
return make_identifier();
}
"__imag__" |
"__imag" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_IMAG; }
else
return make_identifier();
}
%{
/* note: "wchar_t" should be in the list above, but it is left out */
/* because it is a 'typedef' in some standard header files */
%}
"_var_arg_typeof" { if(PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR)
{ loc(); return TOK_CW_VAR_ARG_TYPEOF; }
else
return make_identifier();
}
"__builtin_va_arg" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_BUILTIN_VA_ARG; }
else
return make_identifier();
}
"__builtin_offsetof" |
"__offsetof__" |
"offsetof" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_OFFSETOF; }
else
return make_identifier();
}
"__builtin_types_compatible_p" {
if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_GCC_BUILTIN_TYPES_COMPATIBLE_P; }
else
return make_identifier();
}
"__builtin_convertvector" {
if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG)
{ loc(); return TOK_CLANG_BUILTIN_CONVERTVECTOR; }
else
return make_identifier();
}
"__alignof__" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_ALIGNOF; }
else
return make_identifier();
}
"__alignof" { // MS supports __alignof:
// http://msdn.microsoft.com/en-us/library/45t0s5f4%28v=vs.71%29.aspx
if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO ||
PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_ALIGNOF; }
else
return make_identifier();
}
"__ALIGNOF__" { if(PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_ALIGNOF; }
else
return make_identifier();
}
"__builtin_alignof" {
// interestingly, gcc doesn't support this,
// but Visual Studio does!
if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_ALIGNOF; }
else
return make_identifier();
}
"__asm" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{
loc();
BEGIN(MSC_ASM);
return TOK_MSC_ASM;
}
else if(PARSER.cpp98)
{
loc();
return TOK_GCC_ASM;
}
else
BEGIN(GCC_ASM);
}
"asm" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR)
{
if(PARSER.cpp98)
{
loc();
return TOK_GCC_ASM;
}
else
BEGIN(GCC_ASM);
}
else
return make_identifier();
}
"__asm__" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{
if(PARSER.cpp98)
{
loc();
return TOK_GCC_ASM;
}
else
BEGIN(GCC_ASM);
}
else
return make_identifier();
}
"__based" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{ loc(); return TOK_MSC_BASED; }
else
return make_identifier();
}
"__unaligned" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{ /* ignore for now */ }
else
return make_identifier();
}
"__wchar_t" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO)
{ loc(); return TOK_WCHAR_T; }
else
return make_identifier();
}
%{
/* C++ Keywords and Operators */
%}
alignas { return cpp11_keyword(TOK_ALIGNAS); } // C++11
alignof { return cpp11_keyword(TOK_ALIGNOF); } // C++11
and { return cpp98_keyword(TOK_ANDAND); }
and_eq { return cpp98_keyword(TOK_ANDASSIGN); }
bool { return cpp98_keyword(TOK_BOOL); }
catch { return cpp98_keyword(TOK_CATCH); }
char16_t { // C++11, but Visual Studio uses typedefs
if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
return make_identifier();
else
return cpp11_keyword(TOK_CHAR16_T);
}
char32_t { // C++11, but Visual Studio uses typedefs
if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
return make_identifier();
else
return cpp11_keyword(TOK_CHAR32_T);
}
class { return cpp98_keyword(TOK_CLASS); }
compl { return cpp98_keyword('~'); }
constexpr { return cpp11_keyword(TOK_CONSTEXPR); } // C++11
delete { return cpp98_keyword(TOK_DELETE); }
decltype { return cpp11_keyword(TOK_DECLTYPE); } // C++11
explicit { return cpp98_keyword(TOK_EXPLICIT); }
false { return cpp98_keyword(TOK_FALSE); }
friend { return cpp98_keyword(TOK_FRIEND); }
mutable { return cpp98_keyword(TOK_MUTABLE); }
namespace { return cpp98_keyword(TOK_NAMESPACE); }
new { return cpp98_keyword(TOK_NEW); }
nodiscard { return cpp11_keyword(TOK_NODISCARD); } // C++11
noexcept { return cpp11_keyword(TOK_NOEXCEPT); } // C++11
noreturn { return cpp11_keyword(TOK_NORETURN); } // C++11
not { return cpp98_keyword('!'); }
not_eq { return cpp98_keyword(TOK_NE); }
nullptr { return cpp11_keyword(TOK_NULLPTR); } // C++11
operator { return cpp98_keyword(TOK_OPERATOR); }
or { return cpp98_keyword(TOK_OROR); }
or_eq { return cpp98_keyword(TOK_ORASSIGN); }
private { return cpp98_keyword(TOK_PRIVATE); }
protected { return cpp98_keyword(TOK_PROTECTED); }
public { return cpp98_keyword(TOK_PUBLIC); }
static_assert { // C++11, but Visual Studio supports it in all modes
// as a keyword, even though the documentation claims
// it's a macro.
if(PARSER.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO)
{
loc(); return TOK_STATIC_ASSERT;
}
else
return cpp11_keyword(TOK_STATIC_ASSERT);
}
template { return cpp98_keyword(TOK_TEMPLATE); }
this { return cpp98_keyword(TOK_THIS); }
thread_local { return cpp11_keyword(TOK_THREAD_LOCAL); } // C++11
throw { return cpp98_keyword(TOK_THROW); }
true { return cpp98_keyword(TOK_TRUE); }
typeid { return cpp98_keyword(TOK_TYPEID); }
typename { return cpp98_keyword(TOK_TYPENAME); }
using { return cpp98_keyword(TOK_USING); }
virtual { return cpp98_keyword(TOK_VIRTUAL); }
wchar_t { // CodeWarrior doesn't have wchar_t built in,
// and MSC has a command-line option to turn it off
if(PARSER.mode==configt::ansi_ct::flavourt::CODEWARRIOR)
return make_identifier();
else
return cpp98_keyword(TOK_WCHAR_T);
}
xor { return cpp98_keyword('^'); }
xor_eq { return cpp98_keyword(TOK_XORASSIGN); }
".*" { return cpp_operator(TOK_DOTPM); }
"->*" { return cpp_operator(TOK_ARROWPM); }
"::" { if(PARSER.cpp98)
return cpp_operator(TOK_SCOPE);
else
{
yyless(1); // puts all but one : back into stream
loc();
PARSER.tag_following=false;
return ':';
}
}
__decltype { if(PARSER.cpp98 &&
(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
PARSER.mode==configt::ansi_ct::flavourt::CLANG))
return cpp98_keyword(TOK_DECLTYPE);
else
return make_identifier();
}
%{
/* a huge batch of MS C++ extensions
http://msdn.microsoft.com/en-us/library/ms177194(v=vs.80).aspx
Clang and GCC support several of them as well:
http://clang.llvm.org/docs/LanguageExtensions.html#checks-for-type-trait-primitives */
%}
"__has_assign" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_copy" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_finalizer" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_nothrow_assign" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_nothrow_constructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_nothrow_copy" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_trivial_assign" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_trivial_constructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_trivial_copy" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_trivial_destructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_user_destructor" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__has_virtual_destructor" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_abstract" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_base_of" { loc(); return cpp98_keyword(TOK_BINARY_TYPE_PREDICATE); }
"__is_class" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_convertible_to" { loc(); return cpp98_keyword(TOK_BINARY_TYPE_PREDICATE); }
"__is_delegate" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_empty" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_enum" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_interface_class" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_pod" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_polymorphic" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_ref_array" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_ref_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_sealed" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_simple_value_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_union" { loc(); return cpp98_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__is_value_class" { loc(); return MSC_cpp_keyword(TOK_UNARY_TYPE_PREDICATE); }
"__if_exists" { loc(); return MSC_cpp_keyword(TOK_MSC_IF_EXISTS); }
"__if_not_exists" { loc(); return MSC_cpp_keyword(TOK_MSC_IF_NOT_EXISTS); }
"__underlying_type" { loc(); return cpp98_keyword(TOK_UNDERLYING_TYPE); }
"["{ws}"repeatable" |
"["{ws}"source_annotation_attribute" |
"["{ws}"returnvalue" |
"["{ws}"SA_Pre" |
"["{ws}"SA_Post" |
"["{ws}"SA_FormatString" |
"["{ws}"SA_Success" |
"["{ws}"uuid" |
"["{ws}"emitidl" |
"["{ws}"module" |