mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:41:27 +01:00
Shift Parser from 'Identifier' to 'Name' naming (#2947)
This PR renames parse nodes on a Name/NameExpression taxonomy. NameExpressions occur in a name context. The difference is that in non-expression contexts it's useful to return the identifier / string ID for adding to name lookup, whereas in expression contexts it's useful to return the resolved node ID for consistency with other expressions. In the code, I do note SelfValueName is returned in the expression context: I'd expect this to change, as `self` in `[self: Self]` versus `self.Foo()` will probably be best handled similarly to the above. That means that, in the proposed taxonomy, both `SelfValueName` and `SelfValueNameExpression` will exist in order to assist semantics. To contrast choices: Original | Current | [zygoloid suggestion](https://discord.com/channels/655572317891461132/655578254970716160/1121581663399464970) | [This PR](https://discord.com/channels/655572317891461132/655578254970716160/1121814551789318215) --- | --- | --- | --- DeclaredName/DesignatedName | Identifier | NameComponent | Name NameReference | NameReference | NameReference | NameExpression SelfValueIdentifier | SelfValueIdentifier | SelfValueReference | SelfValueName SelfTypeIdentifier | SelfTypeIdentiifer | SelfTypeReference | SelfTypeNameExpression
This commit is contained in:
@@ -46,7 +46,7 @@ auto SemanticsHandleDeducedParameterListStart(SemanticsContext& context,
|
||||
auto SemanticsHandleDesignatorExpression(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
auto name_id =
|
||||
context.node_stack().Pop<SemanticsStringId>(ParseNodeKind::Identifier);
|
||||
context.node_stack().Pop<SemanticsStringId>(ParseNodeKind::Name);
|
||||
|
||||
auto base_id = context.node_stack().Pop<SemanticsNodeId>();
|
||||
auto base = context.semantics_ir().GetNode(base_id);
|
||||
@@ -140,15 +140,6 @@ auto SemanticsHandleGenericPatternBinding(SemanticsContext& context,
|
||||
return context.TODO(parse_node, "GenericPatternBinding");
|
||||
}
|
||||
|
||||
auto SemanticsHandleIdentifier(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
auto name_str = context.parse_tree().GetNodeText(parse_node);
|
||||
auto name_id = context.semantics_ir().AddString(name_str);
|
||||
// The parent is responsible for binding the name.
|
||||
context.node_stack().Push(parse_node, name_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto SemanticsHandleInfixOperator(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
auto rhs_id = context.node_stack().Pop<SemanticsNodeId>();
|
||||
@@ -292,8 +283,17 @@ auto SemanticsHandleLiteral(SemanticsContext& context,
|
||||
return true;
|
||||
}
|
||||
|
||||
auto SemanticsHandleNameReference(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
auto SemanticsHandleName(SemanticsContext& context, ParseTree::Node parse_node)
|
||||
-> bool {
|
||||
auto name_str = context.parse_tree().GetNodeText(parse_node);
|
||||
auto name_id = context.semantics_ir().AddString(name_str);
|
||||
// The parent is responsible for binding the name.
|
||||
context.node_stack().Push(parse_node, name_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto SemanticsHandleNameExpression(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
auto name = context.parse_tree().GetNodeText(parse_node);
|
||||
context.node_stack().Push(parse_node, context.LookupName(parse_node, name));
|
||||
return true;
|
||||
@@ -381,7 +381,7 @@ auto SemanticsHandlePatternBinding(SemanticsContext& context,
|
||||
// Get the name.
|
||||
auto [name_node, name_id] =
|
||||
context.node_stack().PopWithParseNode<SemanticsStringId>(
|
||||
ParseNodeKind::Identifier);
|
||||
ParseNodeKind::Name);
|
||||
|
||||
// Allocate storage, linked to the name for error locations.
|
||||
auto storage_id =
|
||||
@@ -495,14 +495,14 @@ auto SemanticsHandleReturnType(SemanticsContext& context,
|
||||
return true;
|
||||
}
|
||||
|
||||
auto SemanticsHandleSelfTypeIdentifier(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleSelfTypeIdentifier");
|
||||
auto SemanticsHandleSelfTypeNameExpression(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleSelfTypeNameExpression");
|
||||
}
|
||||
|
||||
auto SemanticsHandleSelfValueIdentifier(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleSelfValueIdentifier");
|
||||
auto SemanticsHandleSelfValueName(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleSelfValueName");
|
||||
}
|
||||
|
||||
auto SemanticsHandleShortCircuitOperand(SemanticsContext& context,
|
||||
|
||||
Reference in New Issue
Block a user