use super::*;
mod display;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FunctionKind {
Macro,
Micro,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FunctionDeclaration {
pub name: NamePathNode,
pub kind: FunctionKind,
pub annotations: AnnotationNode,
pub generics: ParametersList,
pub parameters: ParametersList,
pub returns: FunctionReturnNode,
pub body: StatementBlock,
}
#[derive(Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StatementBlock {
pub terms: Vec<StatementKind>,
pub span: Range<u32>,
}
impl StatementBlock {
pub fn new(capacity: usize, span: &Range<u32>) -> Self {
Self { terms: Vec::with_capacity(capacity), span: span.clone() }
}
pub fn update_span(&mut self) {
if let Some(_first) = self.terms.first() {}
if let Some(_last) = self.terms.last() {}
}
}
#[derive(Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FunctionReturnNode {
pub typing: Option<ExpressionKind>,
pub effect: Vec<ExpressionKind>,
}
impl StatementBlock {
pub fn last_semicolon(&self) -> bool {
match self.terms.last() {
Some(StatementKind::Expression(s)) => s.omit,
_ => false,
}
}
pub fn fill_semicolon(&mut self) {
todo!()
}
}
impl FunctionReturnNode {
pub fn is_empty(&self) -> bool {
self.typing.is_none() && self.effect.is_empty()
}
}
impl FunctionDeclaration {
pub fn has_return_type(&self) -> bool {
self.returns.typing.is_some()
}
pub fn omit_return(&self) -> bool {
!self.body.last_semicolon()
}
}