Statement.cc 501 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;
Elemer Lelik's avatar
Elemer Lelik committed
63
64
65
66
67
68
69
70
71
72
  }

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

  void StatementBlock::dump(unsigned int level) const
  {
    size_t n = stmts.size();
73
74
    DEBUG(level, "StatementBlock at %p with %lu", static_cast<const void*>(this),
      static_cast<unsigned long>( n ));
Elemer Lelik's avatar
Elemer Lelik committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    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);
98
99
100
101
102
103
    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
104
105
106
107
108
109
110
  }

  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));
111
112
113
114
115
116
    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
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
  }

  /** \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)) {
161
162
163
164
165
166
167
168
169
170
    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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
	} 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)
  {
186
187
188
    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
189
190
191
192
193
    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
194
  Type *StatementBlock::get_mtc_system_comptype(bool is_system)
Elemer Lelik's avatar
Elemer Lelik committed
195
196
  {
    // return NULL outside test cases
197
198
199
200
201
202
203
204
205
206
207
208
209
    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();
210
211
212
213
    } else if (asstype == Common::Assignment::A_FUNCTION ||
               asstype == Common::Assignment::A_FUNCTION_RVAL ||
               asstype == Common::Assignment::A_FUNCTION_RTEMP ||
               asstype == Common::Assignment::A_ALTSTEP) {
214
215
216
217
218
219
      if (is_system) {
        return my_def->get_SystemType();
      } else {
        return my_def->get_MtcType();
      }
    } else {
Elemer Lelik's avatar
Elemer Lelik committed
220
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
      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);
248
249
250
251
252
253
    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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  }

  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);
  }
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
  
  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;
  }
Elemer Lelik's avatar
Elemer Lelik committed
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420

  StatementBlock::returnstatus_t StatementBlock::has_return() const
  {
    returnstatus_t ret_val = RS_NO;
    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_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;
	  }
	} else return RS_YES;
      } 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:
                return RS_YES;
              case RS_MAYBE:
                ret_val = RS_MAYBE;
              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:
	  return RS_YES;
	case RS_MAYBE:
	  ret_val = RS_MAYBE;
	default:
	  break;
	}
      }
    }
    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();
421
422
423
424
425
426
    for (size_t i = 0; i < catch_blocks.size(); ++i) {
      catch_blocks[i]->chk();
    }
    if (finally_block != NULL) {
      finally_block->chk();
    }
Elemer Lelik's avatar
Elemer Lelik committed
427
428
429
430
431
432
433
434
    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();
435
436
437
438
439
440
    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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
  }

  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);
    }
458
459
460
461
462
463
    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
464
465
466
467
468
469
470
471
472
473
474
475
476
    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());
    }
477
478
479
480
481
482
    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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  }

  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);
505
506
507
508
509
510
    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
511
512
  }

513
514
  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
515
516
517
518
  {
    if (exception_handling==EH_TRY) {
      str = mputstr(str, "TTCN_TryBlock try_block;\n");
    }
519
520
    if (finally_block != NULL) {
      string tmp_id = get_scope_mod_gen()->get_temporary_id();
521
522
#if __cplusplus < 201103L
      str = mputprintf(str,
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
        "class %s_finally {\n"
        "public:\n", tmp_id.c_str());
      // TODO: all local declarations (or those referenced in the 'finally' block) need to
      // be added as members of this class, so the destructor can reach them
      if (include_location_info) {
        str = mputprintf(str,
          "TTCN_Location& current_location;\n"
          "%s_finally(TTCN_Location& p_loc):current_location(p_loc) { }\n",
          tmp_id.c_str());
      }
      str = mputprintf(str,
        "~%s_finally() {\n", tmp_id.c_str());
      str = finally_block->generate_code(str, def_glob_vars, src_glob_vars);
      str = mputprintf(str,
        "}\n"
        "};\n"
        "%s_finally %s%s;\n",
        tmp_id.c_str(), tmp_id.c_str(),
541
542
        include_location_info ? "(current_location)" : "");
#else
543
544
545
546
547
      // C++11 version:
      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");
548
#endif
549
550
551
552
    }
    if (catch_blocks.size() > 0) {
      str = mputstr(str, "try {\n");
    }
Elemer Lelik's avatar
Elemer Lelik committed
553
554
    if (stmts.size()>0) {
      Statement* first_stmt = stmts[0];
555
      str = first_stmt->generate_code(str, def_glob_vars, src_glob_vars);
Elemer Lelik's avatar
Elemer Lelik committed
556
557
558
559
560
561
562
563
      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++) {
564
      str = stmts[i]->generate_code(str, def_glob_vars, src_glob_vars);
Elemer Lelik's avatar
Elemer Lelik committed
565
    }
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
    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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
    return str;
  }

  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++)
606
607
        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
608
609
610
611
612
613
614
615
616
617
      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++)
618
619
      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
620
621
622
623
624
625
626
    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);
627
628
629
630
631
632
    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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
  }

  // =================================
  // ===== 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
647
648
    case S_START_PROFILER:
    case S_STOP_PROFILER:
Elemer Lelik's avatar
Elemer Lelik committed
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
      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;
691
692
693
694
    case S_SELECTUNION:
      delete select_union.expr;
      delete select_union.sus;
      break;
695
696
697
698
    case S_SELECT_CLASS:
      delete select_class.ref;
      delete select_class.sccs;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
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
    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;
736
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
737
738
739
740
741
742
743
      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;
744
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
745
746
747
748
749
750
      break;
    case S_REPLY:
      delete port_op.portref;
      delete port_op.s.sendpar;
      delete port_op.s.replyval;
      delete port_op.s.toclause;
751
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
752
753
754
755
756
757
      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;
758
      delete port_op.s.timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
759
760
761
762
763
764
765
766
767
      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;
768
      delete port_op.r.redirect.index;
769
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
770
771
772
773
774
775
776
777
      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;
778
      delete port_op.r.redirect.index;
779
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
780
781
782
783
784
785
786
787
788
789
      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;
790
      delete port_op.r.redirect.index;
791
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
792
793
794
795
796
797
798
799
800
      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;
801
      delete port_op.r.redirect.index;
802
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
803
804
805
806
807
      break;
    case S_CHECK:
      delete port_op.portref;
      delete port_op.r.fromclause;
      delete port_op.r.redirect.sender;
808
      delete port_op.r.redirect.index;
809
      delete port_op.r.redirect.timestamp;
Elemer Lelik's avatar
Elemer Lelik committed
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
      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:
828
829
      delete comp_op.compref;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
830
831
    case S_KILLED:
      delete comp_op.compref;
832
      delete comp_op.index_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
833
834
835
836
837
838
      break;
    case S_DONE:
      if (comp_op.compref) {
        delete comp_op.compref;
        delete comp_op.donereturn.donematch;
        delete comp_op.donereturn.redirect;
839
        delete comp_op.index_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
840
841
842
843
844
845
846
847
848
849
      }
      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;
850
      delete config_op.ap_list;
Elemer Lelik's avatar
Elemer Lelik committed
851
852
853
854
855
856
      break;
    case S_START_TIMER:
      delete timer_op.timerref;
      delete timer_op.value;
      break;
    case S_TIMEOUT:
857
      delete timer_op.index_redirect;
858
859
860
      // no break
    case S_STOP_TIMER:
      delete timer_op.timerref;
Elemer Lelik's avatar
Elemer Lelik committed
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
      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
883
884
885
    case S_INT2ENUM:
      delete convert_op.val;
      delete convert_op.ref;
Elemer Lelik's avatar
Elemer Lelik committed
886
      break;
887
888
889
890
891
    case S_UPDATE:
      delete update_op.ref;
      delete update_op.w_attrib_path;
      delete update_op.err_attrib;
      break;
892
893
894
895
    case S_SETSTATE:
      delete setstate_op.val;
      delete setstate_op.ti;
      break;
896
897
898
899
    case S_SETENCODE:
      delete setencode_op.type;
      delete setencode_op.encoding;
      break;
900
901
902
903
904
905
906
907
    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
908
909
910
911
912
913
914
915
916
917
918
919
920
    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
921
922
    case S_START_PROFILER:
    case S_STOP_PROFILER:
Elemer Lelik's avatar
Elemer Lelik committed
923
924
925
926
927
928
929
930
931
932
933
      break;
    case S_BREAK:
    case S_CONTINUE:
      brk_cnt.loop_stmt=0;
      brk_cnt.ags=0;
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

934
  Statement::Statement(statementtype_t p_st, Reference *p_ref, Value *p_val)
Elemer Lelik's avatar
Elemer Lelik committed
935
936
937
938
939
940
941
942
943
944
945
946
947
    : 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;
948
949
950
951
952
953
    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
954
955
956
957
958
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

959
  Statement::Statement(statementtype_t p_st, Reference *p_ref)
Elemer Lelik's avatar
Elemer Lelik committed
960
961
962
963
964
965
966
967
968
969
970
    : 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;
971
972
973
974
975
976
977
978
979
    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
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
    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
  }
1120
  
1121
  Statement::Statement(statementtype_t p_st, Value *p_expr, SelectUnions *p_sus)
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
    : 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
  }
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
    
  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
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

  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;
1253
1254
1255
1256
    case S_SETSTATE:
      setstate_op.val = p_val;
      setstate_op.ti = NULL;
      break;
Elemer Lelik's avatar
Elemer Lelik committed
1257
1258
1259
1260
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
  
  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
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290

  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,
1291
1292
                       TemplateInstance *p_templinst, Value *p_val,
                       Reference* p_timestampredirect, bool p_translate)
Elemer Lelik's avatar
Elemer Lelik committed
1293
1294
1295
1296
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_SEND:
1297
      if((!p_ref && p_translate == false) || !p_templinst)
Elemer Lelik's avatar
Elemer Lelik committed
1298
1299
        FATAL_ERROR("Statement::Statement()");
      port_op.portref=p_ref;
1300
      port_op.translate = p_translate;
Elemer Lelik's avatar
Elemer Lelik committed
1301
1302
      port_op.s.sendpar=p_templinst;
      port_op.s.toclause=p_val;
1303
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1304
1305
1306
1307
1308
1309
1310
1311
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Reference *p_ref,
              TemplateInstance *p_templinst, Value *p_timerval,
1312
1313
              bool p_nowait, Value *p_toclause, Reference* p_timestampredirect,
              AltGuards *p_callbody)
Elemer Lelik's avatar
Elemer Lelik committed
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
    : 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;
1326
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1327
1328
1329
1330
1331
1332
1333
1334
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Reference *p_ref,
                       TemplateInstance *p_templinst, Value *p_replyval,
1335
                       Value *p_toclause, Reference* p_timestampredirect)
Elemer Lelik's avatar
Elemer Lelik committed
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
    : 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;
1346
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1347
1348
1349
1350
1351
1352
1353
1354
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st, Reference *p_ref,
                       Reference *p_sig, TemplateInstance *p_templinst,
1355
                       Value *p_toclause, Reference* p_timestampredirect)
Elemer Lelik's avatar
Elemer Lelik committed
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
    : 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;
1367
      port_op.s.timestampredirect = p_timestampredirect;
Elemer Lelik's avatar
Elemer Lelik committed
1368
1369
1370
1371
1372
1373
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1374
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1375
1376
                       TemplateInstance *p_templinst,
                       TemplateInstance *p_fromclause,
1377
                       ValueRedirect *p_redirectval, Reference *p_redirectsender,
1378
1379
                       Reference* p_redirectindex, Reference* p_timestamp_redirect,
                       bool p_translate)
Elemer Lelik's avatar
Elemer Lelik committed
1380
1381
1382
1383
1384
1385
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_RECEIVE:
    case S_CHECK_RECEIVE:
    case S_TRIGGER:
1386
      port_op.translate = p_translate;
Elemer Lelik's avatar
Elemer Lelik committed
1387
      port_op.portref=p_ref;
1388
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1389
1390
1391
1392
1393
      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;
1394
      port_op.r.redirect.index = p_redirectindex;
1395
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1396
1397
1398
1399
1400
1401
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1402
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1403
1404
1405
                       TemplateInstance *p_templinst,
                       TemplateInstance *p_fromclause,
                       ParamRedirect *p_redirectparam,
1406
                       Reference *p_redirectsender,
1407
1408
                       Reference* p_redirectindex,
                       Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1409
1410
1411
1412
1413
1414
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_GETCALL:
    case S_CHECK_GETCALL:
      port_op.portref=p_ref;
1415
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1416
1417
1418
1419
1420
      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;
1421
      port_op.r.redirect.index = p_redirectindex;
1422
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1423
1424
1425
1426
1427
1428
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1429
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1430
1431
1432
                       TemplateInstance *p_templinst,
                       TemplateInstance *p_valuematch,
                       TemplateInstance *p_fromclause,
1433
                       ValueRedirect *p_redirectval, ParamRedirect *p_redirectparam,
1434
1435
                       Reference *p_redirectsender, Reference* p_redirectindex,
                       Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1436
1437
1438
1439
1440
1441
1442
    : 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;
1443
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1444
1445
1446
1447
1448
1449
      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;
1450
      port_op.r.redirect.index = p_redirectindex;
1451
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1452
1453
1454
1455
1456
1457
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1458
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1459
1460
                       Reference *p_sig, TemplateInstance *p_templinst,
                       bool p_timeout, TemplateInstance *p_fromclause,
1461
                       ValueRedirect *p_redirectval, Reference *p_redirectsender,
1462
                       Reference* p_redirectindex, Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1463
1464
1465
1466
1467
1468
1469
1470
1471
    : 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;
1472
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
      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;
1483
      port_op.r.redirect.index = p_redirectindex;
1484
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1485
1486
1487
1488
1489
1490
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

1491
  Statement::Statement(statementtype_t p_st, Reference *p_ref, bool p_anyfrom,
Elemer Lelik's avatar
Elemer Lelik committed
1492
                       TemplateInstance *p_fromclause,
1493
1494
                       Reference *p_redirectsender, Reference* p_redirectindex,
                       Reference* p_timestamp_redirect)
Elemer Lelik's avatar
Elemer Lelik committed
1495
1496
1497
1498
1499
    : statementtype(p_st), my_sb(0)
  {
    switch(statementtype) {
    case S_CHECK:
      port_op.portref=p_ref; // may be NULL for "any port.check"
1500
      port_op.anyfrom = p_anyfrom;
Elemer Lelik's avatar
Elemer Lelik committed
1501
1502
1503
1504
      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;
1505
      port_op.r.redirect.index = p_redirectindex;
1506
      port_op.r.redirect.timestamp = p_timestamp_redirect;
Elemer Lelik's avatar
Elemer Lelik committed
1507
1508
1509
1510
1511
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
  
  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
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542

  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,
1543
1544
                       TemplateInstance *p_donematch, ValueRedirect *p_redirect,
                       Reference* p_index_redirect, bool p_any_from)
Elemer Lelik's avatar
Elemer Lelik committed
1545
1546
1547
1548
1549
1550
1551
1552
    : 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;
1553
1554
      comp_op.index_redirect = p_index_redirect;
      comp_op.any_from = p_any_from;
Elemer Lelik's avatar
Elemer Lelik committed
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
      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:
1566
1567
1568
      comp_op.donereturn.donematch = NULL;
      comp_op.donereturn.redirect = NULL;
      // no break
Elemer Lelik's avatar
Elemer Lelik committed
1569
1570
1571
    case S_KILLED:
      comp_op.compref = 0;
      comp_op.any_or_all = p_anyall;
1572
1573
      comp_op.any_from = false;
      comp_op.index_redirect = NULL;
Elemer Lelik's avatar
Elemer Lelik committed
1574
1575
1576
1577
1578
1579
1580
1581
      break;
    default:
      FATAL_ERROR("Statement::Statement()");
    } // switch statementtype
  }

  Statement::Statement(statementtype_t p_st,
                       Value *p_compref1, Reference *p_portref1,
1582
1583
                       Value *p_compref2, Reference *p_portref2,
                       ParsedActualParameters* p_params)
Elemer Lelik's avatar
Elemer Lelik committed
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
    : 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;
1597
      config_op.translate=false;
1598
1599
      config_op.parsed_params=p_params;
      config_op.fp_list=NULL;
Elemer Lelik's avatar
Elemer Lelik committed
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
      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
1622
1623
  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
1624
  {
Elemer Lelik's avatar
Elemer Lelik committed
1625
1626
1627
1628
1629
1630
1631
1632
1633
    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;
1634
1635
1636
1637
1638
1639
1640
    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
1641
1642
1643
    default:
      FATAL_ERROR("Statement::Statement()");
    }
Elemer Lelik's avatar
Elemer Lelik committed
1644
  }
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
  
  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()");
    }
  }
1668
  
1669
  Statement::Statement(statementtype_t p_st, Value* p_val, TemplateInstance* p_ti)
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
  : 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()");
    }
  }
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
    
  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()");
    }
  }
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
  
  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
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728

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

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

  void Statement::dump(unsigned int level) const
  {
1729
    DEBUG(level, "Statement at %p, a(n) %s", static_cast<const void *>(this),
Elemer Lelik's avatar
Elemer Lelik committed
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
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
          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";
1786
    case S_SELECTUNION: return "select-union";
1787
    case S_SELECT_CLASS: return "select-class";
Elemer Lelik's avatar
Elemer Lelik committed
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828