github.com/pankona/gometalinter@v2.0.11+incompatible/_linters/src/honnef.co/go/tools/staticcheck/vrp/channel.go (about) 1 package vrp 2 3 import ( 4 "fmt" 5 6 "honnef.co/go/tools/ssa" 7 ) 8 9 type ChannelInterval struct { 10 Size IntInterval 11 } 12 13 func (c ChannelInterval) Union(other Range) Range { 14 i, ok := other.(ChannelInterval) 15 if !ok { 16 i = ChannelInterval{EmptyIntInterval} 17 } 18 if c.Size.Empty() || !c.Size.IsKnown() { 19 return i 20 } 21 if i.Size.Empty() || !i.Size.IsKnown() { 22 return c 23 } 24 return ChannelInterval{ 25 Size: c.Size.Union(i.Size).(IntInterval), 26 } 27 } 28 29 func (c ChannelInterval) String() string { 30 return c.Size.String() 31 } 32 33 func (c ChannelInterval) IsKnown() bool { 34 return c.Size.IsKnown() 35 } 36 37 type MakeChannelConstraint struct { 38 aConstraint 39 Buffer ssa.Value 40 } 41 type ChannelChangeTypeConstraint struct { 42 aConstraint 43 X ssa.Value 44 } 45 46 func NewMakeChannelConstraint(buffer, y ssa.Value) Constraint { 47 return &MakeChannelConstraint{NewConstraint(y), buffer} 48 } 49 func NewChannelChangeTypeConstraint(x, y ssa.Value) Constraint { 50 return &ChannelChangeTypeConstraint{NewConstraint(y), x} 51 } 52 53 func (c *MakeChannelConstraint) Operands() []ssa.Value { return []ssa.Value{c.Buffer} } 54 func (c *ChannelChangeTypeConstraint) Operands() []ssa.Value { return []ssa.Value{c.X} } 55 56 func (c *MakeChannelConstraint) String() string { 57 return fmt.Sprintf("%s = make(chan, %s)", c.Y().Name, c.Buffer.Name()) 58 } 59 func (c *ChannelChangeTypeConstraint) String() string { 60 return fmt.Sprintf("%s = changetype(%s)", c.Y().Name, c.X.Name()) 61 } 62 63 func (c *MakeChannelConstraint) Eval(g *Graph) Range { 64 i, ok := g.Range(c.Buffer).(IntInterval) 65 if !ok { 66 return ChannelInterval{NewIntInterval(NewZ(0), PInfinity)} 67 } 68 if i.Lower.Sign() == -1 { 69 i.Lower = NewZ(0) 70 } 71 return ChannelInterval{i} 72 } 73 func (c *ChannelChangeTypeConstraint) Eval(g *Graph) Range { return g.Range(c.X) }