Statement.cc 509 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
/******************************************************************************
Adam Knapp's avatar
Adam Knapp committed
2
 * Copyright (c) 2000-2021 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
 *
 * Contributors:
 *   Baji, Laszlo
 *   Balasko, Jeno
 *   Baranyi, Botond
 *   Beres, Szabolcs
 *   Delic, Adam
 *   Feher, Csaba
 *   Forstner, Matyas
 *   Kovacs, Ferenc
 *   Raduly, Csaba
 *   Szabados, Kristof
19
 *   Szabo, Bence Janos
Elemer Lelik's avatar
Elemer Lelik committed
20
21
22
23
 *   Szabo, Janos Zoltan – initial implementation
 *   Zalanyi, Balazs Andor
 *
 ******************************************************************************/
Elemer Lelik's avatar
Elemer Lelik committed
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "../../common/dbgnew.hh"
#include "Statement.hh"
#include "Ttcnstuff.hh"
#include "../TypeCompat.hh"
#include "../CompType.hh"
#include "../CompField.hh"
#include "../SigParam.hh"
#include "TtcnTemplate.hh"
#include "ILT.hh"
#include "ArrayDimensions.hh"
#include "../Int.hh"
#include "../main.hh"
#include "Attributes.hh"
37
#include "compiler2/Valuestuff.hh"
Elemer Lelik's avatar
Elemer Lelik committed
38
39
40
41
42
43
44
45

namespace Ttcn {

  // =================================
  // ===== StatementBlock
  // =================================

  StatementBlock::StatementBlock()
46
47
    : Scope(), checked(false), labels_checked(false), my_sb(0), my_def(0), exception_handling(EH_NONE),
    finally_block(NULL)
Elemer Lelik's avatar
Elemer Lelik committed
48
49
50
51
52
53
54
55
56
57
  {
  }

  StatementBlock::~StatementBlock()
  {
    for(size_t i=0; i<stmts.size(); i++)
      delete stmts[i];
    stmts.clear();
    defs.clear();
    labels.clear();
58
59
60
61
62
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      delete catch_blocks[i];
    }
    catch_blocks.clear();
    delete finally_block;
63
    refd_local_defs.clear();
Elemer Lelik's avatar
Elemer Lelik committed
64
65
66
67
68
69
70
71
72
73
  }

  StatementBlock *StatementBlock::clone() const
  {
    FATAL_ERROR("StatementBlock::clone");
  }

  void StatementBlock::dump(unsigned int level) const
  {
    size_t n = stmts.size();
74
75
    DEBUG(level, "StatementBlock at %p with %lu", static_cast<const void*>(this),
      static_cast<unsigned long>( n ));
Elemer Lelik's avatar
Elemer Lelik committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    for (size_t i = 0; i < n; ++i) {
      stmts[i]->dump(level+1);
    }
  }

  void StatementBlock::add_stmt(Statement *p_stmt, bool to_front)
  {
    if(!p_stmt)
      FATAL_ERROR("StatementBlock::add_stmt()");
    if (to_front) {
      stmts.add_front(p_stmt);
    } else {
      stmts.add(p_stmt);
    }
    p_stmt->set_my_scope(this);
    p_stmt->set_my_sb(this, stmts.size()-1);
  }

  void StatementBlock::set_my_scope(Scope *p_scope)
  {
    set_parent_scope(p_scope);
    for(size_t i=0; i<stmts.size(); i++)
      stmts[i]->set_my_scope(this);
99
100
101
102
103
104
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->set_parent_scope(p_scope);
    }
    if (finally_block != NULL) {
      finally_block->set_parent_scope(p_scope);
    }
Elemer Lelik's avatar
Elemer Lelik committed
105
106
107
108
109
110
111
  }

  void StatementBlock::set_fullname(const string& p_fullname)
  {
    Node::set_fullname(p_fullname);
    for(size_t i=0; i<stmts.size(); i++)
      stmts[i]->set_fullname(p_fullname+".stmt_"+Int2string(i+1));
112
113
114
115
116
117
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->set_fullname(p_fullname + ".catch_block_" + Int2string(i + 1));
    }
    if (finally_block != NULL) {
      finally_block->set_fullname(p_fullname + ".finally_block");
    }
Elemer Lelik's avatar
Elemer Lelik committed
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
  }

  /** \todo handle loops and conditional statements */
  Statement *StatementBlock::get_first_stmt() const
  {
    size_t nof_stmts = stmts.size();
    for (size_t i = 0; i < nof_stmts; i++) {
      Statement *stmt = stmts[i];
      switch (stmt->get_statementtype()) {
      case Statement::S_LABEL:
	// ignore and go to the next statement
	break;
      case Statement::S_BLOCK: {
	// if the block is not empty return its first statement
	// otherwise go to the next statement
	Statement *first_stmt = stmt->get_block()->get_first_stmt();
	if (first_stmt) return first_stmt;
	else break; }
      case Statement::S_DOWHILE: {
	// if the block is not empty return its first statement
	// otherwise return the whole do-while statement
	Statement *first_stmt = stmt->get_block()->get_first_stmt();
	if (first_stmt) return first_stmt;
	else return stmt; }
      default:
        return stmt;
      }
    }
    return 0;
  }

  void StatementBlock::register_def(Definition *p_def)
  {
    if(!p_def) FATAL_ERROR("StatementBlock::register_def()");
    const Identifier& id=p_def->get_id();
    if (defs.has_key(id)) {
      const char *dispname = id.get_dispname().c_str();
      p_def->error("Duplicate definition with identifier `%s'", dispname);
      defs[id]->note("Previous definition with identifier `%s' is here",
	dispname);
    } else {
      defs.add(id, p_def);
      if (parent_scope) {
	if (parent_scope->has_ass_withId(id)) {
162
163
164
165
166
167
168
169
170
171
    if (parent_scope->get_scope_class() == NULL) {
      const char *dispname = id.get_dispname().c_str();
      p_def->error("Definition with identifier `%s' is not unique"
                         " in the scope hierarchy", dispname);
      Reference ref(0, id.clone());
      Common::Assignment *ass = parent_scope->get_ass_bySRef(&ref);
      if (!ass) FATAL_ERROR("StatementBlock::register_def()");
      ass->note("Previous definition with identifier `%s' in higher "
                       "scope unit is here", dispname);
    }
Elemer Lelik's avatar
Elemer Lelik committed
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
	} else if (parent_scope->is_valid_moduleid(id)) {
	  p_def->warning("Definition with name `%s' hides a module identifier",
	    id.get_dispname().c_str());
	}
      }
    }
  }

  bool StatementBlock::has_ass_withId(const Identifier& p_id)
  {
    return defs.has_key(p_id) || get_parent_scope()->has_ass_withId(p_id);
  }

  Common::Assignment* StatementBlock::get_ass_bySRef(Ref_simple *p_ref)
  {
187
188
189
    if(p_ref->get_modid() || p_ref->get_reftype() != Ref_simple::REF_BASIC) {
      return get_parent_scope()->get_ass_bySRef(p_ref);
    }
Elemer Lelik's avatar
Elemer Lelik committed
190
191
192
193
194
    const Identifier& id=*p_ref->get_id();
    if(defs.has_key(id)) return defs[id];
    else return get_parent_scope()->get_ass_bySRef(p_ref);
  }

Elemer Lelik's avatar
Elemer Lelik committed
195
  Type *StatementBlock::get_mtc_system_comptype(bool is_system)
Elemer Lelik's avatar
Elemer Lelik committed
196
197
  {
    // return NULL outside test cases
198
199
200
201
202
203
204
205
206
207
208
209
210
    if (!my_def)
      return 0;
    Common::Assignment::asstype_t asstype = my_def->get_asstype();
    if (asstype == Common::Assignment::A_TESTCASE) {
      if (is_system) {
        Def_Testcase *t_tc = dynamic_cast<Def_Testcase*>(my_def);
        if (!t_tc) FATAL_ERROR("StatementBlock::get_mtc_system_comptype()");
        Type *system_ct = t_tc->get_SystemType();
        if (system_ct) return system_ct;
        // otherwise (if the testcase has no system clause) the type of 'system'
        // is the same as the type of 'mtc' (which is given in 'runs on' clause)
      }
      return my_def->get_RunsOnType();
211
212
213
214
    } else if (asstype == Common::Assignment::A_FUNCTION ||
               asstype == Common::Assignment::A_FUNCTION_RVAL ||
               asstype == Common::Assignment::A_FUNCTION_RTEMP ||
               asstype == Common::Assignment::A_ALTSTEP) {
215
216
217
218
219
220
      if (is_system) {
        return my_def->get_SystemType();
      } else {
        return my_def->get_MtcType();
      }
    } else {
Elemer Lelik's avatar
Elemer Lelik committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
      return 0;
    }
  }

  Ttcn::StatementBlock *StatementBlock::get_statementblock_scope()
  {
    return this;
  }

  void StatementBlock::set_my_sb(StatementBlock *p_sb, size_t p_index)
  {
    my_sb=p_sb;
    my_sb_index=p_index;
    for(size_t i=0; i<stmts.size(); i++)
      stmts[i]->set_my_sb(this, i);
  }

  size_t StatementBlock::get_my_sb_index() const
  {
    if(!my_sb) FATAL_ERROR("StatementBlock::get_my_sb_index()");
    return my_sb_index;
  }

  void StatementBlock::set_my_def(Definition *p_def)
  {
    my_def=p_def;
    for(size_t i=0; i<stmts.size(); i++)
      stmts[i]->set_my_def(p_def);
249
250
251
252
253
254
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->set_my_def(p_def);
    }
    if (finally_block != NULL) {
      finally_block->set_my_def(p_def);
    }
