From 0e1680747445c76c563f4df565b0d94c75c41b1d Mon Sep 17 00:00:00 2001
From: ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 17 Apr 2014 19:10:27 +0000
Subject: compiler: Define immutability for numeric, constant, type info, type
 conversion, and addressof expressions.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@209493 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/go/gofrontend/expressions.cc | 55 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

(limited to 'gcc/go')

diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index bd2e3183bfe..199461061d9 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -554,6 +554,10 @@ class Error_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_immutable() const
+  { return true; }
+
   bool
   do_numeric_constant_value(Numeric_constant* nc) const
   {
@@ -1422,6 +1426,10 @@ class Boolean_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_immutable() const
+  { return true; }
+
   Type*
   do_type();
 
@@ -1789,6 +1797,10 @@ class Integer_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_immutable() const
+  { return true; }
+
   bool
   do_numeric_constant_value(Numeric_constant* nc) const;
 
@@ -2108,6 +2120,10 @@ class Float_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_immutable() const
+  { return true; }
+
   bool
   do_numeric_constant_value(Numeric_constant* nc) const
   {
@@ -2291,6 +2307,10 @@ class Complex_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_immutable() const
+  { return true; }
+
   bool
   do_numeric_constant_value(Numeric_constant* nc) const
   {
@@ -2505,6 +2525,10 @@ class Const_expression : public Expression
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_immutable() const
+  { return true; }
+
   bool
   do_numeric_constant_value(Numeric_constant* nc) const;
 
@@ -2993,6 +3017,9 @@ class Type_conversion_expression : public Expression
   bool
   do_is_constant() const;
 
+  bool
+  do_is_immutable() const;
+
   bool
   do_numeric_constant_value(Numeric_constant*) const;
 
@@ -3175,6 +3202,27 @@ Type_conversion_expression::do_is_constant() const
   return true;
 }
 
+// Return whether a type conversion is immutable.
+
+bool
+Type_conversion_expression::do_is_immutable() const
+{
+  Type* type = this->type_;
+  Type* expr_type = this->expr_->type();
+
+  if (type->interface_type() != NULL
+      || expr_type->interface_type() != NULL)
+    return false;
+
+  if (!this->expr_->is_immutable())
+    return false;
+
+  if (Type::are_identical(type, expr_type, false, NULL))
+    return true;
+
+  return type->is_basic_type() && expr_type->is_basic_type();
+}
+
 // Return the constant numeric value if there is one.
 
 bool
@@ -3599,7 +3647,8 @@ class Unary_expression : public Expression
 
   bool
   do_is_immutable() const
-  { return this->expr_->is_immutable(); }
+  { return this->expr_->is_immutable()
+      || (this->op_ == OPERATOR_AND && this->expr_->is_variable()); }
 
   bool
   do_numeric_constant_value(Numeric_constant*) const;
@@ -14076,6 +14125,10 @@ class Type_info_expression : public Expression
   { }
 
  protected:
+  bool
+  do_is_immutable() const
+  { return true; }
+
   Type*
   do_type();
 
-- 
cgit v1.2.1