mirror of
https://github.com/burrowers/garble.git
synced 2025-09-26 20:01:16 +08:00
start using go/ast.Preorder
Thanks to being able to use range-over-func, some control flow in our code gets simplified.
This commit is contained in:
@@ -175,7 +175,7 @@ func handleCompositeLiteral(obfRand *obfRand, isPointer bool, node *ast.Composit
|
||||
//
|
||||
// We don't set any "end" or middle positions, because they seem irrelevant.
|
||||
func withPos(node ast.Node, pos token.Pos) ast.Node {
|
||||
ast.Inspect(node, func(node ast.Node) bool {
|
||||
for node := range ast.Preorder(node) {
|
||||
switch node := node.(type) {
|
||||
case *ast.BasicLit:
|
||||
node.ValuePos = pos
|
||||
@@ -207,8 +207,7 @@ func withPos(node ast.Node, pos token.Pos) ast.Node {
|
||||
case *ast.BranchStmt:
|
||||
node.TokPos = pos
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
|
@@ -71,7 +71,7 @@ func printFile(lpkg *listedPackage, file *ast.File) ([]byte, error) {
|
||||
// we use a list of offsets indexed by identifiers in source order.
|
||||
var origCallOffsets []int
|
||||
nextOffset := -1
|
||||
ast.Inspect(file, func(node ast.Node) bool {
|
||||
for node := range ast.Preorder(file) {
|
||||
switch node := node.(type) {
|
||||
case *ast.CallExpr:
|
||||
nextOffset = fsetFile.Position(node.Pos()).Offset
|
||||
@@ -79,8 +79,7 @@ func printFile(lpkg *listedPackage, file *ast.File) ([]byte, error) {
|
||||
origCallOffsets = append(origCallOffsets, nextOffset)
|
||||
nextOffset = -1
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
copied := 0
|
||||
printBuf2.Reset()
|
||||
|
@@ -80,7 +80,7 @@ One can reverse a captured panic stack trace as follows:
|
||||
fieldToStruct := computeFieldToStruct(info)
|
||||
for i, file := range files {
|
||||
goFile := lpkg.CompiledGoFiles[i]
|
||||
ast.Inspect(file, func(node ast.Node) bool {
|
||||
for node := range ast.Preorder(file) {
|
||||
switch node := node.(type) {
|
||||
|
||||
// Replace names.
|
||||
@@ -125,9 +125,7 @@ One can reverse a captured panic stack trace as follows:
|
||||
fmt.Sprintf("%s/%s", lpkg.ImportPath, goFile),
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
repl := strings.NewReplacer(replaces...)
|
||||
|
@@ -201,16 +201,13 @@ func stripRuntime(basename string, file *ast.File) {
|
||||
}
|
||||
case "runtime1.go":
|
||||
usesEnv := func(node ast.Node) bool {
|
||||
seen := false
|
||||
ast.Inspect(node, func(node ast.Node) bool {
|
||||
for node := range ast.Preorder(node) {
|
||||
ident, ok := node.(*ast.Ident)
|
||||
if ok && ident.Name == "gogetenv" {
|
||||
seen = true
|
||||
return false
|
||||
return true
|
||||
}
|
||||
return true
|
||||
})
|
||||
return seen
|
||||
}
|
||||
return false
|
||||
}
|
||||
filenames:
|
||||
switch funcDecl.Name.Name {
|
||||
|
Reference in New Issue
Block a user