Ejemplo n.º 1
0
        private BasicMapWrite(
            MapType mapType,
            ITypeTuple indexTypes,
            IType sourceType,
            IType resultType,
            ITypeTuple mapTypeArguments
            )
        {
            Debug.Assert(mapType != null);
            Debug.Assert(mapTypeArguments != null);
            Debug.Assert(indexTypes != null);
            Debug.Assert(sourceType != null);
            Debug.Assert(resultType != null);
            Debug.Assert(indexTypes.Count() == mapType.domain.Count());
            Debug.Assert(mapTypeArguments.Count() == mapType.typeParameters.Length);

            this.mapType          = mapType;
            mapIndexTypes         = indexTypes;
            this.sourceType       = sourceType;
            this.resultType       = resultType;
            this.mapTypeArguments = TypeTuple.make(mapTypeArguments);
            Debug.Assert(this.mapTypeArguments != null);
            this.typeArguments = TypeTuple.make(new IType[1] {
                mapType
            }.Concat(mapTypeArguments));
            this.argumentTypes     = TypeTuple.make(new [] { mapType }.Concat(mapIndexTypes).Concat(new[] { sourceType }));
            this.freeTypeVariables =
                new HashSet <TypeVariable>(resultType.freeTypeVariables.
                                           Union(mapType.freeTypeVariables).
                                           Union(sourceType.freeTypeVariables).
                                           Union(from it in mapIndexTypes from fv in it.freeTypeVariables select fv)
                                           );
        }
        ////////////////////////////////////////////

        ////////////////////////////////////////////
        public override Expression substitute(ExpressionSubstitution s)
        {
            string ss = makeSubstitutionString(s);

            if (substitutionCache.ContainsKey(ss))
            {
                return(substitutionCache[ss]);
            }

            bool needSubstitution = false;

            foreach (var fv in freeVariables)
            {
                if (s.lookup(fv.name) != null)
                {
                    needSubstitution = true;
                }
            }
            foreach (var ftv in freeTypeVariables)
            {
                if (s.typeSubstitution.map(ftv) != null)
                {
                    needSubstitution = true;
                }
            }

            Expression result = this;

            if (needSubstitution)
            {
                ExpressionList sArgs = arguments.substitute(s);
                if (function.name == "==<>")
                {
                    Debug.Assert(sArgs.count == 2);
                    if (sArgs[0].type.ToStringN() == sArgs[1].type.ToStringN())
                    {
                        result =
                            new BasicFAE(
                                BFunctionTemplate.eq.getInstance(TypeTuple.make(new[] { sArgs[0].type })), sArgs);
                    }
                    else if (sArgs.freeTypeVariables.Count > 0)
                    {
                        result =
                            new BasicFAE(
                                BFunctionTemplate.eqG.getInstance(TypeTuple.make(from a in sArgs select a.type)), sArgs);
                    }
                    else
                    {
                        result = new BasicLiteralExpression(BooleanValue.makeBooleanValue(false));
                    }
                    //equality of different types
                }
                else
                {
                    result = new BasicFAE(function.substitute(s.typeSubstitution), sArgs);
                }
            }
            substitutionCache[ss] = result;
            return(result);
        }
Ejemplo n.º 3
0
 public static Function eq(IType t)
 {
     if (t is BooleanType)
     {
         return(equivalence);
     }
     return(BFunctionTemplate.eq.getInstance(TypeTuple.make(new [] { t })));
 }
Ejemplo n.º 4
0
 protected Operator(string name, string nameN, IEnumerable <IType> argumentTypes)
 {
     Debug.Assert(name != null);
     Debug.Assert(!name.Contains('!'));
     this.name          = name;
     this.nameN         = nameN;
     this.argumentTypes = TypeTuple.make(argumentTypes);
 }
Ejemplo n.º 5
0
        public ITypeTuple makeTypes(IList <Type> boogieTypes, Context context)
        {
            var types = new IType[boogieTypes.Count];

            for (int i = 0; i < boogieTypes.Count; i++)
            {
                types[i] = makeTypeI(boogieTypes[i], context);
            }
            return(TypeTuple.make(types));
        }
