-
Notifications
You must be signed in to change notification settings - Fork 12
/
typeinfo.go
59 lines (49 loc) · 1.47 KB
/
typeinfo.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
// Copyright 2020 The searKing Author. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// TypeInfo for Parsing.
// Also includes a Lexical Analysis and Syntactic Analysis.
package main
import (
"fmt"
"github.com/searKing/golang/tools/pkg/ast/generic"
)
type tokenType int
const (
tokenTypeParen tokenType = iota
tokenTypeName
)
type _token struct {
typ tokenType
value string
}
type typeInfo struct {
// These fields are reset for each type being generated.
Name string // Name of the sync.Pool type.
Import string // import path of the sync.Pool type.
valueType string // The type of the value in sync.Pool.
valueImport string // import path of the sync.Pool's value.
valueIsPointer bool // whether the value's type is ptr
valueTypePrefix string // The type's prefix, such as []*[]
}
func newTypeInfo(input string) []typeInfo {
var infos []typeInfo
for _, info := range generic.New(input) {
info_ := typeInfo{
Name: info.Name,
Import: info.Import,
}
for i, template := range info.TemplateTypes {
if i == 0 {
info_.valueImport = template.Import
info_.valueType = template.Type
info_.valueIsPointer = template.IsPointer
info_.valueTypePrefix = template.TypePrefix
continue
}
panic(fmt.Sprintf("unexpected redundant #%d template type: %s, only 1 is expected", i, &template))
}
infos = append(infos, info_)
}
return infos
}