252 return; |
252 return; |
253 } |
253 } |
254 |
254 |
255 |
255 |
256 |
256 |
|
257 |
|
258 /* narrow implicit FB call in IL. |
|
259 * e.g. CLK ton_var |
|
260 * CU counter_var |
|
261 * |
|
262 * The algorithm will be to build a fake il_fb_call_c equivalent to the implicit IL FB call, and let |
|
263 * the visit(il_fb_call_c *) method handle it! |
|
264 */ |
|
265 void narrow_candidate_datatypes_c::narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) { |
|
266 if (NULL == called_fb_declaration) |
|
267 /* The fill_candidate_datatypes_c was not able to determine which FB is being called! |
|
268 * This may be because the il_operand is not the name of a FB instance, or no operand was given. |
|
269 * In that case, we just give up! |
|
270 */ |
|
271 return; |
|
272 if (NULL == prev_il_instruction) { |
|
273 /* This IL implicit FB call (e.g. CLK ton_var) is not preceded by another IL instruction |
|
274 * (or list of instructions) that will set the IL current/default value. |
|
275 * We cannot proceed verifying type compatibility of something that does not ecist. |
|
276 */ |
|
277 return; |
|
278 } |
|
279 |
|
280 identifier_c variable_name(param_name); |
|
281 // SYM_REF1(il_assign_operator_c, variable_name) |
|
282 il_assign_operator_c il_assign_operator(&variable_name); |
|
283 // SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list) |
|
284 il_param_assignment_c il_param_assignment(&il_assign_operator, prev_il_instruction/*il_operand*/, NULL); |
|
285 il_param_list_c il_param_list; |
|
286 il_param_list.add_element(&il_param_assignment); |
|
287 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration) |
|
288 il_fb_call_c il_fb_call(NULL, il_operand, NULL, &il_param_list); |
|
289 |
|
290 /* A FB call does not return any datatype, but the IL instructions that come after this |
|
291 * FB call may require a specific datatype in the il current/default variable, |
|
292 * so we must pass this information up to the IL instruction before the FB call, since it will |
|
293 * be that IL instruction that will be required to produce the desired dtataype. |
|
294 * |
|
295 * The above will be done by the visit(il_fb_call_c *) method, so we must make sure to |
|
296 * correctly set up the il_fb_call.datatype variable! |
|
297 */ |
|
298 copy_candidate_datatype_list(il_instruction/*from*/, &il_fb_call/*to*/); |
|
299 il_fb_call.datatype = il_instruction->datatype; |
|
300 il_fb_call.accept(*this); |
|
301 il_instruction->datatype = il_fb_call.datatype; |
|
302 } |
|
303 |
|
304 |
257 /* a helper function... */ |
305 /* a helper function... */ |
258 symbol_c *narrow_candidate_datatypes_c::base_type(symbol_c *symbol) { |
306 symbol_c *narrow_candidate_datatypes_c::base_type(symbol_c *symbol) { |
259 /* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used |
307 /* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used |
260 * in the code. |
308 * in the code. |
261 */ |
309 */ |
402 |
450 |
403 /* | label ':' [il_incomplete_instruction] eol_list */ |
451 /* | label ':' [il_incomplete_instruction] eol_list */ |
404 // SYM_REF2(il_instruction_c, label, il_instruction) |
452 // SYM_REF2(il_instruction_c, label, il_instruction) |
405 // void *visit(instruction_list_c *symbol); |
453 // void *visit(instruction_list_c *symbol); |
406 void *narrow_candidate_datatypes_c::visit(il_instruction_c *symbol) { |
454 void *narrow_candidate_datatypes_c::visit(il_instruction_c *symbol) { |
407 if (NULL == symbol->il_instruction) |
455 if (NULL == symbol->il_instruction) { |
408 return NULL; |
456 /* this empty/null il_instruction cannot generate the desired datatype. We pass on the request to the previous il instruction. */ |
409 |
457 if (NULL != symbol->prev_il_instruction) |
410 prev_il_instruction = symbol->prev_il_instruction; |
458 symbol->prev_il_instruction->datatype = symbol->datatype; |
411 /* Tell the il_instruction the datatype that it must generate - this was chosen by the next il_instruction (we iterate backwards!) */ |
459 } else { |
412 symbol->il_instruction->datatype = symbol->datatype; |
460 prev_il_instruction = symbol->prev_il_instruction; |
413 symbol->il_instruction->accept(*this); |
461 /* Tell the il_instruction the datatype that it must generate - this was chosen by the next il_instruction (remember: we are iterating backwards!) */ |
|
462 symbol->il_instruction->datatype = symbol->datatype; |
|
463 symbol->il_instruction->accept(*this); |
|
464 } |
414 return NULL; |
465 return NULL; |
415 } |
466 } |
416 |
467 |
417 |
468 |
418 |
469 |
503 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
554 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
504 */ |
555 */ |
505 /* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */ |
556 /* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */ |
506 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration) |
557 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration) |
507 void *narrow_candidate_datatypes_c::visit(il_fb_call_c *symbol) { |
558 void *narrow_candidate_datatypes_c::visit(il_fb_call_c *symbol) { |
|
559 /* set the desired datatype of the previous il instruction */ |
|
560 /* NOTE 1: |
|
561 * A FB call does not return any datatype, but the IL instructions that come after this |
|
562 * FB call may require a specific datatype in the il current/default variable, |
|
563 * so we must pass this information up to the IL instruction before the FB call, since it will |
|
564 * be that IL instruction that will be required to produce the desired dtataype. |
|
565 * NOTE 2: |
|
566 * Copying the required datatype must be done before calling narrow_[non]formal_call(). |
|
567 * Note that this visit(il_fb_call_c *) method will be called from narrow_implicit_il_fb_call(). |
|
568 * This means that we must also be able to handle implicit IL FB calls (e.g. CU counter_var) |
|
569 * correctly in this visitor class. |
|
570 * When handling these implicit IL calls, the parameter_value being passed to the FB parameter |
|
571 * (in the previous example, the 'CU' parameter) is actually the prev_il_instruction. |
|
572 * In this case, the prev_il_instruction->datatype will be set by the arrow_[non]formal_call(), |
|
573 * using the prama_value pointer to this same object. |
|
574 * If we were to have the following line of code after calling arrow_[non]formal_call(), |
|
575 * we would then be overwriting the datatype with the wrong value! |
|
576 */ |
|
577 prev_il_instruction->datatype = symbol->datatype; |
|
578 |
508 /* Note: We do not use the symbol->called_fb_declaration value (set in fill_candidate_datatypes_c) |
579 /* Note: We do not use the symbol->called_fb_declaration value (set in fill_candidate_datatypes_c) |
509 * because we try to identify any other datatype errors in the expressions used in the |
580 * because we try to identify any other datatype errors in the expressions used in the |
510 * parameters to the FB call. e.g. |
581 * parameters to the FB call. e.g. |
511 * fb_var( |
582 * fb_var( |
512 * in1 := var1, |
583 * in1 := var1, |
625 void *narrow_candidate_datatypes_c::visit(NOT_operator_c *symbol) { |
696 void *narrow_candidate_datatypes_c::visit(NOT_operator_c *symbol) { |
626 prev_il_instruction = symbol; |
697 prev_il_instruction = symbol; |
627 return NULL; |
698 return NULL; |
628 } |
699 } |
629 |
700 |
630 void *narrow_candidate_datatypes_c::visit(S_operator_c *symbol) {return handle_il_instruction(symbol);} |
701 void *narrow_candidate_datatypes_c::visit(S_operator_c *symbol) { |
631 void *narrow_candidate_datatypes_c::visit(R_operator_c *symbol) {return handle_il_instruction(symbol);} |
702 /* TODO: what if this is a FB call? */ |
632 void *narrow_candidate_datatypes_c::visit(S1_operator_c *symbol) {return handle_il_instruction(symbol);} |
703 return handle_il_instruction(symbol); |
633 void *narrow_candidate_datatypes_c::visit(R1_operator_c *symbol) {return handle_il_instruction(symbol);} |
704 } |
|
705 void *narrow_candidate_datatypes_c::visit(R_operator_c *symbol) { |
|
706 /* TODO: what if this is a FB call? */ |
|
707 return handle_il_instruction(symbol); |
|
708 } |
|
709 |
|
710 |
|
711 void *narrow_candidate_datatypes_c::visit(S1_operator_c *symbol) { |
|
712 narrow_implicit_il_fb_call(symbol, "S1", symbol->called_fb_declaration); |
|
713 return NULL; |
|
714 } |
|
715 |
|
716 void *narrow_candidate_datatypes_c::visit(R1_operator_c *symbol) { |
|
717 narrow_implicit_il_fb_call(symbol, "R1", symbol->called_fb_declaration); |
|
718 return NULL; |
|
719 } |
634 |
720 |
635 void *narrow_candidate_datatypes_c::visit(CLK_operator_c *symbol) { |
721 void *narrow_candidate_datatypes_c::visit(CLK_operator_c *symbol) { |
|
722 narrow_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration); |
636 return NULL; |
723 return NULL; |
637 } |
724 } |
638 |
725 |
639 void *narrow_candidate_datatypes_c::visit(CU_operator_c *symbol) { |
726 void *narrow_candidate_datatypes_c::visit(CU_operator_c *symbol) { |
|
727 narrow_implicit_il_fb_call(symbol, "CU", symbol->called_fb_declaration); |
640 return NULL; |
728 return NULL; |
641 } |
729 } |
642 |
730 |
643 void *narrow_candidate_datatypes_c::visit(CD_operator_c *symbol) { |
731 void *narrow_candidate_datatypes_c::visit(CD_operator_c *symbol) { |
|
732 narrow_implicit_il_fb_call(symbol, "CD", symbol->called_fb_declaration); |
644 return NULL; |
733 return NULL; |
645 } |
734 } |
646 |
735 |
647 void *narrow_candidate_datatypes_c::visit(PV_operator_c *symbol) { |
736 void *narrow_candidate_datatypes_c::visit(PV_operator_c *symbol) { |
|
737 narrow_implicit_il_fb_call(symbol, "PV", symbol->called_fb_declaration); |
648 return NULL; |
738 return NULL; |
649 } |
739 } |
650 |
740 |
651 void *narrow_candidate_datatypes_c::visit(IN_operator_c *symbol) { |
741 void *narrow_candidate_datatypes_c::visit(IN_operator_c *symbol) { |
|
742 narrow_implicit_il_fb_call(symbol, "IN", symbol->called_fb_declaration); |
652 return NULL; |
743 return NULL; |
653 } |
744 } |
654 |
745 |
655 void *narrow_candidate_datatypes_c::visit(PT_operator_c *symbol) { |
746 void *narrow_candidate_datatypes_c::visit(PT_operator_c *symbol) { |
656 return NULL; |
747 narrow_implicit_il_fb_call(symbol, "PT", symbol->called_fb_declaration); |
657 } |
748 return NULL; |
658 |
749 } |
659 void *narrow_candidate_datatypes_c::visit(AND_operator_c *symbol) {return handle_il_instruction(symbol);} |
750 |
660 void *narrow_candidate_datatypes_c::visit(OR_operator_c *symbol) {return handle_il_instruction(symbol);} |
751 |
661 void *narrow_candidate_datatypes_c::visit(XOR_operator_c *symbol) {return handle_il_instruction(symbol);} |
752 |
|
753 void *narrow_candidate_datatypes_c::visit(AND_operator_c *symbol) {return handle_il_instruction(symbol);} |
|
754 void *narrow_candidate_datatypes_c::visit(OR_operator_c *symbol) {return handle_il_instruction(symbol);} |
|
755 void *narrow_candidate_datatypes_c::visit(XOR_operator_c *symbol) {return handle_il_instruction(symbol);} |
662 void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {return handle_il_instruction(symbol);} |
756 void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {return handle_il_instruction(symbol);} |
663 void *narrow_candidate_datatypes_c::visit(ORN_operator_c *symbol) {return handle_il_instruction(symbol);} |
757 void *narrow_candidate_datatypes_c::visit(ORN_operator_c *symbol) {return handle_il_instruction(symbol);} |
664 void *narrow_candidate_datatypes_c::visit(XORN_operator_c *symbol) {return handle_il_instruction(symbol);} |
758 void *narrow_candidate_datatypes_c::visit(XORN_operator_c *symbol) {return handle_il_instruction(symbol);} |
665 void *narrow_candidate_datatypes_c::visit(ADD_operator_c *symbol) {return handle_il_instruction(symbol);} |
759 void *narrow_candidate_datatypes_c::visit(ADD_operator_c *symbol) {return handle_il_instruction(symbol);} |
666 void *narrow_candidate_datatypes_c::visit(SUB_operator_c *symbol) {return handle_il_instruction(symbol);} |
760 void *narrow_candidate_datatypes_c::visit(SUB_operator_c *symbol) {return handle_il_instruction(symbol);} |
667 void *narrow_candidate_datatypes_c::visit(MUL_operator_c *symbol) {return handle_il_instruction(symbol);} |
761 void *narrow_candidate_datatypes_c::visit(MUL_operator_c *symbol) {return handle_il_instruction(symbol);} |
668 void *narrow_candidate_datatypes_c::visit(DIV_operator_c *symbol) {return handle_il_instruction(symbol);} |
762 void *narrow_candidate_datatypes_c::visit(DIV_operator_c *symbol) {return handle_il_instruction(symbol);} |
669 void *narrow_candidate_datatypes_c::visit(MOD_operator_c *symbol) {return handle_il_instruction(symbol);} |
763 void *narrow_candidate_datatypes_c::visit(MOD_operator_c *symbol) {return handle_il_instruction(symbol);} |
670 void *narrow_candidate_datatypes_c::visit(GT_operator_c *symbol) {return handle_il_instruction(symbol);} |
764 void *narrow_candidate_datatypes_c::visit(GT_operator_c *symbol) {return handle_il_instruction(symbol);} |
671 void *narrow_candidate_datatypes_c::visit(GE_operator_c *symbol) {return handle_il_instruction(symbol);} |
765 void *narrow_candidate_datatypes_c::visit(GE_operator_c *symbol) {return handle_il_instruction(symbol);} |
672 void *narrow_candidate_datatypes_c::visit(EQ_operator_c *symbol) {return handle_il_instruction(symbol);} |
766 void *narrow_candidate_datatypes_c::visit(EQ_operator_c *symbol) {return handle_il_instruction(symbol);} |
673 void *narrow_candidate_datatypes_c::visit(LT_operator_c *symbol) {return handle_il_instruction(symbol);} |
767 void *narrow_candidate_datatypes_c::visit(LT_operator_c *symbol) {return handle_il_instruction(symbol);} |
674 void *narrow_candidate_datatypes_c::visit(LE_operator_c *symbol) {return handle_il_instruction(symbol);} |
768 void *narrow_candidate_datatypes_c::visit(LE_operator_c *symbol) {return handle_il_instruction(symbol);} |
675 void *narrow_candidate_datatypes_c::visit(NE_operator_c *symbol) {return handle_il_instruction(symbol);} |
769 void *narrow_candidate_datatypes_c::visit(NE_operator_c *symbol) {return handle_il_instruction(symbol);} |
|
770 |
676 |
771 |
677 void *narrow_candidate_datatypes_c::visit(CAL_operator_c *symbol) { |
772 void *narrow_candidate_datatypes_c::visit(CAL_operator_c *symbol) { |
678 return NULL; |
773 return NULL; |
679 } |
774 } |
680 |
775 |