Clean up interface of node block stack after recent changes. (#3229)

- `Peek()` no longer returns a useful value, because we often don't
allocate a `NodeBlockId` until we finish building the block. Remove it
and update both its callers.
- Rename `PeekForAdd()` to `PeekOrAdd()` since it's no longer used to
get a block ID to add elements into.
- `PushForAdd()` was unused. Remove it.
- Add `NodeBlockStack::AddNode` to combine the operations of adding a
node and inserting it into a block.
This commit is contained in:
Richard Smith authored and GitHub committed 2023-09-14 16:05:05 +00:00
1 parent e81d171226
commit 85d5b40429
7 files changed
+50 -52

No files matched your search

+1 -2
View File
@@ -22,13 +22,12 @@ auto NodeBlockStack::Push(SemIR::NodeBlockId id) -> void {
++size_;
}
auto NodeBlockStack::PeekForAdd(int depth) -> SemIR::NodeBlockId {
auto NodeBlockStack::PeekOrAdd(int depth) -> SemIR::NodeBlockId {
CARBON_CHECK(size() > depth) << "no such block";
int index = size() - depth - 1;
auto& slot = stack_[index];
if (!slot.id.is_valid()) {
slot.id = semantics_ir_->AddNodeBlockId();
CARBON_VLOG() << name_ << " Add " << index << ": " << slot.id << "\n";
}
return slot.id;
}