116 generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
114 generate_c_inlinefcall_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
117 : generate_c_typedecl_c(s4o_ptr), |
115 : generate_c_typedecl_c(s4o_ptr), |
118 default_variable_name(IL_DEFVAR, NULL), |
116 default_variable_name(IL_DEFVAR, NULL), |
119 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
117 default_variable_back_name(IL_DEFVAR_BACK, NULL) |
120 { |
118 { |
121 search_expression_type = new search_expression_type_c(scope); |
|
122 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
119 search_varfb_instance_type = new search_varfb_instance_type_c(scope); |
123 search_var_instance_decl = new search_var_instance_decl_c(scope); |
120 search_var_instance_decl = new search_var_instance_decl_c (scope); |
124 |
121 |
125 this->set_variable_prefix(variable_prefix); |
122 this->set_variable_prefix(variable_prefix); |
126 current_operand = NULL; |
123 current_operand = NULL; |
127 current_operand_type = NULL; |
124 current_operand_type = NULL; |
128 il_default_variable_init_value = NULL; |
125 il_default_variable_init_value = NULL; |
269 |
265 |
270 generating_inlinefunction = false; |
266 generating_inlinefunction = false; |
271 } |
267 } |
272 |
268 |
273 private: |
269 private: |
|
270 /* a small helper function */ |
|
271 symbol_c *default_literal_type(symbol_c *symbol) { |
|
272 if (get_datatype_info_c::is_ANY_INT_literal(symbol)) { |
|
273 return &search_constant_type_c::lint_type_name; |
|
274 } |
|
275 else if (get_datatype_info_c::is_ANY_REAL_literal(symbol)) { |
|
276 return &search_constant_type_c::lreal_type_name; |
|
277 } |
|
278 return symbol; |
|
279 } |
274 |
280 |
275 /* A helper function... */ |
281 /* A helper function... */ |
276 void CMP_operator_result_type() { |
282 void CMP_operator_result_type() { |
277 /* the data type resulting from this operation... */ |
283 /* the data type resulting from this operation... */ |
278 this->default_variable_name.current_type = &(this->bool_type); |
284 this->default_variable_name.current_type = &(this->bool_type); |
279 } |
285 } |
280 |
286 |
281 /* A helper function... */ |
287 /* A helper function... */ |
282 void BYTE_operator_result_type(void) { |
288 void BYTE_operator_result_type(void) { |
283 if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
289 if (get_datatype_info_c::is_ANY_INT_literal(this->default_variable_name.current_type)) { |
284 if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
290 if (get_datatype_info_c::is_ANY_INT_literal(this->current_operand_type)) |
285 this->default_variable_name.current_type = &(this->lword_type); |
291 this->default_variable_name.current_type = &(this->lword_type); |
286 else |
292 else |
287 this->default_variable_name.current_type = this->current_operand_type; |
293 this->default_variable_name.current_type = this->current_operand_type; |
288 } |
294 } |
289 else if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
295 else if (get_datatype_info_c::is_ANY_INT_literal(this->current_operand_type)) |
290 this->current_operand_type = this->default_variable_name.current_type; |
296 this->current_operand_type = this->default_variable_name.current_type; |
291 } |
297 } |
292 |
298 |
293 /* A helper function... */ |
299 /* A helper function... */ |
294 void NUM_operator_result_type(void) { |
300 void NUM_operator_result_type(void) { |
295 if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) { |
301 if (get_datatype_info_c::is_ANY_REAL_literal(this->default_variable_name.current_type)) { |
296 if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
302 if (get_datatype_info_c::is_ANY_INT_literal(this->current_operand_type) || |
297 search_expression_type->is_literal_real_type(this->current_operand_type)) |
303 get_datatype_info_c::is_ANY_REAL_literal(this->current_operand_type)) |
298 this->default_variable_name.current_type = &(this->lreal_type); |
304 this->default_variable_name.current_type = &(this->lreal_type); |
299 else |
305 else |
300 this->default_variable_name.current_type = this->current_operand_type; |
306 this->default_variable_name.current_type = this->current_operand_type; |
301 } |
307 } |
302 else if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) { |
308 else if (get_datatype_info_c::is_ANY_INT_literal(this->default_variable_name.current_type)) { |
303 if (search_expression_type->is_literal_integer_type(this->current_operand_type)) |
309 if (get_datatype_info_c::is_ANY_INT_literal(this->current_operand_type)) |
304 this->default_variable_name.current_type = &(this->lint_type); |
310 this->default_variable_name.current_type = &(this->lint_type); |
305 else if (search_expression_type->is_literal_real_type(this->current_operand_type)) |
311 else if (get_datatype_info_c::is_ANY_REAL_literal(this->current_operand_type)) |
306 this->default_variable_name.current_type = &(this->lreal_type); |
312 this->default_variable_name.current_type = &(this->lreal_type); |
307 else |
313 else |
308 this->default_variable_name.current_type = this->current_operand_type; |
314 this->default_variable_name.current_type = this->current_operand_type; |
309 } |
315 } |
310 else if (search_expression_type->is_literal_integer_type(this->current_operand_type) || |
316 else if (get_datatype_info_c::is_ANY_INT_literal(this->current_operand_type) || |
311 search_expression_type->is_literal_real_type(this->current_operand_type)) |
317 get_datatype_info_c::is_ANY_REAL_literal(this->current_operand_type)) |
312 this->current_operand_type = this->default_variable_name.current_type; |
318 this->current_operand_type = this->default_variable_name.current_type; |
313 } |
319 } |
314 |
320 |
315 void *print_getter(symbol_c *symbol) { |
321 void *print_getter(symbol_c *symbol) { |
316 unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
322 unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
854 this->default_variable_name.current_type = this->current_operand_type; |
860 this->default_variable_name.current_type = this->current_operand_type; |
855 return NULL; |
861 return NULL; |
856 } |
862 } |
857 |
863 |
858 void *visit(AND_operator_c *symbol) { |
864 void *visit(AND_operator_c *symbol) { |
859 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
865 if (get_datatype_info_c::is_ANY_BIT_compatible(this->default_variable_name.current_type)) { |
860 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
861 BYTE_operator_result_type(); |
866 BYTE_operator_result_type(); |
862 } |
867 } |
863 else {ERROR;} |
868 else {ERROR;} |
864 return NULL; |
869 return NULL; |
865 } |
870 } |
866 |
871 |
867 void *visit(OR_operator_c *symbol) { |
872 void *visit(OR_operator_c *symbol) { |
868 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
873 if (get_datatype_info_c::is_ANY_BIT_compatible(this->default_variable_name.current_type)) { |
869 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
870 BYTE_operator_result_type(); |
874 BYTE_operator_result_type(); |
871 } |
875 } |
872 else {ERROR;} |
876 else {ERROR;} |
873 return NULL; |
877 return NULL; |
874 } |
878 } |
875 |
879 |
876 void *visit(XOR_operator_c *symbol) { |
880 void *visit(XOR_operator_c *symbol) { |
877 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
881 if (get_datatype_info_c::is_ANY_BIT_compatible(this->default_variable_name.current_type)) { |
878 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
879 BYTE_operator_result_type(); |
882 BYTE_operator_result_type(); |
880 } |
883 } |
881 else {ERROR;} |
884 else {ERROR;} |
882 return NULL; |
885 return NULL; |
883 } |
886 } |
884 |
887 |
885 void *visit(ANDN_operator_c *symbol) { |
888 void *visit(ANDN_operator_c *symbol) { |
886 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
889 if (get_datatype_info_c::is_ANY_BIT_compatible(this->default_variable_name.current_type)) { |
887 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
888 BYTE_operator_result_type(); |
890 BYTE_operator_result_type(); |
889 } |
891 } |
890 else {ERROR;} |
892 else {ERROR;} |
891 return NULL; |
893 return NULL; |
892 } |
894 } |
893 |
895 |
894 void *visit(ORN_operator_c *symbol) { |
896 void *visit(ORN_operator_c *symbol) { |
895 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
897 if (get_datatype_info_c::is_ANY_BIT_compatible(this->default_variable_name.current_type)) { |
896 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
897 BYTE_operator_result_type(); |
898 BYTE_operator_result_type(); |
898 } |
899 } |
899 else {ERROR;} |
900 else {ERROR;} |
900 return NULL; |
901 return NULL; |
901 } |
902 } |
902 |
903 |
903 void *visit(XORN_operator_c *symbol) { |
904 void *visit(XORN_operator_c *symbol) { |
904 if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && |
905 if (get_datatype_info_c::is_ANY_BIT_compatible(this->default_variable_name.current_type)) { |
905 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
906 BYTE_operator_result_type(); |
906 BYTE_operator_result_type(); |
907 } |
907 } |
908 else {ERROR;} |
908 else {ERROR;} |
909 return NULL; |
909 return NULL; |
910 } |
910 } |
911 |
911 |
912 void *visit(ADD_operator_c *symbol) { |
912 void *visit(ADD_operator_c *symbol) { |
913 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
913 if (get_datatype_info_c::is_TIME_compatible (symbol->datatype) || |
914 search_expression_type->is_time_type(this->current_operand_type)) { |
914 get_datatype_info_c::is_ANY_DATE_compatible (symbol->datatype)) { |
915 /* the data type resulting from this operation... */ |
915 /* the data type resulting from this operation... */ |
916 this->default_variable_name.current_type = this->current_operand_type; |
916 this->default_variable_name.current_type = this->current_operand_type; |
917 } |
917 } else { |
918 else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
|
919 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
920 NUM_operator_result_type(); |
918 NUM_operator_result_type(); |
921 } |
919 } |
922 else {ERROR;} |
|
923 return NULL; |
920 return NULL; |
924 } |
921 } |
925 |
922 |
926 void *visit(SUB_operator_c *symbol) { |
923 void *visit(SUB_operator_c *symbol) { |
927 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
924 if (get_datatype_info_c::is_TIME_compatible (symbol->datatype) || |
928 search_expression_type->is_time_type(this->current_operand_type)) { |
925 get_datatype_info_c::is_ANY_DATE_compatible (symbol->datatype)) { |
929 /* the data type resulting from this operation... */ |
926 /* the data type resulting from this operation... */ |
930 this->default_variable_name.current_type = this->current_operand_type; |
927 this->default_variable_name.current_type = this->current_operand_type; |
931 } |
928 } else { |
932 else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
929 NUM_operator_result_type(); |
933 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
930 } |
934 NUM_operator_result_type(); |
|
935 } |
|
936 else {ERROR;} |
|
937 return NULL; |
931 return NULL; |
938 } |
932 } |
939 |
933 |
940 void *visit(MUL_operator_c *symbol) { |
934 void *visit(MUL_operator_c *symbol) { |
941 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
935 if (get_datatype_info_c::is_TIME_compatible (symbol->datatype)) { |
942 search_expression_type->is_integer_type(this->current_operand_type)) { |
|
943 /* the data type resulting from this operation is unchanged! */ |
936 /* the data type resulting from this operation is unchanged! */ |
944 } |
937 } else { |
945 else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
938 NUM_operator_result_type(); |
946 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
939 } |
947 NUM_operator_result_type(); |
|
948 } |
|
949 else {ERROR;} |
|
950 return NULL; |
940 return NULL; |
951 } |
941 } |
952 |
942 |
953 void *visit(DIV_operator_c *symbol) { |
943 void *visit(DIV_operator_c *symbol) { |
954 if (search_expression_type->is_time_type(this->default_variable_name.current_type) && |
944 if (get_datatype_info_c::is_TIME_compatible (symbol->datatype)) { |
955 search_expression_type->is_integer_type(this->current_operand_type)) { |
|
956 /* the data type resulting from this operation is unchanged! */ |
945 /* the data type resulting from this operation is unchanged! */ |
957 } |
946 } else { |
958 else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
|
959 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
960 NUM_operator_result_type(); |
947 NUM_operator_result_type(); |
961 } |
948 } |
962 else {ERROR;} |
|
963 return NULL; |
949 return NULL; |
964 } |
950 } |
965 |
951 |
966 void *visit(MOD_operator_c *symbol) { |
952 void *visit(MOD_operator_c *symbol) { |
967 if (search_expression_type->is_num_type(this->default_variable_name.current_type) && |
953 NUM_operator_result_type(); |
968 search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { |
|
969 NUM_operator_result_type(); |
|
970 } |
|
971 else {ERROR;} |
|
972 return NULL; |
954 return NULL; |
973 } |
955 } |
974 |
956 |
975 void *visit(GT_operator_c *symbol) {CMP_operator_result_type(); return NULL;} |
957 void *visit(GT_operator_c *symbol) {CMP_operator_result_type(); return NULL;} |
976 void *visit(GE_operator_c *symbol) {CMP_operator_result_type(); return NULL;} |
958 void *visit(GE_operator_c *symbol) {CMP_operator_result_type(); return NULL;} |