mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 17:01:04 +01:00
Semantic analysis for if expressions (#2893)
Add semantic analysis and semantics IR building for `if` expressions, and add the first parts of control flow handling to semantics IR. After discussion with @chandlerc, use [block arguments](https://en.wikipedia.org/wiki/Static_single-assignment_form#Block_arguments) to convey values from the two arms of the `if` to the result. For now, only a single block argument is supported, but we should revisit this as we explore more of the requirements of the Semantics IR form. Functions can now contain multiple code blocks, so grab the entry block up-front instead of assuming the entry block will be at the top of the block stack when we reach the end of function emission. Add trivial support for `bool` type literal, because without it we can't write testcases.
This commit is contained in:
@@ -61,7 +61,11 @@ auto SemanticsContext::VerifyOnFinish() -> void {
|
||||
}
|
||||
|
||||
auto SemanticsContext::AddNode(SemanticsNode node) -> SemanticsNodeId {
|
||||
auto block = node_block_stack_.PeekForAdd();
|
||||
return AddNodeToBlock(node_block_stack_.PeekForAdd(), node);
|
||||
}
|
||||
|
||||
auto SemanticsContext::AddNodeToBlock(SemanticsNodeBlockId block,
|
||||
SemanticsNode node) -> SemanticsNodeId {
|
||||
CARBON_VLOG() << "AddNode " << block << ": " << node << "\n";
|
||||
return semantics_ir_->AddNode(block, node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user