aboutsummaryrefslogtreecommitdiff
path: root/gdb/parse.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2010-08-19 13:33:15 +0000
committerDoug Evans <dje@google.com>2010-08-19 13:33:15 +0000
commitd30f5e1f70ffa9fab08ccdacdba1bd6365d2511d (patch)
treea578156b090268842ed34a2a077d2eb6b6519cd2 /gdb/parse.c
parent2837d59e6b7e523fee86a5a5a050ecb5554ccd1b (diff)
downloadgdb-d30f5e1f70ffa9fab08ccdacdba1bd6365d2511d.zip
gdb-d30f5e1f70ffa9fab08ccdacdba1bd6365d2511d.tar.gz
gdb-d30f5e1f70ffa9fab08ccdacdba1bd6365d2511d.tar.bz2
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 035572e..18038ed 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". */