236 return; |
236 return; |
237 } |
237 } |
238 |
238 |
239 |
239 |
240 |
240 |
241 void print_datatypes_error_c::handle_implicit_il_fb_invocation(symbol_c *il_operator, const char *param_name, symbol_c *called_fb_declaration) { |
241 void *print_datatypes_error_c::handle_implicit_il_fb_invocation(const char *param_name, symbol_c *il_operator, symbol_c *called_fb_declaration) { |
242 if (NULL == il_operand) { |
242 if (NULL == il_operand) { |
243 STAGE3_ERROR(0, il_operator, il_operator, "Missing operand for FB call operator '%s'.", param_name); |
243 STAGE3_ERROR(0, il_operator, il_operator, "Missing operand for FB call operator '%s'.", param_name); |
244 return; |
244 return NULL; |
245 } |
245 } |
246 il_operand->accept(*this); |
246 il_operand->accept(*this); |
247 |
247 |
248 if (NULL == called_fb_declaration) { |
248 if (NULL == called_fb_declaration) { |
249 STAGE3_ERROR(0, il_operator, il_operand, "Invalid FB call: operand is not a FB instance."); |
249 STAGE3_ERROR(0, il_operator, il_operand, "Invalid FB call: operand is not a FB instance."); |
250 return; |
250 return NULL; |
251 } |
251 } |
252 |
252 |
253 if (fake_prev_il_instruction->prev_il_instruction.empty()) { |
253 if (fake_prev_il_instruction->prev_il_instruction.empty()) { |
254 STAGE3_ERROR(0, il_operator, il_operand, "FB invocation operator '%s' must be preceded by a 'LD' (or equivalent) operator.", param_name); |
254 STAGE3_ERROR(0, il_operator, il_operand, "FB invocation operator '%s' must be preceded by a 'LD' (or equivalent) operator.", param_name); |
255 return; |
255 return NULL; |
256 } |
256 } |
257 |
257 |
258 /* Find the corresponding parameter in function declaration */ |
258 /* Find the corresponding parameter in function declaration */ |
259 function_param_iterator_c fp_iterator(called_fb_declaration); |
259 function_param_iterator_c fp_iterator(called_fb_declaration); |
260 if (NULL == fp_iterator.search(param_name)) { |
260 if (NULL == fp_iterator.search(param_name)) { |
264 * if a non-standard (i.e. a FB not defined in the standard library) FB is being called, then |
264 * if a non-standard (i.e. a FB not defined in the standard library) FB is being called, then |
265 * this (CLK, PT, IN, CU, ...) parameter may just have been defined as OUT or INOUT, |
265 * this (CLK, PT, IN, CU, ...) parameter may just have been defined as OUT or INOUT, |
266 * which will not work for an implicit FB call! |
266 * which will not work for an implicit FB call! |
267 */ |
267 */ |
268 STAGE3_ERROR(0, il_operator, il_operand, "FB called by '%s' operator does not have a parameter named '%s'", param_name, param_name); |
268 STAGE3_ERROR(0, il_operator, il_operand, "FB called by '%s' operator does not have a parameter named '%s'", param_name, param_name); |
269 return; |
269 return NULL; |
270 } |
270 } |
271 if (!are_all_datatypes_of_prev_il_instructions_datatypes_equal(fake_prev_il_instruction)) { |
271 if (!are_all_datatypes_of_prev_il_instructions_datatypes_equal(fake_prev_il_instruction)) { |
272 STAGE3_ERROR(0, il_operator, il_operand, "Data type incompatibility between parameter '%s' and value being passed.", param_name); |
272 STAGE3_ERROR(0, il_operator, il_operand, "Data type incompatibility between parameter '%s' and value being passed.", param_name); |
273 return; |
273 return NULL; |
274 } |
274 } |
275 |
275 |
276 |
276 |
277 /* NOTE: The error_level currently being used for errors in variables/constants etc... is rather high. |
277 /* NOTE: The error_level currently being used for errors in variables/constants etc... is rather high. |
278 * However, in the case of an implicit FB call, if the datatype of the operand == NULL, this may be |
278 * However, in the case of an implicit FB call, if the datatype of the operand == NULL, this may be |
281 */ |
281 */ |
282 if (NULL == il_operand->datatype) { |
282 if (NULL == il_operand->datatype) { |
283 /* Note: the case of (NULL == fb_declaration) was already caught above! */ |
283 /* Note: the case of (NULL == fb_declaration) was already caught above! */ |
284 // if (NULL != fb_declaration) { |
284 // if (NULL != fb_declaration) { |
285 STAGE3_ERROR(0, il_operator, il_operator, "Invalid FB call: Datatype incompatibility between the FB's '%s' parameter and value being passed, or paramater '%s' is not a 'VAR_INPUT' parameter.", param_name, param_name); |
285 STAGE3_ERROR(0, il_operator, il_operator, "Invalid FB call: Datatype incompatibility between the FB's '%s' parameter and value being passed, or paramater '%s' is not a 'VAR_INPUT' parameter.", param_name, param_name); |
286 return; |
286 return NULL; |
287 // } |
287 // } |
288 } |
288 } |
289 // |
289 |
290 return; |
290 return NULL; |
291 } |
291 } |
292 |
292 |
293 |
293 |
294 /*********************/ |
294 /*********************/ |
295 /* B 1.2 - Constants */ |
295 /* B 1.2 - Constants */ |
814 // void *visit(il_param_out_assignment_c *symbol); |
814 // void *visit(il_param_out_assignment_c *symbol); |
815 |
815 |
816 /*******************/ |
816 /*******************/ |
817 /* B 2.2 Operators */ |
817 /* B 2.2 Operators */ |
818 /*******************/ |
818 /*******************/ |
|
819 void *print_datatypes_error_c::print_binary_operator_errors(const char *il_operator, symbol_c *symbol, bool deprecated_operation) { |
|
820 if ((symbol->candidate_datatypes.size() == 0) && (il_operand->candidate_datatypes.size() > 0)) { |
|
821 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' operator.", il_operator); |
|
822 } else if (NULL == symbol->datatype) { |
|
823 STAGE3_WARNING(symbol, symbol, "Result of '%s' operation is never used.", il_operator); |
|
824 } else if (deprecated_operation) |
|
825 STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' operator.", il_operator); |
|
826 return NULL; |
|
827 } |
|
828 |
|
829 |
819 void *print_datatypes_error_c::visit(LD_operator_c *symbol) { |
830 void *print_datatypes_error_c::visit(LD_operator_c *symbol) { |
820 return NULL; |
831 return NULL; |
821 } |
832 } |
822 |
833 |
823 void *print_datatypes_error_c::visit(LDN_operator_c *symbol) { |
834 void *print_datatypes_error_c::visit(LDN_operator_c *symbol) { |
878 (il_operand->candidate_datatypes.size() > 0)) |
889 (il_operand->candidate_datatypes.size() > 0)) |
879 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'R' operator."); |
890 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'R' operator."); |
880 return NULL; |
891 return NULL; |
881 } |
892 } |
882 |
893 |
883 void *print_datatypes_error_c::visit(S1_operator_c *symbol) { |
894 void *print_datatypes_error_c::visit( S1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "S1", symbol, symbol->called_fb_declaration);} |
884 handle_implicit_il_fb_invocation(symbol, "S1", symbol->called_fb_declaration); |
895 void *print_datatypes_error_c::visit( R1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "R1", symbol, symbol->called_fb_declaration);} |
885 return NULL; |
896 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) {return handle_implicit_il_fb_invocation("CLK", symbol, symbol->called_fb_declaration);} |
886 } |
897 void *print_datatypes_error_c::visit( CU_operator_c *symbol) {return handle_implicit_il_fb_invocation( "CU", symbol, symbol->called_fb_declaration);} |
887 |
898 void *print_datatypes_error_c::visit( CD_operator_c *symbol) {return handle_implicit_il_fb_invocation( "CD", symbol, symbol->called_fb_declaration);} |
888 void *print_datatypes_error_c::visit(R1_operator_c *symbol) { |
899 void *print_datatypes_error_c::visit( PV_operator_c *symbol) {return handle_implicit_il_fb_invocation( "PV", symbol, symbol->called_fb_declaration);} |
889 handle_implicit_il_fb_invocation(symbol, "R1", symbol->called_fb_declaration); |
900 void *print_datatypes_error_c::visit( IN_operator_c *symbol) {return handle_implicit_il_fb_invocation( "IN", symbol, symbol->called_fb_declaration);} |
890 return NULL; |
901 void *print_datatypes_error_c::visit( PT_operator_c *symbol) {return handle_implicit_il_fb_invocation( "PT", symbol, symbol->called_fb_declaration);} |
891 } |
902 |
892 |
903 void *print_datatypes_error_c::visit(AND_operator_c *symbol) {return print_binary_operator_errors("AND", symbol);} |
893 void *print_datatypes_error_c::visit(CLK_operator_c *symbol) { |
904 void *print_datatypes_error_c::visit( OR_operator_c *symbol) {return print_binary_operator_errors( "OR", symbol);} |
894 handle_implicit_il_fb_invocation(symbol, "CLK", symbol->called_fb_declaration); |
905 void *print_datatypes_error_c::visit(XOR_operator_c *symbol) {return print_binary_operator_errors("XOR", symbol);} |
895 return NULL; |
|
896 } |
|
897 |
|
898 void *print_datatypes_error_c::visit(CU_operator_c *symbol) { |
|
899 handle_implicit_il_fb_invocation(symbol, "CU", symbol->called_fb_declaration); |
|
900 return NULL; |
|
901 } |
|
902 |
|
903 void *print_datatypes_error_c::visit(CD_operator_c *symbol) { |
|
904 handle_implicit_il_fb_invocation(symbol, "CD", symbol->called_fb_declaration); |
|
905 return NULL; |
|
906 } |
|
907 |
|
908 void *print_datatypes_error_c::visit(PV_operator_c *symbol) { |
|
909 handle_implicit_il_fb_invocation(symbol, "PV", symbol->called_fb_declaration); |
|
910 return NULL; |
|
911 } |
|
912 |
|
913 void *print_datatypes_error_c::visit(IN_operator_c *symbol) { |
|
914 handle_implicit_il_fb_invocation(symbol, "IN", symbol->called_fb_declaration); |
|
915 return NULL; |
|
916 } |
|
917 |
|
918 void *print_datatypes_error_c::visit(PT_operator_c *symbol) { |
|
919 handle_implicit_il_fb_invocation(symbol, "PT", symbol->called_fb_declaration); |
|
920 return NULL; |
|
921 } |
|
922 |
|
923 void *print_datatypes_error_c::visit(AND_operator_c *symbol) { |
|
924 if ((symbol->candidate_datatypes.size() == 0) && |
|
925 (il_operand->candidate_datatypes.size() > 0)) |
|
926 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'AND' operator."); |
|
927 return NULL; |
|
928 } |
|
929 |
|
930 void *print_datatypes_error_c::visit(OR_operator_c *symbol) { |
|
931 if ((symbol->candidate_datatypes.size() == 0) && |
|
932 (il_operand->candidate_datatypes.size() > 0)) |
|
933 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'OR' operator."); |
|
934 return NULL; |
|
935 } |
|
936 |
|
937 void *print_datatypes_error_c::visit(XOR_operator_c *symbol) { |
|
938 if ((symbol->candidate_datatypes.size() == 0) && |
|
939 (il_operand->candidate_datatypes.size() > 0)) |
|
940 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'XOR' operator."); |
|
941 return NULL; |
|
942 } |
|
943 |
906 |
944 void *print_datatypes_error_c::visit(ANDN_operator_c *symbol) { |
907 void *print_datatypes_error_c::visit(ANDN_operator_c *symbol) { |
945 if ((symbol->candidate_datatypes.size() == 0) && |
908 if ((symbol->candidate_datatypes.size() == 0) && |
946 (il_operand->candidate_datatypes.size() > 0)) |
909 (il_operand->candidate_datatypes.size() > 0)) |
947 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ANDN' operator."); |
910 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ANDN' operator."); |
960 (il_operand->candidate_datatypes.size() > 0)) |
923 (il_operand->candidate_datatypes.size() > 0)) |
961 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ORN' operator."); |
924 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ORN' operator."); |
962 return NULL; |
925 return NULL; |
963 } |
926 } |
964 |
927 |
965 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) { |
928 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) {return print_binary_operator_errors("ADD", symbol, symbol->deprecated_operation);} |
966 if ((symbol->candidate_datatypes.size() == 0) && |
929 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) {return print_binary_operator_errors("SUB", symbol, symbol->deprecated_operation);} |
967 (il_operand->candidate_datatypes.size() > 0)) |
930 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) {return print_binary_operator_errors("MUL", symbol, symbol->deprecated_operation);} |
968 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ADD' operator."); |
931 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) {return print_binary_operator_errors("DIV", symbol, symbol->deprecated_operation);} |
969 if (symbol->deprecated_operation) |
932 void *print_datatypes_error_c::visit(MOD_operator_c *symbol) {return print_binary_operator_errors("MOD", symbol);} |
970 STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'ADD' operator."); |
|
971 return NULL; |
|
972 } |
|
973 |
|
974 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) { |
|
975 if ((symbol->candidate_datatypes.size() == 0) && |
|
976 (il_operand->candidate_datatypes.size() > 0)) |
|
977 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'SUB' operator."); |
|
978 if (symbol->deprecated_operation) |
|
979 STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'SUB' operator."); |
|
980 return NULL; |
|
981 } |
|
982 |
|
983 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) { |
|
984 if ((symbol->candidate_datatypes.size() == 0) && |
|
985 (il_operand->candidate_datatypes.size() > 0)) |
|
986 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MUL' operator."); |
|
987 if (symbol->deprecated_operation) |
|
988 STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'MUL' operator."); |
|
989 return NULL; |
|
990 } |
|
991 |
|
992 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) { |
|
993 if ((symbol->candidate_datatypes.size() == 0) && |
|
994 (il_operand->candidate_datatypes.size() > 0)) |
|
995 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'DIV' operator."); |
|
996 if (symbol->deprecated_operation) |
|
997 STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'DIV' operator."); |
|
998 return NULL; |
|
999 } |
|
1000 |
|
1001 void *print_datatypes_error_c::visit(MOD_operator_c *symbol) { |
|
1002 if ((symbol->candidate_datatypes.size() == 0) && |
|
1003 (il_operand->candidate_datatypes.size() > 0)) |
|
1004 STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MOD' operator."); |
|
1005 return NULL; |
|
1006 } |
|
1007 |
933 |
1008 void *print_datatypes_error_c::visit(GT_operator_c *symbol) { |
934 void *print_datatypes_error_c::visit(GT_operator_c *symbol) { |
1009 return NULL; |
935 return NULL; |
1010 } |
936 } |
1011 |
937 |