diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index eff1d308..7bc3e7e4 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -433,7 +433,7 @@ fn main() { if !args.funcs.is_empty() { if args.funcs.iter().any(|analyze_for| { FunctionNode::from(func) - .name(&mut analyzer) + .name(&analyzer) .unwrap() .starts_with(analyze_for) }) { @@ -509,7 +509,7 @@ fn main() { let funcs = contract.funcs(&analyzer); for func in funcs.into_iter() { if !args.funcs.is_empty() { - if args.funcs.contains(&func.name(&mut analyzer).unwrap()) { + if args.funcs.contains(&func.name(&analyzer).unwrap()) { let ctx = func.body_ctx(&mut analyzer); let analysis = analyzer .bounds_for_all(arena, &file_mapping, ctx, config) diff --git a/crates/graph/src/graph_elements.rs b/crates/graph/src/graph_elements.rs index 5b255e99..c365b503 100644 --- a/crates/graph/src/graph_elements.rs +++ b/crates/graph/src/graph_elements.rs @@ -40,30 +40,6 @@ pub trait AsDotStr { ) -> String; } -#[derive(Debug, Clone, Ord, Eq, PartialEq, PartialOrd)] -pub enum GraphError { - /// The analyzer thought the node was suppose to be one type, but it was a different one - NodeConfusion(String), - /// Call depth limit reached - MaxStackDepthReached(String), - /// Fork width limit reached - MaxStackWidthReached(String), - /// Tried to set the subcontext of a context that already had a subcontext - ChildRedefinition(String), - /// Tried to update a variable that is in an old context - VariableUpdateInOldContext(String), - /// Variable is detached from all contexts - DetachedVariable(String), - /// Expected a single element, found multiple - ExpectedSingle(String), - /// Expected a vector with a certain number of elements, but it was a different number of elements - StackLengthMismatch(String), - /// A variable had a cyclic reference to another variable and we were unable to break the cycle - UnbreakableRecursion(String), - /// The analyzer thought the node was suppose to be one type, but it was a different one - UnknownVariable(String), -} - #[derive(Debug, Clone, Eq, PartialEq)] pub enum Node { /// An analyzed function body/context diff --git a/crates/graph/src/nodes/block.rs b/crates/graph/src/nodes/block.rs index 4ac5bf6a..8627766f 100644 --- a/crates/graph/src/nodes/block.rs +++ b/crates/graph/src/nodes/block.rs @@ -1,5 +1,5 @@ -use crate::{nodes::Concrete, range::elem::Elem, AsDotStr, GraphBackend, GraphError, Node}; -use shared::{NodeIdx, RangeArena}; +use crate::{nodes::Concrete, range::elem::Elem, AsDotStr, GraphBackend, Node}; +use shared::{GraphError, NodeIdx, RangeArena}; use ethers_core::types::{Address, H256, U256}; diff --git a/crates/graph/src/nodes/builtin.rs b/crates/graph/src/nodes/builtin.rs index 757ca985..07968223 100644 --- a/crates/graph/src/nodes/builtin.rs +++ b/crates/graph/src/nodes/builtin.rs @@ -1,7 +1,7 @@ -use crate::{nodes::Concrete, AnalyzerBackend, GraphBackend, GraphError, Node, SolcRange, VarType}; +use crate::{nodes::Concrete, AnalyzerBackend, GraphBackend, Node, SolcRange, VarType}; use crate::range::elem::*; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use ethers_core::types::{Address, H256, I256, U256}; use solang_parser::pt::{Expression, Loc, Type}; diff --git a/crates/graph/src/nodes/concrete.rs b/crates/graph/src/nodes/concrete.rs index eeafe272..f0521974 100644 --- a/crates/graph/src/nodes/concrete.rs +++ b/crates/graph/src/nodes/concrete.rs @@ -1,5 +1,5 @@ -use crate::{nodes::Builtin, AnalyzerBackend, GraphBackend, GraphError, Node, VarType}; -use shared::NodeIdx; +use crate::{nodes::Builtin, AnalyzerBackend, GraphBackend, Node, VarType}; +use shared::{GraphError, NodeIdx}; use ethers_core::types::{Address, H256, I256, U256}; diff --git a/crates/graph/src/nodes/context/expr_ret.rs b/crates/graph/src/nodes/context/expr_ret.rs index 2195fef9..969f67a3 100644 --- a/crates/graph/src/nodes/context/expr_ret.rs +++ b/crates/graph/src/nodes/context/expr_ret.rs @@ -1,9 +1,9 @@ use crate::{ nodes::{context::ContextVarNode, Concrete}, range::elem::Elem, - AsDotStr, GraphBackend, GraphError, Node, VarType, + AsDotStr, GraphBackend, Node, VarType, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; /// The reason a context was killed #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] diff --git a/crates/graph/src/nodes/context/node.rs b/crates/graph/src/nodes/context/node.rs index 6c4bb8d5..b4b8759e 100644 --- a/crates/graph/src/nodes/context/node.rs +++ b/crates/graph/src/nodes/context/node.rs @@ -1,10 +1,10 @@ use crate::{ nodes::{Concrete, Context, ContextVarNode, KilledKind}, range::elem::Elem, - AnalyzerBackend, AsDotStr, GraphBackend, GraphError, Node, + AnalyzerBackend, AsDotStr, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/nodes/context/querying.rs b/crates/graph/src/nodes/context/querying.rs index 16fd28a9..301a58e9 100644 --- a/crates/graph/src/nodes/context/querying.rs +++ b/crates/graph/src/nodes/context/querying.rs @@ -2,10 +2,10 @@ use crate::{ nodes::{ ContextNode, ContractNode, FunctionNode, SourceUnitNode, SourceUnitPartNode, StructNode, }, - AnalyzerBackend, ContextEdge, Edge, GraphBackend, GraphError, + AnalyzerBackend, ContextEdge, Edge, GraphBackend, }; -use shared::Search; +use shared::{GraphError, Search}; use std::collections::{BTreeMap, BTreeSet}; impl ContextNode { diff --git a/crates/graph/src/nodes/context/solving.rs b/crates/graph/src/nodes/context/solving.rs index af834be9..a67ba661 100644 --- a/crates/graph/src/nodes/context/solving.rs +++ b/crates/graph/src/nodes/context/solving.rs @@ -7,11 +7,11 @@ use crate::{ dl::{DLSolver, SolveStatus}, Atomize, SolverAtom, }, - AnalyzerBackend, GraphBackend, GraphError, + AnalyzerBackend, GraphBackend, }; use std::borrow::Cow; -use shared::RangeArena; +use shared::{GraphError, RangeArena}; use std::collections::BTreeMap; diff --git a/crates/graph/src/nodes/context/typing.rs b/crates/graph/src/nodes/context/typing.rs index e8a56bda..9f94b3b8 100644 --- a/crates/graph/src/nodes/context/typing.rs +++ b/crates/graph/src/nodes/context/typing.rs @@ -1,7 +1,8 @@ use crate::{ nodes::{ContextNode, FunctionNode}, - AnalyzerBackend, GraphBackend, GraphError, + AnalyzerBackend, GraphBackend, }; +use shared::GraphError; impl ContextNode { /// Checks if its an anonymous function call (i.e. loop) diff --git a/crates/graph/src/nodes/context/underlying.rs b/crates/graph/src/nodes/context/underlying.rs index 5008c0b6..00091d55 100644 --- a/crates/graph/src/nodes/context/underlying.rs +++ b/crates/graph/src/nodes/context/underlying.rs @@ -4,9 +4,11 @@ use crate::{ ModifierState, }, solvers::dl::DLSolver, - AnalyzerBackend, GraphError, + AnalyzerBackend, }; +use shared::GraphError; + use solang_parser::pt::Loc; use std::collections::BTreeSet; diff --git a/crates/graph/src/nodes/context/var/node.rs b/crates/graph/src/nodes/context/var/node.rs index 8d1df01f..16893625 100644 --- a/crates/graph/src/nodes/context/var/node.rs +++ b/crates/graph/src/nodes/context/var/node.rs @@ -1,10 +1,10 @@ use crate::{ nodes::{Concrete, ContextNode, ContextVar, TmpConstruction, VarNode}, range::{elem::*, range_string::ToRangeString, Range}, - AsDotStr, ContextEdge, Edge, GraphBackend, GraphError, Node, + AsDotStr, ContextEdge, Edge, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena, Search, StorageLocation}; +use shared::{GraphError, NodeIdx, RangeArena, Search, StorageLocation}; use petgraph::{visit::EdgeRef, Direction}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/nodes/context/var/ranging.rs b/crates/graph/src/nodes/context/var/ranging.rs index 8f0fbef1..a4690704 100644 --- a/crates/graph/src/nodes/context/var/ranging.rs +++ b/crates/graph/src/nodes/context/var/ranging.rs @@ -2,10 +2,10 @@ use crate::range::elem::*; use crate::{ nodes::{Concrete, ContextVarNode}, range::{range_string::ToRangeString, Range, RangeEval}, - AnalyzerBackend, GraphBackend, GraphError, SolcRange, VarType, + AnalyzerBackend, GraphBackend, SolcRange, VarType, }; -use shared::RangeArena; +use shared::{GraphError, RangeArena}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/nodes/context/var/typing.rs b/crates/graph/src/nodes/context/var/typing.rs index 4ca75ccf..132054df 100644 --- a/crates/graph/src/nodes/context/var/typing.rs +++ b/crates/graph/src/nodes/context/var/typing.rs @@ -5,10 +5,10 @@ use crate::{ elem::{RangeElem, RangeExpr, RangeOp}, RangeEval, }, - AnalyzerBackend, ContextEdge, Edge, GraphBackend, GraphError, Node, VarType, + AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, VarType, }; -use shared::{RangeArena, Search, StorageLocation}; +use shared::{GraphError, RangeArena, Search, StorageLocation}; use ethers_core::types::{I256, U256}; use petgraph::{visit::EdgeRef, Direction}; diff --git a/crates/graph/src/nodes/context/var/underlying.rs b/crates/graph/src/nodes/context/var/underlying.rs index ff31d6fb..0b1993c1 100644 --- a/crates/graph/src/nodes/context/var/underlying.rs +++ b/crates/graph/src/nodes/context/var/underlying.rs @@ -4,11 +4,11 @@ use crate::{ EnumNode, Field, FunctionNode, FunctionParam, FunctionReturn, StructNode, TyNode, }, range::Range, - AnalyzerBackend, GraphBackend, GraphError, Node, SolcRange, TypeNode, VarType, + AnalyzerBackend, GraphBackend, Node, SolcRange, TypeNode, VarType, }; use crate::range::elem::*; -use shared::{NodeIdx, StorageLocation}; +use shared::{GraphError, NodeIdx, StorageLocation}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/nodes/context/var/versioning.rs b/crates/graph/src/nodes/context/var/versioning.rs index 594dfa90..ad2cfdcd 100644 --- a/crates/graph/src/nodes/context/var/versioning.rs +++ b/crates/graph/src/nodes/context/var/versioning.rs @@ -1,9 +1,9 @@ use crate::{ nodes::{ContextNode, ContextVarNode}, - ContextEdge, Edge, GraphBackend, GraphError, + ContextEdge, Edge, GraphBackend, }; -use shared::NodeIdx; +use shared::{GraphError, NodeIdx}; use petgraph::{visit::EdgeRef, Direction}; diff --git a/crates/graph/src/nodes/context/variables.rs b/crates/graph/src/nodes/context/variables.rs index 20ccb24e..5ba2e83c 100644 --- a/crates/graph/src/nodes/context/variables.rs +++ b/crates/graph/src/nodes/context/variables.rs @@ -1,7 +1,8 @@ use crate::{ nodes::{ContextNode, ContextVarNode, ExprRet}, - AnalyzerBackend, ContextEdge, Edge, GraphBackend, GraphError, Node, + AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, }; +use shared::GraphError; use solang_parser::pt::Loc; diff --git a/crates/graph/src/nodes/context/versioning.rs b/crates/graph/src/nodes/context/versioning.rs index 3629ca91..d4e9e0f4 100644 --- a/crates/graph/src/nodes/context/versioning.rs +++ b/crates/graph/src/nodes/context/versioning.rs @@ -3,10 +3,11 @@ use crate::ContextEdge; use crate::Edge; use crate::{ nodes::{CallFork, ContextNode, FunctionNode, KilledKind}, - AnalyzerBackend, GraphBackend, GraphError, Node, + AnalyzerBackend, GraphBackend, Node, }; use petgraph::visit::EdgeRef; use petgraph::Direction; +use shared::GraphError; use solang_parser::pt::Loc; diff --git a/crates/graph/src/nodes/contract_ty.rs b/crates/graph/src/nodes/contract_ty.rs index fc9ebb78..ee528f60 100644 --- a/crates/graph/src/nodes/contract_ty.rs +++ b/crates/graph/src/nodes/contract_ty.rs @@ -1,9 +1,9 @@ use crate::{ nodes::{Concrete, FunctionNode, SourceUnitNode, SourceUnitPartNode, StructNode, VarNode}, range::elem::Elem, - AnalyzerBackend, AsDotStr, Edge, GraphBackend, GraphError, Node, + AnalyzerBackend, AsDotStr, Edge, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena, Search}; +use shared::{GraphError, NodeIdx, RangeArena, Search}; use petgraph::{visit::EdgeRef, Direction}; use solang_parser::pt::{ContractDefinition, ContractTy, Identifier, Loc}; diff --git a/crates/graph/src/nodes/enum_ty.rs b/crates/graph/src/nodes/enum_ty.rs index e02b0cdb..5594bdd0 100644 --- a/crates/graph/src/nodes/enum_ty.rs +++ b/crates/graph/src/nodes/enum_ty.rs @@ -1,8 +1,6 @@ -use crate::{ - nodes::Concrete, range::elem::Elem, AsDotStr, GraphBackend, GraphError, Node, SolcRange, -}; +use crate::{nodes::Concrete, range::elem::Elem, AsDotStr, GraphBackend, Node, SolcRange}; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use ethers_core::types::U256; use solang_parser::pt::{EnumDefinition, Identifier, Loc}; diff --git a/crates/graph/src/nodes/err_ty.rs b/crates/graph/src/nodes/err_ty.rs index 4ecd30e6..1f72f8fa 100644 --- a/crates/graph/src/nodes/err_ty.rs +++ b/crates/graph/src/nodes/err_ty.rs @@ -1,8 +1,6 @@ -use crate::{ - nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, GraphBackend, GraphError, Node, -}; +use crate::{nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, GraphBackend, Node}; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use solang_parser::pt::{ErrorDefinition, ErrorParameter, Expression, Identifier, Loc}; #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] diff --git a/crates/graph/src/nodes/func_ty.rs b/crates/graph/src/nodes/func_ty.rs index cf60328b..4b0676ea 100644 --- a/crates/graph/src/nodes/func_ty.rs +++ b/crates/graph/src/nodes/func_ty.rs @@ -2,11 +2,10 @@ use crate::{ nodes::Concrete, nodes::{ContextNode, ContractNode, SourceUnitNode, SourceUnitPartNode}, range::elem::Elem, - AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, GraphError, Node, SolcRange, - VarType, + AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, Node, SolcRange, VarType, }; -use shared::{NodeIdx, RangeArena, Search, StorageLocation}; +use shared::{GraphError, NodeIdx, RangeArena, Search, StorageLocation}; use petgraph::{visit::EdgeRef, Direction}; use solang_parser::{ diff --git a/crates/graph/src/nodes/msg.rs b/crates/graph/src/nodes/msg.rs index c7f71544..a142e54c 100644 --- a/crates/graph/src/nodes/msg.rs +++ b/crates/graph/src/nodes/msg.rs @@ -1,10 +1,10 @@ use crate::{ nodes::{Builtin, Concrete, ContextNode, ContextVar}, range::elem::Elem, - AnalyzerBackend, AsDotStr, GraphBackend, GraphError, Node, + AnalyzerBackend, AsDotStr, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use ethers_core::types::{Address, U256}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/nodes/source_unit.rs b/crates/graph/src/nodes/source_unit.rs index dce79147..cf3a578c 100644 --- a/crates/graph/src/nodes/source_unit.rs +++ b/crates/graph/src/nodes/source_unit.rs @@ -1,10 +1,10 @@ use crate::{ nodes::{Concrete, ContractNode, FunctionNode, SourceUnitPartNode, StructNode, VarNode}, range::elem::Elem, - AsDotStr, GraphBackend, GraphError, Node, + AsDotStr, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; #[derive(Default, Clone, Debug, PartialOrd, PartialEq, Ord, Eq)] pub struct SourceUnit { diff --git a/crates/graph/src/nodes/source_unit_part.rs b/crates/graph/src/nodes/source_unit_part.rs index 34c2e183..b4042c74 100644 --- a/crates/graph/src/nodes/source_unit_part.rs +++ b/crates/graph/src/nodes/source_unit_part.rs @@ -1,10 +1,10 @@ use crate::{ nodes::{Concrete, ContractNode, FunctionNode, StructNode, VarNode}, range::elem::Elem, - AsDotStr, GraphBackend, GraphError, Node, + AsDotStr, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; #[derive(Default, Clone, Debug, PartialOrd, PartialEq, Ord, Eq)] pub struct SourceUnitPart { diff --git a/crates/graph/src/nodes/struct_ty.rs b/crates/graph/src/nodes/struct_ty.rs index 18ba87e9..f3c39066 100644 --- a/crates/graph/src/nodes/struct_ty.rs +++ b/crates/graph/src/nodes/struct_ty.rs @@ -1,9 +1,9 @@ use crate::{ - nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, Edge, GraphBackend, GraphError, - Node, VarType, + nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, Edge, GraphBackend, Node, + VarType, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use petgraph::{visit::EdgeRef, Direction}; use solang_parser::pt::{Expression, Identifier, Loc, StructDefinition, VariableDeclaration}; diff --git a/crates/graph/src/nodes/ty_ty.rs b/crates/graph/src/nodes/ty_ty.rs index b3d4e42d..cdd0097f 100644 --- a/crates/graph/src/nodes/ty_ty.rs +++ b/crates/graph/src/nodes/ty_ty.rs @@ -1,9 +1,8 @@ use crate::{ - nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, GraphBackend, GraphError, Node, - VarType, + nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, GraphBackend, Node, VarType, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Identifier, Loc, TypeDefinition}; diff --git a/crates/graph/src/nodes/var_ty.rs b/crates/graph/src/nodes/var_ty.rs index 802315cc..13893402 100644 --- a/crates/graph/src/nodes/var_ty.rs +++ b/crates/graph/src/nodes/var_ty.rs @@ -3,10 +3,10 @@ use crate::{ Concrete, ContextVar, ContextVarNode, ContractNode, SourceUnitNode, SourceUnitPartNode, }, range::elem::Elem, - AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, GraphError, Node, VarType, + AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, Node, VarType, }; -use shared::{NodeIdx, RangeArena, Search}; +use shared::{GraphError, NodeIdx, RangeArena, Search}; use petgraph::{visit::EdgeRef, Direction}; use solang_parser::pt::{ diff --git a/crates/graph/src/range/elem/concrete.rs b/crates/graph/src/range/elem/concrete.rs index 8ee3f789..0ccf48ae 100644 --- a/crates/graph/src/range/elem/concrete.rs +++ b/crates/graph/src/range/elem/concrete.rs @@ -1,10 +1,10 @@ use crate::{ nodes::{Concrete, ContextVarNode}, range::elem::{Elem, RangeArenaLike, RangeElem}, - GraphBackend, GraphError, + GraphBackend, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use std::hash::{Hash, Hasher}; diff --git a/crates/graph/src/range/elem/elem_enum/arena.rs b/crates/graph/src/range/elem/elem_enum/arena.rs index 6472b2b7..d95967e5 100644 --- a/crates/graph/src/range/elem/elem_enum/arena.rs +++ b/crates/graph/src/range/elem/elem_enum/arena.rs @@ -3,7 +3,7 @@ use crate::{ nodes::Concrete, range::elem::{Elem, RangeElem}, }; -use shared::RangeArena; +use shared::{GraphError, RangeArena}; pub trait RangeArenaLike { fn debug_str(&self, analyzer: &impl GraphBackend) -> String; @@ -15,7 +15,7 @@ pub trait RangeArenaLike { fn to_graph( &mut self, analyzer: &impl GraphBackend, - ) -> Result, usize, petgraph::Directed, usize>, crate::GraphError>; + ) -> Result, usize, petgraph::Directed, usize>, GraphError>; } impl RangeArenaLike> for RangeArena> { @@ -56,8 +56,7 @@ impl RangeArenaLike> for RangeArena> { fn to_graph( &mut self, analyzer: &impl GraphBackend, - ) -> Result, usize, petgraph::Directed, usize>, crate::GraphError> - { + ) -> Result, usize, petgraph::Directed, usize>, GraphError> { let mut graph = petgraph::Graph::default(); let mut added = vec![]; let mut ids = vec![]; @@ -65,7 +64,7 @@ impl RangeArenaLike> for RangeArena> { fn get_children( elem: &Elem, analyzer: &impl GraphBackend, - ) -> Result>, crate::GraphError> { + ) -> Result>, GraphError> { match elem { Elem::Reference(r) => { let cvar = crate::nodes::ContextVarNode::from(r.idx); @@ -93,7 +92,7 @@ impl RangeArenaLike> for RangeArena> { ids: &mut Vec, elem: &Elem, analyzer: &impl GraphBackend, - ) -> Result<(), crate::GraphError> { + ) -> Result<(), GraphError> { assert!(added.len() == ids.len()); if !added.contains(elem) { diff --git a/crates/graph/src/range/elem/elem_enum/impls.rs b/crates/graph/src/range/elem/elem_enum/impls.rs index 2b56f4d6..65351d07 100644 --- a/crates/graph/src/range/elem/elem_enum/impls.rs +++ b/crates/graph/src/range/elem/elem_enum/impls.rs @@ -2,9 +2,9 @@ use crate::elem::{MinMaxed, RangeArenaLike}; use crate::{ nodes::Concrete, range::elem::{Elem, RangeConcrete, RangeDyn, RangeElem, RangeExpr, RangeOp, Reference}, - GraphBackend, GraphError, + GraphBackend, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use ethers_core::types::I256; diff --git a/crates/graph/src/range/elem/elem_enum/range_elem.rs b/crates/graph/src/range/elem/elem_enum/range_elem.rs index dc9898f3..c00d5e40 100644 --- a/crates/graph/src/range/elem/elem_enum/range_elem.rs +++ b/crates/graph/src/range/elem/elem_enum/range_elem.rs @@ -2,10 +2,10 @@ use crate::elem::{MinMaxed, RangeArenaLike}; use crate::{ nodes::{Concrete, ContextVarNode}, range::elem::{collapse, Elem, MaybeCollapsed, RangeElem}, - GraphBackend, GraphError, + GraphBackend, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; impl RangeElem for Elem { type GraphError = GraphError; diff --git a/crates/graph/src/range/elem/elem_trait.rs b/crates/graph/src/range/elem/elem_trait.rs index c4bfcd28..604a49df 100644 --- a/crates/graph/src/range/elem/elem_trait.rs +++ b/crates/graph/src/range/elem/elem_trait.rs @@ -1,6 +1,6 @@ -use crate::{nodes::ContextVarNode, range::elem::Elem, GraphBackend, GraphError}; +use crate::{nodes::ContextVarNode, range::elem::Elem, GraphBackend}; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use std::hash::Hash; pub trait RangeElem: Hash { diff --git a/crates/graph/src/range/elem/expr/mod.rs b/crates/graph/src/range/elem/expr/mod.rs index f69aaeb3..5fd3cb74 100644 --- a/crates/graph/src/range/elem/expr/mod.rs +++ b/crates/graph/src/range/elem/expr/mod.rs @@ -9,13 +9,13 @@ use crate::{ elem::{Elem, MinMaxed, RangeArenaLike, RangeConcrete, RangeElem, RangeOp}, exec_traits::*, }, - GraphBackend, GraphError, + GraphBackend, }; use std::hash::Hash; use std::hash::Hasher; use ethers_core::types::U256; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; /// A range expression composed of other range [`Elem`] #[derive(Clone, Debug, Ord, PartialOrd)] diff --git a/crates/graph/src/range/elem/map_or_array.rs b/crates/graph/src/range/elem/map_or_array.rs index 8e9d7048..2ca07abd 100644 --- a/crates/graph/src/range/elem/map_or_array.rs +++ b/crates/graph/src/range/elem/map_or_array.rs @@ -4,10 +4,10 @@ use crate::{ elem::{Elem, MinMaxed, RangeConcrete, RangeElem}, exec_traits::{RangeCast, RangeMemLen}, }, - GraphBackend, GraphError, + GraphBackend, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use ethers_core::types::{H256, U256}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/range/elem/reference.rs b/crates/graph/src/range/elem/reference.rs index 84af8ef5..0980b431 100644 --- a/crates/graph/src/range/elem/reference.rs +++ b/crates/graph/src/range/elem/reference.rs @@ -4,12 +4,12 @@ use crate::{ elem::{Elem, MinMaxed, RangeArenaLike, RangeConcrete, RangeElem}, Range, }, - GraphBackend, GraphError, TypeNode, VarType, + GraphBackend, TypeNode, VarType, }; use std::hash::Hash; use std::hash::Hasher; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/range/exec/exec_op.rs b/crates/graph/src/range/exec/exec_op.rs index 8f774fbe..876e8e14 100644 --- a/crates/graph/src/range/exec/exec_op.rs +++ b/crates/graph/src/range/exec/exec_op.rs @@ -1,9 +1,9 @@ use crate::{ nodes::Concrete, range::{elem::*, exec::*, exec_traits::*}, - GraphBackend, GraphError, + GraphBackend, }; -use shared::RangeArena; +use shared::{GraphError, RangeArena}; impl ExecOp for RangeExpr { type GraphError = GraphError; @@ -17,16 +17,14 @@ impl ExecOp for RangeExpr { ) -> Result, Self::GraphError> { let idx = self.arena_idx(arena); if let Some(idx) = idx { - if let Some(t) = arena.ranges.get(idx) { - if let Elem::Expr(expr) = t { - tracing::trace!("hitting cache"); - if maximize { - if let Some(MinMaxed::Maximized(max)) = &expr.maximized { - return Ok(*max.clone()); - } - } else if let Some(MinMaxed::Minimized(min)) = &expr.minimized { - return Ok(*min.clone()); + if let Some(Elem::Expr(expr)) = arena.ranges.get(idx) { + tracing::trace!("hitting cache"); + if maximize { + if let Some(MinMaxed::Maximized(max)) = &expr.maximized { + return Ok(*max.clone()); } + } else if let Some(MinMaxed::Minimized(min)) = &expr.minimized { + return Ok(*min.clone()); } } } diff --git a/crates/graph/src/range/solc_range.rs b/crates/graph/src/range/solc_range.rs index eddff194..6fb513cb 100644 --- a/crates/graph/src/range/solc_range.rs +++ b/crates/graph/src/range/solc_range.rs @@ -1,10 +1,10 @@ use crate::{ nodes::{Builtin, Concrete, ContextVarNode}, range::{elem::*, range_string::*, Range, RangeEval}, - AsDotStr, GraphBackend, GraphError, + AsDotStr, GraphBackend, }; -use shared::{NodeIdx, RangeArena}; +use shared::{GraphError, NodeIdx, RangeArena}; use ethers_core::types::{Address, H256, I256, U256}; use solang_parser::pt::Loc; diff --git a/crates/graph/src/solvers/brute.rs b/crates/graph/src/solvers/brute.rs index a810c170..1839b7e2 100644 --- a/crates/graph/src/solvers/brute.rs +++ b/crates/graph/src/solvers/brute.rs @@ -5,10 +5,10 @@ use crate::{ dl::{DLSolver, SolveStatus}, Atomize, SolverAtom, }, - AnalyzerBackend, GraphBackend, GraphError, Range, RangeEval, SolcRange, + AnalyzerBackend, GraphBackend, Range, RangeEval, SolcRange, }; -use shared::RangeArena; +use shared::{GraphError, RangeArena}; use ethers_core::types::U256; use std::collections::BTreeMap; diff --git a/crates/graph/src/solvers/dl.rs b/crates/graph/src/solvers/dl.rs index 109887fa..443d0a3d 100644 --- a/crates/graph/src/solvers/dl.rs +++ b/crates/graph/src/solvers/dl.rs @@ -3,10 +3,10 @@ use crate::{ range::elem::*, range::range_string::ToRangeString, solvers::{AtomOrPart, Atomize, OpType, SolverAtom}, - GraphBackend, GraphError, + GraphBackend, }; -use shared::RangeArena; +use shared::{GraphError, RangeArena}; use ethers_core::types::{I256, U256}; use itertools::Itertools; @@ -570,7 +570,7 @@ impl DLSolver { added_atoms.push((*dyn_elem).clone()); self.graph_map.insert((*dyn_elem).clone(), idx); if let Some(dep) = dep { - if self.var_to_atom_idx.get(&dep).is_none() { + if !self.var_to_atom_idx.contains_key(&dep) { added_deps.push(dep); self.var_to_atom_idx.insert(dep, idx); } diff --git a/crates/graph/src/var_type.rs b/crates/graph/src/var_type.rs index 23112944..3951cd77 100644 --- a/crates/graph/src/var_type.rs +++ b/crates/graph/src/var_type.rs @@ -7,9 +7,9 @@ use crate::{ elem::{Elem, RangeElem}, Range, SolcRange, }, - AnalyzerBackend, AsDotStr, GraphBackend, GraphError, Node, + AnalyzerBackend, AsDotStr, GraphBackend, Node, }; -use shared::RangeArena; +use shared::{GraphError, RangeArena}; use shared::NodeIdx; diff --git a/crates/pyrometer/src/analyzer.rs b/crates/pyrometer/src/analyzer.rs index b5c04553..4825fbf2 100644 --- a/crates/pyrometer/src/analyzer.rs +++ b/crates/pyrometer/src/analyzer.rs @@ -5,8 +5,8 @@ use graph::{nodes::*, ContextEdge, Edge, Node, VarType}; use reqwest::Client; use serde::{Deserialize, Serialize}; use shared::{AnalyzerLike, GraphLike, JoinStats, NodeIdx, Search}; -use shared::{RangeArena, USE_DEBUG_SITE}; -use solc_expressions::{ExprErr, FnCallBuilder, IntoExprErr, StatementParser}; +use shared::{ExprErr, IntoExprErr, RangeArena, USE_DEBUG_SITE}; +use solc_expressions::{FnCallBuilder, StatementParser}; use tokio::runtime::Runtime; use tracing::{error, trace, warn}; @@ -1413,7 +1413,7 @@ impl Analyzer { }); } - async fn post_source_to_site_async(file_no: usize, path: &PathBuf, source: &str) + async fn post_source_to_site_async(file_no: usize, path: &Path, source: &str) where Self: std::marker::Sized, Self: AnalyzerLike, diff --git a/crates/pyrometer/src/analyzer_backend.rs b/crates/pyrometer/src/analyzer_backend.rs index b1c5b627..5f05e91f 100644 --- a/crates/pyrometer/src/analyzer_backend.rs +++ b/crates/pyrometer/src/analyzer_backend.rs @@ -7,8 +7,7 @@ use graph::{ }, AnalyzerBackend, Edge, Node, VarType, }; -use shared::{AnalyzerLike, GraphLike, JoinStats, NodeIdx, RangeArena}; -use solc_expressions::{ExprErr, IntoExprErr}; +use shared::{AnalyzerLike, ExprErr, GraphLike, IntoExprErr, JoinStats, NodeIdx, RangeArena}; use ahash::AHashMap; use ethers_core::types::U256; diff --git a/crates/pyrometer/src/graph_backend.rs b/crates/pyrometer/src/graph_backend.rs index b99f98ae..8fd62682 100644 --- a/crates/pyrometer/src/graph_backend.rs +++ b/crates/pyrometer/src/graph_backend.rs @@ -1265,13 +1265,13 @@ pub fn mermaid_node( match g.node(current_node) { Node::ContextVar(..) => { // highlight self - if let Ok(loc) = graph::nodes::ContextVarNode::from(current_node).loc(g) { - if let solang_parser::pt::Loc::File(f, s, e) = loc { - node_str.push_str(&format!( - "\n{indent}class {} loc_{f}_{s}_{e}", - petgraph::graph::GraphIndex::index(¤t_node) - )); - } + if let Ok(solang_parser::pt::Loc::File(f, s, e)) = + graph::nodes::ContextVarNode::from(current_node).loc(g) + { + node_str.push_str(&format!( + "\n{indent}class {} loc_{f}_{s}_{e}", + petgraph::graph::GraphIndex::index(¤t_node) + )); } // color the forks diff --git a/crates/shared/src/error.rs b/crates/shared/src/error.rs new file mode 100644 index 00000000..4abc5833 --- /dev/null +++ b/crates/shared/src/error.rs @@ -0,0 +1,197 @@ +use solang_parser::pt::Loc; + +#[derive(Debug, Clone, Ord, Eq, PartialEq, PartialOrd)] +pub enum GraphError { + /// The analyzer thought the node was suppose to be one type, but it was a different one + NodeConfusion(String), + /// Call depth limit reached + MaxStackDepthReached(String), + /// Fork width limit reached + MaxStackWidthReached(String), + /// Tried to set the subcontext of a context that already had a subcontext + ChildRedefinition(String), + /// Tried to update a variable that is in an old context + VariableUpdateInOldContext(String), + /// Variable is detached from all contexts + DetachedVariable(String), + /// Expected a single element, found multiple + ExpectedSingle(String), + /// Expected a vector with a certain number of elements, but it was a different number of elements + StackLengthMismatch(String), + /// A variable had a cyclic reference to another variable and we were unable to break the cycle + UnbreakableRecursion(String), + /// The analyzer thought the node was suppose to be one type, but it was a different one + UnknownVariable(String), +} + +impl std::fmt::Display for GraphError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{self:?}") + } +} + +impl std::error::Error for GraphError {} + +/// Convert some error into an expression error by attaching a code source location +pub trait IntoExprErr { + /// Convert into a ExprErr + fn into_expr_err(self, loc: Loc) -> Result; +} + +impl IntoExprErr for Result { + fn into_expr_err(self, loc: Loc) -> Result { + match self { + Ok(v) => Ok(v), + Err(e) => Err(ExprErr::from_graph_err(loc, e)), + } + } +} + +#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)] +/// An error that arose from the analyzer when interpreting expressions and statements +pub enum ExprErr { + ParseError(Loc, String), + NoLhs(Loc, String), + NoRhs(Loc, String), + NoReturn(Loc, String), + ArrayTy(Loc, String), + ArrayIndex(Loc, String), + UnhandledCombo(Loc, String), + UnhandledExprRet(Loc, String), + MultiNot(Loc, String), + VarBadType(Loc, String), + Todo(Loc, String), + BadRange(Loc, String), + ContractFunctionNotFound(Loc, String), + MemberAccessNotFound(Loc, String), + FunctionNotFound(Loc, String), + + FunctionCallBlockTodo(Loc, String), + + NonStoragePush(Loc, String), + IntrinsicNamedArgs(Loc, String), + InvalidFunctionInput(Loc, String), + TakeFromFork(Loc, String), + GraphError(Loc, GraphError), + Unresolved(Loc, String), +} + +impl ExprErr { + /// Convert from a graph error + pub fn from_graph_err(loc: Loc, graph_err: GraphError) -> Self { + Self::GraphError(loc, graph_err) + } +} + +impl ExprErr { + /// Get the code source location of the error + pub fn loc(&self) -> Loc { + use ExprErr::*; + match self { + ParseError(loc, ..) => *loc, + NoLhs(loc, ..) => *loc, + NoRhs(loc, ..) => *loc, + NoReturn(loc, ..) => *loc, + ArrayTy(loc, ..) => *loc, + ArrayIndex(loc, ..) => *loc, + UnhandledCombo(loc, ..) => *loc, + UnhandledExprRet(loc, ..) => *loc, + MultiNot(loc, ..) => *loc, + VarBadType(loc, ..) => *loc, + Todo(loc, ..) => *loc, + FunctionCallBlockTodo(loc, ..) => *loc, + BadRange(loc, ..) => *loc, + ContractFunctionNotFound(loc, ..) => *loc, + MemberAccessNotFound(loc, ..) => *loc, + FunctionNotFound(loc, ..) => *loc, + NonStoragePush(loc, ..) => *loc, + IntrinsicNamedArgs(loc, ..) => *loc, + InvalidFunctionInput(loc, ..) => *loc, + TakeFromFork(loc, ..) => *loc, + GraphError(loc, ..) => *loc, + Unresolved(loc, ..) => *loc, + } + } + + /// Get the error message + pub fn msg(&self) -> &str { + match self { + ExprErr::ParseError(_, msg, ..) => msg, + ExprErr::NoLhs(_, msg, ..) => msg, + ExprErr::NoRhs(_, msg, ..) => msg, + ExprErr::NoReturn(_, msg, ..) => msg, + ExprErr::ArrayTy(_, msg, ..) => msg, + ExprErr::ArrayIndex(_, msg, ..) => msg, + ExprErr::UnhandledCombo(_, msg, ..) => msg, + ExprErr::UnhandledExprRet(_, msg, ..) => msg, + ExprErr::MultiNot(_, msg, ..) => msg, + ExprErr::VarBadType(_, msg, ..) => msg, + ExprErr::Todo(_, msg, ..) => msg, + ExprErr::FunctionCallBlockTodo(_, msg, ..) => msg, + ExprErr::BadRange(_, msg, ..) => msg, + ExprErr::ContractFunctionNotFound(_, msg, ..) => msg, + ExprErr::MemberAccessNotFound(_, msg, ..) => msg, + ExprErr::FunctionNotFound(_, msg, ..) => msg, + ExprErr::NonStoragePush(_, msg, ..) => msg, + ExprErr::IntrinsicNamedArgs(_, msg, ..) => msg, + ExprErr::InvalidFunctionInput(_, msg, ..) => msg, + ExprErr::TakeFromFork(_, msg, ..) => msg, + ExprErr::Unresolved(_, msg, ..) => msg, + ExprErr::GraphError(_, GraphError::NodeConfusion(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::MaxStackDepthReached(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::MaxStackWidthReached(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::ChildRedefinition(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::DetachedVariable(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::VariableUpdateInOldContext(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::ExpectedSingle(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::StackLengthMismatch(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::UnbreakableRecursion(msg), ..) => msg, + ExprErr::GraphError(_, GraphError::UnknownVariable(msg), ..) => msg, + } + } + + /// Get the top-level report message + pub fn report_msg(&self) -> &str { + match self { + ExprErr::ParseError(..) => "Could not parse this", + ExprErr::NoLhs(..) => "No left-hand side passed to expression", + ExprErr::NoRhs(..) => "No right-hand side passed to expression", + ExprErr::NoReturn(..) => "No returned element from expression", + ExprErr::ArrayTy(..) => "Unexpected type as array element", + ExprErr::ArrayIndex(..) => "Unexpected type as array index", + ExprErr::UnhandledCombo(..) => "Unhandled ExprRet variant combination", + ExprErr::UnhandledExprRet(..) => "Unhandled ExprRet variant", + ExprErr::MultiNot(..) => "Expected a single ExprRet in Not statement, got ExprRet::Multi", + ExprErr::VarBadType(..) => "This type cannot be made into a variable", + ExprErr::Todo(..) => "TODO", + ExprErr::FunctionCallBlockTodo(..) => "TODO", + ExprErr::Unresolved(..) => "Unresolved type: This is likely a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::BadRange(..) => "Expected a range for a variable but there was none", + ExprErr::ContractFunctionNotFound(..) => "Contract function could not be Found", + ExprErr::MemberAccessNotFound(..) => "Member element could not be found", + ExprErr::FunctionNotFound(..) => "Function could not be found", + ExprErr::NonStoragePush(..) => "Pushing on non-storage based array is unsupported", + ExprErr::IntrinsicNamedArgs(..) => "Arguments in calls to intrinsic functions cannot be named", + ExprErr::InvalidFunctionInput(..) => "Arguments to this function call do not match required types", + ExprErr::TakeFromFork(..) => "IR Error: Tried to take from an child context that ended up forking", + ExprErr::GraphError(_, GraphError::NodeConfusion(_), ..) => "Graph IR Error: Node type confusion. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::GraphError(_, GraphError::MaxStackDepthReached(_), ..) => "Max call depth reached - either recursion or loop", + ExprErr::GraphError(_, GraphError::MaxStackWidthReached(_), ..) => "TODO: Max fork width reached - Need to widen variables and remove contexts", + ExprErr::GraphError(_, GraphError::ChildRedefinition(_), ..) => "Graph IR Error: Child redefintion. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::GraphError(_, GraphError::DetachedVariable(_), ..) => "Graph IR Error: Detached Variable. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::GraphError(_, GraphError::VariableUpdateInOldContext(_), ..) => "Graph IR Error: Variable update in an old context. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::GraphError(_, GraphError::ExpectedSingle(_), ..) => "Graph IR Error: Expecting single expression return, got multiple. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::GraphError(_, GraphError::StackLengthMismatch(_), ..) => "Graph IR Error: Expected a particular number of elements on the context stack but found a different amount. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::GraphError(_, GraphError::UnbreakableRecursion(_), ..) => "Graph IR Error: Unbreakable recursion in variable range. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", + ExprErr::GraphError(_, GraphError::UnknownVariable(_), ..) => "Graph IR Error: Unknown variable. This is potentially a bug, but more likely a variable name is mistyped.", + } + } +} + +impl std::fmt::Display for ExprErr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}: {}", self.report_msg(), self.msg()) + } +} + +impl std::error::Error for ExprErr {} diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index eb85d13c..7355e36f 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -1,9 +1,11 @@ mod analyzer_like; +mod error; pub mod gas; mod graph_like; mod search; pub use analyzer_like::*; +pub use error::*; pub use graph_like::*; pub use search::*; diff --git a/crates/solc-expressions/src/array.rs b/crates/solc-expressions/src/array.rs index de87e1ef..f4ef4b73 100644 --- a/crates/solc-expressions/src/array.rs +++ b/crates/solc-expressions/src/array.rs @@ -1,14 +1,11 @@ -use crate::{ - require::Require, variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, - ListAccess, -}; +use crate::{require::Require, variable::Variable, ContextBuilder, ExpressionParser, ListAccess}; use graph::{ elem::{Elem, RangeDyn, RangeOp}, nodes::{Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet, TmpConstruction}, AnalyzerBackend, ContextEdge, Edge, Node, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::{ helpers::CodeLocation, diff --git a/crates/solc-expressions/src/assign.rs b/crates/solc-expressions/src/assign.rs index 38c89a6e..edda6a55 100644 --- a/crates/solc-expressions/src/assign.rs +++ b/crates/solc-expressions/src/assign.rs @@ -1,15 +1,12 @@ -use crate::{ - array::Array, variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, - ListAccess, -}; +use crate::{array::Array, variable::Variable, ContextBuilder, ExpressionParser, ListAccess}; use graph::{ elem::{Elem, RangeElem}, nodes::{Concrete, ContextNode, ContextVarNode, ExprRet}, - AnalyzerBackend, ContextEdge, Edge, GraphError, Node, + AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::RangeArena; +use shared::{ExprErr, GraphError, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc}; impl Assign for T where T: AnalyzerBackend + Sized {} diff --git a/crates/solc-expressions/src/bin_op.rs b/crates/solc-expressions/src/bin_op.rs index cb52ed98..bc6943d2 100644 --- a/crates/solc-expressions/src/bin_op.rs +++ b/crates/solc-expressions/src/bin_op.rs @@ -1,6 +1,4 @@ -use crate::{ - require::Require, variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, -}; +use crate::{require::Require, variable::Variable, ContextBuilder, ExpressionParser}; use graph::{ elem::*, @@ -9,7 +7,7 @@ use graph::{ }, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::U256; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/cmp.rs b/crates/solc-expressions/src/cmp.rs index 8cb9fba3..6195f5e5 100644 --- a/crates/solc-expressions/src/cmp.rs +++ b/crates/solc-expressions/src/cmp.rs @@ -1,4 +1,4 @@ -use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr}; +use crate::{ContextBuilder, ExpressionParser}; use graph::{ elem::*, @@ -6,9 +6,9 @@ use graph::{ BuiltInNode, Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet, TmpConstruction, }, - AnalyzerBackend, GraphError, Node, Range, SolcRange, VarType, + AnalyzerBackend, Node, Range, SolcRange, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, GraphError, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc}; use std::cmp::Ordering; diff --git a/crates/solc-expressions/src/cond_op.rs b/crates/solc-expressions/src/cond_op.rs index c2d0f178..b1be1688 100644 --- a/crates/solc-expressions/src/cond_op.rs +++ b/crates/solc-expressions/src/cond_op.rs @@ -1,13 +1,11 @@ -use crate::{ - require::Require, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, StatementParser, -}; +use crate::{require::Require, ContextBuilder, ExpressionParser, StatementParser}; use graph::{ elem::Elem, nodes::{Concrete, Context, ContextNode}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::CodeLocation; use solang_parser::pt::{Expression, Loc, Statement}; diff --git a/crates/solc-expressions/src/context_builder/expr.rs b/crates/solc-expressions/src/context_builder/expr.rs index 4c47b50c..476e980f 100644 --- a/crates/solc-expressions/src/context_builder/expr.rs +++ b/crates/solc-expressions/src/context_builder/expr.rs @@ -1,7 +1,7 @@ use crate::func_call::intrinsic_call::IntrinsicFuncCaller; use crate::{ context_builder::ContextBuilder, func_call::func_caller::FuncCaller, variable::Variable, - ExprErr, ExprTyParser, IntoExprErr, + ExprTyParser, }; use graph::{ @@ -9,7 +9,7 @@ use graph::{ nodes::{Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::I256; use solang_parser::{ diff --git a/crates/solc-expressions/src/context_builder/fn_calls.rs b/crates/solc-expressions/src/context_builder/fn_calls.rs index 34dcc8e7..d07f2b0a 100644 --- a/crates/solc-expressions/src/context_builder/fn_calls.rs +++ b/crates/solc-expressions/src/context_builder/fn_calls.rs @@ -1,4 +1,4 @@ -use crate::{ExprErr, ExpressionParser, StatementParser}; +use crate::{ExpressionParser, StatementParser}; use solang_parser::helpers::CodeLocation; use graph::{ @@ -6,6 +6,8 @@ use graph::{ AnalyzerBackend, Node, }; +use shared::ExprErr; + use solang_parser::pt::{Expression, Statement}; impl FnCallBuilder for T where diff --git a/crates/solc-expressions/src/context_builder/mod.rs b/crates/solc-expressions/src/context_builder/mod.rs index d79b71d2..e57f28fa 100644 --- a/crates/solc-expressions/src/context_builder/mod.rs +++ b/crates/solc-expressions/src/context_builder/mod.rs @@ -1,12 +1,10 @@ //! Trait and blanket implementation for the core parsing loop -use crate::{ExprErr, IntoExprErr}; - use graph::{ elem::Elem, nodes::{Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet, KilledKind}, - AnalyzerBackend, ContextEdge, Edge, GraphError, Node, + AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::RangeArena; +use shared::{ExprErr, GraphError, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/context_builder/stmt.rs b/crates/solc-expressions/src/context_builder/stmt.rs index d3c52d7d..51f24c90 100644 --- a/crates/solc-expressions/src/context_builder/stmt.rs +++ b/crates/solc-expressions/src/context_builder/stmt.rs @@ -3,7 +3,7 @@ use crate::{ func_call::{func_caller::FuncCaller, modifier::ModifierCaller}, loops::Looper, yul::YulBuilder, - ExprErr, ExpressionParser, IntoExprErr, + ExpressionParser, }; use graph::{ @@ -14,7 +14,7 @@ use graph::{ }, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use petgraph::{visit::EdgeRef, Direction}; use solang_parser::{ diff --git a/crates/solc-expressions/src/env.rs b/crates/solc-expressions/src/env.rs index 414e6f12..54d8591f 100644 --- a/crates/solc-expressions/src/env.rs +++ b/crates/solc-expressions/src/env.rs @@ -1,13 +1,11 @@ -use crate::{ - func_call::helper::CallerHelper, func_call::modifier::ModifierCaller, ExprErr, IntoExprErr, -}; +use crate::{func_call::helper::CallerHelper, func_call::modifier::ModifierCaller}; use graph::{ elem::Elem, nodes::{Builtin, Concrete, ContextNode, ContextVar, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::{RangeArena, StorageLocation}; +use shared::{ExprErr, IntoExprErr, RangeArena, StorageLocation}; use solang_parser::pt::{Expression, Identifier, Loc}; diff --git a/crates/solc-expressions/src/func_call/func_caller.rs b/crates/solc-expressions/src/func_call/func_caller.rs index e30f639d..c7b19e1f 100644 --- a/crates/solc-expressions/src/func_call/func_caller.rs +++ b/crates/solc-expressions/src/func_call/func_caller.rs @@ -3,8 +3,7 @@ use crate::{ func_call::join::FuncJoiner, func_call::modifier::ModifierCaller, helper::CallerHelper, internal_call::InternalFuncCaller, intrinsic_call::IntrinsicFuncCaller, - namespaced_call::NameSpaceFuncCaller, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, - StatementParser, + namespaced_call::NameSpaceFuncCaller, ContextBuilder, ExpressionParser, StatementParser, }; use std::cell::RefCell; use std::rc::Rc; @@ -17,7 +16,7 @@ use graph::{ }, AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Loc, NamedArgument}; diff --git a/crates/solc-expressions/src/func_call/helper.rs b/crates/solc-expressions/src/func_call/helper.rs index 3def7e6d..4e84ed86 100644 --- a/crates/solc-expressions/src/func_call/helper.rs +++ b/crates/solc-expressions/src/func_call/helper.rs @@ -1,8 +1,5 @@ //! Helper traits & blanket implementations that help facilitate performing function calls. -use crate::{ - member_access::ListAccess, variable::Variable, ContextBuilder, ExprErr, ExpressionParser, - IntoExprErr, -}; +use crate::{member_access::ListAccess, variable::Variable, ContextBuilder, ExpressionParser}; use graph::{ elem::Elem, @@ -12,7 +9,7 @@ use graph::{ }, AnalyzerBackend, ContextEdge, Edge, Node, Range, VarType, }; -use shared::{NodeIdx, RangeArena, StorageLocation}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena, StorageLocation}; use solang_parser::pt::{CodeLocation, Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/internal_call.rs b/crates/solc-expressions/src/func_call/internal_call.rs index 89c10602..d969f3fb 100644 --- a/crates/solc-expressions/src/func_call/internal_call.rs +++ b/crates/solc-expressions/src/func_call/internal_call.rs @@ -3,7 +3,7 @@ use crate::func_caller::NamedOrUnnamedArgs; use crate::{ assign::Assign, func_call::func_caller::FuncCaller, helper::CallerHelper, ContextBuilder, - ExprErr, ExpressionParser, IntoExprErr, + ExpressionParser, }; use graph::{ @@ -11,7 +11,7 @@ use graph::{ nodes::{Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Identifier, Loc, NamedArgument}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/abi.rs b/crates/solc-expressions/src/func_call/intrinsic_call/abi.rs index 1651866f..aa543077 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/abi.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/abi.rs @@ -1,12 +1,12 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr}; +use crate::{ContextBuilder, ExpressionParser}; use graph::{ elem::Elem, nodes::{Builtin, Concrete, ContextNode, ContextVar, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/address.rs b/crates/solc-expressions/src/func_call/intrinsic_call/address.rs index 0abe0230..c0c42475 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/address.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/address.rs @@ -1,10 +1,10 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ExprErr, IntoExprErr}; use graph::{ nodes::{Builtin, ContextNode, ContextVar, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; +use shared::{ExprErr, IntoExprErr}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/array.rs b/crates/solc-expressions/src/func_call/intrinsic_call/array.rs index 5a3286f4..3bf86b5c 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/array.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/array.rs @@ -1,14 +1,12 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ - array::Array, bin_op::BinOp, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, ListAccess, -}; +use crate::{array::Array, bin_op::BinOp, ContextBuilder, ExpressionParser, ListAccess}; use graph::{ elem::*, nodes::{Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::U256; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/block.rs b/crates/solc-expressions/src/func_call/intrinsic_call/block.rs index ccf01350..7e09c935 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/block.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/block.rs @@ -1,12 +1,12 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ContextBuilder, ExprErr, IntoExprErr}; +use crate::ContextBuilder; use graph::{ elem::Elem, nodes::{Builtin, Concrete, ContextNode, ContextVar, ExprRet}, AnalyzerBackend, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/constructors.rs b/crates/solc-expressions/src/func_call/intrinsic_call/constructors.rs index 22bcf921..20ae536a 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/constructors.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/constructors.rs @@ -1,15 +1,12 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ - assign::Assign, func_call::helper::CallerHelper, ContextBuilder, ExprErr, ExpressionParser, - IntoExprErr, -}; +use crate::{assign::Assign, func_call::helper::CallerHelper, ContextBuilder, ExpressionParser}; use graph::{ elem::*, nodes::{Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet, StructNode}, AnalyzerBackend, ContextEdge, Edge, Node, Range, VarType, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/dyn_builtin.rs b/crates/solc-expressions/src/func_call/intrinsic_call/dyn_builtin.rs index 410d36aa..0ba6e420 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/dyn_builtin.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/dyn_builtin.rs @@ -1,14 +1,12 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ - variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, ListAccess, -}; +use crate::{variable::Variable, ContextBuilder, ExpressionParser, ListAccess}; use graph::{ elem::{Elem, RangeElem}, nodes::{Builtin, Concrete, ContextNode, ContextVarNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, SolcRange, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs b/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs index ce3d546c..0a5d6b85 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/intrinsic_caller.rs @@ -7,7 +7,7 @@ use crate::{ AbiCaller, AddressCaller, ArrayCaller, BlockCaller, ConstructorCaller, DynBuiltinCaller, MsgCaller, PrecompileCaller, SolidityCaller, TypesCaller, }, - ContextBuilder, ExprErr, IntoExprErr, + ContextBuilder, }; use graph::nodes::ContextVar; use graph::nodes::ContextVarNode; @@ -18,7 +18,7 @@ use graph::{ nodes::{Builtin, Concrete, ContextNode, ExprRet}, AnalyzerBackend, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/msg.rs b/crates/solc-expressions/src/func_call/intrinsic_call/msg.rs index 26b1da9d..ad45f72f 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/msg.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/msg.rs @@ -1,10 +1,10 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ExprErr, IntoExprErr}; use graph::{ nodes::{Builtin, ContextNode, ContextVar, ExprRet}, AnalyzerBackend, Node, }; +use shared::{ExprErr, IntoExprErr}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/precompile.rs b/crates/solc-expressions/src/func_call/intrinsic_call/precompile.rs index 9c6908a0..81021a55 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/precompile.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/precompile.rs @@ -1,7 +1,5 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ - func_call::helper::CallerHelper, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, -}; +use crate::{func_call::helper::CallerHelper, ContextBuilder, ExpressionParser}; use graph::nodes::FunctionNode; use graph::{ @@ -9,7 +7,7 @@ use graph::{ nodes::{Builtin, Concrete, Context, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs b/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs index 0cb1f277..a394767d 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/solidity.rs @@ -1,15 +1,12 @@ use crate::func_caller::NamedOrUnnamedArgs; -use crate::{ - func_call::helper::CallerHelper, require::Require, ContextBuilder, ExprErr, ExpressionParser, - IntoExprErr, -}; +use crate::{func_call::helper::CallerHelper, require::Require, ContextBuilder, ExpressionParser}; use graph::{ elem::Elem, nodes::{Builtin, Concrete, ConcreteNode, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::H256; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/intrinsic_call/types.rs b/crates/solc-expressions/src/func_call/intrinsic_call/types.rs index fbc84e29..b1a9357e 100644 --- a/crates/solc-expressions/src/func_call/intrinsic_call/types.rs +++ b/crates/solc-expressions/src/func_call/intrinsic_call/types.rs @@ -1,6 +1,6 @@ use crate::func_caller::NamedOrUnnamedArgs; use crate::ListAccess; -use crate::{variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr}; +use crate::{variable::Variable, ContextBuilder, ExpressionParser}; use graph::nodes::FunctionNode; use graph::{ @@ -10,7 +10,7 @@ use graph::{ }, AnalyzerBackend, Node, VarType, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/join.rs b/crates/solc-expressions/src/func_call/join.rs index 0aba321d..ba5945ed 100644 --- a/crates/solc-expressions/src/func_call/join.rs +++ b/crates/solc-expressions/src/func_call/join.rs @@ -1,7 +1,7 @@ use crate::context_builder::StatementParser; +use crate::helper::CallerHelper; use crate::member_access::ListAccess; use crate::variable::Variable; -use crate::{helper::CallerHelper, ExprErr, IntoExprErr}; use graph::{ elem::{Elem, RangeElem, RangeExpr, RangeOp}, @@ -11,7 +11,7 @@ use graph::{ }, AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, Range, SolcRange, VarType, }; -use shared::{AnalyzerLike, NodeIdx, RangeArena, StorageLocation}; +use shared::{AnalyzerLike, ExprErr, IntoExprErr, NodeIdx, RangeArena, StorageLocation}; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/modifier.rs b/crates/solc-expressions/src/func_call/modifier.rs index 3b355863..0980ca73 100644 --- a/crates/solc-expressions/src/func_call/modifier.rs +++ b/crates/solc-expressions/src/func_call/modifier.rs @@ -1,16 +1,13 @@ //! Traits & blanket implementations that facilitate performing modifier function calls. -use crate::{ - func_caller::FuncCaller, helper::CallerHelper, ContextBuilder, ExprErr, ExpressionParser, - IntoExprErr, -}; +use crate::{func_caller::FuncCaller, helper::CallerHelper, ContextBuilder, ExpressionParser}; use graph::{ elem::Elem, nodes::{Concrete, Context, ContextNode, ExprRet, FunctionNode, ModifierState}, AnalyzerBackend, Edge, GraphBackend, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::pt::{CodeLocation, Expression, Loc}; diff --git a/crates/solc-expressions/src/func_call/namespaced_call.rs b/crates/solc-expressions/src/func_call/namespaced_call.rs index af229b61..22d093a7 100644 --- a/crates/solc-expressions/src/func_call/namespaced_call.rs +++ b/crates/solc-expressions/src/func_call/namespaced_call.rs @@ -6,7 +6,7 @@ use crate::{ func_call::helper::CallerHelper, intrinsic_call::IntrinsicFuncCaller, member_access::MemberAccess, - ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, + ContextBuilder, ExpressionParser, }; use graph::nodes::{Concrete, ContextVar}; use graph::ContextEdge; @@ -19,7 +19,7 @@ use graph::{ AnalyzerBackend, GraphBackend, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Identifier, Loc}; diff --git a/crates/solc-expressions/src/lib.rs b/crates/solc-expressions/src/lib.rs index 95fe792b..9d4ed05c 100644 --- a/crates/solc-expressions/src/lib.rs +++ b/crates/solc-expressions/src/lib.rs @@ -1,5 +1,3 @@ -use solang_parser::pt::Loc; - mod array; mod assign; mod bin_op; @@ -64,161 +62,3 @@ impl ExprTyParser for T where + Assign { } - -/// Convert some error into an expression error by attaching a code source location -pub trait IntoExprErr { - /// Convert into a ExprErr - fn into_expr_err(self, loc: Loc) -> Result; -} - -impl IntoExprErr for Result { - fn into_expr_err(self, loc: Loc) -> Result { - match self { - Ok(v) => Ok(v), - Err(e) => Err(ExprErr::from_graph_err(loc, e)), - } - } -} - -#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)] -/// An error that arose from the analyzer when interpreting expressions and statements -pub enum ExprErr { - ParseError(Loc, String), - NoLhs(Loc, String), - NoRhs(Loc, String), - NoReturn(Loc, String), - ArrayTy(Loc, String), - ArrayIndex(Loc, String), - UnhandledCombo(Loc, String), - UnhandledExprRet(Loc, String), - MultiNot(Loc, String), - VarBadType(Loc, String), - Todo(Loc, String), - BadRange(Loc, String), - ContractFunctionNotFound(Loc, String), - MemberAccessNotFound(Loc, String), - FunctionNotFound(Loc, String), - - FunctionCallBlockTodo(Loc, String), - - NonStoragePush(Loc, String), - IntrinsicNamedArgs(Loc, String), - InvalidFunctionInput(Loc, String), - TakeFromFork(Loc, String), - GraphError(Loc, graph::GraphError), - Unresolved(Loc, String), -} - -impl ExprErr { - /// Convert from a graph error - pub fn from_graph_err(loc: Loc, graph_err: graph::GraphError) -> Self { - Self::GraphError(loc, graph_err) - } -} - -impl ExprErr { - /// Get the code source location of the error - pub fn loc(&self) -> Loc { - use ExprErr::*; - match self { - ParseError(loc, ..) => *loc, - NoLhs(loc, ..) => *loc, - NoRhs(loc, ..) => *loc, - NoReturn(loc, ..) => *loc, - ArrayTy(loc, ..) => *loc, - ArrayIndex(loc, ..) => *loc, - UnhandledCombo(loc, ..) => *loc, - UnhandledExprRet(loc, ..) => *loc, - MultiNot(loc, ..) => *loc, - VarBadType(loc, ..) => *loc, - Todo(loc, ..) => *loc, - FunctionCallBlockTodo(loc, ..) => *loc, - BadRange(loc, ..) => *loc, - ContractFunctionNotFound(loc, ..) => *loc, - MemberAccessNotFound(loc, ..) => *loc, - FunctionNotFound(loc, ..) => *loc, - NonStoragePush(loc, ..) => *loc, - IntrinsicNamedArgs(loc, ..) => *loc, - InvalidFunctionInput(loc, ..) => *loc, - TakeFromFork(loc, ..) => *loc, - GraphError(loc, ..) => *loc, - Unresolved(loc, ..) => *loc, - } - } - - /// Get the error message - pub fn msg(&self) -> &str { - use ExprErr::*; - match self { - ParseError(_, msg, ..) => msg, - NoLhs(_, msg, ..) => msg, - NoRhs(_, msg, ..) => msg, - NoReturn(_, msg, ..) => msg, - ArrayTy(_, msg, ..) => msg, - ArrayIndex(_, msg, ..) => msg, - UnhandledCombo(_, msg, ..) => msg, - UnhandledExprRet(_, msg, ..) => msg, - MultiNot(_, msg, ..) => msg, - VarBadType(_, msg, ..) => msg, - Todo(_, msg, ..) => msg, - FunctionCallBlockTodo(_, msg, ..) => msg, - BadRange(_, msg, ..) => msg, - ContractFunctionNotFound(_, msg, ..) => msg, - MemberAccessNotFound(_, msg, ..) => msg, - FunctionNotFound(_, msg, ..) => msg, - NonStoragePush(_, msg, ..) => msg, - IntrinsicNamedArgs(_, msg, ..) => msg, - InvalidFunctionInput(_, msg, ..) => msg, - TakeFromFork(_, msg, ..) => msg, - Unresolved(_, msg, ..) => msg, - GraphError(_loc, graph::GraphError::NodeConfusion(msg), ..) => msg, - GraphError(_loc, graph::GraphError::MaxStackDepthReached(msg), ..) => msg, - GraphError(_loc, graph::GraphError::MaxStackWidthReached(msg), ..) => msg, - GraphError(_loc, graph::GraphError::ChildRedefinition(msg), ..) => msg, - GraphError(_loc, graph::GraphError::DetachedVariable(msg), ..) => msg, - GraphError(_loc, graph::GraphError::VariableUpdateInOldContext(msg), ..) => msg, - GraphError(_loc, graph::GraphError::ExpectedSingle(msg), ..) => msg, - GraphError(_loc, graph::GraphError::StackLengthMismatch(msg), ..) => msg, - GraphError(_loc, graph::GraphError::UnbreakableRecursion(msg), ..) => msg, - GraphError(_loc, graph::GraphError::UnknownVariable(msg), ..) => msg, - } - } - - /// Get the top-level report message - pub fn report_msg(&self) -> &str { - use ExprErr::*; - match self { - ParseError(..) => "Could not parse this", - NoLhs(..) => "No left-hand side passed to expression", - NoRhs(..) => "No right-hand side passed to expression", - NoReturn(..) => "No returned element from expression", - ArrayTy(..) => "Unexpected type as array element", - ArrayIndex(..) => "Unexpected type as array index", - UnhandledCombo(..) => "Unhandled ExprRet variant combination", - UnhandledExprRet(..) => "Unhandled ExprRet variant", - MultiNot(..) => "Expected a single ExprRet in Not statement, got ExprRet::Multi", - VarBadType(..) => "This type cannot be made into a variable", - Todo(..) => "TODO", - FunctionCallBlockTodo(..) => "TODO", - Unresolved(..) => "Unresolved type: This is likely a bug. Please report it at https://github.com/nascentxyz/pyrometer", - BadRange(..) => "Expected a range for a variable but there was none", - ContractFunctionNotFound(..) => "Contract function could not be Found", - MemberAccessNotFound(..) => "Member element could not be found", - FunctionNotFound(..) => "Function could not be found", - NonStoragePush(..) => "Pushing on non-storage based array is unsupported", - IntrinsicNamedArgs(..) => "Arguments in calls to intrinsic functions cannot be named", - InvalidFunctionInput(..) => "Arguments to this function call do not match required types", - TakeFromFork(..) => "IR Error: Tried to take from an child context that ended up forking", - GraphError(_loc, graph::GraphError::NodeConfusion(_), ..) => "Graph IR Error: Node type confusion. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", - GraphError(_loc, graph::GraphError::MaxStackDepthReached(_), ..) => "Max call depth reached - either recursion or loop", - GraphError(_loc, graph::GraphError::MaxStackWidthReached(_), ..) => "TODO: Max fork width reached - Need to widen variables and remove contexts", - GraphError(_loc, graph::GraphError::ChildRedefinition(_), ..) => "Graph IR Error: Child redefintion. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", - GraphError(_loc, graph::GraphError::DetachedVariable(_), ..) => "Graph IR Error: Detached Variable. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", - GraphError(_loc, graph::GraphError::VariableUpdateInOldContext(_), ..) => "Graph IR Error: Variable update in an old context. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", - GraphError(_loc, graph::GraphError::ExpectedSingle(_), ..) => "Graph IR Error: Expecting single expression return, got multiple. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", - GraphError(_loc, graph::GraphError::StackLengthMismatch(_), ..) => "Graph IR Error: Expected a particular number of elements on the context stack but found a different amount. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", - GraphError(_loc, graph::GraphError::UnbreakableRecursion(_), ..) => "Graph IR Error: Unbreakable recursion in variable range. This is potentially a bug. Please report it at https://github.com/nascentxyz/pyrometer", - GraphError(_loc, graph::GraphError::UnknownVariable(_), ..) => "Graph IR Error: Unknown variable. This is potentially a bug, but more likely a variable name is mistyped.", - } - } -} diff --git a/crates/solc-expressions/src/list.rs b/crates/solc-expressions/src/list.rs index 263dad5c..52a24f25 100644 --- a/crates/solc-expressions/src/list.rs +++ b/crates/solc-expressions/src/list.rs @@ -1,11 +1,11 @@ -use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr}; +use crate::{ContextBuilder, ExpressionParser}; use graph::{ elem::Elem, nodes::{Concrete, ContextNode, ContextVar, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc, Parameter, ParameterList}; diff --git a/crates/solc-expressions/src/literal.rs b/crates/solc-expressions/src/literal.rs index fb118816..dac3bcf6 100644 --- a/crates/solc-expressions/src/literal.rs +++ b/crates/solc-expressions/src/literal.rs @@ -1,11 +1,9 @@ -use crate::{ExprErr, IntoExprErr}; - use graph::{ elem::*, nodes::{Builtin, Concrete, ConcreteNode, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::{Address, H256, I256, U256}; use solang_parser::pt::{HexLiteral, Identifier, Loc}; diff --git a/crates/solc-expressions/src/loops.rs b/crates/solc-expressions/src/loops.rs index aa6f4488..efaefb0b 100644 --- a/crates/solc-expressions/src/loops.rs +++ b/crates/solc-expressions/src/loops.rs @@ -1,4 +1,4 @@ -use crate::{variable::Variable, ContextBuilder, ExprErr, IntoExprErr, StatementParser}; +use crate::{variable::Variable, ContextBuilder, StatementParser}; use graph::ContextEdge; use graph::Edge; @@ -7,7 +7,7 @@ use graph::{ nodes::{Concrete, Context, ContextNode}, AnalyzerBackend, GraphBackend, Node, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Loc, Statement}; diff --git a/crates/solc-expressions/src/member_access/builtin_access.rs b/crates/solc-expressions/src/member_access/builtin_access.rs index 3ea01028..24f020fa 100644 --- a/crates/solc-expressions/src/member_access/builtin_access.rs +++ b/crates/solc-expressions/src/member_access/builtin_access.rs @@ -1,9 +1,10 @@ -use crate::{ExprErr, IntoExprErr, LibraryAccess}; +use crate::LibraryAccess; use graph::{ nodes::{BuiltInNode, Builtin, Concrete, ContextNode, ContextVar, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; +use shared::{ExprErr, IntoExprErr}; use ethers_core::types::{I256, U256}; use solang_parser::pt::{Expression, Identifier, Loc}; diff --git a/crates/solc-expressions/src/member_access/contract_access.rs b/crates/solc-expressions/src/member_access/contract_access.rs index d64a3ff0..963610b8 100644 --- a/crates/solc-expressions/src/member_access/contract_access.rs +++ b/crates/solc-expressions/src/member_access/contract_access.rs @@ -1,10 +1,8 @@ -use crate::{ExprErr, IntoExprErr}; - use graph::{ nodes::{Builtin, Concrete, ContextNode, ContextVar, ContractNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::NodeIdx; +use shared::{ExprErr, IntoExprErr, NodeIdx}; use solang_parser::pt::{Expression, Identifier, Loc}; diff --git a/crates/solc-expressions/src/member_access/enum_access.rs b/crates/solc-expressions/src/member_access/enum_access.rs index c373e772..cad05663 100644 --- a/crates/solc-expressions/src/member_access/enum_access.rs +++ b/crates/solc-expressions/src/member_access/enum_access.rs @@ -1,10 +1,10 @@ -use crate::{ExprErr, IntoExprErr, LibraryAccess}; +use crate::LibraryAccess; use graph::{ nodes::{ContextNode, ContextVar, EnumNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::NodeIdx; +use shared::{ExprErr, IntoExprErr, NodeIdx}; use solang_parser::pt::{Expression, Identifier, Loc}; diff --git a/crates/solc-expressions/src/member_access/library_access.rs b/crates/solc-expressions/src/member_access/library_access.rs index 164b5f0b..62a138e4 100644 --- a/crates/solc-expressions/src/member_access/library_access.rs +++ b/crates/solc-expressions/src/member_access/library_access.rs @@ -1,10 +1,8 @@ -use crate::ExprErr; - use graph::{ nodes::{ContextNode, ExprRet, FunctionNode}, AnalyzerBackend, Edge, }; -use shared::NodeIdx; +use shared::{ExprErr, NodeIdx}; use petgraph::{visit::EdgeRef, Direction}; use solang_parser::pt::{Expression, Identifier}; diff --git a/crates/solc-expressions/src/member_access/list_access.rs b/crates/solc-expressions/src/member_access/list_access.rs index ab1be6ad..41ecd902 100644 --- a/crates/solc-expressions/src/member_access/list_access.rs +++ b/crates/solc-expressions/src/member_access/list_access.rs @@ -1,11 +1,11 @@ -use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, Variable}; +use crate::{ContextBuilder, ExpressionParser, Variable}; use graph::{ elem::*, nodes::{BuiltInNode, Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, Range, SolcRange, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::U256; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/member_access/member_trait.rs b/crates/solc-expressions/src/member_access/member_trait.rs index d266afeb..fd0de843 100644 --- a/crates/solc-expressions/src/member_access/member_trait.rs +++ b/crates/solc-expressions/src/member_access/member_trait.rs @@ -1,6 +1,6 @@ use crate::{ - BuiltinAccess, ContextBuilder, ContractAccess, EnumAccess, Env, ExprErr, ExpressionParser, - IntoExprErr, ListAccess, StructAccess, + BuiltinAccess, ContextBuilder, ContractAccess, EnumAccess, Env, ExpressionParser, ListAccess, + StructAccess, }; use graph::{ @@ -11,7 +11,7 @@ use graph::{ }, AnalyzerBackend, Node, TypeNode, VarType, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use solang_parser::pt::{Expression, Identifier, Loc}; diff --git a/crates/solc-expressions/src/member_access/struct_access.rs b/crates/solc-expressions/src/member_access/struct_access.rs index 84b7bfb8..65c73877 100644 --- a/crates/solc-expressions/src/member_access/struct_access.rs +++ b/crates/solc-expressions/src/member_access/struct_access.rs @@ -1,10 +1,10 @@ -use crate::{ExprErr, IntoExprErr, LibraryAccess}; +use crate::LibraryAccess; use graph::{ nodes::{ContextNode, ContextVar, ContextVarNode, ExprRet, StructNode}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::NodeIdx; +use shared::{ExprErr, IntoExprErr, NodeIdx}; use solang_parser::pt::{Expression, Identifier, Loc}; diff --git a/crates/solc-expressions/src/pre_post_in_decrement.rs b/crates/solc-expressions/src/pre_post_in_decrement.rs index 275c979a..8621893b 100644 --- a/crates/solc-expressions/src/pre_post_in_decrement.rs +++ b/crates/solc-expressions/src/pre_post_in_decrement.rs @@ -1,13 +1,11 @@ -use crate::{ - context_builder::ContextBuilder, variable::Variable, ExprErr, ExpressionParser, IntoExprErr, -}; +use crate::{context_builder::ContextBuilder, variable::Variable, ExpressionParser}; use graph::{ elem::*, nodes::{Concrete, ContextNode, ContextVarNode, ExprRet}, AnalyzerBackend, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::U256; use solang_parser::pt::{Expression, Loc}; diff --git a/crates/solc-expressions/src/require.rs b/crates/solc-expressions/src/require.rs index 28d4f608..dee22f09 100644 --- a/crates/solc-expressions/src/require.rs +++ b/crates/solc-expressions/src/require.rs @@ -1,4 +1,4 @@ -use crate::{BinOp, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, Variable}; +use crate::{BinOp, ContextBuilder, ExpressionParser, Variable}; use graph::{ elem::*, @@ -9,7 +9,7 @@ use graph::{ range_string::ToRangeString, AnalyzerBackend, ContextEdge, Edge, Node, Range, RangeEval, SolcRange, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use ethers_core::types::I256; use solang_parser::{ diff --git a/crates/solc-expressions/src/variable.rs b/crates/solc-expressions/src/variable.rs index daa8cda5..525c3dbf 100644 --- a/crates/solc-expressions/src/variable.rs +++ b/crates/solc-expressions/src/variable.rs @@ -1,11 +1,11 @@ -use crate::{assign::Assign, env::Env, ContextBuilder, ExprErr, IntoExprErr}; +use crate::{assign::Assign, env::Env, ContextBuilder}; use graph::{ elem::Elem, nodes::{Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet, VarNode}, - AnalyzerBackend, ContextEdge, Edge, GraphError, Node, VarType, + AnalyzerBackend, ContextEdge, Edge, Node, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, GraphError, IntoExprErr, RangeArena}; use solang_parser::pt::{Expression, Identifier, Loc, VariableDeclaration}; diff --git a/crates/solc-expressions/src/yul/yul_builder.rs b/crates/solc-expressions/src/yul/yul_builder.rs index b878b7e8..dcaa8f74 100644 --- a/crates/solc-expressions/src/yul/yul_builder.rs +++ b/crates/solc-expressions/src/yul/yul_builder.rs @@ -1,8 +1,6 @@ //! Trait and blanket implementation for parsing yul-based statements and expressions -use crate::{ - yul::YulCondOp, yul::YulFuncCaller, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, -}; +use crate::{yul::YulCondOp, yul::YulFuncCaller, ContextBuilder, ExpressionParser}; use graph::{ elem::Elem, @@ -11,7 +9,7 @@ use graph::{ }, AnalyzerBackend, ContextEdge, Edge, Node, SolcRange, VarType, }; -use shared::RangeArena; +use shared::{ExprErr, IntoExprErr, RangeArena}; use solang_parser::{ helpers::CodeLocation, diff --git a/crates/solc-expressions/src/yul/yul_cond_op.rs b/crates/solc-expressions/src/yul/yul_cond_op.rs index 6a63b839..aa8b58b7 100644 --- a/crates/solc-expressions/src/yul/yul_cond_op.rs +++ b/crates/solc-expressions/src/yul/yul_cond_op.rs @@ -1,11 +1,11 @@ -use crate::{require::Require, yul::YulBuilder, ContextBuilder, ExprErr, IntoExprErr}; +use crate::{require::Require, yul::YulBuilder, ContextBuilder}; use graph::{ elem::*, nodes::{Concrete, ConcreteNode, Context, ContextNode, ContextVar, ContextVarNode, ExprRet}, AnalyzerBackend, ContextEdge, Edge, Node, }; -use shared::{NodeIdx, RangeArena}; +use shared::{ExprErr, IntoExprErr, NodeIdx, RangeArena}; use ethers_core::types::U256; use solang_parser::pt::{ diff --git a/crates/solc-expressions/src/yul/yul_funcs.rs b/crates/solc-expressions/src/yul/yul_funcs.rs index faf389d7..cb2d4e7c 100644 --- a/crates/solc-expressions/src/yul/yul_funcs.rs +++ b/crates/solc-expressions/src/yul/yul_funcs.rs @@ -1,7 +1,4 @@ -use crate::{ - assign::Assign, variable::Variable, yul::YulBuilder, BinOp, Cmp, ContextBuilder, Env, ExprErr, - IntoExprErr, -}; +use crate::{assign::Assign, variable::Variable, yul::YulBuilder, BinOp, Cmp, ContextBuilder, Env}; use graph::{ elem::*, @@ -11,7 +8,7 @@ use graph::{ }, AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, SolcRange, VarType, }; -use shared::{RangeArena, StorageLocation}; +use shared::{ExprErr, IntoExprErr, RangeArena, StorageLocation}; use ethers_core::types::U256; use solang_parser::pt::{Expression, Loc, YulExpression, YulFunctionCall};