I'm currently writing a static C++ code analyser using clang's python bindings and for some reason, I can not find wether something is extern or not in the AST eventhough there is a CursorKind which seems to be apropriate (CXCursor_LinkageSpec)
What I mean is that when parsing code like extern int foo; I will only find my variable foo in the AST and not a single clue of its linkage specifications.
What am I missing?
Regards
class VarDecl has a member function: bool hasExternalStorage () const which tells you whether the variable is extern or not.
I'm using clang's C++ lib. Hope it will help with your python work.
Bit of a necroanswer but if you go in to clang\lib\Sema\SemaCodeComplete.cpp(in \llvm\tools\ if you follow llvm's installation instructions) and add the following line:
case Decl::LinkageSpec: return CXCursor_LinkageSpec;
To the switch in:
CXCursorKind clang::getCursorKindForDecl(const Decl *D)
It should resolve the issue of clang's Python binder returning UNEXPOSED_DECL instead of the correct LINKAGE_SPEC. This change was made at revision 183352(2013-06-05).
Example from my version:
CXCursorKind clang::getCursorKindForDecl(const Decl *D) {
if (!D)
return CXCursor_UnexposedDecl;
switch (D->getKind()) {
case Decl::Enum: return CXCursor_EnumDecl;
case Decl::LinkageSpec: return CXCursor_LinkageSpec;
// ......
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With