Elemer Lelik's avatar
Elemer Lelik committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
  }

  void StatementBlock::set_my_ags(AltGuards *p_ags)
  {
    for(size_t i=0; i<stmts.size(); i++)
      stmts[i]->set_my_ags(p_ags);
  }

  void StatementBlock::set_my_laic_stmt(AltGuards *p_ags,
                                        Statement *p_loop_stmt)
  {
    for(size_t i=0; i<stmts.size(); i++)
      stmts[i]->set_my_laic_stmt(p_ags, p_loop_stmt);
  }
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  
  void StatementBlock::add_catch_block(StatementBlock* p_catch)
  {
    if (p_catch == NULL) {
      FATAL_ERROR("StatementBlock::add_catch_block");
    }
    p_catch->exception_handling = EH_OOP_CATCH;
    catch_blocks.add(p_catch);
  }
  
  void StatementBlock::set_finally_block(StatementBlock* p_finally)
  {
    if (finally_block != NULL || p_finally == NULL) {
      FATAL_ERROR("StatementBlock::set_finally_block");
    }
    p_finally->exception_handling = EH_OOP_FINALLY;
    finally_block = p_finally;
  }
287
  
288
289
290
291
292
293
294
295
296
297
  void StatementBlock::add_refd_local_def(Common::Assignment* p_def)
  {
    if (exception_handling != EH_OOP_FINALLY || p_def == NULL) {
      FATAL_ERROR("StatementBlock::add_refd_local_defs");
    }
    if (!refd_local_defs.has_key(p_def)) {
      refd_local_defs.add(p_def, NULL);
    }
  }
  
298
299
300
301
302
303
304
305
306
307
308
  boolean StatementBlock::is_in_finally_block() const
  {
    if (exception_handling == EH_OOP_FINALLY) {
      return TRUE;
    }
    if (my_sb != NULL) {
      return my_sb->is_in_finally_block();
    }
    return FALSE;
  }
  
309
310
311
312
313
314
315
316
317
318
319
  StatementBlock* StatementBlock::get_finally_block()
  {
    if (exception_handling == EH_OOP_FINALLY) {
      return this;
    }
    if (my_sb != NULL) {
      return my_sb->get_finally_block();
    }
    FATAL_ERROR("StatementBlock::get_finally_block()");
  }
  
320
321
322
323
324
  boolean StatementBlock::is_empty() const
  {
    return stmts.size() == 0 && exception_handling == StatementBlock::EH_NONE &&
      catch_blocks.size() == 0 && finally_block == NULL;
  }
Elemer Lelik's avatar
Elemer Lelik committed
325
326
327
328
329

  StatementBlock::returnstatus_t StatementBlock::has_return() const
  {
    returnstatus_t ret_val = RS_NO;
    size_t nof_stmts = stmts.size();
330
    for (size_t i = 0; i < nof_stmts && ret_val != RS_YES; i++) {
Elemer Lelik's avatar
Elemer Lelik committed
331
332
333
334
335
336
337
338
339
340
341
      Statement *stmt = stmts[i];
      if (stmt->get_statementtype() == Statement::S_GOTO) {
	if (stmt->goto_jumps_forward()) {
	  // heuristics without deep analysis of the control flow graph:
	  // skip over the next statements until a (used) label is found
	  // the behaviour will be sound (i.e. no false errors will be reported)
	  for (i++; i < nof_stmts; i++) {
	    stmt = stmts[i];
	    if (stmt->get_statementtype() == Statement::S_LABEL &&
		stmt->label_is_used()) break;
	  }
342
	} else ret_val = RS_YES;
Elemer Lelik's avatar
Elemer Lelik committed
343
344
345
346
347
348
349
350
351
352
      } else if (stmt->get_statementtype()==Statement::S_BLOCK && stmt->get_block()->exception_handling!=EH_NONE) {
        switch (stmt->get_block()->exception_handling) {
        case EH_TRY: // the i-th statement is a try{} statement block, the (i+1)-th must be a catch{} block
          if ((i+1)<nof_stmts && stmts[i+1]->get_statementtype()==Statement::S_BLOCK && stmts[i+1]->get_block()->exception_handling==EH_CATCH) {
            returnstatus_t try_block_rs = stmt->has_return();
            returnstatus_t catch_block_rs = stmts[i+1]->has_return();
            // 3 x 3 combinations
            if (try_block_rs==catch_block_rs) {
              switch (try_block_rs) {
              case RS_YES:
353
354
                ret_val = RS_YES;
                break;
Elemer Lelik's avatar
Elemer Lelik committed
355
356
              case RS_MAYBE:
                ret_val = RS_MAYBE;
357
                break;
Elemer Lelik's avatar
Elemer Lelik committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
              default:
                break;
              }
            } else {
              ret_val = RS_MAYBE;
            }
          } else { // if next statement is not a catch{} block then that error has already been reported
            ret_val = RS_MAYBE; // assume the catch block was an RS_MAYBE
          }
          break;
        case EH_CATCH:
          // logically this is part of the preceding try{} block, handle it as part of it, see above case EH_TRY
          break;
        default:
          FATAL_ERROR("StatementBlock::has_return()");
        }
      } else {
	switch (stmt->has_return()) {
	case RS_YES:
377
378
	  ret_val = RS_YES;
	  break;
Elemer Lelik's avatar
Elemer Lelik committed
379
380
	case RS_MAYBE:
	  ret_val = RS_MAYBE;
381
	  break;
Elemer Lelik's avatar
Elemer Lelik committed
382
383
384
385
386
	default:
	  break;
	}
      }
    }
387
388
389
390
391
392
393
394
395
396
397
398
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      // all 'catch' blocks must also have return for the statement block to have return
      switch(catch_blocks[i]->has_return()) {
      case RS_YES:
        break; // OK, keep checking
      case RS_MAYBE:
        return RS_MAYBE;
      case RS_NO:
        ret_val = (ret_val == RS_NO) ? RS_NO : RS_MAYBE;
        break;
      }
    }
Elemer Lelik's avatar
Elemer Lelik committed
399
400
401
402
403
404
405
406
407
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
    return ret_val;
  }

  bool StatementBlock::has_receiving_stmt(size_t start_i) const
  {
    for(size_t i=start_i; i<stmts.size(); i++)
      if(stmts[i]->has_receiving_stmt()) return true;
    return false;
  }

  bool StatementBlock::has_def_stmt_i(size_t start_i) const
  {
    for(size_t i=start_i; i<stmts.size(); i++)
      if(stmts[i]->get_statementtype()==Statement::S_DEF) return true;
    return false;
  }

  size_t StatementBlock::last_receiving_stmt_i() const
  {
    size_t nof_stmts = stmts.size();
    if (nof_stmts > 0) {
      size_t i = nof_stmts;
      do {
	if (stmts[--i]->has_receiving_stmt()) return i;
      } while (i > 0);
    }
    return nof_stmts;
  }

  StatementBlock *StatementBlock::get_parent_block() const
  {
    for (Scope *s = get_parent_scope(); s; s=s->get_parent_scope()) {
      StatementBlock *sb = dynamic_cast<StatementBlock*>(s);
      if (sb) return sb;
    }
    return 0;
  }

  void StatementBlock::chk_trycatch_blocks(Statement* s1, Statement* s2) {
    if (s1 && s1->get_statementtype()==Statement::S_BLOCK && s1->get_block()->get_exception_handling()==StatementBlock::EH_TRY) {
      if (!(s2 && s2->get_statementtype()==Statement::S_BLOCK && s2->get_block()->get_exception_handling()==StatementBlock::EH_CATCH)) {
        s1->error("`try' statement block must be followed by a `catch' block");
      }
    }
    if (s2 && s2->get_statementtype()==Statement::S_BLOCK && s2->get_block()->get_exception_handling()==StatementBlock::EH_CATCH) {
      if (!(s1 && s1->get_statementtype()==Statement::S_BLOCK && s1->get_block()->get_exception_handling()==StatementBlock::EH_TRY)) {
        s2->error("`catch' statement block must be preceded by a `try' block");
      }
    }
  }

  void StatementBlock::chk()
  {
    if (checked) return;
    chk_labels();
    bool unreach_found = false;
    size_t nof_stmts = stmts.size();
    Statement *prev_stmt = 0;
    for (size_t i = 0; i < nof_stmts; i++) {
      Statement *stmt = stmts[i];
      stmt->chk();
      if (!unreach_found && stmt->get_statementtype() != Statement::S_LABEL &&
	  prev_stmt && prev_stmt->is_terminating()) {
	// a statement is unreachable if:
	// - it is not a label (i.e. goto cannot jump to it)
	// - it is not the first statement of the block
	// - the previous statement terminates the control flow
	stmt->warning("Control never reaches this statement");
	unreach_found = true;
      }
      // check try-catch statement block usage
      chk_trycatch_blocks(prev_stmt, stmt);
      //
      prev_stmt = stmt;
    }
    chk_trycatch_blocks(prev_stmt, 0);
    chk_unused_labels();
476
    map<string, Definition> catch_types;
477
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
      if (oop_features) {
        catch_blocks[i]->chk();
        Definition* def_exc = catch_blocks[i]->get_stmt_byIndex(0)->get_def();
        string catch_type_str = def_exc->get_Type()->get_exception_name();
        if (catch_types.has_key(catch_type_str)) {
          def_exc->error("Duplicate catch block definition for exception type `%s'", catch_type_str.c_str());
          catch_types[catch_type_str]->note("Catch block for the same exception type already defined here");
        }
        else {
          catch_types.add(catch_type_str, def_exc);
        }
      }
      else {
        catch_blocks[i]->error("The compiler option `-k' must be activated to use object-oriented features such as catch clauses.");
      }
493
    }
494
    catch_types.clear();
495
496
497
    if (finally_block != NULL) {
      finally_block->chk();
    }
