Closed dmcardle closed 1 year ago
get_tokens
only return tokens without preprocess.
To traverse the AST, use cursor.get_children()
( https://github.com/sighingnow/libclang/blob/master/python/clang/cindex.py#L2002) instead.
Thanks for the response, @sighingnow!
I don't think cursor.get_children()
solves the problem (or maybe I'm misunderstanding).
I'm already traversing the AST and finding the desired CALL_EXPR, but I want to get the tokens after preprocessing. Something like clang::syntax::TokenBuffer::expandedTokens()
.
I added a little bit to the test above — I can't figure out how to wrangle get_children()
to do something useful here.
# Use `cursor.get_children()` as recommended in
# <https://github.com/sighingnow/libclang/issues/61>.
# The CALL_EXPR has two children, but their spelling does not
# correspond to the call arguments.
self.assertEqual([c.spelling for c in cursor.get_children()],
['magic', ''])
# The CALL_EXPR's one argument has no children.
self.assertEqual(len(list(arg.get_children())), 0)
Hi, folks!
As the title suggests, I'm getting an incorrect spelling for CALL_EXPR arguments, but only when the call site was created by expanding a macro.
Here's a Python test that shows what I'm talking about: