Value.cc 528 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
/******************************************************************************
balaskoa's avatar
balaskoa committed
2
 * Copyright (c) 2000-2018 Ericsson Telecom AB
Elemer Lelik's avatar
Elemer Lelik committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "../common/dbgnew.hh"
#include "Value.hh"
#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"
56
#include "ttcn3/JsonAST.hh"
Elemer Lelik's avatar
Elemer Lelik committed
57
#include "../common/JSON_Tokenizer.hh"
Elemer Lelik's avatar
Elemer Lelik committed
58
#include "ttcn3/Ttcn2Json.hh"
Elemer Lelik's avatar
Elemer Lelik committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

#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)
    : GovernedSimple(p), valuetype(p.valuetype), my_governor(0)
82
    , in_brackets(p.in_brackets)
Elemer Lelik's avatar
Elemer Lelik committed
83
84
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
  {
    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
172
      case OPTYPE_PROF_RUNNING:
Elemer Lelik's avatar
Elemer Lelik committed
173
        break;
174
175
176
      case OPTYPE_GET_PORT_REF:
        u.expr.type = p.u.expr.type; // the type is not owned, don't copy it
        break;
177
178
179
180
181
      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
182
183
184
185
186
187
188
189
      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:
190
      case OPTYPE_BSON2JSON:
191
      case OPTYPE_CBOR2JSON:
Elemer Lelik's avatar
Elemer Lelik committed
192
193
194
195
196
197
198
199
200
201
202
203
      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:
204
      case OPTYPE_JSON2BSON:
205
      case OPTYPE_JSON2CBOR:
Elemer Lelik's avatar
Elemer Lelik committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
      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
225
226
227
      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
228
229
230
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
      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;
263
264
      case OPTYPE_UNDEF_RUNNING: // r1 [r2] b4
      case OPTYPE_TMR_RUNNING: // r1 [r2] b4
Elemer Lelik's avatar
Elemer Lelik committed
265
        u.expr.r1=p.u.expr.r1->clone();
266
267
        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
268
        break;
269
270
271
272
273
274
      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
275
      case OPTYPE_SUBSTR:
276
      case OPTYPE_ENCODE:
Elemer Lelik's avatar
Elemer Lelik committed
277
        u.expr.ti1=p.u.expr.ti1->clone();
278
279
        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
280
281
282
283
284
        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();
285
        u.expr.b4=p.u.expr.b4;
Elemer Lelik's avatar
Elemer Lelik committed
286
287
288
289
290
291
292
293
294
295
296
297
        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;
298
299
300
      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
301
302
303
304
      case OPTYPE_LENGTHOF: // ti1
      case OPTYPE_SIZEOF:  // ti1
      case OPTYPE_ISPRESENT:
      case OPTYPE_TTCN2STRING:
305
306
      case OPTYPE_ISVALUE:
      case OPTYPE_ISBOUND:
Elemer Lelik's avatar
Elemer Lelik committed
307
308
        u.expr.ti1=p.u.expr.ti1->clone();
        break;
309
      case OPTYPE_ENCVALUE_UNICHAR: // ti1 [v2] [v3] [v4]
310
311
        u.expr.ti1=p.u.expr.ti1->clone();
        u.expr.v2=p.u.expr.v2?p.u.expr.v2->clone():0;
312
313
        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;
314
        break; 
315
      case OPTYPE_DECVALUE_UNICHAR: // r1 r2 [v3] [v4] [v5]
316
317
        u.expr.r1 = p.u.expr.r1->clone();
        u.expr.r2 = p.u.expr.r2->clone();
318
319
320
        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;
321
        break;
Elemer Lelik's avatar
Elemer Lelik committed
322
323
324
325
326
327
328
329
      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;
330
331
332
333
334
      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;
Elemer Lelik's avatar
Elemer Lelik committed
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
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
      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:
377
      case OPTYPE_ANY2UNISTR:
Elemer Lelik's avatar
Elemer Lelik committed
378
379
        u.expr.logargs = p.u.expr.logargs->clone();
        break;
380
381
382
383
      case OPTYPE_ISTEMPLATEKIND:
        u.expr.ti1 = p.u.expr.ti1->clone();
        u.expr.v2 = p.u.expr.v2->clone();
        break;
Elemer Lelik's avatar
Elemer Lelik committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
      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;
404
405
406
407
    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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
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
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  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;
500
501
502
503
    case V_ANY_VALUE:
    case V_ANY_OR_OMIT:
      delete u.len_res;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
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
    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
531
    case OPTYPE_PROF_RUNNING:
532
    case OPTYPE_GET_PORT_REF: // type (not owned)
Elemer Lelik's avatar
Elemer Lelik committed
533
      break;
534
535
536
537
    case OPTYPE_COMP_RUNNING: // v1 [r2] b4
    case OPTYPE_COMP_ALIVE:
      delete u.expr.r2;
      // no break
Elemer Lelik's avatar
Elemer Lelik committed
538
539
540
541
542
543
544
545
    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:
546
    case OPTYPE_BSON2JSON:
547
    case OPTYPE_CBOR2JSON:
Elemer Lelik's avatar
Elemer Lelik committed
548
549
550
551
552
553
554
555
556
557
558
559
    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:
560
    case OPTYPE_JSON2BSON:
561
    case OPTYPE_JSON2CBOR:
Elemer Lelik's avatar
Elemer Lelik committed
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
    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
579
    case OPTYPE_HOSTID:
Elemer Lelik's avatar
Elemer Lelik committed
580
581
582
583
584
585
586
587
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
      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;
614
615
    case OPTYPE_UNDEF_RUNNING: // r1 [r2] b4
    case OPTYPE_TMR_RUNNING: // r1 [r2] b4
Elemer Lelik's avatar
Elemer Lelik committed
616
617
618
      delete u.expr.r1;
      delete u.expr.r2;
      break;
619
620
621
622
623
624
    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
625
    case OPTYPE_SUBSTR:
626
    case OPTYPE_ENCODE:
Elemer Lelik's avatar
Elemer Lelik committed
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
      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;
647
648
649
    case OPTYPE_VALUEOF: // ti1 [subrefs2]
      delete u.expr.subrefs2;
      // fall through
Elemer Lelik's avatar
Elemer Lelik committed
650
651
652
653
654
655
656
657
    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;
658
    case OPTYPE_ISTEMPLATEKIND: // ti1 v2
659
660
661
      delete u.expr.ti1;
      delete u.expr.v2;
      break;
662
663
664
665
666
667
668
    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]
669
670
671
      delete u.expr.r1;
      delete u.expr.r2;
      delete u.expr.v3;
672
673
      delete u.expr.v4;
      delete u.expr.v5;
674
      break;
Elemer Lelik's avatar
Elemer Lelik committed
675
676
677
678
679
680
681
682
    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;
683
684
685
686
687
    case OPTYPE_CHECKSTATE_ANY: // [r1] v2
    case OPTYPE_CHECKSTATE_ALL:
      delete u.expr.r1;
      delete u.expr.v2;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
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
    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]
      delete u.expr.v1;
      if(u.expr.state!=EXPR_CHECKED)
        delete u.expr.t_list2;
      else
        delete u.expr.ap_list2;
      delete u.expr.v3;
      break;
    case OPTYPE_LOG2STR:
725
    case OPTYPE_ANY2UNISTR:
Elemer Lelik's avatar
Elemer Lelik committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
      delete u.expr.logargs;
      break;
    default:
      FATAL_ERROR("Value::clean_up_expr()");
    } // switch
  }

  void Value::copy_and_destroy(Value *src)
  {
    clean_up();
    valuetype = src->valuetype;
    u = src->u;
    // update the pointer used for caching if it points to the value itself
    if (valuetype == V_REFD && u.ref.refd_last == src) u.ref.refd_last = this;
    src->valuetype = V_ERROR;
    delete src;
  }

  Value::Value(valuetype_t p_vt)
745
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
  {
    switch(valuetype) {
    case V_NULL:
    case V_TTCN3_NULL:
    case V_OMIT:
    case V_NOTUSED:
    case V_ERROR:
      break;
    case V_OID:
    case V_ROID:
      u.oid_comps=new vector<OID_comp>();
      break;
    case V_NAMEDBITS:
      u.ids=new map<string, Identifier>();
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, bool p_val_bool)
767
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
768
769
770
771
772
773
774
775
776
777
778
  {
    switch(valuetype) {
    case V_BOOL:
      u.val_bool=p_val_bool;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, const Int& p_val_Int)
779
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
780
781
782
783
784
785
786
787
788
789
790
  {
    switch(valuetype) {
    case V_INT:
      u.val_Int=new int_val_t(p_val_Int);
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, int_val_t *p_val_Int)
791
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
792
793
794
795
796
797
798
799
800
801
802
  {
    switch(valuetype){
    case V_INT:
      u.val_Int=p_val_Int;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    }
  }

  Value::Value(valuetype_t p_vt, string *p_val_str)
803
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
  {
    if(!p_val_str) FATAL_ERROR("NULL parameter");
    switch(valuetype) {
    case V_BSTR:
    case V_HSTR:
    case V_OSTR:
    case V_CSTR:
    case V_ISO2022STR:
      set_val_str(p_val_str);
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, ustring *p_val_ustr)
820
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
821
822
823
824
825
826
827
  {
    if (p_vt != V_USTR || !p_val_ustr) FATAL_ERROR("Value::Value()");
    set_val_ustr(p_val_ustr);
    u.ustr.convert_str = false;
  }

  Value::Value(valuetype_t p_vt, CharSyms *p_char_syms)
828
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
829
830
831
832
833
834
835
836
837
838
839
840
  {
    if (!p_char_syms) FATAL_ERROR("NULL parameter");
    switch (valuetype) {
    case V_CHARSYMS:
      u.char_syms = p_char_syms;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, Identifier *p_val_id)
841
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
  {
    if(!p_val_id)
      FATAL_ERROR("NULL parameter");
    switch(valuetype) {
    case V_NAMEDINT:
    case V_ENUM:
    case V_UNDEF_LOWERID:
      u.val_id=p_val_id;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, Identifier *p_id, Value *p_val)
857
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
858
859
860
861
862
863
864
865
866
867
868
869
870
871
  {
    if(!p_id || !p_val)
      FATAL_ERROR("NULL parameter");
    switch(valuetype) {
    case V_CHOICE:
      u.choice.alt_name=p_id;
      u.choice.alt_value=p_val;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, const Real& p_val_Real)
872
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
873
874
875
876
877
878
879
880
881
882
883
  {
    switch(valuetype) {
    case V_REAL:
      u.val_Real=p_val_Real;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, Values *p_vs)
884
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
  {
    if(!p_vs) FATAL_ERROR("NULL parameter");
    switch(valuetype) {
    case V_SEQOF:
    case V_SETOF:
    case V_ARRAY:
      u.val_vs=p_vs;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, Value *p_v,
    Ttcn::ParsedActualParameters *p_t_list)
900
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
  {
    if(!p_v || !p_t_list) FATAL_ERROR("NULL parameter");
    switch(valuetype) {
    case V_INVOKE:
      u.invoke.v = p_v;
      u.invoke.t_list = p_t_list;
      u.invoke.ap_list = 0;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    }
  }

  // -
  Value::Value(operationtype_t p_optype)
916
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_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
933
    case OPTYPE_PROF_RUNNING:
Elemer Lelik's avatar
Elemer Lelik committed
934
      break;
935
936
937
    case OPTYPE_GET_PORT_REF:
      u.expr.type = NULL; // will be set during semantic analysis
      break;
Elemer Lelik's avatar
Elemer Lelik committed
938
939
940
941
942
943
944
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  // v1
  Value::Value(operationtype_t p_optype, Value *p_v1)
945
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
946
947
948
949
950
951
952
953
954
955
956
957
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_UNARYPLUS:
    case OPTYPE_UNARYMINUS:
    case OPTYPE_NOT:
    case OPTYPE_NOT4B:
    case OPTYPE_BIT2HEX:
    case OPTYPE_BIT2INT:
    case OPTYPE_BIT2OCT:
    case OPTYPE_BIT2STR:
958
    case OPTYPE_BSON2JSON:
959
    case OPTYPE_CBOR2JSON:
Elemer Lelik's avatar
Elemer Lelik committed
960
961
962
963
964
965
966
967
968
969
970
971
    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:
972
    case OPTYPE_JSON2BSON:
973
    case OPTYPE_JSON2CBOR:
Elemer Lelik's avatar
Elemer Lelik committed
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
    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:
      if(!p_v1) FATAL_ERROR("Value::Value()");
      u.expr.v1=p_v1;
      break;
ebensza's avatar
ebensza committed
994
995
996
    case OPTYPE_HOSTID:
      u.expr.v1=p_v1;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
997
998
999
1000
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
1001
1002
1003
1004
  
  // v1 [r2] b4
  Value::Value(operationtype_t p_optype, Value* p_v1, Ttcn::Ref_base *p_r2,
               bool p_b4)
1005
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_COMP_RUNNING:
    case OPTYPE_COMP_ALIVE:
      if (p_v1 == NULL) {
        FATAL_ERROR("Value::Value()");
      }
      u.expr.v1 = p_v1;
      u.expr.r2 = p_r2;
      u.expr.b4 = p_b4;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
Elemer Lelik's avatar
Elemer Lelik committed
1023
1024
1025

  // ti1
  Value::Value(operationtype_t p_optype, TemplateInstance *p_ti1)
1026
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1027
1028
1029
1030
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
1031
1032
1033
1034
1035
    case OPTYPE_ENCVALUE_UNICHAR:
      u.expr.v2 = NULL;
      u.expr.v3 = NULL;
      u.expr.v4 = NULL;
      // fall through
Elemer Lelik's avatar
Elemer Lelik committed
1036
1037
1038
1039
1040
1041
1042
1043
1044
    case OPTYPE_LENGTHOF:
    case OPTYPE_SIZEOF:
    case OPTYPE_VALUEOF:
    case OPTYPE_ISVALUE:
    case OPTYPE_ISBOUND:
    case OPTYPE_ISPRESENT:
    case OPTYPE_TTCN2STRING:
      if(!p_ti1) FATAL_ERROR("Value::Value()");
      u.expr.ti1=p_ti1;
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
      if (p_optype == OPTYPE_VALUEOF) {
        u.expr.subrefs2 = NULL;
      }
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
  
  // ti1 subrefs2
  Value::Value(operationtype_t p_optype, TemplateInstance* p_ti1,
               Ttcn::FieldOrArrayRefs* p_subrefs2)
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch (p_optype) {
    case OPTYPE_VALUEOF:
      if (p_ti1 == NULL || p_subrefs2 == NULL) {
        FATAL_ERROR("Value::Value()");
      }
      u.expr.ti1 = p_ti1;
      u.expr.subrefs2 = p_subrefs2;
Elemer Lelik's avatar
Elemer Lelik committed
1068
1069
1070
1071
1072
1073
1074
1075
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  // r1
  Value::Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1)
1076
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_TMR_READ:
    case OPTYPE_ACTIVATE:
      if(!p_r1) FATAL_ERROR("Value::Value()");
      u.expr.r1=p_r1;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
1090
1091
1092
1093
  
  // r1 [r2] b4
  Value::Value(operationtype_t p_optype, Ttcn::Ref_base* p_r1, Ttcn::Ref_base* p_r2,
               bool p_b4)
1094
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch (p_optype) {
    case OPTYPE_UNDEF_RUNNING:
      if (p_r1 == NULL) {
        FATAL_ERROR("Value::Value()");
      }
      u.expr.r1 = p_r1;
      u.expr.r2 = p_r2;
      u.expr.b4 = p_b4;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
Elemer Lelik's avatar
Elemer Lelik committed
1111
1112
1113
1114

  // v1 t_list2
  Value::Value(operationtype_t p_optype, Value *p_v1,
      Ttcn::ParsedActualParameters *p_ap_list)
1115
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_ACTIVATE_REFD:
      if(!p_v1 || !p_ap_list) FATAL_ERROR("Value::Value()");
      u.expr.v1 = p_v1;
      u.expr.t_list2 = p_ap_list;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    }
  }

  //v1 t_list2 v3
  Value::Value(operationtype_t p_optype, Value *p_v1,
    Ttcn::ParsedActualParameters *p_t_list2, Value *p_v3)
1133
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_EXECUTE_REFD:
      if(!p_v1 || !p_t_list2) FATAL_ERROR("Value::Value()");
      u.expr.v1 = p_v1;
      u.expr.t_list2 = p_t_list2;
      u.expr.v3 = p_v3;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    }
  }

1149
  // r1 [v2] or [r1] v2
Elemer Lelik's avatar
Elemer Lelik committed
1150
  Value::Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1, Value *p_v2)
1151
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1152
1153
1154
1155
1156
1157
1158
1159
1160
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_EXECUTE:
      if(!p_r1) FATAL_ERROR("Value::Value()");
      u.expr.r1=p_r1;
      u.expr.v2=p_v2;
      break;
1161
1162
1163
1164
1165
1166
    case OPTYPE_CHECKSTATE_ANY:
    case OPTYPE_CHECKSTATE_ALL:
      if(!p_v2) FATAL_ERROR("Value::Value()");
      u.expr.r1=p_r1; // may be null if any port or all port
      u.expr.v2=p_v2;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1167
1168
1169
1170
1171
1172
1173
1174
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  // r1 [v2] [v3] b4
  Value::Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1,
               Value *p_v2, Value *p_v3, bool p_b4)
1175
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_COMP_CREATE:
      if(!p_r1) FATAL_ERROR("Value::Value()");
      u.expr.r1=p_r1;
      u.expr.v2=p_v2;
      u.expr.v3=p_v3;
      u.expr.b4=p_b4;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  // v1 v2
  Value::Value(operationtype_t p_optype, Value *p_v1, Value *p_v2)
1194
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_ADD:
    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:
      if(!p_v1 || !p_v2) FATAL_ERROR("Value::Value()");
      u.expr.v1=p_v1;
      u.expr.v2=p_v2;
      break;
    case OPTYPE_UNICHAR2OCT:
    case OPTYPE_OCT2UNICHAR:
    case OPTYPE_ENCODE_BASE64:
      if(!p_v1) FATAL_ERROR("Value::Value()");
      u.expr.v1=p_v1;
      // p_v2 may be NULL if there is no second param
      u.expr.v2=p_v2;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  // ti1 v2 v3 ti4
  Value::Value(operationtype_t p_optype, TemplateInstance *p_ti1, Value *p_v2,
    Value *p_v3, TemplateInstance *p_ti4) :
1245
      GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch (p_optype) {
    case OPTYPE_REPLACE:
      if (!p_ti1 || !p_v2 || !p_v3 || !p_ti4) FATAL_ERROR("Value::Value()");
      u.expr.ti1 = p_ti1;
      u.expr.v2 = p_v2;
      u.expr.v3 = p_v3;
      u.expr.ti4 = p_ti4;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  // v1 v2 v3
  Value::Value(operationtype_t p_optype, Value *p_v1, Value *p_v2, Value *p_v3)
1264
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1265
1266
1267
1268
1269
1270
1271
1272
1273
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_DECOMP:
      if(!p_v1 || !p_v2 || !p_v3) FATAL_ERROR("Value::Value()");
      u.expr.v1=p_v1;
      u.expr.v2=p_v2;
      u.expr.v3=p_v3;
1274
      break;   
Elemer Lelik's avatar
Elemer Lelik committed
1275
1276
1277
1278
1279
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

1280
1281
  // ti1 [v2]
  Value::Value(operationtype_t p_optype, TemplateInstance *p_ti1,  Value *p_v2)
1282
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
1283
1284
1285
1286
1287
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_ENCVALUE_UNICHAR:
1288
1289
1290
1291
      u.expr.v3 = NULL;
      u.expr.v4 = NULL;
      // fall through
    case OPTYPE_ISTEMPLATEKIND:    
1292
1293
1294
1295
1296
1297
1298
1299
1300
      if(!p_ti1 || !p_v2) FATAL_ERROR("Value::Value()");
      u.expr.ti1=p_ti1;
      u.expr.v2=p_v2;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
  
Elemer Lelik's avatar
Elemer Lelik committed
1301
1302
  // ti1 v2 v3
  Value::Value(operationtype_t p_optype, TemplateInstance *p_ti1, Value *p_v2, Value *p_v3)
1303
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1304
1305
1306
1307
  {
    u.expr.v_optype=p_optype;
    u.expr.state=EXPR_NOT_CHECKED;
    switch(p_optype) {
1308
1309
1310
1311
    case OPTYPE_ENCVALUE_UNICHAR:
      u.expr.v4 = NULL;
      // fall through
    case OPTYPE_SUBSTR:          
Elemer Lelik's avatar
Elemer Lelik committed
1312
1313
1314
1315
1316
      if(!p_ti1 || !p_v2 || !p_v3) FATAL_ERROR("Value::Value()");
      u.expr.ti1 = p_ti1;
      u.expr.v2=p_v2;
      u.expr.v3=p_v3;
      break;
1317
1318
1319
1320
1321
1322
1323
1324
    case OPTYPE_ENCODE:
      if (p_ti1 == NULL) {
        FATAL_ERROR("Value::Value()");
      }
      u.expr.ti1 = p_ti1;
      u.expr.v2 = p_v2;
      u.expr.v3 = p_v3;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1325
1326
1327
1328
1329
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

1330
1331
1332
  // ti1 t2 v3 b4
  Value::Value(operationtype_t p_optype, TemplateInstance *p_ti1,
               TemplateInstance *p_t2, Value *p_v3, bool p_b4)
1333
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1334
1335
1336
1337
1338
1339
1340
1341
  {
    u.expr.v_optype=p_optype;
    u.expr.state=EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_REGEXP:
      if(!p_ti1 || !p_t2 || !p_v3) FATAL_ERROR("Value::Value()");
      u.expr.ti1 = p_ti1;
      u.expr.t2 = p_t2;
1342
1343
      u.expr.v3 = p_v3;
      u.expr.b4 = p_b4;
Elemer Lelik's avatar
Elemer Lelik committed
1344
1345
1346
1347
1348
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
  
  // ti1 v2 v3 v4
  Value::Value(operationtype_t p_optype, TemplateInstance* p_ti1, Value* p_v2,
               Value* p_v3, Value* p_v4)
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch (p_optype) {
    case OPTYPE_ENCVALUE_UNICHAR:
      if (p_ti1 == NULL || p_v2 == NULL || p_v3 == NULL || p_v4 == NULL) {
        FATAL_ERROR("Value::Value()");
      }
      u.expr.ti1 = p_ti1;
      u.expr.v2 = p_v2;
      u.expr.v3 = p_v3;
      u.expr.v4 = p_v4;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    }
  }
Elemer Lelik's avatar
Elemer Lelik committed
1371
1372
1373

  // v1 t2
  Value::Value(operationtype_t p_optype, Value *p_v1, TemplateInstance *p_t2)
1374
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_MATCH:
      if(!p_v1 || !p_t2) FATAL_ERROR("Value::Value()");
      u.expr.v1=p_v1;
      u.expr.t2=p_t2;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  // r1 i2
  Value::Value(operationtype_t p_optype, Ttcn::Reference *p_r1,
               Identifier *p_i2)
1392
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_ISCHOSEN:
      if(!p_r1 || !p_i2) FATAL_ERROR("Value::Value()");
      u.expr.r1=p_r1;
      u.expr.i2=p_i2;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(operationtype_t p_optype, LogArguments *p_logargs)
1408
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1409
1410
1411
1412
1413
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_LOG2STR:
1414
    case OPTYPE_ANY2UNISTR:
Elemer Lelik's avatar
Elemer Lelik committed
1415
1416
1417
1418
1419
1420
1421
1422
1423
      if (!p_logargs) FATAL_ERROR("Value::Value()");
      u.expr.logargs = p_logargs;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, macrotype_t p_macrotype)
1424
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
  {
    if (p_vt != V_MACRO) FATAL_ERROR("Value::Value()");
    switch (p_macrotype) {
    case MACRO_MODULEID:
    case MACRO_FILENAME:
    case MACRO_BFILENAME:
    case MACRO_FILEPATH:
    case MACRO_LINENUMBER:
    case MACRO_LINENUMBER_C:
    case MACRO_DEFINITIONID:
    case MACRO_SCOPE:
    case MACRO_TESTCASEID:
      break;
    default:
      FATAL_ERROR("Value::Value()");
    }
    u.macro = p_macrotype;
  }

  Value::Value(valuetype_t p_vt, NamedValues *p_nvs)
1445
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
  {
    if(!p_nvs) FATAL_ERROR("NULL parameter");
    switch(valuetype) {
    case V_SEQ:
    case V_SET:
      u.val_nvs=p_nvs;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, Reference *p_ref)
1459
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
  {
    if (!p_ref) FATAL_ERROR("NULL parameter: Value::Value()");
    switch(p_vt) {
    case V_REFD:
      u.ref.ref = p_ref;
      u.ref.refd_last = 0;
      break;
    case V_REFER:
      u.refered = p_ref;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    }
  }

  Value::Value(valuetype_t p_vt, Block *p_block)
1476
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
  {
    if(!p_block) FATAL_ERROR("NULL parameter");
    switch(valuetype) {
    case V_UNDEF_BLOCK:
      u.block=p_block;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }

  Value::Value(valuetype_t p_vt, verdict_t p_verdict)
1489
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
  {
    if (valuetype != V_VERDICT) FATAL_ERROR("Value::Value()");
    switch (p_verdict) {
    case Verdict_NONE:
    case Verdict_PASS:
    case Verdict_INCONC:
    case Verdict_FAIL:
    case Verdict_ERROR:
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
    u.verdict = p_verdict;
  }

  Value::Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1, Ttcn::Ref_base *p_r2)
1506
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
Elemer Lelik's avatar
Elemer Lelik committed
1507
1508
1509
1510
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
1511
    case OPTYPE_DECVALUE_UNICHAR:
1512
1513
1514
      u.expr.v5 = NULL;
      // fall through
    case OPTYPE_DECODE:
Elemer Lelik's avatar
Elemer Lelik committed
1515
1516
1517
      if(!p_r1 || !p_r2) FATAL_ERROR("Value::Value()");
      u.expr.r1=p_r1;
      u.expr.r2=p_r2;
1518
      u.expr.v3=NULL;
1519
      u.expr.v4 = NULL;
Elemer Lelik's avatar
Elemer Lelik committed
1520
1521
1522
1523
1524
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
1525
1526
1527
1528
  
  // r1 r2 [v3]
  Value::Value(operationtype_t p_optype, Ttcn::Ref_base *p_r1, Ttcn::Ref_base *p_r2,
          Value *p_v3)
1529
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
1530
1531
1532
1533
1534
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch(p_optype) {
    case OPTYPE_DECVALUE_UNICHAR:
1535
1536
1537
      u.expr.v5 = NULL;
      // fall through
    case OPTYPE_DECODE:
1538
1539
1540
1541
      if(!p_r1 || !p_r2 || !p_v3) FATAL_ERROR("Value::Value()");
      u.expr.r1=p_r1;
      u.expr.r2=p_r2;
      u.expr.v3=p_v3;
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
      u.expr.v4 = NULL;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
  
  // r1 r2 [v3] [v4]
  Value::Value(operationtype_t p_optype, Ttcn::Ref_base* p_r1, Ttcn::Ref_base* p_r2,
               Value* p_v3, Value* p_v4)
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch (p_optype) {
    case OPTYPE_DECVALUE_UNICHAR:
      u.expr.v5 = NULL;
      // fall through
    case OPTYPE_DECODE:
      if(p_r1 == NULL || p_r2 == NULL || p_v3 == NULL || p_v4 == NULL) {
        FATAL_ERROR("Value::Value()");
      }
      u.expr.r1 = p_r1;
      u.expr.r2 = p_r2;
      u.expr.v3 = p_v3;
      u.expr.v4 = p_v4;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
  
  // r1 r2 [v3] [v4] [v5]
  Value::Value(operationtype_t p_optype, Ttcn::Ref_base* p_r1, Ttcn::Ref_base* p_r2,
               Value* p_v3, Value* p_v4, Value* p_v5)
    : GovernedSimple(S_V), valuetype(V_EXPR), my_governor(0), in_brackets(false)
  {
    u.expr.v_optype = p_optype;
    u.expr.state = EXPR_NOT_CHECKED;
    switch (p_optype) {
    case OPTYPE_DECVALUE_UNICHAR:
      if(p_r1 == NULL || p_r2 == NULL || p_v3 == NULL || p_v4 == NULL || p_v5 == NULL) {
        FATAL_ERROR("Value::Value()");
      }
      u.expr.r1 = p_r1;
      u.expr.r2 = p_r2;
      u.expr.v3 = p_v3;
      u.expr.v4 = p_v4;
      u.expr.v5 = p_v5;
1591
1592
1593
1594
1595
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
  
  // V_ANY_VALUE, V_ANY_OR_OMIT
  Value::Value(valuetype_t p_vt, Ttcn::LengthRestriction* p_len_res)
    : GovernedSimple(S_V), valuetype(p_vt), my_governor(0)
  {
    switch(p_vt) {
    case V_ANY_VALUE:
    case V_ANY_OR_OMIT:
      u.len_res = p_len_res;
      break;
    default:
      FATAL_ERROR("Value::Value()");
    } // switch
  }
Elemer Lelik's avatar
Elemer Lelik committed
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626

  Value::~Value()
  {
    clean_up();
  }

  Value *Value::clone() const
  {
    return new Value(*this);
  }

  Value::operationtype_t Value::get_optype() const
  {
    if(valuetype!=V_EXPR)
      FATAL_ERROR("Value::get_optype()");
    return u.expr.v_optype;
  }
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
  
  Value* Value::get_concat_operand(bool first_operand) const
  {
    if (valuetype != V_EXPR || u.expr.v_optype != OPTYPE_CONCAT) {
      FATAL_ERROR("Value::get_concat_operand()");
    }
    return first_operand ? u.expr.v1 : u.expr.v2;
  }
  
  Ttcn::LengthRestriction* Value::take_length_restriction()
  {
    if (valuetype != V_ANY_VALUE && valuetype != V_ANY_OR_OMIT) {
      FATAL_ERROR("Value::take_length_restriction()");
    }
    Ttcn::LengthRestriction* ptr = u.len_res;
    u.len_res = NULL;
    return ptr;
  }
Elemer Lelik's avatar
Elemer Lelik committed
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759

  void Value::set_my_governor(Type *p_gov)
  {
    if(!p_gov)
      FATAL_ERROR("Value::set_my_governor(): NULL parameter");
    my_governor=p_gov;
  }

  Type *Value::get_my_governor() const
  {
    return my_governor;
  }

  void Value::set_fullname(const string& p_fullname)
  {
    GovernedSimple::set_fullname(p_fullname);
    switch(valuetype) {
    case V_CHARSYMS:
      u.char_syms->set_fullname(p_fullname);
      break;
    case V_OID:
    case V_ROID:
      for(size_t i=0; i<u.oid_comps->size(); i++)
        (*u.oid_comps)[i]->set_fullname(p_fullname+"."+Int2string(i+1));
      break;
    case V_CHOICE:
      u.choice.alt_value->set_fullname(p_fullname + "." +
        u.choice.alt_name->get_dispname());
      break;
    case V_SEQOF:
    case V_SETOF:
    case V_ARRAY:
      u.val_vs->set_fullname(p_fullname);
      break;
    case V_SEQ:
    case V_SET:
      u.val_nvs->set_fullname(p_fullname);
      break;
    case V_REFD:
      u.ref.ref->set_fullname(p_fullname);
      break;
    case V_REFER:
      u.refered->set_fullname(p_fullname);
      break;
    case V_INVOKE:
      u.invoke.v->set_fullname(p_fullname);
      if(u.invoke.t_list) u.invoke.t_list->set_fullname(p_fullname);
      if(u.invoke.ap_list) u.invoke.ap_list->set_fullname(p_fullname);
      break;
    case V_EXPR:
      set_fullname_expr(p_fullname);
      break;
    default:
      break;
    } // switch
  }

  void Value::set_my_scope(Scope *p_scope)
  {
    GovernedSimple::set_my_scope(p_scope);
    switch(valuetype) {
    case V_CHARSYMS:
      u.char_syms->set_my_scope(p_scope);
      break;
    case V_OID:
    case V_ROID:
      for(size_t i=0; i<u.oid_comps->size(); i++)
        (*u.oid_comps)[i]->set_my_scope(p_scope);
      break;
    case V_CHOICE:
      u.choice.alt_value->set_my_scope(p_scope);
      break;
    case V_SEQOF:
    case V_SETOF:
    case V_ARRAY:
      u.val_vs->set_my_scope(p_scope);
      break;
    case V_SEQ:
    case V_SET:
      u.val_nvs->set_my_scope(p_scope);
      break;
    case V_REFD:
      u.ref.ref->set_my_scope(p_scope);
      break;
    case V_REFER:
      u.refered->set_my_scope(p_scope);
      break;
    case V_INVOKE:
      u.invoke.v->set_my_scope(p_scope);
      if(u.invoke.t_list) u.invoke.t_list->set_my_scope(p_scope);
      if(u.invoke.ap_list) u.invoke.ap_list->set_my_scope(p_scope);
      break;
    case V_EXPR:
      set_my_scope_expr(p_scope);
      break;
    default:
      break;
    } // switch
  }

  void Value::set_fullname_expr(const string& p_fullname)
  {
    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
1760
    case OPTYPE_PROF_RUNNING:
1761
    case OPTYPE_GET_PORT_REF:
Elemer Lelik's avatar
Elemer Lelik committed
1762
1763
1764
1765
1766
1767
1768
1769
1770
      break;
    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:
1771
    case OPTYPE_BSON2JSON:
1772
    case OPTYPE_CBOR2JSON:
Elemer Lelik's avatar
Elemer Lelik committed
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
    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:
1785
    case OPTYPE_JSON2BSON:
1786
    case OPTYPE_JSON2CBOR:
Elemer Lelik's avatar
Elemer Lelik committed
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
    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:
      u.expr.v1->set_fullname(p_fullname+".<operand>");
      break;
ebensza's avatar
ebensza committed
1806
1807
1808
    case OPTYPE_HOSTID: // [v1]
      if(u.expr.v1) u.expr.v1->set_fullname(p_fullname+".<operand>");
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
    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->set_fullname(p_fullname+".<operand1>");
      u.expr.v2->set_fullname(p_fullname+".<operand2>");
      break;
    case OPTYPE_UNICHAR2OCT:
    case OPTYPE_OCT2UNICHAR:
    case OPTYPE_ENCODE_BASE64:
      u.expr.v1->set_fullname(p_fullname+".<operand1>");
      if(u.expr.v2) u.expr.v2->set_fullname(p_fullname+".<operand2>");
      break;
    case OPTYPE_DECODE:
      u.expr.r1->set_fullname(p_fullname+".<operand1>");
      u.expr.r2->set_fullname(p_fullname+".<operand2>");
1847
1848
1849
1850
1851
1852
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_fullname(p_fullname+".<operand2>");
      }
      if (u.expr.v4 != NULL) {
        u.expr.v4->set_fullname(p_fullname+".<operand3>");
      }
Elemer Lelik's avatar
Elemer Lelik committed
1853
1854
      break;
    case OPTYPE_SUBSTR:
1855
    case OPTYPE_ENCODE:
Elemer Lelik's avatar
Elemer Lelik committed
1856
      u.expr.ti1->set_fullname(p_fullname+".<operand1>");
1857
1858
1859
1860
1861
1862
      if (u.expr.v2 != NULL) {
        u.expr.v2->set_fullname(p_fullname+".<operand2>");
      }
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_fullname(p_fullname+".<operand3>");
      }
Elemer Lelik's avatar
Elemer Lelik committed
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
      break;
    case OPTYPE_REGEXP:
      u.expr.ti1->set_fullname(p_fullname+".<operand1>");
      u.expr.t2->set_fullname(p_fullname+".<operand2>");
      u.expr.v3->set_fullname(p_fullname+".<operand3>");
      break;
    case OPTYPE_DECOMP: // v1 v2 v3
      u.expr.v1->set_fullname(p_fullname+".<operand1>");
      u.expr.v2->set_fullname(p_fullname+".<operand2>");
      u.expr.v3->set_fullname(p_fullname+".<operand3>");
      break;
    case OPTYPE_REPLACE:
      u.expr.ti1->set_fullname(p_fullname+".<operand1>");
      u.expr.v2->set_fullname(p_fullname+".<operand2>");
      u.expr.v3->set_fullname(p_fullname+".<operand3>");
      u.expr.ti4->set_fullname(p_fullname+".<operand4>");
      break;
1880
1881
1882
1883
1884
    case OPTYPE_VALUEOF: // ti1 [subrefs2]
      if (u.expr.subrefs2 != NULL) {
        u.expr.subrefs2->set_fullname(p_fullname + ".<subrefs>");
      }
      // fall through
Elemer Lelik's avatar
Elemer Lelik committed
1885
1886
1887
1888
1889
1890
1891
1892
    case OPTYPE_LENGTHOF: // ti1
    case OPTYPE_SIZEOF:   // ti1
    case OPTYPE_ISVALUE:
    case OPTYPE_ISBOUND:
    case OPTYPE_ISPRESENT:
    case OPTYPE_TTCN2STRING:
      u.expr.ti1->set_fullname(p_fullname+".<operand>");
      break;
1893
1894
1895
1896
    case OPTYPE_ISTEMPLATEKIND: // ti1 v2
      u.expr.ti1->set_fullname(p_fullname+".<operand1>");
      u.expr.v2->set_fullname(p_fullname+".<operand2>");
      break;
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
    case OPTYPE_ENCVALUE_UNICHAR: // ti1 [v2] [v3] [v4]
      u.expr.ti1->set_fullname(p_fullname + ".<operand1>");
      if (u.expr.v2 != NULL) {
        u.expr.v2->set_fullname(p_fullname + ".<operand2>");
      }
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_fullname(p_fullname + ".<operand3>");
      }
      if (u.expr.v4 != NULL) {
        u.expr.v4->set_fullname(p_fullname + ".<operand4>");
      }
      break;
    case OPTYPE_DECVALUE_UNICHAR: // r1 r2 [v3] [v4] [v5]
      u.expr.r1->set_fullname(p_fullname + ".<operand1>");
      u.expr.r2->set_fullname(p_fullname + ".<operand2>");
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_fullname(p_fullname + ".<operand3>");
      }
      if (u.expr.v4 != NULL) {
        u.expr.v4->set_fullname(p_fullname + ".<operand4>");
      }
      if (u.expr.v5 != NULL) {
        u.expr.v4->set_fullname(p_fullname + ".<operand5>");
      }
1921
      break;
1922
    case OPTYPE_TMR_READ: // r1
Elemer Lelik's avatar
Elemer Lelik committed
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
    case OPTYPE_ACTIVATE:
      u.expr.r1->set_fullname(p_fullname+".<operand>");
      break;
    case OPTYPE_EXECUTE: // r1 [v2]
      u.expr.r1->set_fullname(p_fullname+".<operand1>");
      if(u.expr.v2) u.expr.v2->set_fullname(p_fullname+".<operand2>");
      break;
    case OPTYPE_COMP_CREATE: // r1 [v2] [v3] b4
      u.expr.r1->set_fullname(p_fullname+".<operand1>");
      if(u.expr.v2) u.expr.v2->set_fullname(p_fullname+".<operand2>");
      if(u.expr.v3) u.expr.v3->set_fullname(p_fullname+".<operand3>");
      break;
    case OPTYPE_MATCH: // v1 t2
      u.expr.v1->set_fullname(p_fullname+".<operand1>");
      u.expr.t2->set_fullname(p_fullname+".<operand2>");
      break;
    case OPTYPE_ISCHOSEN: // r1 i2
      u.expr.r1->set_fullname(p_fullname+".<operand>");
      break;
    case OPTYPE_ISCHOSEN_V: // v1 i2
      u.expr.v1->set_fullname(p_fullname+".<operand>");
      break;
    case OPTYPE_ISCHOSEN_T: // t1 i2
      u.expr.t1->set_fullname(p_fullname+".<operand>");
      break;
    case OPTYPE_ACTIVATE_REFD:
      u.expr.v1->set_fullname(p_fullname+".<reference>");
      if(u.expr.state!=EXPR_CHECKED)
        u.expr.t_list2->set_fullname(p_fullname+".<parameterlist>");
      else
        u.expr.ap_list2->set_fullname(p_fullname+".<parameterlist>");
      break;
    case OPTYPE_EXECUTE_REFD:
      u.expr.v1->set_fullname(p_fullname+".<reference>");
      if(u.expr.state!=EXPR_CHECKED)
        u.expr.t_list2->set_fullname(p_fullname+".<parameterlist>");
      else
        u.expr.ap_list2->set_fullname(p_fullname+".<parameterlist>");
      if(u.expr.v3)
        u.expr.v3->set_fullname(p_fullname+".<operand3>");
      break;
    case OPTYPE_LOG2STR:
      u.expr.logargs->set_fullname(p_fullname+".<logargs>");
      break;
1967
1968
1969
    case OPTYPE_ANY2UNISTR:
      u.expr.logargs->set_fullname(p_fullname+".<logarg>");
      break;
1970
1971
1972
1973
    case OPTYPE_CHECKSTATE_ANY: // [r1] v2
    case OPTYPE_CHECKSTATE_ALL:
      u.expr.v2->set_fullname(p_fullname+".<operand1>");
      break;
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
    case OPTYPE_UNDEF_RUNNING: // r1 [r2] b4
    case OPTYPE_TMR_RUNNING:
      u.expr.r1->set_fullname(p_fullname+".<operand>");
      if (u.expr.r2 != NULL) {
        u.expr.r2->set_fullname(p_fullname+".redirindex");
      }
      break;
    case OPTYPE_COMP_RUNNING: // v1 [r2] b4
    case OPTYPE_COMP_ALIVE:
      u.expr.v1->set_fullname(p_fullname+".<operand>");
      if (u.expr.r2 != NULL) {
        u.expr.r2->set_fullname(p_fullname+".redirindex");
      }
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
    default:
      FATAL_ERROR("Value::set_fullname_expr()");
    } // switch
  }

  void Value::set_my_scope_expr(Scope *p_scope)
  {
    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
2008
    case OPTYPE_PROF_RUNNING:
2009
    case OPTYPE_GET_PORT_REF:
Elemer Lelik's avatar
Elemer Lelik committed
2010
      break;
2011
2012
2013
2014
2015
2016
    case OPTYPE_COMP_RUNNING: // v1 [r2] b4
    case OPTYPE_COMP_ALIVE:
      if (u.expr.r2 != NULL) {
        u.expr.r2->set_my_scope(p_scope);
      }
      // no break
Elemer Lelik's avatar
Elemer Lelik committed
2017
2018
2019
2020
2021
2022
2023
2024
    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:
2025
    case OPTYPE_BSON2JSON:
2026
    case OPTYPE_CBOR2JSON:
Elemer Lelik's avatar
Elemer Lelik committed
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
    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:
2039
    case OPTYPE_JSON2BSON:
2040
    case OPTYPE_JSON2CBOR:
Elemer Lelik's avatar
Elemer Lelik committed
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
    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:
      u.expr.v1->set_my_scope(p_scope);
      break;
ebensza's avatar
ebensza committed
2060
2061
2062
    case OPTYPE_HOSTID: // [v1]
      if(u.expr.v1) u.expr.v1->set_my_scope(p_scope);
      break;
Elemer Lelik's avatar
Elemer Lelik committed
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
    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->set_my_scope(p_scope);
      u.expr.v2->set_my_scope(p_scope);
      break;
    case OPTYPE_UNICHAR2OCT:
    case OPTYPE_OCT2UNICHAR:
    case OPTYPE_ENCODE_BASE64:
      u.expr.v1->set_my_scope(p_scope);
      if(u.expr.v2) u.expr.v2->set_my_scope(p_scope);
      break;
2098
2099
    case OPTYPE_UNDEF_RUNNING: // r1 [r2] b4
    case OPTYPE_TMR_RUNNING: // r1 [r2] b4
Elemer Lelik's avatar
Elemer Lelik committed
2100
      u.expr.r1->set_my_scope(p_scope);
2101
2102
2103
      if (u.expr.r2 != NULL) {
        u.expr.r2->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2104
      break;
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
    case OPTYPE_DECODE: // r1 r2 [v3] [v4]
      u.expr.r1->set_my_scope(p_scope);
      u.expr.r2->set_my_scope(p_scope);
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_my_scope(p_scope);
      }
      if (u.expr.v4 != NULL) {
        u.expr.v4->set_my_scope(p_scope);
      }
      break;
Elemer Lelik's avatar
Elemer Lelik committed
2115
    case OPTYPE_SUBSTR:
2116
    case OPTYPE_ENCODE:
Elemer Lelik's avatar
Elemer Lelik committed
2117
      u.expr.ti1->set_my_scope(p_scope);
2118
2119
2120
2121
2122
2123
      if (u.expr.v2 != NULL) {
        u.expr.v2->set_my_scope(p_scope);
      }
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
      break;
    case OPTYPE_REGEXP:
      u.expr.ti1->set_my_scope(p_scope);
      u.expr.t2->set_my_scope(p_scope);
      u.expr.v3->set_my_scope(p_scope);
      break;
    case OPTYPE_DECOMP: // v1 v2 v3
      u.expr.v1->set_my_scope(p_scope);
      u.expr.v2->set_my_scope(p_scope);
      u.expr.v3->set_my_scope(p_scope);
      break;
    case OPTYPE_REPLACE:
      u.expr.ti1->set_my_scope(p_scope);
      u.expr.v2->set_my_scope(p_scope);
      u.expr.v3->set_my_scope(p_scope);
      u.expr.ti4->set_my_scope(p_scope);
      break;
2141
2142
2143
2144
2145
    case OPTYPE_VALUEOF: // ti1 [subrefs2]
      if (u.expr.subrefs2 != NULL) {
        u.expr.subrefs2->set_my_scope(p_scope);
      }
      // fall through
Elemer Lelik's avatar
Elemer Lelik committed
2146
2147
2148
2149
2150
2151
2152
2153
    case OPTYPE_LENGTHOF: // ti1
    case OPTYPE_SIZEOF: // ti1
    case OPTYPE_ISVALUE:
    case OPTYPE_ISBOUND:
    case OPTYPE_ISPRESENT:
    case OPTYPE_TTCN2STRING:
      u.expr.ti1->set_my_scope(p_scope);
      break;
2154
2155
2156
2157
    case OPTYPE_ISTEMPLATEKIND: // ti1 v2
      u.expr.ti1->set_my_scope(p_scope);
      u.expr.v2->set_my_scope(p_scope);
      break;
2158
    case OPTYPE_ENCVALUE_UNICHAR: //ti1 [v2] [v3] [v4]
2159
      u.expr.ti1->set_my_scope(p_scope);
2160
2161
2162
2163
2164
2165
2166
2167
2168
      if (u.expr.v2 != NULL) {
        u.expr.v2->set_my_scope(p_scope);
      }
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_my_scope(p_scope);
      }
      if (u.expr.v4 != NULL) {
        u.expr.v4->set_my_scope(p_scope);
      }
2169
      break;
2170
    case OPTYPE_DECVALUE_UNICHAR: // r1 r2 [v3] [v4] [v5]
2171
2172
      u.expr.r1->set_my_scope(p_scope);
      u.expr.r2->set_my_scope(p_scope);
2173
2174
2175
2176
2177
2178
2179
2180
2181
      if (u.expr.v3 != NULL) {
        u.expr.v3->set_my_scope(p_scope);
      }
      if (u.expr.v4 != NULL) {
        u.expr.v4->set_my_scope(p_scope);
      }
      if (u.expr.v5 != NULL) {
        u.expr.v5->set_my_scope(p_scope);
      }
2182
      break;
2183
    case OPTYPE_TMR_READ: // r1
Elemer Lelik's avatar
Elemer Lelik committed
2184
2185
2186
2187
2188
2189
2190
    case OPTYPE_ACTIVATE:
      u.expr.r1->set_my_scope(p_scope);
      break;
    case OPTYPE_EXECUTE: // r1 [v2]
      u.expr.r1->set_my_scope(p_scope);
      if(u.expr.v2) u.expr.v2->set_my_scope(p_scope);
      break;
2191
2192
2193
2194
2195
    case OPTYPE_CHECKSTATE_ANY: // [r1] v2
    case OPTYPE_CHECKSTATE_ALL:
      if(u.expr.r1) u.expr.r1->set_my_scope(p_scope);
      u.expr.v2->set_my_scope(p_scope);
      break;
Elemer Lelik's avatar
Elemer Lelik committed
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
    case OPTYPE_COMP_CREATE: // r1 [v2] [v3]
      u.expr.r1->set_my_scope(p_scope);
      if(u.expr.v2) u.expr.v2->set_my_scope(p_scope);
      if(u.expr.v3) u.expr.v3->set_my_scope(p_scope);
      break;
    case OPTYPE_MATCH: // v1 t2
      u.expr.v1->set_my_scope(p_scope);
      u.expr.t2->set_my_scope(p_scope);
      break;
    case OPTYPE_ISCHOSEN: // r1 i2
      u.expr.r1->set_my_scope(p_scope);
      break;
    case OPTYPE_ISCHOSEN_V: // v1 i2
      u.expr.v1->set_my_scope(p_scope);
      break;
    case OPTYPE_ISCHOSEN_T: // t1 i2
      u.expr.t1->set_my_scope(p_scope);
      break;
    case OPTYPE_ACTIVATE_REFD:
      u.expr.v1->set_my_scope(p_scope);
      if(u.expr.state!=EXPR_CHECKED) {
	if(u.expr.t_list2) u.expr.t_list2->set_my_scope(p_scope);
	else
	  if(u.expr.ap_list2) u.expr.ap_list2->set_my_scope(p_scope);
      } break;
    case OPTYPE_EXECUTE_REFD:
      u.expr.v1->set_my_scope(p_scope);
      if(u.expr.state!=EXPR_CHECKED) {
	if(u.expr.t_list2) u.expr.t_list2->set_my_scope(p_scope);
	else
	  if(u.expr.ap_list2) u.expr.ap_list2->set_my_scope(p_scope);
      }
      if(u.expr.v3)
	u.expr.v3->set_my_scope(p_scope);
      break;
    case OPTYPE_LOG2STR:
2232
    case OPTYPE_ANY2UNISTR:
Elemer Lelik's avatar
Elemer Lelik committed
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
      u.expr.logargs->set_my_scope(p_scope);
      break;
    default:
      FATAL_ERROR("Value::set_my_scope_expr()");
    } // switch
  }

  void Value::set_genname_recursive(const string& p_genname)
  {
    size_t genname_len = p_genname.size();
    if (genname_len >= 4 &&
	p_genname.find("()()", genname_len - 4) == genname_len - 4) {
      // if the genname ends with ()() (i.e. the value stands for an optional
      // field) then drop the last () from the own genname, but leave it for
      // the embedded values
      set_genname(p_genname.substr(0, genname_len - 2));
    } else set_genname(p_genname);
    switch(valuetype) {
    case V_CHOICE: {
      string embedded_genname(p_genname);
      embedded_genname += '.';
      // If this is a choice value for an anytype, prepend the AT_ prefix
      // to the name of the alternative. The genname is used later in
      // Common::Value::generate_code_init_se()
      if (my_governor->get_type_refd_last()->get_typetype()==Type::T_ANYTYPE)
        embedded_genname += "AT_";
      embedded_genname += u.choice.alt_name->get_name();
      embedded_genname += "()";
      u.choice.alt_value->set_genname_recursive(embedded_genname);
      break; }
    case V_SEQOF:
    case V_SETOF: {
      if (!is_indexed()) {
        size_t nof_vs = u.val_vs->get_nof_vs();
        for (size_t i = 0; i < nof_vs; i++) {
          string embedded_genname(p_genname);
          embedded_genname += '[';
          embedded_genname += Int2string(i);
          embedded_genname += ']';
          u.val_vs->get_v_byIndex(i)->set_genname_recursive(embedded_genname);
        }
      } else {
        size_t nof_ivs = u.val_vs->get_nof_ivs();
        for (size_t i = 0; i < nof_ivs; i++) {
          string embedded_genname(p_genname);
          embedded_genname += '[';
          embedded_genname += Int2string(i);
          embedded_genname += ']';
          u.val_vs->get_iv_byIndex(i)->get_value()
            ->set_genname_recursive(embedded_genname);
        }
      }
      break; }
    case V_ARRAY: {
      if (!my_governor) return; // error recovery
      Type *type = my_governor->get_type_refd_last();
      if (type->get_typetype() != Type::T_ARRAY) return; // error recovery
      Int offset = type->get_dimension()->get_offset();
      if (!is_indexed()) {
        size_t nof_vs = u.val_vs->get_nof_vs();
        for (size_t i = 0; i < nof_vs; i++) {
          string embedded_genname(p_genname);
          embedded_genname += '[';
          embedded_genname += Int2string(offset + i);
          embedded_genname += ']';
          u.val_vs->get_v_byIndex(i)->set_genname_recursive(embedded_genname);
        }
      } else {
        size_t nof_ivs = u.val_vs->get_nof_ivs();
        for (size_t i = 0; i < nof_ivs; i++) {
          string embedded_genname(p_genname);
          embedded_genname += '[';
          embedded_genname += Int2string(offset + i);
          embedded_genname += ']';
          u.val_vs->get_iv_byIndex(i)->get_value()
            ->set_genname_recursive(embedded_genname);
        }
      }
      break; }
    case V_SEQ:
    case V_SET: {
      if (!my_governor) return; // error recovery
      Type *t = my_governor->get_type_refd_last();
      if (!t->is_secho()) return; // error recovery
      size_t nof_nvs = u.val_nvs->get_nof_nvs();
      for (size_t i = 0; i < nof_nvs; i++) {
	NamedValue *nv = u.val_nvs->get_nv_byIndex(i);
	const Identifier& id = nv->get_name();
	if (!t->has_comp_withName(id)) return; // error recovery
	string embedded_genname(p_genname);
	embedded_genname += '.';
	embedded_genname += id.get_name();
	embedded_genname += "()";
	if (t->get_comp_byName(id)->get_is_optional())
	  embedded_genname += "()";
	nv->get_value()->set_genname_recursive(embedded_genname);
      }
      break; }
    default:
      break;
    } // switch
  }

  void Value::set_genname_prefix(const char *p_genname_prefix)
  {
    GovernedSimple::set_genname_prefix(p_genname_prefix);
    switch(valuetype) {
    case V_CHOICE:
      u.choice.alt_value->set_genname_prefix(p_genname_prefix);
      break;
    case V_SEQOF:
    case V_SETOF:
    case V_ARRAY:
      if (!is_indexed()) {
        for (size_t i = 0; i < u.val_vs->get_nof_vs(); i++)
          u.val_vs->get_v_byIndex(i)->set_genname_prefix(p_genname_prefix);
      } else {
        for (size_t i = 0; i < u.val_vs->get_nof_ivs(); i++)
          u.val_vs->get_iv_byIndex(i)->get_value()
            ->set_genname_prefix(p_genname_prefix);
      }
      break;
    case V_SEQ:
    case V_SET:
      for (size_t i = 0; i < u.val_nvs->get_nof_nvs(); i++)
        u.val_nvs->get_nv_byIndex(i)->get_value()
	  ->set_genname_prefix(p_genname_prefix);
      break;
    default:
      break;
    } // switch
  }

  void Value::set_code_section(code_section_t p_code_section)
  {
    GovernedSimple::set_code_section(p_code_section);
    switch(valuetype) {
    case V_EXPR:
      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
2384
      case OPTYPE_PROF_RUNNING:
2385
      case OPTYPE_GET_PORT_REF: