More work on the constant generation tool.
This commit is contained in:
parent
20306d881c
commit
4632d80576
|
@ -32,52 +32,37 @@ func main() {
|
||||||
pkg = pkgs[k]
|
pkg = pkgs[k]
|
||||||
}
|
}
|
||||||
|
|
||||||
var run func(...ast.Decl)
|
do(pkg)
|
||||||
var runstmt func(ast.Stmt)
|
}
|
||||||
var runblock func(*ast.BlockStmt)
|
|
||||||
|
|
||||||
desired := func(name string) bool {
|
type walker struct {
|
||||||
return strings.HasPrefix(name, "_")
|
desired func(string) bool
|
||||||
}
|
}
|
||||||
run = func(decls ...ast.Decl) {
|
|
||||||
for _, d := range decls {
|
func (w *walker) Visit(node ast.Node) ast.Visitor {
|
||||||
switch dd := d.(type) {
|
if n, ok := node.(*ast.Ident); ok {
|
||||||
case *ast.FuncDecl:
|
if w.desired(n.Name) {
|
||||||
runblock(dd.Body)
|
known := "<unknown>"
|
||||||
case *ast.GenDecl:
|
if n.Obj != nil {
|
||||||
if desired(d.Name.String()) {
|
known = n.Obj.Kind.String()
|
||||||
fmt.Println(d.Name.String())
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unknown decl type %T: %v", dd, dd))
|
|
||||||
}
|
}
|
||||||
|
fmt.Println(n.Name + "\t\t" + known)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runstmt = func(s ast.Stmt) {
|
return w
|
||||||
switch ss := s.(type) {
|
}
|
||||||
case *ast.DeclStmt:
|
|
||||||
run(ss.Decl)
|
func do(pkg *ast.Package) {
|
||||||
case *ast.LabeledStmt:
|
desired := func(name string) bool {
|
||||||
runstmt(ss.Stmt)
|
if strings.HasPrefix(name, "_") && len(name) > 1 {
|
||||||
case *ast.AssignStmt:
|
return !strings.ContainsAny(name,
|
||||||
// TODO go through Lhs if ss.Tok type == DEFINE
|
"abcdefghijklmnopqrstuvwxyz")
|
||||||
case *ast.GoStmt:
|
|
||||||
// these don't have decls
|
|
||||||
case *ast.EmptyStmt:
|
|
||||||
case *ast.ExprStmt:
|
|
||||||
case *ast.SendStmt:
|
|
||||||
case *ast.IncDecStmt:
|
|
||||||
// all do nothing
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unknown stmt type %T: %v", dd, dd))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
runblock = func(block *ast.BlockStmt) {
|
|
||||||
for _, s := range block.Stmt {
|
|
||||||
runstmt(s)
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
for _, f := range pkg.Files {
|
for _, f := range pkg.Files {
|
||||||
run(f.Decls...)
|
for _, d := range f.Decls {
|
||||||
|
ast.Walk(&walker{desired}, d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue