66 */ |
66 */ |
67 search_expression_type_c *search_expression_type; |
67 search_expression_type_c *search_expression_type; |
68 |
68 |
69 search_varfb_instance_type_c *search_varfb_instance_type; |
69 search_varfb_instance_type_c *search_varfb_instance_type; |
70 |
70 |
|
71 search_base_type_c search_base_type; |
|
72 |
|
73 symbol_c* current_array_type; |
|
74 |
71 public: |
75 public: |
72 generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
76 generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
73 : generate_c_typedecl_c(s4o_ptr) { |
77 : generate_c_typedecl_c(s4o_ptr) { |
74 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
78 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
75 search_expression_type = new search_expression_type_c(scope); |
79 search_expression_type = new search_expression_type_c(scope); |
76 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
80 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
77 this->set_variable_prefix(variable_prefix); |
81 this->set_variable_prefix(variable_prefix); |
|
82 current_array_type = NULL; |
78 } |
83 } |
79 |
84 |
80 virtual ~generate_c_st_c(void) { |
85 virtual ~generate_c_st_c(void) { |
81 delete search_fb_instance_decl; |
86 delete search_fb_instance_decl; |
82 delete search_expression_type; |
87 delete search_expression_type; |
154 this->print_variable_prefix(); |
159 this->print_variable_prefix(); |
155 s4o.printlocation(symbol->value + 1); |
160 s4o.printlocation(symbol->value + 1); |
156 s4o.print(")"); |
161 s4o.print(")"); |
157 return NULL; |
162 return NULL; |
158 } |
163 } |
|
164 |
|
165 /*************************************/ |
|
166 /* B.1.4.2 Multi-element Variables */ |
|
167 /*************************************/ |
|
168 |
|
169 /* subscripted_variable '[' subscript_list ']' */ |
|
170 //SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
171 void *visit(array_variable_c *symbol) { |
|
172 current_array_type = search_varfb_instance_type->get_type(symbol->subscripted_variable, false); |
|
173 symbol->subscripted_variable->accept(*this); |
|
174 if (current_array_type != NULL) { |
|
175 symbol->subscript_list->accept(*this); |
|
176 current_array_type = NULL; |
|
177 } |
|
178 return NULL; |
|
179 } |
|
180 |
|
181 /* subscript_list ',' subscript */ |
|
182 void *visit(subscript_list_c *symbol) { |
|
183 for (int i = 0; i < symbol->n; i++) { |
|
184 s4o.print("[__"); |
|
185 current_array_type->accept(*this); |
|
186 s4o.print("_TRANSIDX"); |
|
187 print_integer(i); |
|
188 s4o.print("("); |
|
189 symbol->elements[i]->accept(*this); |
|
190 s4o.print(")]"); |
|
191 } |
|
192 return NULL; |
|
193 } |
|
194 |
159 |
195 |
160 /***************************************/ |
196 /***************************************/ |
161 /* B.3 - Language ST (Structured Text) */ |
197 /* B.3 - Language ST (Structured Text) */ |
162 /***************************************/ |
198 /***************************************/ |
163 /***********************/ |
199 /***********************/ |
508 param_value = function_call_param_iterator.next(); |
544 param_value = function_call_param_iterator.next(); |
509 |
545 |
510 symbol_c *param_type = fp_iterator.param_type(); |
546 symbol_c *param_type = fp_iterator.param_type(); |
511 if (param_type == NULL) ERROR; |
547 if (param_type == NULL) ERROR; |
512 |
548 |
|
549 search_base_type.explore_type(param_type); |
|
550 |
513 switch (param_direction) { |
551 switch (param_direction) { |
514 case function_param_iterator_c::direction_in: |
552 case function_param_iterator_c::direction_in: |
515 if (param_value == NULL) { |
553 if (param_value == NULL) { |
516 /* No value given for parameter, so we must use the default... */ |
554 /* No value given for parameter, so we must use the default... */ |
517 /* First check whether default value specified in function declaration...*/ |
555 /* First check whether default value specified in function declaration...*/ |
520 if (param_value == NULL) { |
558 if (param_value == NULL) { |
521 /* If not, get the default value of this variable's type */ |
559 /* If not, get the default value of this variable's type */ |
522 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
560 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
523 } |
561 } |
524 if (param_value == NULL) ERROR; |
562 if (param_value == NULL) ERROR; |
|
563 if (search_base_type.base_is_subrange()) { |
|
564 s4o.print("__CHECK_"); |
|
565 param_type->accept(*this); |
|
566 s4o.print("("); |
|
567 } |
525 param_value->accept(*this); |
568 param_value->accept(*this); |
|
569 if (search_base_type.base_is_subrange()) |
|
570 s4o.print(")"); |
526 break; |
571 break; |
527 case function_param_iterator_c::direction_out: |
572 case function_param_iterator_c::direction_out: |
528 case function_param_iterator_c::direction_inout: |
573 case function_param_iterator_c::direction_inout: |
529 if (param_value == NULL) { |
574 if (param_value == NULL) { |
530 /* no parameter value given, so we pass a previously declared temporary variable. */ |
575 /* no parameter value given, so we pass a previously declared temporary variable. */ |
558 |
603 |
559 /*********************************/ |
604 /*********************************/ |
560 /* B 3.2.1 Assignment Statements */ |
605 /* B 3.2.1 Assignment Statements */ |
561 /*********************************/ |
606 /*********************************/ |
562 void *visit(assignment_statement_c *symbol) { |
607 void *visit(assignment_statement_c *symbol) { |
|
608 symbol_c *left_type = search_varfb_instance_type->get_type(symbol->l_exp, false); |
|
609 symbol_c *base_type = (symbol_c *)search_base_type.explore_type(left_type); |
|
610 |
563 symbol->l_exp->accept(*this); |
611 symbol->l_exp->accept(*this); |
564 s4o.print(" = "); |
612 s4o.print(" = "); |
|
613 if (search_base_type.base_is_subrange()) { |
|
614 s4o.print("__CHECK_"); |
|
615 left_type->accept(*this); |
|
616 s4o.print("("); |
|
617 } |
565 symbol->r_exp->accept(*this); |
618 symbol->r_exp->accept(*this); |
|
619 if (search_base_type.base_is_subrange()) |
|
620 s4o.print(")"); |
|
621 s4o.print("; // "); |
|
622 left_type->accept(*this); |
|
623 s4o.print(" "); |
|
624 base_type->accept(*this); |
566 return NULL; |
625 return NULL; |
567 } |
626 } |
568 |
627 |
569 /*****************************************/ |
628 /*****************************************/ |
570 /* B 3.2.2 Subprogram Control Statements */ |
629 /* B 3.2.2 Subprogram Control Statements */ |
599 |
658 |
600 /* Get the value from a foo(<param_value>) style call */ |
659 /* Get the value from a foo(<param_value>) style call */ |
601 if (param_value == NULL) |
660 if (param_value == NULL) |
602 param_value = function_call_param_iterator.next(); |
661 param_value = function_call_param_iterator.next(); |
603 |
662 |
|
663 symbol_c *param_type = fp_iterator.param_type(); |
|
664 if (param_type == NULL) ERROR; |
|
665 |
|
666 search_base_type.explore_type(param_type); |
|
667 |
604 /* now output the value assignment */ |
668 /* now output the value assignment */ |
605 if (param_value != NULL) |
669 if (param_value != NULL) |
606 if ((param_direction == function_param_iterator_c::direction_in) || |
670 if ((param_direction == function_param_iterator_c::direction_in) || |
607 (param_direction == function_param_iterator_c::direction_inout)) { |
671 (param_direction == function_param_iterator_c::direction_inout)) { |
608 print_variable_prefix(); |
672 print_variable_prefix(); |
609 symbol->fb_name->accept(*this); |
673 symbol->fb_name->accept(*this); |
610 s4o.print("."); |
674 s4o.print("."); |
611 param_name->accept(*this); |
675 param_name->accept(*this); |
612 s4o.print(" = "); |
676 s4o.print(" = "); |
|
677 if (search_base_type.base_is_subrange()) { |
|
678 s4o.print("__CHECK_"); |
|
679 param_type->accept(*this); |
|
680 s4o.print("("); |
|
681 } |
613 param_value->accept(*this); |
682 param_value->accept(*this); |
|
683 if (search_base_type.base_is_subrange()) |
|
684 s4o.print(")"); |
614 s4o.print(";\n" + s4o.indent_spaces); |
685 s4o.print(";\n" + s4o.indent_spaces); |
615 } |
686 } |
616 } /* for(...) */ |
687 } /* for(...) */ |
617 |
688 |
618 /* now call the function... */ |
689 /* now call the function... */ |
640 |
711 |
641 /* now output the value assignment */ |
712 /* now output the value assignment */ |
642 if (param_value != NULL) |
713 if (param_value != NULL) |
643 if ((param_direction == function_param_iterator_c::direction_out) || |
714 if ((param_direction == function_param_iterator_c::direction_out) || |
644 (param_direction == function_param_iterator_c::direction_inout)) { |
715 (param_direction == function_param_iterator_c::direction_inout)) { |
|
716 symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false); |
|
717 search_base_type.explore_type(param_type); |
|
718 |
645 s4o.print(";\n"+ s4o.indent_spaces); |
719 s4o.print(";\n"+ s4o.indent_spaces); |
646 param_value->accept(*this); |
720 param_value->accept(*this); |
647 s4o.print(" = "); |
721 s4o.print(" = "); |
|
722 if (search_base_type.base_is_subrange()) { |
|
723 s4o.print("__CHECK_"); |
|
724 param_type->accept(*this); |
|
725 s4o.print("("); |
|
726 } |
648 print_variable_prefix(); |
727 print_variable_prefix(); |
649 symbol->fb_name->accept(*this); |
728 symbol->fb_name->accept(*this); |
650 s4o.print("."); |
729 s4o.print("."); |
651 param_name->accept(*this); |
730 param_name->accept(*this); |
|
731 if (search_base_type.base_is_subrange()) |
|
732 s4o.print(")"); |
652 } |
733 } |
653 } /* for(...) */ |
734 } /* for(...) */ |
654 |
735 |
655 return NULL; |
736 return NULL; |
656 } |
737 } |