mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 07:11:04 +01:00
Refactor declaration name context logic to its own class. (#2989)
This started with cleaning up the remaining Name/expression type punning in the node stack, and grew. I'm factoring out a class because we've previously expressed the desire to factor logic out of SemanticsContext where possible, and this seemed like a reasonable cut. NameExpression as the first node as a QualifiedExpression allows the qualifier handling to consider Name in one less spot, an incremental simplification. However, the additional complexity caused by this makes me split ApplyNameQualifier/ApplyExpressionQualifier in order to avoid repeat checks of the parse node's kind. The logic is still largely shared, thus a couple helper functions. I think this is all fairly well structured in the isolated class. I can see that we may want to avoid passing SemanticsContext as an argument in the future if it elides a step of lookup.
This commit is contained in:
@@ -82,7 +82,8 @@ class SemanticsNodeStack {
|
||||
PopForSoloParseNode<RequiredParseKind>();
|
||||
}
|
||||
|
||||
// Pops the top of the stack and returns the parse_node and the ID.
|
||||
// Pops an expression from the top of the stack and returns the parse_node and
|
||||
// the ID.
|
||||
auto PopExpressionWithParseNode()
|
||||
-> std::pair<ParseTree::Node, SemanticsNodeId> {
|
||||
return PopWithParseNode<SemanticsNodeId>();
|
||||
@@ -325,12 +326,6 @@ class SemanticsNodeStack {
|
||||
|
||||
// Require a ParseNodeKind be mapped to a particular IdKind.
|
||||
auto RequireIdKind(ParseNodeKind parse_kind, IdKind id_kind) -> void {
|
||||
// TODO: Name can be popped as a node_id by declaration name handling. Will
|
||||
// refactor to remove this quirk.
|
||||
if (parse_kind == ParseNodeKind::Name &&
|
||||
id_kind == IdKind::SemanticsNodeId) {
|
||||
return;
|
||||
}
|
||||
CARBON_CHECK(ParseNodeKindToIdKind(parse_kind) == id_kind)
|
||||
<< "Unexpected IdKind mapping for " << parse_kind;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user