Parsing, semantic analysis, and lowering for and, or, not. (#2897)

Lowering for `and` and `or` is not yet complete because `Branch` lowering isn't done yet.
This commit is contained in:
Richard Smith
2023-06-14 13:03:13 -07:00
committed by GitHub
parent 8b1e820848
commit 06ce3b0161
28 changed files with 470 additions and 55 deletions
@@ -140,8 +140,9 @@ auto ParserHandleExpressionInPostfixLoop(ParserContext& context) -> void {
auto ParserHandleExpressionLoop(ParserContext& context) -> void {
auto state = context.PopState();
auto operator_kind = context.PositionKind();
auto trailing_operator = PrecedenceGroup::ForTrailing(
context.PositionKind(), context.IsTrailingOperatorInfix());
operator_kind, context.IsTrailingOperatorInfix());
if (!trailing_operator) {
if (state.has_error) {
context.ReturnErrorOnState();
@@ -181,6 +182,13 @@ auto ParserHandleExpressionLoop(ParserContext& context) -> void {
state.lhs_precedence = operator_precedence;
if (is_binary) {
if (operator_kind == TokenKind::And || operator_kind == TokenKind::Or) {
// For `and` and `or`, wrap the first operand in a virtual parse tree
// node so that semantics can insert control flow here.
context.AddNode(ParseNodeKind::ShortCircuitOperand, state.token,
state.subtree_start, state.has_error);
}
state.state = ParserState::ExpressionLoopForBinary;
context.PushState(state);
context.PushStateForExpression(operator_precedence);