Commit 0316d661 authored by griesemer's avatar griesemer Committed by Robert Griesemer

go/types: improved documentation for WriteExpr and ExprString

Fixes #22377.

Change-Id: I0a0e1bde558df964f0961dc4cfc305e72d590e1a
Reviewed-on: https://go-review.googlesource.com/72690Reviewed-by: default avatarAlan Donovan <adonovan@google.com>
parent 083338cb
...@@ -11,14 +11,18 @@ import ( ...@@ -11,14 +11,18 @@ import (
"go/ast" "go/ast"
) )
// ExprString returns the (possibly simplified) string representation for x. // ExprString returns the (possibly shortened) string representation for x.
// Shortened representations are suitable for user interfaces but may not
// necessarily follow Go syntax.
func ExprString(x ast.Expr) string { func ExprString(x ast.Expr) string {
var buf bytes.Buffer var buf bytes.Buffer
WriteExpr(&buf, x) WriteExpr(&buf, x)
return buf.String() return buf.String()
} }
// WriteExpr writes the (possibly simplified) string representation for x to buf. // WriteExpr writes the (possibly shortened) string representation for x to buf.
// Shortened representations are suitable for user interfaces but may not
// necessarily follow Go syntax.
func WriteExpr(buf *bytes.Buffer, x ast.Expr) { func WriteExpr(buf *bytes.Buffer, x ast.Expr) {
// The AST preserves source-level parentheses so there is // The AST preserves source-level parentheses so there is
// no need to introduce them here to correct for different // no need to introduce them here to correct for different
...@@ -44,12 +48,12 @@ func WriteExpr(buf *bytes.Buffer, x ast.Expr) { ...@@ -44,12 +48,12 @@ func WriteExpr(buf *bytes.Buffer, x ast.Expr) {
case *ast.FuncLit: case *ast.FuncLit:
buf.WriteByte('(') buf.WriteByte('(')
WriteExpr(buf, x.Type) WriteExpr(buf, x.Type)
buf.WriteString(" literal)") // simplified buf.WriteString(" literal)") // shortened
case *ast.CompositeLit: case *ast.CompositeLit:
buf.WriteByte('(') buf.WriteByte('(')
WriteExpr(buf, x.Type) WriteExpr(buf, x.Type)
buf.WriteString(" literal)") // simplified buf.WriteString(" literal)") // shortened
case *ast.ParenExpr: case *ast.ParenExpr:
buf.WriteByte('(') buf.WriteByte('(')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment