-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from gostaticanalysis/release-v2.1.1
Release v2.1.1
- Loading branch information
Showing
21 changed files
with
479 additions
and
88 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
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
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
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,27 @@ | ||
package internal | ||
|
||
import ( | ||
"flag" | ||
"io" | ||
|
||
"golang.org/x/tools/go/packages" | ||
"golang.org/x/tools/go/ssa" | ||
) | ||
|
||
type Pass struct { | ||
*packages.Package | ||
SSA *ssa.Program | ||
SrcFuncs []*ssa.Function | ||
Stdin io.Reader | ||
Stdout io.Writer | ||
Stderr io.Writer | ||
} | ||
|
||
type Analyzer struct { | ||
Name string | ||
Doc string | ||
Flags *flag.FlagSet | ||
Config *packages.Config | ||
SSABuilderMode ssa.BuilderMode | ||
Run func(pass *Pass) error | ||
} |
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,78 @@ | ||
package internal | ||
|
||
import ( | ||
"go/ast" | ||
"go/types" | ||
|
||
"golang.org/x/tools/go/packages" | ||
"golang.org/x/tools/go/ssa" | ||
) | ||
|
||
// copy from golang.org/x/tools/analysis/passes/buildssa | ||
func BuildSSA(pkg *packages.Package, mode ssa.BuilderMode) (*ssa.Program, []*ssa.Function, error) { | ||
|
||
prog := ssa.NewProgram(pkg.Fset, mode) | ||
|
||
// Create SSA packages for all imports. | ||
// Order is not significant. | ||
created := make(map[*types.Package]bool) | ||
var createAll func(pkgs []*types.Package) | ||
createAll = func(pkgs []*types.Package) { | ||
for _, p := range pkgs { | ||
if !created[p] { | ||
created[p] = true | ||
prog.CreatePackage(p, nil, nil, true) | ||
createAll(p.Imports()) | ||
} | ||
} | ||
} | ||
createAll(pkg.Types.Imports()) | ||
|
||
// Create and build the primary package. | ||
ssapkg := prog.CreatePackage(pkg.Types, pkg.Syntax, pkg.TypesInfo, false) | ||
ssapkg.Build() | ||
|
||
// Compute list of source functions, including literals, | ||
// in source order. | ||
var funcs []*ssa.Function | ||
for _, f := range pkg.Syntax { | ||
for _, decl := range f.Decls { | ||
if fdecl, ok := decl.(*ast.FuncDecl); ok { | ||
|
||
// SSA will not build a Function | ||
// for a FuncDecl named blank. | ||
// That's arguably too strict but | ||
// relaxing it would break uniqueness of | ||
// names of package members. | ||
if fdecl.Name.Name == "_" { | ||
continue | ||
} | ||
|
||
// (init functions have distinct Func | ||
// objects named "init" and distinct | ||
// ssa.Functions named "init#1", ...) | ||
|
||
fn := pkg.TypesInfo.Defs[fdecl.Name].(*types.Func) | ||
if fn == nil { | ||
panic(fn) | ||
} | ||
|
||
f := ssapkg.Prog.FuncValue(fn) | ||
if f == nil { | ||
panic(fn) | ||
} | ||
|
||
var addAnons func(f *ssa.Function) | ||
addAnons = func(f *ssa.Function) { | ||
funcs = append(funcs, f) | ||
for _, anon := range f.AnonFuncs { | ||
addAnons(anon) | ||
} | ||
} | ||
addAnons(f) | ||
} | ||
} | ||
} | ||
|
||
return prog, funcs, nil | ||
} |
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
@@ if eq .Kind "packages" -@@ | ||
a.go:5:6 identifier is gopher | ||
a.go:6:8 identifier is gopher | ||
@@ end -@@ | ||
a.f | ||
Block 0 | ||
*ssa.Call print(0:int) | ||
*ssa.Builtin builtin print | ||
*ssa.Const 0:int | ||
*ssa.Return return |
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
Oops, something went wrong.