aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/export.h
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-11-27 23:29:15 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-11-27 23:29:15 +0000
commit9b4e458bd7a31b288e5c944cd27419a7f434367e (patch)
tree64a5c3a3eacb60fdeed40da0d460c6c6a27647f0 /gcc/go/gofrontend/export.h
parentda29d2a36ef4bc2d6459267ce21ac932ddfbad6a (diff)
downloadgcc-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/export.h')
-rw-r--r--gcc/go/gofrontend/export.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h
index 3cbf8e1..69fbd6e 100644
--- a/gcc/go/gofrontend/export.h
+++ b/gcc/go/gofrontend/export.h
@@ -303,7 +303,7 @@ class Export_function_body : public String_dump
{
public:
Export_function_body(Export* exp, int indent)
- : exp_(exp), indent_(indent)
+ : exp_(exp), type_context_(NULL), indent_(indent)
{ }
// Write a character to the body.
@@ -326,6 +326,16 @@ class Export_function_body : public String_dump
write_type(const Type* type)
{ this->exp_->write_type_to(type, this); }
+ // Return the current type context.
+ Type*
+ type_context() const
+ { return this->type_context_; }
+
+ // Set the current type context.
+ void
+ set_type_context(Type* type)
+ { this->type_context_ = type; }
+
// Append as many spaces as the current indentation level.
void
indent()
@@ -354,6 +364,8 @@ class Export_function_body : public String_dump
Export* exp_;
// The body we are building.
std::string body_;
+ // Current type context. Used to avoid duplicate type conversions.
+ Type* type_context_;
// Current indentation level: the number of spaces before each statement.
int indent_;
};