stage3/constant_folding.cc
changeset 667 bd1360f29f15
parent 661 f537c3315f83
parent 633 73b56dc69e61
child 690 6156ee2b4e32
equal deleted inserted replaced
666:8ba9ec4bae50 667:bd1360f29f15
   330  * integer         {digit}((_?{digit})*)
   330  * integer         {digit}((_?{digit})*)
   331  */
   331  */
   332 real64_t extract_real_value(symbol_c *sym, bool *overflow) {
   332 real64_t extract_real_value(symbol_c *sym, bool *overflow) {
   333   std::string str = "";
   333   std::string str = "";
   334   real_c *real_sym;
   334   real_c *real_sym;
       
   335   fixed_point_c *fixed_point_sym;
   335   char   *endptr;
   336   char   *endptr;
   336   real64_t ret;
   337   real64_t ret;
   337 
   338 
   338   if ((real_sym = dynamic_cast<real_c *>(sym)) == NULL) ERROR;
   339   if ((real_sym = dynamic_cast<real_c *>(sym)) != NULL) {
   339   for(unsigned int i = 0; i < strlen(real_sym->value); i++)
   340 	for(unsigned int i = 0; i < strlen(real_sym->value); i++)
   340     if (real_sym->value[i] != '_') str += real_sym->value[i];
   341       if (real_sym->value[i] != '_') str += real_sym->value[i];
       
   342   }
       
   343   else if ((fixed_point_sym = dynamic_cast<fixed_point_c *>(sym)) != NULL) {
       
   344     for(unsigned int i = 0; i < strlen(fixed_point_sym->value); i++)
       
   345       if (fixed_point_sym->value[i] != '_') str += fixed_point_sym->value[i];
       
   346   }
       
   347   else ERROR;
   341     
   348     
   342   errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly!
   349   errno = 0; // since strtoXX() may legally return 0, we must set errno to 0 to detect errors correctly!
   343   #if    (real64_t  == float)
   350   #if    (real64_t  == float)
   344     ret = strtof(str.c_str(),  &endptr);
   351     ret = strtof(str.c_str(),  &endptr);
   345   #elif  (real64_t  == double)
   352   #elif  (real64_t  == double)
   897 void *constant_folding_c::visit(boolean_false_c *symbol) {
   904 void *constant_folding_c::visit(boolean_false_c *symbol) {
   898 	SET_CVALUE(bool, symbol, false);
   905 	SET_CVALUE(bool, symbol, false);
   899 	return NULL;
   906 	return NULL;
   900 }
   907 }
   901 
   908 
   902 
   909 /************************/
       
   910 /* B 1.2.3.1 - Duration */
       
   911 /********* **************/
       
   912 void *constant_folding_c::visit(fixed_point_c *symbol) {
       
   913 	bool overflow;
       
   914 	SET_CVALUE(real64, symbol, extract_real_value(symbol, &overflow));
       
   915 	if (overflow) SET_OVFLOW(real64, symbol);
       
   916 	return NULL;
       
   917 }
   903 
   918 
   904 
   919 
   905 
   920 
   906 /****************************************/
   921 /****************************************/
   907 /* B.2 - Language IL (Instruction List) */
   922 /* B.2 - Language IL (Instruction List) */