Add ErgConfig::inherit

and remove with_module_path
This commit is contained in:
Shunsuke Shibayama 2022-12-14 05:38:50 +09:00
parent 0e928c758f
commit b09fce8a86
2 changed files with 10 additions and 11 deletions

View file

@ -225,14 +225,6 @@ impl ErgConfig {
}
}
pub fn with_module_path(path: PathBuf) -> Self {
Self {
module: Box::leak(path.to_str().unwrap().to_string().into_boxed_str()),
input: Input::File(path),
..ErgConfig::default()
}
}
/// cloneのエイリアス(実際のcloneコストは低いので)
#[inline]
pub fn copy(&self) -> Self {
@ -247,6 +239,14 @@ impl ErgConfig {
}
}
pub fn inherit(&self, path: PathBuf) -> Self {
Self {
module: Box::leak(path.to_str().unwrap().to_string().into_boxed_str()),
input: Input::File(path),
..self.copy()
}
}
pub fn parse() -> Self {
let mut args = env::args();
args.next(); // "ergc"

View file

@ -1,7 +1,6 @@
use std::option::Option;
use std::path::{Path, PathBuf};
use erg_common::config::ErgConfig;
use erg_common::env::erg_pystd_path;
use erg_common::levenshtein::get_similar_name;
use erg_common::python_util::BUILTIN_PYTHON_MODS;
@ -1215,7 +1214,7 @@ impl Context {
if mod_cache.get(&path).is_some() {
return Ok(path);
}
let cfg = ErgConfig::with_module_path(path.clone());
let cfg = self.cfg.inherit(path.clone());
let src = cfg.input.read();
let mut builder =
HIRBuilder::new_with_cache(cfg, __name__, mod_cache.clone(), py_mod_cache.clone());
@ -1307,7 +1306,7 @@ impl Context {
if py_mod_cache.get(&path).is_some() {
return Ok(path);
}
let cfg = ErgConfig::with_module_path(path.clone());
let cfg = self.cfg.inherit(path.clone());
let src = cfg.input.read();
let mut builder = HIRBuilder::new_with_cache(
cfg,