(alias string, expr dag.Expr)
| 543 | } |
| 544 | |
| 545 | func pullupExpr(alias string, expr dag.Expr) (dag.Expr, bool) { |
| 546 | e, ok := expr.(*dag.BinaryExpr) |
| 547 | if !ok { |
| 548 | return nil, false |
| 549 | } |
| 550 | if e.Op == "and" { |
| 551 | lhs, lok := pullupExpr(alias, e.LHS) |
| 552 | rhs, rok := pullupExpr(alias, e.RHS) |
| 553 | if !lok || !rok { |
| 554 | return nil, false |
| 555 | } |
| 556 | return dag.NewBinaryExpr("and", lhs, rhs), true |
| 557 | } |
| 558 | if e.Op == "or" { |
| 559 | lhs, lok := pullupExpr(alias, e.LHS) |
| 560 | rhs, rok := pullupExpr(alias, e.RHS) |
| 561 | if !lok || !rok { |
| 562 | return nil, false |
| 563 | } |
| 564 | return dag.NewBinaryExpr("or", lhs, rhs), true |
| 565 | |
| 566 | } |
| 567 | var c dag.Expr |
| 568 | var this *dag.ThisExpr |
| 569 | if t, ok := e.LHS.(*dag.ThisExpr); ok && isConst(e.RHS) { |
| 570 | this, c = t, e.RHS |
| 571 | } else if t, ok := e.RHS.(*dag.ThisExpr); ok && isConst(e.LHS) { |
| 572 | this, c = t, e.LHS |
| 573 | } |
| 574 | if c == nil || this == nil || len(this.Path) < 1 || this.Path[0] != alias { |
| 575 | return nil, false |
| 576 | } |
| 577 | path := slices.Clone(this.Path[1:]) |
| 578 | return dag.NewBinaryExpr(e.Op, dag.NewThis(path), c), true |
| 579 | } |
| 580 | |
| 581 | func isConst(e dag.Expr) bool { |
| 582 | switch e := e.(type) { |
no test coverage detected