Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tamer
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-04-09 12:58:41 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-04-28 09:06:25 -0400
commit323ea79bf8b15a573b3cc0bffb157ba7b5f99276 (patch)
treeaa1d2784124cfa6ede575d016864767567a29609 /tamer
parent9220de4769d7f3cfa4e155233b61ebb761a01486 (diff)
downloadtame-323ea79bf8b15a573b3cc0bffb157ba7b5f99276.tar.gz
tame-323ea79bf8b15a573b3cc0bffb157ba7b5f99276.tar.bz2
tame-323ea79bf8b15a573b3cc0bffb157ba7b5f99276.zip
[DEV-7084] TAMER: Basic AsgBuilder cleanup
This just tidies things up a little bit before I get into some further refactoring. I wrote the original code when I was just learning Rust not too long ago, so it's interesting to see how my understanding has changed over that relatively short period of time.
Diffstat (limited to 'tamer')
-rw-r--r--tamer/src/obj/xmlo/asg_builder.rs77
1 files changed, 31 insertions, 46 deletions
diff --git a/tamer/src/obj/xmlo/asg_builder.rs b/tamer/src/obj/xmlo/asg_builder.rs
index 6a5047b..de834b6 100644
--- a/tamer/src/obj/xmlo/asg_builder.rs
+++ b/tamer/src/obj/xmlo/asg_builder.rs
@@ -72,23 +72,20 @@ where
) -> Result<'i, S, Ix> {
let mut elig = None;
let first = state.name.is_none();
-
let found = state.found.get_or_insert(Default::default());
loop {
- match self.read_event() {
- Ok(XmloEvent::Package(attrs)) => {
+ match self.read_event()? {
+ XmloEvent::Package(attrs) => {
if first {
state.name = attrs.name;
state.relroot = attrs.relroot;
}
+
elig = attrs.elig;
}
- Ok(XmloEvent::SymDeps(sym, deps)) => {
- // TODO: API needs to expose whether a symbol is already
- // known so that we can warn on them
-
+ XmloEvent::SymDeps(sym, deps) => {
// Maps should not pull in symbols since we may end up
// mapping to params that are never actually used
if !sym.starts_with(":map:") {
@@ -98,16 +95,16 @@ where
}
}
- Ok(XmloEvent::SymDecl(sym, attrs)) => {
+ XmloEvent::SymDecl(sym, attrs) => {
if let Some(sym_src) = attrs.src {
found.insert(sym_src);
} else {
let owned = attrs.src.is_none();
let extern_ = attrs.extern_;
- let kind = (&attrs).try_into().map_err(|err| {
+ let kindval = (&attrs).try_into().map_err(|err| {
format!("sym `{}` attrs error: {}", sym, err)
- });
+ })?;
let mut src: Source = attrs.into();
@@ -117,50 +114,38 @@ where
src.pkg_name = None;
}
- match kind {
- Ok(kindval) => {
- // TODO: inefficient
- let link_root = owned
- && (kindval == IdentKind::Meta
- || kindval == IdentKind::Map
- || kindval == IdentKind::RetMap);
-
- if extern_ {
- graph.declare_extern(sym, kindval, src)?;
- } else {
- let node =
- graph.declare(sym, kindval, src)?;
-
- if link_root {
- state.roots.push(node);
- }
- }
+ let link_root = owned
+ && matches!(
+ kindval,
+ IdentKind::Meta
+ | IdentKind::Map
+ | IdentKind::RetMap
+ );
+
+ if extern_ {
+ graph.declare_extern(sym, kindval, src)?;
+ } else {
+ let node = graph.declare(sym, kindval, src)?;
+
+ if link_root {
+ state.roots.push(node);
}
- Err(e) => return Err(e.into()),
- };
+ }
}
}
- Ok(XmloEvent::Fragment(sym, text)) => {
- match graph.lookup(sym) {
- Some(frag) => match graph.set_fragment(frag, text) {
- Ok(_) => (),
- Err(e) => return Err(e.into()),
- },
- None => {
- return Err(XmloError::MissingFragment(
- String::from("missing fragment"),
- )
- .into());
- }
- };
+ XmloEvent::Fragment(sym, text) => {
+ let frag =
+ graph.lookup(sym).ok_or(XmloError::MissingFragment(
+ String::from("missing fragment"),
+ ))?;
+
+ graph.set_fragment(frag, text)?;
}
// We don't need to read any further than the end of the
// header (symtable, sym-deps, fragments)
- Ok(XmloEvent::Eoh) => break,
-
- Err(e) => return Err(e.into()),
+ XmloEvent::Eoh => break,
}
}