]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/parser/parser.go
go/ast: add Unparen(Expr) helper
[gostls13.git] / src / go / parser / parser.go
index e1d941eff31d3bb50fd971bb33f0e26bee5cbd41..7d8f727b0c93e2ae09621b3c0f1b6142ca826450 100644 (file)
@@ -1654,14 +1654,6 @@ func (p *parser) parseLiteralValue(typ ast.Expr) ast.Expr {
        return &ast.CompositeLit{Type: typ, Lbrace: lbrace, Elts: elts, Rbrace: rbrace}
 }
 
-// If x is of the form (T), unparen returns unparen(T), otherwise it returns x.
-func unparen(x ast.Expr) ast.Expr {
-       if p, isParen := x.(*ast.ParenExpr); isParen {
-               x = unparen(p.X)
-       }
-       return x
-}
-
 func (p *parser) parsePrimaryExpr(x ast.Expr) ast.Expr {
        if p.trace {
                defer un(trace(p, "PrimaryExpr"))
@@ -1706,7 +1698,7 @@ func (p *parser) parsePrimaryExpr(x ast.Expr) ast.Expr {
                case token.LBRACE:
                        // operand may have returned a parenthesized complit
                        // type; accept it but complain if we have a complit
-                       t := unparen(x)
+                       t := ast.Unparen(x)
                        // determine if '{' belongs to a composite literal or a block statement
                        switch t.(type) {
                        case *ast.BadExpr, *ast.Ident, *ast.SelectorExpr:
@@ -1949,7 +1941,7 @@ func (p *parser) parseSimpleStmt(mode int) (ast.Stmt, bool) {
 
 func (p *parser) parseCallExpr(callType string) *ast.CallExpr {
        x := p.parseRhs() // could be a conversion: (some type)(x)
-       if t := unparen(x); t != x {
+       if t := ast.Unparen(x); t != x {
                p.error(x.Pos(), fmt.Sprintf("expression in %s must not be parenthesized", callType))
                x = t
        }