Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 1584 | |
| 1585 | // Format implements the NodeFormatter interface. |
| 1586 | func (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 | |
| 1607 | type annotateSyntaxMode int |
| 1608 |
nothing calls this directly
no test coverage detected