mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 19:03:27 +00:00
Refactor project structure
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
bd878dd1c9
commit
e3c227ae06
35
kernel/libs/comp-sys/component-macro/src/init_comp.rs
Normal file
35
kernel/libs/comp-sys/component-macro/src/init_comp.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use proc_macro2::{TokenStream, TokenTree};
|
||||
use quote::{ToTokens, TokenStreamExt};
|
||||
use syn::parse::Parse;
|
||||
|
||||
/// The content inside typeflag macro
|
||||
pub struct ComponentInitFunction {
|
||||
function: Vec<TokenTree>,
|
||||
pub function_name: TokenTree,
|
||||
}
|
||||
|
||||
impl Parse for ComponentInitFunction {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
let mut vec: Vec<TokenTree> = Vec::new();
|
||||
vec.push(input.parse().unwrap());
|
||||
let function_name: TokenTree = input.parse().unwrap();
|
||||
vec.push(function_name.clone());
|
||||
while !input.is_empty() {
|
||||
vec.push(input.parse().unwrap())
|
||||
}
|
||||
Ok(ComponentInitFunction {
|
||||
function: vec,
|
||||
function_name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for ComponentInitFunction {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
for token in &self.function {
|
||||
tokens.append(token.clone());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user