Ejemplo n.º 6
0
        public IFormula visit(ExistentialFormula f)
        {
            var fvs  = (from fv in f.f.ffreeVariables where fv != f.var select fv).ToArray();
            var fvts = TypeTuple.make(from fv in fvs select fv.type);
            var newF = srs.getFreshFunction("@sk", fvts, f.var.type);

            var fvTerms = (from fv in fvs select new Variable(fv)).ToArray <ITerm>();

            return(f.f.substitute(new Substitution(f.var, new FunctionApplicationFormula(newF, fvTerms))).visit(this));
        }
 public BasicFunctionSignature(IType resultType, IEnumerable <IType> arguments)
 {
     Debug.Assert(resultType != null);
     Debug.Assert(arguments != null);
     foreach (var a in arguments)
     {
         Debug.Assert(a != null);
     }
     this.resultType = resultType;
     argumentTypes   = TypeTuple.make(arguments);
 }
Ejemplo n.º 8
0
        public static BasicMapRead mapRead(MapType mapType, ITypeTuple typeArguments)
        {
            Debug.Assert(mapType != null);
            Debug.Assert(typeArguments != null);
            Debug.Assert(mapType.typeParameters.Length == typeArguments.Count());

            var s             = new TypeParameterInstantiation(mapType.typeParameters, typeArguments);
            var argumentTypes = TypeTuple.make(new [] { mapType }.Concat(from a in mapType.domain select a.substitute(s)));
            var resultType    = mapType.range.substitute(s);

            return(mapRead(typeArguments, argumentTypes, resultType));
        }
Ejemplo n.º 9
0
        public static Function eq(IType t1, IType t2)
        {
//urij: special treatment for equality with type quantification
            Debug.Assert(!t1.isGround || !t2.isGround);
            if (t1.ToStringN() == t2.ToStringN())
            {
                return(BFunctionTemplate.eq.getInstance(TypeTuple.make(new [] { t1 })));
            }
            else
            {
                return(BFunctionTemplate.eqG.getInstance(TypeTuple.make(new[] { t1, t2 })));
            }
        }
 public BasicFunctionTemplateInstance(
     FunctionTemplate template,
     IEnumerable <IType> typeArguments
     )
     : base(
         template.name,
         template.signature.resultType.substitute(new TypeParameterInstantiation(template.typeParameters,
                                                                                 typeArguments)),
         (from at in template.signature.argumentTypes
          select at.substitute(new TypeParameterInstantiation(template.typeParameters, typeArguments))).ToArray()
         )
 {
     this.template  = template;
     pTypeArguments = TypeTuple.make(typeArguments);
 }
Ejemplo n.º 11
0
 protected TermTupleC(IEnumerable <T> ts)
     : base(ts)
 {
     this.orderedFreeVariables = new List <LVar>();
     foreach (var t in ts)
     {
         foreach (var fv in t.orderedFreeVariables)
         {
             if (!orderedFreeVariables.Contains(fv))
             {
                 orderedFreeVariables.Add(fv);
             }
         }
     }
     this.dataTypes = TypeTuple.make(from t in ts select t.type);
 }
 private BoogieBitVectorConcatenationFunction(BvConcatExpr bce, int w0, int w1)
     : base(
         "++",//bce."++",//FunctionSymbol.ToString(),
         BitVectorType.makeBitVectorType(w0 + w1),
         new IType[2]
 {
     BitVectorType.makeBitVectorType(w0),
     BitVectorType.makeBitVectorType(w1)
 }
         )
 {
     boogieExpression = bce;
     this.w0          = w0;
     this.w1          = w1;
     typeArguments    = TypeTuple.make();
 }
 private BoogieBitVectorExtractorFunction(BvExtractExpr bee, int w, int from, int to)
     : base(
         "BV[]",//bee.FunctionSymbol.ToString(),
         BitVectorType.makeBitVectorType(to - from),
         new IType[1]
 {
     BitVectorType.makeBitVectorType(w)
 }
         )
 {
     boogieExpression = bee;
     this.w           = w;
     this.from        = from;
     this.to          = to;
     typeArguments    = TypeTuple.make();
 }
