41 |
41 |
42 class generate_cc_sfcdecl_c: protected generate_cc_typedecl_c { |
42 class generate_cc_sfcdecl_c: protected generate_cc_typedecl_c { |
43 |
43 |
44 public: |
44 public: |
45 typedef enum { |
45 typedef enum { |
46 sfcdecl_sg, |
46 sfcdecl_sd, |
47 sfcinit_sg, |
47 sfcinit_sd, |
48 stepdef_sg, |
48 stepdef_sd, |
49 stepundef_sg, |
49 stepundef_sd, |
50 actiondef_sg, |
50 actiondef_sd, |
51 actionundef_sg |
51 actionundef_sd |
52 } sfcgeneration_t; |
52 } sfcdeclaration_t; |
53 |
53 |
54 private: |
54 private: |
55 char step_number; |
55 char step_number; |
56 char action_number; |
56 char action_number; |
57 char transition_number; |
57 char transition_number; |
58 |
58 |
59 sfcgeneration_t wanted_sfcgeneration; |
59 sfcdeclaration_t wanted_sfcdeclaration; |
60 |
60 |
61 public: |
61 public: |
62 generate_cc_sfcdecl_c(stage4out_c *s4o_ptr, sfcgeneration_t sfcgeneration) |
62 generate_cc_sfcdecl_c(stage4out_c *s4o_ptr, sfcdeclaration_t sfcdeclaration) |
63 : generate_cc_typedecl_c(s4o_ptr) { |
63 : generate_cc_typedecl_c(s4o_ptr) { |
64 wanted_sfcgeneration = sfcgeneration; |
64 wanted_sfcdeclaration = sfcdeclaration; |
65 } |
65 } |
66 ~generate_cc_sfcdecl_c(void) {} |
66 ~generate_cc_sfcdecl_c(void) {} |
67 |
67 |
68 void print(symbol_c *symbol, const char *variable_prefix = NULL) { |
68 void print(symbol_c *symbol, const char *variable_prefix = NULL) { |
69 this->set_variable_prefix(variable_prefix); |
69 this->set_variable_prefix(variable_prefix); |
77 |
77 |
78 void *visit(sequential_function_chart_c *symbol) { |
78 void *visit(sequential_function_chart_c *symbol) { |
79 step_number = 0; |
79 step_number = 0; |
80 action_number = 0; |
80 action_number = 0; |
81 transition_number = 0; |
81 transition_number = 0; |
82 switch (wanted_sfcgeneration) { |
82 switch (wanted_sfcdeclaration) { |
83 case sfcdecl_sg: |
83 case sfcdecl_sd: |
84 for(int i = 0; i < symbol->n; i++) |
84 for(int i = 0; i < symbol->n; i++) |
85 symbol->elements[i]->accept(*this); |
85 symbol->elements[i]->accept(*this); |
86 |
86 |
87 /* steps table declaration */ |
87 /* steps table declaration */ |
88 s4o.print(s4o.indent_spaces + "STEP step_list["); |
88 s4o.print(s4o.indent_spaces + "STEP step_list["); |
103 /* transitions table declaration */ |
103 /* transitions table declaration */ |
104 s4o.print(s4o.indent_spaces + "USINT transition_list["); |
104 s4o.print(s4o.indent_spaces + "USINT transition_list["); |
105 s4o.print_integer(transition_number); |
105 s4o.print_integer(transition_number); |
106 s4o.print("];\n"); |
106 s4o.print("];\n"); |
107 break; |
107 break; |
108 case sfcinit_sg: |
108 case sfcinit_sd: |
109 /* steps table initialisation */ |
109 /* steps table initialisation */ |
110 s4o.print(s4o.indent_spaces + "STEP temp_step = {0, 0, 0};\n"); |
110 s4o.print(s4o.indent_spaces + "STEP temp_step = {0, 0, 0};\n"); |
111 s4o.print(s4o.indent_spaces + "for(UINT i = 0; i < "); |
111 s4o.print(s4o.indent_spaces + "for(UINT i = 0; i < "); |
112 print_variable_prefix(); |
112 print_variable_prefix(); |
113 s4o.print("nb_steps; i++) {\n"); |
113 s4o.print("nb_steps; i++) {\n"); |
130 print_variable_prefix(); |
130 print_variable_prefix(); |
131 s4o.print("action_list[i] = temp_action;\n"); |
131 s4o.print("action_list[i] = temp_action;\n"); |
132 s4o.indent_left(); |
132 s4o.indent_left(); |
133 s4o.print(s4o.indent_spaces + "}\n"); |
133 s4o.print(s4o.indent_spaces + "}\n"); |
134 break; |
134 break; |
135 case stepdef_sg: |
135 case stepdef_sd: |
136 s4o.print("// Steps definitions\n"); |
136 s4o.print("// Steps definitions\n"); |
137 for(int i = 0; i < symbol->n; i++) |
137 for(int i = 0; i < symbol->n; i++) |
138 symbol->elements[i]->accept(*this); |
138 symbol->elements[i]->accept(*this); |
139 s4o.print("\n"); |
139 s4o.print("\n"); |
140 break; |
140 break; |
141 case actiondef_sg: |
141 case actiondef_sd: |
142 s4o.print("// Actions definitions\n"); |
142 s4o.print("// Actions definitions\n"); |
143 for(int i = 0; i < symbol->n; i++) |
143 for(int i = 0; i < symbol->n; i++) |
144 symbol->elements[i]->accept(*this); |
144 symbol->elements[i]->accept(*this); |
145 s4o.print("\n"); |
145 s4o.print("\n"); |
146 break; |
146 break; |
147 case stepundef_sg: |
147 case stepundef_sd: |
148 s4o.print("// Steps undefinitions\n"); |
148 s4o.print("// Steps undefinitions\n"); |
149 for(int i = 0; i < symbol->n; i++) |
149 for(int i = 0; i < symbol->n; i++) |
150 symbol->elements[i]->accept(*this); |
150 symbol->elements[i]->accept(*this); |
151 s4o.print("\n"); |
151 s4o.print("\n"); |
152 break; |
152 break; |
153 case actionundef_sg: |
153 case actionundef_sd: |
154 s4o.print("// Actions undefinitions\n"); |
154 s4o.print("// Actions undefinitions\n"); |
155 for(int i = 0; i < symbol->n; i++) |
155 for(int i = 0; i < symbol->n; i++) |
156 symbol->elements[i]->accept(*this); |
156 symbol->elements[i]->accept(*this); |
157 s4o.print("\n"); |
157 s4o.print("\n"); |
158 break; |
158 break; |
159 } |
159 } |
160 return NULL; |
160 return NULL; |
161 } |
161 } |
162 |
162 |
163 void *visit(initial_step_c *symbol) { |
163 void *visit(initial_step_c *symbol) { |
164 switch (wanted_sfcgeneration) { |
164 switch (wanted_sfcdeclaration) { |
165 case sfcdecl_sg: |
165 case sfcdecl_sd: |
166 step_number++; |
166 step_number++; |
167 break; |
167 break; |
168 case sfcinit_sg: |
168 case sfcinit_sd: |
169 s4o.print(s4o.indent_spaces); |
169 s4o.print(s4o.indent_spaces); |
170 print_variable_prefix(); |
170 print_variable_prefix(); |
171 s4o.print("action_list["); |
171 s4o.print("action_list["); |
172 s4o.print_integer(step_number); |
172 s4o.print_integer(step_number); |
173 s4o.print("].state = 1;\n"); |
173 s4o.print("].state = 1;\n"); |
174 step_number++; |
174 step_number++; |
175 break; |
175 break; |
176 case stepdef_sg: |
176 case stepdef_sd: |
177 s4o.print("#define "); |
177 s4o.print("#define "); |
178 s4o.print(SFC_STEP_ACTION_PREFIX); |
178 s4o.print(SFC_STEP_ACTION_PREFIX); |
179 symbol->step_name->accept(*this); |
179 symbol->step_name->accept(*this); |
180 s4o.print(" "); |
180 s4o.print(" "); |
181 s4o.print_integer(step_number); |
181 s4o.print_integer(step_number); |
182 s4o.print("\n"); |
182 s4o.print("\n"); |
183 step_number++; |
183 step_number++; |
184 break; |
184 break; |
185 case stepundef_sg: |
185 case stepundef_sd: |
186 s4o.print("#undef "); |
186 s4o.print("#undef "); |
187 s4o.print(SFC_STEP_ACTION_PREFIX); |
187 s4o.print(SFC_STEP_ACTION_PREFIX); |
188 symbol->step_name->accept(*this); |
188 symbol->step_name->accept(*this); |
189 s4o.print("\n"); |
189 s4o.print("\n"); |
190 break; |
190 break; |
193 } |
193 } |
194 return NULL; |
194 return NULL; |
195 } |
195 } |
196 |
196 |
197 void *visit(step_c *symbol) { |
197 void *visit(step_c *symbol) { |
198 switch (wanted_sfcgeneration) { |
198 switch (wanted_sfcdeclaration) { |
199 case sfcdecl_sg: |
199 case sfcdecl_sd: |
200 step_number++; |
200 step_number++; |
201 break; |
201 break; |
202 case stepdef_sg: |
202 case stepdef_sd: |
203 s4o.print("#define "); |
203 s4o.print("#define "); |
204 s4o.print(SFC_STEP_ACTION_PREFIX); |
204 s4o.print(SFC_STEP_ACTION_PREFIX); |
205 symbol->step_name->accept(*this); |
205 symbol->step_name->accept(*this); |
206 s4o.print(" "); |
206 s4o.print(" "); |
207 s4o.print_integer(step_number); |
207 s4o.print_integer(step_number); |
208 s4o.print("\n"); |
208 s4o.print("\n"); |
209 step_number++; |
209 step_number++; |
210 break; |
210 break; |
211 case stepundef_sg: |
211 case stepundef_sd: |
212 s4o.print("#undef "); |
212 s4o.print("#undef "); |
213 s4o.print(SFC_STEP_ACTION_PREFIX); |
213 s4o.print(SFC_STEP_ACTION_PREFIX); |
214 symbol->step_name->accept(*this); |
214 symbol->step_name->accept(*this); |
215 s4o.print("\n"); |
215 s4o.print("\n"); |
216 break; |
216 break; |
219 } |
219 } |
220 return NULL; |
220 return NULL; |
221 } |
221 } |
222 |
222 |
223 void *visit(transition_c *symbol) { |
223 void *visit(transition_c *symbol) { |
224 switch (wanted_sfcgeneration) { |
224 switch (wanted_sfcdeclaration) { |
225 case sfcdecl_sg: |
225 case sfcdecl_sd: |
226 transition_number++; |
226 transition_number++; |
227 break; |
227 break; |
228 default: |
228 default: |
229 break; |
229 break; |
230 } |
230 } |
231 return NULL; |
231 return NULL; |
232 } |
232 } |
233 |
233 |
234 void *visit(action_c *symbol) { |
234 void *visit(action_c *symbol) { |
235 switch (wanted_sfcgeneration) { |
235 switch (wanted_sfcdeclaration) { |
236 case actiondef_sg: |
236 case actiondef_sd: |
237 s4o.print("#define "); |
237 s4o.print("#define "); |
238 s4o.print(SFC_STEP_ACTION_PREFIX); |
238 s4o.print(SFC_STEP_ACTION_PREFIX); |
239 symbol->action_name->accept(*this); |
239 symbol->action_name->accept(*this); |
240 s4o.print(" "); |
240 s4o.print(" "); |
241 s4o.print_integer(action_number); |
241 s4o.print_integer(action_number); |
242 s4o.print("\n"); |
242 s4o.print("\n"); |
243 action_number++; |
243 action_number++; |
244 break; |
244 break; |
245 case actionundef_sg: |
245 case actionundef_sd: |
246 s4o.print("#undef "); |
246 s4o.print("#undef "); |
247 s4o.print(SFC_STEP_ACTION_PREFIX); |
247 s4o.print(SFC_STEP_ACTION_PREFIX); |
248 symbol->action_name->accept(*this); |
248 symbol->action_name->accept(*this); |
249 s4o.print("\n"); |
249 s4o.print("\n"); |
250 break; |
250 break; |
251 case sfcdecl_sg: |
251 case sfcdecl_sd: |
252 action_number++; |
252 action_number++; |
253 break; |
253 break; |
254 default: |
254 default: |
255 break; |
255 break; |
256 } |
256 } |