Some small cleanups.
authorMario de Sousa <msousa@fe.up.pt>
Mon, 27 Feb 2012 11:28:51 +0000
changeset 456 ca8d98289ff9
parent 455 933c0dccc82f
child 457 67d8b07bac22
Some small cleanups.
stage3/fill_candidate_datatypes.cc
stage3/narrow_candidate_datatypes.cc
stage3/narrow_candidate_datatypes.hh
--- a/stage3/fill_candidate_datatypes.cc	Sat Feb 25 19:16:35 2012 +0000
+++ b/stage3/fill_candidate_datatypes.cc	Mon Feb 27 11:28:51 2012 +0000
@@ -283,6 +283,17 @@
 	called_fb_declaration = fb_decl;
 
 	/* This implicit FB call does not change the value stored in the current/default IL variable */
+	/* It does, however, require that the datatype be compatible with the input parameter of the FB being called. 
+	 * If we were to follow the filling & narrowing algorithm correctly (implemented in fill_candidate_datatypes_c
+	 * & narrow_candidate_datatypes_c respectively), we should be restricting the candidate_datatpes to the datatypes
+	 * that are compatible to the FB call. 
+	 * However, doing the above will often result in some very confusing error messages for the user, especially in the case
+	 * in which the FB call is wrong, so the resulting cadidate datatypes is an empty list. In this case, the user would see
+	 * many error messages related to the IL instructions that follow the FB call, even though those IL instructions may be perfectly
+	 * correct.
+	 * For now, we will simply let the narrow_candidate_datatypes_c verify if the datatypes are compatible (something that should be done
+	 * here).
+	 */
 	if (NULL != prev_il_instruction)
 		copy_candidate_datatype_list(prev_il_instruction/*from*/, il_instruction/*to*/);
 
--- a/stage3/narrow_candidate_datatypes.cc	Sat Feb 25 19:16:35 2012 +0000
+++ b/stage3/narrow_candidate_datatypes.cc	Mon Feb 27 11:28:51 2012 +0000
@@ -259,7 +259,7 @@
  * The algorithm will be to build a fake il_fb_call_c equivalent to the implicit IL FB call, and let 
  * the visit(il_fb_call_c *) method handle it!
  */
-void narrow_candidate_datatypes_c::narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
+void *narrow_candidate_datatypes_c::narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
 
 	/* set the datatype of the il_operand, this is, the FB being called! */
 	if (NULL != il_operand) {
@@ -274,7 +274,7 @@
 		 * (or list of instructions) that will set the IL current/default value.
 		 * We cannot proceed verifying type compatibility of something that does not exist.
 		 */
-		return;
+		return NULL;
 	}
 
 	if (NULL == fb_decl) {
@@ -282,7 +282,7 @@
 		/* so we simply pass on the required datatype to the prev_il_instruction */
 		/* The invalid FB invocation will be caught by the print_datatypes_error_c by analysing NULL value in il_operand->datatype! */
 		prev_il_instruction->datatype = il_instruction->datatype;
-		return;
+		return NULL;
 	}
 	
 
@@ -345,6 +345,7 @@
 	} else {
 		prev_il_instruction->datatype = NULL;
 	}
+	return NULL;
 }
 
 
@@ -594,6 +595,7 @@
 return NULL;
 }
 
+
 /*   il_call_operator prev_declared_fb_name
  * | il_call_operator prev_declared_fb_name '(' ')'
  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
@@ -746,6 +748,7 @@
 }
 
 void *narrow_candidate_datatypes_c::visit(NOT_operator_c *symbol) {
+  /* TODO: ... */
 	return NULL;
 }
 
@@ -759,65 +762,33 @@
 }
 
 
