示例#1
0
    def generic_visit(self, node):

        # label this node
        out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node))

        # edges to children
        for fieldname, fieldvalue in ast.iter_fields(node):
            for index, child in enumerate_flatten(fieldvalue):
                if isinstance(child, ast.AST):
                    suffix = "".join(["[%d]" % i for i in index])
                    out_string += 'n{} -> n{} [label="{}{}"];\n'.format(
                        id(node), id(child), fieldname, suffix)
                    out_string += self.visit(child)
        return out_string
示例#2
0
文件: dotgen.py 项目: i-Zaak/ctree
    def generic_visit(self, node):

        # label this node
        out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node))

        # edges to children
        for fieldname, fieldvalue in ast.iter_fields(node):
            for index, child in enumerate_flatten(fieldvalue):
                if isinstance(child, ast.AST):
                    suffix = "".join(["[%d]" % i for i in index])
                    out_string += 'n{} -> n{} [label="{}{}"];\n'.format(
                        id(node), id(child), fieldname, suffix)
                    out_string += self.visit(child)
        return out_string
示例#3
0
    def generic_visit(self, node):
        # label this node
        out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node))

        # edge to parent
        if hasattr(node, 'parent') and node.parent is not None:
            out_string += 'n%s -> n%s [label="parent",style=dotted];\n' % (
                id(node), id(node.parent))

        # edges to children
        for fieldname, fieldvalue in ast.iter_fields(node):
            for index, child in enumerate_flatten(fieldvalue):
                if isinstance(child, ast.AST):
                    suffix = "".join(["[%d]" % i for i in index])
                    out_string += 'n%d -> n%d [label="%s%s"];\n' % (
                        id(node), id(child), fieldname, suffix)
                    out_string += _to_dot(child)
        return out_string
示例#4
0
    def generic_visit(self, node):
        # abort if visited
        if node in self._visited:
            return ""
        else:
            self._visited.append(node)

        # label this node
        out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node))

        # edges to children
        for fieldname, fieldvalue in ast.iter_fields(node):
            for index, child in enumerate_flatten(fieldvalue):
                if isinstance(child, ast.AST):
                    suffix = "".join(["[%d]" % i for i in index])
                    out_string += 'n%d -> n%d [label="%s%s"];\n' % (id(node), id(child), fieldname, suffix)
                    out_string += self.visit(child)
        return out_string
示例#5
0
    def generic_visit(self, node):
        # abort if visited
        if node in self._visited:
            return ""
        else:
            self._visited.append(node)

        # label this node
        out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node))

        # edges to children
        for fieldname, fieldvalue in ast.iter_fields(node):
            for index, child in enumerate_flatten(fieldvalue):
                if isinstance(child, ast.AST):
                    suffix = "".join(["[%d]" % i for i in index])
                    out_string += 'n%d -> n%d [label="%s%s"];\n' % (
                        id(node), id(child), fieldname, suffix)
                    out_string += self.visit(child)
        return out_string
示例#6
0
 def _check(self, nested, exp_indices):
     act_indices, values = zip(*enumerate_flatten(nested))
     for actual, expected in zip(act_indices, exp_indices):
         self.assertTupleEqual(actual, expected)
示例#7
0
 def _check(self, nested, exp_indices):
     act_indices, values = zip(*enumerate_flatten(nested))
     for actual, expected in zip(act_indices, exp_indices):
         self.assertTupleEqual(actual, expected)