548 /* | function_name [il_operand_list] */ |
548 /* | function_name [il_operand_list] */ |
549 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
549 // SYM_REF2(il_function_call_c, function_name, il_operand_list) |
550 void *visit(il_function_call_c *symbol) { |
550 void *visit(il_function_call_c *symbol) { |
551 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
551 function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name); |
552 |
552 |
553 if (f_decl == function_symtable.end_value()) |
553 if (f_decl == function_symtable.end_value()) { |
554 /* should never occur. The function being called MUST be in the symtable... */ |
554 /* should never occur. The function being called MUST be in the symtable... */ |
555 ERROR; |
555 function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); |
556 |
556 if (current_function_type == function_none) ERROR; |
557 /* determine the base data type returned by the function being called... */ |
557 |
558 search_base_type_c search_base_type; |
558 symbol_c *param_data_type = default_variable_name.current_type; |
559 symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
559 symbol_c *return_data_type = (symbol_c *)search_expression_type->compute_standard_function_il(symbol, param_data_type); |
560 symbol_c *param_data_type = default_variable_name.current_type; |
560 if (NULL == return_data_type) ERROR; |
561 if (NULL == return_data_type) ERROR; |
561 |
562 |
562 default_variable_name.current_type = return_data_type; |
563 default_variable_name.current_type = return_data_type; |
563 this->default_variable_name.accept(*this); |
564 this->default_variable_name.accept(*this); |
564 default_variable_name.current_type = param_data_type; |
565 default_variable_name.current_type = param_data_type; |
565 s4o.print(" = "); |
566 s4o.print(" = "); |
566 |
567 |
567 function_call_param_iterator_c function_call_param_iterator(symbol); |
568 symbol->function_name->accept(*this); |
568 |
569 s4o.print("("); |
569 int nb_param = 1; |
570 |
570 if (symbol->il_operand_list != NULL) |
571 /* loop through each function parameter, find the value we should pass |
571 nb_param += ((list_c *)symbol->il_operand_list)->n; |
572 * to it, and then output the c equivalent... |
572 |
573 */ |
573 for(int current_param = 0; current_param < nb_param; current_param++) { |
574 |
574 symbol_c *param_value; |
575 function_param_iterator_c fp_iterator(f_decl); |
575 if (current_param == 0) |
576 identifier_c *param_name; |
576 param_value = &this->default_variable_name; |
577 function_call_param_iterator_c function_call_param_iterator(symbol); |
577 else { |
578 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
578 symbol_c *param_name = NULL; |
579 if (i != 1) |
579 switch (current_function_type) { |
580 s4o.print(", "); |
580 default: ERROR; |
581 |
581 } |
582 symbol_c *param_type = fp_iterator.param_type(); |
582 |
583 if (param_type == NULL) ERROR; |
583 |
584 |
584 /* Get the value from a foo(<param_name> = <param_value>) style call */ |
585 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
585 param_value = function_call_param_iterator.search(param_name); |
586 |
586 delete param_name; |
587 |
587 |
588 symbol_c *param_value = NULL; |
588 /* Get the value from a foo(<param_value>) style call */ |
589 |
589 if (param_value == NULL) |
590 /* if it is the first parameter, semantics specifies that we should |
590 param_value = function_call_param_iterator.next(); |
591 * get the value off the IL default variable! |
591 |
|
592 if (param_value == NULL) ERROR; |
|
593 } |
|
594 |
|
595 switch (current_function_type) { |
|
596 case (function_sqrt): |
|
597 if (current_param == 0) { |
|
598 s4o.print("sqrt("); |
|
599 param_value->accept(*this); |
|
600 s4o.print(")"); |
|
601 } |
|
602 else ERROR; |
|
603 break; |
|
604 default: ERROR; |
|
605 } |
|
606 } /* for(...) */ |
|
607 |
|
608 /* the data type returned by the function, and stored in the il default variable... */ |
|
609 default_variable_name.current_type = return_data_type; |
|
610 } |
|
611 else { |
|
612 /* determine the base data type returned by the function being called... */ |
|
613 search_base_type_c search_base_type; |
|
614 symbol_c *return_data_type = (symbol_c *)f_decl->type_name->accept(search_base_type); |
|
615 symbol_c *param_data_type = default_variable_name.current_type; |
|
616 if (NULL == return_data_type) ERROR; |
|
617 |
|
618 default_variable_name.current_type = return_data_type; |
|
619 this->default_variable_name.accept(*this); |
|
620 default_variable_name.current_type = param_data_type; |
|
621 s4o.print(" = "); |
|
622 |
|
623 symbol->function_name->accept(*this); |
|
624 s4o.print("("); |
|
625 |
|
626 /* loop through each function parameter, find the value we should pass |
|
627 * to it, and then output the c equivalent... |
592 */ |
628 */ |
593 if (1 == i) |
629 |
594 param_value = &this->default_variable_name; |
630 function_param_iterator_c fp_iterator(f_decl); |
595 |
631 identifier_c *param_name; |
596 /* Get the value from a foo(<param_name> = <param_value>) style call */ |
632 function_call_param_iterator_c function_call_param_iterator(symbol); |
597 /* NOTE: the following line of code is not required in this case, but it doesn't |
633 for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) { |
598 * harm to leave it in, as in the case of a non-formal syntax function call, |
634 if (i != 1) |
599 * it will always return NULL. |
635 s4o.print(", "); |
600 * We leave it in in case we later decide to merge this part of the code together |
636 |
601 * with the function calling code in generate_cc_st_c, which does require |
637 symbol_c *param_type = fp_iterator.param_type(); |
602 * the following line... |
638 if (param_type == NULL) ERROR; |
603 */ |
639 |
604 if (param_value == NULL) |
640 function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction(); |
605 param_value = function_call_param_iterator.search(param_name); |
641 |
606 |
642 |
607 /* Get the value from a foo(<param_value>) style call */ |
643 symbol_c *param_value = NULL; |
608 if (param_value == NULL) |
644 |
609 param_value = function_call_param_iterator.next(); |
645 /* if it is the first parameter, semantics specifies that we should |
610 |
646 * get the value off the IL default variable! |
611 switch (param_direction) { |
647 */ |
612 case function_param_iterator_c::direction_in: |
648 if (1 == i) |
613 if (param_value == NULL) { |
649 param_value = &this->default_variable_name; |
614 /* No value given for parameter, so we must use the default... */ |
650 |
615 /* First check whether default value specified in function declaration...*/ |
651 /* Get the value from a foo(<param_name> = <param_value>) style call */ |
616 param_value = fp_iterator.default_value(); |
652 /* NOTE: the following line of code is not required in this case, but it doesn't |
617 } |
653 * harm to leave it in, as in the case of a non-formal syntax function call, |
618 if (param_value == NULL) { |
654 * it will always return NULL. |
619 /* If not, get the default value of this variable's type */ |
655 * We leave it in in case we later decide to merge this part of the code together |
620 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
656 * with the function calling code in generate_cc_st_c, which does require |
621 } |
657 * the following line... |
622 if (param_value == NULL) ERROR; |
658 */ |
623 param_value->accept(*this); |
659 if (param_value == NULL) |
624 break; |
660 param_value = function_call_param_iterator.search(param_name); |
625 case function_param_iterator_c::direction_out: |
661 |
626 case function_param_iterator_c::direction_inout: |
662 /* Get the value from a foo(<param_value>) style call */ |
627 if (param_value == NULL) { |
663 if (param_value == NULL) |
628 /* no parameter value given, so we pass a previously declared temporary variable. */ |
664 param_value = function_call_param_iterator.next(); |
629 std::string *temp_var_name = temp_var_name_factory.new_name(); |
665 |
630 s4o.print(*temp_var_name); |
666 switch (param_direction) { |
631 delete temp_var_name; |
667 case function_param_iterator_c::direction_in: |
632 } else { |
668 if (param_value == NULL) { |
|
669 /* No value given for parameter, so we must use the default... */ |
|
670 /* First check whether default value specified in function declaration...*/ |
|
671 param_value = fp_iterator.default_value(); |
|
672 } |
|
673 if (param_value == NULL) { |
|
674 /* If not, get the default value of this variable's type */ |
|
675 param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance()); |
|
676 } |
|
677 if (param_value == NULL) ERROR; |
633 param_value->accept(*this); |
678 param_value->accept(*this); |
634 } |
679 break; |
635 break; |
680 case function_param_iterator_c::direction_out: |
636 case function_param_iterator_c::direction_extref: |
681 case function_param_iterator_c::direction_inout: |
637 /* TODO! */ |
682 if (param_value == NULL) { |
638 ERROR; |
683 /* no parameter value given, so we pass a previously declared temporary variable. */ |
639 break; |
684 std::string *temp_var_name = temp_var_name_factory.new_name(); |
640 } /* switch */ |
685 s4o.print(*temp_var_name); |
641 } /* for(...) */ |
686 delete temp_var_name; |
642 |
687 } else { |
643 s4o.print(")"); |
688 param_value->accept(*this); |
644 |
689 } |
645 /* the data type returned by the function, and stored in the il default variable... */ |
690 break; |
646 default_variable_name.current_type = return_data_type; |
691 case function_param_iterator_c::direction_extref: |
647 |
692 /* TODO! */ |
|
693 ERROR; |
|
694 break; |
|
695 } /* switch */ |
|
696 } /* for(...) */ |
|
697 |
|
698 s4o.print(")"); |
|
699 /* the data type returned by the function, and stored in the il default variable... */ |
|
700 default_variable_name.current_type = return_data_type; |
|
701 } |
|
702 |
648 return NULL; |
703 return NULL; |
649 } |
704 } |
650 |
705 |
651 |
706 |
652 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
707 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
1078 void *visit(PV_operator_c *symbol) {return XXX_CAL_operator("PV", this->current_operand);} |
1133 void *visit(PV_operator_c *symbol) {return XXX_CAL_operator("PV", this->current_operand);} |
1079 void *visit(IN_operator_c *symbol) {return XXX_CAL_operator("IN", this->current_operand);} |
1134 void *visit(IN_operator_c *symbol) {return XXX_CAL_operator("IN", this->current_operand);} |
1080 void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} |
1135 void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} |
1081 |
1136 |
1082 void *visit(AND_operator_c *symbol) { |
1137 void *visit(AND_operator_c *symbol) { |
1083 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1138 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1084 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1139 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1085 XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); |
1140 XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); |
1086 /* the data type resulting from this operation... */ |
1141 /* the data type resulting from this operation... */ |
1087 this->default_variable_name.current_type = this->current_operand_type; |
1142 this->default_variable_name.current_type = this->current_operand_type; |
1088 } |
1143 } |
1089 else {ERROR;} |
1144 else {ERROR;} |
1090 return NULL; |
1145 return NULL; |
1091 } |
1146 } |
1092 |
1147 |
1093 void *visit(OR_operator_c *symbol) { |
1148 void *visit(OR_operator_c *symbol) { |
1094 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1149 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1095 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1150 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1096 XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); |
1151 XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); |
1097 /* the data type resulting from this operation... */ |
1152 /* the data type resulting from this operation... */ |
1098 this->default_variable_name.current_type = this->current_operand_type; |
1153 this->default_variable_name.current_type = this->current_operand_type; |
1099 } |
1154 } |
1100 else {ERROR;} |
1155 else {ERROR;} |
1101 return NULL; |
1156 return NULL; |
1102 } |
1157 } |
1103 |
1158 |
1104 void *visit(XOR_operator_c *symbol) { |
1159 void *visit(XOR_operator_c *symbol) { |
1105 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1160 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1106 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1161 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1107 // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! |
1162 // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! |
1108 XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); |
1163 XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); |
1109 /* the data type resulting from this operation... */ |
1164 /* the data type resulting from this operation... */ |
1110 this->default_variable_name.current_type = this->current_operand_type; |
1165 this->default_variable_name.current_type = this->current_operand_type; |
1111 } |
1166 } |
1112 else {ERROR;} |
1167 else {ERROR;} |
1113 return NULL; |
1168 return NULL; |
1114 } |
1169 } |
1115 |
1170 |
1116 void *visit(ANDN_operator_c *symbol) { |
1171 void *visit(ANDN_operator_c *symbol) { |
1117 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1172 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
1118 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1173 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1119 XXX_operator(&(this->default_variable_name), |
1174 XXX_operator(&(this->default_variable_name), |
1120 search_expression_type->is_bool_type(this->current_operand_type)?" &= !":" &= ~", |
1175 search_expression_type->is_bool_type(this->current_operand_type)?" &= !":" &= ~", |
1121 this->current_operand); |
1176 this->current_operand); |
1122 /* the data type resulting from this operation... */ |
1177 /* the data type resulting from this operation... */ |
1123 this->default_variable_name.current_type = this->current_operand_type; |
1178 this->default_variable_name.current_type = this->current_operand_type; |
1152 else {ERROR;} |
1207 else {ERROR;} |
1153 return NULL; |
1208 return NULL; |
1154 } |
1209 } |
1155 |
1210 |
1156 void *visit(ADD_operator_c *symbol) { |
1211 void *visit(ADD_operator_c *symbol) { |
1157 if (search_expression_type->is_time_compatible(this->default_variable_name.current_type) && |
1212 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
1158 search_expression_type->is_time_compatible(this->current_operand_type)) { |
1213 search_expression_type->is_time_type(this->current_operand_type)) { |
1159 XXX_function("__add_timespec", &(this->default_variable_name), this->current_operand); |
1214 XXX_function("__add_timespec", &(this->default_variable_name), this->current_operand); |
1160 /* the data type resulting from this operation... */ |
1215 /* the data type resulting from this operation... */ |
1161 this->default_variable_name.current_type = this->current_operand_type; |
1216 this->default_variable_name.current_type = this->current_operand_type; |
1162 return NULL; |
1217 return NULL; |
1163 } |
1218 } |
1164 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1219 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1165 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1220 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1166 XXX_operator(&(this->default_variable_name), " += ", this->current_operand); |
1221 XXX_operator(&(this->default_variable_name), " += ", this->current_operand); |
1167 /* the data type resulting from this operation... */ |
1222 /* the data type resulting from this operation... */ |
1168 this->default_variable_name.current_type = this->current_operand_type; |
1223 this->default_variable_name.current_type = this->current_operand_type; |
1169 return NULL; |
1224 return NULL; |
1170 } |
1225 } |
1171 ERROR; |
1226 ERROR; |
1172 return NULL; |
1227 return NULL; |
1173 } |
1228 } |
1174 |
1229 |
1175 void *visit(SUB_operator_c *symbol) { |
1230 void *visit(SUB_operator_c *symbol) { |
1176 if (search_expression_type->is_time_compatible(this->default_variable_name.current_type) && |
1231 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
1177 search_expression_type->is_time_compatible(this->current_operand_type)) { |
1232 search_expression_type->is_time_type(this->current_operand_type)) { |
1178 XXX_function("__sub_timespec", &(this->default_variable_name), this->current_operand); |
1233 XXX_function("__sub_timespec", &(this->default_variable_name), this->current_operand); |
1179 /* the data type resulting from this operation... */ |
1234 /* the data type resulting from this operation... */ |
1180 this->default_variable_name.current_type = this->current_operand_type; |
1235 this->default_variable_name.current_type = this->current_operand_type; |
1181 return NULL; |
1236 return NULL; |
1182 } |
1237 } |
1183 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1238 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1184 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1239 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1185 XXX_operator(&(this->default_variable_name), " -= ", this->current_operand); |
1240 XXX_operator(&(this->default_variable_name), " -= ", this->current_operand); |
1186 /* the data type resulting from this operation... */ |
1241 /* the data type resulting from this operation... */ |
1187 this->default_variable_name.current_type = this->current_operand_type; |
1242 this->default_variable_name.current_type = this->current_operand_type; |
1188 return NULL; |
1243 return NULL; |
1189 } |
1244 } |
1190 ERROR; |
1245 ERROR; |
1191 return NULL; |
1246 return NULL; |
1192 } |
1247 } |
1193 |
1248 |
1194 void *visit(MUL_operator_c *symbol) { |
1249 void *visit(MUL_operator_c *symbol) { |
1195 if (search_expression_type->is_time_compatible(this->default_variable_name.current_type) && |
1250 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
1196 search_expression_type->is_time_compatible(this->current_operand_type)) { |
1251 search_expression_type->is_integer_type(this->current_operand_type)) { |
1197 XXX_function("__mul_timespec", &(this->default_variable_name), this->current_operand); |
1252 XXX_function("__mul_timespec", &(this->default_variable_name), this->current_operand); |
1198 /* the data type resulting from this operation... */ |
1253 /* the data type resulting from this operation... */ |
1199 this->default_variable_name.current_type = this->current_operand_type; |
1254 this->default_variable_name.current_type = this->current_operand_type; |
1200 return NULL; |
1255 return NULL; |
1201 } |
1256 } |
1202 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1257 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1203 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1258 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1204 XXX_operator(&(this->default_variable_name), " *= ", this->current_operand); |
1259 XXX_operator(&(this->default_variable_name), " *= ", this->current_operand); |
1205 /* the data type resulting from this operation... */ |
1260 /* the data type resulting from this operation... */ |
1206 this->default_variable_name.current_type = this->current_operand_type; |
1261 this->default_variable_name.current_type = this->current_operand_type; |
1207 return NULL; |
1262 return NULL; |
1208 } |
1263 } |
1209 ERROR; |
1264 ERROR; |
1210 return NULL; |
1265 return NULL; |
1211 } |
1266 } |
1212 |
1267 |
1213 void *visit(DIV_operator_c *symbol) { |
1268 void *visit(DIV_operator_c *symbol) { |
1214 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1269 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1215 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1270 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1216 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
1271 XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); |
1217 /* the data type resulting from this operation... */ |
1272 /* the data type resulting from this operation... */ |
1218 this->default_variable_name.current_type = this->current_operand_type; |
1273 this->default_variable_name.current_type = this->current_operand_type; |
1219 } |
1274 } |
1220 else {ERROR;} |
1275 else {ERROR;} |
1221 return NULL; |
1276 return NULL; |
1222 } |
1277 } |
1223 |
1278 |
1224 void *visit(MOD_operator_c *symbol) { |
1279 void *visit(MOD_operator_c *symbol) { |
1225 if (search_expression_type->is_numeric_compatible(this->default_variable_name.current_type) && |
1280 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
1226 search_expression_type->is_numeric_compatible(this->current_operand_type)) { |
1281 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
1227 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
1282 XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); |
1228 /* the data type resulting from this operation... */ |
1283 /* the data type resulting from this operation... */ |
1229 this->default_variable_name.current_type = this->current_operand_type; |
1284 this->default_variable_name.current_type = this->current_operand_type; |
1230 } |
1285 } |
1231 else {ERROR;} |
1286 else {ERROR;} |