Add check widening status for IL operator.
authorManuele Conti <conti.ma@alice.it>
Sun, 11 Mar 2012 22:21:47 +0100
changeset 476 38d85e9a0507
parent 475 28816126cf8d
child 477 c0c6ff7357b7
Add check widening status for IL operator.
Fix check widening status for ST expression.
absyntax/absyntax.def
stage3/fill_candidate_datatypes.cc
stage3/fill_candidate_datatypes.hh
stage3/print_datatypes_error.cc
stage3/print_datatypes_error.hh
--- a/absyntax/absyntax.def	Sun Mar 11 18:24:39 2012 +0000
+++ b/absyntax/absyntax.def	Sun Mar 11 22:21:47 2012 +0100
@@ -970,7 +970,8 @@
 /*******************/
 /* B 2.2 Operators */
 /*******************/
-/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
+/* NOTE: The parameter 'called_fb_declaration' is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
+/* NOTE: The parameter 'deprecated_operation' is used to pass information to print_datatypes_error from fill_candidate class about operation status */ 
 SYM_REF0(LD_operator_c)
 SYM_REF0(LDN_operator_c)
 SYM_REF0(ST_operator_c)
@@ -992,10 +993,10 @@
 SYM_REF0(ANDN_operator_c)
 SYM_REF0(ORN_operator_c)
 SYM_REF0(XORN_operator_c)
-SYM_REF0(ADD_operator_c)
-SYM_REF0(SUB_operator_c)
-SYM_REF0(MUL_operator_c)
-SYM_REF0(DIV_operator_c)
+SYM_REF0(ADD_operator_c, bool deprecated_operation;)
+SYM_REF0(SUB_operator_c, bool deprecated_operation;)
+SYM_REF0(MUL_operator_c, bool deprecated_operation;)
+SYM_REF0(DIV_operator_c, bool deprecated_operation;)
 SYM_REF0(MOD_operator_c)
 SYM_REF0(GT_operator_c)
 SYM_REF0(GE_operator_c)
@@ -1036,10 +1037,10 @@
 SYM_REF2(gt_expression_c, l_exp, r_exp)
 SYM_REF2(le_expression_c, l_exp, r_exp)
 SYM_REF2(ge_expression_c, l_exp, r_exp)
-SYM_REF2(add_expression_c, l_exp, r_exp)
-SYM_REF2(sub_expression_c, l_exp, r_exp)
-SYM_REF2(mul_expression_c, l_exp, r_exp)
-SYM_REF2(div_expression_c, l_exp, r_exp)
+SYM_REF2(add_expression_c, l_exp, r_exp, bool deprecated_operation;)
+SYM_REF2(sub_expression_c, l_exp, r_exp, bool deprecated_operation;)
+SYM_REF2(mul_expression_c, l_exp, r_exp, bool deprecated_operation;)
+SYM_REF2(div_expression_c, l_exp, r_exp, bool deprecated_operation;)
 SYM_REF2(mod_expression_c, l_exp, r_exp)
 SYM_REF2(power_expression_c, l_exp, r_exp)
 SYM_REF1(neg_expression_c, exp)
--- a/stage3/fill_candidate_datatypes.cc	Sun Mar 11 18:24:39 2012 +0000
+++ b/stage3/fill_candidate_datatypes.cc	Sun Mar 11 22:21:47 2012 +0100
@@ -53,12 +53,14 @@
 fill_candidate_datatypes_c::~fill_candidate_datatypes_c(void) {
 }
 
-symbol_c *fill_candidate_datatypes_c::widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[]) {
+symbol_c *fill_candidate_datatypes_c::widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[], bool &deprecated_operation) {
 	int k;
 	/* find a widening table entry compatible */
 	for (k = 0; NULL != widen_table[k].left;  k++)
-		if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right)))
-			return widen_table[k].result;
+		if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right))) {
+		      deprecated_operation = (widen_table[k].status == widen_entry::deprecated);	
+                      return widen_table[k].result;
+                }
 	return NULL;
 }
 
