mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +00:00
Auto generate visit_source_order
(#17180)
## Summary part of: #15655 I tried generating the source order function using code generation. I tried a simple approach, but it is not enough to generate all of them this way. There is one good thing, that most of the implementations are fine with this. We only have a few that are not. So one benefit of this PR could be it eliminates a lot of the code, hence changing the AST structure will only leave a few places to be fixed. The `source_order` field determines if a node requires a source order implementation. If it’s empty it means source order does not visit anything. Initially I didn’t want to repeat the field names. But I found two things: - `ExprIf` statement unlike other statements does not have the fields defined in source order. This and also some fields do not need to be included in the visit. So we just need a way to determine order, and determine presence. - Relying on the fields sounds more complicated to me. Maybe another solution is to add a new attribute `order` to each field? I'm open to suggestions. But anyway, except for the `ExprIf` we don't need to write the field names in order. Just knowing what fields must be visited are enough. Some nodes had a more complex visitor: `ExprCompare` required zipping two fields. `ExprBoolOp` required a match over the fields. `FstringValue` required a match, I created a new walk_ function that does the match. and used it in code generation. I don’t think this provides real value. Because I mostly moved the code from one file to another. I was tried it as an option. I prefer to leave it in the code as before. Some visitors visit a slice of items. Others visit a single element. I put a check on this in code generation to see if the field requires a for loop or not. I think better approach is to have a consistent style. So we can by default loop over any field that is a sequence. For field types `StringLiteralValue` and `BytesLiteralValue` the types are not a sequence in toml definition. But they implement `iter` so they are iterated over. So the code generation does not properly identify this. So in the code I'm checking for their types. ## Test Plan All the tests should pass without any changes. I checked the generated code to make sure it's the same as old code. I'm not sure if there's a test for the source order visitor.
This commit is contained in:
parent
bd89838212
commit
3ada36b766
5 changed files with 1048 additions and 886 deletions
|
@ -37,6 +37,10 @@
|
|||
# derives:
|
||||
# List of derives to add to the syntax node struct. Clone, Debug, PartialEq are added by default.
|
||||
#
|
||||
# custom_source_order:
|
||||
# A boolean that specifies if this node has a custom source order visitor implementation.
|
||||
# generation of visit_source_order will be skipped for this node.
|
||||
#
|
||||
# fields:
|
||||
# List of fields in the syntax node struct. Each field is a table with the
|
||||
# following keys:
|
||||
|
@ -48,6 +52,10 @@
|
|||
# * `Expr*` - A vector of Expr.
|
||||
# * `&Expr*` - A boxed slice of Expr.
|
||||
# These properties cannot be nested, for example we cannot create a vector of option types.
|
||||
# * is_annotation - If this field is a type annotation.
|
||||
#
|
||||
# source_order:
|
||||
# Defines in what order the fields appear in source
|
||||
#
|
||||
# variant:
|
||||
# The name of the enum variant for this syntax node. Defaults to the node
|
||||
|
@ -57,9 +65,13 @@
|
|||
anynode_is_label = "module"
|
||||
doc = "See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)"
|
||||
|
||||
[Mod.nodes]
|
||||
ModModule = {}
|
||||
ModExpression = {}
|
||||
[Mod.nodes.ModModule]
|
||||
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
|
||||
fields = [{ name = "body", type = "Stmt*" }]
|
||||
|
||||
[Mod.nodes.ModExpression]
|
||||
doc = "See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)"
|
||||
fields = [{ name = "body", type = "Box<Expr>" }]
|
||||
|
||||
[Stmt]
|
||||
add_suffix_to_is_methods = true
|
||||
|
@ -77,8 +89,7 @@ fields = [
|
|||
{ name = "name", type = "Identifier" },
|
||||
{ name = "type_params", type = "Box<crate::TypeParams>?" },
|
||||
{ name = "parameters", type = "Box<crate::Parameters>" },
|
||||
|
||||
{ name = "returns", type = "Expr?" },
|
||||
{ name = "returns", type = "Expr?", is_annotation = true },
|
||||
{ name = "body", type = "Stmt*" },
|
||||
]
|
||||
|
||||
|
@ -127,7 +138,7 @@ fields = [
|
|||
doc = "See also [AnnAssign](https://docs.python.org/3/library/ast.html#ast.AnnAssign)"
|
||||
fields = [
|
||||
{ name = "target", type = "Expr" },
|
||||
{ name = "annotation", type = "Expr" },
|
||||
{ name = "annotation", type = "Expr", is_annotation = true },
|
||||
{ name = "value", type = "Expr?" },
|
||||
{ name = "simple", type = "bool" },
|
||||
]
|
||||
|
@ -305,6 +316,7 @@ doc = "See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)"
|
|||
[Expr.nodes.ExprBoolOp]
|
||||
doc = "See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp)"
|
||||
fields = [{ name = "op", type = "BoolOp" }, { name = "values", type = "Expr*" }]
|
||||
custom_source_order = true
|
||||
|
||||
[Expr.nodes.ExprNamed]
|
||||
doc = "See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr)"
|
||||
|
@ -339,10 +351,12 @@ fields = [
|
|||
{ name = "body", type = "Expr" },
|
||||
{ name = "orelse", type = "Expr" },
|
||||
]
|
||||
source_order = ["body", "test", "orelse"]
|
||||
|
||||
[Expr.nodes.ExprDict]
|
||||
doc = "See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict)"
|
||||
fields = [{ name = "items", type = "DictItem*" }]
|
||||
custom_source_order = true
|
||||
|
||||
[Expr.nodes.ExprSet]
|
||||
doc = "See also [Set](https://docs.python.org/3/library/ast.html#ast.Set)"
|
||||
|
@ -397,6 +411,8 @@ fields = [
|
|||
{ name = "ops", type = "&CmpOp*" },
|
||||
{ name = "comparators", type = "&Expr*" },
|
||||
]
|
||||
# The fields must be visited simultaneously
|
||||
custom_source_order = true
|
||||
|
||||
[Expr.nodes.ExprCall]
|
||||
doc = "See also [Call](https://docs.python.org/3/library/ast.html#ast.Call)"
|
||||
|
@ -415,16 +431,21 @@ it keeps them separate and provide various methods to access the parts.
|
|||
|
||||
See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr)"""
|
||||
fields = [{ name = "value", type = "FStringValue" }]
|
||||
custom_source_order = true
|
||||
|
||||
[Expr.nodes.ExprStringLiteral]
|
||||
doc = """An AST node that represents either a single-part string literal
|
||||
or an implicitly concatenated string literal."""
|
||||
fields = [{ name = "value", type = "StringLiteralValue" }]
|
||||
# Because StringLiteralValue type is an iterator and it's not clear from the type
|
||||
custom_source_order = true
|
||||
|
||||
[Expr.nodes.ExprBytesLiteral]
|
||||
doc = """An AST node that represents either a single-part bytestring literal
|
||||
or an implicitly concatenated bytestring literal."""
|
||||
fields = [{ name = "value", type = "BytesLiteralValue" }]
|
||||
# Because BytesLiteralValue type is an iterator and it's not clear from the type
|
||||
custom_source_order = true
|
||||
|
||||
[Expr.nodes.ExprNumberLiteral]
|
||||
fields = [{ name = "value", type = "Number" }]
|
||||
|
|
|
@ -15,7 +15,7 @@ from typing import Any
|
|||
import tomllib
|
||||
|
||||
# Types that require `crate::`. We can slowly remove these types as we move them to generate scripts.
|
||||
types_requiring_create_prefix = [
|
||||
types_requiring_create_prefix = {
|
||||
"IpyEscapeKind",
|
||||
"ExprContext",
|
||||
"Identifier",
|
||||
|
@ -33,12 +33,11 @@ types_requiring_create_prefix = [
|
|||
"Decorator",
|
||||
"TypeParams",
|
||||
"Parameters",
|
||||
"Arguments",
|
||||
"ElifElseClause",
|
||||
"WithItem",
|
||||
"MatchCase",
|
||||
"Alias",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def rustfmt(code: str) -> str:
|
||||
|
@ -124,6 +123,8 @@ class Node:
|
|||
doc: str | None
|
||||
fields: list[Field] | None
|
||||
derives: list[str]
|
||||
custom_source_order: bool
|
||||
source_order: list[str] | None
|
||||
|
||||
def __init__(self, group: Group, node_name: str, node: dict[str, Any]) -> None:
|
||||
self.name = node_name
|
||||
|
@ -133,26 +134,82 @@ class Node:
|
|||
fields = node.get("fields")
|
||||
if fields is not None:
|
||||
self.fields = [Field(f) for f in fields]
|
||||
self.custom_source_order = node.get("custom_source_order", False)
|
||||
self.derives = node.get("derives", [])
|
||||
self.doc = node.get("doc")
|
||||
self.source_order = node.get("source_order")
|
||||
|
||||
def fields_in_source_order(self) -> list[Field]:
|
||||
if self.fields is None:
|
||||
return []
|
||||
if self.source_order is None:
|
||||
return list(filter(lambda x: not x.skip_source_order(), self.fields))
|
||||
|
||||
fields = []
|
||||
for field_name in self.source_order:
|
||||
field = None
|
||||
for field in self.fields:
|
||||
if field.skip_source_order():
|
||||
continue
|
||||
if field.name == field_name:
|
||||
field = field
|
||||
break
|
||||
fields.append(field)
|
||||
return fields
|
||||
|
||||
|
||||
@dataclass
|
||||
class Field:
|
||||
name: str
|
||||
ty: str
|
||||
_skip_visit: bool
|
||||
is_annotation: bool
|
||||
parsed_ty: FieldType
|
||||
|
||||
def __init__(self, field: dict[str, Any]) -> None:
|
||||
self.name = field["name"]
|
||||
self.ty = field["type"]
|
||||
self.parsed_ty = FieldType(self.ty)
|
||||
self._skip_visit = field.get("skip_visit", False)
|
||||
self.is_annotation = field.get("is_annotation", False)
|
||||
|
||||
def skip_source_order(self) -> bool:
|
||||
return self._skip_visit or self.parsed_ty.inner in [
|
||||
"str",
|
||||
"ExprContext",
|
||||
"Name",
|
||||
"u32",
|
||||
"bool",
|
||||
"Number",
|
||||
"IpyEscapeKind",
|
||||
]
|
||||
|
||||
|
||||
# Extracts the type argument from the given rust type with AST field type syntax.
|
||||
# Box<str> -> str
|
||||
# Box<Expr?> -> Expr
|
||||
# If the type does not have a type argument, it will return the string.
|
||||
# Does not support nested types
|
||||
def extract_type_argument(rust_type_str: str) -> str:
|
||||
rust_type_str = rust_type_str.replace("*", "")
|
||||
rust_type_str = rust_type_str.replace("?", "")
|
||||
rust_type_str = rust_type_str.replace("&", "")
|
||||
|
||||
open_bracket_index = rust_type_str.find("<")
|
||||
if open_bracket_index == -1:
|
||||
return rust_type_str
|
||||
close_bracket_index = rust_type_str.rfind(">")
|
||||
if close_bracket_index == -1 or close_bracket_index <= open_bracket_index:
|
||||
raise ValueError(f"Brackets are not balanced for type {rust_type_str}")
|
||||
inner_type = rust_type_str[open_bracket_index + 1 : close_bracket_index].strip()
|
||||
return inner_type
|
||||
|
||||
|
||||
@dataclass
|
||||
class FieldType:
|
||||
rule: str
|
||||
name: str
|
||||
inner: str
|
||||
seq: bool = False
|
||||
optional: bool = False
|
||||
slice_: bool = False
|
||||
|
@ -160,6 +217,7 @@ class FieldType:
|
|||
def __init__(self, rule: str) -> None:
|
||||
self.rule = rule
|
||||
self.name = ""
|
||||
self.inner = extract_type_argument(rule)
|
||||
|
||||
# The following cases are the limitations of this parser(and not used in the ast.toml):
|
||||
# * Rules that involve declaring a sequence with optional items e.g. Vec<Option<...>>
|
||||
|
@ -201,6 +259,7 @@ def write_preamble(out: list[str]) -> None:
|
|||
// Run `crates/ruff_python_ast/generate.py` to re-generate the file.
|
||||
|
||||
use crate::name::Name;
|
||||
use crate::visitor::source_order::SourceOrderVisitor;
|
||||
""")
|
||||
|
||||
|
||||
|
@ -703,6 +762,98 @@ def write_node(out: list[str], ast: Ast) -> None:
|
|||
out.append("")
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Source order visitor
|
||||
|
||||
|
||||
@dataclass
|
||||
class VisitorInfo:
|
||||
name: str
|
||||
accepts_sequence: bool = False
|
||||
|
||||
|
||||
# Map of AST node types to their corresponding visitor information
|
||||
type_to_visitor_function: dict[str, VisitorInfo] = {
|
||||
"Decorator": VisitorInfo("visit_decorator"),
|
||||
"Identifier": VisitorInfo("visit_identifier"),
|
||||
"crate::TypeParams": VisitorInfo("visit_type_params", True),
|
||||
"crate::Parameters": VisitorInfo("visit_parameters", True),
|
||||
"Expr": VisitorInfo("visit_expr"),
|
||||
"Stmt": VisitorInfo("visit_body", True),
|
||||
"Arguments": VisitorInfo("visit_arguments", True),
|
||||
"crate::Arguments": VisitorInfo("visit_arguments", True),
|
||||
"Operator": VisitorInfo("visit_operator"),
|
||||
"ElifElseClause": VisitorInfo("visit_elif_else_clause"),
|
||||
"WithItem": VisitorInfo("visit_with_item"),
|
||||
"MatchCase": VisitorInfo("visit_match_case"),
|
||||
"ExceptHandler": VisitorInfo("visit_except_handler"),
|
||||
"Alias": VisitorInfo("visit_alias"),
|
||||
"UnaryOp": VisitorInfo("visit_unary_op"),
|
||||
"DictItem": VisitorInfo("visit_dict_item"),
|
||||
"Comprehension": VisitorInfo("visit_comprehension"),
|
||||
"CmpOp": VisitorInfo("visit_cmp_op"),
|
||||
"FStringValue": VisitorInfo("visit_f_string_value"),
|
||||
"StringLiteralValue": VisitorInfo("visit_string_literal"),
|
||||
"BytesLiteralValue": VisitorInfo("visit_bytes_literal"),
|
||||
}
|
||||
annotation_visitor_function = VisitorInfo("visit_annotation")
|
||||
|
||||
|
||||
def write_source_order(out: list[str], ast: Ast) -> None:
|
||||
for group in ast.groups:
|
||||
for node in group.nodes:
|
||||
if node.fields is None or node.custom_source_order:
|
||||
continue
|
||||
name = node.name
|
||||
fields_list = ""
|
||||
body = ""
|
||||
|
||||
for field in node.fields:
|
||||
if field.skip_source_order():
|
||||
fields_list += f"{field.name}: _,\n"
|
||||
else:
|
||||
fields_list += f"{field.name},\n"
|
||||
fields_list += "range: _,\n"
|
||||
|
||||
for field in node.fields_in_source_order():
|
||||
visitor = type_to_visitor_function[field.parsed_ty.inner]
|
||||
if field.is_annotation:
|
||||
visitor = annotation_visitor_function
|
||||
|
||||
if field.parsed_ty.optional:
|
||||
body += f"""
|
||||
if let Some({field.name}) = {field.name} {{
|
||||
visitor.{visitor.name}({field.name});
|
||||
}}\n
|
||||
"""
|
||||
elif not visitor.accepts_sequence and field.parsed_ty.seq:
|
||||
body += f"""
|
||||
for elm in {field.name} {{
|
||||
visitor.{visitor.name}(elm);
|
||||
}}
|
||||
"""
|
||||
else:
|
||||
body += f"visitor.{visitor.name}({field.name});\n"
|
||||
|
||||
visitor_arg_name = "visitor"
|
||||
if len(node.fields_in_source_order()) == 0:
|
||||
visitor_arg_name = "_"
|
||||
|
||||
out.append(f"""
|
||||
impl {name} {{
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, {visitor_arg_name}: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{{
|
||||
let {name} {{
|
||||
{fields_list}
|
||||
}} = self;
|
||||
{body}
|
||||
}}
|
||||
}}
|
||||
""")
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Format and write output
|
||||
|
||||
|
@ -715,6 +866,7 @@ def generate(ast: Ast) -> list[str]:
|
|||
write_anynoderef(out, ast)
|
||||
write_nodekind(out, ast)
|
||||
write_node(out, ast)
|
||||
write_source_order(out, ast)
|
||||
return out
|
||||
|
||||
|
||||
|
|
859
crates/ruff_python_ast/src/generated.rs
generated
859
crates/ruff_python_ast/src/generated.rs
generated
|
@ -2,6 +2,7 @@
|
|||
// Run `crates/ruff_python_ast/generate.py` to re-generate the file.
|
||||
|
||||
use crate::name::Name;
|
||||
use crate::visitor::source_order::SourceOrderVisitor;
|
||||
|
||||
/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
@ -6584,6 +6585,20 @@ impl AnyNodeRef<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ModModule {
|
||||
pub range: ruff_text_size::TextRange,
|
||||
pub body: Vec<Stmt>,
|
||||
}
|
||||
|
||||
/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ModExpression {
|
||||
pub range: ruff_text_size::TextRange,
|
||||
pub body: Box<Expr>,
|
||||
}
|
||||
|
||||
/// See also [FunctionDef](https://docs.python.org/3/library/ast.html#ast.FunctionDef)
|
||||
/// and [AsyncFunctionDef](https://docs.python.org/3/library/ast.html#ast.AsyncFunctionDef).
|
||||
///
|
||||
|
@ -7123,3 +7138,847 @@ pub struct ExprIpyEscapeCommand {
|
|||
pub kind: crate::IpyEscapeKind,
|
||||
pub value: Box<str>,
|
||||
}
|
||||
|
||||
impl ModModule {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ModModule { body, range: _ } = self;
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ModExpression {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ModExpression { body, range: _ } = self;
|
||||
visitor.visit_expr(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtFunctionDef {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtFunctionDef {
|
||||
is_async: _,
|
||||
decorator_list,
|
||||
name,
|
||||
type_params,
|
||||
parameters,
|
||||
returns,
|
||||
body,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for elm in decorator_list {
|
||||
visitor.visit_decorator(elm);
|
||||
}
|
||||
visitor.visit_identifier(name);
|
||||
|
||||
if let Some(type_params) = type_params {
|
||||
visitor.visit_type_params(type_params);
|
||||
}
|
||||
|
||||
visitor.visit_parameters(parameters);
|
||||
|
||||
if let Some(returns) = returns {
|
||||
visitor.visit_annotation(returns);
|
||||
}
|
||||
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtClassDef {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtClassDef {
|
||||
decorator_list,
|
||||
name,
|
||||
type_params,
|
||||
arguments,
|
||||
body,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for elm in decorator_list {
|
||||
visitor.visit_decorator(elm);
|
||||
}
|
||||
visitor.visit_identifier(name);
|
||||
|
||||
if let Some(type_params) = type_params {
|
||||
visitor.visit_type_params(type_params);
|
||||
}
|
||||
|
||||
if let Some(arguments) = arguments {
|
||||
visitor.visit_arguments(arguments);
|
||||
}
|
||||
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtReturn {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtReturn { value, range: _ } = self;
|
||||
|
||||
if let Some(value) = value {
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtDelete {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtDelete { targets, range: _ } = self;
|
||||
|
||||
for elm in targets {
|
||||
visitor.visit_expr(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtTypeAlias {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtTypeAlias {
|
||||
name,
|
||||
type_params,
|
||||
value,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(name);
|
||||
|
||||
if let Some(type_params) = type_params {
|
||||
visitor.visit_type_params(type_params);
|
||||
}
|
||||
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtAssign {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtAssign {
|
||||
targets,
|
||||
value,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for elm in targets {
|
||||
visitor.visit_expr(elm);
|
||||
}
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtAugAssign {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtAugAssign {
|
||||
target,
|
||||
op,
|
||||
value,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_operator(op);
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtAnnAssign {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtAnnAssign {
|
||||
target,
|
||||
annotation,
|
||||
value,
|
||||
simple: _,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_annotation(annotation);
|
||||
|
||||
if let Some(value) = value {
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtFor {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtFor {
|
||||
is_async: _,
|
||||
target,
|
||||
iter,
|
||||
body,
|
||||
orelse,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_expr(iter);
|
||||
visitor.visit_body(body);
|
||||
visitor.visit_body(orelse);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtWhile {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtWhile {
|
||||
test,
|
||||
body,
|
||||
orelse,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(test);
|
||||
visitor.visit_body(body);
|
||||
visitor.visit_body(orelse);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtIf {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtIf {
|
||||
test,
|
||||
body,
|
||||
elif_else_clauses,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(test);
|
||||
visitor.visit_body(body);
|
||||
|
||||
for elm in elif_else_clauses {
|
||||
visitor.visit_elif_else_clause(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtWith {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtWith {
|
||||
is_async: _,
|
||||
items,
|
||||
body,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for elm in items {
|
||||
visitor.visit_with_item(elm);
|
||||
}
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtMatch {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtMatch {
|
||||
subject,
|
||||
cases,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(subject);
|
||||
|
||||
for elm in cases {
|
||||
visitor.visit_match_case(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtRaise {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtRaise {
|
||||
exc,
|
||||
cause,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
if let Some(exc) = exc {
|
||||
visitor.visit_expr(exc);
|
||||
}
|
||||
|
||||
if let Some(cause) = cause {
|
||||
visitor.visit_expr(cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtTry {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtTry {
|
||||
body,
|
||||
handlers,
|
||||
orelse,
|
||||
finalbody,
|
||||
is_star: _,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_body(body);
|
||||
|
||||
for elm in handlers {
|
||||
visitor.visit_except_handler(elm);
|
||||
}
|
||||
visitor.visit_body(orelse);
|
||||
visitor.visit_body(finalbody);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtAssert {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtAssert {
|
||||
test,
|
||||
msg,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(test);
|
||||
|
||||
if let Some(msg) = msg {
|
||||
visitor.visit_expr(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtImport {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtImport { names, range: _ } = self;
|
||||
|
||||
for elm in names {
|
||||
visitor.visit_alias(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtImportFrom {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtImportFrom {
|
||||
module,
|
||||
names,
|
||||
level: _,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
if let Some(module) = module {
|
||||
visitor.visit_identifier(module);
|
||||
}
|
||||
|
||||
for elm in names {
|
||||
visitor.visit_alias(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtGlobal {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtGlobal { names, range: _ } = self;
|
||||
|
||||
for elm in names {
|
||||
visitor.visit_identifier(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtNonlocal {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtNonlocal { names, range: _ } = self;
|
||||
|
||||
for elm in names {
|
||||
visitor.visit_identifier(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtExpr {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtExpr { value, range: _ } = self;
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtPass {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtPass { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtBreak {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtBreak { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtContinue {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtContinue { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl StmtIpyEscapeCommand {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let StmtIpyEscapeCommand {
|
||||
kind: _,
|
||||
value: _,
|
||||
range: _,
|
||||
} = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprNamed {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprNamed {
|
||||
target,
|
||||
value,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprBinOp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprBinOp {
|
||||
left,
|
||||
op,
|
||||
right,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(left);
|
||||
visitor.visit_operator(op);
|
||||
visitor.visit_expr(right);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprUnaryOp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprUnaryOp {
|
||||
op,
|
||||
operand,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_unary_op(op);
|
||||
visitor.visit_expr(operand);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprLambda {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprLambda {
|
||||
parameters,
|
||||
body,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
if let Some(parameters) = parameters {
|
||||
visitor.visit_parameters(parameters);
|
||||
}
|
||||
|
||||
visitor.visit_expr(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprIf {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprIf {
|
||||
test,
|
||||
body,
|
||||
orelse,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(body);
|
||||
visitor.visit_expr(test);
|
||||
visitor.visit_expr(orelse);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprSet {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprSet { elts, range: _ } = self;
|
||||
|
||||
for elm in elts {
|
||||
visitor.visit_expr(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprListComp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprListComp {
|
||||
elt,
|
||||
generators,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(elt);
|
||||
|
||||
for elm in generators {
|
||||
visitor.visit_comprehension(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprSetComp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprSetComp {
|
||||
elt,
|
||||
generators,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(elt);
|
||||
|
||||
for elm in generators {
|
||||
visitor.visit_comprehension(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprDictComp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprDictComp {
|
||||
key,
|
||||
value,
|
||||
generators,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(key);
|
||||
visitor.visit_expr(value);
|
||||
|
||||
for elm in generators {
|
||||
visitor.visit_comprehension(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprGenerator {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprGenerator {
|
||||
elt,
|
||||
generators,
|
||||
parenthesized: _,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(elt);
|
||||
|
||||
for elm in generators {
|
||||
visitor.visit_comprehension(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprAwait {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprAwait { value, range: _ } = self;
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprYield {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprYield { value, range: _ } = self;
|
||||
|
||||
if let Some(value) = value {
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprYieldFrom {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprYieldFrom { value, range: _ } = self;
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprCall {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprCall {
|
||||
func,
|
||||
arguments,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(func);
|
||||
visitor.visit_arguments(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprNumberLiteral {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprNumberLiteral { value: _, range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprBooleanLiteral {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprBooleanLiteral { value: _, range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprNoneLiteral {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprNoneLiteral { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprEllipsisLiteral {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprEllipsisLiteral { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprAttribute {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprAttribute {
|
||||
value,
|
||||
attr,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(value);
|
||||
visitor.visit_identifier(attr);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprSubscript {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprSubscript {
|
||||
value,
|
||||
slice,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(value);
|
||||
visitor.visit_expr(slice);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprStarred {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprStarred {
|
||||
value,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprName {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprName {
|
||||
id: _,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprList {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprList {
|
||||
elts,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for elm in elts {
|
||||
visitor.visit_expr(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprTuple {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprTuple {
|
||||
elts,
|
||||
ctx: _,
|
||||
parenthesized: _,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for elm in elts {
|
||||
visitor.visit_expr(elm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprSlice {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprSlice {
|
||||
lower,
|
||||
upper,
|
||||
step,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
if let Some(lower) = lower {
|
||||
visitor.visit_expr(lower);
|
||||
}
|
||||
|
||||
if let Some(upper) = upper {
|
||||
visitor.visit_expr(upper);
|
||||
}
|
||||
|
||||
if let Some(step) = step {
|
||||
visitor.visit_expr(step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExprIpyEscapeCommand {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ExprIpyEscapeCommand {
|
||||
kind: _,
|
||||
value: _,
|
||||
range: _,
|
||||
} = self;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,255 +6,6 @@ use crate::{
|
|||
PatternKeyword,
|
||||
};
|
||||
|
||||
impl ast::ModModule {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ModModule { body, range: _ } = self;
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ModExpression {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ModExpression { body, range: _ } = self;
|
||||
visitor.visit_expr(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtFunctionDef {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtFunctionDef {
|
||||
parameters,
|
||||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
type_params,
|
||||
range: _,
|
||||
is_async: _,
|
||||
name,
|
||||
} = self;
|
||||
|
||||
for decorator in decorator_list {
|
||||
visitor.visit_decorator(decorator);
|
||||
}
|
||||
|
||||
visitor.visit_identifier(name);
|
||||
|
||||
if let Some(type_params) = type_params {
|
||||
visitor.visit_type_params(type_params);
|
||||
}
|
||||
|
||||
visitor.visit_parameters(parameters);
|
||||
|
||||
if let Some(expr) = returns {
|
||||
visitor.visit_annotation(expr);
|
||||
}
|
||||
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtClassDef {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtClassDef {
|
||||
arguments,
|
||||
body,
|
||||
decorator_list,
|
||||
type_params,
|
||||
name,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for decorator in decorator_list {
|
||||
visitor.visit_decorator(decorator);
|
||||
}
|
||||
|
||||
visitor.visit_identifier(name);
|
||||
|
||||
if let Some(type_params) = type_params {
|
||||
visitor.visit_type_params(type_params);
|
||||
}
|
||||
|
||||
if let Some(arguments) = arguments {
|
||||
visitor.visit_arguments(arguments);
|
||||
}
|
||||
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtReturn {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtReturn { value, range: _ } = self;
|
||||
if let Some(expr) = value {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtDelete {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtDelete { targets, range: _ } = self;
|
||||
for expr in targets {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtTypeAlias {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtTypeAlias {
|
||||
range: _,
|
||||
name,
|
||||
type_params,
|
||||
value,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(name);
|
||||
if let Some(type_params) = type_params {
|
||||
visitor.visit_type_params(type_params);
|
||||
}
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtAssign {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtAssign {
|
||||
targets,
|
||||
value,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for expr in targets {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtAugAssign {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtAugAssign {
|
||||
target,
|
||||
op,
|
||||
value,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_operator(op);
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtAnnAssign {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtAnnAssign {
|
||||
target,
|
||||
annotation,
|
||||
value,
|
||||
range: _,
|
||||
simple: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_annotation(annotation);
|
||||
if let Some(expr) = value {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtFor {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtFor {
|
||||
target,
|
||||
iter,
|
||||
body,
|
||||
orelse,
|
||||
range: _,
|
||||
is_async: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_expr(iter);
|
||||
visitor.visit_body(body);
|
||||
visitor.visit_body(orelse);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtWhile {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtWhile {
|
||||
test,
|
||||
body,
|
||||
orelse,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(test);
|
||||
visitor.visit_body(body);
|
||||
visitor.visit_body(orelse);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtIf {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtIf {
|
||||
test,
|
||||
body,
|
||||
elif_else_clauses,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(test);
|
||||
visitor.visit_body(body);
|
||||
for clause in elif_else_clauses {
|
||||
visitor.visit_elif_else_clause(clause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ElifElseClause {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
|
@ -272,215 +23,19 @@ impl ast::ElifElseClause {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::StmtWith {
|
||||
impl ast::ExprDict {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtWith {
|
||||
items,
|
||||
body,
|
||||
is_async: _,
|
||||
range: _,
|
||||
} = self;
|
||||
let ast::ExprDict { items, range: _ } = self;
|
||||
|
||||
for with_item in items {
|
||||
visitor.visit_with_item(with_item);
|
||||
for ast::DictItem { key, value } in items {
|
||||
if let Some(key) = key {
|
||||
visitor.visit_expr(key);
|
||||
}
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtMatch {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtMatch {
|
||||
subject,
|
||||
cases,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(subject);
|
||||
for match_case in cases {
|
||||
visitor.visit_match_case(match_case);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtRaise {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtRaise {
|
||||
exc,
|
||||
cause,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
if let Some(expr) = exc {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
if let Some(expr) = cause {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtTry {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtTry {
|
||||
body,
|
||||
handlers,
|
||||
orelse,
|
||||
finalbody,
|
||||
is_star: _,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_body(body);
|
||||
for except_handler in handlers {
|
||||
visitor.visit_except_handler(except_handler);
|
||||
}
|
||||
visitor.visit_body(orelse);
|
||||
visitor.visit_body(finalbody);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtAssert {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtAssert {
|
||||
test,
|
||||
msg,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(test);
|
||||
if let Some(expr) = msg {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtImport {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtImport { names, range: _ } = self;
|
||||
|
||||
for alias in names {
|
||||
visitor.visit_alias(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtImportFrom {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtImportFrom {
|
||||
range: _,
|
||||
module,
|
||||
names,
|
||||
level: _,
|
||||
} = self;
|
||||
|
||||
if let Some(module) = module {
|
||||
visitor.visit_identifier(module);
|
||||
}
|
||||
|
||||
for alias in names {
|
||||
visitor.visit_alias(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtGlobal {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtGlobal { range: _, names } = self;
|
||||
|
||||
for name in names {
|
||||
visitor.visit_identifier(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtNonlocal {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtNonlocal { range: _, names } = self;
|
||||
|
||||
for name in names {
|
||||
visitor.visit_identifier(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtExpr {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtExpr { value, range: _ } = self;
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtPass {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtPass { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtBreak {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtBreak { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtContinue {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtContinue { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::StmtIpyEscapeCommand {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::StmtIpyEscapeCommand {
|
||||
range: _,
|
||||
kind: _,
|
||||
value: _,
|
||||
} = self;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -509,227 +64,6 @@ impl ast::ExprBoolOp {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::ExprNamed {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprNamed {
|
||||
target,
|
||||
value,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(target);
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprBinOp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprBinOp {
|
||||
left,
|
||||
op,
|
||||
right,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(left);
|
||||
visitor.visit_operator(op);
|
||||
visitor.visit_expr(right);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprUnaryOp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprUnaryOp {
|
||||
op,
|
||||
operand,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_unary_op(op);
|
||||
visitor.visit_expr(operand);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprLambda {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprLambda {
|
||||
parameters,
|
||||
body,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
if let Some(parameters) = parameters {
|
||||
visitor.visit_parameters(parameters);
|
||||
}
|
||||
visitor.visit_expr(body);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprIf {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprIf {
|
||||
test,
|
||||
body,
|
||||
orelse,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
// `body if test else orelse`
|
||||
visitor.visit_expr(body);
|
||||
visitor.visit_expr(test);
|
||||
visitor.visit_expr(orelse);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprDict {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprDict { items, range: _ } = self;
|
||||
|
||||
for ast::DictItem { key, value } in items {
|
||||
if let Some(key) = key {
|
||||
visitor.visit_expr(key);
|
||||
}
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprSet {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprSet { elts, range: _ } = self;
|
||||
|
||||
for expr in elts {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprListComp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprListComp {
|
||||
elt,
|
||||
generators,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(elt);
|
||||
for comprehension in generators {
|
||||
visitor.visit_comprehension(comprehension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprSetComp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprSetComp {
|
||||
elt,
|
||||
generators,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(elt);
|
||||
for comprehension in generators {
|
||||
visitor.visit_comprehension(comprehension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprDictComp {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprDictComp {
|
||||
key,
|
||||
value,
|
||||
generators,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(key);
|
||||
visitor.visit_expr(value);
|
||||
|
||||
for comprehension in generators {
|
||||
visitor.visit_comprehension(comprehension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprGenerator {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprGenerator {
|
||||
elt,
|
||||
generators,
|
||||
range: _,
|
||||
parenthesized: _,
|
||||
} = self;
|
||||
visitor.visit_expr(elt);
|
||||
for comprehension in generators {
|
||||
visitor.visit_comprehension(comprehension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprAwait {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprAwait { value, range: _ } = self;
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprYield {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprYield { value, range: _ } = self;
|
||||
if let Some(expr) = value {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprYieldFrom {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprYieldFrom { value, range: _ } = self;
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprCompare {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
|
@ -751,21 +85,6 @@ impl ast::ExprCompare {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::ExprCall {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprCall {
|
||||
func,
|
||||
arguments,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(func);
|
||||
visitor.visit_arguments(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::FStringFormatSpec {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
|
@ -852,181 +171,6 @@ impl ast::ExprBytesLiteral {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::ExprNumberLiteral {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprNumberLiteral { range: _, value: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprBooleanLiteral {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprBooleanLiteral { range: _, value: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprNoneLiteral {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprNoneLiteral { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprEllipsisLiteral {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprEllipsisLiteral { range: _ } = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprAttribute {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprAttribute {
|
||||
value,
|
||||
attr,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(value);
|
||||
visitor.visit_identifier(attr);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprSubscript {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprSubscript {
|
||||
value,
|
||||
slice,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
visitor.visit_expr(value);
|
||||
visitor.visit_expr(slice);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprStarred {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprStarred {
|
||||
value,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
visitor.visit_expr(value);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprName {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprName {
|
||||
range: _,
|
||||
id: _,
|
||||
ctx: _,
|
||||
} = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprList {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprList {
|
||||
elts,
|
||||
ctx: _,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
for expr in elts {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprTuple {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprTuple {
|
||||
elts,
|
||||
ctx: _,
|
||||
range: _,
|
||||
parenthesized: _,
|
||||
} = self;
|
||||
|
||||
for expr in elts {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprSlice {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprSlice {
|
||||
lower,
|
||||
upper,
|
||||
step,
|
||||
range: _,
|
||||
} = self;
|
||||
|
||||
if let Some(expr) = lower {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
if let Some(expr) = upper {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
if let Some(expr) = step {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExprIpyEscapeCommand {
|
||||
#[inline]
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, _visitor: &mut V)
|
||||
where
|
||||
V: SourceOrderVisitor<'a> + ?Sized,
|
||||
{
|
||||
let ast::ExprIpyEscapeCommand {
|
||||
range: _,
|
||||
kind: _,
|
||||
value: _,
|
||||
} = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ExceptHandlerExceptHandler {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
where
|
||||
|
|
|
@ -26,20 +26,6 @@ use crate::{
|
|||
TypeParam,
|
||||
};
|
||||
|
||||
/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ModModule {
|
||||
pub range: TextRange,
|
||||
pub body: Vec<Stmt>,
|
||||
}
|
||||
|
||||
/// See also [Expression](https://docs.python.org/3/library/ast.html#ast.Expression)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ModExpression {
|
||||
pub range: TextRange,
|
||||
pub body: Box<Expr>,
|
||||
}
|
||||
|
||||
impl StmtClassDef {
|
||||
/// Return an iterator over the bases of the class.
|
||||
pub fn bases(&self) -> &[Expr] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue