kodept_core/structure/rlt/
top_level.rs1use derive_more::From;
2
3use crate::code_point::CodePoint;
4use crate::structure::Located;
5use crate::structure::rlt::function::BodiedFunction;
6use crate::structure::rlt::new_types::*;
7use crate::structure::rlt::types::TypedParameter;
8
9#[derive(Debug, Clone, PartialEq)]
10pub struct Struct {
11 pub keyword: Keyword,
12 pub id: TypeName,
13 pub parameters: Option<Enclosed<Box<[TypedParameter]>>>,
14 pub body: Option<Enclosed<Box<[BodiedFunction]>>>,
15}
16
17#[derive(Debug, Clone, PartialEq)]
18pub enum Enum {
19 Stack {
20 keyword: Keyword,
21 id: TypeName,
22 contents: Option<Enclosed<Box<[TypeName]>>>,
23 },
24 Heap {
25 keyword: Keyword,
26 id: TypeName,
27 contents: Option<Enclosed<Box<[TypeName]>>>,
28 },
29}
30
31#[derive(Debug, Clone, PartialEq, From)]
32pub enum TopLevelNode {
33 Enum(Enum),
34 Struct(Struct),
35 BodiedFunction(BodiedFunction),
36}
37
38impl Located for Struct {
39 fn location(&self) -> CodePoint {
40 self.keyword.location()
41 }
42}
43
44impl Located for Enum {
45 fn location(&self) -> CodePoint {
46 match self {
47 Enum::Stack { keyword, .. } => keyword.location(),
48 Enum::Heap { keyword, .. } => keyword.location(),
49 }
50 }
51}
52
53impl Located for TopLevelNode {
54 fn location(&self) -> CodePoint {
55 match self {
56 TopLevelNode::Enum(x) => x.location(),
57 TopLevelNode::Struct(x) => x.location(),
58 TopLevelNode::BodiedFunction(x) => x.location(),
59 }
60 }
61}
62
63impl Enum {
64 pub fn id(&self) -> &TypeName {
65 match self {
66 Enum::Stack { id, .. } => id,
67 Enum::Heap { id, .. } => id,
68 }
69 }
70}