forked from go-delve/delve
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proc: simplify next/step/stepout condition code
Adds a library of utility functions to generated breakpoint conditions for next, step and stepout.
- Loading branch information
1 parent
eac6ebe
commit 7dedf1e
Showing
2 changed files
with
48 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// This package contains utility functions used by pkg/proc to generate | ||
// ast.Expr expressions. | ||
|
||
package astutil | ||
|
||
import ( | ||
"go/ast" | ||
"go/token" | ||
"strconv" | ||
) | ||
|
||
// Eql returns an expression evaluating 'x == y'. | ||
func Eql(x, y ast.Expr) *ast.BinaryExpr { | ||
return &ast.BinaryExpr{Op: token.EQL, X: x, Y: y} | ||
} | ||
|
||
// Sel returns an expression evaluating 'x.sel'. | ||
func Sel(x ast.Expr, sel string) *ast.SelectorExpr { | ||
return &ast.SelectorExpr{X: x, Sel: &ast.Ident{Name: sel}} | ||
} | ||
|
||
// PkgVar returns an expression evaluating 'pkg.v'. | ||
func PkgVar(pkg, v string) *ast.SelectorExpr { | ||
return &ast.SelectorExpr{X: &ast.Ident{Name: pkg}, Sel: &ast.Ident{Name: v}} | ||
} | ||
|
||
// Int returns an expression representing the integer 'n'. | ||
func Int(n int64) *ast.BasicLit { | ||
return &ast.BasicLit{Kind: token.INT, Value: strconv.FormatInt(n, 10)} | ||
} | ||
|
||
// And returns an expression evaluating 'x && y'. | ||
func And(x, y ast.Expr) *ast.BinaryExpr { | ||
return &ast.BinaryExpr{Op: token.LAND, X: x, Y: y} | ||
} | ||
|
||
// Or returns an expression evaluating 'x || y'. | ||
func Or(x, y ast.Expr) *ast.BinaryExpr { | ||
return &ast.BinaryExpr{Op: token.LOR, X: x, Y: y} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters