#include "gdbcmd.h"
#include "symfile.h" /* for overlay functions */
#include "inferior.h"
-#include "doublest.h"
+#include "target-float.h"
#include "block.h"
#include "source.h"
#include "objfiles.h"
/* See definition in parser-defs.h. */
-void
-initialize_expout (struct parser_state *ps, size_t initial_size,
- const struct language_defn *lang,
- struct gdbarch *gdbarch)
+parser_state::parser_state (size_t initial_size,
+ const struct language_defn *lang,
+ struct gdbarch *gdbarch)
+ : expout_size (initial_size),
+ expout (XNEWVAR (expression,
+ (sizeof (expression)
+ + EXP_ELEM_TO_BYTES (expout_size)))),
+ expout_ptr (0)
{
- ps->expout_size = initial_size;
- ps->expout_ptr = 0;
- ps->expout
- = (struct expression *) xmalloc (sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size));
- ps->expout->language_defn = lang;
- ps->expout->gdbarch = gdbarch;
+ expout->language_defn = lang;
+ expout->gdbarch = gdbarch;
}
-/* See definition in parser-defs.h. */
-
-void
-reallocate_expout (struct parser_state *ps)
+expression_up
+parser_state::release ()
{
/* Record the actual number of expression elements, and then
reallocate the expression memory so that we free up any
excess elements. */
- ps->expout->nelts = ps->expout_ptr;
- ps->expout = (struct expression *)
- xrealloc (ps->expout,
- sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_ptr));
+ expout->nelts = expout_ptr;
+ expout.reset (XRESIZEVAR (expression, expout.release (),
+ (sizeof (expression)
+ + EXP_ELEM_TO_BYTES (expout_ptr))));
+
+ return std::move (expout);
}
/* This page contains the functions for adding data to the struct expression
if (ps->expout_ptr >= ps->expout_size)
{
ps->expout_size *= 2;
- ps->expout = (struct expression *)
- xrealloc (ps->expout, sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size));
+ ps->expout.reset (XRESIZEVAR (expression, ps->expout.release (),
+ (sizeof (expression)
+ + EXP_ELEM_TO_BYTES (ps->expout_size))));
}
ps->expout->elts[ps->expout_ptr++] = *expelt;
}
}
void
-write_exp_elt_dblcst (struct parser_state *ps, DOUBLEST expelt)
-{
- union exp_element tmp;
-
- memset (&tmp, 0, sizeof (union exp_element));
- tmp.doubleconst = expelt;
- write_exp_elt (ps, &tmp);
-}
-
-void
-write_exp_elt_decfloatcst (struct parser_state *ps, gdb_byte expelt[16])
+write_exp_elt_floatcst (struct parser_state *ps, const gdb_byte expelt[16])
{
union exp_element tmp;
int index;
for (index = 0; index < 16; index++)
- tmp.decfloatconst[index] = expelt[index];
+ tmp.floatconst[index] = expelt[index];
write_exp_elt (ps, &tmp);
}
if (address_p != NULL)
*address_p = addr;
- struct type *the_type;
-
switch (type)
{
case mst_text:
break;
case OP_LONG:
- case OP_DOUBLE:
- case OP_DECFLOAT:
+ case OP_FLOAT:
case OP_VAR_VALUE:
case OP_VAR_MSYM_VALUE:
oplen = 4;
int comma, int void_context_p, int *out_subexp)
{
const struct language_defn *lang = NULL;
- struct parser_state ps;
int subexp;
lexptr = *stringptr;
and others called from *.y) ensure CURRENT_LANGUAGE gets restored
to the value matching SELECTED_FRAME as set by get_current_arch. */
- initialize_expout (&ps, 10, lang, get_current_arch ());
+ parser_state ps (10, lang, get_current_arch ());
scoped_restore_current_language lang_saver;
set_language (lang->la_language);
CATCH (except, RETURN_MASK_ALL)
{
if (! parse_completion)
- {
- xfree (ps.expout);
- throw_exception (except);
- }
+ throw_exception (except);
}
END_CATCH
- reallocate_expout (&ps);
+ /* We have to operate on an "expression *", due to la_post_parser,
+ which explains this funny-looking double release. */
+ expression_up result = ps.release ();
/* Convert expression from postfix form as generated by yacc
parser, to a prefix form. */
if (expressiondebug)
- dump_raw_expression (ps.expout, gdb_stdlog,
+ dump_raw_expression (result.get (), gdb_stdlog,
"before conversion to prefix form");
- subexp = prefixify_expression (ps.expout);
+ subexp = prefixify_expression (result.get ());
if (out_subexp)
*out_subexp = subexp;
- lang->la_post_parser (&ps.expout, void_context_p);
+ lang->la_post_parser (&result, void_context_p);
if (expressiondebug)
- dump_prefix_expression (ps.expout, gdb_stdlog);
+ dump_prefix_expression (result.get (), gdb_stdlog);
*stringptr = lexptr;
- return expression_up (ps.expout);
+ return result;
}
/* Parse STRING as an expression, and complain if this fails
/* A post-parser that does nothing. */
void
-null_post_parser (struct expression **exp, int void_context_p)
+null_post_parser (expression_up *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.
+ Return false if invalid, true if valid.
+ The successfully parsed number is stored in DATA in
+ target format for floating-point type TYPE.
NOTE: This accepts the floating point syntax that sscanf accepts. */
-int
-parse_float (const char *p, int len, DOUBLEST *d, const char **suffix)
+bool
+parse_float (const char *p, int len,
+ const struct type *type, gdb_byte *data)
{
- char *copy;
- int n, num;
-
- copy = (char *) 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;
+ return target_float_from_string (data, type, std::string (p, len));
}
\f
/* Stuff for maintaining a stack of types. Currently just used by C, but
{
case BINOP_VAL:
case OP_COMPLEX:
- case OP_DECFLOAT:
- case OP_DOUBLE:
+ case OP_FLOAT:
case OP_LONG:
case OP_SCOPE:
case OP_TYPE:
if ((ps->expout_ptr + lenelt) >= ps->expout_size)
{
ps->expout_size = std::max (ps->expout_size * 2,
- ps->expout_ptr + lenelt + 10);
- ps->expout = (struct expression *)
- xrealloc (ps->expout, (sizeof (struct expression)
- + EXP_ELEM_TO_BYTES (ps->expout_size)));
+ ps->expout_ptr + lenelt + 10);
+ ps->expout.reset (XRESIZEVAR (expression,
+ ps->expout.release (),
+ (sizeof (struct expression)
+ + EXP_ELEM_TO_BYTES (ps->expout_size))));
}
}