Skip to content

Commit 51e9199

Browse files
committed
feat: added getters
1 parent fd4d5e8 commit 51e9199

1 file changed

Lines changed: 86 additions & 1 deletion

File tree

compiler/astoir_hir/src/scope.rs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//! HIR version of the global scope in order to store descriptors and implementations
22
3+
use std::collections::btree_map::Entry;
4+
35
use compiler_global_scope::key::EntryKey;
4-
use compiler_typing::{TypedGlobalScope, TypedGlobalScopeEntry, raw::RawType, tree::Type};
6+
use compiler_typing::{
7+
TypedGlobalScope, TypedGlobalScopeEntry, bounds::traits, raw::RawType, tree::Type,
8+
};
59
use diagnostics::{DiagnosticResult, DiagnosticSpanOrigin};
610

711
use crate::{ctx::HIRFunction, nodes::HIRNode};
@@ -111,4 +115,85 @@ impl HIRGlobalScopeStorage {
111115
self.scope
112116
.append(name, TypedGlobalScopeEntry::TypeAlias(t), origin)
113117
}
118+
119+
pub fn get_base<K: DiagnosticSpanOrigin>(
120+
&self,
121+
name: EntryKey,
122+
origin: &K,
123+
) -> DiagnosticResult<TypedGlobalScopeEntry> {
124+
self.scope.get_base(name, origin)
125+
}
126+
127+
pub fn get_type<K: DiagnosticSpanOrigin>(
128+
&self,
129+
name: EntryKey,
130+
origin: &K,
131+
) -> DiagnosticResult<RawType> {
132+
self.scope.get_type(name, origin)
133+
}
134+
135+
pub fn get_static_variable<K: DiagnosticSpanOrigin>(
136+
&self,
137+
name: EntryKey,
138+
origin: &K,
139+
) -> DiagnosticResult<Type> {
140+
self.scope.get_static_variable(name, origin)
141+
}
142+
143+
pub fn get_function_base<K: DiagnosticSpanOrigin>(
144+
&self,
145+
name: EntryKey,
146+
origin: &K,
147+
) -> DiagnosticResult<HIRFunction> {
148+
let ind = self.scope.get_function_base(name, origin)?;
149+
150+
return Ok(self.descriptors[ind].clone());
151+
}
152+
153+
pub fn get_function_impl<K: DiagnosticSpanOrigin>(
154+
&self,
155+
name: EntryKey,
156+
origin: &K,
157+
) -> DiagnosticResult<Box<HIRNode>> {
158+
let ind = self.scope.get_function_impl(name, origin)?;
159+
160+
return Ok(self.implementations[ind].clone());
161+
}
162+
163+
pub fn get_implless_function<K: DiagnosticSpanOrigin>(
164+
&self,
165+
name: EntryKey,
166+
origin: &K,
167+
) -> DiagnosticResult<HIRFunction> {
168+
let ind = self.scope.get_implless_function(name, origin)?;
169+
170+
return Ok(self.descriptors[ind].clone());
171+
}
172+
173+
pub fn get_exact_function<K: DiagnosticSpanOrigin>(
174+
&self,
175+
name: EntryKey,
176+
origin: &K,
177+
) -> DiagnosticResult<(HIRFunction, Box<HIRNode>)> {
178+
let inds = self.scope.get_exact_function(name, origin)?;
179+
180+
return Ok((
181+
self.descriptors[inds.0].clone(),
182+
self.implementations[inds.1].clone(),
183+
));
184+
}
185+
186+
pub fn get_exact_struct_function<K: DiagnosticSpanOrigin>(
187+
&self,
188+
name: EntryKey,
189+
origin: &K,
190+
) -> DiagnosticResult<(HIRFunction, Box<HIRNode>, RawType)> {
191+
let res = self.scope.get_exact_struct_function(name, origin)?;
192+
193+
return Ok((
194+
self.descriptors[res.0].clone(),
195+
self.implementations[res.1].clone(),
196+
res.2,
197+
));
198+
}
114199
}

0 commit comments

Comments
 (0)