Skip to content

Commit

Permalink
refactor: ExprErr location
Browse files Browse the repository at this point in the history
  • Loading branch information
plotchy committed Jun 28, 2024
1 parent ed8044b commit 2523d63
Show file tree
Hide file tree
Showing 88 changed files with 370 additions and 359 deletions.
24 changes: 0 additions & 24 deletions crates/graph/src/graph_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/block.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/builtin.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/concrete.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/expr_ret.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/node.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/querying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/solving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion crates/graph/src/nodes/context/typing.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion crates/graph/src/nodes/context/underlying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/var/node.rs
Original file line number Diff line number Diff line change
@@ -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::{NodeIdx, RangeArena, Search, StorageLocation, GraphError};

use petgraph::{visit::EdgeRef, Direction};
use solang_parser::pt::Loc;
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/var/ranging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/var/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/var/underlying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/context/var/versioning.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
3 changes: 2 additions & 1 deletion crates/graph/src/nodes/context/variables.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 2 additions & 1 deletion crates/graph/src/nodes/context/versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use crate::ContextEdge;
use crate::Edge;
use crate::{
nodes::{CallFork, ContextNode, FunctionNode, KilledKind},
AnalyzerBackend, GraphBackend, GraphError, Node,
AnalyzerBackend, GraphBackend, Node,
};
use shared::GraphError;
use petgraph::visit::EdgeRef;
use petgraph::Direction;

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/contract_ty.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/enum_ty.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
nodes::Concrete, range::elem::Elem, AsDotStr, GraphBackend, GraphError, Node, SolcRange,
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};
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/err_ty.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, GraphBackend, GraphError, Node,
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)]
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/func_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::{
nodes::Concrete,
nodes::{ContextNode, ContractNode, SourceUnitNode, SourceUnitPartNode},
range::elem::Elem,
AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, GraphError, Node, SolcRange,
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::{
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/msg.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/source_unit.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/source_unit_part.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/struct_ty.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, Edge, GraphBackend, GraphError,
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};
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/ty_ty.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
nodes::Concrete, range::elem::Elem, AnalyzerBackend, AsDotStr, GraphBackend, GraphError, Node,
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};

Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/nodes/var_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
4 changes: 2 additions & 2 deletions crates/graph/src/range/elem/concrete.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
10 changes: 5 additions & 5 deletions crates/graph/src/range/elem/elem_enum/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
nodes::Concrete,
range::elem::{Elem, RangeElem},
};
use shared::RangeArena;
use shared::{GraphError, RangeArena};

pub trait RangeArenaLike<T> {
fn debug_str(&self, analyzer: &impl GraphBackend) -> String;
Expand All @@ -15,7 +15,7 @@ pub trait RangeArenaLike<T> {
fn to_graph(
&mut self,
analyzer: &impl GraphBackend,
) -> Result<petgraph::Graph<Elem<Concrete>, usize, petgraph::Directed, usize>, crate::GraphError>;
) -> Result<petgraph::Graph<Elem<Concrete>, usize, petgraph::Directed, usize>, GraphError>;
}

impl RangeArenaLike<Elem<Concrete>> for RangeArena<Elem<Concrete>> {
Expand Down Expand Up @@ -56,7 +56,7 @@ impl RangeArenaLike<Elem<Concrete>> for RangeArena<Elem<Concrete>> {
fn to_graph(
&mut self,
analyzer: &impl GraphBackend,
) -> Result<petgraph::Graph<Elem<Concrete>, usize, petgraph::Directed, usize>, crate::GraphError>
) -> Result<petgraph::Graph<Elem<Concrete>, usize, petgraph::Directed, usize>, GraphError>
{
let mut graph = petgraph::Graph::default();
let mut added = vec![];
Expand All @@ -65,7 +65,7 @@ impl RangeArenaLike<Elem<Concrete>> for RangeArena<Elem<Concrete>> {
fn get_children(
elem: &Elem<Concrete>,
analyzer: &impl GraphBackend,
) -> Result<Vec<Elem<Concrete>>, crate::GraphError> {
) -> Result<Vec<Elem<Concrete>>, GraphError> {
match elem {
Elem::Reference(r) => {
let cvar = crate::nodes::ContextVarNode::from(r.idx);
Expand Down Expand Up @@ -93,7 +93,7 @@ impl RangeArenaLike<Elem<Concrete>> for RangeArena<Elem<Concrete>> {
ids: &mut Vec<usize>,
elem: &Elem<Concrete>,
analyzer: &impl GraphBackend,
) -> Result<(), crate::GraphError> {
) -> Result<(), GraphError> {
assert!(added.len() == ids.len());

if !added.contains(elem) {
Expand Down
Loading

0 comments on commit 2523d63

Please sign in to comment.