mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Semantics IR building for if statements. (#2920)
This follows the same structure as `if` expressions, except that no result value is needed. Semantics IR building for code blocks is also added. Rather than popping all the node stack entries we push for statements within a code block, change statements and declarations to not push themselves onto the stack. We're not notionally performing work recursively within prior statements, and we don't need their value for anything, so it seems cleaner to not push them. This also allows statements and declarations to determine what syntactic context they're in by peeking at the top of the stack, though that's not used in this patch.
This commit is contained in:
@@ -22,16 +22,6 @@ auto SemanticsHandleBreakStatementStart(SemanticsContext& context,
|
||||
return context.TODO(parse_node, "HandleBreakStatementStart");
|
||||
}
|
||||
|
||||
auto SemanticsHandleCodeBlock(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleCodeBlock");
|
||||
}
|
||||
|
||||
auto SemanticsHandleCodeBlockStart(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleCodeBlockStart");
|
||||
}
|
||||
|
||||
auto SemanticsHandleContinueStatement(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleContinueStatement");
|
||||
@@ -119,21 +109,19 @@ auto SemanticsHandleDesignatorExpression(SemanticsContext& context,
|
||||
return true;
|
||||
}
|
||||
|
||||
auto SemanticsHandleEmptyDeclaration(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
// Empty declarations have no actions associated, but we still balance the
|
||||
// tree.
|
||||
context.node_stack().Push(parse_node);
|
||||
auto SemanticsHandleEmptyDeclaration(SemanticsContext& /*context*/,
|
||||
ParseTree::Node /*parse_node*/) -> bool {
|
||||
// Empty declarations have no actions associated.
|
||||
return true;
|
||||
}
|
||||
|
||||
auto SemanticsHandleExpressionStatement(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
ParseTree::Node /*parse_node*/)
|
||||
-> bool {
|
||||
// Pop the expression without investigating its contents.
|
||||
// TODO: This will probably eventually need to do some "do not discard"
|
||||
// analysis.
|
||||
context.node_stack().PopAndDiscardId();
|
||||
context.node_stack().Push(parse_node);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -168,26 +156,6 @@ auto SemanticsHandleGenericPatternBinding(SemanticsContext& context,
|
||||
return context.TODO(parse_node, "GenericPatternBinding");
|
||||
}
|
||||
|
||||
auto SemanticsHandleIfCondition(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleIfCondition");
|
||||
}
|
||||
|
||||
auto SemanticsHandleIfConditionStart(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleIfConditionStart");
|
||||
}
|
||||
|
||||
auto SemanticsHandleIfStatement(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleIfStatement");
|
||||
}
|
||||
|
||||
auto SemanticsHandleIfStatementElse(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleIfStatementElse");
|
||||
}
|
||||
|
||||
auto SemanticsHandleInfixOperator(SemanticsContext& context,
|
||||
ParseTree::Node parse_node) -> bool {
|
||||
auto rhs_id = context.node_stack().Pop<SemanticsNodeId>();
|
||||
@@ -484,7 +452,7 @@ auto SemanticsHandleReturnStatement(SemanticsContext& context,
|
||||
.Emit();
|
||||
}
|
||||
|
||||
context.AddNodeAndPush(parse_node, SemanticsNode::Return::Make(parse_node));
|
||||
context.AddNode(SemanticsNode::Return::Make(parse_node));
|
||||
} else {
|
||||
auto arg = context.node_stack().Pop<SemanticsNodeId>();
|
||||
context.node_stack().PopAndDiscardSoloParseNode(
|
||||
@@ -505,10 +473,8 @@ auto SemanticsHandleReturnStatement(SemanticsContext& context,
|
||||
context.ImplicitAsRequired(parse_node, arg, callable.return_type_id);
|
||||
}
|
||||
|
||||
context.AddNodeAndPush(
|
||||
parse_node,
|
||||
SemanticsNode::ReturnExpression::Make(
|
||||
parse_node, context.semantics_ir().GetNode(arg).type_id(), arg));
|
||||
context.AddNode(SemanticsNode::ReturnExpression::Make(
|
||||
parse_node, context.semantics_ir().GetNode(arg).type_id(), arg));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -634,7 +600,6 @@ auto SemanticsHandleVariableDeclaration(SemanticsContext& context,
|
||||
|
||||
context.node_stack().PopAndDiscardSoloParseNode(
|
||||
ParseNodeKind::VariableIntroducer);
|
||||
context.node_stack().Push(parse_node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user