tint: Make ForEachElemPair return value an enum instead of a bool
Bug: tint:1581 Change-Id: Ia16a548c03f7dff4ebc45599e20c0004834da6ae Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/102121 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
e53b6f9502
commit
0dfbaa9ef9
|
@ -3111,11 +3111,13 @@ std::ostream& operator<<(std::ostream& o, const Types& types) {
|
|||
return o;
|
||||
}
|
||||
|
||||
// Calls `f` on deepest elements of both `a` and `b`. If function returns false, it stops
|
||||
// traversing, and return false, otherwise it continues and returns true.
|
||||
// Calls `f` on deepest elements of both `a` and `b`. If function returns Action::kStop, it stops
|
||||
// traversing, and return Action::kStop; if the function returns Action::kContinue, it continues and
|
||||
// returns Action::kContinue when done.
|
||||
// TODO(amaiorano): Move to Constant.h?
|
||||
enum class Action { kStop, kContinue };
|
||||
template <typename Func>
|
||||
bool ForEachElemPair(const sem::Constant* a, const sem::Constant* b, Func&& f) {
|
||||
Action ForEachElemPair(const sem::Constant* a, const sem::Constant* b, Func&& f) {
|
||||
EXPECT_EQ(a->Type(), b->Type());
|
||||
size_t i = 0;
|
||||
while (true) {
|
||||
|
@ -3124,15 +3126,15 @@ bool ForEachElemPair(const sem::Constant* a, const sem::Constant* b, Func&& f) {
|
|||
break;
|
||||
}
|
||||
auto* b_elem = b->Index(i);
|
||||
if (!ForEachElemPair(a_elem, b_elem, f)) {
|
||||
return false;
|
||||
if (ForEachElemPair(a_elem, b_elem, f) == Action::kStop) {
|
||||
return Action::kStop;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (i == 0) {
|
||||
return f(a, b);
|
||||
}
|
||||
return true;
|
||||
return Action::kContinue;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -3209,7 +3211,7 @@ TEST_P(ResolverConstEvalUnaryOpTest, Test) {
|
|||
// data in the MSBs that are outside of the bit-width of T.
|
||||
EXPECT_EQ(a->As<AInt>(), b->As<AInt>());
|
||||
}
|
||||
return !HasFailure();
|
||||
return HasFailure() ? Action::kStop : Action::kContinue;
|
||||
});
|
||||
},
|
||||
c.expected);
|
||||
|
@ -3390,7 +3392,7 @@ TEST_P(ResolverConstEvalBinaryOpTest, Test) {
|
|||
// data in the MSBs that are outside of the bit-width of T.
|
||||
EXPECT_EQ(a->As<AInt>(), b->As<AInt>());
|
||||
}
|
||||
return !HasFailure();
|
||||
return HasFailure() ? Action::kStop : Action::kContinue;
|
||||
});
|
||||
},
|
||||
c.expected);
|
||||
|
@ -3859,7 +3861,7 @@ TEST_F(ResolverConstEvalTest, NotAndOrOfVecs) {
|
|||
|
||||
ForEachElemPair(value, expected_value, [&](const sem::Constant* a, const sem::Constant* b) {
|
||||
EXPECT_EQ(a->As<bool>(), b->As<bool>());
|
||||
return !HasFailure();
|
||||
return HasFailure() ? Action::kStop : Action::kContinue;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue