/
sandeshy.yy
1435 lines (1336 loc) · 32.3 KB
/
sandeshy.yy
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
%{
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Thrift parser.
*
* This parser is used on a thrift definition file.
*/
#ifdef SANDESH
/**
* Sandesh parser.
*
* This parser is used on a sandesh definition file.
*
* sandesh domain specific langauge is derived from apache thrift and
* much of thrift code is reused.
*/
#endif
#define __STDC_LIMIT_MACROS
#define __STDC_FORMAT_MACROS
#include <stdio.h>
#include <inttypes.h>
#include <limits.h>
#include "main.h"
#include "globals.h"
#include "parse/t_program.h"
#include "parse/t_scope.h"
/**
* This global variable is used for automatic numbering of field indices etc.
* when parsing the members of a struct. Field values are automatically
* assigned starting from -1 and working their way down.
*/
int y_field_val = -1;
int g_arglist = 0;
const int struct_is_struct = 0;
const int struct_is_union = 1;
%}
/**
* This structure is used by the parser to hold the data types associated with
* various parse nodes.
*/
%union {
char* id;
int64_t iconst;
double dconst;
bool tbool;
t_doc* tdoc;
t_type* ttype;
t_base_type* tbase;
t_typedef* ttypedef;
t_enum* tenum;
t_enum_value* tenumv;
t_const* tconst;
t_const_value* tconstv;
t_struct* tstruct;
t_service* tservice;
t_function* tfunction;
t_field* tfield;
char* dtext;
t_field::e_req ereq;
t_annotation* tannot;
t_field_id tfieldid;
t_sandesh* tsandesh;
}
/**
* Strings identifier
*/
%token<id> tok_identifier
%token<id> tok_literal
%token<dtext> tok_doctext
%token<id> tok_st_identifier
%token<id> tok_format
/**
* Constant values
*/
%token<iconst> tok_int_constant
%token<dconst> tok_dub_constant
/**
* Header keywords
*/
%token tok_include
%token tok_namespace
%token tok_cpp_namespace
%token tok_cpp_include
%token tok_cpp_type
%token tok_php_namespace
%token tok_py_module
%token tok_perl_package
%token tok_java_package
%token tok_xsd_all
%token tok_xsd_optional
%token tok_xsd_nillable
%token tok_xsd_namespace
%token tok_xsd_attrs
%token tok_ruby_namespace
%token tok_smalltalk_category
%token tok_smalltalk_prefix
%token tok_cocoa_prefix
%token tok_csharp_namespace
%token tok_delphi_namespace
/**
* Base datatype keywords
*/
%token tok_void
%token tok_bool
%token tok_byte
%token tok_string
%token tok_binary
%token tok_slist
%token tok_senum
%token tok_i16
%token tok_i32
%token tok_i64
%token tok_double
%token tok_u16
%token tok_u32
%token tok_u64
%token tok_ipv4
%token tok_ipaddr
%token tok_xml
%token tok_uuid_t
/**
* Complex type keywords
*/
%token tok_map
%token tok_list
%token tok_set
/**
* Function modifiers
*/
%token tok_oneway
%token tok_staticfunction
%token tok_abcfunction
/**
* Sandesh modifiers
*/
%token tok_system
%token tok_request
%token tok_response
%token tok_trace
%token tok_object
%token tok_flow
%token tok_buffer
%token tok_uve
%token tok_dynamic_uve
%token tok_trace_object
%token tok_alarm
%token tok_session
/**
* Thrift language keywords
*/
%token tok_typedef
%token tok_struct
%token tok_xception
%token tok_throws
%token tok_extends
%token tok_service
%token tok_sandesh
%token tok_enum
%token tok_const
%token tok_required
%token tok_optional
%token tok_union
/**
* Grammar nodes
*/
%type<ttype> BaseType
%type<ttype> SimpleBaseType
%type<ttype> ContainerType
%type<ttype> SimpleContainerType
%type<ttype> MapType
%type<ttype> SetType
%type<ttype> ListType
%type<tdoc> Definition
%type<ttype> TypeDefinition
%type<ttypedef> Typedef
%type<ttype> TypeAnnotations
%type<ttype> TypeAnnotationList
%type<tannot> TypeAnnotation
%type<tfield> Field
%type<tfieldid> FieldIdentifier
%type<ereq> FieldRequiredness
%type<ttype> FieldType
%type<tconstv> FieldValue
%type<tstruct> FieldList
%type<tsandesh> SFieldList
%type<tenum> Enum
%type<tenum> EnumDefList
%type<tenumv> EnumDef
%type<ttypedef> Senum
%type<tbase> SenumDefList
%type<id> SenumDef
%type<tconst> Const
%type<tconstv> ConstValue
%type<tconstv> ConstList
%type<tconstv> ConstListContents
%type<tconstv> ConstMap
%type<tconstv> ConstMapContents
%type<iconst> StructHead
%type<tstruct> Struct
%type<tstruct> Xception
%type<tservice> Service
%type<tsandesh> Sandesh
%type<ttype> SandeshType
%type<tfunction> Function
%type<ttype> FunctionType
%type<tservice> FunctionList
%type<tstruct> Throws
%type<tservice> Extends
%type<tbool> Oneway
%type<tbool> StaticFunction
%type<tbool> AbcFunction
%type<tbool> XsdAll
%type<tbool> XsdOptional
%type<tbool> XsdNillable
%type<tstruct> XsdAttributes
%type<id> CppType
%type<dtext> CaptureDocText
%%
/**
* Thrift Grammar Implementation.
*
* For the most part this source file works its way top down from what you
* might expect to find in a typical .thrift file, i.e. type definitions and
* namespaces up top followed by service definitions using those types.
*/
Program:
HeaderList DefinitionList
{
pdebug("Program -> Headers DefinitionList");
if((g_program_doctext_candidate != NULL) && (g_program_doctext_status != ALREADY_PROCESSED))
{
g_program->set_doc(g_program_doctext_candidate);
g_program_doctext_status = ALREADY_PROCESSED;
}
clear_doctext();
}
CaptureDocText:
{
if (g_parse_mode == PROGRAM) {
$$ = g_doctext;
g_doctext = NULL;
} else {
$$ = NULL;
}
}
/* TODO(dreiss): Try to DestroyDocText in all sorts or random places. */
DestroyDocText:
{
if (g_parse_mode == PROGRAM) {
clear_doctext();
}
}
/* We have to DestroyDocText here, otherwise it catches the doctext
on the first real element. */
HeaderList:
HeaderList DestroyDocText Header
{
pdebug("HeaderList -> HeaderList Header");
}
|
{
pdebug("HeaderList -> ");
}
Header:
Include
{
pdebug("Header -> Include");
}
| tok_namespace tok_identifier tok_identifier
{
pdebug("Header -> tok_namespace tok_identifier tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace($2, $3);
}
}
| tok_namespace '*' tok_identifier
{
pdebug("Header -> tok_namespace * tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("*", $3);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_cpp_namespace tok_identifier
{
pwarning(1, "'cpp_namespace' is deprecated. Use 'namespace cpp' instead");
pdebug("Header -> tok_cpp_namespace tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("cpp", $2);
}
}
| tok_cpp_include tok_literal
{
pdebug("Header -> tok_cpp_include tok_literal");
if (g_parse_mode == PROGRAM) {
g_program->add_cpp_include($2);
}
}
| tok_php_namespace tok_identifier
{
pwarning(1, "'php_namespace' is deprecated. Use 'namespace php' instead");
pdebug("Header -> tok_php_namespace tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("php", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_py_module tok_identifier
{
pwarning(1, "'py_module' is deprecated. Use 'namespace py' instead");
pdebug("Header -> tok_py_module tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("py", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_perl_package tok_identifier
{
pwarning(1, "'perl_package' is deprecated. Use 'namespace perl' instead");
pdebug("Header -> tok_perl_namespace tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("perl", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_ruby_namespace tok_identifier
{
pwarning(1, "'ruby_namespace' is deprecated. Use 'namespace rb' instead");
pdebug("Header -> tok_ruby_namespace tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("rb", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_smalltalk_category tok_st_identifier
{
pwarning(1, "'smalltalk_category' is deprecated. Use 'namespace smalltalk.category' instead");
pdebug("Header -> tok_smalltalk_category tok_st_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("smalltalk.category", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_smalltalk_prefix tok_identifier
{
pwarning(1, "'smalltalk_prefix' is deprecated. Use 'namespace smalltalk.prefix' instead");
pdebug("Header -> tok_smalltalk_prefix tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("smalltalk.prefix", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_java_package tok_identifier
{
pwarning(1, "'java_package' is deprecated. Use 'namespace java' instead");
pdebug("Header -> tok_java_package tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("java", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_cocoa_prefix tok_identifier
{
pwarning(1, "'cocoa_prefix' is deprecated. Use 'namespace cocoa' instead");
pdebug("Header -> tok_cocoa_prefix tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("cocoa", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_xsd_namespace tok_literal
{
pwarning(1, "'xsd_namespace' is deprecated. Use 'namespace xsd' instead");
pdebug("Header -> tok_xsd_namespace tok_literal");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("cocoa", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_csharp_namespace tok_identifier
{
pwarning(1, "'csharp_namespace' is deprecated. Use 'namespace csharp' instead");
pdebug("Header -> tok_csharp_namespace tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("csharp", $2);
}
}
/* TODO(dreiss): Get rid of this once everyone is using the new hotness. */
| tok_delphi_namespace tok_identifier
{
pwarning(1, "'delphi_namespace' is deprecated. Use 'namespace delphi' instead");
pdebug("Header -> tok_delphi_namespace tok_identifier");
if (g_parse_mode == PROGRAM) {
g_program->set_namespace("delphi", $2);
}
}
Include:
tok_include tok_literal
{
pdebug("Include -> tok_include tok_literal");
if (g_parse_mode == INCLUDES) {
std::string path = include_file(std::string($2));
if (!path.empty()) {
g_program->add_include(path, std::string($2));
}
}
}
DefinitionList:
DefinitionList CaptureDocText Definition
{
pdebug("DefinitionList -> DefinitionList Definition");
if ($2 != NULL && $3 != NULL) {
$3->set_doc($2);
}
}
|
{
pdebug("DefinitionList -> ");
}
Definition:
Const
{
pdebug("Definition -> Const");
if (g_parse_mode == PROGRAM) {
g_program->add_const($1);
}
$$ = $1;
}
| TypeDefinition
{
pdebug("Definition -> TypeDefinition");
if (g_parse_mode == PROGRAM) {
g_scope->add_type($1->get_name(), $1);
if (g_parent_scope != NULL) {
g_parent_scope->add_type(g_parent_prefix + $1->get_name(), $1);
}
}
$$ = $1;
}
| Service
{
pdebug("Definition -> Service");
if (g_parse_mode == PROGRAM) {
g_scope->add_service($1->get_name(), $1);
if (g_parent_scope != NULL) {
g_parent_scope->add_service(g_parent_prefix + $1->get_name(), $1);
}
g_program->add_service($1);
}
$$ = $1;
}
| Sandesh
{
pdebug("Definition -> Sandesh");
if (g_parse_mode == PROGRAM) {
if (g_scope->get_sandesh($1->get_name())) {
yyerror("Duplicate definition of sandesh: %s ", $1->get_name().c_str());
exit(1);
}
g_scope->add_sandesh($1->get_name(), $1);
if (g_parent_scope != NULL) {
g_parent_scope->add_sandesh(g_parent_prefix + $1->get_name(), $1);
}
g_program->add_sandesh($1);
}
$$ = $1;
}
TypeDefinition:
Typedef
{
pdebug("TypeDefinition -> Typedef");
if (g_parse_mode == PROGRAM) {
g_program->add_typedef($1);
}
}
| Enum
{
pdebug("TypeDefinition -> Enum");
if (g_parse_mode == PROGRAM) {
g_program->add_enum($1);
}
}
| Senum
{
pdebug("TypeDefinition -> Senum");
if (g_parse_mode == PROGRAM) {
g_program->add_typedef($1);
}
}
| Struct
{
pdebug("TypeDefinition -> Struct");
if (g_parse_mode == PROGRAM) {
g_program->add_struct($1);
}
}
| Xception
{
pdebug("TypeDefinition -> Xception");
if (g_parse_mode == PROGRAM) {
g_program->add_xception($1);
}
}
Typedef:
tok_typedef FieldType tok_identifier
{
pdebug("TypeDef -> tok_typedef FieldType tok_identifier");
t_typedef *td = new t_typedef(g_program, $2, $3);
$$ = td;
}
CommaOrSemicolonOptional:
','
{}
| ';'
{}
|
{}
Enum:
tok_enum tok_identifier '{' EnumDefList '}'
{
pdebug("Enum -> tok_enum tok_identifier { EnumDefList }");
$$ = $4;
$$->set_name($2);
$$->resolve_values();
// make constants for all the enum values
if (g_parse_mode == PROGRAM) {
const std::vector<t_enum_value*>& enum_values = $$->get_constants();
std::vector<t_enum_value*>::const_iterator c_iter;
for (c_iter = enum_values.begin(); c_iter != enum_values.end(); ++c_iter) {
std::string const_name = $$->get_name() + "." + (*c_iter)->get_name();
t_const_value* const_val = new t_const_value((*c_iter)->get_value());
const_val->set_enum($$);
g_scope->add_constant(const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val));
if (g_parent_scope != NULL) {
g_parent_scope->add_constant(g_parent_prefix + const_name, new t_const(g_type_i32, (*c_iter)->get_name(), const_val));
}
}
}
}
EnumDefList:
EnumDefList EnumDef
{
pdebug("EnumDefList -> EnumDefList EnumDef");
$$ = $1;
$$->append($2);
}
|
{
pdebug("EnumDefList -> ");
$$ = new t_enum(g_program);
}
EnumDef:
CaptureDocText tok_identifier '=' tok_int_constant CommaOrSemicolonOptional
{
pdebug("EnumDef -> tok_identifier = tok_int_constant");
if ($4 < 0) {
pwarning(1, "Negative value supplied for enum %s.\n", $2);
}
if ($4 > INT_MAX) {
pwarning(1, "64-bit value supplied for enum %s.\n", $2);
}
$$ = new t_enum_value($2, $4);
if ($1 != NULL) {
$$->set_doc($1);
}
}
|
CaptureDocText tok_identifier CommaOrSemicolonOptional
{
pdebug("EnumDef -> tok_identifier");
$$ = new t_enum_value($2);
if ($1 != NULL) {
$$->set_doc($1);
}
}
Senum:
tok_senum tok_identifier '{' SenumDefList '}'
{
pdebug("Senum -> tok_senum tok_identifier { SenumDefList }");
$$ = new t_typedef(g_program, $4, $2);
}
SenumDefList:
SenumDefList SenumDef
{
pdebug("SenumDefList -> SenumDefList SenumDef");
$$ = $1;
$$->add_string_enum_val($2);
}
|
{
pdebug("SenumDefList -> ");
$$ = new t_base_type("string", t_base_type::TYPE_STRING);
$$->set_string_enum(true);
}
SenumDef:
tok_literal CommaOrSemicolonOptional
{
pdebug("SenumDef -> tok_literal");
$$ = $1;
}
Const:
tok_const FieldType tok_identifier '=' ConstValue CommaOrSemicolonOptional
{
pdebug("Const -> tok_const FieldType tok_identifier = ConstValue");
if (g_parse_mode == PROGRAM) {
g_scope->resolve_const_value($5, $2);
$$ = new t_const($2, $3, $5);
validate_const_type($$);
g_scope->add_constant($3, $$);
if (g_parent_scope != NULL) {
g_parent_scope->add_constant(g_parent_prefix + $3, $$);
}
} else {
$$ = NULL;
}
}
ConstValue:
tok_int_constant
{
pdebug("ConstValue => tok_int_constant");
$$ = new t_const_value();
$$->set_integer($1);
if (!g_allow_64bit_consts && ($1 < INT32_MIN || $1 > INT32_MAX)) {
pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
}
}
| tok_dub_constant
{
pdebug("ConstValue => tok_dub_constant");
$$ = new t_const_value();
$$->set_double($1);
}
| tok_literal
{
pdebug("ConstValue => tok_literal");
$$ = new t_const_value($1);
}
| tok_identifier
{
pdebug("ConstValue => tok_identifier");
$$ = new t_const_value();
$$->set_identifier($1);
}
| ConstList
{
pdebug("ConstValue => ConstList");
$$ = $1;
}
| ConstMap
{
pdebug("ConstValue => ConstMap");
$$ = $1;
}
ConstList:
'[' ConstListContents ']'
{
pdebug("ConstList => [ ConstListContents ]");
$$ = $2;
}
ConstListContents:
ConstListContents ConstValue CommaOrSemicolonOptional
{
pdebug("ConstListContents => ConstListContents ConstValue CommaOrSemicolonOptional");
$$ = $1;
$$->add_list($2);
}
|
{
pdebug("ConstListContents =>");
$$ = new t_const_value();
$$->set_list();
}
ConstMap:
'{' ConstMapContents '}'
{
pdebug("ConstMap => { ConstMapContents }");
$$ = $2;
}
ConstMapContents:
ConstMapContents ConstValue ':' ConstValue CommaOrSemicolonOptional
{
pdebug("ConstMapContents => ConstMapContents ConstValue CommaOrSemicolonOptional");
$$ = $1;
$$->add_map($2, $4);
}
|
{
pdebug("ConstMapContents =>");
$$ = new t_const_value();
$$->set_map();
}
StructHead:
tok_struct
{
$$ = struct_is_struct;
}
| tok_union
{
$$ = struct_is_union;
}
Struct:
StructHead tok_identifier XsdAll '{' FieldList '}' TypeAnnotations
{
pdebug("Struct -> tok_struct tok_identifier { FieldList }");
$5->set_xsd_all($3);
$5->set_union($1 == struct_is_union);
$$ = $5;
$$->set_name($2);
if ($7 != NULL) {
$$->annotations_ = $7->annotations_;
delete $7;
}
}
XsdAll:
tok_xsd_all
{
$$ = true;
}
|
{
$$ = false;
}
XsdOptional:
tok_xsd_optional
{
$$ = true;
}
|
{
$$ = false;
}
XsdNillable:
tok_xsd_nillable
{
$$ = true;
}
|
{
$$ = false;
}
XsdAttributes:
tok_xsd_attrs '{' FieldList '}'
{
$$ = $3;
}
|
{
$$ = NULL;
}
Xception:
tok_xception tok_identifier '{' FieldList '}'
{
pdebug("Xception -> tok_xception tok_identifier { FieldList }");
$4->set_name($2);
$4->set_xception(true);
$$ = $4;
}
Sandesh:
SandeshType tok_sandesh tok_identifier '{' SFieldList '}' TypeAnnotations
{
pdebug("Sandesh -> tok_sandesh tok_identifier { SFieldList }");
$5->set_name($3);
$5->set_type($1);
if (($1 != g_type_sandesh_request) &&
($1 != g_type_sandesh_response) &&
($1 != g_type_sandesh_object)) {
if ($5->exist_opt_field()) {
yyerror("optional field not supported in sandesh");
exit(1);
}
}
if ($1 == g_type_sandesh_response) {
$5->append(new t_field(g_type_bool, "more", 0, true));
} else if ($1 == g_type_sandesh_request) {
} else if ($1 == g_type_sandesh_system || $1 == g_type_sandesh_object) {
$5->append(new t_field(g_type_string, "file", SHRT_MIN, true));
$5->append(new t_field(g_type_i32, "line", SHRT_MIN + 1, true));
} else if ($1 == g_type_sandesh_trace || $1 == g_type_sandesh_trace_object) {
$5->append(new t_field(g_type_string, "file", SHRT_MIN, true));
$5->append(new t_field(g_type_i32, "line", SHRT_MIN + 1, true));
}
$$ = $5;
if ($7 != NULL) {
$$->annotations_ = $7->annotations_;
delete $7;
}
}
SandeshType:
tok_system
{
$$ = g_type_sandesh_system;
}
|
tok_request
{
$$ = g_type_sandesh_request;
}
|
tok_response
{
$$ = g_type_sandesh_response;
}
|
tok_trace
{
$$ = g_type_sandesh_trace;
}
|
tok_trace_object
{
$$ = g_type_sandesh_trace_object;
}
|
tok_buffer
{
$$ = g_type_sandesh_buffer;
}
|
tok_uve
{
$$ = g_type_sandesh_uve;
}
|
tok_dynamic_uve
{
$$ = g_type_sandesh_dynamic_uve;
}
|
tok_object
{
$$ = g_type_sandesh_object;
}
|
tok_flow
{
$$ = g_type_sandesh_flow;
}
|
tok_alarm
{
$$ = g_type_sandesh_alarm;
}
|
tok_session
{
$$ = g_type_sandesh_session;
}
Service:
tok_service tok_identifier Extends '{' FlagArgs FunctionList UnflagArgs '}'
{
pdebug("Service -> tok_service tok_identifier { FunctionList }");
$$ = $6;
$$->set_name($2);
$$->set_extends($3);
}
FlagArgs:
{
g_arglist = 1;
}
UnflagArgs:
{
g_arglist = 0;
}
Extends:
tok_extends tok_identifier
{
pdebug("Extends -> tok_extends tok_identifier");
$$ = NULL;
if (g_parse_mode == PROGRAM) {
$$ = g_scope->get_service($2);
if ($$ == NULL) {
yyerror("Service \"%s\" has not been defined.", $2);
exit(1);
}
}
}
|
{
$$ = NULL;
}
FunctionList:
FunctionList Function
{
pdebug("FunctionList -> FunctionList Function");
$$ = $1;
$1->add_function($2);
}
|
{
pdebug("FunctionList -> ");
$$ = new t_service(g_program);
}
Function:
CaptureDocText Oneway AbcFunction StaticFunction FunctionType tok_identifier '(' FieldList ')' Throws CommaOrSemicolonOptional
{
$8->set_name(std::string($6) + "_args");
$$ = new t_function($5, $6, $8, $10, $2, $3, $4);
if ($1 != NULL) {
$$->set_doc($1);
}
}
Oneway:
tok_oneway
{
$$ = true;
}
|
{
$$ = false;
}