94 |
94 |
95 void reset_var_type_symbol(void) { |
95 void reset_var_type_symbol(void) { |
96 this->current_var_type_symbol = NULL; |
96 this->current_var_type_symbol = NULL; |
97 } |
97 } |
98 |
98 |
99 void declare_variables(symbol_c *symbol, bool is_fb = false) { |
99 void declare_variables(symbol_c *symbol, const char* type = "VAR") { |
100 list_c *list = dynamic_cast<list_c *>(symbol); |
100 list_c *list = dynamic_cast<list_c *>(symbol); |
101 /* should NEVER EVER occur!! */ |
101 /* should NEVER EVER occur!! */ |
102 if (list == NULL) ERROR; |
102 if (list == NULL) ERROR; |
103 |
103 |
104 for(int i = 0; i < list->n; i++) { |
104 for(int i = 0; i < list->n; i++) { |
105 declare_variable(list->elements[i], is_fb); |
105 declare_variable(list->elements[i], type); |
106 } |
106 } |
107 } |
107 } |
108 |
108 |
109 void declare_variable(symbol_c *symbol, bool is_fb = false) { |
109 void declare_variable(symbol_c *symbol, const char* type = "VAR") { |
110 if (is_fb) { |
110 if (strcmp(type, "FB") == 0) { |
111 SYMBOL *current_name; |
111 SYMBOL *current_name; |
112 current_name = new SYMBOL; |
112 current_name = new SYMBOL; |
113 current_name->symbol = symbol; |
113 current_name->symbol = symbol; |
114 current_symbol_list.push_back(*current_name); |
114 current_symbol_list.push_back(*current_name); |
115 this->current_var_type_symbol->accept(*this); |
115 this->current_var_type_symbol->accept(*this); |
116 current_symbol_list.pop_back(); |
116 current_symbol_list.pop_back(); |
117 } |
117 } |
118 else { |
118 else { |
119 print_var_number(); |
119 print_var_number(); |
|
120 s4o.print(";"); |
|
121 s4o.print(type); |
120 s4o.print(";"); |
122 s4o.print(";"); |
121 print_symbol_list(); |
123 print_symbol_list(); |
122 symbol->accept(*this); |
124 symbol->accept(*this); |
123 s4o.print(";"); |
125 s4o.print(";"); |
124 print_symbol_list(); |
126 print_symbol_list(); |
174 * current_var_init_symbol private variables... |
176 * current_var_init_symbol private variables... |
175 */ |
177 */ |
176 update_var_type_symbol(symbol->located_var_spec_init); |
178 update_var_type_symbol(symbol->located_var_spec_init); |
177 |
179 |
178 if (symbol->variable_name != NULL) |
180 if (symbol->variable_name != NULL) |
179 declare_variable(symbol->variable_name); |
181 declare_variable(symbol->variable_name, "PT"); |
180 |
182 |
181 current_var_type_symbol = NULL; |
183 current_var_type_symbol = NULL; |
182 return NULL; |
184 return NULL; |
183 } |
185 } |
184 |
186 |
239 * current_var_init_symbol private variables... |
241 * current_var_init_symbol private variables... |
240 */ |
242 */ |
241 update_var_type_symbol(symbol, true); |
243 update_var_type_symbol(symbol, true); |
242 |
244 |
243 /* now to produce the c equivalent... */ |
245 /* now to produce the c equivalent... */ |
244 declare_variables(symbol->fb_name_list, true); |
246 declare_variables(symbol->fb_name_list, "FB"); |
245 |
247 |
246 /* Values no longer in scope, and therefore no longer used. |
248 /* Values no longer in scope, and therefore no longer used. |
247 * Make an effort to keep them set to NULL when not in use |
249 * Make an effort to keep them set to NULL when not in use |
248 * in order to catch bugs as soon as possible... |
250 * in order to catch bugs as soon as possible... |
249 */ |
251 */ |
265 */ |
267 */ |
266 this->current_var_type_symbol = (symbol_c *)(symbol->specification->accept(*search_fb_typedecl)); |
268 this->current_var_type_symbol = (symbol_c *)(symbol->specification->accept(*search_fb_typedecl)); |
267 if (this->current_var_type_symbol == NULL) { |
269 if (this->current_var_type_symbol == NULL) { |
268 this->current_var_type_symbol = symbol->specification; |
270 this->current_var_type_symbol = symbol->specification; |
269 |
271 |
270 declare_variable(symbol->global_var_name); |
272 declare_variable(symbol->global_var_name, "PT"); |
271 } |
273 } |
272 else |
274 else |
273 declare_variable(symbol->global_var_name, true); |
275 declare_variable(symbol->global_var_name, "FB"); |
274 |
276 |
275 /* Values no longer in scope, and therefore no longer used. |
277 /* Values no longer in scope, and therefore no longer used. |
276 * Make an effort to keep them set to NULL when not in use |
278 * Make an effort to keep them set to NULL when not in use |
277 * in order to catch bugs as soon as possible... |
279 * in order to catch bugs as soon as possible... |
278 */ |
280 */ |
380 |
382 |
381 /* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
383 /* INITIAL_STEP step_name ':' action_association_list END_STEP */ |
382 //SYM_REF2(initial_step_c, step_name, action_association_list) |
384 //SYM_REF2(initial_step_c, step_name, action_association_list) |
383 void *visit(initial_step_c *symbol) { |
385 void *visit(initial_step_c *symbol) { |
384 print_var_number(); |
386 print_var_number(); |
385 s4o.print(";"); |
387 s4o.print(";VAR;"); |
386 print_symbol_list(); |
388 print_symbol_list(); |
387 symbol->step_name->accept(*this); |
389 symbol->step_name->accept(*this); |
388 s4o.print(".X;"); |
390 s4o.print(".X;"); |
389 print_symbol_list(); |
391 print_symbol_list(); |
390 s4o.print("step_list["); |
392 s4o.print("step_list["); |
396 |
398 |
397 /* STEP step_name ':' action_association_list END_STEP */ |
399 /* STEP step_name ':' action_association_list END_STEP */ |
398 //SYM_REF2(step_c, step_name, action_association_list) |
400 //SYM_REF2(step_c, step_name, action_association_list) |
399 void *visit(step_c *symbol) { |
401 void *visit(step_c *symbol) { |
400 print_var_number(); |
402 print_var_number(); |
401 s4o.print(";"); |
403 s4o.print(";VAR;"); |
402 print_symbol_list(); |
404 print_symbol_list(); |
403 symbol->step_name->accept(*this); |
405 symbol->step_name->accept(*this); |
404 s4o.print(".X;"); |
406 s4o.print(".X;"); |
405 print_symbol_list(); |
407 print_symbol_list(); |
406 s4o.print("step_list["); |
408 s4o.print("step_list["); |
418 /* transition_name -> may be NULL ! */ |
420 /* transition_name -> may be NULL ! */ |
419 /* integer -> may be NULL ! */ |
421 /* integer -> may be NULL ! */ |
420 //SYM_REF5(transition_c, transition_name, integer, from_steps, to_steps, transition_condition) |
422 //SYM_REF5(transition_c, transition_name, integer, from_steps, to_steps, transition_condition) |
421 void *visit(transition_c *symbol) { |
423 void *visit(transition_c *symbol) { |
422 print_var_number(); |
424 print_var_number(); |
423 s4o.print(";"); |
425 s4o.print(";VAR;"); |
424 print_symbol_list(); |
426 print_symbol_list(); |
425 symbol->from_steps->accept(*this); |
427 symbol->from_steps->accept(*this); |
426 s4o.print("->"); |
428 s4o.print("->"); |
427 symbol->to_steps->accept(*this); |
429 symbol->to_steps->accept(*this); |
428 s4o.print(";"); |
430 s4o.print(";"); |
459 |
461 |
460 /* ACTION action_name ':' function_block_body END_ACTION */ |
462 /* ACTION action_name ':' function_block_body END_ACTION */ |
461 //SYM_REF2(action_c, action_name, function_block_body) |
463 //SYM_REF2(action_c, action_name, function_block_body) |
462 void *visit(action_c *symbol) { |
464 void *visit(action_c *symbol) { |
463 print_var_number(); |
465 print_var_number(); |
464 s4o.print(";"); |
466 s4o.print(";VAR;"); |
465 print_symbol_list(); |
467 print_symbol_list(); |
466 symbol->action_name->accept(*this); |
468 symbol->action_name->accept(*this); |
467 s4o.print(".Q;"); |
469 s4o.print(".Q;"); |
468 print_symbol_list(); |
470 print_symbol_list(); |
469 s4o.print("action_list["); |
471 s4o.print("action_list["); |
485 /* Start off by setting the current_var_type_symbol and |
487 /* Start off by setting the current_var_type_symbol and |
486 * current_var_init_symbol private variables... |
488 * current_var_init_symbol private variables... |
487 */ |
489 */ |
488 update_var_type_symbol(symbol->program_type_name, true); |
490 update_var_type_symbol(symbol->program_type_name, true); |
489 |
491 |
490 declare_variable(symbol->program_name, true); |
492 declare_variable(symbol->program_name, "FB"); |
491 |
493 |
492 /* Values no longer in scope, and therefore no longer used. |
494 /* Values no longer in scope, and therefore no longer used. |
493 * Make an effort to keep them set to NULL when not in use |
495 * Make an effort to keep them set to NULL when not in use |
494 * in order to catch bugs as soon as possible... |
496 * in order to catch bugs as soon as possible... |
495 */ |
497 */ |