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

Method Format

pkg/sql/sem/tree/expr.go:1586–1605  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

1584
1585// Format implements the NodeFormatter interface.
1586func (node *IndirectionExpr) Format(ctx *FmtCtx) {
1587 // If the sub expression is a CastExpr or an Array that has a type,
1588 // we need to wrap it in a ParenExpr, otherwise the indirection
1589 // will get interpreted as part of the type.
1590 // Ex. ('{a}'::_typ)[1] vs. '{a}'::_typ[1].
1591 // Ex. (ARRAY['a'::typ]:::typ[])[1] vs. ARRAY['a'::typ]:::typ[][1].
1592 var annotateArray bool
1593 if arr, ok := node.Expr.(*Array); ctx.HasFlags(FmtParsable) && ok && arr.typ != nil {
1594 if arr.typ.ArrayContents().Family() != types.UnknownFamily {
1595 annotateArray = true
1596 }
1597 }
1598 if _, isCast := node.Expr.(*CastExpr); isCast || annotateArray {
1599 withParens := ParenExpr{Expr: node.Expr}
1600 exprFmtWithParen(ctx, &withParens)
1601 } else {
1602 exprFmtWithParen(ctx, node.Expr)
1603 }
1604 ctx.FormatNode(&node.Indirection)
1605}
1606
1607type annotateSyntaxMode int
1608

Callers

nothing calls this directly

Calls 5

exprFmtWithParenFunction · 0.85
FamilyMethod · 0.80
ArrayContentsMethod · 0.80
FormatNodeMethod · 0.80
HasFlagsMethod · 0.45

Tested by

no test coverage detected