Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-11 15:20:49 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-19 15:42:06 -0400
commit400d5b25a1a0912790f65ceb0fff9f92059e61b9 (patch)
tree9740f9a696a3d2aec51ec39a63fe787d07cc40aa
parentbc976b43cddc639e0ff1adfd61e93e68e894964e (diff)
downloadtame-400d5b25a1a0912790f65ceb0fff9f92059e61b9.tar.gz
tame-400d5b25a1a0912790f65ceb0fff9f92059e61b9.tar.bz2
tame-400d5b25a1a0912790f65ceb0fff9f92059e61b9.zip
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`.
-rw-r--r--tamer/Cargo.lock1
-rw-r--r--tamer/Cargo.toml1
-rw-r--r--tamer/src/ir/asg/base.rs2
-rw-r--r--tamer/src/ir/asg/object.rs19
-rw-r--r--tamer/src/ir/asg/section.rs26
-rw-r--r--tamer/src/lib.rs4
-rw-r--r--tamer/src/obj/xmle/writer/xmle.rs3
7 files changed, 27 insertions, 29 deletions
diff --git a/tamer/Cargo.lock b/tamer/Cargo.lock
index 4b705f8..0b53fa6 100644
--- a/tamer/Cargo.lock
+++ b/tamer/Cargo.lock
@@ -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)",
diff --git a/tamer/Cargo.toml b/tamer/Cargo.toml
index 7d27fd7..69cc200 100644
--- a/tamer/Cargo.toml
+++ b/tamer/Cargo.toml
@@ -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"
diff --git a/tamer/src/ir/asg/base.rs b/tamer/src/ir/asg/base.rs
index a668a6b..387fdfe 100644
--- a/tamer/src/ir/asg/base.rs
+++ b/tamer/src/ir/asg/base.rs
@@ -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 {
diff --git a/tamer/src/ir/asg/object.rs b/tamer/src/ir/asg/object.rs
index b08c346..b183234 100644
--- a/tamer/src/ir/asg/object.rs
+++ b/tamer/src/ir/asg/object.rs
@@ -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.
diff --git a/tamer/src/ir/asg/section.rs b/tamer/src/ir/asg/section.rs
index 75c2369..9ebaf9f 100644
--- a/tamer/src/ir/asg/section.rs
+++ b/tamer/src/ir/asg/section.rs
@@ -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);
diff --git a/tamer/src/lib.rs b/tamer/src/lib.rs
index 4d1fb28..165359c 100644
--- a/tamer/src/lib.rs
+++ b/tamer/src/lib.rs
@@ -26,4 +26,8 @@ pub mod obj;
pub mod sym;
#[cfg(test)]
+#[macro_use]
+extern crate lazy_static;
+
+#[cfg(test)]
pub mod test;
diff --git a/tamer/src/obj/xmle/writer/xmle.rs b/tamer/src/obj/xmle/writer/xmle.rs
index 0a81214..2888d28 100644
--- a/tamer/src/obj/xmle/writer/xmle.rs
+++ b/tamer/src/obj/xmle/writer/xmle.rs
@@ -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);