mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
clean up
This commit is contained in:
parent
3a9abf5b9c
commit
30c67da455
2 changed files with 20 additions and 53 deletions
|
@ -425,7 +425,7 @@ class FoldTraitDefVisitor(EmitVisitor):
|
|||
self.map_user(user)
|
||||
}
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
fn map_user_cfg(&mut self, _user: U) -> Result<std::marker::PhantomData<Self::TargetU>, Self::Error> {
|
||||
fn map_user_cfg(&mut self, _user: std::marker::PhantomData<U>) -> Result<std::marker::PhantomData<Self::TargetU>, Self::Error> {
|
||||
Ok(std::marker::PhantomData)
|
||||
}
|
||||
""",
|
||||
|
@ -496,11 +496,12 @@ class FoldImplVisitor(EmitVisitor):
|
|||
f"{fields_pattern[0]} {{ {fields_pattern[1]}}} {fields_pattern[2]} => {{",
|
||||
depth + 2,
|
||||
)
|
||||
if not type_info.has_attributes:
|
||||
self.emit('#[cfg(not(feature = "more-attributes"))]', depth + 3)
|
||||
self.emit("let custom = std::marker::PhantomData;", depth + 3)
|
||||
self.emit('#[cfg(feature = "more-attributes")]', depth + 3)
|
||||
self.emit("let custom = folder.map_user(custom)?;", depth + 3)
|
||||
|
||||
map_user_suffix = "" if type_info.has_attributes else "_cfg"
|
||||
self.emit(
|
||||
f"let custom = folder.map_user{map_user_suffix}(custom)?;", depth + 3
|
||||
)
|
||||
|
||||
self.gen_construction(
|
||||
fields_pattern[0], cons.fields, fields_pattern[2], depth + 3
|
||||
)
|
||||
|
@ -533,11 +534,8 @@ class FoldImplVisitor(EmitVisitor):
|
|||
fields_pattern = self.make_pattern(struct_name, struct_name, product.fields)
|
||||
self.emit(f"let {struct_name} {{ {fields_pattern[1]} }} = node;", depth + 1)
|
||||
|
||||
if not has_attributes:
|
||||
self.emit('#[cfg(not(feature = "more-attributes"))]', depth + 3)
|
||||
self.emit("let custom = std::marker::PhantomData;", depth + 3)
|
||||
self.emit('#[cfg(feature = "more-attributes")]', depth + 3)
|
||||
self.emit("let custom = folder.map_user(custom)?;", depth + 3)
|
||||
map_user_suffix = "" if has_attributes else "_cfg"
|
||||
self.emit(f"let custom = folder.map_user{map_user_suffix}(custom)?;", depth + 3)
|
||||
|
||||
self.gen_construction(struct_name, product.fields, "", depth + 1)
|
||||
|
||||
|
@ -956,11 +954,7 @@ def write_ast_def(mod, type_info, f):
|
|||
|
||||
|
||||
def write_fold_def(mod, type_info, f):
|
||||
f.write(
|
||||
"""
|
||||
use crate::generic::Custom;
|
||||
"""
|
||||
)
|
||||
f.write("use crate::generic::Custom;")
|
||||
FoldModuleVisitor(f, type_info).visit(mod)
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ pub trait Fold<U> {
|
|||
#[cfg(not(feature = "more-attributes"))]
|
||||
fn map_user_cfg(
|
||||
&mut self,
|
||||
_user: U,
|
||||
_user: std::marker::PhantomData<U>,
|
||||
) -> Result<std::marker::PhantomData<Self::TargetU>, Self::Error> {
|
||||
Ok(std::marker::PhantomData)
|
||||
}
|
||||
|
@ -111,10 +111,7 @@ pub fn fold_mod<U, F: Fold<U> + ?Sized>(
|
|||
type_ignores,
|
||||
custom,
|
||||
}) => {
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(Mod::Module(ModModule {
|
||||
body: Foldable::fold(body, folder)?,
|
||||
type_ignores: Foldable::fold(type_ignores, folder)?,
|
||||
|
@ -122,20 +119,14 @@ pub fn fold_mod<U, F: Fold<U> + ?Sized>(
|
|||
}))
|
||||
}
|
||||
Mod::Interactive(ModInteractive { body, custom }) => {
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(Mod::Interactive(ModInteractive {
|
||||
body: Foldable::fold(body, folder)?,
|
||||
custom,
|
||||
}))
|
||||
}
|
||||
Mod::Expression(ModExpression { body, custom }) => {
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(Mod::Expression(ModExpression {
|
||||
body: Foldable::fold(body, folder)?,
|
||||
custom,
|
||||
|
@ -146,10 +137,7 @@ pub fn fold_mod<U, F: Fold<U> + ?Sized>(
|
|||
returns,
|
||||
custom,
|
||||
}) => {
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(Mod::FunctionType(ModFunctionType {
|
||||
argtypes: Foldable::fold(argtypes, folder)?,
|
||||
returns: Foldable::fold(returns, folder)?,
|
||||
|
@ -900,10 +888,7 @@ pub fn fold_comprehension<U, F: Fold<U> + ?Sized>(
|
|||
is_async,
|
||||
custom,
|
||||
} = node;
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(Comprehension {
|
||||
target: Foldable::fold(target, folder)?,
|
||||
iter: Foldable::fold(iter, folder)?,
|
||||
|
@ -965,10 +950,7 @@ pub fn fold_arguments<U, F: Fold<U> + ?Sized>(
|
|||
defaults,
|
||||
custom,
|
||||
} = node;
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(Arguments {
|
||||
posonlyargs: Foldable::fold(posonlyargs, folder)?,
|
||||
args: Foldable::fold(args, folder)?,
|
||||
|
@ -1071,10 +1053,7 @@ pub fn fold_withitem<U, F: Fold<U> + ?Sized>(
|
|||
optional_vars,
|
||||
custom,
|
||||
} = node;
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(Withitem {
|
||||
context_expr: Foldable::fold(context_expr, folder)?,
|
||||
optional_vars: Foldable::fold(optional_vars, folder)?,
|
||||
|
@ -1100,10 +1079,7 @@ pub fn fold_match_case<U, F: Fold<U> + ?Sized>(
|
|||
body,
|
||||
custom,
|
||||
} = node;
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(MatchCase {
|
||||
pattern: Foldable::fold(pattern, folder)?,
|
||||
guard: Foldable::fold(guard, folder)?,
|
||||
|
@ -1223,10 +1199,7 @@ pub fn fold_type_ignore<U, F: Fold<U> + ?Sized>(
|
|||
tag,
|
||||
custom,
|
||||
}) => {
|
||||
#[cfg(not(feature = "more-attributes"))]
|
||||
let custom = std::marker::PhantomData;
|
||||
#[cfg(feature = "more-attributes")]
|
||||
let custom = folder.map_user(custom)?;
|
||||
let custom = folder.map_user_cfg(custom)?;
|
||||
Ok(TypeIgnore::TypeIgnore(TypeIgnoreTypeIgnore {
|
||||
lineno: Foldable::fold(lineno, folder)?,
|
||||
tag: Foldable::fold(tag, folder)?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue