-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.go
99 lines (91 loc) · 3.95 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package astrav
import (
"go/ast"
"go/importer"
"go/token"
"go/types"
"github.com/pkg/errors"
)
// ParseInfo parses all files for type information which is then available
// from the Nodes. When using Module.ParseFolder, this is done automatically.
func (s *Folder) ParseInfo(path string, fSet *token.FileSet, files []*ast.File) (*types.Package, error) {
s.Info = &types.Info{
Types: map[ast.Expr]types.TypeAndValue{},
Defs: map[*ast.Ident]types.Object{},
Uses: map[*ast.Ident]types.Object{},
Scopes: map[ast.Node]*types.Scope{},
Implicits: map[ast.Node]types.Object{},
Selections: map[*ast.SelectorExpr]*types.Selection{},
}
var conf = types.Config{
Importer: importer.Default(),
}
pkg, err := conf.Check(path, fSet, files, s.Info)
if err != nil {
return nil, errors.WithStack(err)
}
for _, pkg := range s.Pkgs {
pkg.info = s.Info
}
return pkg, nil
}
// NodeType defines a node type string to search for type
type NodeType string
// Nodetype contants
const (
NodeTypeComment NodeType = "*astrav.Comment"
NodeTypeCommentGroup NodeType = "*astrav.CommentGroup"
NodeTypeField NodeType = "*astrav.Field"
NodeTypeFieldList NodeType = "*astrav.FieldList"
NodeTypeBadExpr NodeType = "*astrav.BadExpr"
NodeTypeIdent NodeType = "*astrav.Ident"
NodeTypeEllipsis NodeType = "*astrav.Ellipsis"
NodeTypeBasicLit NodeType = "*astrav.BasicLit"
NodeTypeFuncLit NodeType = "*astrav.FuncLit"
NodeTypeCompositeLit NodeType = "*astrav.CompositeLit"
NodeTypeParenExpr NodeType = "*astrav.ParenExpr"
NodeTypeSelectorExpr NodeType = "*astrav.SelectorExpr"
NodeTypeIndexExpr NodeType = "*astrav.IndexExpr"
NodeTypeSliceExpr NodeType = "*astrav.SliceExpr"
NodeTypeTypeAssertExpr NodeType = "*astrav.TypeAssertExpr"
NodeTypeCallExpr NodeType = "*astrav.CallExpr"
NodeTypeStarExpr NodeType = "*astrav.StarExpr"
NodeTypeUnaryExpr NodeType = "*astrav.UnaryExpr"
NodeTypeBinaryExpr NodeType = "*astrav.BinaryExpr"
NodeTypeKeyValueExpr NodeType = "*astrav.KeyValueExpr"
NodeTypeArrayType NodeType = "*astrav.ArrayType"
NodeTypeStructType NodeType = "*astrav.StructType"
NodeTypeFuncType NodeType = "*astrav.FuncType"
NodeTypeInterfaceType NodeType = "*astrav.InterfaceType"
NodeTypeMapType NodeType = "*astrav.MapType"
NodeTypeChanType NodeType = "*astrav.ChanType"
NodeTypeBadStmt NodeType = "*astrav.BadStmt"
NodeTypeDeclStmt NodeType = "*astrav.DeclStmt"
NodeTypeEmptyStmt NodeType = "*astrav.EmptyStmt"
NodeTypeLabeledStmt NodeType = "*astrav.LabeledStmt"
NodeTypeExprStmt NodeType = "*astrav.ExprStmt"
NodeTypeSendStmt NodeType = "*astrav.SendStmt"
NodeTypeIncDecStmt NodeType = "*astrav.IncDecStmt"
NodeTypeAssignStmt NodeType = "*astrav.AssignStmt"
NodeTypeGoStmt NodeType = "*astrav.GoStmt"
NodeTypeDeferStmt NodeType = "*astrav.DeferStmt"
NodeTypeReturnStmt NodeType = "*astrav.ReturnStmt"
NodeTypeBranchStmt NodeType = "*astrav.BranchStmt"
NodeTypeBlockStmt NodeType = "*astrav.BlockStmt"
NodeTypeIfStmt NodeType = "*astrav.IfStmt"
NodeTypeCaseClause NodeType = "*astrav.CaseClause"
NodeTypeSwitchStmt NodeType = "*astrav.SwitchStmt"
NodeTypeTypeSwitchStmt NodeType = "*astrav.TypeSwitchStmt"
NodeTypeCommClause NodeType = "*astrav.CommClause"
NodeTypeSelectStmt NodeType = "*astrav.SelectStmt"
NodeTypeForStmt NodeType = "*astrav.ForStmt"
NodeTypeRangeStmt NodeType = "*astrav.RangeStmt"
NodeTypeImportSpec NodeType = "*astrav.ImportSpec"
NodeTypeValueSpec NodeType = "*astrav.ValueSpec"
NodeTypeTypeSpec NodeType = "*astrav.TypeSpec"
NodeTypeBadDecl NodeType = "*astrav.BadDecl"
NodeTypeGenDecl NodeType = "*astrav.GenDecl"
NodeTypeFuncDecl NodeType = "*astrav.FuncDecl"
NodeTypeFile NodeType = "*astrav.File"
NodeTypePackage NodeType = "*astrav.Package"
)