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); } }
public SynExpr Mutate(SynExpr input, FsharpCoreOrchestrator iterator) { var castinput = input as SynExpr.Match; var list = castinput.clauses.ToList(); foreach (var clause in castinput.clauses) { if (clause.pat.IsConst && ((Const)clause.pat).constant.IsBool) { //inverts boolean, true -> false and false -> true list[castinput.clauses.ToList().FindIndex(x => x.Equals(clause))] = SynMatchClause.NewClause(NewConst(NewBool(!((Bool)((Const)clause.pat).constant).Item), ((Const)clause.pat).Range), clause.whenExpr, clause.resultExpr, clause.range, clause.spInfo); } } return(SynExpr.NewMatch(castinput.matchSeqPoint, castinput.expr, ListModule.OfSeq(list), castinput.range)); }