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

Method FormatNode

pkg/sql/sem/tree/format.go:331–377  ·  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

329// FormatNode recurses into a node for pretty-printing.
330// Flag-driven special cases can hook into this.
331func (ctx *FmtCtx) FormatNode(n NodeFormatter) {
332 f := ctx.flags
333 if f.HasFlags(FmtShowTypes) {
334 if te, ok := n.(TypedExpr); ok {
335 ctx.WriteByte('(')
336 ctx.formatNodeOrHideConstants(n)
337 ctx.WriteString(")[")
338 if rt := te.ResolvedType(); rt == nil {
339 // An attempt is made to pretty-print an expression that was
340 // not assigned a type yet. This should not happen, so we make
341 // it clear in the output this needs to be investigated
342 // further.
343 ctx.Printf("??? %v", te)
344 } else {
345 ctx.WriteString(rt.String())
346 }
347 ctx.WriteByte(']')
348 return
349 }
350 }
351 if f.HasFlags(FmtAlwaysGroupExprs) {
352 if _, ok := n.(Expr); ok {
353 ctx.WriteByte('(')
354 }
355 }
356 ctx.formatNodeOrHideConstants(n)
357 if f.HasFlags(FmtAlwaysGroupExprs) {
358 if _, ok := n.(Expr); ok {
359 ctx.WriteByte(')')
360 }
361 }
362 if f.HasFlags(fmtDisambiguateDatumTypes) {
363 var typ *types.T
364 if d, isDatum := n.(Datum); isDatum {
365 if p, isPlaceholder := d.(*Placeholder); isPlaceholder {
366 // p.typ will be nil if the placeholder has not been type-checked yet.
367 typ = p.typ
368 } else if d.AmbiguousFormat() {
369 typ = d.ResolvedType()
370 }
371 }
372 if typ != nil {
373 ctx.WriteString(":::")
374 ctx.WriteString(typ.SQLString())
375 }
376 }
377}
378
379// AsStringWithFlags pretty prints a node to a string given specific flags; only
380// flags that don't require Annotations can be used.

Callers 15

StringWithFlagsMethod · 0.95
FQStringMethod · 0.95
FormatNameMethod · 0.95
FormatNamePMethod · 0.95
AsStringWithFlagsFunction · 0.95
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80
FormatMethod · 0.80

Calls 7

PrintfMethod · 0.95
SQLStringMethod · 0.95
ResolvedTypeMethod · 0.65
StringMethod · 0.65
AmbiguousFormatMethod · 0.65
HasFlagsMethod · 0.45

Tested by

no test coverage detected