|
1 | 1 | //! HIR version of the global scope in order to store descriptors and implementations |
2 | 2 |
|
| 3 | +use std::collections::btree_map::Entry; |
| 4 | + |
3 | 5 | 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 | +}; |
5 | 9 | use diagnostics::{DiagnosticResult, DiagnosticSpanOrigin}; |
6 | 10 |
|
7 | 11 | use crate::{ctx::HIRFunction, nodes::HIRNode}; |
@@ -111,4 +115,85 @@ impl HIRGlobalScopeStorage { |
111 | 115 | self.scope |
112 | 116 | .append(name, TypedGlobalScopeEntry::TypeAlias(t), origin) |
113 | 117 | } |
| 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 | + } |
114 | 199 | } |
0 commit comments