Fix bug with DIV and MOD operator in IL code generator
authorlaurent
Wed, 13 Jul 2011 13:40:14 +0200
changeset 345 894c0e6d951c
parent 344 8f71c46a0a55
child 346 620fd98a021d
Fix bug with DIV and MOD operator in IL code generator
stage4/generate_c/generate_c_il.cc
stage4/generate_c/generate_c_inlinefcall.cc
--- a/stage4/generate_c/generate_c_il.cc	Wed Jul 13 12:44:12 2011 +0200
+++ b/stage4/generate_c/generate_c_il.cc	Wed Jul 13 13:40:14 2011 +0200
@@ -1662,17 +1662,15 @@
     XXX_function("__TIME_ADD", &(this->default_variable_name), this->current_operand);
     /* the data type resulting from this operation... */
     this->default_variable_name.current_type = this->current_operand_type;
-    return NULL;
-  }
-  if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+  }
+  else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
 	NUM_operator_result_type();
 	XXX_operator(&(this->default_variable_name), " += ", this->current_operand);
     /* the data type resulting from this operation... */
     this->default_variable_name.current_type = this->current_operand_type;
-    return NULL;
-  }
-  ERROR;
+  }
+  else {ERROR;}
   return NULL;
 }
 
@@ -1682,17 +1680,15 @@
     XXX_function("__TIME_SUB", &(this->default_variable_name), this->current_operand);
     /* the data type resulting from this operation... */
     this->default_variable_name.current_type = this->current_operand_type;
-    return NULL;
-  }
-  if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+  }
+  else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
 	NUM_operator_result_type();
 	XXX_operator(&(this->default_variable_name), " -= ", this->current_operand);
     /* the data type resulting from this operation... */
     this->default_variable_name.current_type = this->current_operand_type;
-    return NULL;
-  }
-  ERROR;
+  }
+  else {ERROR;}
   return NULL;
 }
 
@@ -1700,18 +1696,16 @@
   if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
       search_expression_type->is_integer_type(this->current_operand_type)) {
     XXX_function("__TIME_MUL", &(this->default_variable_name), this->current_operand);
-    /* the data type resulting from this operation... */
-    return NULL;
-  }
-  if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+    /* the data type resulting from this operation is unchanged! */
+  }
+  else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
 	NUM_operator_result_type();
     XXX_operator(&(this->default_variable_name), " *= ", this->current_operand);
     /* the data type resulting from this operation... */
     this->default_variable_name.current_type = this->current_operand_type;
-    return NULL;
-  }
-  ERROR;
+  }
+  else {ERROR;}
   return NULL;
 }
 
@@ -1719,17 +1713,17 @@
   if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
       search_expression_type->is_integer_type(this->current_operand_type)) {
     XXX_function("__TIME_DIV", &(this->default_variable_name), this->current_operand);
-    /* the data type resulting from this operation... */
-    return NULL;
-  }
-  if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+    /* the data type resulting from this operation is unchanged! */
+  }
+  else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
 	NUM_operator_result_type();
 	XXX_operator(&(this->default_variable_name), " /= ", this->current_operand);
     /* the data type resulting from this operation... */
     this->default_variable_name.current_type = this->current_operand_type;
-  }
-  ERROR;
+    return NULL;
+  }
+  else {ERROR;}
   return NULL;
 }
 
@@ -1741,53 +1735,59 @@
     /* the data type resulting from this operation... */
     this->default_variable_name.current_type = this->current_operand_type;
   }
-  ERROR;
+  else {ERROR;}
   return NULL;
 }
 
 void *visit(GT_operator_c *symbol)	{
   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-    return CMP_operator(this->current_operand, "__gt_");
-  ERROR;
+      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+    CMP_operator(this->current_operand, "__gt_");
+  }
+  else {ERROR;}
   return NULL;
 }
 
 void *visit(GE_operator_c *symbol)	{
   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-    return CMP_operator(this->current_operand, "__ge_");
-  ERROR;
+      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+    CMP_operator(this->current_operand, "__ge_");
+  }
+  else {ERROR;}
   return NULL;
 }
 
 void *visit(EQ_operator_c *symbol)	{
-  if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-    return CMP_operator(this->current_operand, "__eq_");
-  ERROR;
+  if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+    CMP_operator(this->current_operand, "__eq_");
+  }
+  else {ERROR;}
   return NULL;
 }
 
 void *visit(LT_operator_c *symbol)	{
   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-    return CMP_operator(this->current_operand, "__lt_");
-  ERROR;
+      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+    CMP_operator(this->current_operand, "__lt_");
+  }
+  else {ERROR;}
   return NULL;
 }
 
 void *visit(LE_operator_c *symbol)	{
   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-    return CMP_operator(this->current_operand, "__le_");
-  ERROR;
+      search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+    CMP_operator(this->current_operand, "__le_");
+  }
+  else {ERROR;}
   return NULL;
 }
 
 void *visit(NE_operator_c *symbol)	{
-  if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-    return CMP_operator(this->current_operand, "__ne_");
-  ERROR;
+  if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+    CMP_operator(this->current_operand, "__ne_");
+  }
+  else {ERROR;}
   return NULL;
 }
 
