235 if (debug) std::cout << "end_function() [" << fcall->candidate_datatypes.size() << "] result.\n"; |
235 if (debug) std::cout << "end_function() [" << fcall->candidate_datatypes.size() << "] result.\n"; |
236 return; |
236 return; |
237 } |
237 } |
238 |
238 |
239 |
239 |
240 |
240 /* handle implicit FB call in IL. |
|
241 * e.g. CLK ton_car |
|
242 * CU counter_var |
|
243 * |
|
244 * The algorithm will be to build a fake il_fb_call_c equivalent to the implicit IL FB call, and let |
|
245 * the visit(il_fb_call_c *) method handle it! |
|
246 */ |
|
247 void fill_candidate_datatypes_c::handle_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) { |
|
248 symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(il_operand); |
|
249 /* This is a call to a non-declared FB/Variable is a semantic error (which is currently caught by stage 2, so this should never occur) |
|
250 * or no operand was given (il_operand == NULL). In this case, we just give up! |
|
251 */ |
|
252 if (NULL == fb_type_id) |
|
253 return; |
|
254 |
|
255 function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id); |
|
256 if (function_block_type_symtable.end_value() == fb_decl) |
|
257 /* The il_operand is not the name of a FB instance. Most probably it is the name of a variable of some other type. |
|
258 * this is a smeantic error, so there is no way we can evaluate the rest of the code. We simply give up, and leave |
|
259 * the candidate_datatype_list empty, and the called_fb_declaration pointing to NULL |
|
260 */ |
|
261 return; |
|
262 |
|
263 |
|
264 identifier_c variable_name(param_name); |
|
265 // SYM_REF1(il_assign_operator_c, variable_name) |
|
266 il_assign_operator_c il_assign_operator(&variable_name); |
|
267 // SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list) |
|
268 il_param_assignment_c il_param_assignment(&il_assign_operator, prev_il_instruction/*il_operand*/, NULL); |
|
269 il_param_list_c il_param_list; |
|
270 il_param_list.add_element(&il_param_assignment); |
|
271 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration) |
|
272 il_fb_call_c il_fb_call(NULL, il_operand, NULL, &il_param_list); |
|
273 |
|
274 il_fb_call.accept(*this); |
|
275 copy_candidate_datatype_list(&il_fb_call/*from*/, il_instruction/*to*/); |
|
276 called_fb_declaration = il_fb_call.called_fb_declaration; |
|
277 } |
241 |
278 |
242 |
279 |
243 /* a helper function... */ |
280 /* a helper function... */ |
244 symbol_c *fill_candidate_datatypes_c::base_type(symbol_c *symbol) { |
281 symbol_c *fill_candidate_datatypes_c::base_type(symbol_c *symbol) { |
245 /* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used |
282 /* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used |
969 |
1006 |
970 void *fill_candidate_datatypes_c::visit(NOT_operator_c *symbol) { |
1007 void *fill_candidate_datatypes_c::visit(NOT_operator_c *symbol) { |
971 return NULL; |
1008 return NULL; |
972 } |
1009 } |
973 |
1010 |
|
1011 |
974 void *fill_candidate_datatypes_c::visit(S_operator_c *symbol) { |
1012 void *fill_candidate_datatypes_c::visit(S_operator_c *symbol) { |
|
1013 /* TODO: what if this is a FB call ?? */ |
975 symbol_c *prev_instruction_type, *operand_type; |
1014 symbol_c *prev_instruction_type, *operand_type; |
976 |
1015 |
977 if (NULL == prev_il_instruction) return NULL; |
1016 if (NULL == prev_il_instruction) return NULL; |
978 for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
1017 for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
979 for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
1018 for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
985 } |
1024 } |
986 if (debug) std::cout << "S [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
1025 if (debug) std::cout << "S [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
987 return NULL; |
1026 return NULL; |
988 } |
1027 } |
989 |
1028 |
|
1029 |
990 void *fill_candidate_datatypes_c::visit(R_operator_c *symbol) { |
1030 void *fill_candidate_datatypes_c::visit(R_operator_c *symbol) { |
|
1031 /* TODO: what if this is a FB call ?? */ |
991 symbol_c *prev_instruction_type, *operand_type; |
1032 symbol_c *prev_instruction_type, *operand_type; |
992 |
1033 |
993 if (NULL == prev_il_instruction) return NULL; |
1034 if (NULL == prev_il_instruction) return NULL; |
994 for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
1035 for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
995 for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
1036 for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
1001 } |
1042 } |
1002 if (debug) std::cout << "R [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
1043 if (debug) std::cout << "R [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
1003 return NULL; |
1044 return NULL; |
1004 } |
1045 } |
1005 |
1046 |
|
1047 |
1006 void *fill_candidate_datatypes_c::visit(S1_operator_c *symbol) { |
1048 void *fill_candidate_datatypes_c::visit(S1_operator_c *symbol) { |
1007 symbol_c *prev_instruction_type, *operand_type; |
1049 handle_implicit_il_fb_call(symbol, "S1", symbol->called_fb_declaration); |
1008 |
|
1009 if (NULL == prev_il_instruction) return NULL; |
|
1010 for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
|
1011 for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
|
1012 prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; |
|
1013 operand_type = il_operand->candidate_datatypes[j]; |
|
1014 if (is_type_equal(prev_instruction_type,operand_type) && is_ANY_BOOL_compatible(operand_type)) |
|
1015 symbol->candidate_datatypes.push_back(prev_instruction_type); |
|
1016 } |
|
1017 } |
|
1018 if (debug) std::cout << "S1 [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
|
1019 return NULL; |
1050 return NULL; |
1020 } |
1051 } |
1021 |
1052 |
1022 void *fill_candidate_datatypes_c::visit(R1_operator_c *symbol) { |
1053 void *fill_candidate_datatypes_c::visit(R1_operator_c *symbol) { |
1023 symbol_c *prev_instruction_type, *operand_type; |
1054 handle_implicit_il_fb_call(symbol, "R1", symbol->called_fb_declaration); |
1024 |
|
1025 if (NULL == prev_il_instruction) return NULL; |
|
1026 for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { |
|
1027 for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) { |
|
1028 prev_instruction_type = prev_il_instruction->candidate_datatypes[i]; |
|
1029 operand_type = il_operand->candidate_datatypes[j]; |
|
1030 if (is_type_equal(prev_instruction_type,operand_type) && is_ANY_BOOL_compatible(operand_type)) |
|
1031 symbol->candidate_datatypes.push_back(prev_instruction_type); |
|
1032 } |
|
1033 } |
|
1034 if (debug) std::cout << "R1 [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
|
1035 return NULL; |
1055 return NULL; |
1036 } |
1056 } |
1037 |
1057 |
1038 void *fill_candidate_datatypes_c::visit(CLK_operator_c *symbol) { |
1058 void *fill_candidate_datatypes_c::visit(CLK_operator_c *symbol) { |
1039 /* MANU: |
1059 handle_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration); |
1040 * How it works? I(MANU) don't know this function |
|
1041 */ |
|
1042 return NULL; |
1060 return NULL; |
1043 } |
1061 } |
1044 |
1062 |
1045 void *fill_candidate_datatypes_c::visit(CU_operator_c *symbol) { |
1063 void *fill_candidate_datatypes_c::visit(CU_operator_c *symbol) { |
1046 /* MANU: |
1064 handle_implicit_il_fb_call(symbol, "CU", symbol->called_fb_declaration); |
1047 * How it works? I(MANU) don't know this function |
|
1048 */ |
|
1049 return NULL; |
1065 return NULL; |
1050 } |
1066 } |
1051 |
1067 |
1052 void *fill_candidate_datatypes_c::visit(CD_operator_c *symbol) { |
1068 void *fill_candidate_datatypes_c::visit(CD_operator_c *symbol) { |
1053 /* MANU: |
1069 handle_implicit_il_fb_call(symbol, "CD", symbol->called_fb_declaration); |
1054 * How it works? I(MANU) don't know this function |
|
1055 */ |
|
1056 return NULL; |
1070 return NULL; |
1057 } |
1071 } |
1058 |
1072 |
1059 void *fill_candidate_datatypes_c::visit(PV_operator_c *symbol) { |
1073 void *fill_candidate_datatypes_c::visit(PV_operator_c *symbol) { |
1060 /* MANU: |
1074 handle_implicit_il_fb_call(symbol, "PV", symbol->called_fb_declaration); |
1061 * How it works? I(MANU) don't know this function |
|
1062 */ |
|
1063 return NULL; |
1075 return NULL; |
1064 } |
1076 } |
1065 |
1077 |
1066 void *fill_candidate_datatypes_c::visit(IN_operator_c *symbol) { |
1078 void *fill_candidate_datatypes_c::visit(IN_operator_c *symbol) { |
1067 /* MANU: |
1079 handle_implicit_il_fb_call(symbol, "IN", symbol->called_fb_declaration); |
1068 * How it works? I(MANU) don't know this function |
|
1069 */ |
|
1070 return NULL; |
1080 return NULL; |
1071 } |
1081 } |
1072 |
1082 |
1073 void *fill_candidate_datatypes_c::visit(PT_operator_c *symbol) { |
1083 void *fill_candidate_datatypes_c::visit(PT_operator_c *symbol) { |
1074 /* MANU: |
1084 handle_implicit_il_fb_call(symbol, "PT", symbol->called_fb_declaration); |
1075 * How it works? I(MANU) don't know this function |
1085 return NULL; |
1076 */ |
1086 } |
1077 return NULL; |
1087 |
1078 } |
|
1079 |
1088 |
1080 void *fill_candidate_datatypes_c::visit(AND_operator_c *symbol) { |
1089 void *fill_candidate_datatypes_c::visit(AND_operator_c *symbol) { |
1081 symbol_c *prev_instruction_type, *operand_type; |
1090 symbol_c *prev_instruction_type, *operand_type; |
1082 |
1091 |
1083 if (NULL == prev_il_instruction) return NULL; |
1092 if (NULL == prev_il_instruction) return NULL; |