ryo_mutations/basic/stmt/
replace_expr.rs1use ryo_source::pure::PureExpr;
15use ryo_symbol::SymbolId;
16
17use crate::Mutation;
18
19#[derive(Debug, Clone)]
21pub struct ReplaceExprMutation {
22 pub old_expr: PureExpr,
24 pub new_expr: PureExpr,
26 pub target_fn: SymbolId,
28 pub replace_all: bool,
30}
31
32impl ReplaceExprMutation {
33 pub fn new(old_expr: PureExpr, new_expr: PureExpr, target_fn: SymbolId) -> Self {
34 Self {
35 old_expr,
36 new_expr,
37 target_fn,
38 replace_all: true,
39 }
40 }
41
42 pub fn first_only(mut self) -> Self {
44 self.replace_all = false;
45 self
46 }
47}
48
49impl Mutation for ReplaceExprMutation {
50 fn describe(&self) -> String {
51 "Replace expression with another expression".to_string()
52 }
53
54 fn mutation_type(&self) -> &'static str {
55 "ReplaceExpr"
56 }
57
58 fn box_clone(&self) -> Box<dyn Mutation> {
59 Box::new(self.clone())
60 }
61}