Commit fda831ed authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: encapsulate reads of gc.Type.Funarg

Changes generated with eg and then manually
checked and in some cases simplified.

Passes toolstash -cmp.

Change-Id: I2119f37f003368ce1884d2863b406d6ffbfe38c7
Reviewed-on: https://go-review.googlesource.com/21563Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent e0307c25
...@@ -263,7 +263,7 @@ func dowidth(t *Type) { ...@@ -263,7 +263,7 @@ func dowidth(t *Type) {
} }
case TSTRUCT: case TSTRUCT:
if t.Funarg { if t.IsFuncArgStruct() {
Fatalf("dowidth fn struct %v", t) Fatalf("dowidth fn struct %v", t)
} }
w = widstruct(t, t, 0, 1) w = widstruct(t, t, 0, 1)
...@@ -335,7 +335,7 @@ func checkwidth(t *Type) { ...@@ -335,7 +335,7 @@ func checkwidth(t *Type) {
// function arg structs should not be checked // function arg structs should not be checked
// outside of the enclosing function. // outside of the enclosing function.
if t.Funarg { if t.IsFuncArgStruct() {
Fatalf("checkwidth %v", t) Fatalf("checkwidth %v", t)
} }
......
...@@ -742,7 +742,7 @@ func basetypeName(t *Type) string { ...@@ -742,7 +742,7 @@ func basetypeName(t *Type) string {
} }
func (p *exporter) paramList(params *Type, numbered bool) { func (p *exporter) paramList(params *Type, numbered bool) {
if !params.IsStruct() || !params.Funarg { if !params.IsFuncArgStruct() {
Fatalf("exporter: parameter list expected") Fatalf("exporter: parameter list expected")
} }
......
...@@ -1435,7 +1435,7 @@ func esccall(e *EscState, n *Node, up *Node) { ...@@ -1435,7 +1435,7 @@ func esccall(e *EscState, n *Node, up *Node) {
ll := n.List ll := n.List
if n.List.Len() == 1 { if n.List.Len() == 1 {
a := n.List.First() a := n.List.First()
if a.Type.IsStruct() && a.Type.Funarg { // f(g()). if a.Type.IsFuncArgStruct() { // f(g())
ll = e.nodeEscState(a).Escretval ll = e.nodeEscState(a).Escretval
} }
} }
......
...@@ -592,7 +592,7 @@ func dumpasmhdr() { ...@@ -592,7 +592,7 @@ func dumpasmhdr() {
case OTYPE: case OTYPE:
t := n.Type t := n.Type
if !t.IsStruct() || t.Map != nil || t.Funarg { if !t.IsStruct() || t.Map != nil || t.IsFuncArgStruct() {
break break
} }
fmt.Fprintf(b, "#define %s__size %d\n", t.Sym.Name, int(t.Width)) fmt.Fprintf(b, "#define %s__size %d\n", t.Sym.Name, int(t.Width))
......
...@@ -690,7 +690,7 @@ func typefmt(t *Type, flag FmtFlag) string { ...@@ -690,7 +690,7 @@ func typefmt(t *Type, flag FmtFlag) string {
} }
var buf bytes.Buffer var buf bytes.Buffer
if t.Funarg { if t.IsFuncArgStruct() {
buf.WriteString("(") buf.WriteString("(")
var flag1 FmtFlag var flag1 FmtFlag
if fmtmode == FTypeId || fmtmode == FErr { // no argument names on function signature, and no "noescape"/"nosplit" tags if fmtmode == FTypeId || fmtmode == FErr { // no argument names on function signature, and no "noescape"/"nosplit" tags
......
...@@ -541,7 +541,7 @@ func nodarg(t interface{}, fp int) *Node { ...@@ -541,7 +541,7 @@ func nodarg(t interface{}, fp int) *Node {
switch t := t.(type) { switch t := t.(type) {
case *Type: case *Type:
// entire argument struct, not just one arg // entire argument struct, not just one arg
if !t.IsStruct() || !t.Funarg { if !t.IsFuncArgStruct() {
Fatalf("nodarg: bad type %v", t) Fatalf("nodarg: bad type %v", t)
} }
n = Nod(ONAME, nil, nil) n = Nod(ONAME, nil, nil)
......
...@@ -324,7 +324,7 @@ func ismulticall(l Nodes) bool { ...@@ -324,7 +324,7 @@ func ismulticall(l Nodes) bool {
// Copyret emits t1, t2, ... = n, where n is a function call, // Copyret emits t1, t2, ... = n, where n is a function call,
// and then returns the list t1, t2, .... // and then returns the list t1, t2, ....
func copyret(n *Node, order *Order) []*Node { func copyret(n *Node, order *Order) []*Node {
if !n.Type.IsStruct() || !n.Type.Funarg { if !n.Type.IsFuncArgStruct() {
Fatalf("copyret %v %d", n.Type, n.Left.Type.Results().NumFields()) Fatalf("copyret %v %d", n.Type, n.Left.Type.Results().NumFields())
} }
......
...@@ -127,7 +127,7 @@ type Type struct { ...@@ -127,7 +127,7 @@ type Type struct {
Chan ChanDir Chan ChanDir
Trecur uint8 // to detect loops Trecur uint8 // to detect loops
Printed bool Printed bool
Funarg bool // on TSTRUCT and TFIELD Funarg bool // TSTRUCT only: whether this struct represents function parameters
Local bool // created in this file Local bool // created in this file
Deferwidth bool Deferwidth bool
Broke bool // broken type definition. Broke bool // broken type definition.
...@@ -566,6 +566,11 @@ func (t *Type) SetNname(n *Node) { ...@@ -566,6 +566,11 @@ func (t *Type) SetNname(n *Node) {
t.nname = n t.nname = n
} }
// IsFuncArgStruct reports whether t is a struct representing function parameters.
func (t *Type) IsFuncArgStruct() bool {
return t.Etype == TSTRUCT && t.Funarg
}
func (t *Type) Methods() *Fields { func (t *Type) Methods() *Fields {
// TODO(mdempsky): Validate t? // TODO(mdempsky): Validate t?
return &t.methods return &t.methods
......
...@@ -1607,7 +1607,7 @@ OpSwitch: ...@@ -1607,7 +1607,7 @@ OpSwitch:
// Unpack multiple-return result before type-checking. // Unpack multiple-return result before type-checking.
var funarg *Type var funarg *Type
if t.IsStruct() && t.Funarg { if t.IsFuncArgStruct() {
funarg = t funarg = t
t = t.Field(0).Type t = t.Field(0).Type
} }
...@@ -2159,7 +2159,7 @@ OpSwitch: ...@@ -2159,7 +2159,7 @@ OpSwitch:
} }
t := n.Type t := n.Type
if t != nil && !t.Funarg && n.Op != OTYPE { if t != nil && !t.IsFuncArgStruct() && n.Op != OTYPE {
switch t.Etype { switch t.Etype {
case TFUNC, // might have TANY; wait until its called case TFUNC, // might have TANY; wait until its called
TANY, TANY,
...@@ -2611,7 +2611,7 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc ...@@ -2611,7 +2611,7 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc
if nl.Len() == 1 { if nl.Len() == 1 {
n = nl.First() n = nl.First()
if n.Type != nil { if n.Type != nil {
if n.Type.IsStruct() && n.Type.Funarg { if n.Type.IsFuncArgStruct() {
if !hasddd(tstruct) { if !hasddd(tstruct) {
n1 := tstruct.NumFields() n1 := tstruct.NumFields()
n2 := n.Type.NumFields() n2 := n.Type.NumFields()
...@@ -3359,7 +3359,7 @@ func typecheckas2(n *Node) { ...@@ -3359,7 +3359,7 @@ func typecheckas2(n *Node) {
} }
switch r.Op { switch r.Op {
case OCALLMETH, OCALLINTER, OCALLFUNC: case OCALLMETH, OCALLINTER, OCALLFUNC:
if !r.Type.IsStruct() || !r.Type.Funarg { if !r.Type.IsFuncArgStruct() {
break break
} }
cr = r.Type.NumFields() cr = r.Type.NumFields()
......
...@@ -1783,7 +1783,7 @@ func ascompatte(op Op, call *Node, isddd bool, nl *Type, lr []*Node, fp int, ini ...@@ -1783,7 +1783,7 @@ func ascompatte(op Op, call *Node, isddd bool, nl *Type, lr []*Node, fp int, ini
var nn []*Node var nn []*Node
// f(g()) where g has multiple return values // f(g()) where g has multiple return values
if r != nil && len(lr) <= 1 && r.Type.IsStruct() && r.Type.Funarg { if r != nil && len(lr) <= 1 && r.Type.IsFuncArgStruct() {
// optimization - can do block copy // optimization - can do block copy
if eqtypenoname(r.Type, nl) { if eqtypenoname(r.Type, nl) {
arg := nodarg(nl, fp) arg := nodarg(nl, fp)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment