Skip to content

Commit

Permalink
maligned: use ast.Inspect instead of ast.Walk
Browse files Browse the repository at this point in the history
Simplifies code slightly.
  • Loading branch information
mdempsky committed Aug 25, 2016
1 parent 9b708e0 commit 08c8e9d
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions maligned.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,18 @@ func main() {
log.Fatal(err)
}

var v visitor
for _, pkg := range prog.InitialPackages() {
v.pkg = pkg
for _, file := range pkg.Files {
ast.Walk(&v, file)
ast.Inspect(file, func(node ast.Node) bool {
if s, ok := node.(*ast.StructType); ok {
malign(node.Pos(), pkg.Types[s].Type.(*types.Struct))
}
return true
})
}
}
}

type visitor struct {
pkg *loader.PackageInfo
}

func (v *visitor) Visit(node ast.Node) ast.Visitor {
if str, ok := node.(*ast.StructType); ok {
malign(node.Pos(), v.pkg.Types[str].Type.(*types.Struct))
}
return v
}

func malign(pos token.Pos, str *types.Struct) {
wordSize := int64(8)
maxAlign := int64(8)
Expand Down

0 comments on commit 08c8e9d

Please sign in to comment.