Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bolos-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ edition = "2018"
proc-macro = true

[dependencies]
syn = { version = "1.0", features = ["full", "extra-traits", "visit"] }
quote = "1.0"
proc-macro2 = "1"
proc-macro-error = { version = "1" }
syn = { version = "2.0.106", features = ["full", "extra-traits", "visit"] }
quote = "1.0.40"
proc-macro2 = "1.0.101"

convert_case = "0.6"
convert_case = "0.8.0"

[dev-dependencies]
bolos = { path = "../bolos" }
7 changes: 2 additions & 5 deletions bolos-derive/src/enum_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
********************************************************************************/
use proc_macro::TokenStream;
use proc_macro_error::{abort, abort_if_dirty};
use quote::{quote, ToTokens};
use syn::{
parse_macro_input, parse_quote, parse_quote_spanned, punctuated::Punctuated, token::Comma,
Expand Down Expand Up @@ -74,6 +73,7 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream {
&Field {
attrs: variant.attrs.clone(),
vis: Visibility::Inherited,
mutability: syn::FieldMutability::None,
ident: None,
colon_token: None,
ty: inner.clone(),
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream {

let unnamed = &unnamed.unnamed;
if unnamed.len() != 1 {
abort!(variant.ident.span(), "only 1 item in field supported")
panic!("only 1 item in field supported")
} else {
let field = unnamed.first().unwrap();
let variant_struct = create_variant_struct_for_unnamed(
Expand Down Expand Up @@ -137,9 +137,6 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream {
}
});

//if we emitted errors let's abort before we emit weird data
abort_if_dirty();

quote! {
#type_enum

Expand Down
14 changes: 8 additions & 6 deletions bolos-derive/src/lazy_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use syn::{
parse_macro_input, spanned::Spanned, AttributeArgs, Error, Expr, Ident, ItemStatic, Meta,
NestedMeta, Token, Type,
parse::Parser, parse_macro_input, punctuated::Punctuated, spanned::Spanned, Error, Expr, Ident,
ItemStatic, Meta, Token, Type,
};

pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream {
let args = parse_macro_input!(metadata as AttributeArgs);
let args = Punctuated::<Meta, Token![,]>::parse_terminated
.parse(metadata)
.unwrap();
let input = parse_macro_input!(input as ItemStatic);

let ItemStatic {
Expand All @@ -39,7 +41,7 @@ pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream {
&name,
*ty,
*expr,
mutability.is_some(),
matches!(mutability, syn::StaticMutability::Mut(_)),
is_cbindgen_mode(&args),
)
.map_err(|e| e.into_compile_error())
Expand Down Expand Up @@ -242,9 +244,9 @@ fn produce_custom_ty(
// For example, it will return true for
//#[attr(cbindgen)]
#[allow(clippy::ptr_arg)]
fn is_cbindgen_mode(args: &AttributeArgs) -> bool {
fn is_cbindgen_mode(args: &Punctuated<Meta, Token![,]>) -> bool {
for arg in args {
if let NestedMeta::Meta(Meta::Path(path)) = arg {
if let Meta::Path(path) = arg {
if path
.segments
.iter()
Expand Down
3 changes: 0 additions & 3 deletions bolos-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemStatic};

use proc_macro_error::proc_macro_error;

pub(crate) mod utils;

// #[bolos::nvm]
Expand Down Expand Up @@ -123,7 +121,6 @@ pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream {

mod enum_init;

#[proc_macro_error]
#[proc_macro_attribute]
/// The aim of this macro is to ease the writing of boilerplate for enums
/// where we want to initialize said enum using [`MaybeUninit`].
Expand Down
15 changes: 7 additions & 8 deletions bolos-derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
use proc_macro_error::emit_error;
use syn::{
punctuated::Punctuated, spanned::Spanned, visit::Visit, Attribute, GenericArgument,
GenericParam, Generics, Ident, Type, TypePath,
punctuated::Punctuated, visit::Visit, Attribute, GenericArgument, GenericParam, Generics,
Ident, Type, TypePath,
};

/// Helper extension iterator to `syn` things
Expand Down Expand Up @@ -68,7 +67,7 @@ impl<'ast> GenericArgumentsCollector<'ast> {
Type::Array(i) => this.visit_type_array(i),
Type::Path(i) => this.visit_type_path(i),
Type::Tuple(i) => this.visit_type_tuple(i),
_ => emit_error!(ty.span(), "unsupported type"),
_ => panic!("unsupported type"),
}

this
Expand Down Expand Up @@ -97,9 +96,9 @@ impl<'ast> GenericArgumentsCollector<'ast> {
impl<'ast> Visit<'ast> for GenericArgumentsCollector<'ast> {
fn visit_parenthesized_generic_arguments(
&mut self,
i: &'ast syn::ParenthesizedGenericArguments,
_i: &'ast syn::ParenthesizedGenericArguments,
) {
emit_error!(i.span(), "paranthesized generics arguments not supported")
panic!("paranthesized generics arguments not supported")
}

fn visit_generic_argument(&mut self, i: &'ast GenericArgument) {
Expand Down Expand Up @@ -186,7 +185,7 @@ impl<'ast> Visit<'ast> for GenericParamsCollector<'ast> {
pub fn remove_doc_comment_attributes(attrs: Vec<Attribute>) -> Vec<Attribute> {
attrs
.into_iter()
.filter(|a| !a.path.is_ident("doc"))
.filter(|a| !a.path().is_ident("doc"))
.collect()
}

Expand All @@ -196,7 +195,7 @@ pub fn remove_doc_comment_attributes(attrs: Vec<Attribute>) -> Vec<Attribute> {
pub fn cfg_variant_attributes(attrs: Vec<Attribute>) -> Vec<Attribute> {
attrs
.into_iter()
.filter(|a| a.path.is_ident("cfg"))
.filter(|a| a.path().is_ident("cfg"))
.collect()
}

Expand Down
Loading