planCallConditional generates a conditional / ternary (c ? t : f) Interpretable.
(expr ast.Expr, args []InterpretableV2)
| 462 | |
| 463 | // planCallConditional generates a conditional / ternary (c ? t : f) Interpretable. |
| 464 | func (p *planBuilder) planCallConditional(expr ast.Expr, args []InterpretableV2) (InterpretableV2, error) { |
| 465 | cond := args[0] |
| 466 | t := args[1] |
| 467 | var tAttr Attribute |
| 468 | truthyAttr, isTruthyAttr := t.(InterpretableAttribute) |
| 469 | if isTruthyAttr { |
| 470 | tAttr = truthyAttr.Attr() |
| 471 | } else { |
| 472 | tAttr = p.attrFactory.RelativeAttribute(t.ID(), t) |
| 473 | } |
| 474 | |
| 475 | f := args[2] |
| 476 | var fAttr Attribute |
| 477 | falsyAttr, isFalsyAttr := f.(InterpretableAttribute) |
| 478 | if isFalsyAttr { |
| 479 | fAttr = falsyAttr.Attr() |
| 480 | } else { |
| 481 | fAttr = p.attrFactory.RelativeAttribute(f.ID(), f) |
| 482 | } |
| 483 | |
| 484 | return &evalAttr{ |
| 485 | adapter: p.adapter, |
| 486 | attr: p.attrFactory.ConditionalAttribute(expr.ID(), cond, tAttr, fAttr), |
| 487 | }, nil |
| 488 | } |
| 489 | |
| 490 | // planCallIndex either extends an attribute with the argument to the index operation, or creates |
| 491 | // a relative attribute based on the return of a function call or operation. |
no test coverage detected