本文整理汇总了Golang中go/ast.AssignStmt.Pos方法的典型用法代码示例。如果您正苦于以下问题:Golang AssignStmt.Pos方法的具体用法?Golang AssignStmt.Pos怎么用?Golang AssignStmt.Pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.AssignStmt
的用法示例。
在下文中一共展示了AssignStmt.Pos方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: compileSubAssign
func (w *World) compileSubAssign(a *ast.AssignStmt, lhs ast.Expr, r Expr) Expr {
l := w.compileLvalue(lhs)
x := typeConv(a.Pos(), l, float64_t)
y := typeConv(a.Pos(), r, float64_t)
sub := &sub{binaryExpr{x, y}}
return &assignStmt{lhs: l, rhs: typeConv(a.Pos(), sub, inputType(l))}
}
示例2: compileDefine
// compile a := b
func (w *World) compileDefine(a *ast.AssignStmt, lhs ast.Expr, r Expr) Expr {
ident, ok := lhs.(*ast.Ident)
if !ok {
panic(err(a.Pos(), "non-name on left side of :="))
}
addr := reflect.New(r.Type())
ok = w.safeDeclare(ident.Name, &reflectLvalue{addr.Elem()})
if !ok {
panic(err(a.Pos(), "already defined: "+ident.Name))
}
return w.compileAssign(a, lhs, r)
}
示例3: compileAssignStmt
// compiles a (single) assign statement lhs = rhs
func (w *World) compileAssignStmt(a *ast.AssignStmt) Expr {
if len(a.Lhs) != 1 || len(a.Rhs) != 1 {
panic(err(a.Pos(), "multiple assignment not allowed"))
}
lhs, rhs := a.Lhs[0], a.Rhs[0]
r := w.compileExpr(rhs)
switch a.Tok {
default:
panic(err(a.Pos(), a.Tok, "not allowed"))
case token.ASSIGN: // =
return w.compileAssign(a, lhs, r)
case token.DEFINE: // :=
return w.compileDefine(a, lhs, r)
case token.ADD_ASSIGN: // +=
return w.compileAddAssign(a, lhs, r)
case token.SUB_ASSIGN: // -=
return w.compileSubAssign(a, lhs, r)
}
}
示例4: doAssignOp
func (a *stmtCompiler) doAssignOp(s *ast.AssignStmt) {
if len(s.Lhs) != 1 || len(s.Rhs) != 1 {
a.diag("tuple assignment cannot be combined with an arithmetic operation")
return
}
// Create temporary block for extractEffect
bc := a.enterChild()
defer bc.exit()
l := a.compileExpr(bc.block, false, s.Lhs[0])
r := a.compileExpr(bc.block, false, s.Rhs[0])
if l == nil || r == nil {
return
}
if l.evalAddr == nil {
l.diag("cannot assign to %s", l.desc)
return
}
effect, l := l.extractEffect(bc.block, "operator-assignment")
binop := r.compileBinaryExpr(assignOpToOp[s.Tok], l, r)
if binop == nil {
return
}
assign := a.compileAssign(s.Pos(), bc.block, l.t, []*expr{binop}, "assignment", "value")
if assign == nil {
log.Panicf("compileAssign type check failed")
}
lf := l.evalAddr
a.push(func(t *Thread) {
effect(t)
assign(lf(t), t)
})
}
示例5: checkAssignStmt
// checkAssignStmt checks for assignments of the form "<expr> = <expr>".
// These are almost always useless, and even when they aren't they are usually a mistake.
func (f *File) checkAssignStmt(stmt *ast.AssignStmt) {
if !vet("assign") {
return
}
if stmt.Tok != token.ASSIGN {
return // ignore :=
}
if len(stmt.Lhs) != len(stmt.Rhs) {
// If LHS and RHS have different cardinality, they can't be the same.
return
}
for i, lhs := range stmt.Lhs {
rhs := stmt.Rhs[i]
if reflect.TypeOf(lhs) != reflect.TypeOf(rhs) {
continue // short-circuit the heavy-weight gofmt check
}
le := f.gofmt(lhs)
re := f.gofmt(rhs)
if le == re {
f.Badf(stmt.Pos(), "self-assignment of %s to %s", re, le)
}
}
}
示例6: compileAssign
// compile a = b
func (w *World) compileAssign(a *ast.AssignStmt, lhs ast.Expr, r Expr) Expr {
l := w.compileLvalue(lhs)
return &assignStmt{lhs: l, rhs: typeConv(a.Pos(), r, inputType(l))}
}