if (expr->numeric_constant_value(&nc))
{
Numeric_constant result;
- if (Unary_expression::eval_constant(op, &nc, loc, &result))
+ bool issued_error;
+ if (Unary_expression::eval_constant(op, &nc, loc, &result,
+ &issued_error))
return result.expression(loc);
+ else if (issued_error)
+ return Expression::make_error(this->location());
}
}
}
// Apply unary opcode OP to UNC, setting NC. Return true if this
-// could be done, false if not. Issue errors for overflow.
+// could be done, false if not. On overflow, issues an error and sets
+// *ISSUED_ERROR.
bool
Unary_expression::eval_constant(Operator op, const Numeric_constant* unc,
- Location location, Numeric_constant* nc)
+ Location location, Numeric_constant* nc,
+ bool* issued_error)
{
+ *issued_error = false;
switch (op)
{
case OPERATOR_PLUS:
mpz_clear(uval);
mpz_clear(val);
- return nc->set_type(unc->type(), true, location);
+ if (!nc->set_type(unc->type(), true, location))
+ {
+ *issued_error = true;
+ return false;
+ }
+ return true;
}
// Return the integral constant value of a unary expression, if it has one.
Numeric_constant unc;
if (!this->expr_->numeric_constant_value(&unc))
return false;
+ bool issued_error;
return Unary_expression::eval_constant(this->op_, &unc, this->location(),
- nc);
+ nc, &issued_error);
}
// Return the type of a unary expression.
// Apply binary opcode OP to LEFT_NC and RIGHT_NC, setting NC. Return
// true if this could be done, false if not. Issue errors at LOCATION
-// as appropriate.
+// as appropriate, and sets *ISSUED_ERROR if it did.
bool
Binary_expression::eval_constant(Operator op, Numeric_constant* left_nc,
Numeric_constant* right_nc,
- Location location, Numeric_constant* nc)
+ Location location, Numeric_constant* nc,
+ bool* issued_error)
{
+ *issued_error = false;
switch (op)
{
case OPERATOR_OROR:
r = Binary_expression::eval_integer(op, left_nc, right_nc, location, nc);
if (r)
- r = nc->set_type(type, true, location);
+ {
+ r = nc->set_type(type, true, location);
+ if (!r)
+ *issued_error = true;
+ }
return r;
}
else
{
Numeric_constant nc;
+ bool issued_error;
if (!Binary_expression::eval_constant(op, &left_nc, &right_nc,
- location, &nc))
+ location, &nc,
+ &issued_error))
+ {
+ if (issued_error)
+ return Expression::make_error(location);
return this;
+ }
return nc.expression(location);
}
}
Numeric_constant right_nc;
if (!this->right_->numeric_constant_value(&right_nc))
return false;
+ bool issued_error;
return Binary_expression::eval_constant(this->op_, &left_nc, &right_nc,
- this->location(), nc);
+ this->location(), nc, &issued_error);
}
// Note that the value is being discarded.
Type_context subcontext(*context);
- if (is_comparison)
+ if (is_constant_expr)
+ {
+ subcontext.type = NULL;
+ subcontext.may_be_abstract = true;
+ }
+ else if (is_comparison)
{
// In a comparison, the context does not determine the types of
// the operands.
subcontext.type = subcontext.type->make_non_abstract_type();
}
- if (!is_constant_expr)
- this->left_->determine_type(&subcontext);
+ this->left_->determine_type(&subcontext);
if (is_shift_op)
{
subcontext.may_be_abstract = false;
}
- if (!is_constant_expr)
- this->right_->determine_type(&subcontext);
+ this->right_->determine_type(&subcontext);
if (is_comparison)
{
}
// Apply unary opcode OP to UNC, setting NC. Return true if this
- // could be done, false if not. Issue errors for overflow.
+ // could be done, false if not. On overflow, issues an error and
+ // sets *ISSUED_ERROR.
static bool
eval_constant(Operator op, const Numeric_constant* unc,
- Location, Numeric_constant* nc);
+ Location, Numeric_constant* nc, bool *issued_error);
static Expression*
do_import(Import*);
// Apply binary opcode OP to LEFT_NC and RIGHT_NC, setting NC.
// Return true if this could be done, false if not. Issue errors at
- // LOCATION as appropriate.
+ // LOCATION as appropriate, and sets *ISSUED_ERROR if it did.
static bool
eval_constant(Operator op, Numeric_constant* left_nc,
Numeric_constant* right_nc, Location location,
- Numeric_constant* nc);
+ Numeric_constant* nc, bool* issued_error);
// Compare constants LEFT_NC and RIGHT_NC according to OP, setting
// *RESULT. Return true if this could be done, false if not. Issue