stage3/fill_candidate_datatypes.cc
changeset 490 29f6ab0bf954
parent 489 2c874cccbb44
child 502 a6211f73690b
equal deleted inserted replaced
489:2c874cccbb44 490:29f6ab0bf954
  1169  * details (e.g. how to round and truncate numbers) as defined in IEC 61131-3, we will leave this to the future.
  1169  * details (e.g. how to round and truncate numbers) as defined in IEC 61131-3, we will leave this to the future.
  1170  * Also, the question will arise if we should also replace calls to standard
  1170  * Also, the question will arise if we should also replace calls to standard
  1171  * functions if the input parameters are all literals (e.g. ADD(42, 42)). This
  1171  * functions if the input parameters are all literals (e.g. ADD(42, 42)). This
  1172  * means this class will be more difficult than it appears at first.
  1172  * means this class will be more difficult than it appears at first.
  1173  */
  1173  */
  1174 void *fill_candidate_datatypes_c::visit(add_expression_c *symbol) {return handle_binary_expression(widen_ADD_table, symbol, symbol->l_exp, symbol->r_exp);}
  1174 void *fill_candidate_datatypes_c::visit(  add_expression_c *symbol) {return handle_binary_expression(widen_ADD_table,  symbol, symbol->l_exp, symbol->r_exp);}
  1175 void *fill_candidate_datatypes_c::visit(sub_expression_c *symbol) {return handle_binary_expression(widen_SUB_table, symbol, symbol->l_exp, symbol->r_exp);}
  1175 void *fill_candidate_datatypes_c::visit(  sub_expression_c *symbol) {return handle_binary_expression(widen_SUB_table,  symbol, symbol->l_exp, symbol->r_exp);}
  1176 void *fill_candidate_datatypes_c::visit(mul_expression_c *symbol) {return handle_binary_expression(widen_MUL_table, symbol, symbol->l_exp, symbol->r_exp);}
  1176 void *fill_candidate_datatypes_c::visit(  mul_expression_c *symbol) {return handle_binary_expression(widen_MUL_table,  symbol, symbol->l_exp, symbol->r_exp);}
  1177 void *fill_candidate_datatypes_c::visit(div_expression_c *symbol) {return handle_binary_expression(widen_DIV_table, symbol, symbol->l_exp, symbol->r_exp);}
  1177 void *fill_candidate_datatypes_c::visit(  div_expression_c *symbol) {return handle_binary_expression(widen_DIV_table,  symbol, symbol->l_exp, symbol->r_exp);}
  1178 void *fill_candidate_datatypes_c::visit(mod_expression_c *symbol) {return handle_binary_expression(widen_MOD_table, symbol, symbol->l_exp, symbol->r_exp);}
  1178 void *fill_candidate_datatypes_c::visit(  mod_expression_c *symbol) {return handle_binary_expression(widen_MOD_table,  symbol, symbol->l_exp, symbol->r_exp);}
  1179 
  1179 void *fill_candidate_datatypes_c::visit(power_expression_c *symbol) {return handle_binary_expression(widen_EXPT_table, symbol, symbol->l_exp, symbol->r_exp);}
  1180 
       
  1181 void *fill_candidate_datatypes_c::visit(power_expression_c *symbol) {
       
  1182 	symbol_c *left_type, *right_type;
       
  1183 	bool check_ok;
       
  1184 
       
  1185 	symbol->l_exp->accept(*this);
       
  1186 	symbol->r_exp->accept(*this);
       
  1187 	check_ok = false;
       
  1188 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1189 		left_type = symbol->l_exp->candidate_datatypes[i];
       
  1190 		if (is_ANY_REAL_compatible(left_type)) {
       
  1191 			check_ok = true;
       
  1192 			break;
       
  1193 		}
       
  1194 	}
       
  1195 	if (! check_ok) return NULL;
       
  1196 	check_ok = false;
       
  1197 	for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1198 		right_type = symbol->r_exp->candidate_datatypes[j];
       
  1199 		if (is_ANY_NUM_compatible(right_type)) {
       
  1200 			check_ok = true;
       
  1201 			break;
       
  1202 		}
       
  1203 	}
       
  1204 	if (! check_ok) return NULL;
       
  1205 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1206 		add_datatype_to_candidate_list(symbol, symbol->l_exp->candidate_datatypes[i]);
       
  1207 	}
       
  1208 	if (debug) std::cout << "** [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1209 	return NULL;
       
  1210 }
       
  1211 
  1180 
  1212 
  1181 
  1213 void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) {
  1182 void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) {
  1214   /* NOTE: The standard defines the syntax for this 'negation' operation, but
  1183   /* NOTE: The standard defines the syntax for this 'negation' operation, but
  1215    *       does not define the its semantics.
  1184    *       does not define the its semantics.