Commit 1e3fcd78 authored by Tom Niget's avatar Tom Niget

Move function parameters emission to separate method

parent 0e3c66da
...@@ -68,6 +68,19 @@ class BlockVisitor(NodeVisitor): ...@@ -68,6 +68,19 @@ class BlockVisitor(NodeVisitor):
yield f" {name};" yield f" {name};"
yield from child_visitor.visit(child) yield from child_visitor.visit(child)
def visit_func_params(self, args: Iterable[tuple[str, BaseType, Optional[ast.expr]]], emission: FunctionEmissionKind) -> Iterable[str]:
for i, (arg, argty, default) in enumerate(args):
if i != 0:
yield ", "
if emission == FunctionEmissionKind.METHOD and i == 0:
yield "Self"
else:
yield from self.visit(argty)
yield arg
if emission in {FunctionEmissionKind.DECLARATION, FunctionEmissionKind.LAMBDA, FunctionEmissionKind.METHOD} and default:
yield " = "
yield from self.expr().visit(default)
def visit_func_new(self, node: ast.FunctionDef, emission: FunctionEmissionKind, skip_first_arg: bool = False) -> Iterable[str]: def visit_func_new(self, node: ast.FunctionDef, emission: FunctionEmissionKind, skip_first_arg: bool = False) -> Iterable[str]:
if emission == FunctionEmissionKind.LAMBDA: if emission == FunctionEmissionKind.LAMBDA:
yield "[&]" yield "[&]"
...@@ -83,17 +96,7 @@ class BlockVisitor(NodeVisitor): ...@@ -83,17 +96,7 @@ class BlockVisitor(NodeVisitor):
args_iter = zip(node.args.args, node.type.parameters, padded_defaults) args_iter = zip(node.args.args, node.type.parameters, padded_defaults)
if skip_first_arg: if skip_first_arg:
next(args_iter) next(args_iter)
for i, (arg, argty, default) in enumerate(args_iter): yield from self.visit_func_params(((arg.arg, argty, default) for arg, argty, default in args_iter), emission)
if i != 0:
yield ", "
if emission == FunctionEmissionKind.METHOD and i == 0:
yield "Self"
else:
yield from self.visit(argty)
yield arg.arg
if emission in {FunctionEmissionKind.DECLARATION, FunctionEmissionKind.LAMBDA, FunctionEmissionKind.METHOD} and default:
yield " = "
yield from self.expr().visit(default)
yield ")" yield ")"
if emission == FunctionEmissionKind.METHOD: if emission == FunctionEmissionKind.METHOD:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment