MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / FormatNode

Method FormatNode

pkg/sql/sem/tree/format.go:616–687  ·  view source on GitHub ↗

FormatNode recurses into a node for pretty-printing. Flag-driven special cases can hook into this.

(n NodeFormatter)

Source from the content-addressed store, hash-verified

614// FormatNode recurses into a node for pretty-printing.
615// Flag-driven special cases can hook into this.
616func (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) {

Callers 15

StringWithFlagsMethod · 0.95
FormatTypeReferenceMethod · 0.95
FQStringMethod · 0.95
FQStringMethod · 0.95
FormatNameMethod · 0.95
FormatNamePMethod · 0.95
FormatURIMethod · 0.95
formatNodeSummaryMethod · 0.95
AsStringWithFlagsFunction · 0.95
AsStringWithFQNamesFunction · 0.95
FormatMethod · 0.80
FormatMethod · 0.80

Calls 10

PrintfMethod · 0.95
FormatTypeReferenceMethod · 0.95
IsNumericMethod · 0.95
ResolvedTypeMethod · 0.65
StringMethod · 0.65
AmbiguousFormatMethod · 0.65
HasFlagsMethod · 0.45
HasAnyFlagsMethod · 0.45

Tested by

no test coverage detected