/
typeinfo.go
47 lines (40 loc) · 1.33 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
// 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 typeInfo struct {
// These Fields are reset for each type being generated.
Name string // Name of the NullJson type.
Import string // import path of the NullJson type.
valueType string // The type of the Data in NullJson.
valueImport string // import path of the NullJson's Data.
valueIsPointer bool // whether the Data'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
}