mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Refactor InstBlockStack to use ArrayStack. (#4104)
The use of ArrayStack here is intended to simplify the logic, and also make better use of the inst heap allocations. Prior changes #4101 and #4103 removed the less related logic from InstBlockStack, although #4103 is the actual part that blocked using ArrayStack. BTW, note the PrintForStackDump implementation was incorrect because it didn't apply size_. This simplification fixes the issue.
This commit is contained in:
@@ -73,5 +73,35 @@ TEST(ArrayStack, Basics) {
|
||||
EXPECT_THAT(stack.PeekAllValues(), ElementsAre(5));
|
||||
}
|
||||
|
||||
TEST(ArrayStack, AppendArray) {
|
||||
ArrayStack<int> stack;
|
||||
|
||||
stack.PushArray();
|
||||
stack.AppendToTop(llvm::ArrayRef<int>());
|
||||
EXPECT_THAT(stack.PeekArray(), IsEmpty());
|
||||
stack.AppendToTop({1, 2});
|
||||
EXPECT_THAT(stack.PeekArray(), ElementsAre(1, 2));
|
||||
}
|
||||
|
||||
TEST(ArrayStack, PeekArrayAt) {
|
||||
ArrayStack<int> stack;
|
||||
|
||||
// Verify behavior with a single array.
|
||||
stack.PushArray();
|
||||
stack.AppendToTop(1);
|
||||
stack.AppendToTop(2);
|
||||
|
||||
EXPECT_THAT(stack.PeekArrayAt(0), ElementsAre(1, 2));
|
||||
|
||||
// Verify behavior with a couple more arrays.
|
||||
stack.PushArray();
|
||||
stack.PushArray();
|
||||
stack.AppendToTop(3);
|
||||
|
||||
EXPECT_THAT(stack.PeekArrayAt(0), ElementsAre(1, 2));
|
||||
EXPECT_THAT(stack.PeekArrayAt(1), IsEmpty());
|
||||
EXPECT_THAT(stack.PeekArrayAt(2), ElementsAre(3));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace Carbon::Testing
|
||||
|
||||
Reference in New Issue
Block a user