planCallConditional generates a conditional / ternary (c ? t : f) Interpretable.
(expr ast.Expr, args []InterpretableV2)
| 481 | |
| 482 | // planCallConditional generates a conditional / ternary (c ? t : f) Interpretable. |
| 483 | func (p *planBuilder) planCallConditional(expr ast.Expr, args []InterpretableV2) (InterpretableV2, error) { |
| 484 | cond := args[0] |
| 485 | t := args[1] |
| 486 | var tAttr Attribute |
| 487 | truthyAttr, isTruthyAttr := t.(InterpretableAttribute) |
| 488 | if isTruthyAttr { |
| 489 | tAttr = truthyAttr.Attr() |
| 490 | } else { |
| 491 | tAttr = p.attrFactory.RelativeAttribute(t.ID(), t) |
| 492 | } |
| 493 | |
| 494 | f := args[2] |
| 495 | var fAttr Attribute |
| 496 | falsyAttr, isFalsyAttr := f.(InterpretableAttribute) |
| 497 | if isFalsyAttr { |
| 498 | fAttr = falsyAttr.Attr() |
| 499 | } else { |
| 500 | fAttr = p.attrFactory.RelativeAttribute(f.ID(), f) |
| 501 | } |
| 502 | |
| 503 | return &evalAttr{ |
| 504 | adapter: p.adapter, |
| 505 | attr: p.attrFactory.ConditionalAttribute(expr.ID(), cond, tAttr, fAttr), |
| 506 | }, nil |
| 507 | } |
| 508 | |
| 509 | // planCallIndex either extends an attribute with the argument to the index operation, or creates |
| 510 | // a relative attribute based on the return of a function call or operation. |
no test coverage detected