File: mapparm.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 22,724 kB
  • sloc: javascript: 2,027; asm: 1,645; sh: 166; yacc: 155; makefile: 49; ansic: 8
file content (91 lines) | stat: -rw-r--r-- 1,905 bytes parent folder | download | duplicates (3)
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
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package generator

import (
	"bytes"
	"fmt"
)

// mapparm describes a parameter of map type; it implements the
// "parm" interface.
type mapparm struct {
	aname   string
	qname   string
	keytype parm
	valtype parm
	keytmp  string
	isBlank
	addrTakenHow
	isGenValFunc
	skipCompare
}

func (p mapparm) IsControl() bool {
	return false
}

func (p mapparm) TypeName() string {
	return p.aname
}

func (p mapparm) QualName() string {
	return p.qname
}

func (p mapparm) Declare(b *bytes.Buffer, prefix string, suffix string, caller bool) {
	n := p.aname
	if caller {
		n = p.qname
	}
	b.WriteString(fmt.Sprintf("%s %s%s", prefix, n, suffix))
}

func (p mapparm) String() string {
	return fmt.Sprintf("%s map[%s]%s", p.aname,
		p.keytype.String(), p.valtype.String())
}

func (p mapparm) GenValue(s *genstate, f *funcdef, value int, caller bool) (string, int) {
	var buf bytes.Buffer

	verb(5, "mapparm.GenValue(%d)", value)

	n := p.aname
	if caller {
		n = p.qname
	}
	buf.WriteString(fmt.Sprintf("%s{", n))
	buf.WriteString(p.keytmp + ": ")

	var valstr string
	valstr, value = s.GenValue(f, p.valtype, value, caller)
	buf.WriteString(valstr + "}")
	return buf.String(), value
}

func (p mapparm) GenElemRef(elidx int, path string) (string, parm) {
	vne := p.valtype.NumElements()
	verb(4, "begin GenElemRef(%d,%s) on %s %d", elidx, path, p.String(), vne)

	ppath := fmt.Sprintf("%s[mkt.%s]", path, p.keytmp)

	// otherwise dig into the value
	verb(4, "recur GenElemRef(%d,...)", elidx)

	// Otherwise our victim is somewhere inside the value
	if p.IsBlank() {
		ppath = "_"
	}
	return p.valtype.GenElemRef(elidx, ppath)
}

func (p mapparm) NumElements() int {
	return p.valtype.NumElements()
}

func (p mapparm) HasPointer() bool {
	return true
}