diff --git a/crates/vlog_parser/src/defines.rs b/crates/vlog_parser/src/defines.rs index d4b27fb..986b858 100644 --- a/crates/vlog_parser/src/defines.rs +++ b/crates/vlog_parser/src/defines.rs @@ -22,7 +22,7 @@ pub enum DefineKind { } /// One `` `define`` or `` `undef`` directive, as written. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Define { /// Whether this entry defines the name or undefines it. pub kind: DefineKind, @@ -48,12 +48,24 @@ pub struct Define { /// /// Redefinition is legal Verilog, so a name can have several definitions; they /// are all kept and [`DefineTable::latest`] picks the last one. -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct DefineTable { entries: Vec, } impl DefineTable { + /// A table from entries that are already known, in source order. + /// + /// The inverse of [`DefineTable::entries`], for the one caller that has a + /// file's directives without the file's tokens: the workspace index's + /// persistent cache, which stores what a parse found and restores it + /// (`docs/features/index-persistence/README.md`). Nothing is re-derived + /// here — `collect_defines` is still the only thing that *reads* a table + /// out of a file. + pub fn from_entries(entries: Vec) -> DefineTable { + DefineTable { entries } + } + /// Every recorded directive, `` `undef``s included, in source order. pub fn entries(&self) -> &[Define] { &self.entries