public ConstructorEmbedding(TypeEmbedder owner, UserSymbol conOrMap, Map <Term, Tuple <uint, UserSymbol> > sortIndices) { Contract.Requires(owner != null && conOrMap != null); Contract.Requires(conOrMap.IsDataConstructor); Constructor = conOrMap; Owner = owner; bool wasAdded; Type = Index.MkApply( conOrMap.Kind == SymbolKind.ConSymb ? ((ConSymb)conOrMap).SortSymbol : ((MapSymb)conOrMap).SortSymbol, TermIndex.EmptyArgs, out wasAdded); var fldNames = new string[conOrMap.Arity]; var fldSorts = new Z3Sort[conOrMap.Arity]; var fldRefs = new uint[conOrMap.Arity]; IEnumerable <Field> flds; if (conOrMap.Kind == SymbolKind.ConSymb) { flds = ((ConDecl)(conOrMap.Definitions.First().Node)).Fields; } else { var mapDecl = (MapDecl)(conOrMap.Definitions.First().Node); flds = mapDecl.Dom.Concat(mapDecl.Cod); } int i = 0; Tuple <uint, UserSymbol> sortData; Term argType; foreach (var f in flds) { argType = Index.GetCanonicalTerm(conOrMap, i); fldNames[i] = string.Format("Get_{0}_{1}", conOrMap.FullName, string.IsNullOrEmpty(f.Name) ? i.ToString() : f.Name); if (sortIndices.TryFindValue(argType, out sortData)) { fldSorts[i] = null; fldRefs[i] = sortData.Item1; } else { fldSorts[i] = owner.GetEmbedding(argType).Representation; fldRefs[i] = 0; } ++i; } Z3Constructor = Context.MkConstructor(conOrMap.FullName, "Is" + conOrMap.FullName, fldNames, fldSorts, fldRefs); }
public UnionEmbedding(TypeEmbedder owner, Term unnType, Map <Term, Tuple <uint, UserSymbol> > sortIndices) { Contract.Requires(owner != null); Owner = owner; Name = string.Format("Unn_{0}", sortIndices[unnType].Item1); Type = unnType; CanonicalUnion = new AppFreeCanUnn(unnType); var unn = CanonicalUnion; Z3Con con; LinkedList <ITypeEmbedding> intFacts, cnstFacts; LinkedList <Z3Con> allConstructors = new LinkedList <Z3Con>(); owner.GetFactorizations(unnType, out intFacts, out cnstFacts); foreach (var te in intFacts) { rngBoxings.Add( te.Type, con = Context.MkConstructor( string.Format("Box_{0}_{1}", Name, te.Representation.Name), string.Format("IsBox_{0}_{1}", Name, te.Representation.Name), new string[] { string.Format("Unbox_{0}_{1}", Name, te.Representation.Name) }, new Z3Sort[] { te.Representation })); allConstructors.AddLast(con); } foreach (var te in cnstFacts) { con = Context.MkConstructor( string.Format("Box_{0}_{1}", Name, te.Representation.Name), string.Format("IsBox_{0}_{1}", Name, te.Representation.Name), new string[] { string.Format("Unbox_{0}_{1}", Name, te.Representation.Name) }, new Z3Sort[] { te.Representation }); allConstructors.AddLast(con); foreach (var t in te.Type.Enumerate(x => x.Args)) { if (t.Symbol.Arity == 0) { otherBoxings.Add(t.Symbol, con); } } } bool wasAdded; foreach (var m in unn.NonRangeMembers) { if (m.Kind == SymbolKind.BaseSortSymb) { var te = Owner.GetEmbedding(Index.MkApply(m, TermIndex.EmptyArgs, out wasAdded)); otherBoxings.Add( m, con = Context.MkConstructor( string.Format("Box_{0}_{1}", Name, te.Representation.Name), string.Format("IsBox_{0}_{1}", Name, te.Representation.Name), new string[] { string.Format("Unbox_{0}_{1}", Name, te.Representation.Name) }, new Z3Sort[] { te.Representation })); allConstructors.AddLast(con); } else if (m.Kind == SymbolKind.UserSortSymb) { otherBoxings.Add( m, con = Context.MkConstructor( string.Format("Box_{0}_{1}", Name, ((UserSortSymb)m).DataSymbol.FullName), string.Format("IsBox_{0}_{1}", Name, ((UserSortSymb)m).DataSymbol.FullName), new string[] { string.Format("Unbox_{0}_{1}", Name, ((UserSortSymb)m).DataSymbol.FullName) }, new Z3Sort[] { null }, new uint[] { sortIndices[Index.MkApply(m, TermIndex.EmptyArgs, out wasAdded)].Item1 })); allConstructors.AddLast(con); } } Boxers = allConstructors.ToArray(allConstructors.Count); }