Debian Codegraph @

cmd/signature-fuzzer/internal/fuzz-generator/parm.go

raw symbols SCIP
1 // Copyright 2021 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package generatorscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/
6
7 import (
8 "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/"
9 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
10 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
11 "sortscip-go gomod github.com/golang/go/src go1.25.0 sort/"
12 )
13
14 // parm is an interface describing an abstract parameter var or return
15 // var; there will be concrete types of various sorts that implement
16 // this interface.
17 type parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm# interface {
18
19 // Declare emits text containing a declaration of this param
20 // or return var into the specified buffer. Prefix is a tag to
21 // prepend before the declaration (for example a variable
22 // name) followed by a space; suffix is an arbitrary string to
23 // tack onto the end of the param's type text. Here 'caller'
24 // is set to true if we're emitting the caller part of a test
25 // pair as opposed to the checker.
26 Declarescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#Declare.(b *bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#, prefix string, suffix string, caller bool)
27
28 // GenElemRef returns a pair [X,Y] corresponding to a
29 // component piece of some composite parm, where X is a string
30 // forming the reference (ex: ".field" if we're picking out a
31 // struct field) and Y is a parm object corresponding to the
32 // type of the element.
33 GenElemRefscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#GenElemRef.(elidx int, path string) (string, parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#)
34
35 // GenValue constructs a new concrete random value appropriate
36 // for the type in question and returns it, along with a
37 // sequence number indicating how many random decisions we had
38 // to make. Here "s" is the current generator state, "f" is
39 // the current function we're emitting, value is a sequence
40 // number indicating how many random decisions have been made
41 // up until this point, and 'caller' is set to true if we're
42 // emitting the caller part of a test pair as opposed to the
43 // checker. Return value is a pair [V,I] where V is the text
44 // if the value, and I is a new sequence number reflecting any
45 // additional random choices we had to make. For example, if
46 // the parm is something like "type Foo struct { f1 int32; f2
47 // float64 }" then we might expect GenValue to emit something
48 // like "Foo{int32(-9), float64(123.123)}".
49 GenValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#GenValue.(s *genstatescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/genstate#, f *funcdefscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/funcdef#, value int, caller bool) (string, int)
50
51 // IsControl returns true if this specific param has been marked
52 // as the single param that controls recursion for a recursive
53 // checker function. The test code doesn't check this param for a specific
54 // value, but instead returns early if it has value 0 or decrements it
55 // on a recursive call.
56 IsControlscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#IsControl.() bool
57
58 // NumElements returns the total number of discrete elements contained
59 // in this parm. For non-composite types, this will always be 1.
60 NumElementsscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#NumElements.() int
61
62 // String returns a descriptive string for this parm.
63 Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#String.() string
64
65 // TypeName returns the non-qualified type name for this parm.
66 TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.() string
67
68 // QualName returns a package-qualified type name for this parm.
69 QualNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#QualName.() string
70
71 // HasPointer returns true if this parm is of pointer type, or
72 // if it is a composite that has a pointer element somewhere inside.
73 // Strings and slices return true for this hook.
74 HasPointerscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#HasPointer.() bool
75
76 // IsBlank() returns true if the name of this parm is "_" (that is,
77 // if we randomly chose to make it a blank). SetBlank() is used
78 // to set the 'blank' property for this parm.
79 IsBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#IsBlank.() bool
80 SetBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#SetBlank.(v bool)
81
82 // AddrTaken() return a token indicating whether this parm should
83 // be address taken or not, the nature of the address-taken-ness (see
84 // below at the def of addrTakenHow). SetAddrTaken is used to set
85 // the address taken property of the parm.
86 AddrTakenscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#AddrTaken.() addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow#
87 SetAddrTakenscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#SetAddrTaken.(val addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow#)
88
89 // IsGenVal() returns true if the values of this type should
90 // be obtained by calling a helper func, as opposed to
91 // emitting code inline (as one would for things like numeric
92 // types). SetIsGenVal is used to set the gen-val property of
93 // the parm.
94 IsGenValscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#IsGenVal.() bool
95 SetIsGenValscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#SetIsGenVal.(val bool)
96
97 // SkipCompare() returns true if we've randomly decided that
98 // we don't want to compare the value for this param or
99 // return. SetSkipCompare is used to set the skip-compare
100 // property of the parm.
101 SkipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#SkipCompare.() skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#
102 SetSkipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#SetSkipCompare.(val skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#)
103 }
104
105 type addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow# uint8
106
107 const (
108 // Param not address taken.
109 notAddrTakenscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/notAddrTaken. addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow# = 0
110
111 // Param address is taken and used for simple reads/writes.
112 addrTakenSimplescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenSimple. addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow# = 1
113
114 // Param address is taken and passed to a well-behaved function.
115 addrTakenPassedscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenPassed. addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow# = 2
116
117 // Param address is taken and stored to a global var.
118 addrTakenHeapscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHeap. addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow# = 3
119 )
120
121 func (a *addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow#) AddrTakenscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow#AddrTaken().() addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow# {
122 return *a
123 }
124
125 func (a *addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow#) SetAddrTakenscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow#SetAddrTaken().(val addrTakenHowscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/addrTakenHow#) {
126 *a = val
127 }
128
129 type isBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isBlank# bool
130
131 func (b *isBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isBlank#) IsBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isBlank#IsBlank().() bool {
132 return bool(*b)
133 }
134
135 func (b *isBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isBlank#) SetBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isBlank#SetBlank().(val bool) {
136 *b = isBlankscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isBlank#(val)
137 }
138
139 type isGenValFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isGenValFunc# bool
140
141 func (g *isGenValFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isGenValFunc#) IsGenValscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isGenValFunc#IsGenVal().() bool {
142 return bool(*g)
143 }
144
145 func (g *isGenValFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isGenValFunc#) SetIsGenValscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isGenValFunc#SetIsGenVal().(val bool) {
146 *g = isGenValFuncscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/isGenValFunc#(val)
147 }
148
149 type skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare# int
150
151 const (
152 // Param not address taken.
153 SkipAllscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/SkipAll. = -1
154 SkipNonescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/SkipNone. = 0
155 SkipPayloadscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/SkipPayload. = 1
156 )
157
158 func (s *skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#) SkipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#SkipCompare().() skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare# {
159 return skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#(*s)
160 }
161
162 func (s *skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#) SetSkipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#SetSkipCompare().(val skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#) {
163 *s = skipComparescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/skipCompare#(val)
164 }
165
166 // containedParms takes an arbitrary param 'p' and returns a slice
167 // with 'p' itself plus any component parms contained within 'p'.
168 func containedParmsscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/containedParms().(p parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#) []parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm# {
169 visited := make(map[string]parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#)
170 worklist := []parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#{p}
171
172 addToWork := func(p parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#) {
173 if p == nil {
174 panic("not expected")
175 }
176 if _, ok := visited[p.TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.()]; !ok {
177 worklist = append(worklist, p)
178 }
179 }
180
181 for len(worklist) != 0 {
182 cp := worklist[0]
183 worklist = worklist[1:]
184 if _, ok := visited[cp.TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.()]; ok {
185 continue
186 }
187 visited[cp.TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.()] = cp
188 switch x := cp.(type) {
189 case *mapparmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/mapparm#:
190 addToWork(x.keytypescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/mapparm#keytype.)
191 addToWork(x.valtypescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/mapparm#valtype.)
192 case *structparmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/structparm#:
193 for _, fld := range x.fieldsscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/structparm#fields. {
194 addToWork(fld)
195 }
196 case *arrayparmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/arrayparm#:
197 addToWork(x.eltypescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/arrayparm#eltype.)
198 case *pointerparmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/pointerparm#:
199 addToWork(x.totypescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/pointerparm#totype.)
200 case *typedefparmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/typedefparm#:
201 addToWork(x.targetscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/typedefparm#target.)
202 }
203 }
204 rv := []parmscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#{}
205 for _, v := range visited {
206 rv = append(rv, v)
207 }
208 sortscip-go gomod github.com/golang/go/src go1.25.0 sort/.Slicescip-go gomod github.com/golang/go/src go1.25.0 sort/Slice().(rv, func(i, j int) bool {
209 if rv[i].TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.() == rv[j].TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.() {
210 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., "%d %d %+v %+v %s %s\n", i, j, rv[i], rv[i].Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#String.(), rv[j], rv[j].Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#String.())
211 panic("unexpected")
212 }
213 return rv[i].TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.() < rv[j].TypeNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/signature-fuzzer/internal/fuzz-generator`/parm#TypeName.()
214 })
215 return rv
216 }