use crate::types::{Endian, ScalarType};
#[derive(Debug, Clone)]
pub struct File {
pub endian: Endian,
pub struct_def: StructDef,
}
#[derive(Debug, Clone)]
pub struct StructDef {
pub name: String,
pub packed: bool,
pub align: Option<u32>,
pub fields: Vec<FieldDef>,
}
#[derive(Debug, Clone)]
pub struct FieldDef {
pub name: String,
pub ty: Type,
pub init: Option<Expr>,
}
#[derive(Debug, Clone)]
pub enum Type {
Scalar(ScalarType),
Array {
elem: ScalarType,
len: Box<Expr>,
},
}
impl Type {
pub fn elem_type(&self) -> ScalarType {
match self {
Type::Scalar(s) => *s,
Type::Array { elem, .. } => *elem,
}
}
}
#[derive(Debug, Clone)]
pub enum Expr {
Number(u64),
String(String),
EnvVar(String),
BinaryOp {
op: BinOp,
left: Box<Expr>,
right: Box<Expr>,
},
UnaryOp {
op: UnaryOp,
operand: Box<Expr>,
},
Call {
name: String,
args: Vec<Expr>,
},
SectionRef(String),
SelfRef,
Range {
base: Box<Expr>,
start: Option<Box<Expr>>,
end: Option<String>,
},
ArrayLiteral(ArrayLiteralKind),
}
#[derive(Debug, Clone)]
pub enum ArrayLiteralKind {
Repeat {
value: Box<Expr>,
count: RepeatCount,
},
List {
elements: Vec<Expr>,
},
}
#[derive(Debug, Clone)]
pub enum RepeatCount {
Explicit(Box<Expr>),
Infer,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinOp {
Or, And, Shl, Shr, Add, Sub, }
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnaryOp {
Not, }