Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Jul 10, 2024
1 parent c6255b8 commit 4c6ec8f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion crates/graph/src/nodes/context/var/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
elem::{RangeElem, RangeExpr, RangeOp},
RangeEval,
},
AnalyzerBackend, ContextEdge, Edge, GraphBackend, GraphError, Node, TypeNode, VarType,
AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, TypeNode, VarType,
};

use shared::{GraphError, RangeArena, Search, StorageLocation};
Expand Down
2 changes: 1 addition & 1 deletion crates/graph/src/nodes/context/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
nodes::{
ContextNode, ContextVarNode, EnumNode, ErrorNode, ExprRet, StructNode, TyNode, VarNode,
},
AnalyzerBackend, ContextEdge, Edge, GraphBackend, GraphError, Node, TypeNode,
AnalyzerBackend, ContextEdge, Edge, GraphBackend, Node, TypeNode,
};
use shared::GraphError;

Expand Down
21 changes: 11 additions & 10 deletions crates/graph/src/nodes/debug_reconstruction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
nodes::{ContractNode, EnumNode, ErrorNode, FunctionNode, StructNode, TyNode, VarNode},
AnalyzerBackend, AsDotStr, Edge, GraphError, TypeNode,
AnalyzerBackend, Edge, TypeNode,
};

use petgraph::{visit::EdgeRef, Direction};
use shared::GraphError;
use solang_parser::pt::Loc;

use std::collections::BTreeMap;
Expand Down Expand Up @@ -74,7 +75,7 @@ impl ContractNode {
let file_no = loc.try_file_no().unwrap();
let name_loc = self.underlying(analyzer)?.name.clone().unwrap().loc;
loc.use_end_from(&name_loc);
Ok(&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()])
Ok(&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()])
}

pub fn reconstruct_inherits(
Expand Down Expand Up @@ -142,7 +143,7 @@ impl ContractNode {
let file_no = loc.try_file_no().unwrap();
format!(
"{};",
&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()]
&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()]
)
})
.collect::<Vec<_>>()
Expand Down Expand Up @@ -470,15 +471,15 @@ impl FunctionNode {
// let overriding = self.get_overriding(analyzer)?;
if let Some(body_loc) = self.body_loc(analyzer)? {
let body =
&analyzer.source_map().get(&file_no).unwrap()[body_loc.start()..body_loc.end()];
&analyzer.file_mapping().get(&file_no).unwrap()[body_loc.start()..body_loc.end()];
Ok(format!(
"{} {body}",
&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()]
&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()]
))
} else {
Ok(format!(
"{};",
&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()]
&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()]
))
}
}
Expand Down Expand Up @@ -513,7 +514,7 @@ impl TyNode {
let file_no = loc.try_file_no().unwrap();
Ok(format!(
"{};\n",
&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()]
&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()]
))
}
}
Expand All @@ -524,7 +525,7 @@ impl EnumNode {
let file_no = loc.try_file_no().unwrap();
Ok(format!(
"{}\n",
&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()]
&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()]
))
}
}
Expand All @@ -535,7 +536,7 @@ impl StructNode {
let file_no = loc.try_file_no().unwrap();
Ok(format!(
"{}\n",
&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()]
&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()]
))
}
}
Expand All @@ -546,7 +547,7 @@ impl ErrorNode {
let file_no = loc.try_file_no().unwrap();
Ok(format!(
"{};\n",
&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()]
&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()]
))
}
}
2 changes: 1 addition & 1 deletion crates/graph/src/nodes/enum_ty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
nodes::{Concrete, ContractNode},
range::elem::Elem,
AsDotStr, Edge, GraphBackend, GraphError, Node, SolcRange,
AsDotStr, Edge, GraphBackend, Node, SolcRange,
};

use shared::{GraphError, NodeIdx, RangeArena};
Expand Down
2 changes: 1 addition & 1 deletion crates/graph/src/nodes/var_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl VarNode {
) -> Result<&'a str, GraphError> {
let loc = self.underlying(analyzer)?.loc;
let file_no = loc.try_file_no().unwrap();
Ok(&analyzer.source_map().get(&file_no).unwrap()[loc.start()..loc.end()])
Ok(&analyzer.file_mapping().get(&file_no).unwrap()[loc.start()..loc.end()])
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/pyrometer/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use graph::elem::Elem;
use graph::{nodes::*, ContextEdge, Edge, Node, VarType};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use shared::{AnalyzerLike, ApplyStats, GraphLike, NodeIdx, Search};
use shared::{ExprErr, IntoExprErr, RangeArena, USE_DEBUG_SITE};
use solc_expressions::{FnCallBuilder, StatementParser};
use tokio::runtime::Runtime;
use tracing::{error, trace, warn};
use shared::{AnalyzerLike, ApplyStats, GraphLike, NodeIdx, Search};
use solc_expressions::{FnCallBuilder, IntoExprErr, StatementParser};

