kodept_core/structure/rlt/
block_level.rs1use derive_more::From;
2
3use crate::code_point::CodePoint;
4use crate::structure::{
5 Located,
6 rlt::expression::{ExpressionBlock, Operation},
7 rlt::new_types::*,
8 rlt::Type,
9};
10use crate::structure::rlt::BodiedFunction;
11
12#[derive(Debug, Clone, PartialEq)]
13pub enum Body {
14 Block(ExpressionBlock),
15 Simplified {
16 flow: Symbol,
17 expression: BlockLevelNode,
18 },
19}
20
21#[derive(Clone, Debug, PartialEq, From)]
22pub enum BlockLevelNode {
23 InitVar(InitializedVariable),
24 Block(ExpressionBlock),
25 Function(BodiedFunction),
26 Operation(Operation),
27}
28
29#[derive(Clone, Debug, PartialEq)]
30pub enum Variable {
31 Immutable {
32 keyword: Keyword,
33 id: Identifier,
34 assigned_type: Option<(Symbol, Type)>,
35 },
36 Mutable {
37 keyword: Keyword,
38 id: Identifier,
39 assigned_type: Option<(Symbol, Type)>,
40 },
41}
42
43#[derive(Clone, Debug, PartialEq)]
44pub struct InitializedVariable {
45 pub variable: Variable,
46 pub equals: Symbol,
47 pub expression: Operation,
48}
49
50impl Located for Variable {
51 fn location(&self) -> CodePoint {
52 match self {
53 Variable::Immutable { id, .. } => id.location(),
54 Variable::Mutable { id, .. } => id.location(),
55 }
56 }
57}
58
59impl Located for InitializedVariable {
60 fn location(&self) -> CodePoint {
61 self.variable.location()
62 }
63}
64
65impl Located for Body {
66 fn location(&self) -> CodePoint {
67 match self {
68 Body::Block(x) => x.location(),
69 Body::Simplified { expression, .. } => expression.location(),
70 }
71 }
72}
73
74impl Located for BlockLevelNode {
75 fn location(&self) -> CodePoint {
76 match self {
77 BlockLevelNode::InitVar(x) => x.location(),
78 BlockLevelNode::Block(x) => x.location(),
79 BlockLevelNode::Function(x) => x.location(),
80 BlockLevelNode::Operation(x) => x.location(),
81 }
82 }
83}