pub use t_ree::types::{FloatWidth, IntWidth, Mutability, Signedness};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GenericParameter {
pub name: String,
pub kind: GenericParameterKind,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum GenericParameterKind {
Type,
Const(Type),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Lifetime {
Named(String),
Inferred,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FunctionSignature {
pub parameters: Vec<Type>,
pub return_type: Box<Type>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Type {
Never,
Bool,
Int(IntWidth, Signedness),
Float(FloatWidth),
Pointer(Mutability, Lifetime, Box<Self>),
Reference(Mutability, Lifetime, Box<Self>),
Array(Box<Self>, ConstExpression),
Vector(Box<Self>, ConstExpression),
Slice(Mutability, Box<Self>),
Tuple(Vec<Self>),
Enum(Vec<Self>),
Named(String, Vec<GenericArgument>),
Function(FunctionSignature),
Generic(String),
Inferred,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum GenericArgument {
Type(Type),
Lifetime(Lifetime),
Const(ConstExpression),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ConstExpression {
Integer(u128),
Named(String),
Add(Box<Self>, Box<Self>),
Subtract(Box<Self>, Box<Self>),
Multiply(Box<Self>, Box<Self>),
Divide(Box<Self>, Box<Self>),
Modulo(Box<Self>, Box<Self>),
BitwiseAnd(Box<Self>, Box<Self>),
BitwiseOr(Box<Self>, Box<Self>),
BitwiseXor(Box<Self>, Box<Self>),
ShiftLeft(Box<Self>, Box<Self>),
ShiftRight(Box<Self>, Box<Self>),
Call(String, Vec<Self>),
Field(Box<Self>, String),
Construction(Vec<(String, Self)>),
}
impl Type {
pub fn unit() -> Self {
Self::Tuple(Vec::new())
}
pub fn is_unit(&self) -> bool {
matches!(self, Self::Tuple(fields) if fields.is_empty())
}
}