There is a problem with libclang — it does not seem to be able to get cursor for standard library functions. I have following Python code:
import clang.cindex
def traverse(node, depth=0):
depth += 1
print depth * '--', node.spelling or node.displayname, node.kind, node.location
for c in node.get_children():
traverse(c, depth)
index = clang.cindex.Index.create()
translation_unit = index.parse('main.cpp', args=['-x', 'c++', '-std=c++11'])
traverse(translation_unit.cursor)
For code like this
6 int main(int argc, char* argv[])
7 {
8 printf("printf %s", "test");
9 return 1;
10 }
it will print following:
---- main CursorKind.FUNCTION_DECL <SourceLocation file 'main.cpp', line 6, column 5>
------ argc CursorKind.PARM_DECL <SourceLocation file 'main.cpp', line 6, column 14>
------ argv CursorKind.PARM_DECL <SourceLocation file 'main.cpp', line 6, column 26>
------ CursorKind.COMPOUND_STMT <SourceLocation file 'main.cpp', line 7, column 1>
-------- CursorKind.RETURN_STMT <SourceLocation file 'main.cpp', line 9, column 5>
---------- CursorKind.INTEGER_LITERAL <SourceLocation file 'main.cpp', line 9, column 12>
As you see, there is no line 8.
Only way to bypass this issue I see is to process tokens and grab needed functions, but I thought there should be a "cleaner" way to do this. Or maybe I am missing something obvious.