Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Dec 11, 2023
1 parent 310804a commit 951ae0f
Show file tree
Hide file tree
Showing 36 changed files with 205 additions and 133 deletions.
2 changes: 1 addition & 1 deletion crates/pyrometer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::builtin_fns;
use analyzers::LocStrSpan;
use graph::{nodes::*, ContextEdge, Edge, Node, VarType};
use shared::{AnalyzerLike, GraphLike, NodeIdx, Search};
use solc_expressions::{StatementParser, ExprErr, IntoExprErr};
use solc_expressions::{ExprErr, IntoExprErr, StatementParser};

use ariadne::{Cache, Color, Config, Fmt, Label, Report, ReportKind, Source, Span};
use petgraph::{graph::*, Directed};
Expand Down
5 changes: 4 additions & 1 deletion crates/solc-expressions/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{ExpressionParser, variable::Variable, require::Require, ContextBuilder, ExprErr, IntoExprErr, ListAccess};
use crate::{
require::Require, variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr,
ListAccess,
};

use graph::{
elem::RangeOp,
Expand Down
9 changes: 4 additions & 5 deletions crates/solc-expressions/src/assign.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::{variable::Variable, ContextBuilder, ExprErr, IntoExprErr, ExpressionParser};
use crate::{variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr};

use graph::{
elem::Elem, GraphError, Range,
elem::Elem,
nodes::{Concrete, ContextNode, ContextVarNode, ExprRet},
AnalyzerBackend, ContextEdge, Edge,
AnalyzerBackend, ContextEdge, Edge, GraphError, Range,
};

use solang_parser::pt::{Expression, Loc};

impl<T> Assign for T where T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {}
/// Handles assignments
pub trait Assign: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
#[tracing::instrument(level = "trace", skip_all)]
#[tracing::instrument(level = "trace", skip_all)]
/// Parse an assignment expression
fn assign_exprs(
&mut self,
Expand Down Expand Up @@ -239,4 +239,3 @@ pub trait Assign: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized
Ok(ExprRet::Single(new_lhs.into()))
}
}

4 changes: 3 additions & 1 deletion crates/solc-expressions/src/bin_op.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{variable::Variable, require::Require, ContextBuilder, ExprErr, IntoExprErr, ExpressionParser};
use crate::{
require::Require, variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr,
};

use graph::{
elem::*,
Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/cmp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ContextBuilder, ExprErr, IntoExprErr, ExpressionParser};
use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr};

