Refactor the node stack into its own class. (#2505)

Currently, there's a mix of accessing node_stack_ both directly and indirectly, and there are already several Push/Pop methods to help wrap the behavior. However, there's also direct access because of shifting over time, as well as variations in _how_ the stack is used.

This migrates to a separate class in order to make a more specific contract for the API. It cleans up existing uses and adds APIs where needed.
This commit is contained in:
Jon Ross-Perkins
2023-01-05 15:16:05 -08:00
committed by GitHub
parent 78ac6cb7d1
commit 2a163ca6cd
8 changed files with 419 additions and 228 deletions
+20 -5
View File
@@ -28,31 +28,46 @@ struct SemanticsNodeId : public IndexBase {
static auto MakeInvalid() -> SemanticsNodeId { return SemanticsNodeId(); }
using IndexBase::IndexBase;
auto Print(llvm::raw_ostream& out) const -> void { out << "node" << index; }
auto Print(llvm::raw_ostream& out) const -> void {
out << "node";
IndexBase::Print(out);
}
};
// The ID of a cross-referenced IR.
struct SemanticsCrossReferenceIRId : public IndexBase {
using IndexBase::IndexBase;
auto Print(llvm::raw_ostream& out) const -> void { out << "ir" << index; }
auto Print(llvm::raw_ostream& out) const -> void {
out << "ir";
IndexBase::Print(out);
}
};
// Type-safe storage of integer literals.
struct SemanticsIntegerLiteralId : public IndexBase {
using IndexBase::IndexBase;
auto Print(llvm::raw_ostream& out) const -> void { out << "int" << index; }
auto Print(llvm::raw_ostream& out) const -> void {
out << "int";
IndexBase::Print(out);
}
};
// Type-safe storage of node blocks.
struct SemanticsNodeBlockId : public IndexBase {
using IndexBase::IndexBase;
auto Print(llvm::raw_ostream& out) const -> void { out << "block" << index; }
auto Print(llvm::raw_ostream& out) const -> void {
out << "block";
IndexBase::Print(out);
}
};
// Type-safe storage of strings.
struct SemanticsStringId : public IndexBase {
using IndexBase::IndexBase;
auto Print(llvm::raw_ostream& out) const -> void { out << "str" << index; }
auto Print(llvm::raw_ostream& out) const -> void {
out << "str";
IndexBase::Print(out);
}
};
// The standard structure for nodes.