Valentin Tolmer via llvm-dev
2016-May-08 04:13 UTC
[llvm-dev] typedef not present in the python AST
Hello, I'm trying to use the python libclang bindings to write a C++ style-checker, and I'd like to detect all the typedefs to recommend switching to using. I'm using libclang 3.8, with the python bindings provided with it. When I parse a file with index = clang.cindex.Index.create() tu = index.parse(f, ['-x', 'c++', '-std=c++11', '-fsyntax-only', '-I', '.']) and then I display the node kinds of every node in the AST (recursively calling get_children() on every node), I get a node of type CursorKind.TYPEDEF_DECL, but only if it is top-level (or inside a namespace or class). If the typedef is in a function body, it doesn't get reported at all (even though variable declarations before and after are reported). Why are they not reported? Thanks, -- Valentin Tolmer
David Wiberg via llvm-dev
2016-May-10 19:02 UTC
[llvm-dev] typedef not present in the python AST
Hi, It should work. I tested according to below (admittedly this was with latest and not 3.8). Are you doing something different?>type test.pyimport clang.cindex def printNodeAndChildren(cursor): print(cursor.kind) for child in cursor.get_children(): printNodeAndChildren(child) index = clang.cindex.Index.create() tu = index.parse('Input.cpp', ['-x', 'c++', '-std=c++11', '-fsyntax-only', '-I', '.']) printNodeAndChildren(tu.cursor)>python test.pyCursorKind.TRANSLATION_UNIT CursorKind.TYPEDEF_DECL CursorKind.FUNCTION_DECL CursorKind.COMPOUND_STMT CursorKind.DECL_STMT CursorKind.TYPEDEF_DECL>type Input.cpptypedef int myModuleType; void foo() { typedef int myFunctionType; } Regards David 2016-05-08 6:13 GMT+02:00 Valentin Tolmer via llvm-dev <llvm-dev at lists.llvm.org>:> Hello, > > I'm trying to use the python libclang bindings to write a C++ > style-checker, and I'd like to detect all the typedefs to recommend > switching to using. I'm using libclang 3.8, with the python bindings > provided with it. > > When I parse a file with > index = clang.cindex.Index.create() > tu = index.parse(f, ['-x', 'c++', '-std=c++11', '-fsyntax-only', '-I', '.']) > > and then I display the node kinds of every node in the AST > (recursively calling get_children() on every node), I get a node of > type CursorKind.TYPEDEF_DECL, but only if it is top-level (or inside a > namespace or class). > > If the typedef is in a function body, it doesn't get reported at all > (even though variable declarations before and after are reported). > > Why are they not reported? > > Thanks, > > -- > Valentin Tolmer > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Valentin Tolmer via llvm-dev
2016-May-10 20:50 UTC
[llvm-dev] typedef not present in the python AST
Hi, On Tue, May 10, 2016 at 12:02 PM, David Wiberg <dwiberg at gmail.com> wrote:> It should work. I tested according to below (admittedly this was with > latest and not 3.8). Are you doing something different?I should have presented a minimal working example. There's still some places in my code where it doesn't work, but I suspect that it's due to compilation errors, due to the wrong flags being used. Is there any way to get the command line from compile_commands.json to provide the flags? By default, I get errors like "stdarg.h" could not be found. Thanks, -- Valentin Tolmer
Possibly Parallel Threads
- [LLVMdev] Parsing C++ headers with Clang bindings for Python
- [LLVMdev] Parsing C++ headers with Clang bindings for Python
- [LLVMdev] Parsing C++ headers with Clang bindings for Python
- [LLVMdev] Parsing C++ template parameters using cindex.py
- [751] trunk/wxruby2/swig/typedefs.i: Added wxUint32 typedef