Implement methods to build a resolver

This commit is contained in:
Florian Diebold 2019-01-23 23:08:41 +01:00
parent 5208c2aa93
commit 758bc72873
5 changed files with 169 additions and 76 deletions

View file

@ -15,7 +15,7 @@ use crate::{
path::Path,
};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct Resolver {
scopes: Vec<Scope>, // maybe a 'linked list' of scopes? or allow linking a Resolver to a parent Resolver? that's an optimization that might not be necessary, though
}
@ -87,6 +87,36 @@ impl Resolver {
self
}
pub(crate) fn push_generic_params_scope(self, params: Arc<GenericParams>) -> Resolver {
self.push_scope(Scope::GenericParams(params))
}
pub(crate) fn push_impl_block_scope(self, impl_block: ImplBlock) -> Resolver {
self.push_scope(Scope::ImplBlockScope(impl_block))
}
pub(crate) fn push_module_scope(self, item_map: Arc<ItemMap>, module_id: ModuleId) -> Resolver {
self.push_scope(Scope::ModuleScope(ModuleItemMap {
item_map,
module_id,
}))
}
pub(crate) fn push_expr_scope(
self,
expr_scopes: Arc<ExprScopes>,
scope_id: ScopeId,
) -> Resolver {
self.push_scope(Scope::ExprScope(ExprScope {
expr_scopes,
scope_id,
}))
}
pub(crate) fn push_function_params(self, body: Arc<Body>) -> Resolver {
self.push_scope(Scope::FunctionParams(body))
}
pub(crate) fn pop_scope(mut self) -> Resolver {
self.scopes.pop();
self