use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::ItemTrait;
use crate::TraitBounds;
use crate::apply::err_ty;
use crate::ast::{Expand, Op};
use crate::codegen::generate_impl;
use crate::parse::parse_item;
use crate::util::Cursor;
pub(crate) fn parse_batch_trait_entry(
cursor: &mut Cursor, top_level: Op, trait_full_path: &TokenStream,
trait_last_ident: &Ident, is_unsafe_trait: bool, start_trait: Option<ItemTrait>,
trait_bounds: &TraitBounds,
) -> TokenStream {
let mut tys = vec![];
if cursor.is_punct(',') {
tys.push(err_ty("batch-impl: spec 列表不能以 `,` 开头"));
}
while let Some(ty) = parse_item(cursor, top_level, trait_last_ident.into()) {
let mut queue = vec![ty];
while let Some(item) = queue.pop() {
match item.expand() {
Expand::Many(expanded) => {
for e in expanded.into_iter().rev() {
queue.push(e);
}
}
Expand::Leaf(leaf) => tys.push(leaf),
}
}
}
let mut impls = start_trait.map_or(quote![], |t| quote![#t]);
for t in tys {
impls.extend(generate_impl(
t,
trait_full_path,
is_unsafe_trait,
trait_bounds,
));
}
impls
}