summaryrefslogtreecommitdiff
path: root/gdb/parse.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2010-08-19 13:33:10 +0000
committerDoug Evans <dje@google.com>2010-08-19 13:33:10 +0000
commit135ac82a029af8c6d2e5de354cd4fad68047dd8c (patch)
treec97de5c6cd7b5a35179a11ebbefab4896833b166 /gdb/parse.c
parent724d4482b9db1aced5ae391ad624f76877991232 (diff)
downloadgdb-135ac82a029af8c6d2e5de354cd4fad68047dd8c.tar.gz
PR exp/11926
* parser-defs.h (parse_float, parse_c_float): Declare. * parse.c (parse_float, parse_c_float): New function. * c-exp.y (parse_number): Call parse_c_float. * objc-exp.y (parse_number): Ditto. * p-exp.y (parse_number): Ditto. Use ANSI/ISO-style definition. * jv-exp.y (parse_number): Call parse_float, fix suffix handling. testsuite/ * gdb.base/printcmds.exp (test_float_accepted): New function. Move existing float tests there. Add tests for floats with suffixes. (test_float_rejected): New function. * gdb.java/jv-print.exp (test_float_accepted): New function. (test_float_rejected): New function. * gdb.objc/print.exp: New file. * gdb.pascal/print.exp: New file. * lib/objc.exp: New file.
Diffstat (limited to 'gdb/parse.c')
-rw-r--r--gdb/parse.c69
1 files changed, 67 insertions, 2 deletions
diff --git a/gdb/parse.c b/gdb/parse.c
index 035572e65bc..18038ed0cd3 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1038,8 +1038,6 @@ prefixify_subexp (struct expression *inexpr,
return result;
}
-/* This page contains the two entry points to this file. */
-
/* Read an expression from the string *STRINGPTR points to,
parse it, and return a pointer to a struct expression that we malloc.
Use block BLOCK as the lexical context for variable names;
@@ -1252,6 +1250,73 @@ void
null_post_parser (struct expression **exp, int void_context_p)
{
}
+
+/* Parse floating point value P of length LEN.
+ Return 0 (false) if invalid, 1 (true) if valid.
+ The successfully parsed number is stored in D.
+ *SUFFIX points to the suffix of the number in P.
+
+ NOTE: This accepts the floating point syntax that sscanf accepts. */
+
+int
+parse_float (const char *p, int len, DOUBLEST *d, const char **suffix)
+{
+ char *copy;
+ char *s;
+ int n, num;
+
+ copy = xmalloc (len + 1);
+ memcpy (copy, p, len);
+ copy[len] = 0;
+
+ num = sscanf (copy, "%" DOUBLEST_SCAN_FORMAT "%n", d, &n);
+ xfree (copy);
+
+ /* The sscanf man page suggests not making any assumptions on the effect
+ of %n on the result, so we don't.
+ That is why we simply test num == 0. */
+ if (num == 0)
+ return 0;
+
+ *suffix = p + n;
+ return 1;
+}
+
+/* Parse floating point value P of length LEN, using the C syntax for floats.
+ Return 0 (false) if invalid, 1 (true) if valid.
+ The successfully parsed number is stored in *D.
+ Its type is taken from builtin_type (gdbarch) and is stored in *T. */
+
+int
+parse_c_float (struct gdbarch *gdbarch, const char *p, int len,
+ DOUBLEST *d, struct type **t)
+{
+ const char *suffix;
+ int suffix_len;
+ const struct builtin_type *builtin_types = builtin_type (gdbarch);
+
+ if (! parse_float (p, len, d, &suffix))
+ return 0;
+
+ suffix_len = p + len - suffix;
+
+ if (suffix_len == 0)
+ *t = builtin_types->builtin_double;
+ else if (suffix_len == 1)
+ {
+ /* Handle suffixes: 'f' for float, 'l' for long double. */
+ if (tolower (*suffix) == 'f')
+ *t = builtin_types->builtin_float;
+ else if (tolower (*suffix) == 'l')
+ *t = builtin_types->builtin_long_double;
+ else
+ return 0;
+ }
+ else
+ return 0;
+
+ return 1;
+}
/* Stuff for maintaining a stack of types. Currently just used by C, but
probably useful for any language which declares its types "backwards". */