cl-typeck: Remove NameCollectable trait, use NameCollector instead :D
This commit is contained in:
parent
b9085551e1
commit
9566f098ac
@ -1,11 +1,11 @@
|
||||
use cl_ast::{
|
||||
ast_visitor::fold::Fold,
|
||||
ast_visitor::{Fold, Visit},
|
||||
desugar::{squash_groups::SquashGroups, while_else::WhileElseDesugar},
|
||||
};
|
||||
use cl_lexer::Lexer;
|
||||
use cl_parser::{inliner::ModuleInliner, Parser};
|
||||
use cl_typeck::{
|
||||
definition::Def, name_collector::NameCollectable, project::Project, type_resolver::resolve,
|
||||
definition::Def, name_collector::NameCollector, project::Project, type_resolver::resolve,
|
||||
};
|
||||
use repline::{error::Error as RlError, prebaked::*};
|
||||
use std::{error::Error, path};
|
||||
@ -38,8 +38,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
};
|
||||
let code = inline_modules(code, concat!(env!("PWD"), "/stdlib"));
|
||||
|
||||
unsafe { TREES.push(code) }.collect_in_root(&mut prj)?;
|
||||
NameCollector::new(&mut prj).visit_file(unsafe { TREES.push(code) });
|
||||
|
||||
main_menu(&mut prj)?;
|
||||
Ok(())
|
||||
@ -84,7 +83,7 @@ fn enter_code(prj: &mut Project) -> Result<(), RlError> {
|
||||
let code = inline_modules(code, "");
|
||||
let code = WhileElseDesugar.fold_file(code);
|
||||
// Safety: this is totally unsafe
|
||||
unsafe { TREES.push(code) }.collect_in_root(prj)?;
|
||||
NameCollector::new(prj).visit_file(unsafe { TREES.push(code) });
|
||||
|
||||
Ok(Response::Accept)
|
||||
})
|
||||
|
@ -8,24 +8,6 @@ use crate::{
|
||||
use cl_ast::{ast_visitor::Visit, *};
|
||||
use std::mem;
|
||||
|
||||
pub trait NameCollectable<'a> {
|
||||
/// Collects the identifiers within this node,
|
||||
/// returning a new [DefID] if any were allocated,
|
||||
/// else returning the parent [DefID]
|
||||
fn collect(&'a self, c: &mut Prj<'a>, parent: DefID) -> Result<DefID, &'static str>;
|
||||
|
||||
fn collect_in_root(&'a self, c: &mut Prj<'a>) -> Result<DefID, &'static str> {
|
||||
self.collect(c, c.root)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> NameCollectable<'a> for File {
|
||||
fn collect(&'a self, prj: &mut Prj<'a>, parent: DefID) -> Result<DefID, &'static str> {
|
||||
NameCollector::with_root(prj, parent).visit_file(self);
|
||||
Ok(parent)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NameCollector<'prj, 'a> {
|
||||
prj: &'prj mut Prj<'a>,
|
||||
@ -34,9 +16,11 @@ pub struct NameCollector<'prj, 'a> {
|
||||
}
|
||||
|
||||
impl<'prj, 'a> NameCollector<'prj, 'a> {
|
||||
/// Constructs a new [NameCollector] out of a [Project](Prj)
|
||||
pub fn new(prj: &'prj mut Prj<'a>) -> Self {
|
||||
Self { parent: prj.root, prj, retval: None }
|
||||
}
|
||||
/// Constructs a new [NameCollector] out of a [Project](Prj) and a parent [DefID]
|
||||
pub fn with_root(prj: &'prj mut Prj<'a>, parent: DefID) -> Self {
|
||||
Self { prj, parent, retval: None }
|
||||
}
|
||||
@ -56,7 +40,7 @@ impl<'prj, 'a> NameCollector<'prj, 'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'prj, 'a> ast_visitor::Visit<'a> for NameCollector<'prj, 'a> {
|
||||
impl<'prj, 'a> Visit<'a> for NameCollector<'prj, 'a> {
|
||||
fn visit_item(&mut self, i: &'a Item) {
|
||||
let Item { extents: _, attrs, vis, kind } = i;
|
||||
if let Some(def) = self.returns(kind, Self::visit_item_kind) {
|
||||
|
Loading…
Reference in New Issue
Block a user