-void *narrow_candidate_datatypes_c::visit(S1_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "S1", symbol->called_fb_declaration);
-	return NULL;
-}
-
-void *narrow_candidate_datatypes_c::visit(R1_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "R1", symbol->called_fb_declaration);
-	return NULL;
-}
-
-void *narrow_candidate_datatypes_c::visit(CLK_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);
-	return NULL;
-}
-
-void *narrow_candidate_datatypes_c::visit(CU_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "CU", symbol->called_fb_declaration);
-	return NULL;
-}
-
-void *narrow_candidate_datatypes_c::visit(CD_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "CD", symbol->called_fb_declaration);
-	return NULL;
-}
-
-void *narrow_candidate_datatypes_c::visit(PV_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "PV", symbol->called_fb_declaration);
-	return NULL;
-}
-
-void *narrow_candidate_datatypes_c::visit(IN_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "IN", symbol->called_fb_declaration);
-	return NULL;
-}
-
-void *narrow_candidate_datatypes_c::visit(PT_operator_c *symbol) {
-	narrow_implicit_il_fb_call(symbol, "PT", symbol->called_fb_declaration);
-	return NULL;
-}
-
-
-
-void *narrow_candidate_datatypes_c::visit(AND_operator_c  *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(OR_operator_c   *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(XOR_operator_c  *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  S1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "S1",  symbol->called_fb_declaration);}
+void *narrow_candidate_datatypes_c::visit(  R1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "R1",  symbol->called_fb_declaration);}
+void *narrow_candidate_datatypes_c::visit( CLK_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);}
+void *narrow_candidate_datatypes_c::visit(  CU_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CU",  symbol->called_fb_declaration);}
+void *narrow_candidate_datatypes_c::visit(  CD_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CD",  symbol->called_fb_declaration);}
+void *narrow_candidate_datatypes_c::visit(  PV_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PV",  symbol->called_fb_declaration);}
+void *narrow_candidate_datatypes_c::visit(  IN_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "IN",  symbol->called_fb_declaration);}
+void *narrow_candidate_datatypes_c::visit(  PT_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PT",  symbol->called_fb_declaration);}
+
+
+void *narrow_candidate_datatypes_c::visit( AND_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  OR_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit( XOR_operator_c *symbol)  {return handle_il_instruction(symbol);}
 void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(ORN_operator_c  *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit( ORN_operator_c *symbol)  {return handle_il_instruction(symbol);}
 void *narrow_candidate_datatypes_c::visit(XORN_operator_c *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(ADD_operator_c  *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(SUB_operator_c  *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(MUL_operator_c  *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(DIV_operator_c  *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(MOD_operator_c  *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(GT_operator_c   *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(GE_operator_c   *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(EQ_operator_c   *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(LT_operator_c   *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(LE_operator_c   *symbol)  {return handle_il_instruction(symbol);}
-void *narrow_candidate_datatypes_c::visit(NE_operator_c   *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit( ADD_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit( SUB_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit( MUL_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit( DIV_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit( MOD_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  GT_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  GE_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  EQ_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  LT_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  LE_operator_c *symbol)  {return handle_il_instruction(symbol);}
+void *narrow_candidate_datatypes_c::visit(  NE_operator_c *symbol)  {return handle_il_instruction(symbol);}
 
 
 // SYM_REF0(CAL_operator_c)
@@ -838,7 +809,7 @@
 	if ((NULL != symbol->datatype) && (!is_type(symbol->datatype, bool_type_name_c))) ERROR;
 	if (symbol->candidate_datatypes.size() > 1) ERROR;
 
-	/* NOTE: If there is not IL instruction following this CALC, CALCN, JMPC, JMPC, ..., instruction,
+	/* NOTE: If there is no IL instruction following this CALC, CALCN, JMPC, JMPC, ..., instruction,
 	 *       we must still provide a bool_type_name_c datatype (if possible, i.e. if it exists in the candidate datatype list).
 	 *       If it is not possible, we set it to NULL
 	 */
@@ -853,17 +824,10 @@
 
 
 // SYM_REF0(CALC_operator_c)
-/* called from il_fb_call_c (symbol->il_call_operator->accpet(*this) ) */
-void *narrow_candidate_datatypes_c::visit(CALC_operator_c *symbol) {
-	return narrow_conditional_flow_control_IL_instruction(symbol);
-}
-
-
 // SYM_REF0(CALCN_operator_c)
-/* called from il_fb_call_c (symbol->il_call_operator->accpet(*this) ) */
-void *narrow_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {
-	return narrow_conditional_flow_control_IL_instruction(symbol);
-}
+/* called from visit(il_fb_call_c *) {symbol->il_call_operator->accpet(*this)} */
+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) {
@@ -878,13 +842,8 @@
 	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( 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 */
@@ -898,13 +857,8 @@
 	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);
-}
+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);}
 
 /* Symbol class handled together with function call checks */
 // void *visit(il_assign_operator_c *symbol, variable_name);
--- a/stage3/narrow_candidate_datatypes.hh	Sat Feb 25 19:16:35 2012 +0000
+++ b/stage3/narrow_candidate_datatypes.hh	Mon Feb 27 11:28:51 2012 +0000
@@ -46,10 +46,10 @@
 
     bool is_widening_compatible(symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, const struct widen_entry widen_table[]);
 
-    void narrow_function_invocation(symbol_c *f_call, generic_function_call_t fcall_data);
-    void narrow_nonformal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_count = NULL);
-    void narrow_formal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_count = NULL);
-    void narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration);
+    void  narrow_function_invocation(symbol_c *f_call, generic_function_call_t fcall_data);
+    void  narrow_nonformal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_count = NULL);
+    void  narrow_formal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_count = NULL);
+    void *narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration);
     void *handle_il_instruction(symbol_c *symbol);
     void *narrow_conditional_flow_control_IL_instruction(symbol_c *symbol);