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:
Richard Smith
2023-06-16 20:10:33 -07:00
committed by GitHub
parent 2ae8117d62
commit 1ea123cd94
13 changed files with 448 additions and 59 deletions
@@ -0,0 +1,24 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/semantics/semantics_context.h"
#include "toolchain/semantics/semantics_node.h"
namespace Carbon {
auto SemanticsHandleCodeBlockStart(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
context.node_stack().Push(parse_node);
context.PushScope();
return true;
}
auto SemanticsHandleCodeBlock(SemanticsContext& context,
ParseTree::Node /*parse_node*/) -> bool {
context.PopScope();
context.node_stack().PopForSoloParseNode(ParseNodeKind::CodeBlockStart);
return true;
}
} // namespace Carbon