Skip to main content

litex/fact/
or_fact.rs

1use crate::prelude::*;
2use std::fmt;
3
4#[derive(Clone)]
5pub struct OrFact {
6    pub facts: Vec<AndChainAtomicFact>,
7    pub line_file: LineFile,
8}
9
10impl OrFact {
11    pub fn new(facts: Vec<AndChainAtomicFact>, line_file: LineFile) -> Self {
12        OrFact { facts, line_file }
13    }
14}
15
16impl fmt::Display for OrFact {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        let fact_strings = self
19            .facts
20            .iter()
21            .map(|fact| fact.to_string())
22            .collect::<Vec<String>>();
23        write!(f, "{}", fact_strings.join(format!(" {} ", OR).as_str()))
24    }
25}
26
27impl OrFact {
28    pub fn key(&self) -> String {
29        return format!(
30            "{}",
31            vec_to_string_with_sep(
32                &self
33                    .facts
34                    .iter()
35                    .map(|fact| fact.key())
36                    .collect::<Vec<String>>(),
37                format!(" {} ", OR)
38            )
39        );
40    }
41
42    pub fn get_args_from_fact(&self) -> Vec<Obj> {
43        let mut result: Vec<Obj> = Vec::new();
44        for and_chain_atomic_fact in self.facts.iter() {
45            let args_from_branch = and_chain_atomic_fact.get_args_from_fact();
46            for arg in args_from_branch {
47                result.push(arg);
48            }
49        }
50        result
51    }
52}