Elemer Lelik's avatar
Elemer Lelik committed
498
499
500
501
502
503
504
505
    checked = true;
  }

  void StatementBlock::chk_allowed_interleave()
  {
    size_t nof_stmts = stmts.size();
    for (size_t i = 0; i < nof_stmts; i++)
      stmts[i]->chk_allowed_interleave();
506
507
508
509
510
511
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->chk_allowed_interleave();
    }
    if (finally_block != NULL) {
      finally_block->chk_allowed_interleave();
    }
Elemer Lelik's avatar
Elemer Lelik committed
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
  }

  void StatementBlock::chk_labels()
  {
    if(labels_checked) return;
    for(size_t i=0; i<stmts.size(); i++) {
      Statement *st=stmts[i];
      if(st->get_statementtype()!=Statement::S_LABEL) continue;
      const Identifier& labelid=st->get_labelid();
      if(has_label(labelid)) {
        const char *name=labelid.get_dispname().c_str();
        st->error("Duplicate label `%s'", name);
        Statement *st2=get_label(labelid);
        st2->note("Previous definition of label `%s' is here", name);
      }
      else labels.add(labelid, st);
    }
529
530
531
532
533
534
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->chk_labels();
    }
    if (finally_block != NULL) {
      finally_block->chk_labels();
    }
Elemer Lelik's avatar
Elemer Lelik committed
535
536
537
538
539
540
541
542
543
544
545
546
547
    labels_checked=true;
  }

  void StatementBlock::chk_unused_labels()
  {
    size_t nof_stmts = stmts.size();
    for (size_t i = 0; i < nof_stmts; i++) {
      Statement *stmt = stmts[i];
      if (stmt->get_statementtype() == Statement::S_LABEL &&
	  !stmt->label_is_used())
	stmt->warning("Label `%s' is defined, but not used",
	  stmt->get_labelid().get_dispname().c_str());
    }
548
549
550
551
552
553
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->chk_unused_labels();
    }
    if (finally_block != NULL) {
      finally_block->chk_unused_labels();
    }
Elemer Lelik's avatar
Elemer Lelik committed
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
  }

  bool StatementBlock::has_label(const Identifier& p_id) const
  {
    for (const StatementBlock *sb = this; sb; sb = sb->get_parent_block())
      if (sb->labels.has_key(p_id)) return true;
    return false;
  }

  Statement *StatementBlock::get_label(const Identifier& p_id) const
  {
    for (const StatementBlock *sb = this; sb; sb = sb->get_parent_block())
      if (sb->labels.has_key(p_id)) return sb->labels[p_id];
    FATAL_ERROR("StatementBlock::get_label()");
    return 0;
  }

  void StatementBlock::set_code_section(
    GovernedSimple::code_section_t p_code_section)
  {
    for(size_t i = 0; i < stmts.size(); i++)
      stmts[i]->set_code_section(p_code_section);
576
577
578
579
580
581
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->set_code_section(p_code_section);
    }
    if (finally_block != NULL) {
      finally_block->set_code_section(p_code_section);
    }
Elemer Lelik's avatar
Elemer Lelik committed
582
583
  }

584
585
  char* StatementBlock::generate_code(char *str, char*& def_glob_vars, char*& src_glob_vars,
                                      AltGuards* alt_guards /* = NULL */)
Elemer Lelik's avatar
Elemer Lelik committed
586
587
588
589
  {
    if (exception_handling==EH_TRY) {
      str = mputstr(str, "TTCN_TryBlock try_block;\n");
    }
590
    if (finally_block != NULL) {
591
#if __cplusplus < 201103L
592
      str = finally_block->generate_code_finally(str, def_glob_vars, src_glob_vars);
593
#else
594
      // C++11 version:
595
      string tmp_id = get_scope_mod_gen()->get_temporary_id();
596
597
598
599
      str = mputprintf(str,
        "FINALLY %s([&] {\n", tmp_id.c_str());
      str = finally_block->generate_code(str, def_glob_vars, src_glob_vars);
      str = mputstr(str, "});\n");
600
#endif
601
602
603
604
    }
    if (catch_blocks.size() > 0) {
      str = mputstr(str, "try {\n");
    }
Elemer Lelik's avatar
Elemer Lelik committed
605
606
    if (stmts.size()>0) {
      Statement* first_stmt = stmts[0];
607
      str = first_stmt->generate_code(str, def_glob_vars, src_glob_vars);
Elemer Lelik's avatar
Elemer Lelik committed
608
609
610
611
612
613
614
615
      if (exception_handling==EH_CATCH) {
        if (first_stmt->get_statementtype()!=Statement::S_DEF) FATAL_ERROR("StatementBlock::generate_code()");
        Definition* error_msg_def = first_stmt->get_def();
        string error_msg_name = error_msg_def->get_id().get_name();
        str = mputprintf(str, "%s = ttcn_error.get_message();\n", error_msg_name.c_str());
      }
    }
    for(size_t i=1; i<stmts.size(); i++) {
616
      str = stmts[i]->generate_code(str, def_glob_vars, src_glob_vars);
Elemer Lelik's avatar
Elemer Lelik committed
617
    }
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
    if (alt_guards != NULL && exception_handling == EH_NONE) {
      str = alt_guards->generate_code_altstep(str, def_glob_vars, src_glob_vars);
    }
    if (exception_handling == EH_OOP_CATCH && alt_guards != NULL) {
      // we are in an altstep's statement block
      // indicate that an alt branch has been chosen (since exceptions can only be raised from
      // the statement blocks of the alt branches)
      str = mputstr(str, "return ALT_YES;\n");
    }
    if (catch_blocks.size() > 0) {
      str = mputstr(str,
        "}\n" // end of the 'try' block
        "catch (EXCEPTION_BASE& exc_base) {\n");
      for (size_t i = 0; i < catch_blocks.size(); ++i) {
        Type* exc_type = catch_blocks[i]->get_stmt_byIndex(0)->get_def()->get_Type();
        str = mputprintf(str,
          "%sif (exc_base.has_type(\"%s\")) {\n",
          i > 0 ? "else " : "", exc_type->get_exception_name().c_str());
        str = catch_blocks[i]->generate_code(str, def_glob_vars, src_glob_vars, alt_guards);
        str = mputstr(str, "}\n");
      }
      // if none of the exception types matched, then just re-throw the exception as if nothing happened
      str = mputstr(str, 
        "else { throw exc_base; }\n"
        "}\n"); // end of the catch block
    }
Elemer Lelik's avatar
Elemer Lelik committed
644
645
    return str;
  }
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
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
  
  char* StatementBlock::generate_code_finally(char* str, char*& def_glob_vars, char*& src_glob_vars)
  {
    // the finally block's code is generated into the destructor of a newly created class;
    // all local definitions, parameters and the TTCN_Location object are added to the class as members,
    // so the destructor can reach them
    if (exception_handling != EH_OOP_FINALLY) {
      FATAL_ERROR("StatementBlock::generate_code_finally");
    }
    string tmp_id = get_scope_mod_gen()->get_temporary_id();
    str = mputprintf(str,
      "class %s_finally {\n"
      "public:\n", tmp_id.c_str());
    
    if (include_location_info) {
      str = mputstr(str, "TTCN_Location& current_location;\n");
    }
    bool* is_const = NULL;
    bool* is_template = NULL;
    bool* is_shadowed = NULL;
    if (refd_local_defs.size() > 0) {
      is_const = new bool[refd_local_defs.size()];
      is_template = new bool[refd_local_defs.size()];
      is_shadowed = new bool[refd_local_defs.size()];
    }
    for (size_t i = 0; i < refd_local_defs.size(); ++i) {
      is_const[i] = false;
      is_template[i] = false;
      is_shadowed[i] = false;
      Common::Assignment* def = refd_local_defs.get_nth_key(i);
      switch (def->get_asstype()) {
      case Common::Assignment::A_PAR_TEMPL_IN:
        is_template[i] = true;
        // fall through
      case Common::Assignment::A_PAR_VAL:
      case Common::Assignment::A_PAR_VAL_IN: {
        FormalPar* fpar = dynamic_cast<FormalPar*>(def);
        if (fpar == NULL) {
          FATAL_ERROR("StatementBlock::generate_code");
        }
        if (fpar->get_used_as_lvalue()) {
          is_shadowed[i] = true;
        }
        else {
          is_const[i] = true;
        }
        break; }
      case Common::Assignment::A_CONST:
        is_const[i] = true;
        break;
      case Common::Assignment::A_TEMPLATE:
        is_const[i] = true;
        // fall through
      case Common::Assignment::A_VAR_TEMPLATE:
      case Common::Assignment::A_PAR_TEMPL_INOUT:
      case Common::Assignment::A_PAR_TEMPL_OUT:
        is_template[i] = true;
        break;
      default:
        break;
      }
      str = mputprintf(str, "%s%s& %s%s;\n",
        is_const[i] ? "const " : "",
        is_template[i] ? def->get_Type()->get_genname_template(my_sb).c_str() : def->get_Type()->get_genname_value(my_sb).c_str(),
        def->get_id().get_name().c_str(), is_shadowed[i] ? "_shadow" : "");
    }
    if (include_location_info || refd_local_defs.size() > 0) {
      str = mputprintf(str, "%s_finally(", tmp_id.c_str());
      if (include_location_info) {
        str = mputstr(str, "TTCN_Location& p_loc");
      }
      for (size_t i = 0; i < refd_local_defs.size(); ++i) {
        Common::Assignment* def = refd_local_defs.get_nth_key(i);
        str = mputprintf(str, "%s%s%s& p_%s",
          include_location_info || i > 0 ? ", " : "", is_const[i] ? "const " : "",
          is_template[i] ? def->get_Type()->get_genname_template(my_sb).c_str() : def->get_Type()->get_genname_value(my_sb).c_str(),
          def->get_id().get_name().c_str());
      }
      str = mputstr(str, "): ");
      if (include_location_info) {
        str = mputstr(str, "current_location(p_loc)");
      }
      for (size_t i = 0; i < refd_local_defs.size(); ++i) {
        Common::Assignment* def = refd_local_defs.get_nth_key(i);
        str = mputprintf(str, "%s%s%s(p_%s)", include_location_info || i > 0 ? ", " : "",
          def->get_id().get_name().c_str(), is_shadowed[i] ? "_shadow" : "", def->get_id().get_name().c_str());
      }
      str = mputstr(str, " { }\n");
    }
    str = mputprintf(str,
      "~%s_finally() {\n"
      "try {\n", tmp_id.c_str());
    str = generate_code(str, def_glob_vars, src_glob_vars);
    str = mputprintf(str,
      "} catch (...) {\n"
      "fprintf(stderr, \"Unhandled exception or dynamic test case error in a finally block. Terminating application.\\n\");\n"
      "exit(EXIT_FAILURE);\n"
      "}\n"
      "}\n"
      "};\n"
      "%s_finally %s",
      tmp_id.c_str(), tmp_id.c_str());
    if (include_location_info || refd_local_defs.size() > 0) {
      str = mputc(str, '(');
      if (include_location_info) {
        str = mputstr(str, "current_location");
      }
      for (size_t i = 0; i < refd_local_defs.size(); ++i) {
        Common::Assignment* def = refd_local_defs.get_nth_key(i);
        str = mputprintf(str, "%s%s%s", include_location_info || i > 0 ? ", " : "",
          def->get_id().get_name().c_str(), is_shadowed[i] ? "_shadow" : "");
      }
      str = mputc(str, ')');
    }
    delete[] is_const;
    delete[] is_template;
    delete[] is_shadowed;
    return mputstr(str, ";\n");
  }
