MCPcopy Create free account
hub / github.com/dolthub/doltgresql / FormatNode

Method FormatNode

postgres/parser/sem/tree/format.go:376–427  ·  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

374// FormatNode recurses into a node for pretty-printing.
375// Flag-driven special cases can hook into this.
376func (ctx *FmtCtx) FormatNode(n NodeFormatter) {
377 f := ctx.flags
378 if f.HasFlags(FmtShowTypes) {
379 if te, ok := n.(TypedExpr); ok {
380 ctx.WriteByte('(')
381 ctx.formatNodeOrHideConstants(n)
382 ctx.WriteString(")[")
383 if rt := te.ResolvedType(); rt == nil {
384 // An attempt is made to pretty-print an expression that was
385 // not assigned a type yet. This should not happen, so we make
386 // it clear in the output this needs to be investigated
387 // further.
388 ctx.Printf("??? %v", te)
389 } else {
390 ctx.WriteString(rt.String())
391 }
392 ctx.WriteByte(']')
393 return
394 }
395 }
396 if f.HasFlags(FmtAlwaysGroupExprs) {
397 if _, ok := n.(Expr); ok {
398 ctx.WriteByte('(')
399 }
400 }
401 ctx.formatNodeOrHideConstants(n)
402 if f.HasFlags(FmtAlwaysGroupExprs) {
403 if _, ok := n.(Expr); ok {
404 ctx.WriteByte(')')
405 }
406 }
407 if f.HasAnyFlags(fmtDisambiguateDatumTypes | FmtPGCatalog) {
408 var typ *types.T
409 if d, isDatum := n.(Datum); isDatum {
410 if p, isPlaceholder := d.(*Placeholder); isPlaceholder {
411 // p.typ will be nil if the placeholder has not been type-checked yet.
412 typ = p.typ
413 } else if d.AmbiguousFormat() {
414 typ = d.ResolvedType()
415 }
416 }
417 if typ != nil {
418 if f.HasFlags(fmtDisambiguateDatumTypes) {
419 ctx.WriteString(":::")
420 ctx.FormatTypeReference(typ)
421 } else if f.HasFlags(FmtPGCatalog) && !typ.IsNumeric() {
422 ctx.WriteString("::")
423 ctx.FormatTypeReference(typ)
424 }
425 }
426 }
427}
428
429// AsStringWithFlags pretty prints a node to a string given specific flags; only
430// flags that don't require Annotations can be used.

Callers 15

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

Calls 10

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

Tested by 2

AutoQuoteIdentFunction · 0.76