mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-24 12:35:55 +08:00
* c-exp.y (parse-number): Modify the float parsing logic to let it
recognize a suffix.
This commit is contained in:
parent
ca9295176c
commit
42969d33cb
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
2005-09-20 Wu Zhou <woodzltc@cn.ibm.com>
|
||||||
|
|
||||||
* expression.h (enum exp_opcode): Fix a format error of a comment.
|
* expression.h (enum exp_opcode): Fix a format error of a comment.
|
||||||
|
39
gdb/c-exp.y
39
gdb/c-exp.y
@ -1074,43 +1074,48 @@ parse_number (p, len, parsed_float, putithere)
|
|||||||
if (parsed_float)
|
if (parsed_float)
|
||||||
{
|
{
|
||||||
/* It's a float since it contains a point or an exponent. */
|
/* 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 */
|
int num = 0; /* number of tokens scanned by scanf */
|
||||||
char saved_char = p[len];
|
char saved_char = p[len];
|
||||||
|
|
||||||
p[len] = 0; /* null-terminate the token */
|
p[len] = 0; /* null-terminate the token */
|
||||||
|
|
||||||
if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
|
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))
|
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
|
else
|
||||||
{
|
{
|
||||||
#ifdef SCANF_HAS_LONG_DOUBLE
|
#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
|
#else
|
||||||
/* Scan it into a double, then assign it to the long double.
|
/* Scan it into a double, then assign it to the long double.
|
||||||
This at least wins with values representable in the range
|
This at least wins with values representable in the range
|
||||||
of doubles. */
|
of doubles. */
|
||||||
double temp;
|
double temp;
|
||||||
num = sscanf (p, "%lg%c", &temp,&c);
|
num = sscanf (p, "%lg%s", &temp,s);
|
||||||
putithere->typed_val_float.dval = temp;
|
putithere->typed_val_float.dval = temp;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
p[len] = saved_char; /* restore the input stream */
|
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 (num == 1)
|
||||||
|
putithere->typed_val_float.type =
|
||||||
|
builtin_type (current_gdbarch)->builtin_double;
|
||||||
|
|
||||||
if (c == 'f')
|
if (num == 2 )
|
||||||
putithere->typed_val_float.type = builtin_type (current_gdbarch)->builtin_float;
|
{
|
||||||
else if (c == 'l')
|
/* See if it has any float suffix: 'f' for float, 'l' for long
|
||||||
putithere->typed_val_float.type = builtin_type (current_gdbarch)->builtin_long_double;
|
double. */
|
||||||
else if (isdigit (c) || c == '.')
|
if (!strcasecmp (s, "f"))
|
||||||
putithere->typed_val_float.type = builtin_type (current_gdbarch)->builtin_double;
|
putithere->typed_val_float.type =
|
||||||
else
|
builtin_type (current_gdbarch)->builtin_float;
|
||||||
return ERROR;
|
else if (!strcasecmp (s, "l"))
|
||||||
|
putithere->typed_val_float.type =
|
||||||
|
builtin_type (current_gdbarch)->builtin_long_double;
|
||||||
|
else
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
return FLOAT;
|
return FLOAT;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user