Elemer Lelik's avatar
Elemer Lelik committed
765
766
767
768
769
770
771
772
773
774
775
776

  void StatementBlock::ilt_generate_code(ILT *ilt)
  {
    size_t nof_stmts = stmts.size();
    if (nof_stmts == 0) return;
    char*& str=ilt->get_out_branches();
    size_t last_recv_stmt_i=last_receiving_stmt_i();
    // has no receiving stmt
    if (last_recv_stmt_i == nof_stmts) {
      bool has_def=has_def_stmt_i();
      if(has_def) str=mputstr(str, "{\n");
      for(size_t i=0; i<nof_stmts; i++)
777
778
        str=stmts[i]->generate_code(str, ilt->get_out_def_glob_vars(),
          ilt->get_out_src_glob_vars());
Elemer Lelik's avatar
Elemer Lelik committed
779
780
781
782
783
784
785
786
787
788
      if(has_def) str=mputstr(str, "}\n");
      return;
    }
    for(size_t i=0; i<=last_recv_stmt_i; i++)
      stmts[i]->ilt_generate_code(ilt);
    // the last part which does not contain receiving stmt
    if(last_recv_stmt_i==nof_stmts-1) return;
    bool has_def=has_def_stmt_i(last_recv_stmt_i+1);
    if(has_def) str=mputstr(str, "{\n");
    for(size_t i=last_recv_stmt_i+1; i<nof_stmts; i++)
789
790
      str=stmts[i]->generate_code(str, ilt->get_out_def_glob_vars(),
        ilt->get_out_src_glob_vars());
Elemer Lelik's avatar
Elemer Lelik committed
791
792
793
794
795
796
797
    if(has_def) str=mputstr(str, "}\n");
  }

  void StatementBlock::set_parent_path(WithAttribPath* p_path)
  {
    for (size_t i = 0; i < stmts.size(); i++)
      stmts[i]->set_parent_path(p_path);
798
799
800
801
802
803
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->set_parent_path(p_path);
    }
    if (finally_block != NULL) {
      finally_block->set_parent_path(p_path);
    }