use ahash::AHashMap;
use ariadne::{Cache, Color, Config, Fmt, Label, Report, ReportKind, Source, Span};
Expand Down
14 changes: 5 additions & 9 deletions crates/pyrometer/src/analyzer_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use graph::{
},
AnalyzerBackend, Edge, GraphBackend, Node, TypeNode, VarType,
};
use shared::{AnalyzerLike, ExprErr, IntoExprErr, ApplyStats, GraphLike, NodeIdx, RangeArena};
use shared::{AnalyzerLike, ApplyStats, ExprErr, GraphLike, IntoExprErr, NodeIdx, RangeArena};

use ahash::AHashMap;
use ethers_core::types::U256;
use solang_parser::{
helpers::CodeLocation,
pt::{Expression, Loc},
};
use solc_expressions::{ExprErr, IntoExprErr};

use std::collections::BTreeMap;
use std::io::Write;
Expand Down Expand Up @@ -507,14 +506,11 @@ impl AnalyzerLike for Analyzer {
&mut self.handled_funcs
}

fn file_mapping(&self) -> BTreeMap<usize, String> {
let mut file_mapping: BTreeMap<usize, String> = BTreeMap::new();
for (source_path, _, o_file_no, _) in self.sources.iter() {
fn file_mapping(&self) -> BTreeMap<usize, &str> {
let mut file_mapping: BTreeMap<usize, &str> = BTreeMap::new();
for (_, sol, o_file_no, _) in self.sources.iter() {
if let Some(file_no) = o_file_no {
file_mapping.insert(
*file_no,
source_path.path_to_solidity_source().display().to_string(),
);
file_mapping.insert(*file_no, sol);
}
}
file_mapping
Expand Down
8 changes: 4 additions & 4 deletions crates/pyrometer/src/graph_backend.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::Analyzer;
use graph::elem::RangeElem;
use graph::nodes::Concrete;
use graph::{
as_dot_str,
elem::Elem,
elem::RangeElem,
nodes::Concrete,
nodes::{ContextNode, ContextVarNode},
AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, Node,
AnalyzerBackend, AsDotStr, ContextEdge, Edge, GraphBackend, Node, TOKYO_NIGHT_COLORS,
};
use graph::{elem::Elem, nodes::ContextVarNode, TOKYO_NIGHT_COLORS};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use shared::RangeArena;
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/analyzer_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub trait AnalyzerLike: GraphLike {
fn apply_stats_mut(&mut self) -> &mut ApplyStats;
fn handled_funcs(&self) -> &[Self::FunctionNode];
fn handled_funcs_mut(&mut self) -> &mut Vec<Self::FunctionNode>;
fn file_mapping(&self) -> BTreeMap<usize, String>;
fn file_mapping(&self) -> BTreeMap<usize, &str>;
fn minimize_debug(&self) -> &Option<String>;
fn minimize_err(&mut self, ctx: Self::ContextNode) -> String;
}
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use graph::{
nodes::{Concrete, ContextNode, ContextVar, ContextVarNode, ExprRet, VarNode},
AnalyzerBackend, ContextEdge, Edge, Node, VarType,
};
use shared::{ExprErr, GraphError, IntoExprErr, RangeArena};
use shared::{ExprErr, GraphError, IntoExprErr, NodeIdx, RangeArena};

use solang_parser::pt::{Expression, Identifier, Loc, StorageLocation, VariableDeclaration};

Expand Down
2 changes: 1 addition & 1 deletion crates/solc-expressions/src/yul/yul_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub trait YulBuilder:
HexStringLiteral(lit, _) => self.hex_literals(ctx, &[lit.clone()]),
StringLiteral(lit, _) => self.string_literal(ctx, lit.loc, &lit.string),
Variable(ident) => {
self.variable(arena, ident, ctx, None)?;
self.variable(arena, ident, ctx, None, None)?;
self.apply_to_edges(ctx, ident.loc, arena, &|analyzer, _arena, edge_ctx, loc| {
if let Some(ret) = edge_ctx.pop_expr_latest(loc, analyzer).into_expr_err(loc)? {
if ContextVarNode::from(ret.expect_single().into_expr_err(loc)?)
Expand Down

0 comments on commit 4c6ec8f

Please sign in to comment.