@@ -1269,7 +1271,8 @@
 
 void *fill_candidate_datatypes_c::visit(ADD_operator_c *symbol) {
 	symbol_c *prev_instruction_type, *operand_type;
-
+        
+        symbol->deprecated_operation = false;
 	if (NULL == prev_il_instruction) return NULL;
 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
@@ -1279,7 +1282,7 @@
 					is_ANY_NUM_compatible(prev_instruction_type))
 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
 			else {
-				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_ADD_table);
+				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_ADD_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 
@@ -1293,6 +1296,7 @@
 void *fill_candidate_datatypes_c::visit(SUB_operator_c *symbol) {
 	symbol_c *prev_instruction_type, *operand_type;
 
+        symbol->deprecated_operation = false;
 	if (NULL == prev_il_instruction) return NULL;
 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
@@ -1302,7 +1306,7 @@
 					is_ANY_NUM_compatible(prev_instruction_type))
 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
 			else {
-				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_SUB_table);
+				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_SUB_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 			}
@@ -1315,6 +1319,7 @@
 void *fill_candidate_datatypes_c::visit(MUL_operator_c *symbol) {
 	symbol_c *prev_instruction_type, *operand_type;
 
+        symbol->deprecated_operation = false;
 	if (NULL == prev_il_instruction) return NULL;
 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
@@ -1324,7 +1329,7 @@
 					is_ANY_NUM_compatible(prev_instruction_type))
 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
 			else {
-				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_MUL_table);
+				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_MUL_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 			}
@@ -1337,6 +1342,7 @@
 void *fill_candidate_datatypes_c::visit(DIV_operator_c *symbol) {
 	symbol_c *prev_instruction_type, *operand_type;
 
+        symbol->deprecated_operation = false;
 	if (NULL == prev_il_instruction) return NULL;
 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
@@ -1346,7 +1352,7 @@
 					is_ANY_NUM_compatible(prev_instruction_type))
 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
 			else {
-				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_DIV_table);
+				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_DIV_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 			}
@@ -1758,6 +1764,7 @@
 	 */
 	symbol_c *left_type, *right_type;
 
+        symbol->deprecated_operation = false;
 	symbol->l_exp->accept(*this);
 	symbol->r_exp->accept(*this);
 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
@@ -1767,7 +1774,7 @@
 			if (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type))
 				add_datatype_to_candidate_list(symbol, left_type);
 			else {
-				symbol_c *result = widening_conversion(left_type, right_type, widen_ADD_table);
+				symbol_c *result = widening_conversion(left_type, right_type, widen_ADD_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 			}
@@ -1781,6 +1788,7 @@
 void *fill_candidate_datatypes_c::visit(sub_expression_c *symbol) {
 	symbol_c *left_type, *right_type;
 
+        symbol->deprecated_operation = false;
 	symbol->l_exp->accept(*this);
 	symbol->r_exp->accept(*this);
 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
@@ -1790,7 +1798,7 @@
 			if (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type))
 				add_datatype_to_candidate_list(symbol, left_type);
 			else {
-				symbol_c *result = widening_conversion(left_type, right_type, widen_SUB_table);
+				symbol_c *result = widening_conversion(left_type, right_type, widen_SUB_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 			}
@@ -1804,6 +1812,7 @@
 void *fill_candidate_datatypes_c::visit(mul_expression_c *symbol) {
 	symbol_c *left_type, *right_type;
 
+        symbol->deprecated_operation = false;
 	symbol->l_exp->accept(*this);
 	symbol->r_exp->accept(*this);
 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
@@ -1813,7 +1822,7 @@
 			if      (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type))
 				add_datatype_to_candidate_list(symbol, left_type);
 			else {
-				symbol_c *result = widening_conversion(left_type, right_type, widen_MUL_table);
+				symbol_c *result = widening_conversion(left_type, right_type, widen_MUL_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 			}
@@ -1828,6 +1837,7 @@
 void *fill_candidate_datatypes_c::visit(div_expression_c *symbol) {
 	symbol_c *left_type, *right_type;
 
+        symbol->deprecated_operation = false;
 	symbol->l_exp->accept(*this);
 	symbol->r_exp->accept(*this);
 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
@@ -1837,7 +1847,7 @@
 			if      (is_type_equal(left_type, right_type) && is_ANY_NUM_type(left_type))
 				add_datatype_to_candidate_list(symbol, left_type);
 			else {
-				symbol_c *result = widening_conversion(left_type, right_type, widen_DIV_table);
+				symbol_c *result = widening_conversion(left_type, right_type, widen_DIV_table, symbol->deprecated_operation);
 				if (result)
 					add_datatype_to_candidate_list(symbol, result);
 			}
--- a/stage3/fill_candidate_datatypes.hh	Sun Mar 11 18:24:39 2012 +0000
+++ b/stage3/fill_candidate_datatypes.hh	Sun Mar 11 22:21:47 2012 +0100
@@ -79,7 +79,7 @@
     /* the current IL operand being analyzed - its symbol and its data type */
     symbol_c *il_operand_type;
     symbol_c *il_operand;
-    symbol_c *widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[]);
+    symbol_c *widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[], bool &deprecated_operation);
 
     /* Match a function declaration with a function call through their parameters.*/
     /* returns true if compatible function/FB invocation, otherwise returns false */
--- a/stage3/print_datatypes_error.cc	Sun Mar 11 18:24:39 2012 +0000
+++ b/stage3/print_datatypes_error.cc	Sun Mar 11 22:21:47 2012 +0100
@@ -124,16 +124,6 @@
 
 
 
-
-void print_datatypes_error_c::check_used_operation_status(symbol_c *symbol, symbol_c *left, symbol_c *right,  const struct widen_entry widen_table[]) {
-	/* find a compatible entry in the widening table */
-	for (int k = 0; NULL != widen_table[k].left;  k++)
-		if (is_type_equal(left, widen_table[k].left) && is_type_equal(right, widen_table[k].right))
-			if  (widen_entry::deprecated == widen_table[k].status)
-				STAGE3_WARNING(symbol, symbol, "Deprecated operation.");
-}
-
-
 /*
 typedef struct {
   symbol_c *function_name,
@@ -973,34 +963,38 @@
 }
 
 void *print_datatypes_error_c::visit(ADD_operator_c *symbol) {
-  /* TODO: print warning messages for deprecated operations! */
 	if ((symbol->candidate_datatypes.size() == 0) 		&&
 		(il_operand->candidate_datatypes.size() > 0))
 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ADD' operator.");
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'ADD' operator.");
 	return NULL;
 }
 
 void *print_datatypes_error_c::visit(SUB_operator_c *symbol) {
-  /* TODO: print warning messages for deprecated operations! */
 	if ((symbol->candidate_datatypes.size() == 0) 		&&
 		(il_operand->candidate_datatypes.size() > 0))
 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'SUB' operator.");
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'SUB' operator.");
 	return NULL;
 }
 
 void *print_datatypes_error_c::visit(MUL_operator_c *symbol) {
-  /* TODO: print warning messages for deprecated operations! */
 	if ((symbol->candidate_datatypes.size() == 0) 		&&
 		(il_operand->candidate_datatypes.size() > 0))
 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'MUL' operator.");
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'MUL' operator.");
 	return NULL;
 }
 
 void *print_datatypes_error_c::visit(DIV_operator_c *symbol) {
-  /* TODO: print warning messages for deprecated operations! */
 	if ((symbol->candidate_datatypes.size() == 0) 		&&
 		(il_operand->candidate_datatypes.size() > 0))
 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'DIV' operator.");
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for 'DIV' operator.");
 	return NULL;
 }
 
@@ -1196,8 +1190,8 @@
 		(symbol->l_exp->candidate_datatypes.size() > 0)	&&
 		(symbol->r_exp->candidate_datatypes.size() > 0))
 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '+' expression.");
