Skip to content

Commit

Permalink
Update syn and darling dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
EliseChouleur committed Oct 2, 2023
1 parent 40b8762 commit 7a10e96
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 70 deletions.
4 changes: 2 additions & 2 deletions robusta-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ proc-macro = true
[dependencies]
quote = "^1"
proc-macro2 = { version = "1.0.21", features = ["span-locations"]}
syn = { version = "^1", features = ["visit", "fold", "derive"] }
syn = { version = "^2", features = ["visit", "fold", "derive"] }
proc-macro-error = { version = "1", default-features = false }
rand = "^0"
darling = "^0.14"
darling = "^0"
Inflector = "0.11.4"
16 changes: 8 additions & 8 deletions robusta-codegen/src/derive/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use crate::derive::utils::generic_params_to_args;
use crate::transformation::JavaPath;
use proc_macro2::{Ident, TokenStream};
use proc_macro_error::{abort, emit_error, emit_warning};
use quote::{quote, quote_spanned};
use quote::{quote, quote_spanned, ToTokens};
use syn::spanned::Spanned;
use syn::{
AngleBracketedGenericArguments, Data, DataStruct, DeriveInput, Field, GenericArgument,
GenericParam, Generics, LifetimeDef, PathArguments, Type, TypePath,
GenericParam, Generics, LifetimeParam, PathArguments, Type, TypePath,
};

