Пример #1
0
        public StringEmbedding(TypeEmbedder owner, uint cost)
        {
            Contract.Requires(owner != null);
            Owner        = owner;
            EncodingCost = cost;
            bool wasAdded;

            Type = Index.MkApply(Index.SymbolTable.GetSortSymbol(BaseSortKind.String), TermIndex.EmptyArgs, out wasAdded);

            charSort = Context.MkBitVecSort(CharWidth);

            //// Converts bit vectors to strings.
            charBoxing = Context.MkConstructor(
                CharBoxingName,
                IsCharName,
                new string[] { CharUnboxingName },
                new Z3Sort[] { charSort });

            //// Append a char to a string
            appStr = Context.MkConstructor(
                AppStrName,
                IsMultiStrName,
                new string[] { AppPrefixName, AppSuffixName },
                new Z3Sort[] { null, charSort },
                new uint[] { 0, 0 });

            neStrSort = Context.MkDatatypeSort(NeStrSortName, new Z3Con[] { charBoxing, appStr });

            isChar       = charBoxing.TesterDecl;
            charUnboxing = charBoxing.AccessorDecls[0];
            isMultiStr   = appStr.TesterDecl;
            appPrefix    = appStr.AccessorDecls[0];
            appSuffix    = appStr.AccessorDecls[1];

            //// Functions for building strings.
            strBoxing = Context.MkConstructor(
                StrBoxingName,
                IsNeStrName,
                new string[] { StrUnboxingName },
                new Z3Sort[] { neStrSort });

            emptyStr = Context.MkConstructor(
                EmptyStrName,
                IsEmptyStrName,
                null,
                null,
                null);

            strSort     = Context.MkDatatypeSort(StrSortName, new Z3Con[] { emptyStr, strBoxing });
            isNeStr     = strBoxing.TesterDecl;
            strUnboxing = strBoxing.AccessorDecls[0];
            isEmptyStr  = emptyStr.TesterDecl;

            Representation = strSort;
            DefaultMember  = new Tuple <Term, Z3Expr>(Index.EmptyStringValue, emptyStr.ConstructorDecl.Apply());
        }
Пример #2
0
        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);
        }
Пример #3
0
        public void SetRepresentation(Z3Sort sort)
        {
            Contract.Requires(Representation == null);
            Representation = sort;

            foreach (var kv in rngBoxings)
            {
                sortToBoxing.Add(kv.Value.AccessorDecls[0].Range, kv.Value);
                allBoxers.Add(kv.Value.ConstructorDecl);
            }

            foreach (var kv in otherBoxings)
            {
                if (!sortToBoxing.ContainsKey(kv.Value.AccessorDecls[0].Range))
                {
                    sortToBoxing.Add(kv.Value.AccessorDecls[0].Range, kv.Value);
                    allBoxers.Add(kv.Value.ConstructorDecl);
                }
            }
        }
Пример #4
0
 public ITypeEmbedding GetEmbedding(Z3Sort sort)
 {
     return(sortToEmbedding[sort]);
 }
Пример #5
0
 public void SetRepresentation(Z3Sort sort)
 {
     Contract.Requires(Representation == null);
     Representation = sort;
 }