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