diff options
author | Joseph Frazer <joseph.frazer@ryansg.com> | 2020-03-07 10:49:41 -0500 |
---|---|---|
committer | Joseph Frazer <joseph.frazer@ryansg.com> | 2020-03-09 08:23:13 -0400 |
commit | f373a00a80a4a366573d178911f455561fc2c0ff (patch) | |
tree | 201b1f3d37207658003e7e87cba48eb4948e8eca | |
parent | 2a5551a04a6705d20e16c54aca1f875198ae89ab (diff) | |
download | tame-f373a00a80a4a366573d178911f455561fc2c0ff.tar.gz tame-f373a00a80a4a366573d178911f455561fc2c0ff.tar.bz2 tame-f373a00a80a4a366573d178911f455561fc2c0ff.zip |
[DEV-7134] Propagate sorting errors
If a node is found while sorting that is not expected, we should show
the error to the user.
-rw-r--r-- | tamer/src/ir/asg/graph.rs | 5 | ||||
-rw-r--r-- | tamer/src/ir/asg/mod.rs | 2 | ||||
-rw-r--r-- | tamer/src/ld/poc.rs | 18 |
3 files changed, 18 insertions, 7 deletions
diff --git a/tamer/src/ir/asg/graph.rs b/tamer/src/ir/asg/graph.rs index e1e38f7..1f56e6c 100644 --- a/tamer/src/ir/asg/graph.rs +++ b/tamer/src/ir/asg/graph.rs @@ -214,6 +214,8 @@ pub enum AsgError { /// /// See [`Asg::set_fragment`] for more information. BadFragmentDest(String), + /// The node was not expected in the current context + UnexpectedNode(String), } impl std::fmt::Display for AsgError { @@ -222,6 +224,9 @@ impl std::fmt::Display for AsgError { Self::BadFragmentDest(msg) => { write!(fmt, "bad fragment destination: {}", msg) } + Self::UnexpectedNode(msg) => { + write!(fmt, "unexpected node: {}", msg) + } } } } diff --git a/tamer/src/ir/asg/mod.rs b/tamer/src/ir/asg/mod.rs index e5a397b..8905768 100644 --- a/tamer/src/ir/asg/mod.rs +++ b/tamer/src/ir/asg/mod.rs @@ -186,7 +186,7 @@ mod graph; mod ident; mod object; -pub use graph::{Asg, AsgResult, ObjectRef}; +pub use graph::{Asg, AsgError, AsgResult, ObjectRef}; pub use ident::{Dim, IdentKind}; pub use object::{FragmentText, Object, Source}; diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs index 6d3d175..6e0a7fe 100644 --- a/tamer/src/ld/poc.rs +++ b/tamer/src/ld/poc.rs @@ -21,7 +21,9 @@ //! banished to its own file to try to make that more clear. use crate::global; -use crate::ir::asg::{Asg, DefaultAsg, IdentKind, Object, ObjectRef, Source}; +use crate::ir::asg::{ + Asg, AsgError, DefaultAsg, IdentKind, Object, ObjectRef, Source, +}; use crate::obj::xmle::writer::{Sections, XmleWriter}; use crate::obj::xmlo::reader::{XmloError, XmloEvent, XmloReader}; use crate::sym::{DefaultInterner, Interner, Symbol}; @@ -76,7 +78,7 @@ pub fn main(package_path: &str, output: &str) -> Result<(), Box<dyn Error>> { .filter_map(|sym| depgraph.lookup(sym)), ); - let mut sorted = sort_deps(&depgraph, &roots); + let mut sorted = sort_deps(&depgraph, &roots)?; //println!("Sorted ({}): {:?}", sorted.len(), sorted); @@ -239,7 +241,7 @@ fn load_xmlo<'a, 'i, I: Interner<'i>>( fn sort_deps<'a, 'i>( depgraph: &'a LinkerAsg<'i>, roots: &Vec<LinkerObjectRef>, -) -> Sections<'a, 'i> { +) -> Result<Sections<'a, 'i>, Box<dyn Error>> { // @type=meta, @preproc:elig-class-yields // @type={ret}map{,:head,:tail} @@ -259,7 +261,7 @@ fn sort_deps<'a, 'i>( // TODO: can we encapsulate NodeIndex? while let Some(index) = dfs.next(&depgraph) { - let ident = depgraph.get(index).unwrap(); + let ident = depgraph.get(index).expect("missing node"); match ident { Object::Ident(_, kind, _) @@ -277,11 +279,15 @@ fn sort_deps<'a, 'i>( | IdentKind::RetMapTail => deps.retmap.push_body(ident), _ => deps.rater.push_body(ident), }, - _ => panic!("unexpected node: {:?}", ident), + _ => { + return Err( + AsgError::UnexpectedNode(format!("{:?}", ident)).into() + ) + } } } - deps + Ok(deps) } fn get_interner_value<'a, 'i, I: Interner<'i>>( |