[llvm-bugs] [Bug 24471] New: libclang python bindings does not reparse file

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 17 00:59:58 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24471

            Bug ID: 24471
           Summary: libclang python bindings does not reparse file
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jeanmarc.leroux at aerys.in
                CC: klimek at google.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

I'm trying tu use liblcang to list all the setters of my C++ headers. I'm using
the Python bindings and libclang.so.3.6.

    def parse(self, flags):
        self._index = clang.cindex.Index.create()
        self._clangSource = self._index.parse(self._path, args=flags)
        self._class =
self._get_minko_script_classes(self._clangSource.cursor)[0]
        print(self._class)
        self._name = self._class.spelling
        self._props = self._get_class_setters(self._class)

    def _get_minko_script_classes(self, root, cursors=[]):
        for cursor in root.get_children():
            if cursor.kind == clang.cindex.CursorKind.CLASS_DECL:
                for c in cursor.get_children():
                    if c.kind == clang.cindex.CursorKind.CXX_BASE_SPECIFIER:
                        if c.displayname == "minko::component::AbstractScript":
                            cursors.append(cursor)
            else:
                self._get_minko_script_classes(cursor, cursors)

        return cursors

    def _get_class_setters(self, cursor):
        setters = {}

        for child in cursor.get_children():
            if (child.kind == clang.cindex.CursorKind.CXX_METHOD
                and child.access_specifier ==
clang.cindex.AccessSpecifier.PUBLIC
                and child.result_type.spelling == 'void'):
                args = list(child.get_arguments())
                if len(args) == 1 and args[0].type.spelling in
MinkoScript.setter_types:
                    setters[child.spelling] = args[0].type.spelling

        return setters

Those 3 methods work just fine and `self._props` will be filled with a
(setter_name, setter_type) dict.

Now when the C++ header is edited - to add a setter for example - I need to
update `self._props`.

So I call `parse` again. It re-creates everything it possibly could about
libclang (index, translation unit...). But the result is exactly the same as
the 1st time. It still takes some time though: it looks like it's actually
doing the job. But it gives the exact same result.

To prove it, I print the class declaration `Cursor` object, and every call to
`parse` will give the same output (so I'm exact it's the exact same `Cursor`
object. For example, calling `parse` twice will give:

    <clang.cindex.Cursor object at 0x7f77105572f0>
    <clang.cindex.Cursor object at 0x7f77105572f0>

I've tried:

 - using the libclang `reparse` function: the problem is the same.
 - copying the file in a temporary file and re-parsing it: the problem is the
same (I'm guessing I should change the file name to, and not just it's path...
but still).

Re-starting my Python app (Blender in this case) is the only way to actually
reparse the file. So I'vre tried reloading the module with `importlib.reload`.
But it makes libclang unusable with weird errors such as "expected Cursor
instance, got Cursor".

So I think it's a bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150817/4fec2538/attachment.html>


More information about the llvm-bugs mailing list