--- a/.maintain/scripts/generate_sol.sh +++ b/.maintain/scripts/generate_sol.sh @@ -11,4 +11,6 @@ formatted=$(mktemp) prettier --config $PRETTIER_CONFIG $raw > $formatted +sed -i -E -e "s/.+\/\/ FORMATTING: FORCE NEWLINE//g" $formatted + mv $formatted $OUTPUT --- a/crates/evm-coder/procedural/src/solidity_interface.rs +++ b/crates/evm-coder/procedural/src/solidity_interface.rs @@ -291,22 +291,40 @@ struct MethodInfo { rename_selector: Option, + hide: bool, } impl Parse for MethodInfo { fn parse(input: ParseStream) -> syn::Result { let mut rename_selector = None; - let lookahead = input.lookahead1(); - if lookahead.peek(kw::rename_selector) { - let k = input.parse::()?; - input.parse::()?; - if rename_selector - .replace(input.parse::()?.value()) - .is_some() - { - return Err(syn::Error::new(k.span(), "rename_selector is already set")); + let mut hide = false; + while !input.is_empty() { + let lookahead = input.lookahead1(); + if lookahead.peek(kw::rename_selector) { + let k = input.parse::()?; + input.parse::()?; + if rename_selector + .replace(input.parse::()?.value()) + .is_some() + { + return Err(syn::Error::new(k.span(), "rename_selector is already set")); + } + } else if lookahead.peek(kw::hide) { + input.parse::()?; + hide = true; + } else { + return Err(lookahead.error()); + } + + if input.peek(Token![,]) { + input.parse::()?; + } else if !input.is_empty() { + return Err(syn::Error::new(input.span(), "expected end")); } } - Ok(Self { rename_selector }) + Ok(Self { + rename_selector, + hide, + }) } } @@ -548,6 +566,7 @@ syn::custom_keyword!(expect_selector); syn::custom_keyword!(rename_selector); + syn::custom_keyword!(hide); } /// Rust methods are parsed into this structure when Solidity code is generated @@ -558,6 +577,7 @@ screaming_name: Ident, selector_str: String, selector: u32, + hide: bool, args: Vec, has_normal_args: bool, has_value_args: bool, @@ -570,6 +590,7 @@ fn try_from(value: &ImplItemMethod) -> syn::Result { let mut info = MethodInfo { rename_selector: None, + hide: false, }; let mut docs = Vec::new(); let mut weight = None; @@ -667,6 +688,7 @@ screaming_name: snake_ident_to_screaming(ident), selector_str, selector, + hide: info.hide, args, has_normal_args, has_value_args, @@ -826,12 +848,14 @@ let docs = &self.docs; let selector_str = &self.selector_str; let selector = self.selector; + let hide = self.hide; let is_payable = self.has_value_args; quote! { SolidityFunction { docs: &[#(#docs),*], selector_str: #selector_str, selector: #selector, + hide: #hide, name: #camel_name, mutability: #mutability, is_payable: #is_payable, --- a/crates/evm-coder/src/solidity.rs +++ b/crates/evm-coder/src/solidity.rs @@ -418,6 +418,7 @@ pub docs: &'static [&'static str], pub selector_str: &'static str, pub selector: u32, + pub hide: bool, pub name: &'static str, pub args: A, pub result: R, @@ -431,16 +432,21 @@ writer: &mut impl fmt::Write, tc: &TypeCollector, ) -> fmt::Result { + let hide_comment = self.hide.then(|| "// ").unwrap_or(""); for doc in self.docs { - writeln!(writer, "\t///{}", doc)?; + writeln!(writer, "\t{hide_comment}///{}", doc)?; } writeln!( writer, - "\t/// @dev EVM selector for this function is: 0x{:0>8x},", + "\t{hide_comment}/// @dev EVM selector for this function is: 0x{:0>8x},", self.selector )?; - writeln!(writer, "\t/// or in textual repr: {}", self.selector_str)?; - write!(writer, "\tfunction {}(", self.name)?; + writeln!( + writer, + "\t{hide_comment}/// or in textual repr: {}", + self.selector_str + )?; + write!(writer, "\t{hide_comment}function {}(", self.name)?; self.args.solidity_name(writer, tc)?; write!(writer, ")")?; if is_impl { @@ -463,22 +469,25 @@ } if is_impl { writeln!(writer, " {{")?; - writeln!(writer, "\t\trequire(false, stub_error);")?; + writeln!(writer, "\t{hide_comment}\trequire(false, stub_error);")?; self.args.solidity_get(writer)?; match &self.mutability { SolidityMutability::Pure => {} - SolidityMutability::View => writeln!(writer, "\t\tdummy;")?, - SolidityMutability::Mutable => writeln!(writer, "\t\tdummy = 0;")?, + SolidityMutability::View => writeln!(writer, "\t{hide_comment}\tdummy;")?, + SolidityMutability::Mutable => writeln!(writer, "\t{hide_comment}\tdummy = 0;")?, } if !self.result.is_empty() { - write!(writer, "\t\treturn ")?; + write!(writer, "\t{hide_comment}\treturn ")?; self.result.solidity_default(writer, tc)?; writeln!(writer, ";")?; } - writeln!(writer, "\t}}")?; + writeln!(writer, "\t{hide_comment}}}")?; } else { writeln!(writer, ";")?; } + if self.hide { + writeln!(writer, "// FORMATTING: FORCE NEWLINE")?; + } Ok(()) } }