mirror of https://github.com/mtshiba/pylyzer
build: update deps
improve location acquisition of import symbols
This commit is contained in:
parent
98fa6d09d2
commit
ffae325bed
|
|
@ -252,9 +252,9 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "els"
|
name = "els"
|
||||||
version = "0.1.24-nightly.3"
|
version = "0.1.24-nightly.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61f3764c26581de3f7c346d73429ccccb8bc644c04590c426e6a762ef4b306b6"
|
checksum = "f74cdce8d05df8b4a6090cc892e34a30ab6880f5ed8786e9346fe4d4fb4c47d5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
|
|
@ -274,9 +274,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_common"
|
name = "erg_common"
|
||||||
version = "0.6.12-nightly.3"
|
version = "0.6.12-nightly.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0af4f3dd859b94446be12295a587c1a0315772da8f4782c6e412c7b0ee6e6619"
|
checksum = "07cc57d02fe5520b0f0a42d30be2604edafa71a35074a35f579f2ca91533d965"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace-on-stack-overflow",
|
"backtrace-on-stack-overflow",
|
||||||
"hermit-abi",
|
"hermit-abi",
|
||||||
|
|
@ -286,9 +286,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_compiler"
|
name = "erg_compiler"
|
||||||
version = "0.6.12-nightly.3"
|
version = "0.6.12-nightly.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d6058e923f99ab3f901256d4c005e675a9bd66b5b7c502535f27d41d66afc3c0"
|
checksum = "101a854704b5bda829d4fa6005d590b2f426ce6624b8361118b4949c7d90c859"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_parser",
|
"erg_parser",
|
||||||
|
|
@ -296,9 +296,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_parser"
|
name = "erg_parser"
|
||||||
version = "0.6.12-nightly.3"
|
version = "0.6.12-nightly.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ecdcb02393d790e952ac55c9e49eb1e7485c86199bc770659915512e7647d9b3"
|
checksum = "43fe0229517462ba79374a8eb1b16a183f0854744af6d4ebfcd4b2ff05539121"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"unicode-xid 0.2.4",
|
"unicode-xid 0.2.4",
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ edition = "2021"
|
||||||
repository = "https://github.com/mtshiba/pylyzer"
|
repository = "https://github.com/mtshiba/pylyzer"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
erg_common = { version = "0.6.12-nightly.3", features = ["py_compat", "els"] }
|
erg_common = { version = "0.6.12-nightly.4", features = ["py_compat", "els"] }
|
||||||
erg_compiler = { version = "0.6.12-nightly.3", features = ["py_compat", "els"] }
|
erg_compiler = { version = "0.6.12-nightly.4", features = ["py_compat", "els"] }
|
||||||
els = { version = "0.1.24-nightly.3", features = ["py_compat"] }
|
els = { version = "0.1.24-nightly.4", features = ["py_compat"] }
|
||||||
rustpython-parser = "0.1.2"
|
rustpython-parser = "0.1.2"
|
||||||
# erg_compiler = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
# erg_compiler = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
||||||
# erg_common = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
# erg_common = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use erg_compiler::erg_parser::ast::{
|
||||||
Dict, Dummy, Expr, Identifier, KeyValue, KwArg, Lambda, LambdaSignature, Literal, Methods,
|
Dict, Dummy, Expr, Identifier, KeyValue, KwArg, Lambda, LambdaSignature, Literal, Methods,
|
||||||
Module, NonDefaultParamSignature, NormalArray, NormalDict, NormalRecord, NormalSet,
|
Module, NonDefaultParamSignature, NormalArray, NormalDict, NormalRecord, NormalSet,
|
||||||
NormalTuple, ParamPattern, Params, PosArg, PreDeclTypeSpec, ReDef, Record, RecordAttrs, Set,
|
NormalTuple, ParamPattern, Params, PosArg, PreDeclTypeSpec, ReDef, Record, RecordAttrs, Set,
|
||||||
Signature, SimpleTypeSpec, SubrSignature, Tuple, TypeAscription, TypeBoundSpecs, TypeSpec,
|
Signature, SubrSignature, Tuple, TypeAscription, TypeBoundSpecs, TypeSpec,
|
||||||
TypeSpecWithOp, UnaryOp, VarName, VarPattern, VarRecordAttr, VarRecordAttrs, VarRecordPattern,
|
TypeSpecWithOp, UnaryOp, VarName, VarPattern, VarRecordAttr, VarRecordAttrs, VarRecordPattern,
|
||||||
VarSignature, VisModifierSpec, ConstPosArg, ConstDict, ConstKeyValue, TupleTypeSpec,
|
VarSignature, VisModifierSpec, ConstPosArg, ConstDict, ConstKeyValue, TupleTypeSpec,
|
||||||
};
|
};
|
||||||
|
|
@ -495,8 +495,8 @@ impl ASTConverter {
|
||||||
Lambda::new(sig, op, Block::new(body), DefId(0))
|
Lambda::new(sig, op, Block::new(body), DefId(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_ident_type_spec(&mut self, name: String, loc: PyLocation) -> SimpleTypeSpec {
|
fn convert_ident_type_spec(&mut self, name: String, loc: PyLocation) -> TypeSpec {
|
||||||
SimpleTypeSpec::new(self.convert_ident(name, loc), ConstArgs::empty())
|
TypeSpec::mono(self.convert_ident(name, loc))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_dummy_type_spec(loc: PyLocation) -> TypeSpec {
|
fn gen_dummy_type_spec(loc: PyLocation) -> TypeSpec {
|
||||||
|
|
@ -527,10 +527,7 @@ impl ASTConverter {
|
||||||
let loc = args.location;
|
let loc = args.location;
|
||||||
let t = self.convert_type_spec(args);
|
let t = self.convert_type_spec(args);
|
||||||
let ident = Identifier::private_with_line("NoneType".into(), loc.row() as u32);
|
let ident = Identifier::private_with_line("NoneType".into(), loc.row() as u32);
|
||||||
let none = TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(SimpleTypeSpec::new(
|
let none = TypeSpec::mono(ident);
|
||||||
ident,
|
|
||||||
ConstArgs::empty(),
|
|
||||||
)));
|
|
||||||
TypeSpec::or(t, none)
|
TypeSpec::or(t, none)
|
||||||
}
|
}
|
||||||
"Literal" => {
|
"Literal" => {
|
||||||
|
|
@ -612,15 +609,11 @@ impl ASTConverter {
|
||||||
fn convert_type_spec(&mut self, expr: Located<ExpressionType>) -> TypeSpec {
|
fn convert_type_spec(&mut self, expr: Located<ExpressionType>) -> TypeSpec {
|
||||||
#[allow(clippy::collapsible_match)]
|
#[allow(clippy::collapsible_match)]
|
||||||
match expr.node {
|
match expr.node {
|
||||||
ExpressionType::Identifier { name } => TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(
|
ExpressionType::Identifier { name } => self.convert_ident_type_spec(name, expr.location),
|
||||||
self.convert_ident_type_spec(name, expr.location),
|
ExpressionType::None => self.convert_ident_type_spec("NoneType".into(), expr.location),
|
||||||
)),
|
|
||||||
ExpressionType::None => TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(
|
|
||||||
self.convert_ident_type_spec("NoneType".into(), expr.location),
|
|
||||||
)),
|
|
||||||
ExpressionType::Attribute { value, name } => {
|
ExpressionType::Attribute { value, name } => {
|
||||||
let namespace = Box::new(self.convert_expr(*value));
|
let namespace = Box::new(self.convert_expr(*value));
|
||||||
let t = self.convert_ident_type_spec(name, expr.location);
|
let t = self.convert_ident(name, expr.location);
|
||||||
let predecl = PreDeclTypeSpec::Attr { namespace, t };
|
let predecl = PreDeclTypeSpec::Attr { namespace, t };
|
||||||
TypeSpec::PreDeclTy(predecl)
|
TypeSpec::PreDeclTy(predecl)
|
||||||
}
|
}
|
||||||
|
|
@ -1029,9 +1022,7 @@ impl ASTConverter {
|
||||||
param_typ_name.into(),
|
param_typ_name.into(),
|
||||||
attr.obj.ln_begin().unwrap_or(0),
|
attr.obj.ln_begin().unwrap_or(0),
|
||||||
);
|
);
|
||||||
let param_typ_spec = TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(
|
let param_typ_spec = TypeSpec::mono(param_typ_ident.clone());
|
||||||
SimpleTypeSpec::new(param_typ_ident.clone(), ConstArgs::empty()),
|
|
||||||
));
|
|
||||||
let expr = Expr::Accessor(Accessor::Ident(param_typ_ident.clone()));
|
let expr = Expr::Accessor(Accessor::Ident(param_typ_ident.clone()));
|
||||||
let param_typ_spec = TypeSpecWithOp::new(AS, param_typ_spec, expr);
|
let param_typ_spec = TypeSpecWithOp::new(AS, param_typ_spec, expr);
|
||||||
let arg_typ_ident = Identifier::public_with_line(
|
let arg_typ_ident = Identifier::public_with_line(
|
||||||
|
|
@ -1082,10 +1073,7 @@ impl ASTConverter {
|
||||||
self.namespace.last().unwrap().into(),
|
self.namespace.last().unwrap().into(),
|
||||||
sig.ln_begin().unwrap_or(0),
|
sig.ln_begin().unwrap_or(0),
|
||||||
);
|
);
|
||||||
let class_spec = TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(SimpleTypeSpec::new(
|
let class_spec = TypeSpec::mono(class_ident);
|
||||||
class_ident,
|
|
||||||
ConstArgs::empty(),
|
|
||||||
)));
|
|
||||||
let sig = Signature::Subr(SubrSignature::new(
|
let sig = Signature::Subr(SubrSignature::new(
|
||||||
set! { Decorator(Expr::static_local("Override")) },
|
set! { Decorator(Expr::static_local("Override")) },
|
||||||
call_ident,
|
call_ident,
|
||||||
|
|
@ -1109,10 +1097,7 @@ impl ASTConverter {
|
||||||
let params = Params::new(vec![], None, vec![], None);
|
let params = Params::new(vec![], None, vec![], None);
|
||||||
let class_ident =
|
let class_ident =
|
||||||
Identifier::public_with_line(DOT, self.namespace.last().unwrap().into(), line as u32);
|
Identifier::public_with_line(DOT, self.namespace.last().unwrap().into(), line as u32);
|
||||||
let class_spec = TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(SimpleTypeSpec::new(
|
let class_spec = TypeSpec::mono(class_ident);
|
||||||
class_ident,
|
|
||||||
ConstArgs::empty(),
|
|
||||||
)));
|
|
||||||
let sig = Signature::Subr(SubrSignature::new(
|
let sig = Signature::Subr(SubrSignature::new(
|
||||||
set! { Decorator(Expr::static_local("Override")) },
|
set! { Decorator(Expr::static_local("Override")) },
|
||||||
call_ident,
|
call_ident,
|
||||||
|
|
@ -1214,10 +1199,7 @@ impl ASTConverter {
|
||||||
body: Vec<Located<StatementType>>,
|
body: Vec<Located<StatementType>>,
|
||||||
inherit: bool,
|
inherit: bool,
|
||||||
) -> (Option<Expr>, Vec<Methods>) {
|
) -> (Option<Expr>, Vec<Methods>) {
|
||||||
let class = TypeSpec::PreDeclTy(PreDeclTypeSpec::Simple(SimpleTypeSpec::new(
|
let class = TypeSpec::mono(ident.clone());
|
||||||
ident.clone(),
|
|
||||||
ConstArgs::empty(),
|
|
||||||
)));
|
|
||||||
let class_as_expr = Expr::Accessor(Accessor::Ident(ident));
|
let class_as_expr = Expr::Accessor(Accessor::Ident(ident));
|
||||||
let (base_type, attrs) = self.extract_method(body, inherit);
|
let (base_type, attrs) = self.extract_method(body, inherit);
|
||||||
let methods = Methods::new(class, class_as_expr, VisModifierSpec::Public(DOT), attrs);
|
let methods = Methods::new(class, class_as_expr, VisModifierSpec::Public(DOT), attrs);
|
||||||
|
|
@ -1704,6 +1686,7 @@ impl ASTConverter {
|
||||||
}
|
}
|
||||||
Expr::Dummy(Dummy::new(None, imports))
|
Expr::Dummy(Dummy::new(None, imports))
|
||||||
}
|
}
|
||||||
|
// from module import foo, bar
|
||||||
StatementType::ImportFrom {
|
StatementType::ImportFrom {
|
||||||
level: _,
|
level: _,
|
||||||
module,
|
module,
|
||||||
|
|
@ -1712,13 +1695,11 @@ impl ASTConverter {
|
||||||
let import_acc = Expr::Accessor(Accessor::Ident(
|
let import_acc = Expr::Accessor(Accessor::Ident(
|
||||||
self.convert_ident("__import__".to_string(), stmt.location),
|
self.convert_ident("__import__".to_string(), stmt.location),
|
||||||
));
|
));
|
||||||
// from . import foo ==> import "./foo"
|
let module = module
|
||||||
let cont = format!(
|
|
||||||
"\"{}\"",
|
|
||||||
module
|
|
||||||
.unwrap_or_else(|| names[0].symbol.clone())
|
.unwrap_or_else(|| names[0].symbol.clone())
|
||||||
.replace('.', "/")
|
.replace('.', "/");
|
||||||
);
|
// from . import foo ==> import "./foo"
|
||||||
|
let cont = format!("\"{module}\"");
|
||||||
let mod_name = Expr::Literal(Literal::new(Token::new(
|
let mod_name = Expr::Literal(Literal::new(Token::new(
|
||||||
TokenKind::StrLit,
|
TokenKind::StrLit,
|
||||||
cont,
|
cont,
|
||||||
|
|
@ -1728,17 +1709,32 @@ impl ASTConverter {
|
||||||
let args = Args::new(vec![PosArg::new(mod_name)], None, vec![], None);
|
let args = Args::new(vec![PosArg::new(mod_name)], None, vec![], None);
|
||||||
let call = import_acc.call_expr(args);
|
let call = import_acc.call_expr(args);
|
||||||
let mut imports = vec![];
|
let mut imports = vec![];
|
||||||
|
// `from module import `
|
||||||
|
let mut loc = PyLocation::new(stmt.location.row(), stmt.location.column() + 5 + module.len() + 8);
|
||||||
for name in names {
|
for name in names {
|
||||||
let true_name = self.convert_ident(name.symbol.clone(), stmt.location);
|
let true_name = self.convert_ident(name.symbol.clone(), loc);
|
||||||
let alias = if let Some(alias) = name.alias {
|
let alias = if let Some(alias) = name.alias {
|
||||||
|
// ` as `
|
||||||
|
for _ in 0..name.symbol.len() + 4 {
|
||||||
|
loc.go_right();
|
||||||
|
}
|
||||||
self.register_name_info(&alias, NameKind::Variable);
|
self.register_name_info(&alias, NameKind::Variable);
|
||||||
|
let alias_len = alias.len();
|
||||||
|
let ident = self.convert_ident(alias, loc);
|
||||||
|
// `, `
|
||||||
|
for _ in 0..alias_len + 2 {
|
||||||
|
loc.go_right();
|
||||||
|
}
|
||||||
VarSignature::new(
|
VarSignature::new(
|
||||||
VarPattern::Ident(self.convert_ident(alias, stmt.location)),
|
VarPattern::Ident(ident),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.register_name_info(&name.symbol, NameKind::Variable);
|
self.register_name_info(&name.symbol, NameKind::Variable);
|
||||||
let ident = self.convert_ident(name.symbol.clone(), stmt.location);
|
let ident = self.convert_ident(name.symbol.clone(), loc);
|
||||||
|
for _ in 0..name.symbol.len() + 2 {
|
||||||
|
loc.go_right();
|
||||||
|
}
|
||||||
VarSignature::new(VarPattern::Ident(ident), None)
|
VarSignature::new(VarPattern::Ident(ident), None)
|
||||||
};
|
};
|
||||||
imports.push(VarRecordAttr::new(true_name, alias));
|
imports.push(VarRecordAttr::new(true_name, alias));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue