Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tamer
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-24 14:14:05 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-24 14:14:05 -0400
commit7a4f6cf9f21cba15b221fc382cba6f41daa82b10 (patch)
tree62e510b5bd3909d35b7e9eb04c67ebadd60e49a4 /tamer
parentf969877324d5c4f5debb6646f4ff95667a92e04f (diff)
downloadtame-7a4f6cf9f21cba15b221fc382cba6f41daa82b10.tar.gz
tame-7a4f6cf9f21cba15b221fc382cba6f41daa82b10.tar.bz2
tame-7a4f6cf9f21cba15b221fc382cba6f41daa82b10.zip
[DEV-7087] TAMER: symbol_dummy! macro
Diffstat (limited to 'tamer')
-rw-r--r--tamer/src/ir/asg/base.rs45
-rw-r--r--tamer/src/ir/asg/object.rs42
-rw-r--r--tamer/src/ir/asg/section.rs3
-rw-r--r--tamer/src/lib.rs5
-rw-r--r--tamer/src/obj/xmle/writer/xmle.rs26
-rw-r--r--tamer/src/sym.rs10
6 files changed, 70 insertions, 61 deletions
diff --git a/tamer/src/ir/asg/base.rs b/tamer/src/ir/asg/base.rs
index d4b03a0..5842e4b 100644
--- a/tamer/src/ir/asg/base.rs
+++ b/tamer/src/ir/asg/base.rs
@@ -468,8 +468,8 @@ mod test {
// index to create a gap, and then use an index within that gap
// to ensure that it's not considered an already-defined
// identifier.
- let syma = Symbol::new_dummy(SymbolIndex::from_u32(5), "syma");
- let symb = Symbol::new_dummy(SymbolIndex::from_u32(1), "symab");
+ let syma = symbol_dummy!(5, "syma");
+ let symb = symbol_dummy!(1, "symab");
let nodea = sut.declare(
&syma,
@@ -522,7 +522,7 @@ mod test {
fn lookup_by_symbol() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "lookup");
+ let sym = symbol_dummy!(1, "lookup");
let node = sut.declare(
&sym,
IdentKind::Meta,
@@ -541,7 +541,7 @@ mod test {
fn declare_extern() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "extern");
+ let sym = symbol_dummy!(1, "extern");
let node = sut.declare_extern(&sym, IdentKind::Meta)?;
assert_eq!(
@@ -556,7 +556,7 @@ mod test {
fn declare_returns_existing() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "symdup");
+ let sym = symbol_dummy!(1, "symdup");
let src = Source::default();
let node = sut.declare(&sym, IdentKind::Meta, src.clone())?;
@@ -585,7 +585,7 @@ mod test {
fn declare_fails_if_transition_fails() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "symdup");
+ let sym = symbol_dummy!(1, "symdup");
let src = Source {
desc: Some("orig".into()),
..Default::default()
@@ -618,7 +618,7 @@ mod test {
fn add_fragment_to_ident() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "tofrag");
+ let sym = symbol_dummy!(1, "tofrag");
let src = Source {
generated: true,
..Default::default()
@@ -649,8 +649,8 @@ mod test {
fn add_ident_dep_to_ident() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
- let dep = Symbol::new_dummy(SymbolIndex::from_u32(2), "dep");
+ let sym = symbol_dummy!(1, "sym");
+ let dep = symbol_dummy!(2, "dep");
let symnode = sut.declare(&sym, IdentKind::Meta, Source::default())?;
let depnode = sut.declare(&dep, IdentKind::Meta, Source::default())?;
@@ -670,8 +670,8 @@ mod test {
fn add_dep_lookup_existing() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
- let dep = Symbol::new_dummy(SymbolIndex::from_u32(2), "dep");
+ let sym = symbol_dummy!(1, "sym");
+ let dep = symbol_dummy!(2, "dep");
let _ = sut.declare(&sym, IdentKind::Meta, Source::default())?;
let _ = sut.declare(&dep, IdentKind::Meta, Source::default())?;
@@ -686,8 +686,8 @@ mod test {
fn add_dep_lookup_missing() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
- let dep = Symbol::new_dummy(SymbolIndex::from_u32(2), "dep");
+ let sym = symbol_dummy!(1, "sym");
+ let dep = symbol_dummy!(2, "dep");
// both of these are missing
let (symnode, depnode) = sut.add_dep_lookup(&sym, &dep);
@@ -703,8 +703,8 @@ mod test {
fn declare_return_missing_symbol() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
- let dep = Symbol::new_dummy(SymbolIndex::from_u32(2), "dep");
+ let sym = symbol_dummy!(1, "sym");
+ let dep = symbol_dummy!(2, "dep");
// both of these are missing, see add_dep_lookup_missing
let (symnode, _) = sut.add_dep_lookup(&sym, &dep);
@@ -746,10 +746,7 @@ mod test {
$(
i += 1;
- let sym = Symbol::new_dummy(
- SymbolIndex::from_u32(i),
- stringify!($name)
- );
+ let sym = symbol_dummy!(i, stringify!($name));
$sut.declare(&sym, $kind, Source::default())?;
let (_, _) = $sut.add_dep_lookup($base, &sym);
@@ -768,7 +765,7 @@ mod test {
let mut map = vec![];
let mut retmap = vec![];
- let base = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym1");
+ let base = symbol_dummy!(1, "sym1");
let base_node =
sut.declare(&base, IdentKind::Map, Source::default())?;
@@ -807,8 +804,8 @@ mod test {
fn graph_sort_missing_node() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
- let dep = Symbol::new_dummy(SymbolIndex::from_u32(2), "dep");
+ let sym = symbol_dummy!(1, "sym");
+ let dep = symbol_dummy!(2, "dep");
let sym_node = sut.declare(
&sym,
@@ -838,8 +835,8 @@ mod test {
fn graph_sort_no_roots() -> AsgResult<()> {
let mut sut = Sut::with_capacity(0, 0);
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
- let dep = Symbol::new_dummy(SymbolIndex::from_u32(2), "dep");
+ let sym = symbol_dummy!(1, "sym");
+ let dep = symbol_dummy!(2, "dep");
let (_, _) = sut.add_dep_lookup(&sym, &dep);
diff --git a/tamer/src/ir/asg/object.rs b/tamer/src/ir/asg/object.rs
index e516cfe..2f5684d 100644
--- a/tamer/src/ir/asg/object.rs
+++ b/tamer/src/ir/asg/object.rs
@@ -482,7 +482,7 @@ mod test {
// Note that IdentObject has no variants capable of None
#[test]
fn ident_object_name() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
assert_eq!(Some(&sym), IdentObject::Missing(&sym).name());
@@ -511,7 +511,7 @@ mod test {
#[test]
fn ident_object_kind() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
let kind = IdentKind::Class(Dim::from_u8(5));
assert_eq!(None, IdentObject::Missing(&sym).kind());
@@ -541,7 +541,7 @@ mod test {
#[test]
fn ident_object_src() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
let src = Source {
desc: Some("test source".into()),
..Default::default()
@@ -570,7 +570,7 @@ mod test {
#[test]
fn ident_object_fragment() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
let text: FragmentText = "foo".into();
assert_eq!(None, IdentObject::Missing(&sym).fragment());
@@ -600,7 +600,7 @@ mod test {
#[test]
fn ident_object_as_ident() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
let ident = IdentObject::Missing(&sym);
// Since we _are_ an IdentObject, we should return a reference
@@ -617,13 +617,13 @@ mod test {
#[test]
fn ident_object_missing() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "missing");
+ let sym = symbol_dummy!(1, "missing");
assert_eq!(IdentObject::Missing(&sym), IdentObject::missing(&sym));
}
#[test]
fn ident_object_ident() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "missing");
+ let sym = symbol_dummy!(1, "missing");
let kind = IdentKind::Meta;
let src = Source {
desc: Some("ident ctor".into()),
@@ -638,7 +638,7 @@ mod test {
#[test]
fn ident_object_extern() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "missing");
+ let sym = symbol_dummy!(1, "missing");
let kind = IdentKind::Class(Dim::from_u8(1));
assert_eq!(
@@ -650,7 +650,7 @@ mod test {
// TODO: incompatible
#[test]
fn redeclare_returns_existing_compatible() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "symdup");
+ let sym = symbol_dummy!(1, "symdup");
let first =
IdentObject::ident(&sym, IdentKind::Meta, Source::default());
@@ -667,7 +667,7 @@ mod test {
#[test]
fn add_fragment_to_ident() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "tofrag");
+ let sym = symbol_dummy!(1, "tofrag");
let src = Source {
generated: true,
..Default::default()
@@ -686,7 +686,7 @@ mod test {
#[test]
fn add_fragment_to_fragment_fails() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "badsym");
+ let sym = symbol_dummy!(1, "badsym");
let ident =
IdentObject::ident(&sym, IdentKind::Meta, Source::default());
@@ -716,8 +716,8 @@ mod test {
// TODO: incompatible
#[test]
fn declare_override_virtual_ident() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "virtual");
- let over_src = Symbol::new_dummy(SymbolIndex::from_u32(2), "src");
+ let sym = symbol_dummy!(1, "virtual");
+ let over_src = symbol_dummy!(2, "src");
let kind = IdentKind::Meta;
let virt = IdentObject::ident(
@@ -743,8 +743,8 @@ mod test {
// TODO: incompatible
#[test]
fn declare_override_virtual_ident_fragment() {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "virtual");
- let over_src = Symbol::new_dummy(SymbolIndex::from_u32(2), "src");
+ let sym = symbol_dummy!(1, "virtual");
+ let over_src = symbol_dummy!(2, "src");
let kind = IdentKind::Meta;
let virt_src = Source {
@@ -783,7 +783,7 @@ mod test {
}
fn add_ident_kind_ignores(given: IdentKind, expected: IdentKind) {
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "tofrag");
+ let sym = symbol_dummy!(1, "tofrag");
let src = Source {
generated: true,
..Default::default()
@@ -823,11 +823,11 @@ mod test {
#[test]
fn source_from_sym_attrs() {
- let nsym = Symbol::new_dummy(SymbolIndex::from_u32(1), "name");
- let ssym = Symbol::new_dummy(SymbolIndex::from_u32(2), "src");
- let psym = Symbol::new_dummy(SymbolIndex::from_u32(3), "parent");
- let ysym = Symbol::new_dummy(SymbolIndex::from_u32(4), "yields");
- let fsym = Symbol::new_dummy(SymbolIndex::from_u32(5), "from");
+ let nsym = symbol_dummy!(1, "name");
+ let ssym = symbol_dummy!(2, "src");
+ let psym = symbol_dummy!(3, "parent");
+ let ysym = symbol_dummy!(4, "yields");
+ let fsym = symbol_dummy!(5, "from");
let attrs = SymAttrs {
pkg_name: Some(&nsym),
diff --git a/tamer/src/ir/asg/section.rs b/tamer/src/ir/asg/section.rs
index 839466e..17eb174 100644
--- a/tamer/src/ir/asg/section.rs
+++ b/tamer/src/ir/asg/section.rs
@@ -155,8 +155,7 @@ mod test {
use crate::sym::{Symbol, SymbolIndex};
lazy_static! {
- static ref SYM: Symbol<'static> =
- Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ static ref SYM: Symbol<'static> = symbol_dummy!(1, "sym");
}
type Sut<'a, 'i> = Section<'a, IdentObject<'i>>;
diff --git a/tamer/src/lib.rs b/tamer/src/lib.rs
index 165359c..3c35893 100644
--- a/tamer/src/lib.rs
+++ b/tamer/src/lib.rs
@@ -20,10 +20,13 @@
//! An incremental rewrite of TAME in Rust.
pub mod global;
+
+#[macro_use]
+pub mod sym;
+
pub mod ir;
pub mod ld;
pub mod obj;
-pub mod sym;
#[cfg(test)]
#[macro_use]
diff --git a/tamer/src/obj/xmle/writer/xmle.rs b/tamer/src/obj/xmle/writer/xmle.rs
index 517abb2..3d2e606 100644
--- a/tamer/src/obj/xmle/writer/xmle.rs
+++ b/tamer/src/obj/xmle/writer/xmle.rs
@@ -453,7 +453,7 @@ mod test {
_ => panic!("did not match expected event"),
}));
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
sut.write_start_package(&sym, &String::from(""))?;
@@ -508,7 +508,7 @@ mod test {
_ => panic!("did not trigger event"),
}));
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
let obj = IdentObject::IdentFragment(
&sym,
IdentKind::Meta,
@@ -530,7 +530,7 @@ mod test {
panic!("callback should not have been called");
}));
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
let obj = IdentObject::Ident(
&sym,
IdentKind::Cgen(Dim::default()),
@@ -551,7 +551,7 @@ mod test {
panic!("callback should not have been called");
}));
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "sym");
+ let sym = symbol_dummy!(1, "sym");
let obj = IdentObject::Missing(&sym);
let mut section = Section::new();
@@ -590,7 +590,7 @@ mod test {
_ => panic!("unexpected event"),
}));
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "random_symbol");
+ let sym = symbol_dummy!(1, "random_symbol");
let object =
IdentObject::Ident(&sym, IdentKind::Worksheet, Source::default());
let mut sections = Sections::new();
@@ -645,11 +645,11 @@ mod test {
_ => panic!("unexpected event"),
}));
- let nsym = Symbol::new_dummy(SymbolIndex::from_u32(1), "name");
- let ssym = Symbol::new_dummy(SymbolIndex::from_u32(2), "src");
- let psym = Symbol::new_dummy(SymbolIndex::from_u32(3), "parent");
- let ysym = Symbol::new_dummy(SymbolIndex::from_u32(4), "yields");
- let fsym = Symbol::new_dummy(SymbolIndex::from_u32(5), "from");
+ let nsym = symbol_dummy!(1, "name");
+ let ssym = symbol_dummy!(2, "src");
+ let psym = symbol_dummy!(3, "parent");
+ let ysym = symbol_dummy!(4, "yields");
+ let fsym = symbol_dummy!(5, "from");
let attrs = SymAttrs {
pkg_name: Some(&nsym),
@@ -692,8 +692,8 @@ mod test {
_ => panic!("unexpected event"),
}));
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "source symbol");
- let symb = Symbol::new_dummy(SymbolIndex::from_u32(2), "dest symbol");
+ let sym = symbol_dummy!(1, "source symbol");
+ let symb = symbol_dummy!(2, "dest symbol");
let mut src = Source::default();
src.from = Some(vec![&symb]);
@@ -713,7 +713,7 @@ mod test {
_ => panic!("unexpected write"),
}));
- let sym = Symbol::new_dummy(SymbolIndex::from_u32(1), "random_symbol");
+ let sym = symbol_dummy!(1, "random_symbol");
let object =
IdentObject::Ident(&sym, IdentKind::Worksheet, Source::default());
diff --git a/tamer/src/sym.rs b/tamer/src/sym.rs
index 9d394ad..8ed88f9 100644
--- a/tamer/src/sym.rs
+++ b/tamer/src/sym.rs
@@ -371,6 +371,8 @@ impl<'i> Symbol<'i> {
/// builds.
/// This separate name is meant to strongly imply that you should not be
/// doing this otherwise.
+ ///
+ /// See also `dummy_symbol!`.
#[cfg(test)]
#[inline(always)]
pub fn new_dummy(index: SymbolIndex, str: &'i str) -> Symbol<'i> {
@@ -615,6 +617,14 @@ pub type FxArenaInterner<'i> = ArenaInterner<'i, FxBuildHasher>;
/// see [`FxArenaInterner`].
pub type DefaultInterner<'i> = FxArenaInterner<'i>;
+/// Concisely define dummy symbols for testing.
+#[cfg(test)]
+macro_rules! symbol_dummy {
+ ($id:expr, $name:expr) => {
+ Symbol::new_dummy(SymbolIndex::from_u32($id), $name);
+ };
+}
+
#[cfg(test)]
mod test {
use super::*;