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;
|
||||
|
||||
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 {
|
||||
|
|
|
@ -72,6 +72,20 @@ TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) {
|
|||
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) {
|
||||
auto ary = std::make_unique<IdentifierExpression>("ary");
|
||||
auto idx = std::make_unique<IdentifierExpression>("idx");
|
||||
|
|
|
@ -41,9 +41,7 @@ ElseStatement::~ElseStatement() = default;
|
|||
|
||||
bool ElseStatement::IsValid() const {
|
||||
for (const auto& stmt : body_) {
|
||||
if (stmt == nullptr)
|
||||
return false;
|
||||
if (!stmt->IsValid())
|
||||
if (stmt == nullptr || !stmt->IsValid())
|
||||
return false;
|
||||
}
|
||||
if (condition_)
|
||||
|
|
Loading…
Reference in New Issue