Fix bug with task interval using fixed_point value for duration items
authorLaurent Bessard
Thu, 13 Sep 2012 16:35:10 +0200
changeset 633 73b56dc69e61
parent 632 76c3d707ffa1
child 634 736b36a83548
child 635 a20a70021d37
child 667 bd1360f29f15
Fix bug with task interval using fixed_point value for duration items
stage3/constant_folding.cc
stage3/constant_folding.hh
--- a/stage3/constant_folding.cc	Thu Sep 13 15:14:55 2012 +0200
+++ b/stage3/constant_folding.cc	Thu Sep 13 16:35:10 2012 +0200
@@ -313,12 +313,19 @@
 real64_t extract_real_value(symbol_c *sym, bool *overflow) {
   std::string str = "";
   real_c *real_sym;
+  fixed_point_c *fixed_point_sym;
   char   *endptr;
   real64_t ret;
 
-  if ((real_sym = dynamic_cast<real_c *>(sym)) == NULL) ERROR;
-  for(unsigned int i = 0; i < strlen(real_sym->value); i++)
-    if (real_sym->value[i] != '_') str += real_sym->value[i];
+  if ((real_sym = dynamic_cast<real_c *>(sym)) != NULL) {
+	for(unsigned int i = 0; i < strlen(real_sym->value); i++)
+      if (real_sym->value[i] != '_') str += real_sym->value[i];
+  }
+  else if ((fixed_point_sym = dynamic_cast<fixed_point_c *>(sym)) != NULL) {
+    for(unsigned int i = 0; i < strlen(fixed_point_sym->value); i++)
+      if (fixed_point_sym->value[i] != '_') str += fixed_point_sym->value[i];
+  }
+  else ERROR;
     
   errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly!
   #if    (real64_t  == float)
@@ -835,7 +842,15 @@
 	return NULL;
 }
 
-
+/************************/
+/* B 1.2.3.1 - Duration */
+/********* **************/
+void *constant_folding_c::visit(fixed_point_c *symbol) {
+	bool overflow;
+	SET_CVALUE(real64, symbol, extract_real_value(symbol, &overflow));
+	if (overflow) SET_OVFLOW(real64, symbol);
+	return NULL;
+}
 
 
 
@@ -1094,4 +1109,4 @@
 void *constant_folding_c::visit(   not_expression_c *symbol) {symbol->  exp->accept(*this); return handle_not(symbol, symbol->exp);}
 
 /* TODO: handle function invocations... */
-// void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {}
\ No newline at end of file
+// void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {}
--- a/stage3/constant_folding.hh	Thu Sep 13 15:14:55 2012 +0200
+++ b/stage3/constant_folding.hh	Thu Sep 13 16:35:10 2012 +0200
@@ -82,6 +82,11 @@
     void *visit(boolean_true_c *symbol);
     void *visit(boolean_false_c *symbol);
 
+    /************************/
+    /* B 1.2.3.1 - Duration */
+    /********* **************/
+    void *visit(fixed_point_c *symbol);
+
     /****************************************/
     /* B.2 - Language IL (Instruction List) */
     /****************************************/