mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2024-11-27 09:50:41 +00:00
Consolidate Operand code
This commit is contained in:
parent
097b9cec00
commit
e627fa8983
@ -17,6 +17,7 @@ mod fold;
|
||||
mod full;
|
||||
mod gen;
|
||||
mod json;
|
||||
mod operand;
|
||||
mod parse;
|
||||
mod version;
|
||||
mod visit;
|
||||
|
38
codegen/src/operand.rs
Normal file
38
codegen/src/operand.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
pub enum Operand {
|
||||
Borrowed(TokenStream),
|
||||
Owned(TokenStream),
|
||||
}
|
||||
|
||||
pub use self::Operand::*;
|
||||
|
||||
impl Operand {
|
||||
pub fn tokens(&self) -> &TokenStream {
|
||||
match self {
|
||||
Borrowed(n) | Owned(n) => n,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ref_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Borrowed(n) => n.clone(),
|
||||
Owned(n) => quote!(&#n),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ref_mut_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Borrowed(n) => n.clone(),
|
||||
Owned(n) => quote!(&mut #n),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn owned_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Borrowed(n) => quote!(*#n),
|
||||
Owned(n) => n.clone(),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
use crate::operand::*;
|
||||
use crate::{file, full, gen};
|
||||
use inflections::Inflect;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
@ -17,35 +18,6 @@ fn under_name(name: &str) -> Ident {
|
||||
Ident::new(&name.to_snake_case(), Span::call_site())
|
||||
}
|
||||
|
||||
enum Operand {
|
||||
Borrowed(TokenStream),
|
||||
Owned(TokenStream),
|
||||
}
|
||||
|
||||
use self::Operand::*;
|
||||
|
||||
impl Operand {
|
||||
fn tokens(&self) -> &TokenStream {
|
||||
match self {
|
||||
Borrowed(n) | Owned(n) => n,
|
||||
}
|
||||
}
|
||||
|
||||
fn ref_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Borrowed(n) => n.clone(),
|
||||
Owned(n) => quote!(&#n),
|
||||
}
|
||||
}
|
||||
|
||||
fn owned_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Borrowed(n) => quote!(*#n),
|
||||
Owned(n) => n.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn simple_visit(item: &str, name: &Operand) -> TokenStream {
|
||||
let ident = under_name(item);
|
||||
let method = Ident::new(&format!("visit_{}", ident), Span::call_site());
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::operand::*;
|
||||
use crate::{file, full, gen};
|
||||
use inflections::Inflect;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
@ -17,35 +18,6 @@ fn under_name(name: &str) -> Ident {
|
||||
Ident::new(&name.to_snake_case(), Span::call_site())
|
||||
}
|
||||
|
||||
enum Operand {
|
||||
Borrowed(TokenStream),
|
||||
Owned(TokenStream),
|
||||
}
|
||||
|
||||
use self::Operand::*;
|
||||
|
||||
impl Operand {
|
||||
fn tokens(&self) -> &TokenStream {
|
||||
match self {
|
||||
Borrowed(n) | Owned(n) => n,
|
||||
}
|
||||
}
|
||||
|
||||
fn ref_mut_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Borrowed(n) => n.clone(),
|
||||
Owned(n) => quote!(&mut #n),
|
||||
}
|
||||
}
|
||||
|
||||
fn owned_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Borrowed(n) => quote!(*#n),
|
||||
Owned(n) => n.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn simple_visit(item: &str, name: &Operand) -> TokenStream {
|
||||
let ident = under_name(item);
|
||||
let method = Ident::new(&format!("visit_{}_mut", ident), Span::call_site());
|
||||
|
Loading…
Reference in New Issue
Block a user