Clean up the code.
authorMario de Sousa <msousa@fe.up.pt>
Wed, 14 Mar 2012 20:01:50 +0000
changeset 487 1619b2fe03e1
parent 486 e22150ad75fd
child 488 c833f83aac8c
Clean up the code.
stage3/fill_candidate_datatypes.cc
stage3/fill_candidate_datatypes.hh
stage3/narrow_candidate_datatypes.cc
stage3/print_datatypes_error.cc
--- a/stage3/fill_candidate_datatypes.cc	Wed Mar 14 19:31:17 2012 +0000
+++ b/stage3/fill_candidate_datatypes.cc	Wed Mar 14 20:01:50 2012 +0000
@@ -1128,93 +1128,28 @@
 
 
 
-void *fill_candidate_datatypes_c::visit(CAL_operator_c *symbol) {
-	if (NULL == prev_il_instruction) return NULL;
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-	        /* does not need to be bool type !! */
-		add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "CAL [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(CALC_operator_c *symbol) {
+void *fill_candidate_datatypes_c::handle_conditional_il_flow_control_operator(symbol_c *symbol) {
 	if (NULL == prev_il_instruction) return NULL;
 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
 		if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i]))
 			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
 	}
-	if (debug) std::cout <<  "CALC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {
-	if (NULL == prev_il_instruction) return NULL;
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-		if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i]))
-			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "CALCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(RET_operator_c *symbol) {
-	if (NULL == prev_il_instruction) return NULL;
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-	        /* does not need to be bool type !! */
-		add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "RET [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(RETC_operator_c *symbol) {
-	if (NULL == prev_il_instruction) return NULL;
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-		if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i]))
-			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "RETC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(RETCN_operator_c *symbol) {
-	if (NULL == prev_il_instruction) return NULL;
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-		if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i]))
-			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "RETCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(JMP_operator_c *symbol) {
-	if (NULL == prev_il_instruction) return NULL;
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-	        /* does not need to be bool type !! */
-		add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "JMP [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(JMPC_operator_c *symbol) {
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-		if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i]))
-			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "JMPC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
-
-void *fill_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) {
-	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
-		if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i]))
-			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
-	}
-	if (debug) std::cout <<  "JMPCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
-	return NULL;
-}
+	return NULL;
+}
+
+void *fill_candidate_datatypes_c::visit(  CAL_operator_c *symbol) {if (NULL == prev_il_instruction) return NULL; symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;}
+void *fill_candidate_datatypes_c::visit(  RET_operator_c *symbol) {if (NULL == prev_il_instruction) return NULL; symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;}
+void *fill_candidate_datatypes_c::visit(  JMP_operator_c *symbol) {if (NULL == prev_il_instruction) return NULL; symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;}
+void *fill_candidate_datatypes_c::visit( CALC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
+void *fill_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
+void *fill_candidate_datatypes_c::visit( RETC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
+void *fill_candidate_datatypes_c::visit(RETCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
+void *fill_candidate_datatypes_c::visit( JMPC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
+void *fill_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
+
+
+
+
 /* Symbol class handled together with function call checks */
 // void *visit(il_assign_operator_c *symbol, variable_name);
 /* Symbol class handled together with function call checks */
--- a/stage3/fill_candidate_datatypes.hh	Wed Mar 14 19:31:17 2012 +0000
+++ b/stage3/fill_candidate_datatypes.hh	Wed Mar 14 20:01:50 2012 +0000
@@ -89,6 +89,7 @@
     void  handle_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration);
     void *handle_binary_expression(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr);
     void *handle_binary_operator  (const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr);
+    void *handle_conditional_il_flow_control_operator(symbol_c *symbol);
     
     /* a helper function... */
     symbol_c *base_type(symbol_c *symbol);    
--- a/stage3/narrow_candidate_datatypes.cc	Wed Mar 14 19:31:17 2012 +0000
+++ b/stage3/narrow_candidate_datatypes.cc	Wed Mar 14 20:01:50 2012 +0000
@@ -929,14 +929,6 @@
 void *narrow_candidate_datatypes_c::visit(  NE_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
 
 
-// SYM_REF0(CAL_operator_c)
-/* called from il_fb_call_c (symbol->il_call_operator->accpet(*this) ) */
-void *narrow_candidate_datatypes_c::visit(CAL_operator_c *symbol) {
-	/* set the desired datatype of the previous il instruction */
-	/* This FB call does not change the value in the current/default IL variable, so we pass the required datatype to the previous IL instruction */
-	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
-	return NULL;
-}
 
 
 void *narrow_candidate_datatypes_c::narrow_conditional_flow_control_IL_instruction(symbol_c *symbol) {
@@ -960,38 +952,19 @@
 }
 
 
+// SYM_REF0(CAL_operator_c)
 // SYM_REF0(CALC_operator_c)
 // SYM_REF0(CALCN_operator_c)
 /* called from visit(il_fb_call_c *) {symbol->il_call_operator->accpet(*this)} */
+/* NOTE: The CAL, JMP and RET instructions simply set the desired datatype of the previous il instruction since they do not change the value in the current/default IL variable */
+/* called from il_fb_call_c (symbol->il_call_operator->accpet(*this) ) */
+void *narrow_candidate_datatypes_c::visit(  CAL_operator_c *symbol) {set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction); return NULL;}
+void *narrow_candidate_datatypes_c::visit(  RET_operator_c *symbol) {set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction); return NULL;}
+void *narrow_candidate_datatypes_c::visit(  JMP_operator_c *symbol) {set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction); return NULL;}
 void *narrow_candidate_datatypes_c::visit( CALC_operator_c *symbol) {return narrow_conditional_flow_control_IL_instruction(symbol);}
 void *narrow_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {return narrow_conditional_flow_control_IL_instruction(symbol);}
-
-
-void *narrow_candidate_datatypes_c::visit(RET_operator_c *symbol) {
-	/* set the desired datatype of the previous il instruction */
-	/* This RET instruction does not change the value in the current/default IL variable, so we pass the required datatype to the previous IL instruction.
-	 * Actually this should always be NULL, otherwise we have a bug in the flow_control_analysis_c
-	 * However, since that class has not yet been completely finished, we do not yet check this assertion!
-	 */
-// 	if (NULL != symbol->datatype) ERROR;
-	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
-	return NULL;
-}
-
 void *narrow_candidate_datatypes_c::visit( RETC_operator_c *symbol) {return narrow_conditional_flow_control_IL_instruction(symbol);}
 void *narrow_candidate_datatypes_c::visit(RETCN_operator_c *symbol) {return narrow_conditional_flow_control_IL_instruction(symbol);}
-
-void *narrow_candidate_datatypes_c::visit(JMP_operator_c *symbol) {
-	/* set the desired datatype of the previous il instruction */
-	/* This JMP instruction does not change the value in the current/default IL variable, so we pass the required datatype to the previous IL instruction.
-	 * Actually this should always be NULL, otherwise we have a bug in the flow_control_analysis_c
-	 * However, since that class has not yet been completely finished, we do not yet check this assertion!
-	 */
-// 	if (NULL != symbol->datatype) ERROR;
-	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
-	return NULL;
-}
-
 void *narrow_candidate_datatypes_c::visit( JMPC_operator_c *symbol) {return narrow_conditional_flow_control_IL_instruction(symbol);}
 void *narrow_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) {return narrow_conditional_flow_control_IL_instruction(symbol);}
 
