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