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,

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.py

import 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.py

CursorKind.TRANSLATION_UNIT
CursorKind.TYPEDEF_DECL
CursorKind.FUNCTION_DECL
CursorKind.COMPOUND_STMT
CursorKind.DECL_STMT
CursorKind.TYPEDEF_DECL

type Input.cpp

typedef int myModuleType;

void foo()
{
  typedef int myFunctionType;
}

Regards
David

Hi,

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,