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

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Thu Jun 8 12:16:35 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=1094

--- Comment #65 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Dmitry Selyutin from comment #60)

>     @contextlib.contextmanager
>     def Record(self, node):
>         if node.name == self.__name:
>             self.__records.add(node)
>  --->   yield node  <---- REMOVE THIS

"yield Node" should be removed, and then the walking *which is now entirely
decoupled* uses walk() from ast.py, and it becomes:

    v = RecordVisitor("XO")
    for node in walk(db):
        v(node)

or, more to the point, those two lines "for node in walk(db): v(node)"
are moved behind a function which RecordVisitorExample inherits from,
just like in pyomo and in that IVisitor pattern

class IVisitor:
    @staticmethod
    def walk_fn(cls, db, visitor):
       for node in walk(db):
           v(node)

then it is:
    v = RecordVisitor("XO") # inherits from IVisitor
    v.walk_fn(db, v)


*no* Visitor should also perform or be involved in or responsible
for child-node-walking *at all*, at *any* time.


i appreciate this is... complex, it's some of the most ridiculously-short
python code, but unless it is short it very much gets out-of-hand very
quickly.

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


More information about the libre-soc-bugs mailing list