More generics on expressions
This commit is contained in:
@@ -151,6 +151,7 @@ pub struct Expr<T: ProgramInfo> {
|
||||
#[cfg_attr(feature = "fuzz", derive_where(Arbitrary; T: ArbitraryProgramInfo))]
|
||||
#[cfg_attr(feature = "serde", derive_where(Deserialize, Serialize; T: SerdeProgramInfo))]
|
||||
pub enum ExprKind<T: ProgramInfo> {
|
||||
Extra(T::ExprExtra),
|
||||
Variable(u32),
|
||||
Value(Value),
|
||||
Load {
|
||||
@@ -158,11 +159,11 @@ pub enum ExprKind<T: ProgramInfo> {
|
||||
query: Vec<QueryTerm>,
|
||||
},
|
||||
UnaryOp {
|
||||
op: UnaryOpKind,
|
||||
op: T::UnaryOp,
|
||||
term: Arc<Expr<T>>,
|
||||
},
|
||||
BinaryOp {
|
||||
op: BinaryOpKind,
|
||||
op: T::BinaryOp,
|
||||
lhs: Arc<Expr<T>>,
|
||||
rhs: Arc<Expr<T>>,
|
||||
},
|
||||
@@ -337,6 +338,15 @@ pub trait ProgramInfo {
|
||||
|
||||
/// Metadata for each expression tree node.
|
||||
type ExprMeta: Info;
|
||||
|
||||
/// The type of binary operators.
|
||||
type BinaryOp: Info + From<BinaryOpKind> + TryInto<BinaryOpKind>;
|
||||
|
||||
/// The type of unary operators.
|
||||
type UnaryOp: Info + From<UnaryOpKind> + TryInto<UnaryOpKind>;
|
||||
|
||||
/// Extensions to [Expr] past the primitive definitions.
|
||||
type ExprExtra: Info;
|
||||
}
|
||||
|
||||
/// A blanket trait bounding all associated types in [ProgramInfo].
|
||||
@@ -356,6 +366,9 @@ macro_rules! def_bound_info {
|
||||
RuleMeta: $bounds,
|
||||
RuleBodyMeta: $bounds,
|
||||
ExprMeta: $bounds,
|
||||
BinaryOp: $bounds,
|
||||
UnaryOp: $bounds,
|
||||
ExprExtra: $bounds,
|
||||
>
|
||||
{
|
||||
}
|
||||
@@ -368,6 +381,9 @@ macro_rules! def_bound_info {
|
||||
RuleMeta: $bounds,
|
||||
RuleBodyMeta: $bounds,
|
||||
ExprMeta: $bounds,
|
||||
BinaryOp: $bounds,
|
||||
UnaryOp: $bounds,
|
||||
ExprExtra: $bounds,
|
||||
>
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user