Commit fe7144f4 by Ian Lance Taylor

compiler: generate dummy names for blank-named constants.

Otherwise such const declarations are not checked.

From-SVN: r200381
parent 571d3f91
......@@ -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);
......
......@@ -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.
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment