Extend array accessor validity checks
This Cl extends the array accessor to verify the sub expressions are also valid. Bug: tint:11 Change-Id: Ieaa9643e07deaa8c406743c3bbb6fbe3ca9cb1ef Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/16467 Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com> Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
adb80f005a
commit
18747b657a
|
@ -35,7 +35,12 @@ ArrayAccessorExpression::ArrayAccessorExpression(
|
||||||
ArrayAccessorExpression::~ArrayAccessorExpression() = default;
|
ArrayAccessorExpression::~ArrayAccessorExpression() = default;
|
||||||
|
|
||||||
bool ArrayAccessorExpression::IsValid() const {
|
bool ArrayAccessorExpression::IsValid() const {
|
||||||
return array_ != nullptr && idx_expr_ != nullptr;
|
if (array_ == nullptr || !array_->IsValid())
|
||||||
|
return false;
|
||||||
|
if (idx_expr_ == nullptr || !idx_expr_->IsValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrayAccessorExpression::to_str(std::ostream& out, size_t indent) const {
|
void ArrayAccessorExpression::to_str(std::ostream& out, size_t indent) const {
|
||||||
|
|
|
@ -72,6 +72,20 @@ TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) {
|
||||||
EXPECT_FALSE(exp.IsValid());
|
EXPECT_FALSE(exp.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidArray) {
|
||||||
|
auto ary = std::make_unique<IdentifierExpression>("");
|
||||||
|
auto idx = std::make_unique<IdentifierExpression>("idx");
|
||||||
|
ArrayAccessorExpression exp(std::move(ary), std::move(idx));
|
||||||
|
EXPECT_FALSE(exp.IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidIndex) {
|
||||||
|
auto ary = std::make_unique<IdentifierExpression>("ary");
|
||||||
|
auto idx = std::make_unique<IdentifierExpression>("");
|
||||||
|
ArrayAccessorExpression exp(std::move(ary), std::move(idx));
|
||||||
|
EXPECT_FALSE(exp.IsValid());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ArrayAccessorExpressionTest, ToStr) {
|
TEST_F(ArrayAccessorExpressionTest, ToStr) {
|
||||||
auto ary = std::make_unique<IdentifierExpression>("ary");
|
auto ary = std::make_unique<IdentifierExpression>("ary");
|
||||||
auto idx = std::make_unique<IdentifierExpression>("idx");
|
auto idx = std::make_unique<IdentifierExpression>("idx");
|
||||||
|
|
|
@ -41,9 +41,7 @@ ElseStatement::~ElseStatement() = default;
|
||||||
|
|
||||||
bool ElseStatement::IsValid() const {
|
bool ElseStatement::IsValid() const {
|
||||||
for (const auto& stmt : body_) {
|
for (const auto& stmt : body_) {
|
||||||
if (stmt == nullptr)
|
if (stmt == nullptr || !stmt->IsValid())
|
||||||
return false;
|
|
||||||
if (!stmt->IsValid())
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (condition_)
|
if (condition_)
|
||||||
|
|
Loading…
Reference in New Issue