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

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Fri Jun 9 23:30:07 BST 2023


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

--- Comment #75 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
ah. just spotted this:

  class Dataclass(metaclass=DataclassMeta):
    @walkmethod
    def walk(clsself, match=None):
        if match is None: match = lambda subnode: True
        def field_type(field): return field.type
        def field_value(field): return getattr(clsself, field.name)
        field = (field_type if isinstance(clsself, type) else field_value)
                               ^^^^^^^^^^^

ahhhmmm.... ahmhahm....  i'm not sure that this is needed.  if you are
calling the Visitor on a class (not an instance), you *know* that the
visitor-function is going to receive types, not instances.

so there will be no "mixing"...

... but if we _did_ want to mix (have for example *both* visiting of
the database-types *and* visiting of the database-instances) then
one way to handle that would be.... [going back to the old Visitor API]

class ListVisitor(Visitor):
    @contextlib.contextmanager
    def Record(self, node):
        print(node.name)
        yield node
           -- vvvv ---
    def RecordType(self, node):
           -- ^^^^ ---
        print(node.type)
        yield node

it's.... six of one and half a dozen of the other: one option would be
just to call two separate Visitors.

* the first one to print out a c header file,
* the second one to print out the c source file.

but i kinda like the idea of the Visitor being (optionally) able to
handle both (and the same Visitor instance be able to output both
the header and source file)

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


More information about the libre-soc-bugs mailing list