Ejemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////

        protected override void GenSelectStoreFunctions(MapType abstractedType, TypeCtorDecl synonym, out Function /*!*/ select, out Function /*!*/ store)
        {
            //Contract.Requires(synonym != null);
//Contract.Requires(abstractedType != null);
            Contract.Ensures(Contract.ValueAtReturn(out select) != null);
            Contract.Ensures(Contract.ValueAtReturn(out store) != null);
            Contract.Assert(synonym.Name != null);
            string /*!*/ baseName     = synonym.Name;
            int          typeParamNum = abstractedType.FreeVariables.Count +
                                        abstractedType.TypeParameters.Count;

            int arity = typeParamNum + abstractedType.Arguments.Count;

            Type /*!*/[] /*!*/ selectTypes = new Type /*!*/ [arity + 2];
            Type /*!*/[] /*!*/ storeTypes  = new Type /*!*/ [arity + 3];

            int i = 0;

            // Fill in the free variables and type parameters
            for (; i < typeParamNum; i++)
            {
                selectTypes[i] = AxBuilder.T;
                storeTypes[i]  = AxBuilder.T;
            }
            // Fill in the map type
            if (CommandLineOptions.Clo.MonomorphicArrays)
            {
                selectTypes[i] = abstractedType;
                storeTypes[i]  = abstractedType;
            }
            else
            {
                selectTypes[i] = AxBuilder.U;
                storeTypes[i]  = AxBuilder.U;
            }
            i++;
            // Fill in the index types
            foreach (Type /*!*/ type in abstractedType.Arguments)
            {
                Contract.Assert(type != null);
                if (CommandLineOptions.Clo.Monomorphize && AxBuilder.UnchangedType(type))
                {
                    selectTypes[i] = type;
                    storeTypes[i]  = type;
                }
                else
                {
                    selectTypes[i] = AxBuilder.U;
                    storeTypes[i]  = AxBuilder.U;
                }
                i++;
            }
            // Fill in the output type for select function which also happens
            // to be the type of the last argument to the store function
            if (CommandLineOptions.Clo.Monomorphize && AxBuilder.UnchangedType(abstractedType.Result))
            {
                selectTypes[i] = abstractedType.Result;
                storeTypes[i]  = abstractedType.Result;
            }
            else
            {
                selectTypes[i] = AxBuilder.U;
                storeTypes[i]  = AxBuilder.U;
            }
            i++;
            // Fill in the map type which is the output of the store function
            if (CommandLineOptions.Clo.MonomorphicArrays)
            {
                storeTypes[i] = abstractedType;
            }
            else
            {
                storeTypes[i] = AxBuilder.U;
            }
            Contract.Assert(cce.NonNullElements <Type>(selectTypes));
            Contract.Assert(cce.NonNullElements <Type>(storeTypes));

            select = HelperFuns.BoogieFunction(baseName + "Select", selectTypes);
            store  = HelperFuns.BoogieFunction(baseName + "Store", storeTypes);

            if (CommandLineOptions.Clo.UseArrayTheory)
            {
                select.AddAttribute("builtin", "select");
                store.AddAttribute("builtin", "store");
            }
            else
            {
                AxBuilder.AddTypeAxiom(GenMapAxiom0(select, store,
                                                    abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count));
                AxBuilder.AddTypeAxiom(GenMapAxiom1(select, store,
                                                    abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count));
            }
        }