diff -r 5688fa07f89a -r e5deeb6d4d2f absyntax_utils/absyntax_utils.cc --- a/absyntax_utils/absyntax_utils.cc Wed Jun 06 00:20:06 2012 +0200 +++ b/absyntax_utils/absyntax_utils.cc Wed Jun 06 13:28:50 2012 +0100 @@ -116,6 +116,9 @@ return atoll(str.c_str()); } + +/* extract the value of an hex integer from an hex_integer_c object !! */ +/* NOTE: it must ignore underscores! */ uint64_t extract_hex_value(symbol_c *sym) { std::string str = ""; char *endptr; @@ -125,7 +128,7 @@ if ((hex_integer = dynamic_cast(sym)) == NULL) ERROR; for(unsigned int i = 3; i < strlen(hex_integer->value); i++) if (hex_integer->value[i] != '_') str += hex_integer->value[i]; - errno = 0; /* To distinguish success/failure after call */ + ret = strtoull(str.c_str(), &endptr, 16); if (errno != 0) ERROR; @@ -133,6 +136,25 @@ } +/* extract the value of a real from an real_c object !! */ +/* NOTE: it must ignore underscores! */ +double extract_real_value(symbol_c *sym) { + std::string str = ""; + char *endptr; + real_c * real_sym; + uint64_t ret; + + if ((real_sym = dynamic_cast(sym)) == NULL) ERROR; + for(unsigned int i = 3; i < strlen(real_sym->value); i++) + if (real_sym->value[i] != '_') str += real_sym->value[i]; + + ret = strtod(str.c_str(), NULL); + if (errno != 0) ERROR; + + return ret; +} + + /***********************************************************************/ /***********************************************************************/