return n
}
-func nodeWithClass(n Node, c Class) *Node {
- n.SetClass(c)
- n.Name = new(Name)
- return &n
-}
-
// Test all code paths for cmpstackvarlt.
func TestCmpstackvar(t *testing.T) {
+ nod := func(xoffset int64, t *types.Type, s *types.Sym, cl Class) *Node {
+ if s == nil {
+ s = &types.Sym{Name: "."}
+ }
+ n := newname(s)
+ n.Type = t
+ n.Xoffset = xoffset
+ n.SetClass(cl)
+ return n
+ }
testdata := []struct {
a, b *Node
lt bool
}{
{
- nodeWithClass(Node{}, PAUTO),
- nodeWithClass(Node{}, PFUNC),
+ nod(0, nil, nil, PAUTO),
+ nod(0, nil, nil, PFUNC),
false,
},
{
- nodeWithClass(Node{}, PFUNC),
- nodeWithClass(Node{}, PAUTO),
+ nod(0, nil, nil, PFUNC),
+ nod(0, nil, nil, PAUTO),
true,
},
{
- nodeWithClass(Node{Xoffset: 0}, PFUNC),
- nodeWithClass(Node{Xoffset: 10}, PFUNC),
+ nod(0, nil, nil, PFUNC),
+ nod(10, nil, nil, PFUNC),
true,
},
{
- nodeWithClass(Node{Xoffset: 20}, PFUNC),
- nodeWithClass(Node{Xoffset: 10}, PFUNC),
+ nod(20, nil, nil, PFUNC),
+ nod(10, nil, nil, PFUNC),
false,
},
{
- nodeWithClass(Node{Xoffset: 10}, PFUNC),
- nodeWithClass(Node{Xoffset: 10}, PFUNC),
+ nod(10, nil, nil, PFUNC),
+ nod(10, nil, nil, PFUNC),
false,
},
{
- nodeWithClass(Node{Xoffset: 10}, PPARAM),
- nodeWithClass(Node{Xoffset: 20}, PPARAMOUT),
+ nod(10, nil, nil, PPARAM),
+ nod(20, nil, nil, PPARAMOUT),
true,
},
{
- nodeWithClass(Node{Xoffset: 10}, PPARAMOUT),
- nodeWithClass(Node{Xoffset: 20}, PPARAM),
+ nod(10, nil, nil, PPARAMOUT),
+ nod(20, nil, nil, PPARAM),
true,
},
{
- markUsed(nodeWithClass(Node{}, PAUTO)),
- nodeWithClass(Node{}, PAUTO),
+ markUsed(nod(0, nil, nil, PAUTO)),
+ nod(0, nil, nil, PAUTO),
true,
},
{
- nodeWithClass(Node{}, PAUTO),
- markUsed(nodeWithClass(Node{}, PAUTO)),
+ nod(0, nil, nil, PAUTO),
+ markUsed(nod(0, nil, nil, PAUTO)),
false,
},
{
- nodeWithClass(Node{Type: typeWithoutPointers()}, PAUTO),
- nodeWithClass(Node{Type: typeWithPointers()}, PAUTO),
+ nod(0, typeWithoutPointers(), nil, PAUTO),
+ nod(0, typeWithPointers(), nil, PAUTO),
false,
},
{
- nodeWithClass(Node{Type: typeWithPointers()}, PAUTO),
- nodeWithClass(Node{Type: typeWithoutPointers()}, PAUTO),
+ nod(0, typeWithPointers(), nil, PAUTO),
+ nod(0, typeWithoutPointers(), nil, PAUTO),
true,
},
{
- markNeedZero(nodeWithClass(Node{Type: &types.Type{}}, PAUTO)),
- nodeWithClass(Node{Type: &types.Type{}, Name: &Name{}}, PAUTO),
+ markNeedZero(nod(0, &types.Type{}, nil, PAUTO)),
+ nod(0, &types.Type{}, nil, PAUTO),
true,
},
{
- nodeWithClass(Node{Type: &types.Type{}, Name: &Name{}}, PAUTO),
- markNeedZero(nodeWithClass(Node{Type: &types.Type{}}, PAUTO)),
+ nod(0, &types.Type{}, nil, PAUTO),
+ markNeedZero(nod(0, &types.Type{}, nil, PAUTO)),
false,
},
{
- nodeWithClass(Node{Type: &types.Type{Width: 1}, Name: &Name{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{Width: 2}, Name: &Name{}}, PAUTO),
+ nod(0, &types.Type{Width: 1}, nil, PAUTO),
+ nod(0, &types.Type{Width: 2}, nil, PAUTO),
false,
},
{
- nodeWithClass(Node{Type: &types.Type{Width: 2}, Name: &Name{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{Width: 1}, Name: &Name{}}, PAUTO),
+ nod(0, &types.Type{Width: 2}, nil, PAUTO),
+ nod(0, &types.Type{Width: 1}, nil, PAUTO),
true,
},
{
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "abc"}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "xyz"}}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "abc"}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, PAUTO),
true,
},
{
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "abc"}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "abc"}}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "abc"}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "abc"}, PAUTO),
false,
},
{
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "xyz"}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "abc"}}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "abc"}, PAUTO),
false,
},
}
}
func TestStackvarSort(t *testing.T) {
+ nod := func(xoffset int64, t *types.Type, s *types.Sym, cl Class) *Node {
+ n := newname(s)
+ n.Type = t
+ n.Xoffset = xoffset
+ n.SetClass(cl)
+ return n
+ }
inp := []*Node{
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Xoffset: 0, Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- nodeWithClass(Node{Xoffset: 10, Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- nodeWithClass(Node{Xoffset: 20, Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- markUsed(nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO)),
- nodeWithClass(Node{Type: typeWithoutPointers(), Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO),
- markNeedZero(nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO)),
- nodeWithClass(Node{Type: &types.Type{Width: 1}, Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{Width: 2}, Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "abc"}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "xyz"}}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{}, PFUNC),
+ nod(0, &types.Type{}, &types.Sym{}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{}, PFUNC),
+ nod(10, &types.Type{}, &types.Sym{}, PFUNC),
+ nod(20, &types.Type{}, &types.Sym{}, PFUNC),
+ markUsed(nod(0, &types.Type{}, &types.Sym{}, PAUTO)),
+ nod(0, typeWithoutPointers(), &types.Sym{}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{}, PAUTO),
+ markNeedZero(nod(0, &types.Type{}, &types.Sym{}, PAUTO)),
+ nod(0, &types.Type{Width: 1}, &types.Sym{}, PAUTO),
+ nod(0, &types.Type{Width: 2}, &types.Sym{}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "abc"}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, PAUTO),
}
want := []*Node{
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- nodeWithClass(Node{Xoffset: 0, Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- nodeWithClass(Node{Xoffset: 10, Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- nodeWithClass(Node{Xoffset: 20, Type: &types.Type{}, Sym: &types.Sym{}}, PFUNC),
- markUsed(nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO)),
- markNeedZero(nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO)),
- nodeWithClass(Node{Type: &types.Type{Width: 2}, Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{Width: 1}, Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "abc"}}, PAUTO),
- nodeWithClass(Node{Type: &types.Type{}, Sym: &types.Sym{Name: "xyz"}}, PAUTO),
- nodeWithClass(Node{Type: typeWithoutPointers(), Sym: &types.Sym{}}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{}, PFUNC),
+ nod(0, &types.Type{}, &types.Sym{}, PFUNC),
+ nod(10, &types.Type{}, &types.Sym{}, PFUNC),
+ nod(20, &types.Type{}, &types.Sym{}, PFUNC),
+ markUsed(nod(0, &types.Type{}, &types.Sym{}, PAUTO)),
+ markNeedZero(nod(0, &types.Type{}, &types.Sym{}, PAUTO)),
+ nod(0, &types.Type{Width: 2}, &types.Sym{}, PAUTO),
+ nod(0, &types.Type{Width: 1}, &types.Sym{}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "abc"}, PAUTO),
+ nod(0, &types.Type{}, &types.Sym{Name: "xyz"}, PAUTO),
+ nod(0, typeWithoutPointers(), &types.Sym{}, PAUTO),
}
sort.Sort(byStackVar(inp))
if !reflect.DeepEqual(want, inp) {