Value.cc 583 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
/******************************************************************************
balaskoa's avatar
balaskoa committed
2
 * Copyright (c) 2000-2020 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v2.0
Elemer Lelik's avatar
Elemer Lelik committed
5
 * which accompanies this distribution, and is available at
6
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
Elemer Lelik's avatar
Elemer Lelik committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * Contributors:
 *   Baji, Laszlo
 *   Balasko, Jeno
 *   Baranyi, Botond
 *   Beres, Szabolcs
 *   Bibo, Zoltan
 *   Cserveni, Akos
 *   Delic, Adam
 *   Dimitrov, Peter
 *   Feher, Csaba
 *   Forstner, Matyas
 *   Gecse, Roland
 *   Kovacs, Ferenc
 *   Ormandi, Matyas
 *   Raduly, Csaba
 *   Szabados, Kristof
24
 *   Szabo, Bence Janos
Elemer Lelik's avatar
Elemer Lelik committed
25
26
27
28
29
30
 *   Szabo, Janos Zoltan – initial implementation
 *   Szalai, Gabor
 *   Tatarka, Gabor
 *   Zalanyi, Balazs Andor
 *
 ******************************************************************************/
Elemer Lelik's avatar
Elemer Lelik committed
31
32
#include "../common/dbgnew.hh"
#include "Value.hh"
33
#include "AST.hh"
Elemer Lelik's avatar
Elemer Lelik committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Identifier.hh"
#include "Valuestuff.hh"
#include "PredefFunc.hh"
#include "CompField.hh"
#include "CompType.hh"
#include "EnumItem.hh"
#include "TypeCompat.hh"
#include "asn1/Block.hh"
#include "asn1/TokenBuf.hh"
#include "Real.hh"
#include "Int.hh"
#include "main.hh"
#include "Setting.hh"
#include "Type.hh"
#include "ttcn3/TtcnTemplate.hh"
#include "ttcn3/ArrayDimensions.hh"
#include "ustring.hh"
#include "../common/pattern.hh"

#include "ttcn3/PatternString.hh"
#include "ttcn3/Statement.hh"

#include "ttcn3/Attributes.hh"
57
#include "ttcn3/JsonAST.hh"
Elemer Lelik's avatar
Elemer Lelik committed
58
#include "../common/JSON_Tokenizer.hh"
Elemer Lelik's avatar
Elemer Lelik committed
59
#include "ttcn3/Ttcn2Json.hh"
60
#include "ttcn3/Ttcnstuff.hh"
Elemer Lelik's avatar
Elemer Lelik committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

#include <regex.h>
#include <limits.h>

namespace Common {

  static void clean_up_string_elements(map<size_t, Value>*& string_elements)
  {
    if (string_elements) {
      for (size_t i = 0; i < string_elements->size(); i++)
	delete string_elements->get_nth_elem(i);
      string_elements->clear();
      delete string_elements;
      string_elements = 0;
    }
  }

  // =================================
  // ===== Value
  // =================================

