compiler: traverse types of constant expressions

We forgot to ever traverse types of constant expressions.  This rarely
makes a difference--evidently, since nobody noticed--but it does
matter when we inline constant expressions: we need to ensure that the
type is visible to the importing code.

Change-Id: Idd94374d58327658a0fa8305dd675814d2ea1882
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/194317
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index 4db4e4a..cb09ec0 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -1812,6 +1812,9 @@
   do_import(Import_expression*, Location);
 
  protected:
+  int
+  do_traverse(Traverse*);
+
   bool
   do_is_constant() const
   { return true; }
@@ -1864,6 +1867,17 @@
   Type* type_;
 };
 
+// Traverse a boolean expression.  We just need to traverse the type
+// if there is one.
+
+int
+Boolean_expression::do_traverse(Traverse* traverse)
+{
+  if (this->type_ != NULL)
+    return Type::traverse(this->type_, traverse);
+  return TRAVERSE_CONTINUE;
+}
+
 // Get the type.
 
 Type*
@@ -1916,6 +1930,17 @@
 
 // Class String_expression.
 
+// Traverse a string expression.  We just need to traverse the type
+// if there is one.
+
+int
+String_expression::do_traverse(Traverse* traverse)
+{
+  if (this->type_ != NULL)
+    return Type::traverse(this->type_, traverse);
+  return TRAVERSE_CONTINUE;
+}
+
 // Get the type.
 
 Type*
@@ -2290,6 +2315,9 @@
   dump_integer(Ast_dump_context* ast_dump_context, const mpz_t val);
 
  protected:
+  int
+  do_traverse(Traverse*);
+
   bool
   do_is_constant() const
   { return true; }
@@ -2353,6 +2381,17 @@
   bool is_character_constant_;
 };
 
+// Traverse an integer expression.  We just need to traverse the type
+// if there is one.
+
+int
+Integer_expression::do_traverse(Traverse* traverse)
+{
+  if (this->type_ != NULL)
+    return Type::traverse(this->type_, traverse);
+  return TRAVERSE_CONTINUE;
+}
+
 // Return a numeric constant for this expression.  We have to mark
 // this as a character when appropriate.
 
@@ -2714,6 +2753,9 @@
   dump_float(Ast_dump_context* ast_dump_context, const mpfr_t val);
 
  protected:
+  int
+  do_traverse(Traverse*);
+
   bool
   do_is_constant() const
   { return true; }
@@ -2773,6 +2815,17 @@
   Type* type_;
 };
 
+// Traverse a float expression.  We just need to traverse the type if
+// there is one.
+
+int
+Float_expression::do_traverse(Traverse* traverse)
+{
+  if (this->type_ != NULL)
+    return Type::traverse(this->type_, traverse);
+  return TRAVERSE_CONTINUE;
+}
+
 // Return the current type.  If we haven't set the type yet, we return
 // an abstract float type.
 
@@ -2932,6 +2985,9 @@
   dump_complex(Ast_dump_context* ast_dump_context, const mpc_t val);
 
  protected:
+  int
+  do_traverse(Traverse*);
+
   bool
   do_is_constant() const
   { return true; }
@@ -2995,6 +3051,17 @@
   Type* type_;
 };
 
+// Traverse a complex expression.  We just need to traverse the type
+// if there is one.
+
+int
+Complex_expression::do_traverse(Traverse* traverse)
+{
+  if (this->type_ != NULL)
+    return Type::traverse(this->type_, traverse);
+  return TRAVERSE_CONTINUE;
+}
+
 // Return the current type.  If we haven't set the type yet, we return
 // an abstract complex type.
 
diff --git a/go/expressions.h b/go/expressions.h
index 4c743da..2e3d1e0 100644
--- a/go/expressions.h
+++ b/go/expressions.h
@@ -1670,6 +1670,9 @@
   do_import(Import_expression*, Location);
 
  protected:
+  int
+  do_traverse(Traverse*);
+
   bool
   do_is_constant() const
   { return true; }