-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_type.go
129 lines (122 loc) · 2.83 KB
/
node_type.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package typegen
import (
"reflect"
. "github.com/mikeschinkel/go-lib"
)
type NodeType uint
const (
PointerNode = NodeType(reflect.Pointer)
MapNode = NodeType(reflect.Map)
ArrayNode = NodeType(reflect.Array)
SliceNode = NodeType(reflect.Slice)
StructNode = NodeType(reflect.Struct)
InterfaceNode = NodeType(reflect.Interface)
StringNode = NodeType(reflect.String)
IntNode = NodeType(reflect.Int)
Int8Node = NodeType(reflect.Int8)
Int16Node = NodeType(reflect.Int16)
Int32Node = NodeType(reflect.Int32)
Int64Node = NodeType(reflect.Int64)
UintptrNode = NodeType(reflect.Uintptr)
UintNode = NodeType(reflect.Uint)
Uint8Node = NodeType(reflect.Uint8)
Uint16Node = NodeType(reflect.Uint16)
Uint32Node = NodeType(reflect.Uint32)
Uint64Node = NodeType(reflect.Uint64)
Float32Node = NodeType(reflect.Float32)
Float64Node = NodeType(reflect.Float64)
BoolNode = NodeType(reflect.Bool)
FuncNode = NodeType(reflect.Func)
InvalidNode = NodeType(reflect.Invalid)
UnsafePointerNode = NodeType(reflect.UnsafePointer)
FieldNode = NodeType(reflect.UnsafePointer + 10)
ElementNode = NodeType(reflect.UnsafePointer + 11)
SubstitutionNode = NodeType(reflect.UnsafePointer + 12)
)
var (
// ScalarNodeTypes groups NodeTypes that represent scalar values into a slice for
// convenient use with isOneOf() which is called in .scalarChildWritten().
ScalarNodeTypes = []NodeType{
StringNode,
IntNode,
Int8Node,
Int16Node,
Int32Node,
Int64Node,
UintptrNode,
UintNode,
Uint8Node,
Uint16Node,
Uint32Node,
Uint64Node,
Float32Node,
Float64Node,
BoolNode,
UnsafePointerNode,
SubstitutionNode,
}
)
func (nt NodeType) String() string {
return nodeTypeName(nt)
}
func nodeTypeName(nt NodeType) (s string) {
switch nt {
case PointerNode:
s = "pointer"
case MapNode:
s = "map"
case ArrayNode:
s = "array"
case SliceNode:
s = "slice"
case StructNode:
s = "struct"
case InterfaceNode:
s = "interface"
case StringNode:
s = "string"
case IntNode:
s = "int"
case Int8Node:
s = "int8"
case Int16Node:
s = "int16"
case Int32Node:
s = "int32"
case Int64Node:
s = "int64"
case UintNode:
s = "uInt"
case Uint8Node:
s = "uint8"
case Uint16Node:
s = "uint16"
case Uint32Node:
s = "uint32"
case Uint64Node:
s = "uint64"
case Float32Node:
s = "float32"
case Float64Node:
s = "float64"
case BoolNode:
s = "bool"
case FuncNode:
s = "func"
case InvalidNode:
s = "invalid"
case FieldNode:
s = "field"
case ElementNode:
s = "element"
case UnsafePointerNode:
s = "unsafePointer"
case UintptrNode:
s = "uintptr"
case SubstitutionNode:
s = "substitution"
default:
Panicf("Invalid node type: %d", nt)
}
return s
}