From e811dd3672bae8e9421781db6d7c32e48633cc14 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Wed, 7 Feb 2024 10:57:03 -0500 Subject: [PATCH] Add descendents function Add a way to get all descendents of an expression for debugging the size --- python/egglog/declarations.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/egglog/declarations.py b/python/egglog/declarations.py index e1f4bbfd..7e3e80cb 100644 --- a/python/egglog/declarations.py +++ b/python/egglog/declarations.py @@ -1000,6 +1000,16 @@ def from_egg( def to_egg(self, decls: Declarations) -> bindings._Expr: return self.expr.to_egg(decls) + def descendants(self) -> list[TypedExprDecl]: + """ + Returns a list of all the descendants of this expression. + """ + l = [self] + if isinstance(self.expr, CallDecl): + for a in self.expr.args: + l.extend(a.descendants()) + return l + @dataclass class ClassDecl: