planCallConditional generates a conditional / ternary (c ? t : f) Interpretable.
(expr ast.Expr, args []InterpretableV2)
| 515 | |
| 516 | // planCallConditional generates a conditional / ternary (c ? t : f) Interpretable. |
| 517 | func (p *planBuilder) planCallConditional(expr ast.Expr, args []InterpretableV2) (InterpretableV2, error) { |
| 518 | cond := args[0] |
| 519 | t := args[1] |
| 520 | var tAttr Attribute |
| 521 | truthyAttr, isTruthyAttr := t.(InterpretableAttribute) |
| 522 | if isTruthyAttr { |
| 523 | tAttr = truthyAttr.Attr() |
| 524 | } else { |
| 525 | tAttr = p.attrFactory.RelativeAttribute(t.ID(), t) |
| 526 | } |
| 527 | |
| 528 | f := args[2] |
| 529 | var fAttr Attribute |
| 530 | falsyAttr, isFalsyAttr := f.(InterpretableAttribute) |
| 531 | if isFalsyAttr { |
| 532 | fAttr = falsyAttr.Attr() |
| 533 | } else { |
| 534 | fAttr = p.attrFactory.RelativeAttribute(f.ID(), f) |
| 535 | } |
| 536 | |
| 537 | return &evalAttr{ |
| 538 | adapter: p.adapter, |
| 539 | attr: p.attrFactory.ConditionalAttribute(expr.ID(), cond, tAttr, fAttr), |
| 540 | }, nil |
| 541 | } |
| 542 | |
| 543 | // planCallIndex either extends an attribute with the argument to the index operation, or creates |
| 544 | // a relative attribute based on the return of a function call or operation. |
no test coverage detected