[cfe-dev] AST oddities

Peter Stirling peter at pjstirling.plus.com
Sat Aug 2 15:13:33 PDT 2014


Hi,
I've got plans to write a clang tool to automatically generate universal 
foreign function interface definitions, to allow usage of c++ libraries 
from non-c++ languages. As part of that I need to pull out correct 
function and type names from the AST to go into a new .cc file.

clang::NamedDecl::getQualifiedNameAsString() sounds like it should be 
what I want, but I'm having a couple of problems with it so far:

a) for EnumConstantDecl it returns a name including the name of the 
EnumDecl (which is arguably correct, but is invalid in c++ code). I 
think it would be better if there was a second method that produced the 
syntactically correct version.
b) the attached file is a cut-down example from the system headers on my 
machine (gcc-4.8.3 if it matters). When you call 
getQualifiedNameAsString() on the __uselocale function declaration (I 
was surprised to learn that it WAS a function declaration), clang 
returns "__uselocale" and not "__gnu_cxx::__uselocale". Is this a bug, 
or some misunderstanding on my part?

I've been using the RecursiveASTVisitor to do the tree walking, and can 
I ask whether there is some convenient way to prune a node's children, 
without aborting the whole traversal? For example: I want to visit 
CXXRecordDecl, but not the ones inside function bodies. At the moment I 
am walking up the parent DeclContext chain, which (to me) seems less 
than ideal.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: dummy.cc
Type: text/x-c++src
Size: 198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140802/ca523548/attachment.cc>


More information about the cfe-dev mailing list