Commit | Line | Data |
---|---|---|
970ed795 EL |
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 | /////////////////////////////////////////////////////////////////////////////// | |
8 | #ifndef _Ttcn_ILT_HH | |
9 | #define _Ttcn_ILT_HH | |
10 | ||
11 | #include "Statement.hh" | |
12 | #include "AST_ttcn3.hh" | |
13 | #include "../Setting.hh" | |
14 | #include "../vector.hh" | |
15 | ||
16 | namespace Ttcn { | |
17 | ||
18 | /** | |
19 | * \addtogroup AST | |
20 | * | |
21 | * @{ | |
22 | */ | |
23 | ||
24 | using namespace Common; | |
25 | ||
26 | class ILT; | |
27 | class ILT_root; | |
28 | class ILT_branch; | |
29 | ||
30 | class ILT : public Node { | |
31 | protected: // ILT_root and ILT_branch need access | |
32 | vector<ILT_branch> branches; | |
33 | private: | |
34 | /** Copy constructor not implemented */ | |
35 | ILT(const ILT& p); | |
36 | /** Assignment not implemented */ | |
37 | ILT& operator=(const ILT& p); | |
38 | public: | |
39 | ILT() : Node() { } | |
40 | virtual ~ILT(); | |
41 | ||
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); | |
54 | }; | |
55 | ||
56 | /** | |
57 | * Helper class: Interleave Transformation. Used to generate code | |
58 | * for an interleave statement. | |
59 | */ | |
60 | class ILT_root : public ILT { | |
61 | private: | |
62 | Statement *il; /**< interleave */ | |
63 | ||
64 | string mytmpid; | |
65 | size_t tmpnum; | |
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; | |
69 | ||
70 | char *out_def; | |
71 | char *out_statevars; // 0: unused; 1: ready; 2: toplevel (IL) etc | |
72 | char *out_code; | |
73 | char *out_branches; | |
74 | private: | |
75 | /** Copy constructor not implemented */ | |
76 | ILT_root(const ILT_root& p); | |
77 | /** Assignment not implemented */ | |
78 | ILT_root& operator=(const ILT_root& p); | |
79 | public: | |
80 | /** Constructor; the parameter should be an InterleavedStatement */ | |
81 | ILT_root(Statement *p_il); | |
82 | virtual ~ILT_root(); | |
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++; } | |
96 | }; | |
97 | ||
98 | /** | |
99 | * Helper class for ILT. Represents an alt/receiving branch. | |
100 | */ | |
101 | class ILT_branch : public ILT { | |
102 | public: | |
103 | enum branchtype_t { | |
104 | BT_ALT, // ag | |
105 | BT_IL, // ag | |
106 | BT_RECV // stmt | |
107 | }; | |
108 | ||
109 | private: | |
110 | branchtype_t branchtype; | |
111 | union { | |
112 | AltGuard *ag; | |
113 | Statement *stmt; | |
114 | }; | |
115 | ||
116 | ILT_root *root; | |
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.: | |
120 | s5: 5 */ | |
121 | size_t state_var_val; /**< current value of my state var, e.g.: | |
122 | s5==3: 3 */ | |
123 | size_t goto_label_num; /**< goto tmp123_l5: 5 */ | |
124 | private: | |
125 | /** Copy constructor not implemented */ | |
126 | ILT_branch(const ILT_branch& p); | |
127 | /** Assignment not implemented */ | |
128 | ILT_branch& operator=(const ILT_branch& p); | |
129 | public: | |
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); | |
157 | }; | |
158 | ||
159 | } // namespace Ttcn | |
160 | ||
161 | #endif // _Ttcn_ILT_HH | |
162 |