use super::{Block, Decl, Expr, Name, Param, Type};
use crate::source::token::Span;
#[derive(Debug, Clone, PartialEq)]
pub struct Patch {
pub target: Type,
pub items: Vec<PatchItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PatchItem {
Add(Box<Decl>),
AddBases(Vec<Type>),
Before {
method: Target,
uses: Vec<Local>,
body: Block,
},
After {
method: Target,
uses: Vec<Local>,
body: Block,
},
Inside {
method: Target,
points: Vec<Point>,
},
Read {
field: Name,
body: Block,
},
Write {
field: Name,
body: Block,
},
Replace {
method: Target,
body: Block,
},
Priority(i64, Span),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Target {
pub ret: Option<Type>,
pub name: Name,
pub params: Vec<Param>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Local {
pub write: bool,
pub ty: Type,
pub name: Name,
pub ordinal: Option<i64>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Point {
Around {
callee: Callee,
select: Option<Selector>,
body: Block,
},
Arg {
callee: Callee,
select: Option<Selector>,
arg: Name,
body: Block,
},
BeforeCall {
callee: Callee,
select: Option<Selector>,
uses: Vec<Local>,
body: Block,
},
AfterCall {
callee: Callee,
select: Option<Selector>,
uses: Vec<Local>,
body: Block,
},
Field {
write: bool,
field: Name,
select: Option<Selector>,
uses: Vec<Local>,
body: Block,
},
New {
ty: Type,
select: Option<Selector>,
uses: Vec<Local>,
body: Block,
},
Constant {
value: Expr,
to: Expr,
select: Option<Selector>,
},
Local {
local: Local,
value: Expr,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct Callee {
pub path: Vec<Name>,
pub args: Option<Vec<Type>>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Selector {
First,
Last,
Where(Expr),
}