kodept_core/structure/rlt/
function.rs

1use derive_more::From;
2
3use crate::code_point::CodePoint;
4use crate::structure::Located;
5use crate::structure::rlt::block_level::Body;
6use crate::structure::rlt::new_types::*;
7use crate::structure::rlt::types::{Parameter, Type, TypedParameter};
8
9#[derive(Debug, Clone, PartialEq)]
10pub struct BodiedFunction {
11    pub keyword: Keyword,
12    pub id: Identifier,
13    pub params: Option<Enclosed<Box<[Parameter]>>>,
14    pub return_type: Option<(Symbol, Type)>,
15    pub body: Box<Body>,
16}
17
18#[derive(Clone, Debug, PartialEq)]
19pub struct AbstractFunction {
20    pub keyword: Keyword,
21    pub id: Identifier,
22    pub params: Option<Enclosed<Box<[TypedParameter]>>>,
23    pub return_type: Option<(Symbol, Type)>,
24}
25
26#[derive(Clone, Debug, PartialEq, From)]
27pub enum Function {
28    Abstract(AbstractFunction),
29    Bodied(BodiedFunction),
30}
31
32impl Located for BodiedFunction {
33    fn location(&self) -> CodePoint {
34        self.keyword.location()
35    }
36}
37
38impl Located for AbstractFunction {
39    fn location(&self) -> CodePoint {
40        self.keyword.location()
41    }
42}
43
44impl Located for Function {
45    fn location(&self) -> CodePoint {
46        match self {
47            Function::Abstract(x) => x.location(),
48            Function::Bodied(x) => x.location(),
49        }
50    }
51}