ir::asg::Object::Empty: Remove variant

This variant is unnecessary, as it was used only by the indexer to represent
the absence of a node, for which was can simply use `None` in the containing
`Option`.

* tamer/Cargo.toml: Add `lazy_static`.
* tamer/Cargo.lock: Update.
* tamer/src/ir/asg/base.rs (with_capacity): Use `None` in place of
    `Some(Object::Empty)`.
* tamer/src/ir/asg/object.rs: Adjust state machine graphic.
  (Empty): Remove variant.
  (Missing): Remove reference to variance.
* tamer/src/lib.rs: Import `lazy_static` for test builds.
* tamer/obj/xmle/writer/writer.rs (Section::iter): Remove `Object::Empty`
    from documentation.
  (test::): Remove references to `Object::Missing`.  `lazy_static!` used
    here.
* tamer/obj/xmle/writer/xmle.rs (test::write_section_catch_missing): Replace
    reference to `Object::Missing`.
master
Mike Gerwitz 2020-03-11 15:20:49 -04:00
parent bc976b43cd
commit 400d5b25a1
7 changed files with 27 additions and 29 deletions

1
tamer/Cargo.lock generated
View File

@ -243,6 +243,7 @@ dependencies = [
"fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"quick-xml 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -35,4 +35,5 @@ petgraph = ">= 0.4.13"
quick-xml = ">= 0.17.0"
getopts = "0.2"
exitcode = "1.1.2"
lazy_static = ">= 1.4.0"

View File

@ -81,7 +81,7 @@ where
let mut index = Vec::with_capacity(objects);
// Exhaust the first index to be used as a placeholder.
let empty_node = graph.add_node(Some(Object::Empty));
let empty_node = graph.add_node(None);
index.push(empty_node);
Self {

View File

@ -31,19 +31,11 @@ use crate::sym::Symbol;
/// These types represent object states:
///
/// ```text
/// ,-> (Missing) -------.
/// / \ \
/// / v v
/// ((Empty)) -> (Extern) -> ((Ident)) -> ((IdentFragment)).
/// (Missing) -> (Extern) -> ((Ident)) -> ((IdentFragment)).
/// \ ^ /
/// \ / \ /
/// `--------------------` `-----------'
/// ```
///
/// The [`Empty`][Object::Empty] state is never directly accessable
/// through [`Asg`][super::Asg]'s public API,
/// as it represents the _absence_ of an object at that node within the
/// ASG.
#[derive(Debug, PartialEq)]
pub enum Object<'i> {
/// An identifier is expected to be defined but is not yet available.
@ -53,8 +45,6 @@ pub enum Object<'i> {
/// By defining an object as missing,
/// this allows the graph to be built incrementally as objects are
/// discovered.
///
/// Note that this is different than [`Empty`][Object::Empty].
Missing(&'i Symbol<'i>),
/// A resolved identifier.
@ -79,13 +69,6 @@ pub enum Object<'i> {
/// [linker][crate::ld] to put them into the correct order for the
/// final executable.
IdentFragment(&'i Symbol<'i>, IdentKind, Source<'i>, FragmentText),
/// The empty node (default value for indexer).
///
/// This is not a valid state accessible via [`Asg`][super::Asg].
///
/// Note that this is different than [`Missing`][Object::Missing].
Empty,
}
/// Compiled fragment for identifier.

View File

@ -83,9 +83,11 @@ impl<'a, 'i> Section<'a, 'i> {
///
/// ```
/// use tamer::ir::asg::{Object, Section};
/// use tamer::sym::{DefaultInterner, Interner};
///
/// let interner = DefaultInterner::new();
/// let mut section = Section::new();
/// let obj = Object::Empty;
/// let obj = Object::Missing(interner.intern("ident"));
/// let expect = vec![&obj, &obj, &obj];
///
/// section.push_head(&obj);
@ -166,6 +168,12 @@ impl<'a, 'i> Sections<'a, 'i> {
#[cfg(test)]
mod test {
use super::*;
use crate::sym::{Symbol, SymbolIndex};
lazy_static! {
static ref SYM: Symbol<'static> =
Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
}
#[test]
fn section_empty() {
@ -179,7 +187,7 @@ mod test {
#[test]
fn section_head() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
assert!(section.head.is_empty());
@ -191,7 +199,7 @@ mod test {
#[test]
fn section_body() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
assert!(section.body.is_empty());
@ -204,7 +212,7 @@ mod test {
#[test]
fn section_tail() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
assert!(section.tail.is_empty());
@ -216,7 +224,7 @@ mod test {
#[test]
fn section_len() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
assert_eq!(0, section.len());
section.push_head(&obj);
@ -230,7 +238,7 @@ mod test {
#[test]
fn section_is_empty_head() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
assert!(section.is_empty());
section.push_head(&obj);
@ -240,7 +248,7 @@ mod test {
#[test]
fn section_is_empty_body() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
assert!(section.is_empty());
section.push_body(&obj);
@ -250,7 +258,7 @@ mod test {
#[test]
fn section_is_empty_tail() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
assert!(section.is_empty());
section.push_tail(&obj);
@ -260,7 +268,7 @@ mod test {
#[test]
fn section_iterator() {
let mut section = Section::new();
let obj = Object::Empty;
let obj = Object::Missing(&SYM);
let expect = vec![&obj, &obj, &obj];
section.push_head(&obj);

View File

@ -25,5 +25,9 @@ pub mod ld;
pub mod obj;
pub mod sym;
#[cfg(test)]
#[macro_use]
extern crate lazy_static;
#[cfg(test)]
pub mod test;

View File

@ -546,7 +546,8 @@ mod test {
panic!("callback should not have been called");
}));
let obj = Object::Empty;
let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
let obj = Object::Missing(&sym);
let mut section = Section::new();
section.push_body(&obj);