Sync with 5.3.0
[deliverable/titan.core.git] / core / config_process.y
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 %{
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <stdarg.h>
14 #include <ctype.h>
15 #include <errno.h>
16
17 #include <openssl/bn.h>
18
19 #include "../common/config_preproc.h"
20
21 #include "Param_Types.hh"
22 #include "Integer.hh"
23 #include "Float.hh"
24 #include "Boolean.hh"
25 #include "Objid.hh"
26 #include "Verdicttype.hh"
27 #include "Bitstring.hh"
28 #include "Hexstring.hh"
29 #include "Octetstring.hh"
30 #include "Charstring.hh"
31 #include "Universal_charstring.hh"
32
33 #include "Module_list.hh"
34 #include "Port.hh"
35 #include "Runtime.hh"
36
37 #include "LoggingBits.hh"
38 #include "LoggingParam.hh"
39
40 #include "Profiler.hh"
41
42 #define YYERROR_VERBOSE
43
44 #include "config_process.lex.hh"
45
46 extern void reset_config_process_lex(const char* fname);
47 extern void config_process_close();
48 extern int config_process_get_current_line();
49 extern std::string get_cfg_process_current_file();
50
51 static int config_process_parse();
52 static void check_duplicate_option(const char *section_name,
53 const char *option_name, boolean& option_flag);
54 static void check_ignored_section(const char *section_name);
55 static void set_param(Module_Param& module_param);
56 static unsigned char char_to_hexdigit(char c);
57
58 static boolean error_flag = FALSE;
59
60 static Module_Param* parsed_module_param = NULL;
61 static char * parsing_error_messages = NULL;
62
63 /*
64 For detecting duplicate entries in the config file. Start out as FALSE,
65 set to TRUE bycheck_duplicate_option().
66 Exception: duplication of parameters that can be component specific is checked
67 by set_xxx(), these start out as TRUE.
68 */
69 static boolean file_name_set = FALSE,
70 file_mask_set = TRUE,
71 console_mask_set = TRUE,
72 timestamp_format_set = FALSE,
73 source_info_format_set = FALSE,
74 append_file_set = FALSE,
75 log_event_types_set = FALSE,
76 log_entity_name_set = FALSE,
77 begin_controlpart_command_set = FALSE,
78 end_controlpart_command_set = FALSE,
79 begin_testcase_command_set = FALSE,
80 end_testcase_command_set = FALSE,
81 log_file_size_set = TRUE,
82 log_file_number_set = TRUE,
83 log_disk_full_action_set = TRUE,
84 matching_verbosity_set = FALSE,
85 logger_plugins_set = FALSE,
86 plugin_specific_set = FALSE;
87
88 int execute_list_len = 0;
89 execute_list_item *execute_list = NULL;
90
91 string_map_t *config_defines;
92
93 %}
94
95 %union{
96 char *str_val;
97 int_val_t *int_val;
98 int int_native;
99 unsigned int uint_val;
100 double float_val;
101 boolean bool_val;
102 param_objid_t objid_val;
103 verdicttype verdict_val;
104 param_bitstring_t bitstring_val;
105 param_hexstring_t hexstring_val;
106 param_charstring_t charstring_val;
107 param_octetstring_t octetstring_val;
108 universal_char universal_char_val;
109 param_universal_charstring_t universal_charstring_val;
110 Module_Param::operation_type_t param_optype_val;
111 Vector<Module_Param*>* module_param_list;
112 Module_Param* module_param_val;
113 Module_Param_Length_Restriction* module_param_length_restriction;
114 Vector<char*>* name_vector;
115 component_id_t comp_id;
116 execute_list_item execute_item_val;
117 TTCN_Logger::emergency_logging_behaviour_t emergency_logging_behaviour_value;
118 TTCN_Logger::timestamp_format_t timestamp_value;
119 TTCN_Logger::source_info_format_t source_info_value;
120 TTCN_Logger::log_event_types_t log_event_types_value;
121 TTCN_Logger::disk_full_action_t disk_full_action_value;
122 TTCN_Logger::matching_verbosity_t matching_verbosity_value;
123 TTCN_Logger::Severity logseverity_val;
124 Logging_Bits logoptions_val;
125
126 logging_plugin_t *logging_plugins;
127 logging_param_t logging_params;
128 logging_setting_t logging_param_line;
129 }
130
131 %token ModuleParametersKeyword
132 %token LoggingKeyword
133 %token ProfilerKeyword
134 %token TestportParametersKeyword
135 %token ExecuteKeyword
136 %token ExternalCommandsKeyword
137 %token GroupsKeyword
138 %token ComponentsKeyword
139 %token MainControllerKeyword
140 %token IncludeKeyword
141 %token DefineKeyword
142
143 %token Detailed
144 %token Compact
145 %token ObjIdKeyword "objid"
146 %token CharKeyword "char"
147 %token ControlKeyword "control"
148 %token MTCKeyword "mtc"
149 %token SystemKeyword "system"
150 %token NULLKeyword "NULL"
151 %token nullKeyword "null"
152 %token OmitKeyword "omit"
153 %token ComplementKeyword "complement"
154 %token DotDot ".."
155 %token SupersetKeyword "superset"
156 %token SubsetKeyword "subset"
157 %token PatternKeyword "pattern"
158 %token PermutationKeyword "permutation"
159 %token LengthKeyword "length"
160 %token IfpresentKeyword "ifpresent"
161 %token InfinityKeyword "infinity"
162 %token AssignmentChar ":= or ="
163 %token ConcatChar "&="
164 %token LogFile "LogFile or FileName"
165 %token EmergencyLogging
166 %token EmergencyLoggingBehaviour
167 %token EmergencyLoggingMask
168 %token BufferAll
169 %token BufferMasked
170 %token FileMask
171 %token ConsoleMask
172 %token TimestampFormat
173 %token ConsoleTimestampFormat
174 %token SourceInfoFormat "LogSourceInfo or SourceInfoFormat"
175 %token AppendFile
176 %token LogEventTypes
177 %token LogEntityName
178 %token BeginControlPart
179 %token EndControlPart
180 %token BeginTestCase
181 %token EndTestCase
182 %token <str_val> Identifier
183 %token <str_val> ASN1LowerIdentifier "ASN.1 identifier beginning with a lowercase letter"
184 %token <int_val> Number
185 %token <float_val> Float
186 %token <bool_val> BooleanValue "true or false"
187 %token <verdict_val> VerdictValue
188 %token <bitstring_val> Bstring "bit string value"
189 %token <hexstring_val> Hstring "hex string value"
190 %token <octetstring_val> Ostring "octet string value"
191 %token <str_val> BstringMatch "bit string template"
192 %token <str_val> HstringMatch "hex string template"
193 %token <str_val> OstringMatch "octet string template"
194 %token <charstring_val> Cstring "charstring value"
195 %token DNSName "hostname"
196 /* a single bit */
197 %token <logseverity_val> LoggingBit
198 /* a collection of bits */
199 %token <logseverity_val> LoggingBitCollection
200 %token SubCategories
201 %token <emergency_logging_behaviour_value> EmergencyLoggingBehaviourValue "BufferAll or BufferMasked"
202 %token <timestamp_value> TimestampValue "Time, Datetime or Seconds"
203 %token <source_info_value> SourceInfoValue "None, Single or Stack"
204 %token <bool_val> YesNo "yes or no"
205 %token LocalAddress
206 %token TCPPort
207 %token KillTimer
208 %token NumHCs
209 %token UnixSocketEnabled
210 %token YesToken "yes"
211 %token NoToken "no"
212 %token LogFileSize
213 %token LogFileNumber
214 %token DiskFullAction
215 %token MatchingHints
216 %token LoggerPlugins
217 %token Error
218 %token Stop
219 %token Retry
220 %token Delete
221 %token TtcnStringParsingKeyword
222 %token DisableProfilerKeyword "DisableProfiler"
223 %token DisableCoverageKeyword "DisableCoverage"
224 %token DatabaseFileKeyword "DatabaseFile"
225 %token AggregateDataKeyword "AggregateData"
226 %token StatisticsFileKeyword "StatisticsFile"
227 %token DisableStatisticsKeyword "DisableStatistics"
228 %token StatisticsFilterKeyword "StatisticsFilter"
229 %token StartAutomaticallyKeyword "StartAutomatically"
230 %token NetLineTimesKeyword "NetLineTimes"
231 %token NetFunctionTimesKeyword "NetFunctionTimes"
232 %token <uint_val> ProfilerStatsFlag "profiler statistics filter"
233
234 %type <int_val> IntegerValue
235 %type <float_val> FloatValue
236 %type <objid_val> ObjIdValue ObjIdComponentList
237 %type <int_val> ObjIdComponent NumberForm NameAndNumberForm
238
239 %type <universal_charstring_val> UniversalCharstringValue
240 seqUniversalCharstringFragment UniversalCharstringFragment
241 %type <universal_char_val> Quadruple
242 %type <str_val> EnumeratedValue
243
244 %type <str_val> LoggerPluginId
245 %type <logging_plugins> LoggerPlugin LoggerPluginList
246 %type <logging_params> LoggingParam
247 %type <logging_param_line> LoggingParamLines
248 %type <str_val> LogFileName StringValue
249 /* a collection of bits */
250 %type <logoptions_val> LoggingBitmask
251 %type <logoptions_val> LoggingBitOrCollection
252 %type <source_info_value> SourceInfoSetting
253 %type <bool_val> YesNoOrBoolean
254 %type <log_event_types_value> LogEventTypesValue
255 %type <disk_full_action_value> DiskFullActionValue
256 %type <str_val> Command
257 %type <matching_verbosity_value> VerbosityValue
258 %type <comp_id> ComponentId
259 %type <str_val> TestportName ArrayRef TestportParameterName
260 TestportParameterValue
261
262 %type <execute_item_val> ExecuteItem
263
264 %type <bitstring_val> BitstringValue
265 %type <hexstring_val> HexstringValue
266 %type <octetstring_val> OctetstringValue
267
268 %type <name_vector> ParameterName ParameterNameSegment
269 %type <param_optype_val> ParamOpType
270 %type <str_val> FieldName
271 %type <module_param_val> ParameterValue SimpleParameterValue ParameterValueOrNotUsedSymbol
272 FieldValue ArrayItem IndexItem IndexItemList FieldValueList ArrayItemList CompoundValue IntegerRange FloatRange StringRange
273 %type <module_param_list> TemplateItemList
274 %type <module_param_length_restriction> LengthMatch
275 %type <str_val> PatternChunk PatternChunkList
276 %type <int_native> IndexItemIndex LengthBound
277 %type <uint_val> ProfilerStatsFlags
278
279 %destructor { Free($$); }
280 ArrayRef
281 ASN1LowerIdentifier
282 Command
283 EnumeratedValue
284 FieldName
285 Identifier
286 LogFileName
287 StringValue
288 TestportName
289 TestportParameterName
290 TestportParameterValue
291 PatternChunk
292 PatternChunkList
293 BstringMatch
294 HstringMatch
295 OstringMatch
296
297 %destructor { Free($$.components_ptr); }
298 ObjIdComponentList
299 ObjIdValue
300
301 %destructor { Free($$.bits_ptr); }
302 Bstring
303 BitstringValue
304
305 %destructor { Free($$.nibbles_ptr); }
306 Hstring
307 HexstringValue
308
309 %destructor { Free($$.octets_ptr); }
310 Ostring
311 OctetstringValue
312
313 %destructor { Free($$.chars_ptr); }
314 Cstring
315
316 %destructor { Free($$.uchars_ptr); Free($$.quad_positions); }
317 seqUniversalCharstringFragment
318 UniversalCharstringFragment
319 UniversalCharstringValue
320
321 %destructor { if ($$.id_selector == COMPONENT_ID_NAME) Free($$.id_name); }
322 ComponentId
323
324 %destructor { Free($$.module_name); Free($$.testcase_name); }
325 ExecuteItem
326
327 %destructor { delete $$; }
328 IntegerValue
329 NameAndNumberForm
330 Number
331 NumberForm
332 ObjIdComponent
333 ParameterValue
334 SimpleParameterValue
335 ParameterValueOrNotUsedSymbol
336 ArrayItemList
337 FieldValueList
338 IndexItemList
339 CompoundValue
340 ArrayItem
341 FieldValue
342 IndexItem
343 IntegerRange
344 FloatRange
345 StringRange
346
347 %destructor { delete $$; }
348 LengthMatch
349
350 %destructor { for(size_t i=0; i<$$->size(); i++) { delete $$->at(i); } delete $$; }
351 TemplateItemList
352
353 %destructor { for(size_t i=0; i<$$->size(); i++) { Free($$->at(i)); } delete $$; }
354 ParameterName
355 ParameterNameSegment
356
357 %left '+' '-'
358 %left '*' '/'
359 %left UnarySign
360
361 %expect 2
362
363 /*
364 2 conflicts in two distinct states.
365 When seeing a '*' token after an integer or float value in section
366 [MODULE_PARAMETERS] parser cannot decide whether the token is a multiplication
367 operator (shift) or it refers to all modules in the next module parameter
368 (reduce).
369 */
370 %%
371
372 GrammarRoot:
373 ConfigFile
374 {
375 if (Ttcn_String_Parsing::happening()) {
376 config_process_error("Config file cannot be parsed as ttcn string");
377 }
378 }
379 | TtcnStringParsingKeyword ParameterValue
380 {
381 parsed_module_param = $2;
382 }
383 ;
384
385 ConfigFile:
386 /* empty */
387 | ConfigFile Section
388 ;
389
390 Section:
391 ModuleParametersSection
392 | LoggingSection
393 | ProfilerSection
394 | TestportParametersSection
395 | ExecuteSection
396 | ExternalCommandsSection
397 | GroupsSection
398 | ComponentsSection
399 | MainControllerSection
400 | IncludeSection
401 | DefineSection
402 ;
403
404 ModuleParametersSection:
405 ModuleParametersKeyword ModuleParameters
406 ;
407
408 ModuleParameters:
409 /* empty */
410 | ModuleParameters ModuleParameter optSemiColon
411 ;
412
413 ModuleParameter:
414 ParameterName ParamOpType ParameterValue
415 {
416 Module_Param* mp = $3;
417 mp->set_id(new Module_Param_Name(*$1));
418 mp->set_operation_type($2);
419 set_param(*mp);
420 delete mp;
421 delete $1;
422 }
423 ;
424
425 ParameterName:
426 ParameterNameSegment { $$ = $1; }
427 | '*' '.' ParameterNameSegment { $$ = $3; }
428 ;
429
430 ParameterNameSegment:
431 ParameterNameSegment '.' Identifier
432 {
433 $$ = $1;
434 $$->push_back($3);
435 }
436 | ParameterNameSegment '[' Number ']'
437 {
438 $$ = $1;
439 $$->push_back($3->as_string());
440 delete $3;
441 }
442 | Identifier
443 {
444 $$ = new Vector<char*>();
445 $$->push_back($1);
446 }
447 ;
448
449 ParameterValue:
450 SimpleParameterValue
451 {
452 $$ = $1;
453 }
454 | SimpleParameterValue LengthMatch
455 {
456 $$ = $1;
457 $$->set_length_restriction($2);
458 }
459 | SimpleParameterValue IfpresentKeyword
460 {
461 $$ = $1;
462 $$->set_ifpresent();
463 }
464 | SimpleParameterValue LengthMatch IfpresentKeyword
465 {
466 $$ = $1;
467 $$->set_length_restriction($2);
468 $$->set_ifpresent();
469 }
470 ;
471
472 LengthMatch:
473 LengthKeyword '(' LengthBound ')'
474 {
475 $$ = new Module_Param_Length_Restriction();
476 $$->set_single((size_t)$3);
477 }
478 | LengthKeyword '(' LengthBound DotDot LengthBound ')'
479 {
480 if ($3>$5) {
481 config_process_error("invalid length restriction: lower bound > upper bound");
482 }
483 $$ = new Module_Param_Length_Restriction();
484 $$->set_min((size_t)$3);
485 $$->set_max((size_t)$5);
486 }
487 | LengthKeyword '(' LengthBound DotDot InfinityKeyword ')'
488 {
489 $$ = new Module_Param_Length_Restriction();
490 $$->set_min((size_t)$3);
491 }
492 ;
493
494 LengthBound:
495 IntegerValue
496 {
497 if (!$1->is_native()) {
498 config_process_error("bignum length restriction bound.");
499 $$ = 0;
500 } else if ($1->is_negative()) {
501 config_process_error("negative length restriction bound.");
502 $$ = 0;
503 } else {
504 $$ = $1->get_val();
505 }
506 delete $1;
507 }
508 ;
509
510 SimpleParameterValue:
511 IntegerValue
512 {
513 $$ = new Module_Param_Integer($1);
514 }
515 | FloatValue
516 {
517 $$ = new Module_Param_Float($1);
518 }
519 | BooleanValue
520 {
521 $$ = new Module_Param_Boolean($1);
522 }
523 | ObjIdValue
524 {
525 $$ = new Module_Param_Objid($1.n_components, $1.components_ptr);
526 }
527 | VerdictValue
528 {
529 $$ = new Module_Param_Verdict($1);
530 }
531 | BitstringValue
532 {
533 $$ = new Module_Param_Bitstring($1.n_bits, $1.bits_ptr);
534 }
535 | HexstringValue
536 {
537 $$ = new Module_Param_Hexstring($1.n_nibbles, $1.nibbles_ptr);
538 }
539 | OctetstringValue
540 {
541 $$ = new Module_Param_Octetstring($1.n_octets, $1.octets_ptr);
542 }
543 | Cstring
544 {
545 $$ = new Module_Param_Charstring($1.n_chars, $1.chars_ptr);
546 }
547 | UniversalCharstringValue
548 {
549 $$ = new Module_Param_Universal_Charstring($1.n_uchars, $1.uchars_ptr, $1.n_quads, $1.quad_positions);
550 }
551 | EnumeratedValue
552 {
553 $$ = new Module_Param_Enumerated($1);
554 }
555 | OmitKeyword
556 {
557 $$ = new Module_Param_Omit();
558 }
559 | NULLKeyword
560 {
561 $$ = new Module_Param_Asn_Null();
562 }
563 | nullKeyword
564 {
565 $$ = new Module_Param_Ttcn_Null();
566 }
567 | MTCKeyword
568 {
569 $$ = new Module_Param_Ttcn_mtc();
570 }
571 | SystemKeyword
572 {
573 $$ = new Module_Param_Ttcn_system();
574 }
575 | '?'
576 {
577 $$ = new Module_Param_Any();
578 }
579 | '*'
580 {
581 $$ = new Module_Param_AnyOrNone();
582 }
583 | IntegerRange
584 {
585 $$ = $1;
586 }
587 | FloatRange
588 {
589 $$ = $1;
590 }
591 | StringRange
592 {
593 $$ = $1;
594 }
595 | PatternKeyword PatternChunkList
596 {
597 $$ = new Module_Param_Pattern($2);
598 }
599 | BstringMatch
600 {
601 // conversion
602 int n_chars = (int)mstrlen($1);
603 unsigned char* chars_ptr = (unsigned char*)Malloc(n_chars*sizeof(unsigned char));
604 for (int i=0; i<n_chars; i++) {
605 switch ($1[i]) {
606 case '0':
607 chars_ptr[i] = 0;
608 break;
609 case '1':
610 chars_ptr[i] = 1;
611 break;
612 case '?':
613 chars_ptr[i] = 2;
614 break;
615 case '*':
616 chars_ptr[i] = 3;
617 break;
618 default:
619 chars_ptr[i] = 0;
620 config_process_error_f("Invalid char (%c) in bitstring template", $1[i]);
621 }
622 }
623 Free($1);
624 $$ = new Module_Param_Bitstring_Template(n_chars, chars_ptr);
625 }
626 | HstringMatch
627 {
628 int n_chars = (int)mstrlen($1);
629 unsigned char* chars_ptr = (unsigned char*)Malloc(n_chars*sizeof(unsigned char));
630 for (int i=0; i<n_chars; i++) {
631 if ($1[i]=='?') chars_ptr[i] = 16;
632 else if ($1[i]=='*') chars_ptr[i] = 17;
633 else chars_ptr[i] = char_to_hexdigit($1[i]);
634 }
635 Free($1);
636 $$ = new Module_Param_Hexstring_Template(n_chars, chars_ptr);
637 }
638 | OstringMatch
639 {
640 Vector<unsigned short> octet_vec;
641 int str_len = (int)mstrlen($1);
642 for (int i=0; i<str_len; i++) {
643 unsigned short num;
644 if ($1[i]=='?') num = 256;
645 else if ($1[i]=='*') num = 257;
646 else {
647 // first digit
648 num = 16 * char_to_hexdigit($1[i]);
649 i++;
650 if (i>=str_len) config_process_error("Unexpected end of octetstring pattern");
651 // second digit
652 num += char_to_hexdigit($1[i]);
653 }
654 octet_vec.push_back(num);
655 }
656 Free($1);
657 int n_chars = (int)octet_vec.size();
658 unsigned short* chars_ptr = (unsigned short*)Malloc(n_chars*sizeof(unsigned short));
659 for (int i=0; i<n_chars; i++) chars_ptr[i] = octet_vec[i];
660 $$ = new Module_Param_Octetstring_Template(n_chars, chars_ptr);
661 }
662 | CompoundValue
663 {
664 $$ = $1;
665 }
666 ;
667
668 PatternChunkList:
669 PatternChunk
670 {
671 $$ = $1;
672 }
673 | PatternChunkList '&' PatternChunk
674 {
675 $$ = $1;
676 $$ = mputstr($$, $3);
677 Free($3);
678 }
679 ;
680
681 PatternChunk:
682 Cstring
683 {
684 $$ = mcopystr($1.chars_ptr);
685 Free($1.chars_ptr);
686 }
687 | Quadruple
688 {
689 $$ = mprintf("\\q{%d,%d,%d,%d}", $1.uc_group, $1.uc_plane, $1.uc_row, $1.uc_cell);
690 }
691 ;
692
693 IntegerRange:
694 '(' '-' InfinityKeyword DotDot IntegerValue ')'
695 {
696 $$ = new Module_Param_IntRange(NULL, $5);
697 }
698 | '(' IntegerValue DotDot IntegerValue ')'
699 {
700 $$ = new Module_Param_IntRange($2, $4);
701 }
702 | '(' IntegerValue DotDot InfinityKeyword ')'
703 {
704 $$ = new Module_Param_IntRange($2, NULL);
705 }
706 ;
707
708 FloatRange:
709 '(' '-' InfinityKeyword DotDot FloatValue ')'
710 {
711 $$ = new Module_Param_FloatRange(0.0, false, $5, true);
712 }
713 | '(' FloatValue DotDot FloatValue ')'
714 {
715 $$ = new Module_Param_FloatRange($2, true, $4, true);
716 }
717 | '(' FloatValue DotDot InfinityKeyword ')'
718 {
719 $$ = new Module_Param_FloatRange($2, true, 0.0, false);
720 }
721 ;
722
723 StringRange:
724 '(' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
725 {
726 universal_char lower; lower.uc_group=lower.uc_plane=lower.uc_row=lower.uc_cell=0;
727 universal_char upper; upper.uc_group=upper.uc_plane=upper.uc_row=upper.uc_cell=0;
728 if ($2.n_uchars!=1) {
729 config_process_error("Lower bound of char range must be 1 character only");
730 } else if ($4.n_uchars!=1) {
731 config_process_error("Upper bound of char range must be 1 character only");
732 } else {
733 lower = *($2.uchars_ptr);
734 upper = *($4.uchars_ptr);
735 if (upper<lower) {
736 config_process_error("Lower bound is larger than upper bound in the char range");
737 lower = upper;
738 }
739 }
740 Free($2.uchars_ptr);
741 Free($4.uchars_ptr);
742 Free($2.quad_positions);
743 Free($4.quad_positions);
744 $$ = new Module_Param_StringRange(lower, upper);
745 }
746 ;
747
748 IntegerValue:
749 Number { $$ = $1; }
750 | '(' IntegerValue ')' { $$ = $2; }
751 | '+' IntegerValue %prec UnarySign { $$ = $2; }
752 | '-' IntegerValue %prec UnarySign
753 {
754 INTEGER op1;
755 op1.set_val(*$2);
756 $$ = new int_val_t((-op1).get_val());
757 delete $2;
758 }
759 | IntegerValue '+' IntegerValue
760 {
761 INTEGER op1, op2;
762 op1.set_val(*$1);
763 op2.set_val(*$3);
764 $$ = new int_val_t((op1 + op2).get_val());
765 delete $1;
766 delete $3;
767 }
768 | IntegerValue '-' IntegerValue
769 {
770 INTEGER op1, op2;
771 op1.set_val(*$1);
772 op2.set_val(*$3);
773 $$ = new int_val_t((op1 - op2).get_val());
774 delete $1;
775 delete $3;
776 }
777 | IntegerValue '*' IntegerValue
778 {
779 INTEGER op1, op2;
780 op1.set_val(*$1);
781 op2.set_val(*$3);
782 $$ = new int_val_t((op1 * op2).get_val());
783 delete $1;
784 delete $3;
785 }
786 | IntegerValue '/' IntegerValue
787 {
788 if (*$3 == 0) {
789 config_process_error("Integer division by zero.");
790 $$ = new int_val_t((RInt)0);
791 delete $1;
792 delete $3;
793 } else {
794 INTEGER op1, op2;
795 op1.set_val(*$1);
796 op2.set_val(*$3);
797 $$ = new int_val_t((op1 / op2).get_val());
798 delete $1;
799 delete $3;
800 }
801 }
802 ;
803
804 FloatValue:
805 Float { $$ = $1; }
806 | '(' FloatValue ')' { $$ = $2; }
807 | '+' FloatValue %prec UnarySign { $$ = $2; }
808 | '-' FloatValue %prec UnarySign { $$ = -$2; }
809 | FloatValue '+' FloatValue { $$ = $1 + $3; }
810 | FloatValue '-' FloatValue { $$ = $1 - $3; }
811 | FloatValue '*' FloatValue { $$ = $1 * $3; }
812 | FloatValue '/' FloatValue
813 {
814 if ($3 == 0.0) {
815 config_process_error("Floating point division by zero.");
816 $$ = 0.0;
817 } else $$ = $1 / $3;
818 }
819 ;
820
821 ObjIdValue:
822 ObjIdKeyword '{' ObjIdComponentList '}' { $$ = $3; }
823 ;
824
825 ObjIdComponentList:
826 ObjIdComponent
827 {
828 $$.n_components = 1;
829 $$.components_ptr = (int *)Malloc(sizeof(int));
830 $$.components_ptr[0] = $1->get_val();
831 delete $1;
832 }
833 | ObjIdComponentList ObjIdComponent
834 {
835 $$.n_components = $1.n_components + 1;
836 $$.components_ptr = (int *)Realloc($1.components_ptr,
837 $$.n_components * sizeof(int));
838 $$.components_ptr[$$.n_components - 1] = $2->get_val();
839 delete $2;
840 }
841 ;
842
843 ObjIdComponent:
844 NumberForm { $$ = $1; }
845 | NameAndNumberForm { $$ = $1; }
846 ;
847
848 NumberForm:
849 Number { $$ = $1; }
850 ;
851
852 NameAndNumberForm:
853 Identifier '(' Number ')'
854 {
855 Free($1);
856 $$ = $3;
857 }
858 ;
859
860 BitstringValue:
861 Bstring
862 {
863 $$ = $1;
864 }
865 | BitstringValue ConcatOp Bstring
866 {
867 $$.n_bits = $1.n_bits + $3.n_bits;
868 int n_bytes_1 = ($1.n_bits+7)/8;
869 int n_bytes_3 = ($3.n_bits+7)/8;
870 int n_bytes = ($$.n_bits+7)/8;
871 $$.bits_ptr = (unsigned char *)Realloc($1.bits_ptr, n_bytes);
872 int n_rem_1 = $1.n_bits % 8; // remainder bits
873 if (n_rem_1!=0) {
874 for (int i=n_bytes_1; i<n_bytes; i++) {
875 unsigned char S3_byte = $3.bits_ptr[i-n_bytes_1];
876 $$.bits_ptr[i-1] |= S3_byte << n_rem_1;
877 $$.bits_ptr[i] = S3_byte >> (8-n_rem_1);
878 }
879 if (n_bytes_1+n_bytes_3>n_bytes)
880 $$.bits_ptr[n_bytes-1] |= $3.bits_ptr[n_bytes_3-1] << n_rem_1;
881 } else {
882 memcpy($$.bits_ptr + n_bytes_1, $3.bits_ptr, n_bytes_3);
883 }
884 Free($3.bits_ptr);
885 }
886 ;
887
888 HexstringValue:
889 Hstring
890 {
891 $$ = $1;
892 }
893 | HexstringValue ConcatOp Hstring
894 {
895 $$.n_nibbles = $1.n_nibbles + $3.n_nibbles;
896 int n_bytes = ($$.n_nibbles + 1) / 2;
897 $$.nibbles_ptr = (unsigned char *)Realloc($1.nibbles_ptr, n_bytes);
898 int n_bytes_1 = ($1.n_nibbles + 1) / 2;
899 int n_bytes_3 = ($3.n_nibbles + 1) / 2;
900 if ($1.n_nibbles % 2) {
901 for (int i=n_bytes_1; i<n_bytes; i++) {
902 unsigned char S3_byte = $3.nibbles_ptr[i - n_bytes_1];
903 $$.nibbles_ptr[i - 1] |= S3_byte << 4;
904 $$.nibbles_ptr[i] = S3_byte >> 4;
905 }
906 if ($3.n_nibbles % 2)
907 $$.nibbles_ptr[n_bytes - 1] |= $3.nibbles_ptr[n_bytes_3 - 1] << 4;
908 } else {
909 memcpy($$.nibbles_ptr + n_bytes_1, $3.nibbles_ptr, n_bytes_3);
910 }
911 Free($3.nibbles_ptr);
912 }
913 ;
914
915 OctetstringValue:
916 Ostring
917 {
918 $$ = $1;
919 }
920 | OctetstringValue ConcatOp Ostring
921 {
922 $$.n_octets = $1.n_octets + $3.n_octets;
923 $$.octets_ptr = (unsigned char *)Realloc($1.octets_ptr, $$.n_octets);
924 memcpy($$.octets_ptr + $1.n_octets, $3.octets_ptr, $3.n_octets);
925 Free($3.octets_ptr);
926 }
927 ;
928
929 UniversalCharstringValue:
930 Cstring seqUniversalCharstringFragment
931 {
932 $$.n_uchars = $1.n_chars + $2.n_uchars;
933 $$.uchars_ptr = (universal_char*)
934 Malloc($$.n_uchars * sizeof(universal_char));
935 for (int i = 0; i < $1.n_chars; i++) {
936 $$.uchars_ptr[i].uc_group = 0;
937 $$.uchars_ptr[i].uc_plane = 0;
938 $$.uchars_ptr[i].uc_row = 0;
939 $$.uchars_ptr[i].uc_cell = $1.chars_ptr[i];
940 }
941 memcpy($$.uchars_ptr + $1.n_chars, $2.uchars_ptr,
942 $2.n_uchars * sizeof(universal_char));
943 $$.n_quads = $2.n_quads;
944 $$.quad_positions = (int*)Malloc($$.n_quads * sizeof(int));
945 for (int i = 0; i < $$.n_quads; i++) {
946 $$.quad_positions[i] = $2.quad_positions[i] + $1.n_chars;
947 }
948 Free($1.chars_ptr);
949 Free($2.uchars_ptr);
950 Free($2.quad_positions);
951 }
952 | Quadruple
953 {
954 $$.n_uchars = 1;
955 $$.uchars_ptr = (universal_char*)Malloc(sizeof(universal_char));
956 $$.uchars_ptr[0] = $1;
957 $$.n_quads = 1;
958 $$.quad_positions = (int*)Malloc(sizeof(int));
959 $$.quad_positions[0] = 0;
960 }
961 | Quadruple seqUniversalCharstringFragment
962 {
963 $$.n_uchars = $2.n_uchars + 1;
964 $$.uchars_ptr = (universal_char*)
965 Malloc($$.n_uchars * sizeof(universal_char));
966 $$.uchars_ptr[0] = $1;
967 memcpy($$.uchars_ptr + 1, $2.uchars_ptr,
968 $2.n_uchars * sizeof(universal_char));
969 $$.n_quads = $2.n_quads + 1;
970 $$.quad_positions = (int*)Malloc($$.n_quads * sizeof(int));
971 $$.quad_positions[0] = 0;
972 for (int i = 0; i < $2.n_quads; i++) {
973 $$.quad_positions[i + 1] = $2.quad_positions[i] + 1;
974 }
975 Free($2.uchars_ptr);
976 Free($2.quad_positions);
977 }
978 ;
979
980 seqUniversalCharstringFragment:
981 ConcatOp UniversalCharstringFragment
982 {
983 $$ = $2;
984 }
985 | seqUniversalCharstringFragment ConcatOp UniversalCharstringFragment
986 {
987 $$.n_uchars = $1.n_uchars + $3.n_uchars;
988 $$.uchars_ptr = (universal_char*)
989 Realloc($1.uchars_ptr, $$.n_uchars * sizeof(universal_char));
990 memcpy($$.uchars_ptr + $1.n_uchars, $3.uchars_ptr,
991 $3.n_uchars * sizeof(universal_char));
992 $$.n_quads = $1.n_quads + $3.n_quads;
993 $$.quad_positions = (int*)Realloc($1.quad_positions, $$.n_quads * sizeof(int));
994 for (int i = 0; i < $3.n_quads; i++) {
995 $$.quad_positions[$1.n_quads + i] = $3.quad_positions[i] + $1.n_uchars;
996 }
997 Free($3.uchars_ptr);
998 Free($3.quad_positions);
999 }
1000 ;
1001
1002 UniversalCharstringFragment:
1003 Cstring
1004 {
1005 $$.n_uchars = $1.n_chars;
1006 $$.uchars_ptr = (universal_char*)
1007 Malloc($$.n_uchars * sizeof(universal_char));
1008 for (int i = 0; i < $1.n_chars; i++) {
1009 $$.uchars_ptr[i].uc_group = 0;
1010 $$.uchars_ptr[i].uc_plane = 0;
1011 $$.uchars_ptr[i].uc_row = 0;
1012 $$.uchars_ptr[i].uc_cell = $1.chars_ptr[i];
1013 }
1014 $$.n_quads = 0;
1015 $$.quad_positions = 0;
1016 Free($1.chars_ptr);
1017 }
1018 | Quadruple
1019 {
1020 $$.n_uchars = 1;
1021 $$.uchars_ptr = (universal_char*)Malloc(sizeof(universal_char));
1022 $$.uchars_ptr[0] = $1;
1023 $$.n_quads = 1;
1024 $$.quad_positions = (int*)Malloc(sizeof(int));
1025 $$.quad_positions[0] = 0;
1026 }
1027 ;
1028
1029 Quadruple:
1030 CharKeyword '(' IntegerValue ',' IntegerValue ',' IntegerValue ','
1031 IntegerValue ')'
1032 {
1033 if (*$3 < 0 || *$3 > 127) {
1034 char *s = $3->as_string();
1035 config_process_error_f("The first number of quadruple (group) must be "
1036 "within the range 0 .. 127 instead of %s.", s);
1037 Free(s);
1038 $$.uc_group = *$3 < 0 ? 0 : 127;
1039 } else {
1040 $$.uc_group = $3->get_val();
1041 }
1042 if (*$5 < 0 || *$5 > 255) {
1043 char *s = $5->as_string();
1044 config_process_error_f("The second number of quadruple (plane) must be "
1045 "within the range 0 .. 255 instead of %s.", s);
1046 Free(s);
1047 $$.uc_plane = *$5 < 0 ? 0 : 255;
1048 } else {
1049 $$.uc_plane = $5->get_val();
1050 }
1051 if (*$7 < 0 || *$7 > 255) {
1052 char *s = $7->as_string();
1053 config_process_error_f("The third number of quadruple (row) must be "
1054 "within the range 0 .. 255 instead of %s.", s);
1055 Free(s);
1056 $$.uc_row = *$7 < 0 ? 0 : 255;
1057 } else {
1058 $$.uc_row = $7->get_val();
1059 }
1060 if (*$9 < 0 || *$9 > 255) {
1061 char *s = $9->as_string();
1062 config_process_error_f("The fourth number of quadruple (cell) must be "
1063 "within the range 0 .. 255 instead of %s.", s);
1064 Free(s);
1065 $$.uc_cell = *$9 < 0 ? 0 : 255;
1066 } else {
1067 $$.uc_cell = $9->get_val();
1068 }
1069 delete $3;
1070 delete $5;
1071 delete $7;
1072 delete $9;
1073 }
1074 ;
1075
1076 ConcatOp:
1077 '&'
1078 ;
1079
1080 StringValue:
1081 Cstring
1082 {
1083 $$ = mcopystr($1.chars_ptr);
1084 Free($1.chars_ptr);
1085 }
1086 | StringValue ConcatOp Cstring
1087 {
1088 $$ = mputstr($1, $3.chars_ptr);
1089 Free($3.chars_ptr);
1090 }
1091 ;
1092
1093 EnumeratedValue:
1094 Identifier { $$ = $1; }
1095 | ASN1LowerIdentifier { $$ = $1; }
1096 ;
1097
1098 CompoundValue:
1099 '{' '}'
1100 {
1101 $$ = new Module_Param_Value_List();
1102 }
1103 | '{' FieldValueList '}'
1104 {
1105 $$ = $2;
1106 }
1107 | '{' ArrayItemList '}'
1108 {
1109 $$ = $2;
1110 }
1111 | '{' IndexItemList '}'
1112 {
1113 $$ = $2;
1114 }
1115 | '(' ParameterValue ',' TemplateItemList ')' /* at least 2 elements to avoid shift/reduce conflicts with IntegerValue and FloatValue rules */
1116 {
1117 $$ = new Module_Param_List_Template();
1118 $2->set_id(new Module_Param_Index($$->get_size(),false));
1119 $$->add_elem($2);
1120 $$->add_list_with_implicit_ids($4);
1121 delete $4;
1122 }
1123 | ComplementKeyword '(' TemplateItemList ')'
1124 {
1125 $$ = new Module_Param_ComplementList_Template();
1126 $$->add_list_with_implicit_ids($3);
1127 delete $3;
1128 }
1129 | SupersetKeyword '(' TemplateItemList ')'
1130 {
1131 $$ = new Module_Param_Superset_Template();
1132 $$->add_list_with_implicit_ids($3);
1133 delete $3;
1134 }
1135 | SubsetKeyword '(' TemplateItemList ')'
1136 {
1137 $$ = new Module_Param_Subset_Template();
1138 $$->add_list_with_implicit_ids($3);
1139 delete $3;
1140 }
1141 ;
1142
1143 ParameterValueOrNotUsedSymbol:
1144 ParameterValue
1145 {
1146 $$ = $1;
1147 }
1148 | '-'
1149 {
1150 $$ = new Module_Param_NotUsed();
1151 }
1152 ;
1153
1154 TemplateItemList:
1155 ParameterValue
1156 {
1157 $$ = new Vector<Module_Param*>();
1158 $$->push_back($1);
1159 }
1160 | TemplateItemList ',' ParameterValue
1161 {
1162 $$ = $1;
1163 $$->push_back($3);
1164 }
1165 ;
1166
1167 FieldValueList:
1168 FieldValue
1169 {
1170 $$ = new Module_Param_Assignment_List();
1171 $$->add_elem($1);
1172 }
1173 | FieldValueList ',' FieldValue
1174 {
1175 $$ = $1;
1176 $$->add_elem($3);
1177 }
1178 ;
1179
1180 FieldValue:
1181 FieldName AssignmentChar ParameterValueOrNotUsedSymbol
1182 {
1183 $$ = $3;
1184 $$->set_id(new Module_Param_FieldName($1));
1185 }
1186 ;
1187
1188 FieldName:
1189 Identifier
1190 {
1191 $$ = $1;
1192 }
1193 | ASN1LowerIdentifier
1194 {
1195 $$ = $1;
1196 }
1197 ;
1198
1199 ArrayItemList:
1200 ArrayItem
1201 {
1202 $$ = new Module_Param_Value_List();
1203 $1->set_id(new Module_Param_Index($$->get_size(),false));
1204 $$->add_elem($1);
1205 }
1206 | ArrayItemList ',' ArrayItem
1207 {
1208 $$ = $1;
1209 $3->set_id(new Module_Param_Index($$->get_size(),false));
1210 $$->add_elem($3);
1211 }
1212 ;
1213
1214 ArrayItem:
1215 ParameterValueOrNotUsedSymbol
1216 {
1217 $$ = $1;
1218 }
1219 | PermutationKeyword '(' TemplateItemList ')'
1220 {
1221 $$ = new Module_Param_Permutation_Template();
1222 $$->add_list_with_implicit_ids($3);
1223 delete $3;
1224 }
1225 ;
1226
1227 IndexItemList:
1228 IndexItem
1229 {
1230 $$ = new Module_Param_Indexed_List();
1231 $$->add_elem($1);
1232 }
1233 | IndexItemList ',' IndexItem
1234 {
1235 $$ = $1;
1236 $$->add_elem($3);
1237 }
1238 ;
1239
1240 IndexItem:
1241 IndexItemIndex AssignmentChar ParameterValue
1242 {
1243 $$ = $3;
1244 $$->set_id(new Module_Param_Index((size_t)$1,true));
1245 }
1246 ;
1247
1248 IndexItemIndex:
1249 '[' IntegerValue ']'
1250 {
1251 if (!$2->is_native()) {
1252 config_process_error("bignum index."); // todo
1253 }
1254 if ($2->is_negative()) {
1255 config_process_error("negative index."); // todo
1256 }
1257 $$ = $2->get_val();
1258 delete $2;
1259 }
1260 ;
1261
1262 /*************** [LOGGING] section *********************************/
1263
1264 LoggingSection:
1265 LoggingKeyword LoggingParamList
1266 ;
1267
1268 LoggingParamList:
1269 /* empty */
1270 | LoggingParamList LoggingParamLines optSemiColon
1271 {
1272 // Centralized duplication handling for `[LOGGING]'.
1273 if ($2.logparam.log_param_selection != LP_UNKNOWN && TTCN_Logger::add_parameter($2)) {
1274 switch ($2.logparam.log_param_selection) {
1275 case LP_FILEMASK:
1276 check_duplicate_option("LOGGING", "FileMask", file_mask_set);
1277 break;
1278 case LP_CONSOLEMASK:
1279 check_duplicate_option("LOGGING", "ConsoleMask", console_mask_set);
1280 break;
1281 case LP_LOGFILESIZE:
1282 check_duplicate_option("LOGGING", "LogFileSize", log_file_size_set);
1283 break;
1284 case LP_LOGFILENUMBER:
1285 check_duplicate_option("LOGGING", "LogFileNumber", log_file_number_set);
1286 break;
1287 case LP_DISKFULLACTION:
1288 check_duplicate_option("LOGGING", "DiskFullAction", log_disk_full_action_set);
1289 break;
1290 case LP_LOGFILE:
1291 check_duplicate_option("LOGGING", "LogFile", file_name_set);
1292 break;
1293 case LP_TIMESTAMPFORMAT:
1294 check_duplicate_option("LOGGING", "TimeStampFormat", timestamp_format_set);
1295 break;
1296 case LP_SOURCEINFOFORMAT:
1297 check_duplicate_option("LOGGING", "SourceInfoFormat", source_info_format_set);
1298 break;
1299 case LP_APPENDFILE:
1300 check_duplicate_option("LOGGING", "AppendFile", append_file_set);
1301 break;
1302 case LP_LOGEVENTTYPES:
1303 check_duplicate_option("LOGGING", "LogEventTypes", log_event_types_set);
1304 break;
1305 case LP_LOGENTITYNAME:
1306 check_duplicate_option("LOGGING", "LogEntityName", log_entity_name_set);
1307 break;
1308 case LP_MATCHINGHINTS:
1309 check_duplicate_option("LOGGING", "MatchingVerbosity", matching_verbosity_set);
1310 break;
1311 case LP_PLUGIN_SPECIFIC:
1312 // It would be an overkill to check for the infinite number of custom parameters...
1313 check_duplicate_option("LOGGING", "PluginSpecific", plugin_specific_set);
1314 break;
1315 default:
1316 break;
1317 }
1318 }
1319 }
1320 ;
1321
1322 LoggingParamLines:
1323 LoggingParam
1324 {
1325 $$.component.id_selector = COMPONENT_ID_ALL;
1326 $$.component.id_name = NULL;
1327 $$.plugin_id = NULL;
1328 $$.logparam = $1;
1329 }
1330 | ComponentId '.' LoggingParam
1331 {
1332 $$.component = $1;
1333 $$.plugin_id = NULL;
1334 $$.logparam = $3;
1335 }
1336 | ComponentId '.' LoggerPluginId '.' LoggingParam
1337 {
1338 $$.component = $1;
1339 $$.plugin_id = $3;
1340 $$.logparam = $5;
1341 }
1342 | LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
1343 {
1344 check_duplicate_option("LOGGING", "LoggerPlugins", logger_plugins_set);
1345 component_id_t comp;
1346 comp.id_selector = COMPONENT_ID_ALL;
1347 comp.id_name = NULL;
1348 logging_plugin_t *plugin = $4;
1349 while (plugin != NULL) {
1350 // `identifier' and `filename' are reused. Various checks and
1351 // validations must be done in the logger itself (e.g. looking for
1352 // duplicate options).
1353 TTCN_Logger::register_plugin(comp, plugin->identifier, plugin->filename);
1354 logging_plugin_t *tmp = plugin;
1355 plugin = tmp->next;
1356 Free(tmp);
1357 }
1358 $$.logparam.log_param_selection = LP_UNKNOWN;
1359 }
1360 | ComponentId '.' LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
1361 {
1362 check_duplicate_option("LOGGING", "LoggerPlugins", logger_plugins_set);
1363 logging_plugin_t *plugin = $6;
1364 while (plugin != NULL) {
1365 TTCN_Logger::register_plugin($1, plugin->identifier, plugin->filename);
1366 logging_plugin_t *tmp = plugin;
1367 plugin = tmp->next;
1368 Free(tmp);
1369 }
1370 // Component names shall be duplicated in `register_plugin()'.
1371 if ($1.id_selector == COMPONENT_ID_NAME)
1372 Free($1.id_name);
1373 $$.logparam.log_param_selection = LP_UNKNOWN;
1374 }
1375 ;
1376
1377 LoggerPluginList:
1378 LoggerPlugin
1379 {
1380 $$ = $1;
1381 }
1382 | LoggerPluginList ',' LoggerPlugin
1383 {
1384 $$ = $3;
1385 $$->next = $1;
1386 }
1387 ;
1388
1389 LoggerPlugin:
1390 Identifier
1391 {
1392 $$ = (logging_plugin_t *)Malloc(sizeof(logging_plugin_t));
1393 $$->identifier = $1;
1394 $$->filename = NULL;
1395 $$->next = NULL;
1396 }
1397 | Identifier AssignmentChar StringValue
1398 {
1399 $$ = (logging_plugin_t *)Malloc(sizeof(logging_plugin_t));
1400 $$->identifier = $1;
1401 $$->filename = $3;
1402 $$->next = NULL;
1403 }
1404 ;
1405
1406 LoggerPluginId:
1407 '*' { $$ = mcopystr("*"); }
1408 | Identifier { $$ = $1; }
1409 ;
1410
1411 LoggingParam:
1412 FileMask AssignmentChar LoggingBitmask
1413 {
1414 $$.log_param_selection = LP_FILEMASK;
1415 $$.logoptions_val = $3;
1416 }
1417 | ConsoleMask AssignmentChar LoggingBitmask
1418 {
1419 $$.log_param_selection = LP_CONSOLEMASK;
1420 $$.logoptions_val = $3;
1421 }
1422 | LogFileSize AssignmentChar Number
1423 {
1424 $$.log_param_selection = LP_LOGFILESIZE;
1425 $$.int_val = (int)$3->get_val();
1426 delete $3;
1427 }
1428 | EmergencyLogging AssignmentChar Number
1429 {
1430 $$.log_param_selection = LP_EMERGENCY;
1431 $$.int_val = (int)$3->get_val();
1432 delete $3;
1433 }
1434 | EmergencyLoggingBehaviour AssignmentChar EmergencyLoggingBehaviourValue
1435 {
1436 $$.log_param_selection = LP_EMERGENCYBEHAVIOR;
1437 $$.emergency_logging_behaviour_value = $3;
1438 }
1439 | EmergencyLoggingMask AssignmentChar LoggingBitmask
1440 {
1441 $$.log_param_selection = LP_EMERGENCYMASK;
1442 $$.logoptions_val = $3;
1443 }
1444 | LogFileNumber AssignmentChar Number
1445 {
1446 $$.log_param_selection = LP_LOGFILENUMBER;
1447 $$.int_val = (int)$3->get_val();
1448 delete $3;
1449 }
1450 | DiskFullAction AssignmentChar DiskFullActionValue
1451 {
1452 $$.log_param_selection = LP_DISKFULLACTION;
1453 $$.disk_full_action_value = $3;
1454 }
1455 | LogFile AssignmentChar LogFileName
1456 {
1457 $$.log_param_selection = LP_LOGFILE;
1458 $$.str_val = $3;
1459 }
1460 | TimestampFormat AssignmentChar TimestampValue
1461 {
1462 $$.log_param_selection = LP_TIMESTAMPFORMAT;
1463 $$.timestamp_value = $3;
1464 }
1465 | ConsoleTimestampFormat AssignmentChar TimestampValue
1466 {
1467 $$.log_param_selection = LP_UNKNOWN;
1468 }
1469 | SourceInfoFormat AssignmentChar SourceInfoSetting
1470 {
1471 $$.log_param_selection = LP_SOURCEINFOFORMAT;
1472 $$.source_info_value = $3;
1473 }
1474 | AppendFile AssignmentChar YesNoOrBoolean
1475 {
1476 $$.log_param_selection = LP_APPENDFILE;
1477 $$.bool_val = $3;
1478 }
1479 | LogEventTypes AssignmentChar LogEventTypesValue
1480 {
1481 $$.log_param_selection = LP_LOGEVENTTYPES;
1482 $$.log_event_types_value = $3;
1483 }
1484 | LogEntityName AssignmentChar YesNoOrBoolean
1485 {
1486 $$.log_param_selection = LP_LOGENTITYNAME;
1487 $$.bool_val = $3;
1488 }
1489 | MatchingHints AssignmentChar VerbosityValue
1490 {
1491 $$.log_param_selection = LP_MATCHINGHINTS;
1492 $$.matching_verbosity_value = $3;
1493 }
1494 | Identifier AssignmentChar StringValue
1495 {
1496 $$.log_param_selection = LP_PLUGIN_SPECIFIC;
1497 $$.param_name = $1;
1498 $$.str_val = $3;
1499 }
1500 ;
1501
1502 VerbosityValue:
1503 Compact { $$ = TTCN_Logger::VERBOSITY_COMPACT; }
1504 | Detailed { $$ = TTCN_Logger::VERBOSITY_FULL; }
1505 ;
1506
1507 DiskFullActionValue:
1508 Error { $$.type = TTCN_Logger::DISKFULL_ERROR; }
1509 | Stop { $$.type = TTCN_Logger::DISKFULL_STOP; }
1510 | Retry
1511 {
1512 $$.type = TTCN_Logger::DISKFULL_RETRY;
1513 $$.retry_interval = 30; /* default retry interval */
1514 }
1515 | Retry '(' Number ')'
1516 {
1517 $$.type = TTCN_Logger::DISKFULL_RETRY;
1518 $$.retry_interval = (size_t)$3->get_val();
1519 delete $3;
1520 }
1521 | Delete { $$.type = TTCN_Logger::DISKFULL_DELETE; }
1522 ;
1523
1524 LogFileName:
1525 StringValue { $$ = $1; }
1526 ;
1527
1528 LoggingBitOrCollection:
1529 LoggingBit
1530 {
1531 $$.clear();
1532 $$.add_sev($1);
1533 }
1534 | LoggingBitCollection
1535 {
1536 $$.clear();
1537 switch($1)
1538 {
1539 case TTCN_Logger::ACTION_UNQUALIFIED:
1540 $$.add_sev(TTCN_Logger::ACTION_UNQUALIFIED);
1541 break;
1542 case TTCN_Logger::DEFAULTOP_UNQUALIFIED:
1543 $$.add_sev(TTCN_Logger::DEFAULTOP_ACTIVATE);
1544 $$.add_sev(TTCN_Logger::DEFAULTOP_DEACTIVATE);
1545 $$.add_sev(TTCN_Logger::DEFAULTOP_EXIT);
1546 $$.add_sev(TTCN_Logger::DEFAULTOP_UNQUALIFIED);
1547 break;
1548 case TTCN_Logger::ERROR_UNQUALIFIED:
1549 $$.add_sev(TTCN_Logger::ERROR_UNQUALIFIED);
1550 break;
1551 case TTCN_Logger::EXECUTOR_UNQUALIFIED:
1552 $$.add_sev(TTCN_Logger::EXECUTOR_RUNTIME);
1553 $$.add_sev(TTCN_Logger::EXECUTOR_CONFIGDATA);
1554 $$.add_sev(TTCN_Logger::EXECUTOR_EXTCOMMAND);
1555 $$.add_sev(TTCN_Logger::EXECUTOR_COMPONENT);
1556 $$.add_sev(TTCN_Logger::EXECUTOR_LOGOPTIONS);
1557 $$.add_sev(TTCN_Logger::EXECUTOR_UNQUALIFIED);
1558 break;
1559 case TTCN_Logger::FUNCTION_UNQUALIFIED:
1560 $$.add_sev(TTCN_Logger::FUNCTION_RND);
1561 $$.add_sev(TTCN_Logger::FUNCTION_UNQUALIFIED);
1562 break;
1563 case TTCN_Logger::PARALLEL_UNQUALIFIED:
1564 $$.add_sev(TTCN_Logger::PARALLEL_PTC);
1565 $$.add_sev(TTCN_Logger::PARALLEL_PORTCONN);
1566 $$.add_sev(TTCN_Logger::PARALLEL_PORTMAP);
1567 $$.add_sev(TTCN_Logger::PARALLEL_UNQUALIFIED);
1568 break;
1569 case TTCN_Logger::PORTEVENT_UNQUALIFIED:
1570 $$.add_sev(TTCN_Logger::PORTEVENT_PQUEUE);
1571 $$.add_sev(TTCN_Logger::PORTEVENT_MQUEUE);
1572 $$.add_sev(TTCN_Logger::PORTEVENT_STATE);
1573 $$.add_sev(TTCN_Logger::PORTEVENT_PMIN);
1574 $$.add_sev(TTCN_Logger::PORTEVENT_PMOUT);
1575 $$.add_sev(TTCN_Logger::PORTEVENT_PCIN);
1576 $$.add_sev(TTCN_Logger::PORTEVENT_PCOUT);
1577 $$.add_sev(TTCN_Logger::PORTEVENT_MMRECV);
1578 $$.add_sev(TTCN_Logger::PORTEVENT_MMSEND);
1579 $$.add_sev(TTCN_Logger::PORTEVENT_MCRECV);
1580 $$.add_sev(TTCN_Logger::PORTEVENT_MCSEND);
1581 $$.add_sev(TTCN_Logger::PORTEVENT_DUALRECV);
1582 $$.add_sev(TTCN_Logger::PORTEVENT_DUALSEND);
1583 $$.add_sev(TTCN_Logger::PORTEVENT_UNQUALIFIED);
1584 break;
1585 case TTCN_Logger::TESTCASE_UNQUALIFIED:
1586 $$.add_sev(TTCN_Logger::TESTCASE_START);
1587 $$.add_sev(TTCN_Logger::TESTCASE_FINISH);
1588 $$.add_sev(TTCN_Logger::TESTCASE_UNQUALIFIED);
1589 break;
1590 case TTCN_Logger::TIMEROP_UNQUALIFIED:
1591 $$.add_sev(TTCN_Logger::TIMEROP_READ);
1592 $$.add_sev(TTCN_Logger::TIMEROP_START);
1593 $$.add_sev(TTCN_Logger::TIMEROP_GUARD);
1594 $$.add_sev(TTCN_Logger::TIMEROP_STOP);
1595 $$.add_sev(TTCN_Logger::TIMEROP_TIMEOUT);
1596 $$.add_sev(TTCN_Logger::TIMEROP_UNQUALIFIED);
1597 break;
1598 case TTCN_Logger::USER_UNQUALIFIED:
1599 $$.add_sev(TTCN_Logger::USER_UNQUALIFIED);
1600 break;
1601 case TTCN_Logger::STATISTICS_UNQUALIFIED:
1602 $$.add_sev(TTCN_Logger::STATISTICS_VERDICT);
1603 $$.add_sev(TTCN_Logger::STATISTICS_UNQUALIFIED);
1604 break;
1605 case TTCN_Logger::VERDICTOP_UNQUALIFIED:
1606 $$.add_sev(TTCN_Logger::VERDICTOP_GETVERDICT);
1607 $$.add_sev(TTCN_Logger::VERDICTOP_SETVERDICT);
1608 $$.add_sev(TTCN_Logger::VERDICTOP_FINAL);
1609 $$.add_sev(TTCN_Logger::VERDICTOP_UNQUALIFIED);
1610 break;
1611 case TTCN_Logger::WARNING_UNQUALIFIED:
1612 $$.add_sev(TTCN_Logger::WARNING_UNQUALIFIED);
1613 break;
1614 case TTCN_Logger::MATCHING_UNQUALIFIED:
1615 $$.add_sev(TTCN_Logger::MATCHING_DONE);
1616 $$.add_sev(TTCN_Logger::MATCHING_TIMEOUT);
1617 $$.add_sev(TTCN_Logger::MATCHING_PCSUCCESS);
1618 $$.add_sev(TTCN_Logger::MATCHING_PCUNSUCC);
1619 $$.add_sev(TTCN_Logger::MATCHING_PMSUCCESS);
1620 $$.add_sev(TTCN_Logger::MATCHING_PMUNSUCC);
1621 $$.add_sev(TTCN_Logger::MATCHING_MCSUCCESS);
1622 $$.add_sev(TTCN_Logger::MATCHING_MCUNSUCC);
1623 $$.add_sev(TTCN_Logger::MATCHING_MMSUCCESS);
1624 $$.add_sev(TTCN_Logger::MATCHING_MMUNSUCC);
1625 $$.add_sev(TTCN_Logger::MATCHING_PROBLEM);
1626 $$.add_sev(TTCN_Logger::MATCHING_UNQUALIFIED);
1627 break;
1628 case TTCN_Logger::DEBUG_UNQUALIFIED:
1629 $$.add_sev(TTCN_Logger::DEBUG_ENCDEC);
1630 $$.add_sev(TTCN_Logger::DEBUG_TESTPORT);
1631 $$.add_sev(TTCN_Logger::DEBUG_UNQUALIFIED);
1632 break;
1633 case TTCN_Logger::LOG_ALL_IMPORTANT:
1634 $$ = Logging_Bits::log_all;
1635 break;
1636 default:
1637 /* The lexer sent something the parser doesn't understand!
1638 Parser needs to be updated.
1639 */
1640 TTCN_Logger::log_str(TTCN_Logger::ERROR_UNQUALIFIED,
1641 "Internal error: unknown logbit from lexer.");
1642 break;
1643 } // switch
1644 }
1645 ;
1646
1647 LoggingBitmask:
1648 LoggingBitOrCollection
1649 {
1650 $$ = $1;
1651 }
1652 | LoggingBitmask '|' LoggingBitOrCollection
1653 {
1654 $$ = $1;
1655 $$.merge($3);
1656 }
1657 ;
1658
1659 SourceInfoSetting:
1660 SourceInfoValue { $$ = $1; }
1661 | YesNoOrBoolean
1662 {
1663 $$ = $1 ? TTCN_Logger::SINFO_SINGLE : TTCN_Logger::SINFO_NONE;
1664 }
1665 ;
1666
1667 YesNoOrBoolean:
1668 YesNo { $$ = $1; }
1669 | BooleanValue { $$ = $1; }
1670 ;
1671
1672 LogEventTypesValue:
1673 YesNoOrBoolean { $$ = $1 ? TTCN_Logger::LOGEVENTTYPES_YES :
1674 TTCN_Logger::LOGEVENTTYPES_NO; }
1675 | SubCategories { $$ = TTCN_Logger::LOGEVENTTYPES_SUBCATEGORIES; }
1676 | Detailed { $$ = TTCN_Logger::LOGEVENTTYPES_SUBCATEGORIES; }
1677 ;
1678
1679 /*********************** [PROFILER] ********************************/
1680
1681 ProfilerSection:
1682 ProfilerKeyword ProfilerSettings
1683 ;
1684
1685 ProfilerSettings:
1686 /* empty */
1687 | ProfilerSettings ProfilerSetting optSemiColon
1688 ;
1689
1690 ProfilerSetting:
1691 DisableProfilerSetting
1692 | DisableCoverageSetting
1693 | DatabaseFileSetting
1694 | AggregateDataSetting
1695 | StatisticsFileSetting
1696 | DisableStatisticsSetting
1697 | StatisticsFilterSetting
1698 | StartAutomaticallySetting
1699 | NetLineTimesSetting
1700 | NetFunctionTimesSetting
1701 ;
1702
1703 DisableProfilerSetting:
1704 DisableProfilerKeyword AssignmentChar BooleanValue {
1705 ttcn3_prof.set_disable_profiler($3);
1706 }
1707 ;
1708
1709 DisableCoverageSetting:
1710 DisableCoverageKeyword AssignmentChar BooleanValue {
1711 ttcn3_prof.set_disable_coverage($3);
1712 }
1713 ;
1714
1715 DatabaseFileSetting:
1716 DatabaseFileKeyword AssignmentChar StringValue {
1717 ttcn3_prof.set_database_filename($3);
1718 }
1719 ;
1720
1721 AggregateDataSetting:
1722 AggregateDataKeyword AssignmentChar BooleanValue {
1723 ttcn3_prof.set_aggregate_data($3);
1724 }
1725 ;
1726
1727 StatisticsFileSetting:
1728 StatisticsFileKeyword AssignmentChar StringValue {
1729 ttcn3_prof.set_stats_filename($3);
1730 }
1731 ;
1732
1733 DisableStatisticsSetting:
1734 DisableStatisticsKeyword AssignmentChar BooleanValue {
1735 ttcn3_prof.set_disable_stats($3);
1736 }
1737 ;
1738
1739 StatisticsFilterSetting:
1740 StatisticsFilterKeyword AssignmentChar ProfilerStatsFlags {
1741 ttcn3_prof.reset_stats_flags();
1742 ttcn3_prof.add_stats_flags($3);
1743 }
1744 | StatisticsFilterKeyword ConcatChar ProfilerStatsFlags {
1745 ttcn3_prof.add_stats_flags($3);
1746 }
1747 ;
1748
1749 ProfilerStatsFlags:
1750 ProfilerStatsFlag { $$ = $1; }
1751 | ProfilerStatsFlag '&' ProfilerStatsFlags { $$ = $1 | $3; }
1752 | ProfilerStatsFlag '|' ProfilerStatsFlags { $$ = $1 | $3; }
1753 ;
1754
1755 StartAutomaticallySetting:
1756 StartAutomaticallyKeyword AssignmentChar BooleanValue {
1757 if ($3) {
1758 ttcn3_prof.start();
1759 }
1760 else {
1761 ttcn3_prof.stop();
1762 }
1763 }
1764 ;
1765
1766 NetLineTimesSetting:
1767 NetLineTimesKeyword AssignmentChar BooleanValue {
1768 TTCN3_Stack_Depth::set_net_line_times($3);
1769 }
1770 ;
1771
1772 NetFunctionTimesSetting:
1773 NetFunctionTimesKeyword AssignmentChar BooleanValue {
1774 TTCN3_Stack_Depth::set_net_func_times($3);
1775 }
1776 ;
1777
1778
1779 /**************** [TESTPORT_PARAMETERS] ****************************/
1780
1781 TestportParametersSection:
1782 TestportParametersKeyword TestportParameterList
1783 ;
1784
1785 TestportParameterList:
1786 /* empty */
1787 | TestportParameterList TestportParameter optSemiColon
1788 ;
1789
1790 TestportParameter:
1791 ComponentId '.' TestportName '.' TestportParameterName AssignmentChar
1792 TestportParameterValue
1793 {
1794 PORT::add_parameter($1, $3, $5, $7);
1795 if ($1.id_selector == COMPONENT_ID_NAME) Free($1.id_name);
1796 Free($3);
1797 Free($5);
1798 Free($7);
1799 }
1800 ;
1801
1802 ComponentId:
1803 Identifier
1804 {
1805 $$.id_selector = COMPONENT_ID_NAME;
1806 $$.id_name = $1;
1807 }
1808 | Cstring
1809 {
1810 $$.id_selector = COMPONENT_ID_NAME;
1811 $$.id_name = $1.chars_ptr;
1812 }
1813 | Number
1814 {
1815 $$.id_selector = COMPONENT_ID_COMPREF;
1816 $$.id_compref = (component)$1->get_val();
1817 delete $1;
1818 }
1819 | MTCKeyword
1820 {
1821 $$.id_selector = COMPONENT_ID_COMPREF;
1822 $$.id_compref = MTC_COMPREF;
1823 }
1824 | '*'
1825 {
1826 $$.id_selector = COMPONENT_ID_ALL;
1827 $$.id_name = NULL;
1828 }
1829 | SystemKeyword
1830 {
1831 $$.id_selector = COMPONENT_ID_SYSTEM;
1832 $$.id_name = NULL;
1833 }
1834 ;
1835
1836 TestportName:
1837 Identifier { $$ = $1; }
1838 | Identifier ArrayRef
1839 {
1840 $$ = mputstr($1, $2);
1841 Free($2);
1842 }
1843 | '*' { $$ = NULL; }
1844 ;
1845
1846 ArrayRef:
1847 '[' IntegerValue ']'
1848 {
1849 char *s = $2->as_string();
1850 $$ = memptystr();
1851 $$ = mputc ($$, '[');
1852 $$ = mputstr($$, s);
1853 $$ = mputc ($$, ']');
1854 Free(s);
1855 delete $2;
1856 }
1857 | ArrayRef '[' IntegerValue ']'
1858 {
1859 char *s = $3->as_string();
1860 $$ = mputc ($1, '[');
1861 $$ = mputstr($$, s);
1862 $$ = mputc ($$, ']');
1863 Free(s);
1864 delete $3;
1865 }
1866 ;
1867
1868 TestportParameterName:
1869 Identifier { $$ = $1; }
1870 ;
1871
1872 TestportParameterValue:
1873 StringValue { $$ = $1; }
1874 ;
1875
1876 /****************** [EXECUTE] section *************/
1877
1878 ExecuteSection:
1879 ExecuteKeyword ExecuteList
1880 {
1881 if (!TTCN_Runtime::is_single()) config_process_error("Internal error: "
1882 "the Main Controller must not send section [EXECUTE] of the "
1883 "configuration file.");
1884 }
1885 ;
1886
1887 ExecuteList:
1888 /* empty */
1889 | ExecuteList ExecuteItem optSemiColon
1890 {
1891 if (TTCN_Runtime::is_single()) {
1892 execute_list = (execute_list_item *)Realloc(
1893 execute_list, (execute_list_len + 1) *
1894 sizeof(*execute_list));
1895 execute_list[execute_list_len++] = $2;
1896 } else {
1897 Free($2.module_name);
1898 Free($2.testcase_name);
1899 }
1900 }
1901 ;
1902
1903 ExecuteItem:
1904 Identifier
1905 {
1906 $$.module_name = $1;
1907 $$.testcase_name = NULL;
1908 }
1909 | Identifier '.' ControlKeyword
1910 {
1911 $$.module_name = $1;
1912 $$.testcase_name = NULL;
1913 }
1914 | Identifier '.' Identifier
1915 {
1916 $$.module_name = $1;
1917 $$.testcase_name = $3;
1918 }
1919 | Identifier '.' '*'
1920 {
1921 $$.module_name = $1;
1922 $$.testcase_name = mcopystr("*");
1923 }
1924 ;
1925
1926 /****************** [EXTERNAL_COMMANDS] section **********************/
1927
1928 ExternalCommandsSection:
1929 ExternalCommandsKeyword ExternalCommandList
1930 ;
1931
1932 ExternalCommandList:
1933 /* empty */
1934 | ExternalCommandList ExternalCommand optSemiColon
1935 ;
1936
1937 ExternalCommand:
1938 BeginControlPart AssignmentChar Command
1939 {
1940 check_duplicate_option("EXTERNAL_COMMANDS", "BeginControlPart",
1941 begin_controlpart_command_set);
1942
1943 TTCN_Runtime::set_begin_controlpart_command($3);
1944
1945 Free($3);
1946 }
1947 | EndControlPart AssignmentChar Command
1948 {
1949 check_duplicate_option("EXTERNAL_COMMANDS", "EndControlPart",
1950 end_controlpart_command_set);
1951
1952 TTCN_Runtime::set_end_controlpart_command($3);
1953
1954 Free($3);
1955 }
1956 | BeginTestCase AssignmentChar Command
1957 {
1958 check_duplicate_option("EXTERNAL_COMMANDS", "BeginTestCase",
1959 begin_testcase_command_set);
1960
1961 TTCN_Runtime::set_begin_testcase_command($3);
1962
1963 Free($3);
1964 }
1965 | EndTestCase AssignmentChar Command
1966 {
1967 check_duplicate_option("EXTERNAL_COMMANDS", "EndTestCase",
1968 end_testcase_command_set);
1969
1970 TTCN_Runtime::set_end_testcase_command($3);
1971
1972 Free($3);
1973 }
1974 ;
1975
1976 Command:
1977 StringValue { $$ = $1; }
1978 ;
1979
1980 /***************** [GROUPS] section *******************/
1981
1982 GroupsSection:
1983 GroupsKeyword GroupList
1984 {
1985 check_ignored_section("GROUPS");
1986 }
1987 ;
1988
1989 GroupList:
1990 /* empty */
1991 | GroupList Group optSemiColon
1992 ;
1993
1994 Group:
1995 GroupName AssignmentChar GroupMembers
1996 ;
1997
1998 GroupName:
1999 Identifier { Free($1); }
2000 ;
2001
2002 GroupMembers:
2003 '*'
2004 | seqGroupMember
2005 ;
2006
2007 seqGroupMember:
2008 HostName
2009 | seqGroupMember ',' HostName
2010 ;
2011
2012 HostName:
2013 DNSName
2014 | Identifier { Free($1); }
2015 ;
2016
2017 /******************** [COMPONENTS] section *******************/
2018 ComponentsSection:
2019 ComponentsKeyword ComponentList
2020 {
2021 check_ignored_section("COMPONENTS");
2022 }
2023 ;
2024
2025 ComponentList:
2026 /* empty */
2027 | ComponentList ComponentItem optSemiColon
2028 ;
2029
2030 ComponentItem:
2031 ComponentName AssignmentChar ComponentLocation
2032 ;
2033
2034 ComponentName:
2035 Identifier { Free($1); }
2036 | '*'
2037 ;
2038
2039 ComponentLocation:
2040 Identifier { Free($1); }
2041 | DNSName
2042 ;
2043
2044 /****************** [MAIN_CONTROLLER] section *********************/
2045 MainControllerSection:
2046 MainControllerKeyword MCParameterList
2047 {
2048 check_ignored_section("MAIN_CONTROLLER");
2049 }
2050 ;
2051
2052 MCParameterList:
2053 /* empty */
2054 | MCParameterList MCParameter optSemiColon
2055 ;
2056
2057 MCParameter:
2058 LocalAddress AssignmentChar HostName { }
2059 | TCPPort AssignmentChar IntegerValue { delete $3; }
2060 | KillTimer AssignmentChar KillTimerValue { }
2061 | NumHCs AssignmentChar IntegerValue { delete $3; }
2062 | UnixSocketEnabled AssignmentChar YesToken {}
2063 | UnixSocketEnabled AssignmentChar NoToken {}
2064 | UnixSocketEnabled AssignmentChar HostName {}
2065 ;
2066
2067 KillTimerValue:
2068 FloatValue { }
2069 | IntegerValue { delete $1; }
2070 ;
2071
2072 /****************** [INCLUDE] section *********************/
2073 IncludeSection:
2074 IncludeKeyword IncludeFiles
2075 {
2076 if(!TTCN_Runtime::is_single())
2077 config_process_error
2078 ("Internal error: the Main Controller must not send section [INCLUDE]"
2079 " of the configuration file.");
2080 }
2081 ;
2082
2083 IncludeFiles:
2084 /* empty */
2085 | IncludeFiles IncludeFile
2086 ;
2087
2088 IncludeFile:
2089 Cstring { Free($1.chars_ptr); }
2090 ;
2091
2092 /****************** [DEFINE] section *********************/
2093 DefineSection:
2094 DefineKeyword
2095 {
2096 if(!TTCN_Runtime::is_single())
2097 config_process_error
2098 ("Internal error: the Main Controller must not send section [DEFINE]"
2099 " of the configuration file.");
2100 }
2101 ;
2102
2103 /*********************************************************/
2104
2105 ParamOpType:
2106 AssignmentChar
2107 {
2108 $$ = Module_Param::OT_ASSIGN;
2109 }
2110 |
2111 ConcatChar
2112 {
2113 $$ = Module_Param::OT_CONCAT;
2114 }
2115 ;
2116
2117 optSemiColon:
2118 /* empty */
2119 | ';'
2120 ;
2121
2122 %%
2123
2124 static void reset_configuration_options()
2125 {
2126 /* Section [MODULE_PARAMETERS */
2127 /** \todo reset module parameters to their default values */
2128 /* Section [LOGGING] */
2129 TTCN_Logger::close_file();
2130 TTCN_Logger::reset_configuration();
2131 file_name_set = FALSE;
2132 file_mask_set = TRUE;
2133 console_mask_set = TRUE;
2134 timestamp_format_set = FALSE;
2135 source_info_format_set = FALSE;
2136 append_file_set = FALSE;
2137 log_event_types_set = FALSE;
2138 log_entity_name_set = FALSE;
2139 /* Section [TESTPORT_PARAMETERS] */
2140 PORT::clear_parameters();
2141 /* Section [EXTERNAL_COMMANDS] */
2142
2143 TTCN_Runtime::clear_external_commands();
2144
2145 begin_controlpart_command_set = FALSE;
2146 end_controlpart_command_set = FALSE;
2147 begin_testcase_command_set = FALSE;
2148 end_testcase_command_set = FALSE;
2149 }
2150
2151 Module_Param* process_config_string2ttcn(const char* mp_str, bool is_component)
2152 {
2153 if (parsed_module_param!=NULL || parsing_error_messages!=NULL) TTCN_error("Internal error: previously parsed ttcn string was not cleared.");
2154 // add the hidden keyword
2155 std::string mp_string = (is_component) ? std::string("$#&&&(#TTCNSTRINGPARSING_COMPONENT$#&&^#% ") + mp_str
2156 : std::string("$#&&&(#TTCNSTRINGPARSING$#&&^#% ") + mp_str;
2157 struct yy_buffer_state *flex_buffer = config_process__scan_bytes(mp_string.c_str(), (int)mp_string.size());
2158 if (flex_buffer == NULL) TTCN_error("Internal error: flex buffer creation failed.");
2159 reset_config_process_lex(NULL);
2160 error_flag = FALSE;
2161 try {
2162 Ttcn_String_Parsing ttcn_string_parsing;
2163 if (config_process_parse()) error_flag = TRUE;
2164 } catch (const TC_Error& TC_error) {
2165 if (parsed_module_param!=NULL) { delete parsed_module_param; parsed_module_param = NULL; }
2166 error_flag = TRUE;
2167 }
2168 config_process_close();
2169 config_process_lex_destroy();
2170
2171 if (error_flag || parsing_error_messages!=NULL) {
2172 delete parsed_module_param;
2173 parsed_module_param = NULL;
2174 char* pem = parsing_error_messages!=NULL ? parsing_error_messages : mcopystr("Unknown parsing error");
2175 parsing_error_messages = NULL;
2176 TTCN_error_begin("%s", pem);
2177 Free(pem);
2178 TTCN_error_end();
2179 return NULL;
2180 } else {
2181 if (parsed_module_param==NULL) TTCN_error("Internal error: could not parse ttcn string.");
2182 Module_Param* ret_val = parsed_module_param;
2183 parsed_module_param = NULL;
2184 return ret_val;
2185 }
2186 }
2187
2188 boolean process_config_string(const char *config_string, int string_len)
2189 {
2190 error_flag = FALSE;
2191
2192 struct yy_buffer_state *flex_buffer =
2193 config_process__scan_bytes(config_string, string_len);
2194 if (flex_buffer == NULL) {
2195 TTCN_Logger::log_str(TTCN_Logger::ERROR_UNQUALIFIED,
2196 "Internal error: flex buffer creation failed.");
2197 return FALSE;
2198 }
2199
2200 try {
2201 reset_configuration_options();
2202 reset_config_process_lex(NULL);
2203 if (config_process_parse()) error_flag = TRUE;
2204
2205 } catch (const TC_Error& TC_error) {
2206 error_flag = TRUE;
2207 }
2208
2209 config_process_close();
2210 config_process_lex_destroy();
2211
2212 return !error_flag;
2213 }
2214
2215
2216 boolean process_config_file(const char *file_name)
2217 {
2218 error_flag = FALSE;
2219 string_chain_t *filenames=NULL;
2220
2221 reset_configuration_options();
2222
2223 if(preproc_parse_file(file_name, &filenames, &config_defines))
2224 error_flag=TRUE;
2225
2226 while(filenames) {
2227 char *fn=string_chain_cut(&filenames);
2228 reset_config_process_lex(fn);
2229 /* The lexer can modify config_process_in
2230 * when it's input buffer is changed */
2231 config_process_in = fopen(fn, "r");
2232 FILE* tmp_cfg = config_process_in;
2233 if (config_process_in != NULL) {
2234 try {
2235 if(config_process_parse()) error_flag=TRUE;
2236 } catch (const TC_Error& TC_error) {
2237 error_flag=TRUE;
2238 }
2239 fclose(tmp_cfg);
2240 config_process_close();
2241 config_process_lex_destroy();
2242 } else {
2243 TTCN_Logger::begin_event(TTCN_Logger::ERROR_UNQUALIFIED);
2244 TTCN_Logger::log_event("Cannot open configuration file: %s", fn);
2245 TTCN_Logger::OS_error();
2246 TTCN_Logger::end_event();
2247 error_flag=TRUE;
2248 }
2249 /* During parsing flex or libc may use some system calls (e.g. ioctl)
2250 * that fail with an error status. Such error codes shall be ignored in
2251 * future error messages. */
2252 errno = 0;
2253
2254 Free(fn);
2255 }
2256
2257 string_map_free(config_defines);
2258 config_defines = NULL;
2259
2260 return !error_flag;
2261 }
2262
2263 void config_process_error_f(const char *error_str, ...)
2264 {
2265 if (Ttcn_String_Parsing::happening()) {
2266 va_list p_var;
2267 va_start(p_var, error_str);
2268 char* error_msg_str = mprintf_va_list(error_str, p_var);
2269 va_end(p_var);
2270 if (parsing_error_messages!=NULL) parsing_error_messages = mputc(parsing_error_messages, '\n');
2271 parsing_error_messages = mputprintf(parsing_error_messages,
2272 "Parse error in line %d, at or before token `%s': %s", config_process_get_current_line(), config_process_text, error_msg_str);
2273 Free(error_msg_str);
2274 error_flag = TRUE;
2275 return;
2276 }
2277 TTCN_Logger::begin_event(TTCN_Logger::ERROR_UNQUALIFIED);
2278 if (!get_cfg_process_current_file().empty()) {
2279 TTCN_Logger::log_event("Parse error in configuration file `%s': in line %d, "
2280 "at or before token `%s': ",
2281 get_cfg_process_current_file().c_str(), config_process_get_current_line(),
2282 config_process_text
2283 );
2284 } else {
2285 TTCN_Logger::log_event("Parse error while reading configuration "
2286 "information: in line %d, at or before token `%s': ",
2287 config_process_get_current_line(), config_process_text);
2288 }
2289 va_list pvar;
2290 va_start(pvar, error_str);
2291 TTCN_Logger::log_event_va_list(error_str, pvar);
2292 va_end(pvar);
2293 TTCN_Logger::end_event();
2294 error_flag = TRUE;
2295 }
2296
2297 void config_process_error(const char *error_str)
2298 {
2299 config_process_error_f("%s", error_str);
2300 }
2301
2302 void config_preproc_error(const char *error_str, ...)
2303 {
2304 TTCN_Logger::begin_event(TTCN_Logger::ERROR_UNQUALIFIED);
2305 TTCN_Logger::log_event("Parse error while pre-processing configuration"
2306 " file `%s': in line %d: ",
2307 get_cfg_preproc_current_file().c_str(),
2308 config_preproc_yylineno);
2309 va_list pvar;
2310 va_start(pvar, error_str);
2311 TTCN_Logger::log_event_va_list(error_str, pvar);
2312 va_end(pvar);
2313 TTCN_Logger::end_event();
2314 error_flag = TRUE;
2315 }
2316
2317 void path_error(const char *fmt, ...)
2318 {
2319 va_list parameters;
2320 fprintf(stderr, "File error: ");
2321 va_start(parameters, fmt);
2322 vfprintf(stderr, fmt, parameters);
2323 va_end(parameters);
2324 fprintf(stderr, "\n");
2325 }
2326
2327 static void check_duplicate_option(const char *section_name,
2328 const char *option_name, boolean& option_flag)
2329 {
2330 if (option_flag) {
2331 TTCN_warning("Option `%s' was given more than once in section [%s] of the "
2332 "configuration file.", option_name, section_name);
2333 } else option_flag = TRUE;
2334 }
2335
2336 static void check_ignored_section(const char *section_name)
2337 {
2338 if (TTCN_Runtime::is_single()) TTCN_warning("Section [%s] of "
2339 "configuration file is ignored in single mode.", section_name);
2340 else config_process_error_f("Internal error: the Main Controller must not "
2341 "send section [%s] of the configuration file.", section_name);
2342 }
2343
2344 static void set_param(Module_Param& param)
2345 {
2346 try {
2347 Module_List::set_param(param);
2348 }
2349 catch (const TC_Error& TC_error) {
2350 error_flag = TRUE;
2351 }
2352 }
2353
2354 unsigned char char_to_hexdigit(char c)
2355 {
2356 if (c >= '0' && c <= '9') return c - '0';
2357 else if (c >= 'A' && c <= 'F') return c - 'A' + 10;
2358 else if (c >= 'a' && c <= 'f') return c - 'a' + 10;
2359 else {
2360 config_process_error_f("char_to_hexdigit(): invalid argument: %c", c);
2361 return 0; // to avoid warning
2362 }
2363 }
This page took 0.082349 seconds and 5 git commands to generate.