public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch commited: Mark various expressions as immutable
@ 2014-04-17 19:18 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2014-04-17 19:18 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 248 bytes --]

This patch from Chris Manghane marks various expression types as
immutable: numerics, constants, type info, address of, type conversion
when appropriate.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2490 bytes --]

diff -r 194e0f47c9e5 go/expressions.cc
--- a/go/expressions.cc	Wed Apr 16 13:33:13 2014 -0700
+++ b/go/expressions.cc	Thu Apr 17 11:57:28 2014 -0700
@@ -555,6 +555,10 @@
   { return true; }
 
   bool
+  do_is_immutable() const
+  { return true; }
+
+  bool
   do_numeric_constant_value(Numeric_constant* nc) const
   {
     nc->set_unsigned_long(NULL, 0);
@@ -1422,6 +1426,10 @@
   do_is_constant() const
   { return true; }
 
+  bool
+  do_is_immutable() const
+  { return true; }
+
   Type*
   do_type();
 
@@ -1790,6 +1798,10 @@
   { return true; }
 
   bool
+  do_is_immutable() const
+  { return true; }
+
+  bool
   do_numeric_constant_value(Numeric_constant* nc) const;
 
   Type*
@@ -2109,6 +2121,10 @@
   { return true; }
 
   bool
+  do_is_immutable() const
+  { return true; }
+
+  bool
   do_numeric_constant_value(Numeric_constant* nc) const
   {
     nc->set_float(this->type_, this->val_);
@@ -2292,6 +2308,10 @@
   { return true; }
 
   bool
+  do_is_immutable() const
+  { return true; }
+
+  bool
   do_numeric_constant_value(Numeric_constant* nc) const
   {
     nc->set_complex(this->type_, this->real_, this->imag_);
@@ -2506,6 +2526,10 @@
   { return true; }
 
   bool
+  do_is_immutable() const
+  { return true; }
+
+  bool
   do_numeric_constant_value(Numeric_constant* nc) const;
 
   bool
@@ -2994,6 +3018,9 @@
   do_is_constant() const;
 
   bool
+  do_is_immutable() const;
+
+  bool
   do_numeric_constant_value(Numeric_constant*) const;
 
   bool
@@ -3175,6 +3202,27 @@
   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 @@
 
   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 @@
   { }
 
  protected:
+  bool
+  do_is_immutable() const
+  { return true; }
+
   Type*
   do_type();
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-04-17 19:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-17 19:18 Go patch commited: Mark various expressions as immutable Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).