[Libre-soc-bugs] [Bug 1094] insndb instruction database visitor-walker is needed

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Sat Jun 10 09:21:59 BST 2023


--- Comment #82 from Dmitry Selyutin <ghostmansd at gmail.com> ---
Long story short. I share your opinion almost on everything, but I had to at
least probe this route to understand its pros and cons.
The only exception is generic __call__. This actually comes from your
isinstance hints (about another section?), but I realized that relying on class
name is too fragile. isinstance refers to an object (yes, types are objects too
in Python); name just refers to some string. Whilst it looks simpler, it's
indeed less intuitive than explicit checks. If somebody wants this
functionality (per-class context managers), they can do it directly in concrete

class WeirdVisitor(Visitor):
    def __call__(self, node):
        method = getattr(self, node.__class__.__name__, self.Node)
        return method(node)

    def Node(self, node):
        raise 666

    def Record(self, node):
        raise 42

TL;DR: I'm removing paths branch. However, there's still one issue with the
approach you suggest.

    def __call__(self, node):
        print("/".join(self.stack_of_stuff), node)
        yield node
        self.stack_of_stuff.pop(-1) # i think

I'f we're going to drop the Node-inherited classes (Path, String and similar
stuff), there's no way we could call node.name (or, again, some other generic
field, because "name" is occupied). `str` or `bool` don't have such interface.

As for bool inheritance, that's not a problem: whilst bool isn't inheritable,
int is.

You are receiving this mail because:
You are on the CC list for the bug.

More information about the libre-soc-bugs mailing list