Ejemplo n.º 14
0
        private Expression makeMapWriteMap(FAE fae)
        {
            Debug.Assert(fae.function is MapWrite);
            Debug.Assert(fae.arguments[0].type is MapType);
            var        mu = fae.function as MapWrite;
            Expression result;

            if (!versionMap.TryGetValue(fae.ToString(), out result))
            {
                var ot = fae.arguments[0].type as MapType;
                Debug.Assert(ot != null);
                var s = new TypeParameterInstantiation(ot.typeParameters, mu.typeArguments.Skip(1).ToArray());
//                var ots = new MapType(new TypeVariable[0], (from m in ot.domain select m.substitute(s)).ToArray(), ot.range.substitute(s));
                Expression   m = fae.arguments[0];
                Expression[] i = fae.arguments.Take(fae.arguments.count - 1).Skip(1).ToArray();

                if (fae.freeVariables.Count > 0)
                {
//m(fv)[i(fv):=x(fv)] ==> v(fv)  (assume v(fv)[i]==x, assume forall fv : forall j : j!=i(fv) ==> v(fv)[j] == m(fv)[j]
                    var    fvt = TypeTuple.make(from fv in fae.freeVariables select fv.type);
                    string fn  = getFreshMUName("mu");
                    var    ft  = new BFunctionTemplate(fn, "", new TypeVariable[0], new BasicFunctionSignature(ot, fvt),
                                                       null);
                    Function f = ft.getInstance();
                    IEnumerable <BasicBoundVariableExpression> fve = from fv in fae.freeVariables
                                                                     select new BasicBoundVariableExpression(fv);
                    result = new BasicFAE(f, new ExpressionList(fve));
                }
                else
                {
                    //m[i:=x] ==> v  (assume v[i]==x, assume forall j : j!=i ==> v[j] == m[j]
                    string nvn = getFreshMUName("mu");
                    var    nv  = new ProgramVariable(nvn, ot, false, false, false, false);
                    procedure.addVariable(nv);
                    result = new BasicProgramVariableExpression(nv);
                }
                Expression[] j =
                    (from e in i select new BasicBoundVariableExpression(makeBoundVariable(e.type))).ToArray();
                //forall j : j!=i ==> v[j]==m[j]
                addConditionalMapEqualityAxiom(i, result, m, mu.typeArguments);
                //v[i]==x;
                Expression x = fae.arguments.Last();
                addEqualityAxiom(ml(result, i, mu.typeArguments.Skip(1).ToArray(), x.type), fae.arguments.Last());
            }
            return(result);
        }
Ejemplo n.º 15
0
        private Literal makeDefinition(ISet <Clause> d, Clause c)
        {
            Debug.Assert(!c.isFalse);
            Debug.Assert(!c.isTrue);
            Debug.Assert(c.literals.Count > 0);
            if (c.literals.Count == 1)
            {
                return(c.literals.First());
            }

            var fvs = c.freeVariables.ToArray();
            var dts = TypeTuple.make(from fv in fvs select fv.type);
            var N   = srs.getFreshPredicate(CSRS.NPPrefix, dts);

            //            Console.WriteLine("\t\t Defining {0} as {1}", c.ToString(), N.name);
            {
                var nc  = new List <Literal>();
                var vs  = srs.getFreshVariables(fvs);
                var vts = (from v in vs select new Variable(v)).ToArray();
                nc.Add(new Literal(new PredicateApplication(N, vts), false));
                var s = new Substitution(fvs, vts);
                foreach (var a in c.literals)
                {
                    nc.Add(a.substitute(s));
                }
                d.Add(new Clause(nc));
                //                Console.WriteLine("\t\t\t Adding {0}", nc.ToString());
            }
            foreach (var a in c.literals)
            {
                var nc  = new List <Literal>();
                var vs  = srs.getFreshVariables(fvs);
                var vts = (from v in vs select new Variable(v)).ToArray();
                var s   = new Substitution(fvs, vts);
                nc.Add(new Literal(new PredicateApplication(N, vts), true));
                nc.Add(a.substitute(s).negate());
                d.Add(new Clause(nc));
                //                Console.WriteLine("\t\t\t Adding {0}", nc.ToString());
            }

            var ovts = (from v in fvs select new Variable(v)).ToArray();

            return(new Literal(new PredicateApplication(N, ovts), true));
        }
