Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 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 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Forstner, Matyas | |
11 | * Raduly, Csaba | |
12 | * Szabo, Janos Zoltan – initial implementation | |
13 | * | |
14 | ******************************************************************************/ | |
970ed795 EL |
15 | #ifndef _Ttcn_ILT_HH |
16 | #define _Ttcn_ILT_HH | |
17 | ||
18 | #include "Statement.hh" | |
19 | #include "AST_ttcn3.hh" | |
20 | #include "../Setting.hh" | |
21 | #include "../vector.hh" | |
22 | ||
23 | namespace Ttcn { | |
24 | ||
25 | /** | |
26 | * \addtogroup AST | |
27 | * | |
28 | * @{ | |
29 | */ | |
30 | ||
31 | using namespace Common; | |
32 | ||
33 | class ILT; | |
34 | class ILT_root; | |
35 | class ILT_branch; | |
36 | ||
37 | class ILT : public Node { | |
38 | protected: // ILT_root and ILT_branch need access | |
39 | vector<ILT_branch> branches; | |
40 | private: | |
41 | /** Copy constructor not implemented */ | |
42 | ILT(const ILT& p); | |
43 | /** Assignment not implemented */ | |
44 | ILT& operator=(const ILT& p); | |
45 | public: | |
46 | ILT() : Node() { } | |
47 | virtual ~ILT(); | |
48 | ||
49 | virtual ILT_root* get_my_root() = 0; | |
50 | virtual ILT_branch* get_as_branch(); | |
51 | virtual bool is_toplevel() = 0; | |
52 | virtual char*& get_out_def() = 0; | |
53 | virtual char*& get_out_code() = 0; | |
54 | virtual char*& get_out_branches() = 0; | |
55 | virtual const string& get_my_tmpid() = 0; | |
56 | virtual size_t get_new_tmpnum() = 0; | |
57 | virtual size_t get_new_state_var(bool toplevel) = 0; | |
58 | virtual size_t get_new_state_var_val(size_t p_state_var) = 0; | |
59 | virtual size_t get_new_label_num() = 0; | |
60 | void add_branch(ILT_branch *p_branch); | |
61 | }; | |
62 | ||
63 | /** | |
64 | * Helper class: Interleave Transformation. Used to generate code | |
65 | * for an interleave statement. | |
66 | */ | |
67 | class ILT_root : public ILT { | |
68 | private: | |
69 | Statement *il; /**< interleave */ | |
70 | ||
71 | string mytmpid; | |
72 | size_t tmpnum; | |
73 | size_t c_l; /**< counter for l (label) */ | |
74 | size_t c_b; /**< counter for branch index */ | |
75 | vector<size_t> state_var_vals; | |
76 | ||
77 | char *out_def; | |
78 | char *out_statevars; // 0: unused; 1: ready; 2: toplevel (IL) etc | |
79 | char *out_code; | |
80 | char *out_branches; | |
81 | private: | |
82 | /** Copy constructor not implemented */ | |
83 | ILT_root(const ILT_root& p); | |
84 | /** Assignment not implemented */ | |
85 | ILT_root& operator=(const ILT_root& p); | |
86 | public: | |
87 | /** Constructor; the parameter should be an InterleavedStatement */ | |
88 | ILT_root(Statement *p_il); | |
89 | virtual ~ILT_root(); | |
90 | virtual ILT_root *clone() const; | |
91 | virtual ILT_root* get_my_root(); | |
92 | virtual bool is_toplevel(); | |
93 | virtual char*& get_out_def(); | |
94 | virtual char*& get_out_code(); | |
95 | virtual char*& get_out_branches(); | |
96 | virtual const string& get_my_tmpid(); | |
97 | virtual size_t get_new_tmpnum(); | |
98 | virtual size_t get_new_state_var(bool toplevel); | |
99 | virtual size_t get_new_state_var_val(size_t p_state_var); | |
100 | virtual size_t get_new_label_num(); | |
101 | char* generate_code(char *str); | |
102 | size_t get_new_branch_num() { return c_b++; } | |
103 | }; | |
104 | ||
105 | /** | |
106 | * Helper class for ILT. Represents an alt/receiving branch. | |
107 | */ | |
108 | class ILT_branch : public ILT { | |
109 | public: | |
110 | enum branchtype_t { | |
111 | BT_ALT, // ag | |
112 | BT_IL, // ag | |
113 | BT_RECV // stmt | |
114 | }; | |
115 | ||
116 | private: | |
117 | branchtype_t branchtype; | |
118 | union { | |
119 | AltGuard *ag; | |
120 | Statement *stmt; | |
121 | }; | |
122 | ||
123 | ILT_root *root; | |
124 | size_t branch_i; /**< branch index */ | |
125 | string state_cond; /**< code snippet: "s1==3 && s2==1" */ | |
126 | size_t state_var; /**< the state var number of this branch, e.g.: | |
127 | s5: 5 */ | |
128 | size_t state_var_val; /**< current value of my state var, e.g.: | |
129 | s5==3: 3 */ | |
130 | size_t goto_label_num; /**< goto tmp123_l5: 5 */ | |
131 | private: | |
132 | /** Copy constructor not implemented */ | |
133 | ILT_branch(const ILT_branch& p); | |
134 | /** Assignment not implemented */ | |
135 | ILT_branch& operator=(const ILT_branch& p); | |
136 | public: | |
137 | /** Constructor used by BT_ALT and BT_IL */ | |
138 | ILT_branch(branchtype_t p_bt, AltGuard *p_ag, string p_state_cond, | |
139 | size_t p_state_var, size_t p_state_var_val, | |
140 | size_t p_goto_label_num); | |
141 | /** Constructor used by BT_RECV */ | |
142 | ILT_branch(branchtype_t p_bt, Statement *p_stmt, string p_state_cond, | |
143 | size_t p_state_var, size_t p_state_var_val, | |
144 | size_t p_goto_label_num); | |
145 | virtual ~ILT_branch(); | |
146 | virtual ILT_branch *clone() const; | |
147 | void set_my_root(ILT_root *p_root); | |
148 | virtual ILT_root* get_my_root(); | |
149 | virtual ILT_branch* get_as_branch(); | |
150 | virtual bool is_toplevel(); | |
151 | virtual char*& get_out_def(); | |
152 | virtual char*& get_out_code(); | |
153 | virtual char*& get_out_branches(); | |
154 | virtual const string& get_my_tmpid(); | |
155 | virtual size_t get_new_tmpnum(); | |
156 | virtual size_t get_new_state_var(bool toplevel); | |
157 | virtual size_t get_new_state_var_val(size_t p_state_var); | |
158 | virtual size_t get_new_label_num(); | |
159 | void set_branch_i(size_t p_i) {branch_i=p_i;} | |
160 | const string& get_state_cond() {return state_cond;} | |
161 | size_t get_my_state_var() {return state_var;} | |
162 | size_t get_my_state_var_val() {return state_var_val;} | |
163 | void ilt_generate_code(ILT *ilt); | |
164 | }; | |
165 | ||
166 | } // namespace Ttcn | |
167 | ||
168 | #endif // _Ttcn_ILT_HH | |
169 |