Elemer Lelik's avatar
Elemer Lelik committed
804
805
806
807
808
809
810
811
812
813
814
815
816
817
  }

  // =================================
  // ===== Statement
  // =================================

  void Statement::clean_up()
  {
    switch (statementtype) {
    case S_ERROR:
    case S_BREAK:
    case S_CONTINUE:
    case S_STOP_EXEC:
    case S_REPEAT:
Elemer Lelik's avatar
Elemer Lelik committed
818
819
    case S_START_PROFILER:
    case S_STOP_PROFILER:
Elemer Lelik's avatar
Elemer Lelik committed
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
      break;
    case S_START_UNDEF:
    case S_STOP_UNDEF:
      delete undefstartstop.ref;
      delete undefstartstop.val;
      break;
    case S_UNKNOWN_INSTANCE:
    case S_FUNCTION_INSTANCE:
    case S_ALTSTEP_INSTANCE:
    case S_ACTIVATE:
      delete ref_pard;
      break;
    case S_DEF:
      delete def;
      break;
    case S_ASSIGNMENT:
      delete ass;
      break;
    case S_BLOCK:
      delete block;
      break;
    case S_LOG:
    case S_ACTION:
    case S_STOP_TESTCASE:
      delete logargs;
      break;
    case S_LABEL:
      delete label.id;
      delete label.clabel;
      break;
    case S_GOTO:
      delete go_to.id;
      break;
    case S_IF:
      delete if_stmt.ics;
      delete if_stmt.elseblock;
      delete if_stmt.elseblock_location;
      break;
    case S_SELECT:
      delete select.expr;
      delete select.scs;
      break;
862
863
864
865
    case S_SELECTUNION:
      delete select_union.expr;
      delete select_union.sus;
      break;
866
867
868
869
    case S_SELECT_CLASS:
      delete select_class.ref;
      delete select_class.sccs;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
    case S_FOR:
      if(loop.for_stmt.varinst)
        delete loop.for_stmt.init_varinst;
      else
        delete loop.for_stmt.init_ass;
      delete loop.for_stmt.finalexpr;
      delete loop.for_stmt.step;
      delete loop.block;
      if (loop.label_next)
        delete loop.label_next;
      if (loop.il_label_end)
        delete loop.il_label_end;
      break;
    case S_WHILE:
    case S_DOWHILE:
      delete loop.expr;
      delete loop.block;
      if (loop.label_next)
        delete loop.label_next;
      if (loop.il_label_end)
        delete loop.il_label_end;
      break;
    case S_ALT:
    case S_INTERLEAVE:
      delete ags;
      break;
    case S_RETURN:
      delete returnexpr.v;
      delete returnexpr.t;
      break;
    case S_DEACTIVATE:
      delete deactivate;
      break;
    case S_SEND:
      delete port_op.portref;
      delete port_op.s.sendpar;
      delete port_op.s.toclause;
907
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
908
909
910
911
912
913
914
      break;
    case S_CALL:
      delete port_op.portref;
      delete port_op.s.sendpar;
      delete port_op.s.call.timer;
      delete port_op.s.toclause;
      delete port_op.s.call.body;
915
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
916
917
918
919
920
921
      break;
    case S_REPLY:
      delete port_op.portref;
      delete port_op.s.sendpar;
      delete port_op.s.replyval;
      delete port_op.s.toclause;
922
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
923
924
925
926
927
928
      break;
    case S_RAISE:
      delete port_op.portref;
      delete port_op.s.raise.signature_ref;
      delete port_op.s.sendpar;
      delete port_op.s.toclause;
929
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
930
931
932
933
934
935
936
937
938
      break;
    case S_RECEIVE:
    case S_CHECK_RECEIVE:
    case S_TRIGGER:
      delete port_op.portref;
      delete port_op.r.rcvpar;
      delete port_op.r.fromclause;
      delete port_op.r.redirect.value;
      delete port_op.r.redirect.sender;
939
      delete port_op.r.redirect.index;
940
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
941
942
943
944
945
946
947
948
      break;
    case S_GETCALL:
    case S_CHECK_GETCALL:
      delete port_op.portref;
      delete port_op.r.rcvpar;
      delete port_op.r.fromclause;
      delete port_op.r.redirect.param;
      delete port_op.r.redirect.sender;
949
      delete port_op.r.redirect.index;
950
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
951
952
953
954
955
956
957
958
959
960
      break;
    case S_GETREPLY:
    case S_CHECK_GETREPLY:
      delete port_op.portref;
      delete port_op.r.rcvpar;
      delete port_op.r.getreply_valuematch;
      delete port_op.r.fromclause;
      delete port_op.r.redirect.value;
      delete port_op.r.redirect.param;
      delete port_op.r.redirect.sender;
961
      delete port_op.r.redirect.index;
962
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
963
964
965
966
967
968
969
970
971
      break;
    case S_CATCH:
    case S_CHECK_CATCH:
      delete port_op.portref;
      delete port_op.r.ctch.signature_ref;
      delete port_op.r.rcvpar;
      delete port_op.r.fromclause;
      delete port_op.r.redirect.value;
      delete port_op.r.redirect.sender;
972
      delete port_op.r.redirect.index;
973
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
974
975
976
977
978
      break;
    case S_CHECK:
      delete port_op.portref;
      delete port_op.r.fromclause;
      delete port_op.r.redirect.sender;
979
      delete port_op.r.redirect.index;
980
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
      break;
    case S_CLEAR:
    case S_START_PORT:
    case S_STOP_PORT:
    case S_HALT:
      delete port_op.portref;
      break;
    case S_START_COMP:
      delete comp_op.compref;
      delete comp_op.funcinstref;
      break;
    case S_START_COMP_REFD:
      delete comp_op.compref;
      delete comp_op.derefered.value;
      delete comp_op.derefered.ap_list2;
      break;
    case S_STOP_COMP:
    case S_KILL:
999
1000
      delete comp_op.compref;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1001
1002
    case S_KILLED:
      delete comp_op.compref;
1003
      delete comp_op.index_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1004
1005
1006
1007
1008
1009
      break;
    case S_DONE:
      if (comp_op.compref) {
        delete comp_op.compref;
        delete comp_op.donereturn.donematch;
        delete comp_op.donereturn.redirect;
1010
        delete comp_op.index_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
      }
      break;
    case S_CONNECT:
    case S_MAP:
    case S_DISCONNECT:
    case S_UNMAP:
      delete config_op.compref1;
      delete config_op.portref1;
      delete config_op.compref2;
      delete config_op.portref2;
1021
      delete config_op.ap_list;
Elemer Lelik's avatar
Elemer Lelik committed
1022
1023
1024
1025
1026
1027
      break;
    case S_START_TIMER:
      delete timer_op.timerref;
      delete timer_op.value;
      break;
    case S_TIMEOUT:
1028
      delete timer_op.index_redirect;
1029
1030
1031
      // no break
    case S_STOP_TIMER:
      delete timer_op.timerref;
Elemer Lelik's avatar
Elemer Lelik committed
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
      break;
    case S_SETVERDICT:
      delete setverdict.verdictval;
      delete setverdict.logargs;
      break;
    case S_TESTCASE_INSTANCE:
      delete testcase_inst.tcref;
      delete testcase_inst.timerval;
      break;
    case S_TESTCASE_INSTANCE_REFD:
      delete execute_refd.value;
      delete execute_refd.ap_list2;
      delete execute_refd.timerval;
      break;
    case S_ACTIVATE_REFD:
    case S_UNKNOWN_INVOKED:
    case S_FUNCTION_INVOKED:
    case S_ALTSTEP_INVOKED:
      delete fau_refd.value;
      delete fau_refd.ap_list2;
      break;
    case S_STRING2TTCN:
Elemer Lelik's avatar
Elemer Lelik committed
1054
1055
1056
    case S_INT2ENUM:
      delete convert_op.val;
      delete convert_op.ref;
Elemer Lelik's avatar
Elemer Lelik committed
1057
      break;
1058
1059
1060
1061
1062
    case S_UPDATE:
      delete update_op.ref;
      delete update_op.w_attrib_path;
      delete update_op.err_attrib;
      break;
1063
1064
1065
1066
    case S_SETSTATE:
      delete setstate_op.val;
      delete setstate_op.ti;
      break;
1067
1068
1069
1070
    case S_SETENCODE:
      delete setencode_op.type;
      delete setencode_op.encoding;
      break;
1071
1072
1073
1074
1075
1076
1077
1078
    case S_RAISE_OOP:
      if (raise_op.checked) {
        delete raise_op.v;
      }
      else {
        delete raise_op.ti;
      }
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
    default:
      FATAL_ERROR("Statement::clean_up()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_REPEAT:
      ags=0;
    case S_ERROR:
    case S_STOP_EXEC:
Elemer Lelik's avatar
Elemer Lelik committed
1092
1093
    case S_START_PROFILER:
    case S_STOP_PROFILER:
Elemer Lelik's avatar
Elemer Lelik committed
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
      break;
    case S_BREAK:
    case S_CONTINUE:
      brk_cnt.loop_stmt=0;
      brk_cnt.ags=0;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1105
  Statement::Statement(statementtype_t p_st, Reference *p_ref, Value *p_val)
Elemer Lelik's avatar
Elemer Lelik committed
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_START_UNDEF:
      if (!p_ref) FATAL_ERROR("Statement::Statement()");
      undefstartstop.ref=p_ref;
      undefstartstop.val=p_val;
      break;
    case S_STOP_UNDEF:
      if (!p_ref || p_val) FATAL_ERROR("Statement::Statement()");
      undefstartstop.ref=p_ref;
      undefstartstop.val=0;
      break;
1119
1120
1121
1122
1123
1124
    case S_TESTCASE_INSTANCE:
      if(!p_ref)
        FATAL_ERROR("Statement::Statement()");
      testcase_inst.tcref=p_ref;
      testcase_inst.timerval=p_val;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1125
1126
1127
1128
1129
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1130
  Statement::Statement(statementtype_t p_st, Reference *p_ref)
Elemer Lelik's avatar
Elemer Lelik committed
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_UNKNOWN_INSTANCE:
    case S_FUNCTION_INSTANCE:
    case S_ALTSTEP_INSTANCE:
    case S_ACTIVATE:
      if(!p_ref)
        FATAL_ERROR("Statement::Statement()");
      ref_pard=p_ref;
      break;
1142
1143
1144
1145
1146
1147
1148
1149
1150
    case S_CLEAR:
    case S_START_PORT:
    case S_STOP_PORT:
    case S_HALT:
      port_op.portref=p_ref;
      break;
    case S_STOP_TIMER:
      timer_op.timerref=p_ref;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
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
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Value *p_derefered_value,
                       ParsedActualParameters *p_ap_list)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_ACTIVATE_REFD:
    case S_UNKNOWN_INVOKED:
    case S_FUNCTION_INVOKED:
    case S_ALTSTEP_INVOKED:
      if(!p_derefered_value || !p_ap_list)
        FATAL_ERROR("Statement::Statement()");
      fau_refd.value = p_derefered_value;
      fau_refd.t_list1 = p_ap_list;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    }
  }

  Statement::Statement(statementtype_t p_st, Definition *p_def)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_DEF:
      if(!p_def)
        FATAL_ERROR("Statement::Statement()");
      def=p_def;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Assignment *p_ass)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_ASSIGNMENT:
      if(!p_ass)
        FATAL_ERROR("Statement::Statement()");
      ass=p_ass;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, StatementBlock *p_block)
    : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_BLOCK:
      if (!p_block) FATAL_ERROR("Statement::Statement()");
      block = p_block;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, LogArguments *p_logargs)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_LOG:
    case S_ACTION:
    case S_STOP_TESTCASE:
      logargs=p_logargs;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Identifier *p_id)
    : statementtype(p_st), my_sb(0)
  {
    if (!p_id)
      FATAL_ERROR("Statement::Statement()");
    switch (statementtype) {
    case S_LABEL:
      label.id = p_id;
      label.stmt_idx = 0;
      label.clabel = 0;
      label.used = false;
      break;
    case S_GOTO:
      go_to.id = p_id;
      go_to.stmt_idx = 0;
      go_to.label = 0;
      go_to.jumps_forward = false;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, IfClauses *p_ics,
                       StatementBlock *p_block, Location *p_loc)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_IF:
      if(!p_ics)
        FATAL_ERROR("Statement::Statement()");
      if_stmt.ics=p_ics;
      if (p_block) {
	if (!p_loc) FATAL_ERROR("Statement::Statement()");
	if_stmt.elseblock = p_block;
	if_stmt.elseblock_location = p_loc;
      } else {
	if (p_loc) FATAL_ERROR("Statement::Statement()");
	if_stmt.elseblock = 0;
	if_stmt.elseblock_location = 0;
      }
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Value *p_expr, SelectCases *p_scs)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_SELECT:
      if(!p_expr || !p_scs)
        FATAL_ERROR("Statement::Statement()");
      select.expr=p_expr;
      select.scs=p_scs;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
1291
  
1292
  Statement::Statement(statementtype_t p_st, Value *p_expr, SelectUnions *p_sus)
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_SELECTUNION:
      if(!p_expr || !p_sus)
        FATAL_ERROR("Statement::Statement()");
      select_union.expr=p_expr;
      select_union.sus=p_sus;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
    
  Statement::Statement(statementtype_t p_st, Reference *p_ref, SelectClassCases *p_sccs)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_SELECT_CLASS:
      if (p_ref == NULL || p_sccs == NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      select_class.ref = p_ref;
      select_class.sccs = p_sccs;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
Elemer Lelik's avatar
Elemer Lelik committed
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423

  Statement::Statement(statementtype_t p_st, Definitions *p_defs,
                       Assignment *p_ass, Value *p_final,
                       Assignment *p_step, StatementBlock *p_block)
    : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_FOR: // precisely one of p_defs, p_ass allowed
      if (p_defs) {
        // it came from a for loop which looked like this:
        // for (var integer foo:=1; foo<10; foo:=foo+1) ;
	if (p_ass) FATAL_ERROR("Statement::Statement()");
	loop.for_stmt.varinst = true;
	loop.for_stmt.init_varinst = p_defs;
      } else {
        // it came from a for loop which looked like this:
        // for (foo:=1; foo<10; foo:=foo+1) ;
	if (!p_ass) FATAL_ERROR("Statement::Statement()");
	loop.for_stmt.varinst = false;
	loop.for_stmt.init_ass = p_ass;
      }
      if(!p_final || !p_step || !p_block)
        FATAL_ERROR("Statement::Statement()");
      loop.for_stmt.finalexpr=p_final;
      loop.for_stmt.step=p_step;
      loop.block=p_block;
      loop.label_next=0;
      loop.il_label_end=0;
      loop.has_cnt=false;
      loop.has_brk=false;
      loop.has_cnt_in_ags=false;
      loop.iterate_once=false; // not used by for
      loop.is_ilt=false;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Value *p_val,
                       StatementBlock *p_block)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_WHILE:
    case S_DOWHILE:
      if(!p_val || !p_block)
        FATAL_ERROR("Statement::Statement()");
      loop.expr=p_val;
      loop.block=p_block;
      loop.label_next=0;
      loop.il_label_end=0;
      loop.has_cnt=false;
      loop.has_brk=false;
      loop.has_cnt_in_ags=false;
      loop.iterate_once=false; // used only by do-while
      loop.is_ilt=false;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, AltGuards *p_ags)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_ALT:
    case S_INTERLEAVE:
      if(!p_ags)
        FATAL_ERROR("Statement::Statement()");
      ags=p_ags;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Template *p_temp)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_RETURN:
      returnexpr.v=0;
      returnexpr.t=p_temp;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Value *p_val)
    : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_STOP_COMP:
    case S_KILL:
      comp_op.compref=p_val;
      break;
    case S_DEACTIVATE:
      deactivate=p_val;
      break;