Ejemplo n.º 16
0
        public BFunction(
            string name,
            IType resultType,
            IEnumerable <IType> argumentTypes
            )
        {
            Debug.Assert(name != null);
            Debug.Assert(resultType != null);
            Debug.Assert(argumentTypes != null);
            foreach (var at in argumentTypes)
            {
                Debug.Assert(at != null);
            }

//            Debug.Assert(name != "true" && name != "True" && name != "false" && name != "False");
            this.name          = name;
            this.argumentTypes = TypeTuple.make(argumentTypes);
            this.resultType    = resultType;
        }
Ejemplo n.º 17
0
        public static BasicMapRead mapRead(IEnumerable <IType> typeArguments, IEnumerable <IType> argumentTypes, IType resultType)
        {
            Debug.Assert(typeArguments != null);
            Debug.Assert(argumentTypes != null);
            Debug.Assert(argumentTypes.Count() > 0);
            var mapType = argumentTypes.First() as MapType;

            Debug.Assert(mapType != null);
            Debug.Assert(typeArguments.Count() == mapType.typeParameters.Length);
            Debug.Assert(mapType.domain.Count() == argumentTypes.Count() - 1);

            var   substitution = new TypeParameterInstantiation(mapType.typeParameters, typeArguments);
            IType sresultType  = mapType.range.substitute(substitution);

            Debug.Assert(resultType.ToStringN() == sresultType.ToStringN());
            Debug.Assert(argumentTypes.Skip(1).Zip(mapType.domain, (at, mtD) => at.isEquivalent(mtD.substitute(substitution))).All(x => x));
            string indexString = makeIndexString(TypeTuple.make(typeArguments), TypeTuple.make(argumentTypes));

            BasicMapRead result = null;

            bool foundInstance = instances.TryGetValue(indexString, out result);

            if (result != null)
            {
                if (!ReferenceEquals(resultType, result.resultType))
                {
                    foundInstance = false;
                }
                else
                if (argumentTypes.Zip(result.argumentTypes, (x, y) => x.isEquivalent(y)).Any(x => !x))
                {
                    foundInstance = false;
                }
            }
            if (!foundInstance)
            {
                var indexTypes = argumentTypes.Skip(1);
                result = new BasicMapRead(mapType, typeArguments, indexTypes, resultType);
                instances[indexString] = result;
            }
            return(result);
        }
Ejemplo n.º 18
0
        public Expression visit(FAE e)
        {
            var ml = e.function as MapRead;

            if (ml != null)
            {
                Dictionary <string, ITypeTuple> entry;
                if (!srs.mapReads.TryGetValue(ml.mapType.ToStringN(), out entry))
                {
                    srs.mapReads[ml.mapType.ToStringN()] = entry = new Dictionary <string, ITypeTuple>();
                }
                var dts = TypeTuple.make(ml.mapTypeArguments);
                entry[dts.ToString()] = dts;
            }

            foreach (var a in e.arguments)
            {
                a.visit(this);
            }
            return(e);
        }
