1
use crate::Rule;
2
use crate::utilities::TermStack;
3
use crate::utilities::create_var_map;
4

            
5
/// This is a [Rule] condition stored as semi compressed trees such that they can be
6
/// substituted efficiently.
7
#[derive(Hash, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
8
pub struct EMACondition {
9
    /// Conditions lhs and rhs are stored in the term pool as much as possible with a SemiCompressedTermTree
10
    pub lhs_term_stack: TermStack,
11
    pub rhs_term_stack: TermStack,
12

            
13
    /// whether the lhs and rhs should be equal or different
14
    pub equality: bool,
15
}
16

            
17
/// Computes the extended condition from a given rewrite rule.
18
46692
pub fn extend_conditions(rule: &Rule) -> Vec<EMACondition> {
19
46692
    let var_map = create_var_map(&rule.lhs);
20
46692
    let mut conditions = vec![];
21

            
22
46692
    for c in &rule.conditions {
23
15936
        let ema_condition = EMACondition {
24
15936
            lhs_term_stack: TermStack::from_term(&c.lhs.copy(), &var_map),
25
15936
            rhs_term_stack: TermStack::from_term(&c.rhs.copy(), &var_map),
26
15936
            equality: c.equality,
27
15936
        };
28
15936
        conditions.push(ema_condition);
29
15936
    }
30

            
31
46692
    conditions
32
46692
}