本文整理汇总了Golang中go/ast.IncDecStmt类的典型用法代码示例。如果您正苦于以下问题:Golang IncDecStmt类的具体用法?Golang IncDecStmt怎么用?Golang IncDecStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IncDecStmt类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: compileIncDecStmt
func (a *stmtCompiler) compileIncDecStmt(s *ast.IncDecStmt) {
// Create temporary block for extractEffect
bc := a.enterChild()
defer bc.exit()
l := a.compileExpr(bc.block, false, s.X)
if l == nil {
return
}
if l.evalAddr == nil {
l.diag("cannot assign to %s", l.desc)
return
}
if !(l.t.isInteger() || l.t.isFloat()) {
l.diagOpType(s.Tok, l.t)
return
}
var op token.Token
var desc string
switch s.Tok {
case token.INC:
op = token.ADD
desc = "increment statement"
case token.DEC:
op = token.SUB
desc = "decrement statement"
default:
log.Panicf("Unexpected IncDec token %v", s.Tok)
}
effect, l := l.extractEffect(bc.block, desc)
one := l.newExpr(IdealIntType, "constant")
one.pos = s.Pos()
one.eval = func() *big.Int { return big.NewInt(1) }
binop := l.compileBinaryExpr(op, l, one)
if binop == nil {
return
}
assign := a.compileAssign(s.Pos(), bc.block, l.t, []*expr{binop}, "", "")
if assign == nil {
log.Panicf("compileAssign type check failed")
}
lf := l.evalAddr
a.push(func(v *Thread) {
effect(v)
assign(lf(v), v)
})
}
示例2: compileIncDecStmt
func (w *World) compileIncDecStmt(n *ast.IncDecStmt) Expr {
l := w.compileLvalue(n.X)
switch n.Tok {
case token.INC:
rhs_plus1 := &addone{incdec{typeConv(n.Pos(), l, float64_t)}}
return &assignStmt{lhs: l, rhs: typeConv(n.Pos(), rhs_plus1, l.Type())}
case token.DEC:
rhs_minus1 := &subone{incdec{typeConv(n.Pos(), l, float64_t)}}
return &assignStmt{lhs: l, rhs: typeConv(n.Pos(), rhs_minus1, l.Type())}
default:
panic(err(n.Pos(), "not allowed:", n.Tok))
}
}