public static bool ReturnsTheSame(PLvalue left, PLvalue right, SharedData data) { if (left.GetType() != right.GetType()) { return(false); } if (left is ALocalLvalue) { ALocalLvalue aLeft = (ALocalLvalue)left; ALocalLvalue aRight = (ALocalLvalue)right; return(data.LocalLinks[aLeft] == data.LocalLinks[aRight]); } if (left is AFieldLvalue) { AFieldLvalue aLeft = (AFieldLvalue)left; AFieldLvalue aRight = (AFieldLvalue)right; return(data.FieldLinks[aLeft] == data.FieldLinks[aRight]); } if (left is AStructLvalue) { AStructLvalue aLeft = (AStructLvalue)left; AStructLvalue aRight = (AStructLvalue)right; if (data.StructFieldLinks[aLeft] != data.StructFieldLinks[aRight]) { return(false); } return(ReturnsTheSame(aLeft.GetReceiver(), aRight.GetReceiver(), data)); } if (left is AArrayLvalue) { AArrayLvalue aLeft = (AArrayLvalue)left; AArrayLvalue aRight = (AArrayLvalue)right; return(ReturnsTheSame(aLeft.GetIndex(), aRight.GetIndex(), data) && ReturnsTheSame(aLeft.GetBase(), aRight.GetBase(), data)); } throw new Exception("Util.ReturnsTheSame. Unexpected type, got " + left.GetType()); }
private static void MakeCloneRefferences(PLvalue clone, PLvalue lvalue, SharedData data) { data.LvalueTypes[clone] = data.LvalueTypes[lvalue]; if (lvalue is ALocalLvalue) { data.LocalLinks[(ALocalLvalue)clone] = data.LocalLinks[(ALocalLvalue)lvalue]; } else if (lvalue is AFieldLvalue) { data.FieldLinks[(AFieldLvalue)clone] = data.FieldLinks[(AFieldLvalue)lvalue]; } else if (lvalue is AStructLvalue) { AStructLvalue aLvalue = (AStructLvalue)lvalue; AStructLvalue aClone = (AStructLvalue)clone; if (data.StructFieldLinks.ContainsKey(aLvalue)) { data.StructFieldLinks[aClone] = data.StructFieldLinks[aLvalue]; } else { data.StructPropertyLinks[aClone] = data.StructPropertyLinks[aLvalue]; } MakeCloneRefferences(aClone.GetReceiver(), aLvalue.GetReceiver(), data); } else if (lvalue is AStructFieldLvalue) { AStructFieldLvalue aLvalue = (AStructFieldLvalue)lvalue; AStructFieldLvalue aClone = (AStructFieldLvalue)clone; if (data.StructMethodFieldLinks.ContainsKey(aLvalue)) { data.StructMethodFieldLinks[aClone] = data.StructMethodFieldLinks[aLvalue]; } if (data.StructMethodPropertyLinks.ContainsKey(aLvalue)) { data.StructMethodPropertyLinks[aClone] = data.StructMethodPropertyLinks[aLvalue]; } } else if (lvalue is AArrayLvalue) { AArrayLvalue aLvalue = (AArrayLvalue)lvalue; AArrayLvalue aClone = (AArrayLvalue)clone; MakeCloneRefferences(aClone.GetBase(), aLvalue.GetBase(), data); MakeCloneRefferences(aClone.GetIndex(), aLvalue.GetIndex(), data); } else if (lvalue is APointerLvalue) { APointerLvalue aLvalue = (APointerLvalue)lvalue; APointerLvalue aClone = (APointerLvalue)clone; MakeCloneRefferences(aClone.GetBase(), aLvalue.GetBase(), data); } else if (lvalue is AThisLvalue || lvalue is AValueLvalue) { //AThisLvalue aLvalue = (AThisLvalue)lvalue; //Do nothing more } else if (lvalue is APropertyLvalue) { APropertyLvalue aLvalue = (APropertyLvalue)lvalue; APropertyLvalue aClone = (APropertyLvalue)clone; data.PropertyLinks[aClone] = data.PropertyLinks[aLvalue]; } else { throw new Exception("Unexpect lvalue. Got " + lvalue.GetType()); } }