[cfe-dev] Question about usage of Python bindings to clang
Russell Keith-Magee via cfe-dev
cfe-dev at lists.llvm.org
Wed Jan 20 06:11:27 PST 2016
Hi all,
I’ve got some questions about the data returned by the Python bindings to
clang.
When clang is invoked with “-Xclang -ast-dump -fsyntax-only” to dump the
AST for a source file, the output of clang appears to provide much richer
output than the Python bindings exposes. I’m guessing this is because the
relevant details are deeply embedded in the cursor object returned by the
Python API, but I’m not sure where I should be looking for this extra
detail.
In particular, when clang returns a CXXConstructExpr, the Python API
returns CursorKind.CALL_EXPR, which is the same node type returned by a
normal function call - so it isn’t possible to differentiate a normal
method call from a constructor.
Similarly, when clang returns a MaterializeTemporaryExpr or
ImplicitCastExpr, the Python API returns a CursorKind.UNEXPOSED_EXPR.
How do you interrogate the Python API to determine the richer node types
that clang is returning?
If it helps, I’ve posted full example code and output in a gist:
https://gist.github.com/freakboy3742/5826ef09789dfba9042e
This contains three files:
* a sample.cpp file with a simple class, and a function using that class
* An AST dump of the file provided by clang
* The AST produced by the Python bindings, generated by walking the tree,
printing the node kind, type, return type and spelling, and then doing the
same for each child.
Yours,
Russ Magee %-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160120/4cbb79b2/attachment.html>
More information about the cfe-dev
mailing list