mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:01:14 +01:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user