absyntax_utils/absyntax_utils.cc
changeset 567 e5deeb6d4d2f
parent 565 8acbddf75333
child 568 5f79478142d7
equal deleted inserted replaced
566:5688fa07f89a 567:e5deeb6d4d2f
   114 
   114 
   115   /* return atoi(str.c_str()); */
   115   /* return atoi(str.c_str()); */
   116   return atoll(str.c_str());
   116   return atoll(str.c_str());
   117 }
   117 }
   118 
   118 
       
   119 
       
   120 /* extract the value of an hex integer from an hex_integer_c object !! */
       
   121 /* NOTE: it must ignore underscores! */
   119 uint64_t extract_hex_value(symbol_c *sym) {
   122 uint64_t extract_hex_value(symbol_c *sym) {
   120   std::string str = "";
   123   std::string str = "";
   121   char *endptr;
   124   char *endptr;
   122   hex_integer_c * hex_integer;
   125   hex_integer_c * hex_integer;
   123   uint64_t ret;
   126   uint64_t ret;
   124 
   127 
   125   if ((hex_integer = dynamic_cast<hex_integer_c *>(sym)) == NULL) ERROR;
   128   if ((hex_integer = dynamic_cast<hex_integer_c *>(sym)) == NULL) ERROR;
   126   for(unsigned int i = 3; i < strlen(hex_integer->value); i++)
   129   for(unsigned int i = 3; i < strlen(hex_integer->value); i++)
   127     if (hex_integer->value[i] != '_') str += hex_integer->value[i];
   130     if (hex_integer->value[i] != '_') str += hex_integer->value[i];
   128   errno = 0;    /* To distinguish success/failure after call */
   131     
   129   ret = strtoull(str.c_str(), &endptr, 16);
   132   ret = strtoull(str.c_str(), &endptr, 16);
       
   133   if (errno != 0) ERROR;
       
   134 
       
   135   return ret;
       
   136 }
       
   137 
       
   138 
       
   139 /* extract the value of a real from an real_c object !! */
       
   140 /* NOTE: it must ignore underscores! */
       
   141 double extract_real_value(symbol_c *sym) {
       
   142   std::string str = "";
       
   143   char *endptr;
       
   144   real_c * real_sym;
       
   145   uint64_t ret;
       
   146 
       
   147   if ((real_sym = dynamic_cast<real_c *>(sym)) == NULL) ERROR;
       
   148   for(unsigned int i = 3; i < strlen(real_sym->value); i++)
       
   149     if (real_sym->value[i] != '_') str += real_sym->value[i];
       
   150     
       
   151   ret = strtod(str.c_str(), NULL);
   130   if (errno != 0) ERROR;
   152   if (errno != 0) ERROR;
   131 
   153 
   132   return ret;
   154   return ret;
   133 }
   155 }
   134 
   156