1424
1425
1426
1427
    case S_SETSTATE:
      setstate_op.val = p_val;
      setstate_op.ti = NULL;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1428
1429
1430
1431
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
  
  Statement::Statement(statementtype_t p_st, Value *p_val, bool p_any_from,
                       Reference* p_index_redirect)
    : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_KILLED:
      if (p_val == NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      comp_op.compref = p_val;
      comp_op.any_from = p_any_from;
      comp_op.index_redirect = p_index_redirect;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
Elemer Lelik's avatar
Elemer Lelik committed
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461

  Statement::Statement(statementtype_t p_st, Value *p_val,
                       LogArguments *p_logargs)
    : statementtype(p_st), my_sb(0)
  {
    if (!p_val || statementtype != S_SETVERDICT)
      FATAL_ERROR("Statement::Statement()");
    setverdict.verdictval = p_val;
    setverdict.logargs = p_logargs;
  }

  Statement::Statement(statementtype_t p_st, Reference *p_ref,
1462
1463
                       TemplateInstance *p_templinst, Value *p_val,
                       Reference* p_timestampredirect, bool p_translate)
Elemer Lelik's avatar
Elemer Lelik committed
1464
1465
1466
1467
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_SEND:
1468
      if((!p_ref && p_translate == false) || !p_templinst)
Elemer Lelik's avatar
Elemer Lelik committed
1469
1470
        FATAL_ERROR("Statement::Statement()");
      port_op.portref=p_ref;
1471
      port_op.translate = p_translate;
Elemer Lelik's avatar
Elemer Lelik committed
1472
1473
      port_op.s.sendpar=p_templinst;
      port_op.s.toclause=p_val;
1474
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1475
1476
1477
1478
1479
1480
1481
1482
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Reference *p_ref,
              TemplateInstance *p_templinst, Value *p_timerval,
1483
1484
              bool p_nowait, Value *p_toclause, Reference* p_timestampredirect,
              AltGuards *p_callbody)
Elemer Lelik's avatar
Elemer Lelik committed
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_CALL:
      if(!p_ref || !p_templinst || (p_timerval && p_nowait))
        FATAL_ERROR("Statement::Statement()");
      port_op.portref=p_ref;
      port_op.s.sendpar=p_templinst;
      port_op.s.call.timer=p_timerval;
      port_op.s.call.nowait=p_nowait;
      port_op.s.toclause=p_toclause;
      port_op.s.call.body=p_callbody;
1497
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1498
1499
1500
1501
1502
1503
1504
1505
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Reference *p_ref,
                       TemplateInstance *p_templinst, Value *p_replyval,
1506
                       Value *p_toclause, Reference* p_timestampredirect)
Elemer Lelik's avatar
Elemer Lelik committed
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_REPLY:
      if(!p_ref || !p_templinst)
        FATAL_ERROR("Statement::Statement()");
      port_op.portref=p_ref;
      port_op.s.sendpar=p_templinst;
      port_op.s.replyval=p_replyval;
      port_op.s.toclause=p_toclause;
1517
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1518
1519
1520
1521
1522
1523
1524
1525
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Reference *p_ref,
                       Reference *p_sig, TemplateInstance *p_templinst,
1526
                       Value *p_toclause, Reference* p_timestampredirect)
Elemer Lelik's avatar
Elemer Lelik committed
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_RAISE:
      if(!p_ref || !p_templinst || !p_sig)
        FATAL_ERROR("Statement::Statement()");
      port_op.portref=p_ref;
      port_op.s.raise.signature_ref=p_sig;
      port_op.s.raise.signature=0;
      port_op.s.sendpar=p_templinst;
      port_op.s.toclause=p_toclause;
1538
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1539
1540
1541
1542
1543
1544
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1545
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1546
1547
                       TemplateInstance *p_templinst,
                       TemplateInstance *p_fromclause,
1548
                       ValueRedirect *p_redirectval, Reference *p_redirectsender,
1549
1550
                       Reference* p_redirectindex, Reference* p_timestamp_redirect,
                       bool p_translate)
Elemer Lelik's avatar
Elemer Lelik committed
1551
1552
1553
1554
1555
1556
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_RECEIVE:
    case S_CHECK_RECEIVE:
    case S_TRIGGER:
1557
      port_op.translate = p_translate;
Elemer Lelik's avatar
Elemer Lelik committed
1558
      port_op.portref=p_ref;
1559
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1560
1561
1562
1563
1564
      port_op.r.rcvpar=p_templinst;
      port_op.r.fromclause=p_fromclause;
      port_op.r.redirect.value=p_redirectval;
      port_op.r.redirect.param=0;
      port_op.r.redirect.sender=p_redirectsender;
1565
      port_op.r.redirect.index = p_redirectindex;
1566
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1567
1568
1569
1570
1571
1572
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1573
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1574
1575
1576
                       TemplateInstance *p_templinst,
                       TemplateInstance *p_fromclause,
                       ParamRedirect *p_redirectparam,
1577
                       Reference *p_redirectsender,
1578
1579
                       Reference* p_redirectindex,
                       Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1580
1581
1582
1583
1584
1585
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_GETCALL:
    case S_CHECK_GETCALL:
      port_op.portref=p_ref;
1586
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1587
1588
1589
1590
1591
      port_op.r.rcvpar=p_templinst;
      port_op.r.fromclause=p_fromclause;
      port_op.r.redirect.value=0;
      port_op.r.redirect.param=p_redirectparam;
      port_op.r.redirect.sender=p_redirectsender;
1592
      port_op.r.redirect.index = p_redirectindex;
1593
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1594
1595
1596
1597
1598
1599
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1600
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1601
1602
1603
                       TemplateInstance *p_templinst,
                       TemplateInstance *p_valuematch,
                       TemplateInstance *p_fromclause,
1604
                       ValueRedirect *p_redirectval, ParamRedirect *p_redirectparam,
1605
1606
                       Reference *p_redirectsender, Reference* p_redirectindex,
                       Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1607
1608
1609
1610
1611
1612
1613
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_GETREPLY:
    case S_CHECK_GETREPLY:
      if (!p_templinst && p_valuematch) FATAL_ERROR("Statement::Statement()");
      port_op.portref=p_ref;
1614
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1615
1616
1617
1618
1619
1620
      port_op.r.rcvpar=p_templinst;
      port_op.r.getreply_valuematch=p_valuematch;
      port_op.r.fromclause=p_fromclause;
      port_op.r.redirect.value=p_redirectval;
      port_op.r.redirect.param=p_redirectparam;
      port_op.r.redirect.sender=p_redirectsender;
1621
      port_op.r.redirect.index = p_redirectindex;
1622
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1623
1624
1625
1626
1627
1628
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1629
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1630
1631
                       Reference *p_sig, TemplateInstance *p_templinst,
                       bool p_timeout, TemplateInstance *p_fromclause,
1632
                       ValueRedirect *p_redirectval, Reference *p_redirectsender,
1633
                       Reference* p_redirectindex, Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1634
1635
1636
1637
1638
1639
1640
1641
1642
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_CATCH:
    case S_CHECK_CATCH:
      if (((p_sig || p_templinst) && p_timeout) ||
        (p_sig && !p_templinst) || (!p_sig && p_templinst))
	FATAL_ERROR("Statement::Statement()");
      port_op.portref=p_ref;
1643
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
      port_op.r.ctch.signature_ref=p_sig;
      port_op.r.ctch.signature=0;
      port_op.r.rcvpar=p_templinst;
      port_op.r.ctch.timeout=p_timeout;
      port_op.r.ctch.in_call=false;
      port_op.r.ctch.call_has_timer=false;
      port_op.r.fromclause=p_fromclause;
      port_op.r.redirect.value=p_redirectval;
      port_op.r.redirect.param=0;
      port_op.r.redirect.sender=p_redirectsender;
1654
      port_op.r.redirect.index = p_redirectindex;
1655
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1656
1657
1658
1659
1660
1661
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1662
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1663
                       TemplateInstance *p_fromclause,
1664
1665
                       Reference *p_redirectsender, Reference* p_redirectindex,
                       Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1666
1667
1668
1669
1670
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_CHECK:
      port_op.portref=p_ref; // may be NULL for "any port.check"
1671
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1672
1673
1674
1675
      port_op.r.fromclause=p_fromclause;
      port_op.r.redirect.value=0;
      port_op.r.redirect.param=0;
      port_op.r.redirect.sender=p_redirectsender;
1676
      port_op.r.redirect.index = p_redirectindex;
1677
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1678
1679
1680
1681
1682
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
  
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_any_from,
                       Reference* p_redirectindex)
    : statementtype(p_st), my_sb(0)
  {
    if (statementtype != S_TIMEOUT) {
      FATAL_ERROR("Statement::Statement()");
    }
    timer_op.timerref = p_ref;
    timer_op.any_from = p_any_from;
    timer_op.index_redirect = p_redirectindex;
  }
Elemer Lelik's avatar
Elemer Lelik committed
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713

  Statement::Statement(statementtype_t p_st, Value *p_compref,
                        Value *p_derefered_value, ParsedActualParameters *p_ap_list)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_START_COMP_REFD:
      if(!p_compref || !p_derefered_value || !p_ap_list)
        FATAL_ERROR("Statement::Statement()");
      comp_op.compref = p_compref;
      comp_op.derefered.value = p_derefered_value;
      comp_op.derefered.t_list1 = p_ap_list;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    }
  }

  Statement::Statement(statementtype_t p_st, Value *p_compref,
1714
1715
                       TemplateInstance *p_donematch, ValueRedirect *p_redirect,
                       Reference* p_index_redirect, bool p_any_from)
