stage3/narrow_candidate_datatypes.cc
changeset 484 f78750994a82
parent 483 7f839fb100c1
child 487 1619b2fe03e1
equal deleted inserted replaced
483:7f839fb100c1 484:f78750994a82
   908 void *narrow_candidate_datatypes_c::visit(  CD_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CD",  symbol->called_fb_declaration);}
   908 void *narrow_candidate_datatypes_c::visit(  CD_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CD",  symbol->called_fb_declaration);}
   909 void *narrow_candidate_datatypes_c::visit(  PV_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PV",  symbol->called_fb_declaration);}
   909 void *narrow_candidate_datatypes_c::visit(  PV_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PV",  symbol->called_fb_declaration);}
   910 void *narrow_candidate_datatypes_c::visit(  IN_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "IN",  symbol->called_fb_declaration);}
   910 void *narrow_candidate_datatypes_c::visit(  IN_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "IN",  symbol->called_fb_declaration);}
   911 void *narrow_candidate_datatypes_c::visit(  PT_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PT",  symbol->called_fb_declaration);}
   911 void *narrow_candidate_datatypes_c::visit(  PT_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PT",  symbol->called_fb_declaration);}
   912 
   912 
   913 
       
   914 void *narrow_candidate_datatypes_c::visit( AND_operator_c *symbol)  {return narrow_binary_operator(widen_AND_table, symbol);}
   913 void *narrow_candidate_datatypes_c::visit( AND_operator_c *symbol)  {return narrow_binary_operator(widen_AND_table, symbol);}
   915 void *narrow_candidate_datatypes_c::visit(  OR_operator_c *symbol)  {return narrow_binary_operator( widen_OR_table, symbol);}
   914 void *narrow_candidate_datatypes_c::visit(  OR_operator_c *symbol)  {return narrow_binary_operator( widen_OR_table, symbol);}
   916 void *narrow_candidate_datatypes_c::visit( XOR_operator_c *symbol)  {return narrow_binary_operator(widen_XOR_table, symbol);}
   915 void *narrow_candidate_datatypes_c::visit( XOR_operator_c *symbol)  {return narrow_binary_operator(widen_XOR_table, symbol);}
   917 void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol)  {return narrow_binary_operator(widen_AND_table, symbol);}
   916 void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol)  {return narrow_binary_operator(widen_AND_table, symbol);}
   918 void *narrow_candidate_datatypes_c::visit( ORN_operator_c *symbol)  {return narrow_binary_operator( widen_OR_table, symbol);}
   917 void *narrow_candidate_datatypes_c::visit( ORN_operator_c *symbol)  {return narrow_binary_operator( widen_OR_table, symbol);}
   920 void *narrow_candidate_datatypes_c::visit( ADD_operator_c *symbol)  {return narrow_binary_operator(widen_ADD_table, symbol, &(symbol->deprecated_operation));}
   919 void *narrow_candidate_datatypes_c::visit( ADD_operator_c *symbol)  {return narrow_binary_operator(widen_ADD_table, symbol, &(symbol->deprecated_operation));}
   921 void *narrow_candidate_datatypes_c::visit( SUB_operator_c *symbol)  {return narrow_binary_operator(widen_SUB_table, symbol, &(symbol->deprecated_operation));}
   920 void *narrow_candidate_datatypes_c::visit( SUB_operator_c *symbol)  {return narrow_binary_operator(widen_SUB_table, symbol, &(symbol->deprecated_operation));}
   922 void *narrow_candidate_datatypes_c::visit( MUL_operator_c *symbol)  {return narrow_binary_operator(widen_MUL_table, symbol, &(symbol->deprecated_operation));}
   921 void *narrow_candidate_datatypes_c::visit( MUL_operator_c *symbol)  {return narrow_binary_operator(widen_MUL_table, symbol, &(symbol->deprecated_operation));}
   923 void *narrow_candidate_datatypes_c::visit( DIV_operator_c *symbol)  {return narrow_binary_operator(widen_DIV_table, symbol, &(symbol->deprecated_operation));}
   922 void *narrow_candidate_datatypes_c::visit( DIV_operator_c *symbol)  {return narrow_binary_operator(widen_DIV_table, symbol, &(symbol->deprecated_operation));}
   924 void *narrow_candidate_datatypes_c::visit( MOD_operator_c *symbol)  {return narrow_binary_operator(widen_MOD_table, symbol);}
   923 void *narrow_candidate_datatypes_c::visit( MOD_operator_c *symbol)  {return narrow_binary_operator(widen_MOD_table, symbol);}
   925 void *narrow_candidate_datatypes_c::visit(  GT_operator_c *symbol)  {return handle_il_instruction(symbol);}
   924 void *narrow_candidate_datatypes_c::visit(  GT_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
   926 void *narrow_candidate_datatypes_c::visit(  GE_operator_c *symbol)  {return handle_il_instruction(symbol);}
   925 void *narrow_candidate_datatypes_c::visit(  GE_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
   927 void *narrow_candidate_datatypes_c::visit(  EQ_operator_c *symbol)  {return handle_il_instruction(symbol);}
   926 void *narrow_candidate_datatypes_c::visit(  EQ_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
   928 void *narrow_candidate_datatypes_c::visit(  LT_operator_c *symbol)  {return handle_il_instruction(symbol);}
   927 void *narrow_candidate_datatypes_c::visit(  LT_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
   929 void *narrow_candidate_datatypes_c::visit(  LE_operator_c *symbol)  {return handle_il_instruction(symbol);}
   928 void *narrow_candidate_datatypes_c::visit(  LE_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
   930 void *narrow_candidate_datatypes_c::visit(  NE_operator_c *symbol)  {return handle_il_instruction(symbol);}
   929 void *narrow_candidate_datatypes_c::visit(  NE_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
   931 
   930 
   932 
   931 
   933 // SYM_REF0(CAL_operator_c)
   932 // SYM_REF0(CAL_operator_c)
   934 /* called from il_fb_call_c (symbol->il_call_operator->accpet(*this) ) */
   933 /* called from il_fb_call_c (symbol->il_call_operator->accpet(*this) ) */
   935 void *narrow_candidate_datatypes_c::visit(CAL_operator_c *symbol) {
   934 void *narrow_candidate_datatypes_c::visit(CAL_operator_c *symbol) {
  1035 	return NULL;
  1034 	return NULL;
  1036 }
  1035 }
  1037 
  1036 
  1038 
  1037 
  1039 
  1038 
  1040 void *narrow_candidate_datatypes_c::visit( or_expression_c *symbol) {return narrow_binary_expression( widen_OR_table, symbol, symbol->l_exp, symbol->r_exp);}
  1039 void *narrow_candidate_datatypes_c::visit(    or_expression_c *symbol) {return narrow_binary_expression( widen_OR_table, symbol, symbol->l_exp, symbol->r_exp);}
  1041 void *narrow_candidate_datatypes_c::visit(xor_expression_c *symbol) {return narrow_binary_expression(widen_XOR_table, symbol, symbol->l_exp, symbol->r_exp);}
  1040 void *narrow_candidate_datatypes_c::visit(   xor_expression_c *symbol) {return narrow_binary_expression(widen_XOR_table, symbol, symbol->l_exp, symbol->r_exp);}
  1042 void *narrow_candidate_datatypes_c::visit(and_expression_c *symbol) {return narrow_binary_expression(widen_AND_table, symbol, symbol->l_exp, symbol->r_exp);}
  1041 void *narrow_candidate_datatypes_c::visit(   and_expression_c *symbol) {return narrow_binary_expression(widen_AND_table, symbol, symbol->l_exp, symbol->r_exp);}
  1043 
  1042 
  1044 
  1043 void *narrow_candidate_datatypes_c::visit(   equ_expression_c *symbol) {return narrow_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
  1045 void *narrow_candidate_datatypes_c::visit(equ_expression_c *symbol) {
  1044 void *narrow_candidate_datatypes_c::visit(notequ_expression_c *symbol) {return narrow_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
  1046 	/* Here symbol->datatype has already assigned to BOOL
  1045 void *narrow_candidate_datatypes_c::visit(    lt_expression_c *symbol) {return narrow_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
  1047 	 * In conditional symbols like =, <>, =<, <, >, >= we have to set
  1046 void *narrow_candidate_datatypes_c::visit(    gt_expression_c *symbol) {return narrow_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
  1048 	 * l_exp and r_exp expression matched with compatible type.
  1047 void *narrow_candidate_datatypes_c::visit(    le_expression_c *symbol) {return narrow_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
  1049 	 * Example:
  1048 void *narrow_candidate_datatypes_c::visit(    ge_expression_c *symbol) {return narrow_binary_expression(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
  1050 	 * 		INT#14 = INT#81
  1049 
  1051 	 * 		equ_expression_c symbol->datatype = BOOL from top visit
  1050 void *narrow_candidate_datatypes_c::visit(   add_expression_c *symbol) {return narrow_binary_expression(widen_ADD_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
  1052 	 * 		symbol->l_exp->datatype => INT
  1051 void *narrow_candidate_datatypes_c::visit(   sub_expression_c *symbol) {return narrow_binary_expression(widen_SUB_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
  1053 	 * 		symbol->r_exp->datatype => INT
  1052 void *narrow_candidate_datatypes_c::visit(   mul_expression_c *symbol) {return narrow_binary_expression(widen_MUL_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
  1054 	 */
  1053 void *narrow_candidate_datatypes_c::visit(   div_expression_c *symbol) {return narrow_binary_expression(widen_DIV_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
  1055 	symbol_c * selected_type = NULL;
  1054 void *narrow_candidate_datatypes_c::visit(   mod_expression_c *symbol) {return narrow_binary_expression(widen_MOD_table, symbol, symbol->l_exp, symbol->r_exp);}
  1056 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1057 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1058 			if (typeid(*symbol->l_exp->candidate_datatypes[i]) == typeid(*symbol->r_exp->candidate_datatypes[j])) {
       
  1059 				/*
       
  1060 				 * We do not need to check whether the type is an ANY_ELEMENTARY here.
       
  1061 				 * That was already done in fill_candidate_datatypes_c.
       
  1062 				 */
       
  1063 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1064 				break;
       
  1065 			}
       
  1066 		}
       
  1067 	}
       
  1068 
       
  1069 	if (NULL != selected_type) {
       
  1070 		symbol->l_exp->datatype = selected_type;
       
  1071 		symbol->r_exp->datatype = selected_type;
       
  1072 	}
       
  1073 	else
       
  1074 		ERROR;
       
  1075 
       
  1076 	symbol->l_exp->accept(*this);
       
  1077 	symbol->r_exp->accept(*this);
       
  1078 	return NULL;
       
  1079 }
       
  1080 
       
  1081 void *narrow_candidate_datatypes_c::visit(notequ_expression_c *symbol)  {
       
  1082 	symbol_c * selected_type = NULL;
       
  1083 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1084 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1085 			if (typeid(*symbol->l_exp->candidate_datatypes[i]) == typeid(*symbol->r_exp->candidate_datatypes[j])) {
       
  1086 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1087 				break;
       
  1088 			}
       
  1089 		}
       
  1090 	}
       
  1091 
       
  1092 	if (NULL != selected_type) {
       
  1093 		symbol->l_exp->datatype = selected_type;
       
  1094 		symbol->l_exp->accept(*this);
       
  1095 		symbol->r_exp->datatype = selected_type;
       
  1096 		symbol->r_exp->accept(*this);
       
  1097 	}
       
  1098 	else
       
  1099 		ERROR;
       
  1100 	return NULL;
       
  1101 }
       
  1102 
       
  1103 
       
  1104 void *narrow_candidate_datatypes_c::visit(lt_expression_c *symbol) {
       
  1105 	symbol_c * selected_type = NULL;
       
  1106 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1107 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1108 			if (typeid(*symbol->l_exp->candidate_datatypes[i]) == typeid(*symbol->r_exp->candidate_datatypes[j])
       
  1109 					&& is_ANY_ELEMENTARY_type(symbol->l_exp->candidate_datatypes[i])) {
       
  1110 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1111 				break;
       
  1112 			}
       
  1113 		}
       
  1114 	}
       
  1115 
       
  1116 	if (NULL != selected_type) {
       
  1117 		symbol->l_exp->datatype = selected_type;
       
  1118 		symbol->l_exp->accept(*this);
       
  1119 		symbol->r_exp->datatype = selected_type;
       
  1120 		symbol->r_exp->accept(*this);
       
  1121 	}
       
  1122 	else
       
  1123 		ERROR;
       
  1124 	return NULL;
       
  1125 }
       
  1126 
       
  1127 
       
  1128 void *narrow_candidate_datatypes_c::visit(gt_expression_c *symbol) {
       
  1129 	symbol_c * selected_type = NULL;
       
  1130 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1131 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1132 			if (typeid(*symbol->l_exp->candidate_datatypes[i]) == typeid(*symbol->r_exp->candidate_datatypes[j])
       
  1133 					&& is_ANY_ELEMENTARY_type(symbol->l_exp->candidate_datatypes[i])) {
       
  1134 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1135 				break;
       
  1136 			}
       
  1137 		}
       
  1138 	}
       
  1139 
       
  1140 	if (NULL != selected_type) {
       
  1141 		symbol->l_exp->datatype = selected_type;
       
  1142 		symbol->l_exp->accept(*this);
       
  1143 		symbol->r_exp->datatype = selected_type;
       
  1144 		symbol->r_exp->accept(*this);
       
  1145 	}
       
  1146 	else
       
  1147 		ERROR;
       
  1148 	return NULL;
       
  1149 }
       
  1150 
       
  1151 
       
  1152 void *narrow_candidate_datatypes_c::visit(le_expression_c *symbol) {
       
  1153 	symbol_c * selected_type = NULL;
       
  1154 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1155 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1156 			if (typeid(*symbol->l_exp->candidate_datatypes[i]) == typeid(*symbol->r_exp->candidate_datatypes[j])
       
  1157 					&& is_ANY_ELEMENTARY_type(symbol->l_exp->candidate_datatypes[i])) {
       
  1158 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1159 				break;
       
  1160 			}
       
  1161 		}
       
  1162 	}
       
  1163 
       
  1164 	if (NULL != selected_type) {
       
  1165 		symbol->l_exp->datatype = selected_type;
       
  1166 		symbol->l_exp->accept(*this);
       
  1167 		symbol->r_exp->datatype = selected_type;
       
  1168 		symbol->r_exp->accept(*this);
       
  1169 	}
       
  1170 	else
       
  1171 		ERROR;
       
  1172 	return NULL;
       
  1173 }
       
  1174 
       
  1175 
       
  1176 void *narrow_candidate_datatypes_c::visit(ge_expression_c *symbol) {
       
  1177 	symbol_c * selected_type = NULL;
       
  1178 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1179 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1180 			if (typeid(*symbol->l_exp->candidate_datatypes[i]) == typeid(*symbol->r_exp->candidate_datatypes[j])
       
  1181 					&& is_ANY_ELEMENTARY_type(symbol->l_exp->candidate_datatypes[i])) {
       
  1182 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1183 				break;
       
  1184 			}
       
  1185 		}
       
  1186 	}
       
  1187 
       
  1188 	if (NULL != selected_type) {
       
  1189 		symbol->l_exp->datatype = selected_type;
       
  1190 		symbol->l_exp->accept(*this);
       
  1191 		symbol->r_exp->datatype = selected_type;
       
  1192 		symbol->r_exp->accept(*this);
       
  1193 	}
       
  1194 	else
       
  1195 		ERROR;
       
  1196 	return NULL;
       
  1197 }
       
  1198 
       
  1199 void *narrow_candidate_datatypes_c::visit(add_expression_c *symbol) {return narrow_binary_expression(widen_ADD_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
       
  1200 void *narrow_candidate_datatypes_c::visit(sub_expression_c *symbol) {return narrow_binary_expression(widen_SUB_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
       
  1201 void *narrow_candidate_datatypes_c::visit(mul_expression_c *symbol) {return narrow_binary_expression(widen_MUL_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
       
  1202 void *narrow_candidate_datatypes_c::visit(div_expression_c *symbol) {return narrow_binary_expression(widen_DIV_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
       
  1203 void *narrow_candidate_datatypes_c::visit(mod_expression_c *symbol) {return narrow_binary_expression(widen_MOD_table, symbol, symbol->l_exp, symbol->r_exp);}
       
  1204 
  1055 
  1205 
  1056 
  1206 
  1057 
  1207 
  1058 
  1208 void *narrow_candidate_datatypes_c::visit(power_expression_c *symbol) {
  1059 void *narrow_candidate_datatypes_c::visit(power_expression_c *symbol) {