////////////////////////////////////////////

        ////////////////////////////////////////////
        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);
        }
Exemple #2
0
 //////////////////////////////////////////////
 public BasicLiteralExpression(BasicLiteralExpression other)
     : this(other.value)
 {
 }