Rewrite random

pull/110/head
pagran 5 years ago
parent 42d9520c76
commit 182a5d10ce

@ -80,15 +80,12 @@ func findBuildTags(commentGroups []*ast.CommentGroup) (buildTags []string) {
return buildTags
}
func transformLineInfo(fileName string, file *ast.File, fset *token.FileSet) ([]string, *ast.File) {
func transformLineInfo(file *ast.File, fset *token.FileSet) ([]string, *ast.File) {
// Save build tags and add file name leak protection
extraComments := append(findBuildTags(file.Comments), "", "//line :1")
file.Comments = nil
fileSeed := hashWithAsInt64(buildInfo.buildID, fileName)
fileRand := mathrand.New(mathrand.NewSource(fileSeed))
newLines := fileRand.Perm(fset.File(file.Package).LineCount())
newLines := mathrand.Perm(fset.File(file.Package).LineCount())
funcCounter := 0
pre := func(cursor *astutil.Cursor) bool {
@ -105,7 +102,7 @@ func transformLineInfo(fileName string, file *ast.File, fset *token.FileSet) ([]
return true
}
comment := &ast.Comment{Text: fmt.Sprintf("//line %c.go:%d", nameCharset[fileRand.Intn(len(nameCharset))], 1+newLines[funcCounter])}
comment := &ast.Comment{Text: fmt.Sprintf("//line %c.go:%d", nameCharset[mathrand.Intn(len(nameCharset))], 1+newLines[funcCounter])}
funcDecl.Doc = prependComment(funcDecl.Doc, comment)
funcCounter++
return true

@ -526,7 +526,7 @@ func transformCompile(args []string) ([]string, error) {
// messy.
name = "_cgo_" + name
default:
extraComments, file = transformLineInfo(origName, file, fset)
extraComments, file = transformLineInfo(file, fset)
file = transformGo(file, info, blacklist)
// Uncomment for some quick debugging. Do not delete.

Loading…
Cancel
Save