mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 07:11:04 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user