MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Node

Class Node

tensorflow/python/autograph/pyct/cfg.py:44–83  ·  view source on GitHub ↗

A node in the CFG. Although new instances of this class are mutable, the objects that a user finds in the CFG are typically not. The nodes represent edges in the CFG graph, and maintain pointers to allow efficient walking in both forward and reverse order. The following property holds fo

Source from the content-addressed store, hash-verified

42
43
44class Node(object):
45 """A node in the CFG.
46
47 Although new instances of this class are mutable, the objects that a user
48 finds in the CFG are typically not.
49
50 The nodes represent edges in the CFG graph, and maintain pointers to allow
51 efficient walking in both forward and reverse order. The following property
52 holds for all nodes: "child in node.next" iff "node in child.prev".
53
54 Attributes:
55 next: FrozenSet[Node, ...], the nodes that follow this node, in control
56 flow order
57 prev: FrozenSet[Node, ...], the nodes that precede this node, in reverse
58 control flow order
59 ast_node: ast.AST, the AST node corresponding to this CFG node
60 """
61
62 def __init__(self, next_, prev, ast_node):
63 self.next = next_
64 self.prev = prev
65 self.ast_node = ast_node
66
67 def freeze(self):
68 self.next = frozenset(self.next)
69 # Assumption: All CFG nodes have identical life spans, because the graph
70 # owns them. Nodes should never be used outside the context of an existing
71 # graph.
72 self.prev = weakref.WeakSet(self.prev)
73
74 def __repr__(self):
75 if isinstance(self.ast_node, gast.FunctionDef):
76 return 'def %s' % self.ast_node.name
77 elif isinstance(self.ast_node, gast.ClassDef):
78 return 'class %s' % self.ast_node.name
79 elif isinstance(self.ast_node, gast.withitem):
80 return compiler.ast_to_source(
81 self.ast_node.context_expr, include_encoding_marker=False).strip()
82 return compiler.ast_to_source(
83 self.ast_node, include_encoding_marker=False).strip()
84
85
86class Graph(

Callers 1

_add_new_nodeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected