compiler: make xx_constant_value methods non-const
This changes the Expression {numeric,string,boolean}_constant_value methods non-const. This does not affect anything immediately, but will be useful for later CLs in this series. The only real effect is to Builtin_call_expression::do_export, which remains const and can no longer call numeric_constant_value. But it never needed to call it, as do_export runs after do_lower, and do_lower replaces a constant expression with the actual constant. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536641
This commit is contained in:
parent
45a5ab0503
commit
597dba85b3
3 changed files with 37 additions and 67 deletions
|
@ -1,4 +1,4 @@
|
|||
806217827fe30553d535f876f182a9e92f5f648e
|
||||
3c2a441ef6cafb018bb3cc16f8403ae3d1daf2e1
|
||||
|
||||
The first line of this file holds the git revision number of the last
|
||||
merge done from the gofrontend repository.
|
||||
|
|
|
@ -846,7 +846,7 @@ class Error_expression : public Expression
|
|||
{ return false; }
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant* nc) const
|
||||
do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
nc->set_unsigned_long(NULL, 0);
|
||||
return true;
|
||||
|
@ -1992,7 +1992,7 @@ class Boolean_expression : public Expression
|
|||
{ return this->val_ == false; }
|
||||
|
||||
bool
|
||||
do_boolean_constant_value(bool* val) const
|
||||
do_boolean_constant_value(bool* val)
|
||||
{
|
||||
*val = this->val_;
|
||||
return true;
|
||||
|
@ -2537,7 +2537,7 @@ class Integer_expression : public Expression
|
|||
{ return true; }
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant* nc) const;
|
||||
do_numeric_constant_value(Numeric_constant* nc);
|
||||
|
||||
Type*
|
||||
do_type();
|
||||
|
@ -2602,7 +2602,7 @@ Integer_expression::do_traverse(Traverse* traverse)
|
|||
// this as a character when appropriate.
|
||||
|
||||
bool
|
||||
Integer_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
||||
Integer_expression::do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
if (this->is_character_constant_)
|
||||
nc->set_rune(this->type_, this->val_);
|
||||
|
@ -2983,7 +2983,7 @@ class Float_expression : public Expression
|
|||
{ return true; }
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant* nc) const
|
||||
do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
nc->set_float(this->type_, this->val_);
|
||||
return true;
|
||||
|
@ -3219,7 +3219,7 @@ class Complex_expression : public Expression
|
|||
{ return true; }
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant* nc) const
|
||||
do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
nc->set_complex(this->type_, this->val_);
|
||||
return true;
|
||||
|
@ -3480,7 +3480,7 @@ Const_expression::do_lower(Gogo* gogo, Named_object*,
|
|||
// Return a numeric constant value.
|
||||
|
||||
bool
|
||||
Const_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
||||
Const_expression::do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
if (this->seen_)
|
||||
return false;
|
||||
|
@ -3508,7 +3508,7 @@ Const_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
|||
}
|
||||
|
||||
bool
|
||||
Const_expression::do_string_constant_value(std::string* val) const
|
||||
Const_expression::do_string_constant_value(std::string* val)
|
||||
{
|
||||
if (this->seen_)
|
||||
return false;
|
||||
|
@ -3523,7 +3523,7 @@ Const_expression::do_string_constant_value(std::string* val) const
|
|||
}
|
||||
|
||||
bool
|
||||
Const_expression::do_boolean_constant_value(bool* val) const
|
||||
Const_expression::do_boolean_constant_value(bool* val)
|
||||
{
|
||||
if (this->seen_)
|
||||
return false;
|
||||
|
@ -4180,7 +4180,7 @@ Type_conversion_expression::do_is_static_initializer() const
|
|||
|
||||
bool
|
||||
Type_conversion_expression::do_numeric_constant_value(
|
||||
Numeric_constant* nc) const
|
||||
Numeric_constant* nc)
|
||||
{
|
||||
if (!this->type_->is_numeric_type())
|
||||
return false;
|
||||
|
@ -4192,7 +4192,7 @@ Type_conversion_expression::do_numeric_constant_value(
|
|||
// Return the constant string value if there is one.
|
||||
|
||||
bool
|
||||
Type_conversion_expression::do_string_constant_value(std::string* val) const
|
||||
Type_conversion_expression::do_string_constant_value(std::string* val)
|
||||
{
|
||||
if (this->type_->is_string_type() && this->expr_->type()->is_string_type())
|
||||
return this->expr_->string_constant_value(val);
|
||||
|
@ -4229,7 +4229,7 @@ Type_conversion_expression::do_string_constant_value(std::string* val) const
|
|||
// Return the constant boolean value if there is one.
|
||||
|
||||
bool
|
||||
Type_conversion_expression::do_boolean_constant_value(bool* val) const
|
||||
Type_conversion_expression::do_boolean_constant_value(bool* val)
|
||||
{
|
||||
if (!this->type_->is_boolean_type())
|
||||
return false;
|
||||
|
@ -5141,7 +5141,7 @@ Unary_expression::eval_constant(Operator op, const Numeric_constant* unc,
|
|||
// Return the integral constant value of a unary expression, if it has one.
|
||||
|
||||
bool
|
||||
Unary_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
||||
Unary_expression::do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
Numeric_constant unc;
|
||||
if (!this->expr_->numeric_constant_value(&unc))
|
||||
|
@ -5154,7 +5154,7 @@ Unary_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
|||
// Return the boolean constant value of a unary expression, if it has one.
|
||||
|
||||
bool
|
||||
Unary_expression::do_boolean_constant_value(bool* val) const
|
||||
Unary_expression::do_boolean_constant_value(bool* val)
|
||||
{
|
||||
if (this->op_ == OPERATOR_NOT
|
||||
&& this->expr_->boolean_constant_value(val))
|
||||
|
@ -6733,7 +6733,7 @@ Binary_expression::operand_address(Statement_inserter* inserter,
|
|||
// Return the numeric constant value, if it has one.
|
||||
|
||||
bool
|
||||
Binary_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
||||
Binary_expression::do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
Numeric_constant left_nc;
|
||||
if (!this->left_->numeric_constant_value(&left_nc))
|
||||
|
@ -6749,7 +6749,7 @@ Binary_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
|||
// Return the boolean constant value, if it has one.
|
||||
|
||||
bool
|
||||
Binary_expression::do_boolean_constant_value(bool* val) const
|
||||
Binary_expression::do_boolean_constant_value(bool* val)
|
||||
{
|
||||
bool is_comparison = false;
|
||||
switch (this->op_)
|
||||
|
@ -9924,7 +9924,7 @@ Builtin_call_expression::do_is_untyped(Type** ptype) const
|
|||
// Return a numeric constant if possible.
|
||||
|
||||
bool
|
||||
Builtin_call_expression::do_numeric_constant_value(Numeric_constant* nc) const
|
||||
Builtin_call_expression::do_numeric_constant_value(Numeric_constant* nc)
|
||||
{
|
||||
if (this->code_ == BUILTIN_LEN
|
||||
|| this->code_ == BUILTIN_CAP)
|
||||
|
@ -11230,37 +11230,7 @@ Builtin_call_expression::do_get_backend(Translate_context* context)
|
|||
void
|
||||
Builtin_call_expression::do_export(Export_function_body* efb) const
|
||||
{
|
||||
Numeric_constant nc;
|
||||
if (this->numeric_constant_value(&nc))
|
||||
{
|
||||
if (nc.is_int())
|
||||
{
|
||||
mpz_t val;
|
||||
nc.get_int(&val);
|
||||
Integer_expression::export_integer(efb, val);
|
||||
mpz_clear(val);
|
||||
}
|
||||
else if (nc.is_float())
|
||||
{
|
||||
mpfr_t fval;
|
||||
nc.get_float(&fval);
|
||||
Float_expression::export_float(efb, fval);
|
||||
mpfr_clear(fval);
|
||||
}
|
||||
else if (nc.is_complex())
|
||||
{
|
||||
mpc_t cval;
|
||||
nc.get_complex(&cval);
|
||||
Complex_expression::export_complex(efb, cval);
|
||||
mpc_clear(cval);
|
||||
}
|
||||
else
|
||||
go_unreachable();
|
||||
|
||||
// A trailing space lets us reliably identify the end of the number.
|
||||
efb->write_c_string(" ");
|
||||
}
|
||||
else if (this->code_ == BUILTIN_ADD || this->code_ == BUILTIN_SLICE)
|
||||
if (this->code_ == BUILTIN_ADD || this->code_ == BUILTIN_SLICE)
|
||||
{
|
||||
char buf[50];
|
||||
snprintf(buf, sizeof buf, "<p%d>%s", efb->unsafe_package_index(),
|
||||
|
|
|
@ -598,19 +598,19 @@ class Expression
|
|||
// If this is not a numeric constant, return false. If it is one,
|
||||
// return true, and set VAL to hold the value.
|
||||
bool
|
||||
numeric_constant_value(Numeric_constant* val) const
|
||||
numeric_constant_value(Numeric_constant* val)
|
||||
{ return this->do_numeric_constant_value(val); }
|
||||
|
||||
// If this is not a constant expression with string type, return
|
||||
// false. If it is one, return true, and set VAL to the value.
|
||||
bool
|
||||
string_constant_value(std::string* val) const
|
||||
string_constant_value(std::string* val)
|
||||
{ return this->do_string_constant_value(val); }
|
||||
|
||||
// If this is not a constant expression with boolean type, return
|
||||
// false. If it is one, return true, and set VAL to the value.
|
||||
bool
|
||||
boolean_constant_value(bool* val) const
|
||||
boolean_constant_value(bool* val)
|
||||
{ return this->do_boolean_constant_value(val); }
|
||||
|
||||
// If this is a const reference expression, return the named
|
||||
|
@ -1197,19 +1197,19 @@ class Expression
|
|||
// Return whether this is a constant expression of numeric type, and
|
||||
// set the Numeric_constant to the value.
|
||||
virtual bool
|
||||
do_numeric_constant_value(Numeric_constant*) const
|
||||
do_numeric_constant_value(Numeric_constant*)
|
||||
{ return false; }
|
||||
|
||||
// Return whether this is a constant expression of string type, and
|
||||
// set VAL to the value.
|
||||
virtual bool
|
||||
do_string_constant_value(std::string*) const
|
||||
do_string_constant_value(std::string*)
|
||||
{ return false; }
|
||||
|
||||
// Return whether this is a constant expression of boolean type, and
|
||||
// set VAL to the value.
|
||||
virtual bool
|
||||
do_boolean_constant_value(bool*) const
|
||||
do_boolean_constant_value(bool*)
|
||||
{ return false; }
|
||||
|
||||
// Called by the parser if the value is being discarded.
|
||||
|
@ -1532,13 +1532,13 @@ class Const_expression : public Expression
|
|||
{ return true; }
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant* nc) const;
|
||||
do_numeric_constant_value(Numeric_constant* nc);
|
||||
|
||||
bool
|
||||
do_string_constant_value(std::string* val) const;
|
||||
do_string_constant_value(std::string* val);
|
||||
|
||||
bool
|
||||
do_boolean_constant_value(bool* val) const;
|
||||
do_boolean_constant_value(bool* val);
|
||||
|
||||
Type*
|
||||
do_type();
|
||||
|
@ -1865,7 +1865,7 @@ class String_expression : public Expression
|
|||
{ return true; }
|
||||
|
||||
bool
|
||||
do_string_constant_value(std::string* val) const
|
||||
do_string_constant_value(std::string* val)
|
||||
{
|
||||
*val = this->val_;
|
||||
return true;
|
||||
|
@ -1967,13 +1967,13 @@ class Type_conversion_expression : public Expression
|
|||
do_is_static_initializer() const;
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant*) const;
|
||||
do_numeric_constant_value(Numeric_constant*);
|
||||
|
||||
bool
|
||||
do_string_constant_value(std::string*) const;
|
||||
do_string_constant_value(std::string*);
|
||||
|
||||
bool
|
||||
do_boolean_constant_value(bool*) const;
|
||||
do_boolean_constant_value(bool*);
|
||||
|
||||
Type*
|
||||
do_type()
|
||||
|
@ -2169,10 +2169,10 @@ class Unary_expression : public Expression
|
|||
do_is_static_initializer() const;
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant*) const;
|
||||
do_numeric_constant_value(Numeric_constant*);
|
||||
|
||||
bool
|
||||
do_boolean_constant_value(bool*) const;
|
||||
do_boolean_constant_value(bool*);
|
||||
|
||||
Type*
|
||||
do_type();
|
||||
|
@ -2329,10 +2329,10 @@ class Binary_expression : public Expression
|
|||
do_is_static_initializer() const;
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant*) const;
|
||||
do_numeric_constant_value(Numeric_constant*);
|
||||
|
||||
bool
|
||||
do_boolean_constant_value(bool*) const;
|
||||
do_boolean_constant_value(bool*);
|
||||
|
||||
bool
|
||||
do_discarding_value();
|
||||
|
@ -2806,7 +2806,7 @@ class Builtin_call_expression : public Call_expression
|
|||
do_is_untyped(Type**) const;
|
||||
|
||||
bool
|
||||
do_numeric_constant_value(Numeric_constant*) const;
|
||||
do_numeric_constant_value(Numeric_constant*);
|
||||
|
||||
bool
|
||||
do_discarding_value();
|
||||
|
|
Loading…
Add table
Reference in a new issue