use graph::{
elem::*,
Expand Down
4 changes: 3 additions & 1 deletion crates/solc-expressions/src/cond_op.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{require::Require, ContextBuilder, ExprErr, IntoExprErr, StatementParser, ExpressionParser};
use crate::{
require::Require, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr, StatementParser,
};

use graph::{
nodes::{Context, ContextNode},
Expand Down
16 changes: 6 additions & 10 deletions crates/solc-expressions/src/context_builder/expr.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
use crate::{
context_builder::ContextBuilder,
variable::Variable,
func_call::{func_caller::FuncCaller}, ExprErr, ExprTyParser, IntoExprErr,
context_builder::ContextBuilder, func_call::func_caller::FuncCaller, variable::Variable,
ExprErr, ExprTyParser, IntoExprErr,
};

use graph::{
elem::*,
nodes::{
Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet,
},
nodes::{Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet},
AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node,
};

use ethers_core::types::{I256};
use ethers_core::types::I256;
use solang_parser::{
helpers::CodeLocation,
pt::{Expression, Loc},
};


impl<T> ExpressionParser for T where
T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + ExprTyParser
{
Expand All @@ -28,7 +24,7 @@ impl<T> ExpressionParser for T where
pub trait ExpressionParser:
AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + ExprTyParser
{
/// Perform setup for parsing an expression
/// Perform setup for parsing an expression
fn parse_ctx_expr(&mut self, expr: &Expression, ctx: ContextNode) -> Result<(), ExprErr> {
if !ctx.killed_or_ret(self).unwrap() {
let edges = ctx.live_edges(self).into_expr_err(expr.loc())?;
Expand Down Expand Up @@ -390,4 +386,4 @@ pub trait ExpressionParser:
Parenthesis(_loc, expr) => self.parse_ctx_expr(expr, ctx),
}
}
}
}
13 changes: 4 additions & 9 deletions crates/solc-expressions/src/context_builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//! Trait and blanket implementation for the core parsing loop
use crate::{
ExprErr, IntoExprErr,
};
use crate::{ExprErr, IntoExprErr};

use graph::{
nodes::{
ContextNode, ContextVarNode, ExprRet, KilledKind,
},
nodes::{ContextNode, ContextVarNode, ExprRet, KilledKind},
AnalyzerBackend, ContextEdge, Edge, GraphError,
};

Expand All @@ -17,17 +13,16 @@ impl<T> ContextBuilder for T where
{
}

mod stmt;
mod expr;
mod stmt;

pub use stmt::*;
pub use expr::*;
pub use stmt::*;

/// Dispatcher for building up a context of a function
pub trait ContextBuilder:
AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + StatementParser
{

/// TODO: rename this. Sometimes we dont want to kill a context if we hit an error
fn widen_if_limit_hit(&mut self, ctx: ContextNode, maybe_err: Result<(), ExprErr>) -> bool {
match maybe_err {
Expand Down
17 changes: 8 additions & 9 deletions crates/solc-expressions/src/context_builder/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@

use crate::{
context_builder::ContextBuilder,
ExpressionParser,
func_call::{func_caller::FuncCaller, modifier::ModifierCaller}, loops::Looper, yul::YulBuilder, ExprErr, IntoExprErr,
context_builder::ContextBuilder,
func_call::{func_caller::FuncCaller, modifier::ModifierCaller},
loops::Looper,
yul::YulBuilder,
ExprErr, ExpressionParser, IntoExprErr,
};

use graph::{
nodes::{
Context, ContextNode, ContextVar, ContextVarNode, ExprRet, FunctionNode,
FunctionParamNode, FunctionReturnNode, KilledKind,
Context, ContextNode, ContextVar, ContextVarNode, ExprRet, FunctionNode, FunctionParamNode,
FunctionReturnNode, KilledKind,
},
AnalyzerBackend, ContextEdge, Edge, Node,
};
use shared::NodeIdx;


use petgraph::{visit::EdgeRef, Direction};
use solang_parser::{
helpers::CodeLocation,
pt::{Expression, Statement, YulStatement},
};


impl<T> StatementParser for T where
T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + ExpressionParser
{
Expand Down Expand Up @@ -525,4 +524,4 @@ pub trait StatementParser:
Error(_loc) => {}
}
}
}
}
4 changes: 3 additions & 1 deletion crates/solc-expressions/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{func_call::helper::CallerHelper, func_call::modifier::ModifierCaller, ExprErr, IntoExprErr};
use crate::{
func_call::helper::CallerHelper, func_call::modifier::ModifierCaller, ExprErr, IntoExprErr,
};

use graph::{
nodes::{Builtin, Concrete, ContextNode, ContextVar, ExprRet},
Expand Down
14 changes: 6 additions & 8 deletions crates/solc-expressions/src/func_call/func_caller.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
//! Traits & blanket implementations that facilitate performing various forms of function calls.
use crate::{
func_call::modifier::ModifierCaller,
internal_call::InternalFuncCaller, intrinsic_call::IntrinsicFuncCaller,
namespaced_call::NameSpaceFuncCaller, ContextBuilder, ExprErr, IntoExprErr,
helper::CallerHelper, ExpressionParser, StatementParser,
func_call::modifier::ModifierCaller, helper::CallerHelper, internal_call::InternalFuncCaller,
intrinsic_call::IntrinsicFuncCaller, namespaced_call::NameSpaceFuncCaller, ContextBuilder,
ExprErr, ExpressionParser, IntoExprErr, StatementParser,
};

use graph::{
nodes::{
Context, ContextNode, ContextVar, ContextVarNode, ExprRet, FunctionNode,
FunctionParamNode, ModifierState,
Context, ContextNode, ContextVar, ContextVarNode, ExprRet, FunctionNode, FunctionParamNode,
ModifierState,
},
AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node,
};
use shared::{NodeIdx};
use shared::NodeIdx;

use solang_parser::pt::{Expression, Loc, NamedArgument};

Expand Down Expand Up @@ -296,7 +295,6 @@ pub trait FuncCaller:
})
}


