diff --git a/annotation/consume_trigger.go b/annotation/consume_trigger.go index b3ce22ac..9a58229f 100644 --- a/annotation/consume_trigger.go +++ b/annotation/consume_trigger.go @@ -53,6 +53,9 @@ type ConsumingAnnotationTrigger interface { // equals returns true if the passed ConsumingAnnotationTrigger is equal to this one equals(ConsumingAnnotationTrigger) bool + + // Copy returns a deep copy of this ConsumingAnnotationTrigger + Copy() ConsumingAnnotationTrigger } // customPos has the below default implementations, in which case ConsumeTrigger.Pos() will return a default value. @@ -93,6 +96,13 @@ func (t *TriggerIfNonNil) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (t *TriggerIfNonNil) Copy() ConsumingAnnotationTrigger { + copyConsumer := *t + t.Ann = t.Ann.copy() + return ©Consumer +} + // Prestring returns this Prestring as a Prestring func (*TriggerIfNonNil) Prestring() Prestring { return TriggerIfNonNilPrestring{} @@ -130,6 +140,13 @@ func (t *TriggerIfDeepNonNil) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (t *TriggerIfDeepNonNil) Copy() ConsumingAnnotationTrigger { + copyConsumer := *t + t.Ann = t.Ann.copy() + return ©Consumer +} + // Prestring returns this Prestring as a Prestring func (*TriggerIfDeepNonNil) Prestring() Prestring { return TriggerIfDeepNonNilPrestring{} @@ -162,6 +179,12 @@ func (*ConsumeTriggerTautology) equals(other ConsumingAnnotationTrigger) bool { return ok } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (t *ConsumeTriggerTautology) Copy() ConsumingAnnotationTrigger { + copyConsumer := *t + return ©Consumer +} + // Prestring returns this Prestring as a Prestring func (*ConsumeTriggerTautology) Prestring() Prestring { return ConsumeTriggerTautologyPrestring{} @@ -187,6 +210,13 @@ func (p *PtrLoad) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (p *PtrLoad) Copy() ConsumingAnnotationTrigger { + copyConsumer := *p + copyConsumer.ConsumeTriggerTautology = p.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this PtrLoad as a Prestring func (p *PtrLoad) Prestring() Prestring { return PtrLoadPrestring{} @@ -214,6 +244,13 @@ func (i *MapAccess) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (i *MapAccess) Copy() ConsumingAnnotationTrigger { + copyConsumer := *i + copyConsumer.ConsumeTriggerTautology = i.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this MapAccess as a Prestring func (i *MapAccess) Prestring() Prestring { return MapAccessPrestring{} @@ -240,6 +277,13 @@ func (m *MapWrittenTo) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (m *MapWrittenTo) Copy() ConsumingAnnotationTrigger { + copyConsumer := *m + copyConsumer.ConsumeTriggerTautology = m.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this MapWrittenTo as a Prestring func (m *MapWrittenTo) Prestring() Prestring { return MapWrittenToPrestring{} @@ -265,6 +309,13 @@ func (s *SliceAccess) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (s *SliceAccess) Copy() ConsumingAnnotationTrigger { + copyConsumer := *s + copyConsumer.ConsumeTriggerTautology = s.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this SliceAccess as a Prestring func (s *SliceAccess) Prestring() Prestring { return SliceAccessPrestring{} @@ -292,6 +343,13 @@ func (f *FldAccess) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *FldAccess) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.ConsumeTriggerTautology = f.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this FldAccess as a Prestring func (f *FldAccess) Prestring() Prestring { fieldName, methodName := "", "" @@ -341,6 +399,13 @@ func (u *UseAsErrorResult) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (u *UseAsErrorResult) Copy() ConsumingAnnotationTrigger { + copyConsumer := *u + copyConsumer.TriggerIfNonNil = u.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this UseAsErrorResult as a Prestring func (u *UseAsErrorResult) Prestring() Prestring { retAnn := u.Ann.(*RetAnnotationKey) @@ -388,6 +453,13 @@ func (f *FldAssign) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *FldAssign) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfNonNil = f.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this FldAssign as a Prestring func (f *FldAssign) Prestring() Prestring { fldAnn := f.Ann.(*FieldAnnotationKey) @@ -420,6 +492,13 @@ func (f *ArgFldPass) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *ArgFldPass) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfNonNil = f.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this ArgFldPass as a Prestring func (f *ArgFldPass) Prestring() Prestring { ann := f.Ann.(*ParamFieldAnnotationKey) @@ -471,6 +550,13 @@ func (g *GlobalVarAssign) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (g *GlobalVarAssign) Copy() ConsumingAnnotationTrigger { + copyConsumer := *g + copyConsumer.TriggerIfNonNil = g.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this GlobalVarAssign as a Prestring func (g *GlobalVarAssign) Prestring() Prestring { varAnn := g.Ann.(*GlobalVarAnnotationKey) @@ -506,6 +592,13 @@ func (a *ArgPass) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (a *ArgPass) Copy() ConsumingAnnotationTrigger { + copyConsumer := *a + copyConsumer.TriggerIfNonNil = a.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this ArgPass as a Prestring func (a *ArgPass) Prestring() Prestring { switch key := a.Ann.(type) { @@ -559,6 +652,13 @@ func (a *RecvPass) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (a *RecvPass) Copy() ConsumingAnnotationTrigger { + copyConsumer := *a + copyConsumer.TriggerIfNonNil = a.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this RecvPass as a Prestring func (a *RecvPass) Prestring() Prestring { recvAnn := a.Ann.(*RecvAnnotationKey) @@ -592,6 +692,13 @@ func (i *InterfaceResultFromImplementation) equals(other ConsumingAnnotationTrig return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (i *InterfaceResultFromImplementation) Copy() ConsumingAnnotationTrigger { + copyConsumer := *i + copyConsumer.TriggerIfNonNil = i.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this InterfaceResultFromImplementation as a Prestring func (i *InterfaceResultFromImplementation) Prestring() Prestring { retAnn := i.Ann.(*RetAnnotationKey) @@ -630,6 +737,13 @@ func (m *MethodParamFromInterface) equals(other ConsumingAnnotationTrigger) bool return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (m *MethodParamFromInterface) Copy() ConsumingAnnotationTrigger { + copyConsumer := *m + copyConsumer.TriggerIfNonNil = m.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this MethodParamFromInterface as a Prestring func (m *MethodParamFromInterface) Prestring() Prestring { paramAnn := m.Ann.(*ParamAnnotationKey) @@ -691,6 +805,13 @@ func (u *UseAsReturn) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (u *UseAsReturn) Copy() ConsumingAnnotationTrigger { + copyConsumer := *u + copyConsumer.TriggerIfNonNil = u.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this UseAsReturn as a Prestring func (u *UseAsReturn) Prestring() Prestring { switch key := u.Ann.(type) { @@ -763,6 +884,13 @@ func (u *UseAsFldOfReturn) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (u *UseAsFldOfReturn) Copy() ConsumingAnnotationTrigger { + copyConsumer := *u + copyConsumer.TriggerIfNonNil = u.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this UseAsFldOfReturn as a Prestring func (u *UseAsFldOfReturn) Prestring() Prestring { retAnn := u.Ann.(*RetFieldAnnotationKey) @@ -833,6 +961,13 @@ func (f *SliceAssign) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *SliceAssign) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfDeepNonNil = f.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this SliceAssign as a Prestring func (f *SliceAssign) Prestring() Prestring { fldAnn := f.Ann.(*TypeNameAnnotationKey) @@ -863,6 +998,13 @@ func (a *ArrayAssign) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (a *ArrayAssign) Copy() ConsumingAnnotationTrigger { + copyConsumer := *a + copyConsumer.TriggerIfDeepNonNil = a.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this ArrayAssign as a Prestring func (a *ArrayAssign) Prestring() Prestring { fldAnn := a.Ann.(*TypeNameAnnotationKey) @@ -893,6 +1035,13 @@ func (f *PtrAssign) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *PtrAssign) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfDeepNonNil = f.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this PtrAssign as a Prestring func (f *PtrAssign) Prestring() Prestring { fldAnn := f.Ann.(*TypeNameAnnotationKey) @@ -923,6 +1072,13 @@ func (f *MapAssign) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *MapAssign) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfDeepNonNil = f.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this MapAssign as a Prestring func (f *MapAssign) Prestring() Prestring { fldAnn := f.Ann.(*TypeNameAnnotationKey) @@ -954,6 +1110,13 @@ func (d *DeepAssignPrimitive) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (d *DeepAssignPrimitive) Copy() ConsumingAnnotationTrigger { + copyConsumer := *d + copyConsumer.ConsumeTriggerTautology = d.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this Prestring as a Prestring func (*DeepAssignPrimitive) Prestring() Prestring { return DeepAssignPrimitivePrestring{} @@ -979,6 +1142,13 @@ func (p *ParamAssignDeep) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (p *ParamAssignDeep) Copy() ConsumingAnnotationTrigger { + copyConsumer := *p + copyConsumer.TriggerIfDeepNonNil = p.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this ParamAssignDeep as a Prestring func (p *ParamAssignDeep) Prestring() Prestring { return ParamAssignDeepPrestring{p.Ann.(*ParamAnnotationKey).MinimalString()} @@ -1006,6 +1176,13 @@ func (f *FuncRetAssignDeep) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *FuncRetAssignDeep) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfDeepNonNil = f.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this FuncRetAssignDeep as a Prestring func (f *FuncRetAssignDeep) Prestring() Prestring { retAnn := f.Ann.(*RetAnnotationKey) @@ -1039,6 +1216,13 @@ func (v *VariadicParamAssignDeep) equals(other ConsumingAnnotationTrigger) bool return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (v *VariadicParamAssignDeep) Copy() ConsumingAnnotationTrigger { + copyConsumer := *v + copyConsumer.TriggerIfNonNil = v.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this VariadicParamAssignDeep as a Prestring func (v *VariadicParamAssignDeep) Prestring() Prestring { paramAnn := v.Ann.(*ParamAnnotationKey) @@ -1069,6 +1253,13 @@ func (f *FieldAssignDeep) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *FieldAssignDeep) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfDeepNonNil = f.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this FieldAssignDeep as a Prestring func (f *FieldAssignDeep) Prestring() Prestring { fldAnn := f.Ann.(*FieldAnnotationKey) @@ -1097,6 +1288,13 @@ func (g *GlobalVarAssignDeep) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (g *GlobalVarAssignDeep) Copy() ConsumingAnnotationTrigger { + copyConsumer := *g + copyConsumer.TriggerIfDeepNonNil = g.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this GlobalVarAssignDeep as a Prestring func (g *GlobalVarAssignDeep) Prestring() Prestring { varAnn := g.Ann.(*GlobalVarAnnotationKey) @@ -1125,6 +1323,13 @@ func (c *ChanAccess) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (c *ChanAccess) Copy() ConsumingAnnotationTrigger { + copyConsumer := *c + copyConsumer.ConsumeTriggerTautology = c.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this MapWrittenTo as a Prestring func (c *ChanAccess) Prestring() Prestring { return ChanAccessPrestring{} @@ -1151,6 +1356,13 @@ func (l *LocalVarAssignDeep) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (l *LocalVarAssignDeep) Copy() ConsumingAnnotationTrigger { + copyConsumer := *l + copyConsumer.ConsumeTriggerTautology = l.ConsumeTriggerTautology.Copy().(*ConsumeTriggerTautology) + return ©Consumer +} + // Prestring returns this LocalVarAssignDeep as a Prestring func (l *LocalVarAssignDeep) Prestring() Prestring { return LocalVarAssignDeepPrestring{VarName: l.LocalVar.Name()} @@ -1178,6 +1390,13 @@ func (c *ChanSend) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (c *ChanSend) Copy() ConsumingAnnotationTrigger { + copyConsumer := *c + copyConsumer.TriggerIfDeepNonNil = c.TriggerIfDeepNonNil.Copy().(*TriggerIfDeepNonNil) + return ©Consumer +} + // Prestring returns this ChanSend as a Prestring func (c *ChanSend) Prestring() Prestring { typeAnn := c.Ann.(*TypeNameAnnotationKey) @@ -1213,6 +1432,13 @@ func (f *FldEscape) equals(other ConsumingAnnotationTrigger) bool { return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (f *FldEscape) Copy() ConsumingAnnotationTrigger { + copyConsumer := *f + copyConsumer.TriggerIfNonNil = f.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this FldEscape as a Prestring func (f *FldEscape) Prestring() Prestring { ann := f.Ann.(*EscapeFieldAnnotationKey) @@ -1248,6 +1474,13 @@ func (u *UseAsNonErrorRetDependentOnErrorRetNilability) equals(other ConsumingAn return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (u *UseAsNonErrorRetDependentOnErrorRetNilability) Copy() ConsumingAnnotationTrigger { + copyConsumer := *u + copyConsumer.TriggerIfNonNil = u.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this UseAsNonErrorRetDependentOnErrorRetNilability as a Prestring func (u *UseAsNonErrorRetDependentOnErrorRetNilability) Prestring() Prestring { retAnn := u.Ann.(*RetAnnotationKey) @@ -1305,6 +1538,13 @@ func (u *UseAsErrorRetWithNilabilityUnknown) equals(other ConsumingAnnotationTri return false } +// Copy returns a deep copy of this ConsumingAnnotationTrigger +func (u *UseAsErrorRetWithNilabilityUnknown) Copy() ConsumingAnnotationTrigger { + copyConsumer := *u + copyConsumer.TriggerIfNonNil = u.TriggerIfNonNil.Copy().(*TriggerIfNonNil) + return ©Consumer +} + // Prestring returns this UseAsErrorRetWithNilabilityUnknown as a Prestring func (u *UseAsErrorRetWithNilabilityUnknown) Prestring() Prestring { retAnn := u.Ann.(*RetAnnotationKey) @@ -1403,6 +1643,14 @@ func (c *ConsumeTrigger) equals(c2 *ConsumeTrigger) bool { } +// Copy returns a deep copy of the ConsumeTrigger +func (c *ConsumeTrigger) Copy() *ConsumeTrigger { + copyTrigger := *c + copyTrigger.Annotation = c.Annotation.Copy() + copyTrigger.Guards = c.Guards.Copy() + return ©Trigger +} + // Pos returns the source position (e.g., line) of the consumer's expression. In special cases, such as named return, it // returns the position of the stored return AST node func (c *ConsumeTrigger) Pos() token.Pos { @@ -1425,7 +1673,8 @@ func MergeConsumeTriggerSlices(left, right []*ConsumeTrigger) []*ConsumeTrigger // intersect guard sets - if a guard isn't present in both branches it can't // be considered present before the branch out[i] = &ConsumeTrigger{ - Annotation: outTrigger.Annotation, + // Annotation: outTrigger.Annotation, + Annotation: outTrigger.Annotation.Copy(), Expr: outTrigger.Expr, Guards: outTrigger.Guards.Intersection(trigger.Guards), GuardMatched: outTrigger.GuardMatched && trigger.GuardMatched, @@ -1453,7 +1702,8 @@ func ConsumeTriggerSliceAsGuarded(slice []*ConsumeTrigger, guards ...util.GuardN var out []*ConsumeTrigger for _, trigger := range slice { out = append(out, &ConsumeTrigger{ - Annotation: trigger.Annotation, + // Annotation: trigger.Annotation, + Annotation: trigger.Annotation.Copy(), Expr: trigger.Expr, Guards: trigger.Guards.Copy().Add(guards...), }) diff --git a/annotation/key.go b/annotation/key.go index a39a7932..ab816047 100644 --- a/annotation/key.go +++ b/annotation/key.go @@ -42,6 +42,9 @@ type Key interface { // equals returns true if the passed key is equal to this key equals(Key) bool + + // copy returns a deep copy of this key + copy() Key } // FieldAnnotationKey allows the Lookup of a field's Annotation in the Annotation map @@ -70,6 +73,11 @@ func (k *FieldAnnotationKey) equals(other Key) bool { return false } +func (k *FieldAnnotationKey) copy() Key { + copyKey := *k + return ©Key +} + func (k *FieldAnnotationKey) String() string { return fmt.Sprintf("Field %s", k.FieldDecl.Name()) } @@ -115,6 +123,11 @@ func (pk *CallSiteParamAnnotationKey) equals(other Key) bool { return false } +func (pk *CallSiteParamAnnotationKey) copy() Key { + copyKey := *pk + return ©Key +} + func (pk *CallSiteParamAnnotationKey) String() string { argname := "" if pk.ParamName() != nil { @@ -241,6 +254,11 @@ func (pk *ParamAnnotationKey) equals(other Key) bool { return false } +func (pk *ParamAnnotationKey) copy() Key { + copyKey := *pk + return ©Key +} + func (pk *ParamAnnotationKey) String() string { argname := "" if pk.ParamName() != nil { @@ -302,6 +320,11 @@ func (rk *CallSiteRetAnnotationKey) equals(other Key) bool { return false } +func (rk *CallSiteRetAnnotationKey) copy() Key { + copyKey := *rk + return ©Key +} + func (rk *CallSiteRetAnnotationKey) String() string { return fmt.Sprintf("Result %d of Function %s at Location %v", rk.RetNum, rk.FuncDecl.Name(), rk.Location) @@ -344,6 +367,11 @@ func (rk *RetAnnotationKey) equals(other Key) bool { return false } +func (rk *RetAnnotationKey) copy() Key { + copyKey := *rk + return ©Key +} + func (rk *RetAnnotationKey) String() string { return fmt.Sprintf("Result %d of Function %s", rk.RetNum, rk.FuncDecl.Name()) @@ -383,6 +411,11 @@ func (tk *TypeNameAnnotationKey) equals(other Key) bool { return false } +func (tk *TypeNameAnnotationKey) copy() Key { + copyKey := *tk + return ©Key +} + func (tk *TypeNameAnnotationKey) String() string { return fmt.Sprintf("Type %s", tk.TypeDecl.Name()) } @@ -413,6 +446,11 @@ func (gk *GlobalVarAnnotationKey) equals(other Key) bool { return false } +func (gk *GlobalVarAnnotationKey) copy() Key { + copyKey := *gk + return ©Key +} + func (gk *GlobalVarAnnotationKey) String() string { return fmt.Sprintf("Global Variable %s", gk.VarDecl.Name()) } @@ -449,6 +487,11 @@ func (rf *RetFieldAnnotationKey) equals(other Key) bool { return false } +func (rf *RetFieldAnnotationKey) copy() Key { + copyKey := *rf + return ©Key +} + // String returns a string representation of this annotation key func (rf *RetFieldAnnotationKey) String() string { // If the function has a receiver, we add info in the error message @@ -500,6 +543,11 @@ func (ek *EscapeFieldAnnotationKey) equals(other Key) bool { return false } +func (ek *EscapeFieldAnnotationKey) copy() Key { + copyKey := *ek + return ©Key +} + func (ek *EscapeFieldAnnotationKey) String() string { return fmt.Sprintf("escaped Field %s", ek.FieldDecl.Name()) } @@ -560,6 +608,11 @@ func (pf *ParamFieldAnnotationKey) equals(other Key) bool { return false } +func (pf *ParamFieldAnnotationKey) copy() Key { + copyKey := *pf + return ©Key +} + // String returns a string representation of this annotation key for ParamFieldAnnotationKey func (pf *ParamFieldAnnotationKey) String() string { argName := "" @@ -617,6 +670,11 @@ func (rk *RecvAnnotationKey) equals(other Key) bool { return false } +func (rk *RecvAnnotationKey) copy() Key { + copyKey := *rk + return ©Key +} + func (rk *RecvAnnotationKey) String() string { return fmt.Sprintf("Receiver of Method %s", rk.FuncDecl.Name()) } diff --git a/assertion/function/assertiontree/util.go b/assertion/function/assertiontree/util.go index 5207a00a..054b24d2 100644 --- a/assertion/function/assertiontree/util.go +++ b/assertion/function/assertiontree/util.go @@ -389,7 +389,12 @@ func CopyNode(node AssertionNode) AssertionNode { fresh.SetChildren(append(fresh.Children(), freshChild)) } - fresh.SetConsumeTriggers(append(make([]*annotation.ConsumeTrigger, 0, len(node.ConsumeTriggers())), node.ConsumeTriggers()...)) + // fresh.SetConsumeTriggers(append(make([]*annotation.ConsumeTrigger, 0, len(node.ConsumeTriggers())), node.ConsumeTriggers()...)) + copyConsumers := make([]*annotation.ConsumeTrigger, 0, len(node.ConsumeTriggers())) + for _, c := range node.ConsumeTriggers() { + copyConsumers = append(copyConsumers, c.Copy()) + } + fresh.SetConsumeTriggers(copyConsumers) return fresh }