232 |
244 |
233 search_varfb_instance_type_c *search_varfb_instance_type; |
245 search_varfb_instance_type_c *search_varfb_instance_type; |
234 |
246 |
235 search_base_type_c search_base_type; |
247 search_base_type_c search_base_type; |
236 |
248 |
237 bool current_param_is_pointer; |
249 symbol_c* current_array_type; |
|
250 symbol_c* current_param_type; |
|
251 |
|
252 int fcall_number; |
|
253 symbol_c *fbname; |
|
254 |
|
255 variablegeneration_t wanted_variablegeneration; |
238 |
256 |
239 public: |
257 public: |
240 generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL) |
258 generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
241 : generate_c_typedecl_c(s4o_ptr), |
259 : generate_c_typedecl_c(s4o_ptr), |
242 default_variable_name(IL_DEFVAR, NULL), |
260 default_variable_name(IL_DEFVAR, NULL), |
243 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
261 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
244 { |
262 { |
245 search_expression_type = new search_expression_type_c(scope); |
263 search_expression_type = new search_expression_type_c(scope); |
246 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
264 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
247 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
265 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
248 current_operand = NULL; |
266 current_operand = NULL; |
249 current_operand_type = NULL; |
267 current_operand_type = NULL; |
250 il_default_variable_init_value = NULL; |
268 il_default_variable_init_value = NULL; |
251 current_param_is_pointer = false; |
269 current_array_type = NULL; |
|
270 current_param_type = NULL; |
|
271 fcall_number = 0; |
|
272 fbname = name; |
|
273 wanted_variablegeneration = expression_vg; |
252 this->set_variable_prefix(variable_prefix); |
274 this->set_variable_prefix(variable_prefix); |
253 } |
275 } |
254 |
276 |
255 virtual ~generate_c_il_c(void) { |
277 virtual ~generate_c_il_c(void) { |
256 delete search_fb_instance_decl; |
278 delete search_fb_instance_decl; |
379 s4o.print(") "); |
401 s4o.print(") "); |
380 } |
402 } |
381 else {ERROR;} |
403 else {ERROR;} |
382 } |
404 } |
383 |
405 |
|
406 void BYTE_operator_result_type(void) { |
|
407 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
|
408 if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
|
409 this->default_variable_name.current_type = &(this->lword_type); |
|
410 else |
|
411 this->default_variable_name.current_type = this->current_operand_type; |
|
412 } |
|
413 else if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
|
414 this->current_operand_type = this->default_variable_name.current_type; |
|
415 } |
|
416 |
|
417 void NUM_operator_result_type(void) { |
|
418 if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) { |
|
419 if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
|
420 search_expression_type->is_literal_real_type(this->current_operand_type)) |
|
421 this->default_variable_name.current_type = &(this->lreal_type); |
|
422 else |
|
423 this->default_variable_name.current_type = this->current_operand_type; |
|
424 } |
|
425 else if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
|
426 if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
|
427 this->default_variable_name.current_type = &(this->lint_type); |
|
428 else if (search_expression_type->is_literal_real_type(this->current_operand_type)) |
|
429 this->default_variable_name.current_type = &(this->lreal_type); |
|
430 else |
|
431 this->default_variable_name.current_type = this->current_operand_type; |
|
432 } |
|
433 else if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
|
434 search_expression_type->is_literal_real_type(this->current_operand_type)) |
|
435 this->current_operand_type = this->default_variable_name.current_type; |
|
436 } |
|
437 |
|
438 void *print_getter(symbol_c *symbol) { |
|
439 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
|
440 if (wanted_variablegeneration == fparam_output_vg) { |
|
441 if (vartype == search_var_instance_decl_c::external_vt) |
|
442 s4o.print(GET_EXTERNAL_BY_REF); |
|
443 else if (vartype == search_var_instance_decl_c::located_vt) |
|
444 s4o.print(GET_LOCATED_BY_REF); |
|
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 } |
|
456 s4o.print("("); |
|
457 |
|
458 variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; |
|
459 wanted_variablegeneration = complextype_base_vg; |
|
460 symbol->accept(*this); |
|
461 if (search_varfb_instance_type->type_is_complex()) |
|
462 s4o.print(","); |
|
463 wanted_variablegeneration = complextype_suffix_vg; |
|
464 symbol->accept(*this); |
|
465 s4o.print(")"); |
|
466 wanted_variablegeneration = old_wanted_variablegeneration; |
|
467 return NULL; |
|
468 } |
|
469 |
|
470 void *print_setter(symbol_c* symbol, |
|
471 symbol_c* type, |
|
472 symbol_c* value, |
|
473 symbol_c* fb_symbol = NULL, |
|
474 symbol_c* fb_value = NULL, |
|
475 bool negative = false) { |
|
476 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
|
477 if (vartype == search_var_instance_decl_c::external_vt) { |
|
478 symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol); |
|
479 /* TODO Find a solution for forcing global complex variables */ |
|
480 if (variable != NULL) { |
|
481 s4o.print(SET_EXTERNAL); |
|
482 s4o.print("("); |
|
483 variable->var_name->accept(*this); |
|
484 s4o.print(","); |
|
485 } |
|
486 else { |
|
487 s4o.print(SET_COMPLEX_EXTERNAL); |
|
488 s4o.print("("); |
|
489 } |
|
490 } |
|
491 else { |
|
492 if (vartype == search_var_instance_decl_c::located_vt) |
|
493 s4o.print(SET_LOCATED); |
|
494 else |
|
495 s4o.print(SET_VAR); |
|
496 s4o.print("("); |
|
497 } |
|
498 |
|
499 if (fb_symbol != NULL) { |
|
500 print_variable_prefix(); |
|
501 fb_symbol->accept(*this); |
|
502 s4o.print("."); |
|
503 } |
|
504 else |
|
505 wanted_variablegeneration = complextype_base_vg; |
|
506 symbol->accept(*this); |
|
507 s4o.print(","); |
|
508 if (negative) { |
|
509 if (search_expression_type->is_bool_type(this->current_operand_type)) |
|
510 s4o.print("!"); |
|
511 else |
|
512 s4o.print("~"); |
|
513 } |
|
514 wanted_variablegeneration = expression_vg; |
|
515 print_check_function(type, value, fb_value); |
|
516 if (search_varfb_instance_type->type_is_complex()) { |
|
517 s4o.print(","); |
|
518 wanted_variablegeneration = complextype_suffix_vg; |
|
519 symbol->accept(*this); |
|
520 } |
|
521 s4o.print(")"); |
|
522 wanted_variablegeneration = expression_vg; |
|
523 return NULL; |
|
524 } |
384 |
525 |
385 public: |
526 public: |
386 void *visit(il_default_variable_c *symbol) { |
527 void *visit(il_default_variable_c *symbol) { |
387 //s4o.print("il_default_variable_c VISITOR!!\n"); |
528 //s4o.print("il_default_variable_c VISITOR!!\n"); |
388 symbol->var_name->accept(*this); |
529 symbol->var_name->accept(*this); |
389 if (NULL != symbol->current_type) { |
530 if (NULL != symbol->current_type) { |
390 s4o.print("."); |
531 s4o.print("."); |
391 symbol->current_type->accept(*this); |
532 if (search_expression_type->is_literal_integer_type(symbol->current_type)) |
|
533 this->lint_type.accept(*this); |
|
534 else if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) |
|
535 this->lreal_type.accept(*this); |
|
536 else |
|
537 symbol->current_type->accept(*this); |
392 s4o.print("var"); |
538 s4o.print("var"); |
393 } |
539 } |
394 return NULL; |
540 return NULL; |
395 } |
541 } |
396 |
542 |
415 |
561 |
416 |
562 |
417 /*********************/ |
563 /*********************/ |
418 /* B 1.4 - Variables */ |
564 /* B 1.4 - Variables */ |
419 /*********************/ |
565 /*********************/ |
|
566 |
420 void *visit(symbolic_variable_c *symbol) { |
567 void *visit(symbolic_variable_c *symbol) { |
421 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
568 unsigned int vartype; |
422 if (!current_param_is_pointer && (vartype == search_var_instance_decl_c::external_vt || vartype == search_var_instance_decl_c::located_vt)) { |
569 if (wanted_variablegeneration == complextype_base_vg) |
423 s4o.print("*("); |
570 generate_c_base_c::visit(symbol); |
424 generate_c_base_c::visit(symbol); |
571 else if (wanted_variablegeneration == complextype_suffix_vg) |
425 s4o.print(")"); |
572 return NULL; |
426 } |
573 else if (this->is_variable_prefix_null()) { |
427 else if (current_param_is_pointer && vartype != search_var_instance_decl_c::external_vt && vartype != search_var_instance_decl_c::located_vt) { |
574 vartype = search_varfb_instance_type->get_vartype(symbol); |
428 s4o.print("&("); |
575 if (wanted_variablegeneration == fparam_output_vg) { |
429 generate_c_base_c::visit(symbol); |
576 s4o.print("&("); |
430 s4o.print(")"); |
577 generate_c_base_c::visit(symbol); |
431 } |
578 s4o.print(")"); |
432 else { |
579 } |
433 generate_c_base_c::visit(symbol); |
580 else { |
434 } |
581 generate_c_base_c::visit(symbol); |
|
582 } |
|
583 } |
|
584 else |
|
585 print_getter(symbol); |
435 return NULL; |
586 return NULL; |
436 } |
587 } |
437 |
588 |
438 /********************************************/ |
589 /********************************************/ |
439 /* B.1.4.1 Directly Represented Variables */ |
590 /* B.1.4.1 Directly Represented Variables */ |
441 // direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
592 // direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; |
442 void *visit(direct_variable_c *symbol) { |
593 void *visit(direct_variable_c *symbol) { |
443 TRACE("direct_variable_c"); |
594 TRACE("direct_variable_c"); |
444 /* Do not use print_token() as it will change everything into uppercase */ |
595 /* Do not use print_token() as it will change everything into uppercase */ |
445 if (strlen(symbol->value) == 0) ERROR; |
596 if (strlen(symbol->value) == 0) ERROR; |
446 if (!current_param_is_pointer) { |
597 if (this->is_variable_prefix_null()) { |
447 s4o.print("*("); |
598 if (wanted_variablegeneration != fparam_output_vg) |
|
599 s4o.print("*("); |
|
600 } |
|
601 else { |
|
602 switch (wanted_variablegeneration) { |
|
603 case expression_vg: |
|
604 s4o.print(GET_LOCATED); |
|
605 s4o.print("("); |
|
606 break; |
|
607 case fparam_output_vg: |
|
608 s4o.print(GET_LOCATED_BY_REF); |
|
609 s4o.print("("); |
|
610 break; |
|
611 default: |
|
612 break; |
|
613 } |
448 } |
614 } |
449 this->print_variable_prefix(); |
615 this->print_variable_prefix(); |
450 s4o.printlocation(symbol->value + 1); |
616 s4o.printlocation(symbol->value + 1); |
451 if (!current_param_is_pointer) { |
617 if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) || |
|
618 wanted_variablegeneration != assignment_vg) |
452 s4o.print(")"); |
619 s4o.print(")"); |
453 } |
620 return NULL; |
454 return NULL; |
621 } |
455 } |
622 |
456 |
623 /*************************************/ |
|
624 /* B.1.4.2 Multi-element Variables */ |
|
625 /*************************************/ |
|
626 |
|
627 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
628 void *visit(structured_variable_c *symbol) { |
|
629 TRACE("structured_variable_c"); |
|
630 switch (wanted_variablegeneration) { |
|
631 case complextype_base_vg: |
|
632 symbol->record_variable->accept(*this); |
|
633 break; |
|
634 case complextype_suffix_vg: |
|
635 symbol->record_variable->accept(*this); |
|
636 s4o.print("."); |
|
637 symbol->field_selector->accept(*this); |
|
638 break; |
|
639 default: |
|
640 if (this->is_variable_prefix_null()) { |
|
641 symbol->record_variable->accept(*this); |
|
642 s4o.print("."); |
|
643 symbol->field_selector->accept(*this); |
|
644 } |
|
645 else |
|
646 print_getter(symbol); |
|
647 break; |
|
648 } |
|
649 return NULL; |
|
650 } |
|
651 |
|
652 /* subscripted_variable '[' subscript_list ']' */ |
|
653 //SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
654 void *visit(array_variable_c *symbol) { |
|
655 switch (wanted_variablegeneration) { |
|
656 case complextype_base_vg: |
|
657 symbol->subscripted_variable->accept(*this); |
|
658 break; |
|
659 case complextype_suffix_vg: |
|
660 symbol->subscripted_variable->accept(*this); |
|
661 |
|
662 current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
|
663 if (current_array_type == NULL) ERROR; |
|
664 |
|
665 s4o.print(".table"); |
|
666 symbol->subscript_list->accept(*this); |
|
667 |
|
668 current_array_type = NULL; |
|
669 break; |
|
670 default: |
|
671 if (this->is_variable_prefix_null()) { |
|
672 symbol->subscripted_variable->accept(*this); |
|
673 |
|
674 current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
|
675 if (current_array_type == NULL) ERROR; |
|
676 |
|
677 s4o.print(".table"); |
|
678 symbol->subscript_list->accept(*this); |
|
679 |
|
680 current_array_type = NULL; |
|
681 } |
|
682 else |
|
683 print_getter(symbol); |
|
684 break; |
|
685 } |
|
686 return NULL; |
|
687 } |
|
688 |
|
689 /* subscript_list ',' subscript */ |
|
690 void *visit(subscript_list_c *symbol) { |
|
691 for (int i = 0; i < symbol->n; i++) { |
|
692 s4o.print("[__"); |
|
693 current_array_type->accept(*this); |
|
694 s4o.print("_TRANSIDX"); |
|
695 print_integer(i); |
|
696 s4o.print("("); |
|
697 symbol->elements[i]->accept(*this); |
|
698 s4o.print(")]"); |
|
699 } |
|
700 return NULL; |
|
701 } |
|
702 |
|
703 /******************************************/ |
|
704 /* B 1.4.3 - Declaration & Initialisation */ |
|
705 /******************************************/ |
|
706 |
|
707 /* helper symbol for structure_initialization */ |
|
708 /* structure_element_initialization_list ',' structure_element_initialization */ |
|
709 void *visit(structure_element_initialization_list_c *symbol) { |
|
710 generate_c_structure_initialization_c *structure_initialization = new generate_c_structure_initialization_c(&s4o); |
|
711 structure_initialization->init_structure_default(this->current_param_type); |
|
712 structure_initialization->init_structure_values(symbol); |
|
713 delete structure_initialization; |
|
714 return NULL; |
|
715 } |
|
716 |
|
717 /* helper symbol for array_initialization */ |
|
718 /* array_initial_elements_list ',' array_initial_elements */ |
|
719 void *visit(array_initial_elements_list_c *symbol) { |
|
720 generate_c_array_initialization_c *array_initialization = new generate_c_array_initialization_c(&s4o); |
|
721 array_initialization->init_array_size(this->current_param_type); |
|
722 array_initialization->init_array_values(symbol); |
|
723 delete array_initialization; |
|
724 return NULL; |
|
725 } |
457 /****************************************/ |
726 /****************************************/ |
458 /* B.2 - Language IL (Instruction List) */ |
727 /* B.2 - Language IL (Instruction List) */ |
459 /****************************************/ |
728 /****************************************/ |
460 |
729 |
461 /***********************************/ |
730 /***********************************/ |
476 /* Declare the default variable, that will store the result of the IL operations... */ |
745 /* Declare the default variable, that will store the result of the IL operations... */ |
477 s4o.print(s4o.indent_spaces); |
746 s4o.print(s4o.indent_spaces); |
478 s4o.print(IL_DEFVAR_T); |
747 s4o.print(IL_DEFVAR_T); |
479 s4o.print(" "); |
748 s4o.print(" "); |
480 this->default_variable_name.accept(*this); |
749 this->default_variable_name.accept(*this); |
481 s4o.print(";\n\n"); |
750 s4o.print(";\n"); |
|
751 s4o.print(s4o.indent_spaces); |
|
752 print_backup_variable(); |
|
753 s4o.print(".INTvar = 0;\n\n"); |
482 |
754 |
483 print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
755 print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); |
|
756 |
|
757 /* label not used by at least one goto result in a warning. |
|
758 * To work around this we introduce the useless goto |
|
759 * to humour the compiler... |
|
760 */ |
|
761 s4o.print("\n"); |
|
762 s4o.print(s4o.indent_spaces); |
|
763 s4o.print("/* to humour the compiler, we insert a goto */\n"); |
|
764 s4o.print(s4o.indent_spaces); |
|
765 s4o.print("goto "); |
|
766 s4o.print(END_LABEL); |
|
767 s4o.print(";\n"); |
484 |
768 |
485 /* write the label marking the end of the code block */ |
769 /* write the label marking the end of the code block */ |
486 /* please see the comment before the RET_operator_c visitor for details... */ |
770 /* please see the comment before the RET_operator_c visitor for details... */ |
487 s4o.print("\n"); |
771 s4o.print("\n"); |
488 s4o.print(s4o.indent_spaces); |
772 s4o.print(s4o.indent_spaces); |
540 |
824 |
541 |
825 |
542 /* | function_name [il_operand_list] */ |
826 /* | function_name [il_operand_list] */ |
543 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
827 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
544 void *visit(il_function_call_c *symbol) { |
828 void *visit(il_function_call_c *symbol) { |
545 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
546 |
|
547 symbol_c* function_type_prefix = NULL; |
829 symbol_c* function_type_prefix = NULL; |
548 symbol_c* function_name = NULL; |
830 symbol_c* function_name = NULL; |
549 symbol_c* function_type_suffix = NULL; |
831 symbol_c* function_type_suffix = NULL; |
550 std::list<FUNCTION_PARAM> param_list; |
832 DECLARE_PARAM_LIST() |
551 FUNCTION_PARAM *param; |
|
552 |
833 |
553 symbol_c *param_data_type = default_variable_name.current_type; |
834 symbol_c *param_data_type = default_variable_name.current_type; |
554 symbol_c *return_data_type = NULL; |
835 symbol_c *return_data_type = NULL; |
555 |
836 |
|
837 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
838 |
|
839 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
556 if (f_decl == function_symtable.end_value()) { |
840 if (f_decl == function_symtable.end_value()) { |
557 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
841 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
558 if (current_function_type == function_none) ERROR; |
842 if (current_function_type == function_none) ERROR; |
559 |
843 |
560 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
844 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
561 if (NULL == return_data_type) ERROR; |
845 if (NULL == return_data_type) ERROR; |
562 |
846 |
563 function_call_param_iterator_c function_call_param_iterator(symbol); |
847 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
564 |
|
565 /* Add the value from EN param */ |
848 /* Add the value from EN param */ |
566 ADD_PARAM_LIST((symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
849 ADD_PARAM_LIST(en_param_name, |
|
850 (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())), |
567 (symbol_c*)(new bool_type_name_c()), |
851 (symbol_c*)(new bool_type_name_c()), |
568 function_param_iterator_c::direction_in) |
852 function_param_iterator_c::direction_in) |
569 |
853 |
|
854 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
570 /* Add the value from ENO param */ |
855 /* Add the value from ENO param */ |
571 ADD_PARAM_LIST(NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
856 ADD_PARAM_LIST(eno_param_name, NULL, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
572 |
857 |
573 int nb_param = 1; |
858 int nb_param = 1; |
574 if (symbol->il_operand_list != NULL) |
859 if (symbol->il_operand_list != NULL) |
575 nb_param += ((list_c *)symbol->il_operand_list)->n; |
860 nb_param += ((list_c *)symbol->il_operand_list)->n; |
576 |
861 |
577 #define search(x) search_f(x) |
|
578 #define next() next_nf() |
|
579 // #define search_constant_type_c::constant_int_type_name search_expression_type_c::integer |
|
580 #define constant_int_type_name integer |
|
581 #include "il_code_gen.c" |
862 #include "il_code_gen.c" |
582 #undef constant_int_type_name |
|
583 // #undef search_constant_type_c::constant_int_type_name |
|
584 #undef next |
|
585 #undef search |
|
586 |
863 |
587 } |
864 } |
588 else { |
865 else { |
589 /* determine the base data type returned by the function being called... */ |
866 /* determine the base data type returned by the function being called... */ |
590 search_base_type_c search_base_type; |
867 search_base_type_c search_base_type; |
624 */ |
900 */ |
625 if (param_value == NULL) |
901 if (param_value == NULL) |
626 param_value = function_call_param_iterator.search_f(param_name); |
902 param_value = function_call_param_iterator.search_f(param_name); |
627 |
903 |
628 /* Get the value from a foo(<param_value>) style call */ |
904 /* Get the value from a foo(<param_value>) style call */ |
629 if (param_value == NULL) |
905 if (param_value == NULL) { |
630 param_value = function_call_param_iterator.next_nf(); |
906 param_value = function_call_param_iterator.next_nf(); |
|
907 if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR; |
|
908 } |
631 |
909 |
632 if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
910 if (param_value == NULL && param_direction == function_param_iterator_c::direction_in) { |
633 /* No value given for parameter, so we must use the default... */ |
911 /* No value given for parameter, so we must use the default... */ |
634 /* First check whether default value specified in function declaration...*/ |
912 /* First check whether default value specified in function declaration...*/ |
635 param_value = fp_iterator.default_value(); |
913 param_value = fp_iterator.default_value(); |
636 } |
914 } |
637 |
915 |
638 ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
916 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
639 } /* for(...) */ |
917 } /* for(...) */ |
640 } |
918 } |
641 |
919 |
|
920 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
921 |
|
922 bool has_output_params = false; |
|
923 |
|
924 if (!this->is_variable_prefix_null()) { |
|
925 PARAM_LIST_ITERATOR() { |
|
926 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
927 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
928 PARAM_VALUE != NULL) { |
|
929 if (!has_output_params) { |
|
930 has_output_params = true; |
|
931 } |
|
932 } |
|
933 } |
|
934 } |
|
935 |
642 default_variable_name.current_type = return_data_type; |
936 default_variable_name.current_type = return_data_type; |
643 this->default_variable_name.accept(*this); |
937 this->default_variable_name.accept(*this); |
644 default_variable_name.current_type = param_data_type; |
938 default_variable_name.current_type = param_data_type; |
645 s4o.print(" = "); |
939 s4o.print(" = "); |
646 |
940 |
647 if (function_type_prefix != NULL) { |
941 if (function_type_prefix != NULL) { |
648 s4o.print("("); |
942 s4o.print("("); |
649 function_type_prefix->accept(*this); |
943 function_type_prefix->accept(*this); |
650 s4o.print(")"); |
944 s4o.print(")"); |
651 } |
945 } |
652 if (function_name != NULL) |
946 if (has_output_params) { |
|
947 fcall_number++; |
|
948 s4o.print("__"); |
|
949 fbname->accept(*this); |
|
950 s4o.print("_"); |
653 function_name->accept(*this); |
951 function_name->accept(*this); |
654 if (function_type_suffix != NULL) |
952 s4o.print_integer(fcall_number); |
655 function_type_suffix->accept(*this); |
953 } |
|
954 else { |
|
955 if (function_name != NULL) |
|
956 function_name->accept(*this); |
|
957 if (function_type_suffix != NULL) |
|
958 function_type_suffix->accept(*this); |
|
959 } |
656 s4o.print("("); |
960 s4o.print("("); |
657 s4o.indent_right(); |
961 s4o.indent_right(); |
658 |
962 |
659 std::list<FUNCTION_PARAM>::iterator pt; |
963 int nb_param = 0; |
660 for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
964 PARAM_LIST_ITERATOR() { |
661 if (pt != param_list.begin()) |
965 symbol_c *param_value = PARAM_VALUE; |
662 s4o.print(",\n"+s4o.indent_spaces); |
966 current_param_type = PARAM_TYPE; |
663 symbol_c *param_value = pt->param_value; |
|
664 symbol_c *param_type = pt->param_type; |
|
665 |
967 |
666 switch (pt->param_direction) { |
968 switch (PARAM_DIRECTION) { |
667 case function_param_iterator_c::direction_in: |
969 case function_param_iterator_c::direction_in: |
|
970 if (nb_param > 0) |
|
971 s4o.print(",\n"+s4o.indent_spaces); |
668 if (param_value == NULL) { |
972 if (param_value == NULL) { |
669 /* If not, get the default value of this variable's type */ |
973 /* If not, get the default value of this variable's type */ |
670 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
974 param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
671 } |
975 } |
672 if (param_value == NULL) ERROR; |
976 if (param_value == NULL) ERROR; |
673 if (search_base_type.type_is_subrange(param_type)) { |
977 s4o.print("("); |
674 s4o.print("__CHECK_"); |
978 if (search_expression_type->is_literal_integer_type(current_param_type)) |
675 param_type->accept(*this); |
979 search_expression_type->lint_type_name.accept(*this); |
676 s4o.print("("); |
980 else if (search_expression_type->is_literal_real_type(current_param_type)) |
677 } |
981 search_expression_type->lreal_type_name.accept(*this); |
678 param_value->accept(*this); |
982 else |
679 if (search_base_type.type_is_subrange(param_type)) |
983 current_param_type->accept(*this); |
680 s4o.print(")"); |
984 s4o.print(")"); |
|
985 print_check_function(current_param_type, param_value); |
|
986 nb_param++; |
681 break; |
987 break; |
682 case function_param_iterator_c::direction_out: |
988 case function_param_iterator_c::direction_out: |
683 case function_param_iterator_c::direction_inout: |
989 case function_param_iterator_c::direction_inout: |
684 current_param_is_pointer = true; |
990 if (!has_output_params) { |
685 if (param_value == NULL) { |
991 if (nb_param > 0) |
686 s4o.print("NULL"); |
992 s4o.print(",\n"+s4o.indent_spaces); |
687 } else { |
993 if (param_value == NULL) { |
688 param_value->accept(*this); |
994 s4o.print("NULL"); |
689 } |
995 } else { |
690 current_param_is_pointer = false; |
996 wanted_variablegeneration = fparam_output_vg; |
|
997 param_value->accept(*this); |
|
998 wanted_variablegeneration = expression_vg; |
|
999 } |
|
1000 nb_param++; |
|
1001 } |
691 break; |
1002 break; |
692 case function_param_iterator_c::direction_extref: |
1003 case function_param_iterator_c::direction_extref: |
693 /* TODO! */ |
1004 /* TODO! */ |
694 ERROR; |
1005 ERROR; |
695 break; |
1006 break; |
696 } /* switch */ |
1007 } /* switch */ |
697 } |
1008 } |
|
1009 if (has_output_params) { |
|
1010 if (nb_param > 0) |
|
1011 s4o.print(",\n"+s4o.indent_spaces); |
|
1012 s4o.print(FB_FUNCTION_PARAM); |
|
1013 } |
698 |
1014 |
699 s4o.print(")"); |
1015 s4o.print(")"); |
700 /* the data type returned by the function, and stored in the il default variable... */ |
1016 /* the data type returned by the function, and stored in the il default variable... */ |
701 default_variable_name.current_type = return_data_type; |
1017 default_variable_name.current_type = return_data_type; |
|
1018 |
|
1019 CLEAR_PARAM_LIST() |
|
1020 |
702 return NULL; |
1021 return NULL; |
703 } |
1022 } |
704 |
1023 |
705 |
1024 |
706 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
1025 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
805 |
1124 |
806 /* now output the value assignment */ |
1125 /* now output the value assignment */ |
807 if (param_value != NULL) |
1126 if (param_value != NULL) |
808 if ((param_direction == function_param_iterator_c::direction_in) || |
1127 if ((param_direction == function_param_iterator_c::direction_in) || |
809 (param_direction == function_param_iterator_c::direction_inout)) { |
1128 (param_direction == function_param_iterator_c::direction_inout)) { |
810 symbol->fb_name->accept(*this); |
1129 if (this->is_variable_prefix_null()) { |
811 s4o.print("."); |
1130 symbol->fb_name->accept(*this); |
812 param_name->accept(*this); |
1131 s4o.print("."); |
813 s4o.print(" = "); |
1132 param_name->accept(*this); |
814 if (search_base_type.type_is_subrange(param_type)) { |
1133 s4o.print(" = "); |
815 s4o.print("__CHECK_"); |
1134 print_check_function(param_type, param_value); |
816 param_type->accept(*this); |
1135 } |
817 s4o.print("("); |
1136 else { |
|
1137 print_setter(param_name, param_type, param_value, symbol->fb_name); |
818 } |
1138 } |
819 param_value->accept(*this); |
|
820 if (search_base_type.type_is_subrange(param_type)) |
|
821 s4o.print(")"); |
|
822 s4o.print(";\n" + s4o.indent_spaces); |
1139 s4o.print(";\n" + s4o.indent_spaces); |
823 } |
1140 } |
824 } /* for(...) */ |
1141 } /* for(...) */ |
825 |
1142 |
826 /* now call the function... */ |
1143 /* now call the function... */ |
827 function_block_type_name->accept(*this); |
1144 function_block_type_name->accept(*this); |
828 s4o.print(FB_FUNCTION_SUFFIX); |
1145 s4o.print(FB_FUNCTION_SUFFIX); |
829 s4o.print("(&"); |
1146 s4o.print("(&"); |
|
1147 print_variable_prefix(); |
830 symbol->fb_name->accept(*this); |
1148 symbol->fb_name->accept(*this); |
831 s4o.print(")"); |
1149 s4o.print(")"); |
832 |
1150 |
833 /* loop through each function parameter, find the variable to which |
1151 /* loop through each function parameter, find the variable to which |
834 * we should atribute the value of all output or inoutput parameters. |
1152 * we should atribute the value of all output or inoutput parameters. |
847 |
1165 |
848 /* now output the value assignment */ |
1166 /* now output the value assignment */ |
849 if (param_value != NULL) |
1167 if (param_value != NULL) |
850 if ((param_direction == function_param_iterator_c::direction_out) || |
1168 if ((param_direction == function_param_iterator_c::direction_out) || |
851 (param_direction == function_param_iterator_c::direction_inout)) { |
1169 (param_direction == function_param_iterator_c::direction_inout)) { |
852 symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false); |
1170 symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value); |
853 |
1171 s4o.print(";\n" + s4o.indent_spaces); |
854 s4o.print(";\n"+ s4o.indent_spaces); |
1172 if (this->is_variable_prefix_null()) { |
855 param_value->accept(*this); |
1173 param_value->accept(*this); |
856 s4o.print(" = "); |
1174 s4o.print(" = "); |
857 if (search_base_type.type_is_subrange(param_type)) { |
1175 print_check_function(param_type, param_name, symbol->fb_name); |
858 s4o.print("__CHECK_"); |
1176 } |
859 param_type->accept(*this); |
1177 else { |
860 s4o.print("("); |
1178 print_setter(param_value, param_type, param_name, NULL, symbol->fb_name); |
861 } |
1179 } |
862 symbol->fb_name->accept(*this); |
|
863 s4o.print("."); |
|
864 param_name->accept(*this); |
|
865 if (search_base_type.type_is_subrange(param_type)) |
|
866 s4o.print(")"); |
|
867 } |
1180 } |
868 } /* for(...) */ |
1181 } /* for(...) */ |
869 |
1182 |
870 s4o.print(";\n"); |
1183 s4o.print(";\n"); |
871 s4o.indent_left(); |
1184 s4o.indent_left(); |
878 |
1191 |
879 |
1192 |
880 /* | function_name '(' eol_list [il_param_list] ')' */ |
1193 /* | function_name '(' eol_list [il_param_list] ')' */ |
881 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
1194 // SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
882 void *visit(il_formal_funct_call_c *symbol) { |
1195 void *visit(il_formal_funct_call_c *symbol) { |
883 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
|
884 |
|
885 symbol_c* function_type_prefix = NULL; |
1196 symbol_c* function_type_prefix = NULL; |
886 symbol_c* function_name = NULL; |
1197 symbol_c* function_name = NULL; |
887 symbol_c* function_type_suffix = NULL; |
1198 symbol_c* function_type_suffix = NULL; |
888 std::list<FUNCTION_PARAM> param_list; |
1199 DECLARE_PARAM_LIST() |
889 FUNCTION_PARAM *param; |
|
890 |
1200 |
891 symbol_c *return_data_type = NULL; |
1201 symbol_c *return_data_type = NULL; |
892 |
1202 |
|
1203 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
1204 |
|
1205 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
893 if (f_decl == function_symtable.end_value()) { |
1206 if (f_decl == function_symtable.end_value()) { |
894 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
1207 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
895 if (current_function_type == function_none) ERROR; |
1208 if (current_function_type == function_none) ERROR; |
896 |
1209 |
897 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
1210 return_data_type = (symbol_c *)search_expression_type->compute_standard_function_default(NULL, symbol); |
898 if (NULL == return_data_type) ERROR; |
1211 if (NULL == return_data_type) ERROR; |
899 |
1212 |
900 function_call_param_iterator_c function_call_param_iterator(symbol); |
|
901 |
|
902 int nb_param = 0; |
1213 int nb_param = 0; |
903 if (symbol->il_param_list != NULL) |
1214 if (symbol->il_param_list != NULL) |
904 nb_param += ((list_c *)symbol->il_param_list)->n; |
1215 nb_param += ((list_c *)symbol->il_param_list)->n; |
905 |
1216 |
906 identifier_c en_param_name("EN"); |
1217 symbol_c *en_param_name = (symbol_c *)(new identifier_c("EN")); |
907 /* Get the value from EN param */ |
1218 /* Get the value from EN param */ |
908 symbol_c *EN_param_value = function_call_param_iterator.search_f(&en_param_name); |
1219 symbol_c *EN_param_value = function_call_param_iterator.search_f(en_param_name); |
909 if (EN_param_value == NULL) |
1220 if (EN_param_value == NULL) |
910 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
1221 EN_param_value = (symbol_c*)(new boolean_literal_c((symbol_c*)(new bool_type_name_c()), new boolean_true_c())); |
911 else |
1222 else |
912 nb_param --; |
1223 nb_param --; |
913 ADD_PARAM_LIST(EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
1224 ADD_PARAM_LIST(en_param_name, EN_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_in) |
914 |
1225 |
915 identifier_c eno_param_name("EN0"); |
1226 symbol_c *eno_param_name = (symbol_c *)(new identifier_c("ENO")); |
916 /* Get the value from ENO param */ |
1227 /* Get the value from ENO param */ |
917 symbol_c *ENO_param_value = function_call_param_iterator.search_f(&eno_param_name); |
1228 symbol_c *ENO_param_value = function_call_param_iterator.search_f(eno_param_name); |
918 if (ENO_param_value != NULL) |
1229 if (ENO_param_value != NULL) |
919 nb_param --; |
1230 nb_param --; |
920 ADD_PARAM_LIST(ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
1231 ADD_PARAM_LIST(eno_param_name, ENO_param_value, (symbol_c*)(new bool_type_name_c()), function_param_iterator_c::direction_out) |
921 |
1232 |
922 #define search(x) search_f(x) |
|
923 #define next() next_nf() |
|
924 // #define search_constant_type_c::constant_int_type_name search_expression_type_c::integer |
|
925 #define constant_int_type_name integer |
|
926 #include "st_code_gen.c" |
1233 #include "st_code_gen.c" |
927 #undef constant_int_type_name |
|
928 // #undef search_constant_type_c::constant_int_type_name |
|
929 #undef next |
|
930 #undef search |
|
931 |
1234 |
932 } |
1235 } |
933 else { |
1236 else { |
934 /* determine the base data type returned by the function being called... */ |
1237 /* determine the base data type returned by the function being called... */ |
935 search_base_type_c search_base_type; |
1238 search_base_type_c search_base_type; |
964 * it will always return NULL. |
1266 * it will always return NULL. |
965 * We leave it in in case we later decide to merge this part of the code together |
1267 * We leave it in in case we later decide to merge this part of the code together |
966 * with the function calling code in generate_c_st_c, which does require |
1268 * with the function calling code in generate_c_st_c, which does require |
967 * the following line... |
1269 * the following line... |
968 */ |
1270 */ |
969 if (param_value == NULL) |
1271 if (param_value == NULL) { |
970 param_value = function_call_param_iterator.next_nf(); |
1272 param_value = function_call_param_iterator.next_nf(); |
|
1273 if (param_value != NULL && fp_iterator.is_en_eno_param_implicit()) ERROR; |
|
1274 } |
971 |
1275 |
972 if (param_value == NULL) { |
1276 if (param_value == NULL) { |
973 /* No value given for parameter, so we must use the default... */ |
1277 /* No value given for parameter, so we must use the default... */ |
974 /* First check whether default value specified in function declaration...*/ |
1278 /* First check whether default value specified in function declaration...*/ |
975 param_value = fp_iterator.default_value(); |
1279 param_value = fp_iterator.default_value(); |
976 } |
1280 } |
977 |
1281 |
978 ADD_PARAM_LIST(param_value, param_type, fp_iterator.param_direction()) |
1282 ADD_PARAM_LIST(param_name, param_value, param_type, fp_iterator.param_direction()) |
979 } |
1283 } |
980 } |
1284 } |
981 |
1285 |
|
1286 if (function_call_param_iterator.next_nf() != NULL) ERROR; |
|
1287 |
|
1288 bool has_output_params = false; |
|
1289 |
|
1290 if (!this->is_variable_prefix_null()) { |
|
1291 PARAM_LIST_ITERATOR() { |
|
1292 if ((PARAM_DIRECTION == function_param_iterator_c::direction_out || |
|
1293 PARAM_DIRECTION == function_param_iterator_c::direction_inout) && |
|
1294 PARAM_VALUE != NULL) { |
|
1295 if (!has_output_params) { |
|
1296 has_output_params = true; |
|
1297 } |
|
1298 } |
|
1299 } |
|
1300 } |
|
1301 |
982 default_variable_name.current_type = return_data_type; |
1302 default_variable_name.current_type = return_data_type; |
983 this->default_variable_name.accept(*this); |
1303 this->default_variable_name.accept(*this); |
984 s4o.print(" = "); |
1304 s4o.print(" = "); |
985 |
1305 |
986 if (function_type_prefix != NULL) { |
1306 if (function_type_prefix != NULL) { |
987 s4o.print("("); |
1307 s4o.print("("); |
988 function_type_prefix->accept(*this); |
1308 function_type_prefix->accept(*this); |
989 s4o.print(")"); |
1309 s4o.print(")"); |
990 } |
1310 } |
991 if (function_name != NULL) |
1311 if (has_output_params) { |
|
1312 fcall_number++; |
|
1313 s4o.print("__"); |
|
1314 fbname->accept(*this); |
|
1315 s4o.print("_"); |
992 function_name->accept(*this); |
1316 function_name->accept(*this); |
993 if (function_type_suffix != NULL) |
1317 s4o.print_integer(fcall_number); |
994 function_type_suffix->accept(*this); |
1318 } |
|
1319 else { |
|
1320 if (function_name != NULL) |
|
1321 function_name->accept(*this); |
|
1322 if (function_type_suffix != NULL) |
|
1323 function_type_suffix->accept(*this); |
|
1324 } |
995 s4o.print("("); |
1325 s4o.print("("); |
996 s4o.indent_right(); |
1326 s4o.indent_right(); |
997 |
1327 |
998 std::list<FUNCTION_PARAM>::iterator pt; |
1328 int nb_param = 0; |
999 for(pt = param_list.begin(); pt != param_list.end(); pt++) { |
1329 PARAM_LIST_ITERATOR() { |
1000 if (pt != param_list.begin()) |
1330 symbol_c *param_value = PARAM_VALUE; |
1001 s4o.print(",\n"+s4o.indent_spaces); |
1331 current_param_type = PARAM_TYPE; |
1002 symbol_c *param_value = pt->param_value; |
|
1003 symbol_c *param_type = pt->param_type; |
|
1004 |
1332 |
1005 switch (pt->param_direction) { |
1333 switch (PARAM_DIRECTION) { |
1006 case function_param_iterator_c::direction_in: |
1334 case function_param_iterator_c::direction_in: |
1007 if (param_value == NULL) { |
1335 if (nb_param > 0) |
|
1336 s4o.print(",\n"+s4o.indent_spaces); |
|
1337 if (param_value == NULL) { |
1008 /* If not, get the default value of this variable's type */ |
1338 /* If not, get the default value of this variable's type */ |
1009 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
1339 param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance()); |
1010 } |
1340 } |
1011 if (param_value == NULL) ERROR; |
1341 if (param_value == NULL) ERROR; |
1012 if (search_base_type.type_is_subrange(param_type)) { |
1342 s4o.print("("); |
1013 s4o.print("__CHECK_"); |
1343 if (search_expression_type->is_literal_integer_type(current_param_type)) |
1014 param_type->accept(*this); |
1344 search_expression_type->lint_type_name.accept(*this); |
1015 s4o.print("("); |
1345 else if (search_expression_type->is_literal_real_type(current_param_type)) |
1016 } |
1346 search_expression_type->lreal_type_name.accept(*this); |
1017 param_value->accept(*this); |
1347 else |
1018 if (search_base_type.type_is_subrange(param_type)) |
1348 current_param_type->accept(*this); |
1019 s4o.print(")"); |
1349 s4o.print(")"); |
1020 break; |
1350 print_check_function(current_param_type, param_value); |
|
1351 nb_param++; |
|
1352 break; |
1021 case function_param_iterator_c::direction_out: |
1353 case function_param_iterator_c::direction_out: |
1022 case function_param_iterator_c::direction_inout: |
1354 case function_param_iterator_c::direction_inout: |
1023 current_param_is_pointer = true; |
1355 if (!has_output_params) { |
1024 if (param_value == NULL) { |
1356 if (nb_param > 0) |
1025 s4o.print("NULL"); |
1357 s4o.print(",\n"+s4o.indent_spaces); |
1026 } else { |
1358 if (param_value == NULL) { |
1027 param_value->accept(*this); |
1359 s4o.print("NULL"); |
1028 } |
1360 } else { |
1029 current_param_is_pointer = false; |
1361 wanted_variablegeneration = fparam_output_vg; |
1030 break; |
1362 param_value->accept(*this); |
|
1363 wanted_variablegeneration = expression_vg; |
|
1364 } |
|
1365 } |
|
1366 break; |
1031 case function_param_iterator_c::direction_extref: |
1367 case function_param_iterator_c::direction_extref: |
1032 /* TODO! */ |
1368 /* TODO! */ |
1033 ERROR; |
1369 ERROR; |
1034 break; |
1370 break; |
1035 } /* switch */ |
1371 } /* switch */ |
1036 } /* for(...) */ |
1372 } /* for(...) */ |
|
1373 if (has_output_params) { |
|
1374 if (nb_param > 0) |
|
1375 s4o.print(",\n"+s4o.indent_spaces); |
|
1376 s4o.print(FB_FUNCTION_PARAM); |
|
1377 } |
1037 |
1378 |
1038 // symbol->parameter_assignment->accept(*this); |
1379 // symbol->parameter_assignment->accept(*this); |
1039 s4o.print(")"); |
1380 s4o.print(")"); |
1040 /* the data type returned by the function, and stored in the il default variable... */ |
1381 /* the data type returned by the function, and stored in the il default variable... */ |
|
1382 |
|
1383 CLEAR_PARAM_LIST() |
|
1384 |
1041 return NULL; |
1385 return NULL; |
1042 } |
1386 } |
1043 |
1387 |
1044 |
1388 |
1045 /* | il_operand_list ',' il_operand */ |
1389 /* | il_operand_list ',' il_operand */ |
1180 this->current_operand); |
1524 this->current_operand); |
1181 return NULL; |
1525 return NULL; |
1182 } |
1526 } |
1183 |
1527 |
1184 void *visit(ST_operator_c *symbol) { |
1528 void *visit(ST_operator_c *symbol) { |
1185 symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
1529 symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand); |
1186 |
1530 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) || |
1187 this->current_operand->accept(*this); |
1531 search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) |
1188 s4o.print(" = "); |
1532 this->default_variable_name.current_type = this->current_operand_type; |
1189 if (search_base_type.type_is_subrange(operand_type)) { |
1533 if (this->is_variable_prefix_null()) { |
1190 s4o.print("__CHECK_"); |
1534 this->current_operand->accept(*this); |
1191 operand_type->accept(*this); |
1535 s4o.print(" = "); |
1192 s4o.print("("); |
1536 print_check_function(operand_type, (symbol_c*)&(this->default_variable_name)); |
1193 } |
1537 } |
1194 this->default_variable_name.accept(*this); |
1538 else { |
1195 if (search_base_type.type_is_subrange(operand_type)) |
1539 print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name)); |
1196 s4o.print(")"); |
1540 } |
1197 /* the data type resulting from this operation is unchamged. */ |
1541 /* the data type resulting from this operation is unchanged. */ |
1198 return NULL; |
1542 return NULL; |
1199 } |
1543 } |
1200 |
1544 |
1201 void *visit(STN_operator_c *symbol) { |
1545 void *visit(STN_operator_c *symbol) { |
1202 symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false); |
1546 symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand); |
1203 |
1547 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) |
1204 this->current_operand->accept(*this); |
1548 this->default_variable_name.current_type = this->current_operand_type; |
1205 s4o.print(" = "); |
1549 |
1206 if (search_base_type.type_is_subrange(operand_type)) { |
1550 if (this->is_variable_prefix_null()) { |
1207 s4o.print("__CHECK_"); |
1551 this->current_operand->accept(*this); |
1208 operand_type->accept(*this); |
1552 s4o.print(" = "); |
1209 s4o.print("("); |
1553 if (search_expression_type->is_bool_type(this->current_operand_type)) |
1210 } |
1554 s4o.print("!"); |
1211 if (search_expression_type->is_bool_type(this->current_operand_type)) |
1555 else |
1212 s4o.print("!"); |
1556 s4o.print("~"); |
1213 else |
1557 this->default_variable_name.accept(*this); |
1214 s4o.print("~"); |
1558 } |
1215 this->default_variable_name.accept(*this); |
1559 else { |
1216 if (search_base_type.type_is_subrange(operand_type)) |
1560 print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name), NULL, NULL, true); |
1217 s4o.print(")"); |
1561 } |
1218 /* the data type resulting from this operation is unchamged. */ |
1562 /* the data type resulting from this operation is unchanged. */ |
1219 return NULL; |
1563 return NULL; |
1220 } |
1564 } |
1221 |
1565 |
1222 void *visit(NOT_operator_c *symbol) { |
1566 void *visit(NOT_operator_c *symbol) { |
1223 if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR; |
1567 if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR; |
1231 void *visit(S_operator_c *symbol) { |
1575 void *visit(S_operator_c *symbol) { |
1232 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1576 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1233 |
1577 |
1234 C_modifier(); |
1578 C_modifier(); |
1235 this->current_operand->accept(*this); |
1579 this->current_operand->accept(*this); |
1236 s4o.print(search_expression_type->is_bool_type(this->current_operand_type)?" = true":" = 1"); |
1580 s4o.print(" = __"); |
|
1581 if (search_expression_type->is_bool_type(this->current_operand_type)) |
|
1582 s4o.print("BOOL_LITERAL(TRUE)"); |
|
1583 else if (search_expression_type->is_integer_type(this->current_operand_type)) { |
|
1584 this->current_operand_type->accept(*this); |
|
1585 s4o.print("_LITERAL(1)"); |
|
1586 } |
|
1587 else |
|
1588 ERROR; |
1237 /* the data type resulting from this operation is unchanged! */ |
1589 /* the data type resulting from this operation is unchanged! */ |
1238 return NULL; |
1590 return NULL; |
1239 } |
1591 } |
1240 |
1592 |
1241 void *visit(R_operator_c *symbol) { |
1593 void *visit(R_operator_c *symbol) { |
1242 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1594 if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR; |
1243 |
1595 |
1244 C_modifier(); |
1596 C_modifier(); |
1245 this->current_operand->accept(*this); |
1597 this->current_operand->accept(*this); |
1246 s4o.print(search_expression_type->is_bool_type(this->current_operand_type)?" = false":" = 0"); |
1598 s4o.print(" = __"); |
|
1599 if (search_expression_type->is_bool_type(this->current_operand_type)) |
|
1600 s4o.print("BOOL_LITERAL(FALSE)"); |
|
1601 else if (search_expression_type->is_integer_type(this->current_operand_type)) { |
|
1602 this->current_operand_type->accept(*this); |
|
1603 s4o.print("_LITERAL(0)"); |
|
1604 } |
|
1605 else |
|
1606 ERROR; |
1247 /* the data type resulting from this operation is unchanged! */ |
1607 /* the data type resulting from this operation is unchanged! */ |
1248 return NULL; |
1608 return NULL; |
1249 } |
1609 } |
1250 |
1610 |
1251 void *visit(S1_operator_c *symbol) {return XXX_CAL_operator("S1", this->current_operand);} |
1611 void *visit(S1_operator_c *symbol) {return XXX_CAL_operator("S1", this->current_operand);} |
1258 void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} |
1618 void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} |
1259 |
1619 |
1260 void *visit(AND_operator_c *symbol) { |
1620 void *visit(AND_operator_c *symbol) { |
1261 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1621 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1262 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1622 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1263 XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); |
1623 BYTE_operator_result_type(); |
|
1624 XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); |
1264 /* the data type resulting from this operation... */ |
1625 /* the data type resulting from this operation... */ |
1265 this->default_variable_name.current_type = this->current_operand_type; |
1626 this->default_variable_name.current_type = this->current_operand_type; |
1266 } |
1627 } |
1267 else {ERROR;} |
1628 else {ERROR;} |
1268 return NULL; |
1629 return NULL; |
1269 } |
1630 } |
1270 |
1631 |
1271 void *visit(OR_operator_c *symbol) { |
1632 void *visit(OR_operator_c *symbol) { |
1272 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1633 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1273 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1634 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1274 XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); |
1635 BYTE_operator_result_type(); |
|
1636 XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); |
1275 /* the data type resulting from this operation... */ |
1637 /* the data type resulting from this operation... */ |
1276 this->default_variable_name.current_type = this->current_operand_type; |
1638 this->default_variable_name.current_type = this->current_operand_type; |
1277 } |
1639 } |
1278 else {ERROR;} |
1640 else {ERROR;} |
1279 return NULL; |
1641 return NULL; |
1280 } |
1642 } |
1281 |
1643 |
1282 void *visit(XOR_operator_c *symbol) { |
1644 void *visit(XOR_operator_c *symbol) { |
1283 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1645 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1284 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1646 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1285 // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! |
1647 BYTE_operator_result_type(); |
|
1648 // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! |
1286 XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); |
1649 XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); |
1287 /* the data type resulting from this operation... */ |
1650 /* the data type resulting from this operation... */ |
1288 this->default_variable_name.current_type = this->current_operand_type; |
1651 this->default_variable_name.current_type = this->current_operand_type; |
1289 } |
1652 } |
1290 else {ERROR;} |
1653 else {ERROR;} |
1318 } |
1683 } |
1319 |
1684 |
1320 void *visit(XORN_operator_c *symbol) { |
1685 void *visit(XORN_operator_c *symbol) { |
1321 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1686 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1322 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1687 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1323 XXX_operator(&(this->default_variable_name), |
1688 BYTE_operator_result_type(); |
|
1689 XXX_operator(&(this->default_variable_name), |
1324 // bit by bit exclusive OR !! Also seems to work with boolean types! |
1690 // bit by bit exclusive OR !! Also seems to work with boolean types! |
1325 search_expression_type->is_bool_type(this->current_operand_type)?" ^= !":" ^= ~", |
1691 search_expression_type->is_bool_type(this->current_operand_type)?" ^= !":" ^= ~", |
1326 this->current_operand); |
1692 this->current_operand); |
1327 /* the data type resulting from this operation... */ |
1693 /* the data type resulting from this operation... */ |
1328 this->default_variable_name.current_type = this->current_operand_type; |
1694 this->default_variable_name.current_type = this->current_operand_type; |
1394 /* the data type resulting from this operation... */ |
1763 /* the data type resulting from this operation... */ |
1395 return NULL; |
1764 return NULL; |
1396 } |
1765 } |
1397 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1766 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1398 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1767 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1399 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
1768 NUM_operator_result_type(); |
|
1769 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
1400 /* the data type resulting from this operation... */ |
1770 /* the data type resulting from this operation... */ |
1401 this->default_variable_name.current_type = this->current_operand_type; |
1771 this->default_variable_name.current_type = this->current_operand_type; |
1402 } |
1772 } |
1403 ERROR; |
1773 ERROR; |
1404 return NULL; |
1774 return NULL; |
1405 } |
1775 } |
1406 |
1776 |
1407 void *visit(MOD_operator_c *symbol) { |
1777 void *visit(MOD_operator_c *symbol) { |
1408 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1778 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1409 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1779 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1410 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
1780 NUM_operator_result_type(); |
|
1781 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
1411 /* the data type resulting from this operation... */ |
1782 /* the data type resulting from this operation... */ |
1412 this->default_variable_name.current_type = this->current_operand_type; |
1783 this->default_variable_name.current_type = this->current_operand_type; |
1413 } |
1784 } |
1414 ERROR; |
1785 ERROR; |
1415 return NULL; |
1786 return NULL; |