]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compiler: generate dummy names for blank-named constants.
authorIan Lance Taylor <ian@gcc.gnu.org>
Mon, 24 Jun 2013 23:12:48 +0000 (23:12 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Mon, 24 Jun 2013 23:12:48 +0000 (23:12 +0000)
Otherwise such const declarations are not checked.

From-SVN: r200381

gcc/go/gofrontend/gogo-tree.cc
gcc/go/gofrontend/gogo.h
gcc/go/gofrontend/parse.cc

index 06fd4f0bb2291ff572a93a5c04ca8e780af61ddb..a1fe5fec7ca6e77d8a1af6da2e8e960ad70c1eec 100644 (file)
@@ -814,6 +814,15 @@ Gogo::write_globals()
          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 @@ Gogo::write_globals()
            }
        }
 
-      // 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);
index 7f55470a3fe36e5d3279a9dc4be7110f86ea5e63..b6e9e45a1cb4ae8a25274a111c6761824018cad2 100644 (file)
@@ -1687,7 +1687,7 @@ class Named_constant
   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 @@ class Named_constant
   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 @@ class Named_constant
   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.
index b562a78ad00e982fc9de0f2dfed416cd5f6b81ba..0a67bbe40605668a6f2782417f3467b39f2e8d55 100644 (file)
@@ -1457,6 +1457,16 @@ Parse::const_spec(Type** last_type, Expression_list** last_expr_list)
 
       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");