Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
incertia committed Apr 4, 2024
1 parent b34ac24 commit c4bb707
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
4 changes: 3 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ fn main() -> ExitCode {
}

// Set up analysis runner.
let (mut runner, reports) = AnalysisRunner::new(options.curve).with_libraries(&options.libraries).with_files(&options.input_files);
let (mut runner, reports) = AnalysisRunner::new(options.curve)
.with_libraries(&options.libraries)
.with_files(&options.input_files);

// Set up writer and write reports to `stdout`.
let allow_list = options.allow_list.clone();
Expand Down
18 changes: 9 additions & 9 deletions parser/src/include_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub struct FileStack {

#[derive(Debug)]
struct Library {
dir: bool,
path: PathBuf,
dir: bool,
path: PathBuf,
}

impl FileStack {
Expand Down Expand Up @@ -92,9 +92,7 @@ impl FileStack {
}
Ok(())
}
Err(_) => {
self.include_library(include)
}
Err(_) => self.include_library(include),
}
}

Expand All @@ -117,17 +115,19 @@ impl FileStack {
} else {
// only match include paths with a single component i.e. lib.circom and not dir/lib.circom or
// ./lib.circom
if include.path.find(std::path::MAIN_SEPARATOR) == None && lib.path.file_name().expect("good library file") == pathos {
if include.path.find(std::path::MAIN_SEPARATOR) == None
&& lib.path.file_name().expect("good library file") == pathos
{
self.stack.push(lib.path.clone());
return Ok(());
}
}
}

let error = IncludeError {
path: include.path.clone(),
file_id: include.meta.file_id,
file_location: include.meta.file_location(),
path: include.path.clone(),
file_id: include.meta.file_id,
file_location: include.meta.file_location(),
};
Err(Box::new(error.into_report()))
}
Expand Down
6 changes: 5 additions & 1 deletion parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ pub enum ParseResult {
Library(Box<TemplateLibrary>, ReportCollection),
}

pub fn parse_files(file_paths: &[PathBuf], libraries: &[PathBuf], compiler_version: &Version) -> ParseResult {
pub fn parse_files(
file_paths: &[PathBuf],
libraries: &[PathBuf],
compiler_version: &Version,
) -> ParseResult {
let mut reports = ReportCollection::new();
let mut file_stack = FileStack::new(file_paths, libraries, &mut reports);
let mut file_library = FileLibrary::new();
Expand Down
37 changes: 19 additions & 18 deletions program_analysis/src/analysis_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,26 @@ impl AnalysisRunner {
}

pub fn with_libraries(mut self, libraries: &[PathBuf]) -> Self {
self.libraries.extend_from_slice(libraries);
self
self.libraries.extend_from_slice(libraries);
self
}

pub fn with_files(mut self, input_files: &[PathBuf]) -> (Self, ReportCollection) {
let reports = match parser::parse_files(input_files, &self.libraries, &config::COMPILER_VERSION) {
ParseResult::Program(program, warnings) => {
self.template_asts = program.templates;
self.function_asts = program.functions;
self.file_library = program.file_library;
warnings
}
ParseResult::Library(library, warnings) => {
self.template_asts = library.templates;
self.function_asts = library.functions;
self.file_library = library.file_library;
warnings
}
};
let reports =
match parser::parse_files(input_files, &self.libraries, &config::COMPILER_VERSION) {
ParseResult::Program(program, warnings) => {
self.template_asts = program.templates;
self.function_asts = program.functions;
self.file_library = program.file_library;
warnings
}
ParseResult::Library(library, warnings) => {
self.template_asts = library.templates;
self.function_asts = library.functions;
self.file_library = library.file_library;
warnings
}
};
(self, reports)
}

Expand Down Expand Up @@ -223,7 +224,7 @@ impl AnalysisRunner {
// Get the AST corresponding to the template.
let Some(ast) = self.template_asts.get(name) else {
trace!("failed to lift unknown template `{name}`");
return Err(AnalysisError::UnknownTemplate { name: name.to_string() })
return Err(AnalysisError::UnknownTemplate { name: name.to_string() });
};
// Generate the template CFG from the AST. Cache any reports.
let mut reports = ReportCollection::new();
Expand All @@ -249,7 +250,7 @@ impl AnalysisRunner {
// Get the AST corresponding to the function.
let Some(ast) = self.function_asts.get(name) else {
trace!("failed to lift unknown function `{name}`");
return Err(AnalysisError::UnknownFunction { name: name.to_string() })
return Err(AnalysisError::UnknownFunction { name: name.to_string() });
};
// Generate the function CFG from the AST. Cache any reports.
let mut reports = ReportCollection::new();
Expand Down

0 comments on commit c4bb707

Please sign in to comment.