From d05948644228075a1545eaecd4300405ab3621d8 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 3 Nov 2023 16:14:30 +0100 Subject: [PATCH] refactor: Accept Grammar by ref during codegen It's more idiomatic to use implicit Deref and accept arguments by-ref if we do not need to know about the specific container/wrapper they're in. --- crates/codegen/parser/generator/src/code_generator.rs | 3 +-- crates/solidity/outputs/cargo/build/src/main.rs | 2 +- crates/solidity/outputs/npm/build/src/main.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/codegen/parser/generator/src/code_generator.rs b/crates/codegen/parser/generator/src/code_generator.rs index 2ab13c88d6..63fb5c578b 100644 --- a/crates/codegen/parser/generator/src/code_generator.rs +++ b/crates/codegen/parser/generator/src/code_generator.rs @@ -2,7 +2,6 @@ use std::{ collections::{BTreeMap, BTreeSet}, mem, path::PathBuf, - rc::Rc, }; use anyhow::Result; @@ -58,7 +57,7 @@ struct ScannerContext { } impl CodeGenerator { - pub fn write_source(output_dir: &PathBuf, grammar: Rc) -> Result<()> { + pub fn write_source(output_dir: &PathBuf, grammar: &Grammar) -> Result<()> { let mut code = Self::default(); grammar.accept_visitor(&mut code); let code = &code; diff --git a/crates/solidity/outputs/cargo/build/src/main.rs b/crates/solidity/outputs/cargo/build/src/main.rs index 36790bfc75..48f1999d2b 100644 --- a/crates/solidity/outputs/cargo/build/src/main.rs +++ b/crates/solidity/outputs/cargo/build/src/main.rs @@ -20,7 +20,7 @@ fn main() -> Result<()> { let grammar = Grammar::from_dsl_v1(); let crate_dir = CargoWorkspace::locate_source_crate("slang_solidity")?; - CodeGenerator::write_source(&crate_dir.join("src/generated"), grammar)?; + CodeGenerator::write_source(&crate_dir.join("src/generated"), &grammar)?; } // This build script is not directly depended on by the caller source crate, so we need to manually diff --git a/crates/solidity/outputs/npm/build/src/main.rs b/crates/solidity/outputs/npm/build/src/main.rs index d7e25987e7..ab93f61f60 100644 --- a/crates/solidity/outputs/npm/build/src/main.rs +++ b/crates/solidity/outputs/npm/build/src/main.rs @@ -20,7 +20,7 @@ fn main() -> Result<()> { let grammar = Grammar::from_dsl_v1(); let crate_dir = CargoWorkspace::locate_source_crate("solidity_npm_crate")?; - CodeGenerator::write_source(&crate_dir.join("src/generated"), grammar)?; + CodeGenerator::write_source(&crate_dir.join("src/generated"), &grammar)?; } // This build script is not directly depended on by the caller source crate, so we need to manually