  Value::Value(const Value& p)
83
    : GovernedSimple(p), valuetype(p.valuetype), my_governor(p.my_governor)
84
    , in_brackets(p.in_brackets)
Elemer Lelik's avatar
Elemer Lelik committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  {
    switch(valuetype) {
    case V_ERROR:
    case V_NULL:
    case V_OMIT:
    case V_TTCN3_NULL:
    case V_DEFAULT_NULL:
    case V_FAT_NULL:
    case V_NOTUSED:
      break;
    case V_BOOL:
      u.val_bool=p.u.val_bool;
      break;
    case V_INT:
      u.val_Int=new int_val_t(*(p.u.val_Int));
      break;
    case V_NAMEDINT:
    case V_ENUM:
    case V_UNDEF_LOWERID:
      u.val_id=p.u.val_id->clone();
      break;
    case V_REAL:
      u.val_Real=p.u.val_Real;
      break;
    case V_BSTR:
    case V_HSTR:
    case V_OSTR:
    case V_CSTR:
    case V_ISO2022STR:
      set_val_str(new string(*p.u.str.val_str));
      break;
    case V_USTR:
      set_val_ustr(new ustring(*p.u.ustr.val_ustr));
      u.ustr.convert_str = p.u.ustr.convert_str;
      break;
    case V_CHARSYMS:
      u.char_syms = p.u.char_syms->clone();
      break;
    case V_OID:
    case V_ROID:
      u.oid_comps=new vector<OID_comp>;
      for(size_t i=0; i<p.u.oid_comps->size(); i++)
        add_oid_comp((*p.u.oid_comps)[i]->clone());
      break;
    case V_CHOICE:
      u.choice.alt_name=p.u.choice.alt_name->clone();
      u.choice.alt_value=p.u.choice.alt_value->clone();
      break;
    case V_SEQOF:
    case V_SETOF:
    case V_ARRAY:
      u.val_vs=p.u.val_vs->clone();
      break;
    case V_SEQ:
    case V_SET:
      u.val_nvs=p.u.val_nvs->clone();
      break;
    case V_REFD:
      u.ref.ref=p.u.ref.ref->clone();
      u.ref.refd_last=0;
      break;
    case V_NAMEDBITS:
      for(size_t i=0; i<p.u.ids->size(); i++) {
        Identifier *id = p.u.ids->get_nth_elem(i);
        u.ids->add(id->get_name(), id->clone());
      }
      break;
    case V_UNDEF_BLOCK:
      u.block=p.u.block->clone();
      break;
    case V_VERDICT:
      u.verdict=p.u.verdict;
      break;
    case V_EXPR:
      u.expr.v_optype = p.u.expr.v_optype;
      u.expr.state = EXPR_NOT_CHECKED;
      switch(u.expr.v_optype) {
      case OPTYPE_RND: // -
      case OPTYPE_COMP_NULL:
      case OPTYPE_COMP_MTC:
      case OPTYPE_COMP_SYSTEM:
      case OPTYPE_COMP_SELF:
      case OPTYPE_COMP_RUNNING_ANY:
      case OPTYPE_COMP_RUNNING_ALL:
      case OPTYPE_COMP_ALIVE_ANY:
      case OPTYPE_COMP_ALIVE_ALL:
      case OPTYPE_TMR_RUNNING_ANY:
      case OPTYPE_GETVERDICT:
      case OPTYPE_TESTCASENAME:
Elemer Lelik's avatar
Elemer Lelik committed
174
      case OPTYPE_PROF_RUNNING:
175
      case OPTYPE_NOW:
Elemer Lelik's avatar
Elemer Lelik committed
176
        break;
177
178
179
      case OPTYPE_GET_PORT_REF:
        u.expr.type = p.u.expr.type; // the type is not owned, don't copy it
        break;
180
181
182
183
184
      case OPTYPE_COMP_RUNNING: // v1 [r2] b4
      case OPTYPE_COMP_ALIVE:
        u.expr.r2 = p.u.expr.r2 != NULL ? p.u.expr.r2->clone() : NULL;
        u.expr.b4 = p.u.expr.b4;
        // no break
Elemer Lelik's avatar
Elemer Lelik committed
185
186
187
188
189
190
191
192
      case OPTYPE_UNARYPLUS: // v1
      case OPTYPE_UNARYMINUS:
      case OPTYPE_NOT:
      case OPTYPE_NOT4B:
      case OPTYPE_BIT2HEX:
      case OPTYPE_BIT2INT:
      case OPTYPE_BIT2OCT:
      case OPTYPE_BIT2STR:
193
      case OPTYPE_BSON2JSON:
194
      case OPTYPE_CBOR2JSON:
Elemer Lelik's avatar
Elemer Lelik committed
195
196
197
198
199
200
201
202
203
204
205
206
      case OPTYPE_CHAR2INT:
      case OPTYPE_CHAR2OCT:
      case OPTYPE_FLOAT2INT:
      case OPTYPE_FLOAT2STR:
      case OPTYPE_HEX2BIT:
      case OPTYPE_HEX2INT:
      case OPTYPE_HEX2OCT:
      case OPTYPE_HEX2STR:
      case OPTYPE_INT2CHAR:
      case OPTYPE_INT2FLOAT:
      case OPTYPE_INT2STR:
      case OPTYPE_INT2UNICHAR:
207
      case OPTYPE_JSON2BSON:
208
      case OPTYPE_JSON2CBOR:
Elemer Lelik's avatar
Elemer Lelik committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
      case OPTYPE_OCT2BIT:
      case OPTYPE_OCT2CHAR:
      case OPTYPE_OCT2HEX:
      case OPTYPE_OCT2INT:
      case OPTYPE_OCT2STR:
      case OPTYPE_STR2BIT:
      case OPTYPE_STR2FLOAT:
      case OPTYPE_STR2HEX:
      case OPTYPE_STR2INT:
      case OPTYPE_STR2OCT:
      case OPTYPE_UNICHAR2INT:
      case OPTYPE_UNICHAR2CHAR:
      case OPTYPE_ENUM2INT:
      case OPTYPE_RNDWITHVAL:
      case OPTYPE_GET_STRINGENCODING:
      case OPTYPE_DECODE_BASE64:
      case OPTYPE_REMOVE_BOM:
        u.expr.v1=p.u.expr.v1->clone();
        break;
ebensza's avatar
ebensza committed
228
229
230
      case OPTYPE_HOSTID: // [v1]
        u.expr.v1=p.u.expr.v1?p.u.expr.v1->clone():0;
        break;
Elemer Lelik's avatar
Elemer Lelik committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
      case OPTYPE_ADD: // v1 v2
      case OPTYPE_SUBTRACT:
      case OPTYPE_MULTIPLY:
      case OPTYPE_DIVIDE:
      case OPTYPE_MOD:
      case OPTYPE_REM:
      case OPTYPE_CONCAT:
      case OPTYPE_EQ:
      case OPTYPE_LT:
      case OPTYPE_GT:
      case OPTYPE_NE:
      case OPTYPE_GE:
      case OPTYPE_LE:
      case OPTYPE_AND:
      case OPTYPE_OR:
      case OPTYPE_XOR:
      case OPTYPE_AND4B:
      case OPTYPE_OR4B:
      case OPTYPE_XOR4B:
      case OPTYPE_SHL:
      case OPTYPE_SHR:
      case OPTYPE_ROTL:
      case OPTYPE_ROTR:
      case OPTYPE_INT2BIT:
      case OPTYPE_INT2HEX:
      case OPTYPE_INT2OCT:
        u.expr.v1=p.u.expr.v1->clone();
        u.expr.v2=p.u.expr.v2->clone();
        break;
      case OPTYPE_UNICHAR2OCT: // v1 [v2]
      case OPTYPE_OCT2UNICHAR:
      case OPTYPE_ENCODE_BASE64:
        u.expr.v1=p.u.expr.v1->clone();
        u.expr.v2=p.u.expr.v2?p.u.expr.v2->clone():0;
        break;
266
267
      case OPTYPE_UNDEF_RUNNING: // r1 [r2] b4
      case OPTYPE_TMR_RUNNING: // r1 [r2] b4
Elemer Lelik's avatar
Elemer Lelik committed
268
        u.expr.r1=p.u.expr.r1->clone();
269
270
        u.expr.r2 = p.u.expr.r2 != NULL ? p.u.expr.r2->clone() : NULL;
        u.expr.b4 = p.u.expr.b4;
Elemer Lelik's avatar
Elemer Lelik committed
271
        break;
272
273
274
275
276
277
      case OPTYPE_DECODE: // r1 r2 [v3] [v4]
        u.expr.r1 = p.u.expr.r1->clone();
        u.expr.r2 = p.u.expr.r2->clone();
        u.expr.v2 = p.u.expr.v3 != NULL ? p.u.expr.v3->clone() : NULL;
        u.expr.v3 = p.u.expr.v4 != NULL ? p.u.expr.v4->clone() : NULL;
        break;
Elemer Lelik's avatar
Elemer Lelik committed
278
      case OPTYPE_SUBSTR:
279
      case OPTYPE_ENCODE:
Elemer Lelik's avatar
Elemer Lelik committed
280
        u.expr.ti1=p.u.expr.ti1->clone();
281
282
        u.expr.v2 = p.u.expr.v2 != NULL ? p.u.expr.v2->clone() : NULL;
        u.expr.v3 = p.u.expr.v3 != NULL ? p.u.expr.v3->clone() : NULL;
Elemer Lelik's avatar
Elemer Lelik committed
283
284
285
286
287
        break;
      case OPTYPE_REGEXP:
        u.expr.ti1=p.u.expr.ti1->clone();
        u.expr.t2=p.u.expr.t2->clone();
        u.expr.v3=p.u.expr.v3->clone();
288
        u.expr.b4=p.u.expr.b4;
Elemer Lelik's avatar
Elemer Lelik committed
289
290
291
292
293
294
295
296
297
298
299
300
        break;
      case OPTYPE_DECOMP: // v1 v2 v3
        u.expr.v1=p.u.expr.v1->clone();
        u.expr.v2=p.u.expr.v2->clone();
        u.expr.v3=p.u.expr.v3->clone();
        break;
      case OPTYPE_REPLACE:
        u.expr.ti1 = p.u.expr.ti1->clone();
        u.expr.v2 = p.u.expr.v2->clone();
        u.expr.v3 = p.u.expr.v3->clone();
        u.expr.ti4 = p.u.expr.ti4->clone();
        break;
301
302
303
      case OPTYPE_VALUEOF: // ti1 [subrefs2]
        u.expr.subrefs2 = p.u.expr.subrefs2 != NULL ? u.expr.subrefs2->clone() : NULL;
        // fall through
Elemer Lelik's avatar
Elemer Lelik committed
304
305
306
307
      case OPTYPE_LENGTHOF: // ti1
      case OPTYPE_SIZEOF:  // ti1
      case OPTYPE_ISPRESENT:
      case OPTYPE_TTCN2STRING:
308
309
      case OPTYPE_ISVALUE:
      case OPTYPE_ISBOUND:
Elemer Lelik's avatar
Elemer Lelik committed
310
311
        u.expr.ti1=p.u.expr.ti1->clone();
        break;
312
      case OPTYPE_ENCVALUE_UNICHAR: // ti1 [v2] [v3] [v4]
313
314
        u.expr.ti1=p.u.expr.ti1->clone();
        u.expr.v2=p.u.expr.v2?p.u.expr.v2->clone():0;
315
316
        u.expr.v3 = p.u.expr.v3 != NULL ? p.u.expr.v3->clone() : NULL;
        u.expr.v4 = p.u.expr.v4 != NULL ? p.u.expr.v4->clone() : NULL;
317
        break; 
318
      case OPTYPE_DECVALUE_UNICHAR: // r1 r2 [v3] [v4] [v5]
319
320
        u.expr.r1 = p.u.expr.r1->clone();
        u.expr.r2 = p.u.expr.r2->clone();
321
322
323
        u.expr.v3 = p.u.expr.v3 != NULL ? p.u.expr.v3->clone() : NULL;
        u.expr.v4 = p.u.expr.v4 != NULL ? p.u.expr.v4->clone() : NULL;
        u.expr.v5 = p.u.expr.v5 != NULL ? p.u.expr.v5->clone() : NULL;
324
        break;
Elemer Lelik's avatar
Elemer Lelik committed
325
326
327
328
329
330
331
332
      case OPTYPE_TMR_READ:
      case OPTYPE_ACTIVATE:
        u.expr.r1=p.u.expr.r1->clone();
        break;
      case OPTYPE_EXECUTE: // r1 [v2]
        u.expr.r1=p.u.expr.r1->clone();
        u.expr.v2=p.u.expr.v2?p.u.expr.v2->clone():0;
        break;
333
334
335
336
337
      case OPTYPE_CHECKSTATE_ANY: // [r1] v2
      case OPTYPE_CHECKSTATE_ALL:
        u.expr.r1=p.u.expr.r1?p.u.expr.r1->clone():0;
        u.expr.v2=p.u.expr.v2->clone();
        break;
338
339
340
341
342
343
344
345
346
347
348
349
350
351
      case OPTYPE_UNDEF_CREATE:
      case OPTYPE_CLASS_CREATE:
        u.expr.r1 = p.u.expr.r1->clone();
        if (p.u.expr.state != EXPR_CHECKED) {
          u.expr.t_list2 = p.u.expr.t_list2->clone();
        }
        else {
          u.expr.ap_list2 = p.u.expr.ap_list2->clone();
          u.expr.state = EXPR_CHECKED;
        }
        if (u.expr.v_optype == OPTYPE_UNDEF_CREATE) {
          u.expr.b4 = p.u.expr.b4;
        }
        break;
Elemer Lelik's avatar
Elemer Lelik committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
      case OPTYPE_COMP_CREATE: // r1 [v2] [v3]
        u.expr.r1=p.u.expr.r1->clone();
        u.expr.v2=p.u.expr.v2?p.u.expr.v2->clone():0;
        u.expr.v3=p.u.expr.v3?p.u.expr.v3->clone():0;
        u.expr.b4 = p.u.expr.b4;
        break;
      case OPTYPE_MATCH: // v1 t2
        u.expr.v1=p.u.expr.v1->clone();
        u.expr.t2=p.u.expr.t2->clone();
        break;
      case OPTYPE_ISCHOSEN: // r1 i2
        u.expr.r1=p.u.expr.r1->clone();
        u.expr.i2=p.u.expr.i2->clone();
        break;
      case OPTYPE_ISCHOSEN_V: // v1 i2
        u.expr.v1=p.u.expr.v1->clone();
        u.expr.i2=p.u.expr.i2->clone();
        break;
      case OPTYPE_ISCHOSEN_T: // t1 i2
        u.expr.t1=p.u.expr.t1->clone();
        u.expr.i2=p.u.expr.i2->clone();
        break;
      case OPTYPE_ACTIVATE_REFD:
        u.expr.v1 = p.u.expr.v1->clone();
        if(p.u.expr.state!=EXPR_CHECKED)
          u.expr.t_list2 = p.u.expr.t_list2->clone();
        else {
          u.expr.ap_list2 = p.u.expr.ap_list2->clone();
          u.expr.state = EXPR_CHECKED;
          }
        break;
      case OPTYPE_EXECUTE_REFD:
        u.expr.v1 = p.u.expr.v1->clone();
        if(p.u.expr.state!=EXPR_CHECKED)
          u.expr.t_list2 = p.u.expr.t_list2->clone();
        else {
          u.expr.ap_list2 = p.u.expr.ap_list2->clone();
          u.expr.state = EXPR_CHECKED;
          }
        u.expr.v3 = p.u.expr.v3 ? p.u.expr.v3->clone() : 0;
        break;
      case OPTYPE_LOG2STR:
394
      case OPTYPE_ANY2UNISTR:
Elemer Lelik's avatar
Elemer Lelik committed
395
396
        u.expr.logargs = p.u.expr.logargs->clone();
        break;
397
398
399
400
      case OPTYPE_ISTEMPLATEKIND:
        u.expr.ti1 = p.u.expr.ti1->clone();
        u.expr.v2 = p.u.expr.v2->clone();
        break;
401
402
403
404
405
406
407
408
409
      case OPTYPE_OF_CLASS:
      case OPTYPE_CLASS_CASTING:
        u.expr.type = p.u.expr.type->clone();
        u.expr.r2 = p.u.expr.r2->clone();
        break;
      case OPTYPE_CLASS_CASTING_REF:
        u.expr.r1 = p.u.expr.r1->clone();
        u.expr.r2 = p.u.expr.r2->clone();
        break;
Elemer Lelik's avatar
Elemer Lelik committed
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
      default:
        FATAL_ERROR("Value::Value()");
      } // switch
      break;
    case V_MACRO:
      u.macro = p.u.macro;
      break;
    case V_FUNCTION:
    case V_ALTSTEP:
    case V_TESTCASE:
      u.refd_fat = p.u.refd_fat;
      break;
    case V_INVOKE:
      u.invoke.v = p.u.invoke.v->clone();
      u.invoke.t_list = p.u.invoke.t_list?p.u.invoke.t_list->clone():0;
      u.invoke.ap_list = p.u.invoke.ap_list?p.u.invoke.ap_list->clone():0;
      break;
    case V_REFER:
      u.refered = p.u.refered->clone();
      break;
430
431
432
433
    case V_ANY_VALUE:
    case V_ANY_OR_OMIT:
      u.len_res = p.u.len_res != NULL ? p.u.len_res->clone() : NULL;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
434
435
436
437
438
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

439
440
441
  void Value::chk_expr_immutability() {
    switch (valuetype) {
      case V_REFD: {/**< referenced */
442
        Ttcn::Reference* ttcn_ref = dynamic_cast<Ttcn::Reference*>(u.ref.ref);
443
444
        if (ttcn_ref != NULL) {
          ttcn_ref->chk_immutability();
445
446
447
448
449
450
        }
        break;}
      case V_EXPR: /**< expressions */
        switch (u.expr.v_optype) {
          case OPTYPE_TESTCASENAME: // -
            break;
451
452
453
          case OPTYPE_NOW: // -
            error("Operation 'now' cannot be used in alt guards.");
            break;
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
          case OPTYPE_RND: // -
          case OPTYPE_RNDWITHVAL: /** \todo -> SEED */ // v1
            warning("Random number generation 'rnd()' change the actual snapshot.");
            break;
          case OPTYPE_UNARYPLUS: // v1
          case OPTYPE_UNARYMINUS: // v1
          case OPTYPE_NOT: // v1
          case OPTYPE_NOT4B: // v1
          case OPTYPE_BIT2HEX: // v1  6
          case OPTYPE_BIT2INT: // v1
          case OPTYPE_BIT2OCT: // v1
          case OPTYPE_BIT2STR: // v1
          case OPTYPE_CHAR2INT: // v1  10
          case OPTYPE_CHAR2OCT: // v1
          case OPTYPE_FLOAT2INT: // v1
          case OPTYPE_FLOAT2STR: // v1
          case OPTYPE_HEX2BIT: // v1
          case OPTYPE_HEX2INT: // v1
          case OPTYPE_HEX2OCT: // v1
          case OPTYPE_HEX2STR: // v1
          case OPTYPE_INT2CHAR: // v1
          case OPTYPE_INT2FLOAT: // v1
          case OPTYPE_INT2STR: // v1   20
          case OPTYPE_INT2UNICHAR: // v1
          case OPTYPE_OCT2BIT: // v1
          case OPTYPE_OCT2CHAR: // v1
          case OPTYPE_OCT2HEX: // v1
          case OPTYPE_OCT2INT: // v1
          case OPTYPE_OCT2STR: // v1
          case OPTYPE_STR2BIT: // v1
          case OPTYPE_STR2FLOAT: // v1
          case OPTYPE_STR2HEX: // v1
          case OPTYPE_STR2INT: // v1    30
          case OPTYPE_STR2OCT: // v1
          case OPTYPE_UNICHAR2INT: // v1
          case OPTYPE_UNICHAR2CHAR: // v1
          case OPTYPE_ENUM2INT: // v1
          case OPTYPE_REMOVE_BOM: //v1
          case OPTYPE_GET_STRINGENCODING: //v1
          case OPTYPE_DECODE_BASE64: //v1
          case OPTYPE_CBOR2JSON: // v1
          case OPTYPE_JSON2CBOR: // v1
          case OPTYPE_BSON2JSON: // v1
          case OPTYPE_JSON2BSON: // v1
            u.expr.v1->chk_expr_immutability();
            break;
          case OPTYPE_UNICHAR2OCT: // v1 [v2]
          case OPTYPE_OCT2UNICHAR: // v1 [v2]
          case OPTYPE_ENCODE_BASE64: //v1 [v2]
            u.expr.v1->chk_expr_immutability();
            if (u.expr.v2) u.expr.v2->chk_expr_immutability();
            break;
          case OPTYPE_ADD: // v1 v2
          case OPTYPE_SUBTRACT: // v1 v2
          case OPTYPE_MULTIPLY: // v1 v2
          case OPTYPE_DIVIDE: // v1 v2      40
          case OPTYPE_MOD: // v1 v2
          case OPTYPE_REM: // v1 v2
          case OPTYPE_CONCAT: // v1 v2
          case OPTYPE_EQ: // v1 v2 ==
          case OPTYPE_LT: // v1 v2 <
          case OPTYPE_GT: // v1 v2 >
          case OPTYPE_NE: // v1 v2 !=
          case OPTYPE_GE: // v1 v2 >=
          case OPTYPE_LE: // v1 v2 <=
          case OPTYPE_AND: // v1 v2    50
          case OPTYPE_OR: // v1 v2
          case OPTYPE_XOR: // v1 v2
          case OPTYPE_AND4B: // v1 v2
          case OPTYPE_OR4B: // v1 v2
          case OPTYPE_XOR4B: // v1 v2
          case OPTYPE_SHL: // v1 v2
          case OPTYPE_SHR: // v1 v2
          case OPTYPE_ROTL: // v1 v2
          case OPTYPE_ROTR: // v1 v2
          case OPTYPE_INT2BIT: // v1 v2    60
          case OPTYPE_INT2HEX: // v1 v2
          case OPTYPE_INT2OCT: // v1 v2
            u.expr.v1->chk_expr_immutability();
            u.expr.v2->chk_expr_immutability();
            break;
          case OPTYPE_ENCODE: // ti1 [v2] [v3] 35
          case OPTYPE_DECODE: // r1 r2 [v3] [v4]
            // not yet done.
            break;
          case OPTYPE_SUBSTR:
            u.expr.ti1->chk_immutability();
            u.expr.v2->chk_expr_immutability();
            u.expr.v3->chk_expr_immutability();
            break;
          case OPTYPE_REGEXP: 
            u.expr.ti1->chk_immutability();
            u.expr.t2->chk_immutability();
            u.expr.v3->chk_expr_immutability();
            break;
          case OPTYPE_DECOMP: // not implemented (reference guide)
            u.expr.v1->chk_expr_immutability();
            u.expr.v2->chk_expr_immutability();
            u.expr.v3->chk_expr_immutability();
            break;
          case OPTYPE_REPLACE: // ti1 v2 v3 ti4
            u.expr.ti1->chk_immutability();
            u.expr.v2->chk_expr_immutability();
            u.expr.v3->chk_expr_immutability();
            u.expr.ti4->chk_immutability();
            break;
          case OPTYPE_ISVALUE: // ti1   68
          case OPTYPE_ISBOUND: // ti1
          case OPTYPE_ISPRESENT: // ti1
          case OPTYPE_LENGTHOF: // ti1
          case OPTYPE_SIZEOF: // ti1 
          case OPTYPE_VALUEOF: // ti1
          case OPTYPE_TTCN2STRING: // ti1
            u.expr.ti1->chk_immutability();
            break;
          case OPTYPE_ISCHOSEN: // r1 i2
            break;
          case OPTYPE_ISCHOSEN_V: // v1 i2
            u.expr.v1->chk_expr_immutability();
            break;
          case OPTYPE_ISCHOSEN_T: // t1 i2
            u.expr.t1->chk_immutability();
            break;
          case OPTYPE_MATCH: // v1 t2
            u.expr.v1->chk_expr_immutability();
            u.expr.t2->chk_immutability();
            break;
          case OPTYPE_UNDEF_RUNNING:
          case OPTYPE_COMP_NULL:
          case OPTYPE_COMP_MTC:
          case OPTYPE_COMP_SYSTEM:
          case OPTYPE_COMP_SELF:
586
587
          case OPTYPE_UNDEF_CREATE:
          case OPTYPE_CLASS_CREATE: // todo
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
          case OPTYPE_COMP_CREATE: // r1 [v2] [v3] b4
            break;
          case OPTYPE_COMP_RUNNING: // v1 [r2] b4
          case OPTYPE_COMP_RUNNING_ANY: // -
          case OPTYPE_COMP_RUNNING_ALL: // -
          case OPTYPE_COMP_ALIVE: // v1
          case OPTYPE_COMP_ALIVE_ANY: // -
          case OPTYPE_COMP_ALIVE_ALL: // -
            warning("State of component(s) may change during the actual snapshot.");
            break;
          case OPTYPE_TMR_READ: // r1     90
          case OPTYPE_TMR_RUNNING: // r1 [r2] b4
          case OPTYPE_TMR_RUNNING_ANY: // -
            warning("State of timer(s) may change during the actual snapshot.");
            break;
          case OPTYPE_GETVERDICT: // -
          case OPTYPE_ACTIVATE: // r1
          case OPTYPE_ACTIVATE_REFD: //v1 t_list2
          case OPTYPE_EXECUTE: // r1 [v2]
          case OPTYPE_EXECUTE_REFD: // v1 t_list2 [v3]
          case OPTYPE_LOG2STR: // logargs
          case OPTYPE_PROF_RUNNING: // -     99
          case OPTYPE_ENCVALUE_UNICHAR: // ti1 [v2] [v3] [v4]
          case OPTYPE_DECVALUE_UNICHAR: // r1 r2 [v3] [v4] [v5]
          case OPTYPE_GET_PORT_REF: // -optypes
          case OPTYPE_ANY2UNISTR: // logarg: length = 1
            break;
          case OPTYPE_CHECKSTATE_ANY: // [r1] v2: port or any
          case OPTYPE_CHECKSTATE_ALL: // [r1] v2: port or all
617
            warning("State of port(s) may change during the actual snapshot.");
618
619
620
621
622
623
624
625
            break;
          case OPTYPE_HOSTID: // [v1]
            if (u.expr.v1) u.expr.v1->chk_expr_immutability();
            break;
          case OPTYPE_ISTEMPLATEKIND: // ti1 v2
            u.expr.v2->chk_expr_immutability();
            u.expr.ti1->chk_immutability();
            break;
626
627
628
629
630
631
632
633
          case OPTYPE_OF_CLASS:
          case OPTYPE_CLASS_CASTING:
            u.expr.r2->chk_immutability();
            break;
          case OPTYPE_CLASS_CASTING_REF:
            u.expr.r1->chk_immutability();
            u.expr.r2->chk_immutability();
            break;
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
          default:
            FATAL_ERROR("Value::chk_expr_immutability()");
        }
        break;
      case V_ERROR: /**< erroneous */
      case V_UNDEF_LOWERID: /**< undefined loweridentifier */
      case V_NULL: /**< NULL (for ASN.1 NULL type: also in TTCN-3) */
      case V_BOOL: /**< boolean */
      case V_NAMEDINT: /**< integer / named number */
      case V_NAMEDBITS: /**< named bits (identifiers) */
      case V_INT: /**< integer */
      case V_REAL: /**< real/float */
      case V_ENUM: /**< enumerated */
      case V_BSTR: /**< bitstring */
      case V_HSTR: /**< hexstring */
      case V_OSTR: /**< octetstring */
      case V_CSTR: /**< charstring */
      case V_USTR: /**< universal charstring */
      case V_ISO2022STR: /**< ISO-2022 string (treat as octetstring) */
      case V_CHARSYMS: /**< parsed ASN.1 universal string notation */
      case V_OID: /**< object identifier */
      case V_ROID: /**< relative object identifier */
      case V_CHOICE: /**< choice; set directly by the ASN.1 parser */
      case V_SEQOF: /**< sequence (record) of */
      case V_SETOF: /**< set of */
      case V_ARRAY: /**< array */
      case V_SEQ: /**< sequence (record) */
        // TODO test?
      case V_SET: /**< set */
      case V_OPENTYPE: /**< open type */
      case V_UNDEF_BLOCK: /**< undefined {block} */
      case V_OMIT: /**< special value for optional values */
      case V_VERDICT: /**< verdict */
      case V_TTCN3_NULL: /**< TTCN-3 null (for component or default references) */
      case V_DEFAULT_NULL: /**< null default reference */
      case V_FAT_NULL: /**< null for function: altstep and testcase */
      case V_MACRO: /**< macros (%%something) */
      case V_NOTUSED: /**< not used symbol ('-') */
      case V_FUNCTION: /**< function */
      case V_ALTSTEP: /**< altstep */
      case V_TESTCASE: /**< testcase */
      case V_INVOKE: /**< invoke operation */
      case V_REFER: /**< refer(function) */
      case V_ANY_VALUE: /**< any value (?) - used by template concatenation */
      case V_ANY_OR_OMIT: /**< any or omit (*) - used by template concatenation */
        break;
      default:
        FATAL_ERROR("Value::chk_expr_immutability()");
    } // switch
  }

Elemer Lelik's avatar
Elemer Lelik committed
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
  void Value::clean_up()
  {
    switch (valuetype) {
    case V_ERROR:
    case V_NULL:
    case V_BOOL:
    case V_REAL:
    case V_OMIT:
    case V_VERDICT:
    case V_TTCN3_NULL:
    case V_DEFAULT_NULL:
    case V_FAT_NULL:
    case V_MACRO:
    case V_NOTUSED:
    case V_FUNCTION:
    case V_ALTSTEP:
    case V_TESTCASE:
      break;
    case V_INT:
      delete u.val_Int;
      break;
    case V_NAMEDINT:
    case V_ENUM:
    case V_UNDEF_LOWERID:
      delete u.val_id;
      break;
    case V_BSTR:
    case V_HSTR:
    case V_OSTR:
    case V_CSTR:
    case V_ISO2022STR:
      delete u.str.val_str;
      clean_up_string_elements(u.str.str_elements);
      break;
    case V_USTR:
      delete u.ustr.val_ustr;
      clean_up_string_elements(u.ustr.ustr_elements);
      break;
    case V_CHARSYMS:
      delete u.char_syms;
      break;
    case V_OID:
    case V_ROID:
      if (u.oid_comps) {
	for(size_t i=0; i<u.oid_comps->size(); i++)
          delete (*u.oid_comps)[i];
	u.oid_comps->clear();
	delete u.oid_comps;
      }
      break;
    case V_EXPR:
      clean_up_expr();
      break;
    case V_CHOICE:
      delete u.choice.alt_name;
      delete u.choice.alt_value;
      break;
    case V_SEQOF:
    case V_SETOF:
    case V_ARRAY:
      delete u.val_vs;
      break;
    case V_SEQ:
    case V_SET:
      delete u.val_nvs;
      break;
    case V_REFD:
      delete u.ref.ref;
      break;
    case V_REFER:
      delete u.refered;
      break;
    case V_INVOKE:
      delete u.invoke.v;
      delete u.invoke.t_list;
      delete u.invoke.ap_list;
      break;
    case V_NAMEDBITS:
      if(u.ids) {
        for(size_t i=0; i<u.ids->size(); i++) delete u.ids->get_nth_elem(i);
        u.ids->clear();
        delete u.ids;
      }
      break;
    case V_UNDEF_BLOCK:
      delete u.block;
      break;
772
773
774
775
    case V_ANY_VALUE:
    case V_ANY_OR_OMIT:
      delete u.len_res;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
    default:
      FATAL_ERROR("Value::clean_up()");
    } // switch
  }

  void Value::clean_up_expr()
  {
    switch (u.expr.state) {
    case EXPR_CHECKING:
    case EXPR_CHECKING_ERR:
      FATAL_ERROR("Value::clean_up_expr()");
    default:
      break;
    }
    switch (u.expr.v_optype) {
    case OPTYPE_RND: // -
    case OPTYPE_COMP_NULL:
    case OPTYPE_COMP_MTC:
    case OPTYPE_COMP_SYSTEM:
    case OPTYPE_COMP_SELF:
    case OPTYPE_COMP_RUNNING_ANY:
    case OPTYPE_COMP_RUNNING_ALL:
    case OPTYPE_COMP_ALIVE_ANY:
    case OPTYPE_COMP_ALIVE_ALL:
    case OPTYPE_TMR_RUNNING_ANY:
    case OPTYPE_GETVERDICT:
    case OPTYPE_TESTCASENAME:
Elemer Lelik's avatar
Elemer Lelik committed
803
    case OPTYPE_PROF_RUNNING:
804
    case OPTYPE_GET_PORT_REF: // type (not owned)
805
    case OPTYPE_NOW:
Elemer Lelik's avatar
Elemer Lelik committed
806
      break;
807
808
809
810
    case OPTYPE_COMP_RUNNING: // v1 [r2] b4
    case OPTYPE_COMP_ALIVE:
      delete u.expr.r2;
      // no break
Elemer Lelik's avatar
Elemer Lelik committed
811
812
813
814
815
816
817
818
    case OPTYPE_UNARYPLUS: // v1
    case OPTYPE_UNARYMINUS:
    case OPTYPE_NOT:
    case OPTYPE_NOT4B:
    case OPTYPE_BIT2HEX:
    case OPTYPE_BIT2INT:
    case OPTYPE_BIT2OCT:
    case OPTYPE_BIT2STR:
819
    case OPTYPE_BSON2JSON:
820
    case OPTYPE_CBOR2JSON:
Elemer Lelik's avatar
Elemer Lelik committed
821
822
823
824
825
826
827
828
829
830
831
832
    case OPTYPE_CHAR2INT:
    case OPTYPE_CHAR2OCT:
    case OPTYPE_FLOAT2INT:
    case OPTYPE_FLOAT2STR:
    case OPTYPE_HEX2BIT:
    case OPTYPE_HEX2INT:
    case OPTYPE_HEX2OCT:
    case OPTYPE_HEX2STR:
    case OPTYPE_INT2CHAR:
    case OPTYPE_INT2FLOAT:
    case OPTYPE_INT2STR:
    case OPTYPE_INT2UNICHAR:
833
    case OPTYPE_JSON2BSON:
834
    case OPTYPE_JSON2CBOR:
Elemer Lelik's avatar
Elemer Lelik committed
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
    case OPTYPE_OCT2BIT:
    case OPTYPE_OCT2CHAR:
    case OPTYPE_OCT2HEX:
    case OPTYPE_OCT2INT:
    case OPTYPE_OCT2STR:
    case OPTYPE_STR2BIT:
    case OPTYPE_STR2FLOAT:
    case OPTYPE_STR2HEX:
    case OPTYPE_STR2INT:
    case OPTYPE_STR2OCT:
    case OPTYPE_UNICHAR2INT:
    case OPTYPE_UNICHAR2CHAR:
    case OPTYPE_ENUM2INT:
    case OPTYPE_RNDWITHVAL:
    case OPTYPE_REMOVE_BOM:
    case OPTYPE_GET_STRINGENCODING:
    case OPTYPE_DECODE_BASE64:
ebensza's avatar
ebensza committed
852
    case OPTYPE_HOSTID:
Elemer Lelik's avatar
Elemer Lelik committed
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
      delete u.expr.v1;
      break;
    case OPTYPE_ADD: // v1 v2
    case OPTYPE_SUBTRACT:
    case OPTYPE_MULTIPLY:
    case OPTYPE_DIVIDE:
    case OPTYPE_MOD:
    case OPTYPE_REM:
    case OPTYPE_CONCAT:
    case OPTYPE_EQ:
    case OPTYPE_LT:
    case OPTYPE_GT:
    case OPTYPE_NE:
    case OPTYPE_GE:
    case OPTYPE_LE:
    case OPTYPE_AND:
    case OPTYPE_OR:
    case OPTYPE_XOR:
    case OPTYPE_AND4B:
    case OPTYPE_OR4B:
    case OPTYPE_XOR4B:
    case OPTYPE_SHL:
    case OPTYPE_SHR:
    case OPTYPE_ROTL:
    case OPTYPE_ROTR:
    case OPTYPE_INT2BIT:
    case OPTYPE_INT2HEX:
    case OPTYPE_INT2OCT:
    case OPTYPE_UNICHAR2OCT:
    case OPTYPE_OCT2UNICHAR:
    case OPTYPE_ENCODE_BASE64:
      delete u.expr.v1;
      delete u.expr.v2;
      break;
887
888
    case OPTYPE_UNDEF_RUNNING: // r1 [r2] b4
    case OPTYPE_TMR_RUNNING: // r1 [r2] b4
889
    case OPTYPE_CLASS_CASTING_REF:
Elemer Lelik's avatar
Elemer Lelik committed
890
891
892
      delete u.expr.r1;
      delete u.expr.r2;
      break;
893
894
895
896
897
898
    case OPTYPE_DECODE: // r1 r2 [v3] [v4]
      delete u.expr.r1;
      delete u.expr.r2;
      delete u.expr.v3;
      delete u.expr.v4;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
899
    case OPTYPE_SUBSTR:
900
    case OPTYPE_ENCODE:
Elemer Lelik's avatar
Elemer Lelik committed
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
      delete u.expr.ti1;
      delete u.expr.v2;
      delete u.expr.v3;
      break;
    case OPTYPE_REGEXP:
      delete u.expr.ti1;
      delete u.expr.t2;
      delete u.expr.v3;
      break;
    case OPTYPE_DECOMP: // v1 v2 v3
      delete u.expr.v1;
      delete u.expr.v2;
      delete u.expr.v3;
      break;
    case OPTYPE_REPLACE:
      delete u.expr.ti1;
      delete u.expr.v2;
      delete u.expr.v3;
      delete u.expr.ti4;
      break;
921
922
923
    case OPTYPE_VALUEOF: // ti1 [subrefs2]
      delete u.expr.subrefs2;
      // fall through
Elemer Lelik's avatar
Elemer Lelik committed
924
925
926
927
928
929
930
931
    case OPTYPE_LENGTHOF: // ti1
    case OPTYPE_SIZEOF:  // ti1
    case OPTYPE_ISVALUE:
    case OPTYPE_ISBOUND:
    case OPTYPE_ISPRESENT:
    case OPTYPE_TTCN2STRING:
      delete u.expr.ti1;
      break;
932
    case OPTYPE_ISTEMPLATEKIND: // ti1 v2
933
934
935
      delete u.expr.ti1;
      delete u.expr.v2;
      break;
936
937
938
939
940
941
942
    case OPTYPE_ENCVALUE_UNICHAR: // ti1 [v2] [v3] [v4]
      delete u.expr.ti1;
      delete u.expr.v2;
      delete u.expr.v3;
      delete u.expr.v4;
      break;
    case OPTYPE_DECVALUE_UNICHAR: // r1 r2 [v3] [v4] [v5]
943
944
945
      delete u.expr.r1;
      delete u.expr.r2;
      delete u.expr.v3;
946
947
      delete u.expr.v4;
      delete u.expr.v5;
948
      break;
Elemer Lelik's avatar
Elemer Lelik committed
949
950
951
952
953
954
955
956
    case OPTYPE_TMR_READ:
    case OPTYPE_ACTIVATE:
      delete u.expr.r1;
      break;
    case OPTYPE_EXECUTE: // r1 [v2]
      delete u.expr.r1;
      delete u.expr.v2;
      break;
957
958
959
960
961
    case OPTYPE_CHECKSTATE_ANY: // [r1] v2
    case OPTYPE_CHECKSTATE_ALL:
      delete u.expr.r1;
      delete u.expr.v2;
      break;
962
963
964
965
966
967
968
969
970
971
    case OPTYPE_UNDEF_CREATE:
    case OPTYPE_CLASS_CREATE:
      delete u.expr.r1;
      if (u.expr.state != EXPR_CHECKED) {
        delete u.expr.t_list2;
      }
      else {
        delete u.expr.ap_list2;
      }
      break;
Elemer Lelik's avatar
Elemer Lelik committed
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
    case OPTYPE_COMP_CREATE: // r1 [v2] [v3] b4
      delete u.expr.r1;
      delete u.expr.v2;
      delete u.expr.v3;
      break;
    case OPTYPE_MATCH: // v1 t2
      delete u.expr.v1;
      delete u.expr.t2;
      break;
    case OPTYPE_ISCHOSEN: // r1 i2
      delete u.expr.r1;
      delete u.expr.i2;
      break;
    case OPTYPE_ISCHOSEN_V: // v1 i2
      delete u.expr.v1;
      delete u.expr.i2;
      break;
    case OPTYPE_ISCHOSEN_T: // t1 i2
      delete u.expr.t1;
      delete u.expr.i2;
      break;
    case OPTYPE_ACTIVATE_REFD: //v1 t_list2
      delete u.expr.v1;
      if(u.expr.state!=EXPR_CHECKED)
        delete u.expr.t_list2;
      else
        delete u.expr.ap_list2;
      break;
    case OPTYPE_EXECUTE_REFD: //v1 t_list2 [v3]
For faster browsing, not all history is shown. View entire blame