FormatNode recurses into a node for pretty-printing. Flag-driven special cases can hook into this.
(n NodeFormatter)
| 614 | // FormatNode recurses into a node for pretty-printing. |
| 615 | // Flag-driven special cases can hook into this. |
| 616 | func (ctx *FmtCtx) FormatNode(n NodeFormatter) { |
| 617 | f := ctx.flags |
| 618 | if f.HasFlags(FmtShowTypes) { |
| 619 | if te, ok := n.(TypedExpr); ok { |
| 620 | ctx.WriteByte('(') |
| 621 | |
| 622 | if f.HasFlags(FmtMarkRedactionNode) { |
| 623 | ctx.formatNodeMaybeMarkRedaction(n) |
| 624 | } else { |
| 625 | ctx.formatNodeOrAdjustConstants(n) |
| 626 | } |
| 627 | |
| 628 | ctx.WriteString(")[") |
| 629 | if rt := te.ResolvedType(); rt == nil { |
| 630 | // An attempt is made to pretty-print an expression that was |
| 631 | // not assigned a type yet. This should not happen, so we make |
| 632 | // it clear in the output this needs to be investigated |
| 633 | // further. |
| 634 | ctx.Printf("??? %v", te) |
| 635 | } else { |
| 636 | ctx.WriteString(rt.String()) |
| 637 | } |
| 638 | ctx.WriteByte(']') |
| 639 | return |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | callFuncExpr := func(e Expr) bool { |
| 644 | f, ok := e.(*FuncExpr) |
| 645 | return ok && f.InCall |
| 646 | } |
| 647 | |
| 648 | if f.HasFlags(FmtAlwaysGroupExprs) { |
| 649 | if e, ok := n.(Expr); ok && !callFuncExpr(e) { |
| 650 | ctx.WriteByte('(') |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | if f.HasFlags(FmtMarkRedactionNode) { |
| 655 | ctx.formatNodeMaybeMarkRedaction(n) |
| 656 | } else { |
| 657 | ctx.formatNodeOrAdjustConstants(n) |
| 658 | } |
| 659 | |
| 660 | if f.HasFlags(FmtAlwaysGroupExprs) { |
| 661 | if e, ok := n.(Expr); ok && !callFuncExpr(e) { |
| 662 | ctx.WriteByte(')') |
| 663 | } |
| 664 | } |
| 665 | if f.HasAnyFlags(fmtDisambiguateDatumTypes | fmtPGCatalogCasts) { |
| 666 | var typ *types.T |
| 667 | if d, isDatum := n.(Datum); isDatum { |
| 668 | if p, isPlaceholder := d.(*Placeholder); isPlaceholder { |
| 669 | // p.typ will be nil if the placeholder has not been type-checked yet. |
| 670 | typ = p.typ |
| 671 | } else if d.AmbiguousFormat() { |
| 672 | typ = d.ResolvedType() |
| 673 | } else if _, isArray := d.(*DArray); isArray && f.HasFlags(fmtPGCatalogCasts) { |
no test coverage detected