/
generic_type.go
109 lines (86 loc) · 2.79 KB
/
generic_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
package def
import (
"fmt"
"io"
)
type genericNamer struct {
registryName, publicName, internalName string
}
func (t *genericNamer) RegistryName() string { return t.registryName }
func (t *genericNamer) PublicName() string { return t.publicName }
func (t *genericNamer) InternalName() string { return t.internalName }
type genericType struct {
genericNamer
isResolved bool
comment string
pointerDepth int
aliasTypeName string
resolvedAliasType TypeDefiner
values []ValueDefiner
}
func (t *genericType) Category() TypeCategory { return CatNone }
func (t *genericType) Resolve(tr TypeRegistry, vr ValueRegistry) *IncludeSet {
if t.isResolved {
return NewIncludeSet()
}
rval := NewIncludeSet()
if t.publicName == "" {
t.publicName = RenameIdentifier(t.registryName)
}
t.internalName = t.publicName
if t.aliasTypeName != "" {
t.resolvedAliasType = tr[t.aliasTypeName]
rval.MergeWith(t.resolvedAliasType.Resolve(tr, vr))
}
rval.ResolvedTypes[t.registryName] = t
return rval
}
func (t *genericType) IsIdenticalPublicAndInternal() bool { return true }
func (t *genericType) SetAliasType(td TypeDefiner) {
t.aliasTypeName = td.RegistryName()
}
func (t *genericType) IsAlias() bool { return t.resolvedAliasType != nil }
func (t *genericType) AllValues() []ValueDefiner {
return t.values
}
func (t *genericType) PushValue(vd ValueDefiner) {
// Push will overwrite an existing name
for i, v := range t.values {
if v.RegistryName() == vd.RegistryName() {
t.values[i] = vd
return
}
}
t.values = append(t.values, vd)
}
func (t *genericType) AppendValues(vals ValueRegistry) {
for _, v := range vals {
t.values = append(t.values, v)
}
}
func (t *genericType) PrintGlobalDeclarations(io.Writer, int, bool) {}
func (t *genericType) PrintFileInitContent(io.Writer) {}
func (t *genericType) RegisterImports(reg map[string]bool) {}
func (t *genericType) PrintPublicDeclaration(w io.Writer) {
fmt.Fprintln(w, "PrintPublicDeclaration not defined for genericType")
}
func (t *genericType) PrintInternalDeclaration(w io.Writer) {}
func (t *genericType) TranslateToPublic(inputVar string) string {
return inputVar
}
func (t *genericType) TranslateToInternal(inputVar string) string {
return inputVar
}
func (t *genericType) PrintPublicToInternalTranslation(w io.Writer, inputVar, outputVar, _ string) {
fmt.Fprintf(w, "%s := %s\n", outputVar, inputVar)
}
func (t *genericType) PrintTranslateToInternal(w io.Writer, inputVar, outputVar string) {
fmt.Fprintf(w, "%s = %s", outputVar, inputVar)
}
func (t *genericType) PrintDocLink(w io.Writer) {
fmt.Fprintf(w, "// %s: ", t.PublicName())
if t.comment != "" {
fmt.Fprint(w, t.comment, "\n// ")
}
fmt.Fprintf(w, "See https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/%s.html\n", t.RegistryName())
}