You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gosuv/vendor/github.com/gopherjs/gopherjs/compiler/filter/incdecstmt.go

40 lines
754 B

package filter
import (
"go/ast"
"go/constant"
"go/token"
"go/types"
)
func IncDecStmt(stmt ast.Stmt, info *types.Info) ast.Stmt {
if s, ok := stmt.(*ast.IncDecStmt); ok {
t := info.TypeOf(s.X)
if iExpr, isIExpr := s.X.(*ast.IndexExpr); isIExpr {
switch u := info.TypeOf(iExpr.X).Underlying().(type) {
case *types.Array:
t = u.Elem()
case *types.Slice:
t = u.Elem()
case *types.Map:
t = u.Elem()
}
}
tok := token.ADD_ASSIGN
if s.Tok == token.DEC {
tok = token.SUB_ASSIGN
}
one := &ast.BasicLit{Kind: token.INT}
info.Types[one] = types.TypeAndValue{Type: t, Value: constant.MakeInt64(1)}
return &ast.AssignStmt{
Lhs: []ast.Expr{s.X},
Tok: tok,
Rhs: []ast.Expr{one},
}
}
return stmt
}