Commit e7f160c4 by Ian Lance Taylor

Set type of array length expressions.

From-SVN: r170460
parent 67e18edb
...@@ -4287,6 +4287,10 @@ Array_type::verify_length() ...@@ -4287,6 +4287,10 @@ Array_type::verify_length()
{ {
if (this->length_ == NULL) if (this->length_ == NULL)
return true; return true;
Type_context context(Type::lookup_integer_type("int"), false);
this->length_->determine_type(&context);
if (!this->length_->is_constant()) if (!this->length_->is_constant())
{ {
error_at(this->length_->location(), "array bound is not constant"); error_at(this->length_->location(), "array bound is not constant");
...@@ -4294,30 +4298,23 @@ Array_type::verify_length() ...@@ -4294,30 +4298,23 @@ Array_type::verify_length()
} }
mpz_t val; mpz_t val;
mpz_init(val);
Type* t = this->length_->type(); Type* vt;
if (t->integer_type() != NULL) if (!this->length_->integer_constant_value(true, val, &vt))
{ {
Type* vt;
mpz_init(val);
if (!this->length_->integer_constant_value(true, val, &vt))
{
error_at(this->length_->location(),
"array bound is not constant");
mpz_clear(val);
return false;
}
}
else if (t->float_type() != NULL)
{
Type* vt;
mpfr_t fval; mpfr_t fval;
mpfr_init(fval); mpfr_init(fval);
if (!this->length_->float_constant_value(fval, &vt)) if (!this->length_->float_constant_value(fval, &vt))
{ {
error_at(this->length_->location(), if (this->length_->type()->integer_type() != NULL
"array bound is not constant"); || this->length_->type()->float_type() != NULL)
error_at(this->length_->location(),
"array bound is not constant");
else
error_at(this->length_->location(),
"array bound is not numeric");
mpfr_clear(fval); mpfr_clear(fval);
mpz_clear(val);
return false; return false;
} }
if (!mpfr_integer_p(fval)) if (!mpfr_integer_p(fval))
...@@ -4325,18 +4322,13 @@ Array_type::verify_length() ...@@ -4325,18 +4322,13 @@ Array_type::verify_length()
error_at(this->length_->location(), error_at(this->length_->location(),
"array bound truncated to integer"); "array bound truncated to integer");
mpfr_clear(fval); mpfr_clear(fval);
mpz_clear(val);
return false; return false;
} }
mpz_init(val); mpz_init(val);
mpfr_get_z(val, fval, GMP_RNDN); mpfr_get_z(val, fval, GMP_RNDN);
mpfr_clear(fval); mpfr_clear(fval);
} }
else
{
if (!t->is_error_type())
error_at(this->length_->location(), "array bound is not numeric");
return false;
}
if (mpz_sgn(val) < 0) if (mpz_sgn(val) < 0)
{ {
......
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