Elemer Lelik's avatar
Elemer Lelik committed
1716
1717
1718
1719
1720
1721
1722
1723
    : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_DONE:
      if (!p_compref) FATAL_ERROR("Statement::Statement()");
      comp_op.compref = p_compref;
      comp_op.donereturn.donematch = p_donematch;
      comp_op.donereturn.redirect = p_redirect;
1724
1725
      comp_op.index_redirect = p_index_redirect;
      comp_op.any_from = p_any_from;
Elemer Lelik's avatar
Elemer Lelik committed
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, component_t p_anyall)
    : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_DONE:
1737
1738
1739
      comp_op.donereturn.donematch = NULL;
      comp_op.donereturn.redirect = NULL;
      // no break
Elemer Lelik's avatar
Elemer Lelik committed
1740
1741
1742
    case S_KILLED:
      comp_op.compref = 0;
      comp_op.any_or_all = p_anyall;
1743
1744
      comp_op.any_from = false;
      comp_op.index_redirect = NULL;
Elemer Lelik's avatar
Elemer Lelik committed
1745
1746
1747
1748
1749
1750
1751
1752
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st,
                       Value *p_compref1, Reference *p_portref1,
1753
1754
                       Value *p_compref2, Reference *p_portref2,
                       ParsedActualParameters* p_params)
Elemer Lelik's avatar
Elemer Lelik committed
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_CONNECT:
    case S_MAP:
    case S_DISCONNECT:
    case S_UNMAP:
      if(!p_compref1 || !p_portref1 || !p_compref2 || !p_portref2)
        FATAL_ERROR("Statement::Statement()");
      config_op.compref1=p_compref1;
      config_op.portref1=p_portref1;
      config_op.compref2=p_compref2;
      config_op.portref2=p_portref2;
1768
      config_op.translate=false;
1769
1770
      config_op.parsed_params=p_params;
      config_op.fp_list=NULL;
Elemer Lelik's avatar
Elemer Lelik committed
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Value *p_derefered_value,
                        TemplateInstances *p_ap_list, Value *p_val)
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_TESTCASE_INSTANCE_REFD:
      if(!p_derefered_value) FATAL_ERROR("Statement::Statement()");
      execute_refd.value = p_derefered_value;
      execute_refd.t_list1 = p_ap_list;
      execute_refd.timerval = p_val;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    }
  }

Elemer Lelik's avatar
Elemer Lelik committed
1793
1794
  Statement::Statement(statementtype_t p_st, Value* p_val, Reference* p_ref)
    : statementtype(p_st), my_sb(0)
Elemer Lelik's avatar
Elemer Lelik committed
1795
  {
Elemer Lelik's avatar
Elemer Lelik committed
1796
1797
1798
1799
1800
1801
1802
1803
1804
    switch (statementtype) {
    case S_STRING2TTCN:
    case S_INT2ENUM:
      if (p_val==NULL || p_ref==NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      convert_op.val = p_val;
      convert_op.ref = p_ref;
      break;
1805
1806
1807
1808
1809
1810
1811
    case S_START_COMP:
      if (p_val==NULL || p_ref==NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      comp_op.compref = p_val;
      comp_op.funcinstref = p_ref;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1812
1813
1814
    default:
      FATAL_ERROR("Statement::Statement()");
    }
Elemer Lelik's avatar
Elemer Lelik committed
1815
  }
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
  
  Statement::Statement(statementtype_t p_st, Reference* p_ref, MultiWithAttrib* p_attrib)
  : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_UPDATE:
      if (p_ref == NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      update_op.ref = p_ref;
      if (p_attrib != NULL) {
        update_op.w_attrib_path = new WithAttribPath;
        update_op.w_attrib_path->set_with_attr(p_attrib);
      }
      else {
        update_op.w_attrib_path = NULL;
      }
      update_op.err_attrib = NULL;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    }
  }
1839
  
1840
  Statement::Statement(statementtype_t p_st, Value* p_val, TemplateInstance* p_ti)
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
  : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_SETSTATE:
      if (p_val == NULL || p_ti == NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      setstate_op.val = p_val;
      setstate_op.ti = p_ti;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    }
  }
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
    
  Statement::Statement(statementtype_t p_st, Type* p_type, Value* p_encoding)
  : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_SETENCODE:
      if (p_type == NULL || p_encoding == NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      setencode_op.type = p_type;
      setencode_op.encoding = p_encoding;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    }
  }
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
  
  Statement::Statement(statementtype_t p_st, TemplateInstance* p_ti)
  : statementtype(p_st), my_sb(0)
  {
    switch (statementtype) {
    case S_RAISE_OOP:
      if (p_ti == NULL) {
        FATAL_ERROR("Statement::Statement()");
      }
      raise_op.checked = false;
      raise_op.ti = p_ti;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    }
  }
