parameters: (self, node)
return_statement: return parent
docstring: Return the parent of node, if it exists.
docstring_summary: Return the parent of node, if it exists.
docstring_tokens: Return the parent of node if it exists .
function: def parent(self, node):
          """Return the parent of node, if it exists."""
          # If this is the root, then from the algorithm's point of view, it has no
          # parent.
          if node == self.root:
              return None
  
          # We don't have enough information to tell if this is the end_node (which
          # doesn't have a __parent_ field), or the root (which doesn't have a parent
          # from the algorithm's point of view), so cast_type may not be correct for
          # this particular node. Use heuristics.
  
          # The end_node's left child is the root. Note that when printing interators
          # in isolation, the root is unknown.
          if self.left_child(node) == self.root:
              return None
  
          parent = node.cast(self.cast_type).dereference()["__parent_"]
          # If the value at the offset of __parent_ doesn't look like a valid pointer,
          # then assume that node is the end_node (and therefore has no parent).
          # End_node type has a pointer embedded, so should have pointer alignment.
          if addr_as_long(parent) % _void_pointer_type.alignof:
              return None
          # This is ugly, but the only other option is to dereference an invalid
          # pointer.  0x8000 is fairly arbitrary, but has had good results in
          # practice.  If there was a way to tell if a pointer is invalid without
          # actually dereferencing it and spewing error messages, that would be ideal.
          if parent < 0x8000:
              return None
          return parent
function_tokens: def parent ( self , node ) : # If this is the root, then from the algorithm's point of view, it has no # parent. if node == self . root : return None # We don't have enough information to tell if this is the end_node (which # doesn't have a __parent_ field), or the root (which doesn't have a parent # from the algorithm's point of view), so cast_type may not be correct for # this particular node. Use heuristics. # The end_node's left child is the root. Note that when printing interators # in isolation, the root is unknown. if self . left_child ( node ) == self . root : return None parent = node . cast ( self . cast_type ) . dereference ( ) [ "__parent_" ] # If the value at the offset of __parent_ doesn't look like a valid pointer, # then assume that node is the end_node (and therefore has no parent). # End_node type has a pointer embedded, so should have pointer alignment. if addr_as_long ( parent ) % _void_pointer_type . alignof : return None # This is ugly, but the only other option is to dereference an invalid # pointer.  0x8000 is fairly arbitrary, but has had good results in # practice.  If there was a way to tell if a pointer is invalid without # actually dereferencing it and spewing error messages, that would be ideal. if parent < 0x8000 : return None return parent