struct TraitAutoDeriveData {
Expand Down Expand Up @@ -280,7 +280,7 @@ fn get_trait_impl_components(trait_name: &str, input: DeriveInput) -> TraitAutoD
match input.data {
Data::Struct(DataStruct { fields, .. }) => {
let package_attr = input.attrs.iter().find(|a| {
a.path.get_ident().map(ToString::to_string).as_deref() == Some("package")
a.path().get_ident().map(ToString::to_string).as_deref() == Some("package")
});
if package_attr.is_none() {
abort!(input_span, "missing `#[package]` attribute")
Expand All @@ -303,7 +303,7 @@ fn get_trait_impl_components(trait_name: &str, input: DeriveInput) -> TraitAutoD
"".to_string()
});

let lifetimes: HashMap<String, &LifetimeDef> = input
let lifetimes: HashMap<String, &LifetimeParam> = input
.generics
.params
.iter()
Expand Down Expand Up @@ -335,7 +335,7 @@ fn get_trait_impl_components(trait_name: &str, input: DeriveInput) -> TraitAutoD
.iter()
.filter_map(|f| {
let attr = f.attrs.iter().find(|a| {
a.path.get_ident().map(|i| i.to_string()).as_deref() == Some("instance")
a.path().get_ident().map(|i| i.to_string()).as_deref() == Some("instance")
});
attr.map(|a| (f, a))
})
Expand All @@ -345,7 +345,7 @@ fn get_trait_impl_components(trait_name: &str, input: DeriveInput) -> TraitAutoD
.iter()
.filter(|f| {
let attr = f.attrs.iter().find(|a| {
a.path.get_ident().map(|i| i.to_string()).as_deref() == Some("field")
a.path().get_ident().map(|i| i.to_string()).as_deref() == Some("field")
});
attr.is_some()
})
Expand All @@ -363,9 +363,9 @@ fn get_trait_impl_components(trait_name: &str, input: DeriveInput) -> TraitAutoD
match instance_field_data {
None => abort!(input_span, "missing `#[instance] field attribute"),
Some((instance, attr)) => {
if !attr.tokens.is_empty() {
if !attr.into_token_stream().is_empty() {
emit_warning!(
attr.tokens,
attr.into_token_stream(),
"`#[instance]` attribute doesn't have any arguments"
)
}
Expand Down
2 changes: 1 addition & 1 deletion robusta-codegen/src/derive/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn signature_macro_derive_impl(input: DeriveInput) -> syn::Result<TokenStream> {
match input.data {
Data::Struct(DataStruct { .. }) => {
let package_attr = input.attrs.iter().find(|a| {
a.path.get_ident().map(ToString::to_string).as_deref() == Some("package")
a.path().get_ident().map(ToString::to_string).as_deref() == Some("package")
});

match package_attr {
Expand Down
4 changes: 2 additions & 2 deletions robusta-codegen/src/transformation/context.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::transformation::JavaPath;
use syn::{LifetimeDef, Path};
use syn::{LifetimeParam, Path};

#[derive(Clone)]
pub(crate) struct StructContext {
pub(crate) struct_type: Path,
pub(crate) struct_name: String,
pub(crate) struct_lifetimes: Vec<LifetimeDef>,
pub(crate) struct_lifetimes: Vec<LifetimeParam>,
pub(crate) package: Option<JavaPath>,
}
38 changes: 18 additions & 20 deletions robusta-codegen/src/transformation/exported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use syn::spanned::Spanned;
use syn::token::Extern;
use syn::Lifetime;
use syn::Token;
use syn::{parse_quote, GenericParam, Generics, LifetimeDef, TypeTuple};
use syn::{parse_quote, GenericParam, Generics, LifetimeParam, TypeTuple};
use syn::{
Abi, Block, Expr, FnArg, ImplItemMethod, LitStr, Pat, PatIdent, PatType, ReturnType, Signature,
Type, VisPublic, Visibility,
Abi, Block, Expr, FnArg, ImplItemFn, LitStr, Pat, PatIdent, PatType, ReturnType, Signature,
Type, Visibility,
};

use crate::transformation::context::StructContext;
Expand All @@ -26,7 +26,7 @@ pub struct ExportedMethodTransformer<'ctx> {
}

impl<'ctx> Fold for ExportedMethodTransformer<'ctx> {
fn fold_impl_item_method(&mut self, node: ImplItemMethod) -> ImplItemMethod {
fn fold_impl_item_fn(&mut self, node: ImplItemFn) -> ImplItemFn {
let abi = get_abi(&node.sig);
match (&node.vis, &abi.as_deref()) {
(Visibility::Public(_), Some("jni")) => {
Expand All @@ -36,7 +36,7 @@ impl<'ctx> Fold for ExportedMethodTransformer<'ctx> {

let mut jni_method_transformer =
ExternJNIMethodTransformer::new(self.struct_context, call_type_attribute);
jni_method_transformer.fold_impl_item_method(node)
jni_method_transformer.fold_impl_item_fn(node)
}
_ => node,
}
Expand All @@ -58,7 +58,7 @@ impl<'ctx> ExternJNIMethodTransformer<'ctx> {
}

impl<'ctx> Fold for ExternJNIMethodTransformer<'ctx> {
fn fold_impl_item_method(&mut self, node: ImplItemMethod) -> ImplItemMethod {
fn fold_impl_item_fn(&mut self, node: ImplItemFn) -> ImplItemFn {
let jni_signature = JNISignature::new(
node.sig.clone(),
&self.struct_context,
Expand Down Expand Up @@ -197,17 +197,15 @@ impl<'ctx> Fold for ExternJNIMethodTransformer<'ctx> {
.into_iter()
.filter(|a| {
!discarded_known_attributes
.contains(&a.path.segments.to_token_stream().to_string().as_str())
.contains(&a.path().segments.to_token_stream().to_string().as_str())
})
.collect()
};

let node_span = node.span();
ImplItemMethod {
ImplItemFn {
attrs: impl_item_attributes,
vis: Visibility::Public(VisPublic {
pub_token: Token![pub](node_span),
}),
vis: Visibility::Public(Token![pub](node_span)),
defaultness: node.defaultness,
sig: self.fold_signature(node.sig),
block: new_block,
Expand Down Expand Up @@ -281,11 +279,11 @@ mod test {
package: Option<JavaPath>,
struct_name: String,
method_name: String,
) -> ImplItemMethod {
) -> ImplItemFn {
let struct_name_token_stream = TokenStream::from_str(&struct_name).unwrap();
let method_name_token_stream = TokenStream::from_str(&method_name).unwrap();

let method: ImplItemMethod =
let method: ImplItemFn =
parse_quote! { pub extern "jni" fn #method_name_token_stream() {} };
let struct_context = StructContext {
struct_type: parse_quote! { #struct_name_token_stream },
Expand Down Expand Up @@ -339,13 +337,13 @@ mod test {
assert_eq!(output.sig.abi.unwrap().name.unwrap().value(), "system")
}

fn setup_with_params(params: TokenStream, struct_name: String) -> ImplItemMethod {
fn setup_with_params(params: TokenStream, struct_name: String) -> ImplItemFn {
let package = None;
let method_name = "foo".to_string();
let struct_name_token_stream = TokenStream::from_str(&struct_name).unwrap();
let method_name_token_stream = TokenStream::from_str(&method_name).unwrap();

let method: ImplItemMethod = parse_quote! {
let method: ImplItemFn = parse_quote! {
pub extern "jni" fn #method_name_token_stream(#params) -> i32 {}
};

Expand Down Expand Up @@ -453,14 +451,14 @@ mod test {

struct JNISignatureTransformer {
struct_freestanding_transformer: FreestandingTransformer,
struct_lifetimes: Vec<LifetimeDef>,
struct_lifetimes: Vec<LifetimeParam>,
call_type: CallType,
}

impl JNISignatureTransformer {
fn new(
struct_freestanding_transformer: FreestandingTransformer,
struct_lifetimes: Vec<LifetimeDef>,
struct_lifetimes: Vec<LifetimeParam>,
call_type: CallType,
) -> Self {
JNISignatureTransformer {
Expand Down Expand Up @@ -509,7 +507,7 @@ impl JNISignatureTransformer {

e.bounds.push(borrow_lifetime_value.clone());

generics.params.push(GenericParam::Lifetime(LifetimeDef {
generics.params.push(GenericParam::Lifetime(LifetimeParam {
attrs: vec![],
lifetime: borrow_lifetime_value,
colon_token: None,
Expand All @@ -526,7 +524,7 @@ impl JNISignatureTransformer {
ident: Ident::new("borrow", generics_span),
};

generics.params.push(GenericParam::Lifetime(LifetimeDef {
generics.params.push(GenericParam::Lifetime(LifetimeParam {
attrs: vec![],
lifetime: Lifetime {
apostrophe: generics_span,
Expand All @@ -540,7 +538,7 @@ impl JNISignatureTransformer {
},
}));

generics.params.push(GenericParam::Lifetime(LifetimeDef {
generics.params.push(GenericParam::Lifetime(LifetimeParam {
attrs: vec![],
lifetime: borrow_lifetime_value,
colon_token: None,
Expand Down
22 changes: 11 additions & 11 deletions robusta-codegen/src/transformation/imported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use quote::{quote_spanned, ToTokens};
use syn::fold::Fold;
use syn::spanned::Spanned;
use syn::{parse_quote, GenericArgument, PathArguments, Type, TypePath};
use syn::{FnArg, ImplItemMethod, Lit, Pat, PatIdent, ReturnType, Signature};
use syn::{FnArg, ImplItemFn, Lit, Pat, PatIdent, ReturnType, Signature};

use crate::transformation::context::StructContext;
use crate::transformation::utils::get_call_type;
Expand All @@ -18,19 +18,19 @@ pub struct ImportedMethodTransformer<'ctx> {
}

impl<'ctx> Fold for ImportedMethodTransformer<'ctx> {
fn fold_impl_item_method(&mut self, node: ImplItemMethod) -> ImplItemMethod {
fn fold_impl_item_fn(&mut self, node: ImplItemFn) -> ImplItemFn {
let abi = get_abi(&node.sig);
match (&node.vis, &abi.as_deref()) {
(_, Some("java")) => {
let constructor_attribute = node.attrs.iter().find(|a| {
a.path.get_ident().map(ToString::to_string).as_deref() == Some("constructor")
a.path().get_ident().map(ToString::to_string).as_deref() == Some("constructor")
});
let is_constructor = {
match constructor_attribute {
Some(a) => {
if !a.tokens.is_empty() {
if !a.to_token_stream().is_empty() {
emit_warning!(
a.tokens,
a.to_token_stream(),
"#[constructor] attribute does not take parameters"
)
}
Expand Down Expand Up @@ -67,12 +67,12 @@ impl<'ctx> Fold for ImportedMethodTransformer<'ctx> {
.into_iter()
.filter(|a| {
!discarded_known_attributes
.contains(&a.path.segments.to_token_stream().to_string().as_str())
.contains(&a.path().segments.to_token_stream().to_string().as_str())
})
.collect()
};

let dummy = ImplItemMethod {
let dummy = ImplItemFn {
sig: Signature {
abi: None,
..original_signature.clone()
Expand Down Expand Up @@ -159,9 +159,9 @@ impl<'ctx> Fold for ImportedMethodTransformer<'ctx> {
})
.map(|(t, span, attrs)| {
let override_input_type = attrs.iter().find(|attr| {
attr.path.segments.iter().find(|seg| seg.ident.to_string().as_str() == "input_type").is_some()
attr.path().segments.iter().find(|seg| seg.ident.to_string().as_str() == "input_type").is_some()
}).and_then(|a| {
let token_tree: Group = syn::parse2::<Group>(a.clone().tokens).unwrap();
let token_tree: Group = syn::parse2::<Group>(a.clone().to_token_stream()).unwrap();
let token_tree_lit: Lit = syn::parse2::<Lit>(token_tree.stream()).unwrap();

if let Lit::Str(literal) = token_tree_lit {
Expand Down Expand Up @@ -330,7 +330,7 @@ impl<'ctx> Fold for ImportedMethodTransformer<'ctx> {
.clone()
.into_iter()
.filter(|a| {
!a.path
!a.path()
.segments
.iter()
.find(|s| {
Expand All @@ -346,7 +346,7 @@ impl<'ctx> Fold for ImportedMethodTransformer<'ctx> {
FnArg::Receiver(_) => {}
});

ImplItemMethod {
ImplItemFn {
sig: Signature {
abi: None,
..original_signature
Expand Down
Loading

0 comments on commit 7a10e96

Please sign in to comment.