Skip to main content

oak_ada/ast/
mod.rs

1/// The root node of an Ada kind tree
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct AdaRoot {
4    /// The items in this Ada file
5    pub items: Vec<AdaItem>,
6}
7
8impl AdaRoot {
9    /// Create a new Ada root
10    pub fn new(items: Vec<AdaItem>) -> Self {
11        Self { items }
12    }
13
14    /// Get all top-level items in this Ada file
15    pub fn items(&self) -> &[AdaItem] {
16        &self.items
17    }
18}
19
20/// An item in an Ada file (package, procedure, function, etc.)
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum AdaItem {
23    Package(AdaPackage),
24    Procedure(AdaProcedure),
25    Function(AdaFunction),
26    Type(AdaTypeDeclaration),
27    Variable(AdaVariableDeclaration),
28}
29
30/// An Ada package declaration
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct AdaPackage {
33    pub name: String,
34}
35
36impl AdaPackage {
37    pub fn new(name: String) -> Self {
38        Self { name }
39    }
40}
41
42/// An Ada procedure declaration
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct AdaProcedure {
45    pub name: String,
46    pub parameters: Vec<AdaParameter>,
47}
48
49impl AdaProcedure {
50    pub fn new(name: String, parameters: Vec<AdaParameter>) -> Self {
51        Self { name, parameters }
52    }
53}
54
55/// An Ada function declaration
56#[derive(Debug, Clone, PartialEq, Eq)]
57pub struct AdaFunction {
58    pub name: String,
59    pub parameters: Vec<AdaParameter>,
60    pub return_type: String,
61}
62
63impl AdaFunction {
64    pub fn new(name: String, parameters: Vec<AdaParameter>, return_type: String) -> Self {
65        Self { name, parameters, return_type }
66    }
67}
68
69/// An Ada parameter
70#[derive(Debug, Clone, PartialEq, Eq)]
71pub struct AdaParameter {
72    pub name: String,
73    pub param_type: String,
74}
75
76impl AdaParameter {
77    pub fn new(name: String, param_type: String) -> Self {
78        Self { name, param_type }
79    }
80}
81
82/// An Ada type declaration
83#[derive(Debug, Clone, PartialEq, Eq)]
84pub struct AdaTypeDeclaration {
85    pub name: String,
86    pub type_def: String,
87}
88
89impl AdaTypeDeclaration {
90    pub fn new(name: String, type_def: String) -> Self {
91        Self { name, type_def }
92    }
93}
94
95/// An Ada variable declaration
96#[derive(Debug, Clone, PartialEq, Eq)]
97pub struct AdaVariableDeclaration {
98    pub name: String,
99    pub var_type: String,
100}
101
102impl AdaVariableDeclaration {
103    pub fn new(name: String, var_type: String) -> Self {
104        Self { name, var_type }
105    }
106}
107
108impl Default for AdaRoot {
109    fn default() -> Self {
110        Self::new(Vec::new())
111    }
112}