1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
11 #include "Statement.hh"
12 #include "AST_ttcn3.hh"
13 #include "../Setting.hh"
14 #include "../vector.hh"
24 using namespace Common;
30 class ILT : public Node {
31 protected: // ILT_root and ILT_branch need access
32 vector<ILT_branch> branches;
34 /** Copy constructor not implemented */
36 /** Assignment not implemented */
37 ILT& operator=(const ILT& p);
42 virtual ILT_root* get_my_root() = 0;
43 virtual ILT_branch* get_as_branch();
44 virtual bool is_toplevel() = 0;
45 virtual char*& get_out_def() = 0;
46 virtual char*& get_out_code() = 0;
47 virtual char*& get_out_branches() = 0;
48 virtual const string& get_my_tmpid() = 0;
49 virtual size_t get_new_tmpnum() = 0;
50 virtual size_t get_new_state_var(bool toplevel) = 0;
51 virtual size_t get_new_state_var_val(size_t p_state_var) = 0;
52 virtual size_t get_new_label_num() = 0;
53 void add_branch(ILT_branch *p_branch);
57 * Helper class: Interleave Transformation. Used to generate code
58 * for an interleave statement.
60 class ILT_root : public ILT {
62 Statement *il; /**< interleave */
66 size_t c_l; /**< counter for l (label) */
67 size_t c_b; /**< counter for branch index */
68 vector<size_t> state_var_vals;
71 char *out_statevars; // 0: unused; 1: ready; 2: toplevel (IL) etc
75 /** Copy constructor not implemented */
76 ILT_root(const ILT_root& p);
77 /** Assignment not implemented */
78 ILT_root& operator=(const ILT_root& p);
80 /** Constructor; the parameter should be an InterleavedStatement */
81 ILT_root(Statement *p_il);
83 virtual ILT_root *clone() const;
84 virtual ILT_root* get_my_root();
85 virtual bool is_toplevel();
86 virtual char*& get_out_def();
87 virtual char*& get_out_code();
88 virtual char*& get_out_branches();
89 virtual const string& get_my_tmpid();
90 virtual size_t get_new_tmpnum();
91 virtual size_t get_new_state_var(bool toplevel);
92 virtual size_t get_new_state_var_val(size_t p_state_var);
93 virtual size_t get_new_label_num();
94 char* generate_code(char *str);
95 size_t get_new_branch_num() { return c_b++; }
99 * Helper class for ILT. Represents an alt/receiving branch.
101 class ILT_branch : public ILT {
110 branchtype_t branchtype;
117 size_t branch_i; /**< branch index */
118 string state_cond; /**< code snippet: "s1==3 && s2==1" */
119 size_t state_var; /**< the state var number of this branch, e.g.:
121 size_t state_var_val; /**< current value of my state var, e.g.:
123 size_t goto_label_num; /**< goto tmp123_l5: 5 */
125 /** Copy constructor not implemented */
126 ILT_branch(const ILT_branch& p);
127 /** Assignment not implemented */
128 ILT_branch& operator=(const ILT_branch& p);
130 /** Constructor used by BT_ALT and BT_IL */
131 ILT_branch(branchtype_t p_bt, AltGuard *p_ag, string p_state_cond,
132 size_t p_state_var, size_t p_state_var_val,
133 size_t p_goto_label_num);
134 /** Constructor used by BT_RECV */
135 ILT_branch(branchtype_t p_bt, Statement *p_stmt, string p_state_cond,
136 size_t p_state_var, size_t p_state_var_val,
137 size_t p_goto_label_num);
138 virtual ~ILT_branch();
139 virtual ILT_branch *clone() const;
140 void set_my_root(ILT_root *p_root);
141 virtual ILT_root* get_my_root();
142 virtual ILT_branch* get_as_branch();
143 virtual bool is_toplevel();
144 virtual char*& get_out_def();
145 virtual char*& get_out_code();
146 virtual char*& get_out_branches();
147 virtual const string& get_my_tmpid();
148 virtual size_t get_new_tmpnum();
149 virtual size_t get_new_state_var(bool toplevel);
150 virtual size_t get_new_state_var_val(size_t p_state_var);
151 virtual size_t get_new_label_num();
152 void set_branch_i(size_t p_i) {branch_i=p_i;}
153 const string& get_state_cond() {return state_cond;}
154 size_t get_my_state_var() {return state_var;}
155 size_t get_my_state_var_val() {return state_var_val;}
156 void ilt_generate_code(ILT *ilt);
161 #endif // _Ttcn_ILT_HH