static void convert_ast_to_expression (struct parser_state *state,
const struct rust_op *operation,
- const struct rust_op *top);
+ const struct rust_op *top,
+ bool want_type = false);
/* A helper function that converts a vec of rust_ops to a gdb
expression. */
OPERATION is the operation to lower. TOP is a pointer to the
top-most operation; it is used to handle the special case where the
top-most expression is an identifier and can be optionally lowered
- to OP_TYPE. */
+ to OP_TYPE. WANT_TYPE is a flag indicating that, if the expression
+ is the name of a type, then emit an OP_TYPE for it (rather than
+ erroring). If WANT_TYPE is set, then the similar TOP handling is
+ not done. */
static void
convert_ast_to_expression (struct parser_state *state,
const struct rust_op *operation,
- const struct rust_op *top)
+ const struct rust_op *top,
+ bool want_type)
{
switch (operation->opcode)
{
}
break;
+ case UNOP_SIZEOF:
+ convert_ast_to_expression (state, operation->left.op, top, true);
+ write_exp_elt_opcode (state, UNOP_SIZEOF);
+ break;
+
case UNOP_PLUS:
case UNOP_NEG:
case UNOP_COMPLEMENT:
case UNOP_IND:
case UNOP_ADDR:
- case UNOP_SIZEOF:
convert_ast_to_expression (state, operation->left.op, top);
write_exp_elt_opcode (state, operation->opcode);
break;
if (type == NULL)
error (_("No symbol '%s' in current context"), varname);
- if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ if (!want_type
+ && TYPE_CODE (type) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (type) == 0)
{
/* A unit-like struct. */
write_exp_elt_longcst (state, 0);
write_exp_elt_opcode (state, OP_AGGREGATE);
}
- else if (operation == top)
+ else if (want_type || operation == top)
{
write_exp_elt_opcode (state, OP_TYPE);
write_exp_elt_type (state, type);
write_exp_elt_opcode (state, OP_TYPE);
- break;
}
+ else
+ error (_("Found type '%s', which can't be "
+ "evaluated in this context"),
+ varname);
}
}
break;