Elemer Lelik's avatar
Elemer Lelik committed
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899

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

  Statement *Statement::clone() const
  {
    FATAL_ERROR("Statement::clone");
  }

  void Statement::dump(unsigned int level) const
  {
1900
    DEBUG(level, "Statement at %p, a(n) %s", static_cast<const void *>(this),
Elemer Lelik's avatar
Elemer Lelik committed
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
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
          get_stmt_name());
    switch (statementtype) {
    case S_TESTCASE_INSTANCE:
    case S_TESTCASE_INSTANCE_REFD: {
      Common::Value *v = execute_refd.value;
      v->dump(level + 1);
    } break;
    case S_DEF:
      def->dump(level + 1);
      break;
    case S_ASSIGNMENT:
      ass->dump(level + 1);
      break;
    case S_BLOCK:
      block->dump(level + 1);
      break;
    case S_IF:
      if_stmt.ics->dump(level + 1);
      if (if_stmt.elseblock) if_stmt.elseblock->dump(level + 1);
      break;
    default:
      break;
    }
  }

  size_t Statement::get_my_sb_index() const
  {
    switch (statementtype) {
    case S_LABEL:
      return label.stmt_idx;
    case S_GOTO:
      return go_to.stmt_idx;
    default:
      FATAL_ERROR("Statement::get_my_sb_index()");
      return 0;
    }
  }

  const char *Statement::get_stmt_name() const
  {
    switch(statementtype) {
    case S_ERROR: return "<erroneous statement>";
    case S_START_UNDEF: return "start";
    case S_STOP_UNDEF: return "stop";
    case S_UNKNOWN_INSTANCE: return "function or altstep instance";
    case S_UNKNOWN_INVOKED: return "function or altstep type invocation";
    case S_DEF: return "definition";
    case S_ASSIGNMENT: return "assignment";
    case S_FUNCTION_INSTANCE: return "function instance";
    case S_FUNCTION_INVOKED: return "function type invocation";
    case S_BLOCK: return "statement block";
    case S_LOG: return "log";
    case S_LABEL: return "label";
    case S_GOTO: return "goto";
    case S_IF: return "if";
    case S_SELECT: return "select-case";
1957
    case S_SELECTUNION: return "select-union";
1958
    case S_SELECT_CLASS: return "select-class";
Elemer Lelik's avatar
Elemer Lelik committed
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
    case S_FOR: return "for";
    case S_WHILE: return "while";
    case S_DOWHILE: return "do-while";
    case S_BREAK: return "break";
    case S_CONTINUE: return "continue";
    case S_STOP_EXEC: return "stop";
    case S_STOP_TESTCASE: return "testcase.stop";
    case S_ALT: return "alt";
    case S_REPEAT: return "repeat";
    case S_INTERLEAVE: return "interleave";
    case S_ALTSTEP_INSTANCE: return "altstep instance";
    case S_ALTSTEP_INVOKED: return "altstep type invocation";
    case S_RETURN: return "return";
    case S_ACTIVATE:
    case S_ACTIVATE_REFD:
      return "activate";
    case S_DEACTIVATE: return "deactivate";
    case S_SEND: return "send";
    case S_CALL: return "call";
    case S_REPLY: return "reply";
    case S_RAISE: return "raise";
    case S_RECEIVE: return "receive";
    case S_TRIGGER: return "trigger";
    case S_GETCALL: return "getcall";
    case S_GETREPLY: return "getreply";
    case S_CATCH: return "catch";
    case S_CHECK: return "check";
    case S_CHECK_RECEIVE: return "check-receive";
    case S_CHECK_GETCALL: return "check-getcall";
    case S_CHECK_GETREPLY: return "check-getreply";
    case S_CHECK_CATCH: return "check-catch";
    case S_CLEAR: return "clear";
    case S_START_PORT: return "start port";
    case S_STOP_PORT: return "stop port";
    case S_HALT: return "halt";
    case S_START_COMP:
    case S_START_COMP_REFD:
      return "start test component";
    case S_STOP_COMP: return "stop test component";
    case S_DONE: return "done";
    case S_KILL: return "kill";
    case S_KILLED: return "killed";
    case S_CONNECT: return "connect";
    case S_MAP: return "map";
    case S_DISCONNECT: return "disconnect";
    case S_UNMAP: return "unmap";
    case S_START_TIMER: return "start timer";
    case S_STOP_TIMER: return "stop timer";
    case S_TIMEOUT: return "timeout";
    case S_SETVERDICT: return "setverdict";
    case S_ACTION: return "action";
    case S_TESTCASE_INSTANCE:
    case S_TESTCASE_INSTANCE_REFD:
      return "execute";
    case S_STRING2TTCN: return "string2ttcn";
Elemer Lelik's avatar
Elemer Lelik committed
2014
    case S_INT2ENUM: return "int2enum";
Elemer Lelik's avatar
Elemer Lelik committed
2015
2016
    case S_START_PROFILER: return "@profiler.start";
    case S_STOP_PROFILER: return "@profiler.stop";
2017
    case S_UPDATE: return "@update";
2018
    case S_SETSTATE: return "setstate";
2019
    case S_SETENCODE: return "setencode";
Elemer Lelik's avatar
Elemer Lelik committed
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
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
    default:
      FATAL_ERROR("Statement::get_stmt_name()");
      return "";
    } // switch statementtype
  }

  const Identifier& Statement::get_labelid() const
  {
    switch (statementtype) {
    case S_LABEL:
      return *label.id;
    case S_GOTO:
      return *go_to.id;
    default:
      FATAL_ERROR("Statement::get_labelid()");
      return *label.id;
    }
  }

  bool Statement::label_is_used() const
  {
    if (statementtype != S_LABEL) FATAL_ERROR("Statement::label_is_used()");
    return label.used;
  }

  bool Statement::goto_jumps_forward() const
  {
    if (statementtype != S_GOTO) FATAL_ERROR("Statement::goto_jumps_forward()");
    return go_to.jumps_forward;
  }

  const string& Statement::get_clabel()
  {
    if (statementtype != S_LABEL || !my_sb)
      FATAL_ERROR("Statement::get_clabel()");
    if (!label.clabel) label.clabel =
	new string(my_sb->get_scope_mod_gen()->get_temporary_id());
    return *label.clabel;
  }

  Definition *Statement::get_def() const
  {
    if (statementtype != S_DEF) FATAL_ERROR("Statement::get_def()");
    return def;
  }

  AltGuards *Statement::get_ags() const
  {
    if (statementtype != S_ALT && statementtype != S_INTERLEAVE)
      FATAL_ERROR("Statement::get_ags()");
    return ags;
  }

  StatementBlock *Statement::get_block() const
  {
    switch (statementtype) {
    case S_BLOCK:
      return block;
    case S_FOR:
    case S_WHILE:
    case S_DOWHILE:
      return loop.block;
    default:
      FATAL_ERROR("Statement::get_block()");
      return 0;
    }
  }

  void Statement::set_my_scope(Scope *p_scope)
  {
    switch(statementtype) {
    case S_ERROR:
    case S_LABEL:
    case S_GOTO:
    case S_BREAK:
    case S_CONTINUE:
    case S_STOP_EXEC:
    case S_REPEAT:
Elemer Lelik's avatar
Elemer Lelik committed
2098
2099
    case S_START_PROFILER:
    case S_STOP_PROFILER:
Elemer Lelik's avatar
Elemer Lelik committed
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
      break;
    case S_START_UNDEF:
    case S_STOP_UNDEF:
      undefstartstop.ref->set_my_scope(p_scope);
      if (undefstartstop.val) undefstartstop.val->set_my_scope(p_scope);
      break;
    case S_UNKNOWN_INSTANCE:
    case S_FUNCTION_INSTANCE:
    case S_ALTSTEP_INSTANCE:
    case S_ACTIVATE:
      ref_pard->set_my_scope(p_scope);
      break;
    case S_DEF:
      def->set_my_scope(p_scope);
      break;
    case S_ASSIGNMENT:
      ass->set_my_scope(p_scope);
      break;
    case S_BLOCK:
      block->set_my_scope(p_scope);
      break;
    case S_LOG:
    case S_ACTION:
    case S_STOP_TESTCASE:
      if (logargs) logargs->set_my_scope(p_scope);
      break;
    case S_IF:
      if_stmt.ics->set_my_scope(p_scope);
      if(if_stmt.elseblock) if_stmt.elseblock->set_my_scope(p_scope);
      break;
    case S_SELECT:
      select.expr->set_my_scope(p_scope);
      select.scs->set_my_scope(p_scope);
      break;
2134
2135
2136
2137
    case S_SELECTUNION:
      select_union.expr->set_my_scope(p_scope);
      select_union.sus->set_my_scope(p_scope);
      break;
2138
2139
2140
2141
    case S_SELECT_CLASS:
      select_class.ref->set_my_scope(p_scope);
      select_class.sccs->set_my_scope(p_scope);
      break;
Elemer Lelik's avatar
Elemer Lelik committed
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
    case S_FOR:
      if (loop.for_stmt.varinst) {
        loop.for_stmt.init_varinst->set_parent_scope(p_scope);
        loop.for_stmt.finalexpr->set_my_scope(loop.for_stmt.init_varinst);
        loop.for_stmt.step->set_my_scope(loop.for_stmt.init_varinst);
        loop.block->set_my_scope(loop.for_stmt.init_varinst);
      } else {
        loop.for_stmt.init_ass->set_my_scope(p_scope);
        loop.for_stmt.finalexpr->set_my_scope(p_scope);
        loop.for_stmt.step->set_my_scope(p_scope);
        loop.block->set_my_scope(p_scope);
      }
      break;
    case S_WHILE:
    case S_DOWHILE:
      loop.expr->set_my_scope(p_scope);
      loop.block->set_my_scope(p_scope);
      break;
    case S_ALT:
    case S_INTERLEAVE:
      ags->set_my_scope(p_scope);
      break;
    case S_RETURN:
      if (returnexpr.v) returnexpr.v->set_my_scope(p_scope);
      if (returnexpr.t) returnexpr.t->set_my_scope(p_scope);
      break;
    case S_DEACTIVATE:
      if (deactivate) deactivate->set_my_scope(p_scope);
      break;
    case S_SEND:
2172
      if (!port_op.translate) port_op.portref->set_my_scope(p_scope);
Elemer Lelik's avatar
Elemer Lelik committed
2173
2174
      port_op.s.sendpar->set_my_scope(p_scope);
      if(port_op.s.toclause) port_op.s.toclause->set_my_scope(p_scope);
2175
2176
2177
      if (port_op.s.timestampredirect != NULL) {
        port_op.s.timestampredirect->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2178
2179
2180
2181
2182
2183
2184
      break;
    case S_CALL:
      port_op.portref->set_my_scope(p_scope);
      port_op.s.sendpar->set_my_scope(p_scope);
      if(port_op.s.toclause) port_op.s.toclause->set_my_scope(p_scope);
      if(port_op.s.call.timer) port_op.s.call.timer->set_my_scope(p_scope);
      if(port_op.s.call.body) port_op.s.call.body->set_my_scope(p_scope);
2185
2186
2187
      if (port_op.s.timestampredirect != NULL) {
        port_op.s.timestampredirect->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2188
2189
2190
2191
2192
2193
      break;
    case S_REPLY:
      port_op.portref->set_my_scope(p_scope);
      port_op.s.sendpar->set_my_scope(p_scope);
      if(port_op.s.replyval) port_op.s.replyval->set_my_scope(p_scope);
      if(port_op.s.toclause) port_op.s.toclause->set_my_scope(p_scope);
2194
2195
2196
      if (port_op.s.timestampredirect != NULL) {
        port_op.s.timestampredirect->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2197
2198
2199
2200
2201
2202
      break;
    case S_RAISE:
      port_op.portref->set_my_scope(p_scope);
      port_op.s.raise.signature_ref->set_my_scope(p_scope);
      port_op.s.sendpar->set_my_scope(p_scope);
      if(port_op.s.toclause) port_op.s.toclause->set_my_scope(p_scope);
2203
2204
2205
      if (port_op.s.timestampredirect != NULL) {
        port_op.s.timestampredirect->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
      break;
    case S_RECEIVE:
    case S_CHECK_RECEIVE:
    case S_TRIGGER:
      if(port_op.portref) port_op.portref->set_my_scope(p_scope);
      if(port_op.r.rcvpar) port_op.r.rcvpar->set_my_scope(p_scope);
      if(port_op.r.fromclause) port_op.r.fromclause->set_my_scope(p_scope);
      if(port_op.r.redirect.value)
        port_op.r.redirect.value->set_my_scope(p_scope);
      if(port_op.r.redirect.sender)
        port_op.r.redirect.sender->set_my_scope(p_scope);
2217
2218
2219
      if (port_op.r.redirect.index != NULL) {
        port_op.r.redirect.index->set_my_scope(p_scope);
      }
2220
2221
2222
      if (port_op.r.redirect.timestamp != NULL) {
        port_op.r.redirect.timestamp->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
      break;
    case S_GETCALL:
    case S_CHECK_GETCALL:
      if(port_op.portref) port_op.portref->set_my_scope(p_scope);
      if(port_op.r.rcvpar) port_op.r.rcvpar->set_my_scope(p_scope);
      if(port_op.r.fromclause) port_op.r.fromclause->set_my_scope(p_scope);
      if(port_op.r.redirect.param)
        port_op.r.redirect.param->set_my_scope(p_scope);
      if(port_op.r.redirect.sender)
        port_op.r.redirect.sender->set_my_scope(p_scope);
2233
2234
2235
      if (port_op.r.redirect.index != NULL) {
        port_op.r.redirect.index->set_my_scope(p_scope);
      }
2236
2237
2238
      if (port_op.r.redirect.timestamp != NULL) {
        port_op.r.redirect.timestamp->set_my_scope(p_scope);
      }
Elemer Lelik's avatar
Elemer Lelik committed
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
      break;
    case S_GETREPLY:
    case S_CHECK_GETREPLY:
      if(port_op.portref) port_op.portref->set_my_scope(p_scope);
      if(port_op.r.rcvpar) port_op.r.rcvpar->set_my_scope(p_scope);
      if(port_op.r.getreply_valuematch)
        port_op.r.getreply_valuematch->set_my_scope(p_scope);
      if(port_op.r.fromclause) port_op.r.fromclause->set_my_scope(p_scope);
      if(port_op.r.redirect.value)
        port_op.r.redirect.value->set_my_scope(p_scope);
      if(port_op.r.redirect.param)
        port_op.r.redirect.param->set_my_scope(p_scope);
      if(port_op.r.redirect.sender)
        port_op.r.redirect.sender->set_my_scope(p_scope);
2253
2254
2255
      if (port_op.r.redirect.index != NULL) {
        port_op.r.redirect.index->set_my_scope(p_scope);
      }