use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::ItemTrait;
use crate::apply::err_ty;
use crate::codegen::generate_impl;
use crate::parse::parse_item;
use crate::scan::Cursor;
use crate::types::{Expand, Op};
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>,
) -> 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));
}
impls
}