Ejemplo n.º 19
0
        private Predicate makeDefinition(SortedSet <Clause> d, IEnumerable <Clause> cs)
        {
            // N :: forall ci in cs :: [ N \/ \/_i !Nci ] /\ /\_i [!N \/ Nci]

            var defs = from c in cs select makeDefinition(d, c);

            var fvs = freeVariables(cs).ToArray();
            var dts = TypeTuple.make(from fv in fvs select fv.type);
            var N   = srs.getFreshPredicate(CSRS.NPPrefix, dts);

            //            Console.WriteLine("\t Defining {0} as {1}", cs.ToString(), N.name);
            foreach (var def in defs)
            {
                var c   = new List <Literal>();
                var vs  = srs.getFreshVariables(fvs);
                var vts = (from v in vs select new Variable(v)).ToArray();
                c.Add(new Literal(new PredicateApplication(N, vts), false));
                var s = new Substitution(fvs, vts);
                c.Add(def.substitute(s));
                d.Add(new Clause(c));
                //                Console.WriteLine("\t\t Adding {0}", c.ToString());
            }
            {
                var c   = new List <Literal>();
                var vs  = srs.getFreshVariables(fvs);
                var vts = (from v in vs select new Variable(v)).ToArray();
                var s   = new Substitution(fvs, vts);
                c.Add(new Literal(new PredicateApplication(N, vts), true));
                foreach (var def in defs)
                {
                    c.Add(def.substitute(s).negate());
                }
                d.Add(new Clause(c));
                //                Console.WriteLine("\t\t Adding {0}", c.ToString());
            }

//            definitionMap[cs.ToString()] = N;
            return(N);
        }
Ejemplo n.º 20
0
        private BasicMapRead(MapType mapType, IEnumerable <IType> mapTypeArguments, IEnumerable <IType> indexTypes, IType resultType)
        {
            Debug.Assert(mapType != null);
            Debug.Assert(indexTypes != null);
            Debug.Assert(resultType != null);
            Debug.Assert(mapType.domain.Count() == indexTypes.Count());
            Debug.Assert(mapTypeArguments != null);
            Debug.Assert(mapType.typeParameters.Length == mapTypeArguments.Count());

            var substitution = new TypeParameterInstantiation(mapType.typeParameters, mapTypeArguments);

            Debug.Assert(resultType.ToStringN() == mapType.range.substitute(substitution).ToStringN());
            Debug.Assert(mapType.domain.Zip(indexTypes, (x, y) => x.substitute(substitution).isEquivalent(y)).All(x => x));

/*            for (int i = 0; i < indexTypes.Count(); i++)
 *              Debug.Assert(indexTypes[i].ToStringExpanded() ==
 *                           mapType.domain[i].substitute(substitution).ToStringExpanded());
 */
            this.mapType          = mapType;
            mapIndexTypes         = TypeTuple.make(indexTypes);
            this.resultType       = resultType;
            this.mapTypeArguments = TypeTuple.make(mapTypeArguments);
        }
Ejemplo n.º 21
0
        public CFG <BasicBlock, BasicEdge> getCFGFromDAG(Implementation imp, Program program)
        {
//            Console.WriteLine("getCFGFromDAG");
            cfg        = new CFG <BasicBlock, BasicEdge>();
            entry      = cfg.addNode("$start");
            exit       = cfg.addNode("$exit");
            labelIndex = 0;

//            Console.WriteLine("\t\t\tDeclarations");
            foreach (var tld in program.TopLevelDeclarations)
            {
                var a = tld as Axiom;
                if (a != null)
                {
//                    Console.WriteLine("\t\tAdding axiom {0}",a.Expr.ToString());
                    var assume = new Assume(procedure.expressionFactory.makeExpression(a.Expr));
                    entry.appendStatement(assume);
                }
                else
                {
                    var bf = tld as Function;
                    if (bf != null && bf.Body != null)
                    {
                        var ft = scope.findFunctionTemplate(bf.Name);
                        var b  = ft.body;
                        Debug.Assert(b != null);

                        var eqF    = BFunctionTemplate.eq.getInstance(TypeTuple.make(new[] { ft.signature.resultType }));
                        var lhs    = new BasicFAE(ft.getInstance(TypeTuple.make(from tv in ft.typeParameters select new VariableType(tv))), new ExpressionList(from bv in b.arguments select new BasicBoundVariableExpression(bv)));
                        var eqe    = new BasicFAE(eqF, new ExpressionList(lhs, b.expression));
                        var axiom  = procedure.expressionFactory.makeSentence(eqe);
                        var assume = new Assume(axiom);
                        entry.appendStatement(assume);
                    }
                }
            }

//            Console.WriteLine("\t\t\tBlocks");
//            var topoSortedBlocks
            foreach (var b in topoSort(imp.Blocks, imp.Blocks[0]))
            {
                addBlock(b);
            }
            BasicBlock start = cfg.lookupOrAddNode(imp.Blocks[0].Label);

            entry.setControlStatement(new UnconditionalBranch(entry, start));
            exit.setControlStatement(new Programs.Statements.Block(exit));

            cfg.setStartNode("$start");
            cfg.setEndNode("$exit");

            foreach (var bb in cfg.nodes)
            {
                if (!ReferenceEquals(bb, exit) && bb.successors.Count == 0)
                {
                    bb.setControlStatement(new UnconditionalBranch(bb, exit));
                }
            }

            foreach (var bb in cfg.nodes)
            {
                if (!ReferenceEquals(bb, entry) && bb.predecessors.Count == 0)
                {
                    Console.WriteLine("Warning - removing orphan - {0}", bb.label);
                    bb.setControlStatement(new Programs.Statements.Block(bb));
                    bb.delete();
                }
            }

            return(cfg);
        }
