Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2014 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | ******************************************************************************/ | |
8 | %option noyywrap | |
9 | %option never-interactive | |
10 | %option nounput | |
11 | ||
12 | %{ | |
13 | ||
14 | #include <string.h> | |
15 | #include <stdlib.h> | |
16 | #include <assert.h> | |
17 | ||
18 | #include <deque> | |
19 | #include <string> | |
20 | ||
21 | #include "../common/cfg_process_utils.hh" | |
22 | #include "../common/Path2.hh" | |
23 | ||
24 | #include "../common/memory.h" | |
25 | #include "Types.h" | |
26 | #include "Parameters.h" | |
27 | #include "Param_Types.hh" | |
28 | #include "Port.hh" | |
29 | #include "LoggingBits.hh" | |
30 | #include "LoggingParam.hh" | |
31 | #include "Error.hh" | |
32 | #include "config_process.tab.hh" | |
33 | #include "../common/config_preproc.h" | |
34 | #include "../common/path.h" | |
35 | ||
36 | #include "../common/dbgnew.hh" | |
37 | ||
38 | extern string_map_t *config_defines; | |
39 | ||
40 | #define yylval config_process_lval | |
41 | ||
42 | static int current_line; | |
43 | ||
44 | static YY_BUFFER_STATE main_buffer = NULL; | |
45 | /* This buffer is used for macro expansion */ | |
46 | static YY_BUFFER_STATE expansion_buffer = NULL; | |
47 | ||
48 | static std::deque<IncludeElem<YY_BUFFER_STATE> >* include_chain = NULL; | |
49 | ||
50 | static void set_ret_val_cstr(const std::string& cstring) { | |
51 | param_charstring_t& ch_val = yylval.charstring_val; | |
52 | ch_val.n_chars = cstring.size(); | |
53 | ch_val.chars_ptr = (char*) Malloc(ch_val.n_chars + 1); | |
54 | memcpy(ch_val.chars_ptr, cstring.c_str(), cstring.size() + 1); | |
55 | } | |
56 | ||
57 | std::string get_cfg_process_current_file() { | |
58 | if (include_chain && !include_chain->empty()) { | |
59 | return include_chain->back().get_full_path(); | |
60 | } | |
61 | ||
62 | return std::string(); | |
63 | } | |
64 | ||
65 | %} | |
66 | ||
67 | WHITESPACE [ \t] | |
68 | WS {WHITESPACE}* | |
69 | NEWLINE \r|\n|\r\n | |
70 | LINECOMMENT ("//"|"#")[^\r\n]*{NEWLINE} | |
71 | ||
72 | NUMBER 0|([1-9][0-9]*) | |
73 | ||
74 | FLOAT [+-]?({NUMBER}\.[0-9]+)|((({NUMBER}(\.[0-9]+)?)|(\.[0-9]+))[Ee][+-]?{NUMBER}) | |
75 | ||
76 | BIN 0|1 | |
77 | BITSTRING '{BIN}*'B | |
78 | BINMATCH 0|1|\?|\* | |
79 | BITSTRINGMATCH '{BINMATCH}*'B | |
80 | BITSTRING_BAD '[^']*'B | |
81 | ||
82 | HEX [0-9A-Fa-f] | |
83 | HEXSTRING '{HEX}*'H | |
84 | HEXMATCH [0-9A-Fa-f\?\*] | |
85 | HEXSTRINGMATCH '{HEXMATCH}*'H | |
86 | HEXSTRING_BAD '[^']*'H | |
87 | ||
88 | OCT {HEX}{HEX} | |
89 | OCTETSTRING '{OCT}*'O | |
90 | OCTMATCH {HEX}{HEX}|\?|\* | |
91 | OCTETSTRINGMATCH '{OCTMATCH}*'O | |
92 | OCTETSTRING_BAD '[^']*'O | |
93 | ||
94 | BINSTRING_BAD '[^']*' | |
95 | ||
96 | TTCN3IDENTIFIER [A-Za-z][A-Za-z0-9_]* | |
97 | ASN1LOWERIDENTIFIER [a-z](-?[A-Za-z0-9]+)* | |
98 | ||
99 | COMPONENT .*\({NUMBER}\) | |
100 | ||
101 | MACRO_CSTR \${TTCN3IDENTIFIER}|\$"{"{WS}{TTCN3IDENTIFIER}{WS}(","{WS}charstring{WS})?"}" | |
102 | MACRO_BOOL \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}boolean{WS}"}" | |
103 | MACRO_FLOAT \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}float{WS}"}" | |
104 | MACRO_ID \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}identifier{WS}"}" | |
105 | MACRO_INT \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}integer{WS}"}" | |
106 | MACRO_BSTR \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}bitstring{WS}"}" | |
107 | MACRO_HSTR \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}hexstring{WS}"}" | |
108 | MACRO_OSTR \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}octetstring{WS}"}" | |
109 | MACRO_BINARY \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}binaryoctet{WS}"}" | |
110 | MACRO_HOSTNAME \$"{"{WS}{TTCN3IDENTIFIER}{WS}","{WS}hostname{WS}"}" | |
111 | ||
112 | HOSTNAME [A-Za-z0-9]([A-Za-z0-9_\-]*[A-Za-z0-9])? | |
113 | DNSNAME {HOSTNAME}(\.{HOSTNAME})*\.? | |
114 | ||
115 | /* Example: fe80::c002:37ff:fe6c:0%fastethernet0/0 */ | |
116 | IPV6 [0-9A-Fa-f:.]+(%[0-9A-Za-z]+)? | |
117 | ||
118 | TTCNSTRINGPARSING "$#&&&(#TTCNSTRINGPARSING$#&&^#% " | |
119 | TTCNSTRINGPARSING_COMPONENT "$#&&&(#TTCNSTRINGPARSING_COMPONENT$#&&^#% " | |
120 | ||
121 | %x SC_commentblock SC_cstring SC_DEFINE | |
122 | %s SC_MODULE_PARAMETERS SC_LOGGING SC_TESTPORT_PARAMETERS SC_EXECUTE SC_GROUPS | |
123 | %s SC_COMPONENTS SC_EXTERNAL_COMMANDS SC_MAIN_CONTROLLER SC_INCLUDE SC_ORDERED_INCLUDE | |
af710487 | 124 | %s SC_STRING2TTCN_COMPONENT SC_PROFILER |
970ed795 EL |
125 | |
126 | %% | |
127 | ||
128 | int caller_state = INITIAL; | |
129 | std::string cstring; | |
130 | int cstring_start = -1; | |
131 | ||
132 | /* Eat up comments and whitespaces */ | |
133 | ||
134 | "/*" { | |
135 | caller_state = YY_START; | |
136 | BEGIN(SC_commentblock); | |
137 | } | |
138 | <SC_commentblock> | |
139 | { | |
140 | "*/" BEGIN(caller_state); | |
141 | {NEWLINE} current_line++; | |
142 | . /* do nothing */ | |
143 | <<EOF>> { | |
144 | config_process_error("Unterminated block comment (missing */ at the " | |
145 | "end of file)."); | |
146 | BEGIN(caller_state); | |
147 | } | |
148 | } | |
149 | ||
150 | {WHITESPACE} | |
151 | {NEWLINE} | | |
152 | {LINECOMMENT} current_line++; | |
153 | ||
154 | {TTCNSTRINGPARSING} { | |
155 | if (Ttcn_String_Parsing::happening()) { | |
156 | BEGIN(SC_MODULE_PARAMETERS); | |
157 | return TtcnStringParsingKeyword; | |
158 | } else { | |
159 | config_process_error("Invalid character sequence encountered."); | |
160 | } | |
161 | } | |
162 | ||
163 | {TTCNSTRINGPARSING_COMPONENT} { | |
164 | if (Ttcn_String_Parsing::happening()) { | |
165 | BEGIN(SC_STRING2TTCN_COMPONENT); | |
166 | return TtcnStringParsingKeyword; | |
167 | } else { | |
168 | config_process_error("Invalid character sequence encountered."); | |
169 | } | |
170 | } | |
171 | ||
172 | /* Section delimiters */ | |
173 | ||
174 | <*>"["{WS}MODULE_PARAMETERS{WS}"]" { | |
175 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
176 | BEGIN(SC_MODULE_PARAMETERS); | |
177 | return ModuleParametersKeyword; | |
178 | } | |
179 | } | |
180 | ||
181 | <*>"["{WS}LOGGING{WS}"]" { | |
182 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
183 | BEGIN(SC_LOGGING); | |
184 | return LoggingKeyword; | |
185 | } | |
186 | } | |
187 | ||
af710487 | 188 | <*>"["{WS}PROFILER{WS}"]" { |
189 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
190 | BEGIN(SC_PROFILER); | |
191 | return ProfilerKeyword; | |
192 | } | |
193 | } | |
194 | ||
970ed795 EL |
195 | <*>"["{WS}TESTPORT_PARAMETERS{WS}"]" { |
196 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
197 | BEGIN(SC_TESTPORT_PARAMETERS); | |
198 | return TestportParametersKeyword; | |
199 | } | |
200 | } | |
201 | ||
202 | <*>"["{WS}EXECUTE{WS}"]" { | |
203 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
204 | BEGIN(SC_EXECUTE); | |
205 | return ExecuteKeyword; | |
206 | } | |
207 | } | |
208 | ||
209 | <*>"["{WS}EXTERNAL_COMMANDS{WS}"]" { | |
210 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
211 | BEGIN(SC_EXTERNAL_COMMANDS); | |
212 | return ExternalCommandsKeyword; | |
213 | } | |
214 | } | |
215 | ||
216 | <*>"["{WS}GROUPS{WS}"]" { | |
217 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
218 | BEGIN(SC_GROUPS); | |
219 | return GroupsKeyword; | |
220 | } | |
221 | } | |
222 | ||
223 | <*>"["{WS}COMPONENTS{WS}"]" { | |
224 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
225 | BEGIN(SC_COMPONENTS); | |
226 | return ComponentsKeyword; | |
227 | } | |
228 | } | |
229 | ||
230 | <*>"["{WS}MAIN_CONTROLLER{WS}"]" { | |
231 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
232 | BEGIN(SC_MAIN_CONTROLLER); | |
233 | return MainControllerKeyword; | |
234 | } | |
235 | } | |
236 | ||
237 | <*>"["{WS}INCLUDE{WS}"]" { | |
238 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
239 | BEGIN(SC_INCLUDE); | |
240 | return IncludeKeyword; | |
241 | } | |
242 | } | |
243 | ||
244 | <*>"["{WS}ORDERED_INCLUDE{WS}"]" { | |
245 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
246 | BEGIN(SC_ORDERED_INCLUDE); | |
247 | } | |
248 | } | |
249 | ||
250 | <*>"["{WS}DEFINE{WS}"]" { | |
251 | if (YY_START!=SC_commentblock && YY_START!=SC_cstring) { | |
252 | BEGIN(SC_DEFINE); | |
253 | return DefineKeyword; | |
254 | } | |
255 | } | |
256 | ||
257 | /* Rules for SC_DEFINE must precede everything else */ | |
258 | ||
259 | <SC_DEFINE>{ | |
260 | ||
261 | "/*" { | |
262 | caller_state = SC_DEFINE; | |
263 | BEGIN(SC_commentblock); | |
264 | } | |
265 | ||
266 | \" { | |
267 | caller_state = SC_DEFINE; | |
268 | BEGIN(SC_cstring); | |
269 | cstring.clear(); | |
270 | cstring_start = current_line; | |
271 | } | |
272 | ||
273 | {LINECOMMENT}|{NEWLINE} current_line++; | |
274 | ||
275 | \\\" | |
276 | ||
277 | . /* eat unnecessary chars */ | |
278 | ||
279 | } | |
280 | ||
281 | /* Values */ | |
282 | ||
283 | {NUMBER} { | |
284 | yylval.int_val = new int_val_t(yytext); | |
285 | return Number; | |
286 | } | |
287 | ||
288 | {FLOAT} { | |
289 | yylval.float_val = atof(yytext); | |
290 | return Float; | |
291 | } | |
292 | ||
293 | {BITSTRING} { | |
294 | yylval.bitstring_val.n_bits = yyleng - 3; | |
295 | int n_bytes = (yylval.bitstring_val.n_bits + 7) / 8; | |
296 | yylval.bitstring_val.bits_ptr = (unsigned char *)Malloc(n_bytes); | |
297 | memset(yylval.bitstring_val.bits_ptr, 0, n_bytes); | |
298 | for (int i = 0; i < yylval.bitstring_val.n_bits; i++) | |
299 | if (yytext[i+1] == '1') | |
300 | yylval.bitstring_val.bits_ptr[i/8] |= 1 << (i % 8); | |
301 | return Bstring; | |
302 | } | |
303 | ||
304 | {BITSTRINGMATCH} { | |
305 | yylval.str_val = mcopystrn(yytext+1, yyleng-3); | |
306 | return BstringMatch; | |
307 | } | |
308 | ||
309 | {BITSTRING_BAD} { | |
310 | config_process_error("Invalid bitstring value."); | |
311 | yylval.bitstring_val.n_bits = 0; | |
312 | yylval.bitstring_val.bits_ptr = NULL; | |
313 | return Bstring; | |
314 | } | |
315 | ||
316 | {HEXSTRING} { | |
317 | yylval.hexstring_val.n_nibbles = yyleng - 3; | |
318 | int n_bytes = (yylval.hexstring_val.n_nibbles + 1) / 2; | |
319 | yylval.hexstring_val.nibbles_ptr = (unsigned char *)Malloc(n_bytes); | |
320 | memset(yylval.hexstring_val.nibbles_ptr, 0, n_bytes); | |
321 | for (int i = 0; i < yylval.hexstring_val.n_nibbles; i++) { | |
322 | unsigned int hex_digit; | |
323 | sscanf(yytext+i+1, "%1x", &hex_digit); | |
324 | if(i % 2) yylval.hexstring_val.nibbles_ptr[i/2] |= | |
325 | (hex_digit << 4); | |
326 | else yylval.hexstring_val.nibbles_ptr[i/2] |= hex_digit; | |
327 | } | |
328 | return Hstring; | |
329 | } | |
330 | ||
331 | {HEXSTRINGMATCH} { | |
332 | yylval.str_val = mcopystrn(yytext+1, yyleng-3); | |
333 | return HstringMatch; | |
334 | } | |
335 | ||
336 | {HEXSTRING_BAD} { | |
337 | config_process_error("Invalid hexstring value."); | |
338 | yylval.hexstring_val.n_nibbles = 0; | |
339 | yylval.hexstring_val.nibbles_ptr = NULL; | |
340 | return Hstring; | |
341 | } | |
342 | ||
343 | {OCTETSTRING} { | |
344 | yylval.octetstring_val.n_octets = (yyleng - 3) / 2; | |
345 | yylval.octetstring_val.octets_ptr = (unsigned char *) | |
346 | Malloc(yylval.octetstring_val.n_octets); | |
347 | ||
348 | for (int i = 0; i < yylval.octetstring_val.n_octets; i++) { | |
349 | unsigned int this_octet; | |
350 | sscanf(yytext+2*i+1, "%2x", &this_octet); | |
351 | yylval.octetstring_val.octets_ptr[i] = this_octet; | |
352 | } | |
353 | return Ostring; | |
354 | } | |
355 | ||
356 | {OCTETSTRINGMATCH} { | |
357 | yylval.str_val = mcopystrn(yytext+1, yyleng-3); | |
358 | return OstringMatch; | |
359 | } | |
360 | ||
361 | {OCTETSTRING_BAD} { | |
362 | config_process_error("Invalid octetstring value."); | |
363 | yylval.octetstring_val.n_octets = 0; | |
364 | yylval.octetstring_val.octets_ptr = NULL; | |
365 | return Ostring; | |
366 | } | |
367 | ||
368 | {BINSTRING_BAD} config_process_error("Invalid string value."); | |
369 | ||
370 | ' config_process_error("Unmatched ' character."); | |
371 | ||
372 | \" { | |
373 | caller_state = YY_START; | |
374 | BEGIN(SC_cstring); | |
375 | cstring.clear(); | |
376 | cstring_start = current_line; | |
377 | } | |
378 | ||
379 | <SC_cstring> | |
380 | { | |
381 | \"\" cstring += '"'; | |
382 | \" { | |
383 | /* end of the string */ | |
384 | BEGIN(caller_state); | |
385 | switch (caller_state) { | |
386 | case SC_DEFINE: | |
387 | cstring.clear(); | |
388 | break; | |
389 | case SC_ORDERED_INCLUDE: | |
390 | { | |
391 | std::string error_msg = switch_lexer(include_chain, cstring, | |
392 | YY_CURRENT_BUFFER, yy_create_buffer, yy_switch_to_buffer, | |
393 | current_line, YY_BUF_SIZE); | |
394 | if (error_msg.empty()) { | |
395 | BEGIN(INITIAL); | |
396 | } else { | |
397 | config_process_error(error_msg.c_str()); | |
398 | } | |
399 | } | |
400 | break; | |
401 | default: | |
402 | set_ret_val_cstr(cstring); | |
403 | return Cstring; | |
404 | } | |
405 | ||
406 | cstring.clear(); | |
407 | cstring_start = -1; | |
408 | } | |
409 | \\[\\'"?] cstring += yytext[1]; /* backslash-quoted \ or " or ' or ? */ | |
410 | \\{NEWLINE} current_line++; | |
411 | \\a cstring += '\a'; | |
412 | \\b cstring += '\b'; | |
413 | \\f cstring += '\f'; | |
414 | \\n cstring += '\n'; | |
415 | \\r cstring += '\r'; | |
416 | \\t cstring += '\t'; | |
417 | \\v cstring += '\v'; | |
418 | \\[0-7]{1,3} { | |
419 | unsigned int c; | |
420 | sscanf(yytext + 1, "%o", &c); | |
421 | if (c > 255) | |
422 | config_process_error("Invalid octal character code in string " | |
423 | "literal."); | |
424 | else if (c == 0 && caller_state != SC_MODULE_PARAMETERS) | |
425 | config_process_error("NUL characters in string literals are " | |
426 | "allowed only in section [MODULE_PARAMETERS]."); | |
427 | else cstring += c; | |
428 | } | |
429 | \\x{HEX}{1,2} { | |
430 | unsigned int c; | |
431 | sscanf(yytext + 2, "%x", &c); | |
432 | if (c == 0 && caller_state != SC_MODULE_PARAMETERS) | |
433 | config_process_error("NUL characters in string literals are " | |
434 | "allowed only in section [MODULE_PARAMETERS]."); | |
435 | else cstring += c; | |
436 | } | |
437 | \\(x[^\\\"]|.) { | |
438 | config_process_error("Invalid escape sequence in string literal."); | |
439 | } | |
440 | {NEWLINE} { | |
441 | cstring.append(yytext, yyleng); | |
442 | current_line++; | |
443 | } | |
444 | . cstring += yytext[0]; | |
445 | <<EOF>> { | |
446 | if (cstring_start >=0) { | |
447 | config_process_error_f("Unterminated string literal starting at line %d " | |
448 | "(missing \" at the end of file).", cstring_start); | |
449 | } else { | |
450 | config_process_error("Unterminated string literal (missing \" at the " | |
451 | "end of file)."); | |
452 | } | |
453 | BEGIN(caller_state); | |
454 | if (caller_state!=SC_DEFINE) { | |
455 | set_ret_val_cstr(cstring); | |
456 | return Cstring; | |
457 | } | |
458 | ||
459 | cstring.clear(); | |
460 | } | |
461 | } | |
462 | ||
463 | /* Section-wide keywords */ | |
464 | ||
465 | <SC_MODULE_PARAMETERS> | |
466 | { | |
467 | NULL return NULLKeyword; | |
468 | null return nullKeyword; | |
469 | char return CharKeyword; | |
470 | objid return ObjIdKeyword; | |
471 | omit return OmitKeyword; | |
472 | none { | |
473 | yylval.verdict_val = NONE; | |
474 | return VerdictValue; | |
475 | } | |
476 | pass { | |
477 | yylval.verdict_val = PASS; | |
478 | return VerdictValue; | |
479 | } | |
480 | inconc { | |
481 | yylval.verdict_val = INCONC; | |
482 | return VerdictValue; | |
483 | } | |
484 | fail { | |
485 | yylval.verdict_val = FAIL; | |
486 | return VerdictValue; | |
487 | } | |
488 | error { | |
489 | yylval.verdict_val = ERROR; | |
490 | return VerdictValue; | |
491 | } | |
492 | complement return ComplementKeyword; | |
493 | "\.\." return DotDot; | |
494 | superset return SupersetKeyword; | |
495 | subset return SubsetKeyword; | |
496 | pattern return PatternKeyword; | |
497 | permutation return PermutationKeyword; | |
498 | length return LengthKeyword; | |
499 | ifpresent return IfpresentKeyword; | |
500 | infinity return InfinityKeyword; | |
501 | } | |
502 | ||
af710487 | 503 | <SC_MODULE_PARAMETERS,SC_LOGGING,SC_PROFILER> |
970ed795 EL |
504 | { |
505 | true { | |
506 | yylval.bool_val = TRUE; | |
507 | return BooleanValue; | |
508 | } | |
509 | false { | |
510 | yylval.bool_val = FALSE; | |
511 | return BooleanValue; | |
512 | } | |
513 | } | |
514 | ||
515 | /* We could add SC_LOGGING to make mtc and system special for the logging section too */ | |
516 | <SC_MODULE_PARAMETERS,SC_STRING2TTCN_COMPONENT,SC_TESTPORT_PARAMETERS,SC_LOGGING> | |
517 | { | |
518 | mtc return MTCKeyword; | |
519 | system return SystemKeyword; | |
520 | } | |
521 | ||
522 | <SC_LOGGING> | |
523 | { | |
524 | [Ff]ile[Nn]ame | | |
525 | [Ll]og[Ff]ile return LogFile; | |
526 | ||
527 | [Ee]mergency[Ll]ogging return EmergencyLogging; | |
528 | ||
529 | [Ee]mergency[Ll]ogging[Bb]ehaviour return EmergencyLoggingBehaviour; | |
530 | ||
531 | [Ee]mergency[Ll]ogging[Mm]ask return EmergencyLoggingMask; | |
532 | ||
533 | [Ff]ile[Mm]ask return FileMask; | |
534 | ||
535 | [Cc]onsole[Mm]ask return ConsoleMask; | |
536 | ||
537 | [Tt]ime[Ss]tamp[Ff]ormat return TimestampFormat; | |
538 | [Cc]onsole[Tt]ime[Ss]tamp[Ff]ormat return ConsoleTimestampFormat; | |
539 | ||
540 | [Ll]og[Ss]ource[Ii]nfo | | |
541 | [Ss]ource[Ii]nfo[Ff]ormat return SourceInfoFormat; | |
542 | ||
543 | [Aa]ppend[Ff]ile return AppendFile; | |
544 | ||
545 | [Ll]og[Ee]vent[Tt]ypes return LogEventTypes; | |
546 | ||
547 | [Ll]og[Ee]ntity[Nn]ame return LogEntityName; | |
548 | ||
549 | [Ll]og[Ff]ile[Ss]ize return LogFileSize; | |
550 | ||
551 | [Ll]og[Ff]ile[Nn]umber return LogFileNumber; | |
552 | ||
553 | [Dd]isk[Ff]ull[Aa]ction return DiskFullAction; | |
554 | ||
555 | [Mm]atching[Hh]ints return MatchingHints; | |
556 | ||
557 | [Ll]ogger[Pp]lugins return LoggerPlugins; | |
558 | ||
559 | /* Lexer's handling of logging keywords: | |
560 | * | |
561 | * For sub-categories and categories with only one member, | |
562 | * LoggingBit is returned and the value is the corresponding | |
563 | * TTCN_Logger::Severity. | |
564 | * | |
565 | * For the old categories which now have subcategories, the old keyword | |
566 | * is returned as LoggingBitCollection with the corresponding | |
567 | * _UNQUALIFIED as the semantic value. The parser will construct the | |
568 | * multi-bit value. | |
569 | * | |
570 | * The lexer never returns a token with a Logging_Bits type. | |
571 | */ | |
572 | LOG_NOTHING { | |
573 | yylval.logseverity_val = TTCN_Logger::NOTHING_TO_LOG; | |
574 | return LoggingBit; | |
575 | } | |
576 | ||
577 | ACTION_UNQUALIFIED { | |
578 | yylval.logseverity_val = TTCN_Logger::ACTION_UNQUALIFIED; | |
579 | return LoggingBit; | |
580 | } | |
581 | (TTCN_)?ACTION { | |
582 | yylval.logseverity_val = TTCN_Logger::ACTION_UNQUALIFIED; | |
583 | return LoggingBitCollection; | |
584 | } | |
585 | ||
586 | DEBUG_ENCDEC { | |
587 | yylval.logseverity_val = TTCN_Logger::DEBUG_ENCDEC; | |
588 | return LoggingBit; | |
589 | } | |
590 | DEBUG_TESTPORT { | |
591 | yylval.logseverity_val = TTCN_Logger::DEBUG_TESTPORT; | |
592 | return LoggingBit; | |
593 | } | |
594 | DEBUG_UNQUALIFIED { | |
595 | yylval.logseverity_val = TTCN_Logger::DEBUG_UNQUALIFIED; | |
596 | return LoggingBit; | |
597 | } | |
598 | (TTCN_)?DEBUG { | |
599 | yylval.logseverity_val = TTCN_Logger::DEBUG_UNQUALIFIED; | |
600 | return LoggingBitCollection; | |
601 | } | |
602 | ||
603 | DEFAULTOP_ACTIVATE { | |
604 | yylval.logseverity_val = TTCN_Logger::DEFAULTOP_ACTIVATE; | |
605 | return LoggingBit; | |
606 | } | |
607 | DEFAULTOP_DEACTIVATE { | |
608 | yylval.logseverity_val = TTCN_Logger::DEFAULTOP_DEACTIVATE; | |
609 | return LoggingBit; | |
610 | } | |
611 | DEFAULTOP_EXIT { | |
612 | yylval.logseverity_val = TTCN_Logger::DEFAULTOP_EXIT; | |
613 | return LoggingBit; | |
614 | } | |
615 | DEFAULTOP_UNQUALIFIED { | |
616 | yylval.logseverity_val = TTCN_Logger::DEFAULTOP_UNQUALIFIED; | |
617 | return LoggingBit; | |
618 | } | |
619 | (TTCN_)?DEFAULTOP { | |
620 | yylval.logseverity_val = TTCN_Logger::DEFAULTOP_UNQUALIFIED; | |
621 | return LoggingBitCollection; | |
622 | } | |
623 | ||
624 | ERROR_UNQUALIFIED { | |
625 | yylval.logseverity_val = TTCN_Logger::ERROR_UNQUALIFIED; | |
626 | return LoggingBit; | |
627 | } | |
628 | (TTCN_)?ERROR { | |
629 | yylval.logseverity_val = TTCN_Logger::ERROR_UNQUALIFIED; | |
630 | return LoggingBitCollection; | |
631 | } | |
632 | ||
633 | EXECUTOR_COMPONENT { | |
634 | yylval.logseverity_val = TTCN_Logger::EXECUTOR_COMPONENT; | |
635 | return LoggingBit; | |
636 | } | |
637 | EXECUTOR_CONFIGDATA { | |
638 | yylval.logseverity_val = TTCN_Logger::EXECUTOR_CONFIGDATA; | |
639 | return LoggingBit; | |
640 | } | |
641 | EXECUTOR_EXTCOMMAND { | |
642 | yylval.logseverity_val = TTCN_Logger::EXECUTOR_EXTCOMMAND; | |
643 | return LoggingBit; | |
644 | } | |
645 | EXECUTOR_LOGOPTIONS { | |
646 | yylval.logseverity_val = TTCN_Logger::EXECUTOR_LOGOPTIONS; | |
647 | return LoggingBit; | |
648 | } | |
649 | EXECUTOR_RUNTIME { | |
650 | yylval.logseverity_val = TTCN_Logger::EXECUTOR_RUNTIME; | |
651 | return LoggingBit; | |
652 | } | |
653 | EXECUTOR_UNQUALIFIED { | |
654 | yylval.logseverity_val = TTCN_Logger::EXECUTOR_UNQUALIFIED; | |
655 | return LoggingBit; | |
656 | } | |
657 | (TTCN_)?EXECUTOR { | |
658 | yylval.logseverity_val = TTCN_Logger::EXECUTOR_UNQUALIFIED; | |
659 | return LoggingBitCollection; | |
660 | } | |
661 | ||
662 | FUNCTION_RND { | |
663 | yylval.logseverity_val = TTCN_Logger::FUNCTION_RND; | |
664 | return LoggingBit; | |
665 | } | |
666 | FUNCTION_UNQUALIFIED { | |
667 | yylval.logseverity_val = TTCN_Logger::FUNCTION_UNQUALIFIED; | |
668 | return LoggingBit; | |
669 | } | |
670 | (TTCN_)?FUNCTION { | |
671 | yylval.logseverity_val = TTCN_Logger::FUNCTION_UNQUALIFIED; | |
672 | return LoggingBitCollection; | |
673 | } | |
674 | ||
675 | MATCHING_DONE { | |
676 | yylval.logseverity_val = TTCN_Logger::MATCHING_DONE; | |
677 | return LoggingBit; | |
678 | } | |
679 | MATCHING_MCSUCCESS { | |
680 | yylval.logseverity_val = TTCN_Logger::MATCHING_MCSUCCESS; | |
681 | return LoggingBit; | |
682 | } | |
683 | MATCHING_MCUNSUCC { | |
684 | yylval.logseverity_val = TTCN_Logger::MATCHING_MCUNSUCC; | |
685 | return LoggingBit; | |
686 | } | |
687 | MATCHING_MMSUCCESS { | |
688 | yylval.logseverity_val = TTCN_Logger::MATCHING_MMSUCCESS; | |
689 | return LoggingBit; | |
690 | } | |
691 | MATCHING_MMUNSUCC { | |
692 | yylval.logseverity_val = TTCN_Logger::MATCHING_MMUNSUCC; | |
693 | return LoggingBit; | |
694 | } | |
695 | MATCHING_PCSUCCESS { | |
696 | yylval.logseverity_val = TTCN_Logger::MATCHING_PCSUCCESS; | |
697 | return LoggingBit; | |
698 | } | |
699 | MATCHING_PCUNSUCC { | |
700 | yylval.logseverity_val = TTCN_Logger::MATCHING_PCUNSUCC; | |
701 | return LoggingBit; | |
702 | } | |
703 | MATCHING_PMSUCCESS { | |
704 | yylval.logseverity_val = TTCN_Logger::MATCHING_PMSUCCESS; | |
705 | return LoggingBit; | |
706 | } | |
707 | MATCHING_PMUNSUCC { | |
708 | yylval.logseverity_val = TTCN_Logger::MATCHING_PMUNSUCC; | |
709 | return LoggingBit; | |
710 | } | |
711 | MATCHING_PROBLEM { | |
712 | yylval.logseverity_val = TTCN_Logger::MATCHING_PROBLEM; | |
713 | return LoggingBit; | |
714 | } | |
715 | MATCHING_TIMEOUT { | |
716 | yylval.logseverity_val = TTCN_Logger::MATCHING_TIMEOUT; | |
717 | return LoggingBit; | |
718 | } | |
719 | MATCHING_UNQUALIFIED { | |
720 | yylval.logseverity_val = TTCN_Logger::MATCHING_UNQUALIFIED; | |
721 | return LoggingBit; | |
722 | } | |
723 | (TTCN_)?MATCHING { | |
724 | yylval.logseverity_val = TTCN_Logger::MATCHING_UNQUALIFIED; | |
725 | return LoggingBitCollection; | |
726 | } | |
727 | ||
728 | PARALLEL_PORTCONN { | |
729 | yylval.logseverity_val = TTCN_Logger::PARALLEL_PORTCONN; | |
730 | return LoggingBit; | |
731 | } | |
732 | PARALLEL_PORTMAP { | |
733 | yylval.logseverity_val = TTCN_Logger::PARALLEL_PORTMAP; | |
734 | return LoggingBit; | |
735 | } | |
736 | PARALLEL_PTC { | |
737 | yylval.logseverity_val = TTCN_Logger::PARALLEL_PTC; | |
738 | return LoggingBit; | |
739 | } | |
740 | PARALLEL_UNQUALIFIED { | |
741 | yylval.logseverity_val = TTCN_Logger::PARALLEL_UNQUALIFIED; | |
742 | return LoggingBit; | |
743 | } | |
744 | (TTCN_)?PARALLEL { | |
745 | yylval.logseverity_val = TTCN_Logger::PARALLEL_UNQUALIFIED; | |
746 | return LoggingBitCollection; | |
747 | } | |
748 | ||
749 | PORTEVENT_DUALRECV { | |
750 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_DUALRECV; | |
751 | return LoggingBit; | |
752 | } | |
753 | PORTEVENT_DUALSEND { | |
754 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_DUALSEND; | |
755 | return LoggingBit; | |
756 | } | |
757 | PORTEVENT_MCRECV { | |
758 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_MCRECV; | |
759 | return LoggingBit; | |
760 | } | |
761 | PORTEVENT_MCSEND { | |
762 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_MCSEND; | |
763 | return LoggingBit; | |
764 | } | |
765 | PORTEVENT_MMRECV { | |
766 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_MMRECV; | |
767 | return LoggingBit; | |
768 | } | |
769 | PORTEVENT_MMSEND { | |
770 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_MMSEND; | |
771 | return LoggingBit; | |
772 | } | |
773 | PORTEVENT_MQUEUE { | |
774 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_MQUEUE; | |
775 | return LoggingBit; | |
776 | } | |
777 | PORTEVENT_PCIN { | |
778 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_PCIN; | |
779 | return LoggingBit; | |
780 | } | |
781 | PORTEVENT_PCOUT { | |
782 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_PCOUT; | |
783 | return LoggingBit; | |
784 | } | |
785 | PORTEVENT_PMIN { | |
786 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_PMIN; | |
787 | return LoggingBit; | |
788 | } | |
789 | PORTEVENT_PMOUT { | |
790 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_PMOUT; | |
791 | return LoggingBit; | |
792 | } | |
793 | PORTEVENT_PQUEUE { | |
794 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_PQUEUE; | |
795 | return LoggingBit; | |
796 | } | |
797 | PORTEVENT_STATE { | |
798 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_STATE; | |
799 | return LoggingBit; | |
800 | } | |
801 | PORTEVENT_UNQUALIFIED { | |
802 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_UNQUALIFIED; | |
803 | return LoggingBit; | |
804 | } | |
805 | (TTCN_)?PORTEVENT { | |
806 | yylval.logseverity_val = TTCN_Logger::PORTEVENT_UNQUALIFIED; | |
807 | return LoggingBitCollection; | |
808 | } | |
809 | ||
810 | STATISTICS_UNQUALIFIED { | |
811 | yylval.logseverity_val = TTCN_Logger::STATISTICS_UNQUALIFIED; | |
812 | return LoggingBit; | |
813 | } | |
814 | STATISTICS_VERDICT { | |
815 | yylval.logseverity_val = TTCN_Logger::STATISTICS_VERDICT; | |
816 | return LoggingBit; | |
817 | } | |
818 | (TTCN_)?STATISTICS { | |
819 | yylval.logseverity_val = TTCN_Logger::STATISTICS_UNQUALIFIED; | |
820 | return LoggingBitCollection; | |
821 | } | |
822 | ||
823 | TESTCASE_FINISH { | |
824 | yylval.logseverity_val = TTCN_Logger::TESTCASE_FINISH; | |
825 | return LoggingBit; | |
826 | } | |
827 | TESTCASE_START { | |
828 | yylval.logseverity_val = TTCN_Logger::TESTCASE_START; | |
829 | return LoggingBit; | |
830 | } | |
831 | TESTCASE_UNQUALIFIED { | |
832 | yylval.logseverity_val = TTCN_Logger::TESTCASE_UNQUALIFIED; | |
833 | return LoggingBit; | |
834 | } | |
835 | (TTCN_)?TESTCASE { | |
836 | yylval.logseverity_val = TTCN_Logger::TESTCASE_UNQUALIFIED; | |
837 | return LoggingBitCollection; | |
838 | } | |
839 | ||
840 | TIMEROP_GUARD { | |
841 | yylval.logseverity_val = TTCN_Logger::TIMEROP_GUARD; | |
842 | return LoggingBit; | |
843 | } | |
844 | TIMEROP_READ { | |
845 | yylval.logseverity_val = TTCN_Logger::TIMEROP_READ; | |
846 | return LoggingBit; | |
847 | } | |
848 | TIMEROP_START { | |
849 | yylval.logseverity_val = TTCN_Logger::TIMEROP_START; | |
850 | return LoggingBit; | |
851 | } | |
852 | TIMEROP_STOP { | |
853 | yylval.logseverity_val = TTCN_Logger::TIMEROP_STOP; | |
854 | return LoggingBit; | |
855 | } | |
856 | TIMEROP_TIMEOUT { | |
857 | yylval.logseverity_val = TTCN_Logger::TIMEROP_TIMEOUT; | |
858 | return LoggingBit; | |
859 | } | |
860 | TIMEROP_UNQUALIFIED { | |
861 | yylval.logseverity_val = TTCN_Logger::TIMEROP_UNQUALIFIED; | |
862 | return LoggingBit; | |
863 | } | |
864 | (TTCN_)?TIMEROP { | |
865 | yylval.logseverity_val = TTCN_Logger::TIMEROP_UNQUALIFIED; | |
866 | return LoggingBitCollection; | |
867 | } | |
868 | ||
869 | USER_UNQUALIFIED { | |
870 | yylval.logseverity_val = TTCN_Logger::USER_UNQUALIFIED; | |
871 | return LoggingBit; | |
872 | } | |
873 | (TTCN_)?USER { | |
874 | yylval.logseverity_val = TTCN_Logger::USER_UNQUALIFIED; | |
875 | return LoggingBitCollection; | |
876 | } | |
877 | ||
878 | VERDICTOP_FINAL { | |
879 | yylval.logseverity_val = TTCN_Logger::VERDICTOP_FINAL; | |
880 | return LoggingBit; | |
881 | } | |
882 | VERDICTOP_GETVERDICT { | |
883 | yylval.logseverity_val = TTCN_Logger::VERDICTOP_GETVERDICT; | |
884 | return LoggingBit; | |
885 | } | |
886 | VERDICTOP_SETVERDICT { | |
887 | yylval.logseverity_val = TTCN_Logger::VERDICTOP_SETVERDICT; | |
888 | return LoggingBit; | |
889 | } | |
890 | VERDICTOP_UNQUALIFIED { | |
891 | yylval.logseverity_val = TTCN_Logger::VERDICTOP_UNQUALIFIED; | |
892 | return LoggingBit; | |
893 | } | |
894 | (TTCN_)?VERDICTOP { | |
895 | yylval.logseverity_val = TTCN_Logger::VERDICTOP_UNQUALIFIED; | |
896 | return LoggingBitCollection; | |
897 | } | |
898 | ||
899 | WARNING_UNQUALIFIED { | |
900 | yylval.logseverity_val = TTCN_Logger::WARNING_UNQUALIFIED; | |
901 | return LoggingBit; | |
902 | } | |
903 | (TTCN_)?WARNING { | |
904 | yylval.logseverity_val = TTCN_Logger::WARNING_UNQUALIFIED; | |
905 | return LoggingBitCollection; | |
906 | } | |
907 | ||
908 | LOG_ALL { | |
909 | yylval.logseverity_val = TTCN_Logger::LOG_ALL_IMPORTANT; | |
910 | return LoggingBitCollection; | |
911 | } | |
912 | ||
913 | [Tt][Ii][Mm][Ee] { | |
914 | yylval.timestamp_value = TTCN_Logger::TIMESTAMP_TIME; | |
915 | return TimestampValue; | |
916 | } | |
917 | [Dd][Aa][Tt][Ee][Tt][Ii][Mm][Ee] { | |
918 | yylval.timestamp_value = TTCN_Logger::TIMESTAMP_DATETIME; | |
919 | return TimestampValue; | |
920 | } | |
921 | [Ss][Ee][Cc][Oo][Nn][Dd][Ss] { | |
922 | yylval.timestamp_value = TTCN_Logger::TIMESTAMP_SECONDS; | |
923 | return TimestampValue; | |
924 | } | |
925 | [Nn][Oo][Nn][Ee] { | |
926 | yylval.source_info_value = TTCN_Logger::SINFO_NONE; | |
927 | return SourceInfoValue; | |
928 | } | |
929 | [Ss][Ii][Nn][Gg][Ll][Ee] { | |
930 | yylval.source_info_value = TTCN_Logger::SINFO_SINGLE; | |
931 | return SourceInfoValue; | |
932 | } | |
933 | [Ss][Tt][Aa][Cc][Kk] { | |
934 | yylval.source_info_value = TTCN_Logger::SINFO_STACK; | |
935 | return SourceInfoValue; | |
936 | } | |
937 | [Yy][Ee][Ss] { | |
938 | yylval.bool_val = TRUE; | |
939 | return YesNo; | |
940 | } | |
941 | [Nn][Oo] { | |
942 | yylval.bool_val = FALSE; | |
943 | return YesNo; | |
944 | } | |
945 | [Bb]uffer[Aa]ll { | |
946 | yylval.emergency_logging_behaviour_value = TTCN_Logger::BUFFER_ALL; | |
947 | return EmergencyLoggingBehaviourValue; | |
948 | } | |
949 | [Bb]uffer[Mm]asked { | |
950 | yylval.emergency_logging_behaviour_value = TTCN_Logger::BUFFER_MASKED; | |
951 | return EmergencyLoggingBehaviourValue; | |
952 | } | |
953 | ||
954 | [Cc]ompact return Compact; | |
955 | [Dd]etailed return Detailed; | |
956 | [Ss]ub[Cc]ategories return SubCategories; | |
957 | ||
958 | [Ee]rror return Error; | |
959 | ||
960 | [Ss]top return Stop; | |
961 | ||
962 | [Rr]etry return Retry; | |
963 | ||
964 | [Dd]elete return Delete; | |
965 | } | |
966 | ||
af710487 | 967 | <SC_PROFILER> |
968 | { | |
969 | [Dd]isable[Pp]rofiler return DisableProfilerKeyword; | |
970 | [Dd]isable[Cc]overage return DisableCoverageKeyword; | |
971 | [Dd]ata[Bb]ase[Ff]ile return DatabaseFileKeyword; | |
972 | [Aa]ggregate[Dd]ata return AggregateDataKeyword; | |
973 | [Ss]tatistics[Ff]ile return StatisticsFileKeyword; | |
974 | [Dd]isable[Ss]tatistics return DisableStatisticsKeyword; | |
975 | } | |
976 | ||
970ed795 EL |
977 | <SC_EXECUTE>control return ControlKeyword; |
978 | ||
979 | <SC_EXTERNAL_COMMANDS> | |
980 | { | |
981 | [Bb]egin[Cc]ontrol[Pp]art return BeginControlPart; | |
982 | [Ee]nd[Cc]ontrol[Pp]art return EndControlPart; | |
983 | [Bb]egin[Tt]est[Cc]ase return BeginTestCase; | |
984 | [Ee]nd[Tt]est[Cc]ase return EndTestCase; | |
985 | } | |
986 | ||
987 | <SC_MAIN_CONTROLLER> | |
988 | { | |
989 | [Ll]ocal[Aa]ddress return LocalAddress; | |
990 | [Tt][Cc][Pp][Pp]ort return TCPPort; | |
991 | [Kk]ill[Tt]imer return KillTimer; | |
992 | [Nn]um[Hh][Cc]s return NumHCs; | |
993 | [Uu]nix[Ss]ockets[Ee]nabled return UnixSocketEnabled; | |
994 | [Yy][Ee][Ss] return YesToken; | |
995 | [Nn][Oo] return NoToken; | |
996 | } | |
997 | ||
998 | {TTCN3IDENTIFIER} { | |
999 | yylval.str_val = mcopystr(yytext); | |
1000 | return Identifier; | |
1001 | } | |
1002 | ||
1003 | <SC_MODULE_PARAMETERS>{ASN1LOWERIDENTIFIER} { | |
1004 | yylval.str_val = mcopystr(yytext); | |
1005 | for (int i = 0; i < yyleng; i++) { | |
1006 | if (yylval.str_val[i] == '-') yylval.str_val[i] = '_'; | |
1007 | } | |
1008 | TTCN_warning("In line %d of configuration file: `%s' is not a valid TTCN-3 " | |
1009 | "identifier. Did you mean `%s'?", current_line, yytext, yylval.str_val); | |
1010 | return ASN1LowerIdentifier; | |
1011 | } | |
1012 | ||
1013 | <SC_GROUPS,SC_COMPONENTS,SC_MAIN_CONTROLLER>{DNSNAME}|{IPV6} return DNSName; | |
1014 | /* Information is discarded ! */ | |
1015 | ||
1016 | <SC_STRING2TTCN_COMPONENT>{COMPONENT} { | |
1017 | /* Ignore the component name, just return its number */ | |
1018 | size_t len = strlen(yytext); | |
1019 | size_t pos = len - 1; | |
1020 | while(yytext[pos] != '(' && pos != 0) { | |
1021 | --pos; | |
1022 | } | |
1023 | char* comp_num_str = mcopystrn(yytext + pos + 1, len - pos - 1); | |
1024 | yylval.int_val = new int_val_t(comp_num_str); | |
1025 | Free(comp_num_str); | |
1026 | return Number; | |
1027 | } | |
1028 | ||
1029 | {MACRO_BOOL} { | |
1030 | if (config_defines != NULL) { | |
1031 | char *macroname = get_macro_id_from_ref(yytext); | |
1032 | size_t macrolen; | |
1033 | const char *macrovalue = | |
1034 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1035 | if (macrovalue != NULL) { | |
1036 | if (!strcmp(macrovalue, "true")) yylval.bool_val = TRUE; | |
1037 | else if (!strcmp(macrovalue, "false")) yylval.bool_val = FALSE; | |
1038 | else { | |
1039 | config_process_error_f("Macro `%s' cannot be interpreted as boolean " | |
1040 | "value: `%s'", macroname, macrovalue); | |
1041 | yylval.bool_val = FALSE; | |
1042 | } | |
1043 | } else { | |
1044 | config_process_error_f("No macro or environmental variable defined" | |
1045 | " with name `%s'", macroname); | |
1046 | yylval.bool_val = FALSE; | |
1047 | } | |
1048 | Free(macroname); | |
1049 | } else { | |
1050 | config_process_error("Internal error: Macro reference cannot be used in " | |
1051 | "this context."); | |
1052 | yylval.bool_val = FALSE; | |
1053 | } | |
1054 | return BooleanValue; | |
1055 | } | |
1056 | ||
1057 | {MACRO_INT} { | |
1058 | if (config_defines != NULL) { | |
1059 | char *macroname = get_macro_id_from_ref(yytext); | |
1060 | size_t macrolen; | |
1061 | const char *macrovalue = | |
1062 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1063 | if (macrovalue != NULL) { | |
1064 | if (string_is_int(macrovalue, macrolen)) | |
1065 | yylval.int_val = new int_val_t(macrovalue); | |
1066 | else { | |
1067 | config_process_error_f("Macro `%s' cannot be interpreted as integer " | |
1068 | "value: `%s'", macroname, macrovalue); | |
1069 | yylval.int_val = new int_val_t((RInt)0); | |
1070 | } | |
1071 | } else { | |
1072 | config_process_error_f("No macro or environmental variable defined" | |
1073 | " with name `%s'", macroname); | |
1074 | yylval.int_val = new int_val_t((RInt)0); | |
1075 | } | |
1076 | Free(macroname); | |
1077 | } else { | |
1078 | config_process_error("Internal error: Macro reference cannot be used in " | |
1079 | "this context."); | |
1080 | yylval.int_val = new int_val_t((RInt)0); | |
1081 | } | |
1082 | return Number; | |
1083 | } | |
1084 | ||
1085 | {MACRO_FLOAT} { | |
1086 | if (config_defines != NULL) { | |
1087 | char *macroname = get_macro_id_from_ref(yytext); | |
1088 | size_t macrolen; | |
1089 | const char *macrovalue = | |
1090 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1091 | if (macrovalue != NULL) { | |
1092 | if (string_is_float(macrovalue, macrolen)) | |
1093 | yylval.float_val = atof(macrovalue); | |
1094 | else { | |
1095 | config_process_error_f("Macro `%s' cannot be interpreted as float value: " | |
1096 | "`%s'", macroname, macrovalue); | |
1097 | yylval.float_val = 0.0; | |
1098 | } | |
1099 | } else { | |
1100 | config_process_error_f("No macro or environmental variable defined" | |
1101 | " with name `%s'", macroname); | |
1102 | yylval.float_val = 0.0; | |
1103 | } | |
1104 | Free(macroname); | |
1105 | } else { | |
1106 | config_process_error("Internal error: Macro reference cannot be used in " | |
1107 | "this context."); | |
1108 | yylval.float_val = 0.0; | |
1109 | } | |
1110 | return Float; | |
1111 | } | |
1112 | ||
1113 | {MACRO_ID} { | |
1114 | if (config_defines != NULL) { | |
1115 | char *macroname = get_macro_id_from_ref(yytext); | |
1116 | size_t macrolen; | |
1117 | const char *macrovalue = | |
1118 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1119 | boolean is_asn = FALSE; | |
1120 | if (macrovalue != NULL) { | |
1121 | if (string_is_id(macrovalue, macrolen)) { | |
1122 | yylval.str_val = mcopystr(macrovalue); | |
1123 | for (size_t i = 0; i < macrolen; i++) { | |
1124 | if (yylval.str_val[i]=='-') { | |
1125 | yylval.str_val[i] = '_'; | |
1126 | is_asn = TRUE; | |
1127 | } | |
1128 | } | |
1129 | if (is_asn) | |
1130 | TTCN_warning("In line %d of configuration file: `%s' is not a valid" | |
1131 | " TTCN-3 identifier. Did you mean `%s'?", | |
1132 | current_line, macrovalue, yylval.str_val); | |
1133 | } else { | |
1134 | config_process_error_f("Macro `%s' cannot be interpreted as identifier: " | |
1135 | "`%s'", macroname, macrovalue); | |
1136 | yylval.str_val = memptystr(); | |
1137 | } | |
1138 | } else { | |
1139 | config_process_error_f("No macro or environmental variable defined with " | |
1140 | "name `%s'", macroname); | |
1141 | yylval.str_val = memptystr(); | |
1142 | } | |
1143 | Free(macroname); | |
1144 | return is_asn ? ASN1LowerIdentifier : Identifier; | |
1145 | } else { | |
1146 | config_process_error("Internal error: Macro reference cannot be used in " | |
1147 | "this context."); | |
1148 | yylval.str_val = memptystr(); | |
1149 | return Identifier; | |
1150 | } | |
1151 | } | |
1152 | ||
1153 | {MACRO_CSTR} { | |
1154 | if (config_defines == NULL) { | |
1155 | config_process_error("Internal error: Macro reference cannot be used in " | |
1156 | "this context."); | |
1157 | yylval.charstring_val.n_chars = 0; | |
1158 | yylval.charstring_val.chars_ptr = memptystr(); | |
1159 | return Cstring; | |
1160 | } | |
1161 | ||
1162 | char *macroname; | |
1163 | if (yytext[1] == '{') macroname = get_macro_id_from_ref(yytext); | |
1164 | else macroname = mcopystr(yytext + 1); | |
1165 | size_t macrolen; | |
1166 | const char *macrovalue = string_map_get_bykey | |
1167 | (config_defines, macroname, ¯olen); | |
1168 | ||
1169 | if (macrovalue == NULL) { | |
1170 | config_process_error_f("No macro or environmental variable defined with name " | |
1171 | "`%s'", macroname); | |
1172 | yylval.charstring_val.n_chars=0; | |
1173 | yylval.charstring_val.chars_ptr=memptystr(); | |
1174 | Free(macroname); | |
1175 | return Cstring; | |
1176 | } | |
1177 | ||
1178 | if (macrolen > 0 && macrovalue[0] == '{') { // structured | |
1179 | main_buffer = YY_CURRENT_BUFFER; | |
1180 | expansion_buffer = yy_scan_string(macrovalue); | |
1181 | yy_switch_to_buffer(expansion_buffer); | |
1182 | Free(macroname); | |
1183 | } else { | |
1184 | yylval.charstring_val.n_chars=macrolen; | |
1185 | yylval.charstring_val.chars_ptr=(char*)Malloc(macrolen+1); | |
1186 | memcpy(yylval.charstring_val.chars_ptr, macrovalue, macrolen+1); | |
1187 | Free(macroname); | |
1188 | return Cstring; | |
1189 | } | |
1190 | } | |
1191 | ||
1192 | {MACRO_BSTR} { | |
1193 | if (config_defines != NULL) { | |
1194 | char *macroname = get_macro_id_from_ref(yytext); | |
1195 | size_t macrolen; | |
1196 | const char *macrovalue = | |
1197 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1198 | if (macrovalue != NULL) { | |
1199 | if (string_is_bstr(macrovalue, macrolen)) { | |
1200 | yylval.bitstring_val.n_bits = macrolen; | |
1201 | int n_bytes = (yylval.bitstring_val.n_bits + 7) / 8; | |
1202 | yylval.bitstring_val.bits_ptr = (unsigned char *)Malloc(n_bytes); | |
1203 | memset(yylval.bitstring_val.bits_ptr, 0, n_bytes); | |
1204 | for (int i = 0; i < yylval.bitstring_val.n_bits; i++) | |
1205 | if (macrovalue[i] == '1') | |
1206 | yylval.bitstring_val.bits_ptr[i/8] |= 1 << (i % 8); | |
1207 | } else { | |
1208 | config_process_error_f("Macro `%s' cannot be interpreted as bitstring " | |
1209 | "value: `%s'", macroname, macrovalue); | |
1210 | yylval.bitstring_val.n_bits = 0; | |
1211 | yylval.bitstring_val.bits_ptr = NULL; | |
1212 | } | |
1213 | } else { | |
1214 | config_process_error_f("No macro or environmental variable defined with " | |
1215 | "name `%s'", macroname); | |
1216 | yylval.bitstring_val.n_bits = 0; | |
1217 | yylval.bitstring_val.bits_ptr = NULL; | |
1218 | } | |
1219 | Free(macroname); | |
1220 | } else { | |
1221 | config_process_error_f("Internal error: Macro reference cannot be used in " | |
1222 | "this context."); | |
1223 | yylval.bitstring_val.n_bits = 0; | |
1224 | yylval.bitstring_val.bits_ptr = NULL; | |
1225 | } | |
1226 | return Bstring; | |
1227 | } | |
1228 | ||
1229 | {MACRO_HSTR} { | |
1230 | if (config_defines != NULL) { | |
1231 | char *macroname = get_macro_id_from_ref(yytext); | |
1232 | size_t macrolen; | |
1233 | const char *macrovalue = | |
1234 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1235 | if (macrovalue != NULL) { | |
1236 | if(string_is_hstr(macrovalue, macrolen)) { | |
1237 | yylval.hexstring_val.n_nibbles = macrolen; | |
1238 | int n_bytes = (yylval.hexstring_val.n_nibbles + 1) / 2; | |
1239 | yylval.hexstring_val.nibbles_ptr = (unsigned char *)Malloc(n_bytes); | |
1240 | memset(yylval.hexstring_val.nibbles_ptr, 0, n_bytes); | |
1241 | for (int i = 0; i < yylval.hexstring_val.n_nibbles; i++) { | |
1242 | unsigned int hex_digit; | |
1243 | sscanf(macrovalue+i, "%1x", &hex_digit); | |
1244 | if(i % 2) yylval.hexstring_val.nibbles_ptr[i/2] |= | |
1245 | (hex_digit << 4); | |
1246 | else yylval.hexstring_val.nibbles_ptr[i/2] |= hex_digit; | |
1247 | } | |
1248 | } else { | |
1249 | config_process_error_f("Macro `%s' cannot be interpreted as hexstring " | |
1250 | "value: `%s'", macroname, macrovalue); | |
1251 | yylval.hexstring_val.n_nibbles = 0; | |
1252 | yylval.hexstring_val.nibbles_ptr = NULL; | |
1253 | } | |
1254 | } else { | |
1255 | config_process_error_f("No macro or environmental variable defined with " | |
1256 | "name `%s'", macroname); | |
1257 | yylval.hexstring_val.n_nibbles = 0; | |
1258 | yylval.hexstring_val.nibbles_ptr = NULL; | |
1259 | } | |
1260 | Free(macroname); | |
1261 | } else { | |
1262 | config_process_error("Internal error: Macro reference cannot be used in " | |
1263 | "this context."); | |
1264 | yylval.hexstring_val.n_nibbles = 0; | |
1265 | yylval.hexstring_val.nibbles_ptr = NULL; | |
1266 | } | |
1267 | return Hstring; | |
1268 | } | |
1269 | ||
1270 | {MACRO_OSTR} { | |
1271 | if (config_defines != NULL) { | |
1272 | char *macroname = get_macro_id_from_ref(yytext); | |
1273 | size_t macrolen; | |
1274 | const char *macrovalue = | |
1275 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1276 | if (macrovalue != NULL) { | |
1277 | if (string_is_ostr(macrovalue, macrolen)) { | |
1278 | yylval.octetstring_val.n_octets = macrolen / 2; | |
1279 | yylval.octetstring_val.octets_ptr = (unsigned char *) | |
1280 | Malloc(yylval.octetstring_val.n_octets); | |
1281 | for (int i = 0; i < yylval.octetstring_val.n_octets; i++) { | |
1282 | unsigned int this_octet; | |
1283 | sscanf(macrovalue+2*i, "%2x", &this_octet); | |
1284 | yylval.octetstring_val.octets_ptr[i] = this_octet; | |
1285 | } | |
1286 | } else { | |
1287 | config_process_error_f("Macro `%s' cannot be interpreted as octetstring " | |
1288 | "value: `%s'", macroname, macrovalue); | |
1289 | yylval.octetstring_val.n_octets = 0; | |
1290 | yylval.octetstring_val.octets_ptr = NULL; | |
1291 | } | |
1292 | } else { | |
1293 | config_process_error_f("No macro or environmental variable defined with " | |
1294 | "name `%s'", macroname); | |
1295 | yylval.octetstring_val.n_octets = 0; | |
1296 | yylval.octetstring_val.octets_ptr = NULL; | |
1297 | } | |
1298 | Free(macroname); | |
1299 | } else { | |
1300 | config_process_error_f("Internal error: Macro reference cannot be used in " | |
1301 | "this context."); | |
1302 | yylval.octetstring_val.n_octets = 0; | |
1303 | yylval.octetstring_val.octets_ptr = NULL; | |
1304 | } | |
1305 | return Ostring; | |
1306 | } | |
1307 | ||
1308 | {MACRO_BINARY} { | |
1309 | if (config_defines != NULL) { | |
1310 | char *macroname = get_macro_id_from_ref(yytext); | |
1311 | size_t macrolen; | |
1312 | const char *macrovalue = | |
1313 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1314 | if (macrovalue != NULL) { | |
1315 | yylval.octetstring_val.n_octets=macrolen; | |
1316 | yylval.octetstring_val.octets_ptr = (unsigned char*)Malloc(macrolen); | |
1317 | memcpy(yylval.octetstring_val.octets_ptr, macrovalue, macrolen); | |
1318 | } | |
1319 | else { | |
1320 | config_process_error_f("No macro or environmental variable defined with " | |
1321 | "name `%s'", macroname); | |
1322 | yylval.octetstring_val.n_octets = 0; | |
1323 | yylval.octetstring_val.octets_ptr = NULL; | |
1324 | } | |
1325 | Free(macroname); | |
1326 | } else { | |
1327 | config_process_error("Internal error: Macro reference cannot be used in " | |
1328 | "this context."); | |
1329 | yylval.octetstring_val.n_octets = 0; | |
1330 | yylval.octetstring_val.octets_ptr = NULL; | |
1331 | } | |
1332 | return Ostring; | |
1333 | } | |
1334 | ||
1335 | {MACRO_HOSTNAME} { | |
1336 | if (config_defines != NULL) { | |
1337 | char *macroname = get_macro_id_from_ref(yytext); | |
1338 | size_t macrolen; | |
1339 | const char *macrovalue = | |
1340 | string_map_get_bykey(config_defines, macroname, ¯olen); | |
1341 | if (macrovalue != NULL) { | |
1342 | if (!string_is_hostname(macrovalue, macrolen)) { | |
1343 | config_process_error_f("Macro `%s' cannot be interpreted as host name: " | |
1344 | "`%s'", macroname, macrovalue); | |
1345 | } | |
1346 | } else { | |
1347 | config_process_error_f("No macro or environmental variable defined with " | |
1348 | "name `%s'", macroname); | |
1349 | } | |
1350 | Free(macroname); | |
1351 | } else { | |
1352 | config_process_error("Internal error: Macro reference cannot be used in " | |
1353 | "this context."); | |
1354 | } | |
1355 | return DNSName; | |
1356 | } | |
1357 | ||
1358 | ":="|"=" return AssignmentChar; | |
1359 | "&=" return ConcatChar; | |
1360 | ||
1361 | <<EOF>> { | |
1362 | if (expansion_buffer) { | |
1363 | yy_switch_to_buffer(main_buffer); | |
1364 | yy_delete_buffer(expansion_buffer); | |
1365 | expansion_buffer = NULL; | |
1366 | } else { | |
1367 | if (include_chain->size() > 1) { | |
1368 | yy_delete_buffer(YY_CURRENT_BUFFER); | |
1369 | fclose(include_chain->back().fp); | |
1370 | include_chain->pop_back(); | |
1371 | yy_switch_to_buffer(include_chain->back().buffer_state); | |
1372 | current_line = include_chain->back().line_number; | |
1373 | BEGIN(SC_ORDERED_INCLUDE); | |
1374 | } else { | |
1375 | yyterminate(); | |
1376 | return EOF; | |
1377 | } | |
1378 | } | |
1379 | } | |
1380 | ||
1381 | ||
1382 | ||
1383 | . return yytext[0]; | |
1384 | ||
1385 | ||
1386 | %% | |
1387 | ||
1388 | void reset_config_process_lex(const char* fname) | |
1389 | { | |
1390 | if (!include_chain) { | |
1391 | include_chain = new std::deque<IncludeElem<YY_BUFFER_STATE> >(); | |
1392 | } | |
1393 | BEGIN(INITIAL); | |
1394 | current_line = 1; | |
1395 | if (fname) { | |
1396 | include_chain->push_back(IncludeElem<YY_BUFFER_STATE>(std::string(fname), config_process_in)); | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | void config_process_close() { | |
1401 | delete include_chain; | |
1402 | include_chain = NULL; | |
1403 | } | |
1404 | ||
1405 | int config_process_get_current_line() | |
1406 | { | |
1407 | return current_line; | |
1408 | } | |
1409 | ||
1410 |