Sync with 5.3.0
[deliverable/titan.core.git] / compiler2 / ttcn3 / coding_attrib_p.y
CommitLineData
970ed795
EL
1/******************************************************************************
2 * Copyright (c) 2000-2014 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8/* Parser for "extension" attributes of functions, external functions and
9 * port types related to message encoding. */
10
11%{
12
13#include "../../common/dbgnew.hh"
14#include "../string.hh"
15#include "../Identifier.hh"
16#include "../Setting.hh"
17#include "../Type.hh"
18#include "AST_ttcn3.hh"
19#include "Attributes.hh"
20#include "Ttcnstuff.hh"
21#include "../stack.hh"
22
23using namespace Ttcn;
24using namespace Common;
25
26/* Various C macros */
27
28#define YYERROR_VERBOSE
29#define yytext coding_attrib_text
30
31/* C/C++ declarations */
32
33extern char *yytext;
34extern int yylex();
35extern const char *coding_attrib_infile;
36
37/* Init the lexer. Located in coding_attrib_la.l */
38extern void init_coding_attrib_lex(const AttributeSpec& attrib);
39extern void cleanup_coding_attrib_lex();
40
41ExtensionAttributes *extatrs = 0;
42
43static void yyerror(const char *str);
44
45%}
46
47/*********************************************************************
48 * Bison declarations
49 *********************************************************************/
50
51%name-prefix="coding_attrib_"
52%output="coding_attrib_p.cc"
53%expect 0
54
55/*********************************************************************
56 * The union-type
57 *********************************************************************/
58
59%union {
60 ErrorBehaviorList *errorbehaviorlist;
61 ErrorBehaviorSetting *errorbehaviorsetting;
62 PrintingType *printing;
63 Identifier *id;
64 Ttcn::Reference *reference;
65 string *str;
66 Type *type;
67 Types *types;
68 TypeMapping *typemapping;
69 TypeMappings *typemappings;
70 TypeMappingTarget *typemappingtarget;
71 TypeMappingTargets *typemappingtargets;
72
73 struct {
74 Type::MessageEncodingType_t encoding_type;
75 string *encoding_options;
76 } encdec_attribute;
77
78 struct {
79 Type::MessageEncodingType_t encoding_type;
80 string *encoding_options;
81 ErrorBehaviorList *eb_list;
82 } encdec_mapping;
83
84 struct {
85 TypeMappings *in_mappings, *out_mappings;
86 } in_out_mappings;
87
88 struct {
89 Ttcn::Reference *port_type_ref;
90 TypeMappings *in_mappings, *out_mappings;
91 } user_attribute;
92
93 Def_Function_Base::prototype_t prototype;
94 Type::typetype_t typetype;
95 Type::MessageEncodingType_t encoding_type;
96 ExtensionAttributes *extattrs;
97 ExtensionAttribute *extattr;
98 int number;
99}
100
101/*********************************************************************
102 * Tokens with semantic value
103 *********************************************************************/
104
105%token <prototype> PrototypeSetting
106%token <encoding_type> EncodingType
107%token <str> EncodingOption
108%token <str> ErrorBehaviorString
109%token <id> IDentifier "Identifier"
110%token <number> Number
111
112/*********************************************************************
113 * Tokens without semantic value
114 *********************************************************************/
115
116/* TTCN-3 keywords */
117
118%token AddressKeyword "address"
119%token AnyTypeKeyword "anytype"
120%token BitStringKeyword "bitstring"
121%token BooleanKeyword "boolean"
122%token CharStringKeyword "charstring"
123%token DefaultKeyword "default"
124%token EncodeKeyword "encode"
125%token FloatKeyword "float"
126%token FunctionKeyword "function"
127%token HexStringKeyword "hexstring"
128%token InKeyword "in"
129%token IntegerKeyword "integer"
130%token ObjectIdentifierKeyword "objid"
131%token OctetStringKeyword "octetstring"
132%token OutKeyword "out"
133%token UniversalKeyword "universal"
134%token VerdictTypeKeyword "verdicttype"
135%token VersionKeyword "version"
136%token RequiresKeyword "requires"
137%token ReqTitanKeyword "requiresTitan"
138
139/* Non-standard keywords used by the attributes with context-sensitive
140 * recognition */
141
142%token DecodeKeyword "decode"
143%token DiscardKeyword "discard"
144%token ErrorBehaviorKeyword "errorbehavior"
145%token InternalKeyword "internal"
146%token PrototypeKeyword "prototype"
147%token ProviderKeyword "provider"
148%token SimpleKeyword "simple"
149%token UserKeyword "user"
150%token TransparentKeyword "transparent"
151%token PrintingKeyword "printing"
152
153%token CompactKeyword "compact"
154%token PrettyKeyword "pretty"
155
156%token RedirectSymbol "->"
157
158%token '.'
159%token '<'
160%token '>'
161%token '/'
162
163/*********************************************************************
164 * Semantic types of nonterminals
165 *********************************************************************/
166
167%type <errorbehaviorsetting> ErrorBehaviorSetting
168%type <errorbehaviorlist> ErrorBehaviorSettingList ErrorBehaviorAttribute
169%type <printing> PrintingAttribute PrintingType
170%type <reference> FunctionMapping FunctionReference PortTypeReference
171 ReferencedType
172%type <str> EncodingOptions
173%type <type> Type
174%type <types> TypeList
175%type <typemapping> TypeMapping
176%type <typemappings> TypeMappingList
177%type <typemappingtarget> TypeMappingTarget
178%type <typemappingtargets> TypeMappingTargetList
179
180%type <encdec_attribute> DecodeAttribute EncDecAttributeBody EncodeAttribute
181%type <encdec_mapping> DecodeMapping EncodeMapping
182%type <in_out_mappings> InOutTypeMapping InOutTypeMappingList
183%type <user_attribute> UserAttribute
184
185%type <prototype> PrototypeAttribute
186%type <typetype> PredefinedType
187
188%type <extattr> ExtensionAttribute ExternalFunctionAttribute
189 PortTypeAttribute AnyTypeAttribute EncDecValueAttribute
190 VersionAttribute RequiresAttribute TransparentAttribute
191
192%type <extattrs> ExtensionAttributes
193
194/*********************************************************************
195 * Destructors
196 *********************************************************************/
197
198%destructor { delete $$; }
199EncodingOption
200EncodingOptions
201ErrorBehaviorAttribute
202ErrorBehaviorSetting
203ErrorBehaviorSettingList
204ErrorBehaviorString
205FunctionMapping
206FunctionReference
207IDentifier
208PortTypeReference
209ReferencedType
210Type
211TypeList
212TypeMapping
213TypeMappingList
214TypeMappingTarget
215TypeMappingTargetList
216ExtensionAttribute
217ExtensionAttributes
218ExternalFunctionAttribute
219PortTypeAttribute
220AnyTypeAttribute
221EncDecValueAttribute
222VersionAttribute
223RequiresAttribute
224PrintingAttribute
225PrintingType
226
227%destructor { delete $$.encoding_options; }
228DecodeAttribute
229EncDecAttributeBody
230EncodeAttribute
231
232%destructor {
233 delete $$.encoding_options;
234 delete $$.eb_list;
235}
236DecodeMapping
237EncodeMapping
238
239%destructor {
240 delete $$.in_mappings;
241 delete $$.out_mappings;
242}
243InOutTypeMapping
244InOutTypeMappingList
245
246%destructor {
247 delete $$.port_type_ref;
248 delete $$.in_mappings;
249 delete $$.out_mappings;
250}
251UserAttribute
252
253%expect 4
254
255%%
256
257/*********************************************************************
258 * Grammar
259 *********************************************************************/
260
261GrammarRoot:
262 ExtensionAttributes
263 {
264 if (extatrs == 0) extatrs = $1;
265 else {
266 extatrs->import($1);
267 delete $1;
268 }
269 }
270;
271
272ExtensionAttributes:
273 /* empty */
274 {
275 $$ = new ExtensionAttributes;
276 }
277| ExtensionAttributes ExtensionAttribute
278 {
279 $$=$1;
280 if ($2 != NULL) $$->add($2);
281 }
282;
283
284ExtensionAttribute:
285 ExternalFunctionAttribute
286| PortTypeAttribute
287| AnyTypeAttribute
288| EncDecValueAttribute
289| VersionAttribute
290| RequiresAttribute
291| TransparentAttribute
292;
293
294VersionAttribute:
295VersionKeyword IDentifier
296{ // version R2D2
297 $$ = new ExtensionAttribute(NULL, 0, 0, 0, $2); // VERSION
298 $$->set_location(coding_attrib_infile, @$);
299 if ($$->get_type() == ExtensionAttribute::NONE) {
300 $$->error("Incorrect version data '%s'", $2->get_name().c_str());
301 delete $2;
302 delete $$;
303 $$ = NULL;
304 }
305}
306| VersionKeyword '<' IDentifier '>'
307{ // version <RnXnn>
308 $$ = new ExtensionAttribute(NULL, 0, 0, 0, $3, ExtensionAttribute::VERSION_TEMPLATE);
309 $$->set_location(coding_attrib_infile, @$);
310 if ($$->get_type() == ExtensionAttribute::NONE) {
311 $$->error("Incorrect version template '<%s>'", $3->get_name().c_str());
312 delete $3;
313 delete $$;
314 $$ = NULL;
315 }
316}
317| VersionKeyword IDentifier Number Number IDentifier
318{ // version CNL 113 200 R2D2
319 $$ = new ExtensionAttribute($2->get_dispname().c_str(), $3, $4, 0, $5); // VERSION
320 $$->set_location(coding_attrib_infile, @$);
321 if ($$->get_type() == ExtensionAttribute::NONE) {
322 $$->error("Incorrect version data '%s %d %d %s'",
323 $2->get_dispname().c_str(), $3, $4, $5->get_dispname().c_str());
324 delete $5;
325 delete $$;
326 $$ = NULL;
327 }
328 delete $2;
329}
330| VersionKeyword IDentifier Number Number '<' IDentifier '>'
331{ // version CNL 113 200 <RnXnn>
332 $$ = new ExtensionAttribute($2->get_dispname().c_str(), $3, $4, 0, $6, ExtensionAttribute::VERSION_TEMPLATE); // VERSION
333 $$->set_location(coding_attrib_infile, @$);
334 if ($$->get_type() == ExtensionAttribute::NONE) {
335 $$->error("Incorrect version data '%s %d %d <%s>'",
336 $2->get_dispname().c_str(), $3, $4, $6->get_dispname().c_str());
337 delete $6;
338 delete $$;
339 $$ = NULL;
340 }
341 delete $2;
342}
343| VersionKeyword IDentifier Number Number '/' Number IDentifier
344{ // version CNL 113 200 / 1 R2D2
345 $$ = new ExtensionAttribute($2->get_dispname().c_str(), $3, $4, $6, $7); // VERSION
346 $$->set_location(coding_attrib_infile, @$);
347 if ($$->get_type() == ExtensionAttribute::NONE) {
348 $$->error("Incorrect version data '%s %d %d / %d %s'",
349 $2->get_dispname().c_str(), $3, $4, $6, $7->get_dispname().c_str());
350 delete $7;
351 delete $$;
352 $$ = NULL;
353 }
354 delete $2;
355}
356| VersionKeyword IDentifier Number Number '/' Number '<' IDentifier '>'
357{ // version CNL 113 200 / 1 <RnXnn>
358 $$ = new ExtensionAttribute($2->get_dispname().c_str(), $3, $4, $6, $8, ExtensionAttribute::VERSION_TEMPLATE); // VERSION
359 $$->set_location(coding_attrib_infile, @$);
360 if ($$->get_type() == ExtensionAttribute::NONE) {
361 $$->error("Incorrect version data '%s %d %d / %d <%s>'",
362 $2->get_dispname().c_str(), $3, $4, $6, $8->get_dispname().c_str());
363 delete $8;
364 delete $$;
365 $$ = NULL;
366 }
367 delete $2;
368}
369;
370
371RequiresAttribute:
372RequiresKeyword IDentifier IDentifier
373{ // module R1B
374 $$ = new ExtensionAttribute($2, NULL, 0, 0, 0, $3); // REQUIRES
375 $$->set_location(coding_attrib_infile, @$);
376 if ($$->get_type() == ExtensionAttribute::NONE) {
377 /* parsing the version has failed */
378 $$->error("Incorrect version data '%s'", $3->get_name().c_str());
379 delete $2;
380 delete $3;
381 delete $$;
382 $$ = NULL;
383 }
384}
385| RequiresKeyword IDentifier IDentifier Number Number IDentifier
386{ // module CNL xxx xxx R1A
387 $$ = new ExtensionAttribute($2, $3->get_dispname().c_str(), $4, $5, 0, $6); // REQUIRES
388 $$->set_location(coding_attrib_infile, @$);
389 if ($$->get_type() == ExtensionAttribute::NONE) {
390 $$->error("Incorrect version data '%s %d %d %s'",
391 $3->get_dispname().c_str(), $4, $5, $6->get_dispname().c_str());
392 delete $2;
393 delete $6;
394 delete $$;
395 $$ = NULL;
396 }
397 delete $3;
398}
399| RequiresKeyword IDentifier IDentifier Number Number '/' Number IDentifier
400{ // module CNL xxx xxx / 1 R9A
401 $$ = new ExtensionAttribute($2, $3->get_dispname().c_str(), $4, $5, $7, $8); // REQUIRES
402 $$->set_location(coding_attrib_infile, @$);
403 if ($$->get_type() == ExtensionAttribute::NONE) {
404 $$->error("Incorrect version data '%s %d %d / %d %s'",
405 $3->get_dispname().c_str(), $4, $5, $7, $8->get_dispname().c_str());
406 delete $2;
407 delete $8;
408 delete $$;
409 $$ = NULL;
410 }
411 delete $3;
412}
413| ReqTitanKeyword IDentifier
414{ // R1A
415 $$ = new ExtensionAttribute(NULL, 0, 0, 0, $2, ExtensionAttribute::REQ_TITAN);
416 $$->set_location(coding_attrib_infile, @$);
417 if ($$->get_type() == ExtensionAttribute::NONE) {
418 /* parsing the version has failed */
419 $$->error("Incorrect version data '%s'", $2->get_name().c_str());
420 delete $2;
421 delete $$;
422 $$ = NULL;
423 }
424}
425| ReqTitanKeyword IDentifier Number Number IDentifier
426{ // CRL 113 200 R1A
427 $$ = new ExtensionAttribute($2->get_dispname().c_str(), $3, $4, 0, $5, ExtensionAttribute::REQ_TITAN);
428 $$->set_location(coding_attrib_infile, @$);
429 if ($$->get_type() == ExtensionAttribute::NONE) {
430 $$->error("Incorrect version data '%s %d %d %s'",
431 $2->get_dispname().c_str(), $3, $4, $5->get_dispname().c_str());
432 delete $5;
433 delete $$;
434 $$ = NULL;
435 }
436 delete $2;
437}
438| ReqTitanKeyword IDentifier Number Number '/' Number IDentifier
439{ // CRL 113 200 / 2 R1A
440 $$ = new ExtensionAttribute($2->get_dispname().c_str(), $3, $4, $6, $7, ExtensionAttribute::REQ_TITAN);
441 $$->set_location(coding_attrib_infile, @$);
442 if ($$->get_type() == ExtensionAttribute::NONE) {
443 $$->error("Incorrect version data '%s %d %d / %d %s'",
444 $2->get_dispname().c_str(), $3, $4, $6, $7->get_dispname().c_str());
445 delete $7;
446 delete $$;
447 $$ = NULL;
448 }
449 delete $2;
450}
451;
452
453TransparentAttribute: TransparentKeyword
454{
455 $$ = new ExtensionAttribute(ExtensionAttribute::TRANSPARENT);
456 $$->set_location(coding_attrib_infile, @$);
457}
458;
459
460EncDecValueAttribute:
461 InOutTypeMappingList
462 {
463 $$ = new ExtensionAttribute($1.in_mappings, $1.out_mappings); // ENCDECVALUE
464 $$->set_location(coding_attrib_infile, @$);
465 }
466;
467
468/* FunctionAttribute is covered by the PrototypeAttribute branch */
469ExternalFunctionAttribute:
470 PrototypeAttribute
471 {
472 $$ = new ExtensionAttribute($1); // PROTOTYPE
473 $$->set_location(coding_attrib_infile, @$);
474 }
475| EncodeAttribute
476 {
477 $$ = new ExtensionAttribute(ExtensionAttribute::ENCODE,
478 $1.encoding_type, $1.encoding_options);
479 $$->set_location(coding_attrib_infile, @$);
480 }
481| DecodeAttribute
482 {
483 $$ = new ExtensionAttribute(ExtensionAttribute::DECODE,
484 $1.encoding_type, $1.encoding_options);
485 $$->set_location(coding_attrib_infile, @$);
486 }
487| ErrorBehaviorAttribute
488 {
489 $$ = new ExtensionAttribute($1); // ERRORBEHAVIOR
490 $$->set_location(coding_attrib_infile, @$);
491 }
492| PrintingAttribute
493 {
494 $$ = new ExtensionAttribute($1); // PRINTING
495 $$->set_location(coding_attrib_infile, @$);
496 }
497;
498
499PortTypeAttribute:
500 InternalKeyword
501 {
502 $$ = new ExtensionAttribute(PortTypeBody::TP_INTERNAL); // PORT_API
503 $$->set_location(coding_attrib_infile, @$);
504 }
505| AddressKeyword
506 {
507 $$ = new ExtensionAttribute(PortTypeBody::TP_ADDRESS); // PORT_API
508 $$->set_location(coding_attrib_infile, @$);
509 }
510| ProviderKeyword
511 {
512 $$ = new ExtensionAttribute(ExtensionAttribute::PORT_TYPE_PROVIDER);
513 $$->set_location(coding_attrib_infile, @$);
514 }
515| UserAttribute
516 {
517 $$ = new ExtensionAttribute($1.port_type_ref,
518 $1.in_mappings, $1.out_mappings); // PORT_TYPE_USER
519 $$->set_location(coding_attrib_infile, @$);
520 }
521;
522
523PrototypeAttribute:
524 PrototypeKeyword '(' PrototypeSetting ')' { $$ = $3; }
525;
526
527EncodeAttribute:
528 EncodeKeyword EncDecAttributeBody { $$ = $2; }
529;
530
531DecodeAttribute:
532 DecodeKeyword EncDecAttributeBody { $$ = $2; }
533;
534
535EncDecAttributeBody:
536 '(' EncodingType ')'
537 {
538 $$.encoding_type = $2;
539 $$.encoding_options = 0;
540 }
541| '(' EncodingType ':' EncodingOptions ')'
542 {
543 $$.encoding_type = $2;
544 $$.encoding_options = $4;
545 }
546;
547
548EncodingOptions:
549 EncodingOption { $$ = $1; }
550| EncodingOptions EncodingOption
551 {
552 $$ = $1;
553 *$$ += ' ';
554 *$$ += *$2;
555 delete $2;
556 }
557;
558
559ErrorBehaviorAttribute:
560 ErrorBehaviorKeyword '(' ErrorBehaviorSettingList ')'
561 {
562 $$ = $3;
563 $$->set_location(coding_attrib_infile, @$);
564 }
565;
566
567ErrorBehaviorSettingList:
568 ErrorBehaviorSetting
569 {
570 $$ = new ErrorBehaviorList();
571 $$->add_ebs($1);
572 }
573| ErrorBehaviorSettingList ',' ErrorBehaviorSetting
574 {
575 $$ = $1;
576 $$->add_ebs($3);
577 }
578;
579
580ErrorBehaviorSetting:
581 ErrorBehaviorString ':' ErrorBehaviorString
582 {
583 $$ = new ErrorBehaviorSetting(*$1, *$3);
584 $$->set_location(coding_attrib_infile, @$);
585 delete $1;
586 delete $3;
587 }
588;
589
590PrintingAttribute:
591 PrintingKeyword '(' PrintingType ')'
592 {
593 $$ = $3;
594 $$->set_location(coding_attrib_infile, @$);
595 }
596;
597
598PrintingType:
599 CompactKeyword
600 {
601 $$ = new PrintingType();
602 $$->set_printing(PrintingType::PT_COMPACT);
603 }
604| PrettyKeyword
605 {
606 $$ = new PrintingType();
607 $$->set_printing(PrintingType::PT_PRETTY);
608 }
609;
610
611UserAttribute:
612 UserKeyword PortTypeReference InOutTypeMappingList
613 {
614 $$.port_type_ref = $2;
615 $$.in_mappings = $3.in_mappings;
616 $$.out_mappings = $3.out_mappings;
617 }
618;
619
620PortTypeReference:
621 IDentifier
622 {
623 $$ = new Ttcn::Reference($1);
624 $$->set_location(coding_attrib_infile, @$);
625 }
626| IDentifier '.' IDentifier
627 {
628 $$ = new Ttcn::Reference($1, $3);
629 $$->set_location(coding_attrib_infile, @$);
630 }
631;
632
633InOutTypeMappingList:
634 InOutTypeMapping { $$ = $1; }
635| InOutTypeMappingList InOutTypeMapping
636 {
637 if ($1.in_mappings) {
638 $$.in_mappings = $1.in_mappings;
639 if ($2.in_mappings) {
640 $$.in_mappings->steal_mappings($2.in_mappings);
641 delete $2.in_mappings;
642 }
643 } else $$.in_mappings = $2.in_mappings;
644 if ($1.out_mappings) {
645 $$.out_mappings = $1.out_mappings;
646 if ($2.out_mappings) {
647 $$.out_mappings->steal_mappings($2.out_mappings);
648 delete $2.out_mappings;
649 }
650 } else $$.out_mappings = $2.out_mappings;
651 }
652;
653
654InOutTypeMapping:
655 InKeyword '(' TypeMappingList ')'
656 {
657 $$.in_mappings = $3;
658 $$.in_mappings->set_location(coding_attrib_infile, @$);
659 $$.out_mappings = 0;
660 }
661| OutKeyword '(' TypeMappingList ')'
662 {
663 $$.in_mappings = 0;
664 $$.out_mappings = $3;
665 $$.out_mappings->set_location(coding_attrib_infile, @$);
666 }
667;
668
669TypeMappingList:
670 TypeMapping
671 {
672 $$ = new TypeMappings();
673 $$->add_mapping($1);
674 }
675| TypeMappingList ';' TypeMapping
676 {
677 $$ = $1;
678 $$->add_mapping($3);
679 }
680;
681
682TypeMapping:
683 Type RedirectSymbol TypeMappingTargetList
684 {
685 $$ = new TypeMapping($1, $3);
686 $$->set_location(coding_attrib_infile, @$);
687 }
688;
689
690TypeMappingTargetList:
691 TypeMappingTarget
692 {
693 $$ = new TypeMappingTargets();
694 $$->add_target($1);
695 }
696| TypeMappingTargetList ',' TypeMappingTarget
697 {
698 $$ = $1;
699 $$->add_target($3);
700 }
701;
702
703TypeMappingTarget:
704 Type ':' SimpleKeyword
705 {
706 $$ = new TypeMappingTarget($1, TypeMappingTarget::TM_SIMPLE);
707 $$->set_location(coding_attrib_infile, @$);
708 }
709| '-' ':' DiscardKeyword
710 {
711 $$ = new TypeMappingTarget(0, TypeMappingTarget::TM_DISCARD);
712 $$->set_location(coding_attrib_infile, @$);
713 }
714| Type ':' FunctionMapping
715 {
716 $$ = new TypeMappingTarget($1, TypeMappingTarget::TM_FUNCTION, $3);
717 $$->set_location(coding_attrib_infile, @$);
718 }
719| Type ':' EncodeMapping
720 {
721 $$ = new TypeMappingTarget($1, TypeMappingTarget::TM_ENCODE,
722 $3.encoding_type, $3.encoding_options, $3.eb_list);
723 $$->set_location(coding_attrib_infile, @$);
724 }
725| Type ':' DecodeMapping
726 {
727 $$ = new TypeMappingTarget($1, TypeMappingTarget::TM_DECODE,
728 $3.encoding_type, $3.encoding_options, $3.eb_list);
729 $$->set_location(coding_attrib_infile, @$);
730 }
731;
732
733FunctionMapping:
734 FunctionKeyword '(' FunctionReference ')' { $$ = $3; }
735;
736
737FunctionReference:
738 IDentifier
739 {
740 $$ = new Ttcn::Reference($1);
741 $$->set_location(coding_attrib_infile, @$);
742 }
743| IDentifier '.' IDentifier
744 {
745 $$ = new Ttcn::Reference($1, $3);
746 $$->set_location(coding_attrib_infile, @$);
747 }
748;
749
750EncodeMapping:
751 EncodeAttribute
752 {
753 $$.encoding_type = $1.encoding_type;
754 $$.encoding_options = $1.encoding_options;
755 $$.eb_list = 0;
756 }
757| EncodeAttribute ErrorBehaviorAttribute
758 {
759 $$.encoding_type = $1.encoding_type;
760 $$.encoding_options = $1.encoding_options;
761 $$.eb_list = $2;
762 }
763;
764
765DecodeMapping:
766 DecodeAttribute
767 {
768 $$.encoding_type = $1.encoding_type;
769 $$.encoding_options = $1.encoding_options;
770 $$.eb_list = 0;
771 }
772| DecodeAttribute ErrorBehaviorAttribute
773 {
774 $$.encoding_type = $1.encoding_type;
775 $$.encoding_options = $1.encoding_options;
776 $$.eb_list = $2;
777 }
778;
779
780Type:
781 PredefinedType
782 {
783 $$ = new Type($1);
784 $$->set_location(coding_attrib_infile, @$);
785 }
786| ReferencedType
787 {
788 $$ = new Type(Type::T_REFD, $1);
789 $$->set_location(coding_attrib_infile, @$);
790 }
791;
792
793PredefinedType: /* typetype_t */
794 BitStringKeyword { $$ = Type::T_BSTR; }
795| BooleanKeyword { $$ = Type::T_BOOL; }
796| CharStringKeyword { $$ = Type::T_CSTR; }
797| UniversalKeyword CharStringKeyword { $$ = Type::T_USTR; }
798| IntegerKeyword { $$ = Type::T_INT; }
799| OctetStringKeyword { $$ = Type::T_OSTR; }
800| HexStringKeyword { $$ = Type::T_HSTR; }
801| VerdictTypeKeyword { $$ = Type::T_VERDICT; }
802| FloatKeyword { $$ = Type::T_REAL; }
803| AddressKeyword { $$ = Type::T_ADDRESS; }
804| DefaultKeyword { $$ = Type::T_DEFAULT; }
805| AnyTypeKeyword
806 {
807 Location loc(coding_attrib_infile, @$);
808 loc.error("Type `anytype' as a field of `anytype' is not supported");
809 $$ = Type::T_ERROR;
810 }
811| ObjectIdentifierKeyword { $$ = Type::T_OID; }
812;
813
814ReferencedType: /* a Reference* */
815 IDentifier
816 {
817 $$ = new Ttcn::Reference($1);
818 $$->set_location(coding_attrib_infile, @$);
819 }
820| IDentifier '.' IDentifier
821 {
822 $$ = new Ttcn::Reference($1, $3);
823 $$->set_location(coding_attrib_infile, @$);
824 }
825;
826
827
828AnyTypeAttribute:
829 AnyTypeKeyword TypeList
830 {
831 $$ = new ExtensionAttribute($2); // ANYTYPELIST
832 $$->set_location(coding_attrib_infile, @$);
833 }
834
835
836TypeList:
837 Type
838 {
839 $$ = new Types;
840 $$->add_type($1);
841 $$->set_location(coding_attrib_infile, @$);
842 }
843| TypeList ',' Type
844 {
845 $$ = $1;
846 $$->add_type($3);
847 $$->set_location(coding_attrib_infile, @$);
848 }
849;
850
851%%
852
853static void yyerror(const char *str)
854{
855 Location loc(coding_attrib_infile, yylloc);
856 if (*yytext) {
857 // the most recently parsed token is known
858 loc.error("at or before token `%s': %s", yytext, str);
859 } else {
860 // the most recently parsed token is unknown
861 loc.error("%s", str);
862 }
863}
864
865/** Parse all extension attributes in a "with" statement */
866ExtensionAttributes * parse_extattributes(WithAttribPath *w_attrib_path)
867{
868 extatrs = 0;
869 if (!w_attrib_path) FATAL_ERROR("parse_extattributes(): NULL pointer");
870 // Collect attributes from outer scopes
871 vector<SingleWithAttrib> const& real_attribs =
872 w_attrib_path->get_real_attrib();
873 const size_t nof_attribs = real_attribs.size();
874
875 for (size_t i = 0; i < nof_attribs; i++) {
876 SingleWithAttrib *attrib = real_attribs[i];
877 if (attrib->get_attribKeyword() == SingleWithAttrib::AT_EXTENSION) {
878 Qualifiers *qualifiers = attrib->get_attribQualifiers();
879 if (!qualifiers || qualifiers->get_nof_qualifiers() == 0) {
880 // Only care about extension attributes without qualifiers
881 Error_Context cntxt(attrib, "In `extension' attribute");
882 init_coding_attrib_lex(attrib->get_attribSpec());
883 int result = yyparse(); /* 0=ok, 1=error, 2=out of memory */
884 (void)result;
885 cleanup_coding_attrib_lex();
886 } // if no qualifiers
887 } // if AT_EXTENSION
888 } // for
889
890 return extatrs;
891}
This page took 0.055685 seconds and 5 git commands to generate.