diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-11-27 23:29:15 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-11-27 23:29:15 +0000 |
commit | 9b4e458bd7a31b288e5c944cd27419a7f434367e (patch) | |
tree | 64a5c3a3eacb60fdeed40da0d460c6c6a27647f0 /gcc/go/gofrontend/expressions.cc | |
parent | da29d2a36ef4bc2d6459267ce21ac932ddfbad6a (diff) | |
download | gcc-9b4e458bd7a31b288e5c944cd27419a7f434367e.zip gcc-9b4e458bd7a31b288e5c944cd27419a7f434367e.tar.gz gcc-9b4e458bd7a31b288e5c944cd27419a7f434367e.tar.bz2 |
compiler: record final type for numeric expressions
Inlinable function bodies are generated after the determine_types pass,
so we know the type for all constants. Rather than try to determine
it again when inlining, record the type in the export data, using a
$convert expression. Reduce the number of explicit $convert
expressions by recording a type context with the expected type in
cases where that type is known.
Reviewed-on: https://go-review.googlesource.com/c/150071
From-SVN: r266534
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index c33f669..5f00eff 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -2142,11 +2142,25 @@ Integer_expression::export_integer(String_dump* exp, const mpz_t val) void Integer_expression::do_export(Export_function_body* efb) const { + bool added_type = false; + if (this->type_ != NULL + && !this->type_->is_abstract() + && this->type_ != efb->type_context()) + { + efb->write_c_string("$convert("); + efb->write_type(this->type_); + efb->write_c_string(", "); + added_type = true; + } + Integer_expression::export_integer(efb, this->val_); if (this->is_character_constant_) efb->write_c_string("'"); // A trailing space lets us reliably identify the end of the number. efb->write_c_string(" "); + + if (added_type) + efb->write_c_string(")"); } // Import an integer, floating point, or complex value. This handles @@ -2509,9 +2523,23 @@ Float_expression::export_float(String_dump *exp, const mpfr_t val) void Float_expression::do_export(Export_function_body* efb) const { + bool added_type = false; + if (this->type_ != NULL + && !this->type_->is_abstract() + && this->type_ != efb->type_context()) + { + efb->write_c_string("$convert("); + efb->write_type(this->type_); + efb->write_c_string(", "); + added_type = true; + } + Float_expression::export_float(efb, this->val_); // A trailing space lets us reliably identify the end of the number. efb->write_c_string(" "); + + if (added_type) + efb->write_c_string(")"); } // Dump a floating point number to the dump file. @@ -2699,9 +2727,23 @@ Complex_expression::export_complex(String_dump* exp, const mpc_t val) void Complex_expression::do_export(Export_function_body* efb) const { + bool added_type = false; + if (this->type_ != NULL + && !this->type_->is_abstract() + && this->type_ != efb->type_context()) + { + efb->write_c_string("$convert("); + efb->write_type(this->type_); + efb->write_c_string(", "); + added_type = true; + } + Complex_expression::export_complex(efb, this->val_); // A trailing space lets us reliably identify the end of the number. efb->write_c_string(" "); + + if (added_type) + efb->write_c_string(")"); } // Dump a complex expression to the dump file. @@ -3620,7 +3662,14 @@ Type_conversion_expression::do_export(Export_function_body* efb) const efb->write_c_string("$convert("); efb->write_type(this->type_); efb->write_c_string(", "); + + Type* old_context = efb->type_context(); + efb->set_type_context(this->type_); + this->expr_->export_expression(efb); + + efb->set_type_context(old_context); + efb->write_c_string(")"); } |