Min codegen

This commit is contained in:
Emil Fresk 2023-01-03 15:10:59 +01:00 committed by Henrik Tjäder
parent 244b085bcb
commit b1ae562d4f
22 changed files with 129 additions and 1694 deletions

View file

@ -3,8 +3,8 @@ use syn::{
parse::{self, ParseStream},
punctuated::Punctuated,
spanned::Spanned,
Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, PatType, Path,
PathArguments, ReturnType, Token, Type, Visibility,
Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, Path, PathArguments,
ReturnType, Token, Type, Visibility,
};
use crate::syntax::{
@ -231,29 +231,23 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalRes
Ok(resources)
}
type ParseInputResult = Option<(Box<Pat>, Result<Vec<PatType>, FnArg>)>;
pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> ParseInputResult {
pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> Option<Box<Pat>> {
let mut inputs = inputs.into_iter();
match inputs.next() {
Some(FnArg::Typed(first)) => {
if type_is_path(&first.ty, &[name, "Context"]) {
let rest = inputs
.map(|arg| match arg {
FnArg::Typed(arg) => Ok(arg),
_ => Err(arg),
})
.collect::<Result<Vec<_>, _>>();
Some((first.pat, rest))
} else {
None
// No more inputs
if inputs.next().is_none() {
return Some(first.pat);
}
}
}
_ => None,
_ => {}
}
None
}
pub fn type_is_bottom(ty: &ReturnType) -> bool {