Patchwork Go patch committed: Check _ constant declarations

login
register
mail settings
Submitter Ian Taylor
Date June 24, 2013, 11:13 p.m.
Message ID <mcrtxknksq3.fsf@iant-glaptop.roam.corp.google.com>
Download mbox | patch
Permalink /patch/253989/
State New
Headers show

Comments

Ian Taylor - June 24, 2013, 11:13 p.m.
This patch to the Go frontend, from Rémy Oudompheng, checks the
constants named _ are valid.  Such constants are discarded but the
values should still be checked.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline and 4.8 branch.

Ian

Patch

diff -r 49a130a849da go/gogo-tree.cc
--- a/go/gogo-tree.cc	Mon Jun 24 15:07:14 2013 -0700
+++ b/go/gogo-tree.cc	Mon Jun 24 15:55:28 2013 -0700
@@ -814,6 +814,15 @@ 
 	  continue;
 	}
 
+      // Skip blank named functions and constants.
+      if ((no->is_function() && no->func_value()->is_sink())
+	  || (no->is_const() && no->const_value()->is_sink()))
+        {
+          --i;
+          --count;
+          continue;
+        }
+
       // There is nothing useful we can output for constants which
       // have ideal or non-integral type.
       if (no->is_const())
@@ -829,14 +838,6 @@ 
 	    }
 	}
 
-      // Skip blank named functions.
-      if (no->is_function() && no->func_value()->is_sink())
-        {
-          --i;
-          --count;
-          continue;
-        }
-
       if (!no->is_variable())
 	{
 	  vec[i] = no->get_tree(this, NULL);
diff -r 49a130a849da go/gogo.h
--- a/go/gogo.h	Mon Jun 24 15:07:14 2013 -0700
+++ b/go/gogo.h	Mon Jun 24 15:55:28 2013 -0700
@@ -1687,7 +1687,7 @@ 
   Named_constant(Type* type, Expression* expr, int iota_value,
 		 Location location)
     : type_(type), expr_(expr), iota_value_(iota_value), location_(location),
-      lowering_(false)
+      lowering_(false), is_sink_(false)
   { }
 
   Type*
@@ -1721,6 +1721,14 @@ 
   clear_lowering()
   { this->lowering_ = false; }
 
+  bool
+  is_sink() const
+  { return this->is_sink_; }
+
+  void
+  set_is_sink()
+  { this->is_sink_ = true; }
+
   // Traverse the expression.
   int
   traverse_expression(Traverse*);
@@ -1756,6 +1764,8 @@ 
   Location location_;
   // Whether we are currently lowering this constant.
   bool lowering_;
+  // Whether this constant is blank named and needs only type checking.
+  bool is_sink_;
 };
 
 // A type declaration.
diff -r 49a130a849da go/parse.cc
--- a/go/parse.cc	Mon Jun 24 15:07:14 2013 -0700
+++ b/go/parse.cc	Mon Jun 24 15:55:28 2013 -0700
@@ -1457,6 +1457,16 @@ 
 
       if (!Gogo::is_sink_name(pi->name()))
 	this->gogo_->add_constant(*pi, *pe, this->iota_value());
+      else
+	{
+	  static int count;
+	  char buf[30];
+	  snprintf(buf, sizeof buf, ".$sinkconst%d", count);
+	  ++count;
+	  Typed_identifier ti(std::string(buf), type, pi->location());
+	  Named_object* no = this->gogo_->add_constant(ti, *pe, this->iota_value());
+	  no->const_value()->set_is_sink();
+	}
     }
   if (pe != expr_list->end())
     error_at(this->location(), "too many initializers");