Skip to main content

litex/fact/
fact.rs

1use crate::prelude::*;
2use std::fmt;
3#[derive(Clone)]
4pub enum Fact {
5    AtomicFact(AtomicFact),
6    ExistFact(ExistFact),
7    OrFact(OrFact),
8    AndFact(AndFact),
9    ChainFact(ChainFact),
10    ForallFact(ForallFact),
11    ForallFactWithIff(ForallFactWithIff),
12}
13
14impl fmt::Debug for Fact {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        write!(f, "{}", self)
17    }
18}
19
20impl Fact {
21    pub fn fact_type_string(&self) -> String {
22        match self {
23            Fact::AtomicFact(_) => "AtomicFact".to_string(),
24            Fact::ExistFact(_) => "ExistFact".to_string(),
25            Fact::OrFact(_) => "OrFact".to_string(),
26            Fact::AndFact(_) => "AndFact".to_string(),
27            Fact::ChainFact(_) => "ChainFact".to_string(),
28            Fact::ForallFact(_) => "ForallFact".to_string(),
29            Fact::ForallFactWithIff(_) => "ForallFactWithIff".to_string(),
30        }
31    }
32}
33
34impl fmt::Display for Fact {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            Fact::AtomicFact(atomic_fact) => write!(f, "{}", atomic_fact),
38            Fact::ExistFact(exist_fact) => write!(f, "{}", exist_fact),
39            Fact::OrFact(or_fact) => write!(f, "{}", or_fact),
40            Fact::AndFact(and_fact) => write!(f, "{}", and_fact),
41            Fact::ChainFact(chain_fact) => write!(f, "{}", chain_fact),
42            Fact::ForallFact(forall_fact) => write!(f, "{}", forall_fact),
43            Fact::ForallFactWithIff(forall_fact_with_iff) => write!(f, "{}", forall_fact_with_iff),
44        }
45    }
46}
47
48impl Fact {
49    pub fn line_file(&self) -> LineFile {
50        match self {
51            Fact::AtomicFact(a) => a.line_file(),
52            Fact::ExistFact(e) => e.line_file(),
53            Fact::OrFact(o) => o.line_file.clone(),
54            Fact::AndFact(a) => a.line_file(),
55            Fact::ChainFact(c) => c.line_file(),
56            Fact::ForallFact(f) => f.line_file.clone(),
57            Fact::ForallFactWithIff(f) => f.line_file.clone(),
58        }
59    }
60
61    pub fn into_stmt(self) -> Stmt {
62        self.into()
63    }
64}
65
66impl Fact {
67    // TODO 未来删了比较好,因为默认所有stmt里的东西都不能变化了
68    pub fn with_new_line_file(self, line_file: LineFile) -> Fact {
69        match self {
70            Fact::AtomicFact(atomic_fact) => {
71                Fact::AtomicFact(atomic_fact.with_new_line_file(line_file))
72            }
73            Fact::ExistFact(e) => Fact::ExistFact(ExistFact {
74                params_def_with_type: e.params_def_with_type,
75                facts: e.facts,
76                line_file,
77            }),
78            Fact::OrFact(or_fact) => Fact::OrFact(OrFact::new(or_fact.facts, line_file)),
79            Fact::AndFact(and_fact) => Fact::AndFact(AndFact::new(and_fact.facts, line_file)),
80            Fact::ChainFact(chain_fact) => Fact::ChainFact(ChainFact::new(
81                chain_fact.objs,
82                chain_fact.prop_names,
83                line_file,
84            )),
85            Fact::ForallFact(f) => Fact::ForallFact(ForallFact {
86                params_def_with_type: f.params_def_with_type,
87                dom_facts: f.dom_facts,
88                then_facts: f.then_facts,
89                line_file,
90            }),
91            Fact::ForallFactWithIff(f) => Fact::ForallFactWithIff(ForallFactWithIff {
92                forall_fact: f.forall_fact,
93                iff_facts: f.iff_facts,
94                line_file,
95            }),
96        }
97    }
98}