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