fix(els): use NormalizedPathBuf for AbsLocation

This commit is contained in:
Shunsuke Shibayama 2023-09-13 23:26:05 +09:00
parent 138c6ff3d8
commit 38f44e8d31
10 changed files with 40 additions and 14 deletions

View file

@ -708,7 +708,7 @@ impl Context {
} else {
erg_std_decl_path().join(format!("{}.d.er", self.name))
};
let abs_loc = AbsLocation::new(Some(module), loc);
let abs_loc = AbsLocation::new(Some(module.into()), loc);
self.register_builtin_impl(name, t, muty, vis, py_name, abs_loc);
}

View file

@ -17,7 +17,7 @@ pub mod unify;
use std::fmt;
use std::mem;
use std::option::Option; // conflicting to Type::Option
use std::path::{Path, PathBuf};
use std::path::Path;
use erg_common::config::ErgConfig;
use erg_common::consts::DEBUG_MODE;
@ -25,6 +25,7 @@ use erg_common::consts::PYTHON_MODE;
use erg_common::dict::Dict;
use erg_common::error::Location;
use erg_common::impl_display_from_debug;
use erg_common::pathutil::NormalizedPathBuf;
use erg_common::traits::{Locational, Stream};
use erg_common::Str;
use erg_common::{fmt_option, fn_name, get_hash, log};
@ -1010,7 +1011,7 @@ impl Context {
}
pub(crate) fn absolutize(&self, loc: Location) -> AbsLocation {
AbsLocation::new(Some(PathBuf::from(self.module_path())), loc)
AbsLocation::new(Some(NormalizedPathBuf::from(self.module_path())), loc)
}
#[inline]

View file

@ -4,6 +4,7 @@
#[allow(unused_imports)]
use erg_common::log;
use erg_common::pathutil::NormalizedPathBuf;
use erg_common::traits::{Locational, Runnable, Stream};
use erg_common::Str;
use erg_parser::ast::AST;
@ -171,9 +172,9 @@ impl ASTLowerer {
if mode == "eval" {
return;
}
let self_path = self.module.context.module_path();
let self_path = NormalizedPathBuf::from(self.module.context.module_path());
for (referee, value) in self.module.context.index().members().iter() {
if referee.module.as_deref() != Some(self_path) {
if referee.module.as_ref() != Some(&self_path) {
continue;
}
let name_is_auto = &value.name[..] == "_"

View file

@ -3,6 +3,7 @@ use std::fmt;
use std::path::{Path, PathBuf};
use erg_common::dict::Dict;
use erg_common::pathutil::NormalizedPathBuf;
use erg_common::set;
use erg_common::set::Set;
use erg_common::shared::{MappedRwLockReadGuard, RwLockReadGuard, Shared};
@ -112,6 +113,7 @@ impl ModuleIndex {
}
pub fn rename_path(&mut self, old: &Path, new: PathBuf) {
let new = NormalizedPathBuf::new(new);
let mut new_members = Dict::new();
for (loc, mut value) in std::mem::take(&mut self.members) {
if value.vi.def_loc.module.as_deref() == Some(old) {

View file

@ -1,7 +1,7 @@
use std::fmt;
use std::path::PathBuf;
use erg_common::error::Location;
use erg_common::pathutil::NormalizedPathBuf;
use erg_common::set::Set;
use erg_common::{switch_lang, Str};
@ -125,7 +125,7 @@ impl VarKind {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AbsLocation {
pub module: Option<PathBuf>,
pub module: Option<NormalizedPathBuf>,
pub loc: Location,
}
@ -144,14 +144,14 @@ impl std::str::FromStr for AbsLocation {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut split = s.split('@');
let module = split.next().map(PathBuf::from);
let module = split.next().map(NormalizedPathBuf::from);
let loc = split.next().ok_or(())?.parse().map_err(|_| ())?;
Ok(Self { module, loc })
}
}
impl AbsLocation {
pub const fn new(module: Option<PathBuf>, loc: Location) -> Self {
pub const fn new(module: Option<NormalizedPathBuf>, loc: Location) -> Self {
Self { module, loc }
}