34 lines
722 B
Go
34 lines
722 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"go/ast"
|
|
"go/token"
|
|
)
|
|
|
|
func parseFile(f *ast.File) {
|
|
loc := f.Name.String()
|
|
for _, d := range f.Decls {
|
|
switch d := d.(type) {
|
|
case *ast.GenDecl:
|
|
parseGenDecl(loc, d)
|
|
case *ast.FuncDecl:
|
|
parseFuncDecl(loc, d)
|
|
default:
|
|
fmt.Printf("Unknown decl type in %s: %T\n", loc, d)
|
|
}
|
|
}
|
|
}
|
|
|
|
// type specification: "type [=] <typ>"
|
|
func parseTypeSpec(loc string, s *ast.TypeSpec) {
|
|
// type foo bool: .Name + .Type / .Assign = NoPos (== 0)
|
|
// type foo = bool: .Name + .Type / .Assign = <pos>
|
|
name := s.Name.String()
|
|
if s.Assign == token.NoPos {
|
|
fmt.Printf("%s/Defined %s: ", loc, name)
|
|
} else {
|
|
fmt.Printf("%s/Aliased %s: ", loc, name)
|
|
}
|
|
parseTypeExpr(loc, s.Type, true)
|
|
}
|