Module opshin.optimize.optimize_remove_unreachable
Expand source code
from ..typed_util import ScopedSequenceNodeTransformer
"""
Removes statements that are unreachable because a previous statement in the same
sequence is known not to fall through.
"""
class OptimizeRemoveUnreachable(ScopedSequenceNodeTransformer):
step = "Removing unreachable statements"
def visit_sequence(self, statements):
visited = []
for stmt in statements:
if stmt is None:
continue
stmt_cp = self.visit(stmt)
if stmt_cp is None:
continue
visited.append(stmt_cp)
if not getattr(stmt_cp, "can_fall_through", True):
break
return visited
Classes
class OptimizeRemoveUnreachable-
Rewrite nested statement sequences while preserving the surrounding node.
Expand source code
class OptimizeRemoveUnreachable(ScopedSequenceNodeTransformer): step = "Removing unreachable statements" def visit_sequence(self, statements): visited = [] for stmt in statements: if stmt is None: continue stmt_cp = self.visit(stmt) if stmt_cp is None: continue visited.append(stmt_cp) if not getattr(stmt_cp, "can_fall_through", True): break return visitedAncestors
- ScopedSequenceNodeTransformer
- CompilingNodeTransformer
- TypedNodeTransformer
- ast.NodeTransformer
- ast.NodeVisitor
Class variables
var step-
Inherited from:
ScopedSequenceNodeTransformer.stepThe type of the None singleton.
Methods
def visit(self, node)-
Inherited from:
ScopedSequenceNodeTransformer.visitVisit a node.
def visit_sequence(self, statements)-
Expand source code
def visit_sequence(self, statements): visited = [] for stmt in statements: if stmt is None: continue stmt_cp = self.visit(stmt) if stmt_cp is None: continue visited.append(stmt_cp) if not getattr(stmt_cp, "can_fall_through", True): break return visited