Ejemplo n.º 22
0
        ////////////////////////////////////////////////////////////////////////////////////
        private Expression makeExpression(NAryExpr fae, bool old)
        {
            if (fae.Fun is TypeCoercion)
            {
                return(makeExpression(fae.Args[0], old));
            }
            var      arguments = new ExpressionList((from Expr e in fae.Args select makeExpression(e, old)).ToArray());
            Function function;

            if (fae.Fun is MapSelect)
            {
                var typeArguments = new IType[fae.TypeParameters.FormalTypeParams.Count];
                for (int i = 0; i < fae.TypeParameters.FormalTypeParams.Count; i++)
                {
                    typeArguments[i] = makeType(fae.TypeParameters[fae.TypeParameters.FormalTypeParams[i]]);
                }
                var argumentTypes = TypeTuple.make(from a in arguments select a.type);
                function = BasicMapRead.mapRead(
                    typeArguments,
                    argumentTypes,
                    makeType(fae.Type)
                    );
            }
            else if (fae.Fun is MapStore)
            {
                var typeArguments = new IType[fae.TypeParameters.FormalTypeParams.Count];
                for (int i = 0; i < fae.TypeParameters.FormalTypeParams.Count; i++)
                {
                    typeArguments[i] = makeType(fae.TypeParameters[fae.TypeParameters.FormalTypeParams[i]]);
                }
                function = BasicMapWrite.makeMapWrite(typeArguments, (from a in arguments select a.type).ToArray(),
                                                      makeType(fae.ShallowType));
            }
            else if (fae.Fun.FunctionName == "==" || fae.Fun.FunctionName == "!=")
            {
                if (arguments[0].type.isEquivalent(arguments[1].type))
                {
                    function = BFunction.eq(arguments[0].type);
                }
                else
                {
                    Debug.Assert(!arguments[0].type.isGround || !arguments[1].type.isGround);
                    function = BFunction.eq(arguments[0].type, arguments[1].type);
                }
                if (fae.Fun.FunctionName == "!=")
                {
                    arguments = new ExpressionList(
                        new BasicFAE(
                            function,
                            arguments
                            )
                        );
                    function = scope.getFunction("!", TypeTuple.make());
                }
            }
            else if (fae.Fun.FunctionName == "<:")
            {
                function = scope.getFunction(fae.Fun.FunctionName, TypeTuple.make(new[] { arguments[0].type }));
            }
            else if (fae.Fun.FunctionName == BFunctionTemplate.iteName)
            {
                function = scope.getFunction(fae.Fun.FunctionName, TypeTuple.make(new[] { arguments[1].type }));
            }
            else if (fae.Fun.FunctionName == @"-" && fae.Fun.ArgumentCount == 1)
            {
                arguments = new ExpressionList(new[] { new BasicLiteralExpression(IntegerValue.make(0)), arguments[0] });
                function  = scope.getFunction(@"-", TypeTuple.make());
            }
            else
            {
                var typeArguments = TypeTuple.make((fae.TypeParameters == null)
                                                ? new IType[0]
                                                : (from ftp in fae.TypeParameters.FormalTypeParams
                                                   select scope.typeFactory.makeTypeI(fae.TypeParameters[ftp], context)));
                function = scope.getFunction(fae.Fun.FunctionName, typeArguments);
            }
            var result = new BoogieFunctionApplicationExpression(fae, function, arguments);

            Debug.Assert(result.type.ToStringN() ==
                         makeType(fae.Type == null ? fae.ShallowType : fae.Type).ToStringN());
            Debug.Assert(result != null);
            foreach (var fv in result.freeVariables)
            {
                Debug.Assert(context.lookupVariableByOwnName(fv.name) == fv);
            }
            foreach (var ftv in result.freeTypeVariables)
            {
                Debug.Assert(ReferenceEquals(context.lookupTypeVariable(ftv.name), ftv));
            }

            return(result);
        }
