本文整理汇总了Golang中go/ast.BinaryExpr类的典型用法代码示例。如果您正苦于以下问题:Golang BinaryExpr类的具体用法?Golang BinaryExpr怎么用?Golang BinaryExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryExpr类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: compileBinaryExpr
// compiles a binary expression x 'op' y
func (w *World) compileBinaryExpr(n *ast.BinaryExpr) Expr {
switch n.Op {
default:
panic(err(n.Pos(), "not allowed:", n.Op))
case token.ADD:
return &add{w.newBinExpr(n)}
case token.SUB:
return &sub{w.newBinExpr(n)}
case token.MUL:
return &mul{w.newBinExpr(n)}
case token.QUO:
return &quo{w.newBinExpr(n)}
case token.LSS:
return &lss{w.newComp(n)}
case token.GTR:
return >r{w.newComp(n)}
case token.LEQ:
return &leq{w.newComp(n)}
case token.GEQ:
return &geq{w.newComp(n)}
case token.EQL:
return &eql{w.newComp(n)}
case token.NEQ:
return &neq{w.newComp(n)}
case token.LAND:
return &and{w.newBoolOp(n)}
case token.LOR:
return &or{w.newBoolOp(n)}
}
}
示例2: RunMutation
func RunMutation(index int, exp *ast.BinaryExpr, f, t token.Token, src string, fset *token.FileSet, file *ast.File) error {
exp.Op = t
defer func() {
exp.Op = f
}()
err := printFile(src, fset, file)
if err != nil {
return err
}
cmd := exec.Command("go", "test")
cmd.Dir = filepath.Dir(src)
output, err := cmd.CombinedOutput()
if err == nil {
code = 1
log.Printf("mutation %d failed to break any tests", index)
} else if _, ok := err.(*exec.ExitError); ok {
lines := bytes.Split(output, []byte("\n"))
lastLine := lines[len(lines)-2]
if bytes.HasPrefix(lastLine, []byte("FAIL")) {
log.Printf("mutation %d failed the tests properly", index)
} else {
log.Printf("mutation %d created an error: %s", index, lastLine)
}
} else {
return fmt.Errorf("mutation %d failed to run: %s", index, err)
}
return nil
}
示例3: leaveBinaryExpr
func (v *powerVisitor) leaveBinaryExpr(binaryExpr *ast.BinaryExpr) {
if modified, ok := captExpr(binaryExpr.X); ok {
binaryExpr.X = modified
}
if modified, ok := captExpr(binaryExpr.Y); ok {
binaryExpr.Y = modified
}
}
示例4: binaryExprTFunc
func (rp *rewritePackage) binaryExprTFunc(binaryExpr *ast.BinaryExpr) {
if x, ok := binaryExpr.X.(*ast.BasicLit); ok {
binaryExpr.X = rp.wrapBasicLitWithT(x)
}
if y, ok := binaryExpr.Y.(*ast.BasicLit); ok {
binaryExpr.Y = rp.wrapBasicLitWithT(y)
}
}
示例5: checkNilFuncComparison
func (f *File) checkNilFuncComparison(e *ast.BinaryExpr) {
if !vet("nilfunc") {
return
}
// Only want == or != comparisons.
if e.Op != token.EQL && e.Op != token.NEQ {
return
}
// Only want comparisons with a nil identifier on one side.
var e2 ast.Expr
switch {
case f.isNil(e.X):
e2 = e.Y
case f.isNil(e.Y):
e2 = e.X
default:
return
}
// Only want identifiers or selector expressions.
var obj types.Object
switch v := e2.(type) {
case *ast.Ident:
obj = f.pkg.idents[v]
case *ast.SelectorExpr:
obj = f.pkg.idents[v.Sel]
default:
return
}
// Only want functions.
if _, ok := obj.(*types.Func); !ok {
return
}
f.Badf(e.Pos(), "comparison of function %v %v nil is always %v", obj.Name(), e.Op, e.Op == token.NEQ)
}
示例6: newBoolOp
func (w *World) newBoolOp(n *ast.BinaryExpr) boolOp {
x := typeConv(n.Pos(), w.compileExpr(n.X), bool_t)
y := typeConv(n.Pos(), w.compileExpr(n.Y), bool_t)
return boolOp{x, y}
}
示例7: newBinExpr
func (w *World) newBinExpr(n *ast.BinaryExpr) binaryExpr {
x := typeConv(n.Pos(), w.compileExpr(n.X), float64_t)
y := typeConv(n.Pos(), w.compileExpr(n.Y), float64_t)
return binaryExpr{x, y}
}