259 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
263 search_fb_instance_decl = new search_fb_instance_decl_c(scope); |
260 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
264 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
261 current_operand = NULL; |
265 current_operand = NULL; |
262 current_operand_type = NULL; |
266 current_operand_type = NULL; |
263 il_default_variable_init_value = NULL; |
267 il_default_variable_init_value = NULL; |
|
268 current_array_type = NULL; |
264 fcall_number = 0; |
269 fcall_number = 0; |
265 fbname = name; |
270 fbname = name; |
266 wanted_variablegeneration = expression_vg; |
271 wanted_variablegeneration = expression_vg; |
267 this->set_variable_prefix(variable_prefix); |
272 this->set_variable_prefix(variable_prefix); |
268 } |
273 } |
426 else if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
431 else if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
427 search_expression_type->is_literal_real_type(this->current_operand_type)) |
432 search_expression_type->is_literal_real_type(this->current_operand_type)) |
428 this->current_operand_type = this->default_variable_name.current_type; |
433 this->current_operand_type = this->default_variable_name.current_type; |
429 } |
434 } |
430 |
435 |
|
436 void *print_getter(symbol_c *symbol) { |
|
437 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
|
438 if (vartype == search_var_instance_decl_c::external_vt) |
|
439 s4o.print(GET_EXTERNAL); |
|
440 else if (vartype == search_var_instance_decl_c::located_vt) |
|
441 s4o.print(GET_LOCATED); |
|
442 else |
|
443 s4o.print(GET_VAR); |
|
444 s4o.print("("); |
|
445 |
|
446 wanted_variablegeneration = complextype_base_vg; |
|
447 symbol->accept(*this); |
|
448 if (search_varfb_instance_type->type_is_complex()) |
|
449 s4o.print(","); |
|
450 wanted_variablegeneration = complextype_suffix_vg; |
|
451 symbol->accept(*this); |
|
452 s4o.print(")"); |
|
453 wanted_variablegeneration = expression_vg; |
|
454 return NULL; |
|
455 } |
|
456 |
|
457 void *print_setter(symbol_c* symbol, |
|
458 symbol_c* type, |
|
459 symbol_c* value, |
|
460 symbol_c* fb_symbol = NULL, |
|
461 symbol_c* fb_value = NULL, |
|
462 bool negative = false) { |
|
463 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
|
464 if (vartype == search_var_instance_decl_c::external_vt) |
|
465 s4o.print(SET_EXTERNAL); |
|
466 else if (vartype == search_var_instance_decl_c::located_vt) |
|
467 s4o.print(SET_LOCATED); |
|
468 else |
|
469 s4o.print(SET_VAR); |
|
470 s4o.print("("); |
|
471 |
|
472 if (fb_symbol != NULL) { |
|
473 print_variable_prefix(); |
|
474 fb_symbol->accept(*this); |
|
475 s4o.print("."); |
|
476 } |
|
477 else |
|
478 wanted_variablegeneration = complextype_base_vg; |
|
479 symbol->accept(*this); |
|
480 s4o.print(","); |
|
481 if (negative) { |
|
482 if (search_expression_type->is_bool_type(this->current_operand_type)) |
|
483 s4o.print("!"); |
|
484 else |
|
485 s4o.print("~"); |
|
486 } |
|
487 wanted_variablegeneration = expression_vg; |
|
488 print_check_function(type, value, fb_value); |
|
489 if (search_varfb_instance_type->type_is_complex()) { |
|
490 s4o.print(","); |
|
491 wanted_variablegeneration = complextype_suffix_vg; |
|
492 symbol->accept(*this); |
|
493 } |
|
494 s4o.print(")"); |
|
495 wanted_variablegeneration = expression_vg; |
|
496 return NULL; |
|
497 } |
431 |
498 |
432 public: |
499 public: |
433 void *visit(il_default_variable_c *symbol) { |
500 void *visit(il_default_variable_c *symbol) { |
434 //s4o.print("il_default_variable_c VISITOR!!\n"); |
501 //s4o.print("il_default_variable_c VISITOR!!\n"); |
435 symbol->var_name->accept(*this); |
502 symbol->var_name->accept(*this); |
469 /*********************/ |
536 /*********************/ |
470 /* B 1.4 - Variables */ |
537 /* B 1.4 - Variables */ |
471 /*********************/ |
538 /*********************/ |
472 |
539 |
473 void *visit(symbolic_variable_c *symbol) { |
540 void *visit(symbolic_variable_c *symbol) { |
474 unsigned int vartype = search_varfb_instance_type->get_vartype(symbol); |
541 unsigned int vartype; |
475 if (this->is_variable_prefix_null()) { |
542 if (wanted_variablegeneration == complextype_base_vg) |
|
543 generate_c_base_c::visit(symbol); |
|
544 else if (wanted_variablegeneration == complextype_suffix_vg) |
|
545 return NULL; |
|
546 else if (this->is_variable_prefix_null()) { |
|
547 vartype = search_varfb_instance_type->get_vartype(symbol); |
476 if (wanted_variablegeneration == fparam_output_vg) { |
548 if (wanted_variablegeneration == fparam_output_vg) { |
477 if (vartype == search_var_instance_decl_c::external_vt) |
549 if (vartype == search_var_instance_decl_c::external_vt) |
478 s4o.print(GET_EXTERNAL); |
550 s4o.print(GET_EXTERNAL); |
479 else |
551 else |
480 s4o.print("&"); |
552 s4o.print("&"); |
554 this->print_variable_prefix(); |
628 this->print_variable_prefix(); |
555 s4o.printlocation(symbol->value + 1); |
629 s4o.printlocation(symbol->value + 1); |
556 if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) || |
630 if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) || |
557 wanted_variablegeneration != assignment_vg) |
631 wanted_variablegeneration != assignment_vg) |
558 s4o.print(")"); |
632 s4o.print(")"); |
|
633 return NULL; |
|
634 } |
|
635 |
|
636 /*************************************/ |
|
637 /* B.1.4.2 Multi-element Variables */ |
|
638 /*************************************/ |
|
639 |
|
640 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
641 void *visit(structured_variable_c *symbol) { |
|
642 TRACE("structured_variable_c"); |
|
643 switch (wanted_variablegeneration) { |
|
644 case complextype_base_vg: |
|
645 symbol->record_variable->accept(*this); |
|
646 break; |
|
647 case complextype_suffix_vg: |
|
648 symbol->record_variable->accept(*this); |
|
649 s4o.print("."); |
|
650 symbol->field_selector->accept(*this); |
|
651 break; |
|
652 default: |
|
653 if (this->is_variable_prefix_null()) { |
|
654 symbol->record_variable->accept(*this); |
|
655 s4o.print("."); |
|
656 symbol->field_selector->accept(*this); |
|
657 } |
|
658 else |
|
659 print_getter(symbol); |
|
660 break; |
|
661 } |
|
662 return NULL; |
|
663 } |
|
664 |
|
665 /* subscripted_variable '[' subscript_list ']' */ |
|
666 //SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
667 void *visit(array_variable_c *symbol) { |
|
668 switch (wanted_variablegeneration) { |
|
669 case complextype_base_vg: |
|
670 symbol->subscripted_variable->accept(*this); |
|
671 break; |
|
672 case complextype_suffix_vg: |
|
673 current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
|
674 symbol->subscripted_variable->accept(*this); |
|
675 if (current_array_type != NULL) { |
|
676 symbol->subscript_list->accept(*this); |
|
677 current_array_type = NULL; |
|
678 } |
|
679 break; |
|
680 default: |
|
681 if (this->is_variable_prefix_null()) { |
|
682 current_array_type = search_varfb_instance_type->get_rawtype(symbol->subscripted_variable); |
|
683 symbol->subscripted_variable->accept(*this); |
|
684 if (current_array_type != NULL) { |
|
685 symbol->subscript_list->accept(*this); |
|
686 current_array_type = NULL; |
|
687 } |
|
688 } |
|
689 else |
|
690 print_getter(symbol); |
|
691 break; |
|
692 } |
|
693 return NULL; |
|
694 } |
|
695 |
|
696 /* subscript_list ',' subscript */ |
|
697 void *visit(subscript_list_c *symbol) { |
|
698 for (int i = 0; i < symbol->n; i++) { |
|
699 s4o.print("[__"); |
|
700 current_array_type->accept(*this); |
|
701 s4o.print("_TRANSIDX"); |
|
702 print_integer(i); |
|
703 s4o.print("("); |
|
704 symbol->elements[i]->accept(*this); |
|
705 s4o.print(")]"); |
|
706 } |
559 return NULL; |
707 return NULL; |
560 } |
708 } |
561 |
709 |
562 /****************************************/ |
710 /****************************************/ |
563 /* B.2 - Language IL (Instruction List) */ |
711 /* B.2 - Language IL (Instruction List) */ |
958 |
1106 |
959 /* now output the value assignment */ |
1107 /* now output the value assignment */ |
960 if (param_value != NULL) |
1108 if (param_value != NULL) |
961 if ((param_direction == function_param_iterator_c::direction_in) || |
1109 if ((param_direction == function_param_iterator_c::direction_in) || |
962 (param_direction == function_param_iterator_c::direction_inout)) { |
1110 (param_direction == function_param_iterator_c::direction_inout)) { |
963 if (!this->is_variable_prefix_null()) { |
1111 if (this->is_variable_prefix_null()) { |
964 s4o.print(SET_VAR); |
1112 symbol->fb_name->accept(*this); |
965 s4o.print("("); |
1113 s4o.print("."); |
|
1114 param_name->accept(*this); |
|
1115 s4o.print(" = "); |
|
1116 print_check_function(param_type, param_value); |
966 } |
1117 } |
967 symbol->fb_name->accept(*this); |
1118 else { |
968 s4o.print("."); |
1119 print_setter(param_name, param_type, param_value, symbol->fb_name); |
969 param_name->accept(*this); |
1120 } |
970 if (this->is_variable_prefix_null()) |
|
971 s4o.print(" = "); |
|
972 else |
|
973 s4o.print(","); |
|
974 print_check_function(param_type, param_value); |
|
975 if (!this->is_variable_prefix_null()) |
|
976 s4o.print(")"); |
|
977 s4o.print(";\n" + s4o.indent_spaces); |
1121 s4o.print(";\n" + s4o.indent_spaces); |
978 } |
1122 } |
979 } /* for(...) */ |
1123 } /* for(...) */ |
980 |
1124 |
981 /* now call the function... */ |
1125 /* now call the function... */ |
1003 /* now output the value assignment */ |
1147 /* now output the value assignment */ |
1004 if (param_value != NULL) |
1148 if (param_value != NULL) |
1005 if ((param_direction == function_param_iterator_c::direction_out) || |
1149 if ((param_direction == function_param_iterator_c::direction_out) || |
1006 (param_direction == function_param_iterator_c::direction_inout)) { |
1150 (param_direction == function_param_iterator_c::direction_inout)) { |
1007 symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value); |
1151 symbol_c *param_type = search_varfb_instance_type->get_rawtype(param_value); |
1008 unsigned int vartype = search_varfb_instance_type->get_vartype(param_value); |
1152 if (this->is_variable_prefix_null()) { |
1009 |
|
1010 if (!this->is_variable_prefix_null()) { |
|
1011 s4o.print(";\n"+ s4o.indent_spaces); |
|
1012 if (vartype == search_var_instance_decl_c::external_vt) |
|
1013 s4o.print(SET_EXTERNAL); |
|
1014 else if (vartype == search_var_instance_decl_c::located_vt) |
|
1015 s4o.print(SET_LOCATED); |
|
1016 else |
|
1017 s4o.print(SET_VAR); |
|
1018 s4o.print("("); |
|
1019 |
|
1020 wanted_variablegeneration = assignment_vg; |
|
1021 param_value->accept(*this); |
1153 param_value->accept(*this); |
1022 wanted_variablegeneration = expression_vg; |
1154 s4o.print(" = "); |
1023 s4o.print(","); |
1155 print_check_function(param_type, param_name, symbol->fb_name); |
1024 } |
1156 } |
1025 else { |
1157 else { |
1026 param_value->accept(*this); |
1158 print_setter(param_value, param_type, param_name, NULL, symbol->fb_name); |
1027 s4o.print(" = "); |
1159 } |
1028 } |
|
1029 print_check_function(param_type, param_name, symbol->fb_name); |
|
1030 if (!this->is_variable_prefix_null()) |
|
1031 s4o.print(")"); |
|
1032 } |
1160 } |
1033 } /* for(...) */ |
1161 } /* for(...) */ |
1034 |
1162 |
1035 s4o.print(";\n"); |
1163 s4o.print(";\n"); |
1036 s4o.indent_left(); |
1164 s4o.indent_left(); |
1375 return NULL; |
1503 return NULL; |
1376 } |
1504 } |
1377 |
1505 |
1378 void *visit(ST_operator_c *symbol) { |
1506 void *visit(ST_operator_c *symbol) { |
1379 symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand); |
1507 symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand); |
1380 |
1508 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) || |
1381 if (!this->is_variable_prefix_null()) { |
1509 search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) |
1382 unsigned int vartype = search_varfb_instance_type->get_vartype(this->current_operand); |
1510 this->default_variable_name.current_type = this->current_operand_type; |
1383 if (vartype == search_var_instance_decl_c::external_vt) |
1511 if (this->is_variable_prefix_null()) { |
1384 s4o.print(SET_EXTERNAL); |
|
1385 else if (vartype == search_var_instance_decl_c::located_vt) |
|
1386 s4o.print(SET_LOCATED); |
|
1387 else |
|
1388 s4o.print(SET_VAR); |
|
1389 s4o.print("("); |
|
1390 |
|
1391 wanted_variablegeneration = assignment_vg; |
|
1392 this->current_operand->accept(*this); |
|
1393 wanted_variablegeneration = expression_vg; |
|
1394 |
|
1395 s4o.print(","); |
|
1396 } |
|
1397 else { |
|
1398 this->current_operand->accept(*this); |
1512 this->current_operand->accept(*this); |
1399 s4o.print(" = "); |
1513 s4o.print(" = "); |
1400 } |
1514 print_check_function(operand_type, (symbol_c*)&(this->default_variable_name)); |
1401 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) || |
1515 } |
1402 search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) |
1516 else { |
1403 this->default_variable_name.current_type = this->current_operand_type; |
1517 print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name)); |
1404 print_check_function(operand_type, (symbol_c*)&(this->default_variable_name)); |
1518 } |
1405 if (!this->is_variable_prefix_null()) |
|
1406 s4o.print(")"); |
|
1407 /* the data type resulting from this operation is unchanged. */ |
1519 /* the data type resulting from this operation is unchanged. */ |
1408 return NULL; |
1520 return NULL; |
1409 } |
1521 } |
1410 |
1522 |
1411 void *visit(STN_operator_c *symbol) { |
1523 void *visit(STN_operator_c *symbol) { |
1412 symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand); |
1524 symbol_c *operand_type = search_varfb_instance_type->get_rawtype(this->current_operand); |
1413 |
1525 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) |
1414 if (!this->is_variable_prefix_null()) { |
1526 this->default_variable_name.current_type = this->current_operand_type; |
1415 unsigned int vartype = search_varfb_instance_type->get_vartype(this->current_operand); |
1527 |
1416 if (vartype == search_var_instance_decl_c::external_vt) |
1528 if (this->is_variable_prefix_null()) { |
1417 s4o.print(SET_EXTERNAL); |
|
1418 else if (vartype == search_var_instance_decl_c::located_vt) |
|
1419 s4o.print(SET_LOCATED); |
|
1420 else |
|
1421 s4o.print(SET_VAR); |
|
1422 s4o.print("("); |
|
1423 |
|
1424 wanted_variablegeneration = assignment_vg; |
|
1425 this->current_operand->accept(*this); |
|
1426 wanted_variablegeneration = expression_vg; |
|
1427 |
|
1428 s4o.print(","); |
|
1429 } |
|
1430 else { |
|
1431 this->current_operand->accept(*this); |
1529 this->current_operand->accept(*this); |
1432 s4o.print(" = "); |
1530 s4o.print(" = "); |
1433 } |
1531 if (search_expression_type->is_bool_type(this->current_operand_type)) |
1434 if (search_expression_type->is_bool_type(this->current_operand_type)) |
1532 s4o.print("!"); |
1435 s4o.print("!"); |
1533 else |
1436 else |
1534 s4o.print("~"); |
1437 s4o.print("~"); |
1535 this->default_variable_name.accept(*this); |
1438 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) |
1536 } |
1439 this->default_variable_name.current_type = this->current_operand_type; |
1537 else { |
1440 this->default_variable_name.accept(*this); |
1538 print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name), NULL, NULL, true); |
1441 if (!this->is_variable_prefix_null()) |
1539 } |
1442 s4o.print(")"); |
1540 /* the data type resulting from this operation is unchanged. */ |
1443 /* the data type resulting from this operation is unchamged. */ |
|
1444 return NULL; |
1541 return NULL; |
1445 } |
1542 } |
1446 |
1543 |
1447 void *visit(NOT_operator_c *symbol) { |
1544 void *visit(NOT_operator_c *symbol) { |
1448 if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR; |
1545 if ((NULL != this->current_operand) || (NULL != this->current_operand_type)) ERROR; |