Ejemplo n.º 23
0
 private LTPredicate() : base(StateSpace.Functions.Basic.BFunctionTemplate.lt.name, TypeTuple.make(new[] { IntegerType.integerType, IntegerType.integerType }))
 {
 }
 public Function getInstance()
 {
     return(getInstance(TypeTuple.make()));
 }
        public static MapRead mu2ml(MapWrite mu)
        {
            var mlArgTypes = TypeTuple.make(mu.argumentTypes.Take(mu.argumentTypes.Count() - 1));

            return(BasicMapRead.mapRead(mu.typeArguments.Skip(1).ToArray(), mlArgTypes, mu.argumentTypes.Last()));
        }
Ejemplo n.º 26
0
 public MapRead mapRead(IEnumerable <IType> mapTypeArgs)
 {
     Debug.Assert(mapTypeArgs.Count() == mapType.typeParameters.Length);
     return(BasicMapRead.mapRead(mapType, TypeTuple.make(mapTypeArgs)));
 }
Ejemplo n.º 27
0
 private FalsePredicate()
     : base("false", TypeTuple.make())
 {
 }
Ejemplo n.º 28
0
 private TruePredicate()
     : base("true", TypeTuple.make())
 {
 }
Ejemplo n.º 29
0
        public static BasicMapWrite makeMapWrite(
            IEnumerable <IType> mapTypeArgumentsA,
            IEnumerable <IType> argumentTypesA,
            IType resultType)
        {
            var mapTypeArguments = TypeTuple.make(mapTypeArgumentsA);
            var argumentTypes    = TypeTuple.make(argumentTypesA);

            Debug.Assert(mapTypeArguments != null);
            Debug.Assert(argumentTypes != null);
            Debug.Assert(argumentTypes.Count() > 1);
            var mapType    = argumentTypes[0] as MapType;
            var sourceType = argumentTypes.Last();

            Debug.Assert(mapType != null);
            Debug.Assert(mapType.domain.Count() == argumentTypes.Count() - 2);
            Debug.Assert(mapType.typeParameters.Count() == mapTypeArguments.Count());

            var indexString = "";

            foreach (var a in argumentTypes)
            {
                indexString += (indexString == "" ? "" : ",") + a.ToString();
            }

            var indexTypes = TypeTuple.make(argumentTypes.Skip(1).Take(argumentTypes.Count() - 2));

            BasicMapWrite result        = null;
            bool          foundInstance = instances.TryGetValue(indexString, out result);

            if (result != null)
            {
                if (!ReferenceEquals(resultType, result.resultType))
                {
                    foundInstance = false;
                }
                else
                {
                    for (int i = 0; i < argumentTypes.Count(); i++)
                    {
                        if (!ReferenceEquals(argumentTypes[i], result.argumentTypes[i]))
                        {
                            foundInstance = false;
                            break;
                        }
                    }
                }
            }

            if (!foundInstance)
            {
                result = new BasicMapWrite(mapType, indexTypes, sourceType, resultType, mapTypeArguments);
                Debug.Assert(indexString != null);
                Debug.Assert(instances != null);
                Debug.Assert(result != null);
//                instances.Add(indexString,result);
                instances[indexString] = result;
            }

            return(result);
        }