Support for base: T;, .base, x.base. (#3450)

No support for `extend base` yet, in an effort to minimize collisions
with #3412.
This commit is contained in:
Richard Smith
2023-12-04 22:45:59 +00:00
committed by GitHub
parent 30155dbb72
commit 7dffa0c7ec
34 changed files with 1088 additions and 74 deletions
+24 -5
View File
@@ -39,8 +39,7 @@ class NodeStack {
// Pushes a solo parse tree node onto the stack. Used when there is no
// IR generated by the node.
auto Push(Parse::NodeId parse_node) -> void {
CARBON_CHECK(ParseNodeKindToIdKind(parse_tree_->node_kind(parse_node)) ==
IdKind::SoloParseNode)
CARBON_CHECK(ParseNodeIdKind(parse_node) == IdKind::SoloParseNode)
<< "Parse kind expects an Id: " << parse_tree_->node_kind(parse_node);
CARBON_VLOG() << "Node Push " << stack_.size() << ": "
<< parse_tree_->node_kind(parse_node) << " -> <none>\n";
@@ -52,8 +51,7 @@ class NodeStack {
// Pushes a parse tree node onto the stack with an ID.
template <typename IdT>
auto Push(Parse::NodeId parse_node, IdT id) -> void {
CARBON_CHECK(ParseNodeKindToIdKind(parse_tree_->node_kind(parse_node)) ==
IdTypeToIdKind<IdT>())
CARBON_CHECK(ParseNodeIdKind(parse_node) == IdTypeToIdKind<IdT>())
<< "Parse kind expected a different IdT: "
<< parse_tree_->node_kind(parse_node) << " -> " << id << "\n";
CARBON_CHECK(id.is_valid()) << "Push called with invalid id: "
@@ -68,7 +66,14 @@ class NodeStack {
// Returns whether the node on the top of the stack is the specified kind.
template <Parse::NodeKind::RawEnumType RequiredParseKind>
auto PeekIs() const -> bool {
return parse_tree_->node_kind(PeekParseNode()) == RequiredParseKind;
return !stack_.empty() &&
parse_tree_->node_kind(PeekParseNode()) == RequiredParseKind;
}
// Returns whether the node on the top of the stack is a name.
auto PeekIsName() const -> bool {
return !stack_.empty() &&
ParseNodeIdKind(PeekParseNode()) == IdKind::NameId;
}
// Pops the top of the stack without any verification.
@@ -117,6 +122,12 @@ class NodeStack {
return PopWithParseNode<SemIR::InstId>();
}
// Pops a name from the top of the stack and returns the parse_node and
// the ID.
auto PopNameWithParseNode() -> std::pair<Parse::NodeId, SemIR::NameId> {
return PopWithParseNode<SemIR::NameId>();
}
// Pops the top of the stack and returns the parse_node and the ID.
template <Parse::NodeKind::RawEnumType RequiredParseKind>
auto PopWithParseNode() -> auto {
@@ -161,6 +172,9 @@ class NodeStack {
// Expressions map multiple Parse::NodeKinds to SemIR::InstId always.
auto PopExpr() -> SemIR::InstId { return PopExprWithParseNode().second; }
// Pops a name from the top of the stack and returns the ID.
auto PopName() -> SemIR::NameId { return PopNameWithParseNode().second; }
// Pops the top of the stack and returns the ID.
template <Parse::NodeKind::RawEnumType RequiredParseKind>
auto Pop() -> auto {
@@ -333,6 +347,7 @@ class NodeStack {
return IdKind::FunctionId;
case Parse::NodeKind::ClassDefinitionStart:
return IdKind::ClassId;
case Parse::NodeKind::BaseName:
case Parse::NodeKind::Name:
return IdKind::NameId;
case Parse::NodeKind::AbstractModifier:
@@ -360,6 +375,10 @@ class NodeStack {
}
}
auto ParseNodeIdKind(Parse::NodeId node) const -> IdKind {
return ParseNodeKindToIdKind(parse_tree_->node_kind(node));
}
// Translates an ID type to the enum ID kind for comparison with
// ParseNodeKindToIdKind.
template <typename IdT>