forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppBison.yxx
More file actions
4294 lines (4051 loc) · 111 KB
/
cppBison.yxx
File metadata and controls
4294 lines (4051 loc) · 111 KB
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
/**
* @file cppBison.yxx
* @author drose
* @date 1999-01-16
*/
%{
#include "cppBisonDefs.h"
#include "cppParser.h"
#include "cppClosureType.h"
#include "cppExpression.h"
#include "cppSimpleType.h"
#include "cppExtensionType.h"
#include "cppStructType.h"
#include "cppEnumType.h"
#include "cppFunctionType.h"
#include "cppTBDType.h"
#include "cppMakeProperty.h"
#include "cppMakeSeq.h"
#include "cppParameterList.h"
#include "cppInstance.h"
#include "cppClassTemplateParameter.h"
#include "cppTemplateParameterList.h"
#include "cppInstanceIdentifier.h"
#include "cppTypedefType.h"
#include "cppTypeDeclaration.h"
#include "cppVisibility.h"
#include "cppIdentifier.h"
#include "cppScope.h"
#include "cppTemplateScope.h"
#include "cppNamespace.h"
#include "cppUsing.h"
using std::stringstream;
using std::string;
////////////////////////////////////////////////////////////////////
// Defining the interface to the parser.
////////////////////////////////////////////////////////////////////
CPPScope *current_scope = nullptr;
CPPScope *global_scope = nullptr;
CPPPreprocessor *current_lexer = nullptr;
static CPPStructType *current_struct = nullptr;
static CPPEnumType *current_enum = nullptr;
static int current_storage_class = 0;
static CPPType *current_type = nullptr;
static CPPExpression *current_expr = nullptr;
static int publish_nest_level = 0;
static CPPVisibility publish_previous;
static YYLTYPE publish_loc;
static std::vector<CPPScope *> last_scopes;
static std::vector<int> last_storage_classes;
static std::vector<CPPStructType *> last_structs;
int yyparse();
#define YYERROR_VERBOSE
static void
yyerror(const string &msg) {
current_lexer->error(msg, current_lexer->_last_token_loc);
}
static void
yyerror(YYLTYPE *loc, const string &msg) {
current_lexer->error(msg, *loc);
}
static void
yyerror(const string &msg, YYLTYPE &loc) {
current_lexer->error(msg, loc);
}
static void
yywarning(const string &msg, YYLTYPE &loc) {
current_lexer->warning(msg, loc);
}
static int
yylex(YYSTYPE *lval, YYLTYPE *lloc) {
CPPToken token = current_lexer->get_next_token();
*lval = token._lval;
*lloc = token._lloc;
return token._token;
}
void
parse_cpp(CPPParser *cp) {
CPPScope *old_scope = current_scope;
CPPScope *old_global_scope = global_scope;
CPPPreprocessor *old_lexer = current_lexer;
current_scope = cp;
global_scope = cp;
current_lexer = cp;
publish_nest_level = 0;
yyparse();
if (publish_nest_level != 0) {
yyerror("Unclosed __begin_publish", publish_loc);
publish_nest_level = 0;
}
current_scope = old_scope;
global_scope = old_global_scope;
current_lexer = old_lexer;
}
CPPExpression *
parse_const_expr(CPPPreprocessor *pp, CPPScope *new_current_scope,
CPPScope *new_global_scope) {
CPPScope *old_scope = current_scope;
CPPScope *old_global_scope = global_scope;
CPPPreprocessor *old_lexer = current_lexer;
CPPExpression *old_expr = current_expr;
current_scope = new_current_scope;
global_scope = new_global_scope;
current_expr = nullptr;
current_lexer = pp;
yyparse();
CPPExpression *result = current_expr;
current_scope = old_scope;
global_scope = old_global_scope;
current_lexer = old_lexer;
current_expr = old_expr;
return result;
}
CPPType *
parse_type(CPPPreprocessor *pp, CPPScope *new_current_scope,
CPPScope *new_global_scope) {
CPPScope *old_scope = current_scope;
CPPScope *old_global_scope = global_scope;
CPPPreprocessor *old_lexer = current_lexer;
CPPType *old_type = current_type;
current_scope = new_current_scope;
global_scope = new_global_scope;
current_type = nullptr;
current_lexer = pp;
yyparse();
CPPType *result = current_type;
current_scope = old_scope;
global_scope = old_global_scope;
current_lexer = old_lexer;
current_type = old_type;
return result;
}
static void
push_scope(CPPScope *new_scope) {
last_scopes.push_back(current_scope);
if (new_scope != nullptr) {
current_scope = new_scope;
}
}
static void
pop_scope() {
assert(!last_scopes.empty());
current_scope = last_scopes.back();
last_scopes.pop_back();
}
static void
push_storage_class(int new_storage_class) {
last_storage_classes.push_back(current_storage_class);
current_storage_class = new_storage_class;
}
static void
pop_storage_class() {
assert(!last_storage_classes.empty());
current_storage_class = last_storage_classes.back();
last_storage_classes.pop_back();
}
static void
push_struct(CPPStructType *new_struct) {
last_structs.push_back(current_struct);
current_struct = new_struct;
}
static void
pop_struct() {
assert(!last_structs.empty());
current_struct = last_structs.back();
last_structs.pop_back();
}
%}
/* This is a bison-specific declaration to enable recursive calls to
yyparse(). It changes the calling sequence to yylex(), passing
pointers to the current yylval and yylloc. Bison 2.7 introduces a
different syntax that will also pass the current yylloc to yyerror,
but we have to support Bison versions as old as 2.5 for now. */
/*%define api.pure full*/
%pure-parser
%locations
%token <u.real> REAL
%token <u.integer> INTEGER
%token <u.integer> CHAR_TOK
%token <str> SIMPLE_STRING SIMPLE_IDENTIFIER
%token <u.expr> STRING_LITERAL CUSTOM_LITERAL
%token <u.identifier> IDENTIFIER TYPENAME_IDENTIFIER TYPEPACK_IDENTIFIER SCOPING
%token <u.type> TYPEDEFNAME
%token ELLIPSIS
%token OROR
%token ANDAND
%token EQCOMPARE
%token NECOMPARE
%token LECOMPARE
%token GECOMPARE
%token LSHIFT
%token RSHIFT
%token POINTSAT_STAR
%token DOT_STAR
%token UNARY
%token UNARY_NOT
%token UNARY_NEGATE
%token UNARY_MINUS
%token UNARY_PLUS
%token UNARY_STAR
%token UNARY_REF
%token POINTSAT
%token SCOPE
%token PLUSPLUS
%token MINUSMINUS
%token TIMESEQUAL
%token DIVIDEEQUAL
%token MODEQUAL
%token PLUSEQUAL
%token MINUSEQUAL
%token OREQUAL
%token ANDEQUAL
%token XOREQUAL
%token LSHIFTEQUAL
%token RSHIFTEQUAL
%token ATTR_LEFT
%token ATTR_RIGHT
%token KW_ALIGNAS
%token KW_ALIGNOF
%token KW_AUTO
%token KW_BEGIN_PUBLISH
%token KW_BLOCKING
%token KW_BOOL
%token KW_CATCH
%token KW_CHAR
%token KW_CHAR16_T
%token KW_CHAR32_T
%token KW_CLASS
%token KW_CONST
%token KW_CONSTEXPR
%token KW_CONST_CAST
%token KW_DECLTYPE
%token KW_DEFAULT
%token KW_DELETE
%token KW_DOUBLE
%token KW_DYNAMIC_CAST
%token KW_ELSE
%token KW_END_PUBLISH
%token KW_ENUM
%token KW_EXTENSION
%token KW_EXTERN
%token KW_EXPLICIT
%token KW_PUBLISHED
%token KW_FALSE
%token KW_FINAL
%token KW_FLOAT
%token KW_FRIEND
%token KW_FOR
%token KW_GOTO
%token KW_HAS_VIRTUAL_DESTRUCTOR
%token KW_IF
%token KW_INLINE
%token KW_INT
%token KW_IS_ABSTRACT
%token KW_IS_BASE_OF
%token KW_IS_CLASS
%token KW_IS_CONSTRUCTIBLE
%token KW_IS_CONVERTIBLE_TO
%token KW_IS_DESTRUCTIBLE
%token KW_IS_EMPTY
%token KW_IS_ENUM
%token KW_IS_FINAL
%token KW_IS_FUNDAMENTAL
%token KW_IS_POD
%token KW_IS_POLYMORPHIC
%token KW_IS_STANDARD_LAYOUT
%token KW_IS_TRIVIAL
%token KW_IS_UNION
%token KW_LONG
%token KW_MAKE_MAP_KEYS_SEQ
%token KW_MAKE_MAP_PROPERTY
%token KW_MAKE_PROPERTY
%token KW_MAKE_PROPERTY2
%token KW_MAKE_SEQ
%token KW_MAKE_SEQ_PROPERTY
%token KW_MUTABLE
%token KW_NAMESPACE
%token KW_NEW
%token KW_NOEXCEPT
%token KW_NULLPTR
%token KW_OPERATOR
%token KW_OVERRIDE
%token KW_PRIVATE
%token KW_PROTECTED
%token KW_PUBLIC
%token KW_REGISTER
%token KW_REINTERPRET_CAST
%token KW_RETURN
%token KW_SHORT
%token KW_SIGNED
%token KW_SIZEOF
%token KW_STATIC
%token KW_STATIC_ASSERT
%token KW_STATIC_CAST
%token KW_STRUCT
%token KW_TEMPLATE
%token KW_THREAD_LOCAL
%token KW_THROW
%token KW_TRUE
%token KW_TRY
%token KW_TYPEDEF
%token KW_TYPEID
%token KW_TYPENAME
%token KW_UNDERLYING_TYPE
%token KW_UNION
%token KW_UNSIGNED
%token KW_USING
%token KW_VIRTUAL
%token KW_VOID
%token KW_VOLATILE
%token KW_WCHAR_T
%token KW_WHILE
/* These special tokens are used to set the starting state of the
parser. The lexer places the appropriate one of these on the head
of the input stream. */
%token START_CPP
%token START_CONST_EXPR
%token START_TYPE
%type <u.integer> storage_class
%type <u.instance> constructor_prototype
%type <u.instance> function_prototype
%type <u.integer> function_post
%type <str> function_operator
%type <u.decl> template_formal_parameter
%type <u.type> template_formal_parameter_type
%type <u.inst_ident> instance_identifier
%type <u.inst_ident> instance_identifier_and_maybe_trailing_return_type
%type <u.param_list> function_parameter_list
%type <u.param_list> function_parameters
%type <u.param_list> formal_parameter_list
%type <u.param_list> formal_parameters
%type <u.closure_type> capture_list
%type <u.capture> capture
%type <u.expr> template_parameter_maybe_initialize
%type <u.expr> maybe_initialize
%type <u.expr> maybe_initialize_or_constructor_body
%type <u.expr> maybe_initialize_or_function_body
%type <u.instance> function_parameter
%type <u.instance> formal_parameter
%type <u.inst_ident> not_paren_formal_parameter_identifier
%type <u.inst_ident> formal_parameter_identifier
%type <u.inst_ident> parameter_pack_identifier
%type <u.inst_ident> not_paren_empty_instance_identifier
%type <u.inst_ident> empty_instance_identifier
%type <u.type> type type_pack
%type <u.decl> type_decl
%type <u.decl> var_type_decl
%type <u.type> predefined_type
%type <u.type> full_type
%type <u.struct_type> anonymous_struct
%type <u.struct_type> named_struct
%type <u.enum_type> enum
%type <u.extension_enum> enum_keyword
%type <u.extension_enum> struct_keyword
%type <u.simple_type> simple_type
%type <u.simple_type> simple_int_type
%type <u.simple_type> simple_float_type
%type <u.simple_type> simple_void_type
%type <u.type> class_derivation_name
%type <u.type> enum_element_type
%type <u.type> maybe_trailing_return_type
%type <u.identifier> maybe_comma_identifier
/*%type <u.type> typedefname*/
%type <u.identifier> name
%type <u.identifier> name_no_final
%type <u.expr> string_literal
/* We need to treat KW_OPERATOR as a scopable keyword. */
%type <u.identifier> KW_OPERATOR
%type <u.expr> optional_const_expr
%type <u.expr> optional_const_expr_comma
%type <u.expr> const_expr_comma
%type <u.expr> no_angle_bracket_const_expr
%type <u.expr> const_expr
%type <u.expr> const_operand
%type <u.expr> formal_const_expr
%type <u.expr> formal_const_operand
/* Precedence rules. */
%left IDENTIFIER TYPENAME_IDENTIFIER TYPEDEFNAME KW_ENUM ELLIPSIS KW_OPERATOR KW_TYPENAME KW_INT KW_SHORT KW_UNSIGNED KW_SIGNED KW_LONG KW_FLOAT KW_DOUBLE KW_CHAR KW_WCHAR_T KW_CHAR16_T KW_CHAR32_T KW_BOOL
%left '{' ',' ';'
%nonassoc KW_THROW
%right ':'
%right '='
%right '?'
%left OROR
%left ANDAND
%left '|'
%left '^'
%left '&'
%left EQCOMPARE NECOMPARE
%left LECOMPARE GECOMPARE '<' '>'
%left LSHIFT RSHIFT
%left '+' '-'
%left '*' '/' '%'
%left POINTSAT_STAR DOT_STAR
%right UNARY PLUSPLUS MINUSMINUS '~'
%left POINTSAT '.' '(' '['
%right SCOPE
%nonassoc KW_NEW KW_DELETE KW_TRY KW_CATCH
%%
grammar:
START_CPP cpp
| START_CONST_EXPR const_expr
{
current_expr = $2;
}
| START_TYPE full_type
{
current_type = $2;
}
;
cpp:
empty
| cpp ';'
| cpp declaration
;
constructor_inits:
constructor_init
| constructor_inits ',' constructor_init
;
constructor_init:
name '(' optional_const_expr_comma ')'
{
delete $3;
}
| name '(' optional_const_expr_comma ')' ELLIPSIS
{
delete $3;
}
| name '{' optional_const_expr_comma '}'
{
delete $3;
}
;
/* This is principally for the syntax: extern "C" { ... }.
We use storage_class instead of simply KW_EXTERN to avoid
shift/reduce conflicts with yacc's limited differentiation
ability. */
extern_c:
storage_class '{'
{
push_storage_class((current_storage_class & ~CPPInstance::SC_c_binding) |
($1 & CPPInstance::SC_c_binding));
}
cpp '}'
{
pop_storage_class();
}
;
declaration:
type_like_declaration
| template_declaration
| extern_c
| namespace_declaration
| friend_declaration
| KW_TYPEDEF typedef_declaration
| KW_BEGIN_PUBLISH
{
if (publish_nest_level != 0) {
yyerror("Unclosed __begin_publish", publish_loc);
publish_nest_level = 0;
current_scope->set_current_vis(V_public);
}
publish_previous = current_scope->get_current_vis();
publish_loc = @1;
publish_nest_level++;
current_scope->set_current_vis(V_published);
}
| KW_END_PUBLISH
{
if (publish_nest_level != 1) {
yyerror("Unmatched __end_publish", @1);
} else {
current_scope->set_current_vis(publish_previous);
}
publish_nest_level = 0;
}
| KW_PUBLISHED ':'
{
current_scope->set_current_vis(V_published);
}
| KW_PUBLIC ':'
{
if (publish_nest_level > 0) {
current_scope->set_current_vis(V_published);
} else {
current_scope->set_current_vis(V_public);
}
}
| KW_PROTECTED ':'
{
current_scope->set_current_vis(V_protected);
}
| KW_PRIVATE ':'
{
current_scope->set_current_vis(V_private);
}
| KW_MAKE_PROPERTY '(' name ',' IDENTIFIER maybe_comma_identifier ')' ';'
{
CPPDeclaration *getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $5->get_fully_scoped_name(), @5);
} else {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
if ($6 != nullptr) {
CPPDeclaration *setter = $6->find_symbol(current_scope, global_scope, current_lexer);
if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid setter: " + $6->get_fully_scoped_name(), @6);
} else {
make_property->_set_function = setter->as_function_group();
}
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $5->get_fully_scoped_name(), @5);
} else {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
CPPDeclaration *setter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid setter: " + $7->get_fully_scoped_name(), @7);
} else {
make_property->_set_function = setter->as_function_group();
}
CPPDeclaration *deleter = $9->find_symbol(current_scope, global_scope, current_lexer);
if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid delete method: " + $9->get_fully_scoped_name(), @9);
} else {
make_property->_del_function = deleter->as_function_group();
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
length_getter = nullptr;
}
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
getter = nullptr;
}
if (getter != nullptr && length_getter != nullptr) {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
make_property->_length_function = length_getter->as_function_group();
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
length_getter = nullptr;
}
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
getter = nullptr;
}
if (getter != nullptr && length_getter != nullptr) {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
make_property->_length_function = length_getter->as_function_group();
CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
} else {
make_property->_set_function = setter->as_function_group();
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
length_getter = nullptr;
}
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
getter = nullptr;
}
if (getter != nullptr && length_getter != nullptr) {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
make_property->_length_function = length_getter->as_function_group();
CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
} else {
make_property->_set_function = setter->as_function_group();
}
CPPDeclaration *deleter = $11->find_symbol(current_scope, global_scope, current_lexer);
if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid delete method: " + $11->get_fully_scoped_name(), @11);
} else {
make_property->_del_function = deleter->as_function_group();
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
length_getter = nullptr;
}
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
getter = nullptr;
}
if (getter != nullptr && length_getter != nullptr) {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
make_property->_length_function = length_getter->as_function_group();
CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
} else {
make_property->_set_function = setter->as_function_group();
}
CPPDeclaration *deleter = $11->find_symbol(current_scope, global_scope, current_lexer);
if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid delete method: " + $11->get_fully_scoped_name(), @11);
} else {
make_property->_del_function = deleter->as_function_group();
}
CPPDeclaration *inserter = $13->find_symbol(current_scope, global_scope, current_lexer);
if (inserter == nullptr || inserter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid append method: " + $13->get_fully_scoped_name(), @13);
} else {
make_property->_insert_function = inserter->as_function_group();
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_MAP_PROPERTY '(' name ',' IDENTIFIER ')' ';'
{
CPPDeclaration *getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid item getter method: " + $5->get_fully_scoped_name(), @5);
} else {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_mapping, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_MAP_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
} else {
CPPMakeProperty *make_property;
make_property = new CPPMakeProperty($3, CPPMakeProperty::T_mapping, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
} else {
make_property->_has_function = hasser->as_function_group();
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_MAP_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER maybe_comma_identifier ')' ';'
{
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
} else {
CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_mapping, current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
} else {
make_property->_has_function = hasser->as_function_group();
}
CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
} else {
make_property->_set_function = setter->as_function_group();
}
if ($10 != nullptr) {
CPPDeclaration *deleter = $10->find_symbol(current_scope, global_scope, current_lexer);
if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid delete method: " + $10->get_fully_scoped_name(), @10);
} else {
make_property->_del_function = deleter->as_function_group();
}
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_MAP_KEYS_SEQ '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
length_getter = nullptr;
}
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
getter = nullptr;
}
if (getter != nullptr && length_getter != nullptr) {
CPPMakeProperty *make_property = nullptr;
for (size_t i = 0; i < current_scope->_declarations.size(); ++i) {
make_property = current_scope->_declarations[i]->as_make_property();
if (make_property != nullptr) {
if (make_property->get_fully_scoped_name() == $3->get_fully_scoped_name()) {
break;
} else {
make_property = nullptr;
}
}
}
if (make_property != nullptr) {
make_property->_get_key_function = getter->as_function_group();
make_property->_length_function = length_getter->as_function_group();
} else {
yyerror("reference to non-existent MAKE_MAP_PROPERTY: " + $3->get_fully_scoped_name(), @3);
}
}
}
| KW_MAKE_PROPERTY2 '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
} else {
CPPMakeProperty *make_property;
make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal,
current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
} else {
make_property->_has_function = hasser->as_function_group();
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_PROPERTY2 '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
} else {
CPPMakeProperty *make_property;
make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal,
current_scope, @1.file);
make_property->_get_function = getter->as_function_group();
CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
} else {
make_property->_has_function = hasser->as_function_group();
}
CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
} else {
make_property->_set_function = setter->as_function_group();
}
CPPDeclaration *clearer = $11->find_symbol(current_scope, global_scope, current_lexer);
if (clearer == nullptr || clearer->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid clear method: " + $11->get_fully_scoped_name(), @11);
} else {
make_property->_clear_function = clearer->as_function_group();
}
current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
}
}
| KW_MAKE_SEQ '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
{
CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
length_getter = nullptr;
}
CPPDeclaration *element_getter = $7->find_symbol(current_scope, global_scope, current_lexer);
if (element_getter == nullptr || element_getter->get_subtype() != CPPDeclaration::ST_function_group) {
yyerror("reference to non-existent or invalid element method: " + $7->get_fully_scoped_name(), @5);
element_getter = nullptr;
}
if (length_getter != nullptr && element_getter != nullptr) {
CPPMakeSeq *make_seq = new CPPMakeSeq($3,
length_getter->as_function_group(),
element_getter->as_function_group(),
current_scope, @1.file);
current_scope->add_declaration(make_seq, global_scope, current_lexer, @1);
}
}
| KW_STATIC_ASSERT '(' const_expr ',' string_literal ')' ';'
{
CPPExpression::Result result = $3->evaluate();
if (result._type == CPPExpression::RT_error) {
yywarning("static_assert requires a constant expression", @3);
} else if (!result.as_boolean()) {
stringstream str;
str << *$5;
yywarning("static_assert failed: " + str.str(), @3);
}
}
| KW_STATIC_ASSERT '(' const_expr ')' ';'
{
// This alternative version of static_assert was introduced in C++17.
CPPExpression::Result result = $3->evaluate();
if (result._type == CPPExpression::RT_error) {
yywarning("static_assert requires a constant expression", @3);
} else if (!result.as_boolean()) {
yywarning("static_assert failed", @3);
}
}
;
friend_declaration:
KW_FRIEND
{
CPPScope *new_scope = new CPPScope(current_scope, CPPNameComponent("temp"),
V_public);
push_scope(new_scope);
}
declaration
{
delete current_scope;
pop_scope();
}
;
storage_class:
empty
{
$$ = 0;
}
| KW_CONST storage_class
{
// This isn't really a storage class, but it helps with parsing.
$$ = $2 | (int)CPPInstance::SC_const;
}
| KW_EXTERN storage_class
{
$$ = $2 | (int)CPPInstance::SC_extern;
}
| KW_EXTERN SIMPLE_STRING storage_class
{
$$ = $3 | (int)CPPInstance::SC_extern;
if ($2 == "C") {
$$ |= (int)CPPInstance::SC_c_binding;
} else if ($2 == "C++") {
$$ &= ~(int)CPPInstance::SC_c_binding;
} else {
yywarning("Ignoring unknown linkage type \"" + $2 + "\"", @2);
}
}
| KW_STATIC storage_class
{
$$ = $2 | (int)CPPInstance::SC_static;
}
| KW_INLINE storage_class
{
$$ = $2 | (int)CPPInstance::SC_inline;
}
| KW_VIRTUAL storage_class
{
$$ = $2 | (int)CPPInstance::SC_virtual;
}
| KW_EXPLICIT storage_class
{
$$ = $2 | (int)CPPInstance::SC_explicit;
}
| KW_REGISTER storage_class
{
$$ = $2 | (int)CPPInstance::SC_register;
}
| KW_VOLATILE storage_class
{
$$ = $2 | (int)CPPInstance::SC_volatile;