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:
Jon Ross-Perkins
2023-07-17 21:55:29 +00:00
committed by GitHub
parent 43065a1257
commit 446b0ce4ae
14 changed files with 399 additions and 294 deletions
+7 -7
View File
@@ -70,7 +70,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(PackageDirective, PackageIntroducer)
// `namespace`:
// NamespaceStart
// _external_: Identifier or QualifiedDeclaration
// _external_: Name or QualifiedDeclaration
// Namespace
CARBON_PARSE_NODE_KIND_CHILD_COUNT(NamespaceStart, 0)
CARBON_PARSE_NODE_KIND_CHILD_COUNT(Namespace, 2)
@@ -84,7 +84,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart)
// `fn`:
// FunctionIntroducer
// _external_: Identifier or QualifiedDeclaration
// _external_: Name or QualifiedDeclaration
// _external_: ParameterList
// _external_: type expression
// ReturnType
@@ -241,8 +241,8 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpressionComma, 0)
CARBON_PARSE_NODE_KIND_BRACKET(CallExpression, CallExpressionStart)
// A qualified declaration, such as `a.b`:
// _external_: Identifier or QualifiedDeclaration
// _external_: Identifier
// _external_: NameExpression or QualifiedDeclaration
// _external_: Name
// QualifiedDeclaration
//
// TODO: This will eventually more general expressions, for example with
@@ -329,7 +329,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral,
// `class`:
// ClassIntroducer
// _external_: Identifier or QualifiedDeclaration
// _external_: Name or QualifiedDeclaration
// ClassDefinitionStart
// _external_: declarations
// ClassDefinition
@@ -344,7 +344,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(ClassDeclaration, ClassIntroducer)
// `interface`:
// InterfaceIntroducer
// _external_: Identifier or QualifiedDeclaration
// _external_: Name or QualifiedDeclaration
// InterfaceDefinitionStart
// _external_: declarations
// InterfaceDefinition
@@ -359,7 +359,7 @@ CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDeclaration, InterfaceIntroducer)
// `constraint`:
// NamedConstraintIntroducer
// _external_: Identifier or QualifiedDeclaration
// _external_: Name or QualifiedDeclaration
// NamedConstraintDefinitionStart
// _external_: declarations
// NamedConstraintDefinition