[cfe-dev] accessing parent node. Please, help.

Juan Jose Lopez Villarejo jj.lopezvillarejo at cern.ch
Thu Oct 17 03:19:27 PDT 2013


Hello,

I am using the clang python bindings and I can easily access the children of a node/cursor with the function
node.get_children(). See below the code of this function.

Do you have any idea how to get the parent node from a given node? I don't want the semantic_parent or lexical_parent.
Any hack to the code of get_children would make it? I see the word "parent" written there.

Cheers,

Juan






==================
[from cindex.py]

    def get_children(self):
        """Return an iterator for accessing the children of this cursor."""

        # FIXME: Expose iteration from CIndex, PR6125.
        def visitor(child, parent, children):
            # FIXME: Document this assertion in API.
            # FIXME: There should just be an isNull method.
            assert child != conf.lib.clang_getNullCursor()

            # Create reference to TU so it isn't GC'd before Cursor.
            child._tu = self._tu
            children.append(child)
            return 1 # continue
        children = []
        conf.lib.clang_visitChildren(self, callbacks['cursor_visit'](visitor),
            children)
        return iter(children)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131017/43ad6e31/attachment.html>


More information about the cfe-dev mailing list