stage3/narrow_candidate_datatypes.cc
changeset 481 16f943328696
parent 480 8a58d7b8b26c
child 483 7f839fb100c1
equal deleted inserted replaced
480:8a58d7b8b26c 481:16f943328696
   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 
   913 
   914 void *narrow_candidate_datatypes_c::visit( AND_operator_c *symbol)  {return handle_il_instruction(symbol);}
   914 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 handle_il_instruction(symbol);}
   915 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 handle_il_instruction(symbol);}
   916 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 handle_il_instruction(symbol);}
   917 void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol)  {return handle_il_instruction(symbol);}
   918 void *narrow_candidate_datatypes_c::visit( ORN_operator_c *symbol)  {return handle_il_instruction(symbol);}
   918 void *narrow_candidate_datatypes_c::visit( ORN_operator_c *symbol)  {return handle_il_instruction(symbol);}
   919 void *narrow_candidate_datatypes_c::visit(XORN_operator_c *symbol)  {return handle_il_instruction(symbol);}
   919 void *narrow_candidate_datatypes_c::visit(XORN_operator_c *symbol)  {return handle_il_instruction(symbol);}
   920 void *narrow_candidate_datatypes_c::visit( ADD_operator_c *symbol)  {return narrow_binary_operator(widen_ADD_table, symbol, &(symbol->deprecated_operation));}
   920 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));}
   921 void *narrow_candidate_datatypes_c::visit( SUB_operator_c *symbol)  {return narrow_binary_operator(widen_SUB_table, symbol, &(symbol->deprecated_operation));}
  1034 	r_expr->accept(*this);
  1034 	r_expr->accept(*this);
  1035 	return NULL;
  1035 	return NULL;
  1036 }
  1036 }
  1037 
  1037 
  1038 
  1038 
  1039 void *narrow_candidate_datatypes_c::visit(or_expression_c *symbol) {
  1039 
  1040 	symbol_c * selected_type = NULL;
  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);}
  1041 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
  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);}
  1042 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
  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);}
  1043 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])) {
       
  1044 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1045 				break;
       
  1046 			}
       
  1047 		}
       
  1048 	}
       
  1049 
       
  1050 	if (NULL != selected_type) {
       
  1051 		symbol->l_exp->datatype = selected_type;
       
  1052 		symbol->l_exp->accept(*this);
       
  1053 		symbol->r_exp->datatype = selected_type;
       
  1054 		symbol->r_exp->accept(*this);
       
  1055 	}
       
  1056 	else
       
  1057 		ERROR;
       
  1058 	return NULL;
       
  1059 }
       
  1060 
       
  1061 
       
  1062 void *narrow_candidate_datatypes_c::visit(xor_expression_c *symbol) {
       
  1063 	symbol_c * selected_type = NULL;
       
  1064 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1065 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1066 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])) {
       
  1067 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1068 				break;
       
  1069 			}
       
  1070 		}
       
  1071 	}
       
  1072 
       
  1073 	if (NULL != selected_type) {
       
  1074 		symbol->l_exp->datatype = selected_type;
       
  1075 		symbol->l_exp->accept(*this);
       
  1076 		symbol->r_exp->datatype = selected_type;
       
  1077 		symbol->r_exp->accept(*this);
       
  1078 	}
       
  1079 	else
       
  1080 		ERROR;
       
  1081 	return NULL;
       
  1082 }
       
  1083 
       
  1084 
       
  1085 void *narrow_candidate_datatypes_c::visit(and_expression_c *symbol) {
       
  1086 	symbol_c * selected_type = NULL;
       
  1087 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1088 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1089 			if (typeid(*symbol->l_exp->candidate_datatypes[i]) == typeid(*symbol->r_exp->candidate_datatypes[j])) {
       
  1090 				selected_type = symbol->l_exp->candidate_datatypes[i];
       
  1091 				break;
       
  1092 			}
       
  1093 		}
       
  1094 	}
       
  1095 
       
  1096 	if (NULL != selected_type) {
       
  1097 		symbol->l_exp->datatype = selected_type;
       
  1098 		symbol->l_exp->accept(*this);
       
  1099 		symbol->r_exp->datatype = selected_type;
       
  1100 		symbol->r_exp->accept(*this);
       
  1101 	}
       
  1102 	else
       
  1103 		ERROR;
       
  1104 	return NULL;
       
  1105 }
       
  1106 
  1043 
  1107 
  1044 
  1108 void *narrow_candidate_datatypes_c::visit(equ_expression_c *symbol) {
  1045 void *narrow_candidate_datatypes_c::visit(equ_expression_c *symbol) {
  1109 	/* Here symbol->datatype has already assigned to BOOL
  1046 	/* Here symbol->datatype has already assigned to BOOL
  1110 	 * In conditional symbols like =, <>, =<, <, >, >= we have to set
  1047 	 * In conditional symbols like =, <>, =<, <, >, >= we have to set