summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-06-24 23:12:48 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-06-24 23:12:48 +0000
commit7f54d14c3565845971c9e6923196fa4bce9bd1ff (patch)
treea88cc41a00ede1709b36f5548ae84ef02a6923cf
parent0afbb93790d2c7f3f3699ba58f6eb0faef54211b (diff)
downloadgcc-7f54d14c3565845971c9e6923196fa4bce9bd1ff.tar.gz
compiler: generate dummy names for blank-named constants.
Otherwise such const declarations are not checked. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@200381 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/go/gofrontend/gogo-tree.cc17
-rw-r--r--gcc/go/gofrontend/gogo.h12
-rw-r--r--gcc/go/gofrontend/parse.cc10
3 files changed, 30 insertions, 9 deletions
diff --git a/gcc/go/gofrontend/gogo-tree.cc b/gcc/go/gofrontend/gogo-tree.cc
index 06fd4f0bb22..a1fe5fec7ca 100644
--- a/gcc/go/gofrontend/gogo-tree.cc
+++ b/gcc/go/gofrontend/gogo-tree.cc
@@ -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);
diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h
index 7f55470a3fe..b6e9e45a1cb 100644
--- a/gcc/go/gofrontend/gogo.h
+++ b/gcc/go/gofrontend/gogo.h
@@ -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.
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index b562a78ad00..0a67bbe4060 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -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");