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.

Change-Id: I463dd0823bd811c482020ed67a1fdb794ae68253
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536641
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index c7b442d..f218731 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -846,7 +846,7 @@
   { 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 @@
   { 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 @@
   { 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 @@
 // 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 @@
   { 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 @@
   { 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 @@
 // 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 @@
 }
 
 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 @@
 }
 
 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 @@
 
 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 @@
 // 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 @@
 // 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 @@
 // 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 @@
 // 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 @@
 // 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 @@
 // 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 @@
 // 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 @@
 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(),
diff --git a/go/expressions.h b/go/expressions.h
index 3b8ae68..d5df724 100644
--- a/go/expressions.h
+++ b/go/expressions.h
@@ -598,19 +598,19 @@
   // 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 @@
   // 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 @@
   { 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 @@
   { 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 @@
   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 @@
   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 @@
   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 @@
   do_is_untyped(Type**) const;
 
   bool
-  do_numeric_constant_value(Numeric_constant*) const;
+  do_numeric_constant_value(Numeric_constant*);
 
   bool
   do_discarding_value();