| 548 | } |
| 549 | |
| 550 | func newBinaryOperation(op Operator, lhs, rhs FieldExpression) FieldExpression { |
| 551 | binop := &BinaryOperation{ |
| 552 | Op: op, |
| 553 | LHS: lhs, |
| 554 | RHS: rhs, |
| 555 | } |
| 556 | |
| 557 | if attr, ok := lhs.(Attribute); ok && attr.Intrinsic == IntrinsicTraceID { |
| 558 | if static, ok := rhs.(Static); ok { |
| 559 | binop.RHS = normalizeTraceIDOperand(static) |
| 560 | } |
| 561 | } |
| 562 | if attr, ok := rhs.(Attribute); ok && attr.Intrinsic == IntrinsicTraceID { |
| 563 | if static, ok := lhs.(Static); ok { |
| 564 | binop.LHS = normalizeTraceIDOperand(static) |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | // AST rewrite for simplification |
| 569 | if !binop.referencesSpan() && binop.validate() == nil { |
| 570 | if simplified, err := binop.execute(nil); err == nil { |
| 571 | return simplified |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | if (op == OpAnd || op == OpOr) && binop.referencesSpan() { |
| 576 | binop.b = newBranchPredictor(2, 1000) |
| 577 | } |
| 578 | |
| 579 | return binop |
| 580 | } |
| 581 | |
| 582 | // normalizeTraceIDOperand normalizes a Static operand for trace ID |
| 583 | func normalizeTraceIDOperand(operand Static) Static { |