Debian Codegraph @

cmd/signature-fuzzer/internal/fuzz-generator/pointerparm.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 generator
6
7 import (
8 "bytes"
9 "fmt"
10 )
11
12 // pointerparm describes a parameter of pointer type; it implements the
13 // "parm" interface.
14 type pointerparm struct {
15 tag string
16 totype parm
17 isBlank
18 addrTakenHow
19 isGenValFunc
20 skipCompare
21 }
22
23 func (p pointerparm) Declare(b *bytes.Buffer, prefix string, suffix string, caller bool) {
24 n := p.totype.TypeName()
25 if caller {
26 n = p.totype.QualName()
27 }
28 b.WriteString(fmt.Sprintf("%s *%s%s", prefix, n, suffix))
29 }
30
31 func (p pointerparm) GenElemRef(elidx int, path string) (string, parm) {
32 return path, &p
33 }
34
35 func (p pointerparm) GenValue(s *genstate, f *funcdef, value int, caller bool) (string, int) {
36 pref := ""
37 if caller {
38 pref = s.checkerPkg(s.pkidx) + "."
39 }
40 var valstr string
41 valstr, value = s.GenValue(f, p.totype, value, caller)
42 fname := s.genAllocFunc(p.totype)
43 return fmt.Sprintf("%s%s(%s)", pref, fname, valstr), value
44 }
45
46 func (p pointerparm) IsControl() bool {
47 return false
48 }
49
50 func (p pointerparm) NumElements() int {
51 return 1
52 }
53
54 func (p pointerparm) String() string {
55 return fmt.Sprintf("*%s", p.totype)
56 }
57
58 func (p pointerparm) TypeName() string {
59 return fmt.Sprintf("*%s", p.totype.TypeName())
60 }
61
62 func (p pointerparm) QualName() string {
63 return fmt.Sprintf("*%s", p.totype.QualName())
64 }
65
66 func mkPointerParm(to parm) pointerparm {
67 var pp pointerparm
68 pp.tag = "pointer"
69 pp.totype = to
70 return pp
71 }
72
73 func (p pointerparm) HasPointer() bool {
74 return true
75 }