--- a/stage3/print_datatypes_error.cc	Wed Mar 14 19:31:17 2012 +0000
+++ b/stage3/print_datatypes_error.cc	Wed Mar 14 20:01:50 2012 +0000
@@ -933,9 +933,6 @@
 void *print_datatypes_error_c::visit(  NE_operator_c *symbol) {return print_binary_operator_errors( "NE" , symbol);}
 
   
-void *print_datatypes_error_c::visit(CAL_operator_c *symbol) {
-	return NULL;
-}
 
 
 void *print_datatypes_error_c::handle_conditional_flow_control_IL_instruction(symbol_c *symbol, const char *oper) {
@@ -944,37 +941,17 @@
 	return NULL;
 }
 
-void *print_datatypes_error_c::visit(CALC_operator_c *symbol) {
-	return handle_conditional_flow_control_IL_instruction(symbol, "CALC");
-}
-
-void *print_datatypes_error_c::visit(CALCN_operator_c *symbol) {
-	return handle_conditional_flow_control_IL_instruction(symbol, "CALCN");
-}
-
-void *print_datatypes_error_c::visit(RET_operator_c *symbol) {
-	return NULL;
-}
-
-void *print_datatypes_error_c::visit(RETC_operator_c *symbol) {
-	return handle_conditional_flow_control_IL_instruction(symbol, "RETC");
-}
-
-void *print_datatypes_error_c::visit(RETCN_operator_c *symbol) {
-	return handle_conditional_flow_control_IL_instruction(symbol, "RETCN");
-}
-
-void *print_datatypes_error_c::visit(JMP_operator_c *symbol) {
-	return NULL;
-}
-
-void *print_datatypes_error_c::visit(JMPC_operator_c *symbol) {
-	return handle_conditional_flow_control_IL_instruction(symbol, "JMPC");
-}
-
-void *print_datatypes_error_c::visit(JMPCN_operator_c *symbol) {
-	return handle_conditional_flow_control_IL_instruction(symbol, "JMPCN");
-}
+void *print_datatypes_error_c::visit(  CAL_operator_c *symbol) {return NULL;}
+void *print_datatypes_error_c::visit( CALC_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "CALC" );}
+void *print_datatypes_error_c::visit(CALCN_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "CALCN");}
+void *print_datatypes_error_c::visit(  RET_operator_c *symbol) {return NULL;}
+void *print_datatypes_error_c::visit( RETC_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "RETC" );}
+void *print_datatypes_error_c::visit(RETCN_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "RETCN");}
+void *print_datatypes_error_c::visit(  JMP_operator_c *symbol) {return NULL;}
+void *print_datatypes_error_c::visit( JMPC_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "JMPC" );}
+void *print_datatypes_error_c::visit(JMPCN_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "JMPCN");}
+
+
 
 /* Symbol class handled together with function call checks */
 // void *visit(il_assign_operator_c *symbol, variable_name);