29 * This is part of the 4th stage that generates |
29 * This is part of the 4th stage that generates |
30 * a c++ source program equivalent to the SFC, IL and ST |
30 * a c++ source program equivalent to the SFC, IL and ST |
31 * code. |
31 * code. |
32 */ |
32 */ |
33 |
33 |
34 |
34 typedef struct |
35 |
35 { |
|
36 identifier_c *symbol; |
|
37 } VARIABLE; |
36 |
38 |
37 /***********************************************************************/ |
39 /***********************************************************************/ |
38 /***********************************************************************/ |
40 /***********************************************************************/ |
39 /***********************************************************************/ |
41 /***********************************************************************/ |
40 /***********************************************************************/ |
42 /***********************************************************************/ |
53 actioncount_sd, |
55 actioncount_sd, |
54 transitioncount_sd |
56 transitioncount_sd |
55 } sfcdeclaration_t; |
57 } sfcdeclaration_t; |
56 |
58 |
57 private: |
59 private: |
58 char step_number; |
60 int step_number; |
59 char action_number; |
61 int action_number; |
60 char transition_number; |
62 int transition_number; |
|
63 std::list<VARIABLE> variable_list; |
61 |
64 |
62 sfcdeclaration_t wanted_sfcdeclaration; |
65 sfcdeclaration_t wanted_sfcdeclaration; |
|
66 |
|
67 search_var_instance_decl_c *search_var_instance_decl; |
63 |
68 |
64 public: |
69 public: |
65 generate_c_sfcdecl_c(stage4out_c *s4o_ptr, sfcdeclaration_t sfcdeclaration) |
70 generate_c_sfcdecl_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
66 : generate_c_typedecl_c(s4o_ptr) { |
71 : generate_c_typedecl_c(s4o_ptr) { |
67 wanted_sfcdeclaration = sfcdeclaration; |
|
68 } |
|
69 ~generate_c_sfcdecl_c(void) {} |
|
70 |
|
71 void print(symbol_c *symbol, const char *variable_prefix = NULL) { |
|
72 this->set_variable_prefix(variable_prefix); |
72 this->set_variable_prefix(variable_prefix); |
73 |
73 search_var_instance_decl = new search_var_instance_decl_c(scope); |
|
74 } |
|
75 ~generate_c_sfcdecl_c(void) { |
|
76 variable_list.clear(); |
|
77 delete search_var_instance_decl; |
|
78 } |
|
79 |
|
80 void generate(symbol_c *symbol, sfcdeclaration_t declaration_type) { |
|
81 wanted_sfcdeclaration = declaration_type; |
|
82 |
74 symbol->accept(*this); |
83 symbol->accept(*this); |
75 } |
84 } |
76 |
85 |
77 /*********************************************/ |
86 /*********************************************/ |
78 /* B.1.6 Sequential function chart elements */ |
87 /* B.1.6 Sequential function chart elements */ |
79 /*********************************************/ |
88 /*********************************************/ |
80 |
89 |
81 void *visit(sequential_function_chart_c *symbol) { |
90 void *visit(sequential_function_chart_c *symbol) { |
141 s4o.indent_left(); |
150 s4o.indent_left(); |
142 s4o.print(s4o.indent_spaces + "}\n"); |
151 s4o.print(s4o.indent_spaces + "}\n"); |
143 for(int i = 0; i < symbol->n; i++) |
152 for(int i = 0; i < symbol->n; i++) |
144 symbol->elements[i]->accept(*this); |
153 symbol->elements[i]->accept(*this); |
145 |
154 |
146 /* steps table count */ |
155 /* actions table count */ |
147 wanted_sfcdeclaration = actioncount_sd; |
156 wanted_sfcdeclaration = actioncount_sd; |
148 for(int i = 0; i < symbol->n; i++) |
157 for(int i = 0; i < symbol->n; i++) |
149 symbol->elements[i]->accept(*this); |
158 symbol->elements[i]->accept(*this); |
150 s4o.print(s4o.indent_spaces); |
159 s4o.print(s4o.indent_spaces); |
151 print_variable_prefix(); |
160 print_variable_prefix(); |
190 symbol->elements[i]->accept(*this); |
199 symbol->elements[i]->accept(*this); |
191 s4o.print("\n"); |
200 s4o.print("\n"); |
192 break; |
201 break; |
193 case actiondef_sd: |
202 case actiondef_sd: |
194 s4o.print("// Actions definitions\n"); |
203 s4o.print("// Actions definitions\n"); |
|
204 { |
|
205 std::list<VARIABLE>::iterator pt; |
|
206 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
|
207 s4o.print("#define "); |
|
208 s4o.print(SFC_STEP_ACTION_PREFIX); |
|
209 pt->symbol->accept(*this); |
|
210 s4o.print(" "); |
|
211 s4o.print_integer(action_number); |
|
212 s4o.print("\n"); |
|
213 action_number++; |
|
214 } |
|
215 } |
195 for(int i = 0; i < symbol->n; i++) |
216 for(int i = 0; i < symbol->n; i++) |
196 symbol->elements[i]->accept(*this); |
217 symbol->elements[i]->accept(*this); |
197 s4o.print("\n"); |
218 s4o.print("\n"); |
198 break; |
219 break; |
199 case stepundef_sd: |
220 case stepundef_sd: |
202 symbol->elements[i]->accept(*this); |
223 symbol->elements[i]->accept(*this); |
203 s4o.print("\n"); |
224 s4o.print("\n"); |
204 break; |
225 break; |
205 case actionundef_sd: |
226 case actionundef_sd: |
206 s4o.print("// Actions undefinitions\n"); |
227 s4o.print("// Actions undefinitions\n"); |
|
228 { |
|
229 std::list<VARIABLE>::iterator pt; |
|
230 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
|
231 s4o.print("#undef "); |
|
232 s4o.print(SFC_STEP_ACTION_PREFIX); |
|
233 pt->symbol->accept(*this); |
|
234 s4o.print("\n"); |
|
235 } |
|
236 } |
207 for(int i = 0; i < symbol->n; i++) |
237 for(int i = 0; i < symbol->n; i++) |
208 symbol->elements[i]->accept(*this); |
238 symbol->elements[i]->accept(*this); |
209 s4o.print("\n"); |
239 s4o.print("\n"); |
210 break; |
240 break; |
211 default: |
241 default: |
273 symbol->step_name->accept(*this); |
311 symbol->step_name->accept(*this); |
274 s4o.print("\n"); |
312 s4o.print("\n"); |
275 break; |
313 break; |
276 default: |
314 default: |
277 break; |
315 break; |
|
316 } |
|
317 return NULL; |
|
318 } |
|
319 |
|
320 void *visit(action_association_c *symbol) { |
|
321 /* we try to find the variable instance declaration, to determine if symbol is variable... */ |
|
322 symbol_c *var_decl = search_var_instance_decl->get_decl(symbol->action_name); |
|
323 |
|
324 if (var_decl != NULL) { |
|
325 std::list<VARIABLE>::iterator pt; |
|
326 for(pt = variable_list.begin(); pt != variable_list.end(); pt++) { |
|
327 if (!compare_identifiers(pt->symbol, symbol->action_name)) |
|
328 return NULL; |
|
329 } |
|
330 VARIABLE *variable; |
|
331 variable = new VARIABLE; |
|
332 variable->symbol = (identifier_c*)(symbol->action_name); |
|
333 variable_list.push_back(*variable); |
|
334 action_number++; |
278 } |
335 } |
279 return NULL; |
336 return NULL; |
280 } |
337 } |
281 |
338 |
282 void *visit(transition_c *symbol) { |
339 void *visit(transition_c *symbol) { |