Example #1
0
        private IEnumerable <Expression> SubstVar(ExpressionTree formula, MapDisplayExpr args)
        {
            var varMap = new Dictionary <Expression, List <Expression> >();

            foreach (var pair in args.Elements)
            {
                Contract.Assert(pair.A is NameSegment, Error.MkErr(formula.TreeToExpression(), 1, "Variable"));
                foreach (var p1 in ResolveExpression(pair.A))
                {
                    Expression key = null;
                    if (p1 is Expression)
                    {
                        key = p1 as Expression;
                    }
                    else if (p1 is IVariable)
                    {
                        key = VariableToExpression(p1 as IVariable);
                    }
                    else
                    {
                        Contract.Assert(false, "Sum Tin Wong");
                    }
                    Contract.Assert(key != null, Error.MkErr(formula.TreeToExpression(), 1, "Variable"));
                    var tempList = ResolveExpression(pair.B).Select(p2 => p2 is IVariable ? VariableToExpression((IVariable)p2) : p2 as Expression).ToList();
                    if (key != null)
                    {
                        varMap.Add(key, tempList);
                    }
                }
            }
            return(ReplaceVar(varMap, formula));
        }
Example #2
0
        private IEnumerable <Expression> SubstOp(ExpressionTree formula, MapDisplayExpr args)
        {
            var opcodeMap = new Dictionary <BinaryExpr.Opcode, BinaryExpr.Opcode>();

            foreach (var pair in args.Elements)
            {
                var op1String = pair.A as LiteralExpr;
                Contract.Assert(op1String != null);
                var op2String = pair.B as LiteralExpr;
                Contract.Assert(op2String != null);
                opcodeMap.Add(StringToOp(op1String?.Value.ToString()), StringToOp(op2String?.Value.ToString()));
            }
            return(ReplaceOp(opcodeMap, formula));
        }
Example #3
0
        private MapType GetMapType(MapDisplayExpr mde)
        {
            var element = mde.Elements[0];

            if (element.A.GetType() != element.B.GetType())
            {
                return(MapType.Undefined);
            }
            if (element.A.GetType() == typeof(StringLiteralExpr))
            {
                return(MapType.Op);
            }
            if (element.A.GetType() == typeof(NameSegment))
            {
                return(MapType.Var);
            }
            return(MapType.Undefined);
        }
Example #4
0
 private IEnumerable<Expression> SubstVar(ExpressionTree formula, MapDisplayExpr args) {
   var varMap = new Dictionary<Expression, List<Expression>>();
   foreach (var pair in args.Elements) {
     Contract.Assert(pair.A is NameSegment, Error.MkErr(formula.TreeToExpression(), 1, "Variable"));
     foreach (var p1 in ResolveExpression(pair.A)) {
       Expression key = null;
       if (p1 is Expression)
         key = p1 as Expression;
       else if (p1 is IVariable)
         key = VariableToExpression(p1 as IVariable);
       else
         Contract.Assert(false, "Sum Tin Wong");
       Contract.Assert(key != null, Error.MkErr(formula.TreeToExpression(), 1, "Variable"));
       var tempList = ResolveExpression(pair.B).Select(p2 => p2 is IVariable ? VariableToExpression((IVariable) p2) : p2 as Expression).ToList();
       if (key != null)
         varMap.Add(key, tempList);
     }
   }
   return ReplaceVar(varMap, formula);
 }
Example #5
0
 private static bool ShallowEq(MapDisplayExpr expr1, MapDisplayExpr expr2)
 {
     return(expr1.Finite == expr2.Finite);
 }
Example #6
0
        void MapDisplayExpr(IToken/*!*/ mapToken, bool finite, out Expression e)
        {
            Contract.Ensures(Contract.ValueAtReturn(out e) != null);
            List<ExpressionPair/*!*/>/*!*/ elements= new List<ExpressionPair/*!*/>() ;
            e = dummyExpr;

            Expect(48);
            if (StartOf(7)) {
            MapLiteralExpressions(out elements);
            }
            e = new MapDisplayExpr(mapToken, finite, elements);
            Expect(49);
        }
Example #7
0
    private MapType GetMapType(MapDisplayExpr mde) {
      var element = mde.Elements[0];

      if (element.A.GetType() != element.B.GetType())
        return MapType.Undefined;
      if (element.A.GetType() == typeof(StringLiteralExpr))
        return MapType.Op;
      if (element.A.GetType() == typeof(NameSegment))
        return MapType.Var;
      return MapType.Undefined;
    }
Example #8
0
    private IEnumerable<Expression> SubstOp(ExpressionTree formula, MapDisplayExpr args) {
      var opcodeMap = new Dictionary<BinaryExpr.Opcode, BinaryExpr.Opcode>();

      foreach (var pair in args.Elements) {
        var op1String = pair.A as LiteralExpr;
        Contract.Assert(op1String != null);
        var op2String = pair.B as LiteralExpr;
        Contract.Assert(op2String != null);
        opcodeMap.Add(StringToOp(op1String?.Value.ToString()), StringToOp(op2String?.Value.ToString()));
      }
      return ReplaceOp(opcodeMap, formula);
    }