mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(ast_tools): simplify define_pass! macro (#6901)
This commit is contained in:
parent
1d981bfa53
commit
26de0de326
3 changed files with 24 additions and 17 deletions
|
|
@ -21,9 +21,9 @@ compile_error!("This module only supports 64bit architectures.");
|
|||
|
||||
type WellKnown = FxHashMap<&'static str, PlatformLayout>;
|
||||
|
||||
define_pass! {
|
||||
pub struct CalcLayout;
|
||||
}
|
||||
pub struct CalcLayout;
|
||||
|
||||
define_pass!(CalcLayout);
|
||||
|
||||
impl Pass for CalcLayout {
|
||||
fn each(&mut self, ty: &mut AstType, ctx: &EarlyCtx) -> crate::Result<bool> {
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ impl Unresolved for Vec<Inherit> {
|
|||
}
|
||||
}
|
||||
|
||||
define_pass! {
|
||||
pub struct Linker;
|
||||
}
|
||||
pub struct Linker;
|
||||
|
||||
define_pass!(Linker);
|
||||
|
||||
impl Pass for Linker {
|
||||
/// # Panics
|
||||
|
|
|
|||
|
|
@ -43,19 +43,26 @@ pub trait Pass {
|
|||
}
|
||||
|
||||
macro_rules! define_pass {
|
||||
($vis:vis struct $ident:ident $($lifetime:lifetime)? $($rest:tt)*) => {
|
||||
$vis struct $ident $($lifetime)? $($rest)*
|
||||
impl $($lifetime)? $crate::codegen::Runner for $ident $($lifetime)? {
|
||||
type Context = $crate::codegen::EarlyCtx;
|
||||
type Output = ();
|
||||
fn name(&self) -> &'static str {
|
||||
stringify!($ident)
|
||||
}
|
||||
($ident:ident $($lifetime:lifetime)?) => {
|
||||
const _: () = {
|
||||
use $crate::{
|
||||
codegen::{EarlyCtx, Runner},
|
||||
Result,
|
||||
};
|
||||
|
||||
fn run(&mut self, ctx: &Self::Context) -> $crate::Result<Self::Output> {
|
||||
self.call(ctx).map(|_| ())
|
||||
impl $($lifetime)? Runner for $ident $($lifetime)? {
|
||||
type Context = EarlyCtx;
|
||||
type Output = ();
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
stringify!($ident)
|
||||
}
|
||||
|
||||
fn run(&mut self, ctx: &Self::Context) -> Result<()> {
|
||||
self.call(ctx).map(|_| ())
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue