GoPLS Viewer

Home|gopls/cmd/signature-fuzzer/internal/fuzz-generator/arrayparm.go
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
5package generator
6
7import (
8    "bytes"
9    "fmt"
10)
11
12// arrayparm describes a parameter of array type; it implements the
13// "parm" interface.
14type arrayparm struct {
15    aname     string
16    qname     string
17    nelements uint8
18    eltype    parm
19    slice     bool
20    isBlank
21    addrTakenHow
22    isGenValFunc
23    skipCompare
24}
25
26func (p arrayparmIsControl() bool {
27    return false
28}
29
30func (p arrayparmTypeName() string {
31    return p.aname
32}
33
34func (p arrayparmQualName() string {
35    return p.qname
36}
37
38func (p arrayparmDeclare(b *bytes.Bufferprefix stringsuffix stringcaller bool) {
39    n := p.aname
40    if caller {
41        n = p.qname
42    }
43    b.WriteString(fmt.Sprintf("%s %s%s"prefixnsuffix))
44}
45
46func (p arrayparmString() string {
47    return fmt.Sprintf("%s %d-element array of %s"p.anamep.nelementsp.eltype.String())
48}
49
50func (p arrayparmGenValue(s *genstatef *funcdefvalue intcaller bool) (stringint) {
51    var buf bytes.Buffer
52
53    verb(5"arrayparm.GenValue(%d)"value)
54
55    n := p.aname
56    if caller {
57        n = p.qname
58    }
59    buf.WriteString(fmt.Sprintf("%s{"n))
60    for i := 0i < int(p.nelements); i++ {
61        var valstr string
62        valstrvalue = s.GenValue(fp.eltypevaluecaller)
63        writeCom(&bufi)
64        buf.WriteString(valstr)
65    }
66    buf.WriteString("}")
67    return buf.String(), value
68}
69
70func (p arrayparmGenElemRef(elidx intpath string) (stringparm) {
71    ene := p.eltype.NumElements()
72    verb(4"begin GenElemRef(%d,%s) on %s ene %d"elidxpathp.String(), ene)
73
74    // For empty arrays, convention is to return empty string
75    if ene == 0 {
76        return "", &p
77    }
78
79    // Find slot within array of element of interest
80    slot := elidx / ene
81
82    // If this is the element we're interested in, return it
83    if ene == 1 {
84        verb(4"hit scalar element")
85        epath := fmt.Sprintf("%s[%d]"pathslot)
86        if path == "_" || p.IsBlank() {
87            epath = "_"
88        }
89        return epathp.eltype
90    }
91
92    verb(4"recur slot=%d GenElemRef(%d,...)"slotelidx-(slot*ene))
93
94    // Otherwise our victim is somewhere inside the slot
95    ppath := fmt.Sprintf("%s[%d]"pathslot)
96    if p.IsBlank() {
97        ppath = "_"
98    }
99    return p.eltype.GenElemRef(elidx-(slot*ene), ppath)
100}
101
102func (p arrayparmNumElements() int {
103    return p.eltype.NumElements() * int(p.nelements)
104}
105
106func (p arrayparmHasPointer() bool {
107    return p.eltype.HasPointer() || p.slice
108}
109
MembersX
arrayparm.GenValue
arrayparm.GenValue.s
arrayparm.HasPointer.p
arrayparm.HasPointer
arrayparm.qname
arrayparm.slice
arrayparm.Declare.prefix
arrayparm.GenElemRef.elidx
arrayparm.GenElemRef.ppath
arrayparm.eltype
arrayparm.String.p
arrayparm.GenValue.n
arrayparm.Declare
arrayparm.Declare.suffix
arrayparm.GenValue.f
arrayparm.GenElemRef.p
arrayparm
arrayparm.IsControl.p
arrayparm.TypeName
arrayparm.GenValue.p
arrayparm.GenValue.buf
arrayparm.aname
arrayparm.Declare.caller
arrayparm.String
arrayparm.GenElemRef.ene
arrayparm.NumElements.p
arrayparm.IsControl
arrayparm.GenValue.value
arrayparm.GenElemRef
arrayparm.Declare.b
arrayparm.Declare.n
fmt
arrayparm.TypeName.p
arrayparm.QualName.p
arrayparm.GenValue.caller
arrayparm.GenValue.i
arrayparm.GenElemRef.path
bytes
arrayparm.QualName
arrayparm.Declare.p
arrayparm.NumElements
arrayparm.nelements
arrayparm.GenValue.BlockStmt.valstr
arrayparm.GenElemRef.BlockStmt.epath
Members
X