aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Zhou <woodzltc@cn.ibm.com>2005-09-20 08:55:55 +0000
committerWu Zhou <woodzltc@cn.ibm.com>2005-09-20 08:55:55 +0000
commit42969d33cb6f40b9dba99fdfdf448e553677dde3 (patch)
treeb82446d4254b540e37248307f97349bdd245acc5
parentca9295176c78c61895933517fcb2c73efa093a0a (diff)
downloadgdb-42969d33cb6f40b9dba99fdfdf448e553677dde3.zip
gdb-42969d33cb6f40b9dba99fdfdf448e553677dde3.tar.gz
gdb-42969d33cb6f40b9dba99fdfdf448e553677dde3.tar.bz2
* c-exp.y (parse-number): Modify the float parsing logic to let it
recognize a suffix.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/c-exp.y43
2 files changed, 29 insertions, 19 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7e8c96d..6fe82ea 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2005-09-20 Wu Zhou <woodzltc@cn.ibm.com>
+ * c-exp.y (parse-number): Modify the float parsing logic to let it
+ recognize a suffix.
+
+2005-09-20 Wu Zhou <woodzltc@cn.ibm.com>
+
* expression.h (enum exp_opcode): Fix a format error of a comment.
2005-09-20 Wu Zhou <woodzltc@cn.ibm.com>
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 1988e93..637796c 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1074,43 +1074,48 @@ parse_number (p, len, parsed_float, putithere)
if (parsed_float)
{
/* It's a float since it contains a point or an exponent. */
- char c;
+ char *s = malloc (len);
int num = 0; /* number of tokens scanned by scanf */
char saved_char = p[len];
p[len] = 0; /* null-terminate the token */
+
if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
- num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval,&c);
+ num = sscanf (p, "%g%s", (float *) &putithere->typed_val_float.dval,s);
else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
- num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval,&c);
+ num = sscanf (p, "%lg%s", (double *) &putithere->typed_val_float.dval,s);
else
{
#ifdef SCANF_HAS_LONG_DOUBLE
- num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval,&c);
+ num = sscanf (p, "%Lg%s", &putithere->typed_val_float.dval,s);
#else
/* Scan it into a double, then assign it to the long double.
This at least wins with values representable in the range
of doubles. */
double temp;
- num = sscanf (p, "%lg%c", &temp,&c);
+ num = sscanf (p, "%lg%s", &temp,s);
putithere->typed_val_float.dval = temp;
#endif
}
p[len] = saved_char; /* restore the input stream */
- if (num != 1) /* check scanf found ONLY a float ... */
- return ERROR;
- /* See if it has `f' or `l' suffix (float or long double). */
-
- c = tolower (p[len - 1]);
-
- if (c == 'f')
- putithere->typed_val_float.type = builtin_type (current_gdbarch)->builtin_float;
- else if (c == 'l')
- putithere->typed_val_float.type = builtin_type (current_gdbarch)->builtin_long_double;
- else if (isdigit (c) || c == '.')
- putithere->typed_val_float.type = builtin_type (current_gdbarch)->builtin_double;
- else
- return ERROR;
+
+ if (num == 1)
+ putithere->typed_val_float.type =
+ builtin_type (current_gdbarch)->builtin_double;
+
+ if (num == 2 )
+ {
+ /* See if it has any float suffix: 'f' for float, 'l' for long
+ double. */
+ if (!strcasecmp (s, "f"))
+ putithere->typed_val_float.type =
+ builtin_type (current_gdbarch)->builtin_float;
+ else if (!strcasecmp (s, "l"))
+ putithere->typed_val_float.type =
+ builtin_type (current_gdbarch)->builtin_long_double;
+ else
+ return ERROR;
+ }
return FLOAT;
}