use crate::SourceSpan;
use super::item::{Ident, Path};
use super::punct::Punctuated;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LitKind {
Integer,
Float,
String,
Char,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum UnaryOp {
Plus,
Negate,
LogicalNot,
BitwiseNot,
Deref,
AddressOf,
PreIncrement,
PreDecrement,
PostIncrement,
PostDecrement,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BinaryOp {
Add,
Sub,
Mul,
Div,
Mod,
ShiftLeft,
ShiftRight,
Less,
LessEqual,
Greater,
GreaterEqual,
ThreeWay,
Equal,
NotEqual,
BitAnd,
BitXor,
BitOr,
LogicalAnd,
LogicalOr,
Assign,
AddAssign,
SubAssign,
MulAssign,
DivAssign,
ModAssign,
ShiftLeftAssign,
ShiftRightAssign,
BitAndAssign,
BitXorAssign,
BitOrAssign,
Dot,
Arrow,
DotStar,
ArrowStar,
Comma,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CastKind {
Static,
Dynamic,
Const,
Reinterpret,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Expr<'de> {
Lit(ExprLit<'de>),
Ident(ExprIdent<'de>),
Path(ExprPath<'de>),
Paren(ExprParen<'de>),
Bool(ExprBool<'de>),
Nullptr(ExprNullptr<'de>),
This(ExprThis<'de>),
Unary(ExprUnary<'de>),
Binary(ExprBinary<'de>),
Conditional(ExprConditional<'de>),
Call(ExprCall<'de>),
MethodCall(ExprMethodCall<'de>),
Index(ExprIndex<'de>),
Field(ExprField<'de>),
Cast(ExprCast<'de>),
CStyleCast(ExprCStyleCast<'de>),
Sizeof(ExprSizeof<'de>),
Alignof(ExprAlignof<'de>),
New(ExprNew<'de>),
Delete(ExprDelete<'de>),
Throw(ExprThrow<'de>),
Lambda(ExprLambda<'de>),
Typeid(ExprTypeid<'de>),
InitList(ExprInitList<'de>),
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ExprLit<'de> {
pub span: SourceSpan<'de>,
pub kind: LitKind,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ExprIdent<'de> {
pub ident: Ident<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprPath<'de> {
pub path: Path<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprParen<'de> {
pub expr: Box<Expr<'de>>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ExprBool<'de> {
pub span: SourceSpan<'de>,
pub value: bool,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ExprNullptr<'de> {
pub span: SourceSpan<'de>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ExprThis<'de> {
pub span: SourceSpan<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprUnary<'de> {
pub op: UnaryOp,
pub operand: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprBinary<'de> {
pub lhs: Box<Expr<'de>>,
pub op: BinaryOp,
pub rhs: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprConditional<'de> {
pub condition: Box<Expr<'de>>,
pub then_expr: Box<Expr<'de>>,
pub else_expr: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprCall<'de> {
pub func: Box<Expr<'de>>,
pub args: Punctuated<'de, Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprMethodCall<'de> {
pub receiver: Box<Expr<'de>>,
pub arrow: bool,
pub method: Ident<'de>,
pub args: Punctuated<'de, Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprIndex<'de> {
pub object: Box<Expr<'de>>,
pub index: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprField<'de> {
pub object: Box<Expr<'de>>,
pub arrow: bool,
pub member: Ident<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprCast<'de> {
pub cast_kind: CastKind,
pub ty: Box<super::ty::Type<'de>>,
pub expr: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprCStyleCast<'de> {
pub ty: Box<super::ty::Type<'de>>,
pub expr: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprSizeof<'de> {
pub operand: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprAlignof<'de> {
pub ty: Box<super::ty::Type<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprNew<'de> {
pub global: bool,
pub placement: Option<Punctuated<'de, Expr<'de>>>,
pub ty: Box<super::ty::Type<'de>>,
pub initializer: Option<NewInitializer<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum NewInitializer<'de> {
Parens(Punctuated<'de, Expr<'de>>),
Braces(Vec<Expr<'de>>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprDelete<'de> {
pub global: bool,
pub array: bool,
pub expr: Box<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprThrow<'de> {
pub expr: Option<Box<Expr<'de>>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprLambda<'de> {
pub captures: Vec<LambdaCapture<'de>>,
pub inputs: Option<Punctuated<'de, super::item::FnArg<'de>>>,
pub return_type: Option<Box<super::ty::Type<'de>>>,
pub body: super::stmt::Block<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LambdaCapture<'de> {
DefaultCopy,
DefaultRef,
ByValue(Ident<'de>),
ByRef(Ident<'de>),
This,
StarThis,
Init(Ident<'de>, Box<Expr<'de>>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprTypeid<'de> {
pub operand: TypeidOperand<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TypeidOperand<'de> {
Type(Box<super::ty::Type<'de>>),
Expr(Box<Expr<'de>>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExprInitList<'de> {
pub elements: Vec<Expr<'de>>,
}