pub fn analyze(artifact: &Artifact) -> Result<AnalysisResult, AnalysisError>Expand description
Performs comprehensive analysis of Solidity source code.
This is the main entry point for source code analysis. It compiles the provided Solidity input, processes the AST, and performs step-by-step analysis to extract debugging information.
§Arguments
input- The Solc versioned input containing source files and compilation settings
§Returns
Returns an AnalysisResult containing all analysis data, or an AnalysisError
if compilation or analysis fails.
§Process Overview
- Compilation: Uses the Solc compiler to compile the source code
- AST Processing: Parses and prunes the AST for each source file
- Parallel Analysis: Analyzes each source file in parallel
- Step Partitioning: Divides source code into executable steps
- Hook Generation: Creates pre and post-execution hooks for each step
- Index Building: Builds lookup tables for steps and variables
§Example
use foundry_compilers::solc::SolcVersionedInput;
use crate::analysis::common::analyze;
// Create your SolcVersionedInput
let input = SolcVersionedInput::build(/* ... */);
// Run the analysis
match analyze(input) {
Ok(result) => {
println!("Analysis completed successfully");
println!("Files analyzed: {}", result.sources.len());
println!("Total steps: {}", result.usid_to_step.len());
}
Err(e) => eprintln!("Analysis failed: {}", e),
}§Errors
This function can return the following errors:
AnalysisError::StepPartitionError: When step partitioning fails