--- a/stage4/generate_c/generate_c_inlinefcall.cc	Wed Jul 13 12:44:12 2011 +0200
+++ b/stage4/generate_c/generate_c_inlinefcall.cc	Wed Jul 13 13:40:14 2011 +0200
@@ -245,14 +245,13 @@
   private:
 
     /* A helper function... */
-	void *CMP_operator_result_type() {
+	void CMP_operator_result_type() {
 	  /* the data type resulting from this operation... */
 	  this->default_variable_name.current_type = &(this->bool_type);
-	  return NULL;
 	}
 
 	/* A helper function... */
-    void *BYTE_operator_result_type(void) {
+    void BYTE_operator_result_type(void) {
 	  if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) {
 		if (search_expression_type->is_literal_integer_type(this->current_operand_type))
 		  this->default_variable_name.current_type = &(this->lword_type);
@@ -261,11 +260,10 @@
 	  }
 	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type))
 		  this->current_operand_type = this->default_variable_name.current_type;
-	  return NULL;
 	}
 
     /* A helper function... */
-    void *NUM_operator_result_type(void) {
+    void NUM_operator_result_type(void) {
 	  if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) {
 		if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
 			search_expression_type->is_literal_real_type(this->current_operand_type))
@@ -284,7 +282,6 @@
 	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
 			   search_expression_type->is_literal_real_type(this->current_operand_type))
 		this->current_operand_type = this->default_variable_name.current_type;
-	  return NULL;
 	}
 
     void *print_getter(symbol_c *symbol) {
@@ -778,13 +775,12 @@
           search_expression_type->is_time_type(this->current_operand_type)) {
         /* the data type resulting from this operation... */
         this->default_variable_name.current_type = this->current_operand_type;
-        return NULL;
-      }
-      if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+      }
+      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
-        return NUM_operator_result_type();
-      }
-      ERROR;
+        NUM_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
@@ -793,93 +789,99 @@
           search_expression_type->is_time_type(this->current_operand_type)) {
         /* the data type resulting from this operation... */
         this->default_variable_name.current_type = this->current_operand_type;
-        return NULL;
-      }
-      if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+      }
+      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
-    	return NUM_operator_result_type();
-      }
-      ERROR;
+    	NUM_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(MUL_operator_c *symbol)	{
       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
           search_expression_type->is_integer_type(this->current_operand_type)) {
-        return NULL;
-      }
-      if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+        /* the data type resulting from this operation is unchanged! */
+      }
+      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
-    	return NUM_operator_result_type();
-      }
-      ERROR;
+    	NUM_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(DIV_operator_c *symbol)	{
       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
           search_expression_type->is_integer_type(this->current_operand_type)) {
-        return NULL;
-      }
-      if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
+        /* the data type resulting from this operation is unchanged! */
+      }
+      else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
-        return NUM_operator_result_type();
-      }
-      ERROR;
+        NUM_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(MOD_operator_c *symbol)	{
       if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
-        return NUM_operator_result_type();
-      }
-      ERROR;
+        NUM_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(GT_operator_c *symbol)	{
       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-        return CMP_operator_result_type();
-      ERROR;
+          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+        CMP_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(GE_operator_c *symbol)	{
       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-        return CMP_operator_result_type();
-      ERROR;
+          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+        CMP_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(EQ_operator_c *symbol)	{
-      if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-        return CMP_operator_result_type();
-      ERROR;
+      if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+        CMP_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(LT_operator_c *symbol)	{
       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-        return CMP_operator_result_type();
+          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+        CMP_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(LE_operator_c *symbol)	{
       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
-          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-        return CMP_operator_result_type();
-      ERROR;
+          search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+        CMP_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }
 
     void *visit(NE_operator_c *symbol)	{
-      if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
-        return CMP_operator_result_type();
-      ERROR;
+      if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
+        CMP_operator_result_type();
+      }
+      else {ERROR;}
       return NULL;
     }