use hir_expand::name::Name;
use la_arena::{Idx, RawIdx};
-use syntax::ast::RangeOp;
use crate::{
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
+ intern::Interned,
path::{GenericArgs, Path},
type_ref::{Mutability, Rawness, TypeRef},
BlockId,
};
+pub use syntax::ast::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp};
+
pub type ExprId = Idx<Expr>;
pub(crate) fn dummy_expr_id() -> ExprId {
ExprId::from_raw(RawIdx::from(!0))
ByteString(Vec<u8>),
Char(char),
Bool(bool),
- Int(u64, Option<BuiltinInt>),
- Uint(u64, Option<BuiltinUint>),
+ Int(i128, Option<BuiltinInt>),
+ Uint(u128, Option<BuiltinUint>),
Float(u64, Option<BuiltinFloat>), // FIXME: f64 is not Eq
}
},
Block {
id: BlockId,
- statements: Vec<Statement>,
+ statements: Box<[Statement]>,
tail: Option<ExprId>,
label: Option<LabelId>,
},
},
Call {
callee: ExprId,
- args: Vec<ExprId>,
+ args: Box<[ExprId]>,
},
MethodCall {
receiver: ExprId,
method_name: Name,
- args: Vec<ExprId>,
- generic_args: Option<GenericArgs>,
+ args: Box<[ExprId]>,
+ generic_args: Option<Box<GenericArgs>>,
},
Match {
expr: ExprId,
- arms: Vec<MatchArm>,
+ arms: Box<[MatchArm]>,
},
Continue {
label: Option<Name>,
expr: Option<ExprId>,
},
RecordLit {
- path: Option<Path>,
- fields: Vec<RecordLitField>,
+ path: Option<Box<Path>>,
+ fields: Box<[RecordLitField]>,
spread: Option<ExprId>,
},
Field {
},
Cast {
expr: ExprId,
- type_ref: TypeRef,
+ type_ref: Interned<TypeRef>,
},
Ref {
expr: ExprId,
index: ExprId,
},
Lambda {
- args: Vec<PatId>,
- arg_types: Vec<Option<TypeRef>>,
- ret_type: Option<TypeRef>,
+ args: Box<[PatId]>,
+ arg_types: Box<[Option<Interned<TypeRef>>]>,
+ ret_type: Option<Interned<TypeRef>>,
body: ExprId,
},
Tuple {
- exprs: Vec<ExprId>,
+ exprs: Box<[ExprId]>,
},
Unsafe {
body: ExprId,
Literal(Literal),
}
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
-pub enum BinaryOp {
- LogicOp(LogicOp),
- ArithOp(ArithOp),
- CmpOp(CmpOp),
- Assignment { op: Option<ArithOp> },
-}
-
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
-pub enum LogicOp {
- And,
- Or,
-}
-
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
-pub enum CmpOp {
- Eq { negated: bool },
- Ord { ordering: Ordering, strict: bool },
-}
-
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
-pub enum Ordering {
- Less,
- Greater,
-}
-
-#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
-pub enum ArithOp {
- Add,
- Mul,
- Sub,
- Div,
- Rem,
- Shl,
- Shr,
- BitXor,
- BitOr,
- BitAnd,
-}
-
-pub use syntax::ast::PrefixOp as UnaryOp;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Array {
ElementList(Vec<ExprId>),
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct MatchArm {
pub pat: PatId,
- pub guard: Option<ExprId>,
+ pub guard: Option<MatchGuard>,
pub expr: ExprId,
}
+#[derive(Debug, Clone, Eq, PartialEq)]
+pub enum MatchGuard {
+ If { expr: ExprId },
+
+ IfLet { pat: PatId, expr: ExprId },
+}
+
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct RecordLitField {
pub name: Name,
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Statement {
- Let { pat: PatId, type_ref: Option<TypeRef>, initializer: Option<ExprId> },
- Expr(ExprId),
+ Let {
+ pat: PatId,
+ type_ref: Option<Interned<TypeRef>>,
+ initializer: Option<ExprId>,
+ else_branch: Option<ExprId>,
+ },
+ Expr {
+ expr: ExprId,
+ has_semi: bool,
+ },
}
impl Expr {
}
}
Expr::Block { statements, tail, .. } => {
- for stmt in statements {
+ for stmt in statements.iter() {
match stmt {
Statement::Let { initializer, .. } => {
if let Some(expr) = initializer {
f(*expr);
}
}
- Statement::Expr(e) => f(*e),
+ Statement::Expr { expr: expression, .. } => f(*expression),
}
}
if let Some(expr) = tail {
}
Expr::Call { callee, args } => {
f(*callee);
- for arg in args {
+ for arg in args.iter() {
f(*arg);
}
}
Expr::MethodCall { receiver, args, .. } => {
f(*receiver);
- for arg in args {
+ for arg in args.iter() {
f(*arg);
}
}
Expr::Match { expr, arms } => {
f(*expr);
- for arm in arms {
+ for arm in arms.iter() {
f(arm.expr);
}
}
}
}
Expr::RecordLit { fields, spread, .. } => {
- for field in fields {
+ for field in fields.iter() {
f(field.expr);
}
if let Some(expr) = spread {
f(*expr);
}
Expr::Tuple { exprs } => {
- for expr in exprs {
+ for expr in exprs.iter() {
f(*expr);
}
}
Wild,
Tuple { args: Vec<PatId>, ellipsis: Option<usize> },
Or(Vec<PatId>),
- Record { path: Option<Path>, args: Vec<RecordFieldPat>, ellipsis: bool },
+ Record { path: Option<Box<Path>>, args: Vec<RecordFieldPat>, ellipsis: bool },
Range { start: ExprId, end: ExprId },
Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> },
- Path(Path),
+ Path(Box<Path>),
Lit(ExprId),
Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> },
- TupleStruct { path: Option<Path>, args: Vec<PatId>, ellipsis: Option<usize> },
+ TupleStruct { path: Option<Box<Path>>, args: Vec<PatId>, ellipsis: Option<usize> },
Ref { pat: PatId, mutability: Mutability },
Box { inner: PatId },
ConstBlock(ExprId),