use super::*;
mod display;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FunctionType {
Macro,
Micro,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FunctionDeclaration {
pub r#type: FunctionType,
pub namepath: NamePathNode,
pub modifiers: Vec<IdentifierNode>,
pub attributes: Option<String>,
pub generic: Option<GenericArgumentNode>,
pub arguments: ApplyArgumentNode,
pub r#return: Option<FunctionReturnNode>,
pub body: StatementBlock,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FunctionDeclarationInline {
pub generic: GenericArgumentNode,
pub arguments: ApplyArgumentNode,
pub r#return: Option<ExpressionNode>,
pub body: StatementBlock,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct StatementBlock {
pub terms: Vec<StatementNode>,
pub span: Range<u32>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FunctionReturnNode {
pub returns: ExpressionNode,
pub span: Range<u32>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FunctionEffectNode {
pub effects: Vec<ExpressionNode>,
pub span: Range<u32>,
}
impl StatementBlock {
pub fn last_semicolon(&self) -> bool {
match self.terms.last() {
Some(s) => s.end_semicolon,
None => true,
}
}
pub fn fill_semicolon(&mut self) {
for x in self.terms.iter_mut().rev().skip(1) {
x.end_semicolon = true;
}
}
}
impl FunctionDeclaration {
pub fn has_return_type(&self) -> bool {
self.r#return.is_some()
}
pub fn omit_return(&self) -> bool {
!self.body.last_semicolon()
}
}