78 search_varfb_instance_type_c *search_varfb_instance_type; |
78 search_varfb_instance_type_c *search_varfb_instance_type; |
79 |
79 |
80 search_base_type_c search_base_type; |
80 search_base_type_c search_base_type; |
81 |
81 |
82 symbol_c* current_array_type; |
82 symbol_c* current_array_type; |
|
83 symbol_c* current_param_type; |
83 |
84 |
84 int fcall_number; |
85 int fcall_number; |
85 symbol_c *fbname; |
86 symbol_c *fbname; |
86 |
87 |
87 variablegeneration_t wanted_variablegeneration; |
88 variablegeneration_t wanted_variablegeneration; |
92 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
93 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
93 search_expression_type = new search_expression_type_c(scope); |
94 search_expression_type = new search_expression_type_c(scope); |
94 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
95 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
95 this->set_variable_prefix(variable_prefix); |
96 this->set_variable_prefix(variable_prefix); |
96 current_array_type = NULL; |
97 current_array_type = NULL; |
|
98 current_param_type = NULL; |
97 fcall_number = 0; |
99 fcall_number = 0; |
98 fbname = name; |
100 fbname = name; |
99 wanted_variablegeneration = expression_vg; |
101 wanted_variablegeneration = expression_vg; |
100 } |
102 } |
101 |
103 |
113 |
115 |
114 private: |
116 private: |
115 |
117 |
116 void *print_getter(symbol_c *symbol) { |
118 void *print_getter(symbol_c *symbol) { |
117 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
119 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
118 if (vartype == search_var_instance_decl_c::external_vt) |
120 if (wanted_variablegeneration == fparam_output_vg) { |
119 s4o.print(GET_EXTERNAL); |
121 if (vartype == search_var_instance_decl_c::external_vt) |
120 else if (vartype == search_var_instance_decl_c::located_vt) |
122 s4o.print(GET_EXTERNAL_BY_REF); |
121 s4o.print(GET_LOCATED); |
123 else if (vartype == search_var_instance_decl_c::located_vt) |
122 else |
124 s4o.print(GET_LOCATED_BY_REF); |
123 s4o.print(GET_VAR); |
125 else |
|
126 s4o.print(GET_VAR_BY_REF); |
|
127 } |
|
128 else { |
|
129 if (vartype == search_var_instance_decl_c::external_vt) |
|
130 s4o.print(GET_EXTERNAL); |
|
131 else if (vartype == search_var_instance_decl_c::located_vt) |
|
132 s4o.print(GET_LOCATED); |
|
133 else |
|
134 s4o.print(GET_VAR); |
|
135 } |
124 s4o.print("("); |
136 s4o.print("("); |
125 |
137 |
|
138 variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; |
126 wanted_variablegeneration = complextype_base_vg; |
139 wanted_variablegeneration = complextype_base_vg; |
127 symbol->accept(*this); |
140 symbol->accept(*this); |
128 if (search_varfb_instance_type->type_is_complex()) |
141 if (search_varfb_instance_type->type_is_complex()) |
129 s4o.print(","); |
142 s4o.print(","); |
130 wanted_variablegeneration = complextype_suffix_vg; |
143 wanted_variablegeneration = complextype_suffix_vg; |
131 symbol->accept(*this); |
144 symbol->accept(*this); |
132 s4o.print(")"); |
145 s4o.print(")"); |
133 wanted_variablegeneration = expression_vg; |
146 wanted_variablegeneration = old_wanted_variablegeneration; |
134 return NULL; |
147 return NULL; |
135 } |
148 } |
136 |
149 |
137 void *print_setter(symbol_c* symbol, |
150 void *print_setter(symbol_c* symbol, |
138 symbol_c* type, |
151 symbol_c* type, |
193 else if (wanted_variablegeneration == complextype_suffix_vg) |
206 else if (wanted_variablegeneration == complextype_suffix_vg) |
194 return NULL; |
207 return NULL; |
195 else if (this->is_variable_prefix_null()) { |
208 else if (this->is_variable_prefix_null()) { |
196 vartype = search_varfb_instance_type->get_vartype(symbol); |
209 vartype = search_varfb_instance_type->get_vartype(symbol); |
197 if (wanted_variablegeneration == fparam_output_vg) { |
210 if (wanted_variablegeneration == fparam_output_vg) { |
198 if (vartype == search_var_instance_decl_c::external_vt) |
211 if (vartype == search_var_instance_decl_c::inoutput_vt) |
199 s4o.print(GET_EXTERNAL); |
212 generate_c_base_c::visit(symbol); |
200 else |
213 else { |
201 s4o.print("&"); |
214 s4o.print("&("); |
202 s4o.print("("); |
215 generate_c_base_c::visit(symbol); |
203 generate_c_base_c::visit(symbol); |
216 s4o.print(")"); |
204 s4o.print(")"); |
217 } |
205 } |
218 } |
206 else { |
219 else { |
207 if (vartype == search_var_instance_decl_c::external_vt) { |
220 if (vartype == search_var_instance_decl_c::inoutput_vt) { |
208 s4o.print(GET_EXTERNAL); |
221 s4o.print("(*"); |
209 s4o.print("("); |
|
210 generate_c_base_c::visit(symbol); |
222 generate_c_base_c::visit(symbol); |
211 s4o.print(")"); |
223 s4o.print(")"); |
212 } |
224 } |
213 else |
225 else |
214 generate_c_base_c::visit(symbol); |
226 generate_c_base_c::visit(symbol); |
215 } |
227 } |
216 } |
228 } |
217 else { |
229 else |
218 switch (wanted_variablegeneration) { |
230 print_getter(symbol); |
219 case expression_vg: |
|
220 vartype = search_varfb_instance_type->get_vartype(symbol); |
|
221 if (vartype == search_var_instance_decl_c::external_vt) |
|
222 s4o.print(GET_EXTERNAL); |
|
223 else if (vartype == search_var_instance_decl_c::located_vt) |
|
224 s4o.print(GET_LOCATED); |
|
225 else |
|
226 s4o.print(GET_VAR); |
|
227 s4o.print("("); |
|
228 generate_c_base_c::visit(symbol); |
|
229 s4o.print(")"); |
|
230 break; |
|
231 case fparam_output_vg: |
|
232 vartype = search_varfb_instance_type->get_vartype(symbol); |
|
233 if (vartype == search_var_instance_decl_c::external_vt) |
|
234 s4o.print(GET_EXTERNAL_BY_REF); |
|
235 else if (vartype == search_var_instance_decl_c::located_vt) |
|
236 s4o.print(GET_LOCATED_BY_REF); |
|
237 else |
|
238 s4o.print(GET_VAR_BY_REF); |
|
239 s4o.print("("); |
|
240 generate_c_base_c::visit(symbol); |
|
241 s4o.print(")"); |
|
242 break; |
|
243 default: |
|
244 generate_c_base_c::visit(symbol); |
|
245 break; |
|
246 } |
|
247 } |
|
248 return NULL; |
231 return NULL; |
249 } |
232 } |
250 |
233 |
251 /********************************************/ |
234 /********************************************/ |
252 /* B.1.4.1 Directly Represented Variables */ |
235 /* B.1.4.1 Directly Represented Variables */ |
354 s4o.print(")]"); |
337 s4o.print(")]"); |
355 } |
338 } |
356 return NULL; |
339 return NULL; |
357 } |
340 } |
358 |
341 |
|
342 /******************************************/ |
|
343 /* B 1.4.3 - Declaration & Initialisation */ |
|
344 /******************************************/ |
|
345 void *visit(structure_element_initialization_list_c *symbol) { |
|
346 generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
347 structure_initialization->init_structure_default(this->current_param_type); |
|
348 structure_initialization->current_mode = generate_c_structure_initialization_c::initializationvalue_sm; |
|
349 symbol->accept(*structure_initialization); |
|
350 delete structure_initialization; |
|
351 return NULL; |
|
352 } |
359 |
353 |
360 /***************************************/ |
354 /***************************************/ |
361 /* B.3 - Language ST (Structured Text) */ |
355 /* B.3 - Language ST (Structured Text) */ |
362 /***************************************/ |
356 /***************************************/ |
363 /***********************/ |
357 /***********************/ |
609 |
603 |
610 symbol_c *function_return_type = search_expression_type->get_type(symbol); |
604 symbol_c *function_return_type = search_expression_type->get_type(symbol); |
611 |
605 |
612 int nb_param = ((list_c *)parameter_assignment_list)->n; |
606 int nb_param = ((list_c *)parameter_assignment_list)->n; |
613 |
607 |
614 identifier_c en_param_name("EN"); |
608 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
615 /* Get the value from EN param */ |
609 /* Get the value from EN param */ |
616 symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); |
610 symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
617 if (EN_param_value == NULL) |
611 if (EN_param_value == NULL) |
618 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
612 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
619 else |
613 else |
620 nb_param --; |
614 nb_param --; |
621 ADD_PARAM_LIST(&en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
615 ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
622 |
616 |
623 identifier_c eno_param_name("ENO"); |
617 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
624 /* Get the value from ENO param */ |
618 /* Get the value from ENO param */ |
625 symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); |
619 symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
626 if (ENO_param_value != NULL) |
620 if (ENO_param_value != NULL) |
627 nb_param --; |
621 nb_param --; |
628 ADD_PARAM_LIST(&eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
622 ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
629 |
623 |
630 #include "st_code_gen.c" |
624 #include "st_code_gen.c" |
631 |
625 |
632 } |
626 } |
633 else { |
627 else { |
690 fcall_number++; |
684 fcall_number++; |
691 s4o.print("__"); |
685 s4o.print("__"); |
692 fbname->accept(*this); |
686 fbname->accept(*this); |
693 s4o.print("_"); |
687 s4o.print("_"); |
694 function_name->accept(*this); |
688 function_name->accept(*this); |
|
689 if (function_type_suffix != NULL) |
|
690 function_type_suffix->accept(*this); |
695 s4o.print_integer(fcall_number); |
691 s4o.print_integer(fcall_number); |
696 } |
692 } |
697 else { |
693 else { |
698 function_name->accept(*this); |
694 function_name->accept(*this); |
699 if (function_type_suffix != NULL) |
695 if (function_type_suffix != NULL) |
703 s4o.indent_right(); |
699 s4o.indent_right(); |
704 |
700 |
705 int nb_param = 0; |
701 int nb_param = 0; |
706 PARAM_LIST_ITERATOR() { |
702 PARAM_LIST_ITERATOR() { |
707 symbol_c *param_value = PARAM_VALUE; |
703 symbol_c *param_value = PARAM_VALUE; |
708 symbol_c *param_type = PARAM_TYPE; |
704 current_param_type = PARAM_TYPE; |
709 |
705 |
710 switch (PARAM_DIRECTION) { |
706 switch (PARAM_DIRECTION) { |
711 case function_param_iterator_c::direction_in: |
707 case function_param_iterator_c::direction_in: |
712 if (nb_param > 0) |
708 if (nb_param > 0) |
713 s4o.print(",\n"+s4o.indent_spaces); |
709 s4o.print(",\n"+s4o.indent_spaces); |
714 if (param_value == NULL) { |
710 if (param_value == NULL) { |
715 /* If not, get the default value of this variable's type */ |
711 /* If not, get the default value of this variable's type */ |
716 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
712 param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
717 } |
713 } |
718 if (param_value == NULL) ERROR; |
714 if (param_value == NULL) ERROR; |
719 s4o.print("("); |
715 s4o.print("("); |
720 if (search_expression_type->is_literal_integer_type(param_type)) |
716 if (search_expression_type->is_literal_integer_type(current_param_type)) |
721 search_expression_type->lint_type_name.accept(*this); |
717 search_expression_type->lint_type_name.accept(*this); |
722 else if (search_expression_type->is_literal_real_type(param_type)) |
718 else if (search_expression_type->is_literal_real_type(current_param_type)) |
723 search_expression_type->lreal_type_name.accept(*this); |
719 search_expression_type->lreal_type_name.accept(*this); |
724 else |
720 else |
725 param_type->accept(*this); |
721 current_param_type->accept(*this); |
726 s4o.print(")"); |
722 s4o.print(")"); |
727 print_check_function(param_type, param_value); |
723 print_check_function(current_param_type, param_value); |
728 nb_param++; |
724 nb_param++; |
729 break; |
725 break; |
730 case function_param_iterator_c::direction_out: |
726 case function_param_iterator_c::direction_out: |
731 case function_param_iterator_c::direction_inout: |
727 case function_param_iterator_c::direction_inout: |
732 if (!has_output_params) { |
728 if (!has_output_params) { |