/// Actually executes the function
#[tracing::instrument(level = "trace", skip_all)]
fn execute_call_inner(
Expand Down
12 changes: 3 additions & 9 deletions crates/solc-expressions/src/func_call/helper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Helper traits & blanket implementations that help facilitate performing function calls.
use crate::{
ContextBuilder, ExprErr, IntoExprErr, variable::Variable, ExpressionParser
};
use crate::{variable::Variable, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr};

use graph::{
nodes::{
Expand All @@ -14,11 +12,7 @@ use shared::{NodeIdx, StorageLocation};

use solang_parser::pt::{Expression, Loc};

use std::{
cell::RefCell,
collections::BTreeMap,
rc::Rc
};
use std::{cell::RefCell, collections::BTreeMap, rc::Rc};

impl<T> CallerHelper for T where T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {}
/// Helper trait for performing function calls
Expand Down Expand Up @@ -582,4 +576,4 @@ pub trait CallerHelper: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> +
}
Ok(())
}
}
}
13 changes: 11 additions & 2 deletions crates/solc-expressions/src/func_call/internal_call.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Traits & blanket implementations that facilitate performing locally scoped function calls.
use crate::{func_call::func_caller::FuncCaller, helper::CallerHelper, ContextBuilder, ExprErr, IntoExprErr, ExpressionParser, assign::Assign};
use crate::{
assign::Assign, func_call::func_caller::FuncCaller, helper::CallerHelper, ContextBuilder,
ExprErr, ExpressionParser, IntoExprErr,
};

use graph::{
nodes::{Builtin, Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet},
Expand Down Expand Up @@ -232,7 +235,13 @@ pub trait InternalFuncCaller:
ctx.push_expr(inputs, analyzer).into_expr_err(loc)?;
return Ok(());
}
analyzer.setup_fn_call(&ident.loc, &inputs, (possible_funcs[0]).into(), ctx, None)
analyzer.setup_fn_call(
&ident.loc,
&inputs,
(possible_funcs[0]).into(),
ctx,
None,
)
})
}
_ => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ContextBuilder, ExprErr, IntoExprErr, ExpressionParser};
use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr};

use graph::{
nodes::{Builtin, ContextNode, ContextVar, ExprRet},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{array::Array, ContextBuilder, ExprErr, IntoExprErr, ListAccess, ExpressionParser, assign::Assign, variable::Variable};
use crate::{
array::Array, assign::Assign, variable::Variable, ContextBuilder, ExprErr, ExpressionParser,
IntoExprErr, ListAccess,
};

use graph::{
elem::*,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ContextBuilder, ExprErr, IntoExprErr, ExpressionParser};
use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr};

use graph::{
nodes::{Builtin, ContextNode, ContextVar, ExprRet},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{ContextBuilder, ExprErr, IntoExprErr, func_call::helper::CallerHelper, ExpressionParser, assign::Assign};
use crate::{
assign::Assign, func_call::helper::CallerHelper, ContextBuilder, ExprErr, ExpressionParser,
IntoExprErr,
};

use graph::{
elem::*,
Expand All @@ -15,7 +18,9 @@ impl<T> ConstructorCaller for T where
}

/// Trait for constructing compound types like contracts, structs and arrays
pub trait ConstructorCaller: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + CallerHelper {
pub trait ConstructorCaller:
AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + CallerHelper
{
/// Construct an array
fn construct_array(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{ContextBuilder, ExprErr, IntoExprErr, ExpressionParser};
use crate::{ContextBuilder, ExprErr, ExpressionParser, IntoExprErr};

use graph::{
nodes::{Builtin, Concrete, ContextNode, ContextVarNode, ExprRet},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
func_call::helper::CallerHelper,
intrinsic_call::{
AbiCaller, AddressCaller, ArrayCaller, BlockCaller, ConstructorCaller, DynBuiltinCaller,
MsgCaller, PrecompileCaller, SolidityCaller, TypesCaller,
},
ContextBuilder, ExprErr, IntoExprErr, func_call::helper::CallerHelper
ContextBuilder, ExprErr, IntoExprErr,
};

use graph::{
Expand Down
14 changes: 10 additions & 4 deletions crates/solc-expressions/src/func_call/intrinsic_call/precompile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{ContextBuilder, ExprErr, IntoExprErr, func_call::helper::CallerHelper, ExpressionParser};
use crate::{
func_call::helper::CallerHelper, ContextBuilder, ExprErr, ExpressionParser, IntoExprErr,
};

use graph::{
nodes::{Builtin, Context, ContextNode, ContextVar, ContextVarNode, ExprRet},
Expand All @@ -8,11 +10,15 @@ use shared::NodeIdx;

use solang_parser::pt::{Expression, Loc};

impl<T> PrecompileCaller for T where T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + CallerHelper
{}
impl<T> PrecompileCaller for T where
T: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + CallerHelper
{
}

/// Trait for calling precompile intrinsic functions, like `ecrecover`
pub trait PrecompileCaller: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + CallerHelper {
pub trait PrecompileCaller:
AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized + CallerHelper
{
/// Perform a precompile's function call, like `ecrecover`
fn precompile_call(
&mut self,
Expand Down
Loading

0 comments on commit 951ae0f

Please sign in to comment.