[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 00:41:49 BST 2023


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

--- Comment #80 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Luke Kenneth Casson Leighton from comment #79)

> likewise will look tomorrow :) but when you are awake i think
> you'll find that what you want is likely achievable with the
> "stack_of_stuff" from comment #76. 

ok yes it was easy to check - took a look: definitely "no" :)

it is perfectly reasonable to have the Visitor itself be
aware of the "order" of things, and to do "stuff" such as
push the node onto a stack that is *local* to the Visitor.

to reproduce what you did, i believe it is:

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

as simple as that.

* no need for pathlib when "/".join() will do (complete overkill)
* the names are accumulated as the __call__ goes down the depth

basically if there is a temptation to add any parameters (like the
depth parameter), it should be resisted :)

the *visitor* function becomes responsible for *using* the fact
that it is being called.

the only good additional parameter, as jacob pointed out, would be
to have the node index.

    def __call__(self, node, node_idx):
    def Record(self, node, node_idx):
    ...

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


More information about the libre-soc-bugs mailing list