private void ValidateStore(IVariableStore store, Dictionary <Variable, Expr> expected) { Assert.AreEqual(expected.Count, store.Count); int keysCount = 0; foreach (var v in store.Keys) { ++keysCount; Assert.IsTrue(expected.ContainsKey(v)); Assert.IsTrue(store.ContainsKey(v)); } Assert.AreEqual(expected.Count, keysCount); // Dummy var var dummyVar = MkSimpleVar("dummy", BPLType.Bool); Assert.IsFalse(store.ContainsKey(dummyVar)); int pairsCount = 0; foreach (var pair in store) { ++pairsCount; Assert.IsTrue(expected.ContainsKey(pair.Key)); Assert.AreSame(expected[pair.Key], pair.Value); } Assert.AreEqual(expected.Count, pairsCount); }
public void MapCopy(Variable dest, Variable src, IVariableStore srcStore) { if (!IsMapVariable(dest)) { throw new ArgumentException("dest is not a map variable"); } if (!IsMapVariable(src)) { throw new ArgumentException("src is not a map variable"); } if (!dest.TypedIdent.Type.Equals(src.TypedIdent.Type)) { throw new ArgumentException("src and dest type do not match"); } if (!MapTypeVariableStore.ContainsKey(dest)) { throw new ArgumentException("destination variable not in store"); } if (!srcStore.ContainsKey(src)) { throw new ArgumentException("src is not in srcStore"); } if (Object.ReferenceEquals(dest, src)) { // Copying to self shouldn't do anything. return; } if (srcStore is SimpleVariableStore) { // We can peak into the internals var srcInternalsMaps = (srcStore as SimpleVariableStore).MapTypeVariableStore; // Clone the internal representation of the map to avoid causing any flushes var mapProxyClone = srcInternalsMaps[src].Clone(this.CopyOnWriteKey); this.MapTypeVariableStore[dest] = mapProxyClone; Debug.Assert(this.MapTypeVariableStore[dest].CopyOnWriteOwnerKey == this.CopyOnWriteKey); } else { // Do potentially the expensive way (may trigger a flush of map stores) this[dest] = srcStore[src]; } }