55 /***********************************************************************/ |
55 /***********************************************************************/ |
56 /***********************************************************************/ |
56 /***********************************************************************/ |
57 |
57 |
58 class generate_var_list_c: protected generate_c_typedecl_c { |
58 class generate_var_list_c: protected generate_c_typedecl_c { |
59 |
59 |
|
60 public: |
|
61 typedef enum { |
|
62 none_dt, |
|
63 programs_dt, |
|
64 variables_dt |
|
65 } declarationtype_t; |
|
66 |
|
67 declarationtype_t current_declarationtype; |
|
68 |
60 private: |
69 private: |
61 symbol_c *current_var_type_symbol; |
70 symbol_c *current_var_type_symbol; |
62 unsigned int current_var_number; |
71 unsigned int current_var_number; |
63 unsigned int step_number; |
72 unsigned int step_number; |
64 unsigned int transition_number; |
73 unsigned int transition_number; |
65 unsigned int action_number; |
74 unsigned int action_number; |
|
75 bool configuration_defined; |
66 std::list<SYMBOL> current_symbol_list; |
76 std::list<SYMBOL> current_symbol_list; |
67 search_base_type_c search_base_type; |
77 search_base_type_c search_base_type; |
68 search_fb_typedecl_c *search_fb_typedecl; |
78 search_fb_typedecl_c *search_fb_typedecl; |
69 |
79 |
70 public: |
80 public: |
71 generate_var_list_c(stage4out_c *s4o_ptr, symbol_c *scope) |
81 generate_var_list_c(stage4out_c *s4o_ptr, symbol_c *scope) |
72 : generate_c_typedecl_c(s4o_ptr) { |
82 : generate_c_typedecl_c(s4o_ptr) { |
73 search_fb_typedecl = new search_fb_typedecl_c(scope); |
83 search_fb_typedecl = new search_fb_typedecl_c(scope); |
|
84 current_var_number = 0; |
74 current_var_type_symbol = NULL; |
85 current_var_type_symbol = NULL; |
75 current_var_number = 0; |
86 current_declarationtype = none_dt; |
76 } |
87 } |
77 |
88 |
78 ~generate_var_list_c(void) { |
89 ~generate_var_list_c(void) { |
79 delete search_fb_typedecl; |
90 delete search_fb_typedecl; |
80 } |
91 } |
81 |
92 |
82 void update_var_type_symbol(symbol_c *symbol, bool is_fb = false) { |
93 void update_var_type_symbol(symbol_c *symbol, bool is_fb = false) { |
|
94 |
83 this->current_var_type_symbol = spec_init_sperator_c::get_spec(symbol); |
95 this->current_var_type_symbol = spec_init_sperator_c::get_spec(symbol); |
84 if (this->current_var_type_symbol == NULL) |
96 if (this->current_var_type_symbol == NULL) |
85 ERROR; |
97 ERROR; |
86 |
98 |
87 if (is_fb) |
99 if (is_fb) |
92 ERROR; |
104 ERROR; |
93 } |
105 } |
94 |
106 |
95 void reset_var_type_symbol(void) { |
107 void reset_var_type_symbol(void) { |
96 this->current_var_type_symbol = NULL; |
108 this->current_var_type_symbol = NULL; |
|
109 } |
|
110 |
|
111 void generate_programs(symbol_c *symbol) { |
|
112 s4o.print("// Programs\n"); |
|
113 current_var_number = 0; |
|
114 configuration_defined = false; |
|
115 current_declarationtype = programs_dt; |
|
116 symbol->accept(*this); |
|
117 current_declarationtype = none_dt; |
|
118 s4o.print("\n"); |
|
119 } |
|
120 |
|
121 void generate_variables(symbol_c *symbol) { |
|
122 s4o.print("// Variables\n"); |
|
123 current_var_number = 0; |
|
124 configuration_defined = false; |
|
125 current_declarationtype = variables_dt; |
|
126 symbol->accept(*this); |
|
127 current_declarationtype = none_dt; |
|
128 s4o.print("\n"); |
97 } |
129 } |
98 |
130 |
99 void declare_variables(symbol_c *symbol, const char* type = "VAR") { |
131 void declare_variables(symbol_c *symbol, const char* type = "VAR") { |
100 list_c *list = dynamic_cast<list_c *>(symbol); |
132 list_c *list = dynamic_cast<list_c *>(symbol); |
101 /* should NEVER EVER occur!! */ |
133 /* should NEVER EVER occur!! */ |
161 for(pt = current_symbol_list.begin(); pt != current_symbol_list.end(); pt++) { |
193 for(pt = current_symbol_list.begin(); pt != current_symbol_list.end(); pt++) { |
162 pt->symbol->accept(*this); |
194 pt->symbol->accept(*this); |
163 s4o.print("."); |
195 s4o.print("."); |
164 } |
196 } |
165 } |
197 } |
166 |
198 |
167 /********************************************/ |
199 /********************************************/ |
168 /* B.1.4.3 Declaration and initilization */ |
200 /* B.1.4.3 - Declaration and initialization */ |
169 /********************************************/ |
201 /********************************************/ |
170 |
202 |
171 /* [variable_name] location ':' located_var_spec_init */ |
203 /* [variable_name] location ':' located_var_spec_init */ |
172 /* variable_name -> may be NULL ! */ |
204 /* variable_name -> may be NULL ! */ |
173 //SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
205 //SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
174 void *visit(located_var_decl_c *symbol) { |
206 void *visit(located_var_decl_c *symbol) { |
340 reset_var_type_symbol(); |
372 reset_var_type_symbol(); |
341 |
373 |
342 return NULL; |
374 return NULL; |
343 } |
375 } |
344 |
376 |
|
377 /********************************/ |
|
378 /* B 1.3.3 - Derived data types */ |
|
379 /********************************/ |
|
380 void *visit(data_type_declaration_c *symbol) { |
|
381 return NULL; |
|
382 } |
|
383 |
345 /**************************************/ |
384 /**************************************/ |
346 /* B.1.5 - Program organization units */ |
385 /* B.1.5 - Program organization units */ |
347 /**************************************/ |
386 /**************************************/ |
|
387 |
|
388 /***********************/ |
|
389 /* B 1.5.1 - Functions */ |
|
390 /***********************/ |
|
391 void *visit(function_declaration_c *symbol) { |
|
392 return NULL; |
|
393 } |
348 |
394 |
349 /*****************************/ |
395 /*****************************/ |
350 /* B 1.5.2 - Function Blocks */ |
396 /* B 1.5.2 - Function Blocks */ |
351 /*****************************/ |
397 /*****************************/ |
352 void *visit(function_block_declaration_c *symbol) { |
398 void *visit(function_block_declaration_c *symbol) { |
353 symbol->var_declarations->accept(*this); |
399 if (current_declarationtype == variables_dt && configuration_defined) { |
354 symbol->fblock_body->accept(*this); |
400 symbol->var_declarations->accept(*this); |
|
401 symbol->fblock_body->accept(*this); |
|
402 } |
355 return NULL; |
403 return NULL; |
356 } |
404 } |
357 |
405 |
358 /**********************/ |
406 /**********************/ |
359 /* B 1.5.3 - Programs */ |
407 /* B 1.5.3 - Programs */ |
360 /**********************/ |
408 /**********************/ |
361 void *visit(program_declaration_c *symbol) { |
409 void *visit(program_declaration_c *symbol) { |
362 symbol->var_declarations->accept(*this); |
410 if (current_declarationtype == variables_dt && configuration_defined) { |
363 symbol->function_block_body->accept(*this); |
411 symbol->var_declarations->accept(*this); |
|
412 symbol->function_block_body->accept(*this); |
|
413 } |
364 return NULL; |
414 return NULL; |
365 } |
415 } |
366 |
416 |
367 /**********************************************/ |
417 /**********************************************/ |
368 /* B 1.6 - Sequential function chart elements */ |
418 /* B 1.6 - Sequential function chart elements */ |
482 |
532 |
483 /* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
533 /* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
484 //SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
534 //SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
485 void *visit(program_configuration_c *symbol) { |
535 void *visit(program_configuration_c *symbol) { |
486 |
536 |
487 /* Start off by setting the current_var_type_symbol and |
537 switch (current_declarationtype) { |
488 * current_var_init_symbol private variables... |
538 case programs_dt: |
489 */ |
539 print_var_number(); |
490 update_var_type_symbol(symbol->program_type_name, true); |
540 s4o.print(";"); |
491 |
541 print_symbol_list(); |
492 declare_variable(symbol->program_name, "FB"); |
542 symbol->program_name->accept(*this); |
493 |
543 s4o.print(";"); |
494 /* Values no longer in scope, and therefore no longer used. |
544 symbol->program_type_name->accept(*this); |
495 * Make an effort to keep them set to NULL when not in use |
545 s4o.print(";\n"); |
496 * in order to catch bugs as soon as possible... |
546 break; |
497 */ |
547 case variables_dt: |
498 reset_var_type_symbol(); |
548 /* Start off by setting the current_var_type_symbol and |
|
549 * current_var_init_symbol private variables... |
|
550 */ |
|
551 update_var_type_symbol(symbol->program_type_name, true); |
|
552 |
|
553 declare_variable(symbol->program_name, "FB"); |
|
554 |
|
555 /* Values no longer in scope, and therefore no longer used. |
|
556 * Make an effort to keep them set to NULL when not in use |
|
557 * in order to catch bugs as soon as possible... |
|
558 */ |
|
559 reset_var_type_symbol(); |
|
560 |
|
561 break; |
|
562 default: |
|
563 break; |
|
564 } |
499 |
565 |
500 return NULL; |
566 return NULL; |
501 } |
567 } |
502 |
568 |
503 /* CONFIGURATION configuration_name |
569 /* CONFIGURATION configuration_name |
511 void *visit(configuration_declaration_c *symbol) { |
577 void *visit(configuration_declaration_c *symbol) { |
512 SYMBOL *current_name; |
578 SYMBOL *current_name; |
513 current_name = new SYMBOL; |
579 current_name = new SYMBOL; |
514 current_name->symbol = symbol->configuration_name; |
580 current_name->symbol = symbol->configuration_name; |
515 current_symbol_list.push_back(*current_name); |
581 current_symbol_list.push_back(*current_name); |
|
582 configuration_defined = true; |
516 symbol->resource_declarations->accept(*this); |
583 symbol->resource_declarations->accept(*this); |
517 current_symbol_list.pop_back(); |
584 current_symbol_list.pop_back(); |
|
585 configuration_defined = false; |
518 return NULL; |
586 return NULL; |
519 } |
587 } |
520 |
588 |
521 /* RESOURCE resource_name ON resource_type_name |
589 /* RESOURCE resource_name ON resource_type_name |
522 * optional_global_var_declarations |
590 * optional_global_var_declarations |