示例#1
0
        private static void VisitExpression(SynExpr expr)
        {
            if (expr.IsIfThenElse)
            {
                SynExpr.IfThenElse expression = (SynExpr.IfThenElse)expr;
                Console.WriteLine("Conditional:");
                VisitExpression(expression.ifExpr);
                VisitExpression(expression.thenExpr);
                VisitExpression(expression.elseExpr.Value);
            }
            else if (expr.IsLetOrUse)
            {
                SynExpr.LetOrUse expression = (SynExpr.LetOrUse)expr;
                Console.WriteLine("LetOrUse with the following bindings:");
                foreach (var binding in expression.bindings)
                {
                    VisitPattern(binding.headPat);
                    VisitExpression(binding.expr);
                }
                Console.WriteLine("And the following body:");
                VisitExpression(expression.body);
            }
            else if (expr.IsMatch)
            {
                SynMatchClause toReplace = null;
                foreach (var clause in ((SynExpr.Match)expr).clauses)
                {
                    if (clause.pat.IsConst)
                    {
                        if (((Const)clause.pat).constant.IsBool && ((Bool)((Const)clause.pat).constant).Item == true)
                        {
                            toReplace = clause;
                        }
                    }
                }
                if (toReplace != null)
                {
                    var list = ((SynExpr.Match)expr).clauses.ToList();
                    list[((SynExpr.Match)expr).clauses.ToList().FindIndex(x => x.Equals(toReplace))] = SynMatchClause.NewClause(NewConst(NewBool(false), ((Const)toReplace.pat).Range), toReplace.whenExpr, toReplace.resultExpr, toReplace.range, toReplace.spInfo);
                    expr = SynExpr.NewMatch(((SynExpr.Match)expr).matchSeqPoint, ((SynExpr.Match)expr).expr, ListModule.OfSeq(list), ((SynExpr.Match)expr).range);
                }
                Console.WriteLine(expr);
            }

            else
            {
                Console.WriteLine(" - not supported expression: " + expr);
            }
        }
示例#2
0
        public SynExpr Mutate(SynExpr expr)
        {
            var handler = _fsharpMutationsSynExpr.FindHandler(expr.GetType());

            return(handler.Mutate(expr, this));
        }
 public ChameleonExpression([CanBeNull] SynExpr expr) =>
 public ChameleonExpression([CanBeNull] SynExpr expr, int startOffset, int lineStart)
 {
     SynExpr             = expr;
     OriginalStartOffset = startOffset;
     OriginalLineStart   = lineStart;
 }