264 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
265 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
265 current_operand = NULL; |
266 current_operand = NULL; |
266 current_operand_type = NULL; |
267 current_operand_type = NULL; |
267 il_default_variable_init_value = NULL; |
268 il_default_variable_init_value = NULL; |
268 current_array_type = NULL; |
269 current_array_type = NULL; |
|
270 current_param_type = NULL; |
269 fcall_number = 0; |
271 fcall_number = 0; |
270 fbname = name; |
272 fbname = name; |
271 wanted_variablegeneration = expression_vg; |
273 wanted_variablegeneration = expression_vg; |
272 this->set_variable_prefix(variable_prefix); |
274 this->set_variable_prefix(variable_prefix); |
273 } |
275 } |
433 this->current_operand_type = this->default_variable_name.current_type; |
435 this->current_operand_type = this->default_variable_name.current_type; |
434 } |
436 } |
435 |
437 |
436 void *print_getter(symbol_c *symbol) { |
438 void *print_getter(symbol_c *symbol) { |
437 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
439 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
438 if (vartype == search_var_instance_decl_c::external_vt) |
440 if (wanted_variablegeneration == fparam_output_vg) { |
439 s4o.print(GET_EXTERNAL); |
441 if (vartype == search_var_instance_decl_c::external_vt) |
440 else if (vartype == search_var_instance_decl_c::located_vt) |
442 s4o.print(GET_EXTERNAL_BY_REF); |
441 s4o.print(GET_LOCATED); |
443 else if (vartype == search_var_instance_decl_c::located_vt) |
442 else |
444 s4o.print(GET_LOCATED_BY_REF); |
443 s4o.print(GET_VAR); |
445 else |
|
446 s4o.print(GET_VAR_BY_REF); |
|
447 } |
|
448 else { |
|
449 if (vartype == search_var_instance_decl_c::external_vt) |
|
450 s4o.print(GET_EXTERNAL); |
|
451 else if (vartype == search_var_instance_decl_c::located_vt) |
|
452 s4o.print(GET_LOCATED); |
|
453 else |
|
454 s4o.print(GET_VAR); |
|
455 } |
444 s4o.print("("); |
456 s4o.print("("); |
445 |
457 |
|
458 variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; |
446 wanted_variablegeneration = complextype_base_vg; |
459 wanted_variablegeneration = complextype_base_vg; |
447 symbol->accept(*this); |
460 symbol->accept(*this); |
448 if (search_varfb_instance_type->type_is_complex()) |
461 if (search_varfb_instance_type->type_is_complex()) |
449 s4o.print(","); |
462 s4o.print(","); |
450 wanted_variablegeneration = complextype_suffix_vg; |
463 wanted_variablegeneration = complextype_suffix_vg; |
451 symbol->accept(*this); |
464 symbol->accept(*this); |
452 s4o.print(")"); |
465 s4o.print(")"); |
453 wanted_variablegeneration = expression_vg; |
466 wanted_variablegeneration = old_wanted_variablegeneration; |
454 return NULL; |
467 return NULL; |
455 } |
468 } |
456 |
469 |
457 void *print_setter(symbol_c* symbol, |
470 void *print_setter(symbol_c* symbol, |
458 symbol_c* type, |
471 symbol_c* type, |
577 } |
590 } |
578 else |
591 else |
579 generate_c_base_c::visit(symbol); |
592 generate_c_base_c::visit(symbol); |
580 } |
593 } |
581 } |
594 } |
582 else { |
595 else |
583 switch (wanted_variablegeneration) { |
596 print_getter(symbol); |
584 case expression_vg: |
|
585 vartype = search_varfb_instance_type->get_vartype(symbol); |
|
586 if (vartype == search_var_instance_decl_c::external_vt) |
|
587 s4o.print(GET_EXTERNAL); |
|
588 else if (vartype == search_var_instance_decl_c::located_vt) |
|
589 s4o.print(GET_LOCATED); |
|
590 else |
|
591 s4o.print(GET_VAR); |
|
592 s4o.print("("); |
|
593 generate_c_base_c::visit(symbol); |
|
594 s4o.print(")"); |
|
595 break; |
|
596 case fparam_output_vg: |
|
597 vartype = search_varfb_instance_type->get_vartype(symbol); |
|
598 if (vartype == search_var_instance_decl_c::external_vt) |
|
599 s4o.print(GET_EXTERNAL_BY_REF); |
|
600 else if (vartype == search_var_instance_decl_c::located_vt) |
|
601 s4o.print(GET_LOCATED_BY_REF); |
|
602 else |
|
603 s4o.print(GET_VAR_BY_REF); |
|
604 s4o.print("("); |
|
605 generate_c_base_c::visit(symbol); |
|
606 s4o.print(")"); |
|
607 break; |
|
608 default: |
|
609 generate_c_base_c::visit(symbol); |
|
610 break; |
|
611 } |
|
612 } |
|
613 return NULL; |
597 return NULL; |
614 } |
598 } |
615 |
599 |
616 /********************************************/ |
600 /********************************************/ |
617 /* B.1.4.1 Directly Represented Variables */ |
601 /* B.1.4.1 Directly Represented Variables */ |
716 print_integer(i); |
700 print_integer(i); |
717 s4o.print("("); |
701 s4o.print("("); |
718 symbol->elements[i]->accept(*this); |
702 symbol->elements[i]->accept(*this); |
719 s4o.print(")]"); |
703 s4o.print(")]"); |
720 } |
704 } |
|
705 return NULL; |
|
706 } |
|
707 |
|
708 /******************************************/ |
|
709 /* B 1.4.3 - Declaration & Initialisation */ |
|
710 /******************************************/ |
|
711 void *visit(structure_element_initialization_list_c *symbol) { |
|
712 generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
713 structure_initialization->init_structure_default(this->current_param_type); |
|
714 structure_initialization->current_mode = generate_c_structure_initialization_c::initializationvalue_sm; |
|
715 symbol->accept(*structure_initialization); |
|
716 delete structure_initialization; |
721 return NULL; |
717 return NULL; |
722 } |
718 } |
723 |
719 |
724 /****************************************/ |
720 /****************************************/ |
725 /* B.2 - Language IL (Instruction List) */ |
721 /* B.2 - Language IL (Instruction List) */ |
822 |
818 |
823 |
819 |
824 /* | function_name [il_operand_list] */ |
820 /* | function_name [il_operand_list] */ |
825 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
821 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
826 void *visit(il_function_call_c *symbol) { |
822 void *visit(il_function_call_c *symbol) { |
827 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
828 |
|
829 symbol_c* function_type_prefix = NULL; |
823 symbol_c* function_type_prefix = NULL; |
830 symbol_c* function_name = NULL; |
824 symbol_c* function_name = NULL; |
831 symbol_c* function_type_suffix = NULL; |
825 symbol_c* function_type_suffix = NULL; |
832 DECLARE_PARAM_LIST() |
826 DECLARE_PARAM_LIST() |
833 |
827 |
834 symbol_c *param_data_type = default_variable_name.current_type; |
828 symbol_c *param_data_type = default_variable_name.current_type; |
835 symbol_c *return_data_type = NULL; |
829 symbol_c *return_data_type = NULL; |
836 |
830 |
837 function_call_param_iterator_c function_call_param_iterator(symbol); |
831 function_call_param_iterator_c function_call_param_iterator(symbol); |
838 |
832 |
|
833 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
839 if (f_decl == function_symtable.end_value()) { |
834 if (f_decl == function_symtable.end_value()) { |
840 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
835 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
841 if (current_function_type == function_none) ERROR; |
836 if (current_function_type == function_none) ERROR; |
842 |
837 |
843 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
838 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
844 if (NULL == return_data_type) ERROR; |
839 if (NULL == return_data_type) ERROR; |
845 |
840 |
846 identifier_c en_param_name("EN"); |
841 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
847 /* Add the value from EN param */ |
842 /* Add the value from EN param */ |
848 ADD_PARAM_LIST(&en_param_name, |
843 ADD_PARAM_LIST(en_param_name, |
849 (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
844 (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
850 (symbol_c*)(new bool_type_name_c()), |
845 (symbol_c*)(new bool_type_name_c()), |
851 function_param_iterator_c::direction_in) |
846 function_param_iterator_c::direction_in) |
852 |
847 |
853 identifier_c eno_param_name("ENO"); |
848 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
854 /* Add the value from ENO param */ |
849 /* Add the value from ENO param */ |
855 ADD_PARAM_LIST(&eno_param_name, NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
850 ADD_PARAM_LIST(eno_param_name, NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
856 |
851 |
857 int nb_param = 1; |
852 int nb_param = 1; |
858 if (symbol->il_operand_list != NULL) |
853 if (symbol->il_operand_list != NULL) |
859 nb_param += ((list_c *)symbol->il_operand_list)->n; |
854 nb_param += ((list_c *)symbol->il_operand_list)->n; |
860 |
855 |
960 s4o.indent_right(); |
955 s4o.indent_right(); |
961 |
956 |
962 int nb_param = 0; |
957 int nb_param = 0; |
963 PARAM_LIST_ITERATOR() { |
958 PARAM_LIST_ITERATOR() { |
964 symbol_c *param_value = PARAM_VALUE; |
959 symbol_c *param_value = PARAM_VALUE; |
965 symbol_c *param_type = PARAM_TYPE; |
960 current_param_type = PARAM_TYPE; |
966 |
961 |
967 switch (PARAM_DIRECTION) { |
962 switch (PARAM_DIRECTION) { |
968 case function_param_iterator_c::direction_in: |
963 case function_param_iterator_c::direction_in: |
969 if (nb_param > 0) |
964 if (nb_param > 0) |
970 s4o.print(",\n"+s4o.indent_spaces); |
965 s4o.print(",\n"+s4o.indent_spaces); |
971 if (param_value == NULL) { |
966 if (param_value == NULL) { |
972 /* If not, get the default value of this variable's type */ |
967 /* If not, get the default value of this variable's type */ |
973 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
968 param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
974 } |
969 } |
975 if (param_value == NULL) ERROR; |
970 if (param_value == NULL) ERROR; |
976 s4o.print("("); |
971 s4o.print("("); |
977 if (search_expression_type->is_literal_integer_type(param_type)) |
972 if (search_expression_type->is_literal_integer_type(current_param_type)) |
978 search_expression_type->lint_type_name.accept(*this); |
973 search_expression_type->lint_type_name.accept(*this); |
979 else if (search_expression_type->is_literal_real_type(param_type)) |
974 else if (search_expression_type->is_literal_real_type(current_param_type)) |
980 search_expression_type->lreal_type_name.accept(*this); |
975 search_expression_type->lreal_type_name.accept(*this); |
981 else |
976 else |
982 param_type->accept(*this); |
977 current_param_type->accept(*this); |
983 s4o.print(")"); |
978 s4o.print(")"); |
984 print_check_function(param_type, param_value); |
979 print_check_function(current_param_type, param_value); |
985 nb_param++; |
980 nb_param++; |
986 break; |
981 break; |
987 case function_param_iterator_c::direction_out: |
982 case function_param_iterator_c::direction_out: |
988 case function_param_iterator_c::direction_inout: |
983 case function_param_iterator_c::direction_inout: |
989 if (!has_output_params) { |
984 if (!has_output_params) { |
1188 |
1183 |
1189 |
1184 |
1190 /* | function_name '(' eol_list [il_param_list] ')' */ |
1185 /* | function_name '(' eol_list [il_param_list] ')' */ |
1191 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
1186 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
1192 void *visit(il_formal_funct_call_c *symbol) { |
1187 void *visit(il_formal_funct_call_c *symbol) { |
1193 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
1194 |
|
1195 symbol_c* function_type_prefix = NULL; |
1188 symbol_c* function_type_prefix = NULL; |
1196 symbol_c* function_name = NULL; |
1189 symbol_c* function_name = NULL; |
1197 symbol_c* function_type_suffix = NULL; |
1190 symbol_c* function_type_suffix = NULL; |
1198 DECLARE_PARAM_LIST() |
1191 DECLARE_PARAM_LIST() |
1199 |
1192 |
1200 symbol_c *return_data_type = NULL; |
1193 symbol_c *return_data_type = NULL; |
1201 |
1194 |
1202 function_call_param_iterator_c function_call_param_iterator(symbol); |
1195 function_call_param_iterator_c function_call_param_iterator(symbol); |
1203 |
1196 |
|
1197 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
1204 if (f_decl == function_symtable.end_value()) { |
1198 if (f_decl == function_symtable.end_value()) { |
1205 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
1199 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
1206 if (current_function_type == function_none) ERROR; |
1200 if (current_function_type == function_none) ERROR; |
1207 |
1201 |
1208 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
1202 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
1210 |
1204 |
1211 int nb_param = 0; |
1205 int nb_param = 0; |
1212 if (symbol->il_param_list != NULL) |
1206 if (symbol->il_param_list != NULL) |
1213 nb_param += ((list_c *)symbol->il_param_list)->n; |
1207 nb_param += ((list_c *)symbol->il_param_list)->n; |
1214 |
1208 |
1215 identifier_c en_param_name("EN"); |
1209 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
1216 /* Get the value from EN param */ |
1210 /* Get the value from EN param */ |
1217 symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); |
1211 symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
1218 if (EN_param_value == NULL) |
1212 if (EN_param_value == NULL) |
1219 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
1213 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
1220 else |
1214 else |
1221 nb_param --; |
1215 nb_param --; |
1222 ADD_PARAM_LIST(&en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
1216 ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
1223 |
1217 |
1224 identifier_c eno_param_name("EN0"); |
1218 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
1225 /* Get the value from ENO param */ |
1219 /* Get the value from ENO param */ |
1226 symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); |
1220 symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
1227 if (ENO_param_value != NULL) |
1221 if (ENO_param_value != NULL) |
1228 nb_param --; |
1222 nb_param --; |
1229 ADD_PARAM_LIST(&eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
1223 ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
1230 |
1224 |
1231 #include "st_code_gen.c" |
1225 #include "st_code_gen.c" |
1232 |
1226 |
1233 } |
1227 } |
1234 else { |
1228 else { |
1324 s4o.indent_right(); |
1318 s4o.indent_right(); |
1325 |
1319 |
1326 int nb_param = 0; |
1320 int nb_param = 0; |
1327 PARAM_LIST_ITERATOR() { |
1321 PARAM_LIST_ITERATOR() { |
1328 symbol_c *param_value = PARAM_VALUE; |
1322 symbol_c *param_value = PARAM_VALUE; |
1329 symbol_c *param_type = PARAM_TYPE; |
1323 current_param_type = PARAM_TYPE; |
1330 |
1324 |
1331 switch (PARAM_DIRECTION) { |
1325 switch (PARAM_DIRECTION) { |
1332 case function_param_iterator_c::direction_in: |
1326 case function_param_iterator_c::direction_in: |
1333 if (nb_param > 0) |
1327 if (nb_param > 0) |
1334 s4o.print(",\n"+s4o.indent_spaces); |
1328 s4o.print(",\n"+s4o.indent_spaces); |
1335 if (param_value == NULL) { |
1329 if (param_value == NULL) { |
1336 /* If not, get the default value of this variable's type */ |
1330 /* If not, get the default value of this variable's type */ |
1337 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
1331 param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
1338 } |
1332 } |
1339 if (param_value == NULL) ERROR; |
1333 if (param_value == NULL) ERROR; |
1340 s4o.print("("); |
1334 s4o.print("("); |
1341 if (search_expression_type->is_literal_integer_type(param_type)) |
1335 if (search_expression_type->is_literal_integer_type(current_param_type)) |
1342 search_expression_type->lint_type_name.accept(*this); |
1336 search_expression_type->lint_type_name.accept(*this); |
1343 else if (search_expression_type->is_literal_real_type(param_type)) |
1337 else if (search_expression_type->is_literal_real_type(current_param_type)) |
1344 search_expression_type->lreal_type_name.accept(*this); |
1338 search_expression_type->lreal_type_name.accept(*this); |
1345 else |
1339 else |
1346 param_type->accept(*this); |
1340 current_param_type->accept(*this); |
1347 s4o.print(")"); |
1341 s4o.print(")"); |
1348 print_check_function(param_type, param_value); |
1342 print_check_function(current_param_type, param_value); |
1349 nb_param++; |
1343 nb_param++; |
1350 break; |
1344 break; |
1351 case function_param_iterator_c::direction_out: |
1345 case function_param_iterator_c::direction_out: |
1352 case function_param_iterator_c::direction_inout: |
1346 case function_param_iterator_c::direction_inout: |
1353 if (!has_output_params) { |
1347 if (!has_output_params) { |