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