-	
-	check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_ADD_table);
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for '+' expression.");	
 	return NULL;
 }
 
@@ -1209,8 +1203,9 @@
 	if ((symbol->candidate_datatypes.size() == 0) 		&&
 		(symbol->l_exp->candidate_datatypes.size() > 0)	&&
 		(symbol->r_exp->candidate_datatypes.size() > 0))
-			STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '-' expression.");
-	check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_SUB_table);
+		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '-' expression.");
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for '-' expression.");
 	return NULL;
 }
 
@@ -1221,7 +1216,8 @@
 		(symbol->l_exp->candidate_datatypes.size() > 0)	&&
 		(symbol->r_exp->candidate_datatypes.size() > 0))
 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '*' expression.");
-	check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_MUL_table);
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for '*' expression.");
 	return NULL;
 }
 
@@ -1232,7 +1228,8 @@
 		(symbol->l_exp->candidate_datatypes.size() > 0)	&&
 		(symbol->r_exp->candidate_datatypes.size() > 0))
 		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '/' expression.");
-	check_used_operation_status(symbol, symbol->l_exp->datatype,symbol->r_exp->datatype, widen_DIV_table);
+        if (symbol->deprecated_operation)
+                STAGE3_WARNING(symbol, symbol, "Deprecated operation for '/' expression.");
 	return NULL;
 }
 
--- a/stage3/print_datatypes_error.hh	Sun Mar 11 18:24:39 2012 +0000
+++ b/stage3/print_datatypes_error.hh	Sun Mar 11 22:21:47 2012 +0100
@@ -91,7 +91,6 @@
     void handle_function_invocation(symbol_c *fcall, generic_function_call_t fcall_data);
     void handle_implicit_il_fb_invocation(symbol_c *il_operator, const char *param_name, symbol_c *called_fb_declaration);  
     void *handle_conditional_flow_control_IL_instruction(symbol_c *symbol, const char *oper);
-    void check_used_operation_status(symbol_c *symbol, symbol_c *left, symbol_c *right,  const struct widen_entry widen_table[]);
     
   public:
     print_datatypes_error_c(symbol_c *ignore);