FormatNode recurses into a node for pretty-printing. Flag-driven special cases can hook into this.
(n NodeFormatter)
| 329 | // FormatNode recurses into a node for pretty-printing. |
| 330 | // Flag-driven special cases can hook into this